Commit 299e096a authored by Basile Sauvage's avatar Basile Sauvage

debut de collector_Dijkstra

parent 00fd1802
......@@ -226,6 +226,54 @@ public:
void collectBorder(Dart d) ;
};
/*********************************************************
* Collector Dijkstra
*********************************************************/
/*
* collect all primitives of the connected component containing "centerDart"
* within a distance < maxDist (the shortest path follows edges)
*/
template <typename PFP>
class Collector_Dijkstra : public Collector<PFP>
{
protected:
const VertexAttribute<typename PFP::VEC3>& position;
typename PFP::REAL maxDist;
typedef struct
{
typename std::multimap<float,Dart>::iterator it ;
bool valid ;
static std::string CGoGNnameOfType() { return "DijkstraVertexInfo" ; }
} DijkstraVertexInfo ;
typedef NoMathIOAttribute<DijkstraVertexInfo> VertexInfo ;
VertexAttribute<VertexInfo> vertexInfo ;
std::multimap<float,Dart> front ;
public:
Collector_Dijkstra(typename PFP::MAP& m, const VertexAttribute<typename PFP::VEC3>& p, typename PFP::REAL d = 0) :
Collector<PFP>(m),
position(p),
maxDist(d)
{
vertexInfo = m.template addAttribute<VertexInfo, VERTEX>("vertexInfo");
}
~Collector_Dijkstra(){
this->map.removeAttribute(vertexInfo);
}
inline void init (Dart d) {Collector<PFP>::init(d); front.clear();}
inline void setMaxDistance(typename PFP::REAL d) { maxDist = d; }
inline typename PFP::REAL getMaxDist() const { return maxDist; }
inline const VertexAttribute<typename PFP::VEC3>& getPosition() const { return position; }
void collectAll(Dart d);
void collectBorder(Dart d);
private :
inline float edgeLength (Dart d);
};
} // namespace Selection
......
......@@ -414,6 +414,7 @@ void Collector_NormalAngle_Triangles<PFP>::collectAll(Dart d)
typedef typename PFP::REAL REAL;
this->init(d);
this->insideVertices.reserve(32);
this->insideEdges.reserve(32);
this->insideFaces.reserve(32);
this->border.reserve(32);
......@@ -497,7 +498,6 @@ void Collector_NormalAngle_Triangles<PFP>::collectBorder(Dart d)
typedef typename PFP::REAL REAL;
this->init(d);
this->insideEdges.reserve(32);
this->insideFaces.reserve(32);
this->border.reserve(32);
......@@ -552,6 +552,66 @@ void Collector_NormalAngle_Triangles<PFP>::collectBorder(Dart d)
this->insideFaces.clear();
}
/*********************************************************
* Collector Dijkstra
*********************************************************/
template <typename PFP>
void Collector_Dijkstra<PFP>::collectAll(Dart dinit){
init(dinit);
CellMarkerStore<VERTEX> vmReached (this->map);
vertexInfo[this->centerDart].it = front.insert(std::pair<float,Dart>(0.0, this->centerDart));
vertexInfo[this->centerDart].valid = true;
vmReached.mark(this->centerDart);
while ( !front.empty() && front.begin()->first < this->maxDist)
{
Dart e = front.begin()->second;
float d = front.begin()->first;
front.erase(vertexInfo[e].it);
vertexInfo[e].valid=false;
this->insideVertices.push_back(e);
Traversor2VVaE<typename PFP::MAP> tv (this->map, e);
for (Dart f = tv.begin(); f != tv.end(); f=tv.next())
{
VertexInfo& vi (vertexInfo[f]);
if (vmReached.isMarked(f))
{
if (vi.valid) // probably useless but faster
{
float dist = d + edgeLength(f);
if (dist < vi.it->first)
{
front.erase(vi.it);
vi.it = front.insert(std::pair<float,Dart>(dist, f));
}
}
}
else
{
vi.it = front.insert(std::pair<float,Dart>(d + edgeLength(f), f));
vi.valid=true;
vmReached.mark(f);
}
}
}
}
template <typename PFP>
void Collector_Dijkstra<PFP>::collectBorder(Dart d){
}
template <typename PFP>
inline float Collector_Dijkstra<PFP>::edgeLength (Dart d){
typename PFP::VEC3 v = Algo::Geometry::vectorOutOfDart<PFP>(this->map, d, this->position);
return v.norm();
}
} // namespace Selection
......
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