#include "occ_libstl.h" #include #include #include #include #include /* Common */ static void occ_mesh_stl_add_triangle(Handle_StlMesh_Mesh* mesh, const foug_stl_triangle_t* tri) { 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); } /* ASCII STL */ static void occ_mesh_stla_igeom_begin_solid(foug_stla_geom_input_t* geom, const char* /*name*/) { Handle_StlMesh_Mesh* mesh = static_cast(geom->cookie); if (mesh->IsNull()) *mesh = new StlMesh_Mesh; (*mesh)->AddDomain(); } static void occ_mesh_stla_igeom_process_next_triangle(foug_stla_geom_input_t* geom, const foug_stl_triangle_t* tri) { Handle_StlMesh_Mesh* mesh = static_cast(geom->cookie); occ_mesh_stl_add_triangle(mesh, tri); } void foug_stla_geom_input_set_occmesh(foug_stla_geom_input_t* input, Handle_StlMesh_Mesh* mesh) { input->cookie = mesh; input->begin_solid_func = occ_mesh_stla_igeom_begin_solid; input->process_next_triangle_func = occ_mesh_stla_igeom_process_next_triangle; input->end_solid_func = NULL; } /* Binary STL */ static void occ_mesh_stlb_igeom_begin_triangles(foug_stlb_geom_input_t* geom, uint32_t /*count*/) { Handle_StlMesh_Mesh* mesh = static_cast(geom->cookie); *mesh = new StlMesh_Mesh; (*mesh)->AddDomain(); } static void occ_mesh_stlb_igeom_process_next_triangle(foug_stlb_geom_input_t* geom, const foug_stlb_triangle_t* face) { Handle_StlMesh_Mesh* mesh = static_cast(geom->cookie); occ_mesh_stl_add_triangle(mesh, &(face->data)); } void foug_stlb_geom_input_set_occmesh(foug_stlb_geom_input_t* input, Handle_StlMesh_Mesh* mesh) { input->cookie = mesh; input->process_header_func = NULL; input->begin_triangles_func = occ_mesh_stlb_igeom_begin_triangles; input->process_next_triangle_func = occ_mesh_stlb_igeom_process_next_triangle; input->end_triangles_func = NULL; } static void occ_mesh_stlb_ogeom_get_header(const foug_stlb_geom_output_t* /*geom*/, uint8_t* header) { std::memcpy(header, "Generated by libfougdatax-c", FOUG_STLB_HEADER_SIZE); } static uint32_t occ_mesh_stlb_ogeom_get_triangle_count(const foug_stlb_geom_output_t* geom) { Handle_StlMesh_Mesh* mesh = static_cast(geom->cookie); if ((*mesh)->NbDomains() >= 1) return (*mesh)->NbTriangles(1); return 0; } static void occ_mesh_stlb_ogeom_get_triangle(const foug_stlb_geom_output_t* geom, uint32_t index, foug_stlb_triangle_t* facet) { Handle_StlMesh_Mesh* mesh = static_cast(geom->cookie); const StlMesh_SequenceOfMeshTriangle& meshTriangles = (*mesh)->Triangles(1); const Handle_StlMesh_MeshTriangle tri = meshTriangles.Value(index + 1); Standard_Integer v1; Standard_Integer v2; Standard_Integer v3; Standard_Real xN; Standard_Real yN; Standard_Real zN; tri->GetVertexAndOrientation(v1, v2, v3, xN, yN, zN); facet->data.normal.x = xN; facet->data.normal.y = yN; facet->data.normal.z = zN; const TColgp_SequenceOfXYZ& vertices = (*mesh)->Vertices(1); const gp_XYZ& coordsV1 = vertices.Value(v1); const gp_XYZ& coordsV2 = vertices.Value(v2); const gp_XYZ& coordsV3 = vertices.Value(v3); facet->data.v1.x = coordsV1.X(); facet->data.v2.x = coordsV2.X(); facet->data.v3.x = coordsV3.X(); facet->data.v1.y = coordsV1.Y(); facet->data.v2.y = coordsV2.Y(); facet->data.v3.y = coordsV3.Y(); facet->data.v1.z = coordsV1.Z(); facet->data.v2.z = coordsV2.Z(); facet->data.v3.z = coordsV3.Z(); facet->attribute_byte_count = 0; } void foug_stlb_geom_output_set_occmesh(foug_stlb_geom_output_t* output, Handle_StlMesh_Mesh* mesh) { output->cookie = mesh; output->get_header_func = occ_mesh_stlb_ogeom_get_header; output->get_triangle_count_func = occ_mesh_stlb_ogeom_get_triangle_count; output->get_triangle_func = occ_mesh_stlb_ogeom_get_triangle; }