[372] | 1 | #ifndef _Preprocessor_H__
|
---|
| 2 | #define _Preprocessor_H__
|
---|
| 3 |
|
---|
| 4 | #include <string>
|
---|
[2176] | 5 | //
|
---|
[372] | 6 | #include "Containers.h"
|
---|
| 7 | #include "Mesh.h"
|
---|
| 8 | #include "KdTree.h"
|
---|
[2105] | 9 | #include "SimpleRay.h"
|
---|
[372] | 10 |
|
---|
[2342] | 11 |
|
---|
[860] | 12 | namespace GtpVisibilityPreprocessor {
|
---|
[2342] | 13 |
|
---|
| 14 | class PreprocessorThread;
|
---|
[409] | 15 | class RenderSimulator;
|
---|
[372] | 16 | class SceneGraph;
|
---|
[429] | 17 | class Exporter;
|
---|
[439] | 18 | class ViewCellsManager;
|
---|
[445] | 19 | class BspTree;
|
---|
[1006] | 20 | class VspOspTree;
|
---|
[445] | 21 | class VspBspTree;
|
---|
[468] | 22 | class RenderSimulator;
|
---|
[490] | 23 | struct VssRayContainer;
|
---|
[1020] | 24 | class SamplingStrategy;
|
---|
[496] | 25 | class GlRendererBuffer;
|
---|
[1022] | 26 | class VspTree;
|
---|
[1279] | 27 | class HierarchyManager;
|
---|
[1264] | 28 | class BvHierarchy;
|
---|
[1221] | 29 | class Intersectable;
|
---|
[1287] | 30 | class VssRay;
|
---|
[1520] | 31 | class RayCaster;
|
---|
[1968] | 32 | class GlobalLinesRenderer;
|
---|
[490] | 33 |
|
---|
[1520] | 34 |
|
---|
[372] | 35 | /** Namespace for the external visibility preprocessor
|
---|
| 36 |
|
---|
| 37 | This namespace includes all classes which are created by the VUT (Vienna University
|
---|
| 38 | of Technology) for the External Visibility Preprocessor of the GTP (GameTools Project)
|
---|
| 39 | (www.gametools.org).
|
---|
| 40 | */
|
---|
| 41 |
|
---|
[1145] | 42 | /** Main class of the visibility preprocessor. Responsible for loading and
|
---|
| 43 | saving of the input and output files. Initiates construction of the kD-tree,
|
---|
| 44 | viewcell loading/generation and the visibility computation itself.
|
---|
| 45 | */
|
---|
[1521] | 46 | class Preprocessor
|
---|
[1145] | 47 | {
|
---|
[1520] | 48 | friend class RayCaster;
|
---|
| 49 | friend class IntelRayCaster;
|
---|
| 50 | friend class InternalRayCaster;
|
---|
[1564] | 51 |
|
---|
[372] | 52 | public:
|
---|
| 53 | /** Default constructor initialising e.g., KD tree and BSP tree.
|
---|
| 54 | */
|
---|
| 55 | Preprocessor();
|
---|
| 56 |
|
---|
[1520] | 57 | virtual ~Preprocessor();
|
---|
[372] | 58 |
|
---|
[1564] | 59 | /** Load the input scene.
|
---|
[2187] | 60 | @param filename file to load
|
---|
| 61 | @return true on success
|
---|
[1564] | 62 | */
|
---|
[2342] | 63 | virtual bool LoadScene(const string &filename);
|
---|
[372] | 64 |
|
---|
[1564] | 65 | /** Export all preprocessed data in a XML format understandable by the
|
---|
[2187] | 66 | PreprocessingInterface of the GtpVisibilityPreprocessor Module.
|
---|
| 67 | The file can be compressed depending on the environement settings.
|
---|
| 68 | @return true on successful export
|
---|
[1564] | 69 | */
|
---|
[2342] | 70 | virtual bool ExportPreprocessedData(const string &filename);
|
---|
[871] | 71 |
|
---|
[1564] | 72 | /** Build the KdTree of currently loaded occluders/occludees/viewcells. The construction
|
---|
[2187] | 73 | is driven by the environment settings, which also sais which of the three types of
|
---|
| 74 | entities should be used to drive the heuristical construction (only occluders by default)
|
---|
[1564] | 75 | */
|
---|
| 76 | virtual bool BuildKdTree();
|
---|
[871] | 77 |
|
---|
[1564] | 78 | /** Compute visibility method. This method has to be reimplemented by the actual
|
---|
[2187] | 79 | Preprocessor implementation (e.g. SamplingPreprocessor, ExactPreprocessor,
|
---|
| 80 | GlobalSamplingpreprocessor)
|
---|
[1564] | 81 | */
|
---|
| 82 | virtual bool ComputeVisibility() = 0;
|
---|
[1292] | 83 |
|
---|
[1564] | 84 | /** Post Process the computed visibility. By default applys the visibility filter
|
---|
[2187] | 85 | (if specified in the environment and export the preprocessed data
|
---|
| 86 | */
|
---|
[1564] | 87 | virtual bool PostProcessVisibility();
|
---|
[1292] | 88 |
|
---|
[1564] | 89 | /** View cells are either loaded or prepared for generation, according to the chosen environment
|
---|
[2187] | 90 | object. Important evironment options are, e.g, the view cell type.
|
---|
| 91 | Should be done after scene loading (i.e., some options are based on scene type).
|
---|
[1564] | 92 | */
|
---|
| 93 | bool PrepareViewCells();
|
---|
[1020] | 94 |
|
---|
[1564] | 95 | /** Construct viewcells from the scratch
|
---|
| 96 | */
|
---|
| 97 | bool ConstructViewCells();
|
---|
| 98 |
|
---|
| 99 | /** Returns the specified sample strategy, NULL if no valid strategy.
|
---|
| 100 | */
|
---|
[1884] | 101 | SamplingStrategy *GenerateSamplingStrategy(const int strategyId);
|
---|
[1564] | 102 |
|
---|
| 103 | /** Export preprocessor data.
|
---|
| 104 | */
|
---|
[2342] | 105 | bool Export(const string &filename, const bool scene, 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 | */
|
---|
[2187] | 115 | bool LoadSamples(VssRayContainer &samples, ObjectContainer &objects) const;
|
---|
[508] | 116 |
|
---|
[1564] | 117 | /** Exports samples to file.
|
---|
[2187] | 118 | @returns true if samples were written successfully
|
---|
[1564] | 119 | */
|
---|
| 120 | bool ExportSamples(const VssRayContainer &samples) const;
|
---|
[1197] | 121 |
|
---|
[2342] | 122 | bool LoadKdTree(const string &filename);
|
---|
| 123 | bool ExportKdTree(const string &filename);
|
---|
[1381] | 124 |
|
---|
[1926] | 125 | virtual bool
|
---|
[2001] | 126 | ExportRays(const char *filename,
|
---|
| 127 | const VssRayContainer &vssRays,
|
---|
| 128 | const int number,
|
---|
| 129 | const bool exportScene = false
|
---|
| 130 | );
|
---|
[1926] | 131 |
|
---|
[2048] | 132 | bool ExportRayAnimation(const char *filename,
|
---|
| 133 | const vector<VssRayContainer> &vssRays);
|
---|
[2002] | 134 |
|
---|
[2048] | 135 | virtual int GenerateRays(const int number,
|
---|
| 136 | SamplingStrategy &strategy,
|
---|
| 137 | SimpleRayContainer &rays);
|
---|
[1786] | 138 |
|
---|
[1926] | 139 | virtual int GenerateRays(const int number,
|
---|
[2048] | 140 | const int raysType,
|
---|
| 141 | SimpleRayContainer &rays);
|
---|
[1786] | 142 |
|
---|
| 143 | bool GenerateRayBundle(SimpleRayContainer &rayBundle,
|
---|
[2048] | 144 | const SimpleRay &mainRay,
|
---|
| 145 | const int number,
|
---|
| 146 | const int shuffleType) const;
|
---|
[1786] | 147 |
|
---|
| 148 | virtual void CastRays(SimpleRayContainer &rays,
|
---|
[1932] | 149 | VssRayContainer &vssRays,
|
---|
| 150 | const bool castDoubleRays,
|
---|
[1996] | 151 | const bool pruneInvalidRays = true);
|
---|
[1786] | 152 |
|
---|
[2342] | 153 | virtual void
|
---|
| 154 | CastRaysWithHwGlobalLines(
|
---|
| 155 | SimpleRayContainer &rays,
|
---|
| 156 | VssRayContainer &vssRays,
|
---|
| 157 | const bool castDoubleRays,
|
---|
| 158 | const bool pruneInvalidRays
|
---|
| 159 | );
|
---|
[2076] | 160 |
|
---|
[2187] | 161 | /** Compute pixel error of the current PVS solution by sampling given number of viewpoints.
|
---|
[2048] | 162 | */
|
---|
[1958] | 163 | virtual void ComputeRenderError();
|
---|
[1931] | 164 |
|
---|
[1564] | 165 | /** Returns a view cells manager of the given name.
|
---|
| 166 | */
|
---|
| 167 | ViewCellsManager *CreateViewCellsManager(const char *name);
|
---|
[1221] | 168 |
|
---|
[1564] | 169 | GlRendererBuffer *GetRenderer();
|
---|
[492] | 170 |
|
---|
[2342] | 171 | bool InitRayCast(const string &externKdTree, const string &internKdTree);
|
---|
[409] | 172 |
|
---|
[2342] | 173 | bool LoadInternKdTree(const string &internKdTree);
|
---|
[2003] | 174 |
|
---|
[2342] | 175 | bool ExportObj(const string &filename, const ObjectContainer &objects);
|
---|
[429] | 176 |
|
---|
[1786] | 177 | Intersectable *GetParentObject(const int index) const;
|
---|
[1926] | 178 | Vector3 GetParentNormal(const int index) const;
|
---|
| 179 |
|
---|
| 180 | /** Sets a Preprocessor thread.
|
---|
| 181 | */
|
---|
| 182 | void SetThread(PreprocessorThread *t);
|
---|
| 183 |
|
---|
| 184 | /** Returns a Preprocessor thread.
|
---|
| 185 | */
|
---|
| 186 | PreprocessorThread *GetThread() const;
|
---|
| 187 |
|
---|
[1958] | 188 | Intersectable *GetObjectById(const int id);
|
---|
[1926] | 189 |
|
---|
[1968] | 190 | void PrepareHwGlobalLines();
|
---|
[2048] | 191 |
|
---|
| 192 | virtual void DeterminePvsObjects(VssRayContainer &rays);
|
---|
| 193 |
|
---|
[2115] | 194 | static bool LoadObjects(const string &filename,
|
---|
[2342] | 195 | ObjectContainer &pvsObjects,
|
---|
[2115] | 196 | const ObjectContainer &preprocessorObject);
|
---|
[2048] | 197 |
|
---|
[538] | 198 |
|
---|
[2342] | 199 | /////////////////////////
|
---|
| 200 |
|
---|
[1564] | 201 | /// scene graph loaded from file
|
---|
| 202 | SceneGraph *mSceneGraph;
|
---|
[599] | 203 |
|
---|
[1564] | 204 | /// raw array of objects
|
---|
| 205 | ObjectContainer mObjects;
|
---|
[658] | 206 |
|
---|
[1564] | 207 | /// kD-tree organizing the scene graph (occluders + occludees) + viewcells
|
---|
| 208 | KdTree *mKdTree;
|
---|
| 209 | /// View space partition bsp tree
|
---|
| 210 | VspBspTree *mVspBspTree;
|
---|
| 211 | /// BSP tree representing the viewcells
|
---|
| 212 | BspTree *mBspTree;
|
---|
[878] | 213 |
|
---|
[1564] | 214 | /// list of all loaded occluders
|
---|
| 215 | ObjectContainer mOccluders;
|
---|
| 216 | /// list of all loaded occludees
|
---|
| 217 | ObjectContainer mOccludees;
|
---|
[1221] | 218 |
|
---|
[1251] | 219 |
|
---|
[1564] | 220 | ViewCellsManager *mViewCellsManager;
|
---|
| 221 |
|
---|
| 222 | /// greedy optimized hierarchy for both objects and view cells
|
---|
| 223 | VspOspTree *mVspOspTree;
|
---|
| 224 |
|
---|
| 225 | bool mUseGlRenderer;
|
---|
| 226 | bool mUseGlDebugger;
|
---|
[2342] | 227 |
|
---|
[2187] | 228 | bool mUseHwGlobalLines;
|
---|
[1564] | 229 | bool mLoadViewCells;
|
---|
| 230 |
|
---|
| 231 | bool mDetectEmptyViewSpace;
|
---|
| 232 |
|
---|
| 233 | bool mQuitOnFinish;
|
---|
| 234 | bool mLoadMeshes;
|
---|
| 235 | bool mComputeVisibility;
|
---|
| 236 |
|
---|
| 237 | bool mExportVisibility;
|
---|
| 238 | string mVisibilityFileName;
|
---|
| 239 |
|
---|
| 240 | bool mApplyVisibilityFilter;
|
---|
| 241 | bool mApplyVisibilitySpatialFilter;
|
---|
| 242 |
|
---|
| 243 | float mVisibilityFilterWidth;
|
---|
| 244 |
|
---|
| 245 | int mPass;
|
---|
[2342] | 246 |
|
---|
[1723] | 247 | bool mStopComputation;
|
---|
[2342] | 248 |
|
---|
[1695] | 249 | bool mExportObj;
|
---|
| 250 |
|
---|
[1926] | 251 | bool mExportRays;
|
---|
[2008] | 252 | bool mExportAnimation;
|
---|
[1926] | 253 | int mExportNumRays;
|
---|
[1900] | 254 |
|
---|
[1786] | 255 | ofstream mStats;
|
---|
[1771] | 256 |
|
---|
[1926] | 257 | GlRendererBuffer *renderer;
|
---|
[2342] | 258 |
|
---|
[1966] | 259 | int mTotalSamples;
|
---|
[2046] | 260 | int mTotalTime;
|
---|
[1968] | 261 | int mSamplesPerPass;
|
---|
| 262 | int mSamplesPerEvaluation;
|
---|
[1966] | 263 |
|
---|
[2342] | 264 | RayCaster *mRayCaster;
|
---|
[2076] | 265 |
|
---|
[2187] | 266 |
|
---|
[492] | 267 | protected:
|
---|
| 268 |
|
---|
[2183] | 269 | bool LoadBinaryObj(const std::string &filename,
|
---|
[2342] | 270 | SceneGraphNode *root,
|
---|
[2183] | 271 | std::vector<FaceParentInfo> *parents);
|
---|
[1658] | 272 |
|
---|
[2342] | 273 | bool ExportBinaryObj(const std::string &filename, SceneGraphNode *root);
|
---|
[1658] | 274 |
|
---|
[1520] | 275 | void SetupRay(Ray &ray, const Vector3 &point, const Vector3 &direction) const;
|
---|
[1251] | 276 |
|
---|
[1520] | 277 | void EvalPvsStat();
|
---|
[492] | 278 |
|
---|
[1786] | 279 | virtual void EvalViewCellHistogram();
|
---|
[1771] | 280 |
|
---|
[2342] | 281 |
|
---|
[1520] | 282 | /////////////////////////
|
---|
| 283 |
|
---|
[2017] | 284 | GlobalLinesRenderer *mGlobalLinesRenderer;
|
---|
| 285 |
|
---|
| 286 | /// samples used for construction of the BSP view cells tree.
|
---|
[1564] | 287 | int mBspConstructionSamples;
|
---|
| 288 | /// samples used for construction of the VSP OSP tree.
|
---|
| 289 | int mVspOspConstructionSamples;
|
---|
[1786] | 290 | /// Simulates rendering of the scene.
|
---|
[1564] | 291 | RenderSimulator *mRenderSimulator;
|
---|
[1520] | 292 |
|
---|
[1564] | 293 | vector<FaceParentInfo> mFaceParents;
|
---|
[492] | 294 |
|
---|
[1723] | 295 | /// if box around view space should be used
|
---|
| 296 | bool mUseViewSpaceBox;
|
---|
[1867] | 297 |
|
---|
[1926] | 298 | PreprocessorThread *mThread;
|
---|
[372] | 299 | };
|
---|
| 300 |
|
---|
[2017] | 301 | extern Preprocessor *preprocessor;
|
---|
[372] | 302 |
|
---|
[860] | 303 | }
|
---|
| 304 |
|
---|
[372] | 305 | #endif
|
---|