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