Commit ea93f7ca authored by untereiner's avatar untereiner

adding catmull-clark and sqrt(3) lazy wavelets

parent d25284ab
...@@ -650,11 +650,14 @@ void MyQT::importMesh(std::string& filename) ...@@ -650,11 +650,14 @@ void MyQT::importMesh(std::string& filename)
else else
{ {
std::cerr << "could not import " << filename << std::endl ; std::cerr << "could not import " << filename << std::endl ;
return ;
} }
m_selected = NIL; m_selected = NIL;
m_selected2 = NIL; m_selected2 = NIL;
m_render_topo->updateData<PFP>(myMap, position, m_ex1,m_ex2,m_ex3, nb);
bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position) ; bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position) ;
setParamObject(bb.maxSize(), bb.center().data()) ; setParamObject(bb.maxSize(), bb.center().data()) ;
m_shift = bb.maxSize()/200.0f; m_shift = bb.maxSize()/200.0f;
......
...@@ -97,7 +97,7 @@ public: ...@@ -97,7 +97,7 @@ public:
{} {}
void updateAfterCollapse(Dart d2, Dart dd2) ; void updateAfterCollapse(Dart d2, Dart dd2) ;
void updateWithoutCollapse() { } void updateWithoutCollapse();
} ; } ;
template <typename PFP> template <typename PFP>
...@@ -142,7 +142,7 @@ public: ...@@ -142,7 +142,7 @@ public:
void updateBeforeCollapse(Dart d) ; void updateBeforeCollapse(Dart d) ;
void updateAfterCollapse(Dart d2, Dart dd2) ; void updateAfterCollapse(Dart d2, Dart dd2) ;
void updateWithoutCollapse() { } void updateWithoutCollapse();
} ; } ;
template <typename PFP> template <typename PFP>
...@@ -246,7 +246,7 @@ public: ...@@ -246,7 +246,7 @@ public:
void updateBeforeCollapse(Dart d) ; void updateBeforeCollapse(Dart d) ;
void updateAfterCollapse(Dart d2, Dart dd2) ; void updateAfterCollapse(Dart d2, Dart dd2) ;
void updateWithoutCollapse() { } void updateWithoutCollapse();
} ; } ;
template <typename PFP> template <typename PFP>
...@@ -344,7 +344,7 @@ public: ...@@ -344,7 +344,7 @@ public:
void updateBeforeCollapse(Dart d) ; void updateBeforeCollapse(Dart d) ;
void updateAfterCollapse(Dart d2, Dart dd2) ; void updateAfterCollapse(Dart d2, Dart dd2) ;
void updateWithoutCollapse() { } void updateWithoutCollapse();
} ; } ;
template <typename PFP> template <typename PFP>
...@@ -392,7 +392,7 @@ public: ...@@ -392,7 +392,7 @@ public:
void updateBeforeCollapse(Dart d) ; void updateBeforeCollapse(Dart d) ;
void updateAfterCollapse(Dart d2, Dart dd2) ; void updateAfterCollapse(Dart d2, Dart dd2) ;
void updateWithoutCollapse() { } void updateWithoutCollapse();
} ; } ;
/***************************************************************************************************************** /*****************************************************************************************************************
......
...@@ -69,6 +69,7 @@ void EdgeSelector_MapOrder<PFP>::updateAfterCollapse(Dart d2, Dart dd2) ...@@ -69,6 +69,7 @@ void EdgeSelector_MapOrder<PFP>::updateAfterCollapse(Dart d2, Dart dd2)
} }
} }
/************************************************************************************ /************************************************************************************
* RANDOM * * RANDOM *
************************************************************************************/ ************************************************************************************/
...@@ -126,6 +127,22 @@ void EdgeSelector_Random<PFP>::updateAfterCollapse(Dart d2, Dart dd2) ...@@ -126,6 +127,22 @@ void EdgeSelector_Random<PFP>::updateAfterCollapse(Dart d2, Dart dd2)
} while(!this->m_select(cur) || !m.edgeCanCollapse(darts[cur])) ; } while(!this->m_select(cur) || !m.edgeCanCollapse(darts[cur])) ;
} }
template <typename PFP>
void EdgeSelector_Random<PFP>::updateWithoutCollapse()
{
MAP& m = this->m_map ;
allSkipped = false ;
do
{
++cur ;
if(cur == darts.size())
{
cur = 0 ;
allSkipped = true ;
}
} while(!this->m_select(cur) || !m.edgeCanCollapse(darts[cur])) ;
}
/************************************************************************************ /************************************************************************************
* EDGE LENGTH * * EDGE LENGTH *
************************************************************************************/ ************************************************************************************/
...@@ -222,6 +239,17 @@ void EdgeSelector_Length<PFP>::updateAfterCollapse(Dart d2, Dart dd2) ...@@ -222,6 +239,17 @@ void EdgeSelector_Length<PFP>::updateAfterCollapse(Dart d2, Dart dd2)
cur = edges.begin() ; // set the current edge to the first one cur = edges.begin() ; // set the current edge to the first one
} }
template <typename PFP>
void EdgeSelector_Length<PFP>::updateWithoutCollapse()
{
EdgeInfo& einfo = edgeInfo[(*cur).second] ;
einfo.valid = false ;
edges.erase(einfo.it) ;
//edges.erase(cur) ;
cur = edges.begin();
}
template <typename PFP> template <typename PFP>
void EdgeSelector_Length<PFP>::initEdgeInfo(Dart d) void EdgeSelector_Length<PFP>::initEdgeInfo(Dart d)
{ {
...@@ -417,6 +445,17 @@ void EdgeSelector_QEM<PFP>::updateAfterCollapse(Dart d2, Dart dd2) ...@@ -417,6 +445,17 @@ void EdgeSelector_QEM<PFP>::updateAfterCollapse(Dart d2, Dart dd2)
cur = edges.begin() ; // set the current edge to the first one cur = edges.begin() ; // set the current edge to the first one
} }
template <typename PFP>
void EdgeSelector_QEM<PFP>::updateWithoutCollapse()
{
EdgeInfo& einfo = edgeInfo[(*cur).second] ;
einfo.valid = false ;
edges.erase(einfo.it) ;
//edges.erase(cur) ;
cur = edges.begin();
}
template <typename PFP> template <typename PFP>
void EdgeSelector_QEM<PFP>::initEdgeInfo(Dart d) void EdgeSelector_QEM<PFP>::initEdgeInfo(Dart d)
{ {
...@@ -479,18 +518,6 @@ void EdgeSelector_QEM<PFP>::computeEdgeInfo(Dart d, EdgeInfo& einfo) ...@@ -479,18 +518,6 @@ void EdgeSelector_QEM<PFP>::computeEdgeInfo(Dart d, EdgeInfo& einfo)
einfo.valid = true ; einfo.valid = true ;
} }
template <typename PFP>
void EdgeSelector_QEM<PFP>::updateWithoutCollapse()
{
EdgeInfo& einfo = edgeInfo[(*cur).second] ;
einfo.valid = false ;
edges.erase(einfo.it) ;
//edges.erase(cur) ;
cur = edges.begin();
}
/************************************************************************************ /************************************************************************************
* QUADRIC ERROR METRIC (Memoryless version) * * QUADRIC ERROR METRIC (Memoryless version) *
************************************************************************************/ ************************************************************************************/
...@@ -660,6 +687,17 @@ void EdgeSelector_QEMml<PFP>::updateAfterCollapse(Dart d2, Dart dd2) ...@@ -660,6 +687,17 @@ void EdgeSelector_QEMml<PFP>::updateAfterCollapse(Dart d2, Dart dd2)
cur = edges.begin() ; // set the current edge to the first one cur = edges.begin() ; // set the current edge to the first one
} }
template <typename PFP>
void EdgeSelector_QEMml<PFP>::updateWithoutCollapse()
{
EdgeInfo& einfo = edgeInfo[(*cur).second] ;
einfo.valid = false ;
edges.erase(einfo.it) ;
//edges.erase(cur) ;
cur = edges.begin();
}
template <typename PFP> template <typename PFP>
void EdgeSelector_QEMml<PFP>::initEdgeInfo(Dart d) void EdgeSelector_QEMml<PFP>::initEdgeInfo(Dart d)
{ {
...@@ -839,6 +877,17 @@ void EdgeSelector_Curvature<PFP>::updateAfterCollapse(Dart d2, Dart dd2) ...@@ -839,6 +877,17 @@ void EdgeSelector_Curvature<PFP>::updateAfterCollapse(Dart d2, Dart dd2)
cur = edges.begin() ; // set the current edge to the first one cur = edges.begin() ; // set the current edge to the first one
} }
template <typename PFP>
void EdgeSelector_Curvature<PFP>::updateWithoutCollapse()
{
EdgeInfo& einfo = edgeInfo[(*cur).second] ;
einfo.valid = false ;
edges.erase(einfo.it) ;
//edges.erase(cur) ;
cur = edges.begin();
}
template <typename PFP> template <typename PFP>
void EdgeSelector_Curvature<PFP>::initEdgeInfo(Dart d) void EdgeSelector_Curvature<PFP>::initEdgeInfo(Dart d)
{ {
...@@ -1039,6 +1088,17 @@ void EdgeSelector_MinDetail<PFP>::updateAfterCollapse(Dart d2, Dart dd2) ...@@ -1039,6 +1088,17 @@ void EdgeSelector_MinDetail<PFP>::updateAfterCollapse(Dart d2, Dart dd2)
cur = edges.begin() ; // set the current edge to the first one cur = edges.begin() ; // set the current edge to the first one
} }
template <typename PFP>
void EdgeSelector_MinDetail<PFP>::updateWithoutCollapse()
{
EdgeInfo& einfo = edgeInfo[(*cur).second] ;
einfo.valid = false ;
edges.erase(einfo.it) ;
//edges.erase(cur) ;
cur = edges.begin();
}
template <typename PFP> template <typename PFP>
void EdgeSelector_MinDetail<PFP>::initEdgeInfo(Dart d) void EdgeSelector_MinDetail<PFP>::initEdgeInfo(Dart d)
{ {
......
...@@ -39,7 +39,8 @@ namespace DecimationVolumes ...@@ -39,7 +39,8 @@ namespace DecimationVolumes
enum ApproximatorType enum ApproximatorType
{ {
A_QEM A_QEM,
A_MidEdge
}; };
template <typename PFP> template <typename PFP>
...@@ -61,12 +62,10 @@ public: ...@@ -61,12 +62,10 @@ public:
virtual const std::string& getApproximatedAttributeName() const = 0 ; virtual const std::string& getApproximatedAttributeName() const = 0 ;
virtual ApproximatorType getType() const = 0 ; virtual ApproximatorType getType() const = 0 ;
virtual bool init() = 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 ; virtual const PredictorGen<PFP>* getPredictor() const = 0 ;
virtual void approximate(Operator<PFP>* op) = 0 ;
virtual void saveApprox(Operator<PFP>* op) = 0 ;
virtual void affectApprox(Operator<PFP>* op) = 0 ;
virtual void approximate(Dart d) = 0;
} ; } ;
...@@ -123,46 +122,21 @@ public: ...@@ -123,46 +122,21 @@ public:
return m_approx[d] ; return m_approx[d] ;
} }
const Predictor<PFP, T>* getPredictor() const void saveApprox(Dart d)
{ {
return m_predictor ; m_app = m_approx[d] ;
} }
const T& getDetail(Dart d) const void affectApprox(Dart d)
{ {
assert(m_predictor || !"Trying to get detail on a non-predictive scheme") ; m_attrV[d] = m_app ;
return m_detail[d] ;
} }
void setDetail(Dart d, T& val) const Predictor<PFP, T>* getPredictor() const
{
assert(m_predictor || !"Trying to set detail on a non-predictive scheme") ;
m_detail[d] = val ;
}
virtual void saveApprox(Operator<PFP>* op)
{
Dart d = op->getEdge();
m_app = m_approx[d];
}
virtual void affectApprox(Operator<PFP>* op)
{ {
Dart d = op->getEdge(); return m_predictor ;
m_attrV[d] = m_app;
} }
// void saveApprox(Dart d)
// {
// m_app = m_approx[d] ;
// }
//
// void affectApprox(Dart d)
// {
// m_attrV[d] = m_app ;
// }
}; };
......
...@@ -38,13 +38,13 @@ void decimate( ...@@ -38,13 +38,13 @@ void decimate(
) )
{ {
std::vector<ApproximatorGen<PFP>*> approximators ; std::vector<ApproximatorGen<PFP>*> approximators ;
EdgeSelector<PFP>* selector = NULL ; Selector<PFP>* selector = NULL ;
//choose the Approximator //choose the Approximator
switch(a) switch(a)
{ {
case A_QEM : case A_MidEdge :
approximators.push_back(new Approximator_QEM<PFP>(map, position)) ; approximators.push_back(new Approximator_MidEdge<PFP>(map, position)) ;
break ; break ;
default : default :
CGoGNout << "not yet implemented" << CGoGNendl; CGoGNout << "not yet implemented" << CGoGNendl;
...@@ -54,8 +54,11 @@ void decimate( ...@@ -54,8 +54,11 @@ void decimate(
//choose the Selector //choose the Selector
switch(s) switch(s)
{ {
case S_QEM : case S_MapOrder :
selector = new EdgeSelector_QEM<PFP>(map, position, approximators, selected) ; selector = new Algo::DecimationVolumes::EdgeSelector_MapOrder<PFP>(map, position, approximators, selected) ;
break ;
case S_Random :
selector = new Algo::DecimationVolumes::EdgeSelector_Random<PFP>(map, position, approximators, selected) ;
break ; break ;
default: default:
CGoGNout << "not yet implemented" << CGoGNendl; CGoGNout << "not yet implemented" << CGoGNendl;
...@@ -78,42 +81,38 @@ void decimate( ...@@ -78,42 +81,38 @@ void decimate(
while(!finished) while(!finished)
{ {
//Next Operator to perform if(!selector->nextEdge(d))
Operator<PFP> *op; break ;
if((op = selector->nextOperator()) == NULL) std::cout << "d = " << d << std::endl;
break;
--nbVertices ;
Dart d2 = map.phi2(map.phi_1(d)) ;
Dart dd2 = map.phi2(map.phi_1(map.phi2(d))) ;
// compute approximated attributes
for(typename std::vector<ApproximatorGen<PFP>*>::iterator it = approximators.begin(); it != approximators.end(); ++it) for(typename std::vector<ApproximatorGen<PFP>*>::iterator it = approximators.begin(); it != approximators.end(); ++it)
{ {
(*it)->approximate(op) ; (*it)->approximate(d) ; // compute approximated attributes
(*it)->saveApprox(op) ; (*it)->saveApprox(d) ;
} }
//Update the selector before performing operation selector->updateBeforeCollapse(d) ; // update selector
if(!selector->updateBeforeOperation(op))
break; map.collapseEdge(d) ; // collapse edge
//Perform the topological operation and if(!map.check())
//compute the number of resulting cells finished = true;
nbVertices -= op->collapse(map, position);
for(typename std::vector<ApproximatorGen<PFP>*>::iterator it = approximators.begin(); it != approximators.end(); ++it) for(typename std::vector<ApproximatorGen<PFP>*>::iterator it = approximators.begin(); it != approximators.end(); ++it)
(*it)->affectApprox(op); // affect data to the resulting vertex (*it)->affectApprox(d2); // affect data to the resulting vertex
//Update the embedded position and selector->updateAfterCollapse(d2, dd2) ;// update selector
//search the next operation to perform
selector->updateAfterOperation(op);
if(nbVertices <= nbWantedVertices) if(nbVertices <= nbWantedVertices)
finished = true ; finished = true ;
delete op;
} }
selector->finish() ;
CGoGNout << "..done (" << nbVertices << " vertices)" << CGoGNendl ; CGoGNout << "..done (" << nbVertices << " vertices)" << CGoGNendl ;
delete selector ; delete selector ;
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
#include "Container/fakeAttribute.h" #include "Container/fakeAttribute.h"
#include "Algo/DecimationVolumes/selector.h" #include "Algo/DecimationVolumes/selector.h"
#include "Algo/DecimationVolumes/operator.h"
#include "Utils/qem.h" #include "Utils/qem.h"
#include "Topology/generic/traversorCell.h" #include "Topology/generic/traversorCell.h"
...@@ -16,80 +15,166 @@ namespace Algo ...@@ -16,80 +15,166 @@ namespace Algo
namespace DecimationVolumes namespace DecimationVolumes
{ {
/******************************************************************************** /*
* Parent Edge Selector * * Map Order
********************************************************************************/ */
template <typename PFP> template <typename PFP>
class EdgeSelector : public Selector<PFP> class EdgeSelector_MapOrder : public Selector<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:
private:
Dart cur ;
public: public:
EdgeSelector(MAP& m, VertexAttribute<typename PFP::VEC3>& pos, std::vector<ApproximatorGen<PFP>*>& approx, const FunctorSelect& select) : EdgeSelector_MapOrder(MAP& m, VertexAttribute<typename PFP::VEC3>& pos, std::vector<ApproximatorGen<PFP>*>& approx, const FunctorSelect& select) :
Selector<PFP>(m, pos, approx, select) Selector<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) ;
void updateWithoutCollapse() { }
} ;
};
/*
* Random
*/
template <typename PFP> template <typename PFP>
class EdgeSelector_QEM : public EdgeSelector<PFP> class EdgeSelector_Random : public Selector<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 ;
private: private:
typedef struct std::vector<Dart> darts ;
{ unsigned int cur ;
typename std::multimap<float, Dart>::iterator it; bool allSkipped ;
bool valid;
static std::string CGoGNnameOfType() { return "QEMedgeInfo" ; } public:
} QEMedgeInfo; EdgeSelector_Random(MAP& m, VertexAttribute<typename PFP::VEC3>& pos, std::vector<ApproximatorGen<PFP>*>& approx, const FunctorSelect& select) :
Selector<PFP>(m, pos, approx, select),
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) ;
typedef NoMathIOAttribute<QEMedgeInfo> EdgeInfo; void updateWithoutCollapse() { }
} ;
EdgeAttribute<EdgeInfo> edgeInfo; /*
VertexAttribute<Quadric<REAL> > quadric; * Edge Length
Quadric<REAL> tmpQ; */
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 NoMathIOAttribute<LengthEdgeInfo> EdgeInfo ;
std::multimap<float, Dart> edges; EdgeAttribute<EdgeInfo> edgeInfo ;
typename std::multimap<float, Dart>::iterator cur;
Approximator<PFP, typename PFP::VEC3>* m_positionApproximator; std::multimap<float,Dart> edges ;
typename std::multimap<float,Dart>::iterator cur ;
void initEdgeInfo(Dart d); void initEdgeInfo(Dart d) ;
void updateEdgeInfo(Dart d, bool recompute); void updateEdgeInfo(Dart d, bool recompute) ;
void computeEdgeInfo(Dart d, EdgeInfo& einfo); void computeEdgeInfo(Dart d, EdgeInfo& einfo) ;
public: public:
EdgeSelector_QEM(MAP& m, VertexAttribute<typename PFP::VEC3>& pos, EdgeSelector_Length(MAP& m, VertexAttribute<typename PFP::VEC3>& pos, std::vector<ApproximatorGen<PFP>*>& approx, const FunctorSelect& select) :
std::vector<ApproximatorGen<PFP>* >& approx, const FunctorSelect& select) : Selector<PFP>(m, pos, approx, select)
EdgeSelector<PFP>(m, pos, approx, select)
{ {
edgeInfo = m.template addAttribute<EdgeInfo, EDGE>("edgeInfo"); edgeInfo = m.template addAttribute<EdgeInfo, EDGE>("edgeInfo") ;
quadric = m.template addAttribute<Quadric<REAL>, VERTEX>("QEMquadric");
} }
~EdgeSelector_Length()
~EdgeSelector_QEM()
{ {
this->m_map.removeAttribute(quadric); this->m_map.removeAttribute(edgeInfo) ;
this->m_map.removeAttribute(edgeInfo);
} }
SelectorType getType() { return S_EdgeLength ; }
bool init() ;
bool nextEdge(Dart& d) ;