Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
libnest2d::placers Namespace Reference

Classes

class  _BottomLeftPlacer
 
class  _NofitPolyPlacer
 
struct  BLConfig
 
struct  DefaultEpsilon
 
struct  DefaultEpsilon< T, enable_if_t< std::is_floating_point< T >::value, T > >
 
struct  DefaultEpsilon< T, enable_if_t< std::is_integral< T >::value, T > >
 
class  EdgeCache
 
struct  EmptyConfig
 
struct  Lvl
 
struct  NfpPConfig
 
class  PlacerBoilerplate
 

Functions

template<class RawShape >
void correctNfpPosition (nfp::NfpResult< RawShape > &nfp, const _Item< RawShape > &stationary, const _Item< RawShape > &orbiter)
 
template<class RawShape >
void correctNfpPosition (nfp::NfpResult< RawShape > &nfp, const RawShape &stationary, const _Item< RawShape > &orbiter)
 
template<class RawShape , class Circle = _Circle<TPoint<RawShape>>>
Circle minimizeCircle (const RawShape &sh)
 
template<class RawShape >
_Circle< TPoint< RawShape > > boundingCircle (const RawShape &sh)
 

Class Documentation

◆ libnest2d::placers::DefaultEpsilon

struct libnest2d::placers::DefaultEpsilon
template<class T, class = T>
struct libnest2d::placers::DefaultEpsilon< T, class >

◆ libnest2d::placers::EmptyConfig

struct libnest2d::placers::EmptyConfig

Function Documentation

◆ boundingCircle()

template<class RawShape >
_Circle< TPoint< RawShape > > libnest2d::placers::boundingCircle ( const RawShape &  sh)
432 {
433 return minimizeCircle(sh);
434}
Circle minimizeCircle(const RawShape &sh)
Definition nfpplacer.hpp:379

References minimizeCircle().

Referenced by libnest2d::placers::_NofitPolyPlacer< RawShape, TBin >::finalAlign(), and libnest2d::placers::_NofitPolyPlacer< RawShape, TBin >::overfit().

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

◆ correctNfpPosition() [1/2]

template<class RawShape >
void libnest2d::placers::correctNfpPosition ( nfp::NfpResult< RawShape > &  nfp,
const _Item< RawShape > &  stationary,
const _Item< RawShape > &  orbiter 
)
inline
345{
346 // The provided nfp is somewhere in the dark. We need to get it
347 // to the right position around the stationary shape.
348 // This is done by choosing the leftmost lowest vertex of the
349 // orbiting polygon to be touched with the rightmost upper
350 // vertex of the stationary polygon. In this configuration, the
351 // reference vertex of the orbiting polygon (which can be dragged around
352 // the nfp) will be its rightmost upper vertex that coincides with the
353 // rightmost upper vertex of the nfp. No proof provided other than Jonas
354 // Lindmark's reasoning about the reference vertex of nfp in his thesis
355 // ("No fit polygon problem" - section 2.1.9)
356
357 auto touch_sh = stationary.rightmostTopVertex();
358 auto touch_other = orbiter.leftmostBottomVertex();
359 auto dtouch = touch_sh - touch_other;
360 auto top_other = orbiter.rightmostTopVertex() + dtouch;
361 auto dnfp = top_other - nfp.second; // nfp.second is the nfp reference point
362 shapelike::translate(nfp.first, dnfp);
363}
Vertex leftmostBottomVertex() const
Definition nester.hpp:412
Vertex rightmostTopVertex() const
Definition nester.hpp:403

References libnest2d::_Item< RawShape >::leftmostBottomVertex(), libnest2d::_Item< RawShape >::rightmostTopVertex(), and libnest2d::shapelike::translate().

+ Here is the call graph for this function:

◆ correctNfpPosition() [2/2]

