OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::KDTreeIndirect< ANumDimensions, ACoordType, ACoordinateFn > Class Template Reference

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

Inheritance diagram for Slic3r::KDTreeIndirect< ANumDimensions, ACoordType, ACoordinateFn >:
Collaboration diagram for Slic3r::KDTreeIndirect< ANumDimensions, ACoordType, ACoordinateFn >:

Public Types

enum  : size_t { npos = size_t(-1) }
using CoordinateFn = ACoordinateFn
using CoordType = ACoordType

Public Member Functions

 KDTreeIndirect (CoordinateFn coordinate)
 KDTreeIndirect (CoordinateFn coordinate, std::vector< size_t > indices)
 KDTreeIndirect (CoordinateFn coordinate, size_t num_indices)
 KDTreeIndirect (KDTreeIndirect &&rhs)
KDTreeIndirect & operator= (KDTreeIndirect &&rhs)
void clear ()
void build (size_t num_indices)
void build (std::vector< size_t > &indices)
template<typename CoordType>
unsigned int descent_mask (const CoordType &point_coord, const CoordType &search_radius, size_t idx, size_t dimension) const
template<typename Visitor>
void visit (Visitor &visitor) const

Public Attributes

CoordinateFn coordinate

Static Public Attributes

static constexpr size_t NumDimensions = ANumDimensions

Private Member Functions

void build_recursive (std::vector< size_t > &input, size_t node, const size_t dimension, const size_t left, const size_t right)
void partition_input (std::vector< size_t > &input, const size_t dimension, size_t left, size_t right, const size_t k) const
template<typename Visitor>
void visit_recursive (size_t node, size_t dimension, Visitor &visitor) const

Private Attributes

std::vector< size_t > m_nodes

Detailed Description

template<size_t ANumDimensions, typename ACoordType, typename ACoordinateFn>
class Slic3r::KDTreeIndirect< ANumDimensions, ACoordType, ACoordinateFn >

Member Typedef Documentation

◆ CoordinateFn

template<size_t ANumDimensions, typename ACoordType, typename ACoordinateFn>
using Slic3r::KDTreeIndirect< ANumDimensions, ACoordType, ACoordinateFn >::CoordinateFn = ACoordinateFn

◆ CoordType

template<size_t ANumDimensions, typename ACoordType, typename ACoordinateFn>
using Slic3r::KDTreeIndirect< ANumDimensions, ACoordType, ACoordinateFn >::CoordType = ACoordType

Member Enumeration Documentation

◆ anonymous enum

template<size_t ANumDimensions, typename ACoordType, typename ACoordinateFn>
anonymous enum : size_t
Enumerator
npos 
34 : size_t {
35 npos = size_t(-1)
36 };
Definition KDTreeIndirect.hpp:28
@ npos
Definition KDTreeIndirect.hpp:35

Constructor & Destructor Documentation

◆ KDTreeIndirect() [1/4]

template<size_t ANumDimensions, typename ACoordType, typename ACoordinateFn>
Slic3r::KDTreeIndirect< ANumDimensions, ACoordType, ACoordinateFn >::KDTreeIndirect ( CoordinateFn coordinate)
inline
CoordinateFn coordinate
Definition KDTreeIndirect.hpp:84

◆ KDTreeIndirect() [2/4]

template<size_t ANumDimensions, typename ACoordType, typename ACoordinateFn>
Slic3r::KDTreeIndirect< ANumDimensions, ACoordType, ACoordinateFn >::KDTreeIndirect ( CoordinateFn coordinate,
std::vector< size_t > indices )
inline
void build(size_t num_indices)
Definition KDTreeIndirect.hpp:45

◆ KDTreeIndirect() [3/4]

template<size_t ANumDimensions, typename ACoordType, typename ACoordinateFn>
Slic3r::KDTreeIndirect< ANumDimensions, ACoordType, ACoordinateFn >::KDTreeIndirect ( CoordinateFn coordinate,
size_t num_indices )
inline

◆ KDTreeIndirect() [4/4]

template<size_t ANumDimensions, typename ACoordType, typename ACoordinateFn>
Slic3r::KDTreeIndirect< ANumDimensions, ACoordType, ACoordinateFn >::KDTreeIndirect ( KDTreeIndirect< ANumDimensions, ACoordType, ACoordinateFn > && rhs)
inline
std::vector< size_t > m_nodes
Definition KDTreeIndirect.hpp:194

Member Function Documentation

◆ build() [1/2]

