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

#include <src/libslic3r/AABBMesh.hpp>

+ Collaboration diagram for Slic3r::AABBMesh:

Classes

class  AABBImpl
 
class  hit_result
 

Public Member Functions

 AABBMesh (const indexed_triangle_set &tmesh, bool calculate_epsilon=false)
 
 AABBMesh (const TriangleMesh &mesh, bool calculate_epsilon=false)
 
 AABBMesh (const AABBMesh &other)
 
AABBMeshoperator= (const AABBMesh &)
 
 AABBMesh (AABBMesh &&other)
 
AABBMeshoperator= (AABBMesh &&other)
 
 ~AABBMesh ()
 
const std::vector< Vec3f > & vertices () const
 
const std::vector< Vec3i > & indices () const
 
const Vec3fvertices (size_t idx) const
 
const Vec3iindices (size_t idx) const
 
hit_result query_ray_hit (const Vec3d &s, const Vec3d &dir) const
 
std::vector< hit_resultquery_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_setget_triangle_mesh () const
 
const VertexFaceIndexvertex_face_index () const
 
const std::vector< Vec3i > & face_neighbor_index () const
 

Private Member Functions

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

Private Attributes

const indexed_triangle_setm_tm
 
std::unique_ptr< AABBImplm_aabb
 
VertexFaceIndex m_vfidx
 
std::vector< Vec3im_fnidx
 

Detailed Description

Constructor & Destructor Documentation

◆ AABBMesh() [1/4]

Slic3r::AABBMesh::AABBMesh ( const indexed_triangle_set tmesh,
bool  calculate_epsilon = false 
)
explicit
76 : m_tm(&tmesh)
77 , m_aabb(new AABBImpl())
78 , m_vfidx{tmesh}
80{
81 init(tmesh, calculate_epsilon);
82}
void init(const M &mesh, bool calculate_epsilon)
Definition AABBMesh.cpp:69
VertexFaceIndex m_vfidx
Definition AABBMesh.hpp:33
std::vector< Vec3i > m_fnidx
Definition AABBMesh.hpp:34
const indexed_triangle_set * m_tm
Definition AABBMesh.hpp:30
std::unique_ptr< AABBImpl > m_aabb
Definition AABBMesh.hpp:32
std::vector< Vec3i > its_face_neighbors(const indexed_triangle_set &its)
Definition TriangleMesh.cpp:1520

References init().

+ Here is the call graph for this function:

◆ AABBMesh() [2/4]

Slic3r::AABBMesh::AABBMesh ( const TriangleMesh mesh,
bool  calculate_epsilon = false 
)
explicit
85 : m_tm(&mesh.its)
86 , m_aabb(new AABBImpl())
87 , m_vfidx{mesh.its}
88 , m_fnidx{its_face_neighbors(mesh.its)}
89{
90 init(mesh, calculate_epsilon);
91}

References init().

+ Here is the call graph for this function:

◆ AABBMesh() [3/4]

Slic3r::AABBMesh::AABBMesh ( const AABBMesh other)
96 : m_tm(other.m_tm)
97 , m_aabb(new AABBImpl(*other.m_aabb))
98 , m_vfidx{other.m_vfidx}
99 , m_fnidx{other.m_fnidx}
100{}

◆ AABBMesh() [4/4]

Slic3r::AABBMesh::AABBMesh ( AABBMesh &&  other)
default

◆ ~AABBMesh()

Slic3r::AABBMesh::~AABBMesh ( )
93{}

Member Function Documentation

◆ face_neighbor_index()

const std::vector< Vec3i > & Slic3r::AABBMesh::face_neighbor_index ( ) const
inline
136{ return m_fnidx; }

References m_fnidx.

Referenced by Slic3r::get_normal().

+ Here is the caller graph for this function:

◆ get_triangle_mesh()

const indexed_triangle_set * Slic3r::AABBMesh::get_triangle_mesh ( ) const
inline
133{ return m_tm; }

