Commit c052557b authored by untereiner's avatar untereiner

deleting some old files

parent 55cb77c0
/*******************************************************************************
* 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"
#include "Algo/DecimationVolumes/predictor.h"
namespace CGoGN
{
namespace Algo
{
namespace Volume
{
namespace Decimation
{
enum ApproximatorType
{
A_QEM,
A_MidEdge,
A_MidFace,
A_MidVolume,
A_hHalfEdgeCollapse,
A_QEM
};
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(unsigned int index = 0) const = 0 ;
virtual ApproximatorType getType() const = 0 ;
virtual bool init() = 0 ;
virtual void approximate(Dart d) = 0 ;
virtual void saveApprox(Dart d) = 0 ;
virtual void affectApprox(Dart d) = 0 ;
virtual const PredictorGen<PFP>* getPredictor() const = 0 ;
} ;
template <typename PFP, typename T, unsigned int ORBIT>
class Approximator : public ApproximatorGen<PFP>
{
public:
typedef typename PFP::MAP MAP ;
typedef typename PFP::VEC3 VEC3 ;
typedef typename PFP::REAL REAL;
protected:
Predictor<PFP, T>* m_predictor ;
std::vector<VertexAttribute<T>* > m_attrV ; // vertex attributes to be approximated
std::vector<AttributeHandler<T,ORBIT> > m_approx ; // attributes to store approximation result
std::vector<AttributeHandler<T,ORBIT> > m_detail ; // attributes to store detail information for reconstruction
std::vector<T> m_app ;
public:
Approximator(MAP& m, std::vector<VertexAttribute<T>* > va, Predictor<PFP, T> * predictor) :
ApproximatorGen<PFP>(m), m_predictor(predictor), m_attrV(va)
{
const unsigned int& size = m_attrV.size() ;
assert(size > 0 || !"Approximator: no attributes provided") ;
m_approx.resize(size) ;
m_detail.resize(size) ;
m_app.resize(size) ;
for (unsigned int i = 0 ; i < size ; ++i)
{
if (!m_attrV[i]->isValid())
std::cerr << "Approximator Warning: attribute number " << i << " is not valid" << std::endl ;
std::stringstream aname ;
aname << "approx_" << m_attrV[i]->name() ;
m_approx[i] = this->m_map.template addAttribute<T, ORBIT>(aname.str()) ;
if(m_predictor) // if predictors are associated to the approximator
{ // create attributes to store the details needed for reconstruction
std::stringstream dname ;
dname << "detail_" << m_attrV[i]->name() ;
m_detail[i] = this->m_map.template addAttribute<T, ORBIT>(dname.str()) ;
}
}
}
virtual ~Approximator()
{
for (unsigned int i = 0 ; i < m_attrV.size() ; ++i)
{
this->m_map.template removeAttribute(m_approx[i]) ;
if(m_predictor)
this->m_map.template removeAttribute(m_detail[i]) ;
}
}
const std::string& getApproximatedAttributeName(unsigned int index = 0) const
{
return m_attrV[index]->name() ;
}
unsigned int getNbApproximated() const
{
return m_attrV.size() ;
}
void saveApprox(Dart d)
{
for (unsigned int i = 0 ; i < m_attrV.size() ; ++i)
m_app[i] = m_approx[i][d] ;
}
void affectApprox(Dart d)
{
for (unsigned int i = 0 ; i < m_attrV.size() ; ++i)
m_attrV[i]->operator[](d) = m_app[i] ;
}
const T& getApprox(Dart d, unsigned int index = 0) const
{
return m_approx[index][d] ;
}
const VertexAttribute<T>& getAttr(unsigned int index = 0) const
{
return *(m_attrV[index]) ;
}
std::vector<T> getAllApprox(Dart d) const
{
std::vector<T> res ;
res.resize(m_attrV.size()) ;
for (unsigned int i = 0 ; i < m_attrV.size() ; ++i)
res[i] = m_approx[i][d] ;
return res ;
}
const Predictor<PFP, T>* getPredictor() const
{
return m_predictor ;
}
};
} // namespace Decimation
} // namespace Volume
} // 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/edgeSelector.h"
#include "Algo/DecimationVolumes/geometryApproximator.h"
#include "Algo/DecimationVolumes/operator.h"
namespace CGoGN
{
namespace Algo
{
namespace Volume
{
namespace Decimation
{
template <typename PFP>
void decimate(
typename PFP::MAP& map,
SelectorType s,
ApproximatorType a,
VertexAttribute<typename PFP::VEC3>& position,
unsigned int percentWantedVertices
);
} //namespace Decimation
} //namesapce Volume
} //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 Volume
{
namespace Decimation
{
template <typename PFP>
void decimate(typename PFP::MAP& map, SelectorType s, ApproximatorType a,
VertexAttribute<typename PFP::VEC3>& position, unsigned int percentWantedVertices)
{
std::vector<ApproximatorGen<PFP>*> approximators ;
Selector<PFP>* selector = NULL ;
//choose the Approximator
switch(a)
{
case A_MidEdge :
approximators.push_back(new Approximator_MidEdge<PFP>(map, position)) ;
break ;
default :
CGoGNout << "not yet implemented" << CGoGNendl;
break;
}
//choose the Selector
switch(s)
{
case S_MapOrder :
selector = new Algo::Volume::Decimation::EdgeSelector_MapOrder<PFP>(map, position, approximators) ;
break ;
case S_Random :
selector = new Algo::Volume::Decimation::EdgeSelector_Random<PFP>(map, position, approximators) ;
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>() ;
unsigned int nbWantedVertices = nbVertices * percentWantedVertices / 100 ;
CGoGNout << " decimate (" << nbVertices << " vertices).." << /* flush */ CGoGNendl ;
bool finished = false ;
Dart d;
while(!finished)
{
if(!selector->nextEdge(d))
break ;
std::cout << "d = " << d << std::endl;
--nbVertices ;
Dart d2 = map.phi2(map.phi_1(d)) ;
Dart dd2 = map.phi2(map.phi_1(map.phi2(d))) ;
for(typename std::vector<ApproximatorGen<PFP>*>::iterator it = approximators.begin(); it != approximators.end(); ++it)
{
(*it)->approximate(d) ; // compute approximated attributes
(*it)->saveApprox(d) ;
}
selector->updateBeforeCollapse(d) ; // update selector
map.collapseEdge(d) ; // collapse edge
if(!map.check())
finished = true;
for(typename std::vector<ApproximatorGen<PFP>*>::iterator it = approximators.begin(); it != approximators.end(); ++it)
(*it)->affectApprox(d2); // affect data to the resulting vertex
selector->updateAfterCollapse(d2, dd2) ;// update selector
if(nbVertices <= nbWantedVertices)
finished = true ;
}
CGoGNout << "..done (" << nbVertices << " vertices)" << CGoGNendl ;
delete selector ;
for(typename std::vector<ApproximatorGen<PFP>*>::iterator it = approximators.begin(); it != approximators.end(); ++it)
delete (*it) ;
}
} //namespace Decimation
} //namespace Volume
} //namespace Algo
} //namespace CGoGN
// if(!selector->nextEdge(d))
// break ;
//
//
// Dart d2 = map.phi2(map.phi_1(d)) ;
// Dart dd2 = map.phi2(map.phi_1(map.phi2(d))) ;
//
// std::cout << "bin a contracter : " << d << std::endl;
// std::cout << "voisin d2 : " << d2 << std::endl;
// std::cout << "voisin dd2 : " << dd2 << std::endl;
//
// --nbVertices ;
//
// for(typename std::vector<ApproximatorGen<PFP>*>::iterator it = approximators.begin(); it != approximators.end(); ++it)
// {
// (*it)->approximate(d) ; // compute approximated attributes
// (*it)->saveApprox(d) ;
// }
//
// selector->updateBeforeCollapse(d) ; // update selector
//
// map.collapseEdge(d) ; // collapse edge
//
// for(typename std::vector<ApproximatorGen<PFP>*>::iterator it = approximators.begin(); it != approximators.end(); ++it)
// (*it)->affectApprox(d2); // affect data to the resulting vertex
//
// selector->updateAfterCollapse(d2, dd2) ;// update selector
//
// if(nbVertices <= nbWantedVertices)
// finished = true ;
#ifndef __EDGE_SELECTOR_VOLUMES_H__
#define __EDGE_SELECTOR_VOLUMES_H__
#include "Container/fakeAttribute.h"
#include "Algo/DecimationVolumes/selector.h"
#include "Utils/qem.h"
#include "Topology/generic/traversorCell.h"
namespace CGoGN
{
namespace Algo
{
namespace Volume
{
namespace Decimation
{
/*
* Map Order
*/
template <typename PFP>
class EdgeSelector_MapOrder : public Selector<PFP>
{
public:
typedef typename PFP::MAP MAP ;
typedef typename PFP::VEC3 VEC3 ;
typedef typename PFP::REAL REAL ;
private:
Dart cur ;
public:
EdgeSelector_MapOrder(MAP& m, VertexAttribute<typename PFP::VEC3>& pos, std::vector<ApproximatorGen<PFP>*>& approx) :
Selector<PFP>(m, pos, approx)
{}
~EdgeSelector_MapOrder()
{}
SelectorType getType() { return S_MapOrder ; }
bool init() ;
bool nextEdge(Dart& d) ;
void updateBeforeCollapse(Dart d)
{}
void updateAfterCollapse(Dart d2, Dart dd2) ;
void updateWithoutCollapse() { }
} ;
/*
* Random
*/
template <typename PFP>
class EdgeSelector_Random : public Selector<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) :
Selector<PFP>(m, pos, approx),
cur(0),
allSkipped(false)
{}
~EdgeSelector_Random()
{}
SelectorType getType() { return S_Random ; }
bool init() ;
bool nextEdge(Dart& d) ;
void updateBeforeCollapse(Dart d2)
{}
void updateAfterCollapse(Dart d2, Dart dd2) ;
void updateWithoutCollapse() { }
} ;
/*
* Edge Length
*/
template <typename PFP>
class EdgeSelector_Length : public Selector<PFP>
{
public:
typedef typename PFP::MAP MAP ;
typedef typename PFP::VEC3 VEC3 ;
typedef typename PFP::REAL REAL ;
private:
typedef struct
{
typename std::multimap<float,Dart>::iterator it ;
bool valid ;
static std::string CGoGNnameOfType() { return "LengthEdgeInfo" ; }
} LengthEdgeInfo ;
typedef NoTypeNameAttribute<LengthEdgeInfo> EdgeInfo ;
EdgeAttribute<EdgeInfo> edgeInfo ;
std::multimap<float,Dart> edges ;
typename std::multimap<float,Dart>::iterator cur ;
void initEdgeInfo(Dart d) ;
void updateEdgeInfo(Dart d, bool recompute) ;
void computeEdgeInfo(Dart d, EdgeInfo& einfo) ;
public:
EdgeSelector_Length(MAP& m, VertexAttribute<typename PFP::VEC3>& pos, std::vector<ApproximatorGen<PFP>*>& approx) :
Selector<PFP>(m, pos, approx)
{
edgeInfo = m.template addAttribute<EdgeInfo, EDGE>("edgeInfo") ;
}
~EdgeSelector_Length()
{
this->m_map.removeAttribute(edgeInfo) ;
}
SelectorType getType() { return S_EdgeLength ; }
bool init() ;
bool nextEdge(Dart& d) ;
void updateBeforeCollapse(Dart d) ;
void updateAfterCollapse(Dart d2, Dart dd2) ;
void updateWithoutCollapse() { }
} ;
/*
* Progressive Tetrahedralizations [SG98]
* Oliver Staadt && Markus Gross
*/
template <typename PFP>
class EdgeSelector_SG98 : public Selector<PFP>
{
public:
typedef typename PFP::MAP MAP ;
typedef typename PFP::VEC3 VEC3 ;
typedef typename PFP::REAL REAL ;
private:
typedef struct
{
typename std::multimap<float,Dart>::iterator it ;
bool valid ;
static std::string CGoGNnameOfType() { return "SG98edgeInfo" ; }
} SG98edgeInfo ;
typedef NoTypeNameAttribute<SG98edgeInfo> EdgeInfo ;
EdgeAttribute<EdgeInfo> edgeInfo ;
std::multimap<float,Dart> edges ;
typename std::multimap<float,Dart>::iterator cur ;
Approximator<PFP, typename PFP::VEC3>* m_positionApproximator ;
void initEdgeInfo(Dart d) ;
void updateEdgeInfo(Dart d, bool recompute) ;
void computeEdgeInfo(Dart d, EdgeInfo& einfo) ;
public:
EdgeSelector_SG98(MAP& m, VertexAttribute<typename PFP::VEC3>& pos, std::vector<ApproximatorGen<PFP>*>& approx) :
Selector<PFP>(m, pos, approx), m_positionApproximator(NULL)
{
edgeInfo = m.template addAttribute<EdgeInfo, EDGE>("edgeInfo") ;
}
~EdgeSelector_SG98()
{
this->m_map.removeAttribute(edgeInfo) ;
}
SelectorType getType() { return S_SG98 ; }
bool init() ;
bool nextEdge(Dart& d) ;
void updateBeforeCollapse(Dart d);
void updateAfterCollapse(Dart d2, Dart dd2) ;
void updateWithoutCollapse() { }
} ;
} //end namespace Decimation
} //namespace Volume
} //end namespace Algo
} //end namespace CGoGN
#include "Algo/DecimationVolumes/edgeSelector.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 *
* *
*******************************************************************************/
#include "Algo/DecimationVolumes/geometryApproximator.h"
#include "Algo/Geometry/volume.h"
#include <time.h>
namespace CGoGN
{
namespace Algo
{
namespace Volume
{
namespace Decimation
{
/************************************************************************************
* MAP ORDER *
************************************************************************************/
template <typename PFP>
bool EdgeSelector_MapOrder<PFP>::init()
{
MAP& m = this->m_map ;
cur = m.begin() ;
while(!m.edgeCanCollapse(cur))
{
m.next(cur) ;
if(cur == m.end())
return false;
}
return true ;
}
template <typename PFP>
bool EdgeSelector_MapOrder<PFP>::nextEdge(Dart& d)
{
MAP& m = this->m_map ;
if(cur == m.end())
return false ;
d = cur ;
return true ;
}
template <typename PFP>
void EdgeSelector_MapOrder<PFP>::updateAfterCollapse(Dart d2, Dart dd2)
{
MAP& m = this->m_map ;
cur = m.begin() ;
while(!this->m_select(cur) || !m.edgeCanCollapse(cur))
{
m.next(cur) ;
if(cur == m.end())
break ;
}
}