OpenCASCADE Make Primitives-Sphere

OpenCASCADE Make Primitives-Sphere

eryar@163.com

Abstract. The sphere is the simplest topology shape of the BRep structure. But there are several import concept of the sphere edges, such as degenerated edge and seam edge. So construct a sphere by code, you will learn these.

Key Words. OpenCASCADE, Sphere, BRep

1. Introduction

球体(sphere)是边界表示法(BRep)中最简单的一个拓朴形状了,因为它直接由球面来构造。但是其中包含了一些重要的概念,如退化边(degenerated edge)、衔接边(seam edge)。由代码手工来构造一个球体,可以学习这些概念。首先要知道OpenCASCADE中球面的参数方程:

在Draw Test Harness中显示如下图所示:

Figure 1.1 Sphere in Draw Test Harness

由球面的参数方程可知,当参数u=0或2PI时,对应球面上的点就是上图所示的绿线,实际上是由两个线重合在一起了。

当参数v=-PI/2或PI/2时,对应球面上两个极点,因为球面的两个极点处法向为零,而球面在两个极点处的法向是存在的,所以这样的点即为边退化而成,称为退化边。

三维曲线圆的参数方程如下所示:

通过代码从点开始来构造一个球体,从而来加深理解OpenCASCADE的BRep表示法。

2.Make the Sphere

2.1 Make Vertex

从顶点开始来创建球体。因为球体就是一个球面,为了得到Face的Wire,需要构造一个闭合的区域。这里选择两个极点作为球体的顶点。创建球体的两个极点,程序代码如下所示:

// make the north and south poles.
aBuilder.MakeVertex(aNorthPole, aPoints[0], Precision::Confusion());
aBuilder.MakeVertex(aSouthPole, aPoints[1], Precision::Confusion());

2.2 Make Edge

为了得到闭合的Wire,需要四条边,其中在球面两个极点处的两条退化边,还有连接两个极点的重合的衔接边。创建边的代码如下所示:

// make the seam edge with the 3D geometry curve.
aBuilder.MakeEdge(aSeamEdge, new Geom_Circle(aCircle), Precision::Confusion());

// there is no 3D geometry curve in the degenerated edge.
aBuilder.MakeEdge(aNorthEdge);
aBuilder.Degenerated(aNorthEdge, Standard_True);

// there is no 3D geometry curve in the degenerated edge.
aBuilder.MakeEdge(aSouthEdge);
aBuilder.Degenerated(aSouthEdge, Standard_True);

// set the vertex info of the seam edges.
{
    TopoDS_Vertex V1 = aNorthPole;
    TopoDS_Vertex V2 = aSouthPole;

    V1.Reverse();

    aBuilder.Add(aSeamEdge, V1);
    aBuilder.Add(aSeamEdge, V2);

    aBuilder.UpdateVertex(V1, ElCLib::Parameter(aCircle, aPoints[0]), aSeamEdge, Precision::Confusion());
        
  aBuilder.UpdateVertex(V2, ElCLib::Parameter(aCircle, aPoints[1]), aSeamEdge, Precision::Confusion());

    BRepTools::Update(aSeamEdge);
}

// set the vertex info of the north degenerated edge.
{
    TopoDS_Vertex V1 = aNorthPole;
    TopoDS_Vertex V2 = aNorthPole;

    V2.Reverse();

    aBuilder.Add(aNorthEdge, V1);
    aBuilder.Add(aNorthEdge, V2);

    BRepTools::Update(aNorthEdge);
}

// set the vertex info of the south degenerated edge.
{
    TopoDS_Vertex V1 = aSouthPole;
    TopoDS_Vertex V2 = aSouthPole;

    V2.Reverse();

    aBuilder.Add(aSouthEdge, V1);
    aBuilder.Add(aSouthEdge, V2);

    BRepTools::Update(aSouthEdge);
}

由上述代码可知,衔接边中包含了几何信息:三维曲线圆;退化边中未包含几何信息,但将其退化边属性设置为true。之后将边上顶点在曲线上对应的参数值设置到边中,退化边不需要设置。

2.3 Make Wire

创建Wire需要确保组成Wire的边要闭合。程序代码如下所示:

// make wire.
aBuilder.MakeWire(aWire);

// add edges to the wire.
{
    TopoDS_Edge E1 = aNorthEdge;
    TopoDS_Edge E2 = aSeamEdge;
    TopoDS_Edge E3 = aSouthEdge;
    TopoDS_Edge E4 = aSeamEdge;

    E1.Reverse();
    E4.Reverse();

    aBuilder.Add(aWire, E1);
    aBuilder.Add(aWire, E2);
    aBuilder.Add(aWire, E3);
    aBuilder.Add(aWire, E4);

    BRepTools::Update(aWire);
}

2.4 Make Face

创建面后,将边与面关联起来至关重要,即PCurve的设置。程序代码如下所示:

// make face.
aBuilder.MakeFace(aFace, new Geom_SphericalSurface(aSphere), Precision::Confusion());

// set the pcurve info between edge and face.
{
    aBuilder.Range(aNorthEdge, 0.0, 2 * M_PI);
    aBuilder.UpdateEdge(aNorthEdge, new Geom2d_Line(aLines[0]), aFace, Precision::Confusion());

    aBuilder.Range(aSeamEdge, 1.5 * M_PI, 2.5 * M_PI);
    aBuilder.UpdateEdge(aSeamEdge, new Geom2d_Line(aLines[1]), new Geom2d_Line(aLines[2]), aFace, Precision::Confusion());
    aBuilder.Continuity(aSeamEdge, aFace, aFace, GeomAbs_CN);
        
    aBuilder.Range(aSouthEdge, 0.0, 2 * M_PI);
    aBuilder.UpdateEdge(aSouthEdge, new Geom2d_Line(aLines[3]), aFace, Precision::Confusion());

    BRepTools::Update(aFace);
}

