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