Rename gmio_vec3 structs

*gmio_vec3_f32 -> gmio_vec3f
*gmio_vec3_f64 -> gmio_vec3d
This commit is contained in:
Hugues Delorme 2016-03-14 16:31:48 +01:00
parent 2764e77c56
commit 2f873e3089
16 changed files with 114 additions and 106 deletions

View File

@ -43,16 +43,16 @@ static unsigned totalTriangleCount(const aiScene* scene)
return meshnum; return meshnum;
} }
GMIO_INLINE void copy_gmio_vec3_f32( GMIO_INLINE void copy_gmio_vec3f(
aiVector3D* vec3, const gmio_vec3_f32& coords) aiVector3D* vec3, const gmio_vec3f& coords)
{ {
*vec3 = *((aiVector3D*)&coords); *vec3 = *((aiVector3D*)&coords);
} }
GMIO_INLINE void copy_aiVector3D( GMIO_INLINE void copy_aiVector3D(
gmio_vec3_f32* coords, const aiVector3D& vec3) gmio_vec3f* coords, const aiVector3D& vec3)
{ {
*coords = *((gmio_vec3_f32*)&vec3); *coords = *((gmio_vec3f*)&vec3);
} }
namespace BmkAssimp { namespace BmkAssimp {
@ -198,13 +198,13 @@ static void add_triangle(
aiVector3D* vp = &pMesh->mVertices[tri_id * 3]; aiVector3D* vp = &pMesh->mVertices[tri_id * 3];
aiVector3D* vn = &pMesh->mNormals[tri_id * 3]; aiVector3D* vn = &pMesh->mNormals[tri_id * 3];
copy_gmio_vec3_f32(vn, triangle->n); copy_gmio_vec3f(vn, triangle->n);
*(vn+1) = *vn; *(vn+1) = *vn;
*(vn+2) = *vn; *(vn+2) = *vn;
copy_gmio_vec3_f32(vp, triangle->v1); copy_gmio_vec3f(vp, triangle->v1);
copy_gmio_vec3_f32(vp+1, triangle->v2); copy_gmio_vec3f(vp+1, triangle->v2);
copy_gmio_vec3_f32(vp+2, triangle->v3); copy_gmio_vec3f(vp+2, triangle->v3);
if (helper->hasToCountTriangle) if (helper->hasToCountTriangle)
++(helper->totalTriangleCount); ++(helper->totalTriangleCount);

View File

@ -66,7 +66,7 @@ static void my_3d_mesh__copy_triangle(
{ /* Copy new triangle */ { /* Copy new triangle */
struct my_3d_triangle* my_tri = &my_mesh->triangle_array[triangle_id]; struct my_3d_triangle* my_tri = &my_mesh->triangle_array[triangle_id];
const struct gmio_vec3_f32* tri_vertices = &triangle->v1; const struct gmio_vec3f* tri_vertices = &triangle->v1;
int i; int i;
for (i = 0; i < 3; ++i) { for (i = 0; i < 3; ++i) {
my_tri->vertex[i].coords[0] = tri_vertices[i].x; my_tri->vertex[i].coords[0] = tri_vertices[i].x;

View File

@ -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_mesh* my_mesh = (const struct my_3d_mesh*)cookie;
const struct my_3d_triangle* my_tri = &my_mesh->triangle_array[tri_id]; const struct my_3d_triangle* my_tri = &my_mesh->triangle_array[tri_id];
struct gmio_vec3_f32* tri_vertices = &triangle->v1; struct gmio_vec3f* tri_vertices = &triangle->v1;
int i; int i;
for (i = 0; i < 3; ++i) { for (i = 0; i < 3; ++i) {
tri_vertices[i].x = (float)my_tri->vertex[i].coords[0]; tri_vertices[i].x = (float)my_tri->vertex[i].coords[0];

View File

@ -18,29 +18,29 @@
#include "../global.h" #include "../global.h"
/*! Computes in-place cross product of float32 coords (ux,uy,uz) ^ (vx,vy,vz) */ /*! Computes in-place cross product of two gmio_vec3f objects */
GMIO_INLINE void gmio_cross_product_f32( GMIO_INLINE void gmio_vec3f_cross_product(
float ux, float uy, float uz, const struct gmio_vec3f* u,
float vx, float vy, float vz, const struct gmio_vec3f* v,
float* nx, float* ny, float* nz); struct gmio_vec3f* n);
/*! Computes in-place cross product of float64 coords (ux,uy,uz) ^ (vx,vy,vz) */ /*! Computes in-place cross product of two gmio_vec3d objects */
GMIO_INLINE void gmio_cross_product_f64( GMIO_INLINE void gmio_vec3d_cross_product(
double ux, double uy, double uz, const struct gmio_vec3d* u,
double vx, double vy, double vz, const struct gmio_vec3d* v,
double* nx, double* ny, double* nz); struct gmio_vec3d* n);
/*! Returns the squared length of float32 vector (x, y, z) */ /*! Returns the squared length of a gmio_vec3f object */
GMIO_INLINE float gmio_sqr_length_f32(float x, float y, float z); GMIO_INLINE float gmio_vec3f_sqr_length(const struct gmio_vec3f* v);
/*! Returns the squared length of float64 vector (x, y, z) */ /*! Returns the squared length of a gmio_vec3d object */
GMIO_INLINE double gmio_sqr_length_f64(double x, double y, double z); GMIO_INLINE double gmio_vec3d_sqr_length(const struct gmio_vec3d* v);
/*! Normalizes in-place the float32 (x,y,z) coords */ /*! Normalizes in-place a gmio_vec3f object */
GMIO_INLINE void gmio_normalize_f32(float* x, float* y, float* z); GMIO_INLINE void gmio_vec3f_normalize(struct gmio_vec3f* v);
/*! Normalizes in-place the float64 (x,y,z) coords */ /*! Normalizes in-place a gmio_vec3d object */
GMIO_INLINE void gmio_normalize_f64(double* x, double* y, double* z); GMIO_INLINE void gmio_vec3d_normalize(struct gmio_vec3d* v);
/* /*
* Implementation * Implementation
@ -48,51 +48,61 @@ GMIO_INLINE void gmio_normalize_f64(double* x, double* y, double* z);
#include <math.h> #include <math.h>
void gmio_cross_product_f32( void gmio_vec3f_cross_product(
float ux, float uy, float uz, const struct gmio_vec3f* u,
float vx, float vy, float vz, const struct gmio_vec3f* v,
float* nx, float* ny, float* nz) struct gmio_vec3f* n)
{ {
*nx = uy*vz - uz*vx; const float ux = u->x, uy = u->y, uz = u->z;
*ny = uz*vx - ux*vz; const float vx = v->x, vy = v->y, vz = v->z;
*nz = ux*vy - uy*vx; n->x = uy*vz - uz*vx;
gmio_normalize_f32(nx, ny, nz); n->y = uz*vx - ux*vz;
n->z = ux*vy - uy*vx;
gmio_vec3f_normalize(n);
} }
void gmio_cross_product_f64( void gmio_vec3d_cross_product(
double ux, double uy, double uz, const struct gmio_vec3d* u,
double vx, double vy, double vz, const struct gmio_vec3d* v,
double* nx, double* ny, double* nz) struct gmio_vec3d* n)
{ {
*nx = uy*vz - uz*vx; const double ux = u->x, uy = u->y, uz = u->z;
*ny = uz*vx - ux*vz; const double vx = v->x, vy = v->y, vz = v->z;
*nz = ux*vy - uy*vx; n->x = uy*vz - uz*vx;
gmio_normalize_f64(nx, ny, nz); n->y = uz*vx - ux*vz;
n->z = ux*vy - uy*vx;
gmio_vec3d_normalize(n);
} }
float gmio_sqr_length_f32(float x, float y, float z) float gmio_vec3f_sqr_length(const struct gmio_vec3f* v)
{ return x*x + y*y + z*z; }
double gmio_sqr_length_f64(double x, double y, double z)
{ return x*x + y*y + z*z; }
void gmio_normalize_f32(float* x, float* y, float* z)
{ {
const float d = (float)sqrt(gmio_sqr_length_f32(*x, *y, *z)); const float vx = v->x, vy = v->y, vz = v->z;
return vx*vx + vy*vy + vz*vz;
}
double gmio_vec3d_sqr_length(const struct gmio_vec3d* v)
{
const double vx = v->x, vy = v->y, vz = v->z;
return vx*vx + vy*vy + vz*vz;
}
void gmio_vec3f_normalize(struct gmio_vec3f* v)
{
const float d = (float)sqrt(gmio_vec3f_sqr_length(v));
if (d > 0.f) { if (d > 0.f) {
*x /= d; v->x /= d;
*y /= d; v->y /= d;
*z /= d; v->z /= d;
} }
} }
void gmio_normalize_f64(double* x, double* y, double* z) void gmio_vec3d_normalize(struct gmio_vec3d* v)
{ {
const double d = sqrt(gmio_sqr_length_f64(*x, *y, *z)); const double d = sqrt(gmio_vec3d_sqr_length(v));
if (d > 0.) { if (d > 0.) {
*x /= d; v->x /= d;
*y /= d; v->y /= d;
*z /= d; v->z /= d;
} }
} }

View File

@ -23,16 +23,16 @@
#ifndef GMIO_CORE_VECGEOM_H #ifndef GMIO_CORE_VECGEOM_H
#define GMIO_CORE_VECGEOM_H #define GMIO_CORE_VECGEOM_H
/*! Vector of three float32 coords */ /*! Vector of three float coords */
struct gmio_vec3_f32 struct gmio_vec3f
{ {
float x; float x;
float y; float y;
float z; float z;
}; };
/*! Vector of three float64 coords */ /*! Vector of three double coords */
struct gmio_vec3_f64 struct gmio_vec3d
{ {
double x; double x;
double y; double y;

View File

@ -119,7 +119,7 @@ GMIO_INLINE char* gmio_write_stdio_format(
GMIO_INLINE char* gmio_write_coords( GMIO_INLINE char* gmio_write_coords(
char* buffer, char* buffer,
const char* coords_format, const char* coords_format,
const struct gmio_vec3_f32* coords) const struct gmio_vec3f* coords)
{ {
return buffer + sprintf(buffer, return buffer + sprintf(buffer,
coords_format, coords->x, coords->y, coords->z); coords_format, coords->x, coords->y, coords->z);

View File

@ -27,7 +27,7 @@
enum gmio_stl_constants enum gmio_stl_constants
{ {
/*! Compact size of a gmio_vec3_f32 object */ /*! Compact size of a gmio_vec3f object */
GMIO_STL_COORDS_RAWSIZE = (3 * sizeof(float)), GMIO_STL_COORDS_RAWSIZE = (3 * sizeof(float)),
/*! Compact size of a gmio_stl_triangle object, STL ascii format */ /*! Compact size of a gmio_stl_triangle object, STL ascii format */

View File

@ -33,11 +33,6 @@
enum { GMIO_FIXED_BUFFER_SIZE = 1024 }; enum { GMIO_FIXED_BUFFER_SIZE = 1024 };
GMIO_INLINE float gmio_sqrlen(const struct gmio_vec3_f32* c)
{
return gmio_sqr_length_f32(c->x, c->y, c->z);
}
/* Does \p str contains <SPC>token ? */ /* Does \p str contains <SPC>token ? */
static bool gmio_str_has_token(const char* str, const char* token) static bool gmio_str_has_token(const char* str, const char* token)
{ {
@ -72,7 +67,9 @@ static enum gmio_stl_format gmio_stlb_format(
memcpy(&tri, memcpy(&tri,
buff + GMIO_STLB_HEADER_SIZE + 4, buff + GMIO_STLB_HEADER_SIZE + 4,
GMIO_STLB_TRIANGLE_RAWSIZE); GMIO_STLB_TRIANGLE_RAWSIZE);
if (gmio_float32_ulp_equals(gmio_sqrlen(&tri.n), 1.f, 100)) { if (gmio_float32_ulp_equals(
gmio_vec3f_sqr_length(&tri.n), 1.f, 100))
{
#ifdef GMIO_HOST_IS_BIG_ENDIAN #ifdef GMIO_HOST_IS_BIG_ENDIAN
return GMIO_STL_FORMAT_BINARY_BE; return GMIO_STL_FORMAT_BINARY_BE;
#else #else
@ -80,7 +77,9 @@ static enum gmio_stl_format gmio_stlb_format(
#endif #endif
} }
gmio_stl_triangle_bswap(&tri); gmio_stl_triangle_bswap(&tri);
if (gmio_float32_ulp_equals(gmio_sqrlen(&tri.n), 1.f, 100)) { if (gmio_float32_ulp_equals(
gmio_vec3f_sqr_length(&tri.n), 1.f, 100))
{
#ifdef GMIO_HOST_IS_BIG_ENDIAN #ifdef GMIO_HOST_IS_BIG_ENDIAN
return GMIO_STL_FORMAT_BINARY_LE; return GMIO_STL_FORMAT_BINARY_LE;
#else #else

View File

@ -17,10 +17,10 @@
#include "../gmio_core/internal/vecgeom_utils.h" #include "../gmio_core/internal/vecgeom_utils.h"
GMIO_INLINE struct gmio_vec3_f32 gmio_vec3_f32_diff( GMIO_INLINE struct gmio_vec3f gmio_vec3f_sub(
const struct gmio_vec3_f32* u, const struct gmio_vec3_f32* v) const struct gmio_vec3f* u, const struct gmio_vec3f* v)
{ {
struct gmio_vec3_f32 diff; struct gmio_vec3f diff;
diff.x = u->x - v->x; diff.x = u->x - v->x;
diff.y = u->y - v->y; diff.y = u->y - v->y;
diff.z = u->z - v->z; diff.z = u->z - v->z;
@ -29,8 +29,7 @@ GMIO_INLINE struct gmio_vec3_f32 gmio_vec3_f32_diff(
void gmio_stl_triangle_compute_normal(struct gmio_stl_triangle* tri) void gmio_stl_triangle_compute_normal(struct gmio_stl_triangle* tri)
{ {
const struct gmio_vec3_f32 u = gmio_vec3_f32_diff(&tri->v2, &tri->v1); const struct gmio_vec3f u = gmio_vec3f_sub(&tri->v2, &tri->v1);
const struct gmio_vec3_f32 v = gmio_vec3_f32_diff(&tri->v3, &tri->v1); const struct gmio_vec3f v = gmio_vec3f_sub(&tri->v3, &tri->v1);
struct gmio_vec3_f32* n = &tri->n; gmio_vec3f_cross_product(&u, &v, &tri->n);
gmio_cross_product_f32(u.x, u.y, u.z, v.x, v.y, v.z, &n->x, &n->y, &n->z);
} }

View File

@ -29,10 +29,10 @@
/*! STL mesh triangle */ /*! STL mesh triangle */
struct gmio_stl_triangle struct gmio_stl_triangle
{ {
struct gmio_vec3_f32 n; /*!< Normal vector */ struct gmio_vec3f n; /*!< Normal vector */
struct gmio_vec3_f32 v1; /*!< Vertex 1 */ struct gmio_vec3f v1; /*!< Vertex 1 */
struct gmio_vec3_f32 v2; /*!< Vertex 2 */ struct gmio_vec3f v2; /*!< Vertex 2 */
struct gmio_vec3_f32 v3; /*!< Vertex 3 */ struct gmio_vec3f v3; /*!< Vertex 3 */
uint16_t attribute_byte_count; /*!< Useful only for STL binary format */ uint16_t attribute_byte_count; /*!< Useful only for STL binary format */
}; };

View File

@ -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 */ /* Parses STL (x,y,z) coords, each coord being separated by whitespaces */
GMIO_INLINE int parse_xyz_coords( GMIO_INLINE int parse_xyz_coords(
struct gmio_stla_parse_data* data, struct gmio_vec3_f32* coords); struct gmio_stla_parse_data* data, struct gmio_vec3f* coords);
/* Parses a STL facet, ie. facet ... endfacet */ /* Parses a STL facet, ie. facet ... endfacet */
static int parse_facet( static int parse_facet(
@ -588,7 +588,7 @@ GMIO_INLINE int is_float_char(const char* str)
|| c == '+'; || c == '+';
} }
int parse_xyz_coords(struct gmio_stla_parse_data* data, struct gmio_vec3_f32* coords) int parse_xyz_coords(struct gmio_stla_parse_data* data, struct gmio_vec3f* coords)
{ {
int errc = 0; int errc = 0;
struct gmio_stringstream* sstream = &data->strstream; struct gmio_stringstream* sstream = &data->strstream;

View File

@ -36,10 +36,10 @@ static void occmesh_add_triangle(
StlMesh_Mesh* mesh = static_cast<StlMesh_Mesh*>(cookie); StlMesh_Mesh* mesh = static_cast<StlMesh_Mesh*>(cookie);
if (tri_id == 0) if (tri_id == 0)
mesh->AddDomain(); mesh->AddDomain();
const gmio_vec3_f32& v1 = tri->v1; const gmio_vec3f& v1 = tri->v1;
const gmio_vec3_f32& v2 = tri->v2; const gmio_vec3f& v2 = tri->v2;
const gmio_vec3_f32& v3 = tri->v3; const gmio_vec3f& v3 = tri->v3;
const gmio_vec3_f32& n = tri->n; const gmio_vec3f& n = tri->n;
mesh->AddTriangle(mesh->AddOnlyNewVertex(v1.x, v1.y, v1.z), mesh->AddTriangle(mesh->AddOnlyNewVertex(v1.x, v1.y, v1.z),
mesh->AddOnlyNewVertex(v2.x, v2.y, v2.z), mesh->AddOnlyNewVertex(v2.x, v2.y, v2.z),
mesh->AddOnlyNewVertex(v3.x, v3.y, v3.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( static inline void gmio_stl_occ_copy_xyz(
gmio_vec3_f32* stl_coords, const gp_XYZ& coords) gmio_vec3f* stl_coords, const gp_XYZ& coords)
{ {
stl_coords->x = static_cast<float>(coords.X()); stl_coords->x = static_cast<float>(coords.X());
stl_coords->y = static_cast<float>(coords.Y()); stl_coords->y = static_cast<float>(coords.Y());
@ -66,7 +66,7 @@ static void occmesh_get_triangle(
int idV1, idV2, idV3; int idV1, idV2, idV3;
double xN, yN, zN; double xN, yN, zN;
occTri->GetVertexAndOrientation(idV1, idV2, idV3, xN, yN, zN); occTri->GetVertexAndOrientation(idV1, idV2, idV3, xN, yN, zN);
gmio_vec3_f32& n = tri->n; gmio_vec3f& n = tri->n;
n.x = static_cast<float>(xN); n.x = static_cast<float>(xN);
n.y = static_cast<float>(yN); n.y = static_cast<float>(yN);
n.z = static_cast<float>(zN); n.z = static_cast<float>(zN);

View File

@ -31,9 +31,9 @@ void gmio_string_trim_from_end(char *str, size_t len)
} }
} }
bool gmio_vec3_f32_equal( bool gmio_vec3f_equal(
const struct gmio_vec3_f32 *lhs, const struct gmio_vec3f *lhs,
const struct gmio_vec3_f32 *rhs, const struct gmio_vec3f *rhs,
uint32_t max_ulp_diff) uint32_t max_ulp_diff)
{ {
return gmio_float32_ulp_equals(lhs->x, rhs->x, max_ulp_diff) return gmio_float32_ulp_equals(lhs->x, rhs->x, max_ulp_diff)

View File

@ -25,9 +25,9 @@
void gmio_string_trim_from_end(char* str, size_t len); void gmio_string_trim_from_end(char* str, size_t len);
/*! Does \p lhs == \p rhs using gmio_float32_ulp_equals() on coords ? */ /*! Does \p lhs == \p rhs using gmio_float32_ulp_equals() on coords ? */
bool gmio_vec3_f32_equal( bool gmio_vec3f_equal(
const struct gmio_vec3_f32* lhs, const struct gmio_vec3f* lhs,
const struct gmio_vec3_f32* rhs, const struct gmio_vec3f* rhs,
uint32_t max_ulp_diff); uint32_t max_ulp_diff);
#endif /* GMIO_TESTS_CORE_UTILS_H */ #endif /* GMIO_TESTS_CORE_UTILS_H */

View File

@ -133,10 +133,10 @@ bool gmio_stl_triangle_equal(
const struct gmio_stl_triangle *rhs, const struct gmio_stl_triangle *rhs,
uint32_t max_ulp_diff) uint32_t max_ulp_diff)
{ {
return gmio_vec3_f32_equal(&lhs->n, &rhs->n, max_ulp_diff) return gmio_vec3f_equal(&lhs->n, &rhs->n, max_ulp_diff)
&& gmio_vec3_f32_equal(&lhs->v1, &rhs->v1, max_ulp_diff) && gmio_vec3f_equal(&lhs->v1, &rhs->v1, max_ulp_diff)
&& gmio_vec3_f32_equal(&lhs->v2, &rhs->v2, max_ulp_diff) && gmio_vec3f_equal(&lhs->v2, &rhs->v2, max_ulp_diff)
&& gmio_vec3_f32_equal(&lhs->v3, &rhs->v3, max_ulp_diff) && gmio_vec3f_equal(&lhs->v3, &rhs->v3, max_ulp_diff)
&& lhs->attribute_byte_count == rhs->attribute_byte_count; && lhs->attribute_byte_count == rhs->attribute_byte_count;
} }

View File

@ -27,10 +27,10 @@ GMIO_PRAGMA_MSVC_WARNING_PUSH_AND_DISABLE(4127)
const char* test_stl_coords_packing() const char* test_stl_coords_packing()
{ {
UTEST_COMPARE_UINT(0, offsetof(struct gmio_vec3_f32, x)); UTEST_COMPARE_UINT(0, offsetof(struct gmio_vec3f, x));
UTEST_COMPARE_UINT(4, offsetof(struct gmio_vec3_f32, y)); UTEST_COMPARE_UINT(4, offsetof(struct gmio_vec3f, y));
UTEST_COMPARE_UINT(8, offsetof(struct gmio_vec3_f32, z)); UTEST_COMPARE_UINT(8, offsetof(struct gmio_vec3f, z));
UTEST_COMPARE_UINT(GMIO_STL_COORDS_RAWSIZE, sizeof(struct gmio_vec3_f32)); UTEST_COMPARE_UINT(GMIO_STL_COORDS_RAWSIZE, sizeof(struct gmio_vec3f));
return NULL; return NULL;
} }