gmio_support: hide internal API of the OpenCascade iterators
This commit is contained in:
parent
6c0e50cac4
commit
2f3f1afe9f
@ -22,37 +22,6 @@
|
||||
#include <TopoDS.hxx>
|
||||
#include <TopoDS_Face.hxx>
|
||||
|
||||
namespace internal {
|
||||
|
||||
static void occshape_get_triangle(
|
||||
const void* cookie, uint32_t /*tri_id*/, gmio_stl_triangle* tri)
|
||||
{
|
||||
void* wcookie = const_cast<void*>(cookie);
|
||||
gmio_stl_occshape_iterator* it =
|
||||
static_cast<gmio_stl_occshape_iterator*>(wcookie);
|
||||
|
||||
const bool reversed = it->face_is_reversed();
|
||||
const gp_Trsf& trsf = it->face_trsf();
|
||||
const TColgp_Array1OfPnt* nodes = it->face_nodes();
|
||||
int n1, n2, n3; // Node index
|
||||
it->face_current_triangle()->Get(n1, n2, n3);
|
||||
gp_Pnt p1 = nodes->Value(n1);
|
||||
gp_Pnt p2 = nodes->Value(reversed ? n3 : n2);
|
||||
gp_Pnt p3 = nodes->Value(reversed ? n2 : n3);
|
||||
if (trsf.Form() != gp_Identity) {
|
||||
p1.Transform(trsf);
|
||||
p2.Transform(trsf);
|
||||
p3.Transform(trsf);
|
||||
}
|
||||
gmio_stl_occ_copy_xyz(&tri->v1, p1.XYZ());
|
||||
gmio_stl_occ_copy_xyz(&tri->v2, p2.XYZ());
|
||||
gmio_stl_occ_copy_xyz(&tri->v3, p3.XYZ());
|
||||
gmio_stl_triangle_compute_normal(tri);
|
||||
it->move_to_next_tri();
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
|
||||
gmio_stl_mesh gmio_stl_occmesh(const gmio_stl_occshape_iterator& it)
|
||||
{
|
||||
gmio_stl_mesh mesh = {};
|
||||
@ -69,7 +38,8 @@ gmio_stl_mesh gmio_stl_occmesh(const gmio_stl_occshape_iterator& it)
|
||||
}
|
||||
}
|
||||
|
||||
mesh.func_get_triangle = internal::occshape_get_triangle;
|
||||
//mesh.func_get_triangle = internal::occshape_get_triangle;
|
||||
mesh.func_get_triangle = &gmio_stl_occshape_iterator::get_triangle;
|
||||
return mesh;
|
||||
}
|
||||
|
||||
@ -92,6 +62,35 @@ gmio_stl_occshape_iterator::gmio_stl_occshape_iterator(const TopoDS_Shape& shape
|
||||
}
|
||||
}
|
||||
|
||||
void gmio_stl_occshape_iterator::get_triangle(
|
||||
const void *cookie, uint32_t /*tri_id*/, gmio_stl_triangle *tri)
|
||||
{
|
||||
void* wcookie = const_cast<void*>(cookie);
|
||||
gmio_stl_occshape_iterator* it =
|
||||
static_cast<gmio_stl_occshape_iterator*>(wcookie);
|
||||
|
||||
const bool reversed = it->m_face_is_reversed;
|
||||
const gp_Trsf& trsf = it->m_face_trsf;
|
||||
const TColgp_Array1OfPnt* nodes = it->m_face_nodes;
|
||||
int n1, n2, n3; // Node index
|
||||
const Poly_Triangle& curr_tri =
|
||||
it->m_face_triangles->Value(it->m_face_tri_id);
|
||||
curr_tri.Get(n1, n2, n3);
|
||||
gp_Pnt p1 = nodes->Value(n1);
|
||||
gp_Pnt p2 = nodes->Value(reversed ? n3 : n2);
|
||||
gp_Pnt p3 = nodes->Value(reversed ? n2 : n3);
|
||||
if (trsf.Form() != gp_Identity) {
|
||||
p1.Transform(trsf);
|
||||
p2.Transform(trsf);
|
||||
p3.Transform(trsf);
|
||||
}
|
||||
gmio_stl_occ_copy_xyz(&tri->v1, p1.XYZ());
|
||||
gmio_stl_occ_copy_xyz(&tri->v2, p2.XYZ());
|
||||
gmio_stl_occ_copy_xyz(&tri->v3, p3.XYZ());
|
||||
gmio_stl_triangle_compute_normal(tri);
|
||||
it->move_to_next_tri();
|
||||
}
|
||||
|
||||
bool gmio_stl_occshape_iterator::move_to_next_tri()
|
||||
{
|
||||
++m_face_tri_id;
|
||||
|
@ -55,25 +55,22 @@ gmio_stl_mesh gmio_stl_occmesh(const gmio_stl_occshape_iterator& it);
|
||||
|
||||
/*! Forward iterator over the triangles of OpenCascade's TopoDS_Shape
|
||||
*
|
||||
* It is used to iterate efficiently over the triangles of all internally
|
||||
* triangulated sub faces
|
||||
*
|
||||
* Don't use API of this class, it's intended to gmio_stl_occmesh()
|
||||
* It is used to iterate over the triangles of all triangulated sub faces(the
|
||||
* Poly_Triangulation object).
|
||||
*/
|
||||
struct gmio_stl_occshape_iterator
|
||||
{
|
||||
gmio_stl_occshape_iterator();
|
||||
explicit gmio_stl_occshape_iterator(const TopoDS_Shape& shape);
|
||||
|
||||
inline const TopoDS_Shape* shape() const;
|
||||
|
||||
bool move_to_next_tri();
|
||||
inline bool face_is_reversed() const;
|
||||
inline const gp_Trsf& face_trsf() const;
|
||||
inline const TColgp_Array1OfPnt* face_nodes() const;
|
||||
inline const Poly_Triangle* face_current_triangle() const;
|
||||
inline const TopoDS_Shape* shape() const { return m_shape; }
|
||||
|
||||
private:
|
||||
friend gmio_stl_mesh gmio_stl_occmesh(const gmio_stl_occshape_iterator&);
|
||||
static void get_triangle(
|
||||
const void* cookie, uint32_t tri_id, gmio_stl_triangle* tri);
|
||||
|
||||
bool move_to_next_tri();
|
||||
void reset_face();
|
||||
void cache_face(const TopoDS_Face& face);
|
||||
|
||||
@ -88,29 +85,5 @@ private:
|
||||
int m_face_last_tri_id;
|
||||
};
|
||||
|
||||
|
||||
#ifndef DOXYGEN
|
||||
|
||||
/*
|
||||
* Implementation
|
||||
*/
|
||||
|
||||
const TopoDS_Shape *gmio_stl_occshape_iterator::shape() const
|
||||
{ return m_shape; }
|
||||
|
||||
bool gmio_stl_occshape_iterator::face_is_reversed() const
|
||||
{ return m_face_is_reversed; }
|
||||
|
||||
const gp_Trsf &gmio_stl_occshape_iterator::face_trsf() const
|
||||
{ return m_face_trsf; }
|
||||
|
||||
const TColgp_Array1OfPnt *gmio_stl_occshape_iterator::face_nodes() const
|
||||
{ return m_face_nodes; }
|
||||
|
||||
const Poly_Triangle *gmio_stl_occshape_iterator::face_current_triangle() const
|
||||
{ return &m_face_triangles->Value(m_face_tri_id); }
|
||||
|
||||
#endif /* !DOXYGEN */
|
||||
|
||||
#endif /* GMIO_SUPPORT_STL_OCC_BREP_H */
|
||||
/*! @} */
|
||||
|
@ -48,27 +48,6 @@ static void occmesh_add_triangle(
|
||||
n.x, n.y, n.z);
|
||||
}
|
||||
|
||||
static void occmesh_get_triangle(
|
||||
const void* cookie, uint32_t tri_id, gmio_stl_triangle* tri)
|
||||
{
|
||||
void* wcookie = const_cast<void*>(cookie);
|
||||
gmio_stl_occmesh_iterator* it =
|
||||
static_cast<gmio_stl_occmesh_iterator*>(wcookie);
|
||||
|
||||
if (it->move_to_next_tri(tri_id)) {
|
||||
int iv1, iv2, iv3;
|
||||
double nx, ny, nz;
|
||||
const Handle_StlMesh_MeshTriangle& occTri = it->domain_tri(tri_id);
|
||||
occTri->GetVertexAndOrientation(iv1, iv2, iv3, nx, ny, nz);
|
||||
gmio_stl_occ_copy_xyz(&tri->n, nx, ny, nz);
|
||||
|
||||
const TColgp_SequenceOfXYZ& vertices = it->domain_vertices();
|
||||
gmio_stl_occ_copy_xyz(&tri->v1, vertices.Value(iv1));
|
||||
gmio_stl_occ_copy_xyz(&tri->v2, vertices.Value(iv2));
|
||||
gmio_stl_occ_copy_xyz(&tri->v3, vertices.Value(iv3));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
|
||||
gmio_stl_mesh gmio_stl_occmesh(const gmio_stl_occmesh_iterator& it)
|
||||
@ -78,7 +57,7 @@ gmio_stl_mesh gmio_stl_occmesh(const gmio_stl_occmesh_iterator& it)
|
||||
const int domain_count = it.mesh() != NULL ? it.mesh()->NbDomains() : 0;
|
||||
for (int dom_id = 1; dom_id <= domain_count; ++dom_id)
|
||||
mesh.triangle_count += it.mesh()->NbTriangles(dom_id);
|
||||
mesh.func_get_triangle = internal::occmesh_get_triangle;
|
||||
mesh.func_get_triangle = gmio_stl_occmesh_iterator::get_triangle;
|
||||
return mesh;
|
||||
}
|
||||
|
||||
@ -110,6 +89,30 @@ gmio_stl_occmesh_iterator::gmio_stl_occmesh_iterator(const Handle_StlMesh_Mesh &
|
||||
this->init(internal::occMeshPtr(hnd));
|
||||
}
|
||||
|
||||
void gmio_stl_occmesh_iterator::get_triangle(
|
||||
const void *cookie, uint32_t tri_id, gmio_stl_triangle *tri)
|
||||
{
|
||||
void* wcookie = const_cast<void*>(cookie);
|
||||
gmio_stl_occmesh_iterator* it =
|
||||
static_cast<gmio_stl_occmesh_iterator*>(wcookie);
|
||||
|
||||
if (it->move_to_next_tri(tri_id)) {
|
||||
const int dom_tri_id = tri_id - it->m_domain_first_tri_id + 1;
|
||||
const Handle_StlMesh_MeshTriangle& occTri =
|
||||
it->m_domain_triangles->Value(dom_tri_id);
|
||||
|
||||
int iv1, iv2, iv3;
|
||||
double nx, ny, nz;
|
||||
occTri->GetVertexAndOrientation(iv1, iv2, iv3, nx, ny, nz);
|
||||
gmio_stl_occ_copy_xyz(&tri->n, nx, ny, nz);
|
||||
|
||||
const TColgp_SequenceOfXYZ* vertices = it->m_domain_vertices;
|
||||
gmio_stl_occ_copy_xyz(&tri->v1, vertices->Value(iv1));
|
||||
gmio_stl_occ_copy_xyz(&tri->v2, vertices->Value(iv2));
|
||||
gmio_stl_occ_copy_xyz(&tri->v3, vertices->Value(iv3));
|
||||
}
|
||||
}
|
||||
|
||||
void gmio_stl_occmesh_iterator::init(const StlMesh_Mesh* mesh)
|
||||
{
|
||||
m_mesh = mesh;
|
||||
|
@ -70,10 +70,8 @@ gmio_stl_mesh_creator gmio_stl_occmesh_creator(const Handle_StlMesh_Mesh& hnd);
|
||||
|
||||
/*! Forward iterator over the triangles of OpenCascade's StlMesh_Mesh
|
||||
*
|
||||
* It is used to iterate efficiently over the triangles of all domains within
|
||||
* It is used internally to iterate over the triangles of all domains within
|
||||
* a StlMesh_Mesh object.
|
||||
*
|
||||
* Don't use API of this class, it's intended to gmio_stl_occmesh()
|
||||
*/
|
||||
struct gmio_stl_occmesh_iterator
|
||||
{
|
||||
@ -81,13 +79,14 @@ struct gmio_stl_occmesh_iterator
|
||||
explicit gmio_stl_occmesh_iterator(const StlMesh_Mesh* mesh);
|
||||
explicit gmio_stl_occmesh_iterator(const Handle_StlMesh_Mesh& hnd);
|
||||
|
||||
inline const StlMesh_Mesh* mesh() const;
|
||||
|
||||
bool move_to_next_tri(uint32_t tri_id);
|
||||
inline const Handle_StlMesh_MeshTriangle& domain_tri(uint32_t tri_id) const;
|
||||
inline const TColgp_SequenceOfXYZ& domain_vertices() const;
|
||||
inline const StlMesh_Mesh* mesh() const { return m_mesh; }
|
||||
|
||||
private:
|
||||
friend gmio_stl_mesh gmio_stl_occmesh(const gmio_stl_occmesh_iterator&);
|
||||
static void get_triangle(
|
||||
const void* cookie, uint32_t tri_id, gmio_stl_triangle* tri);
|
||||
|
||||
bool move_to_next_tri(uint32_t tri_id);
|
||||
void init(const StlMesh_Mesh* mesh);
|
||||
void cache_domain(int dom_id);
|
||||
|
||||
@ -100,26 +99,5 @@ private:
|
||||
uint32_t m_domain_last_tri_id;
|
||||
};
|
||||
|
||||
#ifndef DOXYGEN
|
||||
|
||||
/*
|
||||
* Implementation
|
||||
*/
|
||||
|
||||
const Handle_StlMesh_MeshTriangle&
|
||||
gmio_stl_occmesh_iterator::domain_tri(uint32_t tri_id) const
|
||||
{
|
||||
const int dom_tri_id = tri_id - m_domain_first_tri_id + 1;
|
||||
return m_domain_triangles->Value(dom_tri_id);
|
||||
}
|
||||
|
||||
const TColgp_SequenceOfXYZ &gmio_stl_occmesh_iterator::domain_vertices() const
|
||||
{ return *m_domain_vertices; }
|
||||
|
||||
const StlMesh_Mesh *gmio_stl_occmesh_iterator::mesh() const
|
||||
{ return m_mesh; }
|
||||
|
||||
#endif /* !DOXYGEN */
|
||||
|
||||
#endif /* GMIO_SUPPORT_STL_OCC_MESH_H */
|
||||
/*! @} */
|
||||
|
@ -22,41 +22,6 @@
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
namespace internal {
|
||||
|
||||
static void occmesh_datasource_get_triangle(
|
||||
const void* cookie, uint32_t /*tri_id*/, gmio_stl_triangle* tri)
|
||||
{
|
||||
void* wcookie = const_cast<void*>(cookie);
|
||||
gmio_stl_occmesh_datasource_iterator* it =
|
||||
static_cast<gmio_stl_occmesh_datasource_iterator*>(wcookie);
|
||||
const MeshVS_DataSource* data_src = it->data_src();
|
||||
|
||||
int node_count;
|
||||
MeshVS_EntityType entity_type;
|
||||
const Standard_Boolean get_geom_ok =
|
||||
data_src->GetGeom(
|
||||
it->current_element_key(),
|
||||
Standard_True, // Is element
|
||||
it->cached_element_coords(),
|
||||
node_count,
|
||||
entity_type);
|
||||
if (get_geom_ok && node_count == 3) {
|
||||
// Copy vertex coords
|
||||
const TColStd_Array1OfReal& in_coords_array = it->cached_element_coords();
|
||||
float* out_coords_ptr = &tri->v1.x;
|
||||
for (int i = 0; i < 9; ++i)
|
||||
out_coords_ptr[i] = static_cast<float>(in_coords_array.Value(i + 1));
|
||||
// Copy normal coords
|
||||
double nx, ny, nz;
|
||||
data_src->GetNormal(it->current_element_key(), 3, nx, ny, nz);
|
||||
gmio_stl_occ_copy_xyz(&tri->n, nx, ny, nz);
|
||||
}
|
||||
it->move_to_next_tri();
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
|
||||
gmio_stl_mesh gmio_stl_occmesh(const gmio_stl_occmesh_datasource_iterator& it)
|
||||
{
|
||||
gmio_stl_mesh mesh = {};
|
||||
@ -64,7 +29,7 @@ gmio_stl_mesh gmio_stl_occmesh(const gmio_stl_occmesh_datasource_iterator& it)
|
||||
mesh.triangle_count =
|
||||
it.data_src() != NULL ?
|
||||
it.data_src()->GetAllElements().Extent() : 0;
|
||||
mesh.func_get_triangle = internal::occmesh_datasource_get_triangle;
|
||||
mesh.func_get_triangle = gmio_stl_occmesh_datasource_iterator::get_triangle;
|
||||
return mesh;
|
||||
}
|
||||
|
||||
@ -90,3 +55,36 @@ gmio_stl_occmesh_datasource_iterator::gmio_stl_occmesh_datasource_iterator(
|
||||
if (m_data_src != NULL)
|
||||
m_element_it.Initialize(m_data_src->GetAllElements());
|
||||
}
|
||||
|
||||
void gmio_stl_occmesh_datasource_iterator::get_triangle(
|
||||
const void *cookie, uint32_t /*tri_id*/, gmio_stl_triangle *tri)
|
||||
{
|
||||
void* wcookie = const_cast<void*>(cookie);
|
||||
gmio_stl_occmesh_datasource_iterator* it =
|
||||
static_cast<gmio_stl_occmesh_datasource_iterator*>(wcookie);
|
||||
const MeshVS_DataSource* data_src = it->data_src();
|
||||
const int curr_element_key = it->m_element_it.Key();
|
||||
TColStd_Array1OfReal& element_coords = it->m_element_coords;
|
||||
|
||||
int node_count;
|
||||
MeshVS_EntityType entity_type;
|
||||
const Standard_Boolean get_geom_ok =
|
||||
data_src->GetGeom(
|
||||
curr_element_key,
|
||||
Standard_True, // Is element
|
||||
element_coords,
|
||||
node_count,
|
||||
entity_type);
|
||||
if (get_geom_ok && node_count == 3) {
|
||||
// Copy vertex coords
|
||||
const TColStd_Array1OfReal& in_coords_array = element_coords;
|
||||
float* out_coords_ptr = &tri->v1.x;
|
||||
for (int i = 0; i < 9; ++i)
|
||||
out_coords_ptr[i] = static_cast<float>(in_coords_array.Value(i + 1));
|
||||
// Copy normal coords
|
||||
double nx, ny, nz;
|
||||
data_src->GetNormal(curr_element_key, 3, nx, ny, nz);
|
||||
gmio_stl_occ_copy_xyz(&tri->n, nx, ny, nz);
|
||||
}
|
||||
it->m_element_it.Next();
|
||||
}
|
||||
|
@ -57,8 +57,6 @@ gmio_stl_mesh gmio_stl_occmesh(const gmio_stl_occmesh_datasource_iterator& it);
|
||||
* It is used to iterate efficiently over the elements of a MeshVS_DataSource
|
||||
* object.\n
|
||||
* Each element should be of type MeshVS_ET_Face and made of 3 nodes.
|
||||
*
|
||||
* Don't use API of this class, it's intended to gmio_stl_occmesh()
|
||||
*/
|
||||
struct gmio_stl_occmesh_datasource_iterator
|
||||
{
|
||||
@ -66,37 +64,18 @@ struct gmio_stl_occmesh_datasource_iterator
|
||||
explicit gmio_stl_occmesh_datasource_iterator(const MeshVS_DataSource* data_src);
|
||||
explicit gmio_stl_occmesh_datasource_iterator(const Handle_MeshVS_DataSource& hnd);
|
||||
|
||||
inline const MeshVS_DataSource* data_src() const;
|
||||
|
||||
inline void move_to_next_tri();
|
||||
inline int current_element_key() const;
|
||||
inline TColStd_Array1OfReal& cached_element_coords();
|
||||
inline const MeshVS_DataSource* data_src() const { return m_data_src; }
|
||||
|
||||
private:
|
||||
friend gmio_stl_mesh gmio_stl_occmesh(
|
||||
const gmio_stl_occmesh_datasource_iterator&);
|
||||
static void get_triangle(
|
||||
const void* cookie, uint32_t tri_id, gmio_stl_triangle* tri);
|
||||
|
||||
const MeshVS_DataSource* m_data_src;
|
||||
TColStd_MapIteratorOfPackedMapOfInteger m_element_it;
|
||||
TColStd_Array1OfReal m_element_coords;
|
||||
};
|
||||
|
||||
#ifndef DOXYGEN
|
||||
|
||||
/*
|
||||
* Implementation
|
||||
*/
|
||||
|
||||
void gmio_stl_occmesh_datasource_iterator::move_to_next_tri()
|
||||
{ m_element_it.Next(); }
|
||||
|
||||
int gmio_stl_occmesh_datasource_iterator::current_element_key() const
|
||||
{ return m_element_it.Key(); }
|
||||
|
||||
TColStd_Array1OfReal& gmio_stl_occmesh_datasource_iterator::cached_element_coords()
|
||||
{ return m_element_coords; }
|
||||
|
||||
const MeshVS_DataSource* gmio_stl_occmesh_datasource_iterator::data_src() const
|
||||
{ return m_data_src; }
|
||||
|
||||
#endif /* !DOXYGEN */
|
||||
|
||||
#endif /* GMIO_SUPPORT_STL_OCC_MESHVS_H */
|
||||
/*! @} */
|
||||
|
Loading…
Reference in New Issue
Block a user