diff --git a/src/gmio_support/stl_occ.cpp b/src/gmio_support/stl_occ.cpp index 47042df..289ef70 100644 --- a/src/gmio_support/stl_occ.cpp +++ b/src/gmio_support/stl_occ.cpp @@ -30,55 +30,59 @@ static StlMesh_Mesh* occMeshPtr(const Handle_StlMesh_Mesh& mesh) return mesh.operator->(); } -static void occmesh_add_triangle(void* cookie, - uint32_t tri_id, - const gmio_stl_triangle_t* tri) +static void occmesh_add_triangle( + void* cookie, uint32_t tri_id, const gmio_stl_triangle_t* tri) { StlMesh_Mesh* mesh = static_cast(cookie); if (tri_id == 0) mesh->AddDomain(); - mesh->AddTriangle(mesh->AddOnlyNewVertex(tri->v1.x, tri->v1.y, tri->v1.z), - mesh->AddOnlyNewVertex(tri->v2.x, tri->v2.y, tri->v2.z), - mesh->AddOnlyNewVertex(tri->v3.x, tri->v3.y, tri->v3.z), - tri->normal.x, tri->normal.y, tri->normal.z); + const gmio_stl_coords& v1 = tri->v1; + const gmio_stl_coords& v2 = tri->v2; + const gmio_stl_coords& v3 = tri->v3; + const gmio_stl_coords& n = tri->normal; + mesh->AddTriangle(mesh->AddOnlyNewVertex(v1.x, v1.y, v1.z), + mesh->AddOnlyNewVertex(v2.x, v2.y, v2.z), + mesh->AddOnlyNewVertex(v3.x, v3.y, v3.z), + n.x, n.y, n.z); } static void occmesh_get_triangle( - const void* cookie, uint32_t tri_id, gmio_stl_triangle_t* triangle) + const void* cookie, uint32_t tri_id, gmio_stl_triangle_t* tri) { const gmio_occ_stl_mesh_domain_t* mesh_domain = static_cast(cookie); - const StlMesh_SequenceOfMeshTriangle& occTriangles = - mesh_domain->mesh->Triangles(mesh_domain->domain_id); const Handle_StlMesh_MeshTriangle& occTri = - occTriangles.Value(tri_id + 1); - int v1; - int v2; - int v3; + mesh_domain->triangles()->Value(tri_id + 1); + int idV1; + int idV2; + int idV3; double xN; double yN; double zN; - occTri->GetVertexAndOrientation(v1, v2, v3, xN, yN, zN); - triangle->normal.x = float(xN); - triangle->normal.y = float(yN); - triangle->normal.z = float(zN); + occTri->GetVertexAndOrientation(idV1, idV2, idV3, xN, yN, zN); + gmio_stl_coords& n = tri->normal; + n.x = static_cast(xN); + n.y = static_cast(yN); + n.z = static_cast(zN); - const TColgp_SequenceOfXYZ& vertices = - mesh_domain->mesh->Vertices(mesh_domain->domain_id); - const gp_XYZ& coordsV1 = vertices.Value(v1); - const gp_XYZ& coordsV2 = vertices.Value(v2); - const gp_XYZ& coordsV3 = vertices.Value(v3); - triangle->v1.x = float(coordsV1.X()); - triangle->v2.x = float(coordsV2.X()); - triangle->v3.x = float(coordsV3.X()); + const TColgp_SequenceOfXYZ& vertices = *mesh_domain->vertices(); + const gp_XYZ& coordsV1 = vertices.Value(idV1); + gmio_stl_coords& v1 = tri->v1; + v1.x = static_cast(coordsV1.X()); + v1.y = static_cast(coordsV1.Y()); + v1.z = static_cast(coordsV1.Z()); - triangle->v1.y = float(coordsV1.Y()); - triangle->v2.y = float(coordsV2.Y()); - triangle->v3.y = float(coordsV3.Y()); + const gp_XYZ& coordsV2 = vertices.Value(idV2); + gmio_stl_coords& v2 = tri->v2; + v2.x = static_cast(coordsV2.X()); + v2.y = static_cast(coordsV2.Y()); + v2.z = static_cast(coordsV2.Z()); - triangle->v1.z = float(coordsV1.Z()); - triangle->v2.z = float(coordsV2.Z()); - triangle->v3.z = float(coordsV3.Z()); + const gp_XYZ& coordsV3 = vertices.Value(idV3); + gmio_stl_coords& v3 = tri->v3; + v3.x = static_cast(coordsV3.X()); + v3.y = static_cast(coordsV3.Y()); + v3.z = static_cast(coordsV3.Z()); } } // namespace internal @@ -87,9 +91,9 @@ gmio_stl_mesh_t gmio_stl_occmesh(const gmio_occ_stl_mesh_domain_t* mesh_domain) { gmio_stl_mesh_t mesh = {0}; mesh.cookie = mesh_domain; - if (mesh_domain != NULL && mesh_domain->mesh != NULL) { + if (mesh_domain != NULL && mesh_domain->mesh() != NULL) { mesh.triangle_count = - mesh_domain->mesh->NbTriangles(mesh_domain->domain_id); + mesh_domain->mesh()->NbTriangles(mesh_domain->domain_id()); } mesh.func_get_triangle = internal::occmesh_get_triangle; return mesh; @@ -109,22 +113,27 @@ gmio_stl_mesh_creator_t gmio_stl_hnd_occmesh_creator(const Handle_StlMesh_Mesh & } gmio_occ_stl_mesh_domain::gmio_occ_stl_mesh_domain() - : mesh(NULL), - domain_id(0) + : m_mesh(NULL), + m_domain_id(0), + m_triangles(NULL), + m_vertices(NULL) { } gmio_occ_stl_mesh_domain::gmio_occ_stl_mesh_domain( const StlMesh_Mesh *msh, int dom_id) - : mesh(msh), - domain_id(dom_id) - + : m_mesh(msh), + m_domain_id(dom_id), + m_triangles(&msh->Triangles(dom_id)), + m_vertices(&msh->Vertices(dom_id)) { } gmio_occ_stl_mesh_domain::gmio_occ_stl_mesh_domain( - const Handle_StlMesh_Mesh &hndMesh, int dom_id) - : mesh(internal::occMeshPtr(hndMesh)), - domain_id(dom_id) + const Handle_StlMesh_Mesh &hnd, int dom_id) + : m_mesh(internal::occMeshPtr(hnd)), + m_domain_id(dom_id), + m_triangles(&m_mesh->Triangles(dom_id)), + m_vertices(&m_mesh->Vertices(dom_id)) { } diff --git a/src/gmio_support/stl_occ.h b/src/gmio_support/stl_occ.h index 6016e62..bc41fbf 100644 --- a/src/gmio_support/stl_occ.h +++ b/src/gmio_support/stl_occ.h @@ -33,6 +33,8 @@ class Handle_StlMesh_Mesh; class StlMesh_Mesh; +class StlMesh_SequenceOfMeshTriangle; +class TColgp_SequenceOfXYZ; /*! Domain in a OpenCascade \c StlMesh_Mesh object * @@ -42,9 +44,18 @@ struct GMIO_LIBSUPPORT_EXPORT gmio_occ_stl_mesh_domain { gmio_occ_stl_mesh_domain(); gmio_occ_stl_mesh_domain(const StlMesh_Mesh* mesh, int dom_id = 1); - gmio_occ_stl_mesh_domain(const Handle_StlMesh_Mesh& hndMesh, int dom_id = 1); - const StlMesh_Mesh* mesh; - int domain_id; + gmio_occ_stl_mesh_domain(const Handle_StlMesh_Mesh& hnd, int dom_id = 1); + + inline const StlMesh_Mesh* mesh() const; + inline int domain_id() const; + inline const StlMesh_SequenceOfMeshTriangle* triangles() const; + inline const TColgp_SequenceOfXYZ* vertices() const; + +private: + const StlMesh_Mesh* m_mesh; + int m_domain_id; + const StlMesh_SequenceOfMeshTriangle* m_triangles; + const TColgp_SequenceOfXYZ* m_vertices; }; typedef struct gmio_occ_stl_mesh_domain gmio_occ_stl_mesh_domain_t; @@ -71,5 +82,23 @@ gmio_stl_mesh_creator_t gmio_stl_occmesh_creator(StlMesh_Mesh* mesh); GMIO_LIBSUPPORT_EXPORT gmio_stl_mesh_creator_t gmio_stl_hnd_occmesh_creator(const Handle_StlMesh_Mesh& hnd); + + +// -- +// -- Implementation +// -- + +const StlMesh_Mesh* gmio_occ_stl_mesh_domain::mesh() const +{ return m_mesh; } + +int gmio_occ_stl_mesh_domain::domain_id() const +{ return m_domain_id; } + +const StlMesh_SequenceOfMeshTriangle* gmio_occ_stl_mesh_domain::triangles() const +{ return m_triangles; } + +const TColgp_SequenceOfXYZ* gmio_occ_stl_mesh_domain::vertices() const +{ return m_vertices; } + #endif /* GMIO_SUPPORT_STL_OCC_H */ /*! @} */