一.废话

在OCC中如果要实现一个拓扑(TopoDS_Shape)的变换(平移,(点,轴,面)镜像,旋转,缩放,移位,形状),那么gp_trsf,gp_GTrsf是一个很好的媒介。深入理解其中的含义,可以组合起来使用,实现复杂的拓扑变换功能,要想熟练使用,必须在实践中体会

在此使用到的几何知识可以参考:几何变换之仿射变换

在OpenCaseCade6.8.0源代码中有介绍:

gp_trsf(平移,(点,轴,面)镜像,旋转,缩放,移位)

//! Geometric transformation on a shape.
//! The transformation to be applied is defined as a
//! gp_Trsf transformation, i.e. a transformation which does
//! not modify the underlying geometry of shapes.
//! The transformation is applied to:
//! -   all curves which support edges of a shape, and
//! -   all surfaces which support its faces.
//! A Transform object provides a framework for:
//! -   defining the geometric transformation to be applied,
//! -   implementing the transformation algorithm, and
//! -   consulting the results.

谷歌翻译:

在3D空间中定义非持久变换。 实现了以下转换:。 平移,旋转,缩放。 关于点,线,平面的对称性。 复杂的转换可以通过使用矩阵“乘”方法组合先前的基本转换来获得。 转换可以表示如下:
//! V1 V2 V3         T          XYZ      XYZ
//! | a11 a12 a13 a14 |     | x |        | x'|
//! | a21 a22 a23 a24 |     | y |        | y'|
//! | a31 a32 a33 a34 |     | z |   =   | z'|
//! | 0 0 0 1 |                     | 1 |        | 1 |
//! 其中{V1,V2,V3}定义转换的矢量部分,T定义转换的平移部分。 这种转换永远不会改变对象的性质。

gp_GTrsf(形状变换)

//! Defines a non-persistent transformation in 3D space.
//! This transformation is a general transformation.
//! It can be a Trsf from gp, an affinity, or you can define
//! your own transformation giving the matrix of transformation.
//!
//! With a Gtrsf you can transform only a triplet of coordinates
//! XYZ. It is not possible to transform other geometric objects
//! because these transformations can change the nature of non-
//! elementary geometric objects.
//! The transformation GTrsf can be represented as follow :
//!
//! V1   V2   V3       T          XYZ      XYZ
//! | a11  a12  a13   a14 |    | x |       | x'|
//! | a21  a22  a23   a24 |    | y |       | y'|
//! | a31  a32  a33   a34 |    | z |   =  | z'|
//! |  0    0    0     1  |            | 1 |       | 1 |
//!
//! where {V1, V2, V3} define the vectorial part of the
//! transformation and T defines the translation part of the
//! transformation.
//! Warning
//! A GTrsf transformation is only applicable to
//! coordinates. Be careful if you apply such a
//! transformation to all points of a geometric object, as
//! this can change the nature of the object and thus
//! render it incoherent!
//! Typically, a circle is transformed into an ellipse by an
//! affinity transformation. To avoid modifying the nature of
//! an object, use a gp_Trsf transformation instead, as
//! objects of this class respect the nature of geometric objects.

谷歌翻译:

在3D空间中定义非持久变换。此转换是一般转换。它可以是来自gp的Trsf,相似性,也可以定义自己的转换以提供转换矩阵。使用Gtrsf,您只能变换坐标XYZ的三元组。无法变换其他几何对象,因为这些变换可以改变非基本几何对象的性质。转换GTrsf可以表示为:
//! V1 V2 V3         T           XYZ    XYZ
//! | a11 a12 a13 a14 |      | x |      | x'|
//! | a21 a22 a23 a24 |      | y |      | y'|
//! | a31 a32 a33 a34 |      | z | =   | z'|
//! | 0 0 0 1 |                      | 1 |      | 1 |
//!
 其中{V1,V2,V3}定义转换的矢量部分,T定义转换的平移部分。
 警告
 GTrsf转换仅适用于坐标。如果将这样的变换应用于几何对象的所有点,请小心,因为这会改变对象的性质,从而使其变得不连贯!
通常,通过亲和力转换将圆转换为椭圆。为避免修改对象的性质,请改用gp_Trsf转换,因为此类的对象尊重几何对象的性质。

下面介绍参考自网络资料,稍有改动,Occ6.8.0版,其它版本可能会有稍许变动。

二.拓扑变换的基本描述

1.BRepBuilderAPI_Transform

(类,Occ标准头文件BRepBuilderAPI_Transform.hxx)

(1)    功能说明:拓扑变换

此对象与gp_Trsf相关联进行变换

(2)    构造函数:

BRepBuilderAPI_Transform(const gp_Trsf& T);BRepBuilderAPI_Transform(const TopoDS_Shape& S, const gp_Trsf& T, const Standard_Boolean Copy = Standard_False);

(3)    参数说明:

T:要进行的变换

S:进行变换的拓扑图形

Copy:是否用副本进行变换

(4)    备注:

Perform是该对象的一个方法。

BRepBuilderAPI_Transform(gp_Trsf T) 与public void Perform(TopoDS_Shape S, bool Copy)
相等于
BRepBuilderAPI_Transform(TopoDS_Shape S, gp_Trsf T, bool Copy)。

(5)    实例:

例1:点对称

OCC源码:

Makes the transformation into a symmetrical transformation.//! P is the center of the symmetry.void SetMirror (const gp_Pnt& P) ;

使用示例:

TopoDS_Shape S;gp_Trsf theTransformation = new gp_Trsf();gp_Pnt PntCenterOfTheTransformation = new gp_Pnt(110, 60, 60);theTransformation.SetMirror(PntCenterOfTheTransformation);//点对称镜像BRepBuilderAPI_Transform myBRepTransformation =new BRepBuilderAPI_Transform(S,theTransformation, false);TopoDS_Shape S2 = myBRepTransformation.Shape();  //获得通过镜像转换后的新的拓扑

例2:轴对称

OCC源码:

//! Makes the transformation into a symmetrical transformation.
//! A1 is the center of the axial symmetry.
Standard_EXPORT   void SetMirror (const gp_Ax1& A1) ;

使用实例:

TopoDS_Shape S ;gp_Trsf theTransformation = new gp_Trsf();gp_Ax1 axe = new gp_Ax1(new gp_Pnt(110, 60, 60), new gp_Dir(0.0, 1.0, 0.0));                   theTransformation.SetMirror(axe);//镜像BRepBuilderAPI_Transform myBRepTransformation =new BRepBuilderAPI_Transform(S, theTransformation, false);TopoDS_Shape S2 = myBRepTransformation.Shape(); //获取通过轴对称转换的新的拓扑

例3:面对称

OCC源代码:

//! Makes the transformation into a symmetrical transformation.
//! A2 is the center of the planar symmetry
//! and defines the plane of symmetry by its origin, "X
//! Direction" and "Y Direction".
Standard_EXPORT   void SetMirror (const gp_Ax2& A2) ;

使用示例:

TopoDS_Shape S = new BRepPrimAPI_MakeWedge(60.0, 100.0, 80.0, 20.0).Shape();        gp_Trsf theTransformation = new OCgp_Trsf();gp_Ax2 axe2 = new gp_Ax2(new gp_Pnt(0, 0, 0), new gp_Dir(1, 0, 0));theTransformation.SetMirror(axe2);//镜像BRepBuilderAPI_Transform myBRepTransformation =new BRepBuilderAPI_Transform(S, theTransformation, false);TopoDS_Shape S2 = myBRepTransformation.Shape();  //获取通过面对称转换的新的拓扑

关于面对称,需要说明一下:

gp_Ax1(3D空间中的一个轴)

gp_Ax2(右手坐标系)

gp_Ax3(左手坐标系)

此示例中使用的是gp_Ax2右手坐标系,面对称会以该定义的坐标系中x轴y轴所构成的面作为对称的面来转换。

例4:旋转变换

OCC源代码:

 //! Changes the transformation into a rotation.//! A1 is the rotation axis and Ang is the angular value of the//! rotation in radians.Standard_EXPORT   void SetRotation (const gp_Ax1& A1, const Standard_Real Ang) ;//! Changes the transformation into a rotation defined by quaternion.//! Note that rotation is performed around origin, i.e.//! no translation is involved.Standard_EXPORT   void SetRotation (const gp_Quaternion& R) ;

使用示例:

TopoDS_Shape S;gp_Trsf theTransformation = new gp_Trsf();gp_Ax1 axe = new gp_Ax1(new gp_Pnt(200, 60, 60), new gp_Dir(0.0, 1.0, 0.0));//指定旋转轴         theTransformation.SetRotation(axe, 30 * System.Math.PI / 180); //旋转角度(单位:弧度)BRepBuilderAPI_Transform myBRepTransformation =new BRepBuilderAPI_Transform(S, theTransformation, false);TopoDS_Shape S2 = myBRepTransformation.Shape();//获取旋转转换的新的拓扑

例5:缩放变换

OCC源代码:

//! Changes the transformation into a scale.
//! P is the center of the scale and S is the scaling value.
//! Raises ConstructionError  If <S> is null.
Standard_EXPORT   void SetScale (const gp_Pnt& P, const Standard_Real S) ;

使用示例:

TopoDS_Shape S;gp_Trsf theTransformation = new gp_Trsf();gp_Pnt theCenterOfScale = new gp_Pnt(100, 60, 60);  //旋转基本点theTransformation.SetScale(theCenterOfScale, 0.3);  //缩放比例BRepBuilderAPI_Transform myBRepTransformation =new BRepBuilderAPI_Transform(S, theTransformation, false);TopoDS_Shape S2 = myBRepTransformation.Shape();//获取缩放转换后的新的拓扑

例6:平移变换

OCC源代码:

//! Changes the transformation into a translation.
//! V is the vector of the translation.void SetTranslation (const gp_Vec& V) ;//! Makes the transformation into a translation where the translation vector
//! is the vector (P1, P2) defined from point P1 to point P2.void SetTranslation (const gp_Pnt& P1, const gp_Pnt& P2) ;

使用示例:

TopoDS_Shape S;gp_Trsf theTransformation = new gp_Trsf();gp_Vec theVectorOfTranslation = new gp_Vec(-6, -6, 6);  //此处平移向量是带有长度与方向的theTransformation.SetTranslation(theVectorOfTranslation);BRepBuilderAPI_Transform myBRepTransformation =new BRepBuilderAPI_Transform(S, theTransformation, false);TopoDS_Shape S2 = myBRepTransformation.Shape();

例7:移位(Displacement)变换

OCC源代码:

 //! Modifies this transformation so that it transforms the//! coordinate system defined by FromSystem1 into the//! one defined by ToSystem2. After this modification, this//! transformation transforms://! -   the origin of FromSystem1 into the origin of ToSystem2,//! -   the "X Direction" of FromSystem1 into the "X//! Direction" of ToSystem2,//! -   the "Y Direction" of FromSystem1 into the "Y//! Direction" of ToSystem2, and//! -   the "main Direction" of FromSystem1 into the "main//! Direction" of ToSystem2.//! Warning//! When you know the coordinates of a point in one//! coordinate system and you want to express these//! coordinates in another one, do not use the//! transformation resulting from this function. Use the//! transformation that results from SetTransformation instead.//! SetDisplacement and SetTransformation create//! related transformations: the vectorial part of one is the//! inverse of the vectorial part of the other.Standard_EXPORT   void SetDisplacement (const gp_Ax3& FromSystem1, const gp_Ax3& ToSystem2) ;

使用示例:

TopoDS_Shape S;gp_Trsf theTransformation = new gp_Trsf();gp_Ax3 ax3_1 = new gp_Ax3(new OCgp_Pnt(0, 0, 0), new gp_Dir(0, 0, 1));  //左手坐标系gp_Ax3 ax3_2 = new OCgp_Ax3(new gp_Pnt(60, 60, 60), new gp_Dir(1, 1, 1));theTransformation.SetDisplacement(ax3_1, ax3_2);BRepBuilderAPI_Transform myBRepTransformation =new BRepBuilderAPI_Transform(S, theTransformation, false);TopoDS_Shape TransformedShape = myBRepTransformation.Shape();

例8:组合变换

       功能:可以将上述多个变换组合在一起,组合方式即:每一个gp_Trsf对象相乘即可(OCC提供对应方法与重载的*运算符)

OCC源码:

gp_Trsf Multiplied (const gp_Trsf& T)  const;   //两个变换gp_Trsf相乘的函数gp_Trsf operator * (const gp_Trsf& T)  const     //重载的*运算符,可以直接使用两个对象相乘
{return Multiplied(T);
}//! Computes the transformation composed with <me> and T.//! <me> = <me> * T
Standard_EXPORT   void Multiply (const gp_Trsf& T) ;  //如注释<me> = <me> * Tvoid operator *= (const gp_Trsf& T)                   //重载的*=  运算符
{Multiply(T);
}

使用示例:

假如要实现旋转加平移,直接将旋转的gp_Trsf对象与平移的gp_Trsf 对象相乘即可其它操作类似,虽然是相乘但是实际是OCC内部对转换矩阵平移部分与旋转部分做了矩阵运算,构成了一个新的变换矩阵,将旋转部分与平移部分结合到了一起,详细矩阵变化请查阅文章开头仿射变换 文章介绍的各种图形变换的转换矩阵规则与运算。

2.BRepBuilderAPI_GTransform

(类,Occ标准头文件BRepBuilderAPI_GTransform.hxx)

(1)    功能说明:拓扑变换

此对象与gp_GTrsf相关联进行变换

(2)    构造函数:

//! Constructs a framework for applying the geometric
//! transformation T to a shape. Use the function
//! Perform to define the shape to transform.
Standard_EXPORT BRepBuilderAPI_GTransform(const gp_GTrsf& T);//! Constructs a framework for applying the geometric
//! transformation T to a shape, and applies it to the shape S.
//! -   If the transformation T is direct and isometric (i.e. if
//! the determinant of the vectorial part of T is equal to
//! 1.), and if Copy equals false (default value), the
//! resulting shape is the same as the original but with
//! a new location assigned to it.
//! -   In all other cases, the transformation is applied to
//! a duplicate of S.
//! Use the function Shape to access the result.
//! Note: the constructed framework can be reused to
//! apply the same geometric transformation to other
//! shapes: just specify them with the function Perform.
Standard_EXPORT BRepBuilderAPI_GTransform(const TopoDS_Shape& S, const gp_GTrsf& T, const Standard_Boolean Copy = Standard_False);

(3)    参数说明:

T:要进行的变换

S:进行变换的拓扑图形

Copy:是否用副本进行变换

(4)    实例:

例1:变形(deform)变换

OCC源代码:

//! Replaces the vectorial part of this transformation by Matrix.void SetVectorialPart (const gp_Mat& Matrix) ;//! Replaces the translation part of
//! this transformation by the coordinates of the number triple Coord.Standard_EXPORT   void SetTranslationPart (const gp_XYZ& Coord) ;

使用示例:

TopoDS_Shape S;gp_GTrsf theTransformation = new gp_GTrsf();gp_Mat rot = new gp_Mat(1, 0, 0, 0, 0.5, 0, 0, 0, 1.5);  //描述一个三行三列的矩阵,用以替换转换的矢量部分theTransformation.SetVectorialPart(rot);theTransformation.SetTranslationPart(new gp_XYZ(5, 5, 5)); //使用一个给定的坐标系作为转换,即替换原图形的局部坐标系BRepBuilderAPI_GTransform myBRepTransformation =new BRepBuilderAPI_GTransform(S, theTransformation, false);TopoDS_Shape S2 = myBRepTransformation.Shape(); //改变形状以及位置后的拓扑

参考资料:

http://www.cppblog.com/eryar/archive/2015/01/22/209612.html

网络文档资料

OpenCasCade拓扑变换(使用gp_trsf)相关推荐

  1. OpenCASCADE绘制测试线束:拓扑命令之拓扑变换

    OpenCASCADE绘制测试线束:拓扑命令之拓扑变换 拓扑变换 tcopy tmove, treset ttranslate, rotate tmirror, tscale 拓扑变换 变换是矩阵的应 ...

  2. OpenCasCade拓扑几何的布尔运算

    一.首先简单介绍一下布尔运算: 布尔运算是数字符号化的逻辑推演法,包括联合.相交.相减.在图形处理操作中引用了这种逻辑运算方法以使简单的基本图形组合产生新的形体,并由二维布尔运算发展到三维图形的布尔运 ...

  3. GIS中的拓扑关系和ArcGIS中的拓扑

    目录 GIS中的拓扑关系 ArcGIS中的拓扑 GIS中的拓扑关系 拓扑研究的是几何图形的一些性质,它们在图形被弯曲.拉大.缩小或任意的变形下保持不变.在变形过程中不使原来不同的点重合为同一个点,又不 ...

  4. AAAI 2021 | 用于图拓扑演化的深度图谱进化网络

    论文工作 在深度图学习领域,构建具有表达性高效的模型来处理源图和目标图之间的全局和局部演化模式是一项具有挑战性的工作,另一方面,但手工确定合适的指定谱模型需要大量的劳动,拟合它们的潜在组合和成分的难度 ...

  5. 拓扑概念和GIS拓扑函数

    拓扑 所谓"拓扑"就是把实体抽象成与其大小.形状无关的"点",而把连接实体的线路抽象成"线",进而以图的形式来表示这些点与线之间关系的方法, ...

  6. 数学各个分支(借花献佛)——数论,拓扑,射影几何,常微分方程,非欧几何

    文章目录 前言 1. 数论 1.1数论的发展 1.2数论的分支 2. 拓扑学 2.1 拓扑学的由来 2.2 什么是拓扑学 3. 射影几何 3.1 射影几何的发展 3.2 射影几何的内容 3.3 mar ...

  7. 《WCF技术内幕》翻译15:第1部分_第3章_消息交换模式、拓扑与编排:消息拓扑、消息编排和本章小结...

    消息拓扑 消息拓扑描述的是在一个或多个发送者和接受者之间消息如何发送的.消息拓扑可以描述简单的应用-应用的连接关系,但是它同样可以描述复杂的应用-企业的连接.在后续文章里,面向服务的应用的作用会显现出 ...

  8. 【从零开始】PythonOCC

    目录 1. 三维展示 2. 基本的几何操作 2.1 建立坐标轴 2.2 获取三维物体的包围盒 3. 拓扑操作 3.1 拓扑形状之间的布尔操作 3.2 拓扑形状的数据获取 4. 经典案例--画瓶子 参考 ...

  9. 【OCC学习14】OCC Foundation Classes

    一.OOC Modules OCC包含6大模块,简单描述如下: 模块名称 功能描述 Foundation Classes 基础类,包含被其他模块使用的数据结构及工具 Modeling Data 实现2 ...

  10. 数学各个研究方向简介

    1. 数论 人类从学会计数开始就一直和自然数打交道了,后来由于实践的需要,数的概念进一步扩充,自然数被叫做正整数,而把它们的相反数叫做负整数,介于正整数和负整数中间的中性数叫做0.它们和起来叫做整数. ...

最新文章

  1. atomic原子类实现机制_JUC学习笔记--Atomic原子类
  2. 运维经验分享:关于系统运维监控的几点建议
  3. 自己写分布式配置中心(上篇)- 单机模式
  4. java多线程遇到的问题_关于Java多线程遇到的问题.
  5. 第四十三期:2020年企业面临的20大数据安全风险
  6. linux c 内存elf,gcc加入linux ELF有什么功能?
  7. 如何在JS判断是否为IE浏览器
  8. shell编程之进阶篇四简单流程控制
  9. r语言mfrow全程_如何使用R完成文章中图片处理小教程
  10. 什么原因导致MacBook Pro过热?如何解决这一问题?
  11. 解决springboot的application.yml配置不生效问题
  12. java xml解析 jdom_Java语言中XML的JDom解析方式
  13. Nature communications
  14. 什么是无刷直流电机?
  15. Ubuntu RTL8821ce网卡驱动
  16. 基于element-ui的Vue计算工作日组件
  17. 遇险哪里还有空报警?求救app告诉你,有的
  18. python 三维曲线拟合_python实现三维拟合的方法
  19. 计算机上面的按键作用,电脑键盘上各种键的作用是什么 电脑键盘上每个键的作用说明【图文】...
  20. nginx笔记1:nginx指令与上下文

热门文章

  1. unity人物旋转移动代码_Unity实现人物旋转和移动效果
  2. h5居中loading_H5样式与布局 --常用居中方法
  3. python编写程序输入球的半径_使用python,我希望绘制一个具有给定半径的3D球形帽...
  4. 微课有关计算机应用基础,【计算机仿真论文】微课在计算机应用基础课的应用(共3802字)...
  5. 客户机操作系统已禁用 cpu_强实时工业互联网虚拟化操作系统Intewell
  6. python中and和的区别_python中逻辑与或(and、or)和按位与或异或(amp;、|、^)区别...
  7. birt字体 linux,linux下birt 图表中文乱码问题
  8. arch linux 网卡配置,请问新的arch网络配置文件在哪?或者如何手配ip 子网掩码等...
  9. java的类加载器体系结构和双亲委派机制
  10. Hiho----无间道之并查集