[372] | 1 | #ifndef _Preprocessor_H__
|
---|
| 2 | #define _Preprocessor_H__
|
---|
| 3 |
|
---|
| 4 | #include <string>
|
---|
| 5 | using namespace std;
|
---|
| 6 | #include "Containers.h"
|
---|
| 7 | #include "Mesh.h"
|
---|
| 8 | #include "KdTree.h"
|
---|
| 9 |
|
---|
[492] | 10 |
|
---|
[1520] | 11 |
|
---|
[860] | 12 | namespace GtpVisibilityPreprocessor {
|
---|
| 13 |
|
---|
[409] | 14 | class RenderSimulator;
|
---|
[372] | 15 | class SceneGraph;
|
---|
[429] | 16 | class Exporter;
|
---|
[439] | 17 | class ViewCellsManager;
|
---|
[445] | 18 | class BspTree;
|
---|
[1006] | 19 | class VspOspTree;
|
---|
[445] | 20 | class VspBspTree;
|
---|
[468] | 21 | class RenderSimulator;
|
---|
[490] | 22 | struct VssRayContainer;
|
---|
[1020] | 23 | class SamplingStrategy;
|
---|
[496] | 24 | class GlRendererBuffer;
|
---|
[1022] | 25 | class VspTree;
|
---|
[1279] | 26 | class HierarchyManager;
|
---|
[1264] | 27 | class BvHierarchy;
|
---|
[1221] | 28 | class Intersectable;
|
---|
[1287] | 29 | class VssRay;
|
---|
[1520] | 30 | class RayCaster;
|
---|
[490] | 31 |
|
---|
[1520] | 32 |
|
---|
[372] | 33 | /** Namespace for the external visibility preprocessor
|
---|
| 34 |
|
---|
| 35 | This namespace includes all classes which are created by the VUT (Vienna University
|
---|
| 36 | of Technology) for the External Visibility Preprocessor of the GTP (GameTools Project)
|
---|
| 37 | (www.gametools.org).
|
---|
| 38 | */
|
---|
| 39 |
|
---|
[1145] | 40 | /** Main class of the visibility preprocessor. Responsible for loading and
|
---|
| 41 | saving of the input and output files. Initiates construction of the kD-tree,
|
---|
| 42 | viewcell loading/generation and the visibility computation itself.
|
---|
| 43 | */
|
---|
[1521] | 44 | class Preprocessor
|
---|
[1145] | 45 | {
|
---|
[1520] | 46 | friend class RayCaster;
|
---|
| 47 | friend class IntelRayCaster;
|
---|
| 48 | friend class InternalRayCaster;
|
---|
[1564] | 49 |
|
---|
[372] | 50 | public:
|
---|
| 51 | /** Default constructor initialising e.g., KD tree and BSP tree.
|
---|
| 52 | */
|
---|
| 53 | Preprocessor();
|
---|
| 54 |
|
---|
[1520] | 55 | virtual ~Preprocessor();
|
---|
[372] | 56 |
|
---|
[1564] | 57 | /** Load the input scene.
|
---|
| 58 | @param filename file to load
|
---|
| 59 | @return true on success
|
---|
| 60 | */
|
---|
| 61 | virtual bool LoadScene(const string filename);
|
---|
[372] | 62 |
|
---|
[1564] | 63 | /** Export all preprocessed data in a XML format understandable by the
|
---|
| 64 | PreprocessingInterface of the GtpVisibilityPreprocessor Module.
|
---|
| 65 | The file can be compressed depending on the environement settings.
|
---|
| 66 | @return true on successful export
|
---|
| 67 | */
|
---|
| 68 | virtual bool ExportPreprocessedData(const string filename);
|
---|
[871] | 69 |
|
---|
[1564] | 70 | /** Build the KdTree of currently loaded occluders/occludees/viewcells. The construction
|
---|
| 71 | is driven by the environment settings, which also sais which of the three types of
|
---|
| 72 | entities should be used to drive the heuristical construction (only occluders by default)
|
---|
| 73 | */
|
---|
| 74 | virtual bool BuildKdTree();
|
---|
[871] | 75 |
|
---|
[1564] | 76 | /** Compute visibility method. This method has to be reimplemented by the actual
|
---|
| 77 | Preprocessor implementation (e.g. SamplingPreprocessor, ExactPreprocessor,
|
---|
| 78 | GlobalSamplingpreprocessor)
|
---|
| 79 | */
|
---|
| 80 | virtual bool ComputeVisibility() = 0;
|
---|
[1292] | 81 |
|
---|
[1564] | 82 | /** Post Process the computed visibility. By default applys the visibility filter
|
---|
| 83 | (if specified in the environment and export the preprocessed data */
|
---|
| 84 | virtual bool PostProcessVisibility();
|
---|
[1292] | 85 |
|
---|
[1564] | 86 | /** View cells are either loaded or prepared for generation, according to the chosen environment
|
---|
| 87 | object. Important evironment options are, e.g, the view cell type.
|
---|
| 88 | Should be done after scene loading (i.e., some options are based on scene type).
|
---|
| 89 | */
|
---|
| 90 | bool PrepareViewCells();
|
---|
[1020] | 91 |
|
---|
[1564] | 92 | /** Construct viewcells from the scratch
|
---|
| 93 | */
|
---|
| 94 | bool ConstructViewCells();
|
---|
| 95 |
|
---|
| 96 | /** Returns the specified sample strategy, NULL if no valid strategy.
|
---|
| 97 | */
|
---|
| 98 | SamplingStrategy *GenerateSamplingStrategy(const int strategyId) const;
|
---|
| 99 |
|
---|
| 100 | /** Export preprocessor data.
|
---|
| 101 | */
|
---|
| 102 | bool Export(
|
---|
[1521] | 103 | const string filename,
|
---|
| 104 | const bool scene,
|
---|
[1545] | 105 | const bool kdtree);
|
---|
[372] | 106 |
|
---|
[1564] | 107 | virtual void KdTreeStatistics(ostream &s);
|
---|
| 108 | virtual void BspTreeStatistics(ostream &s);
|
---|
[490] | 109 |
|
---|
[1564] | 110 | /** Loads samples from file.
|
---|
| 111 | @param samples returns the stored sample rays
|
---|
| 112 | @param objects needed to associate the objects ids
|
---|
| 113 | @returns true if samples were loaded successfully
|
---|
| 114 | */
|
---|
| 115 | bool LoadSamples(VssRayContainer &samples,
|
---|
| 116 | ObjectContainer &objects) const;
|
---|
[508] | 117 |
|
---|
[1564] | 118 | /** Exports samples to file.
|
---|
| 119 | @returns true if samples were written successfully
|
---|
| 120 | */
|
---|
| 121 | bool ExportSamples(const VssRayContainer &samples) const;
|
---|
[1197] | 122 |
|
---|
[1564] | 123 | bool LoadKdTree(const string filename);
|
---|
| 124 | bool ExportKdTree(const string filename);
|
---|
[1381] | 125 |
|
---|
[1564] | 126 | virtual bool
|
---|
| 127 | GenerateRays(
|
---|
| 128 | const int number,
|
---|
| 129 | const int raysType,
|
---|
| 130 | SimpleRayContainer &rays
|
---|
| 131 | );
|
---|
[573] | 132 |
|
---|
[1564] | 133 | bool GenerateRayBundle(
|
---|
| 134 | SimpleRayContainer &rayBundle,
|
---|
| 135 | const SimpleRay &mainRay,
|
---|
| 136 | const int number,
|
---|
| 137 | const int shuffleType) const;
|
---|
[1221] | 138 |
|
---|
[1564] | 139 | virtual void CastRays(SimpleRayContainer &rays,
|
---|
| 140 | VssRayContainer &vssRays,
|
---|
| 141 | const bool castDoubleRays,
|
---|
| 142 | const bool pruneInvalidRays = true);
|
---|
[1221] | 143 |
|
---|
[1564] | 144 | /** Returns a view cells manager of the given name.
|
---|
| 145 | */
|
---|
| 146 | ViewCellsManager *CreateViewCellsManager(const char *name);
|
---|
| 147 | /** Returns a hierarchy manager of the given name.
|
---|
| 148 | */
|
---|
| 149 | HierarchyManager *CreateHierarchyManager(const char *name);
|
---|
[1221] | 150 |
|
---|
[1564] | 151 | GlRendererBuffer *GetRenderer();
|
---|
[492] | 152 |
|
---|
[1564] | 153 | bool InitRayCast(const string externKdTree, const string internKdTree);
|
---|
[409] | 154 |
|
---|
[429] | 155 |
|
---|
[1564] | 156 | ////////////////////////////////////////////////
|
---|
[538] | 157 |
|
---|
[1564] | 158 | /// scene graph loaded from file
|
---|
| 159 | SceneGraph *mSceneGraph;
|
---|
[599] | 160 |
|
---|
[1564] | 161 | /// raw array of objects
|
---|
| 162 | ObjectContainer mObjects;
|
---|
[658] | 163 |
|
---|
[1564] | 164 | /// kD-tree organizing the scene graph (occluders + occludees) + viewcells
|
---|
| 165 | KdTree *mKdTree;
|
---|
| 166 | /// View space partition bsp tree
|
---|
| 167 | VspBspTree *mVspBspTree;
|
---|
| 168 | /// Hierarchy manager handling view space and object space partition
|
---|
| 169 | HierarchyManager *mHierarchyManager;
|
---|
| 170 | /// BSP tree representing the viewcells
|
---|
| 171 | BspTree *mBspTree;
|
---|
[878] | 172 |
|
---|
[1564] | 173 | /// list of all loaded occluders
|
---|
| 174 | ObjectContainer mOccluders;
|
---|
| 175 | /// list of all loaded occludees
|
---|
| 176 | ObjectContainer mOccludees;
|
---|
[1221] | 177 |
|
---|
[1251] | 178 |
|
---|
[1564] | 179 | ViewCellsManager *mViewCellsManager;
|
---|
| 180 |
|
---|
| 181 | /// greedy optimized hierarchy for both objects and view cells
|
---|
| 182 | VspOspTree *mVspOspTree;
|
---|
| 183 |
|
---|
| 184 | bool mUseGlRenderer;
|
---|
| 185 | bool mUseGlDebugger;
|
---|
| 186 |
|
---|
| 187 | bool mLoadViewCells;
|
---|
| 188 |
|
---|
| 189 | bool mDetectEmptyViewSpace;
|
---|
| 190 |
|
---|
| 191 | bool mQuitOnFinish;
|
---|
| 192 | bool mLoadMeshes;
|
---|
| 193 | bool mComputeVisibility;
|
---|
| 194 |
|
---|
| 195 | bool mExportVisibility;
|
---|
| 196 | string mVisibilityFileName;
|
---|
| 197 |
|
---|
| 198 | bool mApplyVisibilityFilter;
|
---|
| 199 | bool mApplyVisibilitySpatialFilter;
|
---|
| 200 |
|
---|
| 201 | float mVisibilityFilterWidth;
|
---|
| 202 |
|
---|
| 203 | int mPass;
|
---|
[1613] | 204 |
|
---|
| 205 | bool mDelayVisibilityComputation;
|
---|
| 206 | bool mStopComputation;
|
---|
| 207 |
|
---|
[492] | 208 | protected:
|
---|
| 209 |
|
---|
[1658] | 210 | bool LoadBinaryObj(const string filename,
|
---|
| 211 | SceneGraphNode *root,
|
---|
| 212 | vector<FaceParentInfo> *parents);
|
---|
| 213 |
|
---|
| 214 | bool ExportBinaryObj(const string filename, SceneGraphNode *root);
|
---|
| 215 |
|
---|
| 216 |
|
---|
[1520] | 217 | void SetupRay(Ray &ray, const Vector3 &point, const Vector3 &direction) const;
|
---|
[1251] | 218 |
|
---|
[1520] | 219 | void EvalPvsStat();
|
---|
[492] | 220 |
|
---|
[1520] | 221 | /////////////////////////
|
---|
| 222 |
|
---|
[1564] | 223 | RayCaster *mRayCaster;
|
---|
| 224 | /// samples used for construction of the BSP view cells tree.
|
---|
| 225 | int mBspConstructionSamples;
|
---|
| 226 | /// samples used for construction of the VSP OSP tree.
|
---|
| 227 | int mVspOspConstructionSamples;
|
---|
| 228 | /** Simulates rendering of the scene.
|
---|
| 229 | */
|
---|
| 230 | RenderSimulator *mRenderSimulator;
|
---|
[1520] | 231 |
|
---|
[1564] | 232 | vector<FaceParentInfo> mFaceParents;
|
---|
[492] | 233 |
|
---|
[1564] | 234 | GlRendererBuffer *renderer;
|
---|
| 235 |
|
---|
| 236 |
|
---|
[372] | 237 | };
|
---|
| 238 |
|
---|
| 239 |
|
---|
[860] | 240 | }
|
---|
| 241 |
|
---|
[372] | 242 | #endif
|
---|