34 : _ndims(range.
ndims()),
36 _lowerPoints(range.
ndims()),
37 _upperPoints(range.
ndims())
39 _numsubranges = _divideRange(id_list.size(), range, _lowerPoints, _upperPoints);
41 std::vector<int> subrangeIndex(_ndims, 0);
42 typename std::list<ID_type>::const_iterator id_itr = id_list.begin();
45 _subrangeMap.insert(SubRangePair_t(*id_itr, subrangeIndex));
46 _assignedSubRange_ids.push_back(*id_itr);
48 }
while (_advanceIndex(subrangeIndex));
61 return _fullRange.
ndims();
88 return _assignedSubRange_ids;
113 typename SubRangeMap_t::const_iterator itr = _subrangeMap.find(
id);
114 if (itr != _subrangeMap.end())
116 Distribution_Position_t index = (*itr).second;
117 std::vector<int> lower, upper;
118 for (
int i = 0; i < _ndims; ++i)
120 lower.push_back(_lowerPoints[i][index[i]]);
121 upper.push_back(_upperPoints[i][index[i]]);
123 return WxRange(_ndims, &lower[0], &upper[0]);
133 return _lowerPoints[dim];
138 return _upperPoints[dim];
148 std::vector<int> lowerExtension(_ndims, 0);
149 std::vector<int> upperExtension(_ndims, 0);
150 upperExtension[dim] = _fullRange.
length(dim) * (stretchFactor - 1);
152 _fullRange = _fullRange.
extend(&lowerExtension[0], &upperExtension[0]);
154 int numPoints = _lowerPoints[dim].size();
155 std::vector<int> newLower(numPoints);
157 _lowerPoints[dim][0];
159 for (
int i = 0; i < numPoints; ++i)
161 newLower[i] = (_lowerPoints[dim][i] - baseline) * stretchFactor + baseline;
162 _upperPoints[dim][i] =
163 (_upperPoints[dim][i] - _lowerPoints[dim][i] + 1) * stretchFactor +
166 _lowerPoints[dim] = newLower;
179 std::vector<int> lowerExtension(_ndims, 0);
180 std::vector<int> upperExtension(_ndims, 1);
182 newSR._fullRange = _fullRange.
extend(&lowerExtension[0],
185 for (
int dim = 0; dim <
ndims(); dim++)
187 int numPoints = _upperPoints[dim].size();
188 std::vector<int> newUpper(numPoints);
190 for (
int i = 0; i < numPoints; ++i)
191 newSR._upperPoints[dim][i] += 1;
203 std::vector<int> newlowervec(1, lowerPoint);
204 std::vector<int> newuppervec(1, upperPoint);
206 _lowerPoints.push_back(newlowervec);
207 _upperPoints.push_back(newuppervec);
209 _fullRange = _fullRange.
extDim(lowerPoint, upperPoint);
212 for (
typename SubRangeMap_t::iterator itr = _subrangeMap.begin();
213 itr != _subrangeMap.end();
215 (*itr).second.push_back(0);
248 typedef std::vector<int> Distribution_Position_t;
249 typedef std::map<ID_type, Distribution_Position_t> SubRangeMap_t;
250 typedef std::pair<ID_type, Distribution_Position_t> SubRangePair_t;
252 typedef std::vector<std::vector<int>> Distribution_Storage_t;
256 Distribution_Storage_t _lowerPoints;
257 Distribution_Storage_t _upperPoints;
258 SubRangeMap_t _subrangeMap;
265 int _divideRange(
unsigned maxSubRangesDesired,
267 Distribution_Storage_t& lowerPoints,
268 Distribution_Storage_t& upperPoints)
275 real uniformNumSplits_f = std::pow(maxSubRangesDesired, 1.0 /
ndims);
276 int numSplitsInt = std::floor(uniformNumSplits_f);
279 int numSubRangesActuallyAssigned = 1;
281 for (
int i = 0; i <
ndims; ++i)
284 int nominalLength = (
real) decompRange.
length(i) / numSplitsInt;
288 int remainingSplitsThisDim =
289 maxSubRangesDesired / numSubRangesActuallyAssigned;
293 int lowerPos = decompRange.
lower(i);
296 lowerPoints[i].push_back(lowerPos);
298 std::min(lowerPos + nominalLength - 1, decompRange.
upper(i));
300 if ((numThisDim + 2) * numSubRangesActuallyAssigned >
304 decompRange.
upper(i);
307 upperPoints[i].push_back(upperPos);
308 lowerPos = upperPos + 1;
310 }
while (lowerPos <= decompRange.
upper(i));
311 numSubRangesActuallyAssigned *= numThisDim;
313 return numSubRangesActuallyAssigned;
316 bool _advanceIndex(Distribution_Position_t& subrangeIndex,
int dim = 0)
const
319 if (dim < _ndims - 1)
321 higherResult = _advanceIndex(subrangeIndex, dim + 1);
327 int nextIndex = subrangeIndex[dim] + 1;
328 if (nextIndex == _lowerPoints[dim].size())
331 for (
int i = dim + 1; i < _ndims; ++i)
332 subrangeIndex[i] = 0;
334 subrangeIndex[dim] = nextIndex;
unsigned ndims() const
Dimensionality of box.
Definition: wxbox.h:113
TYPE upper(unsigned dim) const
Upper bound along dimension 'dim'.
Definition: wxbox.h:147
TYPE lower(unsigned dim) const
Lower bound along dimension 'dim'.
Definition: wxbox.h:124
WxBox< TYPE > extDim(TYPE low, TYPE upp) const
Returns a new box which has one greater dimension than this one.
WxRange represents a hyper-rectangular domain of an n-dimensional space of integers.
Definition: wxrange.h:23
int length(unsigned dim) const
Length of edge along dimension 'dim'.
Definition: wxrange.h:294
WxRange extend(const int low[], const int upp[]) const
Returns a range which is extended by the given amount along each side in each dimension.
Definition: wxrange.h:170
WxSplitRange splits a range into smaller ranges in a cartesian manner.
Definition: wxsplitrange.h:18
const std::vector< int > & getLowerPoints(int dim) const
Definition: wxsplitrange.h:131
unsigned numRanges() const
Number of sub-ranges in split.
Definition: wxsplitrange.h:67
const SubRangesAssigned_C_ordering_t getAssignedSubRangeIDs() const
Returns the assigned subrange ids for all of the assigned subranges.
Definition: wxsplitrange.h:86
void stretchDimension(int dim, unsigned int stretchFactor)
modifies the split range such that in the dimension specified all the range coordinates are stretched...
Definition: wxsplitrange.h:146
WxSplitRange< ID_type > cell_to_node_center() const
modifies the split range such that the global range and each sub-range are modified such that the low...
Definition: wxsplitrange.h:175
unsigned ndims() const
Dimension of range split.
Definition: wxsplitrange.h:59
int empty_range_t
Definition: wxsplitrange.h:20
WxRange getRange(const ID_type &id) const
Return neighbor for a given sub-range and side.
Definition: wxsplitrange.h:111
const WxRange & getGlobalRange() const
Return the global range that was split.
Definition: wxsplitrange.h:75
void addDimension(int lowerPoint, int upperPoint)
modifies the split range such that the number of dimensions is increased by one, covering the unsplit...
Definition: wxsplitrange.h:201
WxSplitRange(const WxRange &range, const std::list< ID_type > &id_list)
Split supplied range into smaller number of ranges.
Definition: wxsplitrange.h:33
const std::vector< int > & getUpperPoints(int dim) const
Definition: wxsplitrange.h:136
virtual ~WxSplitRange()
Destory a split range.
Definition: wxsplitrange.h:54
std::vector< ID_type > SubRangesAssigned_C_ordering_t
Definition: wxsplitrange.h:21
#define real
Definition: wmoclunstructuredreconstruction.h:11