[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 |
|
---|
[1145] | 10 | // matt: remove qt dependencies
|
---|
| 11 | //#include <QObject>
|
---|
[492] | 12 |
|
---|
[860] | 13 | namespace GtpVisibilityPreprocessor {
|
---|
| 14 |
|
---|
[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;
|
---|
| 27 | class OspTree;
|
---|
[1264] | 28 | class BvHierarchy;
|
---|
[1221] | 29 | class Intersectable;
|
---|
[490] | 30 |
|
---|
[372] | 31 | /** Namespace for the external visibility preprocessor
|
---|
| 32 |
|
---|
| 33 | This namespace includes all classes which are created by the VUT (Vienna University
|
---|
| 34 | of Technology) for the External Visibility Preprocessor of the GTP (GameTools Project)
|
---|
| 35 | (www.gametools.org).
|
---|
| 36 | */
|
---|
| 37 |
|
---|
[1145] | 38 | /** Main class of the visibility preprocessor. Responsible for loading and
|
---|
| 39 | saving of the input and output files. Initiates construction of the kD-tree,
|
---|
| 40 | viewcell loading/generation and the visibility computation itself.
|
---|
| 41 | */
|
---|
| 42 | // matt: remove qt dependencies
|
---|
| 43 | class Preprocessor// : public QObject
|
---|
| 44 | {
|
---|
| 45 | //Q_OBJECT
|
---|
[492] | 46 |
|
---|
[372] | 47 | public:
|
---|
| 48 | /** Default constructor initialising e.g., KD tree and BSP tree.
|
---|
| 49 | */
|
---|
| 50 | Preprocessor();
|
---|
| 51 |
|
---|
| 52 | virtual ~Preprocessor();
|
---|
| 53 |
|
---|
| 54 | /** Load the input scene.
|
---|
| 55 | @param filename file to load
|
---|
[1145] | 56 | @return true on success
|
---|
[372] | 57 | */
|
---|
| 58 | virtual bool LoadScene(const string filename);
|
---|
| 59 |
|
---|
| 60 | /** Export all preprocessed data in a XML format understandable by the
|
---|
| 61 | PreprocessingInterface of the GtpVisibilityPreprocessor Module. The file can be compressed depending
|
---|
| 62 | on the environement settings.
|
---|
| 63 | @return true on successful export
|
---|
| 64 | */
|
---|
| 65 | virtual bool ExportPreprocessedData(const string filename);
|
---|
| 66 |
|
---|
| 67 | /** Build the KdTree of currently loaded occluders/occludees/viewcells. The construction
|
---|
| 68 | is driven by the environment settings, which also sais which of the three types of
|
---|
| 69 | entities should be used to drive the heuristical construction (only occluders by default)
|
---|
| 70 | */
|
---|
| 71 | virtual bool BuildKdTree();
|
---|
| 72 |
|
---|
| 73 | /** Compute visibility method. This method has to be reimplemented by the actual
|
---|
| 74 | Preprocessor implementation (e.g. SamplingPreprocessor, ExactPreprocessor,
|
---|
| 75 | GlobalSamplingpreprocessor)
|
---|
| 76 | */
|
---|
| 77 | virtual bool ComputeVisibility() = 0;
|
---|
[871] | 78 |
|
---|
| 79 | /** Post Process the computed visibility. By default applys the visibility filter
|
---|
| 80 | (if specified in the environment and export the preprocessed data */
|
---|
| 81 | virtual bool PostProcessVisibility();
|
---|
| 82 |
|
---|
[439] | 83 | /** View cells are either loaded or prepared for generation, according to the chosen environment
|
---|
| 84 | object. Important evironment options are, e.g, the view cell type.
|
---|
| 85 | Should be done after scene loading (i.e., some options are based on scene type).
|
---|
| 86 | */
|
---|
| 87 | bool PrepareViewCells();
|
---|
[372] | 88 |
|
---|
[1020] | 89 | /** Returns the specified sample strategy, NULL if no valid strategy.
|
---|
| 90 | */
|
---|
| 91 | SamplingStrategy *GenerateSamplingStrategy(const int strategyId) const;
|
---|
| 92 |
|
---|
[372] | 93 | bool
|
---|
| 94 | Export( const string filename,
|
---|
| 95 | const bool scene,
|
---|
| 96 | const bool kdtree,
|
---|
| 97 | const bool bsptree
|
---|
| 98 | );
|
---|
| 99 |
|
---|
| 100 |
|
---|
| 101 | virtual void KdTreeStatistics(ostream &s);
|
---|
| 102 | virtual void BspTreeStatistics(ostream &s);
|
---|
| 103 |
|
---|
[490] | 104 | /** Loads samples from file.
|
---|
| 105 | @param samples returns the stored sample rays
|
---|
| 106 | @param objects needed to associate the objects ids
|
---|
| 107 | @returns true if samples were loaded successfully
|
---|
| 108 | */
|
---|
| 109 | bool LoadSamples(VssRayContainer &samples,
|
---|
| 110 | ObjectContainer &objects) const;
|
---|
| 111 |
|
---|
| 112 | /** Exports samples to file.
|
---|
| 113 | @returns true if samples were written successfully
|
---|
| 114 | */
|
---|
[508] | 115 | bool ExportSamples(const VssRayContainer &samples) const;
|
---|
| 116 |
|
---|
[1197] | 117 | bool LoadKdTree();
|
---|
| 118 | bool ExportKdTree();
|
---|
| 119 |
|
---|
[563] | 120 | /** Get Sample rays of particular type, returns false if this
|
---|
| 121 | type of rays is not supported by the preprocessor
|
---|
| 122 | */
|
---|
| 123 | enum {
|
---|
| 124 | OBJECT_BASED_DISTRIBUTION,
|
---|
| 125 | DIRECTION_BASED_DISTRIBUTION,
|
---|
| 126 | DIRECTION_BOX_BASED_DISTRIBUTION,
|
---|
| 127 | SPATIAL_BOX_BASED_DISTRIBUTION,
|
---|
| 128 | RSS_BASED_DISTRIBUTION,
|
---|
| 129 | RSS_SILHOUETTE_BASED_DISTRIBUTION,
|
---|
[576] | 130 | VSS_BASED_DISTRIBUTION,
|
---|
[1020] | 131 | OBJECT_DIRECTION_BASED_DISTRIBUTION,
|
---|
| 132 | OBJECTS_INTERIOR_DISTRIBUTION
|
---|
[563] | 133 | };
|
---|
| 134 |
|
---|
[1221] | 135 | enum {
|
---|
[1272] | 136 | INTERNAL_RAYCASTER = 0,
|
---|
[1221] | 137 | INTEL_RAYCASTER
|
---|
| 138 | };
|
---|
| 139 |
|
---|
[563] | 140 | virtual bool
|
---|
| 141 | GenerateRays(
|
---|
| 142 | const int number,
|
---|
| 143 | const int raysType,
|
---|
| 144 | SimpleRayContainer &rays
|
---|
| 145 | );
|
---|
| 146 |
|
---|
[573] | 147 | virtual void CastRays(SimpleRayContainer &rays,
|
---|
[1272] | 148 | VssRayContainer &vssRays) {};
|
---|
[573] | 149 |
|
---|
[1022] | 150 | /** Returns a view cells manager with respect to the given name.
|
---|
| 151 | */
|
---|
[575] | 152 | ViewCellsManager *CreateViewCellsManager(const char *name);
|
---|
[1221] | 153 |
|
---|
| 154 | GlRendererBuffer *GetRenderer() { return renderer;}
|
---|
| 155 |
|
---|
| 156 | bool InitRayCast(const string externKdTree);
|
---|
| 157 |
|
---|
[1251] | 158 | int CastRay(
|
---|
| 159 | const Vector3 &viewPoint,
|
---|
| 160 | const Vector3 &direction,
|
---|
| 161 | const float probability,
|
---|
| 162 | VssRayContainer &vssRays,
|
---|
| 163 | const AxisAlignedBox3 &box
|
---|
| 164 | );
|
---|
| 165 |
|
---|
[1221] | 166 | ////////////////////////////////////////////////
|
---|
| 167 |
|
---|
[372] | 168 | /// scene graph loaded from file
|
---|
| 169 | SceneGraph *mSceneGraph;
|
---|
[492] | 170 |
|
---|
| 171 | /// raw array of objects
|
---|
| 172 | ObjectContainer mObjects;
|
---|
[372] | 173 |
|
---|
| 174 | /// kD-tree organizing the scene graph (occluders + occludees) + viewcells
|
---|
| 175 | KdTree *mKdTree;
|
---|
[445] | 176 | /// View space partition bsp tree
|
---|
| 177 | VspBspTree *mVspBspTree;
|
---|
[1022] | 178 | // view space partition tree
|
---|
| 179 | VspTree *mVspTree;
|
---|
| 180 | /// object space partition tree
|
---|
| 181 | OspTree *mOspTree;
|
---|
| 182 | /// BSP tree representing the viewcells
|
---|
| 183 | BspTree *mBspTree;
|
---|
| 184 |
|
---|
[1264] | 185 | BvHierarchy *mBvHierarchy;
|
---|
| 186 |
|
---|
[372] | 187 | /// list of all loaded occluders
|
---|
| 188 | ObjectContainer mOccluders;
|
---|
| 189 | /// list of all loaded occludees
|
---|
| 190 | ObjectContainer mOccludees;
|
---|
[439] | 191 |
|
---|
[1022] | 192 |
|
---|
[439] | 193 | ViewCellsManager *mViewCellsManager;
|
---|
[409] | 194 |
|
---|
[1006] | 195 | /// greedy optimized hierarchy for both objects and view cells
|
---|
| 196 | VspOspTree *mVspOspTree;
|
---|
[429] | 197 |
|
---|
[492] | 198 | bool mUseGlRenderer;
|
---|
[538] | 199 | bool mUseGlDebugger;
|
---|
| 200 |
|
---|
[518] | 201 | bool mLoadViewCells;
|
---|
[534] | 202 |
|
---|
| 203 | bool mDetectEmptyViewSpace;
|
---|
[599] | 204 |
|
---|
| 205 | bool mQuitOnFinish;
|
---|
[658] | 206 | bool mLoadPolygonsAsMeshes;
|
---|
[685] | 207 | bool mComputeVisibility;
|
---|
[658] | 208 |
|
---|
[871] | 209 | bool mExportVisibility;
|
---|
| 210 | string mVisibilityFileName;
|
---|
| 211 |
|
---|
| 212 | bool mApplyVisibilityFilter;
|
---|
[904] | 213 | bool mApplyVisibilitySpatialFilter;
|
---|
[878] | 214 |
|
---|
| 215 | float mVisibilityFilterWidth;
|
---|
[1221] | 216 |
|
---|
| 217 | int GetRayCastMethod() { return mRayCastMethod; }
|
---|
| 218 | void SetRayCastMethod(int rayCastMethod) { mRayCastMethod = rayCastMethod; }
|
---|
| 219 |
|
---|
[1251] | 220 | int mPass;
|
---|
| 221 |
|
---|
[492] | 222 | protected:
|
---|
| 223 |
|
---|
[1251] | 224 | void SetupRay(Ray &ray, const Vector3 &point, const Vector3 &direction);
|
---|
| 225 |
|
---|
| 226 | int CastInternalRay(
|
---|
| 227 | const Vector3 &viewPoint,
|
---|
| 228 | const Vector3 &direction,
|
---|
| 229 | const float probability,
|
---|
| 230 | VssRayContainer &vssRays,
|
---|
| 231 | const AxisAlignedBox3 &box);
|
---|
| 232 |
|
---|
| 233 | int CastIntelDoubleRay(
|
---|
| 234 | const Vector3 &viewPoint,
|
---|
| 235 | const Vector3 &direction,
|
---|
| 236 | const float probability,
|
---|
| 237 | VssRayContainer &vssRays,
|
---|
| 238 | const AxisAlignedBox3 &box);
|
---|
| 239 |
|
---|
| 240 | Intersectable *CastIntelSingleRay(
|
---|
| 241 | const Vector3 &viewPoint,
|
---|
| 242 | const Vector3 &direction,
|
---|
| 243 | Vector3 &tPoint,
|
---|
| 244 | const AxisAlignedBox3 &box);
|
---|
| 245 |
|
---|
[492] | 246 | /////////////////////////
|
---|
| 247 |
|
---|
[1221] | 248 | int mRayCastMethod;
|
---|
[492] | 249 | /// samples used for construction of the BSP view cells tree.
|
---|
| 250 | int mBspConstructionSamples;
|
---|
[1006] | 251 | /// samples used for construction of the VSP OSP tree.
|
---|
| 252 | int mVspOspConstructionSamples;
|
---|
[468] | 253 | /** Simulates rendering of the scene.
|
---|
| 254 | */
|
---|
| 255 | RenderSimulator *mRenderSimulator;
|
---|
[492] | 256 |
|
---|
[1221] | 257 | vector<Intersectable *> mFaceParents;
|
---|
[496] | 258 | GlRendererBuffer *renderer;
|
---|
[1145] | 259 | // matt: remove qt dependencies
|
---|
| 260 | //signals:
|
---|
[492] | 261 | void EvalPvsStat();
|
---|
| 262 |
|
---|
[372] | 263 | };
|
---|
| 264 |
|
---|
[1145] | 265 | //extern Preprocessor *preprocessor;
|
---|
[372] | 266 |
|
---|
[860] | 267 | }
|
---|
| 268 |
|
---|
[372] | 269 | #endif
|
---|