source: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp @ 1233

Revision 1233, 19.8 KB checked in by mattausch, 18 years ago (diff)
Line 
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"
8#include "ViewCellsManager.h"
9#include "ViewCellBsp.h"
10#include "VspBspTree.h"
11#include "RenderSimulator.h"
12#include "GlRenderer.h"
13#include "PlyParser.h"
14#include "SamplingStrategy.h"
15#include "VspTree.h"
16#include "OspTree.h"
17#include "ObjParser.h"
18#ifdef INTEL_COMPILER
19#include "ArchModeler2MLRT.hxx"
20#endif
21
22namespace GtpVisibilityPreprocessor {
23
24const static bool ADDITIONAL_GEOMETRY_HACK = false;
25
26//Preprocessor *preprocessor;
27
28
29// HACK: Artificially modify scene to watch rendercost changes
30static void AddGeometry(SceneGraph *scene)
31{
32        scene->mRoot->UpdateBox();
33
34        AxisAlignedBox3 sceneBox = scene->GetBox();
35
36        int n = 200;
37
38        if (0){
39        // form grid of boxes
40        for (int i = 0; i < n; ++ i)
41        {
42                for (int j = 0; j < n; ++ j)
43                {
44                        const Vector3 scale2((float)j * 0.8f / n + 0.1f,  0.05f, (float)i * 0.8f  / (float)n + 0.1f);
45               
46                        const Vector3 pt2 = sceneBox.Min() + scale2 * (sceneBox.Max() - sceneBox.Min());
47               
48                        const Vector3 boxSize = sceneBox.Size() * Vector3(0.0025f, 0.01f, 0.0025f);
49                        AxisAlignedBox3 box(pt2, pt2 + boxSize);
50                        Mesh *mesh = CreateMeshFromBox(box);
51
52                        mesh->Preprocess();
53               
54                        MeshInstance *mi = new MeshInstance(mesh);
55                        scene->mRoot->mGeometry.push_back(mi);
56                }
57        }
58
59        for (int i = 0; i < n; ++ i)
60        {
61                for (int j = 0; j < n; ++ j)
62                {
63                        const Vector3 scale2(0.15f, (float)j * 0.8f / n + 0.1f, (float)i * 0.8f  / (float)n + 0.1f);
64               
65                        Vector3 pt2 = sceneBox.Min() + scale2 * (sceneBox.Max() - sceneBox.Min());
66               
67                        Vector3 boxSize = sceneBox.Size() * Vector3(0.0025f, 0.01f, 0.0025f);
68                        AxisAlignedBox3 box(pt2, pt2 + boxSize);
69                        Mesh *mesh = CreateMeshFromBox(box);
70
71                        mesh->Preprocess();
72               
73                        MeshInstance *mi = new MeshInstance(mesh);
74                        scene->mRoot->mGeometry.push_back(mi);
75                }
76        }
77
78        for (int i = 0; i < n; ++ i)
79        {
80                const Vector3 scale2(2, 0.2f, (float)i * 0.8f  / (float)n + 0.1f);
81               
82                Vector3 pt2 = sceneBox.Min() + scale2 * (sceneBox.Max() - sceneBox.Min());
83               
84                //Vector3 boxSize = sceneBox.Size() * Vector3(0.0025, 0.01, 0.0025);
85                Vector3 boxSize = sceneBox.Size() * Vector3(0.005f, 0.02f, 0.005f);
86
87                AxisAlignedBox3 box(pt2 + 0.1f, pt2 + boxSize);
88                Mesh *mesh = CreateMeshFromBox(box);
89
90                mesh->Preprocess();
91               
92                MeshInstance *mi = new MeshInstance(mesh);
93                scene->mRoot->mGeometry.push_back(mi);
94        }
95       
96        scene->mRoot->UpdateBox();
97        }
98               
99        if (1)
100        {
101                // plane separating view space regions
102                const Vector3 scale(1.0f, 0.0, 0);
103
104                Vector3 pt = sceneBox.Min() + scale * (sceneBox.Max() - sceneBox.Min());
105
106                Plane3 cuttingPlane(Vector3(1, 0, 0), pt);
107                Mesh *planeMesh = new Mesh();
108               
109                Polygon3 *poly = sceneBox.CrossSection(cuttingPlane);
110                IncludePolyInMesh(*poly, *planeMesh);
111               
112                planeMesh->Preprocess();
113               
114                MeshInstance *planeMi = new MeshInstance(planeMesh);
115                scene->mRoot->mGeometry.push_back(planeMi);
116        }       
117}
118
119
120Preprocessor::Preprocessor():
121mKdTree(NULL),
122mBspTree(NULL),
123mVspBspTree(NULL),
124mViewCellsManager(NULL),
125mRenderSimulator(NULL)
126{
127        Environment::GetSingleton()->GetBoolValue("Preprocessor.useGlRenderer", mUseGlRenderer);
128 
129        // renderer will be constructed when the scene graph and viewcell manager will be known
130        renderer = NULL;
131 
132        Environment::GetSingleton()->GetBoolValue("Preprocessor.useGlDebugger", mUseGlDebugger);
133        Environment::GetSingleton()->GetBoolValue("Preprocessor.loadPolygonsAsMeshes", mLoadPolygonsAsMeshes);
134        Environment::GetSingleton()->GetBoolValue("Preprocessor.quitOnFinish", mQuitOnFinish);
135        Environment::GetSingleton()->GetBoolValue("Preprocessor.computeVisibility", mComputeVisibility);
136        Environment::GetSingleton()->GetBoolValue("Preprocessor.detectEmptyViewSpace", mDetectEmptyViewSpace);
137        Environment::GetSingleton()->GetBoolValue("Preprocessor.exportVisibility", mExportVisibility );
138        Environment::GetSingleton()->GetIntValue("Preprocessor.rayCastMethod", mRayCastMethod);
139
140        char buffer[256];
141        Environment::GetSingleton()->GetStringValue("Preprocessor.visibilityFile",  buffer);
142        mVisibilityFileName = buffer;
143        Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilityFilter", mApplyVisibilityFilter );
144        Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilitySpatialFilter",
145                                                          mApplyVisibilitySpatialFilter );
146        Environment::GetSingleton()->GetFloatValue("Preprocessor.visibilityFilterWidth", mVisibilityFilterWidth);
147
148        Debug << "detect empty view space=" << mDetectEmptyViewSpace << endl;
149        Debug << "load polygons as meshes: " << mLoadPolygonsAsMeshes << endl;
150}
151
152
153Preprocessor::~Preprocessor()
154{
155  cout << "cleaning up" << endl;
156
157  cout << "Deleting view cells manager ... \n";
158  DEL_PTR(mViewCellsManager);
159  cout << "done.\n";
160
161  cout << "Deleting bsp tree ... \n";
162  DEL_PTR(mBspTree);
163  cout << "done.\n";
164
165  cout << "Deleting kd tree...\n";
166  DEL_PTR(mKdTree);
167  cout << "done.\n";
168 
169  cout << "Deleting vsp tree...\n";
170  DEL_PTR(mVspTree);
171  cout << "done.\n";
172
173  cout << "Deleting osp tree...\n";
174  DEL_PTR(mOspTree);
175  cout << "done.\n";
176
177  cout << "Deleting vspbsp tree...\n";
178  DEL_PTR(mVspBspTree);
179  cout << "done.\n";
180
181   cout << "Deleting scene graph...\n";
182  DEL_PTR(mSceneGraph);
183  cout << "done.\n";
184
185  DEL_PTR(mRenderSimulator);
186  DEL_PTR(renderer);
187}
188
189int
190SplitFilenames(const string str, vector<string> &filenames)
191{
192        int pos = 0;
193
194        while(1) {
195                int npos = (int)str.find(';', pos);
196               
197                if (npos < 0 || npos - pos < 1)
198                        break;
199                filenames.push_back(string(str, pos, npos - pos));
200                pos = npos + 1;
201        }
202       
203        filenames.push_back(string(str, pos, str.size() - pos));
204        return (int)filenames.size();
205}
206
207
208bool
209Preprocessor::LoadScene(const string filename)
210{
211        // use leaf nodes of the original spatial hierarchy as occludees
212        mSceneGraph = new SceneGraph;
213 
214        Parser *parser;
215        vector<string> filenames;
216        int files = SplitFilenames(filename, filenames);
217        cout << "number of input files: " << files << endl;
218        bool result = false;
219        if (files == 1) {
220               
221                if (strstr(filename.c_str(), ".x3d"))
222                  parser = new X3dParser;
223                else
224                  if (strstr(filename.c_str(), ".ply") || strstr(filename.c_str(), ".plb"))
225                        parser = new PlyParser;
226                  else if (strstr(filename.c_str(), ".obj"))
227                          parser = new ObjParser;
228                  else
229                          parser = new UnigraphicsParser;
230
231                cout<<filename<<endl;
232
233                if (mRayCastMethod == Preprocessor::INTEL_RAYCASTER)
234                        result = parser->ParseFile(filename, &mSceneGraph->mRoot, mLoadPolygonsAsMeshes, &mFaceParents);
235                else
236                        result = parser->ParseFile(filename, &mSceneGraph->mRoot, mLoadPolygonsAsMeshes);
237
238                delete parser;
239
240        } else {
241                // root for different files
242                mSceneGraph->mRoot = new SceneGraphNode;
243                for (int i= 0; i < filenames.size(); i++) {
244                        if (strstr(filenames[i].c_str(), ".x3d"))
245                                parser = new X3dParser;
246                        else
247                                parser = new UnigraphicsParser;
248                                               
249                        SceneGraphNode *node;
250                        if (parser->ParseFile(filenames[i], &node)) {
251                                mSceneGraph->mRoot->mChildren.push_back(node);
252                                // at least one file parsed
253                                result = true;
254                        }
255                        delete parser;
256                }
257        }
258       
259
260        if (result)
261        {
262                // HACK
263                if (ADDITIONAL_GEOMETRY_HACK)
264                        AddGeometry(mSceneGraph);
265               
266                mSceneGraph->AssignObjectIds();
267       
268                int intersectables, faces;
269                mSceneGraph->GetStatistics(intersectables, faces);
270       
271                cout<<filename<<" parsed successfully."<<endl;
272                cout<<"#NUM_OBJECTS (Total numner of objects)\n"<<intersectables<<endl;
273                cout<<"#NUM_FACES (Total numner of faces)\n"<<faces<<endl;
274                mSceneGraph->CollectObjects(&mObjects);
275                mSceneGraph->mRoot->UpdateBox();
276
277                if (0)
278                {
279                        Exporter *exporter = Exporter::GetExporter("testload.x3d");
280
281                        if (exporter)
282                        {
283                                exporter->ExportGeometry(mObjects);
284                                delete exporter;
285                        }
286                }
287        }
288       
289       
290        return result;
291}
292
293bool
294Preprocessor::ExportPreprocessedData(const string filename)
295{
296 
297  mViewCellsManager->ExportViewCells(filename, true, mObjects);
298 
299  return true;
300}
301
302bool
303Preprocessor::PostProcessVisibility()
304{
305 
306  if (mApplyVisibilityFilter || mApplyVisibilitySpatialFilter) {
307        cout<<"Applying visibility filter ...";
308        cout<<"filter width = " << mVisibilityFilterWidth << endl;
309       
310        if (!mViewCellsManager)
311          return false;
312       
313        mViewCellsManager->ApplyFilter(mKdTree,
314                                                                   mApplyVisibilityFilter ? mVisibilityFilterWidth : -1.0f,
315                                                                   mApplyVisibilitySpatialFilter ? mVisibilityFilterWidth : -1.0f);
316        cout << "done." << endl;
317  }
318 
319  // export the preprocessed information to a file
320  if (mExportVisibility)
321        ExportPreprocessedData(mVisibilityFileName);
322 
323  return true;
324}
325
326
327bool
328Preprocessor::BuildKdTree()
329{
330  mKdTree = new KdTree;
331  // add mesh instances of the scene graph to the root of the tree
332  KdLeaf *root = (KdLeaf *)mKdTree->GetRoot();
333  mSceneGraph->CollectObjects(&root->mObjects);
334 
335  long startTime = GetTime();
336
337  cout << "building kd tree ... " << endl;
338  mKdTree->Construct();
339  cout << "construction finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs " << endl;
340  return true;
341}
342
343void
344Preprocessor::KdTreeStatistics(ostream &s)
345{
346  s<<mKdTree->GetStatistics();
347}
348
349void
350Preprocessor::BspTreeStatistics(ostream &s)
351{
352        s << mBspTree->GetStatistics();
353}
354
355bool
356Preprocessor::Export( const string filename,
357                                          const bool scene,
358                                          const bool kdtree,
359                                          const bool bsptree
360                                          )
361{
362  Exporter *exporter = Exporter::GetExporter(filename);
363       
364  if (exporter) {
365    if (scene)
366      exporter->ExportScene(mSceneGraph->mRoot);
367
368    if (kdtree) {
369      exporter->SetWireframe();
370      exporter->ExportKdTree(*mKdTree);
371    }
372
373        if (bsptree) {
374                //exporter->SetWireframe();
375                exporter->ExportBspTree(*mBspTree);
376        }
377
378    delete exporter;
379    return true;
380  }
381
382  return false;
383}
384
385
386bool Preprocessor::PrepareViewCells()
387{
388        //-- parse view cells construction method
389        Environment::GetSingleton()->GetBoolValue("ViewCells.loadFromFile", mLoadViewCells);
390        char buf[100];
391       
392        if (mLoadViewCells)
393        {       
394                Environment::GetSingleton()->GetStringValue("ViewCells.filename", buf);
395                mViewCellsManager = ViewCellsManager::LoadViewCells(buf, &mObjects, true);
396        }
397        else
398        {
399                //-- parse type of view cell container
400                Environment::GetSingleton()->GetStringValue("ViewCells.type", buf);             
401            mViewCellsManager = CreateViewCellsManager(buf);
402
403                // default view space is the extent of the scene
404                mViewCellsManager->SetViewSpaceBox(mSceneGraph->GetBox());
405
406
407        }
408       
409        //-- parameters for render heuristics evaluation
410        float objRenderCost = 0, vcOverhead = 0, moveSpeed = 0;
411
412        Environment::GetSingleton()->GetFloatValue("Simulation.objRenderCost",objRenderCost);
413        Environment::GetSingleton()->GetFloatValue("Simulation.vcOverhead", vcOverhead);
414        Environment::GetSingleton()->GetFloatValue("Simulation.moveSpeed", moveSpeed);
415       
416        mRenderSimulator =
417                new RenderSimulator(mViewCellsManager, objRenderCost, vcOverhead, moveSpeed);
418
419        mViewCellsManager->SetRenderer(mRenderSimulator);
420
421
422        if (mUseGlRenderer || mUseGlDebugger)
423        {
424                // NOTE: render texture should be power of 2 and square
425                // renderer must be initialised
426                // $$matt
427//              renderer = new GlRendererBuffer(1024, 768, mSceneGraph, mViewCellsManager, mKdTree);
428                //              renderer->makeCurrent();
429               
430        }
431       
432        return true;
433}
434
435
436ViewCellsManager *Preprocessor::CreateViewCellsManager(const char *name)
437{
438        if (strcmp(name, "kdTree") == 0)
439        {
440                mViewCellsManager = new KdViewCellsManager(mKdTree);
441        }
442        else if (strcmp(name, "bspTree") == 0)
443        {
444                Debug << "view cell type: Bsp" << endl;
445
446                mBspTree = new BspTree();
447                mViewCellsManager = new BspViewCellsManager(mBspTree);
448        }
449        else if (strcmp(name, "vspBspTree") == 0)
450        {
451                Debug << "view cell type: VspBsp" << endl;
452
453                mVspBspTree = new VspBspTree();
454                mViewCellsManager = new VspBspViewCellsManager(mVspBspTree);
455        }
456        else if (strcmp(name, "vspOspTree") == 0)
457        {
458                mVspTree = new VspTree();
459                mOspTree = new OspTree();
460               
461                // HACK for testing if per kd evaluation works!!
462                mOspTree = new OspTree(*mKdTree);
463
464                mViewCellsManager = new VspOspViewCellsManager(mVspTree, mOspTree);
465        }
466        else if (strcmp(name, "sceneDependent") == 0)
467        {
468                Debug << "view cell type: Bsp" << endl;
469
470                //TODO
471                mBspTree = new BspTree();
472                mViewCellsManager = new BspViewCellsManager(mBspTree);
473        }
474        else
475        {
476                cerr << "Wrong view cells type " << name << "!!!" << endl;
477                exit(1);
478        }
479
480        return mViewCellsManager;
481}
482
483
484// use ascii format to store rays
485#define USE_ASCII 0
486
487
488static inline bool ilt(Intersectable *obj1, Intersectable *obj2)
489{
490        return obj1->mId < obj2->mId;
491}
492
493
494bool Preprocessor::LoadKdTree()
495{
496        return true;
497}
498
499bool Preprocessor::ExportKdTree()
500{
501        return true;
502}
503
504
505bool Preprocessor::LoadSamples(VssRayContainer &samples,
506                                                           ObjectContainer &objects) const
507{
508        std::stable_sort(objects.begin(), objects.end(), ilt);
509        char fileName[100];
510        Environment::GetSingleton()->GetStringValue("Preprocessor.samplesFilename", fileName);
511       
512    Vector3 origin, termination;
513        // HACK: needed only for lower_bound algorithm to find the
514        // intersected objects
515        MeshInstance sObj(NULL);
516        MeshInstance tObj(NULL);
517
518#if USE_ASCII
519        ifstream samplesIn(fileName);
520        if (!samplesIn.is_open())
521                return false;
522
523        string buf;
524        while (!(getline(samplesIn, buf)).eof())
525        {
526                sscanf(buf.c_str(), "%f %f %f %f %f %f %d %d",
527                           &origin.x, &origin.y, &origin.z,
528                           &termination.x, &termination.y, &termination.z,
529                           &(sObj.mId), &(tObj.mId));
530               
531                Intersectable *sourceObj = NULL;
532                Intersectable *termObj = NULL;
533               
534                if (sObj.mId >= 0)
535                {
536                        ObjectContainer::iterator oit =
537                                lower_bound(objects.begin(), objects.end(), &sObj, ilt);
538                        sourceObj = *oit;
539                }
540               
541                if (tObj.mId >= 0)
542                {
543                        ObjectContainer::iterator oit =
544                                lower_bound(objects.begin(), objects.end(), &tObj, ilt);
545                        termObj = *oit;
546                }
547
548                samples.push_back(new VssRay(origin, termination, sourceObj, termObj));
549        }
550#else
551        ifstream samplesIn(fileName, ios::binary);
552        if (!samplesIn.is_open())
553                return false;
554
555        while (1)
556        {
557                 samplesIn.read(reinterpret_cast<char *>(&origin), sizeof(Vector3));
558                 samplesIn.read(reinterpret_cast<char *>(&termination), sizeof(Vector3));
559                 samplesIn.read(reinterpret_cast<char *>(&(sObj.mId)), sizeof(int));
560                 samplesIn.read(reinterpret_cast<char *>(&(tObj.mId)), sizeof(int));
561               
562                 if (samplesIn.eof())
563                        break;
564
565                Intersectable *sourceObj = NULL;
566                Intersectable *termObj = NULL;
567               
568                if (sObj.mId >= 0)
569                {
570                        ObjectContainer::iterator oit =
571                                lower_bound(objects.begin(), objects.end(), &sObj, ilt);
572                        sourceObj = *oit;
573                }
574               
575                if (tObj.mId >= 0)
576                {
577                        ObjectContainer::iterator oit =
578                                lower_bound(objects.begin(), objects.end(), &tObj, ilt);
579                        termObj = *oit;
580                }
581
582                samples.push_back(new VssRay(origin, termination, sourceObj, termObj));
583        }
584
585#endif
586        samplesIn.close();
587
588        return true;
589}
590
591
592bool Preprocessor::ExportSamples(const VssRayContainer &samples) const
593{
594        char fileName[100];
595        Environment::GetSingleton()->GetStringValue("Preprocessor.samplesFilename", fileName);
596       
597
598        VssRayContainer::const_iterator it, it_end = samples.end();
599       
600#if USE_ASCII
601        ofstream samplesOut(fileName);
602        if (!samplesOut.is_open())
603                return false;
604
605        for (it = samples.begin(); it != it_end; ++ it)
606        {
607                VssRay *ray = *it;
608                int sourceid = ray->mOriginObject ? ray->mOriginObject->mId : -1;               
609                int termid = ray->mTerminationObject ? ray->mTerminationObject->mId : -1;       
610
611                samplesOut << ray->GetOrigin().x << " " << ray->GetOrigin().y << " " << ray->GetOrigin().z << " "
612                                   << ray->GetTermination().x << " " << ray->GetTermination().y << " " << ray->GetTermination().z << " "
613                                   << sourceid << " " << termid << "\n";
614        }
615#else
616        ofstream samplesOut(fileName, ios::binary);
617        if (!samplesOut.is_open())
618                return false;
619
620        for (it = samples.begin(); it != it_end; ++ it)
621        {       
622                VssRay *ray = *it;
623                Vector3 origin(ray->GetOrigin());
624                Vector3 termination(ray->GetTermination());
625               
626                int sourceid = ray->mOriginObject ? ray->mOriginObject->mId : -1;               
627                int termid = ray->mTerminationObject ? ray->mTerminationObject->mId : -1;               
628
629                samplesOut.write(reinterpret_cast<char *>(&origin), sizeof(Vector3));
630                samplesOut.write(reinterpret_cast<char *>(&termination), sizeof(Vector3));
631                samplesOut.write(reinterpret_cast<char *>(&sourceid), sizeof(int));
632                samplesOut.write(reinterpret_cast<char *>(&termid), sizeof(int));
633    }
634#endif
635        samplesOut.close();
636
637        return true;
638}
639
640#if 0 // matt: implemented interface samplestrategy
641bool
642Preprocessor::GenerateRays(
643                                                   const int number,
644                                                   const int sampleType,
645                                                   SimpleRayContainer &rays
646                                                   )
647{
648  Vector3 origin, direction;
649  int startSize = (int)rays.size();
650  for (int i=0; (int)rays.size() - startSize  < number; i ++) {
651        // now get the direction
652        switch (sampleType) {
653        case OBJECT_BASED_DISTRIBUTION: {
654          mViewCellsManager->GetViewPoint(origin);
655          Vector3 point;
656          Vector3 normal;
657          int i = RandomValue(0, mObjects.size() - 1);
658          Intersectable *object = mObjects[i];
659          object->GetRandomSurfacePoint(point, normal);
660          direction = point - origin;
661        }
662          break;
663        case OBJECT_DIRECTION_BASED_DISTRIBUTION: {
664          int i = RandomValue(0, mObjects.size() - 1);
665          Intersectable *object = mObjects[i];
666          Vector3 normal;
667          object->GetRandomSurfacePoint(origin, normal);
668          direction = UniformRandomVector(normal);
669          origin += 0.1f*direction;
670        }
671          break;
672        case DIRECTION_BASED_DISTRIBUTION:
673          mViewCellsManager->GetViewPoint(origin);
674          direction = UniformRandomVector();
675          break;
676        case DIRECTION_BOX_BASED_DISTRIBUTION: {
677          mViewCellsManager->GetViewPoint(origin);
678          float alpha = RandomValue(0.0f, 2*M_PI);
679          float beta = RandomValue(-M_PI/2, M_PI/2);
680          direction = VssRay::GetDirection(alpha, beta);
681          break;
682        }
683        case SPATIAL_BOX_BASED_DISTRIBUTION:
684          mViewCellsManager->GetViewPoint(origin);
685          direction = mKdTree->GetBox().GetRandomPoint() - origin;
686          break;
687        default:
688          // unsuported distribution type
689          return false;
690        }
691        // $$ jb the pdf is yet not correct for all sampling methods!
692        float pdf = 1.0f;
693        float c = Magnitude(direction);
694        if (c > Limits::Small) {
695          direction*=1.0f/c;
696          rays.AddRay(SimpleRay(origin, direction, pdf));
697        }
698  }
699  return true;
700}
701#endif
702bool Preprocessor::GenerateRays(const int number,
703                                                                const int sampleType,
704                                                                SimpleRayContainer &rays)
705{
706        Vector3 origin, direction;
707       
708        const int startSize = (int)rays.size();
709        SamplingStrategy *strategy = GenerateSamplingStrategy(sampleType);
710
711        if (!strategy)
712                return false;
713
714        for (int i=0; (int)rays.size() - startSize < number; ++ i)
715        {
716                SimpleRay newRay;
717                bool success = strategy->GenerateSample(newRay);
718
719                if (success)
720                        rays.AddRay(newRay);
721        }
722
723        delete strategy;
724
725    return true;
726}
727
728
729SamplingStrategy *Preprocessor::GenerateSamplingStrategy(const int strategyId) const
730{
731        switch (strategyId)
732        {
733        case OBJECT_BASED_DISTRIBUTION:
734                return new ObjectBasedDistribution(*this);
735        case OBJECT_DIRECTION_BASED_DISTRIBUTION:
736                return new ObjectDirectionBasedDistribution(*this);
737        case DIRECTION_BASED_DISTRIBUTION:
738                return new DirectionBasedDistribution(*this);
739        case DIRECTION_BOX_BASED_DISTRIBUTION:
740                return new DirectionBoxBasedDistribution(*this);
741        case SPATIAL_BOX_BASED_DISTRIBUTION:
742                return new SpatialBoxBasedDistribution(*this);
743        //case OBJECTS_INTERIOR_DISTRIBUTION:
744        //      return new ObjectsInteriorDistribution(*this);
745        default: // no valid strategy
746                return NULL;
747        }
748
749        // should never come here
750        return NULL;
751}
752
753
754bool Preprocessor::InitRayCast(const string externKdTree)
755{
756        switch (mRayCastMethod) // use intel ray tracing
757        {
758        case INTEL_RAYCASTER:
759#ifdef INTEL_COMPILER
760                return mlrtaLoadAS(externKdTree.c_str());
761#endif
762        case INTERNAL_RAYCASTER:
763        default:
764                break;
765        }
766
767        return true;
768}
769
770}
Note: See TracBrowser for help on using the repository browser.