Skip to content

Commit

Permalink
Avoid using auto as type of Eigen expressions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Noisyfox committed Feb 26, 2025
1 parent 41584cf commit da64ee9
Show file tree
Hide file tree
Showing 18 changed files with 45 additions and 45 deletions.
4 changes: 2 additions & 2 deletions src/libslic3r/Algorithm/LineSplit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ using SplitNode = std::vector<ClipperZUtils::ZPath*>;
static bool point_on_line(const Point& p, const Line& l)
{
// Check collinear
const auto d1 = l.b - l.a;
const auto d2 = p - l.a;
const Vec2crd d1 = l.b - l.a;
const Vec2crd d2 = p - l.a;
if (d1.x() * d2.y() != d1.y() * d2.x()) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libslic3r/Arachne/utils/ExtrusionLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ void ExtrusionLine::simplify(const int64_t smallest_line_segment_squared, const
Point intersection_point;
bool has_intersection = Line(previous_previous.p, previous.p).intersection_infinite(Line(current.p, next.p), &intersection_point);
const auto dist_greater = [](const Point& p1, const Point& p2, const int64_t threshold) {
const auto vec = (p1 - p2).cwiseAbs().cast<uint64_t>();
const auto vec = (p1 - p2).cwiseAbs().cast<uint64_t>().eval();
if(vec.x() > threshold || vec.y() > threshold) {
// If this condition is true, the distance is definitely greater than the threshold.
// We don't need to calculate the squared norm at all, which avoid potential arithmetic overflow.
Expand Down
2 changes: 1 addition & 1 deletion src/libslic3r/CutSurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1887,7 +1887,7 @@ uint32_t priv::get_closest_point_index(const SearchData &sd,
const Polygon &poly = (id.polygon_index == 0) ?
shape.contour :
shape.holes[id.polygon_index - 1];
auto p_ = p.cast<coord_t>();
Vec2crd p_ = p.cast<coord_t>();
return p_ == poly[id.point_index];
};

Expand Down
2 changes: 1 addition & 1 deletion src/libslic3r/Emboss.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1672,7 +1672,7 @@ Vec3d Emboss::suggest_up(const Vec3d normal, double up_limit)

std::optional<float> Emboss::calc_up(const Transform3d &tr, double up_limit)
{
auto tr_linear = tr.linear();
auto tr_linear = tr.linear().eval();
// z base of transformation ( tr * UnitZ )
Vec3d normal = tr_linear.col(2);
// scaled matrix has base with different size
Expand Down
8 changes: 4 additions & 4 deletions src/libslic3r/Fill/FillAdaptive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1447,7 +1447,7 @@ static std::vector<CubeProperties> make_cubes_properties(double max_cube_edge_le
static inline bool is_overhang_triangle(const Vec3d &a, const Vec3d &b, const Vec3d &c, const Vec3d &up)
{
// Calculate triangle normal.
auto n = (b - a).cross(c - b);
Vec3d n = (b - a).cross(c - b);
return n.dot(up) > 0.707 * n.norm();
}

Expand Down Expand Up @@ -1493,9 +1493,9 @@ OctreePtr build_octree(
};
auto up_vector = support_overhangs_only ? Vec3d(transform_to_octree() * Vec3d(0., 0., 1.)) : Vec3d();
for (auto &tri : triangle_mesh.indices) {
auto a = triangle_mesh.vertices[tri[0]].cast<double>();
auto b = triangle_mesh.vertices[tri[1]].cast<double>();
auto c = triangle_mesh.vertices[tri[2]].cast<double>();
Vec3d a = triangle_mesh.vertices[tri[0]].cast<double>();
Vec3d b = triangle_mesh.vertices[tri[1]].cast<double>();
Vec3d c = triangle_mesh.vertices[tri[2]].cast<double>();
if (! support_overhangs_only || is_overhang_triangle(a, b, c, up_vector))
process_triangle(a, b, c);
}
Expand Down
4 changes: 2 additions & 2 deletions src/libslic3r/GCode/ExtrusionProcessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ std::vector<ExtendedPoint> estimate_points_properties(const POINTS
double t1 = std::max(a0, a1);

if (t0 < 1.0) {
auto p0 = curr.position + t0 * (next.position - curr.position);
Vec2d p0 = curr.position + t0 * (next.position - curr.position);
auto [p0_dist, p0_near_l,
p0_x] = unscaled_prev_layer.template distance_from_lines_extra<SIGNED_DISTANCE>(p0.cast<AABBScalar>());
ExtendedPoint new_p{};
Expand All @@ -161,7 +161,7 @@ std::vector<ExtendedPoint> estimate_points_properties(const POINTS
}
}
if (t1 > 0.0) {
auto p1 = curr.position + t1 * (next.position - curr.position);
Vec2d p1 = curr.position + t1 * (next.position - curr.position);
auto [p1_dist, p1_near_l,
p1_x] = unscaled_prev_layer.template distance_from_lines_extra<SIGNED_DISTANCE>(p1.cast<AABBScalar>());
ExtendedPoint new_p{};
Expand Down
10 changes: 5 additions & 5 deletions src/libslic3r/Geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -693,10 +693,10 @@ Transformation Transformation::volume_to_bed_transformation(const Transformation
pts(7, 0) = bbox.max.x(); pts(7, 1) = bbox.max.y(); pts(7, 2) = bbox.max.z();

// Corners of the bounding box transformed into the modifier mesh coordinate space, with inverse rotation applied to the modifier.
auto qs = pts *
auto qs = (pts *
(instance_rotation_trafo *
Eigen::Scaling(instance_transformation.get_scaling_factor().cwiseProduct(instance_transformation.get_mirror())) *
volume_rotation_trafo).inverse().transpose();
volume_rotation_trafo).inverse().transpose()).eval();
// Fill in scaling based on least squares fitting of the bounding box corners.
Vec3d scale;
for (int i = 0; i < 3; ++i)
Expand Down Expand Up @@ -767,7 +767,7 @@ double rotation_diff_z(const Vec3d &rot_xyz_from, const Vec3d &rot_xyz_to)

TransformationSVD::TransformationSVD(const Transform3d& trafo)
{
const auto &m0 = trafo.matrix().block<3, 3>(0, 0);
const Matrix3d m0 = trafo.matrix().block<3, 3>(0, 0);
mirror = m0.determinant() < 0.0;

Matrix3d m;
Expand Down Expand Up @@ -832,8 +832,8 @@ TransformationSVD::TransformationSVD(const Transform3d& trafo)
qua_world.normalize();
Transform3d cur_matrix_world;
temp_world.set_matrix(cur_matrix_world.fromPositionOrientationScale(pt, qua_world, Vec3d(1., 1., 1.)));
auto temp_xyz = temp_world.get_matrix().inverse() * xyz;
auto new_pos = temp_world.get_matrix() * (rotateMat4.get_matrix() * temp_xyz);
Vec3d temp_xyz = temp_world.get_matrix().inverse() * xyz;
Vec3d new_pos = temp_world.get_matrix() * (rotateMat4.get_matrix() * temp_xyz);
curMat.set_offset(new_pos);

return curMat;
Expand Down
2 changes: 1 addition & 1 deletion src/libslic3r/Line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void Line::extend(double offset)

Vec3d Linef3::intersect_plane(double z) const
{
auto v = (this->b - this->a).cast<double>();
Vec3d v = (this->b - this->a).cast<double>();
double t = (z - this->a(2)) / v(2);
return Vec3d(this->a(0) + v(0) * t, this->a(1) + v(1) * t, z);
}
Expand Down
6 changes: 3 additions & 3 deletions src/libslic3r/Measure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ namespace Slic3r {
namespace Measure {
bool get_point_projection_to_plane(const Vec3d &pt, const Vec3d &plane_origin, const Vec3d &plane_normal, Vec3d &intersection_pt)
{
auto normal = plane_normal.normalized();
auto BA = plane_origin - pt;
Vec3d normal = plane_normal.normalized();
Vec3d BA = plane_origin - pt;
auto length = BA.dot(normal);
intersection_pt = pt + length * normal;
return true;
Expand All @@ -29,7 +29,7 @@ Vec3d get_one_point_in_plane(const Vec3d &plane_origin, const Vec3d &plane_norma
if (abs(plane_normal.dot(dir)) > 1 - eps) {
dir = Vec3d(0, 1, 0);
}
auto new_pt = plane_origin + dir;
Vec3d new_pt = plane_origin + dir;
Vec3d retult;
get_point_projection_to_plane(new_pt, plane_origin, plane_normal, retult);
return retult;
Expand Down
8 changes: 4 additions & 4 deletions src/libslic3r/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2991,11 +2991,11 @@ bool Model::obj_import_vertex_color_deal(const std::vector<unsigned char> &verte
auto v0 = volume->mesh().its.vertices[face[0]];
auto v1 = volume->mesh().its.vertices[face[1]];
auto v2 = volume->mesh().its.vertices[face[2]];
auto dir_0_1 = (v1 - v0).normalized();
auto dir_0_2 = (v2 - v0).normalized();
auto dir_0_1 = (v1 - v0).normalized().eval();
auto dir_0_2 = (v2 - v0).normalized().eval();
float sita0 = acos(dir_0_1.dot(dir_0_2));
auto dir_1_0 = -dir_0_1;
auto dir_1_2 = (v2 - v1).normalized();
auto dir_1_0 = (-dir_0_1).eval();
auto dir_1_2 = (v2 - v1).normalized().eval();
float sita1 = acos(dir_1_0.dot(dir_1_2));
float sita2 = PI - sita0 - sita1;
std::array<float, 3> sitas = {sita0, sita1, sita2};
Expand Down
14 changes: 7 additions & 7 deletions src/libslic3r/Orient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class AutoOrienter {
BOOST_LOG_TRIVIAL(info) << CostItems::field_names();
std::cout << CostItems::field_names() << std::endl;
for (int i = 0; i < orientations.size();i++) {
auto orientation = -orientations[i];
Vec3f orientation = -orientations[i];

project_vertices(orientation);

Expand Down Expand Up @@ -382,9 +382,9 @@ class AutoOrienter {

float total_min_z = z_projected.minCoeff();
// filter bottom area
auto bottom_condition = z_max.array() < total_min_z + this->params.FIRST_LAY_H - EPSILON;
auto bottom_condition_hull = z_max_hull.array() < total_min_z + this->params.FIRST_LAY_H - EPSILON;
auto bottom_condition_2nd = z_max.array() < total_min_z + this->params.FIRST_LAY_H/2.f - EPSILON;
auto bottom_condition = (z_max.array() < total_min_z + this->params.FIRST_LAY_H - EPSILON).eval();
auto bottom_condition_hull = (z_max_hull.array() < total_min_z + this->params.FIRST_LAY_H - EPSILON).eval();
auto bottom_condition_2nd = (z_max.array() < total_min_z + this->params.FIRST_LAY_H / 2.f - EPSILON).eval();
//The first layer is sliced on half of the first layer height.
//The bottom area is measured by accumulating first layer area with the facets area below first layer height.
//By combining these two factors, we can avoid the wrong orientation of large planar faces while not influence the
Expand All @@ -397,8 +397,8 @@ class AutoOrienter {
{
normal_projection(i) = normals.row(i).dot(orientation);
}
auto areas_appearance = areas.cwiseProduct((is_apperance * params.APPERANCE_FACE_SUPP + Eigen::VectorXf::Ones(is_apperance.rows(), is_apperance.cols())));
auto overhang_areas = ((normal_projection.array() < params.ASCENT) * (!bottom_condition_2nd)).select(areas_appearance, 0);
auto areas_appearance = areas.cwiseProduct((is_apperance * params.APPERANCE_FACE_SUPP + Eigen::VectorXf::Ones(is_apperance.rows(), is_apperance.cols()))).eval();
auto overhang_areas = ((normal_projection.array() < params.ASCENT) * (!bottom_condition_2nd)).select(areas_appearance, 0).eval();
Eigen::MatrixXf inner = normal_projection.array() - params.ASCENT;
inner = inner.cwiseMin(0).cwiseAbs();
if (min_volume)
Expand Down Expand Up @@ -437,7 +437,7 @@ class AutoOrienter {
costs.bottom_hull = (bottom_condition_hull).select(areas_hull, 0).sum();

// low angle faces
auto normal_projection_abs = normal_projection.cwiseAbs();
auto normal_projection_abs = normal_projection.cwiseAbs().eval();
Eigen::MatrixXf laf_areas = ((normal_projection_abs.array() < params.LAF_MAX) * (normal_projection_abs.array() > params.LAF_MIN) * (z_max.array() > total_min_z + params.FIRST_LAY_H)).select(areas, 0);
costs.area_laf = laf_areas.sum();

Expand Down
2 changes: 1 addition & 1 deletion src/libslic3r/Point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void Point::rotate(double angle, const Point &center)
Vec2d cur = this->cast<double>();
double s = ::sin(angle);
double c = ::cos(angle);
auto d = cur - center.cast<double>();
Vec2d d = cur - center.cast<double>();
this->x() = fast_round_up<coord_t>(center.x() + c * d.x() - s * d.y());
this->y() = fast_round_up<coord_t>(center.y() + s * d.x() + c * d.y());
}
Expand Down
4 changes: 2 additions & 2 deletions src/libslic3r/Support/TreeSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3296,8 +3296,8 @@ void TreeSupport::generate_contact_points()
int nSize = points.size();
for (int i = 0; i < nSize; i++) {
auto pt = points[i];
auto v1 = (pt - points[(i - 1 + nSize) % nSize]).cast<double>().normalized();
auto v2 = (pt - points[(i + 1) % nSize]).cast<double>().normalized();
Vec2d v1 = (pt - points[(i - 1 + nSize) % nSize]).cast<double>().normalized();
Vec2d v2 = (pt - points[(i + 1) % nSize]).cast<double>().normalized();
if (v1.dot(v2) > -0.7) { // angle smaller than 135 degrees
SupportNode *contact_node = insert_point(pt, overhang, radius, false, add_interface);
if (contact_node) {
Expand Down
6 changes: 3 additions & 3 deletions src/libslic3r/Support/TreeSupport3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1480,8 +1480,8 @@ static unsigned int move_inside(const Polygons &polygons, Point &from, int dista
const Point& a = p1;
const Point& b = p2;
const Point& p = from;
auto ab = (b - a).cast<int64_t>();
auto ap = (p - a).cast<int64_t>();
Vec2i64 ab = (b - a).cast<int64_t>();
Vec2i64 ap = (p - a).cast<int64_t>();
int64_t ab_length2 = ab.squaredNorm();
if (ab_length2 <= 0) { //A = B, i.e. the input polygon had two adjacent points on top of each other.
p1 = p2; //Skip only one of the points.
Expand All @@ -1506,7 +1506,7 @@ static unsigned int move_inside(const Polygons &polygons, Point &from, int dista
double lab = abd.norm();
double lp1p2 = p1p2.norm();
// inward direction irrespective of sign of [distance]
auto inward_dir = perp(abd * (scaled<double>(10.0) / lab) + p1p2 * (scaled<double>(10.0) / lp1p2));
Vec2d inward_dir = perp(abd * (scaled<double>(10.0) / lab) + p1p2 * (scaled<double>(10.0) / lp1p2));
// MM2INT(10.0) to retain precision for the eventual normalization
ret = x + (inward_dir * (distance / inward_dir.norm())).cast<coord_t>();
is_already_on_correct_side_of_boundary = inward_dir.dot((p - x).cast<double>()) * distance >= 0;
Expand Down
4 changes: 2 additions & 2 deletions src/slic3r/GUI/2DBed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@ void Bed_2D::repaint(const std::vector<Vec2d>& shape)
auto x_end = Vec2d(origin_px(0) + axes_len, origin_px(1));
dc.DrawLine(wxPoint(origin_px(0), origin_px(1)), wxPoint(x_end(0), x_end(1)));
for (auto angle : { -arrow_angle, arrow_angle }) {
auto end = Eigen::Translation2d(x_end) * Eigen::Rotation2Dd(angle) * Eigen::Translation2d(- x_end) * Eigen::Vector2d(x_end(0) - arrow_len, x_end(1));
Vec2d end = Eigen::Translation2d(x_end) * Eigen::Rotation2Dd(angle) * Eigen::Translation2d(- x_end) * Eigen::Vector2d(x_end(0) - arrow_len, x_end(1));
dc.DrawLine(wxPoint(x_end(0), x_end(1)), wxPoint(end(0), end(1)));
}

dc.SetPen(wxPen(wxColour(0, 255, 0), 2, wxPENSTYLE_SOLID)); // green
auto y_end = Vec2d(origin_px(0), origin_px(1) - axes_len);
dc.DrawLine(wxPoint(origin_px(0), origin_px(1)), wxPoint(y_end(0), y_end(1)));
for (auto angle : { -arrow_angle, arrow_angle }) {
auto end = Eigen::Translation2d(y_end) * Eigen::Rotation2Dd(angle) * Eigen::Translation2d(- y_end) * Eigen::Vector2d(y_end(0), y_end(1) + arrow_len);
Vec2d end = Eigen::Translation2d(y_end) * Eigen::Rotation2Dd(angle) * Eigen::Translation2d(- y_end) * Eigen::Vector2d(y_end(0), y_end(1) + arrow_len);
dc.DrawLine(wxPoint(y_end(0), y_end(1)), wxPoint(end(0), end(1)));
}

Expand Down
6 changes: 3 additions & 3 deletions src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2470,11 +2470,11 @@ void GLGizmoMeasure::set_distance(bool same_model_object, const Vec3d &displacem
selection->set_mode(same_model_object ? Selection::Volume : Selection::Instance);
m_pending_scale ++;
if (same_model_object == false) {
auto object_displacement = v->get_instance_transformation().get_matrix_no_offset().inverse() * displacement;
Vec3d object_displacement = v->get_instance_transformation().get_matrix_no_offset().inverse() * displacement;
v->set_instance_transformation(v->get_instance_transformation().get_matrix() * Geometry::translation_transform(object_displacement));
} else {
Geometry::Transformation tran(v->world_matrix());
auto local_displacement = tran.get_matrix_no_offset().inverse() * displacement;
Vec3d local_displacement = tran.get_matrix_no_offset().inverse() * displacement;
v->set_volume_transformation(v->get_volume_transformation().get_matrix() * Geometry::translation_transform(local_displacement));
}
wxGetApp().plater()->canvas3D()->do_move("");
Expand Down Expand Up @@ -2647,7 +2647,7 @@ void GLGizmoMeasure::set_parallel_distance(bool same_model_object, float dist)
const auto [idx2, normal2, pt2] = m_selected_features.second.feature->get_plane();
Vec3d proj_pt2;
Measure::get_point_projection_to_plane(pt2, pt1, normal1, proj_pt2);
auto new_pt2 = proj_pt2 + normal1 * dist;
Vec3d new_pt2 = proj_pt2 + normal1 * dist;

Vec3d displacement = new_pt2 - pt2;

Expand Down
4 changes: 2 additions & 2 deletions src/slic3r/GUI/SurfaceDrag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ Transform3d get_volume_transformation(
std::optional<float> current_angle,
const std::optional<double> &up_limit)
{
auto world_linear = world.linear();
auto world_linear = world.linear().eval();
// Calculate offset: transformation to wanted position
{
// Reset skew of the text Z axis:
Expand All @@ -609,7 +609,7 @@ Transform3d get_volume_transformation(
Vec3d text_z_world = world_linear.col(2); // world_linear * Vec3d::UnitZ()
auto z_rotation = Eigen::Quaternion<double, Eigen::DontAlign>::FromTwoVectors(text_z_world, world_dir);
Transform3d world_new = z_rotation * world;
auto world_new_linear = world_new.linear();
auto world_new_linear = world_new.linear().eval();

// Fix direction of up vector to zero initial rotation
if(up_limit.has_value()){
Expand Down
2 changes: 1 addition & 1 deletion src/slic3r/Utils/RaycastManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ std::optional<RaycastManager::Hit> RaycastManager::first_hit(const Vec3d& point,
// NOTE: Anisotropic transformation of normal is not perpendiculat to triangle
const Vec3i32 tri = hit_mesh->indices(hit_face);
std::array<Vec3d,3> pts;
auto tr = hit_tramsformation->linear();
auto tr = hit_tramsformation->linear().eval();
for (int i = 0; i < 3; ++i)
pts[i] = tr * hit_mesh->vertices(tri[i]).cast<double>();
Vec3d normal_world = (pts[1] - pts[0]).cross(pts[2] - pts[1]);
Expand Down

0 comments on commit da64ee9

Please sign in to comment.