Topology and Geometry in OpenCascade-Adapters

简介: Topology and Geometry in OpenCascade-Adapters eryar@163.com 摘要Abstract:本文简要介绍了适配器模式(adapter pattern),并结合程序实例对OpenCascade中的拓朴与几何的适配器的使用进行说明。

Topology and Geometry in OpenCascade-Adapters

eryar@163.com

摘要Abstract:本文简要介绍了适配器模式(adapter pattern),并结合程序实例对OpenCascade中的拓朴与几何的适配器的使用进行说明。

关键字Key Words:OpenCascade、BRep、Topology、Geometry、Adapter

一、适配器模式简介 Introduction of Adapter pattern

类对象结构型模式适配器模式(Adapter):

意图(Intent):将一个类的接口转换成客户希望的另外一个接口。Adapter模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作。

别名(Also Known As):包装器Wrapper

动机(Motivation):有时,为复用而设计的工具箱类不能够被复用的原因仅仅是因为它的接口与专业应用领域所需要的接口不匹配。

适用性(Applicability),以下情况使用Adapter模式:

l 你想使用一个已经存在的类,而它的接口不符合你的需求;

l 你想创建一个可以复用的类,该类可以与其他不相关的类或不可预见的类(即那些接口可能不一定兼容的类)协同工作;

l (仅适用于对象Adapter)你想使用一些已经存在的子类,但是不可能对每一个都进行子类化以匹配它们的接口。对象适配器可以适配它的父类接口;

结构(Structure):

类适配器使用多重继承对一个接口与另一个接口进行匹配,如下图所示:

wps_clip_image-1576

Figure 1.1 Class adapter structure

对象适配器依赖于对象组合,如下图所示:

wps_clip_image-9276

Figure 1.2 Object adapter structure

协作(Collaborations):Client在Adapter实例上调用一些操作,接着适配器调用Adaptee的操作实现这个请求。

关于适配器模式(Adapter pattern)更多信息,请参考GoF的经典之作《Design Patterns-Elements of Reuseable Object-Oriented Software》。

二、适配器模式在OpenCascade中的应用

一些OpenCascade的算法可以操作表示曲线的对象,然而他们提供的API接受Adaptor3d_Curve而不接受Geom_Curve。例如,包Extrema(用来计算点、线、面之间的距离)可用来计算几何曲线(Geom_Curve)和拓朴边(TopoDS_Edge)的求交、投影和其他一些算法。其他的例子有计算长度,面积等。这种方法称为适配器模式(Adapter pattern)。

wps_clip_image-3262

Figure 1.3 Adaptor3d_Curve class diagram

从上面的类图可以看出,GeomAdaptor3d_Curve是Adaptor3d_Curve的子类,该类用来适配Geom_Curve类型,BRepAdaptor_Curve用于适配TopoDS_Edge类型。BRepAdaptor_CompCurve用于适配TopoDS_Wire。对于二维曲线和曲面也有类似功能的类。通过适配器使不同的曲线(几何曲线和拓朴边)在一起工作,如下代码所示,计算几何曲线和拓朴边长度的方式统一了:

 1  /*
 2  *    Copyright (c) 2013 eryar All Rights Reserved.
 3  *
 4  *        File    : Main.cpp
 5  *        Author  : eryar@163.com
 6  *        Date    : 2013-09-27
 7  *        Version : 1.0v
 8  *
 9  *    Description : GeomAdaptor: provides an interface between the services provided by any curve.
10  *                  BRepAdaptor: provides classes to access the geometry of the BRep models.
11  *                  
12  */
13 
14  #define  WNT
15  #include  < gp_Circ.hxx >
16  #include  < Geom_Circle.hxx >
17  #include  < GeomAdaptor_Curve.hxx >
18 
19  #include  < TopoDS_Edge.hxx >
20  #include  < BRepBuilderAPI_MakeEdge.hxx >
21  #include  < BRepAdaptor_Curve.hxx >
22 
23  #include  < GCPnts_AbscissaPoint.hxx >
24 
25  #pragma comment(lib,  " TKernel.lib " )
26  #pragma comment(lib,  " TKMath.lib " )
27  #pragma comment(lib,  " TKG3d.lib " )
28  #pragma comment(lib,  " TKBRep.lib " )
29  #pragma comment(lib,  " TKGeomBase.lib " )
30  #pragma comment(lib,  " TKTopAlgo.lib " )
31 
32  int  main( void )
33  {
34      Handle_Geom_Curve aCurve  =   new  Geom_Circle(gp::XOY(),  1.0 );
35      Standard_Real dCurveLength  =  GCPnts_AbscissaPoint::Length(GeomAdaptor_Curve(aCurve));
36 
37      TopoDS_Edge anEdge  =  BRepBuilderAPI_MakeEdge(gp_Circ(gp::XOY(),  1.0 ));
38      Standard_Real dEdgeLength  =  GCPnts_AbscissaPoint::Length(BRepAdaptor_Curve(anEdge));
39 
40      std::cout  <<   " Circle curve length:  "   <<  dCurveLength  <<  std::endl;
41      std::cout  <<   " Circle edge length:  "   <<  dEdgeLength  <<  std::endl;
42 
43       return   0 ;
44  }

