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

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