几何尺寸与公差论坛

 找回密码
 注册
查看: 9384|回复: 1

【转帖】我执行Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(top

[复制链接]
发表于 2007-11-28 11:57:48 | 显示全部楼层 |阅读模式
我执行Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(topoFace, aLoc);,似乎根本没有进入三角化的代码就退出了
// ***************************************************************
//  Translation   version:  1.0   · date: 11/28/2007
//  -------------------------------------------------------------
//  OCC TopoDS_Shape类型数据导出
//  -------------------------------------------------------------
//  Copyright (C) 2007 - All Rights Reserved
// ***************************************************************
//
// ***************************************************************
#include <iostream>
using namespace std;

#define  WNT

#include <TopoDS_Shape.hxx>
#include <BRepPrimAPI_MakeTorus.hxx>
#include <BRepPrimAPI_MakeBox.hxx>
#include <BRepAlgoAPI_Section.hxx>
#include <gp_Pln.hxx>
#include <TopoDS_Iterator.hxx>
#include <BRep_Tool.hxx>
#include <oly_Triangulation.hxx>
#include <TopoDS.hxx>
#include <oly_PolygonOnTriangulation.hxx>

#pragma comment( lib, "TKTopAlgo" )
#pragma comment( lib, "TKernel" )
#pragma comment( lib, "TKPrim" )
#pragma comment( lib, "TKBRep" )
#pragma comment( lib, "TKBO" )
#pragma comment( lib, "TKMath" )

void translationDispatch(const TopoDS_Shape& topoShape);

//************************************
// Method:    topoEdgeTranslater
// FullName:  topoEdgeTranslater
// Access:    public
// Returns:   void
// Qualifier: 转化线数据
// Parameter: const TopoDS_Shape & topoShape
//************************************
void topoEdgeTranslater(const TopoDS_Shape& topoShape)
{   
    TopoDS_Edge topoEdge = TopoDS::Edge(topoShape);

    Handle(Poly_PolygonOnTriangulation) aEdgePoly;
    Standard_Integer i = 1;
    Handle(Poly_Triangulation) T;
    TopLoc_Location aEdgeLoc;
    BRep_Tool:olygonOnTriangulation(topoEdge, aEdgePoly, T, aEdgeLoc, i);

    if(aEdgePoly.IsNull())
    {
        return;
    }

    gp_Trsf edgeTransf;
    Standard_Boolean isidtrsf = true;
    if(!aEdgeLoc.IsIdentity())  
    {
        isidtrsf = false;
        edgeTransf = aEdgeLoc.Transformation();
    }

    Standard_Integer nbnodes = aEdgePoly->NbNodes();
    const TColStd_Array1OfInteger& Nodesidx = aEdgePoly->Nodes();
    const TColgp_Array1OfPnt& theNodes = T->Nodes();

    float coord[3];
   
    for(int j=1; j < nbnodes; j++) {

        Standard_Integer id1 = Nodesidx(j);
        Standard_Integer id2 = Nodesidx(j+1);

        gp_Pnt pt1 = theNodes(id1);
        gp_Pnt pt2 = theNodes(id2);

        if(!isidtrsf) {
            // apply edge transformation
            pt1.Transform(edgeTransf);
            pt2.Transform(edgeTransf);
        }

        // insert pt1
        coord[0] = (float)pt1.X(); coord[1] = (float)pt1.Y(); coord[2] = (float)pt1.Z();
        cout << "line: ( " << coord[0] << ", " << coord[1] << ", " << coord[2] << " )" << " To ";

        // insert pt2
        coord[0] = (float)pt2.X(); coord[1] = (float)pt2.Y(); coord[2] = (float)pt2.Z();               
        cout << "( " << coord[0] << ", " << coord[1] << ", " << coord[2] << " )" << endl;        
    }
}

//************************************
// Method:    topoFaceTranslater
// FullName:  topoFaceTranslater
// Access:    public
// Returns:   void
// Qualifier: 转化面数据,将其三角化为表面三角Mesh
// Parameter: const TopoDS_Shape & topoShape
//************************************
void topoFaceTranslater(const TopoDS_Shape& topoShape)
{   
    TopoDS_Face topoFace = TopoDS::Face(topoShape);
   
    if (topoFace.IsNull())
    {
        return;
    }
        
    TopLoc_Location aLoc;   
    Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(topoFace, aLoc);
   
    if(aPoly.IsNull())
    {
        return;
    }
   
    gp_Trsf myTransf;
    Standard_Boolean identity = true;
    if(!aLoc.IsIdentity())  
    {
        identity = false;
        myTransf = aLoc.Transformation();
    }

    Standard_Integer nbNodesInFace = aPoly->NbNodes();
    Standard_Integer nbTriInFace = aPoly->NbTriangles();

    const Poly_Array1OfTriangle& Triangles = aPoly->Triangles();
    const TColgp_Array1OfPnt& Nodes = aPoly->Nodes();

    // 获取顶点数据
    cout << "顶点数据:" << endl;
    for(Standard_Integer i=1;i<=nbNodesInFace;i++)
    {
        gp_Pnt P = Nodes(i);
        float coord[3];
        if(!identity) P.Transform(myTransf);
        coord[0] = (float)P.X(); coord[1] = (float)P.Y(); coord[2] = (float)P.Z();

        cout << i-1 << ": ( " << coord[0] << ", " << coord[1] << ", " << coord[2] << " )" << endl;        
    }

    // 获取三角网拓扑数据
    cout << "三角网拓扑数据:" << endl;
    for(Standard_Integer i=1;i<=nbTriInFace;i++)
    {
        // Get the triangle
        Standard_Integer N1,N2,N3;
        Triangles(i).Get(N1,N2,N3);

        int pts[3];
        pts[0] = N1-1; pts[1] = N2-1; pts[2] = N3-1;
        cout << i-1 << ": ( " << pts[0] << ", " << pts[1] << ", " << pts[2] << " )" << endl;        
    }
}

//************************************
// Method:    topoVertexTranslater
// FullName:  topoVertexTranslater
// Access:    public
// Returns:   void
// Qualifier: 转换顶点
// Parameter: const TopoDS_Shape & topoShape
//************************************
void topoVertexTranslater(const TopoDS_Shape& topoShape)
{   
    // TODO:
}



//************************************
// Method:    translationDispatch
// FullName:  translationDispatch
// Access:    public
// Returns:   void
// Qualifier: OCC TopoDS_Shape数据转换入口
// Parameter: const TopoDS_Shape & topoShape
//************************************
void translationDispatch(const TopoDS_Shape& topoShape)
{   
    if (topoShape.IsNull())
    {
        return;
    }

    switch(topoShape.ShapeType())
    {
    case TopAbs_EDGE:        
        cout << "TopAbs_EDGE" << endl;            
        break;        
    case TopAbs_FACE:        
        cout << "TopAbs_FACE" << endl;        
        break;
    case TopAbs_SHAPE:        
        cout << "TopAbs_SHAPE" << endl;        
        break;
    case TopAbs_SHELL:        
        cout << "TopAbs_SHELL" << endl;               
        break;
    case TopAbs_SOLID:        
        cout << "TopAbs_SOLID" << endl;        
        break;
    case TopAbs_VERTEX:        
        cout << "TopAbs_VERTEX" << endl;            
        break;
    case TopAbs_WIRE:        
        cout << "TopAbs_WIRE" << endl;            
        break;        
    case TopAbs_COMPOUND:        
        cout << "TopAbs_COMPOUND" << endl;
        break;
    case TopAbs_COMPSOLID:        
        cout << "TopAbs_COMPSOLID" << endl;            
        break;
    default:        
        break;
    }

    switch(topoShape.ShapeType())
    {
    case TopAbs_EDGE:                    
        topoEdgeTranslater(topoShape);
        break;        
    case TopAbs_FACE:                    
        topoFaceTranslater(topoShape);        
        break;
    case TopAbs_VERTEX:
        topoVertexTranslater(topoShape);
        break;
    case TopAbs_SHAPE:        
    case TopAbs_SHELL:        
    case TopAbs_SOLID:            
    case TopAbs_WIRE:        
    case TopAbs_COMPOUND:        
    case TopAbs_COMPSOLID:
        {
            TopoDS_Iterator anIt;
            TopoDS_Shape aSTmp;   

            anIt.Initialize(topoShape);

            for (; anIt.More(); anIt.Next())
            {        
                aSTmp=anIt.Value();

                if (!aSTmp.IsNull())
                {
                    translationDispatch(aSTmp);
                }
            }
        }
        break;
    default:
        break;
    }
}


int main(int argc, char** argv)
{
    TopoDS_Shape theTorus = BRepPrimAPI_MakeTorus(60.0, 20.0);

    gp_Pln P(1,2,1,-15);

    TopoDS_Shape pSection = BRepAlgoAPI_Section(theTorus,P);  

    TopoDS_Shape theBox = BRepPrimAPI_MakeBox(200,60,60);

    translationDispatch(theBox);

    return 0;
}
 楼主| 发表于 2007-11-28 11:59:40 | 显示全部楼层

回复: 【转帖】我执行Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulati

子优 11:01:02
在translationDispatch(theBox);之前
薛定谔的猫 11:01:13

子优 11:01:27
    BRepMesh::Mesh(theBox, 0.5);
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|小黑屋|几何尺寸与公差论坛

GMT+8, 2024-12-22 11:22 , Processed in 0.039539 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表