From cb138a20b861a288ba448666049e0df45fb71c5d Mon Sep 17 00:00:00 2001 From: bubnikv Date: Tue, 21 Aug 2018 17:43:05 +0200 Subject: Completely replaced the homebrew Pointf3 class with Eigen Vec3d. Replaced the unscale macro with a template, implemented templates for unscaling Eigen vectors. --- xs/src/libslic3r/BoundingBox.cpp | 72 +++++++++----------- xs/src/libslic3r/BoundingBox.hpp | 44 +++++------- xs/src/libslic3r/ExtrusionEntity.hpp | 2 +- xs/src/libslic3r/Fill/FillConcentric.cpp | 2 +- xs/src/libslic3r/Fill/FillGyroid.cpp | 4 +- xs/src/libslic3r/Fill/FillRectilinear.cpp | 2 +- xs/src/libslic3r/Fill/FillRectilinear2.cpp | 2 +- xs/src/libslic3r/Fill/FillRectilinear3.cpp | 2 +- xs/src/libslic3r/GCode.cpp | 13 ++-- xs/src/libslic3r/GCode/Analyzer.cpp | 18 ++--- xs/src/libslic3r/GCode/Analyzer.hpp | 16 ++--- xs/src/libslic3r/GCode/CoolingBuffer.cpp | 2 +- xs/src/libslic3r/GCode/PrintExtents.cpp | 14 ++-- xs/src/libslic3r/GCodeWriter.cpp | 6 +- xs/src/libslic3r/GCodeWriter.hpp | 8 +-- xs/src/libslic3r/Line.cpp | 4 +- xs/src/libslic3r/Line.hpp | 10 +-- xs/src/libslic3r/Model.cpp | 54 ++++++--------- xs/src/libslic3r/Model.hpp | 8 +-- xs/src/libslic3r/PerimeterGenerator.cpp | 4 +- xs/src/libslic3r/Point.hpp | 55 ++++++--------- xs/src/libslic3r/Print.cpp | 6 +- xs/src/libslic3r/Print.hpp | 2 +- xs/src/libslic3r/PrintObject.cpp | 6 +- xs/src/libslic3r/SVG.cpp | 2 +- xs/src/libslic3r/Slicing.cpp | 4 +- xs/src/libslic3r/TriangleMesh.cpp | 44 ++++++------ xs/src/libslic3r/TriangleMesh.hpp | 2 +- xs/src/libslic3r/libslic3r.h | 4 +- xs/src/perlglue.cpp | 2 +- xs/src/slic3r/GUI/2DBed.cpp | 4 +- xs/src/slic3r/GUI/3DScene.cpp | 81 +++++++++++----------- xs/src/slic3r/GUI/3DScene.hpp | 8 +-- xs/src/slic3r/GUI/BedShapeDialog.cpp | 4 +- xs/src/slic3r/GUI/GLCanvas3D.cpp | 105 +++++++++++++++-------------- xs/src/slic3r/GUI/GLCanvas3D.hpp | 14 ++-- xs/src/slic3r/GUI/GLGizmo.cpp | 5 +- xs/src/slic3r/GUI/GLGizmo.hpp | 1 - xs/xsp/BoundingBox.xsp | 12 ++-- xs/xsp/GUI_3DScene.xsp | 4 +- xs/xsp/Line.xsp | 8 +-- xs/xsp/Model.xsp | 6 +- xs/xsp/Point.xsp | 20 +++--- xs/xsp/TriangleMesh.xsp | 4 +- xs/xsp/my.map | 6 +- xs/xsp/typemap.xspt | 6 +- 46 files changed, 329 insertions(+), 373 deletions(-) diff --git a/xs/src/libslic3r/BoundingBox.cpp b/xs/src/libslic3r/BoundingBox.cpp index 68136b916..81a748f8f 100644 --- a/xs/src/libslic3r/BoundingBox.cpp +++ b/xs/src/libslic3r/BoundingBox.cpp @@ -9,7 +9,7 @@ namespace Slic3r { template BoundingBoxBase::BoundingBoxBase(const std::vector &points); template BoundingBoxBase::BoundingBoxBase(const std::vector &points); -template BoundingBox3Base::BoundingBox3Base(const std::vector &points); +template BoundingBox3Base::BoundingBox3Base(const std::vector &points); BoundingBox::BoundingBox(const Lines &lines) { @@ -22,8 +22,7 @@ BoundingBox::BoundingBox(const Lines &lines) *this = BoundingBox(points); } -void -BoundingBox::polygon(Polygon* polygon) const +void BoundingBox::polygon(Polygon* polygon) const { polygon->points.clear(); polygon->points.resize(4); @@ -37,8 +36,7 @@ BoundingBox::polygon(Polygon* polygon) const polygon->points[3](1) = this->max(1); } -Polygon -BoundingBox::polygon() const +Polygon BoundingBox::polygon() const { Polygon p; this->polygon(&p); @@ -73,18 +71,17 @@ BoundingBoxBase::scale(double factor) } template void BoundingBoxBase::scale(double factor); template void BoundingBoxBase::scale(double factor); -template void BoundingBoxBase::scale(double factor); +template void BoundingBoxBase::scale(double factor); template void BoundingBoxBase::merge(const PointClass &point) { if (this->defined) { - this->min(0) = std::min(point(0), this->min(0)); - this->min(1) = std::min(point(1), this->min(1)); - this->max(0) = std::max(point(0), this->max(0)); - this->max(1) = std::max(point(1), this->max(1)); + this->min = this->min.cwiseMin(point); + this->max = this->max.cwiseMax(point); } else { - this->min = this->max = point; + this->min = point; + this->max = point; this->defined = true; } } @@ -105,10 +102,8 @@ BoundingBoxBase::merge(const BoundingBoxBase &bb) assert(bb.defined || bb.min(0) >= bb.max(0) || bb.min(1) >= bb.max(1)); if (bb.defined) { if (this->defined) { - this->min(0) = std::min(bb.min(0), this->min(0)); - this->min(1) = std::min(bb.min(1), this->min(1)); - this->max(0) = std::max(bb.max(0), this->max(0)); - this->max(1) = std::max(bb.max(1), this->max(1)); + this->min = this->min.cwiseMin(bb.min); + this->max = this->max.cwiseMax(bb.max); } else { this->min = bb.min; this->max = bb.max; @@ -123,19 +118,22 @@ template void BoundingBox3Base::merge(const PointClass &point) { if (this->defined) { - this->min(2) = std::min(point(2), this->min(2)); - this->max(2) = std::max(point(2), this->max(2)); + this->min = this->min.cwiseMin(point); + this->max = this->max.cwiseMax(point); + } else { + this->min = point; + this->max = point; + this->defined = true; } - BoundingBoxBase::merge(point); } -template void BoundingBox3Base::merge(const Pointf3 &point); +template void BoundingBox3Base::merge(const Vec3d &point); template void BoundingBox3Base::merge(const std::vector &points) { this->merge(BoundingBox3Base(points)); } -template void BoundingBox3Base::merge(const Pointf3s &points); +template void BoundingBox3Base::merge(const Pointf3s &points); template void BoundingBox3Base::merge(const BoundingBox3Base &bb) @@ -143,13 +141,16 @@ BoundingBox3Base::merge(const BoundingBox3Base &bb) assert(bb.defined || bb.min(0) >= bb.max(0) || bb.min(1) >= bb.max(1) || bb.min(2) >= bb.max(2)); if (bb.defined) { if (this->defined) { - this->min(2) = std::min(bb.min(2), this->min(2)); - this->max(2) = std::max(bb.max(2), this->max(2)); + this->min = this->min.cwiseMin(bb.min); + this->max = this->max.cwiseMax(bb.max); + } else { + this->min = bb.min; + this->max = bb.max; + this->defined = true; } - BoundingBoxBase::merge(bb); } } -template void BoundingBox3Base::merge(const BoundingBox3Base &bb); +template void BoundingBox3Base::merge(const BoundingBox3Base &bb); template PointClass BoundingBoxBase::size() const @@ -164,7 +165,7 @@ BoundingBox3Base::size() const { return PointClass(this->max(0) - this->min(0), this->max(1) - this->min(1), this->max(2) - this->min(2)); } -template Pointf3 BoundingBox3Base::size() const; +template Vec3d BoundingBox3Base::size() const; template double BoundingBoxBase::radius() const { @@ -183,7 +184,7 @@ template double BoundingBox3Base::radius() const double z = this->max(2) - this->min(2); return 0.5 * sqrt(x*x+y*y+z*z); } -template double BoundingBox3Base::radius() const; +template double BoundingBox3Base::radius() const; template void BoundingBoxBase::offset(coordf_t delta) @@ -202,15 +203,12 @@ BoundingBox3Base::offset(coordf_t delta) this->min -= v; this->max += v; } -template void BoundingBox3Base::offset(coordf_t delta); +template void BoundingBox3Base::offset(coordf_t delta); template PointClass BoundingBoxBase::center() const { - return PointClass( - (this->max(0) + this->min(0))/2, - (this->max(1) + this->min(1))/2 - ); + return (this->min + this->max) / 2; } template Point BoundingBoxBase::center() const; template Pointf BoundingBoxBase::center() const; @@ -218,13 +216,9 @@ template Pointf BoundingBoxBase::center() const; template PointClass BoundingBox3Base::center() const { - return PointClass( - (this->max(0) + this->min(0))/2, - (this->max(1) + this->min(1))/2, - (this->max(2) + this->min(2))/2 - ); + return (this->min + this->max) / 2; } -template Pointf3 BoundingBox3Base::center() const; +template Vec3d BoundingBox3Base::center() const; template coordf_t BoundingBox3Base::max_size() const @@ -232,7 +226,7 @@ BoundingBox3Base::max_size() const PointClass s = size(); return std::max(s(0), std::max(s(1), s(2))); } -template coordf_t BoundingBox3Base::max_size() const; +template coordf_t BoundingBox3Base::max_size() const; // Align a coordinate to a grid. The coordinate may be negative, // the aligned value will never be bigger than the original one. @@ -287,7 +281,7 @@ BoundingBoxf3 BoundingBoxf3::transformed(const Transform3f& matrix) const max_z = std::max(max_z, transf_vertices(2, i)); } - return BoundingBoxf3(Pointf3((coordf_t)min_x, (coordf_t)min_y, (coordf_t)min_z), Pointf3((coordf_t)max_x, (coordf_t)max_y, (coordf_t)max_z)); + return BoundingBoxf3(Vec3d((coordf_t)min_x, (coordf_t)min_y, (coordf_t)min_z), Vec3d((coordf_t)max_x, (coordf_t)max_y, (coordf_t)max_z)); } } diff --git a/xs/src/libslic3r/BoundingBox.hpp b/xs/src/libslic3r/BoundingBox.hpp index d09658774..7a0287860 100644 --- a/xs/src/libslic3r/BoundingBox.hpp +++ b/xs/src/libslic3r/BoundingBox.hpp @@ -7,11 +7,6 @@ namespace Slic3r { -typedef Point Size; -typedef Point3 Size3; -typedef Pointf Sizef; -typedef Pointf3 Sizef3; - template class BoundingBoxBase { @@ -20,7 +15,7 @@ public: PointClass max; bool defined; - BoundingBoxBase() : defined(false) {}; + BoundingBoxBase() : defined(false), min(PointClass::Zero()), max(PointClass::Zero()) {} BoundingBoxBase(const PointClass &pmin, const PointClass &pmax) : min(pmin), max(pmax), defined(pmin(0) < pmax(0) && pmin(1) < pmax(1)) {} BoundingBoxBase(const std::vector& points) @@ -29,14 +24,11 @@ public: CONFESS("Empty point set supplied to BoundingBoxBase constructor"); typename std::vector::const_iterator it = points.begin(); - this->min(0) = this->max(0) = (*it)(0); - this->min(1) = this->max(1) = (*it)(1); - for (++it; it != points.end(); ++it) - { - this->min(0) = std::min((*it)(0), this->min(0)); - this->min(1) = std::min((*it)(1), this->min(1)); - this->max(0) = std::max((*it)(0), this->max(0)); - this->max(1) = std::max((*it)(1), this->max(1)); + this->min = *it; + this->max = *it; + for (++ it; it != points.end(); ++ it) { + this->min = this->min.cwiseMin(*it); + this->max = this->max.cwiseMax(*it); } this->defined = (this->min(0) < this->max(0)) && (this->min(1) < this->max(1)); } @@ -71,19 +63,17 @@ public: BoundingBoxBase(pmin, pmax) { if (pmin(2) >= pmax(2)) BoundingBoxBase::defined = false; } BoundingBox3Base(const std::vector& points) - : BoundingBoxBase(points) { if (points.empty()) CONFESS("Empty point set supplied to BoundingBox3Base constructor"); - typename std::vector::const_iterator it = points.begin(); - this->min(2) = this->max(2) = (*it)(2); - for (++it; it != points.end(); ++it) - { - this->min(2) = std::min((*it)(2), this->min(2)); - this->max(2) = std::max((*it)(2), this->max(2)); + this->min = *it; + this->max = *it; + for (++ it; it != points.end(); ++ it) { + this->min = this->min.cwiseMin(*it); + this->max = this->max.cwiseMax(*it); } - this->defined &= (this->min(2) < this->max(2)); + this->defined = (this->min(0) < this->max(0)) && (this->min(1) < this->max(1)) && (this->min(2) < this->max(2)); } void merge(const PointClass &point); void merge(const std::vector &points); @@ -91,7 +81,7 @@ public: PointClass size() const; double radius() const; void translate(coordf_t x, coordf_t y, coordf_t z) { assert(this->defined); PointClass v(x, y, z); this->min += v; this->max += v; } - void translate(const Pointf3 &v) { this->min += v; this->max += v; } + void translate(const Vec3d &v) { this->min += v; this->max += v; } void offset(coordf_t delta); PointClass center() const; coordf_t max_size() const; @@ -146,12 +136,12 @@ public: BoundingBoxf(const std::vector &points) : BoundingBoxBase(points) {}; }; -class BoundingBoxf3 : public BoundingBox3Base +class BoundingBoxf3 : public BoundingBox3Base { public: - BoundingBoxf3() : BoundingBox3Base() {}; - BoundingBoxf3(const Pointf3 &pmin, const Pointf3 &pmax) : BoundingBox3Base(pmin, pmax) {}; - BoundingBoxf3(const std::vector &points) : BoundingBox3Base(points) {}; + BoundingBoxf3() : BoundingBox3Base() {}; + BoundingBoxf3(const Vec3d &pmin, const Vec3d &pmax) : BoundingBox3Base(pmin, pmax) {}; + BoundingBoxf3(const std::vector &points) : BoundingBox3Base(points) {}; BoundingBoxf3 transformed(const Transform3f& matrix) const; }; diff --git a/xs/src/libslic3r/ExtrusionEntity.hpp b/xs/src/libslic3r/ExtrusionEntity.hpp index 15363e8ed..90675c04a 100644 --- a/xs/src/libslic3r/ExtrusionEntity.hpp +++ b/xs/src/libslic3r/ExtrusionEntity.hpp @@ -149,7 +149,7 @@ public: // Minimum volumetric velocity of this extrusion entity. Used by the constant nozzle pressure algorithm. double min_mm3_per_mm() const { return this->mm3_per_mm; } Polyline as_polyline() const { return this->polyline; } - virtual double total_volume() const { return mm3_per_mm * unscale(length()); } + virtual double total_volume() const { return mm3_per_mm * unscale(length()); } private: void _inflate_collection(const Polylines &polylines, ExtrusionEntityCollection* collection) const; diff --git a/xs/src/libslic3r/Fill/FillConcentric.cpp b/xs/src/libslic3r/Fill/FillConcentric.cpp index d0f9510cc..8a3a7ea89 100644 --- a/xs/src/libslic3r/Fill/FillConcentric.cpp +++ b/xs/src/libslic3r/Fill/FillConcentric.cpp @@ -21,7 +21,7 @@ void FillConcentric::_fill_surface_single( if (params.density > 0.9999f && !params.dont_adjust) { distance = this->_adjust_solid_spacing(bounding_box.size()(0), distance); - this->spacing = unscale(distance); + this->spacing = unscale(distance); } Polygons loops = (Polygons)expolygon; diff --git a/xs/src/libslic3r/Fill/FillGyroid.cpp b/xs/src/libslic3r/Fill/FillGyroid.cpp index 003893649..bbaebc5f9 100644 --- a/xs/src/libslic3r/Fill/FillGyroid.cpp +++ b/xs/src/libslic3r/Fill/FillGyroid.cpp @@ -71,10 +71,10 @@ static std::vector make_one_period(double width, double scaleFactor, dou for (unsigned int i=1;i(scaleFactor) * std::abs(cross2(rp, lp) - cross2(rp - lp, tp)) / lrv.norm(); if (dist_mm > tolerance) { // if the difference from straight line is more than this double x = 0.5f * (points[i-1](0) + points[i](0)); points.emplace_back(Pointf(x, f(x, z_sin, z_cos, vertical, flip))); diff --git a/xs/src/libslic3r/Fill/FillRectilinear.cpp b/xs/src/libslic3r/Fill/FillRectilinear.cpp index 2209d219e..205eb1b66 100644 --- a/xs/src/libslic3r/Fill/FillRectilinear.cpp +++ b/xs/src/libslic3r/Fill/FillRectilinear.cpp @@ -27,7 +27,7 @@ void FillRectilinear::_fill_surface_single( // define flow spacing according to requested density if (params.density > 0.9999f && !params.dont_adjust) { this->_line_spacing = this->_adjust_solid_spacing(bounding_box.size()(0), this->_line_spacing); - this->spacing = unscale(this->_line_spacing); + this->spacing = unscale(this->_line_spacing); } else { // extend bounding box so that our pattern will be aligned with other layers // Transform the reference point to the rotated coordinate system. diff --git a/xs/src/libslic3r/Fill/FillRectilinear2.cpp b/xs/src/libslic3r/Fill/FillRectilinear2.cpp index f18ab0f62..65440d0ef 100644 --- a/xs/src/libslic3r/Fill/FillRectilinear2.cpp +++ b/xs/src/libslic3r/Fill/FillRectilinear2.cpp @@ -792,7 +792,7 @@ bool FillRectilinear2::fill_surface_by_lines(const Surface *surface, const FillP // define flow spacing according to requested density if (params.full_infill() && !params.dont_adjust) { line_spacing = this->_adjust_solid_spacing(bounding_box.size()(0), line_spacing); - this->spacing = unscale(line_spacing); + this->spacing = unscale(line_spacing); } else { // extend bounding box so that our pattern will be aligned with other layers // Transform the reference point to the rotated coordinate system. diff --git a/xs/src/libslic3r/Fill/FillRectilinear3.cpp b/xs/src/libslic3r/Fill/FillRectilinear3.cpp index d80bbfe6e..72c8b1ec5 100644 --- a/xs/src/libslic3r/Fill/FillRectilinear3.cpp +++ b/xs/src/libslic3r/Fill/FillRectilinear3.cpp @@ -391,7 +391,7 @@ static bool prepare_infill_hatching_segments( // Full infill, adjust the line spacing to fit an integer number of lines. out.line_spacing = Fill::_adjust_solid_spacing(bounding_box.size()(0), line_spacing); // Report back the adjusted line spacing. - fill_dir_params.spacing = float(unscale(line_spacing)); + fill_dir_params.spacing = unscale(line_spacing); } else { // Extend bounding box so that our pattern will be aligned with the other layers. // Transform the reference point to the rotated coordinate system. diff --git a/xs/src/libslic3r/GCode.cpp b/xs/src/libslic3r/GCode.cpp index 419299135..2f911440a 100644 --- a/xs/src/libslic3r/GCode.cpp +++ b/xs/src/libslic3r/GCode.cpp @@ -64,7 +64,7 @@ std::string OozePrevention::pre_toolchange(GCode &gcodegen) // move to the nearest standby point if (!this->standby_points.empty()) { // get current position in print coordinates - Pointf3 writer_pos = gcodegen.writer().get_position(); + Vec3d writer_pos = gcodegen.writer().get_position(); Point pos = Point::new_scale(writer_pos(0), writer_pos(1)); // find standby point @@ -74,7 +74,7 @@ std::string OozePrevention::pre_toolchange(GCode &gcodegen) /* We don't call gcodegen.travel_to() because we don't need retraction (it was already triggered by the caller) nor avoid_crossing_perimeters and also because the coordinates of the destination point must not be transformed by origin nor current extruder offset. */ - gcode += gcodegen.writer().travel_to_xy(Pointf::new_unscale(standby_point), + gcode += gcodegen.writer().travel_to_xy(unscale(standby_point), "move to standby position"); } @@ -831,7 +831,7 @@ void GCode::_do_export(Print &print, FILE *file, GCodePreviewData *preview_data) final_extruder_id = tool_ordering.last_extruder(); assert(final_extruder_id != (unsigned int)-1); } - this->set_origin(unscale(copy(0)), unscale(copy(1))); + this->set_origin(unscale(copy)); if (finished_objects > 0) { // Move to the origin position for the copy we're going to print. // This happens before Z goes down to layer 0 again, so that no collision happens hopefully. @@ -1547,7 +1547,7 @@ void GCode::process_layer( if (m_last_obj_copy != this_object_copy) m_avoid_crossing_perimeters.use_external_mp_once = true; m_last_obj_copy = this_object_copy; - this->set_origin(unscale(copy(0)), unscale(copy(1))); + this->set_origin(unscale(copy)); if (object_by_extruder.support != nullptr && !print_wipe_extrusions) { m_layer = layers[layer_id].support_layer; gcode += this->extrude_support( @@ -2621,9 +2621,7 @@ std::string GCode::set_extruder(unsigned int extruder_id) Pointf GCode::point_to_gcode(const Point &point) const { Pointf extruder_offset = EXTRUDER_CONFIG(extruder_offset); - return Pointf( - unscale(point(0)) + m_origin(0) - extruder_offset(0), - unscale(point(1)) + m_origin(1) - extruder_offset(1)); + return unscale(point) + m_origin - extruder_offset; } // convert a model-space scaled point into G-code coordinates @@ -2635,7 +2633,6 @@ Point GCode::gcode_to_point(const Pointf &point) const scale_(point(1) - m_origin(1) + extruder_offset(1))); } - // Goes through by_region std::vector and returns reference to a subvector of entities, that are to be printed // during infill/perimeter wiping, or normally (depends on wiping_entities parameter) // Returns a reference to member to avoid copying. diff --git a/xs/src/libslic3r/GCode/Analyzer.cpp b/xs/src/libslic3r/GCode/Analyzer.cpp index 44e6e9acb..ce9a9ac8e 100644 --- a/xs/src/libslic3r/GCode/Analyzer.cpp +++ b/xs/src/libslic3r/GCode/Analyzer.cpp @@ -14,7 +14,7 @@ static const float MMMIN_TO_MMSEC = 1.0f / 60.0f; static const float INCHES_TO_MM = 25.4f; static const float DEFAULT_FEEDRATE = 0.0f; static const unsigned int DEFAULT_EXTRUDER_ID = 0; -static const Slic3r::Pointf3 DEFAULT_START_POSITION = Slic3r::Pointf3(0.0f, 0.0f, 0.0f); +static const Slic3r::Vec3d DEFAULT_START_POSITION = Slic3r::Vec3d(0.0f, 0.0f, 0.0f); static const float DEFAULT_START_EXTRUSION = 0.0f; namespace Slic3r { @@ -71,7 +71,7 @@ bool GCodeAnalyzer::Metadata::operator != (const GCodeAnalyzer::Metadata& other) return false; } -GCodeAnalyzer::GCodeMove::GCodeMove(GCodeMove::EType type, ExtrusionRole extrusion_role, unsigned int extruder_id, double mm3_per_mm, float width, float height, float feedrate, const Pointf3& start_position, const Pointf3& end_position, float delta_extruder) +GCodeAnalyzer::GCodeMove::GCodeMove(GCodeMove::EType type, ExtrusionRole extrusion_role, unsigned int extruder_id, double mm3_per_mm, float width, float height, float feedrate, const Vec3d& start_position, const Vec3d& end_position, float delta_extruder) : type(type) , data(extrusion_role, extruder_id, mm3_per_mm, width, height, feedrate) , start_position(start_position) @@ -80,7 +80,7 @@ GCodeAnalyzer::GCodeMove::GCodeMove(GCodeMove::EType type, ExtrusionRole extrusi { } -GCodeAnalyzer::GCodeMove::GCodeMove(GCodeMove::EType type, const GCodeAnalyzer::Metadata& data, const Pointf3& start_position, const Pointf3& end_position, float delta_extruder) +GCodeAnalyzer::GCodeMove::GCodeMove(GCodeMove::EType type, const GCodeAnalyzer::Metadata& data, const Vec3d& start_position, const Vec3d& end_position, float delta_extruder) : type(type) , data(data) , start_position(start_position) @@ -587,12 +587,12 @@ void GCodeAnalyzer::_reset_axes_position() ::memset((void*)m_state.position, 0, Num_Axis * sizeof(float)); } -void GCodeAnalyzer::_set_start_position(const Pointf3& position) +void GCodeAnalyzer::_set_start_position(const Vec3d& position) { m_state.start_position = position; } -const Pointf3& GCodeAnalyzer::_get_start_position() const +const Vec3d& GCodeAnalyzer::_get_start_position() const { return m_state.start_position; } @@ -612,9 +612,9 @@ float GCodeAnalyzer::_get_delta_extrusion() const return _get_axis_position(E) - m_state.start_extrusion; } -Pointf3 GCodeAnalyzer::_get_end_position() const +Vec3d GCodeAnalyzer::_get_end_position() const { - return Pointf3(m_state.position[X], m_state.position[Y], m_state.position[Z]); + return Vec3d(m_state.position[X], m_state.position[Y], m_state.position[Z]); } void GCodeAnalyzer::_store_move(GCodeAnalyzer::GCodeMove::EType type) @@ -673,7 +673,7 @@ void GCodeAnalyzer::_calc_gcode_preview_extrusion_layers(GCodePreviewData& previ Metadata data; float z = FLT_MAX; Polyline polyline; - Pointf3 position(FLT_MAX, FLT_MAX, FLT_MAX); + Vec3d position(FLT_MAX, FLT_MAX, FLT_MAX); float volumetric_rate = FLT_MAX; GCodePreviewData::Range height_range; GCodePreviewData::Range width_range; @@ -742,7 +742,7 @@ void GCodeAnalyzer::_calc_gcode_preview_travel(GCodePreviewData& preview_data) return; Polyline3 polyline; - Pointf3 position(FLT_MAX, FLT_MAX, FLT_MAX); + Vec3d position(FLT_MAX, FLT_MAX, FLT_MAX); GCodePreviewData::Travel::EType type = GCodePreviewData::Travel::Num_Types; GCodePreviewData::Travel::Polyline::EDirection direction = GCodePreviewData::Travel::Polyline::Num_Directions; float feedrate = FLT_MAX; diff --git a/xs/src/libslic3r/GCode/Analyzer.hpp b/xs/src/libslic3r/GCode/Analyzer.hpp index 03dbab338..27a49b869 100644 --- a/xs/src/libslic3r/GCode/Analyzer.hpp +++ b/xs/src/libslic3r/GCode/Analyzer.hpp @@ -75,12 +75,12 @@ public: EType type; Metadata data; - Pointf3 start_position; - Pointf3 end_position; + Vec3d start_position; + Vec3d end_position; float delta_extruder; - GCodeMove(EType type, ExtrusionRole extrusion_role, unsigned int extruder_id, double mm3_per_mm, float width, float height, float feedrate, const Pointf3& start_position, const Pointf3& end_position, float delta_extruder); - GCodeMove(EType type, const Metadata& data, const Pointf3& start_position, const Pointf3& end_position, float delta_extruder); + GCodeMove(EType type, ExtrusionRole extrusion_role, unsigned int extruder_id, double mm3_per_mm, float width, float height, float feedrate, const Vec3d& start_position, const Vec3d& end_position, float delta_extruder); + GCodeMove(EType type, const Metadata& data, const Vec3d& start_position, const Vec3d& end_position, float delta_extruder); }; typedef std::vector GCodeMovesList; @@ -93,7 +93,7 @@ private: EPositioningType global_positioning_type; EPositioningType e_local_positioning_type; Metadata data; - Pointf3 start_position; + Vec3d start_position = Vec3d::Zero(); float start_extrusion; float position[Num_Axis]; }; @@ -206,15 +206,15 @@ private: // Sets axes position to zero void _reset_axes_position(); - void _set_start_position(const Pointf3& position); - const Pointf3& _get_start_position() const; + void _set_start_position(const Vec3d& position); + const Vec3d& _get_start_position() const; void _set_start_extrusion(float extrusion); float _get_start_extrusion() const; float _get_delta_extrusion() const; // Returns current xyz position (from m_state.position[]) - Pointf3 _get_end_position() const; + Vec3d _get_end_position() const; // Adds a new move with the given data void _store_move(GCodeMove::EType type); diff --git a/xs/src/libslic3r/GCode/CoolingBuffer.cpp b/xs/src/libslic3r/GCode/CoolingBuffer.cpp index 0f361b250..40ccc7b09 100644 --- a/xs/src/libslic3r/GCode/CoolingBuffer.cpp +++ b/xs/src/libslic3r/GCode/CoolingBuffer.cpp @@ -23,7 +23,7 @@ CoolingBuffer::CoolingBuffer(GCode &gcodegen) : m_gcodegen(gcodegen), m_current_ void CoolingBuffer::reset() { m_current_pos.assign(5, 0.f); - Pointf3 pos = m_gcodegen.writer().get_position(); + Vec3d pos = m_gcodegen.writer().get_position(); m_current_pos[0] = float(pos(0)); m_current_pos[1] = float(pos(1)); m_current_pos[2] = float(pos(2)); diff --git a/xs/src/libslic3r/GCode/PrintExtents.cpp b/xs/src/libslic3r/GCode/PrintExtents.cpp index e1d4e257f..a1cd0cde9 100644 --- a/xs/src/libslic3r/GCode/PrintExtents.cpp +++ b/xs/src/libslic3r/GCode/PrintExtents.cpp @@ -32,8 +32,8 @@ static inline BoundingBoxf extrusionentity_extents(const ExtrusionPath &extrusio BoundingBox bbox = extrusion_polyline_extents(extrusion_path.polyline, scale_(0.5 * extrusion_path.width)); BoundingBoxf bboxf; if (! empty(bbox)) { - bboxf.min = Pointf::new_unscale(bbox.min); - bboxf.max = Pointf::new_unscale(bbox.max); + bboxf.min = unscale(bbox.min); + bboxf.max = unscale(bbox.max); bboxf.defined = true; } return bboxf; @@ -46,8 +46,8 @@ static inline BoundingBoxf extrusionentity_extents(const ExtrusionLoop &extrusio bbox.merge(extrusion_polyline_extents(extrusion_path.polyline, scale_(0.5 * extrusion_path.width))); BoundingBoxf bboxf; if (! empty(bbox)) { - bboxf.min = Pointf::new_unscale(bbox.min); - bboxf.max = Pointf::new_unscale(bbox.max); + bboxf.min = unscale(bbox.min); + bboxf.max = unscale(bbox.max); bboxf.defined = true; } return bboxf; @@ -60,8 +60,8 @@ static inline BoundingBoxf extrusionentity_extents(const ExtrusionMultiPath &ext bbox.merge(extrusion_polyline_extents(extrusion_path.polyline, scale_(0.5 * extrusion_path.width))); BoundingBoxf bboxf; if (! empty(bbox)) { - bboxf.min = Pointf::new_unscale(bbox.min); - bboxf.max = Pointf::new_unscale(bbox.max); + bboxf.min = unscale(bbox.min); + bboxf.max = unscale(bbox.max); bboxf.defined = true; } return bboxf; @@ -123,7 +123,7 @@ BoundingBoxf get_print_object_extrusions_extents(const PrintObject &print_object bbox_this.merge(extrusionentity_extents(extrusion_entity)); for (const Point &offset : print_object._shifted_copies) { BoundingBoxf bbox_translated(bbox_this); - bbox_translated.translate(Pointf::new_unscale(offset)); + bbox_translated.translate(unscale(offset)); bbox.merge(bbox_translated); } } diff --git a/xs/src/libslic3r/GCodeWriter.cpp b/xs/src/libslic3r/GCodeWriter.cpp index cefbdad2e..5352e9502 100644 --- a/xs/src/libslic3r/GCodeWriter.cpp +++ b/xs/src/libslic3r/GCodeWriter.cpp @@ -290,7 +290,7 @@ std::string GCodeWriter::travel_to_xy(const Pointf &point, const std::string &co return gcode.str(); } -std::string GCodeWriter::travel_to_xyz(const Pointf3 &point, const std::string &comment) +std::string GCodeWriter::travel_to_xyz(const Vec3d &point, const std::string &comment) { /* If target Z is lower than current Z but higher than nominal Z we don't perform the Z move but we only move in the XY plane and @@ -299,7 +299,7 @@ std::string GCodeWriter::travel_to_xyz(const Pointf3 &point, const std::string & if (!this->will_move_z(point(2))) { double nominal_z = m_pos(2) - m_lifted; m_lifted = m_lifted - (point(2) - nominal_z); - return this->travel_to_xy(point.xy()); + return this->travel_to_xy(to_2d(point)); } /* In all the other cases, we perform an actual XYZ move and cancel @@ -373,7 +373,7 @@ std::string GCodeWriter::extrude_to_xy(const Pointf &point, double dE, const std return gcode.str(); } -std::string GCodeWriter::extrude_to_xyz(const Pointf3 &point, double dE, const std::string &comment) +std::string GCodeWriter::extrude_to_xyz(const Vec3d &point, double dE, const std::string &comment) { m_pos = point; m_lifted = 0; diff --git a/xs/src/libslic3r/GCodeWriter.hpp b/xs/src/libslic3r/GCodeWriter.hpp index f706b8768..d02bbfe60 100644 --- a/xs/src/libslic3r/GCodeWriter.hpp +++ b/xs/src/libslic3r/GCodeWriter.hpp @@ -56,17 +56,17 @@ public: std::string toolchange(unsigned int extruder_id); std::string set_speed(double F, const std::string &comment = std::string(), const std::string &cooling_marker = std::string()) const; std::string travel_to_xy(const Pointf &point, const std::string &comment = std::string()); - std::string travel_to_xyz(const Pointf3 &point, const std::string &comment = std::string()); + std::string travel_to_xyz(const Vec3d &point, const std::string &comment = std::string()); std::string travel_to_z(double z, const std::string &comment = std::string()); bool will_move_z(double z) const; std::string extrude_to_xy(const Pointf &point, double dE, const std::string &comment = std::string()); - std::string extrude_to_xyz(const Pointf3 &point, double dE, const std::string &comment = std::string()); + std::string extrude_to_xyz(const Vec3d &point, double dE, const std::string &comment = std::string()); std::string retract(bool before_wipe = false); std::string retract_for_toolchange(bool before_wipe = false); std::string unretract(); std::string lift(); std::string unlift(); - Pointf3 get_position() const { return m_pos; } + Vec3d get_position() const { return m_pos; } private: std::vector m_extruders; @@ -81,7 +81,7 @@ private: unsigned int m_last_bed_temperature; bool m_last_bed_temperature_reached; double m_lifted; - Pointf3 m_pos; + Vec3d m_pos = Vec3d::Zero(); std::string _travel_to_z(double z, const std::string &comment); std::string _retract(double length, double restart_extra, const std::string &comment); diff --git a/xs/src/libslic3r/Line.cpp b/xs/src/libslic3r/Line.cpp index 93e888efa..a29e4ce4e 100644 --- a/xs/src/libslic3r/Line.cpp +++ b/xs/src/libslic3r/Line.cpp @@ -97,11 +97,11 @@ bool Line::intersection(const Line &l2, Point *intersection) const return false; // not intersecting } -Pointf3 Linef3::intersect_plane(double z) const +Vec3d Linef3::intersect_plane(double z) const { auto v = (this->b - this->a).cast(); double t = (z - this->a(2)) / v(2); - return Pointf3(this->a(0) + v(0) * t, this->a(1) + v(1) * t, z); + return Vec3d(this->a(0) + v(0) * t, this->a(1) + v(1) * t, z); } } diff --git a/xs/src/libslic3r/Line.hpp b/xs/src/libslic3r/Line.hpp index 39c2e1ff1..39a7c2223 100644 --- a/xs/src/libslic3r/Line.hpp +++ b/xs/src/libslic3r/Line.hpp @@ -81,13 +81,13 @@ public: class Linef3 { public: - Linef3() {} - explicit Linef3(Pointf3 _a, Pointf3 _b): a(_a), b(_b) {} - Pointf3 intersect_plane(double z) const; + Linef3() : a(0., 0., 0.), b(0., 0., 0.) {} + explicit Linef3(Vec3d _a, Vec3d _b): a(_a), b(_b) {} + Vec3d intersect_plane(double z) const; void scale(double factor) { this->a *= factor; this->b *= factor; } - Pointf3 a; - Pointf3 b; + Vec3d a; + Vec3d b; }; } // namespace Slic3r diff --git a/xs/src/libslic3r/Model.cpp b/xs/src/libslic3r/Model.cpp index c5b8ad8df..cc59b6558 100644 --- a/xs/src/libslic3r/Model.cpp +++ b/xs/src/libslic3r/Model.cpp @@ -251,7 +251,7 @@ void Model::center_instances_around_point(const Pointf &point) for (size_t i = 0; i < o->instances.size(); ++ i) bb.merge(o->instance_bounding_box(i, false)); - Pointf shift = point - 0.5 * bb.size().xy() - bb.min.xy(); + Pointf shift = point - 0.5 * to_2d(bb.size()) - to_2d(bb.min); for (ModelObject *o : this->objects) { for (ModelInstance *i : o->instances) i->offset += shift; @@ -309,8 +309,8 @@ bool Model::arrange_objects(coordf_t dist, const BoundingBoxf* bb) for (size_t i = 0; i < o->instances.size(); ++ i) { // an accurate snug bounding box around the transformed mesh. BoundingBoxf3 bbox(o->instance_bounding_box(i, true)); - instance_sizes.push_back(bbox.size().xy()); - instance_centers.push_back(bbox.center().xy()); + instance_sizes.emplace_back(to_2d(bbox.size())); + instance_centers.emplace_back(to_2d(bbox.center())); } Pointfs positions; @@ -332,7 +332,7 @@ bool Model::arrange_objects(coordf_t dist, const BoundingBoxf* bb) // Duplicate the entire model preserving instance relative positions. void Model::duplicate(size_t copies_num, coordf_t dist, const BoundingBoxf* bb) { - Pointfs model_sizes(copies_num-1, this->bounding_box().size().xy()); + Pointfs model_sizes(copies_num-1, to_2d(this->bounding_box().size())); Pointfs positions; if (! _arrange(model_sizes, dist, bb, positions)) CONFESS("Cannot duplicate part as the resulting objects would not fit on the print bed.\n"); @@ -375,7 +375,7 @@ void Model::duplicate_objects_grid(size_t x, size_t y, coordf_t dist) ModelObject* object = this->objects.front(); object->clear_instances(); - Sizef3 size = object->bounding_box().size(); + Vec3d size = object->bounding_box().size(); for (size_t x_copy = 1; x_copy <= x; ++x_copy) { for (size_t y_copy = 1; y_copy <= y; ++y_copy) { @@ -642,7 +642,7 @@ BoundingBoxf3 ModelObject::tight_bounding_box(bool include_modifiers) const { // original point const stl_vertex& v = facet.vertex[i]; - Pointf3 p((double)v.x, (double)v.y, (double)v.z); + Vec3d p((double)v.x, (double)v.y, (double)v.z); // scale p(0) *= inst->scaling_factor; @@ -727,10 +727,10 @@ void ModelObject::center_around_origin() bb.merge(v->mesh.bounding_box()); // first align to origin on XYZ - Vectorf3 vector(-bb.min(0), -bb.min(1), -bb.min(2)); + Vec3d vector(-bb.min(0), -bb.min(1), -bb.min(2)); // then center it on XY - Sizef3 size = bb.size(); + Vec3d size = bb.size(); vector(0) -= size(0)/2; vector(1) -= size(1)/2; @@ -741,7 +741,7 @@ void ModelObject::center_around_origin() for (ModelInstance *i : this->instances) { // apply rotation and scaling to vector as well before translating instance, // in order to leave final position unaltered - Vectorf v = - vector.xy(); + Vectorf v = - to_2d(vector); v.rotate(i->rotation); i->offset += v * i->scaling_factor; } @@ -757,12 +757,12 @@ void ModelObject::translate(coordf_t x, coordf_t y, coordf_t z) m_bounding_box.translate(x, y, z); } -void ModelObject::scale(const Pointf3 &versor) +void ModelObject::scale(const Vec3d &versor) { for (ModelVolume *v : this->volumes) v->mesh.scale(versor); // reset origin translation since it doesn't make sense anymore - this->origin_translation = Pointf3(0,0,0); + this->origin_translation = Vec3d(0,0,0); this->invalidate_bounding_box(); } @@ -784,7 +784,7 @@ void ModelObject::rotate(float angle, const Axis &axis) } } - this->origin_translation = Pointf3(0, 0, 0); + this->origin_translation = Vec3d(0, 0, 0); this->invalidate_bounding_box(); } @@ -798,7 +798,7 @@ void ModelObject::transform(const float* matrix3x4) v->mesh.transform(matrix3x4); } - origin_translation = Pointf3(0.0, 0.0, 0.0); + origin_translation = Vec3d(0.0, 0.0, 0.0); invalidate_bounding_box(); } @@ -806,7 +806,7 @@ void ModelObject::mirror(const Axis &axis) { for (ModelVolume *v : this->volumes) v->mesh.mirror(axis); - this->origin_translation = Pointf3(0,0,0); + this->origin_translation = Vec3d(0,0,0); this->invalidate_bounding_box(); } @@ -929,7 +929,7 @@ void ModelObject::check_instances_print_volume_state(const BoundingBoxf3& print_ { // original point const stl_vertex& v = facet.vertex[i]; - Pointf3 p((double)v.x, (double)v.y, (double)v.z); + Vec3d p((double)v.x, (double)v.y, (double)v.z); // scale p(0) *= inst->scaling_factor; @@ -970,7 +970,7 @@ void ModelObject::print_info() const TriangleMesh mesh = this->raw_mesh(); mesh.check_topology(); BoundingBoxf3 bb = mesh.bounding_box(); - Sizef3 size = bb.size(); + Vec3d size = bb.size(); cout << "size_x = " << size(0) << endl; cout << "size_y = " << size(1) << endl; cout << "size_z = " << size(2) << endl; @@ -1082,30 +1082,20 @@ BoundingBoxf3 ModelInstance::transform_mesh_bounding_box(const TriangleMesh* mes for (int i = 0; i < mesh->stl.stats.number_of_facets; ++ i) { const stl_facet &facet = mesh->stl.facet_start[i]; for (int j = 0; j < 3; ++ j) { - stl_vertex v = facet.vertex[j]; - double xold = v.x; - double yold = v.y; - v.x = float(c * xold - s * yold); - v.y = float(s * xold + c * yold); - bbox.merge(Pointf3(v.x, v.y, v.z)); + const stl_vertex &v = facet.vertex[j]; + bbox.merge(Vec3d(c * v.x - s * v.y, s * v.x + c * v.y, v.z)); } } if (! empty(bbox)) { // Scale the bounding box uniformly. if (std::abs(this->scaling_factor - 1.) > EPSILON) { - bbox.min(0) *= float(this->scaling_factor); - bbox.min(1) *= float(this->scaling_factor); - bbox.min(2) *= float(this->scaling_factor); - bbox.max(0) *= float(this->scaling_factor); - bbox.max(1) *= float(this->scaling_factor); - bbox.max(2) *= float(this->scaling_factor); + bbox.min *= this->scaling_factor; + bbox.max *= this->scaling_factor; } // Translate the bounding box. if (! dont_translate) { - bbox.min(0) += float(this->offset(0)); - bbox.min(1) += float(this->offset(1)); - bbox.max(0) += float(this->offset(0)); - bbox.max(1) += float(this->offset(1)); + Eigen::Map(bbox.min.data()) += this->offset; + Eigen::Map(bbox.max.data()) += this->offset; } } return bbox; diff --git a/xs/src/libslic3r/Model.hpp b/xs/src/libslic3r/Model.hpp index 8dcfff024..dfe391b0e 100644 --- a/xs/src/libslic3r/Model.hpp +++ b/xs/src/libslic3r/Model.hpp @@ -84,7 +84,7 @@ public: center_around_origin() method. Callers might want to apply the same translation to new volumes before adding them to this object in order to preserve alignment when user expects that. */ - Pointf3 origin_translation; + Vec3d origin_translation; Model* get_model() const { return m_model; }; @@ -120,9 +120,9 @@ public: // A snug bounding box around the transformed non-modifier object volumes. BoundingBoxf3 instance_bounding_box(size_t instance_idx, bool dont_translate = false) const; void center_around_origin(); - void translate(const Vectorf3 &vector) { this->translate(vector(0), vector(1), vector(2)); } + void translate(const Vec3d &vector) { this->translate(vector(0), vector(1), vector(2)); } void translate(coordf_t x, coordf_t y, coordf_t z); - void scale(const Pointf3 &versor); + void scale(const Vec3d &versor); void rotate(float angle, const Axis &axis); void transform(const float* matrix3x4); void mirror(const Axis &axis); @@ -138,7 +138,7 @@ public: void print_info() const; private: - ModelObject(Model *model) : layer_height_profile_valid(false), m_model(model), m_bounding_box_valid(false) {} + ModelObject(Model *model) : layer_height_profile_valid(false), m_model(model), origin_translation(Vec3d::Zero()), m_bounding_box_valid(false) {} ModelObject(Model *model, const ModelObject &other, bool copy_volumes = true); ModelObject& operator= (ModelObject other); void swap(ModelObject &other); diff --git a/xs/src/libslic3r/PerimeterGenerator.cpp b/xs/src/libslic3r/PerimeterGenerator.cpp index 8e7b33cc8..de8aeeb2a 100644 --- a/xs/src/libslic3r/PerimeterGenerator.cpp +++ b/xs/src/libslic3r/PerimeterGenerator.cpp @@ -243,7 +243,7 @@ void PerimeterGenerator::process() perimeter_spacing / 2; // only apply infill overlap if we actually have one perimeter if (inset > 0) - inset -= scale_(this->config->get_abs_value("infill_overlap", unscale(inset + solid_infill_spacing / 2))); + inset -= scale_(this->config->get_abs_value("infill_overlap", unscale(inset + solid_infill_spacing / 2))); // simplify infill contours according to resolution Polygons pp; for (ExPolygon &ex : last) @@ -420,7 +420,7 @@ static inline ExtrusionPaths thick_polyline_to_extrusion_paths(const ThickPolyli path.polyline.append(line.b); // Convert from spacing to extrusion width based on the extrusion model // of a square extrusion ended with semi circles. - flow.width = unscale(w) + flow.height * (1. - 0.25 * PI); + flow.width = unscale(w) + flow.height * (1. - 0.25 * PI); #ifdef SLIC3R_DEBUG printf(" filling %f gap\n", flow.width); #endif diff --git a/xs/src/libslic3r/Point.hpp b/xs/src/libslic3r/Point.hpp index 311951175..e189e22ee 100644 --- a/xs/src/libslic3r/Point.hpp +++ b/xs/src/libslic3r/Point.hpp @@ -18,17 +18,9 @@ class MultiPoint; class Point; class Point3; class Pointf; -class Pointf3; typedef Point Vector; typedef Point3 Vector3; typedef Pointf Vectorf; -typedef Pointf3 Vectorf3; -typedef std::vector Points; -typedef std::vector PointPtrs; -typedef std::vector PointConstPtrs; -typedef std::vector Points3; -typedef std::vector Pointfs; -typedef std::vector Pointf3s; // Eigen types, to replace the Slic3r's own types in the future. // Vector types with a fixed point coordinate base type. @@ -43,6 +35,13 @@ typedef Eigen::Matrix Vec3f; typedef Eigen::Matrix Vec2d; typedef Eigen::Matrix Vec3d; +typedef std::vector Points; +typedef std::vector PointPtrs; +typedef std::vector PointConstPtrs; +typedef std::vector Points3; +typedef std::vector Pointfs; +typedef std::vector Pointf3s; + typedef Eigen::Transform Transform2f; typedef Eigen::Transform Transform2d; typedef Eigen::Transform Transform3f; @@ -53,6 +52,18 @@ inline coord_t cross2(const Vec2crd &v1, const Vec2crd &v2) { return v1(0) * v2( 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 Vec2crd to_2d(const Vec3crd &pt3) { return Vec2crd(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 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))); } +inline Vec2d unscale(const Vec2d &pt) { return Vec2d(unscale(pt(0)), unscale(pt(1))); } +inline Vec3d unscale(coord_t x, coord_t y, coord_t z) { return Vec3d(unscale(x), unscale(y), unscale(z)); } +inline Vec3d unscale(const Vec3crd &pt) { return Vec3d(unscale(pt(0)), unscale(pt(1)), unscale(pt(2))); } +inline Vec3d unscale(const Vec3d &pt) { return Vec3d(unscale(pt(0)), unscale(pt(1)), unscale(pt(2))); } + inline std::string to_string(const Vec2crd &pt) { return std::string("[") + std::to_string(pt(0)) + ", " + std::to_string(pt(1)) + "]"; } inline std::string to_string(const Vec2d &pt) { return std::string("[") + std::to_string(pt(0)) + ", " + std::to_string(pt(1)) + "]"; } inline std::string to_string(const Vec3crd &pt) { return std::string("[") + std::to_string(pt(0)) + ", " + std::to_string(pt(1)) + ", " + std::to_string(pt(2)) + "]"; } @@ -229,8 +240,6 @@ public: this->Vec3crd::operator=(other); return *this; } - - Point xy() const { return Point((*this)(0), (*this)(1)); } }; std::ostream& operator<<(std::ostream &stm, const Pointf &pointf); @@ -245,8 +254,6 @@ public: // This constructor allows you to construct Pointf from Eigen expressions template Pointf(const Eigen::MatrixBase &other) : Vec2d(other) {} - static Pointf new_unscale(coord_t x, coord_t y) { return Pointf(unscale(x), unscale(y)); } - static Pointf new_unscale(const Point &p) { return Pointf(unscale(p(0)), unscale(p(1))); } // This method allows you to assign Eigen expressions to MyVectorType template @@ -262,30 +269,6 @@ public: bool operator< (const Pointf& rhs) const { return (*this)(0) < rhs(0) || ((*this)(0) == rhs(0) && (*this)(1) < rhs(1)); } }; -class Pointf3 : public Vec3d -{ -public: - typedef coordf_t coord_type; - - explicit Pointf3() { (*this)(0) = (*this)(1) = (*this)(2) = 0.; } - explicit Pointf3(coordf_t x, coordf_t y, coordf_t z) { (*this)(0) = x; (*this)(1) = y; (*this)(2) = z; } - // This constructor allows you to construct Pointf from Eigen expressions - template - Pointf3(const Eigen::MatrixBase &other) : Vec3d(other) {} - static Pointf3 new_unscale(coord_t x, coord_t y, coord_t z) { return Pointf3(unscale(x), unscale(y), unscale(z)); } - static Pointf3 new_unscale(const Point3& p) { return Pointf3(unscale(p(0)), unscale(p(1)), unscale(p(2))); } - - // This method allows you to assign Eigen expressions to MyVectorType - template - Pointf3& operator=(const Eigen::MatrixBase &other) - { - this->Vec3d::operator=(other); - return *this; - } - - Pointf xy() const { return Pointf((*this)(0), (*this)(1)); } -}; - } // namespace Slic3r // start Boost diff --git a/xs/src/libslic3r/Print.cpp b/xs/src/libslic3r/Print.cpp index 82dee9049..230201cc1 100644 --- a/xs/src/libslic3r/Print.cpp +++ b/xs/src/libslic3r/Print.cpp @@ -536,7 +536,7 @@ bool Print::has_skirt() const std::string Print::validate() const { BoundingBox bed_box_2D = get_extents(Polygon::new_scale(config.bed_shape.values)); - BoundingBoxf3 print_volume(Pointf3(unscale(bed_box_2D.min(0)), unscale(bed_box_2D.min(1)), 0.0), Pointf3(unscale(bed_box_2D.max(0)), unscale(bed_box_2D.max(1)), config.max_print_height)); + BoundingBoxf3 print_volume(unscale(bed_box_2D.min(0), bed_box_2D.min(1), 0.0), unscale(bed_box_2D.max(0), bed_box_2D.max(1), scale_(config.max_print_height))); // Allow the objects to protrude below the print bed, only the part of the object above the print bed will be sliced. print_volume.min(2) = -1e10; unsigned int printable_count = 0; @@ -724,7 +724,7 @@ BoundingBox Print::bounding_box() const for (const PrintObject *object : this->objects) for (Point copy : object->_shifted_copies) { bb.merge(copy); - copy += object->size.xy(); + copy += to_2d(object->size); bb.merge(copy); } return bb; @@ -967,7 +967,7 @@ void Print::_make_skirt() this->skirt.append(eloop); if (this->config.min_skirt_length.value > 0) { // The skirt length is limited. Sum the total amount of filament length extruded, in mm. - extruded_length[extruder_idx] += unscale(loop.length()) * extruders_e_per_mm[extruder_idx]; + extruded_length[extruder_idx] += unscale(loop.length()) * extruders_e_per_mm[extruder_idx]; if (extruded_length[extruder_idx] < this->config.min_skirt_length.value) { // Not extruded enough yet with the current extruder. Add another loop. if (i == 1) diff --git a/xs/src/libslic3r/Print.hpp b/xs/src/libslic3r/Print.hpp index 36e6784cd..734b04e3f 100644 --- a/xs/src/libslic3r/Print.hpp +++ b/xs/src/libslic3r/Print.hpp @@ -144,7 +144,7 @@ public: bool set_copies(const Points &points); bool reload_model_instances(); // since the object is aligned to origin, bounding box coincides with size - BoundingBox bounding_box() const { return BoundingBox(Point(0,0), this->size.xy()); } + BoundingBox bounding_box() const { return BoundingBox(Point(0,0), to_2d(this->size)); } // adds region_id, too, if necessary void add_region_volume(unsigned int region_id, int volume_id) { diff --git a/xs/src/libslic3r/PrintObject.cpp b/xs/src/libslic3r/PrintObject.cpp index 8df711196..10ebcb18e 100644 --- a/xs/src/libslic3r/PrintObject.cpp +++ b/xs/src/libslic3r/PrintObject.cpp @@ -50,7 +50,7 @@ PrintObject::PrintObject(Print* print, ModelObject* model_object, const Bounding // (copies are expressed in G-code coordinates and this translation is not publicly exposed). this->_copies_shift = Point::new_scale(modobj_bbox.min(0), modobj_bbox.min(1)); // Scale the object size and store it - Pointf3 size = modobj_bbox.size(); + Vec3d size = modobj_bbox.size(); this->size = Point3::new_scale(size(0), size(1), size(2)); } @@ -1121,7 +1121,7 @@ SlicingParameters PrintObject::slicing_parameters() const { return SlicingParameters::create_from_config( this->print()->config, this->config, - unscale(this->size(2)), this->print()->object_extruders()); + unscale(this->size(2)), this->print()->object_extruders()); } bool PrintObject::update_layer_height_profile(std::vector &layer_height_profile) const @@ -1335,7 +1335,7 @@ std::vector PrintObject::_slice_region(size_t region_id, const std:: // consider the first one this->model_object()->instances.front()->transform_mesh(&mesh, true); // align mesh to Z = 0 (it should be already aligned actually) and apply XY shift - mesh.translate(- float(unscale(this->_copies_shift(0))), - float(unscale(this->_copies_shift(1))), -float(this->model_object()->bounding_box().min(2))); + mesh.translate(- unscale(this->_copies_shift(0)), - unscale(this->_copies_shift(1)), - float(this->model_object()->bounding_box().min(2))); // perform actual slicing TriangleMeshSlicer mslicer(&mesh); mslicer.slice(z, &layers); diff --git a/xs/src/libslic3r/SVG.cpp b/xs/src/libslic3r/SVG.cpp index d3a0eed36..2113acc43 100644 --- a/xs/src/libslic3r/SVG.cpp +++ b/xs/src/libslic3r/SVG.cpp @@ -3,7 +3,7 @@ #include -#define COORD(x) ((float)unscale((x))*10) +#define COORD(x) (unscale((x))*10) namespace Slic3r { diff --git a/xs/src/libslic3r/Slicing.cpp b/xs/src/libslic3r/Slicing.cpp index d745a803c..bebff6c43 100644 --- a/xs/src/libslic3r/Slicing.cpp +++ b/xs/src/libslic3r/Slicing.cpp @@ -607,7 +607,7 @@ int generate_layer_height_texture( // Intensity profile to visualize the layers. coordf_t intensity = cos(M_PI * 0.7 * (mid - z) / h); // Color mapping from layer height to RGB. - Pointf3 color( + Vec3d color( intensity * lerp(coordf_t(color1(0)), coordf_t(color2(0)), t), intensity * lerp(coordf_t(color1(1)), coordf_t(color2(1)), t), intensity * lerp(coordf_t(color1(2)), coordf_t(color2(2)), t)); @@ -639,7 +639,7 @@ int generate_layer_height_texture( const Point3 &color1 = palette_raw[idx1]; const Point3 &color2 = palette_raw[idx2]; // Color mapping from layer height to RGB. - Pointf3 color( + Vec3d color( lerp(coordf_t(color1(0)), coordf_t(color2(0)), t), lerp(coordf_t(color1(1)), coordf_t(color2(1)), t), lerp(coordf_t(color1(2)), coordf_t(color2(2)), t)); diff --git a/xs/src/libslic3r/TriangleMesh.cpp b/xs/src/libslic3r/TriangleMesh.cpp index 30ef637e5..ff226ad9e 100644 --- a/xs/src/libslic3r/TriangleMesh.cpp +++ b/xs/src/libslic3r/TriangleMesh.cpp @@ -52,17 +52,17 @@ TriangleMesh::TriangleMesh(const Pointf3s &points, const std::vector& fa for (int i = 0; i < stl.stats.number_of_facets; i++) { stl_facet facet; - const Pointf3& ref_f1 = points[facets[i](0)]; + const Vec3d& ref_f1 = points[facets[i](0)]; facet.vertex[0].x = ref_f1(0); facet.vertex[0].y = ref_f1(1); facet.vertex[0].z = ref_f1(2); - const Pointf3& ref_f2 = points[facets[i](1)]; + const Vec3d& ref_f2 = points[facets[i](1)]; facet.vertex[1].x = ref_f2(0); facet.vertex[1].y = ref_f2(1); facet.vertex[1].z = ref_f2(2); - const Pointf3& ref_f3 = points[facets[i](2)]; + const Vec3d& ref_f3 = points[facets[i](2)]; facet.vertex[2].x = ref_f3(0); facet.vertex[2].y = ref_f3(1); facet.vertex[2].z = ref_f3(2); @@ -300,7 +300,7 @@ void TriangleMesh::scale(float factor) stl_invalidate_shared_vertices(&this->stl); } -void TriangleMesh::scale(const Pointf3 &versor) +void TriangleMesh::scale(const Vec3d &versor) { float fversor[3]; fversor[0] = versor(0); @@ -1493,8 +1493,8 @@ void TriangleMeshSlicer::cut(float z, TriangleMesh* upper, TriangleMesh* lower) facet.normal.y = 0; facet.normal.z = -1; for (size_t i = 0; i <= 2; ++i) { - facet.vertex[i].x = unscale(p.points[i](0)); - facet.vertex[i].y = unscale(p.points[i](1)); + facet.vertex[i].x = unscale(p.points[i](0)); + facet.vertex[i].y = unscale(p.points[i](1)); facet.vertex[i].z = z; } stl_add_facet(&upper->stl, &facet); @@ -1519,8 +1519,8 @@ void TriangleMeshSlicer::cut(float z, TriangleMesh* upper, TriangleMesh* lower) facet.normal.y = 0; facet.normal.z = 1; for (size_t i = 0; i <= 2; ++i) { - facet.vertex[i].x = unscale(polygon->points[i](0)); - facet.vertex[i].y = unscale(polygon->points[i](1)); + facet.vertex[i].x = unscale(polygon->points[i](0)); + facet.vertex[i].y = unscale(polygon->points[i](1)); facet.vertex[i].z = z; } stl_add_facet(&lower->stl, &facet); @@ -1534,10 +1534,10 @@ void TriangleMeshSlicer::cut(float z, TriangleMesh* upper, TriangleMesh* lower) // Generate the vertex list for a cube solid of arbitrary size in X/Y/Z. TriangleMesh make_cube(double x, double y, double z) { - Pointf3 pv[8] = { - Pointf3(x, y, 0), Pointf3(x, 0, 0), Pointf3(0, 0, 0), - Pointf3(0, y, 0), Pointf3(x, y, z), Pointf3(0, y, z), - Pointf3(0, 0, z), Pointf3(x, 0, z) + Vec3d pv[8] = { + Vec3d(x, y, 0), Vec3d(x, 0, 0), Vec3d(0, 0, 0), + Vec3d(0, y, 0), Vec3d(x, y, z), Vec3d(0, y, z), + Vec3d(0, 0, z), Vec3d(x, 0, z) }; Point3 fv[12] = { Point3(0, 1, 2), Point3(0, 2, 3), Point3(4, 5, 6), @@ -1561,8 +1561,8 @@ TriangleMesh make_cylinder(double r, double h, double fa) { std::vector facets; // 2 special vertices, top and bottom center, rest are relative to this - vertices.emplace_back(Pointf3(0.0, 0.0, 0.0)); - vertices.emplace_back(Pointf3(0.0, 0.0, h)); + vertices.emplace_back(Vec3d(0.0, 0.0, 0.0)); + vertices.emplace_back(Vec3d(0.0, 0.0, h)); // adjust via rounding to get an even multiple for any provided angle. double angle = (2*PI / floor(2*PI / fa)); @@ -1572,13 +1572,13 @@ TriangleMesh make_cylinder(double r, double h, double fa) { // top and bottom. // Special case: Last line shares 2 vertices with the first line. unsigned id = vertices.size() - 1; - vertices.emplace_back(Pointf3(sin(0) * r , cos(0) * r, 0)); - vertices.emplace_back(Pointf3(sin(0) * r , cos(0) * r, h)); + vertices.emplace_back(Vec3d(sin(0) * r , cos(0) * r, 0)); + vertices.emplace_back(Vec3d(sin(0) * r , cos(0) * r, h)); for (double i = 0; i < 2*PI; i+=angle) { Pointf p(0, r); p.rotate(i); - vertices.emplace_back(Pointf3(p(0), p(1), 0.)); - vertices.emplace_back(Pointf3(p(0), p(1), h)); + 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(Point3( 0, id - 1, id - 3)); // top facets.emplace_back(Point3(id, 1, id - 2)); // bottom @@ -1619,7 +1619,7 @@ TriangleMesh make_sphere(double rho, double fa) { // special case: first ring connects to 0,0,0 // insert and form facets. - vertices.emplace_back(Pointf3(0.0, 0.0, -rho)); + vertices.emplace_back(Vec3d(0.0, 0.0, -rho)); size_t id = vertices.size(); for (size_t i = 0; i < ring.size(); i++) { // Fixed scaling @@ -1628,7 +1628,7 @@ TriangleMesh make_sphere(double rho, double fa) { const double r = sqrt(abs(rho*rho - z*z)); Pointf b(0, r); b.rotate(ring[i]); - vertices.emplace_back(Pointf3(b(0), b(1), z)); + vertices.emplace_back(Vec3d(b(0), b(1), z)); facets.emplace_back((i == 0) ? Point3(1, 0, ring.size()) : Point3(id, 0, id - 1)); ++ id; } @@ -1641,7 +1641,7 @@ TriangleMesh make_sphere(double rho, double fa) { for (size_t i = 0; i < ring.size(); i++) { Pointf b(0, r); b.rotate(ring[i]); - vertices.emplace_back(Pointf3(b(0), b(1), z)); + vertices.emplace_back(Vec3d(b(0), b(1), z)); if (i == 0) { // wrap around facets.emplace_back(Point3(id + ring.size() - 1 , id, id - 1)); @@ -1657,7 +1657,7 @@ TriangleMesh make_sphere(double rho, double fa) { // special case: last ring connects to 0,0,rho*2.0 // only form facets. - vertices.emplace_back(Pointf3(0.0, 0.0, rho)); + vertices.emplace_back(Vec3d(0.0, 0.0, rho)); for (size_t i = 0; i < ring.size(); i++) { if (i == 0) { // third vertex is on the other side of the ring. diff --git a/xs/src/libslic3r/TriangleMesh.hpp b/xs/src/libslic3r/TriangleMesh.hpp index c700784a5..b04d09f32 100644 --- a/xs/src/libslic3r/TriangleMesh.hpp +++ b/xs/src/libslic3r/TriangleMesh.hpp @@ -37,7 +37,7 @@ public: bool is_manifold() const; void WriteOBJFile(char* output_file); void scale(float factor); - void scale(const Pointf3 &versor); + void scale(const Vec3d &versor); void translate(float x, float y, float z); void rotate(float angle, const Axis &axis); void rotate_x(float angle); diff --git a/xs/src/libslic3r/libslic3r.h b/xs/src/libslic3r/libslic3r.h index 862ce2e51..6fea64cd1 100644 --- a/xs/src/libslic3r/libslic3r.h +++ b/xs/src/libslic3r/libslic3r.h @@ -45,7 +45,6 @@ typedef double coordf_t; //FIXME Better to use an inline function with an explicit return type. //inline coord_t scale_(coordf_t v) { return coord_t(floor(v / SCALING_FACTOR + 0.5f)); } #define scale_(val) ((val) / SCALING_FACTOR) -#define unscale(val) ((val) * SCALING_FACTOR) #define SCALED_EPSILON scale_(EPSILON) /* Implementation of CONFESS("foo"): */ #ifdef _MSC_VER @@ -102,6 +101,9 @@ inline std::string debug_out_path(const char *name, ...) namespace Slic3r { +template +inline T unscale(Q v) { return T(v) * T(SCALING_FACTOR); } + enum Axis { X=0, Y, Z, E, F, NUM_AXES }; template diff --git a/xs/src/perlglue.cpp b/xs/src/perlglue.cpp index dbaf35ae4..46d8d1618 100644 --- a/xs/src/perlglue.cpp +++ b/xs/src/perlglue.cpp @@ -43,7 +43,7 @@ REGISTER_CLASS(BridgeDetector, "BridgeDetector"); REGISTER_CLASS(Point, "Point"); REGISTER_CLASS(Point3, "Point3"); REGISTER_CLASS(Pointf, "Pointf"); -REGISTER_CLASS(Pointf3, "Pointf3"); +__REGISTER_CLASS(Vec3d, "Pointf3"); REGISTER_CLASS(DynamicPrintConfig, "Config"); REGISTER_CLASS(StaticPrintConfig, "Config::Static"); REGISTER_CLASS(PrintObjectConfig, "Config::PrintObject"); diff --git a/xs/src/slic3r/GUI/2DBed.cpp b/xs/src/slic3r/GUI/2DBed.cpp index 5f087a881..35c23272e 100644 --- a/xs/src/slic3r/GUI/2DBed.cpp +++ b/xs/src/slic3r/GUI/2DBed.cpp @@ -91,8 +91,8 @@ void Bed_2D::repaint() for (auto pl : polylines) { for (size_t i = 0; i < pl.points.size()-1; i++){ - Point pt1 = to_pixels(Pointf::new_unscale(pl.points[i])); - Point pt2 = to_pixels(Pointf::new_unscale(pl.points[i+1])); + Point pt1 = to_pixels(unscale(pl.points[i])); + Point pt2 = to_pixels(unscale(pl.points[i+1])); dc.DrawLine(pt1(0), pt1(1), pt2(0), pt2(1)); } } diff --git a/xs/src/slic3r/GUI/3DScene.cpp b/xs/src/slic3r/GUI/3DScene.cpp index 36952d230..86cbe1b6f 100644 --- a/xs/src/slic3r/GUI/3DScene.cpp +++ b/xs/src/slic3r/GUI/3DScene.cpp @@ -195,7 +195,8 @@ const float GLVolume::OUTSIDE_COLOR[4] = { 0.0f, 0.38f, 0.8f, 1.0f }; const float GLVolume::SELECTED_OUTSIDE_COLOR[4] = { 0.19f, 0.58f, 1.0f, 1.0f }; GLVolume::GLVolume(float r, float g, float b, float a) - : m_angle_z(0.0f) + : m_origin(0, 0, 0) + , m_angle_z(0.0f) , m_scale_factor(1.0f) , m_dirty(true) , composite_id(-1) @@ -252,12 +253,12 @@ void GLVolume::set_render_color() set_render_color(color, 4); } -const Pointf3& GLVolume::get_origin() const +const Vec3d& GLVolume::get_origin() const { return m_origin; } -void GLVolume::set_origin(const Pointf3& origin) +void GLVolume::set_origin(const Vec3d& origin) { m_origin = origin; m_dirty = true; @@ -629,7 +630,7 @@ std::vector GLVolumeCollection::load_object( } v.is_modifier = model_volume->modifier; v.shader_outside_printer_detection_enabled = !model_volume->modifier; - v.set_origin(Pointf3(instance->offset(0), instance->offset(1), 0.0)); + v.set_origin(Vec3d(instance->offset(0), instance->offset(1), 0.0)); v.set_angle_z(instance->rotation); v.set_scale_factor(instance->scaling_factor); } @@ -667,7 +668,7 @@ int GLVolumeCollection::load_wipe_tower_preview( {8, 10, 14}, {3, 12, 4}, {3, 13, 12}, {6, 13, 3}, {6, 14, 13}, {7, 14, 6}, {7, 15, 14}, {2, 15, 7}, {2, 8, 15}, {1, 8, 2}, {1, 9, 8}, {0, 9, 1}, {0, 10, 9}, {5, 10, 0}, {5, 11, 10}, {4, 11, 5}, {4, 12, 11}}; for (int i=0;i<16;++i) - points.push_back(Pointf3(out_points_idx[i][0] / (100.f/min_width), out_points_idx[i][1] + depth, out_points_idx[i][2])); + 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(Point3(out_facets_idx[i][0], out_facets_idx[i][1], out_facets_idx[i][2])); TriangleMesh tooth_mesh(points, facets); @@ -680,7 +681,7 @@ int GLVolumeCollection::load_wipe_tower_preview( tooth_mesh.translate(min_width, 0.f, 0.f); } - mesh.scale(Pointf3(width/(n*min_width), 1.f, height)); // Scaling to proper width + mesh.scale(Vec3d(width/(n*min_width), 1.f, height)); // Scaling to proper width } else mesh = make_cube(width, depth, height); @@ -700,7 +701,7 @@ int GLVolumeCollection::load_wipe_tower_preview( else v.indexed_vertex_array.load_mesh_flat_shading(mesh); - v.set_origin(Pointf3(pos_x, pos_y, 0.)); + v.set_origin(Vec3d(pos_x, pos_y, 0.)); // finalize_geometry() clears the vertex arrays, therefore the bounding box has to be computed before finalize_geometry(). v.bounding_box = v.indexed_vertex_array.bounding_box(); @@ -786,7 +787,7 @@ bool GLVolumeCollection::check_outside_state(const DynamicPrintConfig* config, M return false; BoundingBox bed_box_2D = get_extents(Polygon::new_scale(opt->values)); - BoundingBoxf3 print_volume(Pointf3(unscale(bed_box_2D.min(0)), unscale(bed_box_2D.min(1)), 0.0), Pointf3(unscale(bed_box_2D.max(0)), unscale(bed_box_2D.max(1)), config->opt_float("max_print_height"))); + BoundingBoxf3 print_volume(unscale(bed_box_2D.min(0), bed_box_2D.min(1), 0.0), unscale(bed_box_2D.max(0), bed_box_2D.max(1), unscale(config->opt_float("max_print_height")))); // Allow the objects to protrude below the print bed print_volume.min(2) = -1e10; @@ -962,7 +963,7 @@ static void thick_lines_to_indexed_vertex_array( for (size_t ii = 0; ii < lines_end; ++ ii) { size_t i = (ii == lines.size()) ? 0 : ii; const Line &line = lines[i]; - double len = unscale(line.length()); + double len = unscale(line.length()); double inv_len = 1.0 / len; double bottom_z = top_z - heights[i]; double middle_z = 0.5 * (top_z + bottom_z); @@ -972,11 +973,11 @@ static void thick_lines_to_indexed_vertex_array( bool is_last = (ii == lines_end - 1); bool is_closing = closed && is_last; - Vectorf v = Vectorf::new_unscale(line.vector()); + Vectorf v = unscale(line.vector()); v *= inv_len; - Pointf a = Pointf::new_unscale(line.a); - Pointf b = Pointf::new_unscale(line.b); + Pointf a = unscale(line.a); + Pointf b = unscale(line.b); Pointf a1 = a; Pointf a2 = a; Pointf b1 = b; @@ -993,7 +994,7 @@ static void thick_lines_to_indexed_vertex_array( // calculate new XY normals Vector n = line.normal(); - Vectorf3 xy_right_normal = Vectorf3::new_unscale(n(0), n(1), 0); + Vec3d xy_right_normal = unscale(n(0), n(1), 0); xy_right_normal *= inv_len; int idx_a[4]; @@ -1196,15 +1197,15 @@ static void thick_lines_to_indexed_vertex_array(const Lines3& lines, int idx_initial[4] = { -1, -1, -1, -1 }; int idx_prev[4] = { -1, -1, -1, -1 }; double z_prev = 0.0; - Vectorf3 n_right_prev; - Vectorf3 n_top_prev; - Vectorf3 unit_v_prev; + Vec3d n_right_prev = Vec3d::Zero(); + Vec3d n_top_prev = Vec3d::Zero(); + Vec3d unit_v_prev = Vec3d::Zero(); double width_initial = 0.0; // new vertices around the line endpoints // left, right, top, bottom - Pointf3 a[4]; - Pointf3 b[4]; + Vec3d a[4] = { Vec3d::Zero(), Vec3d::Zero(), Vec3d::Zero(), Vec3d::Zero() }; + Vec3d b[4] = { Vec3d::Zero(), Vec3d::Zero(), Vec3d::Zero(), Vec3d::Zero() }; // loop once more in case of closed loops size_t lines_end = closed ? (lines.size() + 1) : lines.size(); @@ -1216,17 +1217,17 @@ static void thick_lines_to_indexed_vertex_array(const Lines3& lines, double height = heights[i]; double width = widths[i]; - Vectorf3 unit_v = Vectorf3::new_unscale(line.vector()).normalized(); + Vec3d unit_v = unscale(line.vector()).normalized(); - Vectorf3 n_top; - Vectorf3 n_right; - Vectorf3 unit_positive_z(0.0, 0.0, 1.0); + Vec3d n_top = Vec3d::Zero(); + Vec3d n_right = Vec3d::Zero(); + Vec3d unit_positive_z(0.0, 0.0, 1.0); if ((line.a(0) == line.b(0)) && (line.a(1) == line.b(1))) { // vertical segment - n_right = (line.a(2) < line.b(2)) ? Vectorf3(-1.0, 0.0, 0.0) : Vectorf3(1.0, 0.0, 0.0); - n_top = Vectorf3(0.0, 1.0, 0.0); + n_right = (line.a(2) < line.b(2)) ? Vec3d(-1.0, 0.0, 0.0) : Vec3d(1.0, 0.0, 0.0); + n_top = Vec3d(0.0, 1.0, 0.0); } else { @@ -1235,10 +1236,10 @@ static void thick_lines_to_indexed_vertex_array(const Lines3& lines, n_top = n_right.cross(unit_v).normalized(); } - Vectorf3 rl_displacement = 0.5 * width * n_right; - Vectorf3 tb_displacement = 0.5 * height * n_top; - Pointf3 l_a = Pointf3::new_unscale(line.a); - Pointf3 l_b = Pointf3::new_unscale(line.b); + Vec3d rl_displacement = 0.5 * width * n_right; + Vec3d tb_displacement = 0.5 * height * n_top; + Vec3d l_a = unscale(line.a); + Vec3d l_b = unscale(line.b); a[RIGHT] = l_a + rl_displacement; a[LEFT] = l_a - rl_displacement; @@ -1249,8 +1250,8 @@ static void thick_lines_to_indexed_vertex_array(const Lines3& lines, b[TOP] = l_b + tb_displacement; b[BOTTOM] = l_b - tb_displacement; - Vectorf3 n_bottom = -n_top; - Vectorf3 n_left = -n_right; + Vec3d n_bottom = -n_top; + Vec3d n_left = -n_right; int idx_a[4]; int idx_b[4]; @@ -1316,9 +1317,9 @@ static void thick_lines_to_indexed_vertex_array(const Lines3& lines, // At the crease angle of 45 degrees, the overshot at the corner will be less than (1-1/cos(PI/8)) = 8.2% over an arc. // averages normals - Vectorf3 average_n_right = 0.5 * (n_right + n_right_prev).normalized(); - Vectorf3 average_n_left = -average_n_right; - Vectorf3 average_rl_displacement = 0.5 * width * average_n_right; + Vec3d average_n_right = 0.5 * (n_right + n_right_prev).normalized(); + Vec3d average_n_left = -average_n_right; + Vec3d average_rl_displacement = 0.5 * width * average_n_right; // updates vertices around a a[RIGHT] = l_a + average_rl_displacement; @@ -1448,7 +1449,7 @@ static void point_to_indexed_vertex_array(const Point3& point, { // builds a double piramid, with vertices on the local axes, around the point - Pointf3 center = Pointf3::new_unscale(point); + Vec3d center = unscale(point); double scale_factor = 1.0; double w = scale_factor * width; @@ -1462,13 +1463,13 @@ static void point_to_indexed_vertex_array(const Point3& point, idxs[i] = idx_last + i; } - Vectorf3 displacement_x(w, 0.0, 0.0); - Vectorf3 displacement_y(0.0, w, 0.0); - Vectorf3 displacement_z(0.0, 0.0, h); + Vec3d displacement_x(w, 0.0, 0.0); + Vec3d displacement_y(0.0, w, 0.0); + Vec3d displacement_z(0.0, 0.0, h); - Vectorf3 unit_x(1.0, 0.0, 0.0); - Vectorf3 unit_y(0.0, 1.0, 0.0); - Vectorf3 unit_z(0.0, 0.0, 1.0); + Vec3d unit_x(1.0, 0.0, 0.0); + Vec3d unit_y(0.0, 1.0, 0.0); + Vec3d unit_z(0.0, 0.0, 1.0); // vertices volume.push_geometry(center - displacement_x, -unit_x); // idxs[0] diff --git a/xs/src/slic3r/GUI/3DScene.hpp b/xs/src/slic3r/GUI/3DScene.hpp index 41839a340..3fbfae169 100644 --- a/xs/src/slic3r/GUI/3DScene.hpp +++ b/xs/src/slic3r/GUI/3DScene.hpp @@ -119,7 +119,7 @@ public: push_geometry(float(x), float(y), float(z), float(nx), float(ny), float(nz)); } - inline void push_geometry(const Pointf3& p, const Vectorf3& n) { + inline void push_geometry(const Vec3d& p, const Vec3d& n) { push_geometry(p(0), p(1), p(2), n(0), n(1), n(2)); } @@ -255,7 +255,7 @@ public: private: // Offset of the volume to be rendered. - Pointf3 m_origin; + Vec3d m_origin; // Rotation around Z axis of the volume to be rendered. float m_angle_z; // Scale factor of the volume to be rendered. @@ -319,8 +319,8 @@ public: // Sets render color in dependence of current state void set_render_color(); - const Pointf3& get_origin() const; - void set_origin(const Pointf3& origin); + const Vec3d& get_origin() const; + void set_origin(const Vec3d& origin); void set_angle_z(float angle_z); void set_scale_factor(float scale_factor); diff --git a/xs/src/slic3r/GUI/BedShapeDialog.cpp b/xs/src/slic3r/GUI/BedShapeDialog.cpp index f021e1b96..b8a57a0c5 100644 --- a/xs/src/slic3r/GUI/BedShapeDialog.cpp +++ b/xs/src/slic3r/GUI/BedShapeDialog.cpp @@ -195,7 +195,7 @@ void BedShapePanel::set_shape(ConfigOptionPoints* points) // all vertices are equidistant to center m_shape_options_book->SetSelection(SHAPE_CIRCULAR); auto optgroup = m_optgroups[SHAPE_CIRCULAR]; - boost::any ret = wxNumberFormatter::ToString(unscale(avg_dist * 2), 0); + boost::any ret = wxNumberFormatter::ToString(unscale(avg_dist * 2), 0); optgroup->set_value("diameter", ret); update_shape(); return; @@ -332,7 +332,7 @@ void BedShapePanel::load_stl() auto polygon = expolygons[0].contour; std::vector points; for (auto pt : polygon.points) - points.push_back(Pointf::new_unscale(pt)); + points.push_back(unscale(pt)); m_canvas->m_bed_shape = points; update_preview(); } diff --git a/xs/src/slic3r/GUI/GLCanvas3D.cpp b/xs/src/slic3r/GUI/GLCanvas3D.cpp index d380c4bfc..a9ef69357 100644 --- a/xs/src/slic3r/GUI/GLCanvas3D.cpp +++ b/xs/src/slic3r/GUI/GLCanvas3D.cpp @@ -71,8 +71,8 @@ bool GeometryBuffer::set_from_triangles(const Polygons& triangles, float z, bool if (generate_tex_coords) m_tex_coords = std::vector(t_size, 0.0f); - float min_x = (float)unscale(triangles[0].points[0](0)); - float min_y = (float)unscale(triangles[0].points[0](1)); + float min_x = unscale(triangles[0].points[0](0)); + float min_y = unscale(triangles[0].points[0](1)); float max_x = min_x; float max_y = min_y; @@ -83,8 +83,8 @@ bool GeometryBuffer::set_from_triangles(const Polygons& triangles, float z, bool for (unsigned int v = 0; v < 3; ++v) { const Point& p = t.points[v]; - float x = (float)unscale(p(0)); - float y = (float)unscale(p(1)); + float x = unscale(p(0)); + float y = unscale(p(1)); m_vertices[v_coord++] = x; m_vertices[v_coord++] = y; @@ -137,11 +137,11 @@ bool GeometryBuffer::set_from_lines(const Lines& lines, float z) unsigned int coord = 0; for (const Line& l : lines) { - m_vertices[coord++] = (float)unscale(l.a(0)); - m_vertices[coord++] = (float)unscale(l.a(1)); + m_vertices[coord++] = unscale(l.a(0)); + m_vertices[coord++] = unscale(l.a(1)); m_vertices[coord++] = z; - m_vertices[coord++] = (float)unscale(l.b(0)); - m_vertices[coord++] = (float)unscale(l.b(1)); + m_vertices[coord++] = unscale(l.b(0)); + m_vertices[coord++] = unscale(l.b(1)); m_vertices[coord++] = z; } @@ -375,7 +375,7 @@ void GLCanvas3D::Bed::_calc_bounding_box() m_bounding_box = BoundingBoxf3(); for (const Pointf& p : m_shape) { - m_bounding_box.merge(Pointf3(p(0), p(1), 0.0)); + m_bounding_box.merge(Vec3d(p(0), p(1), 0.0)); } } @@ -591,7 +591,7 @@ bool GLCanvas3D::Bed::_are_equal(const Pointfs& bed_1, const Pointfs& bed_2) } GLCanvas3D::Axes::Axes() - : length(0.0f) + : origin(0, 0, 0), length(0.0f) { } @@ -1040,7 +1040,7 @@ void GLCanvas3D::LayersEditing::_render_profile(const PrintObject& print_object, // Make the vertical bar a bit wider so the layer height curve does not touch the edge of the bar region. layer_height_max *= 1.12; - coordf_t max_z = unscale(print_object.size(2)); + coordf_t max_z = unscale(print_object.size(2)); double layer_height = dynamic_cast(print_object.config.option("layer_height"))->value; float l = bar_rect.get_left(); float w = bar_rect.get_right() - l; @@ -1075,11 +1075,12 @@ void GLCanvas3D::LayersEditing::_render_profile(const PrintObject& print_object, } const Point GLCanvas3D::Mouse::Drag::Invalid_2D_Point(INT_MAX, INT_MAX); -const Pointf3 GLCanvas3D::Mouse::Drag::Invalid_3D_Point(DBL_MAX, DBL_MAX, DBL_MAX); +const Vec3d GLCanvas3D::Mouse::Drag::Invalid_3D_Point(DBL_MAX, DBL_MAX, DBL_MAX); GLCanvas3D::Mouse::Drag::Drag() : start_position_2D(Invalid_2D_Point) , start_position_3D(Invalid_3D_Point) + , volume_center_offset(0, 0, 0) , move_with_shift(false) , move_volume_idx(-1) , gizmo_volume_idx(-1) @@ -1950,7 +1951,7 @@ void GLCanvas3D::set_bed_shape(const Pointfs& shape) bool new_shape = m_bed.set_shape(shape); // Set the origin and size for painting of the coordinate system axes. - m_axes.origin = Pointf3(0.0, 0.0, (coordf_t)GROUND_Z); + m_axes.origin = Vec3d(0.0, 0.0, (coordf_t)GROUND_Z); set_axes_length(0.3f * (float)m_bed.get_bounding_box().max_size()); if (new_shape) @@ -1970,7 +1971,7 @@ void GLCanvas3D::set_auto_bed_shape() // draw a default square bed around object center const BoundingBoxf3& bbox = volumes_bounding_box(); coordf_t max_size = bbox.max_size(); - const Pointf3 center = bbox.center(); + const Vec3d center = bbox.center(); Pointfs bed_shape; bed_shape.reserve(4); @@ -1982,7 +1983,7 @@ void GLCanvas3D::set_auto_bed_shape() set_bed_shape(bed_shape); // Set the origin for painting of the coordinate system axes. - m_axes.origin = Pointf3(center(0), center(1), (coordf_t)GROUND_Z); + m_axes.origin = Vec3d(center(0), center(1), (coordf_t)GROUND_Z); } void GLCanvas3D::set_axes_length(float length) @@ -2799,7 +2800,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) { // The mouse_to_3d gets the Z coordinate from the Z buffer at the screen coordinate pos x, y, // an converts the screen space coordinate to unscaled object space. - Pointf3 pos3d = (volume_idx == -1) ? Pointf3(DBL_MAX, DBL_MAX, DBL_MAX) : _mouse_to_3d(pos); + Vec3d pos3d = (volume_idx == -1) ? Vec3d(DBL_MAX, DBL_MAX, DBL_MAX) : _mouse_to_3d(pos); // Only accept the initial position, if it is inside the volume bounding box. BoundingBoxf3 volume_bbox = m_volumes.volumes[volume_idx]->transformed_bounding_box(); @@ -2831,7 +2832,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) // Get new position at the same Z of the initial click point. float z0 = 0.0f; float z1 = 1.0f; - Pointf3 cur_pos = Linef3(_mouse_to_3d(pos, &z0), _mouse_to_3d(pos, &z1)).intersect_plane(m_mouse.drag.start_position_3D(2)); + Vec3d cur_pos = Linef3(_mouse_to_3d(pos, &z0), _mouse_to_3d(pos, &z1)).intersect_plane(m_mouse.drag.start_position_3D(2)); // Clip the new position, so the object center remains close to the bed. cur_pos += m_mouse.drag.volume_center_offset; @@ -2839,13 +2840,13 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) if (!m_bed.contains(cur_pos2)) { Point ip = m_bed.point_projection(cur_pos2); - cur_pos(0) = unscale(ip(0)); - cur_pos(1) = unscale(ip(1)); + cur_pos(0) = unscale(ip(0)); + cur_pos(1) = unscale(ip(1)); } cur_pos -= m_mouse.drag.volume_center_offset; // Calculate the translation vector. - Vectorf3 vector = cur_pos - m_mouse.drag.start_position_3D; + Vec3d vector = cur_pos - m_mouse.drag.start_position_3D; // Get the volume being dragged. GLVolume* volume = m_volumes.volumes[m_mouse.drag.move_volume_idx]; // Get all volumes belonging to the same group, if any. @@ -2867,7 +2868,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) // Apply new temporary volume origin and ignore Z. for (GLVolume* v : volumes) - v->set_origin(v->get_origin() + Vectorf3(vector(0), vector(1), 0.0)); + v->set_origin(v->get_origin() + Vec3d(vector(0), vector(1), 0.0)); m_mouse.drag.start_position_3D = cur_pos; m_gizmos.refresh(); @@ -2878,7 +2879,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) { m_mouse.dragging = true; - const Pointf3& cur_pos = _mouse_to_bed_3d(pos); + const Vec3d& cur_pos = _mouse_to_bed_3d(pos); m_gizmos.update(Pointf(cur_pos(0), cur_pos(1))); std::vector volumes; @@ -2931,7 +2932,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) { bb.merge(volume->transformed_bounding_box()); } - const Pointf3& size = bb.size(); + const Vec3d& size = bb.size(); m_on_update_geometry_info_callback.call(size(0), size(1), size(2), m_gizmos.get_scale()); } @@ -2954,7 +2955,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) // if dragging over blank area with left button, rotate if (m_mouse.is_start_position_3D_defined()) { - const Pointf3& orig = m_mouse.drag.start_position_3D; + const Vec3d& orig = m_mouse.drag.start_position_3D; m_camera.phi += (((float)pos(0) - (float)orig(0)) * TRACKBALLSIZE); m_camera.set_theta(m_camera.get_theta() - ((float)pos(1) - (float)orig(1)) * TRACKBALLSIZE); @@ -2962,7 +2963,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) m_dirty = true; } - m_mouse.drag.start_position_3D = Pointf3((coordf_t)pos(0), (coordf_t)pos(1), 0.0); + m_mouse.drag.start_position_3D = Vec3d((coordf_t)pos(0), (coordf_t)pos(1), 0.0); } else if (evt.MiddleIsDown() || evt.RightIsDown()) { @@ -2971,8 +2972,8 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) { // get point in model space at Z = 0 float z = 0.0f; - const Pointf3& cur_pos = _mouse_to_3d(pos, &z); - Pointf3 orig = _mouse_to_3d(m_mouse.drag.start_position_2D, &z); + const Vec3d& cur_pos = _mouse_to_3d(pos, &z); + Vec3d orig = _mouse_to_3d(m_mouse.drag.start_position_2D, &z); m_camera.target += orig - cur_pos; m_on_viewport_changed_callback.call(); @@ -3277,16 +3278,16 @@ float GLCanvas3D::_get_zoom_to_bounding_box_factor(const BoundingBoxf3& bbox) co ::glGetFloatv(GL_MODELVIEW_MATRIX, matrix); // camera axes - Pointf3 right((coordf_t)matrix[0], (coordf_t)matrix[4], (coordf_t)matrix[8]); - Pointf3 up((coordf_t)matrix[1], (coordf_t)matrix[5], (coordf_t)matrix[9]); - Pointf3 forward((coordf_t)matrix[2], (coordf_t)matrix[6], (coordf_t)matrix[10]); + Vec3d right((coordf_t)matrix[0], (coordf_t)matrix[4], (coordf_t)matrix[8]); + Vec3d up((coordf_t)matrix[1], (coordf_t)matrix[5], (coordf_t)matrix[9]); + Vec3d forward((coordf_t)matrix[2], (coordf_t)matrix[6], (coordf_t)matrix[10]); - Pointf3 bb_min = bbox.min; - Pointf3 bb_max = bbox.max; - Pointf3 bb_center = bbox.center(); + Vec3d bb_min = bbox.min; + Vec3d bb_max = bbox.max; + Vec3d bb_center = bbox.center(); // bbox vertices in world space - std::vector vertices; + std::vector vertices; vertices.reserve(8); vertices.push_back(bb_min); vertices.emplace_back(bb_max(0), bb_min(1), bb_min(2)); @@ -3303,11 +3304,11 @@ float GLCanvas3D::_get_zoom_to_bounding_box_factor(const BoundingBoxf3& bbox) co // margin factor to give some empty space around the bbox coordf_t margin_factor = 1.25; - for (const Pointf3 v : vertices) + for (const Vec3d v : vertices) { // project vertex on the plane perpendicular to camera forward axis - Pointf3 pos(v(0) - bb_center(0), v(1) - bb_center(1), v(2) - bb_center(2)); - Pointf3 proj_on_plane = pos - pos.dot(forward) * forward; + Vec3d pos(v(0) - bb_center(0), v(1) - bb_center(1), v(2) - bb_center(2)); + Vec3d proj_on_plane = pos - pos.dot(forward) * forward; // calculates vertex coordinate along camera xy axes coordf_t x_on_plane = proj_on_plane.dot(right); @@ -3389,7 +3390,7 @@ void GLCanvas3D::_camera_tranform() const ::glRotatef(-m_camera.get_theta(), 1.0f, 0.0f, 0.0f); // pitch ::glRotatef(m_camera.phi, 0.0f, 0.0f, 1.0f); // yaw - Pointf3 neg_target = - m_camera.target; + Vec3d neg_target = - m_camera.target; ::glTranslatef((GLfloat)neg_target(0), (GLfloat)neg_target(1), (GLfloat)neg_target(2)); } @@ -3730,7 +3731,7 @@ void GLCanvas3D::_perform_layer_editing_action(wxMouseEvent* evt) { const Rect& rect = LayersEditing::get_bar_rect_screen(*this); float b = rect.get_bottom(); - m_layers_editing.last_z = unscale(selected_obj->size(2)) * (b - evt->GetY() - 1.0f) / (b - rect.get_top()); + m_layers_editing.last_z = unscale(selected_obj->size(2)) * (b - evt->GetY() - 1.0f) / (b - rect.get_top()); m_layers_editing.last_action = evt->ShiftDown() ? (evt->RightIsDown() ? 3 : 2) : (evt->RightIsDown() ? 0 : 1); } @@ -3760,10 +3761,10 @@ void GLCanvas3D::_perform_layer_editing_action(wxMouseEvent* evt) _start_timer(); } -Pointf3 GLCanvas3D::_mouse_to_3d(const Point& mouse_pos, float* z) +Vec3d GLCanvas3D::_mouse_to_3d(const Point& mouse_pos, float* z) { if (m_canvas == nullptr) - return Pointf3(DBL_MAX, DBL_MAX, DBL_MAX); + return Vec3d(DBL_MAX, DBL_MAX, DBL_MAX); _camera_tranform(); @@ -3783,10 +3784,10 @@ Pointf3 GLCanvas3D::_mouse_to_3d(const Point& mouse_pos, float* z) GLdouble out_x, out_y, out_z; ::gluUnProject((GLdouble)mouse_pos(0), (GLdouble)y, (GLdouble)mouse_z, modelview_matrix, projection_matrix, viewport, &out_x, &out_y, &out_z); - return Pointf3((coordf_t)out_x, (coordf_t)out_y, (coordf_t)out_z); + return Vec3d((coordf_t)out_x, (coordf_t)out_y, (coordf_t)out_z); } -Pointf3 GLCanvas3D::_mouse_to_bed_3d(const Point& mouse_pos) +Vec3d GLCanvas3D::_mouse_to_bed_3d(const Point& mouse_pos) { float z0 = 0.0f; float z1 = 1.0f; @@ -4501,7 +4502,7 @@ bool GLCanvas3D::_travel_paths_by_type(const GCodePreviewData& preview_data) TypesList::iterator type = std::find(types.begin(), types.end(), Type(polyline.type)); if (type != types.end()) { - type->volume->print_zs.push_back(unscale(polyline.polyline.bounding_box().min(2))); + type->volume->print_zs.push_back(unscale(polyline.polyline.bounding_box().min(2))); type->volume->offsets.push_back(type->volume->indexed_vertex_array.quad_indices.size()); type->volume->offsets.push_back(type->volume->indexed_vertex_array.triangle_indices.size()); @@ -4567,7 +4568,7 @@ bool GLCanvas3D::_travel_paths_by_feedrate(const GCodePreviewData& preview_data) FeedratesList::iterator feedrate = std::find(feedrates.begin(), feedrates.end(), Feedrate(polyline.feedrate)); if (feedrate != feedrates.end()) { - feedrate->volume->print_zs.push_back(unscale(polyline.polyline.bounding_box().min(2))); + feedrate->volume->print_zs.push_back(unscale(polyline.polyline.bounding_box().min(2))); feedrate->volume->offsets.push_back(feedrate->volume->indexed_vertex_array.quad_indices.size()); feedrate->volume->offsets.push_back(feedrate->volume->indexed_vertex_array.triangle_indices.size()); @@ -4633,7 +4634,7 @@ bool GLCanvas3D::_travel_paths_by_tool(const GCodePreviewData& preview_data, con ToolsList::iterator tool = std::find(tools.begin(), tools.end(), Tool(polyline.extruder_id)); if (tool != tools.end()) { - tool->volume->print_zs.push_back(unscale(polyline.polyline.bounding_box().min(2))); + tool->volume->print_zs.push_back(unscale(polyline.polyline.bounding_box().min(2))); tool->volume->offsets.push_back(tool->volume->indexed_vertex_array.quad_indices.size()); tool->volume->offsets.push_back(tool->volume->indexed_vertex_array.triangle_indices.size()); @@ -4662,7 +4663,7 @@ void GLCanvas3D::_load_gcode_retractions(const GCodePreviewData& preview_data) for (const GCodePreviewData::Retraction::Position& position : copy) { - volume->print_zs.push_back(unscale(position.position(2))); + volume->print_zs.push_back(unscale(position.position(2))); volume->offsets.push_back(volume->indexed_vertex_array.quad_indices.size()); volume->offsets.push_back(volume->indexed_vertex_array.triangle_indices.size()); @@ -4693,7 +4694,7 @@ void GLCanvas3D::_load_gcode_unretractions(const GCodePreviewData& preview_data) for (const GCodePreviewData::Retraction::Position& position : copy) { - volume->print_zs.push_back(unscale(position.position(2))); + volume->print_zs.push_back(unscale(position.position(2))); volume->offsets.push_back(volume->indexed_vertex_array.quad_indices.size()); volume->offsets.push_back(volume->indexed_vertex_array.triangle_indices.size()); @@ -4816,7 +4817,7 @@ void GLCanvas3D::_update_toolpath_volumes_outside_state() if (opt != nullptr) { BoundingBox bed_box_2D = get_extents(Polygon::new_scale(opt->values)); - print_volume = BoundingBoxf3(Pointf3(unscale(bed_box_2D.min(0)) - tolerance_x, unscale(bed_box_2D.min(1)) - tolerance_y, 0.0), Pointf3(unscale(bed_box_2D.max(0)) + tolerance_x, unscale(bed_box_2D.max(1)) + tolerance_y, m_config->opt_float("max_print_height"))); + print_volume = BoundingBoxf3(Vec3d(unscale(bed_box_2D.min(0)) - tolerance_x, unscale(bed_box_2D.min(1)) - tolerance_y, 0.0), Vec3d(unscale(bed_box_2D.max(0)) + tolerance_x, unscale(bed_box_2D.max(1)) + tolerance_y, m_config->opt_float("max_print_height"))); // Allow the objects to protrude below the print bed print_volume.min(2) = -1e10; } @@ -4849,7 +4850,7 @@ void GLCanvas3D::_on_move(const std::vector& volume_idxs) std::set done; // prevent moving instances twice bool object_moved = false; - Pointf3 wipe_tower_origin(0.0, 0.0, 0.0); + Vec3d wipe_tower_origin(0.0, 0.0, 0.0); for (int volume_idx : volume_idxs) { GLVolume* volume = m_volumes.volumes[volume_idx]; @@ -4868,7 +4869,7 @@ void GLCanvas3D::_on_move(const std::vector& volume_idxs) { // Move a regular object. ModelObject* model_object = m_model->objects[obj_idx]; - const Pointf3& origin = volume->get_origin(); + const Vec3d& origin = volume->get_origin(); model_object->instances[instance_idx]->offset = Pointf(origin(0), origin(1)); model_object->invalidate_bounding_box(); object_moved = true; @@ -4881,7 +4882,7 @@ void GLCanvas3D::_on_move(const std::vector& volume_idxs) if (object_moved) m_on_instance_moved_callback.call(); - if (wipe_tower_origin != Pointf3(0.0, 0.0, 0.0)) + if (wipe_tower_origin != Vec3d(0.0, 0.0, 0.0)) m_on_wipe_tower_moved_callback.call(wipe_tower_origin(0), wipe_tower_origin(1)); } diff --git a/xs/src/slic3r/GUI/GLCanvas3D.hpp b/xs/src/slic3r/GUI/GLCanvas3D.hpp index ae20882fc..3d35495b4 100644 --- a/xs/src/slic3r/GUI/GLCanvas3D.hpp +++ b/xs/src/slic3r/GUI/GLCanvas3D.hpp @@ -120,7 +120,7 @@ public: float zoom; float phi; // float distance; - Pointf3 target; + Vec3d target; private: float m_theta; @@ -185,7 +185,7 @@ public: struct Axes { - Pointf3 origin; + Vec3d origin; float length; Axes(); @@ -299,11 +299,11 @@ public: struct Drag { static const Point Invalid_2D_Point; - static const Pointf3 Invalid_3D_Point; + static const Vec3d Invalid_3D_Point; Point start_position_2D; - Pointf3 start_position_3D; - Vectorf3 volume_center_offset; + Vec3d start_position_3D; + Vec3d volume_center_offset; bool move_with_shift; int move_volume_idx; @@ -636,10 +636,10 @@ private: // Convert the screen space coordinate to an object space coordinate. // If the Z screen space coordinate is not provided, a depth buffer value is substituted. - Pointf3 _mouse_to_3d(const Point& mouse_pos, float* z = nullptr); + Vec3d _mouse_to_3d(const Point& mouse_pos, float* z = nullptr); // Convert the screen space coordinate to world coordinate on the bed. - Pointf3 _mouse_to_bed_3d(const Point& mouse_pos); + Vec3d _mouse_to_bed_3d(const Point& mouse_pos); void _start_timer(); void _stop_timer(); diff --git a/xs/src/slic3r/GUI/GLGizmo.cpp b/xs/src/slic3r/GUI/GLGizmo.cpp index f4f947d9c..eaf24c8bc 100644 --- a/xs/src/slic3r/GUI/GLGizmo.cpp +++ b/xs/src/slic3r/GUI/GLGizmo.cpp @@ -262,11 +262,10 @@ void GLGizmoRotate::on_render(const BoundingBoxf3& box) const { ::glDisable(GL_DEPTH_TEST); - const Pointf size = box.size().xy(); - m_center = box.center().xy(); + m_center = to_2d(box.center()); if (!m_keep_radius) { - m_radius = Offset + ::sqrt(sqr(0.5f * size(0)) + sqr(0.5f * size(1))); + m_radius = Offset + 0.5 * to_2d(box.size()).norm(); m_keep_radius = true; } diff --git a/xs/src/slic3r/GUI/GLGizmo.hpp b/xs/src/slic3r/GUI/GLGizmo.hpp index 506b3972e..d6223a14d 100644 --- a/xs/src/slic3r/GUI/GLGizmo.hpp +++ b/xs/src/slic3r/GUI/GLGizmo.hpp @@ -9,7 +9,6 @@ namespace Slic3r { class BoundingBoxf3; -class Pointf3; namespace GUI { diff --git a/xs/xsp/BoundingBox.xsp b/xs/xsp/BoundingBox.xsp index d65f8a523..46a6da98c 100644 --- a/xs/xsp/BoundingBox.xsp +++ b/xs/xsp/BoundingBox.xsp @@ -96,17 +96,17 @@ new_from_points(CLASS, points) Clone clone() %code{% RETVAL = THIS; %}; void merge(BoundingBoxf3* bb) %code{% THIS->merge(*bb); %}; - void merge_point(Pointf3* point) %code{% THIS->merge(*point); %}; + void merge_point(Vec3d* point) %code{% THIS->merge(*point); %}; void scale(double factor); void translate(double x, double y, double z); void offset(double delta); - bool contains_point(Pointf3* point) %code{% RETVAL = THIS->contains(*point); %}; - Clone size(); - Clone center(); + bool contains_point(Vec3d* point) %code{% RETVAL = THIS->contains(*point); %}; + Clone size(); + Clone center(); double radius(); bool empty() %code{% RETVAL = empty(*THIS); %}; - Clone min_point() %code{% RETVAL = THIS->min; %}; - Clone max_point() %code{% RETVAL = THIS->max; %}; + Clone min_point() %code{% RETVAL = THIS->min; %}; + Clone max_point() %code{% RETVAL = THIS->max; %}; double x_min() %code{% RETVAL = THIS->min(0); %}; double x_max() %code{% RETVAL = THIS->max(0); %}; double y_min() %code{% RETVAL = THIS->min(1); %}; diff --git a/xs/xsp/GUI_3DScene.xsp b/xs/xsp/GUI_3DScene.xsp index 6349a7c76..d71e4011c 100644 --- a/xs/xsp/GUI_3DScene.xsp +++ b/xs/xsp/GUI_3DScene.xsp @@ -55,10 +55,10 @@ int object_idx() const; int volume_idx() const; int instance_idx() const; - Clone origin() const + Clone origin() const %code%{ RETVAL = THIS->get_origin(); %}; void translate(double x, double y, double z) - %code%{ THIS->set_origin(THIS->get_origin() + Pointf3(x, y, z)); %}; + %code%{ THIS->set_origin(THIS->get_origin() + Vec3d(x, y, z)); %}; Clone bounding_box() const %code%{ RETVAL = THIS->bounding_box; %}; Clone transformed_bounding_box() const; diff --git a/xs/xsp/Line.xsp b/xs/xsp/Line.xsp index f7437de01..777dc41fa 100644 --- a/xs/xsp/Line.xsp +++ b/xs/xsp/Line.xsp @@ -78,15 +78,15 @@ Line::coincides_with(line_sv) %name{Slic3r::Linef3} class Linef3 { - Linef3(Pointf3* a, Pointf3* b) + Linef3(Vec3d* a, Vec3d* b) %code{% RETVAL = new Linef3(*a, *b); %}; ~Linef3(); Clone clone() %code{% RETVAL = THIS; %}; - Ref a() + Ref a() %code{% RETVAL = &THIS->a; %}; - Ref b() + Ref b() %code{% RETVAL = &THIS->b; %}; - Clone intersect_plane(double z); + Clone intersect_plane(double z); void scale(double factor); }; diff --git a/xs/xsp/Model.xsp b/xs/xsp/Model.xsp index 25c26c380..d8e509527 100644 --- a/xs/xsp/Model.xsp +++ b/xs/xsp/Model.xsp @@ -289,9 +289,9 @@ ModelMaterial::attributes() void set_layer_height_profile(std::vector profile) %code%{ THIS->layer_height_profile = profile; THIS->layer_height_profile_valid = true; %}; - Ref origin_translation() + Ref origin_translation() %code%{ RETVAL = &THIS->origin_translation; %}; - void set_origin_translation(Pointf3* point) + void set_origin_translation(Vec3d* point) %code%{ THIS->origin_translation = *point; %}; bool needed_repair() const; @@ -299,7 +299,7 @@ ModelMaterial::attributes() int facets_count(); void center_around_origin(); void translate(double x, double y, double z); - void scale_xyz(Pointf3* versor) + void scale_xyz(Vec3d* versor) %code{% THIS->scale(*versor); %}; void rotate(float angle, Axis axis); void mirror(Axis axis); diff --git a/xs/xsp/Point.xsp b/xs/xsp/Point.xsp index 2a98f9c39..dc4f592cd 100644 --- a/xs/xsp/Point.xsp +++ b/xs/xsp/Point.xsp @@ -121,10 +121,10 @@ Point::coincides_with(point_sv) std::string serialize() %code{% char buf[2048]; sprintf(buf, "%lf,%lf", (*THIS)(0), (*THIS)(1)); RETVAL = buf; %}; }; -%name{Slic3r::Pointf3} class Pointf3 { - Pointf3(double _x = 0, double _y = 0, double _z = 0); - ~Pointf3(); - Clone clone() +%name{Slic3r::Pointf3} class Vec3d { + Vec3d(double _x = 0, double _y = 0, double _z = 0); + ~Vec3d(); + Clone clone() %code{% RETVAL = THIS; %}; double x() %code{% RETVAL = (*THIS)(0); %}; @@ -139,14 +139,14 @@ Point::coincides_with(point_sv) void set_z(double val) %code{% (*THIS)(2) = val; %}; void translate(double x, double y, double z) - %code{% *THIS += Pointf3(x, y, z); %}; + %code{% *THIS += Vec3d(x, y, z); %}; void scale(double factor) %code{% *THIS *= factor; %}; - double distance_to(Pointf3* point) + double distance_to(Vec3d* point) %code{% RETVAL = (*point - *THIS).norm(); %}; - Pointf3* negative() - %code{% RETVAL = new Pointf3(- *THIS); %}; - Pointf3* vector_to(Pointf3* point) - %code{% RETVAL = new Pointf3(*point - *THIS); %}; + Vec3d* negative() + %code{% RETVAL = new Vec3d(- *THIS); %}; + Vec3d* vector_to(Vec3d* point) + %code{% RETVAL = new Vec3d(*point - *THIS); %}; std::string serialize() %code{% char buf[2048]; sprintf(buf, "%lf,%lf,%lf", (*THIS)(0), (*THIS)(1), (*THIS)(2)); RETVAL = buf; %}; }; diff --git a/xs/xsp/TriangleMesh.xsp b/xs/xsp/TriangleMesh.xsp index 1691066a5..4a269bd84 100644 --- a/xs/xsp/TriangleMesh.xsp +++ b/xs/xsp/TriangleMesh.xsp @@ -16,7 +16,7 @@ void repair(); void WriteOBJFile(char* output_file); void scale(float factor); - void scale_xyz(Pointf3* versor) + void scale_xyz(Vec3d* versor) %code{% THIS->scale(*versor); %}; void translate(float x, float y, float z); void rotate_x(float angle); @@ -33,7 +33,7 @@ ExPolygons horizontal_projection(); Clone convex_hull(); Clone bounding_box(); - Clone center() + Clone center() %code{% RETVAL = THIS->bounding_box().center(); %}; int facets_count(); void reset_repair_stats(); diff --git a/xs/xsp/my.map b/xs/xsp/my.map index 4a14f483f..4c3cc3522 100644 --- a/xs/xsp/my.map +++ b/xs/xsp/my.map @@ -70,9 +70,9 @@ Pointf* O_OBJECT_SLIC3R Ref O_OBJECT_SLIC3R_T Clone O_OBJECT_SLIC3R_T -Pointf3* O_OBJECT_SLIC3R -Ref O_OBJECT_SLIC3R_T -Clone O_OBJECT_SLIC3R_T +Vec3d* O_OBJECT_SLIC3R +Ref O_OBJECT_SLIC3R_T +Clone O_OBJECT_SLIC3R_T Line* O_OBJECT_SLIC3R Ref O_OBJECT_SLIC3R_T diff --git a/xs/xsp/typemap.xspt b/xs/xsp/typemap.xspt index b576b1373..714148794 100644 --- a/xs/xsp/typemap.xspt +++ b/xs/xsp/typemap.xspt @@ -25,9 +25,9 @@ %typemap{Pointf*}; %typemap{Ref}{simple}; %typemap{Clone}{simple}; -%typemap{Pointf3*}; -%typemap{Ref}{simple}; -%typemap{Clone}{simple}; +%typemap{Vec3d*}; +%typemap{Ref}{simple}; +%typemap{Clone}{simple}; %typemap{BoundingBox*}; %typemap{Ref}{simple}; %typemap{Clone}{simple}; -- cgit v1.2.3