Skip to content

Commit

Permalink
Support larger printer (up to hundred meters) (#5320)
Browse files Browse the repository at this point in the history
* Support larger printer sizes by using 64-bit.
SuperSlicer is referenced for some changes.

Co-authored-by: Merill <[email protected]>

* fix build error

* Improve performance when bed are large

* auto adjust grid size

* switch res for large printer

---------

Co-authored-by: Merill <[email protected]>
  • Loading branch information
SoftFever and supermerill authored May 17, 2024
1 parent 5bceebd commit a6c3109
Show file tree
Hide file tree
Showing 108 changed files with 496 additions and 437 deletions.
2 changes: 1 addition & 1 deletion sandboxes/aabb-evaluation/aabb-evaluation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void profile(const TriangleMesh &mesh)
Eigen::MatrixXd occlusion_output1;
{
std::vector<Vec3d> vertices;
std::vector<Vec3i> triangles;
std::vector<Vec3i32> triangles;
for (int i = 0; i < V.rows(); ++ i)
vertices.emplace_back(V.row(i).transpose());
for (int i = 0; i < F.rows(); ++ i)
Expand Down
26 changes: 13 additions & 13 deletions sandboxes/its_neighbor_index/ItsNeighborIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ FaceNeighborIndex its_create_neighbors_index_1(const indexed_triangle_set &its)

// Go through all edges of all facets and mark the facets touching each edge
for (size_t face_id = 0; face_id < its.indices.size(); ++face_id) {
const Vec3i &face = its.indices[face_id];
const Vec3i32 &face = its.indices[face_id];

EdgeID e1 = hash(face(0), face(1)), e2 = hash(face(1), face(2)),
e3 = hash(face(2), face(0));
Expand All @@ -59,7 +59,7 @@ FaceNeighborIndex its_create_neighbors_index_1(const indexed_triangle_set &its)

// Now collect the neighbors for each facet into the final index
for (size_t face_id = 0; face_id < its.indices.size(); ++face_id) {
const Vec3i &face = its.indices[face_id];
const Vec3i32 &face = its.indices[face_id];

EdgeID e1 = hash(face(0), face(1)), e2 = hash(face(1), face(2)),
e3 = hash(face(2), face(0));
Expand All @@ -77,9 +77,9 @@ FaceNeighborIndex its_create_neighbors_index_1(const indexed_triangle_set &its)
return index;
}

std::vector<Vec3i> its_create_neighbors_index_2(const indexed_triangle_set &its)
std::vector<Vec3i32> its_create_neighbors_index_2(const indexed_triangle_set &its)
{
std::vector<Vec3i> out(its.indices.size(), Vec3i(-1, -1, -1));
std::vector<Vec3i32> out(its.indices.size(), Vec3i32(-1, -1, -1));

// Create a mapping from triangle edge into face.
struct EdgeToFace {
Expand Down Expand Up @@ -157,9 +157,9 @@ std::vector<Vec3i> its_create_neighbors_index_2(const indexed_triangle_set &its)
return out;
}

std::vector<Vec3i> its_create_neighbors_index_3(const indexed_triangle_set &its)
std::vector<Vec3i32> its_create_neighbors_index_3(const indexed_triangle_set &its)
{
std::vector<Vec3i> out(its.indices.size(), Vec3i(-1, -1, -1));
std::vector<Vec3i32> out(its.indices.size(), Vec3i32(-1, -1, -1));

// Create a mapping from triangle edge into face.
struct EdgeToFace {
Expand Down Expand Up @@ -288,7 +288,7 @@ FaceNeighborIndex its_create_neighbors_index_4(const indexed_triangle_set &its)

// Go through all edges of all facets and mark the facets touching each edge
for (size_t face_id = 0; face_id < its.indices.size(); ++face_id) {
const Vec3i &face = its.indices[face_id];
const Vec3i32 &face = its.indices[face_id];

EdgeID e1 = hash(face(0), face(1)), e2 = hash(face(1), face(2)),
e3 = hash(face(2), face(0));
Expand All @@ -302,7 +302,7 @@ FaceNeighborIndex its_create_neighbors_index_4(const indexed_triangle_set &its)

// Now collect the neighbors for each facet into the final index
for (size_t face_id = 0; face_id < its.indices.size(); ++face_id) {
const Vec3i &face = its.indices[face_id];
const Vec3i32 &face = its.indices[face_id];

EdgeID e1 = hash(face(0), face(1)), e2 = hash(face(1), face(2)),
e3 = hash(face(2), face(0));
Expand Down Expand Up @@ -443,7 +443,7 @@ std::vector<std::array<size_t, 3>> its_create_neighbors_index_6(const indexed_tr

// Go through all edges of all facets and mark the facets touching each edge
for (size_t face_id = 0; face_id < facenum; ++face_id) {
const Vec3i &face = its.indices[face_id];
const Vec3i32 &face = its.indices[face_id];

edge_map[face_id * 3] = {hash(face(0), face(1)), face_id};
edge_map[face_id * 3 + 1] = {hash(face(1), face(2)), face_id};
Expand Down Expand Up @@ -503,7 +503,7 @@ std::vector<std::array<size_t, 3>> its_create_neighbors_index_7(const indexed_tr

// Go through all edges of all facets and mark the facets touching each edge
for (size_t face_id = 0; face_id < facenum; ++face_id) {
const Vec3i &face = its.indices[face_id];
const Vec3i32 &face = its.indices[face_id];

edge_map[face_id * 3] = {hash(face(0), face(1)), face_id};
edge_map[face_id * 3 + 1] = {hash(face(1), face(2)), face_id};
Expand Down Expand Up @@ -568,7 +568,7 @@ FaceNeighborIndex its_create_neighbors_index_8(const indexed_triangle_set &its)

// Go through all edges of all facets and mark the facets touching each edge
for (size_t face_id = 0; face_id < its.indices.size(); ++face_id) {
const Vec3i &face = its.indices[face_id];
const Vec3i32 &face = its.indices[face_id];

EdgeID e1 = hash(face(0), face(1)), e2 = hash(face(1), face(2)),
e3 = hash(face(2), face(0));
Expand All @@ -582,7 +582,7 @@ FaceNeighborIndex its_create_neighbors_index_8(const indexed_triangle_set &its)

// Now collect the neighbors for each facet into the final index
for (size_t face_id = 0; face_id < its.indices.size(); ++face_id) {
const Vec3i &face = its.indices[face_id];
const Vec3i32 &face = its.indices[face_id];

EdgeID e1 = hash(face(0), face(1)), e2 = hash(face(1), face(2)),
e3 = hash(face(2), face(0));
Expand All @@ -605,7 +605,7 @@ std::vector<Vec3crd> its_create_neighbors_index_9(const indexed_triangle_set &it
return create_face_neighbors_index(ex_seq, its);
}

std::vector<Vec3i> its_create_neighbors_index_10(const indexed_triangle_set &its)
std::vector<Vec3i32> its_create_neighbors_index_10(const indexed_triangle_set &its)
{
return create_face_neighbors_index(ex_tbb, its);
}
Expand Down
6 changes: 3 additions & 3 deletions sandboxes/its_neighbor_index/ItsNeighborIndex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
namespace Slic3r {
using FaceNeighborIndex = std::vector<std::array<size_t, 3>>;
FaceNeighborIndex its_create_neighbors_index_1(const indexed_triangle_set &its);
std::vector<Vec3i> its_create_neighbors_index_2(const indexed_triangle_set &its);
std::vector<Vec3i> its_create_neighbors_index_3(const indexed_triangle_set &its);
std::vector<Vec3i32> its_create_neighbors_index_2(const indexed_triangle_set &its);
std::vector<Vec3i32> its_create_neighbors_index_3(const indexed_triangle_set &its);
FaceNeighborIndex its_create_neighbors_index_4(const indexed_triangle_set &its);
//FaceNeighborIndex its_create_neighbors_index_4(const indexed_triangle_set &its);
std::vector<Vec3crd> its_create_neighbors_index_5(const indexed_triangle_set &its);
std::vector<std::array<size_t, 3>> its_create_neighbors_index_6(const indexed_triangle_set &its);
std::vector<std::array<size_t, 3>> its_create_neighbors_index_7(const indexed_triangle_set &its);
FaceNeighborIndex its_create_neighbors_index_8(const indexed_triangle_set &its);
std::vector<Vec3crd> its_create_neighbors_index_9(const indexed_triangle_set &its);
std::vector<Vec3i> its_create_neighbors_index_10(const indexed_triangle_set &its);
std::vector<Vec3i32> its_create_neighbors_index_10(const indexed_triangle_set &its);

std::vector<std::vector<size_t>> create_vertex_faces_index(const indexed_triangle_set &its);
}
2 changes: 1 addition & 1 deletion sandboxes/opencsg/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ void Controller::on_scroll(long v, long d, MouseInput::WheelAxis /*wa*/)
void Controller::on_moved_to(long x, long y)
{
if (m_left_btn) {
call_cameras(&Camera::rotate, (Vec2i{x, y} - m_mouse_pos).cast<float>());
call_cameras(&Camera::rotate, (Vec2i32{x, y} - m_mouse_pos).cast<float>());
call(&Display::repaint, m_displays);
}

Expand Down
6 changes: 3 additions & 3 deletions sandboxes/opencsg/Engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ class Scene
class Display : public Scene::Listener
{
protected:
Vec2i m_size;
Vec2i32 m_size;
bool m_initialized = false;

std::shared_ptr<Camera> m_camera;
Expand All @@ -379,7 +379,7 @@ class Display : public Scene::Listener
virtual void swap_buffers() = 0;
virtual void set_active(long width, long height);
virtual void set_screen_size(long width, long height);
Vec2i get_screen_size() const { return m_size; }
Vec2i32 get_screen_size() const { return m_size; }

virtual void repaint();

Expand Down Expand Up @@ -438,7 +438,7 @@ class Controller : public std::enable_shared_from_this<Controller>,
public Scene::Listener
{
long m_wheel_pos = 0;
Vec2i m_mouse_pos, m_mouse_pos_rprev, m_mouse_pos_lprev;
Vec2i32 m_mouse_pos, m_mouse_pos_rprev, m_mouse_pos_lprev;
bool m_left_btn = false, m_right_btn = false;

std::shared_ptr<Scene> m_scene;
Expand Down
8 changes: 4 additions & 4 deletions src/admesh/connect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ struct HashEdge {
bool load_nearby(const stl_file *stl, const stl_vertex &a, const stl_vertex &b, float tolerance)
{
// Index of a grid cell spaced by tolerance.
typedef Eigen::Matrix<int32_t, 3, 1, Eigen::DontAlign> Vec3i;
Vec3i vertex1 = ((a - stl->stats.min) / tolerance).cast<int32_t>();
Vec3i vertex2 = ((b - stl->stats.min) / tolerance).cast<int32_t>();
static_assert(sizeof(Vec3i) == 12, "size of Vec3i incorrect");
typedef Eigen::Matrix<int32_t, 3, 1, Eigen::DontAlign> Vec3i32;
Vec3i32 vertex1 = ((a - stl->stats.min) / tolerance).cast<int32_t>();
Vec3i32 vertex2 = ((b - stl->stats.min) / tolerance).cast<int32_t>();
static_assert(sizeof(Vec3i32) == 12, "size of Vec3i32 incorrect");

if (vertex1 == vertex2)
// Both vertices hash to the same value
Expand Down
2 changes: 1 addition & 1 deletion src/clipper/clipper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ enum PolyFillType { pftEvenOdd, pftNonZero, pftPositive, pftNegative };
// If defined, Clipper will work with 32bit signed int coordinates to reduce memory
// consumption and to speed up exact orientation predicate calculation.
// In that case, coordinates and their differences (vectors of the coordinates) have to fit int32_t.
#define CLIPPERLIB_INT32
// #define CLIPPERLIB_INT32

// Point coordinate type
#ifdef CLIPPERLIB_INT32
Expand Down
4 changes: 2 additions & 2 deletions src/libslic3r/AABBMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const std::vector<Vec3f>& AABBMesh::vertices() const



const std::vector<Vec3i>& AABBMesh::indices() const
const std::vector<Vec3i32>& AABBMesh::indices() const
{
return m_tm->indices;
}
Expand All @@ -136,7 +136,7 @@ const Vec3f& AABBMesh::vertices(size_t idx) const



const Vec3i& AABBMesh::indices(size_t idx) const
const Vec3i32& AABBMesh::indices(size_t idx) const
{
return m_tm->indices[idx];
}
Expand Down
8 changes: 4 additions & 4 deletions src/libslic3r/AABBMesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class AABBMesh {

std::unique_ptr<AABBImpl> m_aabb;
VertexFaceIndex m_vfidx; // vertex-face index
std::vector<Vec3i> m_fnidx; // face-neighbor index
std::vector<Vec3i32> m_fnidx; // face-neighbor index

#ifdef SLIC3R_HOLE_RAYCASTER
// This holds a copy of holes in the mesh. Initialized externally
Expand All @@ -57,9 +57,9 @@ class AABBMesh {
~AABBMesh();

const std::vector<Vec3f>& vertices() const;
const std::vector<Vec3i>& indices() const;
const std::vector<Vec3i32>& indices() const;
const Vec3f& vertices(size_t idx) const;
const Vec3i& indices(size_t idx) const;
const Vec3i32& indices(size_t idx) const;

// Result of a raycast
class hit_result {
Expand Down Expand Up @@ -133,7 +133,7 @@ class AABBMesh {
const indexed_triangle_set * get_triangle_mesh() const { return m_tm; }

const VertexFaceIndex &vertex_face_index() const { return m_vfidx; }
const std::vector<Vec3i> &face_neighbor_index() const { return m_fnidx; }
const std::vector<Vec3i32> &face_neighbor_index() const { return m_fnidx; }
};


Expand Down
2 changes: 1 addition & 1 deletion src/libslic3r/AABBTreeIndirect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ class BoundingBoxWrapper {
m_bbox(bbox.min - Point(SCALED_EPSILON, SCALED_EPSILON), bbox.max + Point(SCALED_EPSILON, SCALED_EPSILON)) {}
size_t idx() const { return m_idx; }
const BoundingBox& bbox() const { return m_bbox; }
Point centroid() const { return ((m_bbox.min().cast<int64_t>() + m_bbox.max().cast<int64_t>()) / 2).cast<int32_t>(); }
Point centroid() const { return (m_bbox.min() + m_bbox.max() / 2); }
private:
size_t m_idx;
BoundingBox m_bbox;
Expand Down
15 changes: 9 additions & 6 deletions src/libslic3r/Arachne/SkeletalTrapezoidation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ void SkeletalTrapezoidation::generateToolpaths(std::vector<VariableWidthLines> &
export_graph_to_svg(debug_out_path("ST-updateIsCentral-final-%d.svg", iRun), this->graph, this->outline);
#endif

filterCentral(central_filter_dist);
filterCentral(central_filter_dist());

#ifdef ARACHNE_DEBUG
export_graph_to_svg(debug_out_path("ST-filterCentral-final-%d.svg", iRun), this->graph, this->outline);
Expand Down Expand Up @@ -729,7 +729,7 @@ void SkeletalTrapezoidation::filterNoncentralRegions()
BOOST_LOG_TRIVIAL(warning) << "Encountered an uninitialized bead at the boundary!";
}
assert(edge.to->data.bead_count >= 0 || edge.to->data.distance_to_boundary == 0);
constexpr coord_t max_dist = scaled<coord_t>(0.4);
const coord_t max_dist = scaled<coord_t>(0.4);
filterNoncentralRegions(&edge, edge.to->data.bead_count, 0, max_dist);
}
}
Expand Down Expand Up @@ -1303,6 +1303,7 @@ static inline Point normal(const Point& p0, coord_t len)

void SkeletalTrapezoidation::applyTransitions(ptr_vector_t<std::list<TransitionEnd>>& edge_transition_ends)
{
const auto _snap_dist = snap_dist();
for (edge_t& edge : graph.edges)
{
if (edge.twin->data.hasTransitionEnds())
Expand Down Expand Up @@ -1348,7 +1349,7 @@ void SkeletalTrapezoidation::applyTransitions(ptr_vector_t<std::list<TransitionE
coord_t new_node_bead_count = transition_end.is_lower_end? transition_end.lower_bead_count : transition_end.lower_bead_count + 1;
coord_t end_pos = transition_end.pos;
node_t* close_node = (end_pos < ab_size / 2)? from : to;
if ((end_pos < snap_dist || end_pos > ab_size - snap_dist)
if ((end_pos < _snap_dist || end_pos > ab_size - _snap_dist)
&& close_node->data.bead_count == new_node_bead_count
)
{
Expand Down Expand Up @@ -1390,6 +1391,7 @@ bool SkeletalTrapezoidation::isEndOfCentral(const edge_t& edge_to) const

void SkeletalTrapezoidation::generateExtraRibs()
{
const auto _snap_dist = snap_dist();
for (auto edge_it = graph.edges.begin(); edge_it != graph.edges.end(); ++edge_it)
{
edge_t& edge = *edge_it;
Expand Down Expand Up @@ -1433,7 +1435,7 @@ void SkeletalTrapezoidation::generateExtraRibs()
assert(end_pos > 0);
assert(end_pos < ab_size);
node_t* close_node = (end_pos < ab_size / 2)? from : to;
if ((end_pos < snap_dist || end_pos > ab_size - snap_dist)
if ((end_pos < _snap_dist || end_pos > ab_size - _snap_dist)
&& close_node->data.bead_count == new_node_bead_count
)
{
Expand Down Expand Up @@ -1593,6 +1595,7 @@ SkeletalTrapezoidation::edge_t* SkeletalTrapezoidation::getQuadMaxRedgeTo(edge_t

void SkeletalTrapezoidation::propagateBeadingsUpward(std::vector<edge_t*>& upward_quad_mids, ptr_vector_t<BeadingPropagation>& node_beadings)
{
const auto _central_filter_dist = central_filter_dist();
for (auto upward_quad_mids_it = upward_quad_mids.rbegin(); upward_quad_mids_it != upward_quad_mids.rend(); ++upward_quad_mids_it)
{
edge_t* upward_edge = *upward_quad_mids_it;
Expand All @@ -1609,7 +1612,7 @@ void SkeletalTrapezoidation::propagateBeadingsUpward(std::vector<edge_t*>& upwar
{ // Only propagate to places where there is place
continue;
}
assert((upward_edge->from->data.distance_to_boundary != upward_edge->to->data.distance_to_boundary || shorter_then(upward_edge->to->p - upward_edge->from->p, central_filter_dist)) && "zero difference R edges should always be central");
assert((upward_edge->from->data.distance_to_boundary != upward_edge->to->data.distance_to_boundary || shorter_then(upward_edge->to->p - upward_edge->from->p, _central_filter_dist)) && "zero difference R edges should always be central");
coord_t length = (upward_edge->to->p - upward_edge->from->p).cast<int64_t>().norm();
BeadingPropagation upper_beading = lower_beading;
upper_beading.dist_to_bottom_source += length;
Expand Down Expand Up @@ -1839,7 +1842,7 @@ std::shared_ptr<SkeletalTrapezoidationJoint::BeadingPropagation> SkeletalTrapezo
{
if (node->data.bead_count == -1)
{ // This bug is due to too small central edges
constexpr coord_t nearby_dist = scaled<coord_t>(0.1);
const coord_t nearby_dist = scaled<coord_t>(0.1);
auto nearest_beading = getNearestBeading(node, nearby_dist);
if (nearest_beading)
{
Expand Down
6 changes: 4 additions & 2 deletions src/libslic3r/Arachne/SkeletalTrapezoidation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ class SkeletalTrapezoidation
coord_t transition_filter_dist; //!< Filter transition mids (i.e. anchors) closer together than this
coord_t allowed_filter_deviation; //!< The allowed line width deviation induced by filtering
coord_t beading_propagation_transition_dist; //!< When there are different beadings propagated from below and from above, use this transitioning distance
static constexpr coord_t central_filter_dist = scaled<coord_t>(0.02); //!< Filter areas marked as 'central' smaller than this
static constexpr coord_t snap_dist = scaled<coord_t>(0.02); //!< Generic arithmatic inaccuracy. Only used to determine whether a transition really needs to insert an extra edge.
//!< Filter areas marked as 'central' smaller than this
inline coord_t central_filter_dist() { return scaled<coord_t>(0.02); }
//!< Generic arithmatic inaccuracy. Only used to determine whether a transition really needs to insert an extra edge.
inline coord_t snap_dist() { return scaled<coord_t>(0.02); }

/*!
* The strategy to use to fill a certain shape with lines.
Expand Down
14 changes: 7 additions & 7 deletions src/libslic3r/Arachne/WallToolPaths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ void fixSelfIntersections(const coord_t epsilon, Polygons &thiss)

// Points too close to line segments should be moved a little away from those line segments, but less than epsilon,
// so at least half-epsilon distance between points can still be guaranteed.
constexpr coord_t grid_size = scaled<coord_t>(2.);
const coord_t grid_size = scaled<coord_t>(2.);
auto query_grid = createLocToLineGrid(thiss, grid_size);

const auto move_dist = std::max<int64_t>(2L, half_epsilon - 2);
Expand Down Expand Up @@ -473,11 +473,11 @@ const std::vector<VariableWidthLines> &WallToolPaths::generate()
if (this->inset_count < 1)
return toolpaths;

const coord_t smallest_segment = Slic3r::Arachne::meshfix_maximum_resolution;
const coord_t allowed_distance = Slic3r::Arachne::meshfix_maximum_deviation;
const coord_t smallest_segment = Slic3r::Arachne::meshfix_maximum_resolution();
const coord_t allowed_distance = Slic3r::Arachne::meshfix_maximum_deviation();
const coord_t epsilon_offset = (allowed_distance / 2) - 1;
const double transitioning_angle = Geometry::deg2rad(m_params.wall_transition_angle);
constexpr coord_t discretization_step_size = scaled<coord_t>(0.8);
const coord_t discretization_step_size = scaled<coord_t>(0.8);

// Simplify outline for boost::voronoi consumption. Absolutely no self intersections or near-self intersections allowed:
// TODO: Open question: Does this indeed fix all (or all-but-one-in-a-million) cases for manifold but otherwise possibly complex polygons?
Expand Down Expand Up @@ -692,9 +692,9 @@ void WallToolPaths::simplifyToolPaths(std::vector<VariableWidthLines> &toolpaths
{
for (size_t toolpaths_idx = 0; toolpaths_idx < toolpaths.size(); ++toolpaths_idx)
{
const int64_t maximum_resolution = Slic3r::Arachne::meshfix_maximum_resolution;
const int64_t maximum_deviation = Slic3r::Arachne::meshfix_maximum_deviation;
const int64_t maximum_extrusion_area_deviation = Slic3r::Arachne::meshfix_maximum_extrusion_area_deviation; // unit: μm²
const int64_t maximum_resolution = Slic3r::Arachne::meshfix_maximum_resolution();
const int64_t maximum_deviation = Slic3r::Arachne::meshfix_maximum_deviation();
const int64_t maximum_extrusion_area_deviation = Slic3r::Arachne::meshfix_maximum_extrusion_area_deviation(); // unit: μm²
for (auto& line : toolpaths[toolpaths_idx])
{
line.simplify(maximum_resolution * maximum_resolution, maximum_deviation * maximum_deviation, maximum_extrusion_area_deviation);
Expand Down
Loading

0 comments on commit a6c3109

Please sign in to comment.