Rename gmio_stl_coords -> gmio_vec3_f32(core)
This commit is contained in:
parent
0a14409aea
commit
e4492f92f9
@ -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);
|
||||
|
@ -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})
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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];
|
||||
|
43
src/gmio_core/vecgeom.h
Normal file
43
src/gmio_core/vecgeom.h
Normal file
@ -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 */
|
||||
/*! @} */
|
@ -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);
|
||||
|
@ -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 */
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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 */
|
||||
};
|
||||
|
||||
|
@ -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;
|
||||
|
@ -36,10 +36,10 @@ static void occmesh_add_triangle(
|
||||
StlMesh_Mesh* mesh = static_cast<StlMesh_Mesh*>(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<float>(coords.X());
|
||||
stl_coords->y = static_cast<float>(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<float>(xN);
|
||||
n.y = static_cast<float>(yN);
|
||||
n.z = static_cast<float>(zN);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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 <stddef.h>
|
||||
|
||||
/*! 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 */
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -24,11 +24,6 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
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,
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user