48 #ifndef _SUPER4PCS_ACCELERATORS_INTERSECTION_NODE_H_ 49 #define _SUPER4PCS_ACCELERATORS_INTERSECTION_NODE_H_ 52 #include "super4pcs/accelerators/utils.h" 55 namespace Accelerators{
56 namespace PairExtraction{
67 template <
class Point,
70 class _PointContainer = std::vector<Point>,
71 class _IdContainer = std::vector<unsigned int> >
79 const PointContainer& _points;
86 inline NdNode(
const PointContainer& points,
88 const Point& p = Point::Zero(),
89 unsigned int begin = 0,
91 : _points(points), _ids(ids), _center(p), _begin(begin), _end(end) {}
94 : _points(other._points), _ids(other._ids),
95 _center(other._center),
96 _begin (other._begin), _end(other._end) {}
103 _center = rhs._center;
113 inline int rangeLength()
const {
return int(_end) - int(_begin); }
117 inline unsigned int rangeEnd()
const {
return _end; }
120 {
return _points[_ids[i+_begin]]; }
123 {
return _ids[i+_begin]; }
126 inline const Point&
center()
const {
return _center; }
133 Scalar rootEdgeHalfLength );
141 points, ids, Point::Ones() / 2., 0, ids.size());
145 inline unsigned int _split(
int start,
int end,
151 template <
class Point,
154 class _PointContainer,
163 int l(start), r(end-1);
164 for ( ; l<r ; ++l, --r)
166 while (l < end && _points[_ids[l]][dim] < splitValue)
168 while (r >= start && _points[_ids[r]][dim] >= splitValue)
172 std::swap(_ids[l],_ids[r]);
174 if(l>=end)
return end;
175 return _points[_ids[l]][dim] < splitValue ? l+1 : l;
185 template <
class Point,
188 class _PointContainer,
193 Scalar rootEdgeHalfLength )
196 typedef std::vector< Node > Container;
200 const int offset = childs.size();
203 childs.resize(offset+nbNode, *
this);
207 for(
unsigned int d = 0; d <
Dim; d++){
208 const unsigned int nbInterval =
Utils::POW(
int(2),
int(d+1));
209 const unsigned int nbSplit = nbInterval/2;
210 const unsigned int intervalNode = nbNode / nbSplit;
211 const unsigned int midNode = nbNode / nbInterval;
214 for(
unsigned int s = 0; s != nbSplit; s++) {
215 const unsigned int beginNodeId = s * intervalNode + offset;
216 const unsigned int endNodeId = (s+1) * intervalNode + offset;
218 Scalar currentCenterD = childs[beginNodeId]._center[d];
220 const unsigned int splitId = _split(childs[beginNodeId]._begin,
221 childs[endNodeId-1]._end,
224 const Scalar beforeCenterD = currentCenterD - rootEdgeHalfLength/Scalar(2);
225 const Scalar afterCenterD = currentCenterD + rootEdgeHalfLength/Scalar(2);
228 for (
unsigned int i = beginNodeId; i != beginNodeId + midNode; i++){
229 childs[i]._center[d] = beforeCenterD;
230 childs[i]._end = splitId;
233 for (
unsigned int i = beginNodeId + midNode; i != endNodeId; i++){
234 childs[i]._center[d] = afterCenterD;
235 childs[i]._begin = splitId;
241 if (!childs.empty()) {
242 childs.erase(std::remove_if(childs.begin(), childs.end(), [](
const Node& c)
243 {
return c.rangeLength() == 0; }), childs.end());
_PointContainer PointContainer
Definition: intersectionNode.h:75
unsigned int rangeBegin() const
First position in the id array defining the current instance range.
Definition: intersectionNode.h:115
NdNode(const PointContainer &points, IdContainer &ids, const Point &p=Point::Zero(), unsigned int begin=0, unsigned int end=0)
Definition: intersectionNode.h:86
const Point & pointInRange(unsigned int i) const
Access to the i-eme point in the node. Range limits are NOT tested!
Definition: intersectionNode.h:119
const Point & center() const
Center of the current node.
Definition: intersectionNode.h:126
static NdNode< Point, _dim, Scalar, _PointContainer, _IdContainer > buildUnitRootNode(const PointContainer &points, IdContainer &ids)
Definition: intersectionNode.h:137
~NdNode()
Definition: intersectionNode.h:110
constexpr baseT POW(baseT base, expoT expo)
Compile time pow.
Definition: utils.h:62
unsigned int rangeEnd() const
Last position in the id array defining the current instance range.
Definition: intersectionNode.h:117
_IdContainer IdContainer
Definition: intersectionNode.h:76
unsigned int idInRange(unsigned int i) const
Access to the i-eme point in the node. Range limits are NOT tested!
Definition: intersectionNode.h:122
NdNode(const NdNode< Point, _dim, Scalar, _PointContainer, _IdContainer > &other)
Definition: intersectionNode.h:93
void split(std::vector< NdNode< Point, _dim, Scalar, _PointContainer, _IdContainer > > &childs, Scalar rootEdgeHalfLength)
Split the node and compute child nodes.
Definition: intersectionNode.h:191
int rangeLength() const
Length of the range covered by this node in the id array.
Definition: intersectionNode.h:113
Definition: intersectionNode.h:74
Multidimensional node used for intersection query.
Definition: intersectionNode.h:72