Commit d6a8ae63 authored by Kenneth Vanhoey's avatar Kenneth Vanhoey

some phi2->phi1 conversions + correction of memory failure in exportPlyPTM

parent 6bba6520
...@@ -94,9 +94,7 @@ public: ...@@ -94,9 +94,7 @@ public:
typedef typename PFP::REAL REAL ; typedef typename PFP::REAL REAL ;
typedef Geom::Matrix<3,3,REAL> MATRIX33 ; typedef Geom::Matrix<3,3,REAL> MATRIX33 ;
typedef MATRIX33 FRAME ;
typedef Geom::Matrix<3,6,REAL> MATRIX36 ; typedef Geom::Matrix<3,6,REAL> MATRIX36 ;
typedef MATRIX36 RGBFUNCTIONS ;
private: private:
typedef struct typedef struct
...@@ -107,7 +105,7 @@ private: ...@@ -107,7 +105,7 @@ private:
} LightfieldHalfEdgeInfo ; } LightfieldHalfEdgeInfo ;
typedef NoMathIOAttribute<LightfieldHalfEdgeInfo> HalfEdgeInfo ; typedef NoMathIOAttribute<LightfieldHalfEdgeInfo> HalfEdgeInfo ;
AttributeHandler<FRAME > m_frame ; AttributeHandler<MATRIX33 > m_frame ;
AttributeHandler<HalfEdgeInfo> halfEdgeInfo ; AttributeHandler<HalfEdgeInfo> halfEdgeInfo ;
AttributeHandler<Quadric<REAL> > quadric ; AttributeHandler<Quadric<REAL> > quadric ;
...@@ -117,8 +115,8 @@ private: ...@@ -117,8 +115,8 @@ private:
typename std::multimap<float,Dart>::iterator cur ; typename std::multimap<float,Dart>::iterator cur ;
Approximator<PFP, VEC3>* m_positionApproximator ; Approximator<PFP, VEC3>* m_positionApproximator ;
Approximator<PFP, FRAME >* m_frameApproximator ; Approximator<PFP, MATRIX33 >* m_frameApproximator ;
Approximator<PFP, RGBFUNCTIONS >* m_RGBfunctionsApproximator ; Approximator<PFP, MATRIX36 >* m_RGBfunctionsApproximator ;
void initHalfEdgeInfo(Dart d) ; void initHalfEdgeInfo(Dart d) ;
void updateHalfEdgeInfo(Dart d, bool recompute) ; void updateHalfEdgeInfo(Dart d, bool recompute) ;
...@@ -129,7 +127,7 @@ public: ...@@ -129,7 +127,7 @@ public:
HalfEdgeSelector_Lightfield(MAP& m, typename PFP::TVEC3& pos, std::vector<ApproximatorGen<PFP>*>& approx, const FunctorSelect& select = SelectorTrue()) : HalfEdgeSelector_Lightfield(MAP& m, typename PFP::TVEC3& pos, std::vector<ApproximatorGen<PFP>*>& approx, const FunctorSelect& select = SelectorTrue()) :
EdgeSelector<PFP>(m, pos, approx, select) EdgeSelector<PFP>(m, pos, approx, select)
{ {
m_frame = m.template getAttribute<FRAME>(VERTEX_ORBIT, "frame") ; m_frame = m.template getAttribute<MATRIX33>(VERTEX_ORBIT, "frame") ;
halfEdgeInfo = m.template addAttribute<HalfEdgeInfo>(DART_ORBIT, "halfEdgeInfo") ; halfEdgeInfo = m.template addAttribute<HalfEdgeInfo>(DART_ORBIT, "halfEdgeInfo") ;
quadric = m.template addAttribute<Quadric<REAL> >(VERTEX_ORBIT, "QEMquadric") ; quadric = m.template addAttribute<Quadric<REAL> >(VERTEX_ORBIT, "QEMquadric") ;
......
...@@ -125,6 +125,7 @@ void HalfEdgeSelector_QEMml<PFP>::updateBeforeCollapse(Dart d) ...@@ -125,6 +125,7 @@ void HalfEdgeSelector_QEMml<PFP>::updateBeforeCollapse(Dart d)
halfEdges.erase(edgeE.it) ; halfEdges.erase(edgeE.it) ;
// from the multimap // from the multimap
Dart dd = m.phi2(d) ; Dart dd = m.phi2(d) ;
assert(dd != d) ;
if(dd != d) if(dd != d)
{ {
edgeE = halfEdgeInfo[dd] ; edgeE = halfEdgeInfo[dd] ;
...@@ -162,9 +163,10 @@ void HalfEdgeSelector_QEMml<PFP>::recomputeQuadric(const Dart d, const bool reco ...@@ -162,9 +163,10 @@ void HalfEdgeSelector_QEMml<PFP>::recomputeQuadric(const Dart d, const bool reco
dBack = this->m_map.phi1(dFront) ; dBack = this->m_map.phi1(dFront) ;
dFront = this->m_map.alpha1(dFront) ; dFront = this->m_map.alpha1(dFront) ;
if (dBack != dFront) { // if dFront is no border if (this->m_map.phi2(dFront) != dFront) { // if dFront is no border
quadric[d] += Quadric<REAL>(this->m_position[d],this->m_position[this->m_map.phi1(dFront)],this->m_position[dBack]) ; quadric[d] += Quadric<REAL>(this->m_position[d],this->m_position[dBack],this->m_position[this->m_map.phi1(dFront)]) ;
} }
if (recomputeNeighbors) if (recomputeNeighbors)
recomputeQuadric(dBack, false) ; recomputeQuadric(dBack, false) ;
...@@ -182,19 +184,30 @@ void HalfEdgeSelector_QEMml<PFP>::updateAfterCollapse(Dart d2, Dart dd2) ...@@ -182,19 +184,30 @@ void HalfEdgeSelector_QEMml<PFP>::updateAfterCollapse(Dart d2, Dart dd2)
do do
{ {
updateHalfEdgeInfo(vit, true) ; updateHalfEdgeInfo(vit, true) ;
updateHalfEdgeInfo(m.phi2(vit), true) ; Dart d = m.phi2(vit) ;
if (d != vit) ;
updateHalfEdgeInfo(d, true) ;
updateHalfEdgeInfo(m.phi1(vit), true) ; updateHalfEdgeInfo(m.phi1(vit), true) ;
updateHalfEdgeInfo(m.phi2(m.phi1(vit)), true) ; d = m.phi2(m.phi1(vit)) ;
if (d != m.phi1(vit)) ;
updateHalfEdgeInfo(d, true) ;
Dart stop = m.phi2(vit) ; Dart stop = m.phi2(vit) ;
assert (stop != vit) ;
Dart vit2 = m.alpha_1(m.phi1(vit)) ; Dart vit2 = m.alpha_1(m.phi1(vit)) ;
do { do {
updateHalfEdgeInfo(vit2, true) ; updateHalfEdgeInfo(vit2, true) ;
updateHalfEdgeInfo(m.phi2(vit2), true) ; d = m.phi2(vit2) ;
if (d != vit2) ;
updateHalfEdgeInfo(d, true) ;
updateHalfEdgeInfo(m.phi1(vit2), false) ; updateHalfEdgeInfo(m.phi1(vit2), false) ;
updateHalfEdgeInfo(m.phi2(m.phi1(vit2)), false) ; d = m.phi2(m.phi1(vit2)) ;
vit2 = m.alpha_1(vit2) ; if (d != m.phi1(vit2)) ;
updateHalfEdgeInfo(d, false) ;
vit2 = m.alpha_1(vit2) ;
} while (stop != vit2) ; } while (stop != vit2) ;
vit = m.alpha1(vit) ; vit = m.alpha1(vit) ;
} while(vit != d2) ; } while(vit != d2) ;
...@@ -251,7 +264,7 @@ template <typename PFP> ...@@ -251,7 +264,7 @@ template <typename PFP>
void HalfEdgeSelector_QEMml<PFP>::computeHalfEdgeInfo(Dart d, HalfEdgeInfo& heinfo) void HalfEdgeSelector_QEMml<PFP>::computeHalfEdgeInfo(Dart d, HalfEdgeInfo& heinfo)
{ {
MAP& m = this->m_map ; MAP& m = this->m_map ;
Dart dd = m.phi2(d) ; Dart dd = m.phi1(d) ;
Quadric<REAL> quad ; Quadric<REAL> quad ;
quad += quadric[d] ; // compute the sum of the quad += quadric[d] ; // compute the sum of the
...@@ -288,12 +301,12 @@ bool HalfEdgeSelector_Lightfield<PFP>::init() ...@@ -288,12 +301,12 @@ bool HalfEdgeSelector_Lightfield<PFP>::init()
} }
else if( ok == 1 && (*it)->getApproximatedAttributeName() == "frame") else if( ok == 1 && (*it)->getApproximatedAttributeName() == "frame")
{ {
m_frameApproximator = reinterpret_cast<Approximator<PFP, FRAME>* >(*it) ; // 2) frame (needs position) m_frameApproximator = reinterpret_cast<Approximator<PFP, MATRIX33>* >(*it) ; // 2) frame (needs position)
++ok ; ++ok ;
} }
else if(ok == 2 && (*it)->getApproximatedAttributeName() == "colorPTM") else if(ok == 2 && (*it)->getApproximatedAttributeName() == "colorPTM")
{ {
m_RGBfunctionsApproximator = reinterpret_cast<Approximator<PFP, RGBFUNCTIONS>* >(*it) ; // 3) functions (needs frame) m_RGBfunctionsApproximator = reinterpret_cast<Approximator<PFP, MATRIX36>* >(*it) ; // 3) functions (needs frame)
++ok ; ++ok ;
} }
} }
...@@ -409,8 +422,6 @@ void HalfEdgeSelector_Lightfield<PFP>::recomputeQuadric(const Dart d, const bool ...@@ -409,8 +422,6 @@ void HalfEdgeSelector_Lightfield<PFP>::recomputeQuadric(const Dart d, const bool
if (dBack != dFront) { // if dFront is no border if (dBack != dFront) { // if dFront is no border
quadric[d] += Quadric<REAL>(this->m_position[d],this->m_position[this->m_map.phi1(dFront)],this->m_position[dBack]) ; quadric[d] += Quadric<REAL>(this->m_position[d],this->m_position[this->m_map.phi1(dFront)],this->m_position[dBack]) ;
if (isnan(this->m_position[d][0]))
std::cout << "NaaaaN" << std::endl ;
} }
if (recomputeNeighbors) if (recomputeNeighbors)
recomputeQuadric(dBack, false) ; recomputeQuadric(dBack, false) ;
...@@ -429,23 +440,35 @@ void HalfEdgeSelector_Lightfield<PFP>::updateAfterCollapse(Dart d2, Dart dd2) ...@@ -429,23 +440,35 @@ void HalfEdgeSelector_Lightfield<PFP>::updateAfterCollapse(Dart d2, Dart dd2)
do do
{ {
updateHalfEdgeInfo(vit, true) ; updateHalfEdgeInfo(vit, true) ;
updateHalfEdgeInfo(m.phi2(vit), true) ; Dart d = m.phi2(vit) ;
if (d != vit) ;
updateHalfEdgeInfo(d, true) ;
updateHalfEdgeInfo(m.phi1(vit), true) ; updateHalfEdgeInfo(m.phi1(vit), true) ;
updateHalfEdgeInfo(m.phi2(m.phi1(vit)), true) ; d = m.phi2(m.phi1(vit)) ;
if (d != m.phi1(vit)) ;
updateHalfEdgeInfo(d, true) ;
Dart stop = m.phi2(vit) ; Dart stop = m.phi2(vit) ;
assert (stop != vit) ;
Dart vit2 = m.alpha_1(m.phi1(vit)) ; Dart vit2 = m.alpha_1(m.phi1(vit)) ;
do { do {
updateHalfEdgeInfo(vit2, true) ; updateHalfEdgeInfo(vit2, true) ;
updateHalfEdgeInfo(m.phi2(vit2), true) ; d = m.phi2(vit2) ;
if (d != vit2) ;
updateHalfEdgeInfo(d, true) ;
updateHalfEdgeInfo(m.phi1(vit2), false) ; updateHalfEdgeInfo(m.phi1(vit2), false) ;
updateHalfEdgeInfo(m.phi2(m.phi1(vit2)), false) ; d = m.phi2(m.phi1(vit2)) ;
vit2 = m.alpha_1(vit2) ; if (d != m.phi1(vit2)) ;
updateHalfEdgeInfo(d, false) ;
vit2 = m.alpha_1(vit2) ;
} while (stop != vit2) ; } while (stop != vit2) ;
vit = m.alpha1(vit) ; vit = m.alpha1(vit) ;
} while(vit != d2) ; } while(vit != d2) ;
cur = halfEdges.begin() ; // set the current edge to the first one cur = halfEdges.begin() ; // set the current edge to the first one
} }
...@@ -498,7 +521,7 @@ template <typename PFP> ...@@ -498,7 +521,7 @@ template <typename PFP>
void HalfEdgeSelector_Lightfield<PFP>::computeHalfEdgeInfo(Dart d, HalfEdgeInfo& heinfo) void HalfEdgeSelector_Lightfield<PFP>::computeHalfEdgeInfo(Dart d, HalfEdgeInfo& heinfo)
{ {
MAP& m = this->m_map ; MAP& m = this->m_map ;
Dart dd = m.phi2(d) ; Dart dd = m.phi1(d) ;
// New position // New position
Quadric<REAL> quad ; Quadric<REAL> quad ;
......
...@@ -216,7 +216,7 @@ template <typename PFP> ...@@ -216,7 +216,7 @@ template <typename PFP>
void Approximator_RGBfunctions<PFP>::approximate(Dart d) void Approximator_RGBfunctions<PFP>::approximate(Dart d)
{ {
MAP& m = this->m_map ; MAP& m = this->m_map ;
Dart dd = m.phi2(d) ; // get the two vertices Dart dd = m.phi1(d) ; // get the two vertices
// get hypothetical local frames // get hypothetical local frames
VEC3 i,n ; VEC3 i,n ;
......
...@@ -288,9 +288,8 @@ bool exportPLYPTM(typename PFP::MAP& map, const char* filename, const typename P ...@@ -288,9 +288,8 @@ bool exportPLYPTM(typename PFP::MAP& map, const char* filename, const typename P
if(good(d) && !markF.isMarked(d)) if(good(d) && !markF.isMarked(d))
{ {
markF.markOrbit(FACE_ORBIT, d) ; markF.markOrbit(FACE_ORBIT, d) ;
faces.push_back(0);
unsigned int& nbe = faces.back();
Dart e = d; Dart e = d;
std::vector<unsigned int> face ;
do do
{ {
if (!markV.isMarked(e)) if (!markV.isMarked(e))
...@@ -300,11 +299,15 @@ bool exportPLYPTM(typename PFP::MAP& map, const char* filename, const typename P ...@@ -300,11 +299,15 @@ bool exportPLYPTM(typename PFP::MAP& map, const char* filename, const typename P
markV.mark(e); markV.mark(e);
} }
faces.push_back(tableVertLab[e]); face.push_back(tableVertLab[e]);
nbe++;
e = map.phi1(e); e = map.phi1(e);
} while (e!=d); } while (e!=d) ;
nbf++;
faces.push_back(face.size()) ;
for (unsigned int i = 0 ; i < face.size() ; ++i)
faces.push_back(face.at(i)) ;
++nbf;
} }
} }
...@@ -358,7 +361,7 @@ bool exportPLYPTM(typename PFP::MAP& map, const char* filename, const typename P ...@@ -358,7 +361,7 @@ bool exportPLYPTM(typename PFP::MAP& map, const char* filename, const typename P
out << colorPTM[0][vi][2] << " " << colorPTM[1][vi][2] << " " << colorPTM[2][vi][2] << " " << colorPTM[3][vi][2] << " " << colorPTM[4][vi][2] << " " << colorPTM[5][vi][2] << std::endl ; out << colorPTM[0][vi][2] << " " << colorPTM[1][vi][2] << " " << colorPTM[2][vi][2] << " " << colorPTM[3][vi][2] << " " << colorPTM[4][vi][2] << " " << colorPTM[5][vi][2] << std::endl ;
} }
std::vector<unsigned int>::iterator it = faces.begin();; std::vector<unsigned int>::iterator it = faces.begin();
while (it != faces.end()) while (it != faces.end())
{ {
unsigned int nbe = *it++; unsigned int nbe = *it++;
......
...@@ -43,8 +43,7 @@ public: ...@@ -43,8 +43,7 @@ public:
typedef Geom::Matrix<3,3,REAL> MATRIX33; typedef Geom::Matrix<3,3,REAL> MATRIX33;
typedef Quadric<REAL> QUADRIC; typedef Quadric<REAL> QUADRIC;
typedef MATRIX33 FRAME; typedef Geom::Matrix<3,6,REAL> MATRIX36;
typedef Geom::Matrix<3,6,REAL> RGBFUNCTIONS;
private: private:
MATRIX66 A; MATRIX66 A;
...@@ -58,13 +57,13 @@ public: ...@@ -58,13 +57,13 @@ public:
QuadricRGBfunctions(); QuadricRGBfunctions();
QuadricRGBfunctions(int i); QuadricRGBfunctions(int i);
QuadricRGBfunctions(const QuadricRGBfunctions&); QuadricRGBfunctions(const QuadricRGBfunctions&);
QuadricRGBfunctions(const RGBFUNCTIONS&, const REAL gamma = REAL(0), const REAL alpha = REAL(0)) ; QuadricRGBfunctions(const MATRIX36&, const REAL gamma = REAL(0), const REAL alpha = REAL(0)) ;
virtual ~QuadricRGBfunctions() {} ; virtual ~QuadricRGBfunctions() {} ;
REAL operator() (const RGBFUNCTIONS&) const; REAL operator() (const MATRIX36&) const;
bool findOptimizedRGBfunctions(RGBFUNCTIONS& lff) const; bool findOptimizedRGBfunctions(MATRIX36& lff) const;
void operator += (const QuadricRGBfunctions&) ; void operator += (const QuadricRGBfunctions&) ;
void operator -= (const QuadricRGBfunctions&) ; void operator -= (const QuadricRGBfunctions&) ;
......
...@@ -67,11 +67,11 @@ QuadricRGBfunctions<REAL>::QuadricRGBfunctions(const QuadricRGBfunctions& q) { ...@@ -67,11 +67,11 @@ QuadricRGBfunctions<REAL>::QuadricRGBfunctions(const QuadricRGBfunctions& q) {
} }
template <typename REAL> template <typename REAL>
QuadricRGBfunctions<REAL>::QuadricRGBfunctions(const RGBFUNCTIONS& cf, const REAL gamma, const REAL alpha) { QuadricRGBfunctions<REAL>::QuadricRGBfunctions(const MATRIX36& cf, const REAL gamma, const REAL alpha) {
MATRIX66 R1,R2_b,R2_c ; MATRIX66 R1,R2_b,R2_c ;
buildRotateMatrix(R1,gamma); // Rotation 1 buildRotateMatrix(R1,gamma); // Rotation 1
R1.transpose() ; // R1.transpose() ;
buildIntegralMatrix_A(A,alpha); // Parameterized integral matrix A buildIntegralMatrix_A(A,alpha); // Parameterized integral matrix A
buildIntegralMatrix_b(R2_b,alpha); // Parameterized integral matrix b buildIntegralMatrix_b(R2_b,alpha); // Parameterized integral matrix b
...@@ -92,7 +92,7 @@ QuadricRGBfunctions<REAL>::QuadricRGBfunctions(const RGBFUNCTIONS& cf, const REA ...@@ -92,7 +92,7 @@ QuadricRGBfunctions<REAL>::QuadricRGBfunctions(const RGBFUNCTIONS& cf, const REA
} }
template <typename REAL> template <typename REAL>
REAL QuadricRGBfunctions<REAL>::operator() (const RGBFUNCTIONS& cf) const { REAL QuadricRGBfunctions<REAL>::operator() (const MATRIX36& cf) const {
REAL res = REAL(0); REAL res = REAL(0);
for (unsigned col = RED; col < BLUE+1; ++col) { for (unsigned col = RED; col < BLUE+1; ++col) {
...@@ -112,7 +112,7 @@ REAL QuadricRGBfunctions<REAL>::operator() (const RGBFUNCTIONS& cf) const { ...@@ -112,7 +112,7 @@ REAL QuadricRGBfunctions<REAL>::operator() (const RGBFUNCTIONS& cf) const {
} }
template <typename REAL> template <typename REAL>
bool QuadricRGBfunctions<REAL>::findOptimizedRGBfunctions(RGBFUNCTIONS& cf) const { bool QuadricRGBfunctions<REAL>::findOptimizedRGBfunctions(MATRIX36& cf) const {
MATRIX66 Ainv ; MATRIX66 Ainv ;
REAL det = A.invert(Ainv) ; // Invert matrix REAL det = A.invert(Ainv) ; // Invert matrix
......
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