From e4492f92f9d1462eb5311de75cf2ee0edc0587e8 Mon Sep 17 00:00:00 2001 From: Hugues Delorme Date: Fri, 11 Mar 2016 10:33:13 +0100 Subject: [PATCH] Rename gmio_stl_coords -> gmio_vec3_f32(core) --- benchmarks/benchmark_assimp/main.cpp | 16 +++++------ examples/CMakeLists.txt | 2 +- examples/stl_read_file.c | 2 +- examples/stl_write_file.c | 2 +- src/gmio_core/vecgeom.h | 43 ++++++++++++++++++++++++++++ src/gmio_stl/internal/stla_write.c | 2 +- src/gmio_stl/stl_constants.h | 2 +- src/gmio_stl/stl_format.c | 2 +- src/gmio_stl/stl_triangle.c | 12 ++++---- src/gmio_stl/stl_triangle.h | 22 +++++--------- src/gmio_stl/stla_read.c | 4 +-- src/gmio_support/stl_occ.cpp | 12 ++++---- tests/core_utils.c | 13 +++++++++ tests/core_utils.h | 8 +++++- tests/stl_utils.c | 19 ++++-------- tests/stl_utils.h | 5 ---- tests/test_stl_triangle.c | 8 +++--- 17 files changed, 107 insertions(+), 67 deletions(-) create mode 100644 src/gmio_core/vecgeom.h diff --git a/benchmarks/benchmark_assimp/main.cpp b/benchmarks/benchmark_assimp/main.cpp index 2bc9d44..8ba056f 100644 --- a/benchmarks/benchmark_assimp/main.cpp +++ b/benchmarks/benchmark_assimp/main.cpp @@ -43,16 +43,16 @@ static unsigned totalTriangleCount(const aiScene* scene) return meshnum; } -GMIO_INLINE void copy_gmio_stl_coords( - aiVector3D* vec3, const gmio_stl_coords& coords) +GMIO_INLINE void copy_gmio_vec3_f32( + aiVector3D* vec3, const gmio_vec3_f32& coords) { *vec3 = *((aiVector3D*)&coords); } GMIO_INLINE void copy_aiVector3D( - gmio_stl_coords* coords, const aiVector3D& vec3) + gmio_vec3_f32* coords, const aiVector3D& vec3) { - *coords = *((gmio_stl_coords*)&vec3); + *coords = *((gmio_vec3_f32*)&vec3); } namespace BmkAssimp { @@ -198,13 +198,13 @@ static void add_triangle( aiVector3D* vp = &pMesh->mVertices[tri_id * 3]; aiVector3D* vn = &pMesh->mNormals[tri_id * 3]; - copy_gmio_stl_coords(vn, triangle->n); + copy_gmio_vec3_f32(vn, triangle->n); *(vn+1) = *vn; *(vn+2) = *vn; - copy_gmio_stl_coords(vp, triangle->v1); - copy_gmio_stl_coords(vp+1, triangle->v2); - copy_gmio_stl_coords(vp+2, triangle->v3); + copy_gmio_vec3_f32(vp, triangle->v1); + copy_gmio_vec3_f32(vp+1, triangle->v2); + copy_gmio_vec3_f32(vp+2, triangle->v3); if (helper->hasToCountTriangle) ++(helper->totalTriangleCount); diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 8e1f20c..c922f46 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -28,7 +28,7 @@ set(SUPPORT_STL_OCC_FILES_FILES ${SUPPORT_STL_OCC_FILES_FILES}) add_executable(occstl_read_file occstl_read_file.cpp ${SUPPORT_STL_OCC_FILES}) add_executable(occstl_write_file - occstl_write_file.cpp ${SUPPORT_STL_OCC_FILES}) + occstl_write_file.cpp ${SUPPORT_STL_OCC_FILES}) add_executable(occstl_redefine_mesh_creator occstl_redefine_mesh_creator.cpp ${SUPPORT_STL_OCC_FILES}) diff --git a/examples/stl_read_file.c b/examples/stl_read_file.c index 624d665..4e4923e 100644 --- a/examples/stl_read_file.c +++ b/examples/stl_read_file.c @@ -62,7 +62,7 @@ static void my_3d_mesh__copy_triangle( { /* Copy new triangle */ struct my_3d_triangle* my_tri = &my_mesh->triangle_array[triangle_id]; - const struct gmio_stl_coords* tri_vertices = &triangle->v1; + const struct gmio_vec3_f32* tri_vertices = &triangle->v1; int i; for (i = 0; i < 3; ++i) { my_tri->vertex[i].coords[0] = tri_vertices[i].x; diff --git a/examples/stl_write_file.c b/examples/stl_write_file.c index 61fd73b..5b476df 100644 --- a/examples/stl_write_file.c +++ b/examples/stl_write_file.c @@ -25,7 +25,7 @@ static void my_3d_mesh__get_triangle( { const struct my_3d_mesh* my_mesh = (const struct my_3d_mesh*)cookie; const struct my_3d_triangle* my_tri = &my_mesh->triangle_array[tri_id]; - struct gmio_stl_coords* tri_vertices = &triangle->v1; + struct gmio_vec3_f32* tri_vertices = &triangle->v1; int i; for (i = 0; i < 3; ++i) { tri_vertices[i].x = (float)my_tri->vertex[i].coords[0]; diff --git a/src/gmio_core/vecgeom.h b/src/gmio_core/vecgeom.h new file mode 100644 index 0000000..5be4268 --- /dev/null +++ b/src/gmio_core/vecgeom.h @@ -0,0 +1,43 @@ +/**************************************************************************** +** gmio +** Copyright Fougue (2 Mar. 2015) +** contact@fougue.pro +** +** 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 +** "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html". +****************************************************************************/ + +/*! \file vecgeom.h + * Cartesian vectors + * + * \addtogroup gmio_core + * @{ + */ + +#ifndef GMIO_CORE_VECGEOM_H +#define GMIO_CORE_VECGEOM_H + +/*! Vector of three float32 coords */ +struct gmio_vec3_f32 +{ + float x; + float y; + float z; +}; + +/*! Vector of three float64 coords */ +struct gmio_vec3_f64 +{ + double x; + double y; + double z; +}; + +#endif /* GMIO_CORE_VECGEOM_H */ +/*! @} */ diff --git a/src/gmio_stl/internal/stla_write.c b/src/gmio_stl/internal/stla_write.c index 868fec4..9275490 100644 --- a/src/gmio_stl/internal/stla_write.c +++ b/src/gmio_stl/internal/stla_write.c @@ -119,7 +119,7 @@ GMIO_INLINE char* gmio_write_stdio_format( GMIO_INLINE char* gmio_write_coords( char* buffer, const char* coords_format, - const struct gmio_stl_coords* coords) + const struct gmio_vec3_f32* coords) { return buffer + sprintf(buffer, coords_format, coords->x, coords->y, coords->z); diff --git a/src/gmio_stl/stl_constants.h b/src/gmio_stl/stl_constants.h index 8c2c60a..7539d91 100644 --- a/src/gmio_stl/stl_constants.h +++ b/src/gmio_stl/stl_constants.h @@ -27,7 +27,7 @@ enum gmio_stl_constants { - /*! Compact size of a gmio_stl_coords object */ + /*! Compact size of a gmio_vec3_f32 object */ GMIO_STL_COORDS_RAWSIZE = (3 * sizeof(float)), /*! Compact size of a gmio_stl_triangle object, STL ascii format */ diff --git a/src/gmio_stl/stl_format.c b/src/gmio_stl/stl_format.c index fd8e66e..ebcf7a6 100644 --- a/src/gmio_stl/stl_format.c +++ b/src/gmio_stl/stl_format.c @@ -33,7 +33,7 @@ enum { GMIO_FIXED_BUFFER_SIZE = 1024 }; -GMIO_INLINE float gmio_sqrlen(const struct gmio_stl_coords* c) +GMIO_INLINE float gmio_sqrlen(const struct gmio_vec3_f32* c) { return gmio_sqr_length_f32(c->x, c->y, c->z); } diff --git a/src/gmio_stl/stl_triangle.c b/src/gmio_stl/stl_triangle.c index 58e919c..337cda7 100644 --- a/src/gmio_stl/stl_triangle.c +++ b/src/gmio_stl/stl_triangle.c @@ -17,10 +17,10 @@ #include "../gmio_core/internal/vecgeom_utils.h" -GMIO_INLINE struct gmio_stl_coords gmio_stl_coords_diff( - const struct gmio_stl_coords* u, const struct gmio_stl_coords* v) +GMIO_INLINE struct gmio_vec3_f32 gmio_vec3_f32_diff( + const struct gmio_vec3_f32* u, const struct gmio_vec3_f32* v) { - struct gmio_stl_coords diff; + struct gmio_vec3_f32 diff; diff.x = u->x - v->x; diff.y = u->y - v->y; diff.z = u->z - v->z; @@ -29,8 +29,8 @@ GMIO_INLINE struct gmio_stl_coords gmio_stl_coords_diff( void gmio_stl_triangle_compute_normal(struct gmio_stl_triangle* tri) { - const struct gmio_stl_coords u = gmio_stl_coords_diff(&tri->v2, &tri->v1); - const struct gmio_stl_coords v = gmio_stl_coords_diff(&tri->v3, &tri->v1); - struct gmio_stl_coords* n = &tri->n; + const struct gmio_vec3_f32 u = gmio_vec3_f32_diff(&tri->v2, &tri->v1); + const struct gmio_vec3_f32 v = gmio_vec3_f32_diff(&tri->v3, &tri->v1); + struct gmio_vec3_f32* n = &tri->n; gmio_cross_product_f32(u.x, u.y, u.z, v.x, v.y, v.z, &n->x, &n->y, &n->z); } diff --git a/src/gmio_stl/stl_triangle.h b/src/gmio_stl/stl_triangle.h index 95fb41d..90a7617 100644 --- a/src/gmio_stl/stl_triangle.h +++ b/src/gmio_stl/stl_triangle.h @@ -14,7 +14,7 @@ ****************************************************************************/ /*! \file stl_triangle.h - * Declaration of gmio_stl_coords and gmio_stl_triangle + * Declaration of gmio_stl_triangle * * \addtogroup gmio_stl * @{ @@ -24,23 +24,15 @@ #define GMIO_STL_TRIANGLE_H #include "stl_global.h" +#include "../gmio_core/vecgeom.h" -/*! Cartesian coordinate entity in 3D space, specifically tailored for - * STL needs (single-float) */ -struct gmio_stl_coords -{ - float x; - float y; - float z; -}; - -/*! STL mesh triangle defined three vertices and a normal(orientation) */ +/*! STL mesh triangle */ struct gmio_stl_triangle { - struct gmio_stl_coords n; /*!< Normal vector */ - struct gmio_stl_coords v1; /*!< Vertex 1 */ - struct gmio_stl_coords v2; /*!< Vertex 2 */ - struct gmio_stl_coords v3; /*!< Vertex 3 */ + struct gmio_vec3_f32 n; /*!< Normal vector */ + struct gmio_vec3_f32 v1; /*!< Vertex 1 */ + struct gmio_vec3_f32 v2; /*!< Vertex 2 */ + struct gmio_vec3_f32 v3; /*!< Vertex 3 */ uint16_t attribute_byte_count; /*!< Useful only for STL binary format */ }; diff --git a/src/gmio_stl/stla_read.c b/src/gmio_stl/stla_read.c index a193b2b..392cf5f 100644 --- a/src/gmio_stl/stla_read.c +++ b/src/gmio_stl/stla_read.c @@ -243,7 +243,7 @@ static bool parse_endsolid(struct gmio_stla_parse_data* data); /* Parses STL (x,y,z) coords, each coord being separated by whitespaces */ GMIO_INLINE int parse_xyz_coords( - struct gmio_stla_parse_data* data, struct gmio_stl_coords* coords); + struct gmio_stla_parse_data* data, struct gmio_vec3_f32* coords); /* Parses a STL facet, ie. facet ... endfacet */ static int parse_facet( @@ -588,7 +588,7 @@ GMIO_INLINE int is_float_char(const char* str) || c == '+'; } -int parse_xyz_coords(struct gmio_stla_parse_data* data, struct gmio_stl_coords* coords) +int parse_xyz_coords(struct gmio_stla_parse_data* data, struct gmio_vec3_f32* coords) { int errc = 0; struct gmio_stringstream* sstream = &data->strstream; diff --git a/src/gmio_support/stl_occ.cpp b/src/gmio_support/stl_occ.cpp index 8d5276a..c7a2727 100644 --- a/src/gmio_support/stl_occ.cpp +++ b/src/gmio_support/stl_occ.cpp @@ -36,10 +36,10 @@ static void occmesh_add_triangle( StlMesh_Mesh* mesh = static_cast(cookie); if (tri_id == 0) mesh->AddDomain(); - const gmio_stl_coords& v1 = tri->v1; - const gmio_stl_coords& v2 = tri->v2; - const gmio_stl_coords& v3 = tri->v3; - const gmio_stl_coords& n = tri->n; + const gmio_vec3_f32& v1 = tri->v1; + const gmio_vec3_f32& v2 = tri->v2; + const gmio_vec3_f32& v3 = tri->v3; + const gmio_vec3_f32& n = tri->n; 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), @@ -47,7 +47,7 @@ static void occmesh_add_triangle( } static inline void gmio_stl_occ_copy_xyz( - gmio_stl_coords* stl_coords, const gp_XYZ& coords) + gmio_vec3_f32* stl_coords, const gp_XYZ& coords) { stl_coords->x = static_cast(coords.X()); stl_coords->y = static_cast(coords.Y()); @@ -66,7 +66,7 @@ static void occmesh_get_triangle( int idV1, idV2, idV3; double xN, yN, zN; occTri->GetVertexAndOrientation(idV1, idV2, idV3, xN, yN, zN); - gmio_stl_coords& n = tri->n; + gmio_vec3_f32& n = tri->n; n.x = static_cast(xN); n.y = static_cast(yN); n.z = static_cast(zN); diff --git a/tests/core_utils.c b/tests/core_utils.c index 828e1f8..334902f 100644 --- a/tests/core_utils.c +++ b/tests/core_utils.c @@ -15,6 +15,9 @@ #include "core_utils.h" +#include "../src/gmio_core/internal/numeric_utils.h" +#include "../src/gmio_core/internal/string_ascii_utils.h" + void gmio_string_trim_from_end(char *str, size_t len) { if (len > 0) { @@ -27,3 +30,13 @@ void gmio_string_trim_from_end(char *str, size_t len) } while (len != 0); } } + +bool gmio_vec3_f32_equal( + const struct gmio_vec3_f32 *lhs, + const struct gmio_vec3_f32 *rhs, + uint32_t max_ulp_diff) +{ + return gmio_float32_ulp_equals(lhs->x, rhs->x, max_ulp_diff) + && gmio_float32_ulp_equals(lhs->y, rhs->y, max_ulp_diff) + && gmio_float32_ulp_equals(lhs->z, rhs->z, max_ulp_diff); +} diff --git a/tests/core_utils.h b/tests/core_utils.h index 6707cd2..9401064 100644 --- a/tests/core_utils.h +++ b/tests/core_utils.h @@ -17,11 +17,17 @@ #define GMIO_TESTS_CORE_UTILS_H #include "../src/gmio_core/global.h" -#include "../src/gmio_core/internal/string_ascii_utils.h" +#include "../src/gmio_core/vecgeom.h" #include /*! Trim whitespaces in string \p str from end */ void gmio_string_trim_from_end(char* str, size_t len); +/*! Does \p lhs == \p rhs using gmio_float32_ulp_equals() on coords ? */ +bool gmio_vec3_f32_equal( + const struct gmio_vec3_f32* lhs, + const struct gmio_vec3_f32* rhs, + uint32_t max_ulp_diff); + #endif /* GMIO_TESTS_CORE_UTILS_H */ diff --git a/tests/stl_utils.c b/tests/stl_utils.c index ed3bcd3..15bce24 100644 --- a/tests/stl_utils.c +++ b/tests/stl_utils.c @@ -15,6 +15,7 @@ #include "stl_utils.h" +#include "core_utils.h" #include "../src/gmio_core/internal/min_max.h" #include "../src/gmio_core/internal/numeric_utils.h" #include "../src/gmio_core/internal/safe_cast.h" @@ -127,25 +128,15 @@ struct gmio_stl_mesh gmio_stl_data_mesh(const struct gmio_stl_data *data) return mesh; } -bool gmio_stl_coords_equal( - const struct gmio_stl_coords *lhs, - const struct gmio_stl_coords *rhs, - uint32_t max_ulp_diff) -{ - return gmio_float32_ulp_equals(lhs->x, rhs->x, max_ulp_diff) - && gmio_float32_ulp_equals(lhs->y, rhs->y, max_ulp_diff) - && gmio_float32_ulp_equals(lhs->z, rhs->z, max_ulp_diff); -} - bool gmio_stl_triangle_equal( const struct gmio_stl_triangle *lhs, const struct gmio_stl_triangle *rhs, uint32_t max_ulp_diff) { - return gmio_stl_coords_equal(&lhs->n, &rhs->n, max_ulp_diff) - && gmio_stl_coords_equal(&lhs->v1, &rhs->v1, max_ulp_diff) - && gmio_stl_coords_equal(&lhs->v2, &rhs->v2, max_ulp_diff) - && gmio_stl_coords_equal(&lhs->v3, &rhs->v3, max_ulp_diff) + return gmio_vec3_f32_equal(&lhs->n, &rhs->n, max_ulp_diff) + && gmio_vec3_f32_equal(&lhs->v1, &rhs->v1, max_ulp_diff) + && gmio_vec3_f32_equal(&lhs->v2, &rhs->v2, max_ulp_diff) + && gmio_vec3_f32_equal(&lhs->v3, &rhs->v3, max_ulp_diff) && lhs->attribute_byte_count == rhs->attribute_byte_count; } diff --git a/tests/stl_utils.h b/tests/stl_utils.h index f289f59..6ca49ba 100644 --- a/tests/stl_utils.h +++ b/tests/stl_utils.h @@ -24,11 +24,6 @@ #include -bool gmio_stl_coords_equal( - const struct gmio_stl_coords* lhs, - const struct gmio_stl_coords* rhs, - uint32_t max_ulp_diff); - bool gmio_stl_triangle_equal( const struct gmio_stl_triangle* lhs, const struct gmio_stl_triangle* rhs, diff --git a/tests/test_stl_triangle.c b/tests/test_stl_triangle.c index 4b7ea19..09d6193 100644 --- a/tests/test_stl_triangle.c +++ b/tests/test_stl_triangle.c @@ -27,10 +27,10 @@ GMIO_PRAGMA_MSVC_WARNING_PUSH_AND_DISABLE(4127) const char* test_stl_coords_packing() { - UTEST_COMPARE_UINT(0, offsetof(struct gmio_stl_coords, x)); - UTEST_COMPARE_UINT(4, offsetof(struct gmio_stl_coords, y)); - UTEST_COMPARE_UINT(8, offsetof(struct gmio_stl_coords, z)); - UTEST_COMPARE_UINT(GMIO_STL_COORDS_RAWSIZE, sizeof(struct gmio_stl_coords)); + UTEST_COMPARE_UINT(0, offsetof(struct gmio_vec3_f32, x)); + UTEST_COMPARE_UINT(4, offsetof(struct gmio_vec3_f32, y)); + UTEST_COMPARE_UINT(8, offsetof(struct gmio_vec3_f32, z)); + UTEST_COMPARE_UINT(GMIO_STL_COORDS_RAWSIZE, sizeof(struct gmio_vec3_f32)); return NULL; }