Open CASCADE学习| 提取曲面的PCurve

PCurve这个概念,字面上来理解就是参数曲线(Parametric Curve)。参数空间曲线是在参数曲面的双参数空间中的二维样条曲线。

二维曲线定义的目的只有一个:pCurve,参数曲线。OCC采用参数法构建几何结构,所有的三维曲线(面的边界)都对应于二维参数曲线pCurve。二维参数曲线pCurve上的二维点对应实际曲线上的三维点。如下代码,我们遍历一个Topo_Face的Edge,然后求得Edge对应的pCurve。并显示Face的二维参数面。

​
// OpenCascade library.
#define WNT
#include 
#include 
#include 
#include 
#include 
#include 
#include 
​
#pragma comment(lib, "TKernel.lib")
#pragma comment(lib, "TKMath.lib")
#pragma comment(lib, "TKBRep.lib")
#pragma comment(lib, "TKTopAlgo.lib")
#pragma comment(lib, "TKPrim.lib")
​
​
int main(int argc, char* argv[])
{
    TopoDS_Face face = BRepPrimAPI_MakeSphere(1.0);
    TopExp_Explorer aWireExp(face, TopAbs_WIRE);
    for (aWireExp; aWireExp.More(); aWireExp.Next()) 
    {
        //获取每条wire
        BRepBuilderAPI_MakeWire wire2d;
        TopoDS_Wire aTempWire = TopoDS::Wire(aWireExp.Current());
        //获取Edge
        TopExp_Explorer aEdgeExp(aTempWire, TopAbs_EDGE);
        for (aEdgeExp; aEdgeExp.More(); aEdgeExp.Next()) {
            TopoDS_Edge aTempEdge = TopoDS::Edge(aEdgeExp.Current());
​
            //获取PCurve
            Standard_Real aPFirst, aPLast;
            Handle(Geom2d_Curve) aPCurve = BRep_Tool::CurveOnSurface(aTempEdge, face, aPFirst, aPLast);
            //获取此时PCurve的端点坐标,即UV值。
            gp_Pnt2d pStart, pEnd;
            aPCurve->D0(aPFirst, pStart);
            aPCurve->D0(aPLast, pEnd);
            std::cout << "\n";
            std::cout << "         起始点坐标:[" << pStart.X() << "," << pStart.Y() << "]\n";
            std::cout << "         终止点坐标:[" << pEnd.X() << "," << pEnd.Y() << "]\n";
            TopoDS_Edge aEdge2d = BRepBuilderAPI_MakeEdge2d(aPCurve, aPFirst, aPLast);
            wire2d.Add(aEdge2d);
​
        }
    }
​
    return 0;
}

  起始点坐标:[0,1.5708]

         终止点坐标:[6.28319,1.5708]

         起始点坐标:[6.28319,-1.5708]

         终止点坐标:[6.28319,1.5708]

         起始点坐标:[0,-1.5708]

         终止点坐标:[6.28319,-1.5708]

         起始点坐标:[0,-1.5708]

         终止点坐标:[0,1.5708]

你可能感兴趣的:(Open,CASCADE,学习,Open,CASCADE,c++,PCurve)