Commit 51b71885 authored by Basile Sauvage's avatar Basile Sauvage

ajout de collector_NormalAngle_Triangle

parent 2224c08d
......@@ -165,7 +165,7 @@ public:
};
/*********************************************************
* Collector Normal Angle
* Collector Normal Angle (Vertices)
*********************************************************/
/*
......@@ -177,27 +177,57 @@ template <typename PFP>
class Collector_NormalAngle : public Collector<PFP>
{
protected:
const VertexAttribute<typename PFP::VEC3>& position ;
const VertexAttribute<typename PFP::VEC3>& normal ;
typename PFP::REAL angleThreshold ;
public:
Collector_NormalAngle(
typename PFP::MAP& m,
const VertexAttribute<typename PFP::VEC3>& p,
const VertexAttribute<typename PFP::VEC3>& n,
typename PFP::REAL a
) : Collector<PFP>(m), position(p), normal(n), angleThreshold(a)
) : Collector<PFP>(m), normal(n), angleThreshold(a)
{}
inline void setAngleThreshold(typename PFP::REAL a) { angleThreshold = a; }
inline typename PFP::REAL getAngleThreshold() const { return angleThreshold; }
inline const VertexAttribute<typename PFP::VEC3>& getPosition() const { return position ; }
inline const VertexAttribute<typename PFP::VEC3>& getNormal() const { return normal ; }
void collectAll(Dart d) ;
void collectBorder(Dart d) ;
};
/*********************************************************
* Collector Normal Angle (Triangles)
*********************************************************/
/*
* collect all primitives of the connected component containing "centerDart"
* the angle between the included triangles normal vectors and the central normal vector
* stays under a given threshold
*/
template <typename PFP>
class Collector_NormalAngle_Triangles : public Collector<PFP>
{
protected:
const FaceAttribute<typename PFP::VEC3>& normal ;
typename PFP::REAL angleThreshold ;
public:
Collector_NormalAngle_Triangles(
typename PFP::MAP& m,
const FaceAttribute<typename PFP::VEC3>& n,
typename PFP::REAL a
) : Collector<PFP>(m), normal(n), angleThreshold(a)
{}
inline void setAngleThreshold(typename PFP::REAL a) { angleThreshold = a; }
inline typename PFP::REAL getAngleThreshold() const { return angleThreshold; }
inline const VertexAttribute<typename PFP::VEC3>& getNormal() const { return normal ; }
void collectAll(Dart d) ;
void collectBorder(Dart d) ;
};
} // namespace Selection
} // namespace Algo
......
......@@ -24,6 +24,7 @@
#include "Topology/generic/traversor2.h"
#include "Algo/Geometry/intersection.h"
#include <queue>
namespace CGoGN
{
......@@ -281,7 +282,7 @@ void Collector_WithinSphere<PFP>::computeArea()
}
/*********************************************************
* Collector Normal Angle
* Collector Normal Angle (Vertices)
*********************************************************/
template <typename PFP>
......@@ -401,6 +402,158 @@ void Collector_NormalAngle<PFP>::collectBorder(Dart d)
this->insideVertices.clear();
}
/*********************************************************
* Collector Normal Angle (Triangles)
*********************************************************/
template <typename PFP>
void Collector_NormalAngle_Triangles<PFP>::collectAll(Dart d)
{
typedef typename PFP::VEC3 VEC3;
typedef typename PFP::REAL REAL;
this->init(d);
this->insideEdges.reserve(32);
this->insideFaces.reserve(32);
this->border.reserve(32);
CellMarkerStore<FACE> fm(this->map); // mark the collected inside-faces + front-faces
CellMarkerStore<FACE> fminside(this->map); // mark the collected inside-faces
std::queue<Dart> front;
front.push(this->centerDart);
fm.mark(this->centerDart);
VEC3 centerNormal = this->normal[this->centerDart];
while ( !front.empty() ) // collect inside faces
{
Dart f = front.front();
front.pop();
REAL a = Geom::angle(centerNormal, this->normal[f]);
if (a < angleThreshold )
{ // collect this face and add adjacent faces to the front
this->insideFaces.push_back(f);
fminside.mark(f);
Traversor2FFaE<typename PFP::MAP> t (this->map, f) ;
for (Dart it = t.begin(); it != t.end(); it=t.next())
{
if (!fm.isMarked(it))
{
front.push(it);
fm.mark(it);
}
}
}
}
CellMarkerStore<VERTEX> vm(this->map); // mark inside-vertices and border-vertices
CellMarkerStore<EDGE> em(this->map); // mark inside-edges and border-edges
std::vector<Dart>::iterator f_it;
for (f_it = this->insideFaces.begin(); f_it != this->insideFaces.end(); f_it++)
{ // collect insideVertices, insideEdges, and border
Traversor2FE<typename PFP::MAP> te (this->map, *f_it) ;
for (Dart it = te.begin(); it != te.end(); it=te.next())
{ // collect insideEdges and border
if (!em.isMarked(it))
{
em.mark(it);
if (this->map.isBoundaryEdge(it))
this->border.push_back(it);
else if ( fminside.isMarked(it) && fminside.isMarked(this->map.phi2(it)) )
this->insideEdges.push_back(it);
else
this->border.push_back(it);
}
}
Traversor2FV<typename PFP::MAP> tv (this->map, *f_it) ;
for (Dart it = tv.begin(); it != tv.end(); it=tv.next())
{ // collect insideVertices
if (!vm.isMarked(it))
{
vm.mark(it);
if ( !this->map.isBoundaryVertex(it))
{
Traversor2VF<typename PFP::MAP> tf (this->map, it);
Dart it2 = tf.begin();
while ( (it2 != tf.end()) && fminside.isMarked(it2))
it2=tf.next();
if (it2 == tf.end())
this->insideVertices.push_back(it);
}
}
}
}
}
template <typename PFP>
void Collector_NormalAngle_Triangles<PFP>::collectBorder(Dart d)
{
typedef typename PFP::VEC3 VEC3;
typedef typename PFP::REAL REAL;
this->init(d);
this->insideEdges.reserve(32);
this->insideFaces.reserve(32);
this->border.reserve(32);
CellMarkerStore<FACE> fm(this->map); // mark the collected inside-faces + front-faces
CellMarkerStore<FACE> fminside(this->map); // mark the collected inside-faces
std::queue<Dart> front;
front.push(this->centerDart);
fm.mark(this->centerDart);
VEC3 centerNormal = this->normal[this->centerDart];
while ( !front.empty() ) // collect inside faces
{
Dart f = front.front();
front.pop();
REAL a = Geom::angle(centerNormal, this->normal[f]);
if (a < angleThreshold )
{ // collect this face and add adjacent faces to the front
this->insideFaces.push_back(f);
fminside.mark(f);
Traversor2FFaE<typename PFP::MAP> t (this->map, f) ;
for (Dart it = t.begin(); it != t.end(); it=t.next())
{
if (!fm.isMarked(it))
{
front.push(it);
fm.mark(it);
}
}
}
}
CellMarkerStore<EDGE> em(this->map); // mark inside-edges and border-edges
std::vector<Dart>::iterator f_it;
for (f_it = this->insideFaces.begin(); f_it != this->insideFaces.end(); f_it++)
{ // collect border (edges)
Traversor2FE<typename PFP::MAP> te (this->map, *f_it) ;
for (Dart it = te.begin(); it != te.end(); it=te.next())
{
if (!em.isMarked(it))
{
em.mark(it);
if (this->map.isBoundaryEdge(it))
this->border.push_back(it);
else if ( !fminside.isMarked(it) || !fminside.isMarked(this->map.phi2(it)) )
this->border.push_back(it);
}
}
}
this->insideFaces.clear();
}
} // namespace Selection
} // namespace Algo
......
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