Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
Slic3r::TriangleMesh Class Reference

#include <src/libslic3r/TriangleMesh.hpp>

+ Collaboration diagram for Slic3r::TriangleMesh:

Public Member Functions

 TriangleMesh ()=default
 
 TriangleMesh (const std::vector< Vec3f > &vertices, const std::vector< Vec3i > &faces)
 
 TriangleMesh (std::vector< Vec3f > &&vertices, const std::vector< Vec3i > &&faces)
 
 TriangleMesh (const indexed_triangle_set &M)
 
 TriangleMesh (indexed_triangle_set &&M, const RepairedMeshErrors &repaired_errors=RepairedMeshErrors())
 
void clear ()
 
bool ReadSTLFile (const char *input_file, bool repair=true)
 
bool write_ascii (const char *output_file)
 
bool write_binary (const char *output_file)
 
float volume ()
 
void WriteOBJFile (const char *output_file) const
 
void scale (float factor)
 
void scale (const Vec3f &versor)
 
void translate (float x, float y, float z)
 
void translate (const Vec3f &displacement)
 
void rotate (float angle, const Axis &axis)
 
void rotate (float angle, const Vec3d &axis)
 
void rotate_x (float angle)
 
void rotate_y (float angle)
 
void rotate_z (float angle)
 
void mirror (const Axis axis)
 
void mirror_x ()
 
void mirror_y ()
 
void mirror_z ()
 
void transform (const Transform3d &t, bool fix_left_handed=false)
 
void transform (const Matrix3d &t, bool fix_left_handed=false)
 
void flip_triangles ()
 
void align_to_origin ()
 
void rotate (double angle, Point *center)
 
std::vector< TriangleMeshsplit () const
 
void merge (const TriangleMesh &mesh)
 
ExPolygons horizontal_projection () const
 
Polygon convex_hull ()
 
BoundingBoxf3 bounding_box () const
 
BoundingBoxf3 transformed_bounding_box (const Transform3d &trafo) const
 
BoundingBoxf3 transformed_bounding_box (const Transform3d &trafo, double world_min_z) const
 
Vec3d size () const
 
Vec3d center () const
 Return the center of the related bounding box.
 
TriangleMesh convex_hull_3d () const
 
std::vector< ExPolygonsslice (const std::vector< double > &z) const
 
size_t facets_count () const
 
bool empty () const
 
bool repaired () const
 
bool is_splittable () const
 
bool has_zero_volume () const
 
size_t memsize () const
 
size_t release_optional ()
 
void restore_optional ()
 
const TriangleMeshStatsstats () const
 

Public Attributes

indexed_triangle_set its
 

Private Attributes

TriangleMeshStats m_stats
 

Detailed Description

Constructor & Destructor Documentation

◆ TriangleMesh() [1/5]

Slic3r::TriangleMesh::TriangleMesh ( )
default

◆ TriangleMesh() [2/5]

Slic3r::TriangleMesh::TriangleMesh ( const std::vector< Vec3f > &  vertices,
const std::vector< Vec3i > &  faces 
)
57 : its { faces, vertices }
58{
60}
TriangleMeshStats m_stats
Definition TriangleMesh.hpp:158
indexed_triangle_set its
Definition TriangleMesh.hpp:155
static void fill_initial_stats(const indexed_triangle_set &its, TriangleMeshStats &out)
Definition TriangleMesh.cpp:46

References Slic3r::fill_initial_stats(), its, and m_stats.

+ Here is the call graph for this function:

◆ TriangleMesh() [3/5]

Slic3r::TriangleMesh::TriangleMesh ( std::vector< Vec3f > &&  vertices,
const std::vector< Vec3i > &&  faces 
)
62 : its { std::move(faces), std::move(vertices) }
63{
65}

References Slic3r::fill_initial_stats(), its, and m_stats.

+ Here is the call graph for this function:

◆ TriangleMesh() [4/5]

Slic3r::TriangleMesh::TriangleMesh ( const indexed_triangle_set M)
explicit
67 : its(its)
68{
70}

References Slic3r::fill_initial_stats(), and m_stats.

+ Here is the call graph for this function:

◆ TriangleMesh() [5/5]

Slic3r::TriangleMesh::TriangleMesh ( indexed_triangle_set &&  M,
const RepairedMeshErrors repaired_errors = RepairedMeshErrors() 
)
explicit
72 : its(std::move(its))
73{
74 m_stats.repaired_errors = errors;
76}
RepairedMeshErrors repaired_errors
Definition TriangleMesh.hpp:60

References Slic3r::fill_initial_stats(), its, m_stats, and Slic3r::TriangleMeshStats::repaired_errors.

+ Here is the call graph for this function:

Member Function Documentation

◆ align_to_origin()

void Slic3r::TriangleMesh::align_to_origin ( )
361{
362 this->translate(- m_stats.min(0), - m_stats.min(1), - m_stats.min(2));
363}
void translate(float x, float y, float z)
Definition TriangleMesh.cpp:274
stl_vertex min
Definition TriangleMesh.hpp:51

References m_stats, Slic3r::TriangleMeshStats::min, and translate().

