Coupure prévue mardi 3 Août au matin pour maintenance du serveur. Nous faisons au mieux pour que celle-ci soit la plus brève possible.

Commit 6dd9a98f authored by Basile Sauvage's avatar Basile Sauvage
Browse files

graines incrementales

parent 62510b1a
...@@ -47,12 +47,13 @@ public : ...@@ -47,12 +47,13 @@ public :
~VoronoiDiagram (); ~VoronoiDiagram ();
const std::vector<Dart>& getSeeds (){return seeds;} const std::vector<Dart>& getSeeds (){return seeds;}
virtual void setSeeds (const std::vector<Dart>&); virtual void setSeeds_fromVector (const std::vector<Dart>&);
virtual void setRandomSeeds (unsigned int nbseeds); virtual void setSeeds_random (unsigned int nbseeds);
const std::vector<Dart>& getBorder (){return border;} const std::vector<Dart>& getBorder (){return border;}
void setCost (const EdgeAttribute<REAL>& c); void setCost (const EdgeAttribute<REAL>& c);
void computeDiagram (); Dart computeDiagram ();
virtual void computeDiagram_incremental (unsigned int nbseeds);
void computeDistancesWithinRegion (Dart seed); void computeDistancesWithinRegion (Dart seed);
protected : protected :
...@@ -86,8 +87,9 @@ public : ...@@ -86,8 +87,9 @@ public :
VertexAttribute<REAL>& a); VertexAttribute<REAL>& a);
~CentroidalVoronoiDiagram (); ~CentroidalVoronoiDiagram ();
void setSeeds (const std::vector<Dart>&); void setSeeds_fromVector (const std::vector<Dart>&);
void setRandomSeeds (unsigned int nbseeds); void setSeeds_random (unsigned int nbseeds);
void computeDiagram_incremental (unsigned int nbseeds);
void cumulateEnergy(); void cumulateEnergy();
void cumulateEnergyAndGradients(); void cumulateEnergyAndGradients();
unsigned int moveSeedsOneEdgeNoCheck(); // returns the number of seeds that did move unsigned int moveSeedsOneEdgeNoCheck(); // returns the number of seeds that did move
......
...@@ -33,14 +33,14 @@ void VoronoiDiagram<PFP>::clear () ...@@ -33,14 +33,14 @@ void VoronoiDiagram<PFP>::clear ()
} }
template <typename PFP> template <typename PFP>
void VoronoiDiagram<PFP>::setSeeds (const std::vector<Dart>& s) void VoronoiDiagram<PFP>::setSeeds_fromVector (const std::vector<Dart>& s)
{ {
seeds.clear(); seeds.clear();
seeds = s; seeds = s;
} }
template <typename PFP> template <typename PFP>
void VoronoiDiagram<PFP>::setRandomSeeds (unsigned int nseeds) void VoronoiDiagram<PFP>::setSeeds_random (unsigned int nseeds)
{ {
seeds.clear(); seeds.clear();
srand ( time(NULL) ); srand ( time(NULL) );
...@@ -128,13 +128,14 @@ void VoronoiDiagram<PFP>::updateVertexInFront(Dart f, float d){ ...@@ -128,13 +128,14 @@ void VoronoiDiagram<PFP>::updateVertexInFront(Dart f, float d){
} }
template <typename PFP> template <typename PFP>
void VoronoiDiagram<PFP>::computeDiagram () Dart VoronoiDiagram<PFP>::computeDiagram ()
{ {
initFrontWithSeeds(); initFrontWithSeeds();
Dart e;
while ( !front.empty() ) while ( !front.empty() )
{ {
Dart e = front.begin()->second; e = front.begin()->second;
float d = front.begin()->first; float d = front.begin()->first;
collectVertexFromFront(e); collectVertexFromFront(e);
...@@ -155,6 +156,35 @@ void VoronoiDiagram<PFP>::computeDiagram () ...@@ -155,6 +156,35 @@ void VoronoiDiagram<PFP>::computeDiagram ()
} }
} }
} }
return e;
}
template <typename PFP>
void VoronoiDiagram<PFP>::computeDiagram_incremental (unsigned int nseeds)
{
seeds.clear();
// first seed
srand ( time(NULL) );
unsigned int s = rand() % map.getNbCells(VERTEX);
unsigned int n = 0;
TraversorV<typename PFP::MAP> tv (map);
Dart dit = tv.begin();
while(n<s)
{
dit = tv.next();
++n;
}
seeds.push_back(dit);
// add other seeds one by one
Dart e = computeDiagram();
for(unsigned int i = 1; i< nseeds ; i++)
{
seeds.push_back(e);
e = computeDiagram();
}
} }
template <typename PFP> template <typename PFP>
...@@ -224,16 +254,23 @@ void CentroidalVoronoiDiagram<PFP>::collectVertexFromFront(Dart e){ ...@@ -224,16 +254,23 @@ void CentroidalVoronoiDiagram<PFP>::collectVertexFromFront(Dart e){
template <typename PFP> template <typename PFP>
void CentroidalVoronoiDiagram<PFP>::setSeeds (const std::vector<Dart>& s) void CentroidalVoronoiDiagram<PFP>::setSeeds_fromVector (const std::vector<Dart>& s)
{
VoronoiDiagram<PFP>::setSeeds_fromVector (s);
energyGrad.resize(this->seeds.size());
}
template <typename PFP>
void CentroidalVoronoiDiagram<PFP>::setSeeds_random (unsigned int nseeds)
{ {
VoronoiDiagram<PFP>::setSeeds (s); VoronoiDiagram<PFP>::setSeeds_random (nseeds);
energyGrad.resize(this->seeds.size()); energyGrad.resize(this->seeds.size());
} }
template <typename PFP> template <typename PFP>
void CentroidalVoronoiDiagram<PFP>::setRandomSeeds (unsigned int nseeds) void CentroidalVoronoiDiagram<PFP>::computeDiagram_incremental (unsigned int nseeds)
{ {
VoronoiDiagram<PFP>::setRandomSeeds (nseeds); VoronoiDiagram<PFP>::computeDiagram_incremental (nseeds);
energyGrad.resize(this->seeds.size()); energyGrad.resize(this->seeds.size());
} }
...@@ -278,7 +315,6 @@ unsigned int CentroidalVoronoiDiagram<PFP>::moveSeedsOneEdgeNoCheck(){ ...@@ -278,7 +315,6 @@ unsigned int CentroidalVoronoiDiagram<PFP>::moveSeedsOneEdgeNoCheck(){
template <typename PFP> template <typename PFP>
unsigned int CentroidalVoronoiDiagram<PFP>::moveSeedsOneEdgeCheck(){ unsigned int CentroidalVoronoiDiagram<PFP>::moveSeedsOneEdgeCheck(){
// TODO : probable bug (memoire ?) car les iterations ralentissent inexplicablement
unsigned int m = 0; unsigned int m = 0;
for (unsigned int i = 0; i < this->seeds.size(); i++) for (unsigned int i = 0; i < this->seeds.size(); i++)
{ {
...@@ -353,6 +389,7 @@ typename PFP::REAL CentroidalVoronoiDiagram<PFP>::cumulateEnergyFromRoot(Dart e) ...@@ -353,6 +389,7 @@ typename PFP::REAL CentroidalVoronoiDiagram<PFP>::cumulateEnergyFromRoot(Dart e)
template <typename PFP> template <typename PFP>
void CentroidalVoronoiDiagram<PFP>::cumulateEnergyAndGradientFromSeed(unsigned int numSeed){ void CentroidalVoronoiDiagram<PFP>::cumulateEnergyAndGradientFromSeed(unsigned int numSeed){
// precondition : energyGrad.size() > numSeed
Dart e = this->seeds[numSeed]; Dart e = this->seeds[numSeed];
std::vector<Dart> v; std::vector<Dart> v;
......
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