From 782d3706e13695023f077bf0178e5a862f91e427 Mon Sep 17 00:00:00 2001 From: supermerill Date: Mon, 8 Apr 2019 19:41:04 +0200 Subject: [PATCH] Update/clean code where a wrong int type is used (unsafe int, bad type, ...) as that that can be problematic if the type of coord_t change. --- src/libslic3r/Point.hpp | 25 +++---- src/libslic3r/SLA/SLAAutoSupports.cpp | 12 ++-- src/libslic3r/SLA/SLAAutoSupports.hpp | 12 ++-- src/libslic3r/SLA/SLABoilerPlate.hpp | 22 +++---- src/libslic3r/SLA/SLASupportTree.cpp | 68 ++++++++++---------- src/libslic3r/SLA/SLASupportTree.hpp | 9 +-- src/libslic3r/SLA/SLASupportTreeIGL.cpp | 8 +-- src/libslic3r/Slicing.cpp | 26 ++++---- src/libslic3r/TriangleMesh.cpp | 50 +++++++------- src/libslic3r/TriangleMesh.hpp | 2 +- src/slic3r/GUI/3DScene.cpp | 8 +-- src/slic3r/GUI/GLCanvas3D.cpp | 2 +- src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp | 2 +- src/slic3r/GUI/Plater.cpp | 2 +- 14 files changed, 121 insertions(+), 127 deletions(-) diff --git a/src/libslic3r/Point.hpp b/src/libslic3r/Point.hpp index 112918ece..2df30a61e 100644 --- a/src/libslic3r/Point.hpp +++ b/src/libslic3r/Point.hpp @@ -20,12 +20,12 @@ typedef Point Vector; // Eigen types, to replace the Slic3r's own types in the future. // Vector types with a fixed point coordinate base type. -typedef Eigen::Matrix Vec2crd; -typedef Eigen::Matrix Vec3crd; -typedef Eigen::Matrix Vec2i; -typedef Eigen::Matrix Vec3i; -typedef Eigen::Matrix Vec2i64; -typedef Eigen::Matrix Vec3i64; +typedef Eigen::Matrix Vec2i32; +typedef Eigen::Matrix Vec3i32; +typedef Eigen::Matrix Vec2i64; +typedef Eigen::Matrix Vec3i64; +typedef Vec2i64 Vec2crd; +typedef Vec3i64 Vec3crd; // Vector types with a double coordinate base type. typedef Eigen::Matrix Vec2f; @@ -47,23 +47,23 @@ typedef Eigen::Transform Transform3d inline bool operator<(const Vec2d &lhs, const Vec2d &rhs) { return lhs(0) < rhs(0) || (lhs(0) == rhs(0) && lhs(1) < rhs(1)); } +inline int32_t cross2(const Vec2i32 &v1, const Vec2i32 &v2) { return v1(0) * v2(1) - v1(1) * v2(0); } inline int64_t cross2(const Vec2i64 &v1, const Vec2i64 &v2) { return v1(0) * v2(1) - v1(1) * v2(0); } -inline coord_t cross2(const Vec2crd &v1, const Vec2crd &v2) { return v1(0) * v2(1) - v1(1) * v2(0); } inline float cross2(const Vec2f &v1, const Vec2f &v2) { return v1(0) * v2(1) - v1(1) * v2(0); } inline double cross2(const Vec2d &v1, const Vec2d &v2) { return v1(0) * v2(1) - v1(1) * v2(0); } inline coordf_t dot(const Vec2d &v1, const Vec2d &v2) { return v1.x() * v2.x() + v1.y() * v2.y(); } inline coordf_t dot(const Vec2d &v) { return v.x() * v.x() + v.y() * v.y(); } -inline Vec2crd to_2d(const Vec3crd &pt3) { return Vec2crd(pt3(0), pt3(1)); } +inline Vec3i32 to_2d(const Vec3i32 &pt3) { return Vec3i32(pt3(0), pt3(1)); } inline Vec2i64 to_2d(const Vec3i64 &pt3) { return Vec2i64(pt3(0), pt3(1)); } inline Vec2f to_2d(const Vec3f &pt3) { return Vec2f (pt3(0), pt3(1)); } inline Vec2d to_2d(const Vec3d &pt3) { return Vec2d (pt3(0), pt3(1)); } inline Vec3d to_3d(const Vec2d &v, double z) { return Vec3d(v(0), v(1), z); } inline Vec3f to_3d(const Vec2f &v, float z) { return Vec3f(v(0), v(1), z); } +inline Vec3i32 to_3d(const Vec3i32 &v, float z) { return Vec3i32(int32_t(v(0)), int32_t(v(1)), int32_t(z)); } inline Vec3i64 to_3d(const Vec2i64 &v, float z) { return Vec3i64(int64_t(v(0)), int64_t(v(1)), int64_t(z)); } -inline Vec3crd to_3d(const Vec3crd &p, coord_t z) { return Vec3crd(p(0), p(1), z); } inline Vec2d unscale(coord_t x, coord_t y) { return Vec2d(unscale(x), unscale(y)); } inline Vec2d unscale(const Vec2crd &pt) { return Vec2d(unscale(pt(0)), unscale(pt(1))); } @@ -86,15 +86,16 @@ public: typedef coord_t coord_type; Point() : Vec2crd() { (*this)(0) = 0; (*this)(1) = 0; } - Point(coord_t x, coord_t y) { (*this)(0) = x; (*this)(1) = y; } - Point(int64_t x, int64_t y) { (*this)(0) = coord_t(x); (*this)(1) = coord_t(y); } // for Clipper - Point(double x, double y) { (*this)(0) = coord_t(lrint(x)); (*this)(1) = coord_t(lrint(y)); } + Point(int32_t x, int32_t y) { (*this)(0) = coord_t(x); (*this)(1) = coord_t(y); } + Point(int64_t x, int64_t y) { (*this)(0) = coord_t(x); (*this)(1) = coord_t(y); } + Point(double x, double y) { (*this)(0) = coord_t(lrintl(x)); (*this)(1) = coord_t(lrintl(y)); } Point(const Point &rhs) { *this = rhs; } // This constructor allows you to construct Point from Eigen expressions template Point(const Eigen::MatrixBase &other) : Vec2crd(other) {} static Point new_scale(coordf_t x, coordf_t y) { return Point(coord_t(scale_(x)), coord_t(scale_(y))); } static Point new_scale(const Point &p) { return Point(coord_t(scale_(p.x())), coord_t(scale_(p.y()))); } + static Point new_scale(const Vec2d &p) { return Point(scale_(p.x()), scale_(p.y())); } // This method allows you to assign Eigen expressions to MyVectorType template diff --git a/src/libslic3r/SLA/SLAAutoSupports.cpp b/src/libslic3r/SLA/SLAAutoSupports.cpp index 9e9f07b6c..f13484452 100644 --- a/src/libslic3r/SLA/SLAAutoSupports.cpp +++ b/src/libslic3r/SLA/SLAAutoSupports.cpp @@ -335,7 +335,7 @@ static inline std::vector poisson_disk_from_samples(const std::vector raw_samples_sorted; RawSample sample; @@ -361,7 +361,7 @@ static inline std::vector poisson_disk_from_samples(const std::vector()(cell_id.x()) ^ std::hash()(cell_id.y() * 593); } }; @@ -369,11 +369,11 @@ static inline std::vector poisson_disk_from_samples(const std::vector Cells; + typedef std::unordered_map Cells; Cells cells; { typename Cells::iterator last_cell_id_it; - Vec2i last_cell_id(-1, -1); + Vec2i32 last_cell_id(-1, -1); for (int i = 0; i < raw_samples_sorted.size(); ++ i) { const RawSample &sample = raw_samples_sorted[i]; if (sample.cell_id == last_cell_id) { @@ -397,7 +397,7 @@ static inline std::vector poisson_disk_from_samples(const std::vector poisson_disk_from_samples(const std::vectorsecond; for (int i_sample = 0; i_sample < neighbor.num_poisson_samples; ++ i_sample) diff --git a/src/libslic3r/SLA/SLAAutoSupports.hpp b/src/libslic3r/SLA/SLAAutoSupports.hpp index 038b505da..15a5033bd 100644 --- a/src/libslic3r/SLA/SLAAutoSupports.hpp +++ b/src/libslic3r/SLA/SLAAutoSupports.hpp @@ -129,17 +129,17 @@ public: struct PointGrid3D { struct GridHash { - std::size_t operator()(const Vec3i &cell_id) const { + std::size_t operator()(const Vec3i32 &cell_id) const { return std::hash()(cell_id.x()) ^ std::hash()(cell_id.y() * 593) ^ std::hash()(cell_id.z() * 7919); } }; - typedef std::unordered_multimap Grid; + typedef std::unordered_multimap Grid; Vec3f cell_size; Grid grid; - Vec3i cell_id(const Vec3f &pos) { - return Vec3i(int(floor(pos.x() / cell_size.x())), + Vec3i32 cell_id(const Vec3f &pos) { + return Vec3i32(int(floor(pos.x() / cell_size.x())), int(floor(pos.y() / cell_size.y())), int(floor(pos.z() / cell_size.z()))); } @@ -153,7 +153,7 @@ public: bool collides_with(const Vec2f &pos, Structure *island, float radius) { Vec3f pos3d(pos.x(), pos.y(), float(island->layer->print_z)); - Vec3i cell = cell_id(pos3d); + Vec3i32 cell = cell_id(pos3d); std::pair it_pair = grid.equal_range(cell); if (collides_with(pos3d, radius, it_pair.first, it_pair.second)) return true; @@ -162,7 +162,7 @@ public: for (int k = -1; k < 1; ++ k) { if (i == 0 && j == 0 && k == 0) continue; - it_pair = grid.equal_range(cell + Vec3i(i, j, k)); + it_pair = grid.equal_range(cell + Vec3i32(i, j, k)); if (collides_with(pos3d, radius, it_pair.first, it_pair.second)) return true; } diff --git a/src/libslic3r/SLA/SLABoilerPlate.hpp b/src/libslic3r/SLA/SLABoilerPlate.hpp index 602121af9..a8d2f4865 100644 --- a/src/libslic3r/SLA/SLABoilerPlate.hpp +++ b/src/libslic3r/SLA/SLABoilerPlate.hpp @@ -29,14 +29,14 @@ inline coordf_t& x(Vec3d& p) { return p(0); } inline coordf_t& y(Vec3d& p) { return p(1); } inline coordf_t& z(Vec3d& p) { return p(2); } -inline coord_t& x(Vec3crd& p) { return p(0); } -inline coord_t& y(Vec3crd& p) { return p(1); } -inline coord_t& z(Vec3crd& p) { return p(2); } -inline coord_t x(const Vec3crd& p) { return p(0); } -inline coord_t y(const Vec3crd& p) { return p(1); } -inline coord_t z(const Vec3crd& p) { return p(2); } +inline int32_t& x(Vec3i32& p) { return p(0); } +inline int32_t& y(Vec3i32& p) { return p(1); } +inline int32_t& z(Vec3i32& p) { return p(2); } +inline int32_t x(const Vec3i32& p) { return p(0); } +inline int32_t y(const Vec3i32& p) { return p(1); } +inline int32_t z(const Vec3i32& p) { return p(2); } -using Indices = std::vector; +using Indices = std::vector; /// Intermediate struct for a 3D mesh struct Contour3D { @@ -44,14 +44,14 @@ struct Contour3D { Indices indices; void merge(const Contour3D& ctr) { - auto s3 = coord_t(points.size()); - auto s = indices.size(); + size_t s3 = size_t(points.size()); + size_t s = indices.size(); points.insert(points.end(), ctr.points.begin(), ctr.points.end()); indices.insert(indices.end(), ctr.indices.begin(), ctr.indices.end()); for(size_t n = s; n < indices.size(); n++) { - auto& idx = indices[n]; x(idx) += s3; y(idx) += s3; z(idx) += s3; + Vec3i32& idx = indices[n]; x(idx) += s3; y(idx) += s3; z(idx) += s3; } } @@ -71,7 +71,7 @@ struct Contour3D { } for(auto& f : indices) { - stream << "f " << (f + Vec3i(1, 1, 1)).transpose() << "\n"; + stream << "f " << (f + Vec3i32(1, 1, 1)).transpose() << "\n"; } } }; diff --git a/src/libslic3r/SLA/SLASupportTree.cpp b/src/libslic3r/SLA/SLASupportTree.cpp index 5efa3001c..7c4bf96bf 100644 --- a/src/libslic3r/SLA/SLASupportTree.cpp +++ b/src/libslic3r/SLA/SLASupportTree.cpp @@ -102,8 +102,8 @@ Contour3D sphere(double rho, Portion portion = make_portion(0.0, 2.0*PI), // prohibit close to zero radius if(rho <= 1e-6 && rho >= -1e-6) return ret; - auto& vertices = ret.points; - auto& facets = ret.indices; + Pointf3s& vertices = ret.points; + Indices& facets = ret.indices; // Algorithm: // Add points one-by-one to the sphere grid and form facets using relative @@ -128,7 +128,7 @@ Contour3D sphere(double rho, Portion portion = make_portion(0.0, 2.0*PI), if(sbegin == 0) vertices.emplace_back(Vec3d(0.0, 0.0, -rho + increment*sbegin*2.0*rho)); - auto id = coord_t(vertices.size()); + int32_t id = int32_t(vertices.size()); for (size_t i = 0; i < ring.size(); i++) { // Fixed scaling const double z = -rho + increment*rho*2.0 * (sbegin + 1.0); @@ -138,8 +138,8 @@ Contour3D sphere(double rho, Portion portion = make_portion(0.0, 2.0*PI), vertices.emplace_back(Vec3d(b(0), b(1), z)); if(sbegin == 0) - facets.emplace_back((i == 0) ? Vec3crd(coord_t(ring.size()), 0, 1) : - Vec3crd(id - 1, 0, id)); + facets.emplace_back((i == 0) ? Vec3i32(int32_t(ring.size()), 0, 1) : + Vec3i32(id - 1, 0, id)); ++ id; } @@ -152,15 +152,15 @@ Contour3D sphere(double rho, Portion portion = make_portion(0.0, 2.0*PI), for (size_t i = 0; i < ring.size(); i++) { Vec2d b = Eigen::Rotation2Dd(ring[i]) * Eigen::Vector2d(0, r); vertices.emplace_back(Vec3d(b(0), b(1), z)); - auto id_ringsize = coord_t(id - int(ring.size())); + auto id_ringsize = int32_t(id - int(ring.size())); if (i == 0) { // wrap around - facets.emplace_back(Vec3crd(id - 1, id, - id + coord_t(ring.size() - 1))); - facets.emplace_back(Vec3crd(id - 1, id_ringsize, id)); + facets.emplace_back(Vec3i32(id - 1, id, + id + int32_t(ring.size() - 1))); + facets.emplace_back(Vec3i32(id - 1, id_ringsize, id)); } else { - facets.emplace_back(Vec3crd(id_ringsize - 1, id_ringsize, id)); - facets.emplace_back(Vec3crd(id - 1, id_ringsize - 1, id)); + facets.emplace_back(Vec3i32(id_ringsize - 1, id_ringsize, id)); + facets.emplace_back(Vec3i32(id - 1, id_ringsize - 1, id)); } id++; } @@ -171,13 +171,13 @@ Contour3D sphere(double rho, Portion portion = make_portion(0.0, 2.0*PI), if(send >= size_t(2*PI / angle)) { vertices.emplace_back(Vec3d(0.0, 0.0, -rho + increment*send*2.0*rho)); for (size_t i = 0; i < ring.size(); i++) { - auto id_ringsize = coord_t(id - int(ring.size())); + auto id_ringsize = int32_t(id - int(ring.size())); if (i == 0) { // third vertex is on the other side of the ring. - facets.emplace_back(Vec3crd(id - 1, id_ringsize, id)); + facets.emplace_back(Vec3i32(id - 1, id_ringsize, id)); } else { - auto ci = coord_t(id_ringsize + coord_t(i)); - facets.emplace_back(Vec3crd(ci - 1, ci, id)); + auto ci = int32_t(id_ringsize + int32_t(i)); + facets.emplace_back(Vec3i32(ci - 1, ci, id)); } } } @@ -195,9 +195,9 @@ Contour3D cylinder(double r, double h, size_t ssteps, const Vec3d sp = {0,0,0}) { Contour3D ret; - auto steps = int(ssteps); - auto& points = ret.points; - auto& indices = ret.indices; + int32_t steps = int32_t(ssteps); + Pointf3s& points = ret.points; + Indices& indices = ret.indices; points.reserve(2*ssteps); double a = 2*PI/steps; @@ -222,7 +222,7 @@ Contour3D cylinder(double r, double h, size_t ssteps, const Vec3d sp = {0,0,0}) // Now create long triangles connecting upper and lower circles indices.reserve(2*ssteps); - auto offs = steps; + int32_t offs = steps; for(int i = 0; i < steps - 1; ++i) { indices.emplace_back(i, i + offs, offs + i + 1); indices.emplace_back(i, offs + i + 1, i + 1); @@ -237,16 +237,16 @@ Contour3D cylinder(double r, double h, size_t ssteps, const Vec3d sp = {0,0,0}) // a watertight body. So we create a triangle fan for the upper and lower // ending of the cylinder to close the geometry. points.emplace_back(jp); size_t ci = points.size() - 1; - for(int i = 0; i < steps - 1; ++i) - indices.emplace_back(i + offs + 1, i + offs, ci); + for(int32_t i = 0; i < steps - 1; ++i) + indices.emplace_back(int32_t(i + offs + 1), int32_t(i + offs), int32_t(ci)); - indices.emplace_back(offs, steps + offs - 1, ci); + indices.emplace_back(offs, int32_t(steps + offs - 1), int32_t(ci)); points.emplace_back(endp); ci = points.size() - 1; - for(int i = 0; i < steps - 1; ++i) - indices.emplace_back(ci, i, i + 1); + for(int32_t i = 0; i < steps - 1; ++i) + indices.emplace_back(int32_t(ci), i, i + 1); - indices.emplace_back(steps - 1, 0, ci); + indices.emplace_back(int32_t(steps - 1), int32_t(0), int32_t(ci)); return ret; } @@ -306,10 +306,10 @@ struct Head { // The calculated phi is an offset to the half circles needed to smooth // the transition from the circle to the robe geometry - auto&& s1 = sphere(r_big_mm, make_portion(0, PI/2 + phi), detail); - auto&& s2 = sphere(r_small_mm, make_portion(PI/2 + phi, PI), detail); + Contour3D&& s1 = sphere(r_big_mm, make_portion(0, PI/2 + phi), detail); + Contour3D&& s2 = sphere(r_small_mm, make_portion(PI/2 + phi, PI), detail); - for(auto& p : s2.points) z(p) += h; + for(Vec3d & p : s2.points) z(p) += h; mesh.merge(s1); mesh.merge(s2); @@ -318,17 +318,17 @@ struct Head { idx1 < s1.points.size() - 1; idx1++, idx2++) { - coord_t i1s1 = coord_t(idx1), i1s2 = coord_t(idx2); - coord_t i2s1 = i1s1 + 1, i2s2 = i1s2 + 1; + int32_t i1s1 = int32_t(idx1), i1s2 = int32_t(idx2); + int32_t i2s1 = i1s1 + 1, i2s2 = i1s2 + 1; mesh.indices.emplace_back(i1s1, i2s1, i2s2); mesh.indices.emplace_back(i1s1, i2s2, i1s2); } - auto i1s1 = coord_t(s1.points.size()) - coord_t(steps); - auto i2s1 = coord_t(s1.points.size()) - 1; - auto i1s2 = coord_t(s1.points.size()); - auto i2s2 = coord_t(s1.points.size()) + coord_t(steps) - 1; + int32_t i1s1 = int32_t(s1.points.size()) - int32_t(steps); + int32_t i2s1 = int32_t(s1.points.size()) - 1; + int32_t i1s2 = int32_t(s1.points.size()); + int32_t i2s2 = int32_t(s1.points.size()) + int32_t(steps) - 1; mesh.indices.emplace_back(i2s2, i2s1, i1s1); mesh.indices.emplace_back(i1s2, i2s2, i1s1); diff --git a/src/libslic3r/SLA/SLASupportTree.hpp b/src/libslic3r/SLA/SLASupportTree.hpp index 66677e4d7..bb821534e 100644 --- a/src/libslic3r/SLA/SLASupportTree.hpp +++ b/src/libslic3r/SLA/SLASupportTree.hpp @@ -7,19 +7,12 @@ #include #include +#include #include "SLACommon.hpp" namespace Slic3r { -// Needed types from Point.hpp -typedef int32_t coord_t; -typedef Eigen::Matrix Vec3d; -typedef Eigen::Matrix Vec3f; -typedef Eigen::Matrix Vec3crd; -typedef std::vector Pointf3s; -typedef std::vector Points3; - class TriangleMesh; class Model; class ModelInstance; diff --git a/src/libslic3r/SLA/SLASupportTreeIGL.cpp b/src/libslic3r/SLA/SLASupportTreeIGL.cpp index c368b8604..8b60e1fa2 100644 --- a/src/libslic3r/SLA/SLASupportTreeIGL.cpp +++ b/src/libslic3r/SLA/SLASupportTreeIGL.cpp @@ -287,11 +287,11 @@ PointSet normals(const PointSet& points, } // vector for the neigboring triangles including the detected one. - std::vector neigh; + std::vector neigh; if(ic >= 0) { // The point is right on a vertex of the triangle for(int n = 0; n < mesh.F().rows(); ++n) { thr(); - Vec3i ni = mesh.F().row(n); + Vec3i32 ni = mesh.F().row(n); if((ni(X) == ic || ni(Y) == ic || ni(Z) == ic)) neigh.emplace_back(ni); } @@ -300,7 +300,7 @@ PointSet normals(const PointSet& points, // now get all the neigboring triangles for(int n = 0; n < mesh.F().rows(); ++n) { thr(); - Vec3i ni = mesh.F().row(n); + Vec3i32 ni = mesh.F().row(n); if((ni(X) == ia || ni(Y) == ia || ni(Z) == ia) && (ni(X) == ib || ni(Y) == ib || ni(Z) == ib)) neigh.emplace_back(ni); @@ -309,7 +309,7 @@ PointSet normals(const PointSet& points, // Calculate the normals for the neighboring triangles std::vector neighnorms; neighnorms.reserve(neigh.size()); - for(const Vec3i& tri : neigh) { + for(const Vec3i32& tri : neigh) { const Vec3d& pt1 = mesh.V().row(tri(0)); const Vec3d& pt2 = mesh.V().row(tri(1)); const Vec3d& pt3 = mesh.V().row(tri(2)); diff --git a/src/libslic3r/Slicing.cpp b/src/libslic3r/Slicing.cpp index 21d42b4f2..228ba65eb 100644 --- a/src/libslic3r/Slicing.cpp +++ b/src/libslic3r/Slicing.cpp @@ -591,15 +591,15 @@ int generate_layer_height_texture( void *data, int rows, int cols, bool level_of_detail_2nd_level) { // https://github.com/aschn/gnuplot-colorbrewer - std::vector palette_raw; - palette_raw.push_back(Vec3crd(0x01A, 0x098, 0x050)); - palette_raw.push_back(Vec3crd(0x066, 0x0BD, 0x063)); - palette_raw.push_back(Vec3crd(0x0A6, 0x0D9, 0x06A)); - palette_raw.push_back(Vec3crd(0x0D9, 0x0F1, 0x0EB)); - palette_raw.push_back(Vec3crd(0x0FE, 0x0E6, 0x0EB)); - palette_raw.push_back(Vec3crd(0x0FD, 0x0AE, 0x061)); - palette_raw.push_back(Vec3crd(0x0F4, 0x06D, 0x043)); - palette_raw.push_back(Vec3crd(0x0D7, 0x030, 0x027)); + std::vector palette_raw; + palette_raw.push_back(Vec3i32(0x01A, 0x098, 0x050)); + palette_raw.push_back(Vec3i32(0x066, 0x0BD, 0x063)); + palette_raw.push_back(Vec3i32(0x0A6, 0x0D9, 0x06A)); + palette_raw.push_back(Vec3i32(0x0D9, 0x0F1, 0x0EB)); + palette_raw.push_back(Vec3i32(0x0FE, 0x0E6, 0x0EB)); + palette_raw.push_back(Vec3i32(0x0FD, 0x0AE, 0x061)); + palette_raw.push_back(Vec3i32(0x0F4, 0x06D, 0x043)); + palette_raw.push_back(Vec3i32(0x0D7, 0x030, 0x027)); // Clear the main texture and the 2nd LOD level. // memset(data, 0, rows * cols * (level_of_detail_2nd_level ? 5 : 4)); @@ -630,8 +630,8 @@ int generate_layer_height_texture( int idx1 = clamp(0, int(palette_raw.size() - 1), int(floor(idxf))); int idx2 = std::min(int(palette_raw.size() - 1), idx1 + 1); coordf_t t = idxf - coordf_t(idx1); - const Vec3crd &color1 = palette_raw[idx1]; - const Vec3crd &color2 = palette_raw[idx2]; + const Vec3i32 &color1 = palette_raw[idx1]; + const Vec3i32 &color2 = palette_raw[idx2]; coordf_t z = cell_to_z * coordf_t(cell); assert(z >= lo && z <= hi); // Intensity profile to visualize the layers. @@ -666,8 +666,8 @@ int generate_layer_height_texture( int idx1 = clamp(0, int(palette_raw.size() - 1), int(floor(idxf))); int idx2 = std::min(int(palette_raw.size() - 1), idx1 + 1); coordf_t t = idxf - coordf_t(idx1); - const Vec3crd &color1 = palette_raw[idx1]; - const Vec3crd &color2 = palette_raw[idx2]; + const Vec3i32 &color1 = palette_raw[idx1]; + const Vec3i32 &color2 = palette_raw[idx2]; // Color mapping from layer height to RGB. Vec3d color( lerp(coordf_t(color1(0)), coordf_t(color2(0)), t), diff --git a/src/libslic3r/TriangleMesh.cpp b/src/libslic3r/TriangleMesh.cpp index d4719125d..2b54131f9 100644 --- a/src/libslic3r/TriangleMesh.cpp +++ b/src/libslic3r/TriangleMesh.cpp @@ -42,7 +42,7 @@ namespace Slic3r { -TriangleMesh::TriangleMesh(const Pointf3s &points, const std::vector& facets) +TriangleMesh::TriangleMesh(const Pointf3s &points, const std::vector& facets) : repaired(false) { stl_initialize(&this->stl); @@ -581,7 +581,7 @@ TriangleMesh TriangleMesh::convex_hull_3d() const // Let's collect results: Pointf3s dst_vertices; - std::vector facets; + std::vector facets; auto facet_list = qhull.facetList().toStdVector(); for (const orgQhull::QhullFacet& facet : facet_list) { // iterate through facets @@ -1833,14 +1833,14 @@ TriangleMesh make_cube(double x, double y, double z) { Vec3d(0, y, 0), Vec3d(x, y, z), Vec3d(0, y, z), Vec3d(0, 0, z), Vec3d(x, 0, z) }; - Vec3crd fv[12] = { - Vec3crd(0, 1, 2), Vec3crd(0, 2, 3), Vec3crd(4, 5, 6), - Vec3crd(4, 6, 7), Vec3crd(0, 4, 7), Vec3crd(0, 7, 1), - Vec3crd(1, 7, 6), Vec3crd(1, 6, 2), Vec3crd(2, 6, 5), - Vec3crd(2, 5, 3), Vec3crd(4, 0, 3), Vec3crd(4, 3, 5) + Vec3i32 fv[12] = { + Vec3i32(0, 1, 2), Vec3i32(0, 2, 3), Vec3i32(4, 5, 6), + Vec3i32(4, 6, 7), Vec3i32(0, 4, 7), Vec3i32(0, 7, 1), + Vec3i32(1, 7, 6), Vec3i32(1, 6, 2), Vec3i32(2, 6, 5), + Vec3i32(2, 5, 3), Vec3i32(4, 0, 3), Vec3i32(4, 3, 5) }; - std::vector facets(&fv[0], &fv[0]+12); + std::vector facets(&fv[0], &fv[0]+12); Pointf3s vertices(&pv[0], &pv[0]+8); TriangleMesh mesh(vertices ,facets); @@ -1852,7 +1852,7 @@ TriangleMesh make_cube(double x, double y, double z) { // Default is 360 sides, angle fa is in radians. TriangleMesh make_cylinder(double r, double h, double fa) { Pointf3s vertices; - std::vector facets; + std::vector facets; // 2 special vertices, top and bottom center, rest are relative to this vertices.emplace_back(Vec3d(0.0, 0.0, 0.0)); @@ -1873,16 +1873,16 @@ TriangleMesh make_cylinder(double r, double h, double fa) { vertices.emplace_back(Vec3d(p(0), p(1), 0.)); vertices.emplace_back(Vec3d(p(0), p(1), h)); id = vertices.size() - 1; - facets.emplace_back(Vec3crd( 0, id - 1, id - 3)); // top - facets.emplace_back(Vec3crd(id, 1, id - 2)); // bottom - facets.emplace_back(Vec3crd(id, id - 2, id - 3)); // upper-right of side - facets.emplace_back(Vec3crd(id, id - 3, id - 1)); // bottom-left of side + facets.emplace_back(Vec3i32( 0, id - 1, id - 3)); // top + facets.emplace_back(Vec3i32(id, 1, id - 2)); // bottom + facets.emplace_back(Vec3i32(id, id - 2, id - 3)); // upper-right of side + facets.emplace_back(Vec3i32(id, id - 3, id - 1)); // bottom-left of side } // Connect the last set of vertices with the first. - facets.emplace_back(Vec3crd( 2, 0, id - 1)); - facets.emplace_back(Vec3crd( 1, 3, id)); - facets.emplace_back(Vec3crd(id, 3, 2)); - facets.emplace_back(Vec3crd(id, 2, id - 1)); + facets.emplace_back(Vec3i32( 2, 0, id - 1)); + facets.emplace_back(Vec3i32( 1, 3, id)); + facets.emplace_back(Vec3i32(id, 3, 2)); + facets.emplace_back(Vec3i32(id, 2, id - 1)); TriangleMesh mesh(vertices, facets); return mesh; @@ -1893,7 +1893,7 @@ TriangleMesh make_cylinder(double r, double h, double fa) { // Default angle is 1 degree. TriangleMesh make_sphere(double rho, double fa) { Pointf3s vertices; - std::vector facets; + std::vector facets; // Algorithm: // Add points one-by-one to the sphere grid and form facets using relative coordinates. @@ -1921,7 +1921,7 @@ TriangleMesh make_sphere(double rho, double fa) { const double r = sqrt(abs(rho*rho - z*z)); Vec2d b = Eigen::Rotation2Dd(ring[i]) * Eigen::Vector2d(0, r); vertices.emplace_back(Vec3d(b(0), b(1), z)); - facets.emplace_back((i == 0) ? Vec3crd(1, 0, ring.size()) : Vec3crd(id, 0, id - 1)); + facets.emplace_back((i == 0) ? Vec3i32(1, 0, ring.size()) : Vec3i32(id, 0, id - 1)); ++ id; } @@ -1935,11 +1935,11 @@ TriangleMesh make_sphere(double rho, double fa) { vertices.emplace_back(Vec3d(b(0), b(1), z)); if (i == 0) { // wrap around - facets.emplace_back(Vec3crd(id + ring.size() - 1 , id, id - 1)); - facets.emplace_back(Vec3crd(id, id - ring.size(), id - 1)); + facets.emplace_back(Vec3i32(id + ring.size() - 1 , id, id - 1)); + facets.emplace_back(Vec3i32(id, id - ring.size(), id - 1)); } else { - facets.emplace_back(Vec3crd(id , id - ring.size(), (id - 1) - ring.size())); - facets.emplace_back(Vec3crd(id, id - 1 - ring.size() , id - 1)); + facets.emplace_back(Vec3i32(id , id - ring.size(), (id - 1) - ring.size())); + facets.emplace_back(Vec3i32(id, id - 1 - ring.size() , id - 1)); } id++; } @@ -1952,9 +1952,9 @@ TriangleMesh make_sphere(double rho, double fa) { for (size_t i = 0; i < ring.size(); i++) { if (i == 0) { // third vertex is on the other side of the ring. - facets.emplace_back(Vec3crd(id, id - ring.size(), id - 1)); + facets.emplace_back(Vec3i32(id, id - ring.size(), id - 1)); } else { - facets.emplace_back(Vec3crd(id, id - ring.size() + i, id - ring.size() + (i - 1))); + facets.emplace_back(Vec3i32(id, id - ring.size() + i, id - ring.size() + (i - 1))); } } id++; diff --git a/src/libslic3r/TriangleMesh.hpp b/src/libslic3r/TriangleMesh.hpp index 6a68e0796..8d2293360 100644 --- a/src/libslic3r/TriangleMesh.hpp +++ b/src/libslic3r/TriangleMesh.hpp @@ -22,7 +22,7 @@ class TriangleMesh { public: TriangleMesh() : repaired(false) { stl_initialize(&this->stl); } - TriangleMesh(const Pointf3s &points, const std::vector &facets); + TriangleMesh(const Pointf3s &points, const std::vector &facets); TriangleMesh(const TriangleMesh &other) : repaired(false) { stl_initialize(&this->stl); *this = other; } TriangleMesh(TriangleMesh &&other) : repaired(false) { stl_initialize(&this->stl); this->swap(other); } ~TriangleMesh() { stl_close(&this->stl); } diff --git a/src/slic3r/GUI/3DScene.cpp b/src/slic3r/GUI/3DScene.cpp index 328f0d8be..8e62d8262 100644 --- a/src/slic3r/GUI/3DScene.cpp +++ b/src/slic3r/GUI/3DScene.cpp @@ -660,7 +660,7 @@ int GLVolumeCollection::load_wipe_tower_preview( // We'll now create the box with jagged edge. y-coordinates of the pre-generated model are shifted so that the front // edge has y=0 and centerline of the back edge has y=depth: Pointf3s points; - std::vector facets; + std::vector facets; float out_points_idx[][3] = { { 0, -depth, 0 }, { 0, 0, 0 }, { 38.453f, 0, 0 }, { 61.547f, 0, 0 }, { 100.0f, 0, 0 }, { 100.0f, -depth, 0 }, { 55.7735f, -10.0f, 0 }, { 44.2265f, 10.0f, 0 }, { 38.453f, 0, 1 }, { 0, 0, 1 }, { 0, -depth, 1 }, { 100.0f, -depth, 1 }, { 100.0f, 0, 1 }, { 61.547f, 0, 1 }, { 55.7735f, -10.0f, 1 }, { 44.2265f, 10.0f, 1 } }; int out_facets_idx[][3] = { { 0, 1, 2 }, { 3, 4, 5 }, { 6, 5, 0 }, { 3, 5, 6 }, { 6, 2, 7 }, { 6, 0, 2 }, { 8, 9, 10 }, { 11, 12, 13 }, { 10, 11, 14 }, { 14, 11, 13 }, { 15, 8, 14 }, @@ -669,7 +669,7 @@ int GLVolumeCollection::load_wipe_tower_preview( for (int i=0;i<16;++i) points.push_back(Vec3d(out_points_idx[i][0] / (100.f/min_width), out_points_idx[i][1] + depth, out_points_idx[i][2])); for (int i=0;i<28;++i) - facets.push_back(Vec3crd(out_facets_idx[i][0], out_facets_idx[i][1], out_facets_idx[i][2])); + facets.push_back(Vec3i32(out_facets_idx[i][0], out_facets_idx[i][1], out_facets_idx[i][2])); TriangleMesh tooth_mesh(points, facets); // We have the mesh ready. It has one tooth and width of min_width. We will now append several of these together until we are close to @@ -1778,7 +1778,7 @@ void GLModel::render_legacy() const bool GLArrow::on_init(bool useVBOs) { Pointf3s vertices; - std::vector triangles; + std::vector triangles; // bottom face vertices.emplace_back(0.5, 0.0, -0.1); @@ -1850,7 +1850,7 @@ GLCurvedArrow::GLCurvedArrow(unsigned int resolution) bool GLCurvedArrow::on_init(bool useVBOs) { Pointf3s vertices; - std::vector triangles; + std::vector triangles; double ext_radius = 2.5; double int_radius = 1.5; diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 3f97eb76f..2995e601d 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -2576,7 +2576,7 @@ void GLCanvas3D::render() // we need to set the mouse's scene position here because the depth buffer // could be invalidated by the following gizmo render methods // this position is used later into on_mouse() to drag the objects - m_mouse.scene_position = _mouse_to_3d(m_mouse.position.cast()); + m_mouse.scene_position = _mouse_to_3d(m_mouse.position.cast()); _render_current_gizmo(); _render_selection_sidebar_hints(); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp index 31f6b0278..e058e929f 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp @@ -366,7 +366,7 @@ bool GLGizmoSlaSupports::gizmo_event(SLAGizmoEventType action, const Vec2d& mous double z_offset = volume->get_sla_shift_z(); // bounding box created from the rectangle corners - will take care of order of the corners - BoundingBox rectangle(Points{Point(m_selection_rectangle_start_corner.cast()), Point(m_selection_rectangle_end_corner.cast())}); + BoundingBox rectangle(Points{Point(m_selection_rectangle_start_corner.cast()), Point(m_selection_rectangle_end_corner.cast())}); const Transform3d& instance_matrix_no_translation = volume->get_instance_transformation().get_matrix(true); // we'll recover current look direction from the modelview matrix (in world coords)... diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 43c76db0a..f062aed36 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -1750,7 +1750,7 @@ std::vector Plater::priv::load_model_objects(const ModelObjectPtrs &mode #ifdef AUTOPLACEMENT_ON_LOAD // FIXME distance should be a config value ///////////////////////////////// - auto min_obj_distance = static_cast(6/SCALING_FACTOR); + coord_t min_obj_distance = static_cast(6/SCALING_FACTOR); const auto *bed_shape_opt = config->opt("bed_shape"); assert(bed_shape_opt); auto& bedpoints = bed_shape_opt->values;