Création d'un compte pour un collaborateur extérieur au laboratoire depuis l'intranet ICube : https://intranet.icube.unistra.fr/fr/labs/member/profile

Commit fb95e191 authored by Sylvain Thery's avatar Sylvain Thery
Browse files

Merge branch 'master' of cgogn:~vanhoey/CGoGN

parents 2f7d4461 7af03e77
......@@ -39,11 +39,13 @@ namespace Decimation
enum ApproximatorType
{
A_QEM,
A_QEMhalfEdge,
A_MidEdge,
A_HalfCollapse,
A_CornerCutting,
A_TangentPredict1,
A_TangentPredict2,
A_LightfieldHalf,
A_LightfieldFull
} ;
......
......@@ -25,7 +25,8 @@
#ifndef __DECIMATION_H__
#define __DECIMATION_H__
#include "Algo/Decimation/selector.h"
#include "Algo/Decimation/edgeSelector.h"
#include "Algo/Decimation/halfEdgeSelector.h"
#include "Algo/Decimation/geometryApproximator.h"
#include "Algo/Decimation/lightfieldApproximator.h"
......
......@@ -45,6 +45,9 @@ void decimate(
case A_QEM :
approximators.push_back(new Approximator_QEM<PFP>(map, position)) ;
break ;
case A_QEMhalfEdge :
approximators.push_back(new Approximator_QEMhalfEdge<PFP>(map, position)) ;
break ;
case A_MidEdge :
approximators.push_back(new Approximator_MidEdge<PFP>(map, position)) ;
break ;
......@@ -62,13 +65,44 @@ void decimate(
break ;
case A_LightfieldFull :
{
approximators.push_back(new Approximator_QEM<PFP>(map, position)) ;
approximators.push_back(new Approximator_QEMhalfEdge<PFP>(map, position)) ;
/*
PFP::TVEC3 frame[3] ;
frame[0] = map.template getAttribute<typename PFP::VEC3>(VERTEX_ORBIT, "frame_T") ; // Tangent
frame[1] = map.template getAttribute<typename PFP::VEC3>(VERTEX_ORBIT, "frame_B") ; // Bitangent
frame[2] = map.template getAttribute<typename PFP::VEC3>(VERTEX_ORBIT, "frame_N") ; // Normal
for (unsigned int i = 0 ; i < 3 ; ++i)
if (!frame[i].isValid()) {
std::cerr << "In function decimate : frame[" << i << "] is not valid" << std::endl ;
}
AttributeHandler<typename PFP::VEC3> colorPTM[6] ;
colorPTM[0] = map.template getAttribute<typename PFP::VEC3>(VERTEX_ORBIT, "colorPTM_a") ;
colorPTM[1] = map.template getAttribute<typename PFP::VEC3>(VERTEX_ORBIT, "colorPTM_b") ;
colorPTM[2] = map.template getAttribute<typename PFP::VEC3>(VERTEX_ORBIT, "colorPTM_c") ;
colorPTM[3] = map.template getAttribute<typename PFP::VEC3>(VERTEX_ORBIT, "colorPTM_d") ;
colorPTM[4] = map.template getAttribute<typename PFP::VEC3>(VERTEX_ORBIT, "colorPTM_e") ;
colorPTM[5] = map.template getAttribute<typename PFP::VEC3>(VERTEX_ORBIT, "colorPTM_f") ;
for (unsigned int i = 0 ; i < 6 ; ++i)
if (!colorPTM[i].isValid()) {
std::cerr << "In function decimate : colorPTM[" << i << "] is not valid" << std::endl ;
}
*/
AttributeHandler<Geom::Matrix<3,3,typename PFP::REAL> > frame = map.template getAttribute<Geom::Matrix<3,3,typename PFP::REAL> >(VERTEX_ORBIT, "frame") ;
AttributeHandler<Geom::Matrix<3,6,typename PFP::REAL> > RGBfunctions = map.template getAttribute<Geom::Matrix<3,6,typename PFP::REAL> >(VERTEX_ORBIT, "RGBfunctions") ;
AttributeHandler<Geom::Matrix<3,6,typename PFP::REAL> > RGBfunctions = map.template getAttribute<Geom::Matrix<3,6,typename PFP::REAL> >(VERTEX_ORBIT, "colorPTM") ;
approximators.push_back(new Approximator_Frame<PFP>(map, frame)) ;
approximators.push_back(new Approximator_RGBfunctions<PFP>(map, RGBfunctions)) ;
break ;
}
case A_LightfieldHalf :
{
approximators.push_back(new Approximator_HalfCollapse<PFP>(map, position)) ;
AttributeHandler<Geom::Matrix<3,3,typename PFP::REAL> > frame = map.template getAttribute<Geom::Matrix<3,3,typename PFP::REAL> >(VERTEX_ORBIT, "frame") ;
AttributeHandler<Geom::Matrix<3,6,typename PFP::REAL> > RGBfunctions = map.template getAttribute<Geom::Matrix<3,6,typename PFP::REAL> >(VERTEX_ORBIT, "colorPTM") ;
approximators.push_back(new Approximator_FrameHalf<PFP>(map, frame)) ;
approximators.push_back(new Approximator_RGBfunctionsHalf<PFP>(map, RGBfunctions)) ;
break ;
}
}
switch(s)
......@@ -82,18 +116,24 @@ void decimate(
case S_EdgeLength :
selector = new EdgeSelector_Length<PFP>(map, position, approximators) ;
break ;
case S_QEMml :
selector = new EdgeSelector_QEMml<PFP>(map, position, approximators) ;
break ;
case S_QEM :
selector = new EdgeSelector_QEM<PFP>(map, position, approximators) ;
break ;
case S_Lightfield :
selector = new EdgeSelector_Lightfield<PFP>(map, position, approximators) ;
break ;
case S_Curvature :
selector = new EdgeSelector_Curvature<PFP>(map, position, approximators) ;
break ;
case S_MinDetail :
selector = new EdgeSelector_Random<PFP>(map, position, approximators) ;
break ;
case S_hLightfield :
selector = new HalfEdgeSelector_Lightfield<PFP>(map, position, approximators) ;
break ;
case S_hQEMml :
selector = new HalfEdgeSelector_QEMml<PFP>(map, position, approximators) ;
break ;
}
for(typename std::vector<ApproximatorGen<PFP>*>::iterator it = approximators.begin(); it != approximators.end(); ++it)
......@@ -105,10 +145,16 @@ void decimate(
unsigned int nbVertices = map.getNbOrbits(VERTEX_ORBIT) ;
bool finished = false ;
Dart d ;
while(!finished)
{
if(!selector->nextEdge(d))
std::cout << "Countdown : " ;
std::cout << std::setprecision(8) << (nbVertices - nbWantedVertices) << "\r" << std::flush;
if(!selector->nextEdge(d)) {
std::cout << std::endl << "out" << std::endl ;
break ;
}
--nbVertices ;
......@@ -130,8 +176,10 @@ void decimate(
selector->updateAfterCollapse(d2, dd2) ;// update selector
if(nbVertices <= nbWantedVertices)
if(nbVertices <= nbWantedVertices) {
finished = true ;
std::cout << std::endl << "done" << std::endl ;
}
}
delete selector ;
......
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009, 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: https://iggservis.u-strasbg.fr/CGoGN/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#ifndef __EDGESELECTOR_H__
#define __EDGESELECTOR_H__
#include "Algo/Decimation/selector.h"
namespace CGoGN
{
namespace Algo
{
namespace Decimation
{
template <typename PFP>
class EdgeSelector_MapOrder : public EdgeSelector<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, typename PFP::TVEC3& pos, std::vector<ApproximatorGen<PFP>*>& approx, const FunctorSelect& select = SelectorTrue()) :
EdgeSelector<PFP>(m, pos, approx, select)
{}
~EdgeSelector_MapOrder()
{}
SelectorType getType() { return S_MapOrder ; }
bool init() ;
bool nextEdge(Dart& d) ;
void updateBeforeCollapse(Dart d)
{}
void updateAfterCollapse(Dart d2, Dart dd2) ;
} ;
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, typename PFP::TVEC3& pos, std::vector<ApproximatorGen<PFP>*>& approx, const FunctorSelect& select = SelectorTrue()) :
EdgeSelector<PFP>(m, pos, approx, select)
{}
~EdgeSelector_Random()
{}
SelectorType getType() { return S_Random ; }
bool init() ;
bool nextEdge(Dart& d) ;
void updateBeforeCollapse(Dart d2)
{}
void updateAfterCollapse(Dart d2, Dart dd2) ;
} ;
template <typename PFP>
class EdgeSelector_Length : public EdgeSelector<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 NoMathIOAttribute<LengthEdgeInfo> EdgeInfo ;
AttributeHandler<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, typename PFP::TVEC3& pos, std::vector<ApproximatorGen<PFP>*>& approx, const FunctorSelect& select = SelectorTrue()) :
EdgeSelector<PFP>(m, pos, approx, select)
{
edgeInfo = m.template addAttribute<EdgeInfo>(EDGE_ORBIT, "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) ;
} ;
template <typename PFP>
class EdgeSelector_QEM : public EdgeSelector<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 "QEMedgeInfo" ; }
} QEMedgeInfo ;
typedef NoMathIOAttribute<QEMedgeInfo> EdgeInfo ;
AttributeHandler<EdgeInfo> edgeInfo ;
AttributeHandler<Quadric<REAL> > quadric ;
Quadric<REAL> tmpQ ;
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_QEM(MAP& m, typename PFP::TVEC3& pos, std::vector<ApproximatorGen<PFP>*>& approx, const FunctorSelect& select = SelectorTrue()) :
EdgeSelector<PFP>(m, pos, approx, select)
{
edgeInfo = m.template addAttribute<EdgeInfo>(EDGE_ORBIT, "edgeInfo") ;
quadric = m.template addAttribute<Quadric<REAL> >(VERTEX_ORBIT, "QEMquadric") ;
}
~EdgeSelector_QEM()
{
this->m_map.removeAttribute(quadric) ;
this->m_map.removeAttribute(edgeInfo) ;
}
SelectorType getType() { return S_QEM ; }
bool init() ;
bool nextEdge(Dart& d) ;
void updateBeforeCollapse(Dart d) ;
void updateAfterCollapse(Dart d2, Dart dd2) ;
} ;
template <typename PFP>
class EdgeSelector_QEMml : public EdgeSelector<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 "QEMedgeInfo" ; }
} QEMedgeInfo ;
typedef NoMathIOAttribute<QEMedgeInfo> EdgeInfo ;
AttributeHandler<EdgeInfo> edgeInfo ;
AttributeHandler<Quadric<REAL> > quadric ;
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) ;
void recomputeQuadric(const Dart d, const bool recomputeNeighbors = false) ;
public:
EdgeSelector_QEMml(MAP& m, typename PFP::TVEC3& pos, std::vector<ApproximatorGen<PFP>*>& approx, const FunctorSelect& select = SelectorTrue()) :
EdgeSelector<PFP>(m, pos, approx, select)
{
edgeInfo = m.template addAttribute<EdgeInfo>(EDGE_ORBIT, "edgeInfo") ;
quadric = m.template addAttribute<Quadric<REAL> >(VERTEX_ORBIT, "QEMquadric") ;
}
~EdgeSelector_QEMml()
{
this->m_map.removeAttribute(quadric) ;
this->m_map.removeAttribute(edgeInfo) ;
}
SelectorType getType() { return S_QEMml ; }
bool init() ;
bool nextEdge(Dart& d) ;
void updateBeforeCollapse(Dart d) ;
void updateAfterCollapse(Dart d2, Dart dd2) ;
} ;
template <typename PFP>
class EdgeSelector_Curvature : public EdgeSelector<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 "CurvatureEdgeInfo" ; }
} CurvatureEdgeInfo ;
typedef NoMathIOAttribute<CurvatureEdgeInfo> EdgeInfo ;
typename PFP::TVEC3 normal ;
AttributeHandler<EdgeInfo> edgeInfo ;
typename PFP::TREAL k1 ;
typename PFP::TREAL k2 ;
typename PFP::TVEC3 K1 ;
typename PFP::TVEC3 K2 ;
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_Curvature(MAP& m, typename PFP::TVEC3& pos, std::vector<ApproximatorGen<PFP>*>& approx, const FunctorSelect& select = SelectorTrue()) :
EdgeSelector<PFP>(m, pos, approx, select)
{
normal = m.template getAttribute<VEC3>(VERTEX_ORBIT, "normal") ;
if(!normal.isValid())
{
normal = m.template addAttribute<VEC3>(VERTEX_ORBIT, "normal") ;
Algo::Geometry::computeNormalVertices<PFP>(m, pos, normal) ;
}
k1 = m.template getAttribute<REAL>(VERTEX_ORBIT, "k1") ;
k2 = m.template getAttribute<REAL>(VERTEX_ORBIT, "k2") ;
K1 = m.template getAttribute<VEC3>(VERTEX_ORBIT, "K1") ;
K2 = m.template getAttribute<VEC3>(VERTEX_ORBIT, "K2") ;
// as all these attributes are computed simultaneously by computeCurvatureVertices
// one can assume that if one of them is not valid, the others must be created too
if(!k1.isValid())
{
k1 = m.template addAttribute<REAL>(VERTEX_ORBIT, "k1") ;
k2 = m.template addAttribute<REAL>(VERTEX_ORBIT, "k2") ;
K1 = m.template addAttribute<VEC3>(VERTEX_ORBIT, "K1") ;
K2 = m.template addAttribute<VEC3>(VERTEX_ORBIT, "K2") ;
Algo::Geometry::computeCurvatureVertices<PFP>(m, this->m_position, normal, k1, k2, K1, K2) ;
}
edgeInfo = m.template addAttribute<EdgeInfo>(EDGE_ORBIT, "edgeInfo") ;
}
~EdgeSelector_Curvature()
{
this->m_map.removeAttribute(k1) ;
this->m_map.removeAttribute(k2) ;
this->m_map.removeAttribute(K1) ;
this->m_map.removeAttribute(K2) ;
this->m_map.removeAttribute(edgeInfo) ;
}
SelectorType getType() { return S_Curvature ; }
bool init() ;
bool nextEdge(Dart& d) ;
void updateBeforeCollapse(Dart d) ;
void updateAfterCollapse(Dart d2, Dart dd2) ;
} ;
template <typename PFP>
class EdgeSelector_MinDetail : public EdgeSelector<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 "MinDetailEdgeInfo" ; }
} MinDetailEdgeInfo ;
typedef NoMathIOAttribute<MinDetailEdgeInfo> EdgeInfo ;
AttributeHandler<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_MinDetail(MAP& m, typename PFP::TVEC3& pos, std::vector<ApproximatorGen<PFP>*>& approx, const FunctorSelect& select = SelectorTrue()) :
EdgeSelector<PFP>(m, pos, approx, select)
{
edgeInfo = m.template addAttribute<EdgeInfo>(EDGE_ORBIT, "edgeInfo") ;
}
~EdgeSelector_MinDetail()
{
this->m_map.removeAttribute(edgeInfo) ;
}
SelectorType getType() { return S_MinDetail ; }
bool init() ;
bool nextEdge(Dart& d) ;
void updateBeforeCollapse(Dart d) ;
void updateAfterCollapse(Dart d2, Dart dd2) ;
} ;
} // namespace Decimation
} // namespace Algo
} // namespace CGoGN
#include "Algo/Decimation/edgeSelector.hpp"
#endif
......@@ -473,45 +473,34 @@ void EdgeSelector_QEM<PFP>::computeEdgeInfo(Dart d, EdgeInfo& einfo)
m_positionApproximator->approximate(d) ;
REAL err = quad(m_positionApproximator->getApprox(d)) ;
REAL err = std::max(REAL(0),REAL(quad(m_positionApproximator->getApprox(d)))) ;
einfo.it = edges.insert(std::make_pair(err, d)) ;
einfo.valid = true ;
}
/************************************************************************************
* EDGESELECTOR LIGHTFIELD *
* QUADRIC ERROR METRIC (Memoryless version) *
************************************************************************************/
template <typename PFP>
bool EdgeSelector_Lightfield<PFP>::init()
bool EdgeSelector_QEMml<PFP>::init()
{
MAP& m = this->m_map ;
// Verify availability of required approximators
char ok = 0 ;
bool ok = false ;
for(typename std::vector<ApproximatorGen<PFP>*>::iterator it = this->m_approximators.begin();
it != this->m_approximators.end();
it != this->m_approximators.end() && !ok;
++it)
{
// constraint : 3 approximators in specific order
if(ok == 0 && (*it)->getApproximatedAttributeName() == "position")
{
m_positionApproximator = reinterpret_cast<Approximator<PFP, VEC3>* >(*it) ; // 1) position
++ok ;
}
else if( ok == 1 && (*it)->getApproximatedAttributeName() == "frame")
{
m_frameApproximator = reinterpret_cast<Approximator<PFP, FRAME>* >(*it) ; // 2) frame (needs position)
++ok ;
}
else if(ok == 2 && (*it)->getApproximatedAttributeName() == "RGBfunctions")
if((*it)->getApproximatedAttributeName() == "position")
{
m_RGBfunctionsApproximator = reinterpret_cast<Approximator<PFP, RGBFUNCTIONS>* >(*it) ; // 3) functions (needs frame)
++ok ;
m_positionApproximator = reinterpret_cast<Approximator<PFP, VEC3>* >(*it) ;
ok = true ;
}
}
if(ok != 3)
if(!ok)
return false ;
edges.clear() ;
......@@ -521,24 +510,23 @@ bool EdgeSelector_Lightfield<PFP>::init()
{
if(!vMark.isMarked(d))
{
Quadric<REAL> q ; // create one quadric
quadric[d] = q ; // per vertex
Quadric<REAL> q ; // create one quadric
quadric[d] = q ; // per vertex
vMark.mark(d) ;
}
}
DartMarker mark(m) ;
for(Dart d = m.begin(); d != m.end(); m.next(d)) // init QEM quadrics
for(Dart d = m.begin(); d != m.end(); m.next(d))
{
if(!mark.isMarked(d))
{
Dart d1 = m.phi1(d) ; // for each triangle,
Dart d_1 = m.phi_1(d) ; // initialize the quadric of the triangle
Dart d1 = m.phi1(d) ; // for each triangle,
Dart d_1 = m.phi_1(d) ; // initialize the quadric of the triangle
Quadric<REAL> q(this->m_position[d], this->m_position[d1], this->m_position[d_1]) ;
quadric[d] += q ; // and add the contribution of
quadric[d1] += q ; // this quadric to the ones
quadric[d_1] += q ; // of the 3 incident vertices
quadric[d] += q ; // and add the contribution of
quadric[d1] += q ; // this quadric to the ones
quadric[d_1] += q ; // of the 3 incident vertices
mark.markOrbit(FACE_ORBIT, d) ;
}
}
......@@ -548,7 +536,7 @@ bool EdgeSelector_Lightfield<PFP>::init()
{
if(!eMark.isMarked(d))