OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::AABBMesh Class Reference

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

Collaboration diagram for Slic3r::AABBMesh:

Classes

class  hit_result
class  AABBImpl

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)
AABBMesh & operator= (const AABBMesh &)
 AABBMesh (AABBMesh &&other)
AABBMesh & operator= (AABBMesh &&other)
 ~AABBMesh ()
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
const VertexFaceIndex & vertex_face_index () const
const std::vector< Vec3i32 > & face_neighbor_index () const

Private Member Functions

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

Private Attributes

const indexed_triangle_set * m_tm
std::unique_ptr< AABBImpl > m_aabb
VertexFaceIndex m_vfidx
std::vector< Vec3i32 > m_fnidx

Detailed Description

Constructor & Destructor Documentation

◆ AABBMesh() [1/4]

Slic3r::AABBMesh::AABBMesh ( const indexed_triangle_set & tmesh,
bool calculate_epsilon = false )
explicit
85 : m_tm(&tmesh)
86 , m_aabb(new AABBImpl())
87 , m_vfidx{tmesh}
89{
90 init(tmesh, calculate_epsilon);
91}
Definition AABBMesh.cpp:24
void init(const M &mesh, bool calculate_epsilon)
Definition AABBMesh.cpp:78
VertexFaceIndex m_vfidx
Definition AABBMesh.hpp:37
const indexed_triangle_set * m_tm
Definition AABBMesh.hpp:34
std::vector< Vec3i32 > m_fnidx
Definition AABBMesh.hpp:38
std::unique_ptr< AABBImpl > m_aabb
Definition AABBMesh.hpp:36
std::vector< Vec3i32 > its_face_neighbors(const indexed_triangle_set &its)
Definition TriangleMesh.cpp:1615

References init(), Slic3r::its_face_neighbors(), m_aabb, m_fnidx, m_tm, and m_vfidx.

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

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

◆ AABBMesh() [2/4]

Slic3r::AABBMesh::AABBMesh ( const TriangleMesh & mesh,
bool calculate_epsilon = false )
explicit
94 : m_tm(&mesh.its)
95 , m_aabb(new AABBImpl())
96 , m_vfidx{mesh.its}
97 , m_fnidx{its_face_neighbors(mesh.its)}
98{
99 init(mesh, calculate_epsilon);
100}

References init(), Slic3r::its_face_neighbors(), m_aabb, m_fnidx, m_tm, and m_vfidx.

Here is the call graph for this function:

◆ AABBMesh() [3/4]

Slic3r::AABBMesh::AABBMesh ( const AABBMesh & other)
105 : m_tm(other.m_tm)
106 , m_aabb(new AABBImpl(*other.m_aabb))
107 , m_vfidx{other.m_vfidx}
108 , m_fnidx{other.m_fnidx}
109{}

References AABBMesh(), m_aabb, m_fnidx, m_tm, and m_vfidx.

Here is the call graph for this function:

◆ AABBMesh() [4/4]

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

References AABBMesh().

Here is the call graph for this function:

◆ ~AABBMesh()

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

Member Function Documentation

◆ face_neighbor_index()

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

References m_fnidx.

◆ get_triangle_mesh()

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

References m_tm.

◆ indices() [1/2]

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

References m_tm.

Referenced by Slic3r::GUI::RaycastManager::first_hit().

Here is the caller graph for this function:

◆ indices() [2/2]

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

References m_tm.

◆ init()

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

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
154 {
155
156 return its_unnormalized_normal(*m_tm, face_id).cast<double>().normalized();
157}
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 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

References AABBMesh().

Here is the call graph for this function:

◆ operator=() [2/2]

AABBMesh & Slic3r::AABBMesh::operator= ( const AABBMesh & other)
112{
113 m_tm = other.m_tm;
114 m_aabb.reset(new AABBImpl(*other.m_aabb));
115 m_vfidx = other.m_vfidx;
116 m_fnidx = other.m_fnidx;
117
118 return *this;
119}

References AABBMesh(), m_aabb, m_fnidx, m_tm, and m_vfidx.

Here is the call graph for this function:

◆ query_ray_hit()

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

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(), and query_ray_hits().

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

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
191{
192 std::vector<AABBMesh::hit_result> outs;
193 std::vector<igl::Hit<float>> hits;
194 m_aabb->intersect_ray(*m_tm, s, dir, hits);
195
196 // The sort is necessary, the hits are not always sorted.
197 std::sort(hits.begin(), hits.end(),
198 [](const igl::Hit<float>& a, const igl::Hit<float>& b) { return a.t < b.t; });
199
200 // Remove duplicates. They sometimes appear, for example when the ray is cast
201 // along an axis of a cube due to floating-point approximations in igl (?)
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(AABBMesh::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 Slic3r::GUI::RaycastManager::closest_hit(), Slic3r::GUI::RaycastManager::first_hit(), and 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::AABBMesh::squared_distance ( const Vec3d & p) const
inline
129 {
130 int i;
131 Vec3d c;
132 return squared_distance(p, i, c);
133 }
double squared_distance(const Vec3d &p, int &i, Vec3d &c) const
Definition AABBMesh.cpp:322
Eigen::Matrix< double, 3, 1, Eigen::DontAlign > Vec3d
Definition Point.hpp:68

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
322 {
323 const Eigen::Matrix<double, 1, 3> pp { p };
324 Eigen::Matrix<double, 1, 3> cc { Vec3d::Zero() };
325 const double sqdst { m_aabb->squared_distance(*m_tm, pp, i, cc) };
326 c = cc;
327 return sqdst;
328}

References m_aabb, and m_tm.

Referenced by Slic3r::GUI::RaycastManager::closest(), and squared_distance().

Here is the caller graph for this function:

◆ vertex_face_index()

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

References m_vfidx.

◆ vertices() [1/2]

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

References m_tm.

Referenced by Slic3r::GUI::RaycastManager::first_hit().

Here is the caller graph for this function:

◆ vertices() [2/2]

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

References m_tm.

Member Data Documentation

◆ m_aabb

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

◆ m_fnidx

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

◆ m_tm

◆ m_vfidx

VertexFaceIndex Slic3r::AABBMesh::m_vfidx
private

The documentation for this class was generated from the following files:
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/libslic3r/AABBMesh.hpp
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/libslic3r/AABBMesh.cpp