Commit 2b0795de authored by Basile Sauvage's avatar Basile Sauvage

giag centroidaux : gradient

parent a45828d3
...@@ -65,6 +65,7 @@ template <typename PFP> ...@@ -65,6 +65,7 @@ template <typename PFP>
class CentroidalVoronoiDiagram : public VoronoiDiagram<PFP> { class CentroidalVoronoiDiagram : public VoronoiDiagram<PFP> {
private : private :
typedef typename PFP::REAL REAL; typedef typename PFP::REAL REAL;
typedef typename PFP::VEC3 VEC3;
VertexAttribute<REAL>& distances; // distances from the seed VertexAttribute<REAL>& distances; // distances from the seed
VertexAttribute<Dart>& pathOrigins; // previous vertex on the shortest path from origin VertexAttribute<Dart>& pathOrigins; // previous vertex on the shortest path from origin
...@@ -86,7 +87,7 @@ protected : ...@@ -86,7 +87,7 @@ protected :
void clear(); void clear();
void collectVertexFromFront(Dart e); void collectVertexFromFront(Dart e);
REAL cumulateDistancesFromRoot(Dart e); REAL cumulateDistancesFromRoot(Dart e);
unsigned int moveSeed(unsigned int i); unsigned int moveSeed(unsigned int numSeed);
}; };
......
...@@ -29,7 +29,6 @@ void VoronoiDiagram<PFP>::clear () ...@@ -29,7 +29,6 @@ void VoronoiDiagram<PFP>::clear ()
border.clear(); border.clear();
regions.setAllValues(0); regions.setAllValues(0);
border.clear(); border.clear();
seeds.clear();
front.clear(); front.clear();
vmReached.unmarkAll(); vmReached.unmarkAll();
} }
...@@ -37,14 +36,17 @@ void VoronoiDiagram<PFP>::clear () ...@@ -37,14 +36,17 @@ void VoronoiDiagram<PFP>::clear ()
template <typename PFP> template <typename PFP>
void VoronoiDiagram<PFP>::setSeeds (const std::vector<Dart>& s) void VoronoiDiagram<PFP>::setSeeds (const std::vector<Dart>& s)
{ {
clear(); seeds.clear();
// clear();
seeds = s; seeds = s;
} }
template <typename PFP> template <typename PFP>
void VoronoiDiagram<PFP>::setRandomSeeds (unsigned int nseeds) void VoronoiDiagram<PFP>::setRandomSeeds (unsigned int nseeds)
{ {
clear(); seeds.clear();
// clear();
vmReached.unmarkAll();
srand ( time(NULL) ); srand ( time(NULL) );
unsigned int n = nseeds; unsigned int n = nseeds;
...@@ -63,7 +65,8 @@ void VoronoiDiagram<PFP>::setRandomSeeds (unsigned int nseeds) ...@@ -63,7 +65,8 @@ void VoronoiDiagram<PFP>::setRandomSeeds (unsigned int nseeds)
template <typename PFP> template <typename PFP>
void VoronoiDiagram<PFP>::initFrontWithSeeds () void VoronoiDiagram<PFP>::initFrontWithSeeds ()
{ {
vmReached.unmarkAll(); // vmReached.unmarkAll();
clear();
for (unsigned int i = 0; i < seeds.size(); i++) for (unsigned int i = 0; i < seeds.size(); i++)
{ {
Dart d = seeds[i]; Dart d = seeds[i];
...@@ -205,9 +208,9 @@ typename PFP::REAL CentroidalVoronoiDiagram<PFP>::cumulateDistancesFromRoot(Dart ...@@ -205,9 +208,9 @@ typename PFP::REAL CentroidalVoronoiDiagram<PFP>::cumulateDistancesFromRoot(Dart
} }
template <typename PFP> template <typename PFP>
unsigned int CentroidalVoronoiDiagram<PFP>::moveSeed(unsigned int i){ unsigned int CentroidalVoronoiDiagram<PFP>::moveSeed(unsigned int numSeed){
Dart e = this->seeds[i]; Dart e = this->seeds[numSeed];
unsigned int res = 0; unsigned int seedMoved = 0;
std::vector<Dart> v; std::vector<Dart> v;
v.reserve(8); v.reserve(8);
...@@ -231,6 +234,39 @@ unsigned int CentroidalVoronoiDiagram<PFP>::moveSeed(unsigned int i){ ...@@ -231,6 +234,39 @@ unsigned int CentroidalVoronoiDiagram<PFP>::moveSeed(unsigned int i){
} }
} }
/* second attempt */
VEC3 grad (0.0);
const VertexAttribute<VEC3>& pos = this->map.template getAttribute<VEC3,VERTEX>("position");
for (unsigned int j = 0; j<v.size(); ++j)
{
Dart f = v[j];
// VEC3 edgeV = Algo::Geometry::vectorOutOfDart<PFP>(this->map,this->map.phi2(f),pos);
VEC3 edgeV = pos[f] - pos[this->map.phi2(f)];
edgeV.normalize();
grad += distances[f] * edgeV;
}
float maxProj = 0.0;
for (unsigned int j = 0; j<v.size(); ++j)
{
Dart f = v[j];
// VEC3 edgeV = Algo::Geometry::vectorOutOfDart<PFP>(this->map,this->map.phi2(f),pos);
VEC3 edgeV = pos[f] - pos[this->map.phi2(f)];
// edgeV.normalize();
float proj = edgeV * grad;
proj -= areaElts[e] * this->edgeCost[f] * this->edgeCost[f];
if (proj > maxProj)
{
if (numSeed==1 && j==0) CGoGNout << edgeV * grad << "\t - \t" << areaElts[e] * this->edgeCost[f] * this->edgeCost[f] << CGoGNendl;
maxProj = proj;
seedMoved = 1;
this->seeds[numSeed] = v[j];
}
}
/* end second attempt */
/* first attempt by approximating the energy change
float minDE = 0.0; float minDE = 0.0;
for (unsigned int j = 0; j<v.size(); ++j) for (unsigned int j = 0; j<v.size(); ++j)
{ {
...@@ -240,12 +276,12 @@ unsigned int CentroidalVoronoiDiagram<PFP>::moveSeed(unsigned int i){ ...@@ -240,12 +276,12 @@ unsigned int CentroidalVoronoiDiagram<PFP>::moveSeed(unsigned int i){
if (de < minDE) if (de < minDE)
{ {
minDE = de; minDE = de;
res = 1; seedMoved = 1;
this->seeds[i] = v[j]; this->seeds[numSeed] = v[j];
} }
} }
*/
return res; return seedMoved;
} }
}// end namespace Geometry }// end namespace Geometry
......
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