OCCT示例学习笔记3--Modeling项目

OCCT的版本是7.6.0. Modeling项目,代码学习记录。

1、点镜像

在void CModelingDoc::OnMirror() 函数中。
显示效果如下:
在这里插入图片描述
应用的类如下:

  • BRepPrimAPI_MakeWedge类;上图显示的绿色梯形
  • Geom_CartesianPoint类;点Geom_Point的实现类。
  • AIS_Point类,显示点的类,上图中间的黄色十字。
  • gp_Trsf类,设置镜像移动。
  • BRepBuilderAPI_Transform类;移动变换。

2、轴镜像

在void CModelingDoc::OnMirroraxis()函数中。
显示效果如下:
在这里插入图片描述
应用的类如下:

  • gp_Ax1类,描述轴的类
  • Geom_Axis1Placement类;描述 3D 空间中的轴。
  • AIS_Axis类,显示轴的类。

3、旋转效果

在void CModelingDoc::OnRotate()函数中。
显示效果如下:
在这里插入图片描述

应用的类如下:
上面都有了。略

4、缩放效果

在void CModelingDoc::OnScale()函数中。
显示效果如下:
在这里插入图片描述

应用的类如下:
上面都有了。略

5、移动效果

在void CModelingDoc::OnTranslation()函数中。
显示效果如下:
在这里插入图片描述

应用的类如下:
ISession_Direction类,AIS_InteractiveObject类的子类,显示移动轴。

6、轴坐标位移效果

在void CModelingDoc::OnDisplacement()函数中。
显示效果如下:
在这里插入图片描述

应用的类如下:
通过设置轴来设置位移效果。

	gp_Ax3 ax3_1(gp_Pnt(0,0,0),gp_Dir(0,0,1));
	gp_Ax3 ax3_2(gp_Pnt(60,60,60),gp_Dir(1,1,1));
	gp_Trsf theTransformation;
	theTransformation.SetDisplacement(ax3_1, ax3_2);

7、移动效果

在void CModelingDoc::OnDeform()函数中。
显示效果如下:
在这里插入图片描述

应用的类如下:

  • BRepBuilderAPI_GTransform类
  • gp_GTrsf类,定义 3D 空间中的非持久变换
  • gp_Mat类
	gp_GTrsf theTransformation;
	gp_Mat rot(5, 0, 0, 0, 3, 0, 0, 0, 1);
	theTransformation.SetTranslationPart(gp_XYZ(5, 5, 5));//平移和缩放的位置前后没有变换
	theTransformation.SetVectorialPart(rot);//这个是不同轴向的缩放

8、各种基础模型显示

在void CModelingDoc::OnBox() 函数中。显示效果如下:
在这里插入图片描述

在void CModelingDoc::OnCylinder() 函数中。显示效果如下:
在这里插入图片描述

在void CModelingDoc::OnCone() 函数中。显示效果如下:
在这里插入图片描述

在void CModelingDoc::OnSphere()函数中。显示效果如下:
在这里插入图片描述

在CModelingDoc::OnTorus()函数中。显示效果如下:
在这里插入图片描述

在CModelingDoc::OnWedge()函数中。显示效果如下:
在这里插入图片描述
在CModelingDoc::OnPrism()函数中。显示效果如下:(拉伸功能)
在这里插入图片描述

应用的类如下:

  • BRepPrimAPI_MakeBox类
  • BRepPrimAPI_MakeCylinder类
  • BRepPrimAPI_MakeCone类
  • BRepPrimAPI_MakeSphere类
  • BRepPrimAPI_MakeTorus类
  • BRepPrimAPI_MakeWedge类
  • BRepPrimAPI_MakePrism
  • BRepBuilderAPI_MakeVertex
  • BRepBuilderAPI_MakeEdge
  • BRepBuilderAPI_MakeWire
  • BRepBuilderAPI_MakeFace
  • BRepPrimAPI_MakePrism

9、各种元素的旋转建模

在void CModelingDoc::OnRevol()函数中。显示效果如下:
在这里插入图片描述
应用的类如下:

  • BRepPrimAPI_MakeRevol类,制作旋转扫描拓扑的类。
  • Geom_Axis1Placement类,描述 3D 空间中的轴。
  • AIS_Axis类,显示 3D 空间中的轴。

10、pipe的建模

在void CModelingDoc::OnPipe()函数中。显示效果如下:
在这里插入图片描述