References m_tm.

Referenced by Slic3r::sla::create_branching_tree(), Slic3r::sla::create_pad(), and Slic3r::get_normal().

+ Here is the caller graph for this function:

◆ indices() [1/2]

const std::vector< Vec3i > & Slic3r::AABBMesh::indices ( ) const
126{
127 return m_tm->indices;
128}
std::vector< stl_triangle_vertex_indices > indices
Definition stl.h:164

References indexed_triangle_set::indices, and m_tm.

Referenced by Slic3r::GUI::RaycastManager::first_hit(), Slic3r::get_normal(), and Slic3r::normals().

+ Here is the caller graph for this function:

◆ indices() [2/2]

const Vec3i & Slic3r::AABBMesh::indices ( size_t  idx) const
140{
141 return m_tm->indices[idx];
142}

References indexed_triangle_set::indices, and m_tm.

◆ init()

template<class M >
void Slic3r::AABBMesh::init ( const M &  mesh,
bool  calculate_epsilon 
)
private
70{
71 // Build the AABB accelaration tree
72 m_aabb->init(*m_tm, calculate_epsilon);
73}

References m_aabb, and m_tm.

Referenced by AABBMesh(), and AABBMesh().

+ Here is the caller graph for this function:

◆ normal_by_face_id()

Vec3d Slic3r::AABBMesh::normal_by_face_id ( int  face_id) const
145 {
146
147 return its_unnormalized_normal(*m_tm, face_id).cast<double>().normalized();
148}
stl_normal its_unnormalized_normal(const indexed_triangle_set &its, size_t face_id)
Definition TriangleMesh.hpp:286

References Slic3r::its_unnormalized_normal(), and m_tm.

Referenced by Slic3r::get_normal(), 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]

AABBMesh & Slic3r::AABBMesh::operator= ( AABBMesh &&  other)
default

◆ operator=() [2/2]

AABBMesh & Slic3r::AABBMesh::operator= ( const AABBMesh other)
103{
104 m_tm = other.m_tm;
105 m_aabb.reset(new AABBImpl(*other.m_aabb));
106 m_vfidx = other.m_vfidx;
107 m_fnidx = other.m_fnidx;
108
109 return *this;
110}

References m_aabb, m_fnidx, m_tm, and m_vfidx.

◆ query_ray_hit()

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

References Slic3r::is_approx(), m_aabb, Slic3r::AABBMesh::hit_result::m_dir, Slic3r::AABBMesh::hit_result::m_face_id, Slic3r::AABBMesh::hit_result::m_normal, Slic3r::AABBMesh::hit_result::m_source, Slic3r::AABBMesh::hit_result::m_t, m_tm, normal_by_face_id(), query_ray_hits(), and igl::Hit::t.

Referenced by Slic3r::GUI::GLGizmoCut3D::PartSelection::PartSelection(), Slic3r::sla::DefaultSupportTree::connect_to_model_body(), and Slic3r::sla::DefaultSupportTree::ray_mesh_intersect().

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

◆ query_ray_hits()

std::vector< AABBMesh::hit_result > Slic3r::AABBMesh::query_ray_hits ( const Vec3d s,
const Vec3d dir 
) const
182{
183 std::vector<AABBMesh::hit_result> outs;
184 std::vector<igl::Hit> hits;
185 m_aabb->intersect_ray(*m_tm, s, dir, hits);
186
187 // The sort is necessary, the hits are not always sorted.
188 std::sort(hits.begin(), hits.end(),
189 [](const igl::Hit& a, const igl::Hit& b) { return a.t < b.t; });
190
191 // Remove duplicates. They sometimes appear, for example when the ray is cast
192 // along an axis of a cube due to floating-point approximations in igl (?)
193 hits.erase(std::unique(hits.begin(), hits.end(),
194 [](const igl::Hit& a, const igl::Hit& b)
195 { return a.t == b.t; }),
196 hits.end());
197
198 // Convert the igl::Hit into hit_result
199 outs.reserve(hits.size());
200 for (const igl::Hit& hit : hits) {
201 outs.emplace_back(AABBMesh::hit_result(*this));
202 outs.back().m_t = double(hit.t);
203 outs.back().m_dir = dir;
204 outs.back().m_source = s;
205 if(!std::isinf(hit.t) && !std::isnan(hit.t)) {
206 outs.back().m_normal = this->normal_by_face_id(hit.id);
207 outs.back().m_face_id = hit.id;
208 }
209 }
210
211 return outs;
212}

References m_aabb, m_tm, and normal_by_face_id().

Referenced by Slic3r::GUI::MeshRaycaster::closest_hit(), Slic3r::GUI::RaycastManager::closest_hit(), Slic3r::GUI::RaycastManager::first_hit(), Slic3r::GUI::MeshRaycaster::get_unobscured_idxs(), Slic3r::GUI::MeshRaycaster::is_valid_intersection(), query_ray_hit(), and Slic3r::GUI::MeshRaycaster::unproject_on_mesh().

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

◆ squared_distance() [1/2]

double Slic3r::AABBMesh::squared_distance ( const Vec3d p) const
inline
125 {
126 int i;
127 Vec3d c;
128 return squared_distance(p, i, c);
129 }
double squared_distance(const Vec3d &p, int &i, Vec3d &c) const
Definition AABBMesh.cpp:313
Eigen::Matrix< double, 3, 1, Eigen::DontAlign > Vec3d
Definition Point.hpp:52

References squared_distance().

+ Here is the call graph for this function:

◆ squared_distance() [2/2]

double Slic3r::AABBMesh::squared_distance ( const Vec3d p,
int &  i,
Vec3d c 
) const
313 {
314 double sqdst = 0;
317 sqdst = m_aabb->squared_distance(*m_tm, pp, i, cc);
318 c = cc;
319 return sqdst;
320}
The matrix class, also used for vectors and row-vectors.
Definition Matrix.h:180

References m_aabb, and m_tm.

Referenced by Slic3r::sla::check_ground_route(), Slic3r::GUI::RaycastManager::closest(), Slic3r::sla::create_ground_pillar(), Slic3r::GUI::MeshRaycaster::get_closest_facet(), Slic3r::GUI::MeshRaycaster::get_closest_point(), Slic3r::get_normal(), and squared_distance().

+ Here is the caller graph for this function:

◆ vertex_face_index()

const VertexFaceIndex & Slic3r::AABBMesh::vertex_face_index ( ) const
inline
135{ return m_vfidx; }

References m_vfidx.

Referenced by Slic3r::get_normal().

+ Here is the caller graph for this function:

◆ vertices() [1/2]

const std::vector< Vec3f > & Slic3r::AABBMesh::vertices ( ) const
119{
120 return m_tm->vertices;
121}
std::vector< stl_vertex > vertices
Definition stl.h:165

References m_tm, and indexed_triangle_set::vertices.

Referenced by Slic3r::GUI::RaycastManager::first_hit(), Slic3r::get_normal(), and Slic3r::normals().

+ Here is the caller graph for this function:

◆ vertices() [2/2]

const Vec3f & Slic3r::AABBMesh::vertices ( size_t  idx) const
133{
134 return m_tm->vertices[idx];
135}

References m_tm, and indexed_triangle_set::vertices.

Member Data Documentation

◆ m_aabb

std::unique_ptr<AABBImpl> Slic3r::AABBMesh::m_aabb
private

◆ m_fnidx

std::vector<Vec3i> Slic3r::AABBMesh::m_fnidx
private

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

◆ m_tm

◆ m_vfidx

VertexFaceIndex Slic3r::AABBMesh::m_vfidx
private

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


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