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

Revision 569, 3.5 KB checked in by bittner, 18 years ago (diff)

viewcell validy setting functions extended

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
139  static bool SmallerPvs(const ViewCell *a,
140                                                 const ViewCell *b) {
141        return a->GetPvs().GetSize() < b->GetPvs().GetSize();
142  }
143
144protected:
145
146        /// the potentially visible objects
147        ObjectPvs mPvs;
148
149        float mVolume;
150        float mArea;
151
152
153        bool mValid;
154};
155
156/**
157        View cell belonging to a hierarchy.
158*/
159template<typename T>
160class HierarchyViewCell: public ViewCell
161{
162public:
163        HierarchyViewCell<T>(): mLeaves(0) {}
164        HierarchyViewCell<T>(Mesh *mesh):
165                ViewCell(mesh), mLeaves(0) {}
166
167        void UpdateViewCellsStats(ViewCellsStatistics &vcStat)
168        {
169                ViewCell::UpdateViewCellsStats(vcStat);
170
171                if ((int)mLeaves.size() > vcStat.maxLeaves)
172                        vcStat.maxLeaves = (int)mLeaves.size();
173                vcStat.leaves += (int)mLeaves.size();
174        }
175
176        /// Leaves of the hierarchy which are part of this view cell.
177        std::vector<T> mLeaves;
178};
179
180
181typedef HierarchyViewCell<BspLeaf *> BspViewCell;
182typedef HierarchyViewCell<KdLeaf *> KdViewCell;
183typedef HierarchyViewCell<VspKdLeaf *> VspKdViewCell;
184
185
186#endif
Note: See TracBrowser for help on using the repository browser.