Commit e4da4b21 authored by Basile Sauvage's avatar Basile Sauvage

ajout de Collector_Vertices

parent 295fe9ec
......@@ -139,6 +139,7 @@ public:
* collect all primitives of the connected component containing "centerDart"
* within the sphere of radius "radius" and center "position[centerDart]"
* (hopefully) it defines a 2-manifold (if inserting border-vertices along the border-edges)
* NB : is equivalent to Collector_Vertices with CollectorCriterion_VertexWithinSphere
*/
template <typename PFP>
class Collector_WithinSphere : public Collector<PFP>
......@@ -174,6 +175,7 @@ public:
* collect all primitives of the connected component containing "centerDart"
* the angle between the included vertices normal vectors and the central normal vector
* stays under a given threshold
* NB : is equivalent to Collector_Vertices with CollectorCriterion_VertexNormalAngle
*/
template <typename PFP>
class Collector_NormalAngle : public Collector<PFP>
......@@ -198,6 +200,84 @@ public:
void collectBorder(Dart d) ;
};
/*********************************************************
* Collector Vertices
*********************************************************/
class CollectorCriterion
{
public :
CollectorCriterion() {};
virtual void init(Dart center) = 0;
virtual bool isInside(Dart d) = 0;
};
/*
* collect all vertices of the connected component containing "centerDart"
* within a distance to centerDart defined by the CollectorCriterion
* (hopefully) it defines a 2-manifold (if inserting border-vertices along the border-edges)
*/
template <typename PFP>
class Collector_Vertices : public Collector<PFP>
{
protected:
CollectorCriterion & crit;
public:
Collector_Vertices(typename PFP::MAP& m, CollectorCriterion& c, unsigned int thread=0) :
Collector<PFP>(m, thread),
crit(c)
{}
void collectAll(Dart d);
void collectBorder(Dart d);
};
/*********************************************************
* Collector Criterions
*********************************************************/
template <typename PFP>
class CollectorCriterion_VertexNormalAngle : public CollectorCriterion
{ // tests if the angle between vertex normals is below some threshold
private :
typedef typename PFP::VEC3 VEC3;
typedef typename PFP::REAL REAL;
const VertexAttribute<VEC3> & vertexNormals;
REAL threshold;
VEC3 centerNormal;
public :
CollectorCriterion_VertexNormalAngle(const VertexAttribute<VEC3> & n, REAL th) :
vertexNormals(n), threshold(th), centerNormal(0) {}
void init (Dart center) {centerNormal = vertexNormals[center];}
bool isInside (Dart d) {
return ( Geom::angle(centerNormal, vertexNormals[d]) < threshold);
}
};
template <typename PFP>
class CollectorCriterion_VertexWithinSphere : public CollectorCriterion
{ // tests if the distance between vertices is below some threshold
private :
typedef typename PFP::VEC3 VEC3;
typedef typename PFP::REAL REAL;
const VertexAttribute<VEC3> & vertexPositions;
REAL threshold;
VEC3 centerPosition;
public :
CollectorCriterion_VertexWithinSphere(const VertexAttribute<VEC3> & p, REAL th) :
vertexPositions(p), threshold(th), centerPosition(0) {}
void init (Dart center) {centerPosition = vertexPositions[center];}
bool isInside (Dart d) {
return (vertexPositions[d] - centerPosition).norm() < threshold ;
}
};
/*********************************************************
* Collector Normal Angle (Triangles)
*********************************************************/
......
......@@ -402,6 +402,121 @@ void Collector_NormalAngle<PFP>::collectBorder(Dart d)
this->insideVertices.clear();
}
/*********************************************************
* Collector Vertices
*********************************************************/
template <typename PFP>
void Collector_Vertices<PFP>::collectAll(Dart d)
{
typedef typename PFP::VEC3 VEC3;
typedef typename PFP::REAL REAL;
crit.init(d);
this->init(d);
this->insideEdges.reserve(32);
this->insideFaces.reserve(32);
this->border.reserve(32);
CellMarkerStore<VERTEX> vm(this->map, this->m_thread); // mark the collected inside-vertices
CellMarkerStore<EDGE> em(this->map, this->m_thread); // mark the collected inside-edges + border-edges
CellMarkerStore<FACE> fm(this->map, this->m_thread); // mark the collected inside-faces + border-faces
this->insideVertices.push_back(this->centerDart);
vm.mark(this->centerDart);
unsigned int i = 0;
while (i < this->insideVertices.size())
{
Dart end = this->insideVertices[i];
Dart e = end;
do
{
if (! em.isMarked(e) || ! fm.isMarked(e)) // are both tests useful ?
{
const Dart f = this->map.phi1(e);
const Dart g = this->map.phi1(f);
if (! crit.isInside(f))
{
this->border.push_back(e); // add to border
em.mark(e);
fm.mark(e); // is it useful ?
}
else
{
if (! vm.isMarked(f))
{
this->insideVertices.push_back(f);
vm.mark(f);
}
if (! em.isMarked(e))
{
this->insideEdges.push_back(e);
em.mark(e);
}
if (! fm.isMarked(e) && crit.isInside(g))
{
this->insideFaces.push_back(e);
fm.mark(e);
}
}
}
e = this->map.phi2_1(e);
} while (e != end);
++i;
}
}
template <typename PFP>
void Collector_Vertices<PFP>::collectBorder(Dart d)
{
typedef typename PFP::VEC3 VEC3;
typedef typename PFP::REAL REAL;
crit.init(d);
this->init(d);
this->border.reserve(128);
this->insideVertices.reserve(128);
CellMarkerStore<VERTEX> vm(this->map, this->m_thread); // mark the collected inside-vertices
CellMarkerStore<EDGE> em(this->map, this->m_thread); // mark the collected inside-edges + border-edges
this->insideVertices.push_back(this->centerDart);
vm.mark(this->centerDart);
unsigned int i = 0;
while (i < this->insideVertices.size())
{
Dart end = this->insideVertices[i];
Dart e = end;
do
{
if ( ! em.isMarked(e) )
{
const Dart f = this->map.phi1(e);
if (! crit.isInside(f))
{
this->border.push_back(e); // add to border
}
else
{
if (! vm.isMarked(f))
{
this->insideVertices.push_back(f);
vm.mark(f);
}
}
em.mark(e);
}
e = this->map.phi2_1(e);
} while (e != end);
++i;
}
this->insideVertices.clear();
}
/*********************************************************
* Collector Normal Angle (Triangles)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment