Fixed normals transformation in functions stl_transform()
This commit is contained in:
parent
54357f846f
commit
25ab9e8d5d
@ -184,10 +184,21 @@ extern void stl_mirror_xz(stl_file *stl);
|
|||||||
|
|
||||||
extern void stl_get_size(stl_file *stl);
|
extern void stl_get_size(stl_file *stl);
|
||||||
|
|
||||||
|
// the following function is not used
|
||||||
|
/*
|
||||||
template<typename T>
|
template<typename T>
|
||||||
extern void stl_transform(stl_file *stl, T *trafo3x4)
|
extern void stl_transform(stl_file *stl, T *trafo3x4)
|
||||||
{
|
{
|
||||||
for (uint32_t i_face = 0; i_face < stl->stats.number_of_facets; ++ i_face) {
|
Eigen::Matrix<T, 3, 3, Eigen::DontAlign> trafo3x3;
|
||||||
|
for (int i = 0; i < 3; ++i)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < 3; ++j)
|
||||||
|
{
|
||||||
|
trafo3x3(i, j) = (i * 4) + j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Eigen::Matrix<T, 3, 3, Eigen::DontAlign> r = trafo3x3.inverse().transpose();
|
||||||
|
for (uint32_t i_face = 0; i_face < stl->stats.number_of_facets; ++ i_face) {
|
||||||
stl_facet &face = stl->facet_start[i_face];
|
stl_facet &face = stl->facet_start[i_face];
|
||||||
for (int i_vertex = 0; i_vertex < 3; ++ i_vertex) {
|
for (int i_vertex = 0; i_vertex < 3; ++ i_vertex) {
|
||||||
stl_vertex &v_dst = face.vertex[i_vertex];
|
stl_vertex &v_dst = face.vertex[i_vertex];
|
||||||
@ -196,21 +207,18 @@ extern void stl_transform(stl_file *stl, T *trafo3x4)
|
|||||||
v_dst(1) = T(trafo3x4[4] * v_src(0) + trafo3x4[5] * v_src(1) + trafo3x4[6] * v_src(2) + trafo3x4[7]);
|
v_dst(1) = T(trafo3x4[4] * v_src(0) + trafo3x4[5] * v_src(1) + trafo3x4[6] * v_src(2) + trafo3x4[7]);
|
||||||
v_dst(2) = T(trafo3x4[8] * v_src(0) + trafo3x4[9] * v_src(1) + trafo3x4[10] * v_src(2) + trafo3x4[11]);
|
v_dst(2) = T(trafo3x4[8] * v_src(0) + trafo3x4[9] * v_src(1) + trafo3x4[10] * v_src(2) + trafo3x4[11]);
|
||||||
}
|
}
|
||||||
stl_vertex &v_dst = face.normal;
|
face.normal = (r * face.normal.template cast<T>()).template cast<float>().eval();
|
||||||
stl_vertex v_src = v_dst;
|
}
|
||||||
v_dst(0) = T(trafo3x4[0] * v_src(0) + trafo3x4[1] * v_src(1) + trafo3x4[2] * v_src(2));
|
|
||||||
v_dst(1) = T(trafo3x4[4] * v_src(0) + trafo3x4[5] * v_src(1) + trafo3x4[6] * v_src(2));
|
|
||||||
v_dst(2) = T(trafo3x4[8] * v_src(0) + trafo3x4[9] * v_src(1) + trafo3x4[10] * v_src(2));
|
|
||||||
}
|
|
||||||
|
|
||||||
stl_get_size(stl);
|
stl_get_size(stl);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline void stl_transform(stl_file *stl, const Eigen::Transform<T, 3, Eigen::Affine, Eigen::DontAlign>& t)
|
inline void stl_transform(stl_file *stl, const Eigen::Transform<T, 3, Eigen::Affine, Eigen::DontAlign>& t)
|
||||||
{
|
{
|
||||||
const Eigen::Matrix<double, 3, 3, Eigen::DontAlign> r = t.matrix().template block<3, 3>(0, 0);
|
const Eigen::Matrix<T, 3, 3, Eigen::DontAlign> r = t.matrix().template block<3, 3>(0, 0).inverse().transpose();
|
||||||
for (size_t i = 0; i < stl->stats.number_of_facets; ++ i) {
|
for (size_t i = 0; i < stl->stats.number_of_facets; ++ i) {
|
||||||
stl_facet &f = stl->facet_start[i];
|
stl_facet &f = stl->facet_start[i];
|
||||||
for (size_t j = 0; j < 3; ++j)
|
for (size_t j = 0; j < 3; ++j)
|
||||||
f.vertex[j] = (t * f.vertex[j].template cast<T>()).template cast<float>().eval();
|
f.vertex[j] = (t * f.vertex[j].template cast<T>()).template cast<float>().eval();
|
||||||
@ -223,12 +231,13 @@ inline void stl_transform(stl_file *stl, const Eigen::Transform<T, 3, Eigen::Aff
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
inline void stl_transform(stl_file *stl, const Eigen::Matrix<T, 3, 3, Eigen::DontAlign>& m)
|
inline void stl_transform(stl_file *stl, const Eigen::Matrix<T, 3, 3, Eigen::DontAlign>& m)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < stl->stats.number_of_facets; ++ i) {
|
const Eigen::Matrix<T, 3, 3, Eigen::DontAlign> r = m.inverse().transpose();
|
||||||
|
for (size_t i = 0; i < stl->stats.number_of_facets; ++ i) {
|
||||||
stl_facet &f = stl->facet_start[i];
|
stl_facet &f = stl->facet_start[i];
|
||||||
for (size_t j = 0; j < 3; ++j)
|
for (size_t j = 0; j < 3; ++j)
|
||||||
f.vertex[j] = (m * f.vertex[j].template cast<T>()).template cast<float>().eval();
|
f.vertex[j] = (m * f.vertex[j].template cast<T>()).template cast<float>().eval();
|
||||||
f.normal = (m * f.normal.template cast<T>()).template cast<float>().eval();
|
f.normal = (r * f.normal.template cast<T>()).template cast<float>().eval();
|
||||||
}
|
}
|
||||||
|
|
||||||
stl_get_size(stl);
|
stl_get_size(stl);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user