1 | #ifndef _VisibilityInfo_H__ |
---|
2 | #define _VisibilityInfo_H__ |
---|
3 | |
---|
4 | #include <vector> |
---|
5 | |
---|
6 | //#include "VisibilityMesh.h" |
---|
7 | #include "HierarchyInterface.h" |
---|
8 | |
---|
9 | namespace GtpVisibility { |
---|
10 | |
---|
11 | /** Class storing visibility information. |
---|
12 | */ |
---|
13 | template<typename T>
|
---|
14 | class VisibilityInfo
|
---|
15 | { |
---|
16 | public: |
---|
17 | VisibilityInfo(T source, const int visiblePixels, const int projectedPixels); |
---|
18 | |
---|
19 | /** set source of the info. |
---|
20 | */ |
---|
21 | void SetSource(T source); |
---|
22 | /** get source of the info. |
---|
23 | */ |
---|
24 | T GetSource() const; |
---|
25 | |
---|
26 | int GetVisiblePixels() const; |
---|
27 | int GetProjectedPixels() const; |
---|
28 | |
---|
29 | void SetVisiblePixels(int vis); |
---|
30 | void SetProjectedPixels(int vis); |
---|
31 | |
---|
32 | /** Computes ratio of visible to projected pixels. |
---|
33 | */ |
---|
34 | float ComputeRelativeVisibility(); |
---|
35 | |
---|
36 | /** Adds visibility to current visibility information. |
---|
37 | */ |
---|
38 | void AddVisibility(const VisibilityInfo<T> &info); |
---|
39 | /** Adds visibility to current visibility information. |
---|
40 | */ |
---|
41 | void AddVisibility(const int visiblePixels, const int projectedPixels); |
---|
42 | |
---|
43 | bool operator<(const VisibilityInfo<T> &b) const
|
---|
44 | { |
---|
45 | return mSource < b.mSource; |
---|
46 | } |
---|
47 | |
---|
48 | bool operator==(const VisibilityInfo<T> &b) const
|
---|
49 | { |
---|
50 | return mSource == b.mSource; |
---|
51 | } |
---|
52 | |
---|
53 | protected: |
---|
54 | /** number of visible pixels. |
---|
55 | */ |
---|
56 | int mVisiblePixels; |
---|
57 | /** number of projected pixels |
---|
58 | */ |
---|
59 | int mProjectedPixels;
|
---|
60 |
|
---|
61 | T mSource;
|
---|
62 | }; |
---|
63 | |
---|
64 | //-----------------------------------------------------------------------
|
---|
65 | template <typename T>
|
---|
66 | T VisibilityInfo<T>::GetSource() const
|
---|
67 | {
|
---|
68 | return mSource;
|
---|
69 | } |
---|
70 | |
---|
71 | //-----------------------------------------------------------------------
|
---|
72 | template <typename T>
|
---|
73 | void VisibilityInfo<T>::SetSource(T source)
|
---|
74 | {
|
---|
75 | return mSource;
|
---|
76 | } |
---|
77 |
|
---|
78 | //-----------------------------------------------------------------------
|
---|
79 | template <typename T> |
---|
80 | VisibilityInfo<T>::VisibilityInfo(T source, const int visiblePixels, const int projectedPixels): |
---|
81 | mSource(source), mProjectedPixels(projectedPixels), mVisiblePixels(visiblePixels) |
---|
82 | {
|
---|
83 | }
|
---|
84 |
|
---|
85 | //-----------------------------------------------------------------------
|
---|
86 | template <typename T>
|
---|
87 | int VisibilityInfo<T>::GetVisiblePixels() const |
---|
88 | { |
---|
89 | return mVisiblePixels; |
---|
90 | } |
---|
91 | //-----------------------------------------------------------------------
|
---|
92 | template <typename T> |
---|
93 | int VisibilityInfo<T>::GetProjectedPixels() const |
---|
94 | { |
---|
95 | return mProjectedPixels; |
---|
96 | } |
---|
97 | //-----------------------------------------------------------------------
|
---|
98 | template <typename T> |
---|
99 | void VisibilityInfo<T>::SetVisiblePixels(int vis) |
---|
100 | { |
---|
101 | mVisiblePixels = vis; |
---|
102 | } |
---|
103 | //-----------------------------------------------------------------------
|
---|
104 | template <typename T> |
---|
105 | void VisibilityInfo<T>::SetProjectedPixels(int vis) |
---|
106 | { |
---|
107 | mProjectedPixels = vis; |
---|
108 | } |
---|
109 | //-----------------------------------------------------------------------
|
---|
110 | template <typename T> |
---|
111 | float VisibilityInfo<T>::ComputeRelativeVisibility() |
---|
112 | { |
---|
113 | if (!mProjectedPixels) |
---|
114 | return 0; |
---|
115 | |
---|
116 | return (float)mVisiblePixels / (float)mProjectedPixels; |
---|
117 | } |
---|
118 | //-----------------------------------------------------------------------
|
---|
119 | template <typename T> |
---|
120 | void VisibilityInfo<T>::AddVisibility(const VisibilityInfo<T> &info) |
---|
121 | { |
---|
122 | mVisiblePixels += info.GetVisiblePixels(); |
---|
123 | mProjectedPixels += info.GetProjectedPixels(); |
---|
124 | } |
---|
125 | |
---|
126 | //-----------------------------------------------------------------------
|
---|
127 | template <typename T> |
---|
128 | void VisibilityInfo<T>::AddVisibility(const int visiblePixels, const int projectedPixels) |
---|
129 | { |
---|
130 | mVisiblePixels += visiblePixels; |
---|
131 | mProjectedPixels += projectedPixels; |
---|
132 | } |
---|
133 | |
---|
134 | template<class T>
|
---|
135 | struct InfoContainer
|
---|
136 | {
|
---|
137 | typedef std::vector<VisibilityInfo<T> > Type;
|
---|
138 | };
|
---|
139 |
|
---|
140 | |
---|
141 | } // namespace GtpVisibility
|
---|
142 | |
---|
143 | #endif |
---|