33#include <NDEVR/Buffer.h>
34#include <NDEVR/Vector.h>
35#include <NDEVR/Bounds.h>
36#include <NDEVR/Median.h>
37#include <NDEVR/TypeInfo.h>
38#include <NDEVR/Dictionary.h>
39#include <NDEVR/InfoPipe.h>
40#include <NDEVR/StringView.h>
43#include <NDEVR/OpenMP.h>
47#if NDEVR_SUPPORTS_THREADING
48#define TREE_SORTER_USE_THREAD 0
49#ifdef TREE_SORTER_USE_THREAD
50 #include <NDEVR/BasicThread.h>
53#define TREE_SORTER_USE_THREAD 0
60 template<u
int01 t_dims,
class t_type>
73 values.setAll(
center_ordered[dimension], index_offset, start, size);
85 temp.setSize(end - start);
87 uint04 left_location = start;
88 for (
uint04 i = start; i < end; i++)
90 if (list_sorter[list[i]])
92 list[left_location++] = list[i];
96 temp[temp_location++] = list[i];
99 list.setAll(temp, left_location, temp_location);
111 template<u
int01 t_dims,
class t_type>
118 template<
bool t_has_nans,
class t_list_type>
121 uint04 size = indices.size();
126 for(
uint04 i = 0; i < size; i++)
131 for (
uint01 dimension = 1; dimension < t_dims; ++dimension)
133 for (
uint01 dimension = 0; dimension < t_dims; ++dimension)
139 template<
bool t_has_nans,
class t_list_type>
142 uint04 size = indices.size();
149 centers.setSize(locations.size());
150 bounds.setSize(locations.size());
153 for (
uint04 i = 0; i < locations.size(); i++)
155 auto value = locations[i].template as<t_dims, t_type>();
156 centers[i] = value.center();
158 lib_assert(
IsInvalid(centers[i]) || bounds[i].contains(centers[i]),
"Tree Sorter: Bounds did not contain center");
160 for (
uint01 dimension = 1; dimension < t_dims; ++dimension)
162 for (
uint01 dimension = 0; dimension < t_dims; ++dimension)
168 template<
bool t_has_nans,
class t_list_type>
171 uint04 size = indices.size();
178 for (
uint04 i = 0; i < size; i++)
183 for (
uint04 i = 0; i < indices.size(); i++)
185 auto value = locations[indices[i]].template as<t_dims, t_type>();
186 centers[indices[i]] = value.center();
189 for (
uint01 dimension = 1; dimension < t_dims; ++dimension)
191 for (
uint01 dimension = 0; dimension < t_dims; ++dimension)
200 template<
bool t_has_nans,
class t_center_buffer,
class t_bounds_buffer>
201 void sortList(
uint01 dimension,
const t_center_buffer& centers,
const t_bounds_buffer& bounds)
209 const auto a_val = centers[a][dimension];
210 const auto b_val = centers[b][dimension];
216 return (a_val < b_val);
228 const auto& a_val = bounds[a][MIN][dimension];
229 const auto& b_val = bounds[b][MIN][dimension];
230 if constexpr (t_has_nans)
235 return (a_val < b_val);
243 auto a_val = bounds[a][MAX][dimension];
244 auto b_val = bounds[b][MAX][dimension];
245 if constexpr (t_has_nans)
250 return (a_val < b_val);
261 template<
class t_list_type>
267 for (
uint01 dim = 0; dim < t_dims; ++dim)
275 for (
uint01 dim = 0; dim < t_dims; ++dim)
289 template<
class t_list_type>
293 const uint04 median_location = ((end - start) / 2) + start;
294 for(
uint04 i = start; i < median_location; ++i)
298 for (
uint04 i = median_location; i < end; ++i)
302 for (
uint01 dim = 0; dim < t_dims; ++dim)
309 for (
uint04 n = start + 1; n < end; ++n)
321 for (
uint04 n = start + 1; n < end; ++n)
360 for (
uint04 n = start + 1; n < end; ++n)
372 for (
uint04 n = start + 1; n < end; ++n)
417 const uint04 median_location = ((end - start) / 2) + start;
418 for (
uint04 i = start; i < median_location; i++)
422 for (
uint04 i = median_location; i < end; i++)
426 for (
uint01 dim = 0; dim < t_dims; ++dim)
428 if (dimension != dim)
447 template<
class t_type>
A specification of upper and lower bounds in N-dimensions.
constexpr t_vertex center() const
Returns the center of the bounds.
The equivelent of std::vector but with a bit more control.
A hash-based key-value store, useful for quick associative lookups.
A tree sorter that supports both center-based and boundary-based spatial partitioning.
void createCenterSortList(const Buffer< uint04 > &indices, const t_list_type &locations)
Creates sorted index lists based on element centers.
bool m_uses_boundary
Whether boundary-based sorting is enabled.
Vector< 2, Bounds< t_dims, t_type > > getMedianBounds(uint01 dimension, uint04 start, uint04 end, const t_list_type &locations)
Computes the bounding boxes for both sides of a median split.
Buffer< uint04 > max_ordered[t_dims]
Pre-sorted index arrays by maximum bound for each dimension.
Bounds< t_dims, t_type > getBounds(uint04 start, uint04 finish, const t_list_type &locations) const
Computes the tight bounding box for a range of sorted elements.
Buffer< uint04 > min_ordered[t_dims]
Pre-sorted index arrays by minimum bound for each dimension.
uint04 getMedian(uint01 dimension, uint04 start, uint04 end)
Finds the median element and partitions all sorted lists accordingly.
void createBoundarySortList(const Buffer< uint04 > &indices, const t_list_type &locations)
Creates sorted index lists based on element bounding boxes.
void createHashSortList(const Buffer< uint04 > &indices, const t_list_type &locations)
Creates sorted index lists using a hash-based lookup for sparse element sets.
void sortList(uint01 dimension, const t_center_buffer ¢ers, const t_bounds_buffer &bounds)
Sorts the index lists for a given dimension by center, min, and max values.
Base class for tree sorters that maintain pre-sorted index arrays for efficient spatial partitioning.
void getList(uint01 dimension, uint04 start, uint04 end, Buffer< uint04 > &values, uint04 index_offset)
Copies a range of the center-ordered index list into the output buffer.
Buffer< uint04 > temp_array
Temporary index buffer for partitioning operations.
static void _sortList(const Buffer< bool > &list_sorter, Buffer< uint04 > &list, Buffer< uint04 > &temp, uint04 start, uint04 end)
Partitions a list into two halves based on a boolean mask.
Buffer< uint04 > center_ordered[t_dims]
Pre-sorted index arrays by center value for each dimension.
Buffer< bool > temp_memory
Temporary boolean buffer for partitioning operations.
A fixed-size array with N dimensions used as the basis for geometric and mathematical types.
The primary namespace for the NDEVR SDK.
static constexpr bool IsValid(const Angle< t_type > &value)
Checks whether the given Angle holds a valid value.
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
static constexpr bool IsInvalid(const Angle< t_type > &value)
Checks whether the given Angle holds an invalid value.