#ifndef _ViewCellsManager_H__ #define _ViewCellsManager_H__ #include "Ray.h" #include "VssRay.h" #include "Containers.h" class ViewCell; class Intersectable; class RenderSimulator; class Mesh; struct Triangle3; class SimulationStatistics; class BspTree; class KdTree; class VspKdTree; class VspBspTree; class KdNode; class KdLeaf; class VspKdTree; class AxisAlignedBox3; /** Manages different higher order operations on the view cells. */ class ViewCellsManager { public: /// view cell container types enum {BSP, KD, VSP_KD, VSP_BSP}; /** Constructor taking the maximal number of samples used for construction */ ViewCellsManager(const int constructionSamples); ViewCellsManager(); ~ViewCellsManager(); /** Constructs view cell container with a given number of samples. */ virtual int Construct(const ObjectContainer &objects, const VssRayContainer &rays, AxisAlignedBox3 *sceneBbox = NULL) = 0; /** Casts bundle of rays to the view cells and stores contributions in PVS. */ int CastRays(const RayContainer &rays); /** Casts ray to the view cells and stores contributions in PVS. */ virtual int CastRay(const Ray &ray) = 0; /** Post processes view cells givem´a number of rays. */ virtual int PostProcess(const ObjectContainer &objects, const RayContainer &rays) = 0; /** Show visualization of the view cells. */ virtual void Visualize(const ObjectContainer &objects, const RayContainer &sampleRays) = 0; /** type of the view cell container. */ virtual int GetType() const = 0; /** Simulates rendering with the given view cell partition. @returns render time statistics */ SimulationStatistics SimulateRendering() const; /** Load the input viewcells. The input viewcells should be given as a collection of meshes. Each mesh is assume to form a bounded polyhedron defining the interior of the viewcell. The method then builds a BSP tree of these view cells. @param filename file to load @return true on success */ bool LoadViewCells(const string filename); /** Constructs view cell from base triangle. The ViewCell is extruded along the normal vector. @param the base triangle @param the height of the newly created view cell */ ViewCell *ExtrudeViewCell(const Triangle3 &baseTri, const float height) const; /** Merges two view cells. @note the piercing rays of the front and back will be ordered @returns new view cell based on the merging. */ ViewCell *Merge(ViewCell &front, ViewCell &back) const; /** Generates view cell of type specified by this manager */ virtual ViewCell *GenerateViewCell(Mesh *mesh = NULL) const; /** Adds a new view cell to the list of predefined view cells. */ void AddViewCell(ViewCell *viewCell); /** Derive view cells from objects. */ void DeriveViewCells(const ObjectContainer &objects, ViewCellContainer &viewCells, const int maxViewCells) const; /** Sets maximal number of samples used for the construction of the view cells. */ void SetVisualizationSamples(const int visSamples); /** Sets maximal number of samples used for the visualization of the view cells. */ void SetConstructionSamples(const int constructionSamples); /** Sets maximal number of samples used for the post processing of the view cells. */ void SetPostProcessSamples(const int postProcessingSamples); /** See set. */ int GetVisualizationSamples() const; /** See set. */ int GetConstructionSamples() const; /** See set. */ int GetPostProcessSamples() const; /** Returns true if view cells wer already constructed. */ virtual bool ViewCellsConstructed() const = 0; protected: /** Adds sample constributions to the view cell PVS. @returns number of sample contributions */ virtual int AddSampleContributions(const Ray &ray, Intersectable *sObject, Intersectable *tObject) = 0; /** Initialises the render time simulator. */ void InitRenderSimulator(); ///////////////////// /// the view cell corresponding to unbounded space ViewCell *mUnbounded; /// Simulates rendering RenderSimulator *mRenderSimulator; /// Loaded view cells ViewCellContainer mViewCells; /// maximum number of samples taken for construction of the view cells int mConstructionSamples; int mPostProcessSamples; int mVisualizationSamples; }; /** Manages different higher order operations on the view cells. */ class BspViewCellsManager: public ViewCellsManager { public: BspViewCellsManager(BspTree *tree, int constructionSamples); int Construct(const ObjectContainer &objects, const VssRayContainer &rays, AxisAlignedBox3 *sceneBbox); int CastRay(const Ray &rays); int PostProcess(const ObjectContainer &objects, const RayContainer &rays); void Visualize(const ObjectContainer &objects, const RayContainer &sampleRays); int GetType() const; /** Generates view cell of type specified by this manager */ ViewCell *GenerateViewCell(Mesh *mesh = NULL) const; bool ViewCellsConstructed() const; protected: int AddSampleContributions(const Ray &ray, Intersectable *sObject, Intersectable *tObject); /// the BSP tree. BspTree *mBspTree; private: /** Exports visualization of the BSP splits. */ void ExportSplits(const ObjectContainer &objects, const RayContainer &sampleRays); /** Exports visualization of the BSP PVS. */ void ExportBspPvs(const ObjectContainer &objects, const RayContainer &sampleRays); }; /** Manages different higher order operations on the KD type view cells. */ class KdViewCellsManager: public ViewCellsManager { public: KdViewCellsManager(KdTree *tree); int Construct(const ObjectContainer &objects, const VssRayContainer &rays, AxisAlignedBox3 *sceneBbox); int CastRay(const Ray &ray); int PostProcess(const ObjectContainer &objects, const RayContainer &rays); void Visualize(const ObjectContainer &objects, const RayContainer &sampleRays); int GetType() const; bool ViewCellsConstructed() const; protected: KdNode *GetNodeForPvs(KdLeaf *leaf); int AddSampleContributions(const Ray &ray, Intersectable *sObject, Intersectable *tObject); /// the BSP tree. KdTree *mKdTree; /// depth of the KD tree nodes with represent the view cells int mKdPvsDepth; }; /** Manages different higher order operations on the view cells for vsp kd tree view cells. */ class VspKdViewCellsManager: public ViewCellsManager { public: VspKdViewCellsManager(VspKdTree *vspKdTree, int constructionSamples); int Construct(const ObjectContainer &objects, const VssRayContainer &rays, AxisAlignedBox3 *sceneBbox); int CastRay(const Ray &rays); int PostProcess(const ObjectContainer &objects, const RayContainer &rays); void Visualize(const ObjectContainer &objects, const RayContainer &sampleRays); int GetType() const; bool ViewCellsConstructed() const; protected: int AddSampleContributions(const Ray &ray, Intersectable *sObject, Intersectable *tObject); /// the BSP tree. VspKdTree *mVspKdTree; }; #endif