代码拉取完成,页面将自动刷新
#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);
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。