+ Here is the call graph for this function:

◆ bounding_box()

◆ center()

Vec3d Slic3r::TriangleMesh::center ( ) const
inline

Return the center of the related bounding box.

133{ return this->bounding_box().center(); }
PointType center() const
Definition BoundingBox.cpp:203
BoundingBoxf3 bounding_box() const
Definition TriangleMesh.cpp:432

References bounding_box(), and Slic3r::BoundingBox3Base< PointType >::center().

Referenced by Slic3r::GUI::Emboss::CreateObjectJob::process(), and rotate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clear()

void Slic3r::TriangleMesh::clear ( )
inline
95{ this->its.clear(); m_stats.clear(); }
void clear()
Definition TriangleMesh.hpp:62
void clear()
Definition stl.h:158

References indexed_triangle_set::clear(), Slic3r::TriangleMeshStats::clear(), its, and m_stats.

Referenced by Slic3r::GUI::GLGizmoCut3D::update_connector_shape().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ convex_hull()

Polygon Slic3r::TriangleMesh::convex_hull ( )
422{
423 Points pp;
424 pp.reserve(this->its.vertices.size());
425 for (size_t i = 0; i < this->its.vertices.size(); ++ i) {
426 const stl_vertex &v = this->its.vertices[i];
427 pp.emplace_back(Point::new_scale(v(0), v(1)));
428 }
430}
Polygon convex_hull(Points pts)
Definition ConvexHull.cpp:11
std::vector< Point, PointsAllocator< Point > > Points
Definition Point.hpp:58
std::vector< stl_vertex > vertices
Definition stl.h:165

References Slic3r::Geometry::convex_hull(), its, and indexed_triangle_set::vertices.

Referenced by Slic3r::sla::anonymous_namespace{Rotfinder.cpp}::get_chull_rotations(), and Slic3r::GUI::Selection::scale_to_fit_print_volume().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ convex_hull_3d()

TriangleMesh Slic3r::TriangleMesh::convex_hull_3d ( ) const
501{
502 TriangleMesh mesh(its_convex_hull(this->its));
503 // Quite often qhull produces non-manifold mesh.
504 // assert(mesh.stats().manifold());
505 return mesh;
506}
indexed_triangle_set its_convex_hull(const std::vector< Vec3f > &pts)
Definition TriangleMesh.cpp:1265

References its, and Slic3r::its_convex_hull().

Referenced by Slic3r::sla::find_min_z_height_rotation(), Slic3r::sla::anonymous_namespace{Rotfinder.cpp}::get_chull_rotations(), Slic3r::GLVolumeCollection::load_object_auxiliary(), Slic3r::GLVolumeCollection::load_wipe_tower_preview(), and Slic3r::GUI::GLGizmoFlatten::update_planes().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ empty()

bool Slic3r::TriangleMesh::empty ( ) const
inline
139{ return this->facets_count() == 0; }
size_t facets_count() const
Definition TriangleMesh.hpp:138

References facets_count().

Referenced by Slic3r::GUI::Emboss::create_sources(), Slic3r::GUI::Plater::export_stl_obj(), Slic3r::GUI::Emboss::CreateObjectJob::finalize(), Slic3r::sla::hollow_mesh(), Slic3r::load_obj(), Slic3r::GLVolumeCollection::load_object_auxiliary(), Slic3r::load_stl(), Slic3r::GUI::CommonGizmosDataObjects::Raycaster::on_update(), Slic3r::GUI::CommonGizmosDataObjects::SupportsClipper::on_update(), Slic3r::GUI::GLGizmoCut3D::perform_cut(), Slic3r::ModelObject::process_solid_part_cut(), Slic3r::ModelVolume::split(), Slic3r::SLAPrint::Steps::support_tree(), and Slic3r::GUI::GLGizmoSlaBase::update_volumes().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ facets_count()

size_t Slic3r::TriangleMesh::facets_count ( ) const
inline
138{ assert(m_stats.number_of_facets == this->its.indices.size()); return m_stats.number_of_facets; }
uint32_t number_of_facets
Definition TriangleMesh.hpp:49

References m_stats, and Slic3r::TriangleMeshStats::number_of_facets.

Referenced by empty(), Slic3r::SlicingAdaptive::prepare(), Slic3r::ModelObject::print_info(), Slic3r::ModelObject::split(), and Slic3r::GUI::GLGizmoFlatten::update_planes().

+ Here is the caller graph for this function:

◆ flip_triangles()

void Slic3r::TriangleMesh::flip_triangles ( )
355{
358}
void its_flip_triangles(indexed_triangle_set &its)
Definition TriangleMesh.cpp:737
float volume
Definition TriangleMesh.hpp:53

References its, Slic3r::its_flip_triangles(), m_stats, and Slic3r::TriangleMeshStats::volume.

Referenced by Slic3r::_3MF_Importer::_generate_volumes(), Slic3r::load_obj(), and Slic3r::GUI::GLGizmoMeasure::update_if_needed().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ has_zero_volume()

