gmio_support: make OCC support more C-ish
This commit is contained in:
parent
4c3976d91d
commit
409e590f28
@ -68,7 +68,7 @@ Handle_StlMesh_Mesh stlMesh;
|
||||
static void bmk_stl_read(const char* filepath)
|
||||
{
|
||||
stlMesh = new StlMesh_Mesh;
|
||||
gmio_stl_mesh_creator_t mesh_creator = gmio_stl_occmesh_creator(stlMesh);
|
||||
gmio_stl_mesh_creator_t mesh_creator = gmio_stl_hnd_occmesh_creator(stlMesh);
|
||||
int error = gmio_stl_read_file(filepath, &mesh_creator, NULL);
|
||||
if (error != GMIO_ERROR_OK)
|
||||
printf("gmio error: 0x%X\n", error);
|
||||
@ -76,8 +76,8 @@ static void bmk_stl_read(const char* filepath)
|
||||
|
||||
static void bmk_stl_write(const char* filepath, gmio_stl_format_t format)
|
||||
{
|
||||
const gmio_OccStlMeshDomain occMeshDomain(stlMesh);
|
||||
const gmio_stl_mesh_t mesh = gmio_stl_occmesh(occMeshDomain);
|
||||
const gmio_occ_stl_mesh_domain_t occ_mesh_domain(stlMesh);
|
||||
const gmio_stl_mesh_t mesh = gmio_stl_occmesh(&occ_mesh_domain);
|
||||
|
||||
gmio_stl_write_options_t opts = { 0 };
|
||||
opts.stla_float32_format = GMIO_FLOAT_TEXT_FORMAT_SHORTEST_UPPERCASE;
|
||||
|
@ -46,10 +46,10 @@ static void occmesh_add_triangle(void* cookie,
|
||||
static void occmesh_get_triangle(
|
||||
const void* cookie, uint32_t tri_id, gmio_stl_triangle_t* triangle)
|
||||
{
|
||||
const gmio_OccStlMeshDomain* meshCookie =
|
||||
static_cast<const gmio_OccStlMeshDomain*>(cookie);
|
||||
const gmio_occ_stl_mesh_domain_t* mesh_domain =
|
||||
static_cast<const gmio_occ_stl_mesh_domain_t*>(cookie);
|
||||
const StlMesh_SequenceOfMeshTriangle& occTriangles =
|
||||
meshCookie->mesh()->Triangles(meshCookie->domainId());
|
||||
mesh_domain->mesh->Triangles(mesh_domain->domain_id);
|
||||
const Handle_StlMesh_MeshTriangle& occTri =
|
||||
occTriangles.Value(tri_id + 1);
|
||||
int v1;
|
||||
@ -64,7 +64,7 @@ static void occmesh_get_triangle(
|
||||
triangle->normal.z = float(zN);
|
||||
|
||||
const TColgp_SequenceOfXYZ& vertices =
|
||||
meshCookie->mesh()->Vertices(meshCookie->domainId());
|
||||
mesh_domain->mesh->Vertices(mesh_domain->domain_id);
|
||||
const gp_XYZ& coordsV1 = vertices.Value(v1);
|
||||
const gp_XYZ& coordsV2 = vertices.Value(v2);
|
||||
const gp_XYZ& coordsV3 = vertices.Value(v3);
|
||||
@ -83,46 +83,48 @@ static void occmesh_get_triangle(
|
||||
|
||||
} // namespace internal
|
||||
|
||||
gmio_stl_mesh gmio_stl_occmesh(const gmio_OccStlMeshDomain &meshCookie)
|
||||
gmio_stl_mesh_t gmio_stl_occmesh(const gmio_occ_stl_mesh_domain_t* mesh_domain)
|
||||
{
|
||||
gmio_stl_mesh mesh = { 0 };
|
||||
mesh.cookie = &meshCookie;
|
||||
mesh.triangle_count = meshCookie.mesh()->NbTriangles(meshCookie.domainId());
|
||||
gmio_stl_mesh_t mesh = { 0 };
|
||||
mesh.cookie = mesh_domain;
|
||||
if (mesh_domain != NULL && mesh_domain->mesh != NULL) {
|
||||
mesh.triangle_count =
|
||||
mesh_domain->mesh->NbTriangles(mesh_domain->domain_id);
|
||||
}
|
||||
mesh.func_get_triangle = internal::occmesh_get_triangle;
|
||||
return mesh;
|
||||
}
|
||||
|
||||
gmio_stl_mesh_creator gmio_stl_occmesh_creator(const Handle_StlMesh_Mesh &mesh)
|
||||
gmio_stl_mesh_creator_t gmio_stl_occmesh_creator(StlMesh_Mesh* mesh)
|
||||
{
|
||||
gmio_stl_mesh_creator creator = { 0 };
|
||||
creator.cookie = internal::occMeshPtr(mesh);
|
||||
gmio_stl_mesh_creator_t creator = { 0 };
|
||||
creator.cookie = mesh;
|
||||
creator.func_add_triangle = internal::occmesh_add_triangle;
|
||||
return creator;
|
||||
}
|
||||
|
||||
gmio_OccStlMeshDomain::gmio_OccStlMeshDomain(
|
||||
const Handle_StlMesh_Mesh &stlMesh, int domId)
|
||||
: m_mesh(stlMesh),
|
||||
m_domainId(domId)
|
||||
gmio_stl_mesh_creator_t gmio_stl_hnd_occmesh_creator(const Handle_StlMesh_Mesh &hnd)
|
||||
{
|
||||
return gmio_stl_occmesh_creator(internal::occMeshPtr(hnd));
|
||||
}
|
||||
|
||||
gmio_occ_stl_mesh_domain::gmio_occ_stl_mesh_domain()
|
||||
: mesh(NULL),
|
||||
domain_id(0)
|
||||
{
|
||||
}
|
||||
|
||||
const Handle_StlMesh_Mesh &gmio_OccStlMeshDomain::mesh() const
|
||||
gmio_occ_stl_mesh_domain::gmio_occ_stl_mesh_domain(
|
||||
const StlMesh_Mesh *msh, int dom_id)
|
||||
: mesh(msh),
|
||||
domain_id(dom_id)
|
||||
|
||||
{
|
||||
return m_mesh;
|
||||
}
|
||||
|
||||
void gmio_OccStlMeshDomain::setMesh(const Handle_StlMesh_Mesh &stlMesh)
|
||||
gmio_occ_stl_mesh_domain::gmio_occ_stl_mesh_domain(
|
||||
const Handle_StlMesh_Mesh &hndMesh, int dom_id)
|
||||
: mesh(internal::occMeshPtr(hndMesh)),
|
||||
domain_id(dom_id)
|
||||
{
|
||||
m_mesh = stlMesh;
|
||||
}
|
||||
|
||||
int gmio_OccStlMeshDomain::domainId() const
|
||||
{
|
||||
return m_domainId;
|
||||
}
|
||||
|
||||
void gmio_OccStlMeshDomain::setDomainId(int domId)
|
||||
{
|
||||
m_domainId = domId;
|
||||
}
|
||||
|
@ -17,6 +17,10 @@
|
||||
* Support of OpenCascade's StlMesh_Mesh
|
||||
*/
|
||||
|
||||
#ifndef __cplusplus
|
||||
# error C++ compiler required
|
||||
#endif
|
||||
|
||||
#ifndef GMIO_SUPPORT_STL_OCC_H
|
||||
#define GMIO_SUPPORT_STL_OCC_H
|
||||
|
||||
@ -24,44 +28,44 @@
|
||||
#include "../gmio_stl/stl_mesh.h"
|
||||
#include "../gmio_stl/stl_mesh_creator.h"
|
||||
|
||||
#include <Handle_StlMesh_Mesh.hxx>
|
||||
struct gmio_stl_mesh;
|
||||
struct gmio_stl_mesh_creator;
|
||||
class Handle_StlMesh_Mesh;
|
||||
class StlMesh_Mesh;
|
||||
|
||||
/*! Domain in a OpenCascade \c StlMesh_Mesh object
|
||||
*
|
||||
* The domain is indicated with its index within the STL mesh
|
||||
*/
|
||||
class GMIO_LIBSUPPORT_EXPORT gmio_OccStlMeshDomain
|
||||
struct GMIO_LIBSUPPORT_EXPORT gmio_occ_stl_mesh_domain
|
||||
{
|
||||
public:
|
||||
gmio_OccStlMeshDomain(const Handle_StlMesh_Mesh& stlMesh, int domId = 1);
|
||||
|
||||
const Handle_StlMesh_Mesh& mesh() const;
|
||||
void setMesh(const Handle_StlMesh_Mesh& stlMesh);
|
||||
|
||||
int domainId() const;
|
||||
void setDomainId(int domId);
|
||||
|
||||
private:
|
||||
Handle_StlMesh_Mesh m_mesh;
|
||||
int m_domainId;
|
||||
gmio_occ_stl_mesh_domain();
|
||||
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);
|
||||
const StlMesh_Mesh* mesh;
|
||||
int domain_id;
|
||||
};
|
||||
typedef struct gmio_occ_stl_mesh_domain gmio_occ_stl_mesh_domain_t;
|
||||
|
||||
/*! Returns a gmio_stl_mesh mapped to domain in StlMesh_Mesh
|
||||
*
|
||||
* The mesh's cookie will point to \p meshCookie
|
||||
* The mesh's cookie will point to \p mesh_domain
|
||||
*/
|
||||
GMIO_LIBSUPPORT_EXPORT
|
||||
gmio_stl_mesh gmio_stl_occmesh(const gmio_OccStlMeshDomain& meshCookie);
|
||||
gmio_stl_mesh_t gmio_stl_occmesh(const gmio_occ_stl_mesh_domain_t* mesh_domain);
|
||||
|
||||
/*! Returns a gmio_stl_mesh_creator that will build a new domain in a
|
||||
* StlMesh_Mesh object
|
||||
*
|
||||
* The creator's cookie will point to the internal data(ie StlMesh_Mesh*) of
|
||||
* handle \p mesh
|
||||
* The creator's cookie will point \p mesh
|
||||
*/
|
||||
GMIO_LIBSUPPORT_EXPORT
|
||||
gmio_stl_mesh_creator gmio_stl_occmesh_creator(const Handle_StlMesh_Mesh& mesh);
|
||||
gmio_stl_mesh_creator_t gmio_stl_occmesh_creator(StlMesh_Mesh* mesh);
|
||||
|
||||
/*! Same as gmio_stl_occmesh_creator(StlMesh_Mesh*) but takes a handle
|
||||
*
|
||||
* The creator's cookie will point to the internal data(ie StlMesh_Mesh*) of
|
||||
* handle \p hnd
|
||||
*/
|
||||
GMIO_LIBSUPPORT_EXPORT
|
||||
gmio_stl_mesh_creator_t gmio_stl_hnd_occmesh_creator(const Handle_StlMesh_Mesh& hnd);
|
||||
|
||||
#endif /* GMIO_SUPPORT_STL_OCC_H */
|
||||
|
@ -4,11 +4,13 @@
|
||||
#include <QtCore/QFile>
|
||||
#include "../../src/gmio_support/stream_qt.h"
|
||||
|
||||
#include <Handle_StlMesh_Mesh.hxx>
|
||||
|
||||
int main()
|
||||
{
|
||||
// OpenCascade
|
||||
Handle_StlMesh_Mesh stlMesh;
|
||||
gmio_stl_occmesh_creator(stlMesh);
|
||||
gmio_stl_hnd_occmesh_creator(stlMesh);
|
||||
|
||||
// Qt
|
||||
QFile file;
|
||||
|
Loading…
Reference in New Issue
Block a user