OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::Barycentric Struct Reference

Public Member Functions

 Barycentric (const Vec3f &a, const Vec3f &b, const Vec3f &c)
Vec3f calc (const Vec3f &p) const
bool is_point_inside_triangle (const Vec3f &p) const

Static Public Member Functions

static Vec3f calc (const Vec3f &pt, const Vec3f &p1, const Vec3f &p2, const Vec3f &p3)

Private Attributes

Vec3f a_
Vec3f x1_
Vec3f x2_

Detailed Description

Constructor & Destructor Documentation

◆ Barycentric()

Slic3r::Barycentric::Barycentric ( const Vec3f & a,
const Vec3f & b,
const Vec3f & c )
inline
198 :a_(a)
199 {
200 // Pre-compute denominator
201 const Vec3f v0 = b - a;
202 const Vec3f v1 = c - a;
203 const float d00 = v0.dot(v0);
204 const float d01 = v0.dot(v1);
205 const float d11 = v1.dot(v1);
206 const float inv_denom_ = 1.0f / (d00 * d11 - d01 * d01);
207
208 x1_ = (d11 * v0 - d01 * v1) * inv_denom_;
209 x2_ = (d00 * v1 - d01 * v0) * inv_denom_;
210 }
Eigen::Matrix< float, 3, 1, Eigen::DontAlign > Vec3f
Definition Point.hpp:65
Vec3f x2_
Definition TriangleSelector.cpp:248
Vec3f a_
Definition TriangleSelector.cpp:246
Vec3f x1_
Definition TriangleSelector.cpp:247

References a_, x1_, and x2_.

Member Function Documentation

◆ calc() [1/2]

Vec3f Slic3r::Barycentric::calc ( const Vec3f & p) const
inline
213 {
214 const Vec3f v2 = p - a_;
215 const float v = v2.dot(x1_);
216 const float w = v2.dot(x2_);
217 const float u = 1.f - v - w;
218
219 return {u, v, w};
220 }

References a_, x1_, and x2_.

Referenced by is_point_inside_triangle(), and Slic3r::is_point_inside_triangle().

Here is the caller graph for this function:

◆ calc() [2/2]

Vec3f Slic3r::Barycentric::calc ( const Vec3f & pt,
const Vec3f & p1,
const Vec3f & p2,
const Vec3f & p3 )
inlinestatic
229 {
230 const std::array<Vec3f, 3> vec = {p2 - p1, p3 - p1, pt - p1};
231 const float d00 = vec[0].dot(vec[0]);
232 const float d01 = vec[0].dot(vec[1]);
233 const float d11 = vec[1].dot(vec[1]);
234 const float d20 = vec[2].dot(vec[0]);
235 const float d21 = vec[2].dot(vec[1]);
236 const float denom = d00 * d11 - d01 * d01;
237
238 const float v = (d11 * d20 - d01 * d21) / denom;
239 const float w = (d00 * d21 - d01 * d20) / denom;
240 const float u = 1.f - v - w;
241
242 return {u, v, w};
243 }

◆ is_point_inside_triangle()

bool Slic3r::Barycentric::is_point_inside_triangle ( const Vec3f & p) const
inline
223 {
224 const Vec3f barycentric_cords = calc(p);
225 return std::all_of(begin(barycentric_cords), end(barycentric_cords), [](float cord) { return 0.f <= cord && cord <= 1.0; });
226 }
T * begin(Slic3r::Mat< N, M, T > &mat)
Definition Point.hpp:838
T * end(Slic3r::Mat< N, M, T > &mat)
Definition Point.hpp:841
Vec3f calc(const Vec3f &p) const
Definition TriangleSelector.cpp:212

References calc().

Here is the call graph for this function:

Member Data Documentation

◆ a_

Vec3f Slic3r::Barycentric::a_
private

Referenced by Barycentric(), and calc().

◆ x1_

Vec3f Slic3r::Barycentric::x1_
private

Referenced by Barycentric(), and calc().

◆ x2_

Vec3f Slic3r::Barycentric::x2_
private

Referenced by Barycentric(), and calc().


The documentation for this struct was generated from the following file: