source: trunk/VUT/GtpVisibility/include/VisibilityInfo.h @ 318

Revision 318, 3.7 KB checked in by mattausch, 19 years ago (diff)

VisibilityInfo?: query sort operators as templates
X3dExporter: Fixed polygon wire frame, bsp splits, and bsp split planes visualization
ViewCellBsp?: Added rays to split criteria (not finished yet)
OgreOctreeSceneManager?: fixed error (mNumOctants instead of mNumOctrees)

Line 
1#ifndef _VisibilityInfo_H__
2#define _VisibilityInfo_H__
3
4#include <vector>
5
6#include "VisibilityMesh.h"
7#include "HierarchyInterface.h"
8
9namespace GtpVisibility {
10 
11/** Class storing visibility information.
12*/
13template<typename T>
14class VisibilityInfo
15{
16public:
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
53protected:
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//-----------------------------------------------------------------------
65template <typename T>
66T VisibilityInfo<T>::GetSource() const
67{
68        return mSource;
69}
70
71//-----------------------------------------------------------------------
72template <typename T>
73void VisibilityInfo<T>::SetSource(T source)
74{
75        return mSource;
76}
77
78//-----------------------------------------------------------------------
79template <typename T>
80VisibilityInfo<T>::VisibilityInfo(T source, const int visiblePixels, const int projectedPixels):
81mSource(source), mProjectedPixels(projectedPixels), mVisiblePixels(visiblePixels)
82{
83}
84
85//-----------------------------------------------------------------------
86template <typename T>
87int VisibilityInfo<T>::GetVisiblePixels() const
88{
89        return mVisiblePixels;
90}
91//-----------------------------------------------------------------------
92template <typename T>
93int VisibilityInfo<T>::GetProjectedPixels() const
94{
95        return mProjectedPixels;
96}
97//-----------------------------------------------------------------------
98template <typename T>
99void VisibilityInfo<T>::SetVisiblePixels(int vis)
100{
101        mVisiblePixels = vis;
102}
103//-----------------------------------------------------------------------
104template <typename T>
105void VisibilityInfo<T>::SetProjectedPixels(int vis)
106{
107        mProjectedPixels = vis;
108}
109//-----------------------------------------------------------------------
110template <typename T>
111float VisibilityInfo<T>::ComputeRelativeVisibility()
112{
113        if (!mProjectedPixels)
114                return 0;
115
116        return (float)mVisiblePixels / (float)mProjectedPixels;
117}
118//-----------------------------------------------------------------------
119template <typename T>
120void VisibilityInfo<T>::AddVisibility(const VisibilityInfo<T> &info)
121{
122        mVisiblePixels += info.GetVisiblePixels();
123        mProjectedPixels += info.GetProjectedPixels();
124}
125
126//-----------------------------------------------------------------------
127template <typename T>
128void VisibilityInfo<T>::AddVisibility(const int visiblePixels, const int projectedPixels)
129{
130        mVisiblePixels += visiblePixels;
131        mProjectedPixels += projectedPixels;
132}
133
134typedef VisibilityInfo<Patch *> PatchInfo;
135typedef VisibilityInfo<Mesh *> MeshInfo;
136typedef VisibilityInfo<HierarchyNode *> NodeInfo;
137
138
139template<class T>
140struct InfoContainer
141{
142        typedef std::vector<VisibilityInfo<T> > Type;
143};
144
145typedef std::vector<PatchInfo> PatchInfoContainer;
146typedef std::vector<MeshInfo> MeshInfoContainer;
147typedef std::vector<NodeInfo> NodeInfoContainer;
148
149} // namespace GtpVisibility
150
151#endif
Note: See TracBrowser for help on using the repository browser.