由上述代码可知,球面中包含了一个几何的曲面。创建球面后,将相关的边与面关联起来。参数曲线PCurve的范围Range在球面的参数空间中应该闭合。其中两个退化边的范围都是从0到2PI,而衔接边的范围设置不当,会产生不正确的结果,如下图所示:

Figure 2.4.1 Seam Edge Range[-PI/2, PI/2]

线框模式显示正常,但是不能切换到渲染模式,即不能显示出面。结合其PCurve的范围可以发现组成Wire的边的PCurve不能闭合。

当Seam边的三维曲线方向不当时,会不与球面的Seam重合,如下图所示:

Figure 2.4.2 Circle in Seam Edge Range [-PI/2, PI/2]

Figure 2.4.3 Wrong Seam Edge Geometry Curve

Figure 2.4.4 Wrong Seam Edge Geometry Curve

3. Test the Sphere

正确生成球体后导出为brep文件即可以在Draw Test Harness中来显示及进行一些操作来验证结果的正确性。在Draw Test Harness中打开brep文件并显示球体如下图所示:

Figure 3.1 Show the Sphere from file in Draw Test Harness

将其与一个长方体进行布尔运算,效果如下图所示:

Figure 3.2 Spher and a Box

Figure 3.3 Sphere cut a Box

由上图可知,球体与长方体布尔运算结果正确。

4. Conclusion

通过生成一个球体,示例了特殊边的构造,如退化边和衔接边。需要注意的事项还是组成Wire的所有边中的PCurve必须在面的参数空间中闭合。由PCurve可知,球面对应的参数空间不是几何曲面的范围,而是在v方向上偏移了2PI。

5. References

1. OpenCascade Primitives BRep - Sphere,  

http://www.cppblog.com/eryar/archive/2014/03/22/206279.html

2. PCurve - Curve on Surface, 

http://www.cppblog.com/eryar/archive/2014/03/15/206180.html

3. Topology and Geometry in OpenCascade-Face, 

http://www.cppblog.com/eryar/archive/2013/09/12/203199.html

 

PDF Version and Source code: OpenCASCADE Make Primitives - Sphere

时间: 2024-11-01 00:27:44

OpenCASCADE Make Primitives-Sphere的相关文章

常见3D物理引擎概述

今天帮朋友找3D物理引擎的资料,以前也看过那么多了,一直没有总结过,今天顺便整理一下. 1.  Havok: 老牌的君王,支持功能如下: http://www.havok.com ·         Collision Detection - including Continuous Physics ·         MOPP Technology - for compact representation of large collision meshes ·         Dynamics

OpenCascade Primitives BRep - Sphere

OpenCascade Primitives BRep - Sphere eryar@163.com Abstract. BRep is short for Boundary Representation. Boundary Representation gives a complete description of an object by associating topological and geometric information for solid modeling. In this

OpenCascade Primitives BRep-Torus

OpenCascade Primitives BRep-Torus eryar@163.com Abstract. BRep is short for Boundary Representation. Boundary Representation gives a complete description of an object by associating topological and geometric information for solid modeling. In this ca

OpenCascade Primitives BRep-Cylinder

OpenCascade Primitives BRep-Cylinder eryar@163.com Abstract. BRep is short for Boundary Representation. Boundary Representation gives a complete description of an object by associating topological and geometric information for solid modeling. In this

OpenCascade Primitives BRep - Box

OpenCascade Primitives BRep - Box eryar@163.com Abstract. BRep is short for Boundary Representation. Boundary Representation gives a complete description of an object by associating topological and geometric information for solid modeling. In this ca

OpenCASCADE Outline

OpenCASCADE Outline eryar@163.com      有网友反映blog中关于OpenCASCADE的文章比较杂乱,不太好找,最好能提供一个大纲,这样方便查找.于是决定将这些学习时写的文章整理下,方便对OpenCASCADE的学习理解.其实在http://www.cnblogs.com/opencascade中,已经将文章按目录重新发表了一遍.可以按OpenCASCADE的模块的顺序来学习,也可以挑选自己感兴趣的部分来学习.      由于本人水平所限,文中的错误不妥之处

A Simple OpenCASCADE Qt Demo-occQt

A Simple OpenCASCADE Qt Demo-occQt eryar@163.com Abstract. OpenCASCADE have provided the Qt samples in the samples directory, but they are a little complicated. So I decide write a simple OpenCASCADE Qt demo for the OpenCASCADE beginners.  Key Words.

Qt with OpenCascade

Qt with OpenCascade eryar@163.com 摘要Abstract:详细介绍了如何在Qt中使用OpenCascade. 关键字Key Words:Qt.OpenCascade 一.引言 Introduction 1.1 Overview of Qt Qt是1991年奇趣科技开发的一个跨平台的C++图形用户界面应用程序框架.它提供给应用程序开发者建立艺术级的图形用户界面所需的所有功能.Qt很容易扩展,并且允许真正地组件编程.基本上,Qt同X Window上的Motif,Ope

OpenCascade Shape Representation in OpenSceneGraph

OpenCascade Shape Representation in OpenSceneGraph eryar@163.com 摘要Abstract:本文通过程序实例,将OpenCascade中的拓朴数据(边.面)离散化后在OpenSceneGraph中进行显示.有了这些离散数据,就可以不用OpenCascade的显示模块了,可以使用其他显示引擎对形状进行显示.即若要线框模式显示形状时,就绘制离散形状拓朴边后得到的多段线:若要实体渲染模式显示形状时,就绘制离散形状拓朴面得到的三角网格.理解这些