BBoxBuildInformationTreeStrategy.h
Go to the documentation of this file.
1 #ifndef GfxTL__BBOXBUILDINFORMATIONTREESTRATEGY_HEADER__
2 #define GfxTL__BBOXBUILDINFORMATIONTREESTRATEGY_HEADER__
3 #include <algorithm>
4 
5 namespace GfxTL
6 {
7  template <class InheritedStrategyT>
9  {
10  typedef typename InheritedStrategyT::value_type value_type;
11 
12  class CellData : public InheritedStrategyT::CellData
13  {
14  };
15 
16  template <class BaseT>
17  class StrategyBase : public InheritedStrategyT::template StrategyBase<BaseT>
18  {
19  public:
20  typedef typename InheritedStrategyT::template StrategyBase<BaseT> BaseType;
21  typedef typename BaseType::CellType CellType;
22 
23  protected:
24  // BuildInformation objects do not get copied or copy constructed
25  // once they have been initialized. Therefore vector members of
26  // unknown dimension do not pose a problem.
27  class BuildInformation : public BaseType::BuildInformation
28  {
29  public:
31  {
32  m_bbox[0] = m_bbox[1] = NULL;
33  }
34 
36  {
37  delete[] m_bbox[0];
38  delete[] m_bbox[1];
39  }
40 
42  BBox()
43  {
44  return m_bbox;
45  }
46 
47  const typename ScalarTypeDeferer<value_type>::ScalarType* const*
48  BBox() const
49  {
50  return m_bbox;
51  }
52 
54  };
55 
56  template <class BuildInformationT>
57  void
58  InitRootBuildInformation(BuildInformationT* bi)
59  {
60  BaseType::InitRootBuildInformation(bi);
61  // init bbox
62  bi->m_bbox[0] =
63  new typename ScalarTypeDeferer<value_type>::ScalarType[BaseType::m_dim];
64  bi->m_bbox[1] =
65  new typename ScalarTypeDeferer<value_type>::ScalarType[BaseType::m_dim];
66  // init the values (box of zero volume)
67  typename BaseType::HandleType i = bi->Range().first;
68  BaseType::AssignAsAABoxMin(this->at(this->Dereference(i)), &bi->m_bbox[0]);
69  BaseType::AssignAsAABoxMax(this->at(this->Dereference(i)), &bi->m_bbox[1]);
70  for (++i; i != bi->Range().second; ++i)
71  {
72  BaseType::IncludeInAABox(this->at(this->Dereference(i)), bi->BBox());
73  }
74  }
75 
76  template <class BuildInformationT>
77  void
79  const BuildInformationT& parentInfo,
80  unsigned int childIdx,
81  BuildInformationT* bi)
82  {
83  BaseType::InitBuildInformation(parent, parentInfo, childIdx, bi);
84  // init bbox
85  bi->m_bbox[0] =
86  new typename ScalarTypeDeferer<value_type>::ScalarType[BaseType::m_dim];
87  bi->m_bbox[1] =
88  new typename ScalarTypeDeferer<value_type>::ScalarType[BaseType::m_dim];
89  // init the values (box of zero volume)
90  if (!(bi->Range().second - bi->Range().first))
91  {
92  std::fill(bi->m_bbox[0],
93  bi->m_bbox[0] + BaseType::m_dim,
95  std::fill(bi->m_bbox[1],
96  bi->m_bbox[1] + BaseType::m_dim,
98  return;
99  }
100  typename BaseType::HandleType i = bi->Range().first;
101  BaseType::AssignAsAABoxMin(this->at(this->Dereference(i)), &bi->m_bbox[0]);
102  BaseType::AssignAsAABoxMax(this->at(this->Dereference(i)), &bi->m_bbox[1]);
103  for (++i; i != bi->Range().second; ++i)
104  {
105  BaseType::IncludeInAABox(this->at(this->Dereference(i)), bi->BBox());
106  }
107  }
108  };
109  };
110 }; // namespace GfxTL
111 
112 #endif
GfxTL::BBoxBuildInformationTreeStrategy::StrategyBase::BuildInformation::BBox
const ScalarTypeDeferer< value_type >::ScalarType *const * BBox() const
Definition: BBoxBuildInformationTreeStrategy.h:48
GfxTL::ScalarTypeDeferer
Definition: ScalarTypeDeferer.h:13
GfxTL::BBoxBuildInformationTreeStrategy::StrategyBase::InitRootBuildInformation
void InitRootBuildInformation(BuildInformationT *bi)
Definition: BBoxBuildInformationTreeStrategy.h:58
GfxTL::BBoxBuildInformationTreeStrategy::StrategyBase::BuildInformation::BuildInformation
BuildInformation()
Definition: BBoxBuildInformationTreeStrategy.h:30
GfxTL::BBoxBuildInformationTreeStrategy::value_type
InheritedStrategyT::value_type value_type
Definition: BBoxBuildInformationTreeStrategy.h:10
GfxTL::BBoxBuildInformationTreeStrategy::CellData
Definition: BBoxBuildInformationTreeStrategy.h:12
GfxTL::BBoxBuildInformationTreeStrategy::StrategyBase::CellType
BaseType::CellType CellType
Definition: BBoxBuildInformationTreeStrategy.h:21
GfxTL::BBoxBuildInformationTreeStrategy::StrategyBase::BaseType
InheritedStrategyT::template StrategyBase< BaseT > BaseType
Definition: BBoxBuildInformationTreeStrategy.h:20
GfxTL::BBoxBuildInformationTreeStrategy::StrategyBase::BuildInformation::~BuildInformation
~BuildInformation()
Definition: BBoxBuildInformationTreeStrategy.h:35
GfxTL::BBoxBuildInformationTreeStrategy::StrategyBase::BuildInformation::BBox
ScalarTypeDeferer< value_type >::ScalarType ** BBox()
Definition: BBoxBuildInformationTreeStrategy.h:42
GfxTL
Definition: AABox.h:9
GfxTL::BBoxBuildInformationTreeStrategy::StrategyBase::InitBuildInformation
void InitBuildInformation(const CellType &parent, const BuildInformationT &parentInfo, unsigned int childIdx, BuildInformationT *bi)
Definition: BBoxBuildInformationTreeStrategy.h:78
GfxTL::BBoxBuildInformationTreeStrategy
Definition: BBoxBuildInformationTreeStrategy.h:8
GfxTL::BBoxBuildInformationTreeStrategy::StrategyBase::BuildInformation
Definition: BBoxBuildInformationTreeStrategy.h:27
GfxTL::BBoxBuildInformationTreeStrategy::StrategyBase::BuildInformation::m_bbox
ScalarTypeDeferer< value_type >::ScalarType * m_bbox[2]
Definition: BBoxBuildInformationTreeStrategy.h:53
GfxTL::BBoxBuildInformationTreeStrategy::StrategyBase
Definition: BBoxBuildInformationTreeStrategy.h:17