Skip to content

Commit

Permalink
Support larger printer sizes by using 64-bit.
Browse files Browse the repository at this point in the history
SuperSlicer is referenced for some changes.

Co-authored-by: Merill <[email protected]>
  • Loading branch information
SoftFever and supermerill committed May 10, 2024
1 parent 5bceebd commit 9b2c2bf
Show file tree
Hide file tree
Showing 87 changed files with 380 additions and 362 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
2 changes: 1 addition & 1 deletion src/libslic3r/Arachne/utils/linearAlg2D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ inline static bool isInsideCorner(const Point &a, const Point &b, const Point &c
//

auto normal = [](const Point &p0, coord_t len) -> Point {
int64_t _len = p0.cast<int64_t>().norm();
int64_t _len = p0.norm();
if (_len < 1)
return {len, 0};
return (p0.cast<int64_t>() * int64_t(len) / _len).cast<coord_t>();
Expand Down
18 changes: 9 additions & 9 deletions src/libslic3r/CutSurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ using IsOnSides = std::vector<std::array<bool, 4>>;
/// <param name="t">Triangle</param>
/// <param name="is_on_sides">Flag is vertex index out of plane</param>
/// <returns>True when triangle is out of one of plane</returns>
bool is_all_on_one_side(const Vec3i &t, const IsOnSides& is_on_sides);
bool is_all_on_one_side(const Vec3i32 &t, const IsOnSides& is_on_sides);

} // namespace priv

Expand All @@ -718,7 +718,7 @@ bool priv::is_out_of(const Vec3d &v, const PointNormal &point_normal)
return signed_distance > 1e-5;
};

bool priv::is_all_on_one_side(const Vec3i &t, const IsOnSides& is_on_sides) {
bool priv::is_all_on_one_side(const Vec3i32 &t, const IsOnSides& is_on_sides) {
for (size_t side = 0; side < 4; side++) {
bool result = true;
for (auto vi : t) {
Expand Down Expand Up @@ -1891,7 +1891,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];
Vec2i p_ = p.cast<int>();
auto p_ = p.cast<coord_t>();
return p_ == poly[id.point_index];
};

Expand Down Expand Up @@ -3559,7 +3559,7 @@ SurfaceCut priv::patch2cut(SurfacePatch &patch)
assert(mesh.next(mesh.next(mesh.next(hi))) == hi);

// triangle indicies
Vec3i ti;
Vec3i32 ti;
size_t i = 0;
for (VI vi : { mesh.source(hi),
mesh.target(hi),
Expand Down Expand Up @@ -3742,7 +3742,7 @@ indexed_triangle_set priv::create_indexed_triangle_set(
HI hi_end = hi;

int ti = 0;
Vec3i t;
Vec3i32 t;

do {
VI vi = mesh.source(hi);
Expand Down Expand Up @@ -3802,8 +3802,8 @@ void priv::store(const CutAOIs &aois, const CutMesh &mesh, const std::string &di
size_t bi2 = its.vertices.size();
its.vertices.push_back(b + dir);

its.indices.push_back(Vec3i(ai, ai2, bi));
its.indices.push_back(Vec3i(ai2, bi2, bi));
its.indices.push_back(Vec3i32(ai, ai2, bi));
its.indices.push_back(Vec3i32(ai2, bi2, bi));
}
return its;
};
Expand Down Expand Up @@ -4002,8 +4002,8 @@ indexed_triangle_set priv::create_contour_its(
size_t bi2 = result.vertices.size();
result.vertices.push_back(b + dir);

result.indices.push_back(Vec3i(ai, bi, ai2));
result.indices.push_back(Vec3i(ai2, bi, bi2));
result.indices.push_back(Vec3i32(ai, bi, ai2));
result.indices.push_back(Vec3i32(ai2, bi, bi2));
prev_vi = vi;
}
return result;
Expand Down
12 changes: 6 additions & 6 deletions src/libslic3r/Emboss.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1504,7 +1504,7 @@ indexed_triangle_set polygons2model_unique(
const Points &points)
{
// CW order of triangle indices
std::vector<Vec3i> shape_triangles=Triangulation::triangulate(shape2d, points);
std::vector<Vec3i32> shape_triangles=Triangulation::triangulate(shape2d, points);
uint32_t count_point = points.size();

indexed_triangle_set result;
Expand All @@ -1525,10 +1525,10 @@ indexed_triangle_set polygons2model_unique(
std::make_move_iterator(back_points.end()));
result.indices.reserve(shape_triangles.size() * 2 + points.size() * 2);
// top triangles - change to CCW
for (const Vec3i &t : shape_triangles)
for (const Vec3i32 &t : shape_triangles)
result.indices.emplace_back(t.x(), t.z(), t.y());
// bottom triangles - use CW
for (const Vec3i &t : shape_triangles)
for (const Vec3i32 &t : shape_triangles)
result.indices.emplace_back(t.x() + count_point,
t.y() + count_point,
t.z() + count_point);
Expand Down Expand Up @@ -1564,7 +1564,7 @@ indexed_triangle_set polygons2model_duplicit(
{
// CW order of triangle indices
std::vector<uint32_t> changes = Triangulation::create_changes(points, duplicits);
std::vector<Vec3i> shape_triangles = Triangulation::triangulate(shape2d, points, changes);
std::vector<Vec3i32> shape_triangles = Triangulation::triangulate(shape2d, points, changes);
uint32_t count_point = *std::max_element(changes.begin(), changes.end()) + 1;

indexed_triangle_set result;
Expand Down Expand Up @@ -1596,10 +1596,10 @@ indexed_triangle_set polygons2model_duplicit(

result.indices.reserve(shape_triangles.size() * 2 + points.size() * 2);
// top triangles - change to CCW
for (const Vec3i &t : shape_triangles)
for (const Vec3i32 &t : shape_triangles)
result.indices.emplace_back(t.x(), t.z(), t.y());
// bottom triangles - use CW
for (const Vec3i &t : shape_triangles)
for (const Vec3i32 &t : shape_triangles)
result.indices.emplace_back(t.x() + count_point, t.y() + count_point,
t.z() + count_point);

Expand Down
3 changes: 2 additions & 1 deletion src/libslic3r/Fill/Fill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "FillLightning.hpp"
#include "FillConcentricInternal.hpp"
#include "FillConcentric.hpp"
#include "libslic3r.h"

namespace Slic3r {

Expand Down Expand Up @@ -336,7 +337,7 @@ void split_solid_surface(size_t layer_id, const SurfaceFill &fill, ExPolygons &n
squared_distance_limit_reconnection) {
traced_poly.lows.push_back(candidates_begin->a);
} else {
traced_poly.lows.push_back(traced_poly.lows.back() + Point{scaled_spacing / 2, 0});
traced_poly.lows.push_back(traced_poly.lows.back() + Point{scaled_spacing / 2, coord_t(0)});
traced_poly.lows.push_back(candidates_begin->a - Point{scaled_spacing / 2, 0});
traced_poly.lows.push_back(candidates_begin->a);
}
Expand Down
Loading

0 comments on commit 9b2c2bf

Please sign in to comment.