bool Slic3r::TriangleMesh::has_zero_volume ( ) const
384{
385 const Vec3d sz = size();
386 const double volume_val = sz.x() * sz.y() * sz.z();
387
388 return is_approx(volume_val, 0.0);
389}
Vec3d size() const
Definition TriangleMesh.hpp:131
Eigen::Matrix< double, 3, 1, Eigen::DontAlign > Vec3d
Definition Point.hpp:52
constexpr bool is_approx(Number value, Number test_value, Number precision=EPSILON)
Definition libslic3r.h:271

References Slic3r::is_approx(), and size().

Referenced by Slic3r::ModelObject::split(), and Slic3r::ModelVolume::split().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ horizontal_projection()

ExPolygons Slic3r::TriangleMesh::horizontal_projection ( ) const
416{
417 return union_ex(project_mesh(this->its, Transform3d::Identity(), []() {}));
418}
static EIGEN_DEVICE_FUNC const Transform Identity()
Returns an identity transformation.
Definition Transform.h:539
void project_mesh(const indexed_triangle_set &mesh, const Transform3d &trafo, Polygons *out_top, Polygons *out_bottom, std::function< void()> throw_on_cancel)
Definition TriangleMeshSlicer.cpp:2193
Slic3r::ExPolygons union_ex(const Slic3r::Polygons &subject, ClipperLib::PolyFillType fill_type)
Definition ClipperUtils.cpp:774

References Eigen::Transform< double, 3, Eigen::Affine, Eigen::DontAlign >::Identity(), its, Slic3r::project_mesh(), and Slic3r::union_ex().

Referenced by Slic3r::GUI::BedShapePanel::load_stl().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ is_splittable()

bool Slic3r::TriangleMesh::is_splittable ( ) const

Calculates whether or not the mesh is splittable.

379{
380 return its_is_splittable(this->its);
381}
bool its_is_splittable(const Its &m)
Definition MeshSplitImpl.hpp:188

References its, and Slic3r::its_is_splittable().

+ Here is the call graph for this function:

◆ memsize()

size_t Slic3r::TriangleMesh::memsize ( ) const
516{
517 size_t memsize = 8 + this->its.memsize() + sizeof(m_stats);
518 return memsize;
519}
size_t memsize() const
Definition TriangleMesh.cpp:515
size_t memsize() const
Definition stl.h:160

References its, m_stats, indexed_triangle_set::memsize(), and memsize().

Referenced by memsize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ merge()

void Slic3r::TriangleMesh::merge ( const TriangleMesh mesh)
408{
409 its_merge(this->its, mesh.its);
410 m_stats = m_stats.merge(mesh.m_stats);
411}
void its_merge(indexed_triangle_set &its, indexed_triangle_set &&its_add)
Merge one triangle mesh to another Added triangle set will be consumed.
Definition TriangleMesh.cpp:1355
TriangleMeshStats merge(const TriangleMeshStats &rhs) const
Definition TriangleMesh.hpp:64

References its, Slic3r::its_merge(), m_stats, and Slic3r::TriangleMeshStats::merge().

Referenced by Slic3r::sla::cut_drainholes(), Slic3r::GUI::Plater::export_stl_obj(), Slic3r::sla::hollow_mesh(), Slic3r::GLVolumeCollection::load_wipe_tower_preview(), Slic3r::ModelObject::merge(), Slic3r::ModelObject::mesh(), Slic3r::Model::mesh(), Slic3r::GUI::GLGizmoCut3D::perform_cut(), Slic3r::ModelObject::raw_mesh(), Slic3r::GUI::GLGizmoMeasure::update_if_needed(), and Slic3r::GUI::GLGizmoFlatten::update_planes().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mirror()

void Slic3r::TriangleMesh::mirror ( const Axis  axis)
305{
306 switch (axis) {
307 case X:
308 for (stl_vertex &v : its.vertices)
309 v.x() *= -1.f;
310 break;
311 case Y:
312 for (stl_vertex& v : this->its.vertices)
313 v.y() *= -1.0;
314 break;
315 case Z:
316 for (stl_vertex &v : this->its.vertices)
317 v.z() *= -1.0;
318 break;
319 default:
320 assert(false);
321 return;
322 };
323 its_flip_triangles(this->its);
324 int iaxis = int(axis);
325 std::swap(m_stats.min[iaxis], m_stats.max[iaxis]);
326 m_stats.min[iaxis] *= -1.0;
327 m_stats.max[iaxis] *= -1.0;
328}
const Scalar & y
Definition MathFunctions.h:552
@ Y
Definition libslic3r.h:99
@ Z
Definition libslic3r.h:100
@ X
Definition libslic3r.h:98
TCoord< P > x(const P &p)
Definition geometry_traits.hpp:297

References its, Slic3r::its_flip_triangles(), m_stats, Slic3r::TriangleMeshStats::max, Slic3r::TriangleMeshStats::min, indexed_triangle_set::vertices, Slic3r::X, Slic3r::Y, and Slic3r::Z.

Referenced by mirror_x(), mirror_y(), and mirror_z().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mirror_x()

void Slic3r::TriangleMesh::mirror_x ( )
inline
111{ this->mirror(X); }
void mirror(const Axis axis)
Definition TriangleMesh.cpp:304

