Commit 339e3d3d by Kenneth Vanhoey

### Add CPV decimation. Replace old code.

parent 2504d16e
 ... ... @@ -39,15 +39,16 @@ namespace Decimation enum ApproximatorType { A_QEM, A_QEMhalfEdge, A_hQEM, A_MidEdge, A_HalfCollapse, A_CornerCutting, A_TangentPredict1, A_TangentPredict2, A_LightfieldHalf, A_hColor /*A_LightfieldHalf, A_LightfieldHalf_deprecated, A_LightfieldFull_deprecated A_LightfieldFull_deprecated*/ } ; template ... ... @@ -102,6 +103,9 @@ public: m_detail.resize(m_attrV.size()) ; m_app.resize(m_attrV.size()) ; if (m_attrV.size() < 1) std::cerr << "Approximator: no attributes provided" << std::endl ; for (unsigned int i = 0 ; i < m_attrV.size() ; ++i) { std::stringstream aname ; ... ...
 ... ... @@ -38,113 +38,102 @@ namespace Decimation { template class Approximator_FrameHalf : public Approximator > class Approximator_Color : public Approximator { public: typedef typename PFP::MAP MAP ; typedef typename PFP::VEC3 VEC3 ; typedef typename PFP::REAL REAL ; typedef Geom::Matrix<3,3,REAL> MATRIX33 ; typedef Geom::Matrix<3,6,REAL> MATRIX36 ; protected: VertexAttribute *m_color ; public: Approximator_FrameHalf(MAP& m, VertexAttribute& frame, Predictor* pred = NULL) : Approximator(m, frame, pred) {} ~Approximator_FrameHalf() Approximator_Color(MAP& m, std::vector* >& attr, Predictor* pred = NULL) : Approximator(m, attr, pred) { m_color = this->m_attrV[0] ; assert((m_color->isValid() && m_color->name() == "color") || !"Approximator_Color: the approximated attribute is not valid or not named 'color'") ; } ~Approximator_Color() {} ApproximatorType getType() const { return A_LightfieldHalf ; } bool init() { return true ; } ; void approximate(Dart d) ; } ; template class Approximator_RGBfunctionsHalf : public Approximator > { public: typedef typename PFP::MAP MAP ; typedef typename PFP::VEC3 VEC3 ; typedef typename PFP::REAL REAL ; ApproximatorType getType() const { return A_hColor ; } typedef Geom::Matrix<3,3,REAL> MATRIX33 ; typedef Geom::Matrix<3,6,REAL> MATRIX36 ; bool init() { return true ; } protected: VertexAttribute m_frame ; EdgeAttribute m_approxFrame ; EdgeAttribute > m_quadricRGBfunctions ; public: Approximator_RGBfunctionsHalf(MAP& m, VertexAttribute& rgbfunctions, Predictor* pred = NULL) : Approximator(m, rgbfunctions, pred) { } ~Approximator_RGBfunctionsHalf () {} ApproximatorType getType() const { return A_LightfieldHalf ; } bool init() ; void approximate(Dart d) ; } ; /* template class Approximator_Frame : public Approximator > class Approximator_FrameHalf : public Approximator { public: typedef typename PFP::MAP MAP ; typedef typename PFP::VEC3 VEC3 ; typedef typename PFP::REAL REAL ; typedef Geom::Matrix<3,3,REAL> MATRIX33 ; typedef Geom::Matrix<3,6,REAL> MATRIX36 ; protected: VertexAttribute m_position ; EdgeAttribute m_approxPosition ; public: Approximator_Frame(MAP& m, VertexAttribute& frame, Predictor* pred = NULL) : Approximator(m, frame, pred) Approximator_FrameHalf(MAP& m, std::vector >& attr, Predictor* pred = NULL) : Approximator(m, attr, pred) {} ~Approximator_Frame() ~Approximator_FrameHalf() {} ApproximatorType getType() const { return A_LightfieldFull ; } bool init() ; ApproximatorType getType() const { return A_LightfieldHalf ; } bool init() { return true ; } void approximate(Dart d) ; } ; template class Approximator_RGBfunctions : public Approximator > class Approximator_LightfieldCoefsHalf : public Approximator { public: typedef typename PFP::MAP MAP ; typedef typename PFP::VEC3 VEC3 ; typedef typename PFP::REAL REAL ; typedef Geom::Matrix<3,3,REAL> MATRIX33 ; typedef Geom::Matrix<3,6,REAL> MATRIX36 ; protected: VertexAttribute m_frame ; EdgeAttribute m_approxFrame ; EdgeAttribute > m_quadricRGBfunctions ; public: Approximator_RGBfunctions(MAP& m, VertexAttribute& rgbfunctions, Predictor* pred = NULL) : Approximator(m, rgbfunctions, pred) { } ~Approximator_RGBfunctions() Approximator_LightfieldCoefsHalf(MAP& m, std::vector >& attr, Predictor* pred = NULL) : Approximator(m, attr, pred) {} ApproximatorType getType() const { return A_LightfieldFull ; } bool init() ; ~Approximator_LightfieldCoefsHalf() {} ApproximatorType getType() const { return A_LightfieldHalf ; } bool init() { return true ; } void approximate(Dart d) ; } ; */ } //namespace Decimation } //namespace Algo } //namespace CGoGN #include "Algo/Decimation/lightfieldApproximator.hpp" #include "Algo/Decimation/colorPerVertexApproximator.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 Decimation { /************************************************************************************ * COLOR METRIC * ************************************************************************************/ template void Approximator_Color::approximate(Dart d) { Dart dd = this->m_map.phi1(d) ; this->m_approx[0][d] = m_color->operator[](d) ; this->m_approx[0][d] += m_color->operator[](dd) ; this->m_approx[0][d] /= 2 ; } } //namespace Decimation } //namespace Algo } //namespace CGoGN
 ... ... @@ -28,7 +28,8 @@ #include "Algo/Decimation/edgeSelector.h" #include "Algo/Decimation/halfEdgeSelector.h" #include "Algo/Decimation/geometryApproximator.h" #include "Algo/Decimation/lightfieldApproximator.h" #include "Algo/Decimation/colorPerVertexApproximator.h" //#include "Algo/Decimation/lightfieldApproximator_deprecated.h" namespace CGoGN { ... ... @@ -46,7 +47,8 @@ void decimate( ApproximatorType a, VertexAttribute& position, unsigned int nbWantedVertices, const FunctorSelect& selected = allDarts const FunctorSelect& selected = allDarts, void (*callback_wrapper)(void*, const void*) = NULL, void *callback_object = NULL ) ; } //namespace Decimation ... ...
 ... ... @@ -34,39 +34,88 @@ namespace Decimation template void decimate( typename PFP::MAP& map, SelectorType s, ApproximatorType a, VertexAttribute& position, unsigned int nbWantedVertices, const FunctorSelect& selected VertexAttribute& position, unsigned int nbWantedVertices, const FunctorSelect& selected, void (*callback_wrapper)(void*, const void*), void* callback_object ) { std::vector*> approximators ; EdgeSelector* selector = NULL ; std::vector* > v_pos ; v_pos.push_back(&position) ; switch(a) { case A_QEM : approximators.push_back(new Approximator_QEM(map, position)) ; approximators.push_back(new Approximator_QEM(map, v_pos)) ; break ; case A_QEMhalfEdge : approximators.push_back(new Approximator_QEMhalfEdge(map, position)) ; case A_hQEM : approximators.push_back(new Approximator_QEMhalfEdge(map, v_pos)) ; break ; case A_MidEdge : approximators.push_back(new Approximator_MidEdge(map, position)) ; approximators.push_back(new Approximator_MidEdge(map, v_pos)) ; break ; case A_CornerCutting : approximators.push_back(new Approximator_CornerCutting(map, position)) ; approximators.push_back(new Approximator_CornerCutting(map, v_pos)) ; break ; case A_TangentPredict1 : approximators.push_back(new Approximator_MidEdge(map, position)) ; approximators.push_back(new Approximator_MidEdge(map, v_pos)) ; break ; case A_TangentPredict2 : approximators.push_back(new Approximator_MidEdge(map, position)) ; approximators.push_back(new Approximator_MidEdge(map, v_pos)) ; break ; case A_HalfCollapse : approximators.push_back(new Approximator_HalfCollapse(map, v_pos)) ; break ; case A_hColor : // pos approximators.push_back(new Approximator_HalfCollapse(map, v_pos)) ; // col std::vector* > v_col ; VertexAttribute colors = map.template getAttribute("color") ; v_col.push_back(&colors) ; approximators.push_back(new Approximator_Color(map, v_col)) ; break ; /*case A_LightfieldHalf: approximators.push_back(new Approximator_HalfCollapse(map, position)) ; // Get all frame embeddings std::vector* > vertexAttributesFrame ; VertexAttribute frame0 = myMap.getAttribute("frameT") ; vertexAttributesFrame.push_back(&frame0) ; VertexAttribute frame1 = myMap.getAttribute("frameB") ; vertexAttributesFrame.push_back(&frame1) ; VertexAttribute frame2 = myMap.getAttribute("frameN") ; vertexAttributesFrame.push_back(&frame2) ; approximators.push_back(new Approximator_FrameHalf(map, vertexAttributesFrame)) ; // TODO // Get all coefficient embeddings const unsigned int K = 200 ; std::vector* > vertexAttributesCoefs ; VertexAttribute *PBcoefs = new VertexAttribute[K] ; for (unsigned int k = 0 ; k < K ; ++k) { std::stringstream s ; s << "PBcoefs" << k ; PBcoefs[k] = myMap.getAttribute(s.str()) ; if (!PBcoefs[k].isValid()) break ; vertexAttributesCoefs.push_back(&PBcoefs[k]) ; } const bool& sh = vertexAttributesCoefs.empty() ; // sh or pb VertexAttribute *SHcoefs = new VertexAttribute[K] ; for (unsigned int k = 0 ; k < K ; ++k) { std::stringstream s ; s << "SHcoefs" << k ; SHcoefs[k] = myMap.getAttribute(s.str()) ; if (!SHcoefs[k].isValid()) break ; case A_LightfieldFull : vertexAttributesCoefs.push_back(&SHcoefs[k]) ; } approximators.push_back(new Approximator_LightfieldCoefsHalf(map, vertexAttributesCoefs, sh)) ; // TODO break ; case A_LightfieldFull_deprecated : { approximators.push_back(new Approximator_QEMhalfEdge(map, position)) ; /* / * PFP::TVEC3 frame[3] ; frame[0] = map.template getAttribute("frame_T") ; // Tangent frame[1] = map.template getAttribute("frame_B") ; // Bitangent ... ... @@ -87,22 +136,22 @@ void decimate( if (!colorPTM[i].isValid()) { CGoGNerr << "In function decimate : colorPTM[" << i << "] is not valid" << CGoGNendl ; } */ * VertexAttribute > frame = map.template getAttribute, VERTEX>("frame") ; VertexAttribute > RGBfunctions = map.template getAttribute, VERTEX>("colorPTM") ; approximators.push_back(new Approximator_Frame(map, frame)) ; approximators.push_back(new Approximator_RGBfunctions(map, RGBfunctions)) ; approximators.push_back(new Approximator_Frame_deprecated(map, frame)) ; approximators.push_back(new Approximator_RGBfunctions_deprecated(map, RGBfunctions)) ; break ; } case A_LightfieldHalf : case A_LightfieldHalf_deprecated : { approximators.push_back(new Approximator_HalfCollapse(map, position)) ; VertexAttribute > frame = map.template getAttribute, VERTEX>("frame") ; VertexAttribute > RGBfunctions = map.template getAttribute, VERTEX>("colorPTM") ; approximators.push_back(new Approximator_FrameHalf(map, frame)) ; approximators.push_back(new Approximator_RGBfunctionsHalf(map, RGBfunctions)) ; approximators.push_back(new Approximator_FrameHalf_deprecated(map, frame)) ; approximators.push_back(new Approximator_RGBfunctionsHalf_deprecated(map, RGBfunctions)) ; break ; } }*/ } switch(s) ... ... @@ -128,12 +177,15 @@ void decimate( case S_MinDetail : selector = new EdgeSelector_MinDetail(map, position, approximators, selected) ; break ; case S_hLightfield : selector = new HalfEdgeSelector_Lightfield(map, position, approximators, selected) ; break ; /*case S_hLightfield_deprecated : selector = new HalfEdgeSelector_Lightfield_deprecated(map, position, approximators, selected) ; break ;*/ case S_hQEMml : selector = new HalfEdgeSelector_QEMml(map, position, approximators, selected) ; break ; case S_hColor : selector = new HalfEdgeSelector_Color(map, position, approximators, selected) ; break ; } for(typename std::vector*>::iterator it = approximators.begin(); it != approximators.end(); ++it) ... ... @@ -148,11 +200,8 @@ void decimate( while(!finished) { // CGoGNout << "Countdown : " ; // CGoGNout << std::setprecision(8) << (nbVertices - nbWantedVertices) << "\r" << CGoGNflush ; if(!selector->nextEdge(d)) { // CGoGNout << CGoGNendl << "out" << CGoGNendl ; if(!selector->nextEdge(d)) { break ; } ... ... @@ -176,10 +225,14 @@ void decimate( selector->updateAfterCollapse(d2, dd2) ;// update selector if(nbVertices <= nbWantedVertices) { if(nbVertices <= nbWantedVertices) { finished = true ; // CGoGNout << CGoGNendl << "done" << CGoGNendl ; } // Progress bar support if (callback_wrapper != NULL && callback_object != NULL) callback_wrapper(callback_object, &nbVertices) ; } delete selector ; ... ...
 ... ... @@ -475,6 +475,8 @@ void EdgeSelector_QEM::computeEdgeInfo(Dart d, EdgeInfo& einfo) REAL err = std::max(REAL(0),REAL(quad(m_positionApproximator->getApprox(d)))) ; std::cout << quad(m_positionApproximator->getApprox(d)) << std::endl ; einfo.it = edges.insert(std::make_pair(err, d)) ; einfo.valid = true ; } ... ... @@ -1074,7 +1076,7 @@ void EdgeSelector_MinDetail::updateEdgeInfo(Dart d, bool recompute) template void EdgeSelector_MinDetail::computeEdgeInfo(Dart d, EdgeInfo& einfo) { Dart dd = this->m_map.phi2(d) ; // Dart dd = this->m_map.phi2(d) ; REAL err = REAL(0) ; // for(typename std::vector*>::iterator it = this->m_approximators.begin(); ... ...
 ... ... @@ -79,7 +79,7 @@ public: } ~Approximator_QEMhalfEdge() {} ApproximatorType getType() const { return A_QEMhalfEdge ; } ApproximatorType getType() const { return A_hQEM ; } bool init() ; void approximate(Dart d) ; } ; ... ...