Open CASCADE基础介绍(3)
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
BRepBuilderAPI_Sewing类
将多个邻近图形“缝合”成为一个图形;同时有多个边的情况下无法缝合;
一般操作过程是:
--创建一个空对象;
缺省的公差是1.E-06;
面分析;
缝合操作;
根据需要作剪操作;
--定义公差;
--添加要缝合的对象;
--计算生成;
--输出结果图形;
--如果需要可以输出自由边;
--如果需要可以输出多个边;
--输出其它问题;
主要方法:
--构造函数:
option1 如果为假表示只控制;
option2:分析退化的图形;
option3:为自由边的剪操作;
option4:未复制处理;
BRepBuilderAPI_Sewing(const Standard_Real tolerance = 1.0e-06,const Standard_Boolean option1 = Standard_True,const Standard_Boolean option2 = Standard_True,const Standard_Boolean option3 = Standard_True,const Standard_Boolean option4 = Standard_False);
如果必要,可以初始化参数;
void Init(const Standard_Real tolerance = 1.0e-06,const Standard_Boolean option1 = Standard_True,const Standard_Boolean option2 = Standard_True,const Standard_Boolean option3 = Standard_True,const Standard_Boolean option4 = Standard_False) ;
--添加一个要缝合的图形的方法是;
void Add(const TopoDS_Shape& shape) ;
--生成图形方法是:
void Perform() ;
--得到缝合后的图形方法是:
TopoDS_Shape& SewedShape() const;
--得到自由边(只被一个面共享的边)的数量方法是:
Standard_Integer NbFreeEdges() const;
--得到一个自由边的方法是:
const TopoDS_Edge& FreeEdge(const Standard_Integer index) const;
--得到复合边(被两个及以上面共享的边)的数量:
Standard_Integer NbMultipleEdges() const;
--得到其中的一个复合边:
const TopoDS_Edge& MultipleEdge(const Standard_Integer index) const;
--得到邻近边的数量:
Standard_Integer NbContigousEdges() const;
--得到其中一个邻近边:
const TopoDS_Edge& ContigousEdge(const Standard_Integer index) const;
--得到有一个邻近边的边的集合(截面);
const TopTools_ListOfShape& ContigousEdgeCouple(const Standard_Integer index) const;
--一个截面是否是有边界的(使用SectionToBoundary方法之前):
Standard_Boolean IsSectionBound(const TopoDS_Edge& section) const;
--得到成为截面的原始边。记住,截面是由普通边所组成的,这个信息对于控制来说是很重要的,因为通过原始边可以找到被附加的截面的表面;
const TopoDS_Edge& SectionToBoundary(const TopoDS_Edge& section) const;
--得到每一个退化的图形:
const TopoDS_Shape& DegeneratedShape(const Standard_Integer index) const;
--此图形是否是退化的图形:
Standard_Boolean IsDegenerated(const TopoDS_Shape& shape) const;
--此图形是否已被修改过:
Standard_Boolean IsModified(const TopoDS_Shape& shape) const;
--得到一个修改后的图形:
const TopoDS_Shape& Modified(const TopoDS_Shape& shape) const;
--子图形是否被修改过:
Standard_Boolean IsModifiedSubShape(const TopoDS_Shape& shape) const;
--得到一个修改过的子图形:
TopoDS_Shape ModifiedSubShape(const TopoDS_Shape& shape) const;
--得到每一个被删除的面:
const TopoDS_Face& DeletedFace(const Standard_Integer index) const;
--void Dump() const;打印相关信息;
--得到一个修改后的图形:
TopoDS_Face WhichFace(const TopoDS_Edge& theEdg,const Standard_Integer index = 1) const;
示例:
BRepOffsetAPI_Sewing aMethod;
aMethod.Add(FirstShape);
aMethod.Add(SecondShape);
aMethod.Perform();
TopoDS_Shape sewedShape = aMethod.SewedShape();
Handle(AIS_Shape) result = new AIS_Shape(sewedShape);
BRep_Tool类
提供了处理BRep图形几何对象的一些方法;
如果S是一个Solid,Shell,或Compound.返回为真;
Standard_Boolean IsClosed(const TopoDS_Shape& S) ;
返回在位置L处的几何表面:
Handle_Geom_Surface& Surface(const TopoDS_Face& F,TopLoc_Location& L) ;
返回面的几何表面,如果有一个位置可以是一个拷贝;
Handle_Geom_Surface Surface(const TopoDS_Face& F) ;
返回面的多边三角形,如果没有三角形返回一个空句柄:
const Handle_Poly_Triangulation& Triangulation(const TopoDS_Face& F,TopLoc_Location& L) ;
返加面的公差值:
Standard_Real Tolerance(const TopoDS_Face& F) ;
返回面的自然约束标志:
Standard_Boolean NaturalRestriction(const TopoDS_Face& F) ;
如果E是一个3D曲线或表面上的一个曲线,返回为真;
Standard_Boolean IsGeometric(const TopoDS_Edge& E) ;
返回边的3D曲线,可以是NULL,返回L位置,及参数范围;
Handle_Geom_Curve& Curve(const TopoDS_Edge& E,TopLoc_Location& L,Standard_Real& First,Standard_Real& Last) ;
返回边的3D多边形,返回多边形的位置L;
Handle_Poly_Polygon3D& Polygon3D(const TopoDS_Edge& E,TopLoc_Location& L)
TopLoc_Location类
一个Location 是一个复合的平移;对象类型是TopLoc_Datum3D;
常见方法:
--TopLoc_Location();
构造一个空的局部坐标系统对象;注意,这种被构造的缺省的数据为空;、
--TopLoc_Location(const gp_Trsf& T);
通过T构造一个局部坐标系统;
--TopLoc_Location(const Handle(TopLoc_Datum3D)& D);
通过3D datum D来构造一个局部坐标系统,如果平移T不能表达一个局部坐标系统,会引发构造异常;
--Standard_Boolean IsIdentity() const;如果此位置等于一个单位化平移,返回为真;
-- void Identity() ;设置位置为单位化平移;
--Handle_TopLoc_Datum3D& FirstDatum() 得到位置的第一个基础数据;
-- const TopLoc_Location& NextLocation() const;
另外,具有加减乘除,是否相等方法;
示例:
炸开一个立方体的六个面:
for (TopExp_Explorer exp (aBox,TopAbs_FACE);exp.More();exp.Next()) {
TopoDS_Face aCurrentFace = TopoDS::Face(exp.Current());
//测试当前面的方向
TopAbs_Orientation orient = aCurrentFace.Orientation();
//重新生成几何平面
TopLoc_Location location;
Handle (Geom_Surface) aGeometricSurface = BRep_Tool::Surface(aCurrentFace,location);
Handle (Geom_Plane) aPlane = Handle (Geom_Plane)::DownCast(aGeometricSurface);
//Build an AIS_Shape with a new color
//创建一个新的AIS_Shape
Handle(AIS_Shape) theMovingFace = new AIS_Shape(aCurrentFace);
Quantity_NameOfColor aCurrentColor = (Quantity_NameOfColor)j;
myAISContext->SetColor(theMovingFace,aCurrentColor,Standard_False);
myAISContext->SetMaterial(theMovingFace,Graphic3d_NOM_PLASTIC,Standard_False);
//查找每个面的法向量
gp_Pln agpPlane = aPlane->Pln();
gp_Ax1 norm = agpPlane.Axis();
gp_Dir dir = norm.Direction();
gp_Vec move(dir);
TopLoc_Location aLocation;
Handle (AIS_ConnectedInteractive) theTransformedDisplay = new AIS_ConnectedInteractive();
theTransformedDisplay->Connect(theMovingFace, aLocation);
// = myAISContext->Location(theMovingFace);
Handle (Geom_Transformation) theMove = new Geom_Transformation(aLocation.Transformation());
for (Standard_Integer i=1;i<=30;i++) {
theMove->SetTranslation(move*i);
if (orient==TopAbs_FORWARD) myAISContext->SetLocation(theTransformedDisplay,TopLoc_Location(theMove->Trsf()));
else myAISContext->SetLocation(theTransformedDisplay,TopLoc_Location(theMove->Inverted()->Trsf()));
myAISContext->Redisplay(theTransformedDisplay,Standard_False);
}
j+=15;
}
BRepAlgo类
BRepAlgo提供了一些布尔操作的服务;
注意,在BrepAlgoAPI包中提供了新的布尔操作,代替了旧的布尔操作;
方法:
--static Standard_Boolean IsValid(const TopoDS_Shape& S) ;检测图形是否合法;
--Standard_EXPORT static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,const TopoDS_Shape&
theResult,const Standard_Boolean closedSolid = Standard_False,const Standard_Boolean GeomCtrl = Standard_True) ;
检查在结果图形中所生成和修改后的面是否合法,参数theArgs可以为空,表示所有的面都被检查;如果closedSolid 为真,表示只有封闭的图形合法,如果参数GeomCtrl为假,几何体的顶点和边不检查,自相交的新的wire也不检查;
--Standard_Boolean IsTopologicallyValid(const TopoDS_Shape& S) ;
也是检查图形是否合法,和前一个不同的是,检查 no geometric contols (intersection of wires, pcurve validity) are
performed.
GProp_GProps类
计算图元的属性;
Open CASCADE基础介绍(3)
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
BRepBuilderAPI_Sewing类
将多个邻近图形“缝合”成为一个图形;同时有多个边的情况下无法缝合;
一般操作过程是:
--创建一个空对象;
缺省的公差是1.E-06;
面分析;
缝合操作;
根据需要作剪操作;
--定义公差;
--添加要缝合的对象;
--计算生成;
--输出结果图形;
--如果需要可以输出自由边;
--如果需要可以输出多个边;
--输出其它问题;
主要方法:
--构造函数:
option1 如果为假表示只控制;
option2:分析退化的图形;
option3:为自由边的剪操作;
option4:未复制处理;
BRepBuilderAPI_Sewing(const Standard_Real tolerance = 1.0e-06,const Standard_Boolean option1 = Standard_True,const Standard_Boolean option2 = Standard_True,const Standard_Boolean option3 = Standard_True,const Standard_Boolean option4 = Standard_False);
如果必要,可以初始化参数;
void Init(const Standard_Real tolerance = 1.0e-06,const Standard_Boolean option1 = Standard_True,const Standard_Boolean option2 = Standard_True,const Standard_Boolean option3 = Standard_True,const Standard_Boolean option4 = Standard_False) ;
--添加一个要缝合的图形的方法是;
void Add(const TopoDS_Shape& shape) ;
--生成图形方法是:
void Perform() ;
--得到缝合后的图形方法是:
TopoDS_Shape& SewedShape() const;
--得到自由边(只被一个面共享的边)的数量方法是:
Standard_Integer NbFreeEdges() const;
--得到一个自由边的方法是:
const TopoDS_Edge& FreeEdge(const Standard_Integer index) const;
--得到复合边(被两个及以上面共享的边)的数量:
Standard_Integer NbMultipleEdges() const;
--得到其中的一个复合边:
const TopoDS_Edge& MultipleEdge(const Standard_Integer index) const;
--得到邻近边的数量:
Standard_Integer NbContigousEdges() const;
--得到其中一个邻近边:
const TopoDS_Edge& ContigousEdge(const Standard_Integer index) const;
--得到有一个邻近边的边的集合(截面);
const TopTools_ListOfShape& ContigousEdgeCouple(const Standard_Integer index) const;
--一个截面是否是有边界的(使用SectionToBoundary方法之前):
Standard_Boolean IsSectionBound(const TopoDS_Edge& section) const;
--得到成为截面的原始边。记住,截面是由普通边所组成的,这个信息对于控制来说是很重要的,因为通过原始边可以找到被附加的截面的表面;
const TopoDS_Edge& SectionToBoundary(const TopoDS_Edge& section) const;
--得到每一个退化的图形:
const TopoDS_Shape& DegeneratedShape(const Standard_Integer index) const;
--此图形是否是退化的图形:
Standard_Boolean IsDegenerated(const TopoDS_Shape& shape) const;
--此图形是否已被修改过:
Standard_Boolean IsModified(const TopoDS_Shape& shape) const;
--得到一个修改后的图形:
const TopoDS_Shape& Modified(const TopoDS_Shape& shape) const;
--子图形是否被修改过:
Standard_Boolean IsModifiedSubShape(const TopoDS_Shape& shape) const;
--得到一个修改过的子图形:
TopoDS_Shape ModifiedSubShape(const TopoDS_Shape& shape) const;
--得到每一个被删除的面:
const TopoDS_Face& DeletedFace(const Standard_Integer index) const;
--void Dump() const;打印相关信息;
--得到一个修改后的图形:
TopoDS_Face WhichFace(const TopoDS_Edge& theEdg,const Standard_Integer index = 1) const;
示例:
BRepOffsetAPI_Sewing aMethod;
aMethod.Add(FirstShape);
aMethod.Add(SecondShape);
aMethod.Perform();
TopoDS_Shape sewedShape = aMethod.SewedShape();
Handle(AIS_Shape) result = new AIS_Shape(sewedShape);
BRep_Tool类
提供了处理BRep图形几何对象的一些方法;
如果S是一个Solid,Shell,或Compound.返回为真;
Standard_Boolean IsClosed(const TopoDS_Shape& S) ;
返回在位置L处的几何表面:
Handle_Geom_Surface& Surface(const TopoDS_Face& F,TopLoc_Location& L) ;
返回面的几何表面,如果有一个位置可以是一个拷贝;
Handle_Geom_Surface Surface(const TopoDS_Face& F) ;
返回面的多边三角形,如果没有三角形返回一个空句柄:
const Handle_Poly_Triangulation& Triangulation(const TopoDS_Face& F,TopLoc_Location& L) ;
返加面的公差值:
Standard_Real Tolerance(const TopoDS_Face& F) ;
返回面的自然约束标志:
Standard_Boolean NaturalRestriction(const TopoDS_Face& F) ;
如果E是一个3D曲线或表面上的一个曲线,返回为真;
Standard_Boolean IsGeometric(const TopoDS_Edge& E) ;
返回边的3D曲线,可以是NULL,返回L位置,及参数范围;
Handle_Geom_Curve& Curve(const TopoDS_Edge& E,TopLoc_Location& L,Standard_Real& First,Standard_Real& Last) ;
返回边的3D多边形,返回多边形的位置L;
Handle_Poly_Polygon3D& Polygon3D(const TopoDS_Edge& E,TopLoc_Location& L)
TopLoc_Location类
一个Location 是一个复合的平移;对象类型是TopLoc_Datum3D;
常见方法:
--TopLoc_Location();
构造一个空的局部坐标系统对象;注意,这种被构造的缺省的数据为空;、
--TopLoc_Location(const gp_Trsf& T);
通过T构造一个局部坐标系统;
--TopLoc_Location(const Handle(TopLoc_Datum3D)& D);
通过3D datum D来构造一个局部坐标系统,如果平移T不能表达一个局部坐标系统,会引发构造异常;
--Standard_Boolean IsIdentity() const;如果此位置等于一个单位化平移,返回为真;
-- void Identity() ;设置位置为单位化平移;
--Handle_TopLoc_Datum3D& FirstDatum() 得到位置的第一个基础数据;
-- const TopLoc_Location& NextLocation() const;
另外,具有加减乘除,是否相等方法;
示例:
炸开一个立方体的六个面:
for (TopExp_Explorer exp (aBox,TopAbs_FACE);exp.More();exp.Next()) {
TopoDS_Face aCurrentFace = TopoDS::Face(exp.Current());
//测试当前面的方向
TopAbs_Orientation orient = aCurrentFace.Orientation();
//重新生成几何平面
TopLoc_Location location;
Handle (Geom_Surface) aGeometricSurface = BRep_Tool::Surface(aCurrentFace,location);
Handle (Geom_Plane) aPlane = Handle (Geom_Plane)::DownCast(aGeometricSurface);
//Build an AIS_Shape with a new color
//创建一个新的AIS_Shape
Handle(AIS_Shape) theMovingFace = new AIS_Shape(aCurrentFace);
Quantity_NameOfColor aCurrentColor = (Quantity_NameOfColor)j;
myAISContext->SetColor(theMovingFace,aCurrentColor,Standard_False);
myAISContext->SetMaterial(theMovingFace,Graphic3d_NOM_PLASTIC,Standard_False);
//查找每个面的法向量
gp_Pln agpPlane = aPlane->Pln();
gp_Ax1 norm = agpPlane.Axis();
gp_Dir dir = norm.Direction();
gp_Vec move(dir);
TopLoc_Location aLocation;
Handle (AIS_ConnectedInteractive) theTransformedDisplay = new AIS_ConnectedInteractive();
theTransformedDisplay->Connect(theMovingFace, aLocation);
// = myAISContext->Location(theMovingFace);
Handle (Geom_Transformation) theMove = new Geom_Transformation(aLocation.Transformation());
for (Standard_Integer i=1;i<=30;i++) {
theMove->SetTranslation(move*i);
if (orient==TopAbs_FORWARD) myAISContext->SetLocation(theTransformedDisplay,TopLoc_Location(theMove->Trsf()));
else myAISContext->SetLocation(theTransformedDisplay,TopLoc_Location(theMove->Inverted()->Trsf()));
myAISContext->Redisplay(theTransformedDisplay,Standard_False);
}
j+=15;
}
BRepAlgo类
BRepAlgo提供了一些布尔操作的服务;
注意,在BrepAlgoAPI包中提供了新的布尔操作,代替了旧的布尔操作;
方法:
--static Standard_Boolean IsValid(const TopoDS_Shape& S) ;检测图形是否合法;
--Standard_EXPORT static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,const TopoDS_Shape&
theResult,const Standard_Boolean closedSolid = Standard_False,const Standard_Boolean GeomCtrl = Standard_True) ;
检查在结果图形中所生成和修改后的面是否合法,参数theArgs可以为空,表示所有的面都被检查;如果closedSolid 为真,表示只有封闭的图形合法,如果参数GeomCtrl为假,几何体的顶点和边不检查,自相交的新的wire也不检查;
--Standard_Boolean IsTopologicallyValid(const TopoDS_Shape& S) ;
也是检查图形是否合法,和前一个不同的是,检查 no geometric contols (intersection of wires, pcurve validity) are
performed.
GProp_GProps类
计算图元的属性;