change transformation to use double precision

This commit is contained in:
Michael Kirsch 2019-05-26 13:15:33 +02:00 committed by Joseph Lenox
parent e9a239a7e1
commit 10fc704784
4 changed files with 19 additions and 14 deletions

View File

@ -201,8 +201,8 @@ extern void stl_rotate_z(stl_file *stl, float angle);
extern void stl_mirror_xy(stl_file *stl);
extern void stl_mirror_yz(stl_file *stl);
extern void stl_mirror_xz(stl_file *stl);
extern void stl_transform(stl_file *stl, float const *trafo3x4);
extern void stl_get_transform(stl_file const *stl_src, stl_file *stl_dst, float const *trafo3x4);
extern void stl_transform(stl_file *stl, double const *trafo3x4);
extern void stl_get_transform(stl_file const *stl_src, stl_file *stl_dst, float double *trafo3x4);
extern void stl_open_merge(stl_file *stl, ADMESH_CHAR *file);
extern void stl_invalidate_shared_vertices(stl_file *stl);
extern void stl_generate_shared_vertices(stl_file *stl);

View File

@ -185,7 +185,7 @@ void calculate_normals(stl_file *stl) {
}
}
void stl_transform(stl_file *stl, float const *trafo3x4) {
void stl_transform(stl_file *stl, double const *trafo3x4) {
int i_face, i_vertex, i, j;
if (stl->error)
return;
@ -193,17 +193,19 @@ void stl_transform(stl_file *stl, float const *trafo3x4) {
stl_vertex *vertices = stl->facet_start[i_face].vertex;
for (i_vertex = 0; i_vertex < 3; ++ i_vertex) {
stl_vertex* v_dst = &vertices[i_vertex];
stl_vertex v_src = *v_dst;
v_dst->x = trafo3x4[0] * v_src.x + trafo3x4[1] * v_src.y + trafo3x4[2] * v_src.z + trafo3x4[3];
v_dst->y = trafo3x4[4] * v_src.x + trafo3x4[5] * v_src.y + trafo3x4[6] * v_src.z + trafo3x4[7];
v_dst->z = trafo3x4[8] * v_src.x + trafo3x4[9] * v_src.y + trafo3x4[10] * v_src.z + trafo3x4[11];
double v_src_x = (double)(v_dst->x);
double v_src_y = (double)(v_dst->y);
double v_src_z = (double)(v_dst->z);
v_dst->x = (float)(trafo3x4[0] * v_src_x + trafo3x4[1] * v_src_y + trafo3x4[2] * v_src_z + trafo3x4[3]);
v_dst->y = (float)(trafo3x4[4] * v_src_x + trafo3x4[5] * v_src_y + trafo3x4[6] * v_src_z + trafo3x4[7]);
v_dst->z = (float)(trafo3x4[8] * v_src_x + trafo3x4[9] * v_src_y + trafo3x4[10] * v_src_z + trafo3x4[11]);
}
}
stl_get_size(stl);
calculate_normals(stl);
}
void stl_get_transform(stl_file const *stl_src, stl_file *stl_dst, float const *trafo3x4) {
void stl_get_transform(stl_file const *stl_src, stl_file *stl_dst, double const *trafo3x4) {
int i_face, i_vertex, i, j;
if (stl_src->error || stl_dst->error)
return;
@ -227,9 +229,12 @@ void stl_get_transform(stl_file const *stl_src, stl_file *stl_dst, float const *
for (i_vertex = 0; i_vertex < 3; ++ i_vertex) {
stl_vertex* v_dst = &vertices_dst[i_vertex];
stl_vertex const * v_src = &vertices_src[i_vertex];
v_dst->x = trafo3x4[0] * v_src->x + trafo3x4[1] * v_src->y + trafo3x4[2] * v_src->z + trafo3x4[3];
v_dst->y = trafo3x4[4] * v_src->x + trafo3x4[5] * v_src->y + trafo3x4[6] * v_src->z + trafo3x4[7];
v_dst->z = trafo3x4[8] * v_src->x + trafo3x4[9] * v_src->y + trafo3x4[10] * v_src->z + trafo3x4[11];
double v_src_x = (double)(v_src->x);
double v_src_y = (double)(v_src->y);
double v_src_z = (double)(v_src->z);
v_dst->x = (float)(trafo3x4[0] * v_src_x + trafo3x4[1] * v_src_y + trafo3x4[2] * v_src_z + trafo3x4[3]);
v_dst->y = (float)(trafo3x4[4] * v_src_x + trafo3x4[5] * v_src_y + trafo3x4[6] * v_src_z + trafo3x4[7]);
v_dst->z = (float)(trafo3x4[8] * v_src_x + trafo3x4[9] * v_src_y + trafo3x4[10] * v_src_z + trafo3x4[11]);
}
}
stl_get_size(stl_dst);

View File

@ -57,9 +57,9 @@ void TransformationMatrix::swap(TransformationMatrix &other)
std::swap(this->m33, other.m33); std::swap(this->m34, other.m34);
}
std::vector<float> TransformationMatrix::matrix3x4f() const
std::vector<double> TransformationMatrix::matrix3x4f() const
{
std::vector<float> out_arr(0);
std::vector<double> out_arr(0);
out_arr.reserve(12);
out_arr.push_back(this->m11);
out_arr.push_back(this->m12);

View File

@ -27,7 +27,7 @@ public:
/// Return the row-major form of the represented transformation matrix
/// for admesh transform
std::vector<float> matrix3x4f() const;
std::vector<double> matrix3x4f() const;
/// Return the determinante of the matrix
double determinante() const;