一个函数构建实体 不知道有什么问题 ,请教大神


这样构建一个实体不知道对不对,在测试的时候总有问题,不知道哪出错了

//这段程序目的想根据已知的几何拓扑信息构建一个实体
//SFace 是一个存储一个面的几何拓扑的结构
//faceList 是一个vector(vector<SFace*> faceList), 它表示一个实体的所有面的几何拓扑信息
{
BRepOffsetAPI_Sewing solid;
TopoDS_Face face;

for (auto iter = faceList.begin(); iter != faceList.end(); iter++)
{
    CurrentStructToOCCT(*iter, face);
    solid.Add(face);
}
solid.Perform();
TopoDS_Shape sewedShape = solid.SewedShape();
}

void PCurrentStructToOCCT(SFace* face, TopoDS_Face& aFace)
{
TopoDS_Wire wire;
Handle(Geom_Surface) S;

if(!strcmp(face->name_, "plane"))
    S = ((SPlane*)face)->ToOCCT();
if(!strcmp(face->name_, "spherical_surface"))
    S = ((SSpherical*)face)->ToOCCT();
if(!strcmp(face->name_, "conical_surface"))
    S = ((SConical*)face)->ToOCCT();
if(!strcmp(face->name_, "cylindrical_surface"))
    S = ((SCylindrical*)face)->ToOCCT();
if(!strcmp(face->name_, "toroidal_surface"))
    S = ((SToroidal*)face)->ToOCCT();

//faceBounds 面的边界信息
for(auto itBound = face->faceBounds_.begin(); itBound != face->faceBounds_.end(); itBound++)
{
    BRepBuilderAPI_MakeWire MW;

    //edge curves 信息
    for(auto itCurve = (*itBound)->edgeLoop_.begin(); itCurve != (*itBound)->edgeLoop_.end(); itCurve++)
    {
        //边起始,终点 vertex satrt and vertex end
        gp_Pnt start((*itCurve)->edgeStart_.x, (*itCurve)->edgeStart_.y, (*itCurve)->edgeStart_.z);
        gp_Pnt end((*itCurve)->edgeEnd_.x, (*itCurve)->edgeEnd_.y, (*itCurve)->edgeEnd_.z);

        if(!stricmp((*itCurve)->curveName_, "line"))
        {
            gp_Dir Dir1(((LINE*)(*itCurve))->dir_.dx, ((LINE*)(*itCurve))->dir_.dy, ((LINE*)(*itCurve))->dir_.dz );
            gp_Pnt Pnt1(((LINE*)(*itCurve))->pnt_.x, ((LINE*)(*itCurve))->pnt_.y, ((LINE*)(*itCurve))->pnt_.z);
            gp_Lin pLine(Pnt1, Dir1);
            TopoDS_Edge edge = BRepBuilderAPI_MakeEdge(pLine, start,end).Edge();
            MW.Add(edge);
        }
        if(!stricmp((*itCurve)->curveName_, "circle"))
        {
            gp_Dir N1(((CIRCLE*)(*itCurve))->position_.verAxis.dx,
                ((CIRCLE*)(*itCurve))->position_.verAxis.dy, 
                ((CIRCLE*)(*itCurve))->position_.verAxis.dz );
            gp_Pnt P1(((CIRCLE*)(*itCurve))->position_.point.x, 
                ((CIRCLE*)(*itCurve))->position_.point.y, 
                ((CIRCLE*)(*itCurve))->position_.point.z );
            gp_Ax2 ax1(P1,N1);
            gp_Circ circle(ax1, ((CIRCLE*)(*itCurve))->radius_);
            TopoDS_Edge edge = BRepBuilderAPI_MakeEdge(circle,start,end).Edge();

            MW.Add(edge);
        }
        if(!stricmp((*itCurve)->curveName_, "ellipse"))
        {
            gp_Dir N1(((ELLIPSE*)(*itCurve))->position_.verAxis.dx, ((ELLIPSE*)(*itCurve))->position_.verAxis.dy, ((ELLIPSE*)(*itCurve))->position_.verAxis.dz);
            gp_Pnt P1(((ELLIPSE*)(*itCurve))->position_.point.x, ((ELLIPSE*)(*itCurve))->position_.point.y, ((ELLIPSE*)(*itCurve))->position_.point.z);
            gp_Ax2 ax1(P1, N1);
            gp_Elips elips(ax1, ((ELLIPSE*)(*itCurve))->semi_axis_1_, ((ELLIPSE*)(*itCurve))->semi_axis_2_);
            TopoDS_Edge edge = BRepBuilderAPI_MakeEdge(elips, start, end).Edge();
            MW.Add(edge);
        }
    }
    if (MW.IsDone())
        wire = MW.Wire();
}
BRepBuilderAPI_MakeWire mkWire;
mkWire.Add(wire);
TopoDS_Wire myWireProfile = mkWire.Wire();
aFace = BRepBuilderAPI_MakeFace(S, myWireProfile,true).Face();
}

Geom_Surface * SCylindrical::ToOCCT()
{
gp_Pnt P1(position_->point.x, position_->point.y, position_->point.z);
gp_Vec Vec1(position_->verAxis.dx, position_->verAxis.dy, position_->verAxis.dz);
gp_Dir Dir1(Vec1);
gp_Ax3 Ax31(P1, Dir1);
Geom_CylindricalSurface * Cyl1 = new Geom_CylindricalSurface(Ax31, radius_);
return Cyl1;
}
已邀请:

vujn2003

赞同来自:


~_~ ~_~

要回复问题请先登录注册