Commit da43d0b3 by 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 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* op) = 0 ; virtual void saveApprox(Operator* op) = 0 ; virtual void affectApprox(Operator* op) = 0 ; } ; template class Approximator : public ApproximatorGen { public: typedef typename PFP::MAP MAP ; typedef typename PFP::REAL REAL; protected: //TODO ajouter un predictor VertexAttribute& 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& a): ApproximatorGen(m), m_attrV(a) {} virtual ~Approximator(); const std::string& getApproximatedAttributeName() const { return m_attrV.name() ; } void affectApprox(Operator* 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 void decimate( typename PFP::MAP& map, SelectorType s, ApproximatorType a, VertexAttribute& 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 void decimate( typename PFP::MAP& map, SelectorType s, ApproximatorType a, VertexAttribute& position, unsigned int nbWantedVertices, const FunctorSelect& selected ) { std::vector*> approximators ; Selector* selector = NULL ; //choose the Approximator switch(a) { case A_Centroid : approximators.push_back(new Approximator_Centroid(map, position)) ; break ; default : CGoGNout << "not yet implemented" << CGoGNendl; break; } //choose the Selector switch(s) { case S_MapOrder : selector = new EdgeSelector_MapOrder(map, position, approximators, selected); break ; case S_Random : selector = new EdgeSelector_Random(map, position, approximators, selected); break ; default: CGoGNout << "not yet implemented" << CGoGNendl; break; } for(typename std::vector*>::iterator it = approximators.begin(); it != approximators.end(); ++it) (*it)->init() ; if(!selector->init()) return ; unsigned int nbVertices = map.template getNbOrbits() ; bool finished = false ; while(!finished) { //Next Operator to perform Operator *op; if(!selector->nextOperator(op)) //a changer de nom break; // switch(selector->nextOperatorType()) // { // case O_CEdge : // op = new CollapseEdgeOperator(selector->nextCell(), approximators); // break; // case O_CFace : // break; // case O_CVolume: // break; // } for(typename std::vector*>::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*>::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*>::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 class Approximator ; //template class Operator ; /******************************************************************************** * Parent Selector * ********************************************************************************/ //class du Selector de base template class Selector { public: typedef typename PFP::MAP MAP ; typedef typename PFP::VEC3 VEC3 ; typedef typename PFP::REAL REAL; protected: /** * */ MAP& m_map ; /** * */ VertexAttribute& 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* m_approximator ; public: Selector(MAP& m, VertexAttribute& 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* approx) = 0 ; /** * */ virtual bool nextOperator() = 0 ; /** * */ virtual void updateBeforeOperation(Algo::DecimationVolumique::Operator* op) = 0 ; /** * */ virtual void updateAfterOperation(Algo::DecimationVolumique::Operator* op) = 0 ; /** * */ virtual void finish() = 0 ; /** * */ Algo::DecimationVolumique::Approximator* 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(m, pos) Selector(m, pos) {} {} /* * Initialiszation of the Edge selector * TODO */ virtual void init(Algo::DecimationVolumique::Approximator* approx); // /* // * Select the next dart to collapse // * TODO // */ // virtual bool nextOperator(Algo::DecimationVolumique::Operator* op); // /* // * TODO // */ // virtual void updateBeforeOperation(Algo::DecimationVolumique::Operator* op); // /* // * TODO // */ // virtual void updateAfterOperation(Algo::DecimationVolumique::Operator* 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* approx); void init(); bool nextOperator(); bool nextOperator(Operator* op); void updateBeforeOperation(Algo::DecimationVolumique::Operator* op) void updateBeforeOperation(Operator* op) { } { } void updateAfterOperation(Algo::DecimationVolumique::Operator* op); void updateAfterOperation(Operator* 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* approx); void init(); bool nextOperator(); bool nextOperator(Operator* op); void updateBeforeOperation(Algo::DecimationVolumique::Operator* op) void updateBeforeOperation(Operator* op) { } { } void updateAfterOperation(Algo::DecimationVolumique::Operator* op); void updateAfterOperation(Operator* op); void finish() void finish() { } { } } ; } ; /******************************************************************************** ///******************************************************************************** * Length Edge Selector * // * Length Edge Selector * ********************************************************************************/ // ********************************************************************************/ template //template class EdgeSelector_Length : public EdgeSelector //class EdgeSelector_Length : public EdgeSelector { //{ 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::iterator it ; // typename std::multimap::iterator it ; bool valid ; // bool valid ; } LengthEdgeInfo ; // } LengthEdgeInfo ; // typedef NoMathIOAttribute EdgeInfo ; // typedef NoMathIOAttribute EdgeInfo ; // EdgeAttribute edgeInfo ; // EdgeAttribute edgeInfo ; // std::multimap edges ; // std::multimap edges ; typename std::multimap::iterator cur ; // typename std::multimap::iterator cur ; // // public: //public: EdgeSelector_Length(MAP& m, VertexAttribute& pos) : // EdgeSelector_Length(MAP& m, VertexAttribute& pos) : EdgeSelector(m, pos) // EdgeSelector(m, pos) { // { edgeInfo = m.template addAttribute(EDGE, "edgeInfo") ; // edgeInfo = m.template addAttribute(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* approx); // void init(Algo::DecimationVolumique::Approximator* approx); bool nextOperator(); // bool nextOperator(); void updateBeforeOperation(Algo::DecimationVolumique::Operator* op); // void updateBeforeOperation(Algo::DecimationVolumique::Operator* op); void updateAfterOperation(Algo::DecimationVolumique::Operator* op); // void updateAfterOperation(Algo::DecimationVolumique::Operator* op); void finish() // void finish() { } // { } }; //}; } //end namespace DecimationVolumes } //end namespace DecimationVolumique } //end namespace Algo } //end namespace Algo } //end namespace CGoGN } //end namespace CGoGN