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 c6ae9bb5 authored by untereiner's avatar untereiner
Browse files

volumetric decimation again

parent da43d0b3
......@@ -89,16 +89,23 @@ public:
ApproximatorGen<PFP>(m), m_attrV(a)
{}
virtual ~Approximator();
//virtual ~Approximator();
const std::string& getApproximatedAttributeName() const
{
return m_attrV.name() ;
}
void saveApprox(Operator<PFP>* op)
{
Dart d = op->getEdge();
//m_app = m_approx[d] ;
}
void affectApprox(Operator<PFP>* op)
{
//m_attrV[d] = m_app ;
Dart d = op->getEdge();
m_attrV[d] = m_app ;
}
};
......
......@@ -25,7 +25,7 @@
#ifndef __DECIMATOR_VOLUMES_H__
#define __DECIMATOR_VOLUMES_H__
#include "Algo/DecimationVolumes/selector.h"
#include "Algo/DecimationVolumes/edgeSelector.h"
#include "Algo/DecimationVolumes/geometryApproximator.h"
#include "Algo/DecimationVolumes/operator.h"
......@@ -45,7 +45,7 @@ void decimate(
SelectorType s,
ApproximatorType a,
VertexAttribute<typename PFP::VEC3>& position,
unsigned int nbWantedVertices,
unsigned int percentWantedVertices,
const FunctorSelect& selected = allDarts
);
......
......@@ -34,7 +34,7 @@ namespace DecimationVolumes
template <typename PFP>
void decimate(
typename PFP::MAP& map, SelectorType s, ApproximatorType a,
VertexAttribute<typename PFP::VEC3>& position, unsigned int nbWantedVertices, const FunctorSelect& selected
VertexAttribute<typename PFP::VEC3>& position, unsigned int percentWantedVertices, const FunctorSelect& selected
)
{
std::vector<ApproximatorGen<PFP>*> approximators ;
......@@ -58,7 +58,7 @@ void decimate(
selector = new EdgeSelector_MapOrder<PFP>(map, position, approximators, selected);
break ;
case S_Random :
selector = new EdgeSelector_Random<PFP>(map, position, approximators, selected);
//selector = new EdgeSelector_Random<PFP>(map, position, approximators, selected);
break ;
default:
CGoGNout << "not yet implemented" << CGoGNendl;
......@@ -73,6 +73,8 @@ void decimate(
unsigned int nbVertices = map.template getNbOrbits<VERTEX>() ;
unsigned int nbWantedVertices = nbVertices * percentWantedVertices / 100 ;
CGoGNout << " decimate (" << nbVertices << " vertices).." << /* flush */ CGoGNendl ;
bool finished = false ;
while(!finished)
......@@ -80,27 +82,17 @@ void decimate(
//Next Operator to perform
Operator<PFP> *op;
if(!selector->nextOperator(op)) //a changer de nom
if(!selector->nextOperator(&op))
break;
// switch(selector->nextOperatorType())
// {
// case O_CEdge :
// op = new CollapseEdgeOperator<PFP>(selector->nextCell(), approximators);
// break;
// case O_CFace :
// break;
// case O_CVolume:
// break;
// }
// compute approximated attributes
for(typename std::vector<ApproximatorGen<PFP>*>::iterator it = approximators.begin(); it != approximators.end(); ++it)
{
(*it)->approximate(op) ; // compute approximated attributes
(*it)->approximate(op) ;
}
//Update the selector before performing operation
selector->updateBeforeOperation(op);
selector->updateBeforeOperation(&op);
//Perform the topological operation and
//compute the number of resulting cells
......@@ -111,7 +103,7 @@ void decimate(
//Update the embedded position and
//search the next operation to perform
selector->updateAfterOperation(op);
selector->updateAfterOperation(&op);
if(nbVertices <= nbWantedVertices)
finished = true ;
......@@ -121,6 +113,8 @@ void decimate(
selector->finish() ;
CGoGNout << "..done (" << nbVertices << " vertices)" << CGoGNendl ;
delete selector ;
for(typename std::vector<ApproximatorGen<PFP>*>::iterator it = approximators.begin(); it != approximators.end(); ++it)
......
......@@ -29,8 +29,8 @@ protected:
public:
EdgeSelector(MAP& m, VertexAttribute<typename PFP::VEC3>& pos) :
Selector<PFP>(m, pos)
EdgeSelector(MAP& m, VertexAttribute<typename PFP::VEC3>& pos, std::vector<ApproximatorGen<PFP>*>& approx, const FunctorSelect& select) :
Selector<PFP>(m, pos, approx, select)
{}
};
......@@ -50,8 +50,8 @@ private:
Dart cur;
public:
EdgeSelector_MapOrder(MAP& m, VertexAttribute<typename PFP::VEC3>& pos) :
EdgeSelector<PFP>(m, pos)
EdgeSelector_MapOrder(MAP& m, VertexAttribute<typename PFP::VEC3>& pos, std::vector<ApproximatorGen<PFP>*>& approx, const FunctorSelect& select) :
EdgeSelector<PFP>(m, pos, approx, select)
{}
~EdgeSelector_MapOrder()
......@@ -60,11 +60,11 @@ public:
SelectorType getType() { return S_MapOrder; }
Dart nextCell() { return cur; }
void init();
bool nextOperator(Operator<PFP>* op);
void updateBeforeOperation(Operator<PFP>* op)
bool init();
bool nextOperator(Operator<PFP>** op);
void updateBeforeOperation(Operator<PFP>** op)
{ }
void updateAfterOperation(Operator<PFP>* op);
void updateAfterOperation(Operator<PFP>** op);
void finish()
{ }
......@@ -73,39 +73,39 @@ public:
/********************************************************************************
* Random Selector *
********************************************************************************/
template <typename PFP>
class EdgeSelector_Random : public EdgeSelector<PFP>
{
public:
typedef typename PFP::MAP MAP ;
typedef typename PFP::VEC3 VEC3 ;
typedef typename PFP::REAL REAL ;
private:
std::vector<Dart> darts ;
unsigned int cur ;
bool allSkipped ;
public:
EdgeSelector_Random(MAP& m, VertexAttribute<typename PFP::VEC3>& pos) :
EdgeSelector<PFP>(m, pos)
{}
~EdgeSelector_Random()
{}
SelectorType getType() { return S_Random; }
// Dart nextCell() { return darts[cur]; }
void init();
bool nextOperator(Operator<PFP>* op);
void updateBeforeOperation(Operator<PFP>* op)
{ }
void updateAfterOperation(Operator<PFP>* op);
void finish()
{ }
} ;
//template <typename PFP>
//class EdgeSelector_Random : public EdgeSelector<PFP>
//{
//public:
// typedef typename PFP::MAP MAP ;
// typedef typename PFP::VEC3 VEC3 ;
// typedef typename PFP::REAL REAL ;
//
//private:
// std::vector<Dart> darts ;
// unsigned int cur ;
// bool allSkipped ;
//
//public:
// EdgeSelector_Random(MAP& m, VertexAttribute<typename PFP::VEC3>& pos, std::vector<ApproximatorGen<PFP>*>& approx, const FunctorSelect& select) :
// EdgeSelector<PFP>(m, pos, approx, select)
// {}
//
// ~EdgeSelector_Random()
// {}
//
// SelectorType getType() { return S_Random; }
//// Dart nextCell() { return darts[cur]; }
//
// bool init();
// bool nextOperator(Operator<PFP>** op);
// void updateBeforeOperation(Operator<PFP>* op)
// { }
// void updateAfterOperation(Operator<PFP>* op);
// void finish()
// { }
//
//} ;
///********************************************************************************
// * Length Edge Selector *
......@@ -177,6 +177,6 @@ public:
} //end namespace CGoGN
#include "Algo/DecimationVolumes/selector.hpp"
#include "Algo/DecimationVolumes/edgeSelector.hpp"
#endif
......@@ -39,43 +39,42 @@ namespace DecimationVolumes
************************************************************************************/
template <typename PFP>
void EdgeSelector_MapOrder<PFP>::init()
bool EdgeSelector_MapOrder<PFP>::init()
{
cur = this->m_map.begin() ;
//TODO Choix de nextOperator
//this->nextOp = Algo::DecimationVolumique::O_CEdge;
return true;
}
template <typename PFP>
bool EdgeSelector_MapOrder<PFP>::nextOperator(Operator<PFP>* op)
bool EdgeSelector_MapOrder<PFP>::nextOperator(Operator<PFP>** op)
{
if(cur == this->m_map.end())
return false ;
*op = new CollapseEdgeOperator<PFP>(cur);
return true ;
}
template <typename PFP>
void EdgeSelector_MapOrder<PFP>::updateAfterOperation(Operator<PFP>* op)
void EdgeSelector_MapOrder<PFP>::updateAfterOperation(Operator<PFP>** op)
{
MAP& m = this->m_map ;
//Mise à jour de nextOperator
cur = m.begin() ;
//Update the current dart
if(this->nextOp == Algo::DecimationVolumique::O_CEdge)
while(!(*op)->canPerform(m,cur,this->m_position))
{
cur = m.begin() ;
while(!op->canPerform(m,cur,this->m_position))
{
//CGoGNout << "update " << cur << CGoGNendl;
m.next(cur) ;
if(cur == m.end())
break ;
}
//CGoGNout << "update " << cur << CGoGNendl;
m.next(cur) ;
if(cur == m.end())
break ;
}
}
......@@ -83,67 +82,69 @@ void EdgeSelector_MapOrder<PFP>::updateAfterOperation(Operator<PFP>* op)
* Random Edge Selector *
************************************************************************************/
template <typename PFP>
void EdgeSelector_Random<PFP>::init()
{
MAP& m = this->m_map ;
darts.reserve(m.getNbDarts()) ;
darts.clear() ;
for(Dart d = m.begin(); d != m.end(); m.next(d))
darts.push_back(d) ;
srand(time(NULL)) ;
int remains = darts.size() ;
for(unsigned int i = 0; i < darts.size()-1; ++i) // generate the random permutation
{
int r = (rand() % remains) + i ;
// swap ith and rth elements
Dart tmp = darts[i] ;
darts[i] = darts[r] ;
darts[r] = tmp ;
--remains ;
}
cur = 0 ;
allSkipped = true ;
//TODO Choix de nextOperator
this->nextOp = Algo::DecimationVolumique::O_CEdge;
}
template <typename PFP>
bool EdgeSelector_Random<PFP>::nextOperator(Operator<PFP>* op)
{
if(cur == darts.size() && allSkipped)
return false ;
return true ;
}
template <typename PFP>
void EdgeSelector_Random<PFP>::updateAfterOperation(Operator<PFP>* op)
{
MAP& m = this->m_map ;
allSkipped = false ;
if(this->nextOp == Algo::DecimationVolumique::O_CEdge)
{
// for(typename std::vector<Dart>::iterator it = darts.begin() ; it != darts.end() ; ++it)
// CGoGNout << *it << CGoGNendl;
do
{
++cur ;
if(cur == darts.size())
{
//cur = 0 ;
allSkipped = true ;
}
} while(!allSkipped && !op->canPerform(m,darts[cur],this->m_position)) ;
}
}
//template <typename PFP>
//bool EdgeSelector_Random<PFP>::init()
//{
// MAP& m = this->m_map ;
//
// darts.reserve(m.getNbDarts()) ;
// darts.clear() ;
//
// for(Dart d = m.begin(); d != m.end(); m.next(d))
// darts.push_back(d) ;
//
// srand(time(NULL)) ;
// int remains = darts.size() ;
// for(unsigned int i = 0; i < darts.size()-1; ++i) // generate the random permutation
// {
// int r = (rand() % remains) + i ;
// // swap ith and rth elements
// Dart tmp = darts[i] ;
// darts[i] = darts[r] ;
// darts[r] = tmp ;
// --remains ;
// }
// cur = 0 ;
// allSkipped = true ;
//
// //TODO Choix de nextOperator
// //this->nextOp = O_CEdge;
//
// return true;
//}
//
//template <typename PFP>
//bool EdgeSelector_Random<PFP>::nextOperator(Operator<PFP>** op)
//{
// if(cur == darts.size() && allSkipped)
// return false ;
//
// return true ;
//}
//
//
//template <typename PFP>
//void EdgeSelector_Random<PFP>::updateAfterOperation(Operator<PFP>* op)
//{
// MAP& m = this->m_map ;
// allSkipped = false ;
//
// //if(this->nextOp == O_CEdge)
// //{
//// for(typename std::vector<Dart>::iterator it = darts.begin() ; it != darts.end() ; ++it)
//// CGoGNout << *it << CGoGNendl;
//
// do
// {
// ++cur ;
// if(cur == darts.size())
// {
// //cur = 0 ;
// allSkipped = true ;
// }
// } while(!allSkipped && !op->canPerform(m,darts[cur],this->m_position)) ;
// //}
//}
///************************************************************************************
// * Edge Length Selector *
......
......@@ -51,9 +51,8 @@ public:
~Approximator_Centroid()
{}
ApproximatorType getType() { return A_Centroid; }
void init();
ApproximatorType getType() const { return A_Centroid; }
bool init();
void approximate(Operator<PFP> *op);
} ;
......
......@@ -38,9 +38,9 @@ namespace DecimationVolumes
* Centroid *
************************************************************************************/
template <typename PFP>
void Approximator_Centroid<PFP>::init()
bool Approximator_Centroid<PFP>::init()
{
return true;
}
template <typename PFP>
......@@ -49,7 +49,7 @@ void Approximator_Centroid<PFP>::approximate(Operator<PFP> *op)
Dart d = op->getEdge();
VEC3 a = this->m_attrV[d];
CGoGNout << "d=" << d << " a=" << a << CGoGNendl;
//CGoGNout << "d=" << d << " a=" << a << CGoGNendl;
// get some darts
Dart dd = this->m_map.phi2(d) ;
......
......@@ -45,7 +45,8 @@ enum OperatorType
} ;
template <typename PFP> class Approximator ;
//template <typename PFP, typename T> class Approximator ;
//template <typename PFP> class ApproximatorGen ;
template <typename PFP>
class Operator
......@@ -64,11 +65,11 @@ protected:
* need a pointer to the current approximator if the current selector needs
* the future result of a collapse to estimate its cost
*/
Algo::DecimationVolumique::Approximator<PFP>* m_approximator ;
//ApproximatorGen<PFP>* m_approximator ;
public:
Operator(Dart d, Algo::DecimationVolumique::Approximator<PFP>* approx) :
m_edge(d), m_approximator(approx)
Operator(Dart d) ://, ApproximatorGen<PFP>* approx) :
m_edge(d)//, m_approximator(approx)
{}
Operator() {}
......@@ -77,7 +78,7 @@ public:
Dart getEdge() {return m_edge;}
void setEdge(Dart d) { m_edge = d; }
OperatorType getType() {return O_CVolume;};
virtual OperatorType getType() = 0;
virtual unsigned int perform(MAP& m, VertexAttribute<typename PFP::VEC3>& position) = 0;
virtual bool canPerform(MAP &m ,Dart d, VertexAttribute<typename PFP::VEC3>& position) = 0;
......@@ -95,8 +96,8 @@ protected:
public:
CollapseOperator(Dart d, Algo::DecimationVolumique::Approximator<PFP>* approx) :
Operator<PFP>(d, approx)
CollapseOperator(Dart d) : //, ApproximatorGen<PFP>* approx) :
Operator<PFP>(d)//, approx)
{}
~CollapseOperator() {};
......@@ -116,8 +117,8 @@ protected:
public:
CollapseEdgeOperator(Dart d, Algo::DecimationVolumique::Approximator<PFP>* approx) :
CollapseOperator<PFP>(d, approx)
CollapseEdgeOperator(Dart d) ://, ApproximatorGen<PFP>* approx) :
CollapseOperator<PFP>(d)//, approx)
{}
~CollapseEdgeOperator()
......
......@@ -40,8 +40,10 @@ unsigned int CollapseEdgeOperator<PFP>::perform(MAP& m, VertexAttribute<typename
unsigned int nbCell = 0;
//calcul du nombre de cellule supprime
position[this->m_edge] = this->m_approximator->getApproximation();
nbCell = m.collapseEdge(this->m_edge,true,true);
//position[this->m_edge] = this->m_approximator->getApproximation();
m.collapseEdge(this->m_edge);
++nbCell;
return nbCell;
}
......@@ -83,7 +85,7 @@ bool CollapseEdgeOperator<PFP>::canPerform(MAP &m ,Dart d, VertexAttribute<typen
Dart b = m.phi1(m.phi3(m.phi2(m.phi_1(e))));
//tetrahedre du haut
typename PFP::VEC3 p1 = this->m_approximator->getApproximation();
typename PFP::VEC3 p1 = position[a];//this->m_approximator->getApproximation();
typename PFP::VEC3 p2, p3, p4;
typename PFP::VEC3::DATA_TYPE v1;
......
......@@ -63,7 +63,7 @@ public:
m_map(m), m_position(pos), m_approximators(approx), m_select(select)
{}
virtual ~EdgeSelector()
virtual ~Selector()
{}
/**
......@@ -80,22 +80,22 @@ public:
/**
*
*/
virtual void init() = 0 ;
virtual bool init() = 0 ;
/**
*
*/
virtual bool nextOperator(Operator<PFP>* op) = 0 ;
virtual bool nextOperator(Operator<PFP>** op) = 0 ;
/**
*
*/
virtual void updateBeforeOperation(Operator<PFP>* op) = 0 ;
virtual void updateBeforeOperation(Operator<PFP>** op) = 0 ;
/**
*
*/
virtual void updateAfterOperation(Operator<PFP>* op) = 0 ;
virtual void updateAfterOperation(Operator<PFP>** op) = 0 ;
/**
*
......
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