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