Commit b18a529d authored by Pierre Kraemer's avatar Pierre Kraemer

ajouts divers inclusion / intersection / collector

parent 947fe6a0
...@@ -186,7 +186,6 @@ void Viewer::importMesh(std::string& filename) ...@@ -186,7 +186,6 @@ void Viewer::importMesh(std::string& filename)
m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::TRIANGLES) ; m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::TRIANGLES) ;
bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position) ; bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position) ;
gPosObj = bb.center() ;
normalBaseSize = bb.diagSize() / 100.0f ; normalBaseSize = bb.diagSize() / 100.0f ;
vertexBaseSize = normalBaseSize * 2.0f ; vertexBaseSize = normalBaseSize * 2.0f ;
...@@ -198,7 +197,7 @@ void Viewer::importMesh(std::string& filename) ...@@ -198,7 +197,7 @@ void Viewer::importMesh(std::string& filename)
m_positionVBO->updateData(position) ; m_positionVBO->updateData(position) ;
m_normalVBO->updateData(normal) ; m_normalVBO->updateData(normal) ;
setParamObject(bb.maxSize(), gPosObj.data()) ; setParamObject(bb.maxSize(), bb.center().data()) ;
updateGLMatrices() ; updateGLMatrices() ;
} }
......
...@@ -78,7 +78,6 @@ public: ...@@ -78,7 +78,6 @@ public:
float shininess ; float shininess ;
Geom::BoundingBox<PFP::VEC3> bb ; Geom::BoundingBox<PFP::VEC3> bb ;
Geom::Vec3f gPosObj ;
float normalBaseSize ; float normalBaseSize ;
float normalScaleFactor ; float normalScaleFactor ;
float vertexBaseSize ; float vertexBaseSize ;
......
...@@ -27,6 +27,11 @@ ...@@ -27,6 +27,11 @@
#include "Algo/Decimation/selector.h" #include "Algo/Decimation/selector.h"
#include "Container/fakeAttribute.h"
#include "Utils/qem.h"
#include "Utils/quadricRGBfunctions.h"
#include "Algo/Geometry/curvature.h"
namespace CGoGN namespace CGoGN
{ {
...@@ -246,12 +251,17 @@ private: ...@@ -246,12 +251,17 @@ private:
} CurvatureEdgeInfo ; } CurvatureEdgeInfo ;
typedef NoMathIOAttribute<CurvatureEdgeInfo> EdgeInfo ; typedef NoMathIOAttribute<CurvatureEdgeInfo> EdgeInfo ;
Geom::BoundingBox<VEC3> bb ;
REAL radius ;
typename PFP::TVEC3 normal ; typename PFP::TVEC3 normal ;
AttributeHandler<EdgeInfo> edgeInfo ; AttributeHandler<EdgeInfo> edgeInfo ;
typename PFP::TREAL k1 ; typename PFP::TREAL edgeangle ;
typename PFP::TREAL k2 ; typename PFP::TREAL kmax ;
typename PFP::TVEC3 K1 ; typename PFP::TREAL kmin ;
typename PFP::TVEC3 K2 ; typename PFP::TVEC3 Kmax ;
typename PFP::TVEC3 Kmin ;
typename PFP::TVEC3 Knormal ;
std::multimap<float,Dart> edges ; std::multimap<float,Dart> edges ;
typename std::multimap<float,Dart>::iterator cur ; typename std::multimap<float,Dart>::iterator cur ;
...@@ -266,6 +276,9 @@ public: ...@@ -266,6 +276,9 @@ public:
EdgeSelector_Curvature(MAP& m, typename PFP::TVEC3& pos, std::vector<ApproximatorGen<PFP>*>& approx, const FunctorSelect& select = SelectorTrue()) : EdgeSelector_Curvature(MAP& m, typename PFP::TVEC3& pos, std::vector<ApproximatorGen<PFP>*>& approx, const FunctorSelect& select = SelectorTrue()) :
EdgeSelector<PFP>(m, pos, approx, select) EdgeSelector<PFP>(m, pos, approx, select)
{ {
bb = Algo::Geometry::computeBoundingBox<PFP>(m, pos) ;
radius = bb.diagSize() * 0.003 ;
normal = m.template getAttribute<VEC3>(VERTEX, "normal") ; normal = m.template getAttribute<VEC3>(VERTEX, "normal") ;
if(!normal.isValid()) if(!normal.isValid())
{ {
...@@ -273,29 +286,40 @@ public: ...@@ -273,29 +286,40 @@ public:
Algo::Geometry::computeNormalVertices<PFP>(m, pos, normal) ; Algo::Geometry::computeNormalVertices<PFP>(m, pos, normal) ;
} }
k1 = m.template getAttribute<REAL>(VERTEX, "k1") ; edgeangle = m.template getAttribute<REAL>(VERTEX, "edgeangle") ;
k2 = m.template getAttribute<REAL>(VERTEX, "k2") ; if(!edgeangle.isValid())
K1 = m.template getAttribute<VEC3>(VERTEX, "K1") ; {
K2 = m.template getAttribute<VEC3>(VERTEX, "K2") ; edgeangle = m.template addAttribute<REAL>(EDGE, "edgeangle") ;
Algo::Geometry::computeAnglesBetweenNormalsOnEdges<PFP>(m, pos, edgeangle) ;
}
kmax = m.template getAttribute<REAL>(VERTEX, "kmax") ;
kmin = m.template getAttribute<REAL>(VERTEX, "kmin") ;
Kmax = m.template getAttribute<VEC3>(VERTEX, "Kmax") ;
Kmin = m.template getAttribute<VEC3>(VERTEX, "Kmin") ;
Knormal = m.template getAttribute<VEC3>(VERTEX, "Knormal") ;
// as all these attributes are computed simultaneously by computeCurvatureVertices // as all these attributes are computed simultaneously by computeCurvatureVertices
// one can assume that if one of them is not valid, the others must be created too // one can assume that if one of them is not valid, the others must be created too
if(!k1.isValid()) if(!kmax.isValid())
{ {
k1 = m.template addAttribute<REAL>(VERTEX, "k1") ; kmax = m.template addAttribute<REAL>(VERTEX, "kmax") ;
k2 = m.template addAttribute<REAL>(VERTEX, "k2") ; kmin = m.template addAttribute<REAL>(VERTEX, "kmin") ;
K1 = m.template addAttribute<VEC3>(VERTEX, "K1") ; Kmax = m.template addAttribute<VEC3>(VERTEX, "Kmax") ;
K2 = m.template addAttribute<VEC3>(VERTEX, "K2") ; Kmin = m.template addAttribute<VEC3>(VERTEX, "Kmin") ;
Algo::Geometry::computeCurvatureVertices<PFP>(m, this->m_position, normal, k1, k2, K1, K2) ; Knormal = m.template addAttribute<VEC3>(VERTEX, "Knormal") ;
Algo::Geometry::computeCurvatureVertices_NormalCycles<PFP>(m, radius, pos, normal, edgeangle, kmax, kmin, Kmax, Kmin, Knormal) ;
} }
edgeInfo = m.template addAttribute<EdgeInfo>(EDGE, "edgeInfo") ; edgeInfo = m.template addAttribute<EdgeInfo>(EDGE, "edgeInfo") ;
} }
~EdgeSelector_Curvature() ~EdgeSelector_Curvature()
{ {
this->m_map.removeAttribute(k1) ; this->m_map.removeAttribute(edgeangle) ;
this->m_map.removeAttribute(k2) ; this->m_map.removeAttribute(kmax) ;
this->m_map.removeAttribute(K1) ; this->m_map.removeAttribute(kmin) ;
this->m_map.removeAttribute(K2) ; this->m_map.removeAttribute(Kmax) ;
this->m_map.removeAttribute(Kmin) ;
this->m_map.removeAttribute(Knormal) ;
this->m_map.removeAttribute(edgeInfo) ; this->m_map.removeAttribute(edgeInfo) ;
} }
SelectorType getType() { return S_Curvature ; } SelectorType getType() { return S_Curvature ; }
......
...@@ -795,14 +795,14 @@ void EdgeSelector_Curvature<PFP>::updateAfterCollapse(Dart d2, Dart dd2) ...@@ -795,14 +795,14 @@ void EdgeSelector_Curvature<PFP>::updateAfterCollapse(Dart d2, Dart dd2)
MAP& m = this->m_map ; MAP& m = this->m_map ;
normal[d2] = Algo::Geometry::vertexNormal<PFP>(m, d2, this->m_position) ; normal[d2] = Algo::Geometry::vertexNormal<PFP>(m, d2, this->m_position) ;
Algo::Geometry::computeCurvatureVertex<PFP>(m, d2, this->m_position, normal, k1, k2, K1, K2) ; Algo::Geometry::computeCurvatureVertex_NormalCycles<PFP>(m, d2, radius, this->m_position, normal, edgeangle, kmax, kmin, Kmax, Kmin, Knormal) ;
Dart vit = d2 ; Dart vit = d2 ;
do do
{ {
Dart nVert = m.phi1(vit) ; Dart nVert = m.phi1(vit) ;
normal[nVert] = Algo::Geometry::vertexNormal<PFP>(m, nVert, this->m_position) ; normal[nVert] = Algo::Geometry::vertexNormal<PFP>(m, nVert, this->m_position) ;
Algo::Geometry::computeCurvatureVertex<PFP>(m, nVert, this->m_position, normal, k1, k2, K1, K2) ; Algo::Geometry::computeCurvatureVertex_NormalCycles<PFP>(m, nVert, radius, this->m_position, normal, edgeangle, kmax, kmin, Kmax, Kmin, Knormal) ;
updateEdgeInfo(m.phi1(vit), false) ; // must recompute some edge infos in the updateEdgeInfo(m.phi1(vit), false) ; // must recompute some edge infos in the
if(vit == d2 || vit == dd2) // neighborhood of the collapsed edge if(vit == d2 || vit == dd2) // neighborhood of the collapsed edge
...@@ -891,11 +891,11 @@ void EdgeSelector_Curvature<PFP>::computeEdgeInfo(Dart d, EdgeInfo& einfo) ...@@ -891,11 +891,11 @@ void EdgeSelector_Curvature<PFP>::computeEdgeInfo(Dart d, EdgeInfo& einfo)
// compute things on the coarse version of the mesh // compute things on the coarse version of the mesh
normal[newV] = Algo::Geometry::vertexNormal<PFP>(m, d2, this->m_position) ; normal[newV] = Algo::Geometry::vertexNormal<PFP>(m, d2, this->m_position) ;
Algo::Geometry::computeCurvatureVertex<PFP>(m, d2, this->m_position, normal, k1, k2, K1, K2) ; Algo::Geometry::computeCurvatureVertex_NormalCycles<PFP>(m, d2, radius, this->m_position, normal, edgeangle, kmax, kmin, Kmax, Kmin, Knormal) ;
VEC3 norm = normal[newV] ; // VEC3 norm = normal[newV] ;
REAL mCurv = ( k1[newV] + k2[newV] ) / REAL(2) ; REAL mCurv = (kmax[newV] + kmin[newV]) / REAL(2) ;
VEC3 cDir1 = K1[newV] ; // VEC3 cDir1 = Kmax[newV] ;
// vertex split to reset the initial connectivity and embeddings // vertex split to reset the initial connectivity and embeddings
m.insertTrianglePair(d, d2, dd2) ; m.insertTrianglePair(d, d2, dd2) ;
...@@ -904,17 +904,17 @@ void EdgeSelector_Curvature<PFP>::computeEdgeInfo(Dart d, EdgeInfo& einfo) ...@@ -904,17 +904,17 @@ void EdgeSelector_Curvature<PFP>::computeEdgeInfo(Dart d, EdgeInfo& einfo)
REAL err = 0 ; REAL err = 0 ;
REAL norm_deviation_1 = REAL(1) / abs(norm * normal[v1]) ; // REAL norm_deviation_1 = REAL(1) / abs(norm * normal[v1]) ;
REAL norm_deviation_2 = REAL(1) / abs(norm * normal[v2]) ; // REAL norm_deviation_2 = REAL(1) / abs(norm * normal[v2]) ;
err += norm_deviation_1 + norm_deviation_2 ; // err += norm_deviation_1 + norm_deviation_2 ;
REAL mCurv_deviation_1 = abs(mCurv - (k1[v1] + k2[v1] / REAL(2))) ; REAL mCurv_deviation_1 = abs(mCurv - (kmax[v1] + kmin[v1] / REAL(2))) ;
REAL mCurv_deviation_2 = abs(mCurv - (k1[v2] + k2[v2] / REAL(2))) ; REAL mCurv_deviation_2 = abs(mCurv - (kmax[v2] + kmin[v2] / REAL(2))) ;
err += mCurv_deviation_1 + mCurv_deviation_2 ; err += mCurv_deviation_1 + mCurv_deviation_2 ;
REAL cDir1_deviation_1 = REAL(1) / abs(cDir1 * K1[v1]) ; // REAL cDir1_deviation_1 = REAL(1) / abs(cDir1 * Kmax[v1]) ;
REAL cDir1_deviation_2 = REAL(1) / abs(cDir1 * K1[v2]) ; // REAL cDir1_deviation_2 = REAL(1) / abs(cDir1 * Kmax[v2]) ;
err += cDir1_deviation_1 + cDir1_deviation_2 ; // err += cDir1_deviation_1 + cDir1_deviation_2 ;
einfo.it = edges.insert(std::make_pair(err, d)) ; einfo.it = edges.insert(std::make_pair(err, d)) ;
einfo.valid = true ; einfo.valid = true ;
......
...@@ -25,11 +25,6 @@ ...@@ -25,11 +25,6 @@
#ifndef __SELECTOR_H__ #ifndef __SELECTOR_H__
#define __SELECTOR_H__ #define __SELECTOR_H__
#include "Utils/qem.h"
#include "Utils/quadricRGBfunctions.h"
#include "Container/fakeAttribute.h"
#include "Algo/Geometry/curvature.h"
namespace CGoGN namespace CGoGN
{ {
...@@ -39,7 +34,6 @@ namespace Algo ...@@ -39,7 +34,6 @@ namespace Algo
namespace Decimation namespace Decimation
{ {
enum SelectorType enum SelectorType
{ {
S_MapOrder, S_MapOrder,
...@@ -53,11 +47,9 @@ enum SelectorType ...@@ -53,11 +47,9 @@ enum SelectorType
S_hLightfield S_hLightfield
} ; } ;
template <typename PFP> class ApproximatorGen ; template <typename PFP> class ApproximatorGen ;
template <typename PFP, typename T> class Approximator ; template <typename PFP, typename T> class Approximator ;
template <typename PFP> template <typename PFP>
class EdgeSelector class EdgeSelector
{ {
...@@ -91,5 +83,4 @@ public: ...@@ -91,5 +83,4 @@ public:
} // namespace CGoGN } // namespace CGoGN
#endif #endif
...@@ -67,11 +67,10 @@ EMB volumeCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs) ...@@ -67,11 +67,10 @@ EMB volumeCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs)
std::vector<Dart> visitedFaces; // Faces that are traversed std::vector<Dart> visitedFaces; // Faces that are traversed
visitedFaces.reserve(100); visitedFaces.reserve(100);
visitedFaces.push_back(d); // Start with the face of d visitedFaces.push_back(d); // Start with the face of d
std::vector<Dart>::iterator face;
mark.markOrbit(VERTEX, d) ; mark.markOrbit(VERTEX, d) ;
for(face = visitedFaces.begin(); face != visitedFaces.end(); ++face) for(std::vector<Dart>::iterator face = visitedFaces.begin(); face != visitedFaces.end(); ++face)
{ {
Dart e = *face ; Dart e = *face ;
...@@ -90,7 +89,6 @@ EMB volumeCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs) ...@@ -90,7 +89,6 @@ EMB volumeCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs)
} while(e != *face) ; } while(e != *face) ;
} }
center /= double(count) ; center /= double(count) ;
return center ; return center ;
} }
......
...@@ -95,7 +95,7 @@ void computeCurvatureVertices_NormalCycles( ...@@ -95,7 +95,7 @@ void computeCurvatureVertices_NormalCycles(
typename PFP::REAL radius, typename PFP::REAL radius,
const typename PFP::TVEC3& position, const typename PFP::TVEC3& position,
const typename PFP::TVEC3& normal, const typename PFP::TVEC3& normal,
const typename PFP::TREAL& angles, const typename PFP::TREAL& edgeangle,
typename PFP::TREAL& kmax, typename PFP::TREAL& kmax,
typename PFP::TREAL& kmin, typename PFP::TREAL& kmin,
typename PFP::TVEC3& Kmax, typename PFP::TVEC3& Kmax,
...@@ -110,7 +110,7 @@ void computeCurvatureVertex_NormalCycles( ...@@ -110,7 +110,7 @@ void computeCurvatureVertex_NormalCycles(
typename PFP::REAL radius, typename PFP::REAL radius,
const typename PFP::TVEC3& position, const typename PFP::TVEC3& position,
const typename PFP::TVEC3& normal, const typename PFP::TVEC3& normal,
const typename PFP::TREAL& angles, const typename PFP::TREAL& edgeangle,
typename PFP::TREAL& kmax, typename PFP::TREAL& kmax,
typename PFP::TREAL& kmin, typename PFP::TREAL& kmin,
typename PFP::TVEC3& Kmax, typename PFP::TVEC3& Kmax,
......
...@@ -304,7 +304,7 @@ void computeCurvatureVertices_NormalCycles( ...@@ -304,7 +304,7 @@ void computeCurvatureVertices_NormalCycles(
typename PFP::REAL radius, typename PFP::REAL radius,
const typename PFP::TVEC3& position, const typename PFP::TVEC3& position,
const typename PFP::TVEC3& normal, const typename PFP::TVEC3& normal,
const typename PFP::TREAL& angles, const typename PFP::TREAL& edgeangle,
typename PFP::TREAL& kmax, typename PFP::TREAL& kmax,
typename PFP::TREAL& kmin, typename PFP::TREAL& kmin,
typename PFP::TVEC3& Kmax, typename PFP::TVEC3& Kmax,
...@@ -318,7 +318,7 @@ void computeCurvatureVertices_NormalCycles( ...@@ -318,7 +318,7 @@ void computeCurvatureVertices_NormalCycles(
if(select(d) && !marker.isMarked(d)) if(select(d) && !marker.isMarked(d))
{ {
marker.mark(d); marker.mark(d);
computeCurvatureVertex_NormalCycles<PFP>(map, d, radius, position, normal, angles, kmax, kmin, Kmax, Kmin, Knormal) ; computeCurvatureVertex_NormalCycles<PFP>(map, d, radius, position, normal, edgeangle, kmax, kmin, Kmax, Kmin, Knormal) ;
} }
} }
} }
...@@ -330,7 +330,7 @@ void computeCurvatureVertex_NormalCycles( ...@@ -330,7 +330,7 @@ void computeCurvatureVertex_NormalCycles(
typename PFP::REAL radius, typename PFP::REAL radius,
const typename PFP::TVEC3& position, const typename PFP::TVEC3& position,
const typename PFP::TVEC3& normal, const typename PFP::TVEC3& normal,
const typename PFP::TREAL& angles, const typename PFP::TREAL& edgeangle,
typename PFP::TREAL& kmax, typename PFP::TREAL& kmax,
typename PFP::TREAL& kmin, typename PFP::TREAL& kmin,
typename PFP::TVEC3& Kmax, typename PFP::TVEC3& Kmax,
...@@ -354,16 +354,15 @@ void computeCurvatureVertex_NormalCycles( ...@@ -354,16 +354,15 @@ void computeCurvatureVertex_NormalCycles(
for (std::vector<Dart>::const_iterator it = vd1.begin(); it != vd1.end(); ++it) for (std::vector<Dart>::const_iterator it = vd1.begin(); it != vd1.end(); ++it)
{ {
const VEC3 e = position[map.phi2(*it)] - position[*it] ; const VEC3 e = position[map.phi2(*it)] - position[*it] ;
tensor += Geom::transposed_vectors_mult(e,e) * angles[*it] * (1 / e.norm()) ; tensor += Geom::transposed_vectors_mult(e,e) * edgeangle[*it] * (1 / e.norm()) ;
} }
// border // border
const std::vector<Dart>& vd2 = neigh.getBorder() ; const std::vector<Dart>& vd2 = neigh.getBorder() ;
for (std::vector<Dart>::const_iterator it = vd2.begin(); it != vd2.end(); ++it) for (std::vector<Dart>::const_iterator it = vd2.begin(); it != vd2.end(); ++it)
{ {
const VEC3 e = position[map.phi2(*it)] - position[*it] ; const VEC3 e = position[map.phi2(*it)] - position[*it] ;
const REAL alpha = neigh.intersect_SphereEdge(*it, map.phi2(*it)) ; const REAL alpha = neigh.intersect_SphereEdge(*it, map.phi2(*it)) ;
tensor += Geom::transposed_vectors_mult(e,e) * angles[*it] * (1 / e.norm()) * alpha ; tensor += Geom::transposed_vectors_mult(e,e) * edgeangle[*it] * (1 / e.norm()) * alpha ;
} }
tensor /= neigh.getArea() ; tensor /= neigh.getArea() ;
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "Geometry/basic.h" #include "Geometry/basic.h"
#include "Geometry/intersection.h" #include "Geometry/intersection.h"
#include "Geometry/inclusion.h"
namespace CGoGN namespace CGoGN
{ {
...@@ -75,11 +76,17 @@ bool intersectionSegmentConvexFace(typename PFP::MAP& map, Dart d, const typenam ...@@ -75,11 +76,17 @@ bool intersectionSegmentConvexFace(typename PFP::MAP& map, Dart d, const typenam
template <typename PFP> template <typename PFP>
bool areTrianglesInIntersection(typename PFP::MAP& map, Dart tri1, Dart tri2, const typename PFP::TVEC3& positions) ; bool areTrianglesInIntersection(typename PFP::MAP& map, Dart tri1, Dart tri2, const typename PFP::TVEC3& positions) ;
} /**
*
*/
template <typename PFP>
bool intersectionSphereEdge(typename PFP::MAP& map, typename PFP::VEC3& center, typename PFP::REAL radius, Dart d, const typename PFP::TVEC3& positions, typename PFP::REAL& alpha) ;
} // namespace Geometry
} } // namespace Algo
} } // namespace CGoGN
#include "Algo/Geometry/intersection.hpp" #include "Algo/Geometry/intersection.hpp"
......
...@@ -46,10 +46,10 @@ bool intersectionLineConvexFace(typename PFP::MAP& map, Dart d, const typename P ...@@ -46,10 +46,10 @@ bool intersectionLineConvexFace(typename PFP::MAP& map, Dart d, const typename P
const float SMALL_NUM = std::numeric_limits<typename PFP::REAL>::min() * 5.0f; const float SMALL_NUM = std::numeric_limits<typename PFP::REAL>::min() * 5.0f;
VEC3 p1 = positions[d]; VEC3 p1 = positions[d];
VEC3 n = faceNormal<PFP>(map,d,positions); VEC3 n = faceNormal<PFP>(map, d, positions);
VEC3 w0 = P - p1; VEC3 w0 = P - p1;
float a = -(n*w0); float a = -(n * w0);
float b = n*Dir; float b = n * Dir;
if (fabs(b) < SMALL_NUM) if (fabs(b) < SMALL_NUM)
return false; return false;
...@@ -225,8 +225,25 @@ bool areTrianglesInIntersection(typename PFP::MAP& map, Dart tri1, Dart tri2, co ...@@ -225,8 +225,25 @@ bool areTrianglesInIntersection(typename PFP::MAP& map, Dart tri1, Dart tri2, co
return intersection; return intersection;
} }
template <typename PFP>
bool intersectionSphereEdge(typename PFP::MAP& map, typename PFP::VEC3& center, typename PFP::REAL radius, Dart d, const typename PFP::TVEC3& positions, typename PFP::REAL& alpha)
{
typename PFP::VEC3& p1 = position[d];
typename PFP::VEC3& p2 = position[map.phi1(d)];
if(Geom::isPointInSphere(p1, center, radius) && !Geom::isPointInSphere(p2, center, radius))
{
VEC3 p = p1 - center;
VEC3 qminusp = p2 - center - p;
REAL s = p * qminusp;
REAL n2 = qminusp.norm2();
alpha = (- s + sqrt(s*s + n2 * (radius*radius - p.norm2()))) / n2;
return true ;
}
return false ;
} }
} } // namespace Geometry
} } // namespace Algo
} // namespace CGoGN
...@@ -42,8 +42,9 @@ namespace Selection ...@@ -42,8 +42,9 @@ namespace Selection
{ {
/********************************************************* /*********************************************************
* Collector * Generic Collector
*********************************************************/ *********************************************************/
template <typename PFP> template <typename PFP>
class Collector class Collector
{ {
...@@ -69,6 +70,8 @@ public: ...@@ -69,6 +70,8 @@ public:
virtual void collect() = 0; virtual void collect() = 0;
bool apply(FunctorType& f);
void sort() void sort()
{ {
std::sort(insideVertices.begin(), insideVertices.end()); std::sort(insideVertices.begin(), insideVertices.end());
...@@ -135,6 +138,7 @@ protected: ...@@ -135,6 +138,7 @@ protected:
typename PFP::REAL radius_2; typename PFP::REAL radius_2;
typename PFP::VEC3 centerPosition; typename PFP::VEC3 centerPosition;
typename PFP::REAL area; typename PFP::REAL area;
public: public:
Collector_WithinSphere(typename PFP::MAP& mymap, const typename PFP::TVEC3& myposition) : Collector_WithinSphere(typename PFP::MAP& mymap, const typename PFP::TVEC3& myposition) :
Collector<PFP>(mymap,myposition) Collector<PFP>(mymap,myposition)
......
...@@ -31,15 +31,25 @@ namespace Algo ...@@ -31,15 +31,25 @@ namespace Algo
namespace Selection namespace Selection
{ {
/******************************************** /*********************************************************
* GENERIC COLLECTOR * Generic Collector
********************************************/ *********************************************************/
template <typename PFP> template <typename PFP>
Collector<PFP>::Collector(typename PFP::MAP& mymap, const typename PFP::TVEC3& myposition): Collector<PFP>::Collector(typename PFP::MAP& mymap, const typename PFP::TVEC3& myposition):
map(mymap), map(mymap),
position(myposition) position(myposition)
{} {}
template <typename PFP>
bool Collector<PFP>::apply(FunctorType& f)
{
for(std::vector<Dart>::iterator iv = insideVertices.begin(); iv != insideVertices.end(); ++iv)
if(f(*iv))
return true ;
return false ;
}
template <typename PPFP> template <typename PPFP>
std::ostream& operator<<(std::ostream &out, const Collector<PPFP>& c) std::ostream& operator<<(std::ostream &out, const Collector<PPFP>& c)
{ {
...@@ -121,6 +131,7 @@ void Collector_WithinSphere<PFP>::collect() ...@@ -121,6 +131,7 @@ void Collector_WithinSphere<PFP>::collect()
vm.mark(this->centerDart); vm.mark(this->centerDart);
unsigned int i = 0; unsigned int i = 0;
// for(std::vector<Dart>::iterator iv = this->insideVertices.begin(); iv != this->insideVertices.end(); ++iv)
while (i < this->insideVertices.size()) while (i < this->insideVertices.size())
{ {
Dart end = this->insideVertices[i]; Dart end = this->insideVertices[i];
...@@ -132,7 +143,7 @@ void Collector_WithinSphere<PFP>::collect() ...@@ -132,7 +143,7 @@ void Collector_WithinSphere<PFP>::collect()
const Dart f = this->map.phi1(e); const Dart f = this->map.phi1(e);
const Dart g = this->map.phi1(f); const Dart g = this->map.phi1(f);
if (!this->isInside(f)) if (! this->isInside(f))
{ {
this->border.push_back(e); // add to border this->border.push_back(e); // add to border
em.mark(e); em.mark(e);
...@@ -163,17 +174,17 @@ void Collector_WithinSphere<PFP>::collect() ...@@ -163,17 +174,17 @@ void Collector_WithinSphere<PFP>::collect()
} }
} }
template <typename PFP> //template <typename PFP>
typename PFP::REAL Collector_WithinSphere<PFP>::intersect_SphereEdge(const Dart din, const Dart dout) //typename PFP::REAL Collector_WithinSphere<PFP>::intersect_SphereEdge(const Dart din, const Dart dout)
{ //{
typedef typename PFP::VEC3 VEC3; // typedef typename PFP::VEC3 VEC3;
typedef typename PFP::REAL REAL; // typedef typename PFP::REAL REAL;
VEC3 p = this->position[din] - this->centerPosition; // VEC3 p = this->position[din] - this->centerPosition;
VEC3 qminusp = this->position[dout] - this->centerPosition - p; // VEC3 qminusp = this->position[dout] - this->centerPosition - p;
REAL s = p*qminusp; // REAL s = p * qminusp;