您的位置:首页 > 运维架构

Open CASCADE基础介绍(4)

2008-10-28 18:08 337 查看

Open CASCADE基础介绍(4)

gp_Trsf类

定义一个矩阵变换的类
--可以定义平移、旋转、缩放的矩阵;
--可以对称于一个点,一条线,一个平面;
示例一:
对称于一个点:
gp_Trsf theTransformation;<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

gp_Pnt PntCenterOfTheTransformation(110,60,60);

theTransformation.SetMirror(PntCenterOfTheTransformation);

 

示例二:

绕一个轴旋转:

gp_Trsf theTransformation;

gp_Ax1 axe = gp_Ax1(gp_Pnt(200,60,60),gp_Dir(0.,1.,0.));

theTransformation.SetRotation(axe,30*PI/180);

 

示例三:

缩放:

gp_Trsf theTransformation;

gp_Pnt theCenterOfScale(200,60,60);

theTransformation.SetScale(theCenterOfScale,0.5);

 

示例四:

平移:

gp_Trsf theTransformation;

gp_Vec theVectorOfTranslation(-6,-6,6);

theTransformation.SetTranslation(theVectorOfTranslation);
 

示例五:
Displacement:
TopoDS_Shape S = BRepPrimAPI_MakeWedge(60.,100.,80.,20.);
gp_Trsf theTransformation;
gp_Ax3 ax3_1(gp_Pnt(0,0,0),gp_Dir(0,0,1));
gp_Ax3 ax3_2(gp_Pnt(60,60,60),gp_Dir(1,1,1));
theTransformation.SetDisplacement(ax3_1,ax3_2);
BRepBuilderAPI_Transform myBRepTransformation(S,theTransformation);
TopoDS_Shape TransformedShape = myBRepTransformation.Shape();
 

示例六:
变形
gp_GTrsf theTransformation;
gp_Mat rot(1, 0, 0, 0, 0.5, 0, 0, 0, 1.5);
theTransformation.SetVectorialPart(rot);
theTransformation.SetTranslationPart(gp_XYZ(5,5,5));
BRepBuilderAPI_GTransform myBRepTransformation(S,theTransformation);
TopoDS_Shape S2 = myBRepTransformation.Shape();
 

BuilderAPI_MakeEdge类

定义一生成一个边;此类有多个构造函数,现举其中一个介绍如下:
 

Standard_EXPORT BRepBuilderAPI_MakeEdge(const Handle(Geom2d_Curve)& L,const Handle(Geom_Surface)& S,const TopoDS_Vertex& V1,const TopoDS_Vertex& V2,const Standard_Real p1,const Standard_Real p2);
其参数含义是:
顶点V1和V2用来限制曲线(定义边的约束),值p1和p2为顶点的参数;
曲线可以定义成在一个表面的2D曲线,应用缺省的公差;
参数规则:
对于曲线来说:
--句柄不能为空;
--如果曲线是一个trimmed曲线,使用基础曲线;
对于顶点来说:
--可以为空,表示此参数为无限大;静态方法 Precision::Infinite()用来定义一个无限大的数;
--两个顶点如果位于同一位置,必须一样,当曲线是封闭时使用相同的顶点;
对于参数来说:
--参数为必须在曲线参数范围内,如果曲线是trimmed,使用基础曲线;如果边的条件不满足,返回BRepAPI_ParameterOutOfRange错误;
--参数值不能相等,如果条件不满足,边无法创建,返回BRepAPI_LineThroughIdenticPoints错误;
--参数值可以这样给出C->FirstParameter()
--如果参数值需要切换,比如第一个顶点的参数为P2,第二个顶点的参数为P1,边的方向可以“reversed”;
--对于一个周期曲线,值P1和P2可以通过加或减周期来得到;
--参数值可以无限大,在对应的方向上边是开放的。然而,对应的顶点必须是空图形,如果条件不满足,边无法创建,返回BRepAPI_PointWithInfiniteParameter错误;
--参数值可以被忽略,将通过曲线上的投影进行计算;
--可以给定空间三维点;
 

BRepFeat_MakePipe类

基类为:BRepFeat_Form;
通过基本图形生成一个Pipe;
 

BRepFeat_MakeLinearForm 类
基类为:BRepFeat_RibSlot
在一个平面表面上建一个肋或开凹槽;
 

BRepFeat_Gluer类

粘合两个实体为一个实体;
示例:
(1):创建两个BOX,并找到要粘合的面;
(2):创建要粘合的对象:
BRepFeat_Gluer glue2(S4,S3);
(3):用两个面粘合对象;
glue2.Bind(F4,F3);
(4):重新生成对象:
LocOpe_FindEdges CommonEdges(F4,F3);
       for (CommonEdges.InitIterator(); CommonEdges.More(); CommonEdges.Next())
              glue2.Bind(CommonEdges.EdgeFrom(),CommonEdges.EdgeTo());
       TopoDS_Shape res2 = glue2.Shape();
       myAISContext->Erase(ais3,Standard_False,Standard_False);
      
       ais4->Set(res2);
 

       myAISContext->Redisplay(ais4,Standard_False);
 

Graphic2d_Polyline类
创建一个多边形.
常见方法:
--Length()得到线的点数;
--void Values(const Standard_Integer aRank,Quantity_Length& X,Quantity_Length& Y) const;得到序号为aRank的点;
--void DrawElement(const Handle(Graphic2d_Drawer)& aDrawer,const Standard_Integer anIndex) ;绘制多边形的一条边;
--void DrawVertex(const Handle(Graphic2d_Drawer)& aDrawer,const Standard_Integer anIndex) ;绘制多边形的一个顶点;
--Standard_Boolean Pick(const Standard_ShortReal X,const Standard_ShortReal Y,const Standard_ShortReal aPrecision,const Handle(Graphic2d_Drawer)& aDrawer) ;得到此多边形是否被拾取,注意:PickIndex()方法得到的是最后拾取的点,如果拾取点在线的内部,返回0;
 

Graphic2d_Line类

是Polyline, Circle ... 等图元的基类;
常见方法:
--SetWidthIndex(const Standard_Integer anIndex) ;得到在width map中的宽度的索引;设定对应的线宽值;
--SetTypeIndex(const Standard_Integer anIndex) ;设置线型;
--SetInteriorColorIndex(const Standard_Integer anIndex) ;设置颜色;
--void SetDrawEdge(const Standard_Boolean aDraw) ;设置边是否绘出,注意,这种情况下,polygon的类型必须为:
Graphic2d_TOPF_FILLED 或者 Graphic2d_TOPF_PATTERNED;
--SetInteriorPattern(const Standard_Integer anIndex) ;定义封闭线的内部图案,polygon的填充类型必须是:Graphic2d_TOPF_PATTERNED;
--SetTypeOfPolygonFilling(const Graphic2d_TypeOfPolygonFilling aType) ;定义封闭线的图案,TypeOfPolygonFilling可选类型有:
- Graphic2d_TOPF_EMPTY - Graphic2d_TOPF_FILLED - Graphic2d_TOPF_PATTERNED ;
--Standard_Integer InteriorColorIndex() const;得到颜色索引;
--Standard_Integer InteriorPattern() const;得到所使用的图案索引;
--Graphic2d_TypeOfPolygonFilling TypeOfPolygonFilling() const;得到多边形填充模式;
 

Graphic2d_Primitive类

是Graphic2d_Line类的基类,
常见方法:
--得到及获取颜色索引;
--得到图元元素的数量和顶点的数量:
Standard_Integer NumOfElemIndices() const;
Standard_Integer NumOfVertIndices() const;
--Standard_Integer PickedIndex() const;得到最后拾取的图元元素的索引值;
--void Highlight(const Standard_Integer anIndex = 0) ;高亮显示图元或图元的一部分,当anIndex=0表示所有的图元高亮显示,>0为当所要求的图元元素高亮显示时,<0为所要求的顶点高亮显示时;
--void Unhighlight() ;禁止图元高亮显示;
-- Standard_Boolean IsHighlighted() const;图元是否高亮显示;
--Handle_TColStd_HSequenceOfInteger HighlightIndices() const;得到图元高亮显示的索引序列;
--void SetDisplayMode(const Standard_Integer aMode) ;设置图元显示的模式;
--Standard_Integer DisplayMode() const;得到图元显示的模式;
--Standard_Boolean Graphic2d_GraphicObject::Pick(const Standard_Real X,const Standard_Real Y,const Standard_Real aPrecision,const Handle(Graphic2d_Drawer)& aDrawer) ;
用一个矩形框拾取图形对象,如果图形对象被拾取,返回为真,通过方法Graphic2d_View::Pick调用;
 

--Standard_Boolean Graphic2d_GraphicObject::PickByCircle(const Standard_Real X,const Standard_Real Y,const Standard_Real Radius,const Handle(Graphic2d_Drawer)& aDrawer) ;
用一个园来拾取图形对象,如果图形对象被拾取,返回为真,通过方法Graphic2d_View::PickByCircle调用;
 

--Standard_Boolean Graphic2d_GraphicObject::Pick(const Standard_Real Xmin,const Standard_Real Ymin,const Standard_Real Xmax,const Standard_Real Ymax,const Handle(Graphic2d_Drawer)& aDrawer,const Graphic2d_PickMode aPickMode) ;
 

以下情况下返回值为真:
包括在矩形内:included in rectangle (<aPickMode = PM_INCLUDE>),
不在矩形内:excluded from rectangle (<aPickMode = PM_EXLUDE>),
相交于矩形框:intersected by rectangle (<aPickMode = PM_INTERSECT>),
通过 Xmin, Ymin, Xmax, Ymax定义矩形框。
 

--得到所有在图元内的markers的最小最大值,注意,如果me为空,或未显示,或没有markers返回为假,
 Minx = Miny = RealFirst () ;Maxx = Maxy = RealLast ()
Standard_EXPORT   Standard_Boolean Graphic2d_GraphicObject::MarkerMinMax(Quantity_Length& Minx,Quantity_Length& Maxx,Quantity_Length& Miny,Quantity_Length& Maxy) const;
 

--移除图元;Standard_EXPORT   void Graphic2d_GraphicObject::RemovePrimitive(const Handle(Graphic2d_Primitive)& aPrimitive) ;
 

--绘制图元,以默认的图元属性绘制;void Graphic2d_TransientManager::Draw(const Handle(Graphic2d_Primitive)& aPrimitive) ;
 

AIS2D_InteractiveObject类

使用显示和选择服务,来可视化和选择机制,交互式对象常用来显示数据,曲线,图形,markers,尺寸标注等。
常用方法:
--获取及设置属性
 Handle_Prs2d_Drawer Attributes() const;
void SetAttributes(const Handle(Prs2d_Drawer)& aDrawer) ;
 

--通过Aspect设置属性,到所有图元分配这个Aspect.
Standard_EXPORT   void SetAspect(const Handle(Prs2d_AspectRoot)& anAspect) ;
 

--通过Aspect设置属性,到所有通过InteractiveContext被链接的图元对象;
Standard_EXPORT   void SetAspect(const Handle(Prs2d_AspectRoot)& anAspect,const Handle(Graphic2d_Primitive)& aPrimitive) ;
 

--得到图元的Aspect;
Standard_EXPORT   Handle_Prs2d_AspectRoot GetAspect(const Handle(Graphic2d_Primitive)& aPrimitive) const;
 

--如果图元用一个aspect链接的话返回为真;
Standard_EXPORT   Standard_Boolean HasAspect(const Handle(Graphic2d_Primitive)& aPrimitive) const;
 

--指出交互对象是否有一个交互上下文设备;
Standard_EXPORT   Standard_Boolean HasInteractiveContext() const;
 

--得到交互对象的上下文设备;      
Standard_EXPORT   Handle_AIS2D_InteractiveContext GetContext() const;

Graphic2d_GraphicObject类

是AIS2D_InteractiveObject类的基类;在一个view内创建一个图形对象,一个图形对象管理一系列图元;默认值为:空,可输出,可绘制,可拾取,不显示,不高亮,优先权为0;
主要方法:
设置视图,设置一个变形,设置获取图层,设置获取优先权,禁用/使用输出,是否可输出,禁用/使用Draw.是否可显示,Erase,高亮显示,颜色,拾取等;
 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息