[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"
|
---|
| 11 | #include "VspKdTree.h"
|
---|
[469] | 12 | #include "RenderSimulator.h"
|
---|
[496] | 13 | #include "GlRenderer.h"
|
---|
[372] | 14 |
|
---|
[492] | 15 | Preprocessor *preprocessor;
|
---|
| 16 |
|
---|
[372] | 17 | Preprocessor::Preprocessor():
|
---|
| 18 | mKdTree(NULL),
|
---|
[409] | 19 | mBspTree(NULL),
|
---|
[422] | 20 | mVspKdTree(NULL),
|
---|
[445] | 21 | mVspBspTree(NULL),
|
---|
[439] | 22 | mViewCellsManager(NULL)
|
---|
[308] | 23 | {
|
---|
[492] | 24 | environment->GetBoolValue("Preprocessor.useGlRenderer", mUseGlRenderer);
|
---|
[538] | 25 |
|
---|
[496] | 26 | // renderer will be constructed when the scene graph and viewcell manager will be known
|
---|
| 27 | renderer = NULL;
|
---|
| 28 |
|
---|
[538] | 29 | environment->GetBoolValue("Preprocessor.useGlDebugger", mUseGlDebugger);
|
---|
[372] | 30 | }
|
---|
| 31 |
|
---|
| 32 |
|
---|
| 33 | Preprocessor::~Preprocessor()
|
---|
| 34 | {
|
---|
[563] | 35 | Debug<<"Deleting view cells manager...\n";
|
---|
[496] | 36 | DEL_PTR(mViewCellsManager);
|
---|
[563] | 37 | Debug<<"done.\n";
|
---|
| 38 | Debug<<"Deleting bsp tree...\n";
|
---|
[496] | 39 | DEL_PTR(mBspTree);
|
---|
[563] | 40 | Debug<<"done.\n";
|
---|
| 41 | Debug<<"Deleting kd tree...\n";
|
---|
[496] | 42 | DEL_PTR(mKdTree);
|
---|
[563] | 43 | Debug<<"done.\n";
|
---|
| 44 | Debug<<"Deleting vspkd tree...\n";
|
---|
[496] | 45 | DEL_PTR(mVspKdTree);
|
---|
[563] | 46 | Debug<<"done.\n";
|
---|
| 47 | Debug<<"Deleting vspbsp tree...\n";
|
---|
[496] | 48 | DEL_PTR(mVspBspTree);
|
---|
[563] | 49 | Debug<<"done.\n";
|
---|
[372] | 50 | }
|
---|
| 51 |
|
---|
[387] | 52 | int
|
---|
[419] | 53 | SplitFilenames(const string str, vector<string> &filenames)
|
---|
[387] | 54 | {
|
---|
| 55 | int pos = 0;
|
---|
| 56 |
|
---|
| 57 | while(1) {
|
---|
[469] | 58 | int npos = (int)str.find(';', pos);
|
---|
[387] | 59 |
|
---|
| 60 | if (npos < 0 || npos - pos < 1)
|
---|
| 61 | break;
|
---|
| 62 | filenames.push_back(string(str, pos, npos - pos));
|
---|
| 63 | pos = npos + 1;
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | filenames.push_back(string(str, pos, str.size() - pos));
|
---|
[440] | 67 | return (int)filenames.size();
|
---|
[387] | 68 | }
|
---|
| 69 |
|
---|
[372] | 70 | bool
|
---|
| 71 | Preprocessor::LoadScene(const string filename)
|
---|
| 72 | {
|
---|
[508] | 73 | // use leaf nodes of the original spatial hiearrchy as occludees
|
---|
| 74 | mSceneGraph = new SceneGraph;
|
---|
[372] | 75 |
|
---|
[508] | 76 | Parser *parser;
|
---|
[387] | 77 | vector<string> filenames;
|
---|
| 78 | int files = SplitFilenames(filename, filenames);
|
---|
| 79 | cout<<files<<endl;
|
---|
| 80 | bool result = false;
|
---|
| 81 | if (files == 1) {
|
---|
| 82 |
|
---|
| 83 | if (strstr(filename.c_str(), ".x3d"))
|
---|
| 84 | parser = new X3dParser;
|
---|
| 85 | else
|
---|
| 86 | parser = new UnigraphicsParser;
|
---|
[372] | 87 |
|
---|
[387] | 88 | cout<<filename<<endl;
|
---|
| 89 | result = parser->ParseFile(filename, &mSceneGraph->mRoot);
|
---|
[372] | 90 |
|
---|
[387] | 91 | delete parser;
|
---|
[372] | 92 |
|
---|
[387] | 93 | } else {
|
---|
| 94 | // root for different files
|
---|
| 95 | mSceneGraph->mRoot = new SceneGraphNode;
|
---|
| 96 | for (int i= 0; i < filenames.size(); i++) {
|
---|
| 97 | if (strstr(filenames[i].c_str(), ".x3d"))
|
---|
| 98 | parser = new X3dParser;
|
---|
| 99 | else
|
---|
| 100 | parser = new UnigraphicsParser;
|
---|
| 101 |
|
---|
| 102 | SceneGraphNode *node;
|
---|
| 103 | if (parser->ParseFile(filenames[i], &node)) {
|
---|
| 104 | mSceneGraph->mRoot->mChildren.push_back(node);
|
---|
| 105 | // at least one file parsed
|
---|
| 106 | result = true;
|
---|
| 107 | }
|
---|
| 108 | delete parser;
|
---|
| 109 | }
|
---|
| 110 | }
|
---|
[372] | 111 |
|
---|
| 112 |
|
---|
[387] | 113 | if (result) {
|
---|
[492] | 114 |
|
---|
| 115 | mSceneGraph->AssignObjectIds();
|
---|
| 116 | int intersectables, faces;
|
---|
| 117 | mSceneGraph->GetStatistics(intersectables, faces);
|
---|
| 118 | cout<<filename<<" parsed successfully."<<endl;
|
---|
| 119 | cout<<"#NUM_OBJECTS (Total numner of objects)\n"<<intersectables<<endl;
|
---|
| 120 | cout<<"#NUM_FACES (Total numner of faces)\n"<<faces<<endl;
|
---|
| 121 | mSceneGraph->CollectObjects(&mObjects);
|
---|
| 122 | mSceneGraph->mRoot->UpdateBox();
|
---|
[387] | 123 | }
|
---|
[372] | 124 |
|
---|
[492] | 125 |
|
---|
| 126 | return result;
|
---|
[372] | 127 | }
|
---|
| 128 |
|
---|
| 129 | bool
|
---|
| 130 | Preprocessor::ExportPreprocessedData(const string filename)
|
---|
| 131 | {
|
---|
| 132 | return false;
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 | bool
|
---|
| 136 | Preprocessor::BuildKdTree()
|
---|
| 137 | {
|
---|
| 138 | mKdTree = new KdTree;
|
---|
| 139 | // add mesh instances of the scene graph to the root of the tree
|
---|
| 140 | KdLeaf *root = (KdLeaf *)mKdTree->GetRoot();
|
---|
| 141 | mSceneGraph->CollectObjects(&root->mObjects);
|
---|
| 142 |
|
---|
| 143 | mKdTree->Construct();
|
---|
| 144 | return true;
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | void
|
---|
| 148 | Preprocessor::KdTreeStatistics(ostream &s)
|
---|
| 149 | {
|
---|
| 150 | s<<mKdTree->GetStatistics();
|
---|
| 151 | }
|
---|
| 152 |
|
---|
| 153 | void
|
---|
| 154 | Preprocessor::BspTreeStatistics(ostream &s)
|
---|
| 155 | {
|
---|
| 156 | s << mBspTree->GetStatistics();
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 | bool
|
---|
| 160 | Preprocessor::Export( const string filename,
|
---|
[492] | 161 | const bool scene,
|
---|
| 162 | const bool kdtree,
|
---|
| 163 | const bool bsptree
|
---|
| 164 | )
|
---|
[372] | 165 | {
|
---|
| 166 | Exporter *exporter = Exporter::GetExporter(filename);
|
---|
| 167 |
|
---|
| 168 | if (exporter) {
|
---|
| 169 | if (scene)
|
---|
| 170 | exporter->ExportScene(mSceneGraph->mRoot);
|
---|
| 171 |
|
---|
| 172 | if (kdtree) {
|
---|
| 173 | exporter->SetWireframe();
|
---|
| 174 | exporter->ExportKdTree(*mKdTree);
|
---|
| 175 | }
|
---|
| 176 |
|
---|
| 177 | if (bsptree) {
|
---|
| 178 | //exporter->SetWireframe();
|
---|
| 179 | exporter->ExportBspTree(*mBspTree);
|
---|
| 180 | }
|
---|
| 181 |
|
---|
| 182 | delete exporter;
|
---|
| 183 | return true;
|
---|
| 184 | }
|
---|
| 185 |
|
---|
| 186 | return false;
|
---|
| 187 | }
|
---|
[429] | 188 |
|
---|
[508] | 189 |
|
---|
[463] | 190 | bool Preprocessor::PrepareViewCells()
|
---|
| 191 | {
|
---|
[577] | 192 | //-- parse view cells construction method
|
---|
| 193 | environment->GetBoolValue("ViewCells.loadFromFile", mLoadViewCells);
|
---|
| 194 | char buf[100];
|
---|
| 195 |
|
---|
| 196 | if (mLoadViewCells)
|
---|
| 197 | {
|
---|
| 198 | environment->GetStringValue("ViewCells.filename", buf);
|
---|
| 199 | mViewCellsManager = ViewCellsManager::LoadViewCells(buf, &mObjects);
|
---|
| 200 | }
|
---|
| 201 | else
|
---|
| 202 | {
|
---|
| 203 | //-- parse type of view cell container
|
---|
| 204 | char viewCellsStr[64];
|
---|
| 205 | environment->GetStringValue("ViewCells.type", viewCellsStr);
|
---|
| 206 | mViewCellsManager = CreateViewCellsManager(viewCellsStr);
|
---|
| 207 | }
|
---|
[439] | 208 |
|
---|
[473] | 209 | float objRenderCost = 0, vcOverhead = 0, moveSpeed = 0;
|
---|
| 210 |
|
---|
| 211 | environment->GetFloatValue("Simulation.objRenderCost",objRenderCost);
|
---|
| 212 | environment->GetFloatValue("Simulation.vcOverhead", vcOverhead);
|
---|
| 213 | environment->GetFloatValue("Simulation.moveSpeed", moveSpeed);
|
---|
| 214 |
|
---|
| 215 | mRenderSimulator =
|
---|
| 216 | new RenderSimulator(mViewCellsManager, objRenderCost, vcOverhead, moveSpeed);
|
---|
[440] | 217 |
|
---|
[480] | 218 | mViewCellsManager->SetRenderer(mRenderSimulator);
|
---|
[440] | 219 |
|
---|
[574] | 220 |
|
---|
[538] | 221 | if (mUseGlRenderer || mUseGlDebugger)
|
---|
[540] | 222 | {
|
---|
| 223 | // NOTE: render texture should be power of 2 and square
|
---|
| 224 | // renderer must be initialised
|
---|
| 225 | renderer = new GlRendererBuffer(1024, 768, mSceneGraph, mViewCellsManager, mKdTree);
|
---|
[556] | 226 | // renderer->makeCurrent();
|
---|
[540] | 227 | }
|
---|
[534] | 228 |
|
---|
| 229 |
|
---|
| 230 | environment->GetBoolValue("Preprocessor.detectEmptyViewSpace", mDetectEmptyViewSpace);
|
---|
[496] | 231 |
|
---|
[463] | 232 | return true;
|
---|
[490] | 233 | }
|
---|
| 234 |
|
---|
| 235 |
|
---|
[575] | 236 | ViewCellsManager *Preprocessor::CreateViewCellsManager(const char *name)
|
---|
| 237 | {
|
---|
| 238 | if (strcmp(name, "kdTree") == 0)
|
---|
| 239 | {
|
---|
| 240 | mViewCellsManager = new KdViewCellsManager(mKdTree);
|
---|
| 241 | }
|
---|
| 242 | else if (strcmp(name, "bspTree") == 0)
|
---|
| 243 | {
|
---|
| 244 | Debug << "view cell type: Bsp" << endl;
|
---|
| 245 |
|
---|
[577] | 246 | mBspTree = new BspTree();
|
---|
[575] | 247 | mViewCellsManager = new BspViewCellsManager(mBspTree);
|
---|
| 248 | }
|
---|
| 249 | else if (strcmp(name, "vspBspTree") == 0)
|
---|
| 250 | {
|
---|
| 251 | Debug << "view cell type: VspBsp" << endl;
|
---|
| 252 |
|
---|
[577] | 253 | mVspBspTree = new VspBspTree();
|
---|
[575] | 254 | mViewCellsManager = new VspBspViewCellsManager(mVspBspTree);
|
---|
| 255 | }
|
---|
| 256 | else if (strcmp(name, "vspKdTree") == 0)
|
---|
| 257 | {
|
---|
| 258 | mVspKdTree = new VspKdTree();
|
---|
| 259 |
|
---|
| 260 | mViewCellsManager = new VspKdViewCellsManager(mVspKdTree);
|
---|
| 261 | }
|
---|
| 262 | else if (strcmp(name, "sceneDependent") == 0)
|
---|
| 263 | {
|
---|
| 264 | //TODO
|
---|
| 265 | mBspTree = new BspTree();
|
---|
| 266 |
|
---|
| 267 | Debug << "view cell type: Bsp" << endl;
|
---|
| 268 |
|
---|
| 269 | mViewCellsManager = new BspViewCellsManager(mBspTree);
|
---|
| 270 | }
|
---|
| 271 | else
|
---|
| 272 | {
|
---|
| 273 | cerr<<"Wrong view cells type" << name << endl;
|
---|
| 274 | exit(1);
|
---|
| 275 | }
|
---|
| 276 |
|
---|
| 277 | return mViewCellsManager;
|
---|
| 278 | }
|
---|
| 279 |
|
---|
| 280 |
|
---|
[491] | 281 | // use ascii format to store rays
|
---|
| 282 | #define USE_ASCII 0
|
---|
| 283 |
|
---|
| 284 |
|
---|
[490] | 285 | inline bool ilt(Intersectable *obj1, Intersectable *obj2)
|
---|
| 286 | {
|
---|
| 287 | return obj1->mId < obj2->mId;
|
---|
| 288 | }
|
---|
| 289 |
|
---|
| 290 |
|
---|
| 291 | bool Preprocessor::LoadSamples(VssRayContainer &samples,
|
---|
| 292 | ObjectContainer &objects) const
|
---|
| 293 | {
|
---|
| 294 | std::stable_sort(objects.begin(), objects.end(), ilt);
|
---|
| 295 | char fileName[100];
|
---|
| 296 | environment->GetStringValue("Preprocessor.samplesFilename", fileName);
|
---|
| 297 |
|
---|
[491] | 298 | Vector3 origin, termination;
|
---|
| 299 | // HACK: needed only for lower_bound algorithm to find the
|
---|
| 300 | // intersected objects
|
---|
| 301 | MeshInstance sObj(NULL);
|
---|
| 302 | MeshInstance tObj(NULL);
|
---|
[490] | 303 |
|
---|
[491] | 304 | #if USE_ASCII
|
---|
| 305 | ifstream samplesIn(fileName, ios::binary);
|
---|
[490] | 306 | if (!samplesIn.is_open())
|
---|
| 307 | return false;
|
---|
| 308 |
|
---|
| 309 | string buf;
|
---|
| 310 | while (!(getline(samplesIn, buf)).eof())
|
---|
| 311 | {
|
---|
[491] | 312 | sscanf(buf.c_str(), "%f %f %f %f %f %f %d %d",
|
---|
[490] | 313 | &origin.x, &origin.y, &origin.z,
|
---|
[491] | 314 | &termination.x, &termination.y, &termination.z,
|
---|
| 315 | &(sObj.mId), &(tObj.mId));
|
---|
[490] | 316 |
|
---|
[491] | 317 | Intersectable *sourceObj = NULL;
|
---|
| 318 | Intersectable *termObj = NULL;
|
---|
| 319 |
|
---|
| 320 | if (sObj.mId >= 0)
|
---|
[490] | 321 | {
|
---|
| 322 | ObjectContainer::iterator oit =
|
---|
[491] | 323 | lower_bound(objects.begin(), objects.end(), &sObj, ilt);
|
---|
| 324 | sourceObj = *oit;
|
---|
| 325 | }
|
---|
| 326 |
|
---|
| 327 | if (tObj.mId >= 0)
|
---|
| 328 | {
|
---|
| 329 | ObjectContainer::iterator oit =
|
---|
| 330 | lower_bound(objects.begin(), objects.end(), &tObj, ilt);
|
---|
| 331 | termObj = *oit;
|
---|
| 332 | }
|
---|
[490] | 333 |
|
---|
[491] | 334 | samples.push_back(new VssRay(origin, termination, sourceObj, termObj));
|
---|
| 335 | }
|
---|
| 336 | #else
|
---|
| 337 | ifstream samplesIn(fileName, ios::binary);
|
---|
| 338 | if (!samplesIn.is_open())
|
---|
| 339 | return false;
|
---|
| 340 |
|
---|
| 341 | while (1)
|
---|
| 342 | {
|
---|
| 343 | samplesIn.read(reinterpret_cast<char *>(&origin), sizeof(Vector3));
|
---|
| 344 | samplesIn.read(reinterpret_cast<char *>(&termination), sizeof(Vector3));
|
---|
| 345 | samplesIn.read(reinterpret_cast<char *>(&(sObj.mId)), sizeof(int));
|
---|
| 346 | samplesIn.read(reinterpret_cast<char *>(&(tObj.mId)), sizeof(int));
|
---|
| 347 |
|
---|
| 348 | if (samplesIn.eof())
|
---|
| 349 | break;
|
---|
| 350 |
|
---|
| 351 | Intersectable *sourceObj = NULL;
|
---|
| 352 | Intersectable *termObj = NULL;
|
---|
| 353 |
|
---|
| 354 | if (sObj.mId >= 0)
|
---|
| 355 | {
|
---|
| 356 | ObjectContainer::iterator oit =
|
---|
| 357 | lower_bound(objects.begin(), objects.end(), &sObj, ilt);
|
---|
| 358 | sourceObj = *oit;
|
---|
[490] | 359 | }
|
---|
[491] | 360 |
|
---|
| 361 | if (tObj.mId >= 0)
|
---|
[490] | 362 | {
|
---|
[491] | 363 | ObjectContainer::iterator oit =
|
---|
| 364 | lower_bound(objects.begin(), objects.end(), &tObj, ilt);
|
---|
| 365 | termObj = *oit;
|
---|
[490] | 366 | }
|
---|
[491] | 367 |
|
---|
| 368 | samples.push_back(new VssRay(origin, termination, sourceObj, termObj));
|
---|
[490] | 369 | }
|
---|
[491] | 370 |
|
---|
| 371 | #endif
|
---|
[490] | 372 | samplesIn.close();
|
---|
| 373 |
|
---|
| 374 | return true;
|
---|
| 375 | }
|
---|
| 376 |
|
---|
[508] | 377 |
|
---|
| 378 | bool Preprocessor::ExportSamples(const VssRayContainer &samples) const
|
---|
[490] | 379 | {
|
---|
[491] | 380 | char fileName[100];
|
---|
| 381 | environment->GetStringValue("Preprocessor.samplesFilename", fileName);
|
---|
| 382 |
|
---|
[490] | 383 |
|
---|
| 384 | VssRayContainer::const_iterator it, it_end = samples.end();
|
---|
| 385 |
|
---|
[491] | 386 | #if USE_ASCII
|
---|
| 387 | ofstream samplesOut(fileName);
|
---|
[490] | 388 | if (!samplesOut.is_open())
|
---|
| 389 | return false;
|
---|
| 390 |
|
---|
| 391 | for (it = samples.begin(); it != it_end; ++ it)
|
---|
| 392 | {
|
---|
| 393 | VssRay *ray = *it;
|
---|
[491] | 394 | int sourceid = ray->mOriginObject ? ray->mOriginObject->mId : -1;
|
---|
| 395 | int termid = ray->mTerminationObject ? ray->mTerminationObject->mId : -1;
|
---|
| 396 |
|
---|
[490] | 397 | samplesOut << ray->GetOrigin().x << " " << ray->GetOrigin().y << " " << ray->GetOrigin().z << " "
|
---|
| 398 | << ray->GetTermination().x << " " << ray->GetTermination().y << " " << ray->GetTermination().z << " "
|
---|
[491] | 399 | << sourceid << " " << termid << "\n";
|
---|
[490] | 400 | }
|
---|
[491] | 401 | #else
|
---|
| 402 | ofstream samplesOut(fileName, ios::binary);
|
---|
| 403 | if (!samplesOut.is_open())
|
---|
| 404 | return false;
|
---|
| 405 |
|
---|
| 406 | for (it = samples.begin(); it != it_end; ++ it)
|
---|
| 407 | {
|
---|
| 408 | VssRay *ray = *it;
|
---|
| 409 | Vector3 origin(ray->GetOrigin());
|
---|
| 410 | Vector3 termination(ray->GetTermination());
|
---|
| 411 |
|
---|
| 412 | int sourceid = ray->mOriginObject ? ray->mOriginObject->mId : -1;
|
---|
| 413 | int termid = ray->mTerminationObject ? ray->mTerminationObject->mId : -1;
|
---|
| 414 |
|
---|
| 415 | samplesOut.write(reinterpret_cast<char *>(&origin), sizeof(Vector3));
|
---|
| 416 | samplesOut.write(reinterpret_cast<char *>(&termination), sizeof(Vector3));
|
---|
| 417 | samplesOut.write(reinterpret_cast<char *>(&sourceid), sizeof(int));
|
---|
| 418 | samplesOut.write(reinterpret_cast<char *>(&termid), sizeof(int));
|
---|
| 419 | }
|
---|
| 420 | #endif
|
---|
[490] | 421 | samplesOut.close();
|
---|
| 422 | return true;
|
---|
| 423 | }
|
---|
[563] | 424 |
|
---|
| 425 |
|
---|
| 426 |
|
---|
| 427 | bool
|
---|
| 428 | Preprocessor::GenerateRays(
|
---|
| 429 | const int number,
|
---|
| 430 | const int sampleType,
|
---|
| 431 | SimpleRayContainer &rays
|
---|
| 432 | )
|
---|
| 433 | {
|
---|
| 434 | Vector3 origin, direction;
|
---|
[576] | 435 | int startSize = rays.size();
|
---|
| 436 | for (int i=0; rays.size() - startSize < number; i++) {
|
---|
[563] | 437 | // now get the direction
|
---|
| 438 | switch (sampleType) {
|
---|
| 439 | case OBJECT_BASED_DISTRIBUTION: {
|
---|
[576] | 440 | mViewCellsManager->GetViewPoint(origin);
|
---|
[563] | 441 | Vector3 point;
|
---|
| 442 | Vector3 normal;
|
---|
| 443 | int i = RandomValue(0, mObjects.size() - 1);
|
---|
| 444 | Intersectable *object = mObjects[i];
|
---|
| 445 | object->GetRandomSurfacePoint(point, normal);
|
---|
| 446 | direction = point - origin;
|
---|
| 447 | }
|
---|
| 448 | break;
|
---|
[576] | 449 | case OBJECT_DIRECTION_BASED_DISTRIBUTION: {
|
---|
| 450 | int i = RandomValue(0, mObjects.size() - 1);
|
---|
| 451 | Intersectable *object = mObjects[i];
|
---|
| 452 | Vector3 normal;
|
---|
| 453 | object->GetRandomSurfacePoint(origin, normal);
|
---|
| 454 | direction = UniformRandomVector(normal);
|
---|
| 455 | origin += 0.1f*direction;
|
---|
| 456 | }
|
---|
| 457 | break;
|
---|
[563] | 458 | case DIRECTION_BASED_DISTRIBUTION:
|
---|
[576] | 459 | mViewCellsManager->GetViewPoint(origin);
|
---|
[563] | 460 | direction = UniformRandomVector();
|
---|
| 461 | break;
|
---|
| 462 | case DIRECTION_BOX_BASED_DISTRIBUTION: {
|
---|
[576] | 463 | mViewCellsManager->GetViewPoint(origin);
|
---|
[563] | 464 | float alpha = RandomValue(0.0f, 2*M_PI);
|
---|
| 465 | float beta = RandomValue(-M_PI/2, M_PI/2);
|
---|
| 466 | direction = VssRay::GetDirection(alpha, beta);
|
---|
| 467 | break;
|
---|
| 468 | }
|
---|
| 469 | case SPATIAL_BOX_BASED_DISTRIBUTION:
|
---|
[576] | 470 | mViewCellsManager->GetViewPoint(origin);
|
---|
[563] | 471 | direction = mKdTree->GetBox().GetRandomPoint() - origin;
|
---|
| 472 | break;
|
---|
| 473 | default:
|
---|
| 474 | // unsuported distribution type
|
---|
| 475 | return false;
|
---|
| 476 | }
|
---|
| 477 | // $$ jb the pdf is yet not correct for all sampling methods!
|
---|
| 478 | float pdf = 1.0f;
|
---|
| 479 | float c = Magnitude(direction);
|
---|
| 480 | if (c > Limits::Small) {
|
---|
| 481 | direction*=1.0f/c;
|
---|
| 482 | rays.AddRay(SimpleRay(origin, direction, pdf));
|
---|
| 483 | }
|
---|
| 484 | }
|
---|
| 485 | return true;
|
---|
| 486 | }
|
---|