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/ProgressInfo.h>
42#include <NDEVR/OpenMP.h>
46#if NDEVR_SUPPORTS_THREADING
47#define TREE_SORTER_USE_THREAD 0
48#ifdef TREE_SORTER_USE_THREAD
49 #include <NDEVR/BasicThread.h>
52#define TREE_SORTER_USE_THREAD 0
56 template<u
int01 t_dims,
class t_type>
71 uint04 left_location = start;
72 for (
uint04 i = start; i < end; i++)
74 if (list_sorter[list[i]])
76 list[left_location++] = list[i];
80 temp[temp_location++] = list[i];
83 list.
setAll(temp, left_location, temp_location);
92 template<u
int01 t_dims,
class t_type>
96 template<
bool t_has_nans,
class t_list_type>
99 if(progress) progress->
addMessage(
"Creating tree sort list");
105 for(
uint04 i = 0; i < size; i++)
109 if (progress) progress->
addMessage(
"Sorting boundary");
111 for (
uint01 dimension = 1; dimension < t_dims; ++dimension)
113 for (
uint01 dimension = 0; dimension < t_dims; ++dimension)
116 template<
bool t_has_nans,
class t_list_type>
119 if (progress) progress->
addMessage(
"Creating tree sort list");
127 centers.
setSize(locations.size());
128 bounds.
setSize(locations.size());
129 for (
uint04 i = 0; i < size; i++)
133 if (progress) progress->
addMessage(
"Sorting boundary");
135 for (
uint04 i = 0; i < locations.size(); i++)
137 auto value = locations[i].template as<t_dims, t_type>();
138 centers[i] = value.center();
140 lib_assert(
isNaN(centers[i]) || bounds[i].contains(centers[i]),
"Tree Sorter: Bounds did not contain center");
142 for (
uint01 dimension = 1; dimension < t_dims; ++dimension)
144 for (
uint01 dimension = 0; dimension < t_dims; ++dimension)
147 template<
bool t_has_nans,
class t_list_type>
150 if (progress) progress->
addMessage(
"Creating tree sort list");
158 for (
uint04 i = 0; i < size; i++)
162 if (progress) progress->
addMessage(
"Sorting boundary");
166 auto value = locations[indices[i]].template as<t_dims, t_type>();
167 centers[indices[i]] = value.center();
170 for (
uint01 dimension = 1; dimension < t_dims; ++dimension)
172 for (
uint01 dimension = 0; dimension < t_dims; ++dimension)
177 template<
bool t_has_nans,
class t_center_buffer,
class t_bounds_buffer>
185 case 0: progress->
addMessage(
"Sorting dimension 1");
break;
186 case 1: progress->
addMessage(
"Sorting dimension 2");
break;
187 case 2: progress->
addMessage(
"Sorting dimension 3");
break;
188 case 3: progress->
addMessage(
"Sorting dimension 4");
break;
197 const auto a_val = centers[a][dimension];
198 const auto b_val = centers[b][dimension];
204 return (a_val < b_val);
208 if (progress) progress->
addMessage(
"Bounding Box sorting");
217 const auto& a_val = bounds[a][
MIN][dimension];
218 const auto& b_val = bounds[b][
MIN][dimension];
224 return (a_val < b_val);
232 auto a_val = bounds[a][
MAX][dimension];
233 auto b_val = bounds[b][
MAX][dimension];
236 return (a_val < b_val);
243 template<
class t_list_type>
249 for (
uint01 dim = 0; dim < t_dims; ++dim)
257 for (
uint01 dim = 0; dim < t_dims; ++dim)
265 template<
class t_list_type>
269 const uint04 median_location = ((end - start) / 2) + start;
270 for(
uint04 i = start; i < median_location; ++i)
274 for (
uint04 i = median_location; i < end; ++i)
278 for (
uint01 dim = 0; dim < t_dims; ++dim)
285 for (
uint04 n = start + 1; n < end; ++n)
297 for (
uint04 n = start + 1; n < end; ++n)
309 for (
uint04 n = end - 2; n >= start && !
isNaN(n); --n)
321 for (
uint04 n = end - 2; n >= start && !
isNaN(n); --n)
336 for (
uint04 n = start + 1; n < end; ++n)
348 for (
uint04 n = start + 1; n < end; ++n)
360 for (
uint04 n = end - 2; n >= start && !
isNaN(n); --n)
372 for (
uint04 n = end - 2; n >= start && !
isNaN(n); --n)
388 const uint04 median_location = ((end - start) / 2) + start;
389 for (
uint04 i = start; i < median_location; i++)
393 for (
uint04 i = median_location; i < end; i++)
397 for (
uint01 dim = 0; dim < t_dims; ++dim)
399 if (dimension != dim)
418 template<
class t_type>
#define lib_assert(expression, message)
Asserts some logic in the code. Disabled in non debug mode by default. Can be re-enabled in release u...
Definition LibAssert.h:70
A specification of upper and lower bounds in N-dimensions.
Definition Bounds.hpp:57
constexpr t_vertex center() const
Returns the center of the bounds.
Definition Bounds.hpp:156
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:64
void setAll(const t_o_type *src, t_index_type offset, t_index_type size)
Definition Buffer.hpp:1313
constexpr t_index_type size() const
Definition Buffer.hpp:1461
void setSize(t_index_type new_size)
Definition Buffer.hpp:1413
void clear()
Definition Buffer.hpp:572
Definition Dictionary.h:48
Definition ProgressInfo.hpp:43
virtual bool setProgress(fltp04 percent)=0
virtual bool addMessage(const LogMessage &message)=0
Definition TreeSorter.h:94
void createHashSortList(const Buffer< uint04 > &indices, const t_list_type &locations, ProgressInfo *progress)
Definition TreeSorter.h:148
void createCenterSortList(const Buffer< uint04 > &indices, const t_list_type &locations, ProgressInfo *progress)
Definition TreeSorter.h:97
uint04 getMedian(uint01 dimension, uint04 start, uint04 end)
Definition TreeSorter.h:386
bool m_uses_boundary
Definition TreeSorter.h:415
void sortList(uint01 dimension, const t_center_buffer ¢ers, const t_bounds_buffer &bounds, ProgressInfo *progress)
Definition TreeSorter.h:178
void createBoundarySortList(const Buffer< uint04 > &indices, const t_list_type &locations, ProgressInfo *progress)
Definition TreeSorter.h:117
Buffer< uint04 > max_ordered[t_dims]
Definition TreeSorter.h:414
Buffer< uint04 > min_ordered[t_dims]
Definition TreeSorter.h:413
Bounds< t_dims, t_type > getBounds(uint04 start, uint04 finish, const t_list_type &locations) const
Definition TreeSorter.h:244
Vector< 2, Bounds< t_dims, t_type > > getMedianBounds(uint01 dimension, uint04 start, uint04 end, const t_list_type &locations)
Definition TreeSorter.h:266
Definition TreeSorter.h:58
void getList(uint01 dimension, uint04 start, uint04 end, Buffer< uint04 > &values, uint04 index_offset)
Definition TreeSorter.h:60
Buffer< bool > temp_memory
Definition TreeSorter.h:87
Buffer< uint04 > temp_array
Definition TreeSorter.h:88
Buffer< uint04 > center_ordered[t_dims]
Definition TreeSorter.h:89
static void _sortList(const Buffer< bool > &list_sorter, Buffer< uint04 > &list, Buffer< uint04 > &temp, uint04 start, uint04 end)
Definition TreeSorter.h:66
Definition TreeSorter.h:419
An element of a vector space. An element of the real coordinate space Rn Basis vector,...
Definition Vector.hpp:62
@ MIN
Definition BaseValues.hpp:226
@ MAX
Definition BaseValues.hpp:227
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:98
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:120
constexpr bool isNaN(const t_type &value)
Query if 'value' is valid or invalid.
Definition BaseFunctions.hpp:200
Definition BaseValues.hpp:272