Sun, 07/12/2020 - 17:18
Forums:
Hello,
in my application, I first import a file in the .STL format, storing its vertexes and triangles in two different arrays, and then I try to represent the imported geometry using Opencascade (7.4.0). Te following is the code I'm using to display the geometry starting from vertexes and triangles (of course each triangle is individuated by three indexes, one for vertex):
/*
int l_tri_number = GetTrianglesCount(); // this function gives the number of the triangles in the imported STL file
int l_vertex_number = GetVertexCount(); // this other function gives the number of vertexes (the duplicated vertexes are removed, so here I do not have a number equal to tri_number * 3, but a smaller one)
TColgp_Array1OfPnt l_vertex_array(0, (l_vertex_number-1));
for (long i_vert = 0; i_vert < l_vertex_number; i_vert++)
{
Vector3 l_vert1;
GetVertex(i_vert, l_vert1.x, l_vert1.y, l_vert1.z); // This function gets the three coordinates of the vertex with index i_vert
l_vertex_array(i_vert).SetX(l_vert1.m_x);
l_vertex_array(i_vert).SetY(l_vert1.m_y);
l_vertex_array(i_vert).SetZ(l_vert1.m_z);
} // end for (long i_vert = 0; i_vert < l_vertex_number; i_vert++)
Poly_Array1OfTriangle l_tri_array(0, (l_tri_number-1));
for (long i_tri = 0; i_tri < l_tri_number; i_tri++)
{
int l_idx_vertex1;
int l_idx_vertex2;
int l_idx_vertex3;
GetTrianglevertexIndexes(i_tri, l_idx_vertex1, l_idx_vertex2, l_idx_vertex3); // this function gives the indexes of the vertexes of the trinagle with index i_tri
Poly_Triangle l_triangle;
l_triangle.Set(l_idx_vertex1, l_idx_vertex2, l_idx_vertex3);
l_tri_array.SetValue(i_tri, l_triangle);
} // end for (long i_tri = 0; i_tri < l_tri_number; i_tri++)
//Poly_Triangulation l_poly(l_vertex_array, l_tri_array);
Handle(Poly_Triangulation) triangulation_shape = new Poly_Triangulation(l_vertex_array, l_tri_array);
//AIS_Triangulation l_mesh_tri(triangulation_shape);
Handle(AIS_Triangulation) l_display_mesh = new AIS_Triangulation(triangulation_shape);
myContext->Display(l_display_mesh, TRUE);
However the mesh is not displayed, I do not understand what I'm doing in the wrong way. Could you please help me to solve the problem??
Thank you very much in advance
Thu, 09/03/2020 - 09:49
Hello, you should create a MeshVS_DataSource before, using your triangulation data.
class MeshFromPolyTriangulation: public MeshVS_DataSource
{
// constructor
MeshFromPolyTriangulation(const Handle(Poly_Triangulation) &aPolyTriangulation) { ... }
//! implement other methods of the abstact class MeshVS_Mesh, at least GetAllElements, GetAllNodes, GetGeom, GetNormal, GetNodesByElement
}
Create a MeshVS_Mesh interactive:and set the data source
Handle(MeshVS_Mesh) aMesh = new MeshVS_Mesh();
Handle(MeshFromPolyTriangulation) aMeshDS = new MeshFromPolyTriangulation(triangulation_shape);
aMesh->setDataSource(aMeshDS);
Create a MeshVS_MeshPrsBuilder
Handle(MeshVS_MesgPrsBuilder) aBuilder = new MeshVS_MeshPrsBuilder();
aMesh->AdsBuildere(aBuilder);
Now you call call AIS_InterattiveContext::Displat(...) on aMesh
Play with display properties (color, mesh edges visibile Y/N, shrink, ...)
Ciao
Giovanni