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

Revision 478, 2.8 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/**
20        View cell with an optional mesh representation
21*/
22class ViewCell: public MeshInstance
23{
24public:
25        ViewCell();
26
27        /** Constructor taking a mesh representing the shape of the viewcell.
28        */
29        ViewCell(Mesh *mesh);
30
31        /** Default destructor.
32        */
33        virtual ~ViewCell() {}
34        /** Returns Pvs.
35        */
36        const ObjectPvs &GetPvs() const;
37        ObjectPvs &GetPvs();
38
39        int Type() const;
40
41        /** Adds a passing ray to the passing ray container.
42        */
43        void AddPassingRay(const Ray &ray, const int contributions);
44
45        /** Returns volume of the view cell.
46        */
47        float GetVolume() const;
48
49        /** Returns area of the view cell.
50        */
51        float GetArea() const;
52
53        /** Sets the volume of the view cell.
54        */
55        void SetVolume(float volume);
56       
57        /** Sets the area of the view cell.
58        */
59        void SetArea(float area);
60
61        /// Ray set description of the rays passing through this node.
62        PassingRaySet mPassingRays;
63
64        /// Rays piercing this view cell.
65        RayContainer mPiercingRays;
66
67protected:
68
69        /// the potentially visible objects
70        ObjectPvs mPvs;
71
72        float mVolume;
73        float mArea;
74};
75
76/**
77        View cell belonging to a hierarchy.
78*/
79template<typename T>
80class HierarchyViewCell: public ViewCell
81{
82public:
83        HierarchyViewCell<T>(): mLeaves(0) {}
84        HierarchyViewCell<T>(Mesh *mesh):
85                ViewCell(mesh), mLeaves(0) {}
86
87        /// Leaves of the hierarchy which are part of this view cell.
88        std::vector<T> mLeaves;
89};
90
91typedef HierarchyViewCell<BspLeaf *> BspViewCell;
92typedef HierarchyViewCell<KdLeaf *> KdViewCell;
93typedef HierarchyViewCell<VspKdLeaf *> VspKdViewCell;
94
95
96/** Statistics for a view cell partition.
97*/
98
99class ViewCellsStatistics: public StatisticsBase
100{
101public:
102
103        /// number of view cells
104        int viewCells;
105
106        /// size of the PVS
107        int pvs;
108
109        /// largest PVS of all view cells
110        int maxPvs;
111
112        /// smallest PVS of all view cells
113        int minPvs;
114
115        /// view cells with empty PVS
116        int emptyPvs;
117
118        /// number of leaves covering the view space
119        int leaves;
120
121        /// largest number of leaves covered by one view cell
122        int maxLeaves;
123
124    // Constructor
125        ViewCellsStatistics()
126        {
127                Reset();
128        }
129
130        double AvgLeaves() const {return (double)leaves / (double)viewCells;};
131        double AvgPvs() const {return (double)pvs / (double)viewCells;};
132
133        void Reset()
134        {
135                viewCells = 0;
136                pvs = 0;
137                maxPvs = 0;
138
139                minPvs = 999999;
140                emptyPvs = 0;
141                leaves = 0;
142                maxLeaves = 0;
143        }
144
145        void Print(ostream &app) const;
146
147        friend ostream &operator<<(ostream &s, const ViewCellsStatistics &stat)
148        {
149                stat.Print(s);
150                return s;
151        }
152};
153
154#endif
Note: See TracBrowser for help on using the repository browser.