Make the input mesh transformation consistent.
Also add some comments
This commit is contained in:
parent
11b994a702
commit
8b5a63eaf8
1 changed files with 25 additions and 21 deletions
|
@ -105,7 +105,9 @@ inline double get_supportedness_score(const Facestats &fc)
|
||||||
float cosphi = fc.normal.dot(DOWN);
|
float cosphi = fc.normal.dot(DOWN);
|
||||||
float phi = 1.f - std::acos(cosphi) / float(PI);
|
float phi = 1.f - std::acos(cosphi) / float(PI);
|
||||||
|
|
||||||
// Only consider faces that have slopes below 90 deg:
|
// Phi is raised by 1.0 to not be less than zero when squared in the next
|
||||||
|
// step. If phi is greater than 0.5 (slope is > 90 deg) make phi zero
|
||||||
|
// to not skip this face in the overall score.
|
||||||
phi = (1.f + phi) * (phi >= 0.5f);
|
phi = (1.f + phi) * (phi >= 0.5f);
|
||||||
|
|
||||||
// Make the huge slopes more significant than the smaller slopes
|
// Make the huge slopes more significant than the smaller slopes
|
||||||
|
@ -285,6 +287,26 @@ std::array<double, N> find_min_score(Fn &&fn, It from, It to, StopCond &&stopfn)
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
// Assemble the mesh with the correct transformation to be used in rotation
|
||||||
|
// optimization.
|
||||||
|
TriangleMesh get_mesh_to_rotate(const ModelObject &mo)
|
||||||
|
{
|
||||||
|
TriangleMesh mesh = mo.raw_mesh();
|
||||||
|
mesh.require_shared_vertices();
|
||||||
|
|
||||||
|
ModelInstance *mi = mo.instances[0];
|
||||||
|
auto rotation = Vec3d::Zero();
|
||||||
|
auto offset = Vec3d::Zero();
|
||||||
|
Transform3d trafo_instance = Geometry::assemble_transform(offset,
|
||||||
|
rotation,
|
||||||
|
mi->get_scaling_factor(),
|
||||||
|
mi->get_mirror());
|
||||||
|
|
||||||
|
mesh.transform(trafo_instance);
|
||||||
|
|
||||||
|
return mesh;
|
||||||
|
}
|
||||||
|
|
||||||
Vec2d find_best_misalignment_rotation(const ModelObject & mo,
|
Vec2d find_best_misalignment_rotation(const ModelObject & mo,
|
||||||
const RotOptimizeParams ¶ms)
|
const RotOptimizeParams ¶ms)
|
||||||
{
|
{
|
||||||
|
@ -295,8 +317,7 @@ Vec2d find_best_misalignment_rotation(const ModelObject & mo,
|
||||||
|
|
||||||
// We will use only one instance of this converted mesh to examine different
|
// We will use only one instance of this converted mesh to examine different
|
||||||
// rotations
|
// rotations
|
||||||
TriangleMesh mesh = mo.raw_mesh();
|
TriangleMesh mesh = get_mesh_to_rotate(mo);
|
||||||
mesh.require_shared_vertices();
|
|
||||||
|
|
||||||
// To keep track of the number of iterations
|
// To keep track of the number of iterations
|
||||||
int status = 0;
|
int status = 0;
|
||||||
|
@ -352,17 +373,7 @@ Vec2d find_least_supports_rotation(const ModelObject & mo,
|
||||||
|
|
||||||
// We will use only one instance of this converted mesh to examine different
|
// We will use only one instance of this converted mesh to examine different
|
||||||
// rotations
|
// rotations
|
||||||
TriangleMesh mesh = mo.raw_mesh();
|
TriangleMesh mesh = get_mesh_to_rotate(mo);
|
||||||
mesh.require_shared_vertices();
|
|
||||||
|
|
||||||
ModelInstance* mi = mo.instances[0];
|
|
||||||
Vec3d rotation = mi->get_rotation();
|
|
||||||
Transform3d trafo_instance = Geometry::assemble_transform(mi->get_offset().z() * Vec3d::UnitZ(),
|
|
||||||
rotation,
|
|
||||||
mi->get_scaling_factor(),
|
|
||||||
mi->get_mirror());
|
|
||||||
|
|
||||||
mesh.transform(trafo_instance);
|
|
||||||
|
|
||||||
// To keep track of the number of iterations
|
// To keep track of the number of iterations
|
||||||
unsigned status = 0;
|
unsigned status = 0;
|
||||||
|
@ -430,13 +441,6 @@ Vec2d find_least_supports_rotation(const ModelObject & mo,
|
||||||
|
|
||||||
// Save the result
|
// Save the result
|
||||||
rot = result.optimum;
|
rot = result.optimum;
|
||||||
std::cout << "Score was: " << result.score << std::endl;
|
|
||||||
|
|
||||||
//auto rt = mo.instances[0]->get_rotation();
|
|
||||||
//double score = get_supportedness_score(mesh, to_transform3f({rt(0), rt(1)}));
|
|
||||||
// std::cout << "Score was: " << score << std::endl;
|
|
||||||
// rot[0] = rt(0);
|
|
||||||
// rot[1] = rt(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {rot[0], rot[1]};
|
return {rot[0], rot[1]};
|
||||||
|
|
Loading…
Add table
Reference in a new issue