1 #ifndef TIL_NEIGHBORHOOD_H 2 #define TIL_NEIGHBORHOOD_H 15 #pragma warning( push ) 17 #pragma warning( disable : 4251 ) 22 #define COFFSET(i,j,k) ((i)+3*(j)+9*(k)+13) 25 #define FOR_ALL_NEIGHBORS \ 26 for (i=-1; i<=1; ++i) \ 27 for (j=-1; j<=1; ++j) \ 28 for (k=-1; k<=1; ++k) \ 30 #define APPY_ALL_NEIGHBORS(macro) \ 95 template <
class TNeighborhood >
103 template <
class TNeighborhood >
111 typename TNeighborhood::const_iterator iNeighbor = nh.begin();
112 for (; iNeighbor < nh.end(); ++iNeighbor)
114 if (nh.isNeighbor(*iNeighbor))
116 this->
set(*iNeighbor);
122 void init(
const bool array[3*3*3])
133 template <
typename TFunctor >
138 iNeighbor != m_neighbors.end();
180 void reset() { m_neighbors.clear(); }
208 NeighborList m_neighbors;
231 bool n000,
bool n001,
bool n002,
232 bool n010,
bool n011,
bool n012,
233 bool n020,
bool n021,
bool n022,
234 bool n100,
bool n101,
bool n102,
235 bool n110,
bool n111,
bool n112,
236 bool n120,
bool n121,
bool n122,
237 bool n200,
bool n201,
bool n202,
238 bool n210,
bool n211,
bool n212,
239 bool n220,
bool n221,
bool n222)
241 m_cube[0]= n000; m_cube[1]= n001; m_cube[2]= n002;
242 m_cube[3]= n010; m_cube[4]= n011; m_cube[5]= n012;
243 m_cube[6]= n020; m_cube[7]= n021; m_cube[8]= n022;
244 m_cube[9]= n100; m_cube[10]= n101; m_cube[11]= n102;
245 m_cube[12]= n110; m_cube[13]= n111; m_cube[14]= n112;
246 m_cube[15]= n120; m_cube[16]= n121; m_cube[17]= n122;
247 m_cube[18]= n200; m_cube[19]= n201; m_cube[20]= n202;
248 m_cube[21]= n210; m_cube[22]= n211; m_cube[23]= n212;
249 m_cube[24]= n220; m_cube[25]= n221; m_cube[26]= n222;
258 void init(
const bool array[3*3*3])
260 for (
int i = 0; i < 3*3*3; ++i) m_cube[i] = array[i];
266 void reset() {
for (
int i = 0; i <= 3*3*3; ++i) m_cube[i] =
false; }
269 void set(
int i,
int j,
int k)
271 this->setValue(i,j,k,
true);
282 void remove(
int i,
int j,
int k)
284 this->setValue(i,j,k,
false);
297 assert(
contains(
Range<int,3>(
numeric_array<int,3>(-1,-1,-1),
numeric_array<int,3>(1,1,1)),
numeric_array<int,3>(i, j, k)));
298 return m_cube[Self::offset(i,j,k)];
305 template <
typename TFunctor >
320 template <
int i,
int j,
int k>
325 assert(i >=-1 && i <= 1);
326 assert(j >=-1 && j <= 1);
327 assert(k >=-1 && k <= 1);
328 return m_cube[Self::offset(i,j,k)];
334 void setValue(
int i,
int j,
int k,
bool value)
336 assert(
contains(
Range<int,3>(
numeric_array<int,3>(-1,-1,-1),
numeric_array<int,3>(1,1,1)),
numeric_array<int,3>(i, j, k)));
337 m_cube[Self::offset(i,j,k)] = value;
340 INLINE static int offset(
int i,
int j,
int k) {
return i+3*j+9*k+13; }
390 bool n000, bool n001, bool n002,\ 391 bool n010, bool n011, bool n012,\ 392 bool n020, bool n021, bool n022,\ 393 bool n100, bool n101, bool n102,\ 394 bool n110, bool n111, bool n112,\ 395 bool n120, bool n121, bool n122,\ 396 bool n200, bool n201, bool n202,\ 397 bool n210, bool n211, bool n212,\ 398 bool n220, bool n221, bool n222 414 bool n000,
bool n001,
bool n002,
415 bool n010,
bool n011,
bool n012,
416 bool n020,
bool n021,
bool n022,
417 bool n100,
bool n101,
bool n102,
418 bool n110,
bool n111,
bool n112,
419 bool n120,
bool n121,
bool n122,
420 bool n200,
bool n201,
bool n202,
421 bool n210,
bool n211,
bool n212,
422 bool n220,
bool n221,
bool n222 >
439 if (i==-1 && j==-1 && k==-1)
return n000;
440 if (i==-1 && j==-1 && k== 0)
return n001;
441 if (i==-1 && j==-1 && k==+1)
return n002;
443 if (i==-1 && j== 0 && k==-1)
return n010;
444 if (i==-1 && j== 0 && k== 0)
return n011;
445 if (i==-1 && j== 0 && k==+1)
return n012;
447 if (i==-1 && j==+1 && k==-1)
return n020;
448 if (i==-1 && j==+1 && k== 0)
return n021;
449 if (i==-1 && j==+1 && k==+1)
return n022;
451 if (i== 0 && j==-1 && k==-1)
return n100;
452 if (i== 0 && j==-1 && k== 0)
return n101;
453 if (i== 0 && j==-1 && k==+1)
return n102;
455 if (i== 0 && j== 0 && k==-1)
return n110;
456 if (i== 0 && j== 0 && k== 0)
return n111;
457 if (i== 0 && j== 0 && k==+1)
return n112;
459 if (i== 0 && j==+1 && k==-1)
return n120;
460 if (i== 0 && j==+1 && k== 0)
return n121;
461 if (i== 0 && j==+1 && k==+1)
return n122;
463 if (i==+1 && j==-1 && k==-1)
return n200;
464 if (i==+1 && j==-1 && k== 0)
return n201;
465 if (i==+1 && j==-1 && k==+1)
return n202;
467 if (i==+1 && j== 0 && k==-1)
return n210;
468 if (i==+1 && j== 0 && k== 0)
return n211;
469 if (i==+1 && j== 0 && k==+1)
return n212;
471 if (i==+1 && j==+1 && k==-1)
return n220;
472 if (i==+1 && j==+1 && k== 0)
return n221;
473 if (i==+1 && j==+1 && k==+1)
return n222;
477 template <
int i,
int j,
int k>
566 typedef TArgNeighborhood<
579 typedef TArgNeighborhood<
592 #undef FOR_ALL_NEIGHBORS 595 #pragma warning ( pop ) const Neighborhood N6(0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0)
TArgNeighborhood< 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0 > TN18
Template neighborhood for standard 3D 18-connectivity Note that the center is not included...
void reset(const numeric_array< int, 3 > &v)
void for_all_neighbors(const TFunctor &functor)
Neighborhood(bool n000, bool n001, bool n002, bool n010, bool n011, bool n012, bool n020, bool n021, bool n022, bool n100, bool n101, bool n102, bool n110, bool n111, bool n112, bool n120, bool n121, bool n122, bool n200, bool n201, bool n202, bool n210, bool n211, bool n212, bool n220, bool n221, bool n222)
manual
NeighborList::iterator iterator
Neighborhood_list(const bool array[3 *3 *3])
From C array.
DetemplateAssignOperator1< til::functor::Assign > Assign
TArgNeighborhood< 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 > TN6
Template neighborhood for standard 3D 6-connectivity.
#define COFFSET(i, j, k)
A macro to quickly index into a 3^3 cube.
TArgNeighborhood< 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 > TN26
Template neighborhood for standard 3D 26-connectivity Note that the center is not included...
NeighborList::const_iterator const_iterator
Belongs to package Box Do not include directly, include til/Box.h instead.
Self::const_iterator begin() const
INLINE bool isNeighbor() const
Defines empty classes that serves as labels.
Neighborhood()
No neighbors.
void reset()
Remove all neighbors from neighborhood.
INLINE bool isNeighbor() const
Neighborhood(const bool array[3 *3 *3])
from C array
Neighborhood_list()
Default constructor, empty neighborhood.
Neighborhood as a list of vectors.
Neighborhood_list(const TNeighborhood &nh)
Copy constructor from any type of neighborhood.
boost::enable_if< is_numeric_container< TStorage >, bool >::type contains(const Box< T, D > &box, const TStorage &v)
Check whether a point lies within box.
bool isNeighbor(const numeric_array< int, 3 > &v)
INLINE bool isNeighbor(int i, int j, int k) const
void init(const bool array[3 *3 *3])
From C array.
std::vector< numeric_array< int, 3 > > NeighborList
const Neighborhood N18(0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0)
void for_all_neighbors(const TFunctor &functor)
A loop to execute something per neighbor.
Neighborhood(const Neighborhood &nh)
Copy constructor.
enable_if< is_Neighborhood< TNeighborhood > >::type init(const TNeighborhood &nh)
void init(const Neighborhood &nh)
#define FOR_ALL_NEIGHBORS
Self::const_iterator end() const
bool isNeighbor(int i, int j, int k) const
const Neighborhood N26(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
void init(const bool array[3 *3 *3])