template<size_t ANumDimensions, typename ACoordType, typename ACoordinateFn>
void Slic3r::KDTreeIndirect< ANumDimensions, ACoordType, ACoordinateFn >::build ( size_t num_indices)
inline
46 {
48 indices.reserve(num_indices);
49 for (size_t i = 0; i < num_indices; ++ i)
50 indices.emplace_back(i);
51 this->build(indices);
52 }

Referenced by Slic3r::KDTreeIndirect< 3, float, SeamPlacerImpl::SeamCandidateCoordinateFunctor >::KDTreeIndirect(), Slic3r::KDTreeIndirect< 3, float, SeamPlacerImpl::SeamCandidateCoordinateFunctor >::KDTreeIndirect(), and Slic3r::KDTreeIndirect< 3, float, SeamPlacerImpl::SeamCandidateCoordinateFunctor >::build().

Here is the caller graph for this function:

◆ build() [2/2]

template<size_t ANumDimensions, typename ACoordType, typename ACoordinateFn>
void Slic3r::KDTreeIndirect< ANumDimensions, ACoordType, ACoordinateFn >::build ( std::vector< size_t > & indices)
inline
55 {
56 if (indices.empty())
57 clear();
58 else {
59 // Allocate enough memory for a full binary tree.
60 m_nodes.assign(next_highest_power_of_2(indices.size() + 1), npos);
61 build_recursive(indices, 0, 0, 0, indices.size() - 1);
62 }
63 indices.clear();
64 }
void build_recursive(std::vector< size_t > &input, size_t node, const size_t dimension, const size_t left, const size_t right)
Definition KDTreeIndirect.hpp:88
void clear()
Definition KDTreeIndirect.hpp:43
uint16_t next_highest_power_of_2(uint16_t v)
Definition Utils.hpp:376

◆ build_recursive()

template<size_t ANumDimensions, typename ACoordType, typename ACoordinateFn>
void Slic3r::KDTreeIndirect< ANumDimensions, ACoordType, ACoordinateFn >::build_recursive ( std::vector< size_t > & input,
size_t node,
const size_t dimension,
const size_t left,
const size_t right )
inlineprivate
89 {
90 if (left > right)
91 return;
92
93 assert(node < m_nodes.size());
94
95 if (left == right) {
96 // Insert a node into the balanced tree.
98 return;
99 }
100
101 // Partition the input to left / right pieces of the same length to produce a balanced tree.
102 size_t center = (left + right) / 2;
104 // Insert a node into the tree.
106 // Build up the left / right subtrees.
107 size_t next_dimension = dimension;
109 next_dimension = 0;
110 if (center > left)
113 }
static constexpr size_t NumDimensions
Definition KDTreeIndirect.hpp:30
void partition_input(std::vector< size_t > &input, const size_t dimension, size_t left, size_t right, const size_t k) const
Definition KDTreeIndirect.hpp:119

Referenced by Slic3r::KDTreeIndirect< 3, float, SeamPlacerImpl::SeamCandidateCoordinateFunctor >::build(), and Slic3r::KDTreeIndirect< 3, float, SeamPlacerImpl::SeamCandidateCoordinateFunctor >::build_recursive().

Here is the caller graph for this function:

◆ clear()

template<size_t ANumDimensions, typename ACoordType, typename ACoordinateFn>
void Slic3r::KDTreeIndirect< ANumDimensions, ACoordType, ACoordinateFn >::clear ( )
inline
43{ m_nodes.clear(); }

Referenced by Slic3r::KDTreeIndirect< 3, float, SeamPlacerImpl::SeamCandidateCoordinateFunctor >::build().

Here is the caller graph for this function:

◆ descent_mask()

template<size_t ANumDimensions, typename ACoordType, typename ACoordinateFn>
template<typename CoordType>
unsigned int Slic3r::KDTreeIndirect< ANumDimensions, ACoordType, ACoordinateFn >::descent_mask ( const CoordType & point_coord,
const CoordType & search_radius,
size_t idx,
size_t dimension ) const
inline
68 {
70 return (dist * dist < search_radius + CoordType(EPSILON)) ?
71 // The plane intersects a hypersphere centered at point_coord of search_radius.
73 // The plane does not intersect the hypersphere.
75 }
ACoordType CoordType
Definition KDTreeIndirect.hpp:32

◆ operator=()

template<size_t ANumDimensions, typename ACoordType, typename ACoordinateFn>
KDTreeIndirect & Slic3r::KDTreeIndirect< ANumDimensions, ACoordType, ACoordinateFn >::operator= ( KDTreeIndirect< ANumDimensions, ACoordType, ACoordinateFn > && rhs)
inline

