2015-03-05 00:41:07 +08:00
|
|
|
/****************************************************************************
|
2015-05-28 15:40:24 +08:00
|
|
|
** gmio
|
2015-05-06 15:39:37 +08:00
|
|
|
** Copyright Fougue (2 Mar. 2015)
|
2015-07-13 17:42:03 +08:00
|
|
|
** contact@fougue.pro
|
2015-03-05 00:41:07 +08:00
|
|
|
**
|
|
|
|
** This software is a reusable library whose purpose is to provide complete
|
|
|
|
** I/O support for various CAD file formats (eg. STL)
|
|
|
|
**
|
|
|
|
** This software is governed by the CeCILL-B license under French law and
|
|
|
|
** abiding by the rules of distribution of free software. You can use,
|
|
|
|
** modify and/ or redistribute the software under the terms of the CeCILL-B
|
|
|
|
** license as circulated by CEA, CNRS and INRIA at the following URL
|
2015-03-30 15:05:25 +08:00
|
|
|
** "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html".
|
2015-03-05 00:41:07 +08:00
|
|
|
****************************************************************************/
|
|
|
|
|
2015-04-02 16:27:51 +08:00
|
|
|
#include <gmio_support/stl_occ.h>
|
2014-03-14 00:49:39 +08:00
|
|
|
|
2013-03-07 00:02:19 +08:00
|
|
|
#include <cstring>
|
|
|
|
#include <StlMesh_Mesh.hxx>
|
|
|
|
#include <StlMesh_MeshTriangle.hxx>
|
|
|
|
#include <StlMesh_SequenceOfMeshTriangle.hxx>
|
|
|
|
#include <TColgp_SequenceOfXYZ.hxx>
|
|
|
|
|
2014-01-27 22:03:50 +08:00
|
|
|
namespace internal {
|
|
|
|
|
2013-04-27 06:20:12 +08:00
|
|
|
/* Common */
|
2013-03-07 00:02:19 +08:00
|
|
|
|
2014-01-27 22:03:50 +08:00
|
|
|
static StlMesh_Mesh* occMeshPtr(const Handle_StlMesh_Mesh& mesh)
|
2013-03-07 00:02:19 +08:00
|
|
|
{
|
2015-03-20 00:31:08 +08:00
|
|
|
return mesh.operator->();
|
2013-03-07 00:02:19 +08:00
|
|
|
}
|
|
|
|
|
2015-10-14 18:06:47 +08:00
|
|
|
static void occmesh_add_triangle(
|
2015-12-04 01:00:25 +08:00
|
|
|
void* cookie, uint32_t tri_id, const struct gmio_stl_triangle* tri)
|
2013-03-07 00:02:19 +08:00
|
|
|
{
|
2015-03-20 00:31:08 +08:00
|
|
|
StlMesh_Mesh* mesh = static_cast<StlMesh_Mesh*>(cookie);
|
|
|
|
if (tri_id == 0)
|
|
|
|
mesh->AddDomain();
|
2015-10-14 18:06:47 +08:00
|
|
|
const gmio_stl_coords& v1 = tri->v1;
|
|
|
|
const gmio_stl_coords& v2 = tri->v2;
|
|
|
|
const gmio_stl_coords& v3 = tri->v3;
|
2016-01-21 00:47:30 +08:00
|
|
|
const gmio_stl_coords& n = tri->n;
|
2015-10-14 18:06:47 +08:00
|
|
|
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);
|
2013-03-07 00:02:19 +08:00
|
|
|
}
|
|
|
|
|
2015-03-20 00:31:08 +08:00
|
|
|
static void occmesh_get_triangle(
|
2015-12-04 01:00:25 +08:00
|
|
|
const void* cookie, uint32_t tri_id, struct gmio_stl_triangle* tri)
|
2013-03-07 00:02:19 +08:00
|
|
|
{
|
2015-12-04 01:00:25 +08:00
|
|
|
const struct gmio_occ_stl_mesh_domain* mesh_domain =
|
|
|
|
static_cast<const struct gmio_occ_stl_mesh_domain*>(cookie);
|
2015-03-20 00:31:08 +08:00
|
|
|
const Handle_StlMesh_MeshTriangle& occTri =
|
2015-10-14 18:06:47 +08:00
|
|
|
mesh_domain->triangles()->Value(tri_id + 1);
|
|
|
|
int idV1;
|
|
|
|
int idV2;
|
|
|
|
int idV3;
|
2015-09-02 18:07:17 +08:00
|
|
|
double xN;
|
|
|
|
double yN;
|
|
|
|
double zN;
|
2015-10-14 18:06:47 +08:00
|
|
|
occTri->GetVertexAndOrientation(idV1, idV2, idV3, xN, yN, zN);
|
2016-01-21 00:47:30 +08:00
|
|
|
gmio_stl_coords& n = tri->n;
|
2015-10-14 18:06:47 +08:00
|
|
|
n.x = static_cast<float>(xN);
|
|
|
|
n.y = static_cast<float>(yN);
|
|
|
|
n.z = static_cast<float>(zN);
|
|
|
|
|
|
|
|
const TColgp_SequenceOfXYZ& vertices = *mesh_domain->vertices();
|
|
|
|
const gp_XYZ& coordsV1 = vertices.Value(idV1);
|
|
|
|
gmio_stl_coords& v1 = tri->v1;
|
|
|
|
v1.x = static_cast<float>(coordsV1.X());
|
|
|
|
v1.y = static_cast<float>(coordsV1.Y());
|
|
|
|
v1.z = static_cast<float>(coordsV1.Z());
|
|
|
|
|
|
|
|
const gp_XYZ& coordsV2 = vertices.Value(idV2);
|
|
|
|
gmio_stl_coords& v2 = tri->v2;
|
|
|
|
v2.x = static_cast<float>(coordsV2.X());
|
|
|
|
v2.y = static_cast<float>(coordsV2.Y());
|
|
|
|
v2.z = static_cast<float>(coordsV2.Z());
|
|
|
|
|
|
|
|
const gp_XYZ& coordsV3 = vertices.Value(idV3);
|
|
|
|
gmio_stl_coords& v3 = tri->v3;
|
|
|
|
v3.x = static_cast<float>(coordsV3.X());
|
|
|
|
v3.y = static_cast<float>(coordsV3.Y());
|
|
|
|
v3.z = static_cast<float>(coordsV3.Z());
|
2013-03-07 00:02:19 +08:00
|
|
|
}
|
|
|
|
|
2014-01-29 23:59:19 +08:00
|
|
|
} // namespace internal
|
|
|
|
|
2015-12-04 01:00:25 +08:00
|
|
|
struct gmio_stl_mesh gmio_stl_occmesh(const struct gmio_occ_stl_mesh_domain* mesh_domain)
|
2015-03-19 23:34:53 +08:00
|
|
|
{
|
2015-12-04 01:00:25 +08:00
|
|
|
struct gmio_stl_mesh mesh = {0};
|
2015-09-09 16:54:45 +08:00
|
|
|
mesh.cookie = mesh_domain;
|
2015-10-14 18:06:47 +08:00
|
|
|
if (mesh_domain != NULL && mesh_domain->mesh() != NULL) {
|
2015-09-09 16:54:45 +08:00
|
|
|
mesh.triangle_count =
|
2015-10-14 18:06:47 +08:00
|
|
|
mesh_domain->mesh()->NbTriangles(mesh_domain->domain_id());
|
2015-09-09 16:54:45 +08:00
|
|
|
}
|
2015-09-01 23:32:57 +08:00
|
|
|
mesh.func_get_triangle = internal::occmesh_get_triangle;
|
|
|
|
return mesh;
|
2014-01-29 23:59:19 +08:00
|
|
|
}
|
2014-01-27 22:03:50 +08:00
|
|
|
|
2015-12-04 01:00:25 +08:00
|
|
|
struct gmio_stl_mesh_creator gmio_stl_occmesh_creator(StlMesh_Mesh* mesh)
|
2015-03-19 23:34:53 +08:00
|
|
|
{
|
2015-12-04 01:00:25 +08:00
|
|
|
struct gmio_stl_mesh_creator creator = {0};
|
2015-09-09 16:54:45 +08:00
|
|
|
creator.cookie = mesh;
|
2015-09-01 23:32:57 +08:00
|
|
|
creator.func_add_triangle = internal::occmesh_add_triangle;
|
|
|
|
return creator;
|
2015-03-19 23:34:53 +08:00
|
|
|
}
|
|
|
|
|
2015-12-04 01:00:25 +08:00
|
|
|
struct gmio_stl_mesh_creator gmio_stl_hnd_occmesh_creator(const Handle_StlMesh_Mesh &hnd)
|
2013-03-07 00:02:19 +08:00
|
|
|
{
|
2015-09-09 16:54:45 +08:00
|
|
|
return gmio_stl_occmesh_creator(internal::occMeshPtr(hnd));
|
2013-03-07 00:02:19 +08:00
|
|
|
}
|
|
|
|
|
2015-09-09 16:54:45 +08:00
|
|
|
gmio_occ_stl_mesh_domain::gmio_occ_stl_mesh_domain()
|
2015-10-14 18:06:47 +08:00
|
|
|
: m_mesh(NULL),
|
|
|
|
m_domain_id(0),
|
|
|
|
m_triangles(NULL),
|
|
|
|
m_vertices(NULL)
|
2013-03-07 00:02:19 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-09-09 16:54:45 +08:00
|
|
|
gmio_occ_stl_mesh_domain::gmio_occ_stl_mesh_domain(
|
|
|
|
const StlMesh_Mesh *msh, int dom_id)
|
2015-10-14 18:06:47 +08:00
|
|
|
: m_mesh(msh),
|
|
|
|
m_domain_id(dom_id),
|
|
|
|
m_triangles(&msh->Triangles(dom_id)),
|
|
|
|
m_vertices(&msh->Vertices(dom_id))
|
2013-03-07 00:02:19 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-09-09 16:54:45 +08:00
|
|
|
gmio_occ_stl_mesh_domain::gmio_occ_stl_mesh_domain(
|
2015-10-14 18:06:47 +08:00
|
|
|
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))
|
2013-03-07 00:02:19 +08:00
|
|
|
{
|
|
|
|
}
|