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)
m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::TRIANGLES) ;
bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position) ;
gPosObj = bb.center() ;
normalBaseSize = bb.diagSize() / 100.0f ;
vertexBaseSize = normalBaseSize * 2.0f ;
......@@ -198,7 +197,7 @@ void Viewer::importMesh(std::string& filename)
m_positionVBO->updateData(position) ;
m_normalVBO->updateData(normal) ;
setParamObject(bb.maxSize(), gPosObj.data()) ;
setParamObject(bb.maxSize(), bb.center().data()) ;
updateGLMatrices() ;
}
......
......@@ -78,7 +78,6 @@ public:
float shininess ;
Geom::BoundingBox<PFP::VEC3> bb ;
Geom::Vec3f gPosObj ;
float normalBaseSize ;
float normalScaleFactor ;
float vertexBaseSize ;
......
......@@ -27,6 +27,11 @@
#include "Algo/Decimation/selector.h"
#include "Container/fakeAttribute.h"
#include "Utils/qem.h"
#include "Utils/quadricRGBfunctions.h"
#include "Algo/Geometry/curvature.h"
namespace CGoGN
{
......@@ -246,12 +251,17 @@ private:
} CurvatureEdgeInfo ;
typedef NoMathIOAttribute<CurvatureEdgeInfo> EdgeInfo ;
Geom::BoundingBox<VEC3> bb ;
REAL radius ;
typename PFP::TVEC3 normal ;
AttributeHandler<EdgeInfo> edgeInfo ;
typename PFP::TREAL k1 ;
typename PFP::TREAL k2 ;
typename PFP::TVEC3 K1 ;
typename PFP::TVEC3 K2 ;
typename PFP::TREAL edgeangle ;
typename PFP::TREAL kmax ;
typename PFP::TREAL kmin ;
typename PFP::TVEC3 Kmax ;
typename PFP::TVEC3 Kmin ;
typename PFP::TVEC3 Knormal ;
std::multimap<float,Dart> edges ;
typename std::multimap<float,Dart>::iterator cur ;
......@@ -266,6 +276,9 @@ public:
EdgeSelector_Curvature(MAP& m, typename PFP::TVEC3& pos, std::vector<ApproximatorGen<PFP>*>& approx, const FunctorSelect& select = SelectorTrue()) :
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") ;
if(!normal.isValid())
{
......@@ -273,29 +286,40 @@ public:
Algo::Geometry::computeNormalVertices<PFP>(m, pos, normal) ;
}
k1 = m.template getAttribute<REAL>(VERTEX, "k1") ;
k2 = m.template getAttribute<REAL>(VERTEX, "k2") ;
K1 = m.template getAttribute<VEC3>(VERTEX, "K1") ;
K2 = m.template getAttribute<VEC3>(VERTEX, "K2") ;
edgeangle = m.template getAttribute<REAL>(VERTEX, "edgeangle") ;
if(!edgeangle.isValid())
{
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
// 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") ;
k2 = m.template addAttribute<REAL>(VERTEX, "k2") ;
K1 = m.template addAttribute<VEC3>(VERTEX, "K1") ;
K2 = m.template addAttribute<VEC3>(VERTEX, "K2") ;
Algo::Geometry::computeCurvatureVertices<PFP>(m, this->m_position, normal, k1, k2, K1, K2) ;
kmax = m.template addAttribute<REAL>(VERTEX, "kmax") ;
kmin = m.template addAttribute<REAL>(VERTEX, "kmin") ;
Kmax = m.template addAttribute<VEC3>(VERTEX, "Kmax") ;
Kmin = m.template addAttribute<VEC3>(VERTEX, "Kmin") ;
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") ;
}
~EdgeSelector_Curvature()
{
this->m_map.removeAttribute(k1) ;
this->m_map.removeAttribute(k2) ;
this->m_map.removeAttribute(K1) ;
this->m_map.removeAttribute(K2) ;
this->m_map.removeAttribute(edgeangle) ;
this->m_map.removeAttribute(kmax) ;
this->m_map.removeAttribute(kmin) ;
this->m_map.removeAttribute(Kmax) ;
this->m_map.removeAttribute(Kmin) ;
this->m_map.removeAttribute(Knormal) ;
this->m_map.removeAttribute(edgeInfo) ;
}
SelectorType getType() { return S_Curvature ; }
......
......@@ -795,14 +795,14 @@ void EdgeSelector_Curvature<PFP>::updateAfterCollapse(Dart d2, Dart dd2)
MAP& m = this->m_map ;
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 ;
do
{
Dart nVert = m.phi1(vit) ;
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
if(vit == d2 || vit == dd2) // neighborhood of the collapsed edge
......@@ -891,11 +891,11 @@ void EdgeSelector_Curvature<PFP>::computeEdgeInfo(Dart d, EdgeInfo& einfo)
// compute things on the coarse version of the mesh
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] ;
REAL mCurv = ( k1[newV] + k2[newV] ) / REAL(2) ;
VEC3 cDir1 = K1[newV] ;
// VEC3 norm = normal[newV] ;
REAL mCurv = (kmax[newV] + kmin[newV]) / REAL(2) ;
// VEC3 cDir1 = Kmax[newV] ;
// vertex split to reset the initial connectivity and embeddings
m.insertTrianglePair(d, d2, dd2) ;
......@@ -904,17 +904,17 @@ void EdgeSelector_Curvature<PFP>::computeEdgeInfo(Dart d, EdgeInfo& einfo)
REAL err = 0 ;
REAL norm_deviation_1 = REAL(1) / abs(norm * normal[v1]) ;
REAL norm_deviation_2 = REAL(1) / abs(norm * normal[v2]) ;
err += norm_deviation_1 + norm_deviation_2 ;
// REAL norm_deviation_1 = REAL(1) / abs(norm * normal[v1]) ;
// REAL norm_deviation_2 = REAL(1) / abs(norm * normal[v2]) ;
// err += norm_deviation_1 + norm_deviation_2 ;
REAL mCurv_deviation_1 = abs(mCurv - (k1[v1] + k2[v1] / REAL(2))) ;
REAL mCurv_deviation_2 = abs(mCurv - (k1[v2] + k2[v2] / REAL(2))) ;
REAL mCurv_deviation_1 = abs(mCurv - (kmax[v1] + kmin[v1] / REAL(2))) ;
REAL mCurv_deviation_2 = abs(mCurv - (kmax[v2] + kmin[v2] / REAL(2))) ;
err += mCurv_deviation_1 + mCurv_deviation_2 ;
REAL cDir1_deviation_1 = REAL(1) / abs(cDir1 * K1[v1]) ;
REAL cDir1_deviation_2 = REAL(1) / abs(cDir1 * K1[v2]) ;
err += cDir1_deviation_1 + cDir1_deviation_2 ;
// REAL cDir1_deviation_1 = REAL(1) / abs(cDir1 * Kmax[v1]) ;
// REAL cDir1_deviation_2 = REAL(1) / abs(cDir1 * Kmax[v2]) ;
// err += cDir1_deviation_1 + cDir1_deviation_2 ;
einfo.it = edges.insert(std::make_pair(err, d)) ;
einfo.valid = true ;
......
......@@ -25,11 +25,6 @@
#ifndef __SELECTOR_H__
#define __SELECTOR_H__
#include "Utils/qem.h"
#include "Utils/quadricRGBfunctions.h"
#include "Container/fakeAttribute.h"
#include "Algo/Geometry/curvature.h"
namespace CGoGN
{
......@@ -39,7 +34,6 @@ namespace Algo
namespace Decimation
{
enum SelectorType
{
S_MapOrder,
......@@ -53,11 +47,9 @@ enum SelectorType
S_hLightfield
} ;
template <typename PFP> class ApproximatorGen ;
template <typename PFP, typename T> class Approximator ;
template <typename PFP>
class EdgeSelector
{
......@@ -91,5 +83,4 @@ public:
} // namespace CGoGN
#endif
......@@ -67,11 +67,10 @@ EMB volumeCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs)
std::vector<Dart> visitedFaces; // Faces that are traversed
visitedFaces.reserve(100);
visitedFaces.push_back(d); // Start with the face of d
std::vector<Dart>::iterator face;
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 ;
......@@ -90,7 +89,6 @@ EMB volumeCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs)
} while(e != *face) ;
}
center /= double(count) ;
return center ;
}
......
......@@ -95,7 +95,7 @@ void computeCurvatureVertices_NormalCycles(
typename PFP::REAL radius,
const typename PFP::TVEC3& position,
const typename PFP::TVEC3& normal,
const typename PFP::TREAL& angles,
const typename PFP::TREAL& edgeangle,
typename PFP::TREAL& kmax,
typename PFP::TREAL& kmin,
typename PFP::TVEC3& Kmax,
......@@ -110,7 +110,7 @@ void computeCurvatureVertex_NormalCycles(
typename PFP::REAL radius,
const typename PFP::TVEC3& position,
const typename PFP::TVEC3& normal,
const typename PFP::TREAL& angles,
const typename PFP::TREAL& edgeangle,
typename PFP::TREAL& kmax,
typename PFP::TREAL& kmin,
typename PFP::TVEC3& Kmax,
......
......@@ -304,7 +304,7 @@ void computeCurvatureVertices_NormalCycles(
typename PFP::REAL radius,
const typename PFP::TVEC3& position,
const typename PFP::TVEC3& normal,
const typename PFP::TREAL& angles,
const typename PFP::TREAL& edgeangle,
typename PFP::TREAL& kmax,
typename PFP::TREAL& kmin,
typename PFP::TVEC3& Kmax,
......@@ -318,7 +318,7 @@ void computeCurvatureVertices_NormalCycles(
if(select(d) && !marker.isMarked(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(
typename PFP::REAL radius,
const typename PFP::TVEC3& position,
const typename PFP::TVEC3& normal,
const typename PFP::TREAL& angles,
const typename PFP::TREAL& edgeangle,
typename PFP::TREAL& kmax,
typename PFP::TREAL& kmin,
typename PFP::TVEC3& Kmax,
......@@ -354,16 +354,15 @@ void computeCurvatureVertex_NormalCycles(
for (std::vector<Dart>::const_iterator it = vd1.begin(); it != vd1.end(); ++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
const std::vector<Dart>& vd2 = neigh.getBorder() ;
for (std::vector<Dart>::const_iterator it = vd2.begin(); it != vd2.end(); ++it)
{
const VEC3 e = position[map.phi2(*it)] - position[*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() ;
......
......@@ -27,6 +27,7 @@
#include "Geometry/basic.h"
#include "Geometry/intersection.h"
#include "Geometry/inclusion.h"
namespace CGoGN
{
......@@ -75,11 +76,17 @@ bool intersectionSegmentConvexFace(typename PFP::MAP& map, Dart d, const typenam
template <typename PFP>
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"
......
......@@ -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;
VEC3 p1 = positions[d];
VEC3 n = faceNormal<PFP>(map,d,positions);
VEC3 n = faceNormal<PFP>(map, d, positions);
VEC3 w0 = P - p1;
float a = -(n*w0);
float b = n*Dir;
float a = -(n * w0);
float b = n * Dir;
if (fabs(b) < SMALL_NUM)
return false;
......@@ -225,8 +225,25 @@ bool areTrianglesInIntersection(typename PFP::MAP& map, Dart tri1, Dart tri2, co
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
{
/*********************************************************
* Collector
* Generic Collector
*********************************************************/
template <typename PFP>
class Collector
{
......@@ -69,6 +70,8 @@ public:
virtual void collect() = 0;
bool apply(FunctorType& f);
void sort()
{
std::sort(insideVertices.begin(), insideVertices.end());
......@@ -135,6 +138,7 @@ protected:
typename PFP::REAL radius_2;
typename PFP::VEC3 centerPosition;
typename PFP::REAL area;
public:
Collector_WithinSphere(typename PFP::MAP& mymap, const typename PFP::TVEC3& myposition) :
Collector<PFP>(mymap,myposition)
......
......@@ -31,15 +31,25 @@ namespace Algo
namespace Selection
{
/********************************************
* GENERIC COLLECTOR
********************************************/
/*********************************************************
* Generic Collector
*********************************************************/
template <typename PFP>
Collector<PFP>::Collector(typename PFP::MAP& mymap, const typename PFP::TVEC3& myposition):
map(mymap),
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>
std::ostream& operator<<(std::ostream &out, const Collector<PPFP>& c)
{
......@@ -121,6 +131,7 @@ void Collector_WithinSphere<PFP>::collect()
vm.mark(this->centerDart);
unsigned int i = 0;
// for(std::vector<Dart>::iterator iv = this->insideVertices.begin(); iv != this->insideVertices.end(); ++iv)
while (i < this->insideVertices.size())
{
Dart end = this->insideVertices[i];
......@@ -132,7 +143,7 @@ void Collector_WithinSphere<PFP>::collect()
const Dart f = this->map.phi1(e);
const Dart g = this->map.phi1(f);
if (!this->isInside(f))
if (! this->isInside(f))
{
this->border.push_back(e); // add to border
em.mark(e);
......@@ -163,17 +174,17 @@ void Collector_WithinSphere<PFP>::collect()
}
}
template <typename PFP>
typename PFP::REAL Collector_WithinSphere<PFP>::intersect_SphereEdge(const Dart din, const Dart dout)
{
typedef typename PFP::VEC3 VEC3;
typedef typename PFP::REAL REAL;
VEC3 p = this->position[din] - this->centerPosition;
VEC3 qminusp = this->position[dout] - this->centerPosition - p;
REAL s = p*qminusp;
REAL n2 = qminusp.norm2();
return (- s + sqrt (s*s + n2*(this->radius_2 - p.norm2())))/(n2);
}
//template <typename PFP>
//typename PFP::REAL Collector_WithinSphere<PFP>::intersect_SphereEdge(const Dart din, const Dart dout)
//{
// typedef typename PFP::VEC3 VEC3;
// typedef typename PFP::REAL REAL;
// VEC3 p = this->position[din] - this->centerPosition;
// VEC3 qminusp = this->position[dout] - this->centerPosition - p;
// REAL s = p * qminusp;
// REAL n2 = qminusp.norm2();
// return (- s + sqrt(s * s + n2 * (this->radius_2 - p.norm2()))) / n2;
//}
template <typename PFP>
void Collector_WithinSphere<PFP>::computeArea()
......@@ -189,14 +200,14 @@ void Collector_WithinSphere<PFP>::computeArea()
const Dart g = this->map.phi1(f);
if (this->isInside(g))
{ // only f is outside
typename PFP::REAL alpha = this->intersect_SphereEdge (*it, f);
typename PFP::REAL beta = this->intersect_SphereEdge (g, f);
typename PFP::REAL alpha = this->intersect_SphereEdge(*it, f);
typename PFP::REAL beta = this->intersect_SphereEdge(g, f);
this->area += (alpha+beta - alpha*beta) * Algo::Geometry::triangleArea<PFP>(this->map, *it, this->position);
}
else
{ // f and g are outside
typename PFP::REAL alpha = this->intersect_SphereEdge (*it, f);
typename PFP::REAL beta = this->intersect_SphereEdge (*it, g);
typename PFP::REAL alpha = this->intersect_SphereEdge(*it, f);
typename PFP::REAL beta = this->intersect_SphereEdge(*it, g);
this->area += alpha * beta * Algo::Geometry::triangleArea<PFP>(this->map, *it, this->position);
}
}
......
......@@ -44,13 +44,13 @@ class FuncFaceInter: public FunctorMap<typename PFP::MAP>
{
typedef typename PFP::MAP MAP;
protected:
std::vector<Dart>& m_faces;
std::vector<typename PFP::VEC3>& m_Ipoints ;
const typename PFP::VEC3& m_A;
const typename PFP::VEC3& m_AB;
const typename PFP::TVEC3& m_positions;
public:
/**
* @param map the map
......@@ -64,7 +64,7 @@ public:
bool operator()(Dart d)
{
const typename PFP::VEC3& Ta = m_positions[d];//this->m_map.getVertexEmb(d)->getPosition();
const typename PFP::VEC3& Ta = m_positions[d];
Dart dd = this->m_map.phi1(d);
Dart ddd = this->m_map.phi1(dd);
......@@ -72,13 +72,13 @@ public:
do
{
// get back position of triangle Ta,Tb,Tc
const typename PFP::VEC3& Tb = m_positions[dd]; //this->m_map.getVertexEmb(dd)->getPosition();
const typename PFP::VEC3& Tc = m_positions[ddd]; //this->m_map.getVertexEmb(ddd)->getPosition();
const typename PFP::VEC3& Tb = m_positions[dd];
const typename PFP::VEC3& Tc = m_positions[ddd];
typename PFP::VEC3 I;
if (Geom::intersectionLineTriangle<typename PFP::VEC3>(m_A, m_AB, Ta, Tb, Tc, I))
{
m_faces.push_back(d);
m_Ipoints.push_back(I) ;
m_Ipoints.push_back(I);
notfound = false;
}
// next triangle if we are in polygon
......@@ -95,7 +95,6 @@ class FuncEdgeInter: public FunctorMap<typename PFP::MAP>
{
typedef typename PFP::MAP MAP;
protected:
std::vector<Dart>& m_edges;
const typename PFP::VEC3& m_A;
......@@ -103,6 +102,7 @@ protected:
float m_AB2;
float m_distMax;
const typename PFP::TVEC3& m_positions;
public:
/**
* @param map the map
......@@ -119,9 +119,9 @@ public:
bool operator()(Dart d)
{
// get back position of segment PQ
const typename PFP::VEC3& P = m_positions[d];//this->m_map.getVertexEmb(d)->getPosition();
const typename PFP::VEC3& P = m_positions[d];
Dart dd = this->m_map.phi1(d);
const typename PFP::VEC3& Q = m_positions[dd];//this->m_map.getVertexEmb(dd)->getPosition();
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);
......@@ -161,7 +161,7 @@ public:
bool operator()(Dart d)
{
const typename PFP::VEC3& P = m_positions[d];//this->m_map.getVertexEmb(d)->getPosition();
const typename PFP::VEC3& P = m_positions[d];
float dist = Geom::squaredDistanceLine2Point(m_A, m_AB, m_AB2, P);
if (dist < m_distMax)
{
......@@ -172,7 +172,7 @@ public:
};
/**
* Fonctor which store the dart that correspond to the subpart of face
* Functor which store the dart that correspond to the subpart of face
* that is intersected
* Must be called in foreachface
*/
......@@ -373,7 +373,6 @@ bool distnintOrdering(const std::pair<typename PFP::REAL, unsigned int>& e1, con
return (e1.first < e2.first);
}
} //namespace Selection
} //namespace Algo
......
......@@ -37,43 +37,44 @@ 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 vector of ray (directed ot the scene)
* @param vecFaces (out) vector to store dart of intersected faces
* @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<typename PFP>
void facesRaySelection(typename PFP::MAP& map, const typename PFP::TVEC3& position, const FunctorSelect& good, const typename PFP::VEC3& rayA, const typename PFP::VEC3& rayAB, std::vector<Dart>& vecFaces)
{
std::vector<typename PFP::VEC3> iPoints ;
std::vector<typename PFP::VEC3> iPoints;
// get back intersected faces
vecFaces.clear();
Algo::Selection::FuncFaceInter<PFP> ffi(map, position, vecFaces, iPoints, rayA, rayAB);
map.foreach_orbit(FACE, ffi, good);
// compute all distances to observer for each dart of intersected face
// compute all distances to observer for each intersected face
// and put them in a vector for sorting
typedef std::pair<typename PFP::REAL, Dart> DartDist;
std::vector<DartDist> distndart;
unsigned int nbi = vecFaces.size();
distndart.resize(nbi);
for (unsigned int i=0; i< nbi; ++i)
for (unsigned int i = 0; i < nbi; ++i)
{
distndart[i].second = vecFaces[i];
typename PFP::VEC3 V = iPoints[i] - rayA;
distndart[i].first = V*V;
distndart[i].first = V.norm2();
}
// sort the vector of pair dist/dart
std::sort(distndart.begin(), distndart.end(), distndartOrdering<PFP>);
// store sorted darts in returned vector
for (unsigned int i=0; i< nbi; ++i)
for (unsigned int i = 0; i < nbi; ++i)
vecFaces[i] = distndart[i].second;
}
......@@ -83,13 +84,13 @@ void facesRaySelection(typename PFP::MAP& map, const typename PFP::TVEC3& positi
* @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 cylinder modelling the edge
* @param dist radius of the cylinder of selection
*/
template<typename PFP>
void edgesRaySelection(typename PFP::MAP& map, const typename PFP::TVEC3& position, const FunctorSelect& good, const typename PFP::VEC3& rayA, const typename PFP::VEC3& rayAB, std::vector<Dart>& vecEdges, float dist)
{
typename PFP::REAL dist2 = dist*dist;
typename PFP::REAL AB2 =rayAB*rayAB;
typename PFP::REAL dist2 = dist * dist;
typename PFP::REAL AB2 = rayAB * rayAB;
// recuperation des aretes intersectees
vecEdges.clear();
......@@ -102,22 +103,22 @@ void edgesRaySelection(typename PFP::MAP& map, const typename PFP::TVEC3& positi
unsigned int nbi = vecEdges.size();
distndart.resize(nbi);
// compute all distances to observer for each dart of middle of edge
// 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)])/2.0;
typename PFP::VEC3 V = (position[d] + position[map.phi1(d)]) / typename PFP::REAL(2);
V -= rayA;
distndart[i].first = V*V;
distndart[i].first = V.norm2();
}
// sort the vector of pair dist/dart
std::sort(distndart.begin(), distndart.end(), distndartOrdering<PFP>);
// store sorted darts in returned vector
for (unsigned int i=0; i< nbi; ++i)