OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::sla::IndexedMesh Class Reference

An index-triangle structure for libIGL functions. Also serves as an alternative (raw) input format for the SLASupportTree. More...

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/libslic3r/SLA/IndexedMesh.hpp>

Collaboration diagram for Slic3r::sla::IndexedMesh:

Classes

class  hit_result
class  AABBImpl

Public Member Functions

 IndexedMesh (const indexed_triangle_set &tmesh, bool calculate_epsilon=false)
 IndexedMesh (const TriangleMesh &mesh, bool calculate_epsilon=false)
 IndexedMesh (const IndexedMesh &other)
IndexedMesh & operator= (const IndexedMesh &)
 IndexedMesh (IndexedMesh &&other)
IndexedMesh & operator= (IndexedMesh &&other)
 ~IndexedMesh ()
double ground_level () const
void ground_level_offset (double o)
double ground_level_offset () const
const std::vector< Vec3f > & vertices () const
const std::vector< Vec3i32 > & indices () const
const Vec3f & vertices (size_t idx) const
const Vec3i32 & indices (size_t idx) const
hit_result query_ray_hit (const Vec3d &s, const Vec3d &dir) const
std::vector< hit_result > query_ray_hits (const Vec3d &s, const Vec3d &dir) const
double squared_distance (const Vec3d &p, int &i, Vec3d &c) const
double squared_distance (const Vec3d &p) const
Vec3d normal_by_face_id (int face_id) const
const indexed_triangle_set * get_triangle_mesh () const

Private Member Functions

template<class M>
void init (const M &mesh, bool calculate_epsilon)

Private Attributes

const indexed_triangle_set * m_tm
double m_ground_level = 0
double m_gnd_offset = 0
std::unique_ptr< AABBImpl > m_aabb

Detailed Description

An index-triangle structure for libIGL functions. Also serves as an alternative (raw) input format for the SLASupportTree.

Constructor & Destructor Documentation

◆ IndexedMesh() [1/4]

Slic3r::sla::IndexedMesh::IndexedMesh ( const indexed_triangle_set & tmesh,
bool calculate_epsilon = false )
explicit
95 : m_aabb(new AABBImpl()), m_tm(&tmesh)
96{
97 init(tmesh, calculate_epsilon);
98}
Definition IndexedMesh.cpp:31
const indexed_triangle_set * m_tm
Definition IndexedMesh.hpp:40
std::unique_ptr< AABBImpl > m_aabb
Definition IndexedMesh.hpp:43
void init(const M &mesh, bool calculate_epsilon)
Definition IndexedMesh.cpp:85

References init(), m_aabb, and m_tm.

Referenced by IndexedMesh(), IndexedMesh(), operator=(), and operator=().

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

◆ IndexedMesh() [2/4]

Slic3r::sla::IndexedMesh::IndexedMesh ( const TriangleMesh & mesh,
bool calculate_epsilon = false )
explicit
101 : m_aabb(new AABBImpl()), m_tm(&mesh.its)
102{
103 init(mesh, calculate_epsilon);
104}

References init(), m_aabb, and m_tm.

Here is the call graph for this function:

◆ IndexedMesh() [3/4]

Slic3r::sla::IndexedMesh::IndexedMesh ( const IndexedMesh & other)
108 :
109 m_tm(other.m_tm), m_ground_level(other.m_ground_level),
110 m_aabb( new AABBImpl(*other.m_aabb) ) {}
double m_ground_level
Definition IndexedMesh.hpp:41

References IndexedMesh(), m_aabb, m_ground_level, and m_tm.

Here is the call graph for this function:

◆ IndexedMesh() [4/4]

Slic3r::sla::IndexedMesh::IndexedMesh ( IndexedMesh && other)
default

References IndexedMesh().

Here is the call graph for this function:

◆ ~IndexedMesh()

Slic3r::sla::IndexedMesh::~IndexedMesh ( )
106{}

Member Function Documentation

◆ get_triangle_mesh()

const indexed_triangle_set * Slic3r::sla::IndexedMesh::get_triangle_mesh ( ) const
inline
146{ return m_tm; }

References m_tm.

◆ ground_level()

double Slic3r::sla::IndexedMesh::ground_level ( ) const
inline
68{ return m_ground_level + m_gnd_offset; }
double m_gnd_offset
Definition IndexedMesh.hpp:41

References m_gnd_offset, and m_ground_level.

