CellBBoxBuildInformationKdTreeStrategy.h
Go to the documentation of this file.
1 #ifndef GfxTL__CELLBBOXBUILDINFORMATIONKDTREESTRATEGY_HEADER__
2 #define GfxTL__CELLBBOXBUILDINFORMATIONKDTREESTRATEGY_HEADER__
3 
4 namespace GfxTL
5 {
6  template <class InheritedStrategyT>
8  {
9  typedef typename InheritedStrategyT::value_type value_type;
10 
11  class CellData : public InheritedStrategyT::CellData
12  {
13  };
14 
15  template <class BaseT>
16  class StrategyBase : public InheritedStrategyT::template StrategyBase<BaseT>
17  {
18  public:
19  typedef typename InheritedStrategyT::template StrategyBase<BaseT> BaseType;
20  typedef typename BaseType::CellType CellType;
24 
26  {
27  m_bbox[0] = NULL;
28  m_bbox[1] = NULL;
29  }
30 
32  {
33  delete[] m_bbox[0];
34  delete[] m_bbox[1];
35  }
36 
37  const ScalarType* const*
38  RootCellBBox() const
39  {
40  return m_bbox;
41  }
42 
43  protected:
44  class BuildInformation : public BaseType::BuildInformation
45  {
46  public:
47  ScalarType&
49  {
50  return m_oldBound;
51  }
52 
53  const ScalarType
54  OldBound() const
55  {
56  return m_oldBound;
57  }
58 
59  const ScalarType* const*
60  CellBBox() const
61  {
62  return m_cellBbox;
63  }
64 
65  void
66  CellBBox(ScalarType** cellBbox)
67  {
68  m_cellBbox = cellBbox;
69  }
70 
71  private:
72  ScalarType m_oldBound;
73  ScalarType** m_cellBbox;
74  };
75 
76  template <class BuildInformationT>
77  void
78  InitRootBuildInformation(BuildInformationT* bi)
79  {
80  BaseType::InitRootBuildInformation(bi);
81  delete[] m_bbox[0]; // delete because dimension could have changed
82  delete[] m_bbox[1];
83  // init bbox
84  m_bbox[0] = new ScalarType[BaseType::m_dim];
85  m_bbox[1] = new ScalarType[BaseType::m_dim];
86  // init the values (box of zero volume)
87  typename BaseType::HandleType i = bi->Range().first;
88  this->AssignAsAABoxMin(this->at(this->Dereference(i)), &m_bbox[0]);
89  this->AssignAsAABoxMax(this->at(this->Dereference(i)), &m_bbox[1]);
90  for (++i; i != bi->Range().second; ++i)
91  {
92  this->IncludeInAABox(this->at(this->Dereference(i)), m_bbox);
93  }
94  bi->CellBBox(m_bbox);
95  }
96 
97  template <class BuildInformationT>
98  void
100  const BuildInformationT& parentInfo,
101  unsigned int childIdx,
102  BuildInformationT* bi)
103  {
104  BaseType::InitBuildInformation(parent, parentInfo, childIdx, bi);
105  bi->CellBBox(m_bbox);
106  }
107 
108  template <class BuildInformationT>
109  void
110  EnterGlobalBuildInformation(const CellType& cell, BuildInformationT* bi)
111  {
112  BaseType::EnterGlobalBuildInformation(cell, bi);
113  if (bi->CreateChild() == 0)
114  {
115  bi->OldBound() = m_bbox[1][cell.SplitAxis()];
116  m_bbox[1][cell.SplitAxis()] = cell.SplitValue();
117  }
118  else
119  {
120  bi->OldBound() = m_bbox[0][cell.SplitAxis()];
121  m_bbox[0][cell.SplitAxis()] = cell.SplitValue();
122  }
123  }
124 
125  template <class BuildInformationT>
126  void
127  LeaveGlobalBuildInformation(const CellType& cell, const BuildInformationT& bi)
128  {
129  BaseType::LeaveGlobalBuildInformation(cell, bi);
130  if (bi.CreateChild() == 1)
131  {
132  m_bbox[1][cell.SplitAxis()] = bi.OldBound();
133  }
134  else
135  {
136  m_bbox[0][cell.SplitAxis()] = bi.OldBound();
137  }
138  }
139 
140  private:
141  ScalarType* m_bbox[2];
142  };
143  };
144 }; // namespace GfxTL
145 
146 #endif
GfxTL::CellBBoxBuildInformationKdTreeStrategy::StrategyBase::RootCellBBox
const ScalarType *const * RootCellBBox() const
Definition: CellBBoxBuildInformationKdTreeStrategy.h:38
GfxTL::CellBBoxBuildInformationKdTreeStrategy::StrategyBase::DiffScalarType
ScalarTypeConversion< ScalarType, ScalarType >::DifferenceType DiffScalarType
Definition: CellBBoxBuildInformationKdTreeStrategy.h:23
GfxTL::CellBBoxBuildInformationKdTreeStrategy::StrategyBase::BuildInformation
Definition: CellBBoxBuildInformationKdTreeStrategy.h:44
GfxTL::CellBBoxBuildInformationKdTreeStrategy::StrategyBase::InitRootBuildInformation
void InitRootBuildInformation(BuildInformationT *bi)
Definition: CellBBoxBuildInformationKdTreeStrategy.h:78
GfxTL::ScalarTypeDeferer
Definition: ScalarTypeDeferer.h:13
GfxTL::CellBBoxBuildInformationKdTreeStrategy::StrategyBase::BuildInformation::CellBBox
const ScalarType *const * CellBBox() const
Definition: CellBBoxBuildInformationKdTreeStrategy.h:60
GfxTL::CellBBoxBuildInformationKdTreeStrategy::CellData
Definition: CellBBoxBuildInformationKdTreeStrategy.h:11
GfxTL::CellBBoxBuildInformationKdTreeStrategy
Definition: CellBBoxBuildInformationKdTreeStrategy.h:7
GfxTL::CellBBoxBuildInformationKdTreeStrategy::StrategyBase::ScalarType
ScalarTypeDeferer< value_type >::ScalarType ScalarType
Definition: CellBBoxBuildInformationKdTreeStrategy.h:21
GfxTL::CellBBoxBuildInformationKdTreeStrategy::StrategyBase::CellType
BaseType::CellType CellType
Definition: CellBBoxBuildInformationKdTreeStrategy.h:20
GfxTL::CellBBoxBuildInformationKdTreeStrategy::value_type
InheritedStrategyT::value_type value_type
Definition: CellBBoxBuildInformationKdTreeStrategy.h:9
GfxTL::CellBBoxBuildInformationKdTreeStrategy::StrategyBase::LeaveGlobalBuildInformation
void LeaveGlobalBuildInformation(const CellType &cell, const BuildInformationT &bi)
Definition: CellBBoxBuildInformationKdTreeStrategy.h:127
GfxTL
Definition: AABox.h:9
GfxTL::CellBBoxBuildInformationKdTreeStrategy::StrategyBase::~StrategyBase
~StrategyBase()
Definition: CellBBoxBuildInformationKdTreeStrategy.h:31
GfxTL::ScalarTypeConversion
Definition: ScalarTypeConversion.h:7
GfxTL::CellBBoxBuildInformationKdTreeStrategy::StrategyBase::BuildInformation::OldBound
ScalarType & OldBound()
Definition: CellBBoxBuildInformationKdTreeStrategy.h:48
GfxTL::CellBBoxBuildInformationKdTreeStrategy::StrategyBase::BuildInformation::CellBBox
void CellBBox(ScalarType **cellBbox)
Definition: CellBBoxBuildInformationKdTreeStrategy.h:66
GfxTL::CellBBoxBuildInformationKdTreeStrategy::StrategyBase::StrategyBase
StrategyBase()
Definition: CellBBoxBuildInformationKdTreeStrategy.h:25
GfxTL::CellBBoxBuildInformationKdTreeStrategy::StrategyBase
Definition: CellBBoxBuildInformationKdTreeStrategy.h:16
GfxTL::CellBBoxBuildInformationKdTreeStrategy::StrategyBase::InitBuildInformation
void InitBuildInformation(const CellType &parent, const BuildInformationT &parentInfo, unsigned int childIdx, BuildInformationT *bi)
Definition: CellBBoxBuildInformationKdTreeStrategy.h:99
GfxTL::CellBBoxBuildInformationKdTreeStrategy::StrategyBase::BaseType
InheritedStrategyT::template StrategyBase< BaseT > BaseType
Definition: CellBBoxBuildInformationKdTreeStrategy.h:19
GfxTL::CellBBoxBuildInformationKdTreeStrategy::StrategyBase::BuildInformation::OldBound
const ScalarType OldBound() const
Definition: CellBBoxBuildInformationKdTreeStrategy.h:54
GfxTL::CellBBoxBuildInformationKdTreeStrategy::StrategyBase::EnterGlobalBuildInformation
void EnterGlobalBuildInformation(const CellType &cell, BuildInformationT *bi)
Definition: CellBBoxBuildInformationKdTreeStrategy.h:110