#include "occ_libstl.h" #include #include #include #include #include namespace internal { /* Common */ static StlMesh_Mesh* occMeshPtr(const Handle_StlMesh_Mesh& mesh) { return mesh.operator->(); } static void occmesh_add_triangle(void* cookie, uint32_t /*tri_id*/, const foug_stl_triangle_t* tri, void* /*dummy*/) { StlMesh_Mesh* mesh = static_cast(cookie); const int uId = mesh->AddOnlyNewVertex(tri->v1.x, tri->v1.y, tri->v1.z); const int vId = mesh->AddOnlyNewVertex(tri->v2.x, tri->v2.y, tri->v2.z); const int wId = mesh->AddOnlyNewVertex(tri->v3.x, tri->v3.y, tri->v3.z); mesh->AddTriangle(uId, vId, wId, tri->normal.x, tri->normal.y, tri->normal.z); } static void occmesh_get_triangle(const void* cookie, uint32_t tri_id, foug_stl_triangle_t* triangle) { const foug_OccStlMeshDomain* meshCookie = static_cast(cookie); const StlMesh_SequenceOfMeshTriangle& occTriangles = meshCookie->mesh->Triangles(meshCookie->domainId); const Handle_StlMesh_MeshTriangle& occTri = occTriangles.Value(tri_id + 1); Standard_Integer v1; Standard_Integer v2; Standard_Integer v3; Standard_Real xN; Standard_Real yN; Standard_Real zN; occTri->GetVertexAndOrientation(v1, v2, v3, xN, yN, zN); triangle->normal.x = float(xN); triangle->normal.y = float(yN); triangle->normal.z = float(zN); const TColgp_SequenceOfXYZ& vertices = meshCookie->mesh->Vertices(meshCookie->domainId); 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()); triangle->v1.y = float(coordsV1.Y()); triangle->v2.y = float(coordsV2.Y()); triangle->v3.y = float(coordsV3.Y()); triangle->v1.z = float(coordsV1.Z()); triangle->v2.z = float(coordsV2.Z()); triangle->v3.z = float(coordsV3.Z()); } static void occmesh_add_domain(void* cookie, void* /*dummy*/) { StlMesh_Mesh* mesh = static_cast(cookie); mesh->AddDomain(); } } // namespace internal void foug_stla_geom_input_set_occmesh(foug_stla_geom_input_t* input, const Handle_StlMesh_Mesh &mesh) { input->cookie = internal::occMeshPtr(mesh); input->begin_solid_func = (foug_stla_begin_solid_func_t)internal::occmesh_add_domain; input->process_triangle_func = (foug_stla_process_triangle_func_t)internal::occmesh_add_triangle; input->end_solid_func = NULL; } void foug_stla_geom_output_set_occmesh(foug_stla_geom_output_t *output, const foug_OccStlMeshDomain &meshCookie) { output->cookie = &meshCookie; output->solid_name = NULL; output->triangle_count = meshCookie.mesh->NbTriangles(meshCookie.domainId); output->get_triangle_func = internal::occmesh_get_triangle; } void foug_stlb_geom_input_set_occmesh(foug_stlb_geom_input_t* input, const Handle_StlMesh_Mesh &mesh) { input->cookie = internal::occMeshPtr(mesh); input->process_header_func = NULL; input->begin_triangles_func = (foug_stlb_begin_triangles_func_t)internal::occmesh_add_domain; input->process_triangle_func = (foug_stlb_process_triangle_func_t)internal::occmesh_add_triangle; input->end_triangles_func = NULL; } void foug_stlb_geom_output_set_occmesh(foug_stlb_geom_output_t* output, const foug_OccStlMeshDomain &meshCookie) { static const char occMeshBinaryHeader[] = "Generated by libfougdatax, occmesh geometry"; output->cookie = &meshCookie; output->header = reinterpret_cast(occMeshBinaryHeader); output->triangle_count = meshCookie.mesh->NbTriangles(meshCookie.domainId); output->get_triangle_func = internal::occmesh_get_triangle; } foug_OccStlMeshDomain::foug_OccStlMeshDomain(const Handle_StlMesh_Mesh &stlMesh, int stlDomainId) : mesh(stlMesh), domainId(stlDomainId) { }