程序结果如下所示:

1  Circle curve length:  6.28319  
2  Circle edge length:  6.28319  
3  Press any key to  continue  . . . 

 

三、结论 Conclusion

应用适配器模式使OpenCascade中接口不兼容的类如几何曲线(Geom_Curve)与拓朴边(TopoDS_Edge)可以在一起工作了,如求交计算、投影计算、长度计算等等。

四、参考资料 Bibliography

1. GoF, Design Patterns-Elements of Reuseable Object-Oriented Software

2. Roman Lygin, OpenCascade notes, opencascade.blogspot.com

 

目录
相关文章
|
6月前
265Echarts - GL 矢量场图(Flow on the cartesian)
265Echarts - GL 矢量场图(Flow on the cartesian)
23 0
|
C++ 算法
OpenCASCADE BRep Projection
OpenCASCADE BRep Projection eryar@163.com 一网友发邮件问我下图所示的效果如何在OpenCASCADE中实现,我的想法是先构造出螺旋线,再将螺旋线投影到面上。
1675 0
|
C++ Java Spring
Make Helix Curve in OpenCASCADE
Make Helix Curve in OpenCASCADE eryar@163.com Abstract. OpenCASCADE does not provide helix curve directly, but you can build a helix curve by the pcurve of a surface(curve on surface).
1550 0
|
人工智能
OpenCASCADE General Transformation
OpenCASCADE General Transformation eryar@163.com Abstract. OpenCASCADE provides a general transformation class: gp_GTrsf.
1264 0
OpenCASCADE Make Primitives-Sphere
OpenCASCADE Make Primitives-Sphere eryar@163.com Abstract. The sphere is the simplest topology shape of the BRep structure.
1131 0
|
C语言 Windows 开发工具
OpenCASCADE Conic to BSpline Curves-Parabola
OpenCASCADE Conic to BSpline Curves-Parabola eryar@163.com Abstract. Rational Bezier Curve can represent conic curves such as circle, ellipse, hyperbola, .
1007 0
OpenCASCADE Gauss Integration
OpenCASCADE Gauss Integration eryar@163.com Abstract. Numerical integration is the approximate computation of an integral using numerical techniques.
1281 0
OpenCascade Primitives BRep - Sphere
OpenCascade Primitives BRep - Sphere eryar@163.com Abstract. BRep is short for Boundary Representation.
1086 0
|
算法 openCL 异构计算
OpenCascade Ray Tracing Rendering
OpenCascade Ray Tracing Rendering eryar@163.com 摘要Abstract:OpenCascade6.7.0中引入了光线跟踪算法的实现。使用光线跟踪算法可实现高质量的渲染效果,且可以使用GPU提升渲染效率。
1381 0
|
算法 图形学 C++
Topology Shapes of OpenCascade BRep
Topology Shapes of OpenCascade BRep eryar@163.com 摘要Abstract:通过对OpenCascade中的BRep数据的读写,理解边界表示法的概念及实现。
1826 0

热门文章

最新文章