Mesh Count

Mesh Count

john4TMYX
Enthusiast Enthusiast
877 Views
4 Replies
Message 1 of 5

Mesh Count

john4TMYX
Enthusiast
Enthusiast

Hi guys,

 

I have a face. Now I want to have the meshes from the face. 

 

Ptr<MeshManager> meshMgr = face_ptr->meshManager();
Ptr<TriangleMeshList> meshList = meshMgr->displayMeshes();
Ptr<TriangleMesh> pmesh = meshList->bestMesh();
std::vector<Ptr<Point3D>> mesh_xyz = pmesh->nodeCoordinates();
int triangle_count = pmesh->triangleCount();
std::vector<int> triangle_index = pmesh->nodeIndices();
int face_count = triangle_count / 3;
 
Then I can access the triangles:
for (int i = 0; i < face_count; i++)
{
int idx0 = triangle_index[i * 3];
int idx1 = triangle_index[i * 3 + 1];
int idx2 = triangle_index[i * 3 + 2];
 
Is this the right way?
 
I need all the mesh xyz to do my calculations. 
 
Thank you.
Regards
John
0 Likes
Accepted solutions (1)
878 Views
4 Replies
Replies (4)
Message 2 of 5

MichaelT_123
Advisor
Advisor

Hi  Mr John4TMYX,

 

...Yes and No.

Meshes can come in different forms, ... triangular, quad or even polygonal.

 

polygonCountReturns the number of polygons (more than 4 sides) in the mesh.
polygonNodeIndicesReturns the index values that index into the NodeCoordinates and NormalVectors arrays to define the coordinates of each polygon and the corresponding normal.
quadCountReturns the number of quads in the mesh.
quadNodeIndicesReturns the index values that index into the NodeCoordinates and NormalVectors arrays to define the four coordinates of each quad and the corresponding normal.
triangleCountReturns the number of triangles in the mesh.
triangleNodeIndices

Returns the index values that index into the NodeCoordinates and NormalVectors arrays to define the three coordinates of each triangle and the corresponding normal.

... thus you have to address such diversity first ... unless you are sure that your mesh is of triangular type.

If the latter is the case ... the rest is easy.

 

myTriangleCoordsLst = []   

for tC in triangleCount:

     myTriangleCoord = [nodeCoordinates[triangleNodeIndices[3*tC+0]],

                                         nodeCoordinates[triangleNodeIndices[3*tC+1]],

                                         nodeCoordinates[triangleNodeIndices[3*tC+2]]]

    myTriangleCoordsLst.append(myTriangleCoord )

 

The code is similar or even the same as the one you presented ... as per my 5 sec glimpse.

 

Regards

MichaelT

 

MichaelT
Message 3 of 5

john4TMYX
Enthusiast
Enthusiast

 

but I use the following way to get the mesh from a face:

 

Ptr<MeshManager> meshMgr = face_ptr->meshManager();
Ptr<TriangleMeshList> meshList = meshMgr->displayMeshes();

 

so I assume that the mesh should be triangle mesh, right?

I have printed all the mesh, it is not right at all. 

 

Here is the code snippet:

Ptr<TriangleMesh> pmesh                    = meshList->bestMesh();

std::vector<Ptr<Point3D>> mesh_xyz = pmesh->nodeCoordinates();
int triangle_count                                   = pmesh->triangleCount();
std::vector<int> triangle_index            = pmesh->nodeIndices();
int face_count = triangle_count / 3;
for (int i = 0; i < face_count; i++)
{
            int idx0 = triangle_index[i * 3];
            int idx1 = triangle_index[i * 3 + 1];
            int idx2 = triangle_index[i * 3 + 2];
 
           ON_3dPoint pnt0, pnt1, pnt2;
          ComUtils::get_Point(mesh_xyz[idx0], pnt0);
          ComUtils::get_Point(mesh_xyz[idx1], pnt1);
          ComUtils::get_Point(mesh_xyz[idx2], pnt2);
           ...
}
 
I can't think of other ways to do it based on the document I have read. but the result is not right!
0 Likes
Message 4 of 5

MichaelT_123
Advisor
Advisor
Accepted solution

Hi Mr John4TMYX,

 

       int face_count = triangle_count / 3      ????

what about:

       int face_count = triangle_count 

 

... and by the way ... consider using F360 API to keep consistency of the code.

 

Regards

MichaelT

 

MichaelT
0 Likes
Message 5 of 5

john4TMYX
Enthusiast
Enthusiast

how do you access the xyz for each face?

0 Likes