[372] | 1 | #include "SceneGraph.h"
|
---|
| 2 | #include "Exporter.h"
|
---|
| 3 | #include "UnigraphicsParser.h"
|
---|
| 4 | #include "X3dParser.h"
|
---|
| 5 | #include "Preprocessor.h"
|
---|
| 6 | #include "ViewCell.h"
|
---|
| 7 | #include "Environment.h"
|
---|
[439] | 8 | #include "ViewCellsManager.h"
|
---|
[445] | 9 | #include "ViewCellBsp.h"
|
---|
| 10 | #include "VspBspTree.h"
|
---|
[469] | 11 | #include "RenderSimulator.h"
|
---|
[496] | 12 | #include "GlRenderer.h"
|
---|
[749] | 13 | #include "PlyParser.h"
|
---|
[1020] | 14 | #include "SamplingStrategy.h"
|
---|
[1233] | 15 | #include "VspTree.h"
|
---|
| 16 | #include "OspTree.h"
|
---|
[1221] | 17 | #include "ObjParser.h"
|
---|
[1264] | 18 | #include "BvHierarchy.h"
|
---|
[1279] | 19 | #include "HierarchyManager.h"
|
---|
[1287] | 20 | #include "VssRay.h"
|
---|
[1520] | 21 | #include "IntelRayCaster.h"
|
---|
| 22 | #include "InternalRayCaster.h"
|
---|
[1968] | 23 | #include "GlobalLinesRenderer.h"
|
---|
[1264] | 24 |
|
---|
[1287] | 25 |
|
---|
[1292] | 26 | #define DEBUG_RAYCAST 0
|
---|
[1584] | 27 | #define SHOW_RAYCAST_TIMING 1
|
---|
[1292] | 28 |
|
---|
| 29 |
|
---|
[863] | 30 | namespace GtpVisibilityPreprocessor {
|
---|
[860] | 31 |
|
---|
[1867] | 32 | const static bool ADDITIONAL_GEOMETRY_HACK = false;
|
---|
[860] | 33 |
|
---|
[1867] | 34 | Preprocessor *preprocessor = NULL;
|
---|
| 35 |
|
---|
[1001] | 36 | // HACK: Artificially modify scene to watch rendercost changes
|
---|
[750] | 37 | static void AddGeometry(SceneGraph *scene)
|
---|
| 38 | {
|
---|
[1328] | 39 | scene->GetRoot()->UpdateBox();
|
---|
[752] | 40 |
|
---|
[750] | 41 | AxisAlignedBox3 sceneBox = scene->GetBox();
|
---|
| 42 |
|
---|
| 43 | int n = 200;
|
---|
| 44 |
|
---|
[1291] | 45 | if (0)
|
---|
[750] | 46 | {
|
---|
[1291] | 47 | // form grid of boxes
|
---|
| 48 | for (int i = 0; i < n; ++ i)
|
---|
[750] | 49 | {
|
---|
[1291] | 50 | for (int j = 0; j < n; ++ j)
|
---|
| 51 | {
|
---|
| 52 | const Vector3 scale2((float)j * 0.8f / n + 0.1f, 0.05f, (float)i * 0.8f / (float)n + 0.1f);
|
---|
[750] | 53 |
|
---|
[1291] | 54 | const Vector3 pt2 = sceneBox.Min() + scale2 * (sceneBox.Max() - sceneBox.Min());
|
---|
| 55 |
|
---|
| 56 | const Vector3 boxSize = sceneBox.Size() * Vector3(0.0025f, 0.01f, 0.0025f);
|
---|
| 57 | AxisAlignedBox3 box(pt2, pt2 + boxSize);
|
---|
| 58 | Mesh *mesh = CreateMeshFromBox(box);
|
---|
| 59 |
|
---|
| 60 | mesh->Preprocess();
|
---|
| 61 |
|
---|
| 62 | MeshInstance *mi = new MeshInstance(mesh);
|
---|
[1328] | 63 | scene->GetRoot()->mGeometry.push_back(mi);
|
---|
[1291] | 64 | }
|
---|
[750] | 65 | }
|
---|
| 66 |
|
---|
[1291] | 67 | for (int i = 0; i < n; ++ i)
|
---|
[750] | 68 | {
|
---|
[1291] | 69 | for (int j = 0; j < n; ++ j)
|
---|
| 70 | {
|
---|
| 71 | const Vector3 scale2(0.15f, (float)j * 0.8f / n + 0.1f, (float)i * 0.8f / (float)n + 0.1f);
|
---|
| 72 |
|
---|
| 73 | Vector3 pt2 = sceneBox.Min() + scale2 * (sceneBox.Max() - sceneBox.Min());
|
---|
| 74 |
|
---|
| 75 | Vector3 boxSize = sceneBox.Size() * Vector3(0.0025f, 0.01f, 0.0025f);
|
---|
| 76 | AxisAlignedBox3 box(pt2, pt2 + boxSize);
|
---|
| 77 | Mesh *mesh = CreateMeshFromBox(box);
|
---|
| 78 |
|
---|
| 79 | mesh->Preprocess();
|
---|
| 80 |
|
---|
| 81 | MeshInstance *mi = new MeshInstance(mesh);
|
---|
[1328] | 82 | scene->GetRoot()->mGeometry.push_back(mi);
|
---|
[1291] | 83 | }
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | for (int i = 0; i < n; ++ i)
|
---|
| 87 | {
|
---|
| 88 | const Vector3 scale2(2, 0.2f, (float)i * 0.8f / (float)n + 0.1f);
|
---|
| 89 |
|
---|
[750] | 90 | Vector3 pt2 = sceneBox.Min() + scale2 * (sceneBox.Max() - sceneBox.Min());
|
---|
[1291] | 91 | Vector3 boxSize = sceneBox.Size() * Vector3(0.005f, 0.02f, 0.005f);
|
---|
| 92 |
|
---|
| 93 | AxisAlignedBox3 box(pt2 + 0.1f, pt2 + boxSize);
|
---|
[991] | 94 | Mesh *mesh = CreateMeshFromBox(box);
|
---|
[750] | 95 |
|
---|
| 96 | mesh->Preprocess();
|
---|
[1291] | 97 |
|
---|
[750] | 98 | MeshInstance *mi = new MeshInstance(mesh);
|
---|
[1328] | 99 | scene->GetRoot()->mGeometry.push_back(mi);
|
---|
[750] | 100 | }
|
---|
[1291] | 101 |
|
---|
[1328] | 102 | scene->GetRoot()->UpdateBox();
|
---|
[750] | 103 | }
|
---|
| 104 |
|
---|
[840] | 105 | if (1)
|
---|
| 106 | {
|
---|
[1221] | 107 | // plane separating view space regions
|
---|
[1135] | 108 | const Vector3 scale(1.0f, 0.0, 0);
|
---|
[750] | 109 |
|
---|
[840] | 110 | Vector3 pt = sceneBox.Min() + scale * (sceneBox.Max() - sceneBox.Min());
|
---|
[750] | 111 |
|
---|
[840] | 112 | Plane3 cuttingPlane(Vector3(1, 0, 0), pt);
|
---|
| 113 | Mesh *planeMesh = new Mesh();
|
---|
[1291] | 114 |
|
---|
[840] | 115 | Polygon3 *poly = sceneBox.CrossSection(cuttingPlane);
|
---|
| 116 | IncludePolyInMesh(*poly, *planeMesh);
|
---|
[1291] | 117 |
|
---|
[840] | 118 | planeMesh->Preprocess();
|
---|
[1291] | 119 |
|
---|
[840] | 120 | MeshInstance *planeMi = new MeshInstance(planeMesh);
|
---|
[1328] | 121 | scene->GetRoot()->mGeometry.push_back(planeMi);
|
---|
[840] | 122 | }
|
---|
[750] | 123 | }
|
---|
| 124 |
|
---|
| 125 |
|
---|
[372] | 126 | Preprocessor::Preprocessor():
|
---|
| 127 | mKdTree(NULL),
|
---|
[409] | 128 | mBspTree(NULL),
|
---|
[445] | 129 | mVspBspTree(NULL),
|
---|
[1002] | 130 | mViewCellsManager(NULL),
|
---|
[1251] | 131 | mRenderSimulator(NULL),
|
---|
[1279] | 132 | mPass(0),
|
---|
[1520] | 133 | mSceneGraph(NULL),
|
---|
[1613] | 134 | mRayCaster(NULL),
|
---|
[1926] | 135 | mStopComputation(false),
|
---|
[1968] | 136 | mThread(NULL),
|
---|
| 137 | mGlobalLinesRenderer(NULL)
|
---|
[308] | 138 | {
|
---|
[1004] | 139 | Environment::GetSingleton()->GetBoolValue("Preprocessor.useGlRenderer", mUseGlRenderer);
|
---|
[538] | 140 |
|
---|
[840] | 141 | // renderer will be constructed when the scene graph and viewcell manager will be known
|
---|
| 142 | renderer = NULL;
|
---|
[1785] | 143 |
|
---|
[1004] | 144 | Environment::GetSingleton()->GetBoolValue("Preprocessor.useGlDebugger", mUseGlDebugger);
|
---|
[1379] | 145 | Environment::GetSingleton()->GetBoolValue("Preprocessor.loadMeshes", mLoadMeshes);
|
---|
[1004] | 146 | Environment::GetSingleton()->GetBoolValue("Preprocessor.quitOnFinish", mQuitOnFinish);
|
---|
| 147 | Environment::GetSingleton()->GetBoolValue("Preprocessor.computeVisibility", mComputeVisibility);
|
---|
| 148 | Environment::GetSingleton()->GetBoolValue("Preprocessor.detectEmptyViewSpace", mDetectEmptyViewSpace);
|
---|
| 149 | Environment::GetSingleton()->GetBoolValue("Preprocessor.exportVisibility", mExportVisibility );
|
---|
[1520] | 150 |
|
---|
[871] | 151 | char buffer[256];
|
---|
[1004] | 152 | Environment::GetSingleton()->GetStringValue("Preprocessor.visibilityFile", buffer);
|
---|
[871] | 153 | mVisibilityFileName = buffer;
|
---|
[1771] | 154 |
|
---|
| 155 | Environment::GetSingleton()->GetStringValue("Preprocessor.stats", buffer);
|
---|
| 156 | mStats.open(buffer);
|
---|
| 157 |
|
---|
| 158 |
|
---|
[1749] | 159 | Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilityFilter", mApplyVisibilityFilter);
|
---|
[1004] | 160 | Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilitySpatialFilter",
|
---|
[1695] | 161 | mApplyVisibilitySpatialFilter );
|
---|
[1004] | 162 | Environment::GetSingleton()->GetFloatValue("Preprocessor.visibilityFilterWidth", mVisibilityFilterWidth);
|
---|
[878] | 163 |
|
---|
[1695] | 164 | Environment::GetSingleton()->GetBoolValue("Preprocessor.exportObj", mExportObj);
|
---|
| 165 |
|
---|
[1723] | 166 | Environment::GetSingleton()->GetBoolValue("Preprocessor.useViewSpaceBox", mUseViewSpaceBox);
|
---|
| 167 |
|
---|
[1900] | 168 | Environment::GetSingleton()->GetBoolValue("Preprocessor.Export.rays", mExportRays);
|
---|
| 169 | Environment::GetSingleton()->GetIntValue("Preprocessor.Export.numRays", mExportNumRays);
|
---|
| 170 |
|
---|
[1966] | 171 |
|
---|
| 172 | Environment::GetSingleton()->GetIntValue("Preprocessor.samplesPerPass", mSamplesPerPass);
|
---|
| 173 | Environment::GetSingleton()->GetIntValue("Preprocessor.totalSamples", mTotalSamples);
|
---|
| 174 | Environment::GetSingleton()->GetIntValue("Preprocessor.samplesPerEvaluation",
|
---|
| 175 | mSamplesPerEvaluation);
|
---|
| 176 |
|
---|
[1695] | 177 | Debug << "******* Preprocessor Options **********" << endl;
|
---|
[840] | 178 | Debug << "detect empty view space=" << mDetectEmptyViewSpace << endl;
|
---|
[1379] | 179 | Debug << "load meshes: " << mLoadMeshes << endl;
|
---|
[1695] | 180 | Debug << "load meshes: " << mLoadMeshes << endl;
|
---|
| 181 | Debug << "export obj: " << mExportObj << endl;
|
---|
[1723] | 182 | Debug << "use view space box: " << mUseViewSpaceBox << endl;
|
---|
[372] | 183 | }
|
---|
| 184 |
|
---|
| 185 |
|
---|
| 186 | Preprocessor::~Preprocessor()
|
---|
| 187 | {
|
---|
[1291] | 188 | cout << "cleaning up" << endl;
|
---|
[752] | 189 |
|
---|
[1291] | 190 | cout << "Deleting view cells manager ... \n";
|
---|
| 191 | DEL_PTR(mViewCellsManager);
|
---|
| 192 | cout << "done.\n";
|
---|
[752] | 193 |
|
---|
[1291] | 194 | cout << "Deleting bsp tree ... \n";
|
---|
| 195 | DEL_PTR(mBspTree);
|
---|
[1924] | 196 | cout << "done.\n";
|
---|
[752] | 197 |
|
---|
[1924] | 198 | cout << "Deleting kd tree ...\n";
|
---|
[1291] | 199 | DEL_PTR(mKdTree);
|
---|
| 200 | cout << "done.\n";
|
---|
[752] | 201 |
|
---|
[1923] | 202 | cout << "Deleting vspbsp tree ... \n";
|
---|
[1291] | 203 | DEL_PTR(mVspBspTree);
|
---|
| 204 | cout << "done.\n";
|
---|
[1002] | 205 |
|
---|
[1923] | 206 | cout << "Deleting scene graph ... \n";
|
---|
[1291] | 207 | DEL_PTR(mSceneGraph);
|
---|
| 208 | cout << "done.\n";
|
---|
| 209 |
|
---|
| 210 | DEL_PTR(mRenderSimulator);
|
---|
| 211 | DEL_PTR(renderer);
|
---|
[1523] | 212 | DEL_PTR(mRayCaster);
|
---|
[1968] | 213 |
|
---|
| 214 | DEL_PTR(mGlobalLinesRenderer);
|
---|
[372] | 215 | }
|
---|
| 216 |
|
---|
[1521] | 217 |
|
---|
| 218 | GlRendererBuffer *Preprocessor::GetRenderer()
|
---|
| 219 | {
|
---|
| 220 | return renderer;
|
---|
| 221 | }
|
---|
| 222 |
|
---|
| 223 |
|
---|
| 224 | static int SplitFilenames(const string str, vector<string> &filenames)
|
---|
[387] | 225 | {
|
---|
| 226 | int pos = 0;
|
---|
| 227 |
|
---|
| 228 | while(1) {
|
---|
[469] | 229 | int npos = (int)str.find(';', pos);
|
---|
[387] | 230 |
|
---|
| 231 | if (npos < 0 || npos - pos < 1)
|
---|
| 232 | break;
|
---|
| 233 | filenames.push_back(string(str, pos, npos - pos));
|
---|
| 234 | pos = npos + 1;
|
---|
| 235 | }
|
---|
| 236 |
|
---|
| 237 | filenames.push_back(string(str, pos, str.size() - pos));
|
---|
[440] | 238 | return (int)filenames.size();
|
---|
[387] | 239 | }
|
---|
| 240 |
|
---|
[750] | 241 |
|
---|
[1926] | 242 | void Preprocessor::SetThread(PreprocessorThread *t)
|
---|
| 243 | {
|
---|
| 244 | mThread = t;
|
---|
| 245 | }
|
---|
| 246 |
|
---|
| 247 |
|
---|
| 248 | PreprocessorThread *Preprocessor::GetThread() const
|
---|
| 249 | {
|
---|
| 250 | return mThread;
|
---|
| 251 | }
|
---|
| 252 |
|
---|
| 253 |
|
---|
[1655] | 254 | bool Preprocessor::LoadBinaryObj(const string filename,
|
---|
| 255 | SceneGraphNode *root,
|
---|
| 256 | vector<FaceParentInfo> *parents)
|
---|
| 257 | {
|
---|
[1658] | 258 | //ifstream samplesIn(filename, ios::binary);
|
---|
| 259 | igzstream samplesIn(filename.c_str());
|
---|
| 260 |
|
---|
[1655] | 261 | if (!samplesIn.is_open())
|
---|
| 262 | return false;
|
---|
| 263 |
|
---|
[1658] | 264 | cout << "binary obj dump available, loading " << filename.c_str() << endl;
|
---|
[1655] | 265 | // table associating indices with vectors
|
---|
| 266 | map<int, Vector3> hashTable;
|
---|
[1658] | 267 |
|
---|
[1655] | 268 | // table for vertices
|
---|
| 269 | VertexContainer vertices;
|
---|
| 270 | FaceContainer faces;
|
---|
| 271 |
|
---|
[1786] | 272 | if (parents)
|
---|
| 273 | cout << "using face parents" << endl;
|
---|
| 274 | else
|
---|
| 275 | cout << "not using face parents" << endl;
|
---|
| 276 |
|
---|
[1655] | 277 | while (1)
|
---|
| 278 | {
|
---|
| 279 | Triangle3 tri;
|
---|
| 280 |
|
---|
| 281 | samplesIn.read(reinterpret_cast<char *>(tri.mVertices + 0), sizeof(Vector3));
|
---|
| 282 | samplesIn.read(reinterpret_cast<char *>(tri.mVertices + 1), sizeof(Vector3));
|
---|
| 283 | samplesIn.read(reinterpret_cast<char *>(tri.mVertices + 2), sizeof(Vector3));
|
---|
| 284 |
|
---|
| 285 | // end of file reached
|
---|
| 286 | if (samplesIn.eof())
|
---|
| 287 | break;
|
---|
| 288 |
|
---|
| 289 | TriangleIntersectable *obj = new TriangleIntersectable(tri);
|
---|
| 290 | root->mGeometry.push_back(obj);
|
---|
| 291 |
|
---|
| 292 | // matt: we don't really need to keep an additional data structure
|
---|
| 293 | // if working with triangles => remove this
|
---|
| 294 | if (parents)
|
---|
| 295 | {
|
---|
| 296 | FaceParentInfo info(obj, 0);
|
---|
| 297 | parents->push_back(info);
|
---|
| 298 | }
|
---|
| 299 | }
|
---|
| 300 |
|
---|
| 301 | return true;
|
---|
| 302 | }
|
---|
| 303 |
|
---|
| 304 |
|
---|
[1658] | 305 | bool Preprocessor::ExportBinaryObj(const string filename, SceneGraphNode *root)
|
---|
| 306 | {
|
---|
| 307 | //ifstream samplesIn(filename, ios::binary);
|
---|
| 308 | ogzstream samplesOut(filename.c_str());
|
---|
| 309 | if (!samplesOut.is_open())
|
---|
| 310 | return false;
|
---|
| 311 |
|
---|
| 312 | ObjectContainer::const_iterator oit, oit_end = root->mGeometry.end();
|
---|
| 313 |
|
---|
| 314 | for (oit = root->mGeometry.begin(); oit != oit_end; ++ oit)
|
---|
| 315 | {
|
---|
| 316 | Intersectable *obj = *oit;
|
---|
| 317 |
|
---|
| 318 | if (obj->Type() == Intersectable::TRIANGLE_INTERSECTABLE)
|
---|
| 319 | {
|
---|
| 320 | Triangle3 tri = dynamic_cast<TriangleIntersectable *>(obj)->GetItem();
|
---|
| 321 |
|
---|
| 322 | samplesOut.write(reinterpret_cast<char *>(tri.mVertices + 0), sizeof(Vector3));
|
---|
| 323 | samplesOut.write(reinterpret_cast<char *>(tri.mVertices + 1), sizeof(Vector3));
|
---|
| 324 | samplesOut.write(reinterpret_cast<char *>(tri.mVertices + 2), sizeof(Vector3));
|
---|
| 325 | }
|
---|
| 326 | else
|
---|
| 327 | {
|
---|
| 328 | cout << "not implemented intersectable type " << obj->Type() << endl;
|
---|
| 329 | }
|
---|
| 330 | }
|
---|
| 331 |
|
---|
| 332 | return true;
|
---|
| 333 | }
|
---|
| 334 |
|
---|
[1695] | 335 |
|
---|
| 336 | bool Preprocessor::ExportObj(const string filename, const ObjectContainer &objects)
|
---|
| 337 | {
|
---|
| 338 | ofstream samplesOut(filename.c_str());
|
---|
| 339 |
|
---|
| 340 | if (!samplesOut.is_open())
|
---|
| 341 | return false;
|
---|
| 342 |
|
---|
| 343 | ObjectContainer::const_iterator oit, oit_end = objects.end();
|
---|
| 344 |
|
---|
[1713] | 345 | AxisAlignedBox3 bbox = mSceneGraph->GetBox(); bbox.Enlarge(30.0);
|
---|
[1695] | 346 | for (oit = objects.begin(); oit != oit_end; ++ oit)
|
---|
| 347 | {
|
---|
| 348 | Intersectable *obj = *oit;
|
---|
| 349 |
|
---|
| 350 | if (obj->Type() == Intersectable::TRIANGLE_INTERSECTABLE)
|
---|
| 351 | {
|
---|
| 352 | Triangle3 tri = dynamic_cast<TriangleIntersectable *>(obj)->GetItem();
|
---|
[1701] | 353 | //if (bbox.IsInside(tri.mVertices[0]) && bbox.IsInside(tri.mVertices[1]) && bbox.IsInside(tri.mVertices[2]))
|
---|
| 354 | //{
|
---|
[1713] | 355 | samplesOut << "v " << tri.mVertices[0].x << " " << tri.mVertices[0].y << " " << tri.mVertices[0].z << endl;
|
---|
| 356 | samplesOut << "v " << tri.mVertices[1].x << " " << tri.mVertices[1].y << " " << tri.mVertices[1].z << endl;
|
---|
| 357 | samplesOut << "v " << tri.mVertices[2].x << " " << tri.mVertices[2].y << " " << tri.mVertices[2].z << endl;
|
---|
[1701] | 358 | //}
|
---|
[1695] | 359 | }
|
---|
| 360 | else
|
---|
| 361 | {
|
---|
| 362 | cout << "not implemented intersectable type " << obj->Type() << endl;
|
---|
| 363 | }
|
---|
| 364 | }
|
---|
| 365 |
|
---|
| 366 | // write faces
|
---|
| 367 | int i = 1;
|
---|
[1713] | 368 | for (oit = objects.begin(); oit != oit_end; ++ oit)
|
---|
[1695] | 369 | {
|
---|
| 370 | Intersectable *obj = *oit;
|
---|
| 371 | if (obj->Type() == Intersectable::TRIANGLE_INTERSECTABLE)
|
---|
| 372 | {
|
---|
[1713] | 373 | //Triangle3 tri = dynamic_cast<TriangleIntersectable *>(obj)->GetItem();
|
---|
| 374 | //if (bbox.IsInside(tri.mVertices[0]) && bbox.IsInside(tri.mVertices[1]) && bbox.IsInside(tri.mVertices[2]))
|
---|
| 375 | //{
|
---|
| 376 | Triangle3 tri = dynamic_cast<TriangleIntersectable *>(obj)->GetItem();
|
---|
| 377 | samplesOut << "f " << i << " " << i + 1 << " " << i + 2 << endl;
|
---|
| 378 | i += 3;
|
---|
| 379 | //}
|
---|
[1695] | 380 | }
|
---|
| 381 | else
|
---|
| 382 | {
|
---|
| 383 | cout << "not implemented intersectable type " << obj->Type() << endl;
|
---|
| 384 | }
|
---|
| 385 | }
|
---|
| 386 |
|
---|
| 387 | return true;
|
---|
| 388 |
|
---|
| 389 | }
|
---|
| 390 |
|
---|
[1658] | 391 | static string ReplaceSuffix(string filename, string a, string b)
|
---|
| 392 | {
|
---|
| 393 | string result = filename;
|
---|
| 394 |
|
---|
| 395 | int pos = (int)filename.rfind(a, (int)filename.size() - 1);
|
---|
| 396 | if (pos == filename.size() - a.size()) {
|
---|
| 397 | result.replace(pos, a.size(), b);
|
---|
| 398 | }
|
---|
| 399 | return result;
|
---|
| 400 | }
|
---|
| 401 |
|
---|
| 402 |
|
---|
[1786] | 403 | Intersectable *Preprocessor::GetParentObject(const int index) const
|
---|
| 404 | {
|
---|
| 405 | if (index == -1)
|
---|
[1984] | 406 | return NULL;
|
---|
[1786] | 407 |
|
---|
| 408 | if (!mFaceParents.empty())
|
---|
| 409 | {
|
---|
| 410 | if (index >= (int)mFaceParents.size())
|
---|
| 411 | {
|
---|
[1978] | 412 | cerr << "Warning: triangle index out of range! " << index << endl;
|
---|
[1786] | 413 | return NULL;
|
---|
| 414 | }
|
---|
| 415 | else
|
---|
| 416 | {
|
---|
| 417 | return mFaceParents[index].mObject;
|
---|
| 418 | }
|
---|
| 419 | }
|
---|
| 420 | else
|
---|
[1984] | 421 | {
|
---|
| 422 | if (index >= (int)mObjects.size()) {
|
---|
| 423 | cerr<<"Warning: triangle index out of range! "<<index<<endl;
|
---|
| 424 | return NULL;
|
---|
| 425 | }
|
---|
| 426 | else
|
---|
[1786] | 427 | {
|
---|
[1984] | 428 | return mObjects[index];
|
---|
[1786] | 429 | }
|
---|
[1984] | 430 | }
|
---|
[1786] | 431 | }
|
---|
| 432 |
|
---|
| 433 |
|
---|
| 434 | Vector3 Preprocessor::GetParentNormal(const int index) const
|
---|
| 435 | {
|
---|
| 436 | if (!mFaceParents.empty())
|
---|
| 437 | {
|
---|
| 438 | return mFaceParents[index].mObject->GetNormal(mFaceParents[index].mFaceIndex);
|
---|
| 439 | }
|
---|
| 440 | else
|
---|
| 441 | {
|
---|
| 442 | return mObjects[index]->GetNormal(0);
|
---|
| 443 | }
|
---|
| 444 | }
|
---|
| 445 |
|
---|
| 446 |
|
---|
[372] | 447 | bool
|
---|
| 448 | Preprocessor::LoadScene(const string filename)
|
---|
| 449 | {
|
---|
[1655] | 450 | // use leaf nodes of the original spatial hierarchy as occludees
|
---|
[508] | 451 | mSceneGraph = new SceneGraph;
|
---|
[372] | 452 |
|
---|
[508] | 453 | Parser *parser;
|
---|
[387] | 454 | vector<string> filenames;
|
---|
[1404] | 455 | const int files = SplitFilenames(filename, filenames);
|
---|
[712] | 456 | cout << "number of input files: " << files << endl;
|
---|
[387] | 457 | bool result = false;
|
---|
[1695] | 458 | bool isObj = false;
|
---|
[1344] | 459 |
|
---|
| 460 | // root for different files
|
---|
| 461 | mSceneGraph->SetRoot(new SceneGraphNode());
|
---|
| 462 |
|
---|
[1404] | 463 | // intel ray caster can only trace triangles
|
---|
[1520] | 464 | int rayCastMethod;
|
---|
| 465 | Environment::GetSingleton()->GetIntValue("Preprocessor.rayCastMethod", rayCastMethod);
|
---|
[1827] | 466 | vector<FaceParentInfo> *fi =
|
---|
[1867] | 467 | ((rayCastMethod == RayCaster::INTEL_RAYCASTER) && mLoadMeshes) ?
|
---|
| 468 | &mFaceParents : NULL;
|
---|
| 469 |
|
---|
[1658] | 470 | if (files == 1)
|
---|
[1867] | 471 | {
|
---|
[387] | 472 | if (strstr(filename.c_str(), ".x3d"))
|
---|
[1867] | 473 | {
|
---|
[1655] | 474 | parser = new X3dParser;
|
---|
[1658] | 475 |
|
---|
| 476 | result = parser->ParseFile(filename,
|
---|
| 477 | mSceneGraph->GetRoot(),
|
---|
| 478 | mLoadMeshes,
|
---|
| 479 | fi);
|
---|
| 480 | delete parser;
|
---|
[1655] | 481 | }
|
---|
[1658] | 482 | else if (strstr(filename.c_str(), ".ply") || strstr(filename.c_str(), ".plb"))
|
---|
[1655] | 483 | {
|
---|
[1658] | 484 | parser = new PlyParser;
|
---|
[1655] | 485 |
|
---|
[1658] | 486 | result = parser->ParseFile(filename,
|
---|
| 487 | mSceneGraph->GetRoot(),
|
---|
| 488 | mLoadMeshes,
|
---|
| 489 | fi);
|
---|
| 490 | delete parser;
|
---|
[1655] | 491 | }
|
---|
[1658] | 492 | else if (strstr(filename.c_str(), ".obj"))
|
---|
| 493 | {
|
---|
[1695] | 494 | isObj = true;
|
---|
| 495 |
|
---|
[1658] | 496 | // hack: load binary dump
|
---|
| 497 | string binFile = ReplaceSuffix(filename, ".obj", ".bin");
|
---|
[372] | 498 |
|
---|
[1658] | 499 | if (!mLoadMeshes)
|
---|
| 500 | {
|
---|
| 501 | result = LoadBinaryObj(binFile, mSceneGraph->GetRoot(), fi);
|
---|
| 502 | }
|
---|
| 503 |
|
---|
| 504 | if (!result)
|
---|
| 505 | {
|
---|
| 506 | cout << "no binary dump available or loading full meshes, parsing file" << endl;
|
---|
| 507 | parser = new ObjParser;
|
---|
[1404] | 508 |
|
---|
[1658] | 509 | result = parser->ParseFile(filename,
|
---|
[1655] | 510 | mSceneGraph->GetRoot(),
|
---|
| 511 | mLoadMeshes,
|
---|
| 512 | fi);
|
---|
[1658] | 513 |
|
---|
| 514 | // only works for triangles
|
---|
| 515 | if (!mLoadMeshes)
|
---|
| 516 | {
|
---|
| 517 | cout << "exporting binary obj to " << binFile << "... " << endl;
|
---|
| 518 | ExportBinaryObj(binFile, mSceneGraph->GetRoot());
|
---|
| 519 | cout << "finished" << endl;
|
---|
| 520 | }
|
---|
[1655] | 521 |
|
---|
[1658] | 522 | delete parser;
|
---|
| 523 | }
|
---|
[1660] | 524 | else if (0)
|
---|
[1658] | 525 | {
|
---|
| 526 | ExportBinaryObj("../data/test.bin", mSceneGraph->GetRoot());
|
---|
| 527 | }
|
---|
| 528 | }
|
---|
| 529 | else
|
---|
| 530 | {
|
---|
| 531 | parser = new UnigraphicsParser;
|
---|
| 532 | result = parser->ParseFile(filename,
|
---|
| 533 | mSceneGraph->GetRoot(),
|
---|
| 534 | mLoadMeshes,
|
---|
| 535 | fi);
|
---|
| 536 | delete parser;
|
---|
| 537 | }
|
---|
| 538 |
|
---|
| 539 | cout << filename << endl;
|
---|
[1404] | 540 | }
|
---|
[1658] | 541 | else
|
---|
| 542 | {
|
---|
[1404] | 543 | vector<string>::const_iterator fit, fit_end = filenames.end();
|
---|
[1344] | 544 |
|
---|
[1404] | 545 | for (fit = filenames.begin(); fit != fit_end; ++ fit)
|
---|
| 546 | {
|
---|
| 547 | const string filename = *fit;
|
---|
[1328] | 548 |
|
---|
[1404] | 549 | cout << "parsing file " << filename.c_str() << endl;
|
---|
| 550 | if (strstr(filename.c_str(), ".x3d"))
|
---|
| 551 | parser = new X3dParser;
|
---|
| 552 | else
|
---|
| 553 | parser = new UnigraphicsParser;
|
---|
| 554 |
|
---|
| 555 | SceneGraphNode *node = new SceneGraphNode();
|
---|
[1695] | 556 | const bool success =
|
---|
| 557 | parser->ParseFile(filename, node, mLoadMeshes, fi);
|
---|
[1404] | 558 |
|
---|
| 559 | if (success)
|
---|
| 560 | {
|
---|
| 561 | mSceneGraph->GetRoot()->mChildren.push_back(node);
|
---|
| 562 | result = true; // at least one file parsed
|
---|
| 563 | }
|
---|
| 564 |
|
---|
[1713] | 565 | // temporare hack
|
---|
[1701] | 566 | //if (!strstr(filename.c_str(), "plane")) mSceneGraph->GetRoot()->UpdateBox();
|
---|
| 567 |
|
---|
[1404] | 568 | delete parser;
|
---|
[387] | 569 | }
|
---|
| 570 | }
|
---|
[1344] | 571 |
|
---|
[752] | 572 | if (result)
|
---|
[1344] | 573 | {
|
---|
[752] | 574 | // HACK
|
---|
[1020] | 575 | if (ADDITIONAL_GEOMETRY_HACK)
|
---|
| 576 | AddGeometry(mSceneGraph);
|
---|
[1328] | 577 |
|
---|
[1020] | 578 | mSceneGraph->AssignObjectIds();
|
---|
[1344] | 579 |
|
---|
[1020] | 580 | int intersectables, faces;
|
---|
| 581 | mSceneGraph->GetStatistics(intersectables, faces);
|
---|
[1344] | 582 |
|
---|
[1020] | 583 | cout<<filename<<" parsed successfully."<<endl;
|
---|
| 584 | cout<<"#NUM_OBJECTS (Total numner of objects)\n"<<intersectables<<endl;
|
---|
| 585 | cout<<"#NUM_FACES (Total numner of faces)\n"<<faces<<endl;
|
---|
[1701] | 586 |
|
---|
[1697] | 587 | mObjects.reserve(intersectables);
|
---|
[1020] | 588 | mSceneGraph->CollectObjects(&mObjects);
|
---|
[1713] | 589 |
|
---|
| 590 | // temp hack
|
---|
| 591 | //ExportObj("cropped_vienna.obj", mObjects);
|
---|
[1328] | 592 | mSceneGraph->GetRoot()->UpdateBox();
|
---|
[1713] | 593 |
|
---|
| 594 | cout << "finished loading" << endl;
|
---|
[387] | 595 | }
|
---|
[1328] | 596 |
|
---|
[492] | 597 | return result;
|
---|
[372] | 598 | }
|
---|
| 599 |
|
---|
| 600 | bool
|
---|
| 601 | Preprocessor::ExportPreprocessedData(const string filename)
|
---|
| 602 | {
|
---|
[1486] | 603 | mViewCellsManager->ExportViewCells(filename, true, mObjects);
|
---|
| 604 | return true;
|
---|
[372] | 605 | }
|
---|
| 606 |
|
---|
[1486] | 607 |
|
---|
[372] | 608 | bool
|
---|
[871] | 609 | Preprocessor::PostProcessVisibility()
|
---|
| 610 | {
|
---|
| 611 |
|
---|
[904] | 612 | if (mApplyVisibilityFilter || mApplyVisibilitySpatialFilter) {
|
---|
[997] | 613 | cout<<"Applying visibility filter ...";
|
---|
[1002] | 614 | cout<<"filter width = " << mVisibilityFilterWidth << endl;
|
---|
[904] | 615 |
|
---|
[1002] | 616 | if (!mViewCellsManager)
|
---|
[1199] | 617 | return false;
|
---|
| 618 |
|
---|
[871] | 619 | mViewCellsManager->ApplyFilter(mKdTree,
|
---|
[904] | 620 | mApplyVisibilityFilter ? mVisibilityFilterWidth : -1.0f,
|
---|
| 621 | mApplyVisibilitySpatialFilter ? mVisibilityFilterWidth : -1.0f);
|
---|
[997] | 622 | cout << "done." << endl;
|
---|
[871] | 623 | }
|
---|
| 624 |
|
---|
| 625 | // export the preprocessed information to a file
|
---|
| 626 | if (mExportVisibility)
|
---|
[1486] | 627 | {
|
---|
| 628 | ExportPreprocessedData(mVisibilityFileName);
|
---|
| 629 | }
|
---|
| 630 |
|
---|
[871] | 631 | return true;
|
---|
| 632 | }
|
---|
| 633 |
|
---|
| 634 |
|
---|
| 635 | bool
|
---|
[372] | 636 | Preprocessor::BuildKdTree()
|
---|
| 637 | {
|
---|
| 638 | mKdTree = new KdTree;
|
---|
[1344] | 639 |
|
---|
[372] | 640 | // add mesh instances of the scene graph to the root of the tree
|
---|
| 641 | KdLeaf *root = (KdLeaf *)mKdTree->GetRoot();
|
---|
[1344] | 642 |
|
---|
[372] | 643 | mSceneGraph->CollectObjects(&root->mObjects);
|
---|
[1344] | 644 |
|
---|
[1415] | 645 | const long startTime = GetTime();
|
---|
[1201] | 646 | cout << "building kd tree ... " << endl;
|
---|
[1344] | 647 |
|
---|
[372] | 648 | mKdTree->Construct();
|
---|
[1344] | 649 |
|
---|
[1415] | 650 | cout << "finished kd tree construction in " << TimeDiff(startTime, GetTime()) * 1e-3
|
---|
| 651 | << " secs " << endl;
|
---|
[1344] | 652 |
|
---|
[372] | 653 | return true;
|
---|
| 654 | }
|
---|
| 655 |
|
---|
[1415] | 656 |
|
---|
[372] | 657 | void
|
---|
| 658 | Preprocessor::KdTreeStatistics(ostream &s)
|
---|
| 659 | {
|
---|
| 660 | s<<mKdTree->GetStatistics();
|
---|
| 661 | }
|
---|
| 662 |
|
---|
| 663 | void
|
---|
| 664 | Preprocessor::BspTreeStatistics(ostream &s)
|
---|
| 665 | {
|
---|
| 666 | s << mBspTree->GetStatistics();
|
---|
| 667 | }
|
---|
| 668 |
|
---|
| 669 | bool
|
---|
| 670 | Preprocessor::Export( const string filename,
|
---|
[492] | 671 | const bool scene,
|
---|
[1545] | 672 | const bool kdtree
|
---|
[492] | 673 | )
|
---|
[372] | 674 | {
|
---|
| 675 | Exporter *exporter = Exporter::GetExporter(filename);
|
---|
| 676 |
|
---|
| 677 | if (exporter) {
|
---|
[1545] | 678 | if (2 && scene)
|
---|
[1328] | 679 | exporter->ExportScene(mSceneGraph->GetRoot());
|
---|
[372] | 680 |
|
---|
[1545] | 681 | if (1 && kdtree) {
|
---|
[372] | 682 | exporter->SetWireframe();
|
---|
| 683 | exporter->ExportKdTree(*mKdTree);
|
---|
| 684 | }
|
---|
| 685 |
|
---|
| 686 | delete exporter;
|
---|
| 687 | return true;
|
---|
| 688 | }
|
---|
| 689 |
|
---|
| 690 | return false;
|
---|
| 691 | }
|
---|
[429] | 692 |
|
---|
[508] | 693 |
|
---|
[463] | 694 | bool Preprocessor::PrepareViewCells()
|
---|
| 695 | {
|
---|
[1523] | 696 | ///////
|
---|
[577] | 697 | //-- parse view cells construction method
|
---|
[1563] | 698 |
|
---|
[1004] | 699 | Environment::GetSingleton()->GetBoolValue("ViewCells.loadFromFile", mLoadViewCells);
|
---|
[577] | 700 | char buf[100];
|
---|
[1585] | 701 |
|
---|
[577] | 702 | if (mLoadViewCells)
|
---|
[997] | 703 | {
|
---|
[1740] | 704 | Environment::GetSingleton()->GetStringValue("ViewCells.filename", buf);
|
---|
| 705 | cout << "loading view cells from " << buf << endl<<flush;
|
---|
[1715] | 706 |
|
---|
[1740] | 707 | mViewCellsManager = ViewCellsManager::LoadViewCells(buf, &mObjects, true, NULL);
|
---|
| 708 |
|
---|
| 709 | cout << "view cells loaded." << endl<<flush;
|
---|
| 710 |
|
---|
| 711 | if (!mViewCellsManager)
|
---|
| 712 | {
|
---|
| 713 | return false;
|
---|
| 714 | }
|
---|
[577] | 715 | }
|
---|
| 716 | else
|
---|
| 717 | {
|
---|
[1288] | 718 | // parse type of view cell container
|
---|
[1004] | 719 | Environment::GetSingleton()->GetStringValue("ViewCells.type", buf);
|
---|
[1740] | 720 | mViewCellsManager = CreateViewCellsManager(buf);
|
---|
[1112] | 721 |
|
---|
| 722 | // default view space is the extent of the scene
|
---|
[1723] | 723 | AxisAlignedBox3 viewSpaceBox;
|
---|
[1740] | 724 |
|
---|
[1723] | 725 | if (mUseViewSpaceBox)
|
---|
[1563] | 726 | {
|
---|
[1723] | 727 | viewSpaceBox = mSceneGraph->GetBox();
|
---|
| 728 |
|
---|
[1563] | 729 | // use a small box outside of the scene
|
---|
[1723] | 730 | viewSpaceBox.Scale(Vector3(0.15f, 0.3f, 0.5f));
|
---|
| 731 | //viewSpaceBox.Translate(Vector3(Magnitude(mSceneGraph->GetBox().Size()) * 0.5f, 0, 0));
|
---|
| 732 | viewSpaceBox.Translate(Vector3(Magnitude(mSceneGraph->GetBox().Size()) * 0.3f, 0, 0));
|
---|
| 733 | mViewCellsManager->SetViewSpaceBox(viewSpaceBox);
|
---|
[1563] | 734 | }
|
---|
[1723] | 735 | else
|
---|
| 736 | {
|
---|
| 737 | viewSpaceBox = mSceneGraph->GetBox();
|
---|
| 738 | mViewCellsManager->SetViewSpaceBox(viewSpaceBox);
|
---|
| 739 | }
|
---|
[1545] | 740 |
|
---|
| 741 | bool loadVcGeometry;
|
---|
| 742 | Environment::GetSingleton()->GetBoolValue("ViewCells.loadGeometry", loadVcGeometry);
|
---|
| 743 |
|
---|
| 744 | bool extrudeBaseTriangles;
|
---|
| 745 | Environment::GetSingleton()->GetBoolValue("ViewCells.useBaseTrianglesAsGeometry", extrudeBaseTriangles);
|
---|
| 746 |
|
---|
| 747 | char vcGeomFilename[100];
|
---|
| 748 | Environment::GetSingleton()->GetStringValue("ViewCells.geometryFilename", vcGeomFilename);
|
---|
[1740] | 749 |
|
---|
[1940] | 750 | // create view cells from specified geometry
|
---|
[1627] | 751 | if (loadVcGeometry)
|
---|
[1545] | 752 | {
|
---|
[1627] | 753 | if (mViewCellsManager->GetType() == ViewCellsManager::BSP)
|
---|
[1545] | 754 | {
|
---|
[1627] | 755 | if (!mViewCellsManager->LoadViewCellsGeometry(vcGeomFilename, extrudeBaseTriangles))
|
---|
| 756 | {
|
---|
| 757 | cerr << "loading view cells geometry failed" << endl;
|
---|
| 758 | }
|
---|
[1545] | 759 | }
|
---|
[1627] | 760 | else
|
---|
| 761 | {
|
---|
| 762 | cerr << "loading view cells geometry is not implemented for this manager" << endl;
|
---|
| 763 | }
|
---|
[1545] | 764 | }
|
---|
[577] | 765 | }
|
---|
[1740] | 766 |
|
---|
[1486] | 767 | ////////
|
---|
[1523] | 768 | //-- evaluation of render cost heuristics
|
---|
[1768] | 769 |
|
---|
[473] | 770 | float objRenderCost = 0, vcOverhead = 0, moveSpeed = 0;
|
---|
| 771 |
|
---|
[1004] | 772 | Environment::GetSingleton()->GetFloatValue("Simulation.objRenderCost",objRenderCost);
|
---|
| 773 | Environment::GetSingleton()->GetFloatValue("Simulation.vcOverhead", vcOverhead);
|
---|
| 774 | Environment::GetSingleton()->GetFloatValue("Simulation.moveSpeed", moveSpeed);
|
---|
[1740] | 775 |
|
---|
[473] | 776 | mRenderSimulator =
|
---|
| 777 | new RenderSimulator(mViewCellsManager, objRenderCost, vcOverhead, moveSpeed);
|
---|
[440] | 778 |
|
---|
[480] | 779 | mViewCellsManager->SetRenderer(mRenderSimulator);
|
---|
[1785] | 780 |
|
---|
[1581] | 781 | mViewCellsManager->SetPreprocessor(this);
|
---|
[1940] | 782 |
|
---|
[463] | 783 | return true;
|
---|
[490] | 784 | }
|
---|
| 785 |
|
---|
[1292] | 786 |
|
---|
[1563] | 787 | bool Preprocessor::ConstructViewCells()
|
---|
[1292] | 788 | {
|
---|
[1627] | 789 | // construct view cells using it's own set of samples
|
---|
| 790 | mViewCellsManager->Construct(this);
|
---|
| 791 |
|
---|
| 792 | // visualizations and statistics
|
---|
| 793 | Debug << "finished view cells:" << endl;
|
---|
| 794 | mViewCellsManager->PrintStatistics(Debug);
|
---|
| 795 |
|
---|
| 796 | return true;
|
---|
[1292] | 797 | }
|
---|
[490] | 798 |
|
---|
[1294] | 799 |
|
---|
[575] | 800 | ViewCellsManager *Preprocessor::CreateViewCellsManager(const char *name)
|
---|
| 801 | {
|
---|
[1264] | 802 | ViewCellsTree *vcTree = new ViewCellsTree;
|
---|
| 803 |
|
---|
[575] | 804 | if (strcmp(name, "kdTree") == 0)
|
---|
| 805 | {
|
---|
[1264] | 806 | mViewCellsManager = new KdViewCellsManager(vcTree, mKdTree);
|
---|
[575] | 807 | }
|
---|
| 808 | else if (strcmp(name, "bspTree") == 0)
|
---|
| 809 | {
|
---|
| 810 | Debug << "view cell type: Bsp" << endl;
|
---|
| 811 |
|
---|
[577] | 812 | mBspTree = new BspTree();
|
---|
[1264] | 813 | mViewCellsManager = new BspViewCellsManager(vcTree, mBspTree);
|
---|
[575] | 814 | }
|
---|
| 815 | else if (strcmp(name, "vspBspTree") == 0)
|
---|
| 816 | {
|
---|
| 817 | Debug << "view cell type: VspBsp" << endl;
|
---|
| 818 |
|
---|
[1004] | 819 | mVspBspTree = new VspBspTree();
|
---|
[1264] | 820 | mViewCellsManager = new VspBspViewCellsManager(vcTree, mVspBspTree);
|
---|
[575] | 821 | }
|
---|
[1006] | 822 | else if (strcmp(name, "vspOspTree") == 0)
|
---|
[575] | 823 | {
|
---|
[1421] | 824 | Debug << "view cell type: VspOsp" << endl;
|
---|
[1288] | 825 | char buf[100];
|
---|
| 826 | Environment::GetSingleton()->GetStringValue("Hierarchy.type", buf);
|
---|
[1022] | 827 |
|
---|
[1740] | 828 | mViewCellsManager = new VspOspViewCellsManager(vcTree, buf);
|
---|
[575] | 829 | }
|
---|
[1421] | 830 | else if (strcmp(name, "sceneDependent") == 0) //TODO
|
---|
[575] | 831 | {
|
---|
[1143] | 832 | Debug << "view cell type: Bsp" << endl;
|
---|
[1421] | 833 |
|
---|
[575] | 834 | mBspTree = new BspTree();
|
---|
[1264] | 835 | mViewCellsManager = new BspViewCellsManager(vcTree, mBspTree);
|
---|
[575] | 836 | }
|
---|
| 837 | else
|
---|
| 838 | {
|
---|
[664] | 839 | cerr << "Wrong view cells type " << name << "!!!" << endl;
|
---|
[575] | 840 | exit(1);
|
---|
| 841 | }
|
---|
| 842 |
|
---|
| 843 | return mViewCellsManager;
|
---|
| 844 | }
|
---|
| 845 |
|
---|
| 846 |
|
---|
[491] | 847 | // use ascii format to store rays
|
---|
| 848 | #define USE_ASCII 0
|
---|
| 849 |
|
---|
| 850 |
|
---|
[1145] | 851 | static inline bool ilt(Intersectable *obj1, Intersectable *obj2)
|
---|
[490] | 852 | {
|
---|
| 853 | return obj1->mId < obj2->mId;
|
---|
| 854 | }
|
---|
| 855 |
|
---|
| 856 |
|
---|
[1414] | 857 | bool Preprocessor::LoadKdTree(const string filename)
|
---|
[1197] | 858 | {
|
---|
[1414] | 859 | mKdTree = new KdTree();
|
---|
[1633] | 860 |
|
---|
[1414] | 861 | return mKdTree->LoadBinTree(filename.c_str(), mObjects);
|
---|
[1197] | 862 | }
|
---|
| 863 |
|
---|
[1414] | 864 |
|
---|
| 865 | bool Preprocessor::ExportKdTree(const string filename)
|
---|
[1197] | 866 | {
|
---|
[1414] | 867 | return mKdTree->ExportBinTree(filename.c_str());
|
---|
[1197] | 868 | }
|
---|
| 869 |
|
---|
| 870 |
|
---|
[490] | 871 | bool Preprocessor::LoadSamples(VssRayContainer &samples,
|
---|
| 872 | ObjectContainer &objects) const
|
---|
| 873 | {
|
---|
| 874 | std::stable_sort(objects.begin(), objects.end(), ilt);
|
---|
| 875 | char fileName[100];
|
---|
[1004] | 876 | Environment::GetSingleton()->GetStringValue("Preprocessor.samplesFilename", fileName);
|
---|
[490] | 877 |
|
---|
[491] | 878 | Vector3 origin, termination;
|
---|
| 879 | // HACK: needed only for lower_bound algorithm to find the
|
---|
| 880 | // intersected objects
|
---|
| 881 | MeshInstance sObj(NULL);
|
---|
| 882 | MeshInstance tObj(NULL);
|
---|
[490] | 883 |
|
---|
[491] | 884 | #if USE_ASCII
|
---|
[656] | 885 | ifstream samplesIn(fileName);
|
---|
[490] | 886 | if (!samplesIn.is_open())
|
---|
| 887 | return false;
|
---|
| 888 |
|
---|
| 889 | string buf;
|
---|
| 890 | while (!(getline(samplesIn, buf)).eof())
|
---|
| 891 | {
|
---|
[491] | 892 | sscanf(buf.c_str(), "%f %f %f %f %f %f %d %d",
|
---|
[490] | 893 | &origin.x, &origin.y, &origin.z,
|
---|
[491] | 894 | &termination.x, &termination.y, &termination.z,
|
---|
| 895 | &(sObj.mId), &(tObj.mId));
|
---|
[490] | 896 |
|
---|
[491] | 897 | Intersectable *sourceObj = NULL;
|
---|
| 898 | Intersectable *termObj = NULL;
|
---|
| 899 |
|
---|
| 900 | if (sObj.mId >= 0)
|
---|
[490] | 901 | {
|
---|
| 902 | ObjectContainer::iterator oit =
|
---|
[491] | 903 | lower_bound(objects.begin(), objects.end(), &sObj, ilt);
|
---|
| 904 | sourceObj = *oit;
|
---|
| 905 | }
|
---|
| 906 |
|
---|
| 907 | if (tObj.mId >= 0)
|
---|
| 908 | {
|
---|
| 909 | ObjectContainer::iterator oit =
|
---|
| 910 | lower_bound(objects.begin(), objects.end(), &tObj, ilt);
|
---|
| 911 | termObj = *oit;
|
---|
| 912 | }
|
---|
[490] | 913 |
|
---|
[491] | 914 | samples.push_back(new VssRay(origin, termination, sourceObj, termObj));
|
---|
| 915 | }
|
---|
| 916 | #else
|
---|
| 917 | ifstream samplesIn(fileName, ios::binary);
|
---|
| 918 | if (!samplesIn.is_open())
|
---|
| 919 | return false;
|
---|
| 920 |
|
---|
| 921 | while (1)
|
---|
| 922 | {
|
---|
| 923 | samplesIn.read(reinterpret_cast<char *>(&origin), sizeof(Vector3));
|
---|
| 924 | samplesIn.read(reinterpret_cast<char *>(&termination), sizeof(Vector3));
|
---|
| 925 | samplesIn.read(reinterpret_cast<char *>(&(sObj.mId)), sizeof(int));
|
---|
| 926 | samplesIn.read(reinterpret_cast<char *>(&(tObj.mId)), sizeof(int));
|
---|
| 927 |
|
---|
| 928 | if (samplesIn.eof())
|
---|
| 929 | break;
|
---|
| 930 |
|
---|
| 931 | Intersectable *sourceObj = NULL;
|
---|
| 932 | Intersectable *termObj = NULL;
|
---|
| 933 |
|
---|
| 934 | if (sObj.mId >= 0)
|
---|
| 935 | {
|
---|
| 936 | ObjectContainer::iterator oit =
|
---|
| 937 | lower_bound(objects.begin(), objects.end(), &sObj, ilt);
|
---|
| 938 | sourceObj = *oit;
|
---|
[490] | 939 | }
|
---|
[491] | 940 |
|
---|
| 941 | if (tObj.mId >= 0)
|
---|
[490] | 942 | {
|
---|
[491] | 943 | ObjectContainer::iterator oit =
|
---|
| 944 | lower_bound(objects.begin(), objects.end(), &tObj, ilt);
|
---|
| 945 | termObj = *oit;
|
---|
[490] | 946 | }
|
---|
[491] | 947 |
|
---|
| 948 | samples.push_back(new VssRay(origin, termination, sourceObj, termObj));
|
---|
[490] | 949 | }
|
---|
[1779] | 950 | #endif
|
---|
[491] | 951 |
|
---|
[490] | 952 | samplesIn.close();
|
---|
| 953 |
|
---|
| 954 | return true;
|
---|
| 955 | }
|
---|
| 956 |
|
---|
[508] | 957 |
|
---|
| 958 | bool Preprocessor::ExportSamples(const VssRayContainer &samples) const
|
---|
[490] | 959 | {
|
---|
[491] | 960 | char fileName[100];
|
---|
[1004] | 961 | Environment::GetSingleton()->GetStringValue("Preprocessor.samplesFilename", fileName);
|
---|
[491] | 962 |
|
---|
[490] | 963 |
|
---|
| 964 | VssRayContainer::const_iterator it, it_end = samples.end();
|
---|
| 965 |
|
---|
[491] | 966 | #if USE_ASCII
|
---|
| 967 | ofstream samplesOut(fileName);
|
---|
[490] | 968 | if (!samplesOut.is_open())
|
---|
| 969 | return false;
|
---|
| 970 |
|
---|
| 971 | for (it = samples.begin(); it != it_end; ++ it)
|
---|
| 972 | {
|
---|
| 973 | VssRay *ray = *it;
|
---|
[491] | 974 | int sourceid = ray->mOriginObject ? ray->mOriginObject->mId : -1;
|
---|
| 975 | int termid = ray->mTerminationObject ? ray->mTerminationObject->mId : -1;
|
---|
| 976 |
|
---|
[490] | 977 | samplesOut << ray->GetOrigin().x << " " << ray->GetOrigin().y << " " << ray->GetOrigin().z << " "
|
---|
| 978 | << ray->GetTermination().x << " " << ray->GetTermination().y << " " << ray->GetTermination().z << " "
|
---|
[491] | 979 | << sourceid << " " << termid << "\n";
|
---|
[490] | 980 | }
|
---|
[491] | 981 | #else
|
---|
| 982 | ofstream samplesOut(fileName, ios::binary);
|
---|
| 983 | if (!samplesOut.is_open())
|
---|
| 984 | return false;
|
---|
| 985 |
|
---|
| 986 | for (it = samples.begin(); it != it_end; ++ it)
|
---|
| 987 | {
|
---|
| 988 | VssRay *ray = *it;
|
---|
| 989 | Vector3 origin(ray->GetOrigin());
|
---|
| 990 | Vector3 termination(ray->GetTermination());
|
---|
| 991 |
|
---|
| 992 | int sourceid = ray->mOriginObject ? ray->mOriginObject->mId : -1;
|
---|
| 993 | int termid = ray->mTerminationObject ? ray->mTerminationObject->mId : -1;
|
---|
| 994 |
|
---|
| 995 | samplesOut.write(reinterpret_cast<char *>(&origin), sizeof(Vector3));
|
---|
| 996 | samplesOut.write(reinterpret_cast<char *>(&termination), sizeof(Vector3));
|
---|
| 997 | samplesOut.write(reinterpret_cast<char *>(&sourceid), sizeof(int));
|
---|
| 998 | samplesOut.write(reinterpret_cast<char *>(&termid), sizeof(int));
|
---|
| 999 | }
|
---|
| 1000 | #endif
|
---|
[490] | 1001 | samplesOut.close();
|
---|
[1194] | 1002 |
|
---|
[490] | 1003 | return true;
|
---|
| 1004 | }
|
---|
[563] | 1005 |
|
---|
[1771] | 1006 |
|
---|
| 1007 | int
|
---|
| 1008 | Preprocessor::GenerateRays(const int number,
|
---|
[1867] | 1009 | SamplingStrategy &strategy,
|
---|
| 1010 | SimpleRayContainer &rays)
|
---|
[1020] | 1011 | {
|
---|
[1867] | 1012 | return strategy.GenerateSamples(number, rays);
|
---|
[1771] | 1013 | }
|
---|
[860] | 1014 |
|
---|
[1771] | 1015 | int
|
---|
| 1016 | Preprocessor::GenerateRays(const int number,
|
---|
[1898] | 1017 | const int sampleType,
|
---|
| 1018 | SimpleRayContainer &rays)
|
---|
[1771] | 1019 | {
|
---|
[1772] | 1020 | const int startSize = (int)rays.size();
|
---|
| 1021 | SamplingStrategy *strategy = GenerateSamplingStrategy(sampleType);
|
---|
| 1022 | int castRays = 0;
|
---|
| 1023 |
|
---|
| 1024 | if (!strategy)
|
---|
[1381] | 1025 | {
|
---|
[1772] | 1026 | return 0;
|
---|
[1381] | 1027 | }
|
---|
[1772] | 1028 |
|
---|
[1381] | 1029 | #if 1
|
---|
[1772] | 1030 | castRays = strategy->GenerateSamples(number, rays);
|
---|
[1381] | 1031 | #else
|
---|
[1772] | 1032 | GenerateRayBundle(rays, newRay, 16, 0);
|
---|
| 1033 | castRays += 16;
|
---|
[1381] | 1034 | #endif
|
---|
[1772] | 1035 |
|
---|
| 1036 | delete strategy;
|
---|
| 1037 | return castRays;
|
---|
[878] | 1038 | }
|
---|
[1020] | 1039 |
|
---|
| 1040 |
|
---|
[1884] | 1041 | SamplingStrategy *Preprocessor::GenerateSamplingStrategy(const int strategyId)
|
---|
[1020] | 1042 | {
|
---|
| 1043 | switch (strategyId)
|
---|
| 1044 | {
|
---|
[1520] | 1045 | case SamplingStrategy::OBJECT_BASED_DISTRIBUTION:
|
---|
[1020] | 1046 | return new ObjectBasedDistribution(*this);
|
---|
[1520] | 1047 | case SamplingStrategy::OBJECT_DIRECTION_BASED_DISTRIBUTION:
|
---|
[1020] | 1048 | return new ObjectDirectionBasedDistribution(*this);
|
---|
[1520] | 1049 | case SamplingStrategy::DIRECTION_BASED_DISTRIBUTION:
|
---|
[1020] | 1050 | return new DirectionBasedDistribution(*this);
|
---|
[1520] | 1051 | case SamplingStrategy::DIRECTION_BOX_BASED_DISTRIBUTION:
|
---|
[1020] | 1052 | return new DirectionBoxBasedDistribution(*this);
|
---|
[1520] | 1053 | case SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION:
|
---|
[1020] | 1054 | return new SpatialBoxBasedDistribution(*this);
|
---|
[1695] | 1055 | case SamplingStrategy::REVERSE_OBJECT_BASED_DISTRIBUTION:
|
---|
| 1056 | return new ReverseObjectBasedDistribution(*this);
|
---|
[1769] | 1057 | case SamplingStrategy::VIEWCELL_BORDER_BASED_DISTRIBUTION:
|
---|
| 1058 | return new ViewCellBorderBasedDistribution(*this);
|
---|
[1772] | 1059 | case SamplingStrategy::VIEWSPACE_BORDER_BASED_DISTRIBUTION:
|
---|
| 1060 | return new ViewSpaceBorderBasedDistribution(*this);
|
---|
| 1061 | case SamplingStrategy::REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION:
|
---|
| 1062 | return new ReverseViewSpaceBorderBasedDistribution(*this);
|
---|
[1824] | 1063 | case SamplingStrategy::GLOBAL_LINES_DISTRIBUTION:
|
---|
| 1064 | return new GlobalLinesDistribution(*this);
|
---|
| 1065 |
|
---|
| 1066 | //case OBJECTS_INTERIOR_DISTRIBUTION:
|
---|
| 1067 | // return new ObjectsInteriorDistribution(*this);
|
---|
[1020] | 1068 | default: // no valid strategy
|
---|
[1279] | 1069 | Debug << "warning: no valid sampling strategy" << endl;
|
---|
[1020] | 1070 | return NULL;
|
---|
| 1071 | }
|
---|
[1221] | 1072 |
|
---|
[1570] | 1073 | return NULL; // should never come here
|
---|
[1020] | 1074 | }
|
---|
| 1075 |
|
---|
| 1076 |
|
---|
[1968] | 1077 | bool Preprocessor::InitRayCast(const string externKdTree,
|
---|
| 1078 | const string internKdTree)
|
---|
[1221] | 1079 | {
|
---|
[1633] | 1080 | // always try to load the kd tree
|
---|
[1664] | 1081 | cout << "loading kd tree file " << internKdTree << " ... " << endl;
|
---|
[1634] | 1082 |
|
---|
| 1083 | if (!LoadKdTree(internKdTree))
|
---|
| 1084 | {
|
---|
[1968] | 1085 | cout << "error loading kd tree with filename "
|
---|
| 1086 | << internKdTree << ", rebuilding it instead ... " << endl;
|
---|
[1633] | 1087 | // build new kd tree from scene geometry
|
---|
[1415] | 1088 | BuildKdTree();
|
---|
| 1089 |
|
---|
[1627] | 1090 | // export kd tree?
|
---|
[1633] | 1091 | const long startTime = GetTime();
|
---|
[1627] | 1092 | cout << "exporting kd tree ... ";
|
---|
| 1093 |
|
---|
| 1094 | if (!ExportKdTree(internKdTree))
|
---|
| 1095 | {
|
---|
[1968] | 1096 | cout << " error exporting kd tree with filename "
|
---|
| 1097 | << internKdTree << endl;
|
---|
[1627] | 1098 | }
|
---|
| 1099 | else
|
---|
| 1100 | {
|
---|
[1968] | 1101 | cout << "finished in "
|
---|
| 1102 | << TimeDiff(startTime, GetTime()) * 1e-3
|
---|
| 1103 | << " secs" << endl;
|
---|
[1627] | 1104 | }
|
---|
[1415] | 1105 | }
|
---|
[1633] | 1106 |
|
---|
| 1107 | KdTreeStatistics(cout);
|
---|
| 1108 | cout << mKdTree->GetBox() << endl;
|
---|
[1415] | 1109 |
|
---|
[1633] | 1110 | if (0)
|
---|
| 1111 | {
|
---|
| 1112 | Exporter *exporter = Exporter::GetExporter("dummykd.x3d");
|
---|
| 1113 |
|
---|
| 1114 | if (exporter)
|
---|
| 1115 | {
|
---|
| 1116 | exporter->ExportKdTree(*mKdTree, true);
|
---|
| 1117 | delete exporter;
|
---|
| 1118 | }
|
---|
| 1119 | }
|
---|
| 1120 |
|
---|
[1520] | 1121 | int rayCastMethod;
|
---|
[1968] | 1122 | Environment::GetSingleton()->
|
---|
| 1123 | GetIntValue("Preprocessor.rayCastMethod", rayCastMethod);
|
---|
[1520] | 1124 |
|
---|
| 1125 | if (rayCastMethod == 0)
|
---|
[1221] | 1126 | {
|
---|
[1867] | 1127 | cout << "ray cast method: internal" << endl;
|
---|
[1520] | 1128 | mRayCaster = new InternalRayCaster(*this, mKdTree);
|
---|
[1221] | 1129 | }
|
---|
[1251] | 1130 | else
|
---|
[1520] | 1131 | {
|
---|
[1524] | 1132 | #ifdef GTP_INTERNAL
|
---|
[1867] | 1133 | cout << "ray cast method: intel" << endl;
|
---|
| 1134 | mRayCaster = new IntelRayCaster(*this, externKdTree);
|
---|
[1524] | 1135 | #endif
|
---|
[1251] | 1136 | }
|
---|
[1867] | 1137 |
|
---|
[1520] | 1138 | return true;
|
---|
[1281] | 1139 | }
|
---|
| 1140 |
|
---|
[1292] | 1141 |
|
---|
[1281] | 1142 | void
|
---|
| 1143 | Preprocessor::CastRays(
|
---|
| 1144 | SimpleRayContainer &rays,
|
---|
[1520] | 1145 | VssRayContainer &vssRays,
|
---|
[1528] | 1146 | const bool castDoubleRays,
|
---|
| 1147 | const bool pruneInvalidRays
|
---|
[1281] | 1148 | )
|
---|
| 1149 | {
|
---|
[1344] | 1150 |
|
---|
[1974] | 1151 |
|
---|
| 1152 | const long t1 = GetTime();
|
---|
| 1153 |
|
---|
| 1154 | #if 0
|
---|
| 1155 | mRayCaster->SortRays(rays);
|
---|
| 1156 | cout<<"Rays sorted in "<<TimeDiff(t1, GetTime())<<" s."<<endl;
|
---|
[1984] | 1157 |
|
---|
| 1158 | if (1) {
|
---|
| 1159 | VssRayContainer tmpRays;
|
---|
| 1160 | for (int i=0; i < 200; i++) {
|
---|
| 1161 | tmpRays.push_back(new VssRay(rays[i].mOrigin,
|
---|
| 1162 | rays[i].mOrigin + 100.0f*rays[i].mDirection,
|
---|
| 1163 | NULL,
|
---|
| 1164 | NULL
|
---|
| 1165 | )
|
---|
| 1166 | );
|
---|
| 1167 |
|
---|
| 1168 | }
|
---|
| 1169 | ExportRays("sorted_rays.x3d", tmpRays, 200);
|
---|
| 1170 | }
|
---|
[1974] | 1171 | #endif
|
---|
| 1172 |
|
---|
[1972] | 1173 | SimpleRayContainer::const_iterator rit, rit_end = rays.end();
|
---|
| 1174 |
|
---|
| 1175 | SimpleRayContainer rayBucket;
|
---|
| 1176 | int i = 0;
|
---|
| 1177 | for (rit = rays.begin(); rit != rit_end; ++ rit, ++ i)
|
---|
[1292] | 1178 | {
|
---|
[1972] | 1179 | SimpleRay ray = *rit;
|
---|
| 1180 | // HACK: global lines must be treated special
|
---|
| 1181 | if (ray.mDistribution == SamplingStrategy::HW_GLOBAL_LINES_DISTRIBUTION)
|
---|
[1968] | 1182 | {
|
---|
[1972] | 1183 | mGlobalLinesRenderer->CastGlobalLines(ray, vssRays);
|
---|
[1968] | 1184 | continue;
|
---|
| 1185 | }
|
---|
| 1186 |
|
---|
[1972] | 1187 | rayBucket.push_back(ray);
|
---|
| 1188 |
|
---|
| 1189 | // 16 rays gathered => do ray casting
|
---|
| 1190 | if ((int)rayBucket.size() >= 16)
|
---|
[1520] | 1191 | {
|
---|
[1524] | 1192 | mRayCaster->CastRays16(
|
---|
[1972] | 1193 | rayBucket,
|
---|
[1584] | 1194 | vssRays,
|
---|
| 1195 | mViewCellsManager->GetViewSpaceBox(),
|
---|
| 1196 | castDoubleRays,
|
---|
| 1197 | pruneInvalidRays);
|
---|
[1972] | 1198 |
|
---|
| 1199 | rayBucket.clear();
|
---|
[1292] | 1200 | }
|
---|
[1972] | 1201 |
|
---|
| 1202 | if ((int)rays.size() > 10000 && i % 10000 == 0)
|
---|
[1984] | 1203 | cout<<"\r"<<i<<"/"<<(int)rays.size()<<"\r";
|
---|
[1972] | 1204 | }
|
---|
| 1205 |
|
---|
| 1206 | // cast rest of rays
|
---|
| 1207 | SimpleRayContainer::const_iterator sit, sit_end = rayBucket.end();
|
---|
| 1208 |
|
---|
| 1209 | for (sit = rayBucket.begin(); sit != sit_end; ++ sit)
|
---|
| 1210 | {
|
---|
| 1211 | SimpleRay ray = *sit;
|
---|
| 1212 | // HACK: global lines must be treated special
|
---|
| 1213 | if (ray.mDistribution == SamplingStrategy::HW_GLOBAL_LINES_DISTRIBUTION)
|
---|
[1932] | 1214 | {
|
---|
[1972] | 1215 | mGlobalLinesRenderer->CastGlobalLines(ray, vssRays);
|
---|
| 1216 | }
|
---|
| 1217 | else
|
---|
| 1218 | {
|
---|
[1524] | 1219 | mRayCaster->CastRay(
|
---|
[1972] | 1220 | ray,
|
---|
[1584] | 1221 | vssRays,
|
---|
| 1222 | mViewCellsManager->GetViewSpaceBox(),
|
---|
| 1223 | castDoubleRays,
|
---|
| 1224 | pruneInvalidRays);
|
---|
[1932] | 1225 | }
|
---|
[1524] | 1226 | }
|
---|
[1743] | 1227 |
|
---|
[1972] | 1228 | if ((int)rays.size() > 10000)
|
---|
[1932] | 1229 | {
|
---|
[1968] | 1230 | cout << endl;
|
---|
[1972] | 1231 | long t2 = GetTime();
|
---|
[1286] | 1232 |
|
---|
[1584] | 1233 | #if SHOW_RAYCAST_TIMING
|
---|
[1968] | 1234 | if (castDoubleRays)
|
---|
[1972] | 1235 | cout << 2 * rays.size() / (1e3f * TimeDiff(t1, t2)) << "M rays/s" << endl;
|
---|
[1968] | 1236 | else
|
---|
| 1237 | cout << rays.size() / (1e3f * TimeDiff(t1, t2)) << "M rays/s" << endl;
|
---|
[1743] | 1238 | #endif
|
---|
| 1239 | }
|
---|
[1251] | 1240 | }
|
---|
| 1241 |
|
---|
| 1242 |
|
---|
[1381] | 1243 | bool Preprocessor::GenerateRayBundle(SimpleRayContainer &rayBundle,
|
---|
| 1244 | const SimpleRay &mainRay,
|
---|
| 1245 | const int number,
|
---|
| 1246 | const int pertubType) const
|
---|
| 1247 | {
|
---|
| 1248 | rayBundle.push_back(mainRay);
|
---|
| 1249 |
|
---|
[1564] | 1250 | const float pertubOrigin = 0.0f;
|
---|
| 1251 | const float pertubDir = 0.2f;
|
---|
[1381] | 1252 |
|
---|
| 1253 | for (int i = 0; i < number - 1; ++ i)
|
---|
| 1254 | {
|
---|
| 1255 | Vector3 pertub;
|
---|
| 1256 |
|
---|
| 1257 | pertub.x = RandomValue(0.0f, pertubDir);
|
---|
| 1258 | pertub.y = RandomValue(0.0f, pertubDir);
|
---|
| 1259 | pertub.z = RandomValue(0.0f, pertubDir);
|
---|
[1713] | 1260 |
|
---|
[1381] | 1261 | const Vector3 newDir = mainRay.mDirection + pertub;
|
---|
| 1262 | //const Vector3 newDir = mainRay.mDirection;
|
---|
| 1263 |
|
---|
| 1264 | pertub.x = RandomValue(0.0f, pertubOrigin);
|
---|
| 1265 | pertub.y = RandomValue(0.0f, pertubOrigin);
|
---|
| 1266 | pertub.z = RandomValue(0.0f, pertubOrigin);
|
---|
[1713] | 1267 |
|
---|
[1381] | 1268 | const Vector3 newOrigin = mainRay.mOrigin + pertub;
|
---|
| 1269 | //const Vector3 newOrigin = mainRay.mOrigin;
|
---|
| 1270 |
|
---|
[1883] | 1271 | rayBundle.push_back(SimpleRay(newOrigin, newDir, 0, 1.0f));
|
---|
[1381] | 1272 | }
|
---|
| 1273 |
|
---|
| 1274 | return true;
|
---|
| 1275 | }
|
---|
| 1276 |
|
---|
| 1277 |
|
---|
[1251] | 1278 | void Preprocessor::SetupRay(Ray &ray,
|
---|
| 1279 | const Vector3 &point,
|
---|
[1713] | 1280 | const Vector3 &direction) const
|
---|
[1251] | 1281 | {
|
---|
| 1282 | ray.Clear();
|
---|
| 1283 | // do not store anything else then intersections at the ray
|
---|
[1713] | 1284 | ray.Init(point, direction, Ray::LOCAL_RAY);
|
---|
[1251] | 1285 | }
|
---|
| 1286 |
|
---|
[1968] | 1287 |
|
---|
[1917] | 1288 | void Preprocessor::EvalViewCellHistogram()
|
---|
[1771] | 1289 | {
|
---|
[1917] | 1290 | char filename[256];
|
---|
| 1291 | Environment::GetSingleton()->GetStringValue("Preprocessor.histogram.file", filename);
|
---|
[1771] | 1292 |
|
---|
[1917] | 1293 | // mViewCellsManager->EvalViewCellHistogram(filename, 1000000);
|
---|
| 1294 | mViewCellsManager->EvalViewCellHistogramForPvsSize(filename, 1000000);
|
---|
[1771] | 1295 | }
|
---|
[1520] | 1296 |
|
---|
[1900] | 1297 |
|
---|
| 1298 | bool
|
---|
| 1299 | Preprocessor::ExportRays(const char *filename,
|
---|
| 1300 | const VssRayContainer &vssRays,
|
---|
| 1301 | const int number
|
---|
| 1302 | )
|
---|
| 1303 | {
|
---|
| 1304 | cout<<"Exporting vss rays..."<<endl<<flush;
|
---|
| 1305 |
|
---|
| 1306 | Exporter *exporter = NULL;
|
---|
| 1307 | exporter = Exporter::GetExporter(filename);
|
---|
| 1308 |
|
---|
| 1309 | if (0) {
|
---|
| 1310 | exporter->SetWireframe();
|
---|
| 1311 | exporter->ExportKdTree(*mKdTree);
|
---|
| 1312 | }
|
---|
| 1313 |
|
---|
| 1314 | exporter->SetFilled();
|
---|
| 1315 | // $$JB temporarily do not export the scene
|
---|
| 1316 | if (0)
|
---|
| 1317 | exporter->ExportScene(mSceneGraph->GetRoot());
|
---|
| 1318 |
|
---|
| 1319 | exporter->SetWireframe();
|
---|
| 1320 |
|
---|
| 1321 | if (1) {
|
---|
| 1322 | exporter->SetForcedMaterial(RgbColor(1,0,1));
|
---|
| 1323 | exporter->ExportBox(mViewCellsManager->GetViewSpaceBox());
|
---|
| 1324 | exporter->ResetForcedMaterial();
|
---|
| 1325 | }
|
---|
| 1326 |
|
---|
| 1327 | VssRayContainer rays;
|
---|
| 1328 | vssRays.SelectRays(number, rays);
|
---|
| 1329 | exporter->ExportRays(rays, RgbColor(1, 0, 0));
|
---|
| 1330 | delete exporter;
|
---|
| 1331 | cout<<"done."<<endl<<flush;
|
---|
| 1332 |
|
---|
| 1333 | return true;
|
---|
[1251] | 1334 | }
|
---|
[1900] | 1335 |
|
---|
[1931] | 1336 | void
|
---|
| 1337 | Preprocessor::ComputeRenderError()
|
---|
| 1338 | {
|
---|
| 1339 | // compute rendering error
|
---|
| 1340 |
|
---|
| 1341 | if (renderer && renderer->mPvsStatFrames) {
|
---|
| 1342 | // emit EvalPvsStat();
|
---|
| 1343 | // QMutex mutex;
|
---|
| 1344 | // mutex.lock();
|
---|
| 1345 | // renderer->mRenderingFinished.wait(&mutex);
|
---|
| 1346 | // mutex.unlock();
|
---|
| 1347 |
|
---|
| 1348 | renderer->EvalPvsStat();
|
---|
| 1349 |
|
---|
| 1350 | mStats <<
|
---|
| 1351 | "#AvgPvsRenderError\n" <<renderer->mPvsStat.GetAvgError()<<endl<<
|
---|
| 1352 | "#MaxPvsRenderError\n" <<renderer->mPvsStat.GetMaxError()<<endl<<
|
---|
| 1353 | "#ErrorFreeFrames\n" <<renderer->mPvsStat.GetErrorFreeFrames()<<endl<<
|
---|
| 1354 | "#AvgRenderPvs\n" <<renderer->mPvsStat.GetAvgPvs()<<endl;
|
---|
| 1355 | }
|
---|
[1900] | 1356 | }
|
---|
[1931] | 1357 |
|
---|
[1958] | 1358 |
|
---|
| 1359 | Intersectable *Preprocessor::GetObjectById(const int id)
|
---|
| 1360 | {
|
---|
[1960] | 1361 | #if 1
|
---|
[1958] | 1362 | // create a dummy mesh instance to be able to use stl
|
---|
| 1363 | MeshInstance object(NULL);
|
---|
| 1364 | object.SetId(id);
|
---|
| 1365 |
|
---|
| 1366 | ObjectContainer::const_iterator oit =
|
---|
| 1367 | lower_bound(mObjects.begin(), mObjects.end(), &object, ilt);
|
---|
| 1368 |
|
---|
| 1369 | // objects sorted by id
|
---|
| 1370 | if ((oit != mObjects.end()) && ((*oit)->GetId() == object.GetId()))
|
---|
| 1371 | {
|
---|
| 1372 | return (*oit);
|
---|
| 1373 | }
|
---|
| 1374 | else
|
---|
| 1375 | {
|
---|
| 1376 | return NULL;
|
---|
| 1377 | }
|
---|
| 1378 | #else
|
---|
[1960] | 1379 | return mObjects[id - 1];
|
---|
[1958] | 1380 | #endif
|
---|
[1931] | 1381 | }
|
---|
[1958] | 1382 |
|
---|
[1968] | 1383 |
|
---|
| 1384 | void Preprocessor::PrepareHwGlobalLines()
|
---|
| 1385 | {
|
---|
| 1386 | int texHeight, texWidth;
|
---|
| 1387 | float eps;
|
---|
| 1388 | int maxDepth;
|
---|
| 1389 | bool sampleReverse;
|
---|
| 1390 |
|
---|
| 1391 | Environment::GetSingleton()->GetIntValue("Preprocessor.HwGlobalLines.texHeight", texHeight);
|
---|
[1969] | 1392 | Environment::GetSingleton()->GetIntValue("Preprocessor.HwGlobalLines.texWidth", texWidth);
|
---|
[1968] | 1393 | Environment::GetSingleton()->GetFloatValue("Preprocessor.HwGlobalLines.stepSize", eps);
|
---|
| 1394 | Environment::GetSingleton()->GetIntValue("Preprocessor.HwGlobalLines.maxDepth", maxDepth);
|
---|
| 1395 | Environment::GetSingleton()->GetBoolValue("Preprocessor.HwGlobalLines.sampleReverse", sampleReverse);
|
---|
| 1396 |
|
---|
[1969] | 1397 | Debug << "****** hw global line options *******" << endl;
|
---|
| 1398 | Debug << "texWidth: " << texWidth << endl;
|
---|
| 1399 | Debug << "texHeight: " << texHeight << endl;
|
---|
| 1400 | Debug << "sampleReverse: " << sampleReverse << endl;
|
---|
| 1401 | Debug << "max depth: " << maxDepth << endl;
|
---|
| 1402 | Debug << "step size: " << eps << endl;
|
---|
| 1403 | Debug << endl;
|
---|
| 1404 |
|
---|
| 1405 | globalLinesRenderer = mGlobalLinesRenderer =
|
---|
[1968] | 1406 | new GlobalLinesRenderer(this,
|
---|
| 1407 | texHeight,
|
---|
| 1408 | texWidth,
|
---|
| 1409 | eps,
|
---|
| 1410 | maxDepth,
|
---|
| 1411 | sampleReverse);
|
---|
[1969] | 1412 |
|
---|
[1968] | 1413 | mGlobalLinesRenderer->InitGl();
|
---|
[1958] | 1414 | }
|
---|
[1968] | 1415 |
|
---|
| 1416 | }
|
---|