Commit 45d57d02 authored by Sylvain Thery's avatar Sylvain Thery

Even/Odd pass traversors

parent c039fdfb
...@@ -241,7 +241,7 @@ void Viewer::cb_keyPress(int keycode) ...@@ -241,7 +241,7 @@ void Viewer::cb_keyPress(int keycode)
if(!pos2.isValid()) if(!pos2.isValid())
pos2 = myMap.addAttribute<VEC3, VERTEX>("pos2") ; pos2 = myMap.addAttribute<VEC3, VERTEX>("pos2") ;
for (int i=0; i< 10; ++i) for (int i=0; i< 6; ++i)
{ {
foreach_cell<VERTEX>(myMap, [&] (Vertex d) foreach_cell<VERTEX>(myMap, [&] (Vertex d)
{ {
...@@ -263,7 +263,46 @@ void Viewer::cb_keyPress(int keycode) ...@@ -263,7 +263,46 @@ void Viewer::cb_keyPress(int keycode)
updateGL(); updateGL();
} }
break; break;
case 'B':
{
Utils::Chrono ch;
ch.start();
VertexAttribute<VEC3,MAP_IMPL> pos2 = myMap.getAttribute<VEC3, VERTEX>("pos2") ;
if(!pos2.isValid())
pos2 = myMap.addAttribute<VEC3, VERTEX>("pos2") ;
foreach_cell_EvenOddd<VERTEX>(myMap, [&] (Vertex d)
{
pos2[d] = VEC3(0,0,0);
int nb=0;
foreach_adjacent2<FACE>(myMap,d,[&](Vertex e)
{
pos2[d] += position[e];
nb++;
});
pos2[d]/=nb;
},
[&] (Vertex d)
{
position[d] = VEC3(0,0,0);
int nb=0;
foreach_adjacent2<FACE>(myMap,d,[&](Vertex e)
{
position[d] += pos2[e];
nb++;
});
position[d]/=nb;
},
3);
std::cout << "Even/Odd "<< ch.elapsed()<< " ms "<< std::endl;
Algo::Surface::Geometry::computeNormalVertices<PFP>(myMap, position, normal) ;
m_positionVBO->updateData(position) ;
m_normalVBO->updateData(normal) ;
updateGL();
}
break;
case 'e': case 'e':
{ {
...@@ -330,6 +369,49 @@ void Viewer::cb_keyPress(int keycode) ...@@ -330,6 +369,49 @@ void Viewer::cb_keyPress(int keycode)
} }
break; break;
case'A':
{
Utils::Chrono ch;
ch.start();
TraversorCell<MAP, VERTEX> trav(myMap,true);
for(unsigned int i=0; i<10; ++i)
{
for (Cell<VERTEX> v = trav.begin(), e = trav.end(); v.dart != e.dart; v = trav.next())
{
// normal[v] = Algo::Surface::Geometry::vertexNormal<PFP>(myMap, v, position) ;
normal[v][0] = 0.0f;
}
}
std::cout << "Timing 10 traversors "<< ch.elapsed()<< " ms "<< std::endl;
}
break;
case'Z':
{
Utils::Chrono ch;
ch.start();
TraversorCell<MAP, VERTEX> trav(myMap,true);
TraversorCellEven<MAP, VERTEX> tr1(trav);
TraversorCellOdd<MAP, VERTEX> tr2(trav);
for(unsigned int i=0; i<5; ++i)
{
for (Cell<VERTEX> v = tr1.begin(), e = tr1.end(); v.dart != e.dart; v = tr1.next())
{
// normal[v] = Algo::Surface::Geometry::vertexNormal<PFP>(myMap, v, position) ;
normal[v][0] = 0.0f;
}
for (Cell<VERTEX> v = tr2.begin(), e = tr2.end(); v.dart != e.dart; v = tr2.next())
{
// normal[v] = Algo::Surface::Geometry::vertexNormal<PFP>(myMap, v, position) ;
normal[v][0] = 0.0f;
}
}
std::cout << "Timing 5 traversors even/odd "<< ch.elapsed()<< " ms "<< std::endl;
}
break;
default: default:
...@@ -360,7 +442,7 @@ void Viewer::importMesh(std::string& filename) ...@@ -360,7 +442,7 @@ void Viewer::importMesh(std::string& filename)
position = myMap.getAttribute<PFP::VEC3, VERTEX>(attrNames[0]) ; position = myMap.getAttribute<PFP::VEC3, VERTEX>(attrNames[0]) ;
} }
myMap.enableQuickTraversal<VERTEX>() ; // myMap.enableQuickTraversal<VERTEX>() ;
m_render->initPrimitives<PFP>(myMap, Algo::Render::GL2::POINTS) ; m_render->initPrimitives<PFP>(myMap, Algo::Render::GL2::POINTS) ;
m_render->initPrimitives<PFP>(myMap, Algo::Render::GL2::LINES) ; m_render->initPrimitives<PFP>(myMap, Algo::Render::GL2::LINES) ;
......
...@@ -140,5 +140,28 @@ int main() ...@@ -140,5 +140,28 @@ int main()
std::cout << "Total="<<surf[0]+surf[1]+surf[2]+surf[3]<< std::endl; std::cout << "Total="<<surf[0]+surf[1]+surf[2]+surf[3]<< std::endl;
TraversorV<MAP> tv0(myMap);
TraversorCellEven<MAP,VERTEX> tv1(tv0);
TraversorCellOdd<MAP,VERTEX> tv2(tv0);
std::cout << "PAIR:";
for (Dart d=tv1.begin(); d!=tv1.end(); d=tv1.next())// traverse all vertices (d one dart of each vertex)
std::cout << d << " / ";
std::cout << std::endl;
std::cout << "IMPPAIR:";
for (Dart d=tv2.begin(); d!=tv2.end(); d=tv2.next())// traverse all vertices (d one dart of each vertex)
std::cout << d << " / ";
std::cout << std::endl;
std::cout << "PAIR:";
for (Dart d=tv1.begin(); d!=tv1.end(); d=tv1.next())// traverse all vertices (d one dart of each vertex)
std::cout << d << " / ";
std::cout << std::endl;
std::cout << "IMPPAIR:";
for (Dart d=tv2.begin(); d!=tv2.end(); d=tv2.next())// traverse all vertices (d one dart of each vertex)
std::cout << d << " / ";
std::cout << std::endl;
return 0; return 0;
} }
...@@ -39,7 +39,7 @@ namespace CGoGN ...@@ -39,7 +39,7 @@ namespace CGoGN
template <typename MAP, unsigned int ORBIT> template <typename MAP, unsigned int ORBIT>
class TraversorCell //: public Traversor<MAP> class TraversorCell //: public Traversor<MAP>
{ {
private: protected:
const MAP& m ; const MAP& m ;
unsigned int dimension ; unsigned int dimension ;
...@@ -53,6 +53,9 @@ private: ...@@ -53,6 +53,9 @@ private:
Cell<ORBIT> current ; Cell<ORBIT> current ;
bool firstTraversal ; bool firstTraversal ;
// just for odd/even versions
TraversorCell(const TraversorCell<MAP, ORBIT>& tc);
public: public:
TraversorCell(const MAP& map, bool forceDartMarker = false, unsigned int thread = 0) ; TraversorCell(const MAP& map, bool forceDartMarker = false, unsigned int thread = 0) ;
...@@ -65,10 +68,40 @@ public: ...@@ -65,10 +68,40 @@ public:
inline Cell<ORBIT> next() ; inline Cell<ORBIT> next() ;
inline void skip(Cell<ORBIT> c); inline void skip(Cell<ORBIT> c);
inline unsigned int nbCells();
} ;
template <typename MAP, unsigned int ORBIT>
class TraversorCellEven : public TraversorCell<MAP,ORBIT>
{
public:
TraversorCellEven(const TraversorCell<MAP,ORBIT>& tra):
TraversorCell<MAP,ORBIT>(tra) {}
~TraversorCellEven() { this->cmark = NULL; this->dmark=NULL; }
inline Cell<ORBIT> begin() ;
} ;
template <typename MAP, unsigned int ORBIT>
class TraversorCellOdd : public TraversorCell<MAP,ORBIT>
{
public:
TraversorCellOdd(const TraversorCell<MAP,ORBIT>& tra):
TraversorCell<MAP,ORBIT>(tra) {}
~TraversorCellOdd() {this->cmark = NULL; this->dmark=NULL; }
inline Cell<ORBIT> begin() ;
inline Cell<ORBIT> next() ;
} ; } ;
/* /*
* Executes function f on each ORBIT * Executes function f on each ORBIT
*/ */
...@@ -92,10 +125,34 @@ inline void foreach_cell_until(const MAP& map, FUNC f, bool forceDartMarker = fa ...@@ -92,10 +125,34 @@ inline void foreach_cell_until(const MAP& map, FUNC f, bool forceDartMarker = fa
break; break;
} }
template <unsigned int ORBIT, typename MAP, typename FUNC, typename FUNC2>
inline void foreach_cell_EvenOddd(const MAP& map, FUNC f, FUNC2 g, unsigned int nbpasses=1, bool forceDartMarker = false, unsigned int thread = 0)
{
TraversorCell<MAP, ORBIT> trav(map, forceDartMarker, thread);
TraversorCellEven<MAP, VERTEX> tr1(trav);
TraversorCellOdd<MAP, VERTEX> tr2(trav);
for (unsigned int i=0; i<nbpasses; ++i)
{
for (Cell<ORBIT> c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next())
f(c);
for (Cell<ORBIT> c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next())
g(c);
}
}
namespace Parallel namespace Parallel
{ {
template <unsigned int ORBIT, typename MAP, typename FUNC> template <unsigned int ORBIT, typename MAP, typename FUNC>
void foreach_cell(MAP& map, FUNC func, unsigned int nbth=0, bool needMarkers=true); void foreach_cell(MAP& map, FUNC func, unsigned int nbth=0, bool needMarkers=true);
template <unsigned int ORBIT, typename MAP, typename FUNC_E, typename FUNC_O>
void foreach_cell_EO(MAP& map, FUNC_E funcEven, FUNC_O funcOdd,unsigned int nbth=0, bool needMarkers=true);
} }
template <typename MAP> template <typename MAP>
......
...@@ -54,6 +54,25 @@ TraversorCell<MAP, ORBIT>::TraversorCell(const MAP& map, bool forceDartMarker, u ...@@ -54,6 +54,25 @@ TraversorCell<MAP, ORBIT>::TraversorCell(const MAP& map, bool forceDartMarker, u
} }
} }
template <typename MAP, unsigned int ORBIT>
unsigned int TraversorCell<MAP, ORBIT>::nbCells()
{
return m.template getAttributeContainer<ORBIT>().size();
}
template <typename MAP, unsigned int ORBIT>
TraversorCell<MAP, ORBIT>::TraversorCell(const TraversorCell<MAP, ORBIT>& tc) :
m(tc.m), dmark(tc.dmark), cmark(tc.cmark),
quickTraversal(tc.quickTraversal), current(tc.current), firstTraversal(tc.firstTraversal),
dimension(tc.dimension)
{
}
template <typename MAP, unsigned int ORBIT> template <typename MAP, unsigned int ORBIT>
TraversorCell<MAP, ORBIT>::~TraversorCell() TraversorCell<MAP, ORBIT>::~TraversorCell()
{ {
...@@ -166,6 +185,94 @@ void TraversorCell<MAP, ORBIT>::skip(Cell<ORBIT> c) ...@@ -166,6 +185,94 @@ void TraversorCell<MAP, ORBIT>::skip(Cell<ORBIT> c)
template <typename MAP, unsigned int ORBIT>
Cell<ORBIT> TraversorCellEven<MAP, ORBIT>::begin()
{
Cell<ORBIT> c = TraversorCell<MAP, ORBIT>::begin();
this->firstTraversal = true;
return c;
}
template <typename MAP, unsigned int ORBIT>
Cell<ORBIT> TraversorCellOdd<MAP, ORBIT>::begin()
{
if(this->quickTraversal != NULL)
{
this->qCurrent = this->cont->begin() ;
this->current.dart = this->quickTraversal->operator[](this->qCurrent);
}
else
{
this->current.dart = this->m.begin() ;
while(this->current.dart != this->m.end() && (this->m.isBoundaryMarked(this->dimension, this->current.dart) ))
this->m.next(this->current.dart) ;
if(this->current.dart == this->m.end())
this->current.dart = NIL ;
else
{
if(this->dmark)
this->dmark->template unmarkOrbit<ORBIT>(this->current.dart) ;
else
this->cmark->unmark(this->current) ;
}
}
return this->current ;
}
template <typename MAP, unsigned int ORBIT>
Cell<ORBIT> TraversorCellOdd<MAP, ORBIT>::next()
{
assert(this->current.dart != NIL);
if(this->quickTraversal != NULL)
{
this->cont->next(this->qCurrent) ;
if (this->qCurrent != this->cont->end())
this->current.dart = this->quickTraversal->operator[](this->qCurrent) ;
else this->current.dart = NIL;
}
else
{
if(this->dmark)
{
bool ismarked = this->dmark->isMarked(this->current.dart) ;
while(this->current.dart != NIL && (!ismarked || this->m.isBoundaryMarked(this->dimension,this->current.dart)))
{
this->m.next(this->current.dart) ;
if(this->current.dart == this->m.end())
this->current.dart = NIL ;
else
ismarked = this->dmark->isMarked(this->current.dart) ;
}
if(this->current.dart != NIL)
this->dmark->template unmarkOrbit<ORBIT>(this->current.dart) ;
}
else
{
bool ismarked = this->cmark->isMarked(this->current) ;
while(this->current.dart != NIL && (!ismarked || this->m.isBoundaryMarked(this->dimension, this->current.dart) ))
{
this->m.next(this->current.dart) ;
if(this->current.dart == this->m.end())
this->current.dart = NIL ;
else
ismarked = this->cmark->isMarked(this->current) ;
}
if(this->current.dart != NIL)
this->cmark->unmark(this->current) ;
}
}
return this->current ;
}
namespace Parallel namespace Parallel
{ {
......
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