在这里插入图片描述
应用的类如下:

  • TColgp_Array1OfPnt类,是gp_Pnt 的容器。
  • gp_Pnt类,三维描述一个点。
  • Geom_BezierCurve类,描述有理或非有理贝塞尔曲线。(不懂)
  • gp_Circ类,描述三维的一个圆。
  • BRepOffsetAPI_MakePipe类,描述构建管道的函数。管道通过扫掠沿线(称为脊柱)构建基本形状(称为轮廓)。轮廓不得包含实体。

主要代码如下:

	TopoDS_Edge E = BRepBuilderAPI_MakeEdge(curve);
	TopoDS_Wire wire = BRepBuilderAPI_MakeWire(E);
	
	gp_Circ c = gp_Circ(gp_Ax2(gp_Pnt(0.,0.,0.),gp_Dir(0.,1.,0.)),10.);
	TopoDS_Edge Ec = BRepBuilderAPI_MakeEdge(c);
	TopoDS_Wire Wc = BRepBuilderAPI_MakeWire(Ec);	
	TopoDS_Face F = BRepBuilderAPI_MakeFace(gp_Pln(gp::ZOX()),Wc);
	TopoDS_Shape S = BRepOffsetAPI_MakePipe(wire,F);

11、thru的建模

在void CModelingDoc::OnThru()函数中。显示效果如下:
在这里插入图片描述

应用的类如下:

  • BRepOffsetAPI_ThruSections类,这是一个壳或实体以给定的顺序通过一组部分。通常部分是连线,但第一个和最后一个部分可能是顶点。上图就是该类的两个创建效果一个是平滑化的建模。

主要代码如下:

	BRepOffsetAPI_ThruSections generator(Standard_False,Standard_True);
	generator.AddWire(W1);
	generator.AddWire(W3);
	generator.AddWire(W4);
	generator.AddWire(W2);
	generator.Build();
	TopoDS_Shape S1 = generator.Shape();

12、进化形状的建模

在void CModelingDoc::OnEvolved()函数中。显示效果如下:
在这里插入图片描述

在这里插入图片描述

GeomAbs_Arc类型的效果图。

应用的类如下:

  • BRepBuilderAPI_MakePolygon类,描述构建多边形线的函数。
  • BRepOffsetAPI_MakeEvolved类,描述构建进化形状的函数。演化的形状由平面脊(面或线)和轮廓(线)构建而成。

主要代码如下:

	BRepBuilderAPI_MakePolygon P;
	P.Add(gp_Pnt(0.,0.,0.));
	P.Add(gp_Pnt(200.,0.,0.));
	P.Add(gp_Pnt(200.,200.,0.));
	P.Add(gp_Pnt(0.,200.,0.));
	P.Add(gp_Pnt(0.,0.,0.));
	TopoDS_Wire W = P.Wire();
	
	TopoDS_Wire wprof = BRepBuilderAPI_MakePolygon(
				gp_Pnt(0.,0.,0.),gp_Pnt(-60.,-60.,-200.));
			
	TopoDS_Shape S = BRepOffsetAPI_MakeEvolved(
			W,wprof,GeomAbs_Arc,Standard_True,Standard_False,
			Standard_True,0.0001);
	Handle(AIS_Shape) ais3 = new AIS_Shape(wprof);
	myAISContext->Display(ais3,Standard_False);

13、锥形变换

在void CModelingDoc::OnDraft()函数中。显示效果如下:
在这里插入图片描述
应用的类如下:

  • BRepOffsetAPI_DraftAngle类,形状上的锥形添加变换。

主要代码如下:

	BRepOffsetAPI_DraftAngle adraft(S);
	int i =1;
	TopExp_Explorer Ex;
	for (Ex.Init(S,TopAbs_FACE); Ex.More(); Ex.Next()) {
   
   
		TopoDS_Face F = TopoDS::Face(Ex.Current());
		Handle(Geom_Plane) surf = Handle(Geom_Plane)::DownCast(BRep_Tool::Surface(F));
		gp_Pln apln = surf->Pln();
		gp_Dir dirF = apln.Axis().Direction();
		if (dirF.IsNormal(gp_Dir(0.,0.,1.),Precision::Angular()))
			adraft.Add(F, gp_Dir(0.,0.,1.), 15.0*M_PI/180, gp_Pln(gp::XOY()));
	}
	ais1->Set(adraft.Shape());
	myAISContext->Redisplay(ais1,Standard_False);

14、布尔运算

在void CModelingDoc::OnCut()函数中。显示效果如下:
在这里插入图片描述

在void CModelingDoc::OnFuse()函数中。显示效果如下:
在这里插入图片描述

在void CModelingDoc::OnCommon()函数中。显示效果如下:
在这里插入图片描述

应用的类如下:

  • BRepAlgoAPI_Cut类,布尔减运算。
  • BRepAlgoAPI_Fuse类,布尔加运算。
  • BRepAlgoAPI_Common类,布尔交集运算。

