48 #ifndef _SUPER4PCS_ACCELERATORS_INTERSECTION_FUNCTOR_H_ 49 #define _SUPER4PCS_ACCELERATORS_INTERSECTION_FUNCTOR_H_ 51 #include "super4pcs/accelerators/pairExtraction/intersectionNode.h" 56 namespace Accelerators{
57 namespace PairExtraction{
59 template <
typename Scalar>
60 static Scalar GetRoundedEpsilonValue(Scalar epsilon,
int* lvl =
nullptr) {
61 const int lvlMax = -std::log2(epsilon);
63 if (lvl !=
nullptr) *lvl = lvlMax;
66 return 1.f/pow(2,lvlMax);
75 template <
class _Primitive,
class _Po
int,
int _dim,
typename _Scalar>
82 template <
class PrimitiveContainer,
84 class ProcessingFunctor>
87 const PrimitiveContainer& M,
88 const PointContainer & Q,
90 unsigned int minNodeSize,
91 ProcessingFunctor& functor
100 template <
class Primitive,
class Po
int,
int dim,
typename Scalar>
101 template <
class PrimitiveContainer,
102 class PointContainer,
103 class ProcessingFunctor>
106 const PrimitiveContainer& M,
107 const PointContainer & Q,
109 unsigned int minNodeSize,
110 ProcessingFunctor& functor
117 typedef typename std::vector<Node> NodeContainer;
119 typedef typename Node::IdContainer IdContainer;
120 typedef typename std::pair<unsigned int, unsigned int> ResPair;
121 typedef typename std::vector<ResPair> ResContainer;
124 const unsigned int nbPoint = Q.size();
126 epsilon = GetRoundedEpsilonValue(epsilon, &lvlMax);
131 NodeContainer ping, pong;
132 NodeContainer* nodes = &ping;
133 NodeContainer* childNodes = &pong;
136 std::vector< std::pair<Node, Scalar> > earlyNodes;
139 if (functor.ids.size() != nbPoint){
140 std::cout <<
"[IntersectionFunctor] Init id array" << std::endl;
142 for(
unsigned int i = 0; i < nbPoint; i++)
143 functor.ids.push_back(i);
148 childNodes->push_back(Node::buildUnitRootNode(Q, functor.ids));
151 Scalar edgeHalfLength = 0.f;
154 while (clvl != lvlMax-1){
156 if (childNodes->empty())
159 edgeLength =
Scalar(1.f)/pow(2, clvl);
160 edgeHalfLength = edgeLength/
Scalar(2.f);
163 std::swap(nodes, childNodes);
167 for(
typename NodeContainer::iterator nit = nodes->begin();
168 nit != nodes->end(); nit++){
173 for(
typename PrimitiveContainer::const_iterator pit = M.begin();
174 pit != M.end(); pit++){
176 if ((*pit).intersect(n.center(), edgeHalfLength+epsilon)){
179 if (n.rangeLength() > int(minNodeSize)){
181 n.split(*childNodes, edgeHalfLength);
184 earlyNodes.emplace_back(n, edgeHalfLength+epsilon);
194 ResContainer results;
195 results.reserve(childNodes->size());
197 unsigned int pId = 0;
198 for(
typename PrimitiveContainer::const_iterator itP = M.begin();
199 itP != M.end(); itP++, pId++){
201 for(
typename NodeContainer::const_iterator itN = childNodes->begin();
202 itN != childNodes->end(); itN++){
203 if ((*itP).intersect((*itN).center(), epsilon*2.f)){
205 functor.beginPrimitiveCollect(pId);
206 for(
unsigned int j = 0; j!= (*itN).rangeLength(); j++){
207 if(pId>(*itN).idInRange(j))
208 if((*itP).intersectPoint((*itN).pointInRange(j),epsilon))
209 functor.process(pId, (*itN).idInRange(j));
211 functor.endPrimitiveCollect(pId);
216 for(
typename std::vector< std::pair<Node, Scalar> >::const_iterator itPairs =
218 itPairs != earlyNodes.end();
220 if((*itP).intersect((*itPairs).first.center(), (*itPairs).second)){
223 functor.beginPrimitiveCollect(pId);
224 for(
unsigned int j = 0; j!= (*itPairs).first.rangeLength(); j++){
225 if(pId>(*itPairs).first.idInRange(j))
226 if((*itP).intersectPoint((*itPairs).first.pointInRange(j),epsilon))
227 functor.process(pId, (*itPairs).first.idInRange(j));
230 functor.endPrimitiveCollect(pId);
Extract pairs of points by rasterizing primitives and collect points.
Definition: intersectionFunctor.h:76
void process(const PrimitiveContainer &M, const PointContainer &Q, Scalar &epsilon, unsigned int minNodeSize, ProcessingFunctor &functor)
< Process the extracted pairs
Definition: intersectionFunctor.h:105
_Point Point
Definition: intersectionFunctor.h:77
_Scalar Scalar
Definition: intersectionFunctor.h:79
Definition: intersectionFunctor.h:80
Multidimensional node used for intersection query.
Definition: intersectionNode.h:72
_Primitive Primitive
Definition: intersectionFunctor.h:78