template<class RawShape >
void libnest2d::placers::correctNfpPosition ( nfp::NfpResult< RawShape > &  nfp,
const RawShape &  stationary,
const _Item< RawShape > &  orbiter 
)
inline
369{
370 auto touch_sh = nfp::rightmostUpVertex(stationary);
371 auto touch_other = orbiter.leftmostBottomVertex();
372 auto dtouch = touch_sh - touch_other;
373 auto top_other = orbiter.rightmostTopVertex() + dtouch;
374 auto dnfp = top_other - nfp.second;
375 shapelike::translate(nfp.first, dnfp);
376}

References libnest2d::_Item< RawShape >::leftmostBottomVertex(), libnest2d::_Item< RawShape >::rightmostTopVertex(), libnest2d::nfp::rightmostUpVertex(), and libnest2d::shapelike::translate().

+ Here is the call graph for this function:

◆ minimizeCircle()

template<class RawShape , class Circle = _Circle<TPoint<RawShape>>>
Circle libnest2d::placers::minimizeCircle ( const RawShape &  sh)
379 {
380 using Point = TPoint<RawShape>;
381 using Coord = TCoord<Point>;
382
383 auto& ctr = sl::contour(sh);
384 if(ctr.empty()) return {{0, 0}, 0};
385
386 auto bb = sl::boundingBox(sh);
387 auto capprx = bb.center();
388 auto rapprx = pl::distance(bb.minCorner(), bb.maxCorner());
389
390
391 opt::StopCriteria stopcr;
392 stopcr.max_iterations = 30;
393 stopcr.relative_score_difference = 1e-3;
394 opt::TOptimizer<opt::Method::L_SUBPLEX> solver(stopcr);
395
396 std::vector<double> dists(ctr.size(), 0);
397
398 auto result = solver.optimize_min(
399 [capprx, rapprx, &ctr, &dists](double xf, double yf) {
400 auto xt = Coord( std::round(getX(capprx) + rapprx*xf) );
401 auto yt = Coord( std::round(getY(capprx) + rapprx*yf) );
402
403 Point centr(xt, yt);
404
405 unsigned i = 0;
406 for(auto v : ctr) {
407 dists[i++] = pl::distance(v, centr);
408 }
409
410 auto mit = std::max_element(dists.begin(), dists.end());
411
412 assert(mit != dists.end());
413
414 return *mit;
415 },
416 opt::initvals(0.0, 0.0),
417 opt::bound(-1.0, 1.0), opt::bound(-1.0, 1.0)
418 );
419
420 double oxf = std::get<0>(result.optimum);
421 double oyf = std::get<1>(result.optimum);
422 auto xt = Coord( std::round(getX(capprx) + rapprx*oxf) );
423 auto yt = Coord( std::round(getY(capprx) + rapprx*oyf) );
424
425 Point cc(xt, yt);
426 auto r = result.score;
427
428 return {cc, r};
429}
Definition Point.hpp:158
TCoord< P > getX(const P &p)
Definition geometry_traits.hpp:424
typename PointType< remove_cvref_t< Shape > >::Type TPoint
TPoint<ShapeClass> as shorthand for typename PointType<ShapeClass>::Type.
Definition geometry_traits.hpp:46
typename CoordType< remove_cvref_t< GeomType > >::Type TCoord
TCoord<GeomType> as shorthand for typename CoordType<GeomType>::Type.
Definition geometry_traits.hpp:56
TCoord< PointImpl > Coord
Definition libnest2d.hpp:30
TCoord< P > getY(const P &p)
Definition geometry_traits.hpp:427
Kernel::Point_2 Point
Definition point_areas.cpp:20

References libnest2d::opt::bound(), libnest2d::shapelike::boundingBox(), libnest2d::shapelike::contour(), libnest2d::pointlike::distance(), libnest2d::getX(), libnest2d::getY(), libnest2d::opt::initvals(), libnest2d::opt::StopCriteria::max_iterations, and libnest2d::opt::StopCriteria::relative_score_difference.

Referenced by boundingCircle().

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