FaceNeighborAACubeTreeStrategy.h
Go to the documentation of this file.
1 #ifndef GfxTL__FACENEIGHBORAACUBETREESTRATEGY_HEADER__
2 #define GfxTL__FACENEIGHBORAACUBETREESTRATEGY_HEADER__
3 
4 namespace GfxTL
5 {
6 
7  // requires that InheritedStrategyT supports StrategyBase::CellParent() and CellType::Center()
8  template< class InheritedStrategyT >
10  {
11  typedef typename InheritedStrategyT::value_type value_type;
12 
13  class CellData
14  : public InheritedStrategyT::CellData
15  {};
16 
17  template< class BaseT >
19  : public InheritedStrategyT::template StrategyBase< BaseT >
20  {
21 public:
22  typedef typename InheritedStrategyT::template StrategyBase< BaseT > BaseType;
23  typedef typename BaseType::CellType CellType;
24  enum { Dim = CellType::Dim };
25 
26  // returns the face neighbor along axis in direction (0 = left, 1 = right)
27  // returns in level the level of the neighbor relative to the input cell (upwards)
28  // returns NULL if the cell is on the boundary
29  // This function does not return all face neighbors in the given direction
30  // in the case that the neighbors live on a deeper level than the input cell.
31  // In such a case the face neighbor on the same level as the input cell is
32  // return. All face neighbors on that side are children of the returned cell.
33  const CellType* CellFaceNeighbor(const CellType& cell,
34  unsigned int axis, unsigned int dir, size_t* level) const
35  {
36  const CellType* parent = BaseType::CellParent(cell);
37  if (!parent)
38  {
39  return NULL; // root cell does not have any face neighbors
40  }
41  unsigned int childRelation = CellChildRelation(cell, *parent);
42  // check if face neighbor is another child of parent
43  // this is the case if dir is opposite to the childRelation
44  if (((childRelation >> (Dim - 1 - axis)) & 1) ^ (dir & 1)) // cell on opposite side?
45  {
46  unsigned int faceNeighborRelation
47  = childRelation ^ (1 << (Dim - 1 - axis)); // flip the respective bit
48  if (BaseType::ExistChild(*parent, faceNeighborRelation))
49  {
50  *level = 0;
51  return &(*parent)[faceNeighborRelation];
52  }
53  *level = 1;
54  return parent; // degenerate case -> cell does not have an actual face neighbor
55  }
56  // otherwise the face neighbor is a neighbor of the parent
57  size_t l;
58  const CellType* n = CellFaceNeighbor(*parent, axis, dir, &l);
59  if (!n)
60  {
61  return NULL;
62  }
63  if (l > 0) // if the face neighbor of the parent does not live on the same level as the parent
64  // we are unable to find any deeper face neighbor
65  {
66  *level = l + 1;
67  return n;
68  }
69  // otherwise try to find the child of n that is our face neighbor
70  // our face neighbor is the child that has the opposite side than us on axis
71  unsigned int faceNeighborRelation
72  = childRelation ^ (1 << (Dim - 1 - axis)); // flip the respective bit
73  if (BaseType::ExistChild(*n, faceNeighborRelation))
74  {
75  *level = 0;
76  return &(*n)[faceNeighborRelation];
77  }
78  *level = 1;
79  return n;
80  }
81 
82  // non-const version
84  unsigned int axis, unsigned int dir, size_t* level)
85  {
86  return const_cast< CellType* >(CellFaceNeighbor(cell, axis, dir, level));
87  }
88 
89  unsigned int CellChildRelation(const CellType& cell, const CellType& parent) const
90  {
91  unsigned int childRelation = 0;
92  for (unsigned int i = 0; i < Dim; ++i)
93  {
94  if (cell.Center()[i] > parent.Center()[i])
95  {
96  childRelation |= 1 << (Dim - 1 - i);
97  }
98  }
99  return childRelation;
100  }
101  };
102  };
103 
104 };
105 
106 #endif
GfxTL::FaceNeighborAACubeTreeStrategy::CellData
Definition: FaceNeighborAACubeTreeStrategy.h:13
GfxTL::FaceNeighborAACubeTreeStrategy::value_type
InheritedStrategyT::value_type value_type
Definition: FaceNeighborAACubeTreeStrategy.h:11
GfxTL::FaceNeighborAACubeTreeStrategy::StrategyBase::Dim
@ Dim
Definition: FaceNeighborAACubeTreeStrategy.h:24
GfxTL::FaceNeighborAACubeTreeStrategy::StrategyBase::CellType
BaseType::CellType CellType
Definition: FaceNeighborAACubeTreeStrategy.h:23
GfxTL::FaceNeighborAACubeTreeStrategy::StrategyBase::BaseType
InheritedStrategyT::template StrategyBase< BaseT > BaseType
Definition: FaceNeighborAACubeTreeStrategy.h:22
GfxTL
Definition: AABox.h:8
GfxTL::FaceNeighborAACubeTreeStrategy::StrategyBase
Definition: FaceNeighborAACubeTreeStrategy.h:18
GfxTL::FaceNeighborAACubeTreeStrategy
Definition: FaceNeighborAACubeTreeStrategy.h:9
GfxTL::FaceNeighborAACubeTreeStrategy::StrategyBase::CellFaceNeighbor
CellType * CellFaceNeighbor(CellType &cell, unsigned int axis, unsigned int dir, size_t *level)
Definition: FaceNeighborAACubeTreeStrategy.h:83
GfxTL::FaceNeighborAACubeTreeStrategy::StrategyBase::CellChildRelation
unsigned int CellChildRelation(const CellType &cell, const CellType &parent) const
Definition: FaceNeighborAACubeTreeStrategy.h:89
GfxTL::FaceNeighborAACubeTreeStrategy::StrategyBase::CellFaceNeighbor
const CellType * CellFaceNeighbor(const CellType &cell, unsigned int axis, unsigned int dir, size_t *level) const
Definition: FaceNeighborAACubeTreeStrategy.h:33