主要代码如下:

		TopoDS_Shape FusedShape = BRepAlgoAPI_Fuse(theBox1, theBox2);
		TopoDS_Shape ShapeCut = BRepAlgoAPI_Cut(theSphere, theBox);
		TopoDS_Shape theCommonSurface = BRepAlgoAPI_Common(theBox, theWedge);

15、截面运算

在void CModelingDoc::OnSection()函数中。显示效果如下:

在这里插入图片描述

应用的类如下:

  • BRepPrimAPI_MakeTorus类,构建圆环形状类。
  • BRepPrimAPI_MakeSphere类,构建球体形状类。
  • BRepAlgoAPI_Section类,是在参数和工具之间建立一个截面算法。Section运算的结果由顶点和边组成。

主要代码如下:

		BRepAlgoAPI_Section section(atorus, asphere, PerformNow);
		section.ComputePCurveOn1(Standard_True);
		section.Approximation(TopOpeBRepTool_APPROX);
		section.Build();

		Handle(AIS_Shape) asection = new AIS_Shape(section.Shape());
		myAISContext->SetDisplayMode(asection, 0, Standard_False);

16、平面的截面运算

在void CModelingDoc::OnPsection()函数中。显示效果如下:
在这里插入图片描述

应用的类如下:

  • gp_Pln类,描述 3D 空间中的平面。
  • Geom_Plane类,描述 3D 空间中的平面。
  • gce_MakePln类,实现了以下用于从 gp 创建平面的算法。
  • gp_Pln类,Geom_Plane类和gce_MakePln类,都是描述三维空间中的平面,他们是不同包中的不同算法,每个类里面有一些不同的算法。
  • AIS_Plane类,构造用于显示复合形状的平面基准。
  • BRepAlgoAPI_Section类,是在参数和工具之间建立一个截面算法。Section运算的结果由顶点和边组成。

主要代码如下:

		BRepAlgoAPI_Section section(atorus, asphere, PerformNow);
		section.ComputePCurveOn1(Standard_True);
		section.Approximation(TopOpeBRepTool_APPROX);
		section.Build();

		Handle
03-11
### 集成QT与OCCT的方法 为了实现QT与OpenCASCADE Technology (OCCT) 的集成,通常采用的方式是在QT应用程序中嵌入OCCT的可视化组件。具体来说,在创建几何模型并将其展示给用户的过程中,可以通过以下方式达成: #### 创建几何对象并与AIS_Shape类关联 在构建三维模型时,可以利用OCCT提供的API来定义各种类型的实体,比如球体、圆柱或其他复杂结构。一旦这些实体被成功创建,则可通过`AIS_Shape`实例化相应的表示形式,并进一步加入至场景中的交互式上下文中[^2]。 ```cpp TopoDS_Shape mySphere = BRepPrimAPI_MakeSphere(100.).Shape(); Handle(AIS_Shape) ais_sphere = new AIS_Shape(mySphere); theAISContext->Display(ais_sphere, Standard_True); ``` #### 构建基于QT的应用界面 对于GUI部分的设计,推荐使用QT框架下的控件库来进行开发。这不仅限于简单的按钮和菜单栏设置,还包括更复杂的布局管理以及信号槽机制的支持。特别值得注意的是,当涉及到3D视图呈现时,应考虑将OCCT所提供的交互式视图作为核心显示区域的一部分[^4]。 ```cpp // 初始化QMainWindow及其子部件 QWidget *centralWidget = new QWidget(this); ui.setupUi(centralWidget); // 设置中央窗口的小部件为主窗体的内容区 setCentralWidget(centralWidget); // 将OCC Viewer嵌入到Qt Widget中 Handle(V3d_View) aView = ... ; // 假设已初始化好V3d_View对象 Handle(QvisOccViewerArea) viewerArea(new QvisOccViewerArea(aView)); ui.verticalLayout->addWidget(viewerArea); ``` #### 启动事件循环以保持程序运行态 最后一步是启动QT的消息处理机制——即调用`app.exec()`函数进入主消息循环阶段。这样做能够确保整个应用处于响应状态,随时准备接收来自用户的输入指令或者内部发生的各类事件通知。 ```cpp int main(int argc, char **argv){ QApplication app(argc, argv); MainWindow w; w.show(); return app.exec(); } ``` 通过以上步骤,即可实现在QT环境中高效地运用OCCT技术进行图形操作的目的。此外,如果项目需求涉及更多高级特性,如周期性边界条件设定或是历史记录功能维护等方面的工作,则可以根据具体情况参照官方文档做适当调整[^3]。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值