Method Transformation::reset_scaling_factor() modified to use SVD decomposition of transformation matrix and object manipulator reset button set to use it

This commit is contained in:
enricoturri1966 2023-02-02 11:42:21 +01:00
parent cdd6ce9079
commit f2b986af57
3 changed files with 13 additions and 12 deletions

View File

@ -720,6 +720,12 @@ void Transformation::reset()
}
#if ENABLE_WORLD_COORDINATE
void Transformation::reset_scaling_factor()
{
const Geometry::TransformationSVD svd(*this);
m_matrix = get_offset_matrix() * Transform3d(svd.u) * Transform3d(svd.v.transpose());
}
void Transformation::reset_skew()
{
auto new_scale_factor = [](const Matrix3d& s) {

View File

@ -493,7 +493,7 @@ public:
#if ENABLE_WORLD_COORDINATE
void reset_offset() { set_offset(Vec3d::Zero()); }
void reset_rotation() { set_rotation(Vec3d::Zero()); }
void reset_scaling_factor() { set_scaling_factor(Vec3d::Ones()); }
void reset_scaling_factor();
void reset_mirror() { set_mirror(Vec3d::Ones()); }
void reset_skew();

View File

@ -484,24 +484,19 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent) :
GLCanvas3D* canvas = wxGetApp().plater()->canvas3D();
Selection& selection = canvas->get_selection();
if (selection.is_single_volume_or_modifier()) {
const bool is_left_handed = selection.get_first_volume()->get_volume_transformation().is_left_handed();
const_cast<GLVolume*>(selection.get_first_volume())->set_volume_scaling_factor(Vec3d::Ones());
if (is_left_handed)
const_cast<GLVolume*>(selection.get_first_volume())->set_volume_mirror({ -1.0 , 1.0, 1.0 });
Geometry::Transformation trafo = selection.get_first_volume()->get_volume_transformation();
trafo.reset_scaling_factor();
const_cast<GLVolume*>(selection.get_first_volume())->set_volume_transformation(trafo);
}
else if (selection.is_single_full_instance()) {
const bool is_left_handed = selection.get_first_volume()->get_instance_transformation().is_left_handed();
for (unsigned int idx : selection.get_volume_idxs()) {
const_cast<GLVolume*>(selection.get_volume(idx))->set_instance_scaling_factor(Vec3d::Ones());
if (is_left_handed)
const_cast<GLVolume*>(selection.get_volume(idx))->set_instance_mirror({ -1.0 , 1.0, 1.0 });
}
Geometry::Transformation trafo = selection.get_first_volume()->get_instance_transformation();
trafo.reset_scaling_factor();
const_cast<GLVolume*>(selection.get_first_volume())->set_instance_transformation(trafo);
}
else
return;
canvas->do_scale(L("Reset scale"));
UpdateAndShow(true);
#else
Plater::TakeSnapshot snapshot(wxGetApp().plater(), _L("Reset scale"));