gmio_support: cache OCC triangles and vertices arrays

This commit is contained in:
Hugues Delorme 2015-10-14 12:06:47 +02:00
parent f5c93e70fe
commit 83725f4201
2 changed files with 83 additions and 45 deletions

View File

@ -30,55 +30,59 @@ static StlMesh_Mesh* occMeshPtr(const Handle_StlMesh_Mesh& mesh)
return mesh.operator->(); return mesh.operator->();
} }
static void occmesh_add_triangle(void* cookie, static void occmesh_add_triangle(
uint32_t tri_id, void* cookie, uint32_t tri_id, const gmio_stl_triangle_t* tri)
const gmio_stl_triangle_t* tri)
{ {
StlMesh_Mesh* mesh = static_cast<StlMesh_Mesh*>(cookie); StlMesh_Mesh* mesh = static_cast<StlMesh_Mesh*>(cookie);
if (tri_id == 0) if (tri_id == 0)
mesh->AddDomain(); mesh->AddDomain();
mesh->AddTriangle(mesh->AddOnlyNewVertex(tri->v1.x, tri->v1.y, tri->v1.z), const gmio_stl_coords& v1 = tri->v1;
mesh->AddOnlyNewVertex(tri->v2.x, tri->v2.y, tri->v2.z), const gmio_stl_coords& v2 = tri->v2;
mesh->AddOnlyNewVertex(tri->v3.x, tri->v3.y, tri->v3.z), const gmio_stl_coords& v3 = tri->v3;
tri->normal.x, tri->normal.y, tri->normal.z); 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( 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 = const gmio_occ_stl_mesh_domain_t* mesh_domain =
static_cast<const gmio_occ_stl_mesh_domain_t*>(cookie); static_cast<const gmio_occ_stl_mesh_domain_t*>(cookie);
const StlMesh_SequenceOfMeshTriangle& occTriangles =
mesh_domain->mesh->Triangles(mesh_domain->domain_id);
const Handle_StlMesh_MeshTriangle& occTri = const Handle_StlMesh_MeshTriangle& occTri =
occTriangles.Value(tri_id + 1); mesh_domain->triangles()->Value(tri_id + 1);
int v1; int idV1;
int v2; int idV2;
int v3; int idV3;
double xN; double xN;
double yN; double yN;
double zN; double zN;
occTri->GetVertexAndOrientation(v1, v2, v3, xN, yN, zN); occTri->GetVertexAndOrientation(idV1, idV2, idV3, xN, yN, zN);
triangle->normal.x = float(xN); gmio_stl_coords& n = tri->normal;
triangle->normal.y = float(yN); n.x = static_cast<float>(xN);
triangle->normal.z = float(zN); n.y = static_cast<float>(yN);
n.z = static_cast<float>(zN);
const TColgp_SequenceOfXYZ& vertices = const TColgp_SequenceOfXYZ& vertices = *mesh_domain->vertices();
mesh_domain->mesh->Vertices(mesh_domain->domain_id); const gp_XYZ& coordsV1 = vertices.Value(idV1);
const gp_XYZ& coordsV1 = vertices.Value(v1); gmio_stl_coords& v1 = tri->v1;
const gp_XYZ& coordsV2 = vertices.Value(v2); v1.x = static_cast<float>(coordsV1.X());
const gp_XYZ& coordsV3 = vertices.Value(v3); v1.y = static_cast<float>(coordsV1.Y());
triangle->v1.x = float(coordsV1.X()); v1.z = static_cast<float>(coordsV1.Z());
triangle->v2.x = float(coordsV2.X());
triangle->v3.x = float(coordsV3.X());
triangle->v1.y = float(coordsV1.Y()); const gp_XYZ& coordsV2 = vertices.Value(idV2);
triangle->v2.y = float(coordsV2.Y()); gmio_stl_coords& v2 = tri->v2;
triangle->v3.y = float(coordsV3.Y()); v2.x = static_cast<float>(coordsV2.X());
v2.y = static_cast<float>(coordsV2.Y());
v2.z = static_cast<float>(coordsV2.Z());
triangle->v1.z = float(coordsV1.Z()); const gp_XYZ& coordsV3 = vertices.Value(idV3);
triangle->v2.z = float(coordsV2.Z()); gmio_stl_coords& v3 = tri->v3;
triangle->v3.z = float(coordsV3.Z()); v3.x = static_cast<float>(coordsV3.X());
v3.y = static_cast<float>(coordsV3.Y());
v3.z = static_cast<float>(coordsV3.Z());
} }
} // namespace internal } // 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}; gmio_stl_mesh_t mesh = {0};
mesh.cookie = mesh_domain; mesh.cookie = mesh_domain;
if (mesh_domain != NULL && mesh_domain->mesh != NULL) { if (mesh_domain != NULL && mesh_domain->mesh() != NULL) {
mesh.triangle_count = 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; mesh.func_get_triangle = internal::occmesh_get_triangle;
return mesh; 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() gmio_occ_stl_mesh_domain::gmio_occ_stl_mesh_domain()
: mesh(NULL), : m_mesh(NULL),
domain_id(0) m_domain_id(0),
m_triangles(NULL),
m_vertices(NULL)
{ {
} }
gmio_occ_stl_mesh_domain::gmio_occ_stl_mesh_domain( gmio_occ_stl_mesh_domain::gmio_occ_stl_mesh_domain(
const StlMesh_Mesh *msh, int dom_id) const StlMesh_Mesh *msh, int dom_id)
: mesh(msh), : m_mesh(msh),
domain_id(dom_id) 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( gmio_occ_stl_mesh_domain::gmio_occ_stl_mesh_domain(
const Handle_StlMesh_Mesh &hndMesh, int dom_id) const Handle_StlMesh_Mesh &hnd, int dom_id)
: mesh(internal::occMeshPtr(hndMesh)), : m_mesh(internal::occMeshPtr(hnd)),
domain_id(dom_id) m_domain_id(dom_id),
m_triangles(&m_mesh->Triangles(dom_id)),
m_vertices(&m_mesh->Vertices(dom_id))
{ {
} }

View File

@ -33,6 +33,8 @@
class Handle_StlMesh_Mesh; class Handle_StlMesh_Mesh;
class StlMesh_Mesh; class StlMesh_Mesh;
class StlMesh_SequenceOfMeshTriangle;
class TColgp_SequenceOfXYZ;
/*! Domain in a OpenCascade \c StlMesh_Mesh object /*! 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();
gmio_occ_stl_mesh_domain(const StlMesh_Mesh* mesh, int dom_id = 1); 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); gmio_occ_stl_mesh_domain(const Handle_StlMesh_Mesh& hnd, int dom_id = 1);
const StlMesh_Mesh* mesh;
int domain_id; 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; 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_LIBSUPPORT_EXPORT
gmio_stl_mesh_creator_t gmio_stl_hnd_occmesh_creator(const Handle_StlMesh_Mesh& hnd); 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 */ #endif /* GMIO_SUPPORT_STL_OCC_H */
/*! @} */ /*! @} */