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