View Issue Details

IDProjectCategoryView StatusLast Update
0033365CommunityOCCT:Data Exchangepublic2023-04-14 13:23
ReporterLyndon Alcock Assigned ToLyndon Alcock  
PrioritynormalSeverityjust a question 
Status feedbackResolutionopen 
PlatformWindowsOSVC++ 2022 
Product Version7.6.3 
Summary0033365: Data Exchange - How do I iterate over a mesh without doubling model edge vertices in open cascade?
DescriptionCurrently I am working on exporting from open cascade to off format however i cannot find within the API a way of iterating over all the indices in the model, my current work around is to use ```BRep_Tool::Triangulation(face, location)``` for each of the faces in the BRep however this is creating duplicate vertices for every vertex on the edge of the face, ideally i would like something that iterates over all of the vertices and faces in the model?

this is the current working code
std::vector<double> vertices;
    std::vector<int> indices;
    int index_count = 0;
    int triangle_count = 0;
    for (TopExp_Explorer explorer(shape, TopAbs_FACE); explorer.More(); explorer.Next()) {
        TopoDS_Face face = TopoDS::Face(explorer.Current());
        TopAbs_Orientation face_orientation = face.Orientation();
        TopLoc_Location location;

        Handle(Poly_Triangulation) triangulation = BRep_Tool::Triangulation(face, location);

        if (!triangulation.IsNull()) {

            int nb_nodes = triangulation->NbNodes();
            for (int node_index = 1; node_index <= nb_nodes; node_index++) {
                gp_Pnt node = triangulation->Node(node_index);


            int nb_triangles = triangulation->NbTriangles();
            for (int triangle_index = 1; triangle_index <= nb_triangles; triangle_index++) {
                int i0, i1, i2;
                Poly_Triangle triangle = triangulation->Triangle(triangle_index);
                triangle.Get(i0, i1, i2);
                indices.push_back(i0 - 1 + index_count);
                indices.push_back(i1 - 1 + index_count);
                indices.push_back(i2 - 1 + index_count);

            index_count += nb_nodes;
            triangle_count += nb_triangles;

ideally I would like get the triangulation of the whole model which I imagine would look something like this ```BRep_Tool::Triangulation(shape, location);```, however this does not exist?
TagsNo tags attached.
Test case number



2023-04-13 13:21

developer   ~0113380

Dear @Lyndon Alcock
We do not have functionality to get whole triangulation of the model.
But You can use code samples about writing mesh into some other formats, please make a look into:
We use RWMesh_FaceIterator and some additional tools for this.


2023-04-13 13:22

developer   ~0113381

Dear @Lyndon Alcock
Please use the forum for technical questions:

Lyndon Alcock

2023-04-14 13:23

reporter   ~0113382

I've managed to get it to work by storing double vertices as a map and converting the indices when exporting the code :)

Issue History

Date Modified Username Field Change
2023-04-13 11:16 Lyndon Alcock New Issue
2023-04-13 11:16 Lyndon Alcock Assigned To => ika
2023-04-13 13:18 dpasukhi Category OCCT:Application Framework => OCCT:Data Exchange
2023-04-13 13:18 dpasukhi Summary How do I iterate over a mesh without doubling model edge vertices in open cascade? => Data Exchange - How do I iterate over a mesh without doubling model edge vertices in open cascade?
2023-04-13 13:18 dpasukhi Description Updated
2023-04-13 13:18 dpasukhi Description Updated
2023-04-13 13:21 dpasukhi Note Added: 0113380
2023-04-13 13:21 dpasukhi Assigned To ika => Lyndon Alcock
2023-04-13 13:21 dpasukhi Status new => feedback
2023-04-13 13:22 dpasukhi Note Added: 0113381
2023-04-14 13:23 Lyndon Alcock Note Added: 0113382