References mirror(), and Slic3r::X.

+ Here is the call graph for this function:

◆ mirror_y()

void Slic3r::TriangleMesh::mirror_y ( )
inline
112{ this->mirror(Y); }

References mirror(), and Slic3r::Y.

+ Here is the call graph for this function:

◆ mirror_z()

void Slic3r::TriangleMesh::mirror_z ( )
inline
113{ this->mirror(Z); }

References mirror(), and Slic3r::Z.

+ Here is the call graph for this function:

◆ ReadSTLFile()

bool Slic3r::TriangleMesh::ReadSTLFile ( const char *  input_file,
bool  repair = true 
)
183{
184 stl_file stl;
185 if (! stl_open(&stl, input_file))
186 return false;
187 if (repair)
189
191 m_stats.min = stl.stats.min;
192 m_stats.max = stl.stats.max;
193 m_stats.size = stl.stats.size;
195
196 auto facets_w_1_bad_edge = stl.stats.connected_facets_2_edge - stl.stats.connected_facets_3_edge;
197 auto facets_w_2_bad_edge = stl.stats.connected_facets_1_edge - stl.stats.connected_facets_2_edge;
198 auto facets_w_3_bad_edge = stl.stats.number_of_facets - stl.stats.connected_facets_1_edge;
199 m_stats.open_edges = stl.stats.backwards_edges + facets_w_1_bad_edge + facets_w_2_bad_edge * 2 + facets_w_3_bad_edge * 3;
200
206
208
210 return true;
211}
static void trianglemesh_repair_on_import(stl_file &stl)
Definition TriangleMesh.cpp:80
void stl_generate_shared_vertices(stl_file *stl, indexed_triangle_set &its)
Definition shared.cpp:35
bool stl_open(stl_file *stl, const char *file)
Definition stlinit.cpp:235
stl_vertex size
Definition TriangleMesh.hpp:52
int number_of_parts
Definition TriangleMesh.hpp:54
int open_edges
Definition TriangleMesh.hpp:57
Definition stl.h:137
stl_stats stats
Definition stl.h:153
int backwards_edges
Definition stl.h:128
uint32_t number_of_facets
Definition stl.h:95
int facets_reversed
Definition stl.h:126
int connected_facets_1_edge
Definition stl.h:108
stl_vertex size
Definition stl.h:99
int degenerate_facets
Definition stl.h:120
stl_vertex max
Definition stl.h:97
int number_of_parts
Definition stl.h:132
stl_vertex min
Definition stl.h:98
int facets_removed
Definition stl.h:122
int edges_fixed
Definition stl.h:118
int connected_facets_2_edge
Definition stl.h:109
float volume
Definition stl.h:103
int connected_facets_3_edge
Definition stl.h:110

References stl_stats::backwards_edges, stl_stats::connected_facets_1_edge, stl_stats::connected_facets_2_edge, stl_stats::connected_facets_3_edge, stl_stats::degenerate_facets, stl_stats::edges_fixed, stl_stats::facets_removed, stl_stats::facets_reversed, its, m_stats, stl_stats::max, Slic3r::TriangleMeshStats::max, stl_stats::min, Slic3r::TriangleMeshStats::min, stl_stats::number_of_facets, Slic3r::TriangleMeshStats::number_of_facets, stl_stats::number_of_parts, Slic3r::TriangleMeshStats::number_of_parts, Slic3r::TriangleMeshStats::open_edges, Slic3r::TriangleMeshStats::repaired_errors, stl_stats::size, Slic3r::TriangleMeshStats::size, stl_file::stats, stl_generate_shared_vertices(), stl_open(), Slic3r::trianglemesh_repair_on_import(), stl_stats::volume, and Slic3r::TriangleMeshStats::volume.

Referenced by Slic3r::GUI::GalleryDialog::load_files(), Slic3r::GUI::GalleryDialog::load_label_icon_list(), Slic3r::load_stl(), and Slic3r::GUI::MainFrame::repair_stl().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ release_optional()

size_t Slic3r::TriangleMesh::release_optional ( )
inline
149{ return 0; }

◆ repaired()

bool Slic3r::TriangleMesh::repaired ( ) const

◆ restore_optional()

void Slic3r::TriangleMesh::restore_optional ( )
inline
151{}

◆ rotate() [1/3]

void Slic3r::TriangleMesh::rotate ( double  angle,
Point center 
)
366{
367 if (angle != 0.) {
368 Vec2f c = center->cast<float>();
369 this->translate(-c(0), -c(1), 0);
370 its_rotate_z(this->its, (float)angle);
371 this->translate(c(0), c(1), 0);
372 }
373}
Vec3d center() const
Return the center of the related bounding box.
Definition TriangleMesh.hpp:133
double angle(const Eigen::MatrixBase< Derived > &v1, const Eigen::MatrixBase< Derived2 > &v2)
Definition Point.hpp:112
Eigen::Matrix< float, 2, 1, Eigen::DontAlign > Vec2f
Definition Point.hpp:48
void its_rotate_z(indexed_triangle_set &its, float angle)
Definition util.cpp:180