◆ partition_input()

template<size_t ANumDimensions, typename ACoordType, typename ACoordinateFn>
void Slic3r::KDTreeIndirect< ANumDimensions, ACoordType, ACoordinateFn >::partition_input ( std::vector< size_t > & input,
const size_t dimension,
size_t left,
size_t right,
const size_t k ) const
inlineprivate
120 {
121 while (left < right) {
122 size_t center = (left + right) / 2;
124 {
125 // Bubble sort the input[left], input[center], input[right], so that a median of the three values
126 // will end up in input[center].
130 if (left_value > center_value) {
133 }
134 if (left_value > right_value) {
137 }
141 }
143 }
144 if (right <= left + 2)
145 // The <left, right> interval is already sorted.
146 break;
147 size_t i = left;
148 size_t j = right - 1;
150 // Partition the set based on the pivot.
151 for (;;) {
152 // Skip left points that are already at correct positions.
153 // Search will certainly stop at position (right - 1), which stores the pivot.
154 while (this->coordinate(input[++ i], dimension) < pivot) ;
155 // Skip right points that are already at correct positions.
156 while (this->coordinate(input[-- j], dimension) > pivot && i < j) ;
157 if (i >= j)
158 break;
159 std::swap(input[i], input[j]);
160 }
161 // Restore pivot to the center of the sequence.
162 std::swap(input[i], input[right - 1]);
163 // Which side the kth element is in?
164 if (k < i)
165 right = i - 1;
166 else if (k == i)
167 // Sequence is partitioned, kth element is at its place.
168 break;
169 else
170 left = i + 1;
171 }
172 }

Referenced by Slic3r::KDTreeIndirect< 3, float, SeamPlacerImpl::SeamCandidateCoordinateFunctor >::build_recursive().

Here is the caller graph for this function:

◆ visit()

template<size_t ANumDimensions, typename ACoordType, typename ACoordinateFn>
template<typename Visitor>
void Slic3r::KDTreeIndirect< ANumDimensions, ACoordType, ACoordinateFn >::visit ( Visitor & visitor) const
inline
80 {
82 }
void visit_recursive(size_t node, size_t dimension, Visitor &visitor) const
Definition KDTreeIndirect.hpp:175

Referenced by Slic3r::find_closest_points().

Here is the caller graph for this function:

◆ visit_recursive()

template<size_t ANumDimensions, typename ACoordType, typename ACoordinateFn>
template<typename Visitor>
void Slic3r::KDTreeIndirect< ANumDimensions, ACoordType, ACoordinateFn >::visit_recursive ( size_t node,
size_t dimension,
Visitor & visitor ) const
inlineprivate
176 {
177 assert(! m_nodes.empty());
178 if (node >= m_nodes.size() || m_nodes[node] == npos)
179 return;
180
181 // Left / right child node index.
182 size_t left = node * 2 + 1;
183 size_t right = left + 1;
184 unsigned int mask = visitor(m_nodes[node], dimension);
185 if ((mask & (unsigned int)VisitorReturnMask::STOP) == 0) {
186 size_t next_dimension = (++ dimension == NumDimensions) ? 0 : dimension;
187 if (mask & (unsigned int)VisitorReturnMask::CONTINUE_LEFT)
189 if (mask & (unsigned int)VisitorReturnMask::CONTINUE_RIGHT)
191 }
192 }

Referenced by Slic3r::KDTreeIndirect< 3, float, SeamPlacerImpl::SeamCandidateCoordinateFunctor >::visit(), and Slic3r::KDTreeIndirect< 3, float, SeamPlacerImpl::SeamCandidateCoordinateFunctor >::visit_recursive().

Here is the caller graph for this function:

Member Data Documentation

◆ coordinate

template<size_t ANumDimensions, typename ACoordType, typename ACoordinateFn>
CoordinateFn Slic3r::KDTreeIndirect< ANumDimensions, ACoordType, ACoordinateFn >::coordinate

◆ m_nodes

template<size_t ANumDimensions, typename ACoordType, typename ACoordinateFn>
std::vector<size_t> Slic3r::KDTreeIndirect< ANumDimensions, ACoordType, ACoordinateFn >::m_nodes
private

◆ NumDimensions

template<size_t ANumDimensions, typename ACoordType, typename ACoordinateFn>
size_t Slic3r::KDTreeIndirect< ANumDimensions, ACoordType, ACoordinateFn >::NumDimensions = ANumDimensions
staticconstexpr

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