Commit 1568a9a5 authored by Sylvain Thery's avatar Sylvain Thery

new c++11 syntax for Cell traversal

parent a4f08955
......@@ -129,10 +129,18 @@ void dumpAttribute(const ATTRIB& attr)
template<typename T>
void VertexTyped(MAP& map, T& va)
{
foreach_cell<VERTEX>(map,[&](Vertex v) // for all vertices
{
va[v] = 1.1 * va[v];
});
// foreach_cell<VERTEX>(map,[&](Vertex v) // for all vertices
// {
// va[v] = 1.1 * va[v];
// });
// other syntax for traversal
for (Vertex v : allVertices<MAP>(map))
{
va[v] = 1.1 * va[v];
std::cout << "V:" << v << " -> "<<va[v]<< std::endl;
}
}
// version that take a VertexAttribute, check type at runtime and call instancied template version
......
......@@ -65,6 +65,12 @@ public:
template <typename T2>
Vector(const Vector<DIM, T2>& v) ;
/**
* @brief Vector constructor from list init. (c++11)
* @param args {x,y,z}
*/
Vector(typename std::initializer_list<T> args);
Vector(T x, T y) ;
Vector(T x, T y, T z) ;
......
......@@ -48,6 +48,19 @@ std::string Vector<DIM, T>::CGoGNnameOfType()
/* CONSTRUCTORS */
/**********************************************/
template <unsigned int DIM, typename T>
Vector<DIM, T>::Vector(typename std::initializer_list<T> args)
{
unsigned int i=0;
// fill from initializer list
for (auto iter = args.begin(); (iter != args.end()) && (i<DIM); ++iter, ++i)
m_data[i] = *iter;
// finish with 0 if necessary
for (int j=i;j<DIM;++j)
m_data[j] = 0;
}
template <unsigned int DIM, typename T>
Vector<DIM, T>::Vector()
{
......
......@@ -144,7 +144,6 @@ void foreach_cell(MAP& map, FUNC func, TraversalOptim opt = AUTO, unsigned int n
template <typename MAP, TraversalOptim OPT = AUTO>
class TraversorV : public TraversorCell<MAP, VERTEX, OPT>
{
......@@ -177,6 +176,88 @@ public:
{}
};
template <typename MAP, unsigned int ORBIT, TraversalOptim OPT = AUTO>
class allCells: public TraversorCell<MAP,ORBIT,OPT>
{
public:
allCells(const MAP& map, bool forceDartMarker = false, unsigned int thread = 0):
TraversorCell<MAP,ORBIT,OPT>(map,forceDartMarker,thread) {}
class iterator
{
Cell<ORBIT> m_index;
TraversorCell<MAP,ORBIT,OPT>* m_ptr;
public:
inline iterator(allCells<MAP,ORBIT,OPT>* p, Cell<ORBIT> i): m_ptr(p),m_index(i){}
inline iterator& operator++()
{
m_index = m_ptr->next();
return *this;
}
inline Cell<ORBIT>& operator*()
{
return m_index;
}
inline bool operator!=(iterator it)
{
return m_index.dart != it.m_index.dart;
}
};
inline iterator begin()
{
return iterator(this,TraversorCell<MAP,ORBIT,OPT>::begin());
}
inline iterator end()
{
return iterator(this,TraversorCell<MAP,ORBIT,OPT>::end());
}
};
template <typename MAP, TraversalOptim OPT = AUTO>
class allVertices : public allCells<MAP, VERTEX, OPT>
{
public:
allVertices(const MAP& m, unsigned int thread = 0) : allCells<MAP, VERTEX>(m, false, thread)
{}
};
template <typename MAP, TraversalOptim OPT = AUTO>
class allEdges : public allCells<MAP, EDGE, OPT>
{
public:
allEdges(const MAP& m, unsigned int thread = 0) : allCells<MAP, EDGE>(m, false, thread)
{}
};
template <typename MAP, TraversalOptim OPT = AUTO>
class allFaces : public allCells<MAP, FACE, OPT>
{
public:
allFaces(const MAP& m, unsigned int thread = 0) : allCells<MAP, FACE>(m, false, thread)
{}
};
template <typename MAP, TraversalOptim OPT = AUTO>
class allVolumes : public allCells<MAP, VOLUME, OPT>
{
public:
allVolumes(const MAP& m, unsigned int thread = 0) : allCells<MAP, VOLUME>(m, false, thread)
{}
};
} // namespace CGoGN
......
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