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

Revision 440, 7.2 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;
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        /** Casts bundle of rays to the view cells and stores contributions in PVS.
48        */
49        int CastRays(const RayContainer &rays);
50
51        /** Casts ray to the view cells and stores contributions in PVS.
52        */
53        virtual int CastRay(const Ray &ray) = 0;
54
55        /** Post processes view cells givemŽa number of rays.
56        */
57        virtual int PostProcess(const ObjectContainer &objects,
58                                                        const RayContainer &rays) = 0;
59
60        /** Show visualization of the view cells.
61        */
62        virtual void Visualize(const ObjectContainer &objects,
63                                                   const RayContainer &sampleRays) = 0;
64
65        /** type of the view cell container.
66        */
67        virtual int GetType() const = 0;
68
69        /** Simulates rendering with the given view cell partition.
70                @returns render time statistics
71        */
72        SimulationStatistics SimulateRendering() const;
73
74        /** Load the input viewcells. The input viewcells should be given as a collection
75                of meshes. Each mesh is assume to form a bounded polyhedron defining the interior of
76                the viewcell. The method then builds a BSP tree of these view cells.
77               
78                @param filename file to load
79                @return true on success
80    */
81    bool LoadViewCells(const string filename);
82
83        /** Constructs view cell from base triangle. The ViewCell is extruded along the normal vector.
84                @param the base triangle
85                @param the height of the newly created view cell
86        */
87        ViewCell *ExtrudeViewCell(const Triangle3 &baseTri, const float height) const;
88
89        /** Merges two view cells.
90                @note the piercing rays of the front and back will be ordered   
91                @returns new view cell based on the merging.
92        */
93        ViewCell *Merge(ViewCell &front, ViewCell &back) const;
94       
95        /** Generates view cell of type specified by this manager
96        */
97        virtual ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
98
99        /** Adds a new view cell to the list of predefined view cells.
100        */
101        void AddViewCell(ViewCell *viewCell);
102
103        /** Derive view cells from objects.
104        */
105        void DeriveViewCells(const ObjectContainer &objects,
106                                                 ViewCellContainer &viewCells,
107                                                 const int maxViewCells) const;
108
109        /** Sets maximal number of samples used for the
110                construction of the view cells.
111        */
112        void SetVisualizationSamples(const int visSamples);
113
114        /** Sets maximal number of samples used for the visualization of the view cells.
115        */
116        void SetConstructionSamples(const int constructionSamples);
117
118        /** Sets maximal number of samples used for the post processing of the view cells.
119        */
120        void SetPostProcessSamples(const int postProcessingSamples);
121
122        /** See set.
123        */
124        int GetVisualizationSamples() const;
125
126        /** See set.
127        */
128        int GetConstructionSamples() const;
129
130        /** See set.
131        */
132        int GetPostProcessSamples() const;
133
134        /** Returns true if view cells wer already constructed.
135        */
136        virtual bool ViewCellsConstructed() const = 0;
137       
138protected:
139        /** Adds sample constributions to the view cell PVS.
140                @returns number of sample contributions
141        */
142        virtual int AddSampleContributions(const Ray &ray,
143                                                                           Intersectable *sObject,
144                                                                           Intersectable *tObject) = 0;
145
146        /** Initialises the render time simulator.
147        */
148        void InitRenderSimulator();
149        /////////////////////
150
151       
152        /// the view cell corresponding to unbounded space
153        ViewCell *mUnbounded;
154
155        /// Simulates rendering
156        RenderSimulator *mRenderSimulator;
157
158        /// Loaded view cells
159        ViewCellContainer mViewCells;
160
161        /// maximum number of samples taken for construction of the view cells
162        int mConstructionSamples;
163        int mPostProcessSamples;
164        int mVisualizationSamples;
165};
166
167/**
168        Manages different higher order operations on the view cells.
169*/
170class BspViewCellsManager: public ViewCellsManager
171{
172
173public:
174
175        BspViewCellsManager(BspTree *tree, int constructionSamples);
176
177        int Construct(const ObjectContainer &objects,
178                                  const VssRayContainer &rays,
179                                  AxisAlignedBox3 *sceneBbox);
180
181        int CastRay(const Ray &rays);
182
183        int PostProcess(const ObjectContainer &objects,
184                                        const RayContainer &rays);
185
186        void Visualize(const ObjectContainer &objects,
187                                   const RayContainer &sampleRays);
188
189        int GetType() const;
190       
191        /** Generates view cell of type specified by this manager
192        */
193        ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
194
195        bool ViewCellsConstructed() const;
196
197protected:
198
199        int     AddSampleContributions(const Ray &ray, Intersectable *sObject, Intersectable *tObject);
200
201        /// the BSP tree.
202        BspTree *mBspTree;
203
204
205private:
206
207
208        /** Exports visualization of the BSP splits.
209        */
210        void ExportSplits(const ObjectContainer &objects, const RayContainer &sampleRays);
211
212        /** Exports visualization of the BSP PVS.
213        */
214        void ExportBspPvs(const ObjectContainer &objects, const RayContainer &sampleRays);
215
216};
217
218/**
219        Manages different higher order operations on the KD type view cells.
220*/
221class KdViewCellsManager: public ViewCellsManager
222{
223
224public:
225
226        KdViewCellsManager(KdTree *tree);
227
228        int Construct(const ObjectContainer &objects,
229                                  const VssRayContainer &rays,
230                                  AxisAlignedBox3 *sceneBbox);
231
232        int CastRay(const Ray &ray);
233
234        int PostProcess(const ObjectContainer &objects,
235                                        const RayContainer &rays);
236
237        void Visualize(const ObjectContainer &objects,
238                                   const RayContainer &sampleRays);
239
240        int GetType() const;
241
242        bool ViewCellsConstructed() const;
243
244
245protected:
246
247         KdNode *GetNodeForPvs(KdLeaf *leaf);
248
249         int AddSampleContributions(const Ray &ray, Intersectable *sObject, Intersectable *tObject);
250
251        /// the BSP tree.
252        KdTree *mKdTree;
253
254        /// depth of the KD tree nodes with represent the view cells
255        int mKdPvsDepth;
256};
257
258/**
259        Manages different higher order operations on the view cells
260        for vsp kd tree view cells.
261*/
262class VspKdViewCellsManager: public ViewCellsManager
263{
264
265public:
266
267        VspKdViewCellsManager(VspKdTree *vspKdTree, int constructionSamples);
268
269        int Construct(const ObjectContainer &objects,
270                                  const VssRayContainer &rays,
271                                  AxisAlignedBox3 *sceneBbox);
272
273        int CastRay(const Ray &rays);
274
275        int PostProcess(const ObjectContainer &objects,
276                                        const RayContainer &rays);
277
278        void Visualize(const ObjectContainer &objects,
279                                   const RayContainer &sampleRays);
280
281        int GetType() const;
282       
283        bool ViewCellsConstructed() const;
284
285
286protected:
287
288        int     AddSampleContributions(const Ray &ray, Intersectable *sObject, Intersectable *tObject);
289
290        /// the BSP tree.
291        VspKdTree *mVspKdTree;
292};
293
294
295#endif
Note: See TracBrowser for help on using the repository browser.