OpenFPM_data  0.1.0
Project that contain the implementation and interfaces for basic structure like vectors, grids, graph ... .
 All Data Structures Namespaces Functions Variables Typedefs Friends
CellNNIterator.hpp
1 /*
2  * CellNNIterator.hpp
3  *
4  * Created on: Mar 26, 2015
5  * Author: i-bird
6  */
7 
8 #ifndef CELLNNITERATOR_FULL_HPP_
9 #define CELLNNITERATOR_FULL_HPP_
10 
11 #include "util/mathutil.hpp"
12 
13 #define FULL openfpm::math::pow(3,dim)
14 #define SYM openfpm::math::pow(3,dim)/2
15 #define CRS openfpm::math::pow(2,dim)
16 
17 #define NO_CHECK 1
18 #define SAFE 2
19 
32 template<unsigned int dim, typename Cell,unsigned int NNc_size, unsigned int impl> class CellNNIterator
33 {
34  // Cell list
35  Cell & cl;
36 
37  // Actual NNc_id;
38  size_t NNc_id;
39 
40  // actual cell id = NNc[NNc_id]+cell stored for performance reason
41  size_t cell_id;
42 
43  // actual element id
44  size_t ele_id;
45 
46  // NN cell id
47  const long int (& NNc)[NNc_size];
48 
49  // Center cell, or cell for witch we are searching the NN-cell
50  const long int cell;
51 
52 public:
53 
63  CellNNIterator(size_t cell, long int (&NNc)[NNc_size], Cell & cl)
64  :cl(cl),NNc_id(0),cell_id(NNc[NNc_id] + cell),ele_id(0),NNc(NNc),cell(cell)
65  {
66  }
67 
73  bool isNext()
74  {
75  if (NNc_id >= NNc_size)
76  return false;
77  return true;
78  }
79 
84  {
85  ele_id++;
86 
87  while (ele_id >= cl.getNelements(cell_id))
88  {
89  NNc_id++;
90 
91  // No more Cell
92  if (NNc_id >= NNc_size) return * this;
93 
94  cell_id = NNc[NNc_id] + cell;
95 
96  ele_id = 0;
97  }
98 
99  return *this;
100  }
101 
107  typename Cell::value_type & get()
108  {
109  return cl.get(cell_id,ele_id);
110  }
111 };
112 
120 template<typename Cell> class CellIterator
121 {
122  // Cell list
123  Cell & cl;
124 
125  // actual element id inside the cell
126  size_t ele_id;
127 
128  // selected cell
129  const long int cell;
130 
131 public:
132 
139  CellIterator(const size_t cell, Cell & cl)
140  :cl(cl),ele_id(0),cell(cell)
141  {
142  }
143 
149  bool isNext()
150  {
151  return cl.getNelements(cell) > ele_id;
152  }
153 
158  {
159  ele_id++;
160 
161  return *this;
162  }
163 
169  typename Cell::value_type & get()
170  {
171  return cl.get(cell,ele_id);
172  }
173 };
174 
175 #endif /* CELLNNITERATOR_FULL_HPP_ */
CellNNIterator & operator++()
take the next element
bool isNext()
Check if there is the next element.
CellIterator(const size_t cell, Cell &cl)
Cell iterator.
CellIterator & operator++()
take the next element
it iterate through the elements of a cell
bool isNext()
Check if there is the next element.
CellNNIterator(size_t cell, long int(&NNc)[NNc_size], Cell &cl)
Cell NN iterator.
Iterator for the neighborhood of the cell structures.