Referenced by Slic3r::contour_extrusion_path(), Slic3r::sla::SupportTree::create(), and Slic3r::sla::SupportTreeBuildsteps::execute().

Here is the caller graph for this function:

◆ ground_level_offset() [1/2]

double Slic3r::sla::IndexedMesh::ground_level_offset ( ) const
inline
70{ return m_gnd_offset; }

References m_gnd_offset.

◆ ground_level_offset() [2/2]

void Slic3r::sla::IndexedMesh::ground_level_offset ( double o)
inline
69{ m_gnd_offset = o; }

References m_gnd_offset.

Referenced by Slic3r::PrintObject::contour_z().

Here is the caller graph for this function:

◆ indices() [1/2]

const std::vector< Vec3i32 > & Slic3r::sla::IndexedMesh::indices ( ) const
134{
135 return m_tm->indices;
136}

References m_tm.

Referenced by Slic3r::sla::normals().

Here is the caller graph for this function:

◆ indices() [2/2]

const Vec3i32 & Slic3r::sla::IndexedMesh::indices ( size_t idx) const
148{
149 return m_tm->indices[idx];
150}

References m_tm.

◆ init()

template<class M>
void Slic3r::sla::IndexedMesh::init ( const M & mesh,
bool calculate_epsilon )
private
86{
87 BoundingBoxf3 bb = bounding_box(mesh);
88 m_ground_level += bb.min(Z);
89
90 // Build the AABB accelaration tree
91 m_aabb->init(*m_tm, calculate_epsilon);
92}
@ Z
Definition SupportTreeBuildsteps.hpp:37
BoundingBoxf3 bounding_box(const TriangleMesh &m)
Definition TriangleMesh.hpp:391

References Slic3r::bounding_box(), m_aabb, m_ground_level, m_tm, Slic3r::BoundingBoxBase< PointType, std::vector< PointType > >::min, and Slic3r::sla::Z.

Referenced by IndexedMesh(), and IndexedMesh().

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

◆ normal_by_face_id()

Vec3d Slic3r::sla::IndexedMesh::normal_by_face_id ( int face_id) const
153 {
154
155 return its_unnormalized_normal(*m_tm, face_id).cast<double>().normalized();
156}
stl_normal its_unnormalized_normal(const indexed_triangle_set &its, size_t face_id)
Definition TriangleMesh.hpp:320

References Slic3r::its_unnormalized_normal(), and m_tm.

Referenced by Slic3r::sla::normals(), query_ray_hit(), and query_ray_hits().

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

◆ operator=() [1/2]

IndexedMesh & Slic3r::sla::IndexedMesh::operator= ( const IndexedMesh & other)
114{
115 m_tm = other.m_tm;
116 m_ground_level = other.m_ground_level;
117 m_aabb.reset(new AABBImpl(*other.m_aabb)); return *this;
118}

References IndexedMesh(), m_aabb, m_ground_level, and m_tm.

Here is the call graph for this function:

◆ operator=() [2/2]

IndexedMesh & Slic3r::sla::IndexedMesh::operator= ( IndexedMesh && other)
default

References IndexedMesh().

Here is the call graph for this function:

◆ query_ray_hit()

IndexedMesh::hit_result Slic3r::sla::IndexedMesh::query_ray_hit ( const Vec3d & s,
const Vec3d & dir ) const
161{
162 assert(is_approx(dir.norm(), 1.));
163 igl::Hit<float> hit{-1, -1, 0.f, 0.f, 0.f};
164 hit.t = std::numeric_limits<float>::infinity();
165
166#ifdef SLIC3R_HOLE_RAYCASTER
167 if (! m_holes.empty()) {
168
169 // If there are holes, the hit_results will be made by
170 // query_ray_hits (object) and filter_hits (holes):
171 return filter_hits(query_ray_hits(s, dir));
172 }
173#endif
174
175 m_aabb->intersect_ray(*m_tm, s, dir, hit);
176 hit_result ret(*this);
177 ret.m_t = double(hit.t);
178 ret.m_dir = dir;
179 ret.m_source = s;
180 if(!std::isinf(hit.t) && !std::isnan(hit.t)) {
181 ret.m_normal = this->normal_by_face_id(hit.id);
182 ret.m_face_id = hit.id;
183 }
184
185 return ret;
186}
Definition IndexedMesh.hpp:78
std::vector< hit_result > query_ray_hits(const Vec3d &s, const Vec3d &dir) const
Definition IndexedMesh.cpp:189
Vec3d normal_by_face_id(int face_id) const
Definition IndexedMesh.cpp:153
constexpr bool is_approx(Number value, Number test_value, Number precision=EPSILON)
Definition libslic3r.h:320

References Slic3r::is_approx(), m_aabb, Slic3r::sla::IndexedMesh::hit_result::m_dir, Slic3r::sla::IndexedMesh::hit_result::m_face_id, Slic3r::sla::IndexedMesh::hit_result::m_normal, Slic3r::sla::IndexedMesh::hit_result::m_source, Slic3r::sla::IndexedMesh::hit_result::m_t, m_tm, normal_by_face_id(), and query_ray_hits().

Referenced by Slic3r::contour_extrusion_path(), and Slic3r::FaceDetector::detect_exterior_face().

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

◆ query_ray_hits()

std::vector< IndexedMesh::hit_result > Slic3r::sla::IndexedMesh::query_ray_hits ( const Vec3d & s,
const Vec3d & dir ) const
190{
191 std::vector<IndexedMesh::hit_result> outs;
192 std::vector<igl::Hit<float>> hits;
193 m_aabb->intersect_ray(*m_tm, s, dir, hits);
194
195 // The sort is necessary, the hits are not always sorted.
196 std::sort(hits.begin(), hits.end(),
197 [](const igl::Hit<float>& a, const igl::Hit<float>& b) { return a.t < b.t; });
198
199 // Remove duplicates. They sometimes appear, for example when the ray is cast
200 // along an axis of a cube due to floating-point approximations in igl (?)
201 // BBS: STUDIO-2591 A mesh with overlapping faces cannot be painted
202 //hits.erase(std::unique(hits.begin(), hits.end(),
203 // [](const igl::Hit<float>& a, const igl::Hit<float>& b)
204 // { return a.t == b.t; }),
205 // hits.end());
206
207 // Convert the igl::Hit<float> into hit_result
208 outs.reserve(hits.size());
209 for (const igl::Hit<float>& hit : hits) {
210 outs.emplace_back(IndexedMesh::hit_result(*this));
211 outs.back().m_t = double(hit.t);
212 outs.back().m_dir = dir;
213 outs.back().m_source = s;
214 if(!std::isinf(hit.t) && !std::isnan(hit.t)) {
215 outs.back().m_normal = this->normal_by_face_id(hit.id);
216 outs.back().m_face_id = hit.id;
217 }
218 }
219
220 return outs;
221}

References m_aabb, m_tm, and normal_by_face_id().

Referenced by query_ray_hit().

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

◆ squared_distance() [1/2]

double Slic3r::sla::IndexedMesh::squared_distance ( const Vec3d & p) const
inline
138 {
139 int i;
140 Vec3d c;
141 return squared_distance(p, i, c);
142 }
double squared_distance(const Vec3d &p, int &i, Vec3d &c) const
Definition IndexedMesh.cpp:322
Eigen::Matrix< double, 3, 1, Eigen::DontAlign > Vec3d
Definition SpatIndex.hpp:18

References squared_distance().

Here is the call graph for this function:

◆ squared_distance() [2/2]

double Slic3r::sla::IndexedMesh::squared_distance ( const Vec3d & p,
int & i,
Vec3d & c ) const
322 {
323 double sqdst = 0;
324 Eigen::Matrix<double, 1, 3> pp = p;
325 Eigen::Matrix<double, 1, 3> cc;
326 sqdst = m_aabb->squared_distance(*m_tm, pp, i, cc);
327 c = cc;
328 return sqdst;
329}

References m_aabb, and m_tm.

Referenced by squared_distance().

Here is the caller graph for this function:

◆ vertices() [1/2]

const std::vector< Vec3f > & Slic3r::sla::IndexedMesh::vertices ( ) const
127{
128 return m_tm->vertices;
129}

References m_tm.

Referenced by Slic3r::sla::normals().

Here is the caller graph for this function:

◆ vertices() [2/2]

const Vec3f & Slic3r::sla::IndexedMesh::vertices ( size_t idx) const
141{
142 return m_tm->vertices[idx];
143}

References m_tm.

Member Data Documentation

◆ m_aabb

std::unique_ptr<AABBImpl> Slic3r::sla::IndexedMesh::m_aabb
private

◆ m_gnd_offset

double Slic3r::sla::IndexedMesh::m_gnd_offset = 0
private

◆ m_ground_level

double Slic3r::sla::IndexedMesh::m_ground_level = 0
private

◆ m_tm


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