opencascade中的几种类型转换 [转自Polaris]

   
   
  1. 将Geom_BSplineSurface转化成TopoDS_Face:  
1. 将Geom_BSplineSurface转化成TopoDS_Face:
Handle_Geom_BSplineSurface BSurface;
BRep_Builder builder;
TopoDS_Face Face;
builder.MakeFace(Face,BSurface,Tolerance);
2.将TopoDS_Face 转化为Geom_Surface
Handle_Geom_Surface  currentSur;
TopExp_Explorer Ex; 
Ex.Init(shape,TopAbs_FACE); 
TopoDS_Face currentVt = TopoDS::Face(Ex.Current());
currentSur = BRep_Tool::Surface(currentVt);
3.普通曲线转化为NURBS曲线

Handle(Geom_Curve) ResCurve ;
Handle(Geom_TrimmedCurve) myTrimmed = new Geom_TrimmedCurve(ResCurve, 0, 1);
NurbsCurve = GeomConvert::CurveToBSplineCurve(myTrimmed); //必须指定曲线的类型如Geom_TrimmedCurve

OCC的说明如下:

 

-- Purpose : This function converts a non infinite curve from

-- Geom into a B-spline curve.C must be an ellipse or a

-- circle or a trimmed conic or a trimmed line or a Bezier

-- curve or a trimmed Bezier curve or a BSpline curve or a

-- trimmed BSpline curve or an OffsetCurve. The returned B-spline is

-- not periodic except if C is a Circle or an Ellipse.

 

4. Geom_Surface 转 Geom_BsplineSurface

GeomConvert::SurfaceToBSplineSurface(surface)

其中surface必须为Geom_Surface 中的某一具体类型

OCC的说明如下:

--- Purpose : This algorithm converts a non infinite surface from Geom

-- into a B-spline surface.

-- S must be a trimmed plane or a trimmed cylinder or a trimmed cone

-- or a trimmed sphere or a trimmed torus or a sphere or a torus or

-- a Bezier surface of a trimmed Bezier surface or a trimmed swept

--surfacewith a corresponding basis curve which can be turned into

-- a B-spline curve

5.  点云转 Geom_BsplineSurface

 

  1. Handle_Geom_BSplineSurface CMiniCADTool::BuildSurface(const TColgp_SequenceOfXYZ& seqOfXYZ)  
  2. {  
  3.     // Build the surface:  
  4.     // points are projected on plane z = 0  
  5.     // the projection vector for each point is computed   
  6.     // These data give the input constraints loaded into plate algorithm  
  7.   
  8.     const Standard_Integer nbPnt = seqOfXYZ.Length();  
  9.     Standard_Integer i;  
  10.   
  11.     //Filling plate  
  12.     Plate_Plate myPlate;  
  13.     for (i=1; i<= nbPnt; i += 4) {  
  14.         gp_Vec aVec(0., 0., seqOfXYZ.Value(i).Z());  
  15.         gp_XY  pntXY(seqOfXYZ.Value(i).X(),seqOfXYZ.Value(i).Y());  
  16.         Plate_PinpointConstraint PCst( pntXY,aVec.XYZ() );  
  17.         myPlate.Load(PCst); // Load a pinpoint constraint  
  18.     }  
  19.     myPlate.SolveTI(2, 1.); // Solving plate equations  
  20.     if (!myPlate.IsDone()) {  
  21.         return Handle(Geom_BSplineSurface)();  
  22.     }  
  23.   
  24.     // Computation of plate surface  
  25.     gp_Pnt Or(0,0,0.);  
  26.     gp_Dir Norm(0., 0., 1.);  
  27.     Handle(Geom_Plane) myPlane = new Geom_Plane(Or, Norm);// Plane of normal Oz  
  28.     Handle(GeomPlate_Surface) myPlateSurf = new GeomPlate_Surface(myPlane, myPlate);//plate surface  
  29.   
  30.     GeomPlate_MakeApprox aMKS(myPlateSurf, Precision::Approximation(), 4, 7, 0.001, 0);//bspline surface  
  31.     return aMKS.Surface();  
  32.   
  33. }  
Handle_Geom_BSplineSurface CMiniCADTool::BuildSurface(const TColgp_SequenceOfXYZ& seqOfXYZ)
{
	// Build the surface:
	// points are projected on plane z = 0
	// the projection vector for each point is computed 
	// These data give the input constraints loaded into plate algorithm

	const Standard_Integer nbPnt = seqOfXYZ.Length();
	Standard_Integer i;

	//Filling plate
	Plate_Plate myPlate;
	for (i=1; i<= nbPnt; i += 4) {
		gp_Vec aVec(0., 0., seqOfXYZ.Value(i).Z());
		gp_XY  pntXY(seqOfXYZ.Value(i).X(),seqOfXYZ.Value(i).Y());
		Plate_PinpointConstraint PCst( pntXY,aVec.XYZ() );
		myPlate.Load(PCst); // Load a pinpoint constraint
	}
	myPlate.SolveTI(2, 1.); // Solving plate equations
	if (!myPlate.IsDone()) {
		return Handle(Geom_BSplineSurface)();
	}

	// Computation of plate surface
	gp_Pnt Or(0,0,0.);
	gp_Dir Norm(0., 0., 1.);
	Handle(Geom_Plane) myPlane = new Geom_Plane(Or, Norm);// Plane of normal Oz
	Handle(GeomPlate_Surface) myPlateSurf = new GeomPlate_Surface(myPlane, myPlate);//plate surface

	GeomPlate_MakeApprox aMKS(myPlateSurf, Precision::Approximation(), 4, 7, 0.001, 0);//bspline surface
	return aMKS.Surface();

}
6.surface 向Geom_Plane 向下转换(DownCast方法)其中Geom_Plane类中有方法可以将gp_Pln和Geom_Plane进行相互转化。

 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(BRep_Tool::Surface(SelectFace));
PlaneOfTheView = aPlane->Pln();

 7.TopoDS_Shape 向相应的格式转
例如:Vertex = TopoDS::Vertex(Shape);
8.TopoDS_Vertex向gp_Pnt转
gp_Pnt   P = BRep_Tool::Pnt(Vertex)


 

  • 3
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值