References Slic3r::angle(), center(), its, its_rotate_z(), and translate().

+ Here is the call graph for this function:

◆ rotate() [2/3]

void Slic3r::TriangleMesh::rotate ( float  angle,
const Axis axis 
)
280{
281 if (angle != 0.f) {
283 switch (axis) {
284 case X: its_rotate_x(this->its, angle); break;
285 case Y: its_rotate_y(this->its, angle); break;
286 case Z: its_rotate_z(this->its, angle); break;
287 default: assert(false); return;
288 }
290 }
291}
T rad2deg(T angle)
Definition Geometry.hpp:288
static void update_bounding_box(const indexed_triangle_set &its, TriangleMeshStats &out)
Definition TriangleMesh.cpp:38
void its_rotate_x(indexed_triangle_set &its, float angle)
Definition util.cpp:162
void its_rotate_y(indexed_triangle_set &its, float angle)
Definition util.cpp:171

References Slic3r::angle(), its, its_rotate_x(), its_rotate_y(), its_rotate_z(), m_stats, Slic3r::Geometry::rad2deg(), Slic3r::update_bounding_box(), Slic3r::X, Slic3r::Y, and Slic3r::Z.

Referenced by rotate_x(), rotate_y(), and rotate_z().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rotate() [3/3]

void Slic3r::TriangleMesh::rotate ( float  angle,
const Vec3d axis 
)
294{
295 if (angle != 0.f) {
296 Vec3d axis_norm = axis.normalized();
298 m.rotate(Eigen::AngleAxisd(angle, axis_norm));
299 its_transform(its, m);
301 }
302}
Represents a 3D rotation as a rotation angle around an arbitrary 3D axis.
Definition AngleAxis.h:50
Eigen::Transform< double, 3, Eigen::Affine, Eigen::DontAlign > Transform3d
Definition Point.hpp:81
void its_transform(indexed_triangle_set &its, T *trafo3x4)
Definition stl.h:266

References Slic3r::angle(), Eigen::Transform< double, 3, Eigen::Affine, Eigen::DontAlign >::Identity(), its, its_transform(), m_stats, Eigen::Transform< _Scalar, _Dim, _Mode, _Options >::rotate(), and Slic3r::update_bounding_box().

+ Here is the call graph for this function:

◆ rotate_x()

void Slic3r::TriangleMesh::rotate_x ( float  angle)
inline
107{ this->rotate(angle, X); }
void rotate(float angle, const Axis &axis)
Definition TriangleMesh.cpp:279

References rotate(), and Slic3r::X.

+ Here is the call graph for this function:

◆ rotate_y()

void Slic3r::TriangleMesh::rotate_y ( float  angle)
inline
108{ this->rotate(angle, Y); }

References rotate(), and Slic3r::Y.

+ Here is the call graph for this function:

◆ rotate_z()

void Slic3r::TriangleMesh::rotate_z ( float  angle)
inline
109{ this->rotate(angle, Z); }

References rotate(), and Slic3r::Z.

+ Here is the call graph for this function:

◆ scale() [1/2]

void Slic3r::TriangleMesh::scale ( const Vec3f versor)
241{
242 // Scale extents.
243 auto s = versor.array();
244 m_stats.min.array() *= s;
245 m_stats.max.array() *= s;
246 // Scale size.
247 m_stats.size.array() *= s;
248 // Scale volume.
249 if (m_stats.volume > 0.0)
250 m_stats.volume *= s(0) * s(1) * s(2);
251 if (versor.x() == versor.y() && versor.x() == versor.z()) {
252 float s = versor.x();
253 for (stl_vertex &v : this->its.vertices)
254 v *= s;
255 } else {
256 for (stl_vertex &v : this->its.vertices) {
257 v.x() *= versor.x();
258 v.y() *= versor.y();
259 v.z() *= versor.z();
260 }
261 }
262}

References its, m_stats, Slic3r::TriangleMeshStats::max, Slic3r::TriangleMeshStats::min, Slic3r::TriangleMeshStats::size, indexed_triangle_set::vertices, and Slic3r::TriangleMeshStats::volume.

◆ scale() [2/2]

void Slic3r::TriangleMesh::scale ( float  factor)
236{
237 this->scale(Vec3f(factor, factor, factor));
238}
void scale(float factor)
Definition TriangleMesh.cpp:235
Eigen::Matrix< float, 3, 1, Eigen::DontAlign > Vec3f
Definition Point.hpp:49

References scale().

Referenced by Slic3r::GLVolumeCollection::load_wipe_tower_preview(), and scale().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ size()

Vec3d Slic3r::TriangleMesh::size ( ) const
inline
131{ return m_stats.size.cast<double>(); }

References m_stats, and Slic3r::TriangleMeshStats::size.

Referenced by has_zero_volume().

+ Here is the caller graph for this function:

◆ slice()

std::vector< ExPolygons > Slic3r::TriangleMesh::slice ( const std::vector< double > &  z) const
509{
510 // convert doubles to floats
511 std::vector<float> z_f(z.begin(), z.end());
512 return slice_mesh_ex(this->its, z_f, 0.0004f);
513}
std::vector< ExPolygons > slice_mesh_ex(const indexed_triangle_set &mesh, const std::vector< float > &zs, const MeshSlicingParamsEx &params, std::function< void()> throw_on_cancel)
Definition TriangleMeshSlicer.cpp:1908

References its, and Slic3r::slice_mesh_ex().

+ Here is the call graph for this function:

◆ split()

std::vector< TriangleMesh > Slic3r::TriangleMesh::split ( ) const
392{
393 std::vector<indexed_triangle_set> itss = its_split(this->its);
394 std::vector<TriangleMesh> out;
395 out.reserve(itss.size());
396 for (indexed_triangle_set &m : itss) {
397 // The TriangleMesh constructor shall fill in the mesh statistics including volume.
398 out.emplace_back(std::move(m));
399 if (TriangleMesh &triangle_mesh = out.back(); triangle_mesh.volume() < 0)
400 // Some source mesh parts may be incorrectly oriented. Correct them.
401 triangle_mesh.flip_triangles();
402
403 }
404 return out;
405}
void its_split(const Its &m, OutputIt out_it)
Definition MeshSplitImpl.hpp:128
Definition stl.h:157

References its, Slic3r::its_split(), and volume().

Referenced by Slic3r::ModelVolume::split().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ stats()

const TriangleMeshStats & Slic3r::TriangleMesh::stats ( ) const
inline
153{ return m_stats; }

References m_stats.

Referenced by Slic3r::ModelVolume::get_repaired_errors_count(), Slic3r::is_front_up_left(), cereal::load(), Slic3r::ModelObject::print_info(), cereal::save(), and Slic3r::GUI::Sidebar::show_info_sizer().

+ Here is the caller graph for this function:

◆ transform() [1/2]

void Slic3r::TriangleMesh::transform ( const Matrix3d t,
bool  fix_left_handed = false 
)
343{
344 its_transform(its, m);
345 double det = m.block(0, 0, 3, 3).determinant();
346 if (fix_left_handed && det < 0.) {
348 det = -det;
349 }
350 m_stats.volume *= det;
352}

References its, Slic3r::its_flip_triangles(), its_transform(), m_stats, Slic3r::update_bounding_box(), and Slic3r::TriangleMeshStats::volume.

+ Here is the call graph for this function:

◆ transform() [2/2]

void Slic3r::TriangleMesh::transform ( const Transform3d t,
bool  fix_left_handed = false 
)
331{
332 its_transform(its, t);
333 double det = t.matrix().block(0, 0, 3, 3).determinant();
334 if (fix_left_handed && det < 0.) {
336 det = -det;
337 }
338 m_stats.volume *= det;
340}

References its, Slic3r::its_flip_triangles(), its_transform(), m_stats, Eigen::Transform< _Scalar, _Dim, _Mode, _Options >::matrix(), Slic3r::update_bounding_box(), and Slic3r::TriangleMeshStats::volume.

Referenced by Slic3r::_3MF_Importer::_generate_volumes(), Slic3r::GUI::Plater::export_stl_obj(), Slic3r::sla::RotfinderBoilerplate< MAX_ITER >::get_mesh_to_rotate(), Slic3r::GLVolumeCollection::load_object_auxiliary(), Slic3r::GUI::CommonGizmosDataObjects::Raycaster::on_update(), Slic3r::GUI::GLGizmoCut3D::perform_cut(), Slic3r::SlicingAdaptive::prepare(), Slic3r::ModelObject::process_volume_cut(), Slic3r::ModelObject::raw_mesh(), Slic3r::GUI::Selection::scale_to_fit_print_volume(), Slic3r::ModelInstance::transform_mesh(), Slic3r::ModelVolume::transform_this_mesh(), Slic3r::ModelVolume::transform_this_mesh(), Slic3r::GUI::GLGizmoMeasure::update_if_needed(), Slic3r::GUI::GLGizmoFlatten::update_planes(), and Slic3r::GUI::GLGizmoSlaBase::update_volumes().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ transformed_bounding_box() [1/2]

BoundingBoxf3 Slic3r::TriangleMesh::transformed_bounding_box ( const Transform3d trafo) const
442{
443 BoundingBoxf3 bbox;
444 for (const stl_vertex &v : this->its.vertices)
445 bbox.merge(trafo * v.cast<double>());
446 return bbox;
447}
EIGEN_DEVICE_FUNC CastXpr< NewType >::Type cast() const
Definition CommonCwiseUnaryOps.h:62
void merge(const TriangleMesh &mesh)
Definition TriangleMesh.cpp:407

References Eigen::Transform< _Scalar, _Dim, _Mode, _Options >::cast(), its, Slic3r::BoundingBox3Base< PointType >::merge(), and indexed_triangle_set::vertices.

Referenced by Slic3r::GUI::GLGizmoCut3D::perform_cut(), and Slic3r::GUI::Sidebar::show_info_sizer().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ transformed_bounding_box() [2/2]

BoundingBoxf3 Slic3r::TriangleMesh::transformed_bounding_box ( const Transform3d trafo,
double  world_min_z 
) const
450{
451 // 1) Allocate transformed vertices with their position with respect to print bed surface.
452 std::vector<char> sides;
453 size_t num_above = 0;
455 Transform3f trafo = trafod.cast<float>();
456 sides.reserve(its.vertices.size());
457 for (const stl_vertex &v : this->its.vertices) {
458 const stl_vertex pt = trafo * v;
459 const int sign = pt.z() > world_min_z ? 1 : pt.z() < world_min_z ? -1 : 0;
460 sides.emplace_back(sign);
461 if (sign >= 0) {
462 // Vertex above or on print bed surface. Test whether it is inside the build volume.
463 ++ num_above;
464 bbox.extend(pt);
465 }
466 }
467
468 // 2) Calculate intersections of triangle edges with the build surface.
469 if (num_above < its.vertices.size()) {
470 // Not completely above the build surface and status may still change by testing edges intersecting the build platform.
471 for (const stl_triangle_vertex_indices &tri : its.indices) {
472 const int s[3] = { sides[tri(0)], sides[tri(1)], sides[tri(2)] };
473 if (std::min(s[0], std::min(s[1], s[2])) < 0 && std::max(s[0], std::max(s[1], s[2])) > 0) {
474 // Some edge of this triangle intersects the build platform. Calculate the intersection.
475 int iprev = 2;
476 for (int iedge = 0; iedge < 3; ++ iedge) {
477 if (s[iprev] * s[iedge] == -1) {
478 // edge intersects the build surface. Calculate intersection point.
479 const stl_vertex p1 = trafo * its.vertices[tri(iprev)];
480 const stl_vertex p2 = trafo * its.vertices[tri(iedge)];
481 // Edge crosses the z plane. Calculate intersection point with the plane.
482 const float t = (world_min_z - p1.z()) / (p2.z() - p1.z());
483 bbox.extend(Vec3f(p1.x() + (p2.x() - p1.x()) * t, p1.y() + (p2.y() - p1.y()) * t, world_min_z));
484 }
485 iprev = iedge;
486 }
487 }
488 }
489 }
490
491 BoundingBoxf3 out;
492 if (! bbox.isEmpty()) {
493 out.min = bbox.min().cast<double>();
494 out.max = bbox.max().cast<double>();
495 out.defined = true;
496 };
497 return out;
498}
EIGEN_DEVICE_FUNC const SignReturnType sign() const
Definition ArrayCwiseUnaryOps.h:184
EIGEN_DEVICE_FUNC bool isEmpty() const
Definition AlignedBox.h:95
EIGEN_DEVICE_FUNC const VectorType &() min() const
Definition AlignedBox.h:106
EIGEN_DEVICE_FUNC internal::cast_return_type< Transform, Transform< NewScalarType, Dim, Mode, Options > >::type cast() const
Definition Transform.h:632
EIGEN_DEVICE_FUNC const VectorType &() max() const
Definition AlignedBox.h:110
EIGEN_DEVICE_FUNC AlignedBox & extend(const MatrixBase< Derived > &p)
Definition AlignedBox.h:200
An axis aligned box.
Definition AlignedBox.h:31
Eigen::Transform< float, 3, Eigen::Affine, Eigen::DontAlign > Transform3f
Definition Point.hpp:80

References Eigen::Transform< _Scalar, _Dim, _Mode, _Options >::cast(), Slic3r::BoundingBoxBase< PointType, APointsType >::defined, Eigen::AlignedBox< _Scalar, _AmbientDim >::extend(), indexed_triangle_set::indices, Eigen::AlignedBox< _Scalar, _AmbientDim >::isEmpty(), its, Eigen::AlignedBox< _Scalar, _AmbientDim >::max(), Slic3r::BoundingBoxBase< PointType, APointsType >::max, Eigen::AlignedBox< _Scalar, _AmbientDim >::min(), Slic3r::BoundingBoxBase< PointType, APointsType >::min, sign(), and indexed_triangle_set::vertices.

+ Here is the call graph for this function:

◆ translate() [1/2]

void Slic3r::TriangleMesh::translate ( const Vec3f displacement)
265{
266 if (displacement.x() != 0.f || displacement.y() != 0.f || displacement.z() != 0.f) {
267 for (stl_vertex& v : this->its.vertices)
268 v += displacement;
269 m_stats.min += displacement;
270 m_stats.max += displacement;
271 }
272}

References its, m_stats, Slic3r::TriangleMeshStats::max, Slic3r::TriangleMeshStats::min, and indexed_triangle_set::vertices.

◆ translate() [2/2]

void Slic3r::TriangleMesh::translate ( float  x,
float  y,
float  z 
)
275{
276 this->translate(Vec3f(x, y, z));
277}

References translate().

Referenced by align_to_origin(), Slic3r::GUI::Plater::export_stl_obj(), Slic3r::GLVolumeCollection::load_wipe_tower_preview(), Slic3r::GUI::Emboss::CreateVolumeJob::process(), Slic3r::GUI::Emboss::UpdateJob::process(), Slic3r::ModelObject::process_connector_cut(), rotate(), and translate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ volume()

