BBoxBuildInformationTreeStrategy.h
Go to the documentation of this file.
1#ifndef GfxTL__BBOXBUILDINFORMATIONTREESTRATEGY_HEADER__
2#define GfxTL__BBOXBUILDINFORMATIONTREESTRATEGY_HEADER__
3#include <algorithm>
4
5namespace 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
43 {
44 return m_bbox;
45 }
46
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
const ScalarTypeDeferer< value_type >::ScalarType *const * BBox() const
void InitBuildInformation(const CellType &parent, const BuildInformationT &parentInfo, unsigned int childIdx, BuildInformationT *bi)
InheritedStrategyT::template StrategyBase< BaseT > BaseType
Definition AABox.h:10
PointT::value_type ScalarType