2 Star 1 Fork 1

liuzhongtu/HelloQocct

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
occtDemo.cpp 2.91 KB
一键复制 编辑 原始数据 按行查看 历史
Darren.liu 提交于 2024-03-06 09:20 . 添加注释
#include "occtDemo.h"
#include "Viewer.h"
#include <TopoDS_Shape.hxx>
#include <BRepPrimAPI_MakeBox.hxx>
#include <BRepPrimAPI_MakeCylinder.hxx>
#include <AIS_Shape.hxx>
#include <AIS_PointCloud.hxx>
#include <AIS_Manipulator.hxx>
#include <AIS_InteractiveContext.hxx>
//using namespace occ_demo;
namespace {
// 产生随机数
// 左闭右闭区间
int intervalRand(int min, int max) {
return (rand() % (max - min + 1)) + min;
}
TopoDS_Shape createCylinder(const gp_Pnt& location,
const gp_Dir& direction,
const Standard_Real radius,
const Standard_Real height)
{
return BRepPrimAPI_MakeCylinder(gp_Ax2(location, direction), radius, height);
}
TopoDS_Shape createBox()
{
return BRepPrimAPI_MakeBox(gp_Pnt(0, 0, 0), 100, 200, 300).Shape();
}
}
// 显示坐标系
bool occt_demo::visualizeTriedron(Viewer* viewer)
{
// 获取并更改坐标系的显示状态
Standard_Boolean bTriedronShowed = !viewer->isTrihedronShowed();
// 更新坐标系的显示
viewer->showTrihedron(bTriedronShowed);
viewer->redrawView();
// 返回当前显示状态
return bTriedronShowed;
}
// 显示操作器
void occt_demo::visualizeManipulator(Viewer* viewer)
{
Handle(AIS_InteractiveContext) context = viewer->context();
// display near cylinder
gp_Pnt location(100., 100., 0.);
gp_Dir direction = gp::OZ().Direction();
Standard_Real radius = 10.;
Standard_Real height = 50.;
TopoDS_Shape shapeTopo = createCylinder(location, direction, radius, height);
Handle(AIS_Shape) shape = new AIS_Shape(shapeTopo);
shape->SetMaterial(Graphic3d_NameOfMaterial::Graphic3d_NameOfMaterial_Pewter);
context->Display(shape, AIS_Shaded, AIS_Shape::SelectionMode(TopAbs_SHAPE), Standard_False);
// display manipulator
Handle(AIS_Manipulator) manipulator = new AIS_Manipulator();
manipulator->SetModeActivationOnDetection(true);
manipulator->SetZoomPersistence(true);
manipulator->Attach(shape);
// display far cylinder
location.Translate(gp_Vec(-60., 0., 0.));
shapeTopo = createCylinder(location, direction, radius, height);
shape = new AIS_Shape(shapeTopo);
shape->SetMaterial(Graphic3d_NameOfMaterial::Graphic3d_NameOfMaterial_Stone);
context->Display(shape, AIS_Shaded, AIS_Shape::SelectionMode(TopAbs_SHAPE), Standard_True);
}
// 显示点云
void occt_demo::visualizePointCloud(Viewer* viewer)
{
Handle(AIS_InteractiveContext) context = viewer->context();
// 点云数组
Handle(Graphic3d_ArrayOfPoints) aPoints = new Graphic3d_ArrayOfPoints(1000, Standard_True);
// 为点云数组赋值
srand(time(NULL));
for (size_t i = 0; i < 10; i++)
for (size_t j = 0; j < 10; j++)
for (size_t k = 0; k < 10; k++)
{
Standard_Real x = intervalRand(0, 100);
Standard_Real y = intervalRand(0, 100);
Standard_Real z = intervalRand(0, 100);
aPoints->AddVertex(gp_Pnt(x, y, z), Quantity_Color(Quantity_NOC_WHITE));
}
// 生成并设置点云对象
Handle(AIS_PointCloud) aPntCloud = new AIS_PointCloud();
aPntCloud->SetPoints(aPoints);
//显示点云
context->Display(aPntCloud, Standard_True);
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/liuzhongtu/hello-qocct.git
git@gitee.com:liuzhongtu/hello-qocct.git
liuzhongtu
hello-qocct
HelloQocct
master

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385