float Slic3r::TriangleMesh::volume ( )
224{
225 if (m_stats.volume == -1)
226 m_stats.volume = its_volume(this->its);
227 return m_stats.volume;
228}
float its_volume(const indexed_triangle_set &its)
Definition TriangleMesh.cpp:1403

References its, Slic3r::its_volume(), m_stats, and Slic3r::TriangleMeshStats::volume.

Referenced by Slic3r::_3MF_Importer::_generate_volumes(), Slic3r::load_obj(), Slic3r::ModelObject::print_info(), split(), and Slic3r::GUI::GLGizmoMeasure::update_if_needed().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ write_ascii()

bool Slic3r::TriangleMesh::write_ascii ( const char *  output_file)
214{
215 return its_write_stl_ascii(output_file, "", this->its);
216}
bool its_write_stl_ascii(const char *file, const char *label, const std::vector< stl_triangle_vertex_indices > &indices, const std::vector< stl_vertex > &vertices)
Definition TriangleMesh.cpp:1551

References its, and Slic3r::its_write_stl_ascii().

Referenced by Slic3r::store_stl().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ write_binary()

bool Slic3r::TriangleMesh::write_binary ( const char *  output_file)
219{
220 return its_write_stl_binary(output_file, "", this->its);
221}
bool its_write_stl_binary(const char *file, const char *label, const std::vector< stl_triangle_vertex_indices > &indices, const std::vector< stl_vertex > &vertices)
Definition TriangleMesh.cpp:1578

References its, and Slic3r::its_write_stl_binary().

Referenced by Slic3r::store_stl().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ WriteOBJFile()

void Slic3r::TriangleMesh::WriteOBJFile ( const char *  output_file) const
231{
232 its_write_obj(this->its, output_file);
233}
bool its_write_obj(const indexed_triangle_set &its, const char *file)
Definition shared.cpp:193

References its, and its_write_obj().

Referenced by Slic3r::GUI::MainFrame::repair_stl(), and Slic3r::store_obj().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ its

indexed_triangle_set Slic3r::TriangleMesh::its

Referenced by TriangleMesh(), TriangleMesh(), TriangleMesh(), Slic3r::MeshBoolean::cgal::_mesh_boolean_do(), Slic3r::GUI::Camera::calc_zoom_to_volumes_factor(), clear(), convex_hull(), convex_hull_3d(), Slic3r::GUI::CameraUtils::create_hull2d(), Slic3r::GUI::Emboss::create_sources(), Slic3r::TriangleSelector::deserialize(), Slic3r::MeshBoolean::cgal::does_self_intersect(), Slic3r::TriangleSelectorWrapper::enforce_spot(), Slic3r::GUI::Emboss::CreateVolumeJob::finalize(), Slic3r::sla::anonymous_namespace{Rotfinder.cpp}::find_ground_level(), Slic3r::sla::find_min_z_height_rotation(), flip_triangles(), Slic3r::GUI::Selection::get_bounding_box_in_reference_system(), Slic3r::sla::anonymous_namespace{Rotfinder.cpp}::get_chull_rotations(), Slic3r::ModelObject::get_instance_max_z(), Slic3r::ModelObject::get_instance_min_z(), Slic3r::csg::get_mesh(), Slic3r::csg::get_mesh(), Slic3r::sla::anonymous_namespace{Rotfinder.cpp}::get_misalginment_score(), Slic3r::sla::anonymous_namespace{Rotfinder.cpp}::get_supportedness_onfloor_score(), Slic3r::sla::anonymous_namespace{Rotfinder.cpp}::get_supportedness_score(), Slic3r::sla::anonymous_namespace{Rotfinder.cpp}::get_triangle_vertices(), Slic3r::sla::hollow_mesh(), horizontal_projection(), Slic3r::GUI::GLModel::init_from(), is_splittable(), cereal::load(), memsize(), merge(), mirror(), Slic3r::GUI::CommonGizmosDataObjects::SupportsClipper::on_update(), Slic3r::SlicingAdaptive::prepare(), Slic3r::GUI::Emboss::UpdateJob::process(), Slic3r::ModelObject::process_volume_cut(), ReadSTLFile(), Slic3r::sla::remove_inside_triangles(), Slic3r::TriangleSelector::reset(), rotate(), rotate(), rotate(), cereal::save(), scale(), slice(), split(), transform(), transform(), transformed_bounding_box(), transformed_bounding_box(), translate(), Slic3r::MeshBoolean::cgal::triangle_mesh_to_cgal(), Slic3r::MeshBoolean::triangle_mesh_to_eigen(), Slic3r::GLVolume::SinkingContours::update(), Slic3r::GLVolume::NonManifoldEdges::update(), Slic3r::GUI::GLGizmoMeasure::update_if_needed(), Slic3r::Measure::MeasuringImpl::update_planes(), Slic3r::GUI::GLGizmoFlatten::update_planes(), volume(), write_ascii(), write_binary(), and WriteOBJFile().

◆ m_stats


The documentation for this class was generated from the following files: