Commit 66788fb7 authored by Sauvage's avatar Sauvage

edgeSelector_CurvatureTensor : début de la prog, voire les TODO

parent 190b5f75
...@@ -163,6 +163,9 @@ void decimate( ...@@ -163,6 +163,9 @@ void decimate(
case S_NormalArea : case S_NormalArea :
selector = new EdgeSelector_NormalArea<PFP>(map, position, approximators, selected) ; selector = new EdgeSelector_NormalArea<PFP>(map, position, approximators, selected) ;
break ; break ;
case S_CurvatureTensor :
selector = new EdgeSelector_CurvatureTensor<PFP>(map, position, approximators, selected) ;
break ;
case S_MinDetail : case S_MinDetail :
selector = new EdgeSelector_MinDetail<PFP>(map, position, approximators, selected) ; selector = new EdgeSelector_MinDetail<PFP>(map, position, approximators, selected) ;
break ; break ;
......
...@@ -422,6 +422,65 @@ public: ...@@ -422,6 +422,65 @@ public:
void updateWithoutCollapse(); void updateWithoutCollapse();
} ; } ;
template <typename PFP>
class EdgeSelector_CurvatureTensor : 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 "CurvatureTensorEdgeInfo" ; }
} CurvatureTensorEdgeInfo ;
typedef NoMathIOAttribute<CurvatureEdgeInfo> EdgeInfo ;
EdgeAttribute<EdgeInfo> edgeInfo ;
EdgeAttribute<REAL> edgeangle ;
std::multimap<float,Dart> edges ;
typename std::multimap<float,Dart>::iterator cur ;
Approximator<PFP, VEC3,EDGE>* m_positionApproximator ;
void initEdgeInfo(Dart d) ;
void updateEdgeInfo(Dart d, bool recompute) ;
void computeEdgeInfo(Dart d, EdgeInfo& einfo) ;
public:
EdgeSelector_CurvatureTensor(MAP& m, VertexAttribute<VEC3>& pos, std::vector<ApproximatorGen<PFP>*>& approx, const FunctorSelect& select) :
EdgeSelector<PFP>(m, pos, approx, select),
m_positionApproximator(NULL)
{
edgeangle = m.template getAttribute<REAL, EDGE>("edgeangle") ;
if(!edgeangle.isValid())
{
edgeangle = m.template addAttribute<REAL, EDGE>("edgeangle") ;
Algo::Geometry::computeAnglesBetweenNormalsOnEdges<PFP>(m, pos, edgeangle) ;
}
edgeInfo = m.template addAttribute<EdgeInfo, EDGE>("edgeInfo") ;
}
~EdgeSelector_CurvatureTensor()
{
this->m_map.removeAttribute(edgeangle) ; // TODO : pas malin s'il existait avant
this->m_map.removeAttribute(edgeInfo) ;
}
SelectorType getType() { return S_CurvatureTensor ; }
bool init() ;
bool nextEdge(Dart& d) ;
void updateBeforeCollapse(Dart d) ;
void updateAfterCollapse(Dart d2, Dart dd2) ;
void updateWithoutCollapse() {};
} ;
template <typename PFP> template <typename PFP>
class EdgeSelector_MinDetail : public EdgeSelector<PFP> class EdgeSelector_MinDetail : public EdgeSelector<PFP>
{ {
......
...@@ -1220,6 +1220,215 @@ void EdgeSelector_Curvature<PFP>::computeEdgeInfo(Dart d, EdgeInfo& einfo) ...@@ -1220,6 +1220,215 @@ void EdgeSelector_Curvature<PFP>::computeEdgeInfo(Dart d, EdgeInfo& einfo)
einfo.valid = true ; einfo.valid = true ;
} }
/************************************************************************************
* CURVATURE TENSOR *
************************************************************************************/
template <typename PFP>
bool CurvatureTensor<PFP>::init()
{
MAP& m = this->m_map ;
bool ok = false ;
for(typename std::vector<ApproximatorGen<PFP>*>::iterator it = this->m_approximators.begin();
it != this->m_approximators.end() && !ok;
++it)
{
if((*it)->getApproximatedAttributeName() == "position")
{
assert((*it)->getType() == A_MidEdge || !"Only MidEdge Approximator is valid") ;
m_positionApproximator = reinterpret_cast<Approximator<PFP, VEC3,EDGE>* >(*it) ;
ok = true ;
}
}
if(!ok)
return false ;
edges.clear() ;
// TraversorE<MAP> travE(m);
// for(Dart dit = travE.begin() ; dit != travE.end() ; dit = travE.next())
// {
// computeEdgeMatrix(dit);
// }
for(Dart dit = travE.begin() ; dit != travE.end() ; dit = travE.next())
{
initEdgeInfo(dit) ; // init "edgeInfo" and "edges"
}
cur = edges.begin() ; // init the current edge to the first one
return true ;
}
template <typename PFP>
bool CurvatureTensor<PFP>::nextEdge(Dart& d)
{
if(cur == edges.end() || edges.empty())
return false ;
d = (*cur).second ;
return true ;
}
template <typename PFP>
void CurvatureTensor<PFP>::updateBeforeCollapse(Dart d)
{
MAP& m = this->m_map ;
assert(!m.isBoundaryEdge(d));
EdgeInfo* edgeE = &(edgeInfo[d]) ;
if(edgeE->valid)
{
edges.erase(edgeE->it) ;
edgeE->valid = false;
}
edgeE = &(edgeInfo[m.phi1(d)]) ;
if(edgeE->valid) // remove all
{
edges.erase(edgeE->it) ;
edgeE->valid = false;
}
edgeE = &(edgeInfo[m.phi_1(d)]) ; // the concerned edges
if(edgeE->valid)
{
edges.erase(edgeE->it) ;
edgeE->valid = false;
}
// from the multimap
Dart dd = m.phi2(d) ;
edgeE = &(edgeInfo[m.phi1(dd)]) ;
if(edgeE->valid)
{
edges.erase(edgeE->it) ;
edgeE->valid = false;
}
edgeE = &(edgeInfo[m.phi_1(dd)]) ;
if(edgeE->valid)
{
edges.erase(edgeE->it) ;
edgeE->valid = false;
}
}
template <typename PFP>
void CurvatureTensor<PFP>::updateAfterCollapse(Dart d2, Dart dd2)
{
MAP& m = this->m_map ;
// TODO : here update edge angles : should look like :
// edgeangle[d] = computeAngleBetweenNormalsOnEdge<PFP>(map, d, this->m_position) ;
// update the edge matrices
// Traversor2VE<MAP> te (m,d2);
// for(Dart dit = te.begin() ; dit != te.end() ; dit = te.next())
// {
// computeEdgeMatrix(dit);
// }
// update the multimap
Traversor2VVaE<MAP> tv (m,d2);
CellMarker<EDGE> eMark (m);
for(Dart dit = tv.begin() ; dit != tv.end() ; dit = tv.next())
{
Traversor2VE<MAP> te2 (m,dit);
for(Dart dit2 = te2.begin() ; dit2 != te2.end() ; dit2 = te2.next())
{
if (!eMark.isMarked(dit2))
{
updateEdgeInfo(dit2) ;
eMark.mark(dit2);
}
}
}
cur = edges.begin() ; // set the current edge to the first one
}
template <typename PFP>
void CurvatureTensor<PFP>::initEdgeInfo(Dart d)
{
MAP& m = this->m_map ;
EdgeInfo einfo ;
if(m.edgeCanCollapse(d))
computeEdgeInfo(d, einfo) ;
else
einfo.valid = false ;
edgeInfo[d] = einfo ;
}
template <typename PFP>
void CurvatureTensor<PFP>::updateEdgeInfo(Dart d)
{
MAP& m = this->m_map ;
EdgeInfo& einfo = edgeInfo[d] ;
if(einfo.valid)
edges.erase(einfo.it) ; // remove the edge from the multimap
if(m.edgeCanCollapse(d))
computeEdgeInfo(d, einfo) ;
else
einfo.valid = false ;
}
template <typename PFP>
void EdgeSelector_CurvatureTensor<PFP>::computeEdgeInfo(Dart d, EdgeInfo& einfo)
{
// TODO : code this function : everything complex is here
MAP& m = this->m_map ;
Dart dd = m.phi2(d);
Geom::Matrix33f M1; // init zero included
Geom::Matrix33f M2; // init zero included
assert(! m.isBoundaryEdge(d));
Traversor2VF<MAP> td (m,d);
Dart it = td.begin();
it = td.next();
Dart it2 = td.next();
while( it2 != td.end())
{
M1 += edgeMatrix[m.phi1(it)];
it = it2;
it2 = td.next();
}
Traversor2VF<MAP> tdd (m,dd);
it = tdd.begin();
it = tdd.next();
it2 = tdd.next();
while( it2 != tdd.end())
{
M2 += edgeMatrix[m.phi1(it)];
it = it2;
it2 = tdd.next();
}
m_positionApproximator->approximate(d) ;
const VEC3& a = m_positionApproximator->getApprox(d) ;
const VEC3 av1 = a - this->m_position[d] ;
const VEC3 av2 = a - this->m_position[dd] ;
REAL err = av1 * (M1 * av1) + av2 * (M2 * av2);
einfo.it = edges.insert(std::make_pair(err, d)) ;
einfo.valid = true ;
}
/************************************************************************************ /************************************************************************************
* MIN DETAIL * * MIN DETAIL *
************************************************************************************/ ************************************************************************************/
......
...@@ -44,6 +44,7 @@ enum SelectorType ...@@ -44,6 +44,7 @@ enum SelectorType
S_MinDetail, S_MinDetail,
S_Curvature, S_Curvature,
S_NormalArea, S_NormalArea,
S_CurvatureTensor,
S_ColorNaive, S_ColorNaive,
S_QEMextColor, S_QEMextColor,
S_Lightfield, S_Lightfield,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment