OpenCASCADE Make Primitives-Box
OpenCASCADE Make Primitives-Box
Abstract. By making a simple box to demonstrate the BRep data structure of the OpenCASCADE. The construction method is different from BRepPrimAPI_MakeBox. In the paper construct the box from vertex, edge to solid, while in BRepPrimAPI_MakeBox from solid, shell to vertex. From the construction, the BRep data structure in OpenCASCADE also can be called the Winged-Edge data structure.
Key Words. OpenCASCADE, BRep, Box, The Winged-Edge Structure
1. Introduction
OpenCASCADE的Toolit TKPrim中提供了基本图元的创建功能,像Box, Cylinder, Sphere等等。直接使用Package BRepPrimAPI中的功能,可以方便地创建出基本图元,而不用关心其内部的数据结构。
![]()
Figure 1. BRepPrimAPI Package classes
为 了理解ModelingData模块中OpenCASCADE的边界表示法BRep数据结构,决定参考其实现,自己来创建出基本图元,进而理解其中的 BRep数据结构。本文以最简单的长方体Box入手,从点、边到体的创建出一个形状。并将构造的形状在Draw Test Harness中进行显示,且进行布尔运算,来验证构造结果的正确性。
2.Make a Face of the Box
在OpenCASCADE的包BRepPrim中,构造长方体的方式是形状的根结点出发到叶子结点,即从Shell到Face到Wire最后到Vertex,如下图所示:
![]()
Figure 2.1 Data structure of a Shape
为了程序演示的清晰,本文中采用与OpenCASCADE中相反的方式,即先从叶子结点出发,逐步回到根结点,即先构造出顶点、边最后到实体。长方体由六个面构成,所以先从一个面开始来构造。将一个面构造成功后,其他六个面的构造方法就相同了。
构造使用了BRep_Builder,在创建相应的拓朴的同时可以将其相关的几何信息设置进去。如创建顶点Vertex时,可以将点的坐标信息及容差值设置进去,代码如下所示:
BRep_Builder aBuilder; // make vertex of the box.
aBuilder.MakeVertex(aVertices[], aPoints[], Precision::Confusion());
aBuilder.MakeVertex(aVertices[], aPoints[], Precision::Confusion());
aBuilder.MakeVertex(aVertices[], aPoints[], Precision::Confusion());
aBuilder.MakeVertex(aVertices[], aPoints[], Precision::Confusion());
aBuilder.MakeVertex(aVertices[], aPoints[], Precision::Confusion());
aBuilder.MakeVertex(aVertices[], aPoints[], Precision::Confusion());
aBuilder.MakeVertex(aVertices[], aPoints[], Precision::Confusion());
aBuilder.MakeVertex(aVertices[], aPoints[], Precision::Confusion());
创建边的同时,将其边中的三维曲线信息也设置进去,代码如下所示:
// make edges of the box.
aBuilder.MakeEdge(aEdges[], new Geom_Line(aLines[]), Precision::Confusion());
aBuilder.MakeEdge(aEdges[], new Geom_Line(aLines[]), Precision::Confusion());
aBuilder.MakeEdge(aEdges[], new Geom_Line(aLines[]), Precision::Confusion());
aBuilder.MakeEdge(aEdges[], new Geom_Line(aLines[]), Precision::Confusion()); aBuilder.MakeEdge(aEdges[], new Geom_Line(aLines[]), Precision::Confusion());
aBuilder.MakeEdge(aEdges[], new Geom_Line(aLines[]), Precision::Confusion());
aBuilder.MakeEdge(aEdges[], new Geom_Line(aLines[]), Precision::Confusion());
aBuilder.MakeEdge(aEdges[], new Geom_Line(aLines[]), Precision::Confusion()); aBuilder.MakeEdge(aEdges[], new Geom_Line(aLines[]), Precision::Confusion());
aBuilder.MakeEdge(aEdges[], new Geom_Line(aLines[]), Precision::Confusion());
aBuilder.MakeEdge(aEdges[],new Geom_Line(aLines[]),Precision::Confusion());
aBuilder.MakeEdge(aEdges[],new Geom_Line(aLines[]),Precision::Confusion());
创建的边Edge还需要与顶点Vertex关联上,且需要注意顶点的反向,示例代码如下所示:
// set the vertex info of the edges.
// edge 0:
{
TopoDS_Vertex V1 = aVertices[];
TopoDS_Vertex V2 = aVertices[]; V2.Reverse(); aBuilder.Add(aEdges[], V1);
aBuilder.Add(aEdges[], V2); aBuilder.UpdateVertex(V1, ElCLib::Parameter(aLines[], aPoints[]),
aEdges[], Precision::Confusion());
aBuilder.UpdateVertex(V2, ElCLib::Parameter(aLines[], aPoints[]),
aEdges[], Precision::Confusion()); BRepTools::Update(aEdges[]);
}
接着创建Wire,创建Wire时需要注意边的反向,从而构造成一个闭合的Wire,代码如下所示:
// make wires of the box.
aBuilder.MakeWire(aWires[]); // wire 1: bottom
{
TopoDS_Edge E1 = aEdges[];
TopoDS_Edge E2 = aEdges[];
TopoDS_Edge E3 = aEdges[];
TopoDS_Edge E4 = aEdges[]; E3.Reverse();
E4.Reverse(); aBuilder.Add(aWires[], E1);
aBuilder.Add(aWires[], E2);
aBuilder.Add(aWires[], E3);
aBuilder.Add(aWires[], E4); BRepTools::Update(aWires[]);
}
关键是面的创建及面创建后,设置边与面的关联信息,即PCurve的信息。如果没有PCurve的信息,可视化显示就不能正确显示出面,即网格化算法会失败。长方体底面的创建及PCurve设置代码如下所示:
// make faces of the box.
aBuilder.MakeFace(aFaces[],new Geom_Plane(aPlanes[]),Precision::Confusion()); aBuilder.Add(aFaces[], aWires[]); // set bottom pcurve info of between the edge and surface.
{
// pcurve 0:
double u = 0.0;
double v = 0.0;
double du = 0.0;
double dv = 0.0;
gp_Dir DX = aPlanes[].XAxis().Direction();
gp_Dir DY = aPlanes[].YAxis().Direction(); ElSLib::Parameters(aPlanes[], aLines[].Location(), u, v);
du = aLines[].Direction() * DX;
dv = aLines[].Direction() * DY; aBuilder.UpdateEdge(aEdges[], new Geom2d_Line(gp_Lin2d(gp_Pnt2d(u, v),
gp_Dir2d(du, dv))), aFaces[], Precision::Confusion());
// pcurve 1:
ElSLib::Parameters(aPlanes[], aLines[].Location(), u, v);
du = aLines[].Direction() * DX;
dv = aLines[].Direction() * DY; aBuilder.UpdateEdge(aEdges[], new Geom2d_Line(gp_Lin2d(gp_Pnt2d(u, v),
gp_Dir2d(du, dv))), aFaces[], Precision::Confusion());
// pcurve 2:
ElSLib::Parameters(aPlanes[], aLines[].Location(), u, v);
du = aLines[].Direction() * DX;
dv = aLines[].Direction() * DY; aBuilder.UpdateEdge(aEdges[], new Geom2d_Line(gp_Lin2d(gp_Pnt2d(u, v),
gp_Dir2d(du, dv))), aFaces[], Precision::Confusion());
// pcurve 3:
ElSLib::Parameters(aPlanes[], aLines[].Location(), u, v);
du = aLines[].Direction() * DX;
dv = aLines[].Direction() * DY; aBuilder.UpdateEdge(aEdges[], new Geom2d_Line(gp_Lin2d(gp_Pnt2d(u, v),
gp_Dir2d(du, dv))), aFaces[], Precision::Confusion());
}
历经艰辛,最后终于将一个面创建出来了,且可以在Draw Test Harness中显示,如下图所示:
![]()
Figure 2.2 A Face of the Box in Draw Test Harness
如上图所示,在Darw Test Harness中,边的颜色是有讲究的,说明如下:
In Draw Test Harness, shapes are displayed using isoparametric curves. There is color coding for the Edges:
v A red edge is an isolated edge, which belongs to no faces;
v A green edge is a free boundary edge, which belongs to one face;
v A yello edge is shared edge, which belongs to at least two faces;
![]()
Figure 2.3 Color Coding for Edges in Draw Test Harness
如上图所示,红色的边表示此边不属于任何一个面;绿色的边表示此边只属于一个面;黄色的面表示此面至少属于两个面。
![]()
Figure 2.4 Shared Edges of the Box
如上图所示,当创建出长方体的三个面时,侧面与上下两个底面相连的边显示成了黄色。其他边都是绿色。
3.Finish the Box
将长方体的六个面按上述方式创建完毕后,需要验证其正确性。于是将生成的数据导出为Brep格式,并与其他基本体进行布尔运算。
当导出的长方体为Shell时进行布尔运算会得到的也是壳体,如下图所示的结果:
![]()
Figure 3.1 Box Shell Cut a Cylinder
当导出的长方体为Solid时,若面的方式未正确设置,则布尔运算会失败,如下图所示:
![]()
Figure 3.2 Box Solid Cut a Cylinder
如上图所示,长方体与圆柱体的交线都已经计算出来了,但由于面的方向不对,不知道去除哪些面,保留哪些面。
将面的方向正确设置后,导出为Solid,进行布尔运算,结果正确,如下图所示:
![]()
Figure 3.3 Box Cut Cylinder
测试用的Tcl脚本代码如下所示:
#
# Tcl script to test the box BRep data.
# eryar@163.com
# 2014-11-16 21:55
# OpenCASCADE6.8.0
#
pload ALL restore d:/box.brep b pcylinder c 1.5 bop b c
bopcut r vdisplay r
4.Conclusion
通过创建基本图元,从而进一步来理解OpenCASCADE中的边界表示BRep的数据结构。需要注意的事项有:
v 创建边时,需要设置边中几何曲线的范围;
v 创建边时,需要设置正确与边相关顶点的方向;
v 创建环时,需要确保环中边的参数曲线PCurve能在参数空间中闭合;
v 创建面后,需要在边中设置与面相关的几何信息;
v 创建体时,需要所有面的方向正确;
注:
最后发现前不久写的一篇文章有误,说OpenCASCADE的BRep不是翼边结构。其实从边出发是可以找到与点、面相关的信息的。因为
OpenCASCADE中拓朴结构中有包含关系,所以顶点信息已经包含在边中了,直接遍历边即可得到与此边相关的顶点信息。所以,这样看来
OpenCASCADE中的BRep表示法也是翼边的数据结构。
原文如下:
边界表示方式比较。因为一般的书籍上都详细重
点描述了边界表示中以为边为核心的翼边数据结构,所以有人想从这方面来给OpenCASCADE中的Brep表示法来给个说法。结合上面的类图可知,从边
出发并不能访问到与这条边相关的其他信息,如顶点的信息。如果硬是想在这里给个名分,倒是从点出发可以找到边及面的几何信息,所以OpenCASCADE
中的Brep表示法应该更像是以点为基础的表示方法。OpenNURBS中通过ON_BrepTrim,可以访问其他的信息,而ON_BrepTrim与
边ON_BrepEdge的意义有些相似,所以应该是以边为核心的翼边结构了。
5. References
1. OpenCASCADE BRep vs. OpenNURBS Brep. OpenCASCADE BRep vs. OpenNURBS BRep
PDF Version and Source Code: OpenCASCADE Make Primitives-Box
OpenCASCADE Make Primitives-Box的更多相关文章
- OpenCascade Primitives BRep - Box
OpenCascade Primitives BRep - Box eryar@163.com Abstract. BRep is short for Boundary Representation. ...
- OpenCASCADE Make Primitives-Sphere
OpenCASCADE Make Primitives-Sphere eryar@163.com Abstract. The sphere is the simplest topology shape ...
- OpenCascade Primitives BRep - Sphere
OpenCascade Primitives BRep - Sphere eryar@163.com Abstract. BRep is short for Boundary Representati ...
- OpenCascade Primitives BRep-Cone
OpenCascade Primitives BRep-Cone eryar@163.com Abstract. BRep is short for Boundary Representation. ...
- OpenCascade Primitives BRep-Torus
OpenCascade Primitives BRep-Torus eryar@163.com Abstract. BRep is short for Boundary Representation. ...
- OpenCascade Primitives BRep-Cylinder
OpenCascade Primitives BRep-Cylinder eryar@163.com Abstract. BRep is short for Boundary Representati ...
- A Simple OpenCASCADE Qt Demo-occQt
A Simple OpenCASCADE Qt Demo-occQt eryar@163.com Abstract. OpenCASCADE have provided the Qt samples ...
- OpenCASCADE Shape Location
OpenCASCADE Shape Location eryar@163.com Abstract. The TopLoc package of OpenCASCADE gives resources ...
- OpenCASCADE Camera
OpenCASCADE Camera eryar@163.com Abstract. OpenCASCADE introduce a new class Graphic3d_Camera for th ...
随机推荐
- 时代杂志发文:2017 AR/MR将变得比VR更加重要
每到年末都有很多企业或高管分析科技产业明年趋势.近日,时代杂志网页版刊登了2017年科技行业的五大趋势和热点话题的预测.该本作者TimBajarin,是硅谷市场研究公司CreativeStrategi ...
- iPhone/iPad/Android UI尺寸规范 UI尺寸规范,UI图标尺寸,UI界面尺寸,iPhone6尺寸,iPhone6 Plus尺寸,安卓尺寸,iOS尺寸
iPhone/iPad/Android UI尺寸规范 UI尺寸规范,UI图标尺寸,UI界面尺寸,iPhone6尺寸,iPhone6 Plus尺寸,安卓尺寸,iOS尺寸 iPhone界面尺寸 设备 分辨 ...
- NOIP提高模拟题 完全平方数
完全平方数 (number.***(c/cpp/pas),1000ms,128mb) [问题描述] 一个数如果是另一个整数的完全平方,那么我们就称这个数为完全平方数(Pefect Sqaure),也称 ...
- jsoup获取图片示例
import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.Inp ...
- DOS命令详解
DOS命令详解 命令 \? 可以进入命令帮助 1.md命令创建目录. MKDIR [drive:]pathMD [drive:]path 如果命令扩展被启用,MKDIR 会如下改变: 如果需要,MKD ...
- 有关iOS系统中调用相机设备实现二维码扫描功能的注意点(3/3)
今天我们接着聊聊iOS系统实现二维码扫描的其他注意点. 大家还记得前面我们用到的输出数据的类对象吗?AVCaptureMetadataOutput,就是它!如果我们需要实现目前主流APP扫描二维码的功 ...
- linux进程后台运行及输出重定向
本机环境为ubuntu 14.04 以ping www.baidu.com为例: 1.程序的前台运行 ping www.baidu.com 可以看到,屏幕上输出了baidu返回的结果 2.实现程序后台 ...
- 为什么我如此热爱这样一个比赛(转自vici)
为什么我如此的热爱这样一个比赛呢?因为它总能带给我一个目标,让我去努力实现它.因为可以看到胜利的希望,于是不断的去追逐.虽然其中的过程可能是比较艰辛的. 对于天才选手,作为天生的冠军,大概凭借天赋 ...
- toroiseSVN 无法连接服务器,提示unable connect to ……url 参数错误
之前使用的好好的,有天突然提示无法连接repository url,能ping通服务器,就是一直报错,找了很多方法,如: 1.删除缓存及缓存文件 2.删除软件并重新安装 3.关闭windows防火墙 ...
- 拒绝了对对象 'base_config' (数据库 '****',架构 'dbo')的 SELECT 权限
在网上看了很多资料都是空说一谈,都只是说很简单,然后没有说遇到这样的情况具体该怎么做,看到这里都知道是权限问题,其实我们每一个人都知道,又是我觉得我还是要给以后遇到的朋友个解决方法: 这里用到的数据 ...