diff --git a/include/Algo/Selection/VrRaySelector.h b/include/Algo/Selection/VrRaySelector.h deleted file mode 100644 index 37a1408a185831ae8be47e3326e243ccba08ad4a..0000000000000000000000000000000000000000 --- a/include/Algo/Selection/VrRaySelector.h +++ /dev/null @@ -1,112 +0,0 @@ -/******************************************************************************* -* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps * -* version 0.1 * -* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg * -* * -* This library is free software; you can redistribute it and/or modify it * -* under the terms of the GNU Lesser General Public License as published by the * -* Free Software Foundation; either version 2.1 of the License, or (at your * -* option) any later version. * -* * -* This library is distributed in the hope that it will be useful, but WITHOUT * -* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * -* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * -* for more details. * -* * -* You should have received a copy of the GNU Lesser General Public License * -* along with this library; if not, write to the Free Software Foundation, * -* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * -* * -* Web site: http://cgogn.unistra.fr/ * -* Contact information: cgogn@unistra.fr * -* * -*******************************************************************************/ - -#ifndef __VRRAYSELECTOR_H_ -#define __VRRAYSELECTOR_H_ - -#include -#include -#include -#include "Algo/Parallel/parallel_foreach.h" - - - -namespace CGoGN -{ - -namespace Algo -{ - -namespace Selection -{ - -/** - * Function that does the selection of vertices in a cone, returned darts are sorted from closest to farthest - * @param map the map we want to test - * @param position the position attribute - * @param rayA first point of ray (user side) - * @param rayAB vector of ray (directed ot the scene) - * @param angle angle of the code in degree. - * @param vecVertices (out) vector to store dart of intersected vertices - * @param good the selector - */ -template -void verticesConeSelection(typename PFP::MAP& map, const VertexAttribute& position, - const typename PFP::VEC3& rayA, const typename PFP::VEC3& rayAB, float angle, std::vector& vecVertices, - const FunctorSelect& good= allDarts); - -/** - * Function that does the selection of edges, returned darts are sorted from closest to farthest - * @param map the map we want to test - * @param position the position attribute - * @param rayA first point of ray (user side) - * @param rayAB vector of ray (directed ot the scene) - * @param angle radius of the cylinder of selection - * @param vecEdges (out) vector to store dart of intersected edges - * @param good the selector - */ -template -void edgesConeSelection(typename PFP::MAP& map, const VertexAttribute& position, - const typename PFP::VEC3& rayA, const typename PFP::VEC3& rayAB, float angle, std::vector& vecEdges, - const FunctorSelect& good=allDarts); - - -/** - * Function that select the closest vertex in the bubble - * @param map the map we want to test - * @param position the position attribute - * @param cursor the cursor position (center of bubble) - * @param radiusMax max radius of selection - * @param good the selector - */ -template -Dart verticesBubbleSelection(typename PFP::MAP& map, const VertexAttribute& position, - const typename PFP::VEC3& cursor, PFP::REAL radiusMax, - const FunctorSelect& good=allDarts); - - -/** - * Function that select the closest edge in the bubble - * @param map the map we want to test - * @param position the position attribute - * @param cursor the cursor position (center of bubble) - * @param radiusMax max radius of selection - * @param good the selector - */ -template -Dart edgesBubbleSelection(typename PFP::MAP& map, const VertexAttribute& position, - const typename PFP::VEC3& cursor, PFP::REAL radiusMax, - const FunctorSelect& good=allDarts); - - - - - -} -} -} - - - -#endif diff --git a/include/Algo/Selection/__raySelectFunctor.hpp b/include/Algo/Selection/__raySelectFunctor.hpp deleted file mode 100644 index 3faa69947f5fd95989acd27b968260921bc38484..0000000000000000000000000000000000000000 --- a/include/Algo/Selection/__raySelectFunctor.hpp +++ /dev/null @@ -1,387 +0,0 @@ -/******************************************************************************* -* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps * -* version 0.1 * -* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg * -* * -* This library is free software; you can redistribute it and/or modify it * -* under the terms of the GNU Lesser General Public License as published by the * -* Free Software Foundation; either version 2.1 of the License, or (at your * -* option) any later version. * -* * -* This library is distributed in the hope that it will be useful, but WITHOUT * -* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * -* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * -* for more details. * -* * -* You should have received a copy of the GNU Lesser General Public License * -* along with this library; if not, write to the Free Software Foundation, * -* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * -* * -* Web site: http://cgogn.unistra.fr/ * -* Contact information: cgogn@unistra.fr * -* * -*******************************************************************************/ - -#ifndef RAYSELECTFUNCTOR_H_ -#define RAYSELECTFUNCTOR_H_ - -#include "Geometry/distances.h" -#include "Geometry/intersection.h" - -#include "Algo/Geometry/centroid.h" - -namespace CGoGN -{ - -namespace Algo -{ - -namespace Selection -{ - -template -class FuncFaceInter: public FunctorMap -{ - typedef typename PFP::MAP MAP; - -protected: - std::vector& m_faces; - std::vector& m_Ipoints ; - const typename PFP::VEC3& m_A; - const typename PFP::VEC3& m_AB; - const VertexAttribute& m_positions; - -public: - /** - * @param map the map - * @param f vector of selected darts - * @param A first point of ray - * @param AB direction of ray - */ - FuncFaceInter(MAP& map, const VertexAttribute& position, std::vector& f, std::vector& ip, const typename PFP::VEC3& A, const typename PFP::VEC3& AB): - FunctorMap(map), m_faces(f), m_Ipoints(ip), m_A(A), m_AB(AB), m_positions(position) - {} - - bool operator()(Dart d) - { - const typename PFP::VEC3& Ta = m_positions[d]; - - Dart dd = this->m_map.phi1(d); - Dart ddd = this->m_map.phi1(dd); - bool notfound = true; - do - { - // get back position of triangle Ta,Tb,Tc - const typename PFP::VEC3& Tb = m_positions[dd]; - const typename PFP::VEC3& Tc = m_positions[ddd]; - typename PFP::VEC3 I; -// if (Geom::intersectionLineTriangle(m_A, m_AB, Ta, Tb, Tc, I)) - if (Geom::intersectionRayTriangleOpt(m_A, m_AB, Ta, Tb, Tc, I)) - { - m_faces.push_back(d); - m_Ipoints.push_back(I); - notfound = false; - } - // next triangle if we are in polygon - dd = ddd; - ddd = this->m_map.phi1(dd); - } while ((ddd != d) && notfound); - return false; - } -}; - - -template -class FuncEdgeInter: public FunctorMap -{ - typedef typename PFP::MAP MAP; - -protected: - std::vector& m_edges; - const typename PFP::VEC3& m_A; - const typename PFP::VEC3& m_AB; - float m_AB2; - float m_distMax; - const VertexAttribute& m_positions; - -public: - /** - * @param map the map - * @param e vector of selected darts - * @param A first point of ray - * @param AB direction of ray - * @param AB2 squared length of direction - * @param dm2 max distance from ray squared - */ - FuncEdgeInter(MAP& map, const VertexAttribute& position, std::vector& e, const typename PFP::VEC3& A, const typename PFP::VEC3& AB, typename PFP::REAL AB2, typename PFP::REAL dm2): - FunctorMap(map), m_edges(e), m_A(A), m_AB(AB), m_AB2(AB2), m_distMax(dm2), m_positions(position) - {} - - bool operator()(Dart d) - { - // get back position of segment PQ - const typename PFP::VEC3& P = m_positions[d]; - Dart dd = this->m_map.phi1(d); - const typename PFP::VEC3& Q = m_positions[dd]; - // the three distance to P, Q and (PQ) not used here - float dist = Geom::squaredDistanceLine2Seg(m_A, m_AB, m_AB2, P, Q); - - if (dist < m_distMax) - { - m_edges.push_back(d); - } - return false; - } -}; - - -template -class FuncVertexInter: public FunctorMap -{ - typedef typename PFP::MAP MAP; - -protected: - std::vector& m_vertices; - const typename PFP::VEC3& m_A; - const typename PFP::VEC3& m_AB; - float m_AB2; - float m_distMax; - const VertexAttribute& m_positions; -public: - /** - * @param map the map - * @param v vector of selected darts - * @param A first point of ray - * @param AB direction of ray - * @param AB2 squared length of direction - * @param dm2 max distance from ray squared - */ - FuncVertexInter(MAP& map, const VertexAttribute& position, std::vector& v, const typename PFP::VEC3& A, const typename PFP::VEC3& AB, typename PFP::REAL AB2, typename PFP::REAL dm2): - FunctorMap(map), m_vertices(v), m_A(A), m_AB(AB), m_AB2(AB2), m_distMax(dm2), m_positions(position) - {} - - bool operator()(Dart d) - { - const typename PFP::VEC3& P = m_positions[d]; - float dist = Geom::squaredDistanceLine2Point(m_A, m_AB, m_AB2, P); - if (dist < m_distMax) - { - m_vertices.push_back(d); - } - return false; - } -}; - -/** - * Functor which store the dart that correspond to the subpart of face - * that is intersected - * Must be called in foreachface - */ -template -class FuncDartMapD2Inter: public FunctorMap -{ - typedef typename PFP::MAP MAP ; - -protected: - std::vector& m_darts ; - const typename PFP::VEC3& m_A ; - const typename PFP::VEC3& m_AB ; - const VertexAttribute& m_positions; -public: - /** - * @param map the map - * @param f vector of selected darts - * @param A first point of ray - * @param AB direction of ray - */ - FuncDartMapD2Inter(MAP& map, const VertexAttribute& position, std::vector& f, const typename PFP::VEC3& A, const typename PFP::VEC3& AB): - FunctorMap(map), m_darts(f), m_A(A), m_AB(AB), m_positions(position) - {} - - bool operator()(Dart d) - { - typename PFP::VEC3 center = Geometry::faceCentroid(this->m_map, d, m_positions) ; - bool notfound = true ; - Dart face = d ; - do - { - // get back position of triangle - const typename PFP::VEC3& Tb = m_positions[face]; //this->m_map.getVertexEmb(face)->getPosition() ; - const typename PFP::VEC3& Tc = m_positions[this->m_map.phi1(face)]; //this->m_map.getVertexEmb(this->m_map.phi1(face))->getPosition() ; -// typename PFP::VEC3 I; -// if (Geom::intersectionLineTriangle(m_A, m_AB, center, Tb, Tc, I)) - if (Geom::intersectionRayTriangleOpt(m_A, m_AB, center, Tb, Tc)) - { - m_darts.push_back(face) ; - notfound = false ; - } - face = this->m_map.phi1(face) ; - } while((face != d) && notfound) ; - return false; - } -}; - - - - -template -bool distndartOrdering(const std::pair& e1, const std::pair& e2) -{ - return (e1.first < e2.first); -} - -template -bool distnintOrdering(const std::pair& e1, const std::pair& e2) -{ - return (e1.first < e2.first); -} - - - - -namespace Parallel -{ - -template -class FuncVertexInter: public FunctorMapThreaded -{ - typedef typename PFP::MAP MAP; - -protected: - const VertexAttribute& m_positions; - const typename PFP::VEC3& m_A; - const typename PFP::VEC3& m_AB; - float m_AB2; - float m_distMax; - std::vector > m_vd; - -public: - FuncVertexInter(MAP& map, const VertexAttribute& position, const typename PFP::VEC3& A, const typename PFP::VEC3& AB, typename PFP::REAL AB2, typename PFP::REAL dm2): - FunctorMapThreaded(map), m_positions(position), m_A(A), m_AB(AB), m_AB2(AB2), m_distMax(dm2) - {} - - void run(Dart d, unsigned int thread) - { - const typename PFP::VEC3& P = m_positions[d]; - float dist = Geom::squaredDistanceLine2Point(m_A, m_AB, m_AB2, P); - if (dist < m_distMax) - { - typename PFP::REAL distA = (P-m_A).norm2(); - m_vd.push_back(std::pair(distA,d)); - } - - } - - const std::vector >& getVertexDistances() { return m_vd;} -}; - - -template -class FuncEdgeInter: public FunctorMapThreaded -{ - typedef typename PFP::MAP MAP; - -protected: - const VertexAttribute& m_positions; - const typename PFP::VEC3& m_A; - const typename PFP::VEC3& m_AB; - float m_AB2; - float m_distMax; - std::vector > m_ed; - -public: - FuncEdgeInter(MAP& map, const VertexAttribute& position, const typename PFP::VEC3& A, const typename PFP::VEC3& AB, typename PFP::REAL AB2, typename PFP::REAL dm2): - FunctorMapThreaded(map), m_positions(position), m_A(A), m_AB(AB), m_AB2(AB2), m_distMax(dm2) - {} - - void run(Dart d, unsigned int thread) - { - // get back position of segment PQ - const typename PFP::VEC3& P = m_positions[d]; - Dart dd = this->m_map.phi1(d); - const typename PFP::VEC3& Q = m_positions[dd]; - // the three distance to P, Q and (PQ) not used here - float dist = Geom::squaredDistanceLine2Seg(m_A, m_AB, m_AB2, P, Q); - if (dist < m_distMax) - { - typename PFP::VEC3 M = (P+Q)/2.0; - typename PFP::REAL distA = (M-m_A).norm2(); - m_ed.push_back(std::pair(distA,d)); - } - } - - const std::vector >& getEdgeDistances() { return m_ed;} -}; - - - -template -class FuncFaceInter: public FunctorMapThreaded -{ - typedef typename PFP::MAP MAP; - -protected: - const VertexAttribute& m_positions; - const typename PFP::VEC3& m_A; - const typename PFP::VEC3& m_AB; - std::vector > m_fd; - -public: - FuncFaceInter(MAP& map, const VertexAttribute& position, const typename PFP::VEC3& A, const typename PFP::VEC3& AB): - FunctorMapThreaded(map), m_positions(position), m_A(A), m_AB(AB) - {} - - void run(Dart d, unsigned int thread) - { - const typename PFP::VEC3& Ta = m_positions[d]; - - Dart dd = this->m_map.phi1(d); - Dart ddd = this->m_map.phi1(dd); - bool notfound = true; - do - { - // get back position of triangle Ta,Tb,Tc - const typename PFP::VEC3& Tb = m_positions[dd]; - const typename PFP::VEC3& Tc = m_positions[ddd]; - typename PFP::VEC3 I; - if (Geom::intersectionRayTriangleOpt(m_A, m_AB, Ta, Tb, Tc, I)) - { - typename PFP::REAL dist = (I-m_A).norm2(); - m_fd.push_back(std::pair(dist,d)); - notfound = false; - } - // next triangle if we are in polygon - dd = ddd; - ddd = this->m_map.phi1(dd); - } while ((ddd != d) && notfound); - } - - const std::vector >& getFaceDistances() { return m_fd;} -}; - - - - -} - - - - - - - - - - - - - - - -} //namespace Selection - -} //namespace Algo - -} //namespace CGoGN - -#endif diff --git a/include/Algo/Selection/__raySelector.h b/include/Algo/Selection/__raySelector.h deleted file mode 100644 index 90a65bef2a9bbbb8af9b0afa859dfef0adc97303..0000000000000000000000000000000000000000 --- a/include/Algo/Selection/__raySelector.h +++ /dev/null @@ -1,446 +0,0 @@ -/******************************************************************************* -* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps * -* version 0.1 * -* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg * -* * -* This library is free software; you can redistribute it and/or modify it * -* under the terms of the GNU Lesser General Public License as published by the * -* Free Software Foundation; either version 2.1 of the License, or (at your * -* option) any later version. * -* * -* This library is distributed in the hope that it will be useful, but WITHOUT * -* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * -* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * -* for more details. * -* * -* You should have received a copy of the GNU Lesser General Public License * -* along with this library; if not, write to the Free Software Foundation, * -* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * -* * -* Web site: http://cgogn.unistra.fr/ * -* Contact information: cgogn@unistra.fr * -* * -*******************************************************************************/ - -#ifndef RAYSELECTOR_H_ -#define RAYSELECTOR_H_ - -#include -#include -#include "Algo/Selection/raySelectFunctor.hpp" -#include "Algo/Parallel/parallel_foreach.h" - -namespace CGoGN -{ - -namespace Algo -{ - -namespace Selection -{ - -/** - * Function that does the selection of faces, returned darts are sorted from closest to farthest - * @param map the map we want to test - * @param good a dart selector - * @param rayA first point of ray (user side) - * @param rayAB direction of ray (directed to the scene) - * @param vecFaces (out) vector to store the darts of intersected faces - */ -template -void facesRaySelection(typename PFP::MAP& map, const VertexAttribute& position, const FunctorSelect& good, const typename PFP::VEC3& rayA, const typename PFP::VEC3& rayAB, std::vector& vecFaces) -{ - std::vector iPoints; - - // get back intersected faces - vecFaces.clear(); - Algo::Selection::FuncFaceInter ffi(map, position, vecFaces, iPoints, rayA, rayAB); - map.template foreach_orbit(ffi, good); - - // compute all distances to observer for each intersected face - // and put them in a vector for sorting - typedef std::pair DartDist; - std::vector distndart; - - unsigned int nbi = vecFaces.size(); - distndart.resize(nbi); - for (unsigned int i = 0; i < nbi; ++i) - { - distndart[i].second = vecFaces[i]; - typename PFP::VEC3 V = iPoints[i] - rayA; - distndart[i].first = V.norm2(); - } - - // sort the vector of pair dist/dart - std::sort(distndart.begin(), distndart.end(), distndartOrdering); - - // store sorted darts in returned vector - for (unsigned int i = 0; i < nbi; ++i) - vecFaces[i] = distndart[i].second; -} - -/** - * Function that does the selection of edges, returned darts are sorted from closest to farthest - * @param map the map we want to test - * @param rayA first point of ray (user side) - * @param rayAB vector of ray (directed ot the scene) - * @param vecEdges (out) vector to store dart of intersected edges - * @param dist radius of the cylinder of selection - */ -template -void edgesRaySelection(typename PFP::MAP& map, const VertexAttribute& position, const FunctorSelect& good, const typename PFP::VEC3& rayA, const typename PFP::VEC3& rayAB, std::vector& vecEdges, float dist) -{ - typename PFP::REAL dist2 = dist * dist; - typename PFP::REAL AB2 = rayAB * rayAB; - - // recuperation des aretes intersectees - vecEdges.clear(); - Algo::Selection::FuncEdgeInter ffi(map, position, vecEdges, rayA, rayAB, AB2, dist2); - map.template foreach_orbit(ffi, good); - - typedef std::pair DartDist; - std::vector distndart; - - unsigned int nbi = vecEdges.size(); - distndart.resize(nbi); - - // compute all distances to observer for each middle of intersected edge - // and put them in a vector for sorting - for (unsigned int i = 0; i < nbi; ++i) - { - Dart d = vecEdges[i]; - distndart[i].second = d; - typename PFP::VEC3 V = (position[d] + position[map.phi1(d)]) / typename PFP::REAL(2); - V -= rayA; - distndart[i].first = V.norm2(); - } - - // sort the vector of pair dist/dart - std::sort(distndart.begin(), distndart.end(), distndartOrdering); - - // store sorted darts in returned vector - for (unsigned int i = 0; i < nbi; ++i) - vecEdges[i] = distndart[i].second; -} - -/** - * Function that does the selection of vertices, returned darts are sorted from closest to farthest - * @param map the map we want to test - * @param rayA first point of ray (user side) - * @param rayAB vector of ray (directed ot the scene) - * @param vecVertices (out) vector to store dart of intersected vertices - * @param dist radius of the cylinder of selection - */ -template -void verticesRaySelection(typename PFP::MAP& map, const VertexAttribute& position, const typename PFP::VEC3& rayA, const typename PFP::VEC3& rayAB, std::vector& vecVertices, float dist, const FunctorSelect& good= allDarts) -{ - typename PFP::REAL dist2 = dist * dist; - typename PFP::REAL AB2 = rayAB * rayAB; - - // recuperation des sommets intersectes - vecVertices.clear(); - Algo::Selection::FuncVertexInter ffi(map, position, vecVertices, rayA, rayAB, AB2, dist2); - map.template foreach_orbit(ffi, good); - - typedef std::pair DartDist; - std::vector distndart; - - unsigned int nbi = vecVertices.size(); - distndart.resize(nbi); - - // compute all distances to observer for each intersected vertex - // and put them in a vector for sorting - for (unsigned int i = 0; i < nbi; ++i) - { - Dart d = vecVertices[i]; - distndart[i].second = d; - typename PFP::VEC3 V = position[d] - rayA; - distndart[i].first = V.norm2(); - } - - // sort the vector of pair dist/dart - std::sort(distndart.begin(), distndart.end(), distndartOrdering); - - // store sorted darts in returned vector - for (unsigned int i = 0; i < nbi; ++i) - vecVertices[i] = distndart[i].second; -} - - -namespace Parallel -{ - -template -void facesRaySelection(typename PFP::MAP& map, const VertexAttribute& position, const FunctorSelect& good, const typename PFP::VEC3& rayA, const typename PFP::VEC3& rayAB, std::vector& vecFaces, unsigned int nbth=0, unsigned int current_thread=0) -{ - if (nbth==0) -// nbth = Algo::Parallel::optimalNbThreads(); - nbth =2; // seems to be optimal ? - - std::vector*> functs; - for (unsigned int i=0; i < nbth; ++i) - functs.push_back(new Parallel::FuncFaceInter(map,position,rayA, rayAB)); - - Algo::Parallel::foreach_cell(map, functs, false, good, current_thread); - - - // compute total nb of intersection - unsigned int nbtot=0; - for (unsigned int i=0; i < nbth; ++i) - nbtot += static_cast*>(functs[i])->getFaceDistances().size(); - - std::vector > distndart; - distndart.reserve(nbtot); - for (unsigned int i=0; i < nbth; ++i) - { - distndart.insert(distndart.end(),static_cast*>(functs[i])->getFaceDistances().begin(), static_cast*>(functs[i])->getFaceDistances().end() ); - delete functs[i]; - } - - // sort the vector of pair dist/dart - std::sort(distndart.begin(), distndart.end(), distndartOrdering); - - vecFaces.clear(); - vecFaces.reserve(nbtot); - // store sorted darts in returned vector - for (unsigned int i = 0; i < nbtot; ++i) - vecFaces.push_back(distndart[i].second); -} - -template -void edgesRaySelection(typename PFP::MAP& map, const VertexAttribute& position, const FunctorSelect& good, const typename PFP::VEC3& rayA, const typename PFP::VEC3& rayAB, std::vector& vecEdges, float dist, unsigned int nbth=0, unsigned int current_thread=0) -{ - typename PFP::REAL dist2 = dist * dist; - typename PFP::REAL AB2 = rayAB * rayAB; - - if (nbth==0) -// nbth = Algo::Parallel::optimalNbThreads(); - nbth =2; // seems to be optimal ? - - std::vector*> functs; - for (unsigned int i=0; i < nbth; ++i) - functs.push_back(new Parallel::FuncEdgeInter(map,position,rayA, rayAB, AB2, dist2)); - - Algo::Parallel::foreach_cell(map, functs, false, good, current_thread); - - // compute total nb of intersection - unsigned int nbtot=0; - for (unsigned int i=0; i < nbth; ++i) - nbtot += static_cast*>(functs[i])->getEdgeDistances().size(); - - std::vector > distndart; - distndart.reserve(nbtot); - for (unsigned int i=0; i < nbth; ++i) - { - distndart.insert(distndart.end(),static_cast*>(functs[i])->getEdgeDistances().begin(), static_cast*>(functs[i])->getEdgeDistances().end() ); - delete functs[i]; - } - - // sort the vector of pair dist/dart - std::sort(distndart.begin(), distndart.end(), distndartOrdering); - - // store sorted darts in returned vector - vecEdges.clear(); - vecEdges.reserve(nbtot); - for (unsigned int i = 0; i < nbtot; ++i) - vecEdges.push_back(distndart[i].second); -} - - -template -void verticesRaySelection(typename PFP::MAP& map, const VertexAttribute& position, const typename PFP::VEC3& rayA, const typename PFP::VEC3& rayAB, std::vector& vecVertices, float dist, const FunctorSelect& good= allDarts, unsigned int nbth=0, unsigned int current_thread=0) -{ - typename PFP::REAL dist2 = dist * dist; - typename PFP::REAL AB2 = rayAB * rayAB; - - if (nbth==0) -// nbth = Algo::Parallel::optimalNbThreads(); - nbth =2; // seems to be optimal ? - - std::vector*> functs; - for (unsigned int i=0; i < nbth; ++i) - functs.push_back(new Parallel::FuncVertexInter(map,position,rayA, rayAB, AB2, dist2)); - - Algo::Parallel::foreach_cell(map, functs, false, good, current_thread); - - // compute total nb of intersection - unsigned int nbtot=0; - for (unsigned int i=0; i < nbth; ++i) - nbtot += static_cast*>(functs[i])->getVertexDistances().size(); - - std::vector > distndart; - distndart.reserve(nbtot); - for (unsigned int i=0; i < nbth; ++i) - { - distndart.insert(distndart.end(),static_cast*>(functs[i])->getVertexDistances().begin(), static_cast*>(functs[i])->getVertexDistances().end() ); - delete functs[i]; - } - - // sort the vector of pair dist/dart - std::sort(distndart.begin(), distndart.end(), distndartOrdering); - - // store sorted darts in returned vector - vecVertices.clear(); - vecVertices.reserve(nbtot); - for (unsigned int i = 0; i < nbtot; ++i) - vecVertices.push_back(distndart[i].second); - - -} - -template -void vertexRaySelection(typename PFP::MAP& map, const VertexAttribute& position, const typename PFP::VEC3& rayA, const typename PFP::VEC3& rayAB, Dart& vertex, const FunctorSelect& good = allDarts, unsigned int nbth=0, unsigned int current_thread=0) -{ - std::vector vecFaces; - vecFaces.reserve(100); - Parallel::facesRaySelection(map, position, good, rayA, rayAB, vecFaces, nbth, current_thread); - - if(vecFaces.size() > 0) - { - // recuperation du sommet le plus proche - Dart d = vecFaces.front(); - Dart it = d; - typename PFP::REAL minDist = (rayA - position[it]).norm2(); - vertex = it; - it = map.phi1(it); - while(it != d) - { - typename PFP::REAL dist = (rayA - position[it]).norm2(); - if(dist < minDist) - { - minDist = dist; - vertex = it; - } - it = map.phi1(it); - } - } - else - vertex = NIL; -} - -} - -/** - * Function that does the selection of one vertex - * @param map the map we want to test - * @param rayA first point of ray (user side) - * @param rayAB vector of ray (directed ot the scene) - * @param vertex (out) dart of selected vertex (set to NIL if no vertex selected) - */ -template -void vertexRaySelection(typename PFP::MAP& map, const VertexAttribute& position, const typename PFP::VEC3& rayA, const typename PFP::VEC3& rayAB, Dart& vertex, const FunctorSelect& good = allDarts) -{ - std::vector vecFaces; - std::vector iPoints; - - // recuperation des faces intersectes - Algo::Selection::FuncFaceInter ffi(map, position, vecFaces, iPoints, rayA, rayAB); - map.template foreach_orbit(ffi, good); - - if(vecFaces.size() > 0) - { - typedef std::pair IndexedDist; - std::vector distnint; - - unsigned int nbi = vecFaces.size(); - distnint.resize(nbi); - for (unsigned int i = 0; i < nbi; ++i) - { - distnint[i].first = (iPoints[i] - rayA).norm2(); - distnint[i].second = i; - } - - // sort the vector of pair dist/dart - std::sort(distnint.begin(), distnint.end(), distnintOrdering); - - // recuperation du point d'intersection sur la face la plus proche - unsigned int first = distnint[0].second; - typename PFP::VEC3 ip = iPoints[first]; - - // recuperation du sommet le plus proche du point d'intersection - Dart d = vecFaces[first]; - Dart it = d; - typename PFP::REAL minDist = (ip - position[it]).norm2(); - vertex = it; - it = map.phi1(it); - while(it != d) - { - typename PFP::REAL dist = (ip - position[it]).norm2(); - if(dist < minDist) - { - minDist = dist; - vertex = it; - } - it = map.phi1(it); - } - } - else - vertex = NIL; -} - -/** - * Fonction that do the selection of darts, returned darts are sorted from closest to farthest - * Dart is here considered as a triangle formed by the 2 end vertices of the edge and the face centroid - * @param map the map we want to test - * @param rayA first point of ray (user side) - * @param rayAB vector of ray (directed ot the scene) - * @param vecDarts (out) vector to store dart of intersected darts - */ -template -void dartsRaySelection(typename PFP::MAP& map, const VertexAttribute& position, const typename PFP::VEC3& rayA, const typename PFP::VEC3& rayAB, std::vector& vecDarts, const FunctorSelect& good = allDarts) -{ - // recuperation des brins intersectes - vecDarts.clear(); - Algo::Selection::FuncDartMapD2Inter ffi(map, position, vecDarts, rayA, rayAB); - map.template foreach_orbit(ffi, good); - - typedef std::pair DartDist; - std::vector distndart; - - unsigned int nbi = vecDarts.size(); - distndart.resize(nbi); - - // compute all distances to observer for each dart of middle of edge - // and put them in a vector for sorting - for (unsigned int i = 0; i < nbi; ++i) - { - Dart d = vecDarts[i]; - distndart[i].second = d; - typename PFP::VEC3 V = (position[d] + position[map.phi1(d)]) / typename PFP::REAL(2); - V -= rayA; - distndart[i].first = V.norm2(); - } - - // sort the vector of pair dist/dart - std::sort(distndart.begin(), distndart.end(), distndartOrdering); - - // store sorted darts in returned vector - for (unsigned int i=0; i< nbi; ++i) - vecDarts[i] = distndart[i].second; -} - -template -void facesPlanSelection(typename PFP::MAP& map, const VertexAttribute& position, - const typename Geom::Plane3D& plan, std::vector& vecDarts, - const FunctorSelect& good = allDarts) -{ - TraversorF travF(map); - - for(Dart dit = travF.begin() ; dit != travF.end() ; dit = travF.next() ) - { - if(Geom::intersectionTrianglePlan(position[dit], position[map.phi1(dit)], position[map.phi_1(dit)],plan.d(), plan.normal()) == Geom::FACE_INTERSECTION) - { - vecDarts.push_back(dit); - } - } - - std::cout << "nb faces = " << vecDarts.size() << std::endl; -} - -} //namespace Selection - -} //namespace Algo - -} //namespace CGoGN - -#endif /* RAYSELECTOR_H_ */