source: trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.h @ 564

Revision 564, 3.4 KB checked in by mattausch, 18 years ago (diff)
Line 
1#ifndef _ViewCell_H__
2#define _ViewCell_H__
3
4#include "Mesh.h"
5#include "Containers.h"
6#include "Ray.h"
7#include "Statistics.h"
8//namespace GtpVisibilityPreprocessor {
9
10struct Triangle3;
11
12class BspInterior;
13class BspPvs;
14class BspLeaf;
15class VspKdTree;
16class VspKdLeaf;
17class KdLeaf;
18
19/** Statistics for a view cell partition.
20*/
21
22class ViewCellsStatistics: public StatisticsBase
23{
24public:
25
26        /// number of view cells
27        int viewCells;
28
29        /// size of the PVS
30        int pvs;
31
32        /// largest PVS of all view cells
33        int maxPvs;
34
35        /// smallest PVS of all view cells
36        int minPvs;
37
38        /// view cells with empty PVS
39        int emptyPvs;
40
41        /// number of leaves covering the view space
42        int leaves;
43
44        /// largest number of leaves covered by one view cell
45        int maxLeaves;
46
47        int invalid;
48
49    // Constructor
50        ViewCellsStatistics()
51        {
52                Reset();
53        }
54
55        double AvgLeaves() const {return (double)leaves / (double)viewCells;};
56        double AvgPvs() const {return (double)pvs / (double)viewCells;};
57
58        void Reset()
59        {
60                viewCells = 0;
61                pvs = 0;
62                maxPvs = 0;
63
64                minPvs = 999999;
65                emptyPvs = 0;
66                leaves = 0;
67                maxLeaves = 0;
68                invalid = 0;
69        }
70
71        void Print(ostream &app) const;
72
73        friend ostream &operator<<(ostream &s, const ViewCellsStatistics &stat)
74        {
75                stat.Print(s);
76                return s;
77        }
78};
79
80/**
81        View cell with an optional mesh representation
82*/
83class ViewCell: public MeshInstance
84{
85public:
86        ViewCell();
87
88        /** Constructor taking a mesh representing the shape of the viewcell.
89        */
90        ViewCell(Mesh *mesh);
91
92        /** Default destructor.
93        */
94        virtual ~ViewCell() {}
95        /** Returns Pvs.
96        */
97        const ObjectPvs &GetPvs() const;
98        ObjectPvs &GetPvs();
99
100        int Type() const;
101
102        /** Adds a passing ray to the passing ray container.
103        */
104        void AddPassingRay(const Ray &ray, const int contributions);
105
106        /** Returns volume of the view cell.
107        */
108        float GetVolume() const;
109
110        /** Returns area of the view cell.
111        */
112        float GetArea() const;
113
114        /** Sets the volume of the view cell.
115        */
116        void SetVolume(float volume);
117       
118        /** Sets the area of the view cell.
119        */
120        void SetArea(float area);
121
122        /** Updates the view cell statstics for this particular view cell.
123        */
124        virtual void UpdateViewCellsStats(ViewCellsStatistics &vcStat);
125
126        /// Ray set description of the rays passing through this node.
127        PassingRaySet mPassingRays;
128
129        /// Rays piercing this view cell.
130        RayContainer mPiercingRays;
131
132        /** Sets the mesh for this view cell.
133        */
134        void SetMesh(Mesh *mesh);
135
136        void SetValid(const bool valid);
137        bool GetValid() const;
138
139protected:
140
141        /// the potentially visible objects
142        ObjectPvs mPvs;
143
144        float mVolume;
145        float mArea;
146
147
148        bool mValid;
149};
150
151/**
152        View cell belonging to a hierarchy.
153*/
154template<typename T>
155class HierarchyViewCell: public ViewCell
156{
157public:
158        HierarchyViewCell<T>(): mLeaves(0) {}
159        HierarchyViewCell<T>(Mesh *mesh):
160                ViewCell(mesh), mLeaves(0) {}
161
162        void UpdateViewCellsStats(ViewCellsStatistics &vcStat)
163        {
164                ViewCell::UpdateViewCellsStats(vcStat);
165
166                if ((int)mLeaves.size() > vcStat.maxLeaves)
167                        vcStat.maxLeaves = (int)mLeaves.size();
168                vcStat.leaves += (int)mLeaves.size();
169        }
170
171        /// Leaves of the hierarchy which are part of this view cell.
172        std::vector<T> mLeaves;
173};
174
175
176typedef HierarchyViewCell<BspLeaf *> BspViewCell;
177typedef HierarchyViewCell<KdLeaf *> KdViewCell;
178typedef HierarchyViewCell<VspKdLeaf *> VspKdViewCell;
179
180
181#endif
Note: See TracBrowser for help on using the repository browser.