Commit da43d0b3 authored by untereiner's avatar untereiner

begin of the volumetric decimation return

parent b1b59022
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your *
* option) any later version. *
* *
* This library is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
* *
* Web site: http://cgogn.unistra.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#ifndef __APPROXIMATOR_VOLUMES_H__
#define __APPROXIMATOR_VOLUMES_H__
#include "Algo/DecimationVolumes/operator.h"
namespace CGoGN
{
namespace Algo
{
namespace DecimationVolumes
{
enum ApproximatorType
{
A_Centroid //barycenter of the n-cells
};
template <typename PFP>
class ApproximatorGen
{
public:
typedef typename PFP::MAP MAP ;
typedef typename PFP::VEC3 VEC3 ;
typedef typename PFP::REAL REAL ;
protected:
MAP& m_map ;
public:
ApproximatorGen(MAP& m) : m_map(m)
{}
virtual ~ApproximatorGen()
{}
virtual const std::string& getApproximatedAttributeName() const = 0 ;
virtual ApproximatorType getType() const = 0 ;
virtual bool init() = 0 ;
virtual void approximate(Operator<PFP>* op) = 0 ;
virtual void saveApprox(Operator<PFP>* op) = 0 ;
virtual void affectApprox(Operator<PFP>* op) = 0 ;
} ;
template <typename PFP, typename T>
class Approximator : public ApproximatorGen<PFP>
{
public:
typedef typename PFP::MAP MAP ;
typedef typename PFP::REAL REAL;
protected:
//TODO ajouter un predictor
VertexAttribute<T>& m_attrV; // vertex attribute to be approximated
//TODO Attribute to store approximation result
//TODO attribute to store detail information for reconstruction
T m_app;
public:
Approximator(MAP& m, VertexAttribute<T>& a):
ApproximatorGen<PFP>(m), m_attrV(a)
{}
virtual ~Approximator();
const std::string& getApproximatedAttributeName() const
{
return m_attrV.name() ;
}
void affectApprox(Operator<PFP>* op)
{
//m_attrV[d] = m_app ;
}
};
} // namespace DecimationVolumes
} // namespace Algo
} // namespace CGoGN
#endif
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your *
* option) any later version. *
* *
* This library is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
* *
* Web site: http://cgogn.unistra.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#ifndef __DECIMATOR_VOLUMES_H__
#define __DECIMATOR_VOLUMES_H__
#include "Algo/DecimationVolumes/selector.h"
#include "Algo/DecimationVolumes/geometryApproximator.h"
#include "Algo/DecimationVolumes/operator.h"
namespace CGoGN
{
namespace Algo
{
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 = allDarts
);
} //namespace DecimationVolumes
} //namespace Algo
} //namespace CGoGN
#include "Algo/DecimationVolumes/decimator.hpp"
#endif
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your *
* option) any later version. *
* *
* This library is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
* *
* Web site: http://cgogn.unistra.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
namespace CGoGN
{
namespace Algo
{
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
)
{
std::vector<ApproximatorGen<PFP>*> approximators ;
Selector<PFP>* selector = NULL ;
//choose the Approximator
switch(a)
{
case A_Centroid :
approximators.push_back(new Approximator_Centroid<PFP>(map, position)) ;
break ;
default :
CGoGNout << "not yet implemented" << CGoGNendl;
break;
}
//choose the Selector
switch(s)
{
case S_MapOrder :
selector = new EdgeSelector_MapOrder<PFP>(map, position, approximators, selected);
break ;
case S_Random :
selector = new EdgeSelector_Random<PFP>(map, position, approximators, selected);
break ;
default:
CGoGNout << "not yet implemented" << CGoGNendl;
break;
}
for(typename std::vector<ApproximatorGen<PFP>*>::iterator it = approximators.begin(); it != approximators.end(); ++it)
(*it)->init() ;
if(!selector->init())
return ;
unsigned int nbVertices = map.template getNbOrbits<VERTEX>() ;
bool finished = false ;
while(!finished)
{
//Next Operator to perform
Operator<PFP> *op;
if(!selector->nextOperator(op)) //a changer de nom
break;
// switch(selector->nextOperatorType())
// {
// case O_CEdge :
// op = new CollapseEdgeOperator<PFP>(selector->nextCell(), approximators);
// break;
// case O_CFace :
// break;
// case O_CVolume:
// break;
// }
for(typename std::vector<ApproximatorGen<PFP>*>::iterator it = approximators.begin(); it != approximators.end(); ++it)
{
(*it)->approximate(op) ; // compute approximated attributes
}
//Update the selector before performing operation
selector->updateBeforeOperation(op);
//Perform the topological operation and
//compute the number of resulting cells
nbVertices -= op->perform(map, position);
//for(typename std::vector<ApproximatorGen<PFP>*>::iterator it = approximators.begin(); it != approximators.end(); ++it)
// (*it)->affectApprox(op); // affect data to the resulting vertex
//Update the embedded position and
//search the next operation to perform
selector->updateAfterOperation(op);
if(nbVertices <= nbWantedVertices)
finished = true ;
delete op;
}
selector->finish() ;
delete selector ;
for(typename std::vector<ApproximatorGen<PFP>*>::iterator it = approximators.begin(); it != approximators.end(); ++it)
delete (*it) ;
}
} //namespace DecimationVolumes
} //namespace Algo
} //namespace CGoGN
#ifndef __SELECTORVOL_H__ #ifndef __EDGE_SELECTOR_VOLUMES_H__
#define __SELECTORVOL_H__ #define __EDGE_SELECTOR_VOLUMES_H__
#include "Container/fakeAttribute.h" #include "Container/fakeAttribute.h"
#include "Algo/DecimationVolumique/operator.h" #include "Algo/DecimationVolumes/selector.h"
#include "Algo/DecimationVolumes/operator.h"
namespace CGoGN namespace CGoGN
{ {
...@@ -10,104 +11,9 @@ namespace CGoGN ...@@ -10,104 +11,9 @@ namespace CGoGN
namespace Algo namespace Algo
{ {
namespace DecimationVolumique namespace DecimationVolumes
{ {
enum SelectorType
{
S_MapOrder,
S_Random,
S_EdgeLength
} ;
template <typename PFP> class Approximator ;
//template <typename PFP> class Operator ;
/********************************************************************************
* Parent Selector *
********************************************************************************/
//class du Selector de base
template <typename PFP>
class Selector
{
public:
typedef typename PFP::MAP MAP ;
typedef typename PFP::VEC3 VEC3 ;
typedef typename PFP::REAL REAL;
protected:
/**
*
*/
MAP& m_map ;
/**
*
*/
VertexAttribute<typename PFP::VEC3>& m_position ;
/**
*
*/
Algo::DecimationVolumique::OperatorType nextOp;
/**
* 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 ;
public:
Selector(MAP& m, VertexAttribute<typename PFP::VEC3>& pos) :
m_map(m), m_position(pos)
{}
/**
* Return the type of the selector
* @return the type of the selector
*/
virtual SelectorType getType() = 0 ;
/**
*
*/
virtual Dart nextCell() = 0;
/**
*
*/
virtual void init(Algo::DecimationVolumique::Approximator<PFP>* approx) = 0 ;
/**
*
*/
virtual bool nextOperator() = 0 ;
/**
*
*/
virtual void updateBeforeOperation(Algo::DecimationVolumique::Operator<PFP>* op) = 0 ;
/**
*
*/
virtual void updateAfterOperation(Algo::DecimationVolumique::Operator<PFP>* op) = 0 ;
/**
*
*/
virtual void finish() = 0 ;
/**
*
*/
Algo::DecimationVolumique::Approximator<PFP>* getApproximator() { return m_approximator; }
/**
*
*/
OperatorType nextOperatorType() { return nextOp; }
};
/******************************************************************************** /********************************************************************************
* Parent Edge Selector * * Parent Edge Selector *
********************************************************************************/ ********************************************************************************/
...@@ -127,30 +33,6 @@ public: ...@@ -127,30 +33,6 @@ public:
Selector<PFP>(m, pos) Selector<PFP>(m, pos)
{} {}
/*
* Initialiszation of the Edge selector
* TODO
*/
virtual void init(Algo::DecimationVolumique::Approximator<PFP>* approx);
// /*
// * Select the next dart to collapse
// * TODO
// */
// virtual bool nextOperator(Algo::DecimationVolumique::Operator<PFP>* op);
// /*
// * TODO
// */
// virtual void updateBeforeOperation(Algo::DecimationVolumique::Operator<PFP>* op);
// /*
// * TODO
// */
// virtual void updateAfterOperation(Algo::DecimationVolumique::Operator<PFP>* op);
// /*
// * TODO
// */
// virtual void finish();
}; };
/******************************************************************************** /********************************************************************************
...@@ -178,11 +60,11 @@ public: ...@@ -178,11 +60,11 @@ public:
SelectorType getType() { return S_MapOrder; } SelectorType getType() { return S_MapOrder; }
Dart nextCell() { return cur; } Dart nextCell() { return cur; }
void init(Algo::DecimationVolumique::Approximator<PFP>* approx); void init();
bool nextOperator(); bool nextOperator(Operator<PFP>* op);
void updateBeforeOperation(Algo::DecimationVolumique::Operator<PFP>* op) void updateBeforeOperation(Operator<PFP>* op)
{ } { }
void updateAfterOperation(Algo::DecimationVolumique::Operator<PFP>* op); void updateAfterOperation(Operator<PFP>* op);
void finish() void finish()
{ } { }
...@@ -213,86 +95,88 @@ public: ...@@ -213,86 +95,88 @@ public:
{} {}
SelectorType getType() { return S_Random; } SelectorType getType() { return S_Random; }
Dart nextCell() { return darts[cur]; } // Dart nextCell() { return darts[cur]; }
void init(Algo::DecimationVolumique::Approximator<PFP>* approx); void init();
bool nextOperator(); bool nextOperator(Operator<PFP>* op);
void updateBeforeOperation(Algo::DecimationVolumique::Operator<PFP>* op) void updateBeforeOperation(Operator<PFP>* op)
{ } { }
void updateAfterOperation(Algo::DecimationVolumique::Operator<PFP>* op); void updateAfterOperation(Operator<PFP>* op);
void finish() void finish()
{ } { }
} ; } ;
/******************************************************************************** ///********************************************************************************
* Length Edge Selector * // * Length Edge Selector *
********************************************************************************/ // ********************************************************************************/
template <typename PFP> //template <typename PFP>
class EdgeSelector_Length : public EdgeSelector<PFP> //class EdgeSelector_Length : public EdgeSelector<PFP>
{ //{
public: //public:
typedef typename PFP::MAP MAP; // typedef typename PFP::MAP MAP;
typedef typename PFP::VEC3 VEC3; // typedef typename PFP::VEC3 VEC3;
typedef typename PFP::REAL REAL; // typedef typename PFP::REAL REAL;
//
protected: //protected:
/* // /*
* Update the Edge Informations // * Update the Edge Informations
*/ // */
void updateEdgeInfo(Dart d, typename PFP::VEC3 e); // void updateEdgeInfo(Dart d, typename PFP::VEC3 e);
/* // /*
* Init the Edge informations // * Init the Edge informations
*/ // */
void initEdgeInfo(Dart d); // void initEdgeInfo(Dart d);
/* // /*
* Erase The Edge informations // * Erase The Edge informations
*/ // */
void eraseEdgeInfo(Dart d); // void eraseEdgeInfo(Dart d);
//
private: //private:
//New embedding type for storing informations // //New embedding type for storing informations
typedef struct { // typedef struct {
typename std::multimap<float,Dart>::iterator it ; // typename std::multimap<float,Dart>::iterator it ;
bool valid ; // bool valid ;
} LengthEdgeInfo ; // } LengthEdgeInfo ;
//
typedef NoMathIOAttribute<LengthEdgeInfo> EdgeInfo ; // typedef NoMathIOAttribute<LengthEdgeInfo> EdgeInfo ;
//
EdgeAttribute<EdgeInfo> edgeInfo ; // EdgeAttribute<EdgeInfo> edgeInfo ;
//
std::multimap<float,Dart> edges ; // std::multimap<float,Dart> edges ;
typename std::multimap<float,Dart>::iterator cur ; // typename std::multimap<float,Dart>::iterator cur ;
//
//
public: //public:
EdgeSelector_Length(MAP& m, VertexAttribute<typename PFP::VEC3>& pos) : // EdgeSelector_Length(MAP& m, VertexAttribute<typename PFP::VEC3>& pos) :
EdgeSelector<PFP>(m, pos) // EdgeSelector<PFP>(m, pos)
{ // {
edgeInfo = m.template addAttribute<EdgeInfo>(EDGE, "edgeInfo") ; // edgeInfo = m.template addAttribute<EdgeInfo>(EDGE, "edgeInfo") ;
} // }
//
~EdgeSelector_Length() // ~EdgeSelector_Length()
{ // {
this->m_map.removeAttribute(edgeInfo) ; // this->m_map.removeAttribute(edgeInfo) ;
} // }
//
SelectorType getType() { return S_EdgeLength; } // SelectorType getType() { return S_EdgeLength; }
Dart nexCell() { return (*cur).second; } // Dart nexCell() { return (*cur).second; }
//
void init(Algo::DecimationVolumique::Approximator<PFP>* approx); // void init(Algo::DecimationVolumique::Approximator<PFP>* approx);
bool nextOperator(); // bool nextOperator();
void updateBeforeOperation(Algo::DecimationVolumique::Operator<PFP>* op); // void updateBeforeOperation(Algo::DecimationVolumique::Operator<PFP>* op);
void updateAfterOperation(Algo::DecimationVolumique::Operator<PFP>* op); // void updateAfterOperation(Algo::DecimationVolumique::Operator<PFP>* op);
void finish() // void finish()
{ } // { }
}; //};
} //end namespace DecimationVolumes
} //end namespace DecimationVolumique
} //end namespace Algo } //end namespace Algo
} //end namespace CGoGN } //end namespace CGoGN