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

Revision 468, 11.0 KB checked in by mattausch, 19 years ago (diff)

updated rendersimulator

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