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

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