DGtal 2.1.1
Loading...
Searching...
No Matches
DomainSplitter.h
1
17#pragma once
18
29#include "DGtal/kernel/domains/CDomain.h"
30#include <vector>
31
32namespace DGtal
33{
41 template<typename Domain>
42 struct SplitInfo
43 {
45
46 Domain domain; //< The actual split domain
47 uint32_t hintVoxelCount = 0; //< An expected guess for the number of voxel
48 };
49
55 template<typename Domain>
57 {
59
60 //Output spllitted domain type
61 typedef std::vector<SplitInfo<Domain>> SplitDomainsInfo;
62
72 SplitDomainsInfo operator()(const Domain& d, uint32_t splitHint) const
73 {
74 // Find best match possible for even splitting
75 const uint32_t splitCount = std::floor(std::log(splitHint) / std::log(Domain::dimension));
76 const uint32_t totalSplits = std::pow(splitCount, Domain::dimension);
77
78 if (splitCount == 0)
79 return { SplitInfo{d, 0} };
80
81 auto splitSize = (d.upperBound() - d.lowerBound()) / (int32_t)splitCount;
82 SplitDomainsInfo result;
83 result.reserve(totalSplits);
84
85 for (uint32_t i = 0; i < totalSplits; ++i)
86 {
87 auto start = d.lowerBound();
88 auto idx = i;
89 for (uint32_t j = 0; j < Domain::dimension; ++j)
90 {
91 auto k = idx % splitCount;
92 start[j] += k * splitSize[j] + k; // +k ensure no overlap between domains
93 idx /= splitCount;
94 }
95
96 // Make correction to ensure it remains within the domain
97 auto end = start + splitSize;
98 for (uint32_t j = 0; j < Domain::dimension; ++j)
99 end[j] = std::clamp(end[j], d.lowerBound()[j], d.upperBound()[j]);
100
101 result.emplace_back(Domain(start, end), 0);
102 }
103
104 return result;
105 };
106 };
107
108
114 template<typename Domain>
116 {
117
119
120 //Output spllitted domain type
121 typedef std::vector<SplitInfo<Domain>> SplitDomainsInfo;
122 typedef typename Domain::Dimension Dimension;
123
126
133 : axis( dim )
134 {}
135
142 SplitDomainsInfo operator()( const Domain& d, uint32_t splitHint ) const
143 {
144 return (*this)( d, splitHint, axis );
145 }
146
155 {
156 SplitDomainsInfo result;
157 if (splitHint == 0)
158 return result;
159
160 auto lower = d.lowerBound();
161 auto upper = d.upperBound();
162 auto length = upper[dim] - lower[dim] + 1;
163 uint32_t splitCount = splitHint;
164 if (splitCount > length)
165 splitCount = length;
166
167 result.reserve(splitCount);
168 auto base = length / splitCount;
169 auto rem = length % splitCount;
170
171 auto start = lower;
172 for (uint32_t i = 0; i < splitCount; ++i)
173 {
174 auto size = base + (i < rem ? 1 : 0);
175 auto end = upper;
176 end[dim] = start[dim] + size - 1;
177 result.emplace_back(Domain(start, end), 0);
178 start[dim] = end[dim] + 1;
179 }
180
181 return result;
182 };
183 };
184
185}
const Point & lowerBound() const
const Point & upperBound() const
DGtal is the top-level namespace which contains all DGtal functions and types.
std::int32_t int32_t
signed 32-bit integer.
Definition BasicTypes.h:71
std::uint32_t uint32_t
unsigned 32-bit integer.
Definition BasicTypes.h:62
Splits a domain along one of the domain grid axis.
BOOST_CONCEPT_ASSERT((concepts::CDomain< Domain >))
AxisDomainSplitter(Dimension dim=0)
Constructor.
Dimension axis
The axis used for the default split operator.
SplitDomainsInfo operator()(const Domain &d, uint32_t splitHint, Dimension dim) const
Regularly splits a domain along one axis.
std::vector< SplitInfo< Domain > > SplitDomainsInfo
Domain::Dimension Dimension
SplitDomainsInfo operator()(const Domain &d, uint32_t splitHint) const
Regularly splits a domain along one axis.
Splits a domain evenly along all dimensions.
SplitDomainsInfo operator()(const Domain &d, uint32_t splitHint) const
Splits a domain.
BOOST_CONCEPT_ASSERT((concepts::CDomain< Domain >))
std::vector< SplitInfo< Domain > > SplitDomainsInfo
Data structure returned by Domain splitters.
BOOST_CONCEPT_ASSERT((concepts::CDomain< Domain >))
uint32_t hintVoxelCount
Aim: This concept represents a digital domain, i.e. a non mutable subset of points of the given digit...
Definition CDomain.h:130
HyperRectDomain< Space > Domain
Vector lower(const Vector &z, unsigned int k)
Vector upper(const Vector &z, unsigned int k)