source: trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.h @ 441

Revision 441, 8.0 KB checked in by mattausch, 19 years ago (diff)

added visibilitymanager
removed area computation from bsp

Line 
1#ifndef _ViewCellsManager_H__
2#define _ViewCellsManager_H__
3
4#include "Ray.h"
5#include "VssRay.h"
6#include "Containers.h"
7
8class ViewCell;
9class Intersectable;
10class RenderSimulator;
11class Mesh;
12struct Triangle3;
13class SimulationStatistics;
14class BspTree;
15class KdTree;
16class VspKdTree;
17class VspBspTree;
18class KdNode;
19class KdLeaf;
20class VspKdTree;
21class AxisAlignedBox3;
22/**
23        Manages different higher order operations on the view cells.
24*/
25class ViewCellsManager
26{
27
28public:
29       
30        /// view cell container types
31        enum {BSP, KD, VSP_KD, VSP_BSP};
32
33        /** Constructor taking the maximal number of samples used for construction
34        */
35        ViewCellsManager(const int constructionSamples);
36
37        ViewCellsManager();
38
39        ~ViewCellsManager();
40
41        /** Constructs view cell container with a given number of samples.
42        */
43        virtual int Construct(const ObjectContainer &objects,
44                                                  const VssRayContainer &rays,
45                                                  AxisAlignedBox3 *sceneBbox = NULL) = 0;
46
47        /** Computes sample contributions of the rays to the view cells PVS.
48       
49                @param rays bundle of rays used to find intersections with view cells and
50                adding the contribution
51                @param castRays true if ray should be cast to gain the information, false if rays
52                already hold the view cells intersection information and need not be recast.
53                @param sampleContributions returns the number of sample contributions
54                @param contributingSamples returns the number of contributingSamples
55        */
56        void  ComputeSampleContributions(const RayContainer &rays,
57                                                                         const bool castRays,
58                                                                         int &sampleContributions,
59                                                                         int &contributingSamples);
60
61
62        /** Computes sample contribution of a simgle ray to the view cells PVS.
63                @param ray finds intersections with view cells and holds the contribution
64                @param castRay true if ray should be cast to gain the information, false if ray
65                is already holding the information and need not be recast.
66
67                @returns number of sample contributions
68        */
69        virtual int ComputeSampleContributions(Ray &ray, const bool castRay = true) = 0;
70
71        /** Post processes view cells givemŽa number of rays.
72        */
73        virtual int PostProcess(const ObjectContainer &objects,
74                                                        const RayContainer &rays) = 0;
75
76        /** Show visualization of the view cells.
77        */
78        virtual void Visualize(const ObjectContainer &objects,
79                                                   const RayContainer &sampleRays) = 0;
80
81        /** type of the view cell container.
82        */
83        virtual int GetType() const = 0;
84
85        /** Simulates rendering with the given view cell partition.
86                @returns render time statistics
87        */
88        SimulationStatistics SimulateRendering() const;
89
90        /** Load the input viewcells. The input viewcells should be given as a collection
91                of meshes. Each mesh is assume to form a bounded polyhedron defining the interior of
92                the viewcell. The method then builds a BSP tree of these view cells.
93               
94                @param filename file to load
95                @return true on success
96    */
97    bool LoadViewCells(const string filename);
98
99        /** Constructs view cell from base triangle. The ViewCell is extruded along the normal vector.
100                @param the base triangle
101                @param the height of the newly created view cell
102        */
103        ViewCell *ExtrudeViewCell(const Triangle3 &baseTri, const float height) const;
104
105        /** Merges two view cells.
106                @note the piercing rays of the front and back will be ordered   
107                @returns new view cell based on the merging.
108        */
109        ViewCell *MergeViewCells(ViewCell &front, ViewCell &back) const;
110       
111        /** Generates view cell of type specified by this manager
112        */
113        virtual ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
114
115        /** Adds a new view cell to the list of predefined view cells.
116        */
117        void AddViewCell(ViewCell *viewCell);
118
119        /** Derive view cells from objects.
120        */
121        void DeriveViewCells(const ObjectContainer &objects,
122                                                 ViewCellContainer &viewCells,
123                                                 const int maxViewCells) const;
124
125        /** Sets maximal number of samples used for the
126                construction of the view cells.
127        */
128        void SetVisualizationSamples(const int visSamples);
129
130        /** Sets maximal number of samples used for the visualization of the view cells.
131        */
132        void SetConstructionSamples(const int constructionSamples);
133
134        /** Sets maximal number of samples used for the post processing of the view cells.
135        */
136        void SetPostProcessSamples(const int postProcessingSamples);
137
138        /** See set.
139        */
140        int GetVisualizationSamples() const;
141
142        /** See set.
143        */
144        int GetConstructionSamples() const;
145
146        /** See set.
147        */
148        int GetPostProcessSamples() const;
149
150        /** Returns true if view cells wer already constructed.
151        */
152        virtual bool ViewCellsConstructed() const = 0;
153       
154       
155
156protected:
157       
158       
159
160        /** Initialises the render time simulator.
161        */
162        void InitRenderSimulator();
163        /////////////////////
164
165       
166        /// the view cell corresponding to unbounded space
167        ViewCell *mUnbounded;
168
169        /// Simulates rendering
170        RenderSimulator *mRenderSimulator;
171
172        /// Loaded view cells
173        ViewCellContainer mViewCells;
174
175        /// maximum number of samples taken for construction of the view cells
176        int mConstructionSamples;
177        int mPostProcessSamples;
178        int mVisualizationSamples;
179
180        //-- thresholds used for view cells merge
181        int mMinPvsDif;
182        int mMinPvs;
183        int mMaxPvs;
184};
185
186
187
188/**
189        Manages different higher order operations on the view cells.
190*/
191class BspViewCellsManager: public ViewCellsManager
192{
193
194public:
195
196        BspViewCellsManager(BspTree *tree, int constructionSamples);
197
198        int Construct(const ObjectContainer &objects,
199                                  const VssRayContainer &rays,
200                                  AxisAlignedBox3 *sceneBbox);
201
202        int ComputeSampleContributions(Ray &ray, const bool castRay = false);
203
204        int PostProcess(const ObjectContainer &objects,
205                                        const RayContainer &rays);
206
207        void Visualize(const ObjectContainer &objects,
208                                   const RayContainer &sampleRays);
209
210        int GetType() const;
211       
212        ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
213
214        bool ViewCellsConstructed() const;
215
216protected:
217
218        /** Merges view cells front and back leaf view cell.
219        */
220        bool MergeBspLeafViewCells(BspLeaf *front, BspLeaf *back) const;
221
222        /** Returns true if front and back leaf should be merged.
223        */
224        bool ShouldMerge(BspLeaf *front, BspLeaf *back) const;
225
226        /// the BSP tree.
227        BspTree *mBspTree;
228
229
230private:
231
232
233        /** Exports visualization of the BSP splits.
234        */
235        void ExportSplits(const ObjectContainer &objects, const RayContainer &sampleRays);
236
237        /** Exports visualization of the BSP PVS.
238        */
239        void ExportBspPvs(const ObjectContainer &objects, const RayContainer &sampleRays);
240
241};
242
243/**
244        Manages different higher order operations on the KD type view cells.
245*/
246class KdViewCellsManager: public ViewCellsManager
247{
248
249public:
250
251        KdViewCellsManager(KdTree *tree);
252
253        int Construct(const ObjectContainer &objects,
254                                  const VssRayContainer &rays,
255                                  AxisAlignedBox3 *sceneBbox);
256
257        int CastRay(const Ray &ray);
258
259        int PostProcess(const ObjectContainer &objects,
260                                        const RayContainer &rays);
261
262        void Visualize(const ObjectContainer &objects,
263                                   const RayContainer &sampleRays);
264
265        int GetType() const;
266
267        bool ViewCellsConstructed() const;
268
269
270protected:
271
272         KdNode *GetNodeForPvs(KdLeaf *leaf);
273
274         int ComputeSampleContributions(Ray &ray, const bool castRay = true);
275
276         /// the BSP tree.
277         KdTree *mKdTree;
278
279         /// depth of the KD tree nodes with represent the view cells
280         int mKdPvsDepth;
281};
282
283/**
284        Manages different higher order operations on the view cells
285        for vsp kd tree view cells.
286*/
287class VspKdViewCellsManager: public ViewCellsManager
288{
289
290public:
291
292        VspKdViewCellsManager(VspKdTree *vspKdTree, int constructionSamples);
293
294        int Construct(const ObjectContainer &objects,
295                                  const VssRayContainer &rays,
296                                  AxisAlignedBox3 *sceneBbox);
297
298        int ComputeSampleContributions(Ray &ray, const bool castRay = true);
299
300        int PostProcess(const ObjectContainer &objects,
301                                        const RayContainer &rays);
302
303        void Visualize(const ObjectContainer &objects,
304                                   const RayContainer &sampleRays);
305
306        int GetType() const;
307       
308        bool ViewCellsConstructed() const;
309
310
311protected:
312
313        /// the BSP tree.
314        VspKdTree *mVspKdTree;
315};
316
317
318#endif
Note: See TracBrowser for help on using the repository browser.