Package gp in the OpenCASCADE

eryar@163.com China

一、简介 Introduction to Package gp

gp是几何处理程序包(Geometric Processor package),简称gp。包gp提供以下功能:

  • 代数计算;如坐标计算、矩阵计算;
  • 基本解析几何元素;如变换、点、矢量、线、面、轴、二次曲线和初等曲面;

这些实体同时在二维和三维空间中定义,且包中的类都是非持续的(non-persistent),即这些类的实例都是以值的方式处理而不是引用。当复制这种对象时,是对象本体。改变一个实例不会影响到其他的实例。

可用的几何实体如下所示:

  1. 2D&3D Cartesian coordinates(x,y,z); 二维&三维笛卡尔坐标;
  2. Matrices; 矩阵;
  3. Cartesian points; 笛卡尔坐标点;
  4. Vector; 矢量;
  5. Direction; 方向;
  6. Axis; 轴;
  7. Line; 直线;
  8. Circle; 圆;
  9. Ellipse; 椭圆;
  10. Hyperbola; 双曲线;
  11. Parabola; 抛物线;
  12. Plane; 面;
  13. Infinite cylindrical surface; 柱面;
  14. Spherical surface; 球面;
  15. Toroidal surface; 环面;
  16. Conical surface; 锥面;
二、几何元素的集合 Collections of Primitive Geometric Types

创建几何对象之前,根据你是将几何对象用于二维还是三维来确定。若你需要一个几何对象集而不是单一的几何对象,即用来处理一类几何元素,包TColgp就是提供这种功能的。

Package TColgp提供类如:XY, XYZ, Pnt, Pnt2d, Vec, Vec2d, Lin, Lin2D, Circ, Circ2dTCollection的实例。包中的类简单列举如下:

  • TColgp_Array1OfCirc;
  • TColgp_Array1OfDir;
  • TColgp_Array1OfPnt;
  • TColgp_Array1OfVec;
  • TColgp_Array2OfCirc2d;
  • TColgp_Array2OfPnt;
  • TColgp_HArray1OfCirc2d;
  • TColgp_HArray2OfDir;
  • TColgp_HSequenceOfDir;
  • TColgp_SequenceOfDir;
  • TColgp_SequenceOfPnt;
  • TColgp_SequenceOfXYZ;

个人意见,若使用标准C++的容器类(The STL Template Container),就不需要创建这么多类了。

三、基本几何库 Basic Geometric Libraries

有几个库提供了曲线和曲面的基本计算功能。若要处理由包gp创建的几何对象,初等曲线曲面的有用算法库在包:ElCLibElSLib中。包Precision提供两个数字比较的功能。

  • Package ElCLib; ElCLib代表:Elementary Curves Library. 提供初等曲线曲面的基本几何计算功能;
  • Package ElSLib; ElSLib代表:Elementary Surfaces Library. 提供初等曲面的基本几何计算。
  • Package Bnd;提供二维和三维空间中几何元素包围盒的计算功能;
  • Package Precision; 由于浮点数在计算机内实际上是一个近似表示,在手工计算看来为正确的结果,在计算机中运算未必得出正确的结果。所以,我们得到一个重要的经验:使用浮点数进行相等(==)和不等(!=)比较的操作通常是有问题的。浮点数的相等比较,一般总是使用两者相减的值是否落在0的邻域中来判断。这就是邻域比较技术。在OpenCASCADE中专门提供包Precision来处理两个数值的比较问题。
四、代码示例 Code Sample
//------------------------------------------------------------------------------
//    Copyright (c) 2012 eryar All Rights Reserved.
//
//        File    : Main.cpp
//        Author  : eryar@163.com
//        Date    : 2012-6-23 21:30
//        Version : 1.0v
//
//    Description : Test primitive Geometric Types in OpenCASCADE.
//
//      The Geometric Processor package, called gp.
//
//      The pg package offers classes for both 2D and 3D objects which
//      are handled by value rather than by reference. When this sort of object
//      is copied, it is copied entirely. Changes in one instance will not be 
//      reflected in another.
//
//==============================================================================
 
// Use Toolkit TKernel.
#pragma comment(lib,"TKernel.lib")
// Use Toolkit TKMath.
#pragma comment(lib, "TKMath.lib")
 
#include <gp.hxx>
#include <gp_Pnt.hxx>
#include <gp_Trsf.hxx>
#include <Precision.hxx>
 
void DumpPoint(const gp_Pnt& p);
 
int main(int argc, char* argv[])
{
    gp_Pnt  aPoint(0, 0, 0);
 
    // 1. Translate a point in a direction.
    // The direction determined by a gp_Vec or two gp_Pnt.
    cout<<"Before translated:";
    DumpPoint(aPoint);
 
    aPoint.Translate(gp_Pnt(2, 2, 3), gp_Pnt(10, 10, 0));
 
    cout<<"After translated:";
    DumpPoint(aPoint);
 
    // 2. Rotate a point.
    // Rotate a point by an axis and the rotate angle.
    cout<<"Before rotated:";
    DumpPoint(aPoint);
 
    // Roate 45 degree about Z axis.
    // Positive angle value will be rotated counterclockwise.
    aPoint.Rotate(gp::OZ(), PI/4);
    
    cout<<"After rotated 45 degree about Z axis:";
    DumpPoint(aPoint);
 
    // 2.1 Test Package Precision.
    if (aPoint.X() < Precision::Confusion() && aPoint.X() > -Precision::Confusion())
    {
        cout<<"Point X value:"<<aPoint.X()<<endl;
        cout<<"Precision::Confusion() value:"<<Precision::Confusion()<<endl;
    }
 
    aPoint.Rotate(gp::OZ(), PI/4);
    cout<<"After rotate 45 degree about Z axis:";
    DumpPoint(aPoint);
 
    // 3. Transform a point by gp_Trsf.
    gp_Trsf transform;
    transform.SetMirror(gp::OX());
 
    cout<<"Before gp_Trsf:";
    DumpPoint(aPoint);
 
    aPoint.Transform(transform);
 
    cout<<"After gp_Trsf:";
    DumpPoint(aPoint);
 
    // 4. Mirror a point.
    // 4.1 Performs the symmetrical transformation of
    // a point with respect to an axis placement which
    // is the axis of the symmetry.
    cout<<"Before mirrored with a symmetric axis:";
    DumpPoint(aPoint);
 
    aPoint.Mirror(gp::OY());
 
    cout<<"After mirrored with a symmetric axis:";
    DumpPoint(aPoint);
 
    // 4.2 Performs the symmetrical transformation of
    // a point with respect to a plane.
    cout<<"Before mirrored with a symmetric plane:";
    DumpPoint(aPoint);
 
    aPoint.Mirror(gp::XOY());
 
    cout<<"After mirrored with a symmetric plane";
    DumpPoint(aPoint);
 
    // 5. Scale a point.
    aPoint.SetCoord(1, 2, 1);
    cout<<"Before Scaled:";
    DumpPoint(aPoint);
 
    /*
    // Scale point source code...
    inline void gp_Pnt::Scale (const gp_Pnt& P,
    const Standard_Real S)
    {
    gp_XYZ XYZ = P.coord;
    XYZ.Multiply (1.0 - S);
    coord.Multiply (S);
    coord.Add      (XYZ);
    }
    */
 
    aPoint.Scale(gp_Pnt(1, 2, 2), 2);
 
    cout<<"After Scaled:";
    DumpPoint(aPoint);
 
    return 0;
}
 
/**
* Description: Dump point information.
*/
void DumpPoint( const gp_Pnt& p )
{
    cout<<"("<<p.X()<<","<<p.Y()<<","<<p.Z()<<")"<<endl;
}

输出结果如下:

   1:  Before translated:(0,0,0)
   2:  After translated:(8,8,-3)
   3:  Before rotated:(8,8,-3)
   4:  After rotated 45 degree about Z axis:(8.88178e-016,11.3137,-3)
   5:  Point X value:8.88178e-016
   6:  Precision::Confusion() value:1e-007
   7:  After rotate 45 degree about Z axis:(-8,8,-3)
   8:  Before gp_Trsf:(-8,8,-3)
   9:  After gp_Trsf:(-8,-8,3)
  10:  Before mirrored with a symmetric axis:(-8,-8,3)
  11:  After mirrored with a symmetric axis:(8,-8,-3)
  12:  Before mirrored with a symmetric plane:(8,-8,-3)
  13:  After mirrored with a symmetric plane(8,-8,3)
  14:  Before Scaled:(1,2,1)
  15:  After Scaled:(1,2,0)
  16:  Press any key to continue . . .
五、结论

gp提供了基本的几何元素表示及初等解析几何计算功能。对于几何元素的集合也有自己的类库。对于两个数值的比较采用了邻域比较技术。

Package gp in the OpenCASCADE的更多相关文章

  1. TKmath Package gp数据类型

    点,向量,方向 二维:gp_Pnt2d, gp_Vec2d, gp_Dir2d:它们的内部都存储 gp_XY 三维:gp_Pnt, gp_Vec, gp_Dir:它们的内部都存储 gp_XYZ 轴向与 ...

  2. OpenCASCADE 包说明

    转载地址:http://www.cppblog.com/eryar/archive/2012/06/30/180916.html 一.简介 Introduction to Package gp gp是 ...

  3. OpenCASCADE PCurve of Topological Face

    OpenCASCADE PCurve of Topological Face eryar@163.com Abstract. OpenCASCADE provides a class BRepBuil ...

  4. OpenCASCADE Root-Finding Algorithm

    OpenCASCADE Root-Finding Algorithm eryar@163.com Abstract. A root-finding algorithm is a numerical m ...

  5. Delaunay Triangulation in OpenCascade

    Delaunay Triangulation in OpenCascade eryar@163.com 摘要:本文简要介绍了Delaunay三角剖分的基础理论,并使用OpenCascade的三角剖分算 ...

  6. OpenCASCADE Shape Location

    OpenCASCADE Shape Location eryar@163.com Abstract. The TopLoc package of OpenCASCADE gives resources ...

  7. OpenCASCADE Interpolation - Lagrange

    OpenCASCADE Interpolation - Lagrange eryar@163.com Abstract. Power basis polynomial is the most simp ...

  8. Make Helix Curve in OpenCASCADE

    Make Helix Curve in OpenCASCADE eryar@163.com Abstract. OpenCASCADE does not provide helix curve dir ...

  9. Create views of OpenCASCADE objects in the Debugger

    Create views of OpenCASCADE objects in the Debugger eryar@163.com Abstract. The Visual Studio Natvis ...

随机推荐

  1. 『TCP/IP详解——卷一:协议』读书笔记——13

    2013-08-24 16:03:39 4.6 ARP代理 ARP代理(Proxy ARP):如果ARP请求是从一个网络的主机发往另一个网络上的主机,那么连接这两个网络的路由器就可以回答该请求.这样可 ...

  2. IOS Alcatraz Xcode6.4安装指南

    1.Alcatraz Alcatraz是Xcode上的插件管理器,用过notepad++应该印象深刻,近来在一部新机器 按以前的安装方法安装老是安装不成功.特意查找了下资料,最后安装成功. 2.安装过 ...

  3. Introduction ch3

    [1] Don’t reinvent the wheel; use libraries.[2] Don’t believe in magic; understand what your librari ...

  4. 一个字体引发的bug

    delphi 7 中默认字体样式为‘MS Sans Serif’,一般情况下子级控件会继承父级一些属性,其中包括字体(包括字体大小,字体样式,颜色等)属性.如果动态创建控件且需要修改字体颜色或者大小时 ...

  5. java和android及IOS对接RSA加密经验

    1.网上找的java生成RSA密钥对的例子,产生的字附串实际上是hax后和密钥串 你可以将他们当成静态字附串存在java代码里 2.android和java可以代码复用,IOS对接比较麻烦 3.IOS ...

  6. 二进制求最大公约数&&输出二进制

    Divided Land Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Tot ...

  7. Blend 2015 教程 (三) 模板

    前一篇讲述了一些基本样式的修改方法,并搭建了Style层的基本框架,本篇将进一步修改ListBox的样式. 1. 首先选中ListBox控件,在美工板导航栏中点击ListBox,选择 编辑其他模板-编 ...

  8. MySQL4:存储过程和函数

    什么是存储过程 简单说,存储过程就是一条或多条SQL语句的集合,可视为批文件,但是起作用不仅限于批处理.本文主要讲解如何创建存储过程和存储函数以及变量的使用,如何调用.查看.修改.删除存储过程和存储函 ...

  9. Java IO3:字节流

    流类 Java的流式输入/输出是建立在四个抽象类的基础上的:InputStream.OutputStream.Reader.Writer.它们用来创建具体的流式子类.尽管程序通过具体子类执行输入/输出 ...

  10. Javascript aop(面向切面编程)之around(环绕)

    Aop又叫面向切面编程,其中“通知”是切面的具体实现,分为before(前置通知).after(后置通知).around(环绕通知),用过spring的同学肯定对它非常熟悉,而在js中,AOP是一个被 ...