Changeset 2575 for GTP/trunk/Lib


Ignore:
Timestamp:
01/03/08 15:53:44 (17 years ago)
Author:
bittner
Message:

big merge: preparation for havran ray caster, check if everything works

Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
73 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.cpp

    r2332 r2575  
    11 
    2 // GOLEM library 
    3 #include <assert.h> 
    42#include <iostream> 
    53#include "AxisAlignedBox3.h" 
     
    108#include "Triangle3.h" 
    119#include "VssRay.h" 
     10 
     11 
     12 
     13#include <cassert> 
    1214 
    1315 
     
    210212int 
    211213AxisAlignedBox3::ComputeMinMaxT(const Ray &ray, 
    212                                                                 float *tmin, 
    213                                                                 float *tmax) const 
     214                                float *tmin, 
     215                                float *tmax) const 
    214216{ 
    215217  float minx, maxx, miny, maxy, minz, maxz; 
     
    302304int 
    303305AxisAlignedBox3::ComputeMinMaxT(const Ray &ray, 
    304                                                                 float *tmin, 
    305                                                                 float *tmax) const 
     306                                float *tmin, 
     307                                float *tmax) const 
    306308{ 
    307309  const float dirEps = 1e-8f; 
     
    398400// the bounding box and 0 if it does not. 
    399401int AxisAlignedBox3::ComputeMinMaxT(const Ray &ray, float *tmin, float *tmax, 
    400                                                                         EFaces &entryFace, EFaces &exitFace) const 
     402                                    EFaces &entryFace, EFaces &exitFace) const 
    401403{ 
    402404  float minx, maxx, miny, maxy, minz, maxz; 
     
    18401842int 
    18411843AxisAlignedBox3::ComputeMinMaxT(const Vector3 &origin, 
    1842                                                                 const Vector3 &direction, 
    1843                                                                 float *tmin, 
    1844                                                                 float *tmax) const 
    1845 { 
    1846  
     1844                                const Vector3 &direction, 
     1845                                float *tmin, 
     1846                                float *tmax) const 
     1847{ 
    18471848  register float minx, maxx; 
    18481849 
     
    22352236 
    22362237 
     2238void AxisAlignedBox3::EnlargeToMinSize() 
     2239{ 
     2240  const float epsMin = 1e-7; 
     2241  const float epsAdd = 1e-6; 
     2242  const float epsMul = 1.000005; 
     2243  float dir = mMax.x - mMin.x; 
     2244  assert(dir >= 0.f); 
     2245  if (dir < epsMin) { 
     2246    if (mMax.x > 0) { 
     2247      mMax.x *= epsMul; 
     2248      mMax.x += epsAdd; 
     2249    } 
     2250    else { 
     2251      mMin.x *= epsMul; 
     2252      mMin.x -= epsAdd; 
     2253    } 
     2254    assert(mMin.x < mMax.x); 
     2255  } 
     2256  dir = mMax.y - mMin.y; 
     2257  assert(dir >= 0.f); 
     2258  if (dir < epsMin) { 
     2259    if (mMax.y > 0) { 
     2260      mMax.y *= epsMul; 
     2261      mMax.y += epsAdd; 
     2262    } 
     2263    else { 
     2264      mMin.y *= epsMul; 
     2265      mMin.y -= epsAdd; 
     2266    } 
     2267    assert(mMin.y < mMax.y); 
     2268  } 
     2269  dir = mMax.z - mMin.z; 
     2270  assert(dir >= 0.f); 
     2271  if (dir < epsMin) { 
     2272    if (mMax.z > 0) { 
     2273      mMax.z *= epsMul; 
     2274      mMax.z += epsAdd; 
     2275    } 
     2276    else { 
     2277      mMin.z *= epsMul; 
     2278      mMin.z -= epsAdd; 
     2279    } 
     2280    assert(mMin.z < mMax.z); 
     2281  } 
     2282} 
     2283 
    22372284void AxisAlignedBox3::SetMin(const Vector3 &v)  
    22382285{ 
    2239         mMin = v; 
     2286  mMin = v; 
    22402287} 
    22412288 
     
    22432290void AxisAlignedBox3::SetMax(const Vector3 &v)  
    22442291{ 
    2245         mMax = v; 
     2292  mMax = v; 
    22462293} 
    22472294 
  • GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.h

    r2176 r2575  
    6161  void Enlarge (const Vector3 &v); 
    6262 
     63  void EnlargeToMinSize(); 
     64   
    6365  void SetMin(const Vector3 &v); 
    6466 
     
    232234   
    233235  int  ComputeMinMaxT(const Vector3 &origin, 
    234                                           const Vector3 &direction, 
    235                                           float *tmin, 
    236                                           float *tmax) const; 
     236                      const Vector3 &direction, 
     237                      float *tmin, 
     238                      float *tmax) const; 
    237239         
    238240  // Compute tmin and tmax for a ray, whenever required .. need not pierce box 
     
    241243  // Compute tmin and tmax for a ray, whenever required .. need not pierce box 
    242244  int ComputeMinMaxT(const Ray &ray, 
    243                                         float *tmin, 
    244                                         float *tmax, 
    245                                         EFaces &entryFace, 
    246                                         EFaces &exitFace) const; 
     245                    float *tmin, 
     246                    float *tmax, 
     247                    EFaces &entryFace, 
     248                    EFaces &exitFace) const; 
    247249   
    248250  // If a ray pierces the box .. returns 1, otherwise 0. 
     
    251253  // computes the signed distances for case: tmin < tmax and tmax > 0 
    252254  int GetMinMaxT(const Ray &ray, float *tmin, float *tmax, 
    253                                 EFaces &entryFace, EFaces &exitFace) const; 
     255                EFaces &entryFace, EFaces &exitFace) const; 
    254256   
    255257  // Writes a brief description of the object, indenting by the given 
  • GTP/trunk/Lib/Vis/Preprocessing/src/BitVectorPvs.h

    r2530 r2575  
    7979class BitVectorPvs//: public PvsBase<T> 
    8080{ 
    81         template<typename T, typename S> friend class BitVectorPvsIterator; 
     81  template<typename T1, typename S1> friend class BitVectorPvsIterator; 
    8282 
    8383public: 
     
    121121        bool Find(T sample); 
    122122 
    123         typename BitVectorPvsIterator<T, S> GetIterator() const; 
     123        BitVectorPvsIterator<T, S> GetIterator() const; 
    124124 
    125125        /** Compute continuous PVS difference  
     
    145145        void MergeInPlace(const BitVectorPvs<T, S> &a) 
    146146        { 
    147                 cerr << "bitvector: merge in place not implemented yet" << endl; 
     147          std::cerr << "bitvector: merge in place not implemented yet" 
     148                    << std::endl; 
    148149        } 
    149150 
     
    167168        int SubtractPvs(const BitVectorPvs<T, S> &pvs) 
    168169        { 
    169                 cerr << "not yet implemented" << endl; 
    170                 return 0; 
     170          std::cerr << "not yet implemented" << std::endl; 
     171          return 0; 
    171172        } 
    172173 
     
    177178                                                                                float &pvsEnlargement) 
    178179        { 
    179                 cerr << "not yet implemented" << endl; 
     180          std::cerr << "not yet implemented" << std::endl; 
    180181        } 
    181182 
     
    284285 
    285286template <typename T, typename S> 
    286 void BitVectorPvs<T, S>::Clear(const bool trim = true) 
     287void BitVectorPvs<T, S>::Clear(const bool trim) 
    287288{ 
    288289        bit_vector::iterator bit, bit_end = mEntries.end(); 
     
    309310 
    310311template <typename T, typename S> 
    311 typename BitVectorPvsIterator<T, S> BitVectorPvs<T, S>::GetIterator() const 
    312 { 
    313         BitVectorPvsIterator<T, S> pit(mEntries.begin(), mEntries.end()); 
    314  
    315         return pit; 
     312BitVectorPvsIterator<T, S> BitVectorPvs<T, S>::GetIterator() const 
     313{ 
     314  return BitVectorPvsIterator<T, S>(mEntries.begin(), mEntries.end()); 
    316315} 
    317316 
  • GTP/trunk/Lib/Vis/Preprocessing/src/BoostPreprocessorThread.cpp

    r1867 r2575  
    44#include "SceneGraph.h" 
    55#include "Preprocessor.h" 
    6 #include <boost/thread/thread.hpp> 
     6 
     7// ??????????????? commented by VH ???????????? 
     8//#include <boost/thread/thread.hpp> 
    79 
    810namespace GtpVisibilityPreprocessor { 
    911 
    1012 
     13#ifdef THREADS1 
     14   
    1115BoostPreprocessorThread::BoostPreprocessorThread(Preprocessor *p): 
    1216PreprocessorThread(p), mThread(NULL) 
     
    5155} 
    5256 
     57#endif // THREADS1 
     58 
     59   
    5360} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp

    r2560 r2575  
    525525        //TestEvaluation(sc); 
    526526 
     527#ifdef PERFTIMER    
    527528        // fill view cells cache 
    528529        mNodeTimer.Entry(); 
     530#endif   
    529531 
    530532        const BvhTraversalData &tData = sc.mParentData; 
     
    634636        UpdateViewCells(sc); 
    635637 
     638#ifdef PERFTIMER   
    636639        mNodeTimer.Exit(); 
    637  
     640#endif 
     641         
    638642        // return the new interior node 
    639643        return node; 
     
    647651                                                                ) 
    648652{ 
     653#ifdef PERFTIMER   
    649654        mSubdivTimer.Entry(); 
    650  
     655#endif 
     656         
    651657        BvhSubdivisionCandidate *sc =  
    652658                static_cast<BvhSubdivisionCandidate *>(splitCandidate); 
     
    718724        } 
    719725         
     726#ifdef PERFTIMER   
    720727        mSubdivTimer.Exit(); 
    721  
     728#endif 
     729         
    722730        return currentNode; 
    723731} 
     
    780788                                                                                   const bool preprocessViewCells) 
    781789{ 
    782         mPlaneTimer.Entry(); 
     790#ifdef PERFTIMER   
     791  mPlaneTimer.Entry(); 
     792#endif 
    783793 
    784794        const BvhTraversalData &tData = splitCandidate.mParentData; 
     
    824834        } 
    825835 
     836#ifdef PERFTIMER   
    826837        mPlaneTimer.Exit(); 
    827  
     838#endif 
    828839 
    829840        /////////////////// 
    830841 
     842#ifdef PERFTIMER   
    831843        mEvalTimer.Entry(); 
    832  
     844#endif 
     845         
    833846        // mark view cells according to what part of the split they see 
    834847        // and compute volume 
     
    984997#endif 
    985998 
     999#ifdef PERFTIMER   
    9861000        mEvalTimer.Exit(); 
     1001#endif 
    9871002} 
    9881003 
     
    16761691                                                                                                        const int axis)                                                                                  
    16771692{ 
     1693#ifdef PERFTIMER   
    16781694        mSortTimer.Entry(); 
    1679          
     1695#endif   
    16801696        //-- insert object queries 
    16811697        ObjectContainer *objects = mUseGlobalSorting ?  
     
    16841700        CreateLocalSubdivisionCandidates(*objects, &mSubdivisionCandidates, !mUseGlobalSorting, axis); 
    16851701         
     1702#ifdef PERFTIMER   
    16861703        mSortTimer.Exit(); 
     1704#endif 
    16871705} 
    16881706 
     
    18401858                                                                                 bool useVisibilityBasedHeuristics) 
    18411859{ 
     1860#ifdef PERFTIMER   
    18421861        mSplitTimer.Entry(); 
    1843  
     1862#endif 
     1863         
    18441864        if (mIsInitialSubdivision) 
    18451865        { 
     
    19251945        backObjects = nBackObjects[bestAxis]; 
    19261946 
     1947#ifdef PERFTIMER   
    19271948        mSplitTimer.Exit(); 
    1928  
     1949#endif 
     1950         
    19291951        //cout << "val: " << nCostRatio[bestAxis] << " axis: " << bestAxis << endl; 
    19301952        return nCostRatio[bestAxis]; 
     
    22762298        //-- use view cells cache 
    22772299 
     2300#ifdef PERFTIMER   
    22782301        mCollectTimer.Entry(); 
    2279  
     2302#endif 
     2303         
    22802304        ViewCellContainer *objViewCells = obj->GetOrCreateViewCells(); 
    22812305 
     
    23082332        } 
    23092333 
     2334#ifdef PERFTIMER   
    23102335        mCollectTimer.Exit(); 
    2311  
     2336#endif 
    23122337        return (int)objViewCells->size(); 
    23132338} 
     
    23202345                                                                                  const bool onlyUnmailedRays) 
    23212346{ 
     2347#ifdef PERFTIMER   
    23222348        mCollectTimer.Entry(); 
     2349#endif 
    23232350        VssRayContainer::const_iterator rit, rit_end = obj->GetOrCreateRays()->end(); 
    23242351 
     
    23622389        } 
    23632390 
     2391#ifdef PERFTIMER   
    23642392        mCollectTimer.Exit(); 
     2393#endif 
    23652394        return numRays; 
    23662395} 
     
    24362465                                                                  const bool onlyUnmailedRays) 
    24372466{ 
     2467#ifdef PERFTIMER   
    24382468        mCollectTimer.Entry(); 
     2469#endif 
    24392470        VssRayContainer::const_iterator rit, rit_end = obj->GetOrCreateRays()->end(); 
    24402471 
     
    24782509        } 
    24792510 
     2511#ifdef PERFTIMER   
    24802512        mCollectTimer.Exit(); 
     2513#endif 
    24812514        return numRays; 
    24822515} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h

    r2350 r2575  
    1414#include "IntersectableWrapper.h" 
    1515#include "HierarchyManager.h" 
     16 
     17#ifdef PERFTIMER 
    1618#include "Timer/PerfTimer.h" 
    17  
     19#endif // PERFTIMER 
    1820 
    1921namespace GtpVisibilityPreprocessor { 
     
    213215         
    214216        int CastRay(Ray &ray) { return 0; } 
     217        int CastSimpleRay(const SimpleRay &ray) { return 0;} 
     218        int CastSimpleRay(const SimpleRay &ray, int IndexRay) { return 0;} 
    215219         
    216220        bool IsConvex() const { return true; } 
     
    677681        void CreateUniqueObjectIds(); 
    678682 
     683#ifdef PERFTIMER   
    679684        PerfTimer mNodeTimer; 
    680685        PerfTimer mSubdivTimer; 
     
    684689        PerfTimer mSortTimer; 
    685690        PerfTimer mCollectTimer; 
     691#endif   
    686692 
    687693protected: 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Camera.cpp

    r2176 r2575  
    55#include <IL/ilu.h> 
    66#include <IL/ilut.h> 
     7#include <cassert> 
    78 
    89#include "Camera.h" 
    910#include "Ray.h" 
     11#include "SimpleRay.h" 
    1012#include "KdTree.h" 
    1113#include "Mesh.h" 
    1214#include "Exporter.h" 
    1315#include "SceneGraph.h" 
     16#include "Preprocessor.h" 
     17#include "RayCaster.h" 
     18 
     19#ifdef USE_HAVRAN_RAYCASTER  
     20//#include "timer.h" 
     21#include "raypack.h" 
     22#endif 
    1423 
    1524using namespace std; 
     
    3645bool 
    3746Camera::SnapImage(string filename, 
    38                                   KdTree *tree, 
    39                                   SceneGraph *sceneGraph 
    40                                   ) 
     47                  KdTree *tree, 
     48                  SceneGraph *sceneGraph 
     49                ) 
    4150{ 
    4251  int x; 
     
    167176} 
    168177 
    169 } 
     178 
     179void 
     180Camera::SetupRay(SimpleRay &ray, const int x, const int y) 
     181{ 
     182  Vector3 xv = mRight*((x - mWidth/2)/(float)mWidth); 
     183  Vector3 yv = mUp*((y - mHeight/2)/(float)mHeight); 
     184  Vector3 target = xv + yv + mDirection; 
     185  Vector3 dir = target - mPosition; 
     186  dir.Normalize(); 
     187   
     188  ray.Set(mPosition, dir, 0, 
     189          1.0f, ~(SimpleRay::F_BIDIRECTIONAL)); 
     190} 
     191 
     192bool 
     193Camera::SnapImage(string filename, 
     194                  RayCaster *raycaster, 
     195                  AxisAlignedBox3 &bbox, 
     196                  SceneGraph *sceneGraph 
     197                  ) 
     198{ 
     199  int x; 
     200  int y; 
     201 
     202  bool exportRays = false; 
     203 
     204   
     205  InitDevIl(); 
     206  int components = 4; 
     207  float *buffer = new float[components*mWidth*mHeight]; 
     208  assert(buffer); 
     209  float *pbuffer = buffer; 
     210  //  - components*mWidth; 
     211   
     212  vector<Ray *> rays; 
     213 
     214  long t1 = GetTime(); 
     215 
     216  SimpleRay ray; 
     217  VssRayContainer vssRays; 
     218 
     219  //CTimer timer; 
     220  //timer.Start(); 
     221   
     222  for (y = 0; y < mHeight; y++) { 
     223    cout<<"+"; 
     224    for (x = 0; x < mWidth; x++) { 
     225      SetupRay(ray, mWidth - (x + 1), mHeight - (y + 1)); 
     226 
     227      bool debug = true; 
     228      //          (y == mHeight/2) && (x== mWidth/3); 
     229      //          MeshDebug = debug; 
     230       
     231 
     232      int res = raycaster->CastRay(ray, 
     233                                   vssRays, 
     234                                   bbox, 
     235                                   false, // castDoubleRay, 
     236                                   false); // pruneInvalidRays 
     237       
     238      if (res) { 
     239        Vector3 normal = raycaster->intersect.mNormal; 
     240        float v = 
     241          ray.mDirection.x * normal.x + 
     242          ray.mDirection.y * normal.y + 
     243          ray.mDirection.z * normal.z; 
     244        v *= 1.0f; 
     245        pbuffer[0] = v; 
     246        pbuffer[1] = v; 
     247        pbuffer[2] = v; 
     248        pbuffer[3] = 1.0f;                 
     249      } 
     250      else { 
     251        pbuffer[0] = 0.0; 
     252        pbuffer[1] = 0.0; 
     253        pbuffer[2] = 0.0; 
     254        pbuffer[3] = 1.0f; 
     255      } 
     256      pbuffer+=components; 
     257       
     258      if (debug) { 
     259        Ray *nray = new Ray(ray.mOrigin, ray.mDirection, 
     260                            Ray::LOCAL_RAY); 
     261        rays.push_back(nray); 
     262      } 
     263    } 
     264    //    pbuffer-=2*components*mWidth; 
     265  } // for y 
     266 
     267  //timer.Stop(); 
     268   
     269  long t2 = GetTime(); 
     270  cout<<"\n#RAY_CAST_TIME = "; 
     271  cout << TimeDiff(t1, t2)<<" [mikrosec]\n";   
     272   
     273  cout<<"Saving image"<<endl; 
     274   
     275  ilRegisterType(IL_FLOAT); 
     276  ilTexImage(mWidth, mHeight, 1, 4, IL_RGBA, IL_FLOAT, buffer); 
     277  ilSaveImage((char *const)filename.c_str()); 
     278  delete buffer; 
     279 
     280  cout<<"done."<<endl<<flush; 
     281     
     282  return true; 
     283} 
     284 
     285bool 
     286Camera::SnapImagePacket(string filename, 
     287                        RayCaster *raycaster, 
     288                        AxisAlignedBox3 &bbox, 
     289                        SceneGraph *sceneGraph 
     290                        ) 
     291{ 
     292#ifdef USE_HAVRAN_RAYCASTER  
     293   
     294  int x; 
     295  int y; 
     296 
     297  bool exportRays = false; 
     298 
     299   
     300  InitDevIl(); 
     301  int components = 4; 
     302  float *buffer = new float[components*mWidth*mHeight]; 
     303  assert(buffer); 
     304  float *pbuffer = buffer; 
     305  //  - components*mWidth; 
     306   
     307  vector<Ray *> rays; 
     308 
     309  long t1 = GetTime(); 
     310 
     311  SimpleRay ray; 
     312  VssRayContainer vssRays; 
     313 
     314  //CTimer timer; 
     315  //timer.Start(); 
     316 
     317  RayPacket2x2 rp; 
     318  for (y = 0; y < mHeight-1; y+=2) { 
     319    float *pppbuffer = pbuffer; 
     320    cout<<"+"; 
     321    for (x = 0; x < mWidth-1; x+=2) { 
     322      int i = 0; 
     323      for (int yi = 0; yi < 2; yi++) { 
     324        for (int xi = 0; xi < 2; xi++) { 
     325          SetupRay(ray, mWidth - (x+xi + 1), mHeight - (y+yi + 1)); 
     326          rp.SetLoc(i, ray.mOrigin); 
     327          rp.SetDir(i, ray.mDirection); 
     328          i++; 
     329        } // for xi 
     330      } // for yi       
     331 
     332      raycaster->CastRaysPacket2x2(rp, false, false); 
     333 
     334      i = 0; 
     335      float *ppbuffer = pbuffer; 
     336      for (int yi = 0; yi < 2; yi++) { 
     337        for (int xi = 0; xi < 2; xi++) { 
     338          Intersectable* res = rp.GetObject(i); 
     339          if (res) { 
     340            pbuffer[0] = 1.0f; 
     341            pbuffer[1] = 1.0f; 
     342            pbuffer[2] = 1.0f; 
     343            pbuffer[3] = 1.0f;             
     344          } 
     345          else { 
     346            pbuffer[0] = 0.0; 
     347            pbuffer[1] = 0.0; 
     348            pbuffer[2] = 0.0; 
     349            pbuffer[3] = 1.0f; 
     350          } 
     351          i++; 
     352          ppbuffer += components; 
     353        } // xi 
     354        ppbuffer += components * (mWidth-2); 
     355      } // yi 
     356 
     357      pbuffer = ppbuffer + 2 * components; 
     358    } // for x 
     359    pbuffer = pppbuffer + mWidth * 2 * components; 
     360    pppbuffer = pbuffer; // for the next time; 
     361  } // for y 
     362 
     363  //timer.Stop(); 
     364   
     365  long t2 = GetTime(); 
     366  cout<<"\n#RAY_CAST_TIME = "; 
     367  cout << TimeDiff(t1, t2)<<" [mikrosec]\n";   
     368   
     369  cout<<"Saving image"<<endl; 
     370   
     371  ilRegisterType(IL_FLOAT); 
     372  ilTexImage(mWidth, mHeight, 1, 4, IL_RGBA, IL_FLOAT, buffer); 
     373  ilSaveImage((char *const)filename.c_str()); 
     374  delete buffer; 
     375#endif 
     376  cout<<"done."<<endl<<flush; 
     377     
     378  return true; 
     379} 
     380   
     381 
     382} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Camera.h

    r2176 r2575  
    99class KdTree; 
    1010class SceneGraph; 
    11  
     11class RayCaster; 
    1212 
    1313class Camera 
     
    3030    mFovy = 90.0f*(float)M_PI/180.0f; 
    3131  } 
     32 
     33  Camera(int width, int height) { 
     34    mWidth = width; 
     35    mHeight = height; 
     36    mFovy = 90.0f*(float)M_PI/180.0f; 
     37  } 
     38 
    3239   
    3340  void Precompute() { 
     
    4653  } 
    4754 
    48         void SetDirection(const Vector3 &dir) { 
     55  void SetDirection(const Vector3 &dir) { 
    4956    mDirection = dir; 
    5057    Precompute(); 
     
    5360  void LookInBox(const AxisAlignedBox3 &box) 
    5461  { 
    55     mDirection = Vector3(0,0,1);  
     62    mDirection = Vector3(0,0,1); 
    5663    mPosition = box.Center(); 
    5764    Precompute(); 
     
    6774   
    6875  bool 
    69           SnapImage(std::string filename, 
    70                         KdTree *tree, 
    71                         SceneGraph *sceneGraph 
    72                         ); 
     76  SnapImage(std::string filename, 
     77            KdTree *tree, 
     78            SceneGraph *sceneGraph 
     79            ); 
    7380 
     81  bool 
     82  SnapImage(std::string filename, 
     83            RayCaster *raycaster, 
     84            AxisAlignedBox3 &bbox, 
     85            SceneGraph *sceneGraph 
     86            ); 
     87 
     88  bool 
     89  SnapImagePacket(std::string filename, 
     90                  RayCaster *raycaster, 
     91                  AxisAlignedBox3 &bbox, 
     92                  SceneGraph *sceneGraph 
     93                  ); 
     94   
    7495  void SetupRay(Ray &ray, const int x, const int y); 
    7596 
     97  void SetupRay(SimpleRay &ray, const int x, const int y); 
    7698}; 
    7799 
  • GTP/trunk/Lib/Vis/Preprocessing/src/DifferenceSampling.cpp

    r2560 r2575  
     1 
    12#include "SamplingStrategy.h" 
    23#include "Intersectable.h" 
     
    56#include "ViewCellsManager.h" 
    67#include "Preprocessor.h" 
     8#ifdef PERFTIMER   
    79#include "Timer/PerfTimer.h" 
    8  
     10#endif 
    911 
    1012#ifdef GTP_INTERNAL 
     
    1214#endif 
    1315 
     16 
     17#ifdef PERFTIMER   
    1418PerfTimer sFilterTimer; 
    15  
     19#endif 
    1620 
    1721namespace GtpVisibilityPreprocessor { 
     
    6367        ObjectPvs filteredPvs; 
    6468 
     69         
     70#ifdef PERFTIMER   
    6571        sFilterTimer.Entry(); 
    66      
     72#endif 
     73         
    6774        PvsFilterStatistics pvsStats = mPreprocessor. 
    6875                mViewCellsManager->ApplyFilter2(vc,  
     
    7178                                                                                filteredPvs); 
    7279 
     80#ifdef PERFTIMER   
    7381        sFilterTimer.Exit(); 
    74  
     82#endif 
     83         
    7584        //mDifferencePvs.Clear(false); 
    7685        //mDifferencePvs.Reserve(filteredPvs.GetSize()); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp

    r2542 r2575  
    519519bool 
    520520Environment::GetStringValue(const char *name, 
    521                                                         char *value, 
    522                                                         const bool isFatal) const 
     521                            char *value, 
     522                            const bool isFatal) const 
    523523{ 
    524524  int i = FindOption(name, isFatal); 
     
    538538  return true; 
    539539} 
     540 
     541bool 
     542Environment::GetStringValue(const char *name, 
     543                            string &stringVariable, 
     544                            const bool isFatal) const 
     545{ 
     546  int i = FindOption(name, isFatal); 
     547 
     548  if (i<0) 
     549    return false; 
     550 
     551   
     552  if (options[i].value != NULL) { 
     553    // option was not read, so use the default 
     554    stringVariable = options[i].value; 
     555  } 
     556  else { 
     557    // option was explicitly specified 
     558    stringVariable = options[i].defaultValue; 
     559  } 
     560  return true; 
     561} 
     562 
    540563 
    541564void 
     
    10691092  numParams = 0; 
    10701093  params = NULL; 
    1071   maxOptions = 500; 
     1094  maxOptions = 600; 
    10721095 
    10731096   
     
    28462869                                 "true"); 
    28472870 
    2848         ///////////////////////////////////////////////////////////////// 
    2849  
     2871  ///////////////////////////////////////////////////////////////// 
     2872  // By Vlastimil Havran 
     2873  RegisterOption("BSP.splitclip", optBool, 
     2874                 "kd_splitclip=", "false"); 
     2875  RegisterOption("BSP.emptyCut", optBool, 
     2876                 "kd_emptycut=", "true"); 
     2877  RegisterOption("BSP.termCrit", optString, 
     2878                 "kd_termcrit=", "auto"); 
     2879  RegisterOption("BSP.maxDepthAllowed", optInt, 
     2880                 "kd_maxDepth=", "16"); 
     2881  RegisterOption("BSP.maxEmptyCutDepth", optInt, 
     2882                 "kd_maxEmptyCutDepth=", "4"); 
     2883  RegisterOption("BSP.absMaxAllowedDepth", optInt, 
     2884                 "kd_absMaxAllowedDepth=", "20"); 
     2885  RegisterOption("BSP.maxListLength", optInt, 
     2886                 "kd_maxListLength=", "16"); 
     2887  RegisterOption("BSP.useRadixSort", optBool, 
     2888                 "kd_useRadixSort=", "false"); 
     2889  RegisterOption("BSP.printCuts", optBool, 
     2890                 "kd_printCuts=", "false"); 
     2891  RegisterOption("BSP.algAutoTermination", optInt, 
     2892                 "kd_algAutoTermination=", "0"); 
     2893  RegisterOption("BSP.axisSelectionAlg", optInt, 
     2894                 "kd_axisSelectAlg=", "0"); 
     2895   
     2896  RegisterOption("BSP.decisionCost", optFloat, 
     2897                 "kd_decCost=", "0.3"); 
     2898  RegisterOption("BSP.intersectionCost", optFloat, 
     2899                 "kd_intersectCost=", "0.9"); 
     2900  RegisterOption("BSP.traversalCost", optFloat, 
     2901                 "kd_travCost=", "0.2"); 
     2902  RegisterOption("BSP.biasFreeCuts", optFloat, 
     2903                 "kd_biasFreeCuts=", "0.9"); 
     2904 
     2905  RegisterOption("BSP.minBoxes.use", optBool, 
     2906                 "kd_minBoxesUse=", "false"); 
     2907  RegisterOption("BSP.minBoxes.tight", optBool, 
     2908                 "kd_minBoxesTight=", "false"); 
     2909  RegisterOption("BSP.minBoxes.minObjects", optInt, 
     2910                 "kd_minBoxesMinObjects=", "10"); 
     2911  RegisterOption("BSP.minBoxes.minDepthDistance", optInt, 
     2912                 "kd_minBoxesMinDist=", "3"); 
     2913  RegisterOption("BSP.minBoxes.minSA2ratio", optFloat, 
     2914                 "kd_minBoxesSA2ratio=", "1.0"); 
     2915 
     2916  // The object used for testing 
     2917  RegisterOption("Rays.file", 
     2918                 optString, 
     2919                 "rays_filename=", 
     2920                 "data/fileRays_arena.txt"); 
     2921  RegisterOption("Rays.cnt", 
     2922                 optInt, 
     2923                 "rays_cnt=", "100000"); 
     2924   
     2925  RegisterOption("TestDoubleRays", optBool, 
     2926                 "test_doublrays=", "false"); 
     2927 
     2928  ///////////////////////////////////////////////////////////////// 
    28502929} 
    28512930 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Environment.h

    r2176 r2575  
    1717 
    1818#include "common.h" 
     19#include <cstring> 
     20 
    1921 
    2022namespace GtpVisibilityPreprocessor { 
    2123 
    2224class Vector3; 
    23  
    2425 
    2526/// Enumeration type used to distinguish the type of the environment variable 
     
    314315  /// returns named option as a character string. 
    315316  bool GetStringValue(const char *name, 
    316                                           char *value, 
    317                                           const bool isFatal = false) const; 
     317                      char *value, 
     318                      const bool isFatal = false) const; 
     319 
     320  bool GetStringValue(const char *name, 
     321                      std::string &stringVariable, 
     322                      const bool isFatal = false) const; 
    318323   
    319324  //@} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Exporter.cpp

    r2394 r2575  
    88#include "Polygon3.h" 
    99#include "TraversalTree.h" 
     10#include "Material.h" 
    1011 
    1112 
     
    7172                else 
    7273                { 
    73                         SetForcedMaterial(RandomMaterial()); 
     74                  SetForcedMaterial(RandomMaterial()); 
    7475                } 
    7576                if (0) ExportGeometry(leaf->mObjects);   
  • GTP/trunk/Lib/Vis/Preprocessing/src/FromPointVisibilityTree.h

    r1006 r2575  
    11#ifndef _FromPointVisibilityTree_H__ 
    22#define _FromPointVisibilityTree_H__ 
     3 
     4#include <stack> 
     5#include <fstream> 
    36 
    47#include "Mesh.h" 
    58#include "Containers.h" 
    69#include "Polygon3.h" 
    7 #include <stack> 
    810#include "Statistics.h" 
    911#include "VssRay.h" 
     
    256258        */ 
    257259        int CastRay(Ray &ray); 
     260        int CastSimpleRay(const SimpleRay &ray) { return 0;} 
     261        int CastSimpleRay(const SimpleRay &ray, int IndexRay) { return 0;} 
    258262 
    259263        /// bsp tree construction types 
     
    329333        /** Writes tree to output stream 
    330334        */ 
    331         bool Export(ofstream &stream); 
     335        bool Export(std::ofstream &stream); 
    332336 
    333337        /** Casts beam, i.e. a 5D frustum of rays, into tree. 
     
    690694                @note: should be implemented as visitor 
    691695        */ 
    692         void ExportNode(BspNode *node, ofstream &stream); 
     696  void ExportNode(BspNode *node, std::ofstream &stream); 
    693697 
    694698        /** Returns estimated memory usage of tree. 
     
    782786        int mMaxViewCells; 
    783787         
    784         ofstream  mSubdivisionStats; 
     788  std::ofstream  mSubdivisionStats; 
    785789 
    786790        // if rays should be stored in leaves 
     
    812816        //int mSplits; 
    813817        /// subdivision stats output file 
    814         ofstream mSubdivsionStats; 
     818        std::ofstream mSubdivsionStats; 
    815819        /// if random split axis should be used 
    816820        bool mUseRandomAxis; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp

    r2572 r2575  
    55#include "ViewCellsManager.h" 
    66#include "SceneGraph.h" 
    7 #include "Viewcell.h" 
     7#include "ViewCell.h" 
    88#include "Beam.h" 
    99#include "KdTree.h" 
     
    126126void GlRenderer::RenderTriangle(TriangleIntersectable *object) 
    127127{ 
    128         Triangle3 &t = object->GetItem(); 
     128  Triangle3 *t = &(object->GetItem()); 
    129129 
    130130        glBegin(GL_TRIANGLES); 
    131         Vector3 normal = t.GetNormal(); 
     131        Vector3 normal = t->GetNormal(); 
    132132        glNormal3f(normal.x, normal.y, normal.z); 
    133         glVertex3f(t.mVertices[0].x, t.mVertices[0].y, t.mVertices[0].z); 
    134         glVertex3f(t.mVertices[1].x, t.mVertices[1].y, t.mVertices[1].z); 
    135         glVertex3f(t.mVertices[2].x, t.mVertices[2].y, t.mVertices[2].z); 
     133        glVertex3f(t->mVertices[0].x, t->mVertices[0].y, t->mVertices[0].z); 
     134        glVertex3f(t->mVertices[1].x, t->mVertices[1].y, t->mVertices[1].z); 
     135        glVertex3f(t->mVertices[2].x, t->mVertices[2].y, t->mVertices[2].z); 
    136136        glEnd(); 
    137137} 
     
    420420                if ((*oi)->Type() == Intersectable::TRIANGLE_INTERSECTABLE) { 
    421421                        TriangleIntersectable *object = (TriangleIntersectable *)*oi; 
    422                         Triangle3 &t = object->GetItem(); 
    423  
    424                         Vector3 normal = t.GetNormal(); 
     422                        Triangle3 *t = &(object->GetItem()); 
     423 
     424                        Vector3 normal = t->GetNormal(); 
    425425                        glNormal3f(normal.x, normal.y, normal.z); 
    426                         glVertex3f(t.mVertices[0].x, t.mVertices[0].y, t.mVertices[0].z); 
    427                         glVertex3f(t.mVertices[1].x, t.mVertices[1].y, t.mVertices[1].z); 
    428                         glVertex3f(t.mVertices[2].x, t.mVertices[2].y, t.mVertices[2].z); 
     426                        glVertex3f(t->mVertices[0].x, t->mVertices[0].y, t->mVertices[0].z); 
     427                        glVertex3f(t->mVertices[1].x, t->mVertices[1].y, t->mVertices[1].z); 
     428                        glVertex3f(t->mVertices[2].x, t->mVertices[2].y, t->mVertices[2].z); 
    429429 
    430430                } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Halton.cpp

    r2227 r2575  
    11#include "Halton.h" 
     2 
     3#ifdef PERFTIMER   
    24#include "Timer/PerfTimer.h" 
    3  
     5#endif 
    46 
    57#define PREGENERATE_HALTON 0 
     
    79namespace GtpVisibilityPreprocessor { 
    810 
     11   
     12#ifdef PERFTIMER   
    913PerfTimer haltonTimer; 
    10  
     14#endif 
     15   
    1116// global halton generator 
    1217 
     
    1419  float Halton2::_invBases[2]; 
    1520 
    16   float Halton<1>::_invBases[1]; 
    17   float Halton<2>::_invBases[2]; 
    18   float Halton<3>::_invBases[3]; 
    19   float Halton<4>::_invBases[4]; 
    20   float Halton<5>::_invBases[5]; 
    21   float Halton<6>::_invBases[6]; 
     21  //float Halton<6>::_invBases[6]; 
    2222   
    23  
     23  template<int T> float Halton<T>::_invBases[T]; 
     24   
    2425  Halton<1> dummmyHalton1(true); 
    2526  Halton<2> dummmyHalton2(true); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Halton.h

    r2176 r2575  
    66namespace GtpVisibilityPreprocessor { 
    77 
     8 
     9/** 
     10 * Assert whether the argument is a prime number. 
     11 * @param number the number to be checked 
     12 */ 
     13inline bool IsPrime(const int number) { 
     14  bool isIt = true; 
     15  for(int i = 2; i < number; i++) { 
     16        if(number % i == 0) { 
     17          isIt = false; 
     18          break; 
     19        } 
     20  } 
     21        if(number == 2) { 
     22          isIt = false; 
     23        } 
     24        return isIt; 
     25} 
     26 
     27   
     28  /** 
     29 * Find the nth prime number. 
     30 * @param index the ordinal position in the sequence 
     31 */ 
     32inline int FindPrime(const int index) { 
     33  //  if (index < 1) { 
     34  //    cerr<<"FindPrime: The argument must be non-negative."<<endl; 
     35  //    return -1; 
     36  //  } 
     37 
     38  const int primes[] = {-1, 1, 3, 5, 7, 11, 13}; 
     39  if (index <= 6) 
     40        return primes[index]; 
     41 
     42  int prime = 1; 
     43  int found = 1; 
     44  while(found != index) { 
     45        prime += 2; 
     46          if(IsPrime(prime) == true) { 
     47                found++; 
     48          } 
     49  } 
     50  return prime; 
     51} 
     52 
     53   
    854inline float halton(float baseRec, float prev) { 
    955  //  float r = 1 - prev - 1e-10f; 
     
    82128 
    83129 
    84 /** 
    85  * Assert whether the argument is a prime number. 
    86  * @param number the number to be checked 
    87  */ 
    88 inline bool IsPrime(const int number) { 
    89   bool isIt = true; 
    90   for(int i = 2; i < number; i++) { 
    91         if(number % i == 0) { 
    92           isIt = false; 
    93           break; 
    94         } 
    95   } 
    96         if(number == 2) { 
    97           isIt = false; 
    98         } 
    99         return isIt; 
    100 } 
    101  
    102    
    103   /** 
    104  * Find the nth prime number. 
    105  * @param index the ordinal position in the sequence 
    106  */ 
    107 inline int FindPrime(const int index) { 
    108   //  if (index < 1) { 
    109   //    cerr<<"FindPrime: The argument must be non-negative."<<endl; 
    110   //    return -1; 
    111   //  } 
    112  
    113   const int primes[] = {-1, 1, 3, 5, 7, 11, 13}; 
    114   if (index <= 6) 
    115         return primes[index]; 
    116  
    117   int prime = 1; 
    118   int found = 1; 
    119   while(found != index) { 
    120         prime += 2; 
    121           if(IsPrime(prime) == true) { 
    122                 found++; 
    123           } 
    124   } 
    125   return prime; 
    126 } 
    127  
     130   
    128131struct HaltonSequence { 
    129132public: 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp

    r2543 r2575  
    409409        double sortTime, evalTime, nodeTime, splitTime, subdTime, planeTime, collectTime, viewCellsTime; 
    410410 
     411#ifdef PERFTIMER         
    411412        sortTime = mBvHierarchy->mSortTimer.TotalTime(); 
    412413        evalTime = mBvHierarchy->mEvalTimer.TotalTime(); 
     
    416417        planeTime = mBvHierarchy->mPlaneTimer.TotalTime(); 
    417418        collectTime = mBvHierarchy->mCollectTimer.TotalTime(); 
    418  
     419#endif // #ifdef PERFTIMER  
     420         
    419421        cout << "bvh times" 
    420422                 << " sort : " << sortTime 
     
    437439                 << endl; 
    438440 
     441#ifdef PERFTIMER   
    439442        sortTime = mVspTree->mSortTimer.TotalTime(); 
    440443        evalTime = mVspTree->mEvalTimer.TotalTime(); 
     
    444447        planeTime = mVspTree->mPlaneTimer.TotalTime(); 
    445448        viewCellsTime = mVspTree->mViewCellsTimer.TotalTime(); 
    446  
     449#endif 
     450         
    447451        cout << "vsp times" 
    448452                 << " sort : " << sortTime 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h

    r2543 r2575  
    536536protected: 
    537537 
    538         friend VspTree; 
    539         friend OspTree; 
    540         friend BvHierarchy; 
    541         friend ViewCellsParseHandlers; 
     538        friend class VspTree; 
     539        friend class OspTree; 
     540        friend class BvHierarchy; 
     541        friend class ViewCellsParseHandlers; 
    542542 
    543543 
  • GTP/trunk/Lib/Vis/Preprocessing/src/IntelRayCaster.cpp

    r2574 r2575  
    1414 
    1515FILE *fileOut = 0; 
    16 bool saveRays = true; 
    17   const int saveRaysStart = 3000000; 
     16bool saveRays = false; 
     17const int saveRaysStart = 3000000; 
    1818int cntSavedRaysFLUSH = 0; 
    1919unsigned long int cntSavedRays = 0; 
    2020const int intSavedLIMIT = 1024; 
     21 
    2122void 
    2223InitSaving() 
     
    3334  fclose(fileOut); 
    3435} 
    35  
    36    
    3736 
    3837IntelRayCaster::IntelRayCaster(const Preprocessor &preprocessor,  
  • GTP/trunk/Lib/Vis/Preprocessing/src/InternalRayCaster.cpp

    r2105 r2575  
    2222 
    2323int InternalRayCaster::CastRay(const SimpleRay &simpleRay, 
    24                                                            VssRayContainer &vssRays, 
    25                                                            const AxisAlignedBox3 &box, 
    26                                                            const bool castDoubleRay, 
    27                                                            const bool pruneInvalidRays) 
     24                               VssRayContainer &vssRays, 
     25                               const AxisAlignedBox3 &box, 
     26                               const bool castDoubleRay, 
     27                               const bool pruneInvalidRays) 
    2828{ 
    2929  if (simpleRay.mType == Ray::GLOBAL_RAY) 
    30           return CastGlobalRay(simpleRay, vssRays, box, pruneInvalidRays); 
     30    return CastGlobalRay(simpleRay, vssRays, box, pruneInvalidRays); 
    3131   
    3232  //cout << "internal ray" << endl; 
     
    5151   
    5252  if (mPreprocessor.mKdTree->CastRay(ray)) { 
    53         hitA.mObject = ray.intersections[0].mObject; 
    54         hitA.mPoint = ray.Extrap(ray.intersections[0].mT); 
    55         hitA.mNormal = ray.intersections[0].mNormal;  
    56         //      cout << "hita: " << hitA.mPoint << " !obj: " << hitA.mObject << endl; 
     53    hitA.mObject = ray.intersections[0].mObject; 
     54    hitA.mPoint = ray.Extrap(ray.intersections[0].mT); 
     55    hitA.mNormal = ray.intersections[0].mNormal;  
     56    //  cout << "hita: " << hitA.mPoint << " !obj: " << hitA.mObject << endl; 
    5757  } 
    5858   
     
    6161   
    6262  if (castDoubleRay && mPreprocessor.mKdTree->CastRay(ray)) { 
    63         hitB.mObject = ray.intersections[0].mObject; 
    64         hitB.mPoint = ray.Extrap(ray.intersections[0].mT); 
    65         hitB.mNormal = ray.intersections[0].mNormal; 
     63    hitB.mObject = ray.intersections[0].mObject; 
     64    hitB.mPoint = ray.Extrap(ray.intersections[0].mT); 
     65    hitB.mNormal = ray.intersections[0].mNormal; 
    6666  } 
    6767   
    6868  return ProcessRay( 
    69                                         simpleRay, 
    70                                         hitA, 
    71                                         hitB, 
    72                                         vssRays, 
    73                                         box, 
    74                                         castDoubleRay, 
    75                                         pruneInvalidRays 
    76                                         ); 
     69                    simpleRay, 
     70                    hitA, 
     71                    hitB, 
     72                    vssRays, 
     73                    box, 
     74                    castDoubleRay, 
     75                    pruneInvalidRays 
     76                    ); 
    7777} 
    7878 
     
    8080int 
    8181InternalRayCaster::CastGlobalRay(const SimpleRay &simpleRay, 
    82                                                                 VssRayContainer &vssRays, 
    83                                                                 const AxisAlignedBox3 &box, 
    84                                                                 const bool pruneInvalidRays 
    85                                                                 ) 
     82                                VssRayContainer &vssRays, 
     83                                const AxisAlignedBox3 &box, 
     84                                const bool pruneInvalidRays 
     85                                 ) 
    8686{ 
    8787  static Ray ray; 
     
    103103   
    104104  if (mPreprocessor.mKdTree->CastRay(ray)) { 
    105         // sort intersections 
    106         ray.SortIntersections(); 
    107         //      cout<<"I="<<ray.intersections.size()<<endl; 
    108          
    109          
    110         Ray::Intersection &hit = ray.intersections[0]; 
    111          
    112         if (DotProd(hit.mNormal, ray.GetDir()) < 0) { 
    113           //      cout<<"F:"<<tmin<<" "<<hit.mT<<endl; 
    114           // insert intial segment 
     105    // sort intersections 
     106    ray.SortIntersections(); 
     107    //  cout<<"I="<<ray.intersections.size()<<endl; 
     108         
     109         
     110    Ray::Intersection &hit = ray.intersections[0]; 
     111         
     112    if (DotProd(hit.mNormal, ray.GetDir()) < 0) { 
     113      //          cout<<"F:"<<tmin<<" "<<hit.mT<<endl; 
     114      // insert intial segment 
     115      vssRay = new VssRay( 
     116                          ray.Extrap(tmin), 
     117                          ray.Extrap(hit.mT), 
     118                          NULL, 
     119                          hit.mObject, 
     120                          mPreprocessor.mPass, 
     121                          1.0f //simpleRay.mPdf 
     122                          ); 
     123 
     124      vssRay->mFlags |= VssRay::Valid; 
     125      vssRay->mDistribution = simpleRay.mDistribution; 
     126      vssRays.push_back(vssRay); 
     127      ++hits; 
     128    } 
     129                                 
     130    hit = ray.intersections[ray.intersections.size()-1]; 
     131    if (DotProd(hit.mNormal, ray.GetDir()) > 0) { 
     132      //          cout<<"L:"<<tmax<<" "<<hit.mT<<endl; 
     133       
     134      // insert termination segment 
     135      vssRay = new VssRay( 
     136                          ray.Extrap(tmax), 
     137                          ray.Extrap(hit.mT), 
     138                          NULL, 
     139                          hit.mObject, 
     140                          mPreprocessor.mPass, 
     141                          1.0f //simpleRay.mPdf 
     142                          ); 
     143      vssRay->mFlags |= VssRay::Valid; 
     144      vssRay->mDistribution = simpleRay.mDistribution; 
     145      vssRays.push_back(vssRay); 
     146      ++hits; 
     147    } 
     148         
     149    // insert the rest of segments 
     150    for (int i=0; i < ray.intersections.size() - 1; i++) { 
     151      Ray::Intersection &hitA = ray.intersections[i]; 
     152      Ray::Intersection &hitB = ray.intersections[i + 1]; 
     153      if (hitB.mT - hitA.mT > Limits::Small) { 
     154        if (DotProd(hitA.mNormal, ray.GetDir()) > 0 && 
     155            DotProd(hitB.mNormal, ray.GetDir()) < 0 
     156            ) { 
     157           
    115158          vssRay = new VssRay( 
    116                                                   ray.Extrap(tmin), 
    117                                                   ray.Extrap(hit.mT), 
    118                                                   NULL, 
    119                                                   hit.mObject, 
    120                                                   mPreprocessor.mPass, 
    121                                                   1.0f //simpleRay.mPdf 
    122                                                   ); 
    123  
     159                              ray.Extrap(hitA.mT), 
     160                              ray.Extrap(hitB.mT), 
     161                              hitA.mObject, 
     162                              hitB.mObject, 
     163                              mPreprocessor.mPass, 
     164                              1.0f //simpleRay.mPdf 
     165                              ); 
     166          vssRay->mFlags |= VssRay::Valid; 
     167          vssRay->mDistribution = simpleRay.mDistribution; 
     168          vssRays.push_back(vssRay); 
     169          ++hits; 
     170           
     171          vssRay = new VssRay( 
     172                              ray.Extrap(hitB.mT), 
     173                              ray.Extrap(hitA.mT), 
     174                              hitB.mObject, 
     175                              hitA.mObject, 
     176                              mPreprocessor.mPass, 
     177                              1.0f //simpleRay.mPdf 
     178                              ); 
     179           
    124180          vssRay->mFlags |= VssRay::Valid; 
    125181          vssRay->mDistribution = simpleRay.mDistribution; 
     
    127183          ++hits; 
    128184        } 
    129                                  
    130         hit = ray.intersections[ray.intersections.size()-1]; 
    131         if (DotProd(hit.mNormal, ray.GetDir()) > 0) { 
    132           //      cout<<"L:"<<tmax<<" "<<hit.mT<<endl; 
    133            
    134           // insert termination segment 
    135           vssRay = new VssRay( 
    136                                                   ray.Extrap(tmax), 
    137                                                   ray.Extrap(hit.mT), 
    138                                                   NULL, 
    139                                                   hit.mObject, 
    140                                                   mPreprocessor.mPass, 
    141                                                   1.0f //simpleRay.mPdf 
    142                                                   ); 
    143           vssRay->mFlags |= VssRay::Valid; 
    144           vssRay->mDistribution = simpleRay.mDistribution; 
    145           vssRays.push_back(vssRay); 
    146           ++hits; 
    147         } 
    148          
    149         // insert the rest of segments 
    150         for (int i=0; i < ray.intersections.size() - 1; i++) { 
    151           Ray::Intersection &hitA = ray.intersections[i]; 
    152           Ray::Intersection &hitB = ray.intersections[i + 1]; 
    153           if (hitB.mT - hitA.mT > Limits::Small) { 
    154                 if (DotProd(hitA.mNormal, ray.GetDir()) > 0 && 
    155                         DotProd(hitB.mNormal, ray.GetDir()) < 0 
    156                         ) { 
    157                    
    158                   vssRay = new VssRay( 
    159                                                           ray.Extrap(hitA.mT), 
    160                                                           ray.Extrap(hitB.mT), 
    161                                                           hitA.mObject, 
    162                                                         hitB.mObject, 
    163                                                           mPreprocessor.mPass, 
    164                                                           1.0f //simpleRay.mPdf 
    165                                                           ); 
    166                   vssRay->mFlags |= VssRay::Valid; 
    167                   vssRay->mDistribution = simpleRay.mDistribution; 
    168                   vssRays.push_back(vssRay); 
    169                   ++hits; 
    170                    
    171                   vssRay = new VssRay( 
    172                                                           ray.Extrap(hitB.mT), 
    173                                                           ray.Extrap(hitA.mT), 
    174                                                           hitB.mObject, 
    175                                                           hitA.mObject, 
    176                                                           mPreprocessor.mPass, 
    177                                                           1.0f //simpleRay.mPdf 
    178                                                           ); 
    179                    
    180                   vssRay->mFlags |= VssRay::Valid; 
    181                   vssRay->mDistribution = simpleRay.mDistribution; 
    182                   vssRays.push_back(vssRay); 
    183                   ++hits; 
    184                 } 
    185           } 
    186         } 
     185      } 
     186    } 
    187187  } 
    188188   
     
    192192 
    193193void InternalRayCaster::CastRays16(SimpleRayContainer &rays,  
    194                                                                    VssRayContainer &vssRays, 
    195                                                                    const AxisAlignedBox3 &sbox, 
    196                                                                    const bool castDoubleRays, 
    197                                                                    const bool pruneInvalidRays) 
     194                                   VssRayContainer &vssRays, 
     195                                   const AxisAlignedBox3 &sbox, 
     196                                   const bool castDoubleRays, 
     197                                   const bool pruneInvalidRays) 
    198198{ 
    199199#if DEBUG_RAYCAST 
    200200        Debug << "C16 " << flush; 
    201201#endif 
    202  
    203         SimpleRayContainer::const_iterator sit, sit_end = rays.end(); 
    204  
    205         // no acceleration for ray bundles implemented right now 
    206         for (sit = rays.begin(); sit != sit_end; ++ sit)  
    207         { 
    208                 CastRay(*sit, vssRays, sbox, castDoubleRays, pruneInvalidRays); 
    209         } 
    210  
     202         
     203  SimpleRayContainer::const_iterator sit, sit_end = rays.end(); 
     204 
     205  // no acceleration for ray bundles implemented right now 
     206  for (sit = rays.begin(); sit != sit_end; ++ sit)  
     207  { 
     208    CastRay(*sit, vssRays, sbox, castDoubleRays, pruneInvalidRays); 
     209  } 
     210   
    211211#if DEBUG_RAYCAST 
    212212        Debug<<"C16F\n"<<flush; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/InternalRayCaster.h

    r2176 r2575  
    2828{ 
    2929public: 
    30         /** Default constructor initialising e.g., KD tree 
    31         */ 
    32         InternalRayCaster(const Preprocessor &preprocessor); 
    33         virtual ~InternalRayCaster(); 
    34  
    35         int Type() const { return INTERNAL_RAYCASTER; } 
    36  
    37         virtual int CastRay( 
    38                                                 const SimpleRay &simpleRay, 
    39                                                 VssRayContainer &vssRays, 
    40                                                 const AxisAlignedBox3 &box, 
    41                                                 const bool castDoubleRay, 
    42                                                 const bool pruneInvalidRays = true 
    43                                                 ); 
    44  
    45         virtual void CastRays16(SimpleRayContainer &rays,  
    46                                                         VssRayContainer &vssRays, 
    47                                                         const AxisAlignedBox3 &sbox, 
    48                                                         const bool castDoubleRay, 
    49                                                         const bool pruneInvalidRays = true 
    50                                                         ); 
    51  
    52         virtual int 
    53         CastGlobalRay( 
    54                                   const SimpleRay &simpleRay, 
    55                                   VssRayContainer &vssRays, 
    56                                   const AxisAlignedBox3 &box, 
    57                                   const bool pruneInvalidRays 
    58                                   ); 
     30  /** Default constructor initialising e.g., KD tree 
     31   */ 
     32  InternalRayCaster(const Preprocessor &preprocessor); 
     33  virtual ~InternalRayCaster(); 
     34   
     35  int Type() const { return INTERNAL_RAYCASTER; } 
     36   
     37  virtual int CastRay( 
     38                      const SimpleRay &simpleRay, 
     39                      VssRayContainer &vssRays, 
     40                      const AxisAlignedBox3 &box, 
     41                      const bool castDoubleRay, 
     42                      const bool pruneInvalidRays = true 
     43                      ); 
     44   
     45  virtual void CastRays16(SimpleRayContainer &rays,  
     46                          VssRayContainer &vssRays, 
     47                          const AxisAlignedBox3 &sbox, 
     48                          const bool castDoubleRay, 
     49                          const bool pruneInvalidRays = true 
     50                          ); 
     51   
     52  virtual int 
     53  CastGlobalRay( 
     54                const SimpleRay &simpleRay, 
     55                VssRayContainer &vssRays, 
     56                const AxisAlignedBox3 &box, 
     57                const bool pruneInvalidRays 
     58                ); 
    5959 
    6060protected: 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Intersectable.cpp

    r2543 r2575  
    11#include "Intersectable.h" 
     2#include "SimpleRay.h" 
     3//#include "ktbconf.h" 
    24 
    35using namespace std; 
    46 
     7#if _WIN32 
     8#define ALIGN16 __declspec(align(16)) 
     9#else 
     10ALIGN16 GALIGN16 
     11#endif 
    512 
    613namespace GtpVisibilityPreprocessor { 
    714 
     15 
     16// This is the result of computing intersection 
     17// static data member 
     18  ALIGN16  IntersectionStr 
     19  SimpleRay::IntersectionRes[32]; 
    820 
    921Intersectable::Intersectable():  
     
    1628#endif 
    1729{} 
     30 
    1831 
    1932 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Intersectable.h

    r2543 r2575  
    2121struct FaceParentInfo  
    2222{ 
    23         /// intersectable 
    24         Intersectable *mObject; 
    25         /// face index 
    26         int mFaceIndex; 
    27  
    28         FaceParentInfo(Intersectable *obj, const int fi): 
    29         mObject(obj), mFaceIndex(fi) 
    30         {} 
     23  /// intersectable 
     24  Intersectable *mObject; 
     25  /// face index 
     26  int mFaceIndex; 
     27   
     28  FaceParentInfo(Intersectable *obj, const int fi): 
     29    mObject(obj), mFaceIndex(fi) 
     30  {} 
    3131}; 
    3232 
     
    8989        virtual AxisAlignedBox3 GetBox() const = 0; 
    9090        virtual int CastRay(Ray &ray) = 0; 
     91        virtual int CastSimpleRay(const SimpleRay &ray) = 0; 
     92        virtual int CastSimpleRay(const SimpleRay &ray, int indexRay) = 0; 
    9193 
    9294        virtual bool IsConvex() const = 0; 
     
    157159        BvhLeaf *mBvhLeaf; 
    158160 
    159  
    160161protected: 
    161162 
  • GTP/trunk/Lib/Vis/Preprocessing/src/IntersectableWrapper.cpp

    r2571 r2575  
    44#include "KdTree.h" 
    55#include "BvHierarchy.h" 
     6#include "SimpleRay.h" 
    67 
    78 
     
    1112AxisAlignedBox3 TriangleIntersectable::GetBox() const 
    1213{        
    13         return mItem.GetBoundingBox(); 
    14 } 
    15  
    16  
     14  return mItem.GetBoundingBox(); 
     15} 
     16 
     17 
     18int 
     19TriangleIntersectable::CastSimpleRay(const SimpleRay &ray) 
     20{ 
     21  static Vector3 nearestNormal; 
     22  // std::cout << "To be done - ray triangle intersection\n" << std::endl; 
     23  const int hitCode = mItem.CastSimpleRay(ray, 
     24                                          SimpleRay::IntersectionRes[0].tdist, 
     25                                          SimpleRay::IntersectionRes[0].maxt); 
     26  if (hitCode == Ray::INTERSECTION) { 
     27    SimpleRay::IntersectionRes[0].intersectable = this; 
     28    SimpleRay::IntersectionRes[0].maxt = SimpleRay::IntersectionRes[0].tdist; 
     29    return 1; // intersection occured 
     30  } 
     31  return 0; // no intersection 
     32} 
     33 
     34int 
     35TriangleIntersectable::CastSimpleRay(const SimpleRay &ray, int rayIndex) 
     36{ 
     37  const int hitCode = 
     38    mItem.CastSimpleRay(ray, 
     39                        SimpleRay::IntersectionRes[rayIndex].tdist, 
     40                        SimpleRay::IntersectionRes[rayIndex].maxt); 
     41  if (hitCode == Ray::INTERSECTION) { 
     42    SimpleRay::IntersectionRes[rayIndex].intersectable = this; 
     43    // we copy the closest distance so far - it prunes the search 
     44    // when more triangles in the same leaf and assures the 
     45    // correctness. 
     46    SimpleRay::IntersectionRes[rayIndex].maxt = 
     47      SimpleRay::IntersectionRes[rayIndex].tdist; 
     48    return 1; // intersection occured 
     49  } 
     50  return 0; // no intersection 
     51} 
     52 
     53   
    1754int TriangleIntersectable::CastRay(Ray &ray) 
    1855{        
    19         float nearestT = MAX_FLOAT; 
    20         float t; 
    21         Vector3 nearestNormal; 
    22  
    23         if (ray.GetType() == Ray::LOCAL_RAY && !ray.intersections.empty()) 
    24                 nearestT = ray.intersections[0].mT; 
     56  float nearestT = MAX_FLOAT; 
     57  float t; 
     58  Vector3 nearestNormal; 
     59   
     60  if (ray.GetType() == Ray::LOCAL_RAY && !ray.intersections.empty()) 
     61    nearestT = ray.intersections[0].mT; 
     62   
     63  const int hitCode = mItem.CastRay(ray, t, nearestT, nearestNormal); 
     64   
     65  nearestT = t; 
     66   
     67  if (hitCode == Ray::INTERSECTION) { 
     68    if (ray.GetType() == Ray::LOCAL_RAY && !ray.intersections.empty()) { 
     69      ray.intersections[0] = Ray::Intersection(nearestT, 
     70                                               nearestNormal, 
     71                                               this, 
     72                                               0); 
     73    } 
     74    else { 
     75      ray.intersections.push_back(Ray::Intersection(nearestT, 
     76                                                    nearestNormal, 
     77                                                    this, 
     78                                                    0)); 
     79    } 
     80     
     81    return 1; 
     82  } 
     83   
     84  return 0; 
     85} 
    2586         
    26         const int hitCode = mItem.CastRay(ray, t, nearestT, nearestNormal); 
    27  
    28         nearestT = t; 
    29  
    30         if (hitCode == Ray::INTERSECTION) { 
    31                 if (ray.GetType() == Ray::LOCAL_RAY && !ray.intersections.empty()) { 
    32                         ray.intersections[0] = Ray::Intersection(nearestT, 
    33                                                                                                          nearestNormal, 
    34                                                                                                          this, 
    35                                                                                                          0); 
    36                 } 
    37                 else { 
    38                         ray.intersections.push_back(Ray::Intersection(nearestT, 
    39                                                                                                                   nearestNormal, 
    40                                                                                                                   this, 
    41                                                                                                                   0)); 
    42                 } 
    43                  
    44                 return 1; 
    45         } 
    46          
    47         return 0; 
    48 } 
    49          
    5087 
    5188int TriangleIntersectable::NumberOfFaces() const 
     
    5592 
    5693 
    57 Vector3 TriangleIntersectable::GetNormal(const int idx) const 
    58 { 
    59         return mItem.GetNormal(); 
     94Vector3 
     95TriangleIntersectable::GetNormal(const int idx) const 
     96{ 
     97  return mItem.GetNormal(); 
    6098} 
    6199 
  • GTP/trunk/Lib/Vis/Preprocessing/src/IntersectableWrapper.h

    r2569 r2575  
    4040         
    4141        int CastRay(Ray &ray); 
     42        int CastSimpleRay(const SimpleRay &ray) { return 0;} 
     43        int CastSimpleRay(const SimpleRay &ray, int RayIndex) { return 0;} 
     44   
    4245         
    4346        bool IsConvex() const; 
     
    193196 
    194197        int CastRay(Ray &ray); 
     198 
     199        int CastSimpleRay(const SimpleRay &ray); 
     200        int CastSimpleRay(const SimpleRay &ray, int rayIndex); 
     201         
    195202        AxisAlignedBox3 GetBox() const; 
    196203        int NumberOfFaces() const; 
    197204        Vector3 GetNormal(const int idx) const; 
     205        Vector3 GetNormal() const { return mItem.GetNormal();} 
    198206 
    199207        float GetArea() const {return mItem.GetArea();} 
     
    207215 
    208216        int GetRandomSurfacePoint(const float u, 
    209                                                           const float v, 
    210                                                           Vector3 &point, Vector3 &normal); 
     217                                  const float v, 
     218                                  Vector3 &point, Vector3 &normal); 
    211219 
    212220         
    213221        int GetRandomVisibleSurfacePoint(Vector3 &point, 
    214                                                                         Vector3 &normal, 
    215                                                                         const Vector3 &viewpoint, 
    216                                                                         const int maxTries); 
     222                                        Vector3 &normal, 
     223                                        const Vector3 &viewpoint, 
     224                                        const int maxTries); 
    217225 
    218226        int GetRandomEdgePoint(Vector3 &point, Vector3 &normal); 
     
    244252 
    245253        // hack 
    246         ContainerIntersectable::~ContainerIntersectable()  
     254        ~ContainerIntersectable()  
    247255        { 
    248256                delete mItem; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp

    r2571 r2575  
    2626inline static bool ilt(Intersectable *obj1, Intersectable *obj2) 
    2727{ 
    28         return obj1->mId < obj2->mId; 
     28  return obj1->mId < obj2->mId; 
    2929} 
    3030 
     
    3333mParent(parent), mMailbox(0), mIntersectable(NULL) 
    3434{ 
    35         if (parent) 
    36                 mDepth = parent->mDepth+1; 
    37         else 
    38                 mDepth = 0; 
     35  if (parent) 
     36    mDepth = parent->mDepth+1; 
     37  else 
     38    mDepth = 0; 
    3939} 
    4040 
     
    4242KdInterior::~KdInterior() 
    4343{ 
    44         // recursivly destroy children 
    45         DEL_PTR(mFront); 
    46         DEL_PTR(mBack); 
     44  // recursivly destroy children 
     45  DEL_PTR(mFront); 
     46  DEL_PTR(mBack); 
    4747} 
    4848 
     
    5050KdLeaf::~KdLeaf() 
    5151{ 
    52         DEL_PTR(mViewCell);   
     52  DEL_PTR(mViewCell);   
    5353} 
    5454 
     
    5757{  
    5858  mRoot = new KdLeaf(NULL, 0); 
    59   Environment::GetSingleton()->GetIntValue("KdTree.Termination.maxNodes", mTermMaxNodes); 
    60   Environment::GetSingleton()->GetIntValue("KdTree.Termination.maxDepth", mTermMaxDepth); 
    61   Environment::GetSingleton()->GetIntValue("KdTree.Termination.minCost", mTermMinCost); 
    62   Environment::GetSingleton()->GetFloatValue("KdTree.Termination.maxCostRatio", mMaxCostRatio); 
    63   Environment::GetSingleton()->GetFloatValue("KdTree.Termination.ct_div_ci", mCt_div_ci); 
    64   Environment::GetSingleton()->GetFloatValue("KdTree.splitBorder", mSplitBorder); 
    65   Environment::GetSingleton()->GetFloatValue("KdTree.pvsArea", mKdPvsArea); 
    66  
    67   Environment::GetSingleton()->GetBoolValue("KdTree.sahUseFaces", mSahUseFaces); 
     59  Environment::GetSingleton()->GetIntValue("KdTree.Termination.maxNodes", 
     60                                           mTermMaxNodes); 
     61  Environment::GetSingleton()->GetIntValue("KdTree.Termination.maxDepth", 
     62                                           mTermMaxDepth); 
     63  Environment::GetSingleton()->GetIntValue("KdTree.Termination.minCost", 
     64                                           mTermMinCost); 
     65  Environment::GetSingleton()->GetFloatValue("KdTree.Termination.maxCostRatio", 
     66                                             mMaxCostRatio); 
     67  Environment::GetSingleton()->GetFloatValue("KdTree.Termination.ct_div_ci", 
     68                                             mCt_div_ci); 
     69  Environment::GetSingleton()->GetFloatValue("KdTree.splitBorder", 
     70                                             mSplitBorder); 
     71  Environment::GetSingleton()->GetFloatValue("KdTree.pvsArea", 
     72                                             mKdPvsArea); 
     73 
     74  Environment::GetSingleton()->GetBoolValue("KdTree.sahUseFaces", 
     75                                            mSahUseFaces); 
    6876 
    6977  char splitType[64]; 
     
    97105KdTree::Construct() 
    98106{ 
    99  
    100107  if (!splitCandidates) 
    101108    splitCandidates = new vector<SortableEntry *>; 
     
    158165     
    159166    KdNode *node = SubdivideNode((KdLeaf *) data.mNode, 
    160                                                                 data.mBox, 
    161                                                                 backBox, 
    162                                                                 frontBox 
    163                                                                 ); 
    164  
    165         if (result == NULL) 
     167                                data.mBox, 
     168                                backBox, 
     169                                frontBox 
     170                                ); 
     171 
     172    if (result == NULL) 
    166173      result = node; 
    167174     
    168175    if (!node->IsLeaf()) { 
    169  
    170176      KdInterior *interior = (KdInterior *) node; 
    171177      // push the children on the stack 
     
    173179      tStack.push(TraversalData(interior->mFront, frontBox, data.mDepth+1)); 
    174180       
    175     } else { 
     181    } 
     182    else { 
    176183      EvaluateLeafStats(data); 
    177184    } 
     
    186193KdTree::TerminationCriteriaMet(const KdLeaf *leaf) 
    187194{ 
    188         const bool criteriaMet = 
    189                 ((int)leaf->mObjects.size() <= mTermMinCost) || 
    190                 (leaf->mDepth >= mTermMaxDepth); 
    191   
    192         if (0 && criteriaMet) 
    193                 cerr<<"\n OBJECTS="<<(int)leaf->mObjects.size()<<endl; 
    194  
    195         return criteriaMet; 
     195  const bool criteriaMet = 
     196    ((int)leaf->mObjects.size() <= mTermMinCost) || 
     197    (leaf->mDepth >= mTermMaxDepth); 
     198   
     199  if (0 && criteriaMet) 
     200    cerr<<"\n OBJECTS="<<(int)leaf->mObjects.size()<<endl; 
     201   
     202  return criteriaMet; 
    196203} 
    197204 
     
    199206int 
    200207KdTree::SelectPlane(KdLeaf *leaf, 
    201                                         const AxisAlignedBox3 &box, 
    202                                         float &position 
    203                                         ) 
     208                    const AxisAlignedBox3 &box, 
     209                    float &position 
     210                    ) 
    204211{ 
    205212  int axis = -1; 
     
    217224      bool mOnlyDrivingAxis = true; 
    218225 
    219           if (mOnlyDrivingAxis) { 
    220                 axis = box.Size().DrivingAxis(); 
    221                 costRatio = BestCostRatio(leaf, 
    222                                                                   box, 
    223                                                                   axis, 
    224                                                                   position, 
    225                                                                   objectsBack, 
    226                                                                   objectsFront); 
    227       } else { 
    228                 costRatio = MAX_FLOAT; 
    229                 for (int i=0; i < 3; i++) { 
    230                   float p; 
    231                   float r = BestCostRatio(leaf, 
    232                                                                   box, 
    233                                                                   i, 
    234                                                                   p, 
    235                                                                   objectsBack, 
    236                                                                   objectsFront); 
    237                   if (r < costRatio) { 
    238                         costRatio = r; 
    239                         axis = i; 
    240                         position = p; 
    241                   } 
    242                 } 
     226      if (mOnlyDrivingAxis) { 
     227        axis = box.Size().DrivingAxis(); 
     228        costRatio = BestCostRatio(leaf, 
     229                                  box, 
     230                                  axis, 
     231                                  position, 
     232                                  objectsBack, 
     233                                  objectsFront); 
     234      } 
     235      else { 
     236        // for all 3 axes 
     237        costRatio = MAX_FLOAT; 
     238        for (int i=0; i < 3; i++) { 
     239          float p; 
     240          float r = BestCostRatio(leaf, 
     241                                  box, 
     242                                  i, 
     243                                  p, 
     244                                  objectsBack, 
     245                                  objectsFront); 
     246          if (r < costRatio) { 
     247            costRatio = r; 
     248            axis = i; 
     249            position = p; 
     250          } 
     251        } 
    243252      } 
    244253       
    245254      if (costRatio > mMaxCostRatio) { 
    246                 //cout<<"Too big cost ratio "<<costRatio<<endl; 
    247                 axis = -1; 
     255        //cout<<"Too big cost ratio "<<costRatio<<endl; 
     256        axis = -1; 
    248257      } 
    249258      break; 
     
    254263} 
    255264 
    256 KdNode * 
     265KdNode* 
    257266KdTree::SubdivideNode( 
    258267                      KdLeaf *leaf, 
     
    261270                      AxisAlignedBox3 &frontBBox 
    262271                      ) 
    263 { 
    264    
     272 
    265273  if (TerminationCriteriaMet(leaf)) 
    266           return leaf; 
     274    return leaf; 
    267275 
    268276  float position; 
     
    275283  } 
    276284   
    277   mStat.nodes+=2; 
     285  mStat.nodes += 2; 
    278286  mStat.splits[axis]++; 
    279287   
     
    309317  } 
    310318 
    311    
    312319  KdLeaf *back = new KdLeaf(node, objectsBack); 
    313320  KdLeaf *front = new KdLeaf(node, objectsFront); 
    314  
    315321  
    316322  // replace a link from node's parent 
     
    336342 
    337343 
    338         if (box.Max(axis) >= position ) 
    339         { 
     344    if (box.Max(axis) >= position ) 
     345    { 
    340346      front->mObjects.push_back(*mi); 
    341           //++ (*mi)->mReferences; 
    342         } 
     347      //++ (*mi)->mReferences; 
     348    } 
    343349         
    344350    if (box.Min(axis) < position ) 
    345         { 
     351    { 
    346352      back->mObjects.push_back(*mi); 
    347         // matt: no more ref 
    348         //  ++ (*mi)->mReferences; 
    349         } 
     353      // matt: no more ref 
     354      //  ++ (*mi)->mReferences; 
     355    } 
    350356 
    351357    mStat.objectRefs -= (int)leaf->mObjects.size(); 
     
    353359  } 
    354360 
    355         // store objects referenced in more than one leaf 
    356         // for easy access 
    357         ProcessMultipleRefs(back); 
    358         ProcessMultipleRefs(front); 
    359  
    360         delete leaf; 
    361         return node; 
     361  // store objects referenced in more than one leaf 
     362  // for easy access 
     363  ProcessMultipleRefs(back); 
     364  ProcessMultipleRefs(front); 
     365   
     366  delete leaf; 
     367  return node; 
    362368} 
    363369 
     
    365371void KdTree::ProcessMultipleRefs(KdLeaf *leaf) const 
    366372{ 
    367         // find objects from multiple kd-leaves 
    368         ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end(); 
    369  
    370         for (oit = leaf->mObjects.begin(); oit != oit_end; ++ oit) 
    371         { 
    372                 Intersectable *object = *oit; 
     373  // find objects from multiple kd-leaves 
     374  ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end(); 
     375 
     376  for (oit = leaf->mObjects.begin(); oit != oit_end; ++ oit) 
     377  { 
     378    Intersectable *object = *oit; 
    373379                 
    374                 // matt: no more ref 
    375                 /*if (object->mReferences > 1) 
    376                 { 
    377                         leaf->mMultipleObjects.push_back(object); 
    378                 }*/ 
    379         } 
     380    // matt: no more ref 
     381    /* 
     382      if (object->mReferences > 1) { 
     383        leaf->mMultipleObjects.push_back(object); 
     384      } 
     385    */ 
     386  } 
    380387} 
    381388 
     
    464471void 
    465472KdTree::SortSubdivisionCandidates( 
    466                             KdLeaf *node, 
    467                             const int axis 
    468                             ) 
    469 { 
    470         CLEAR_CONTAINER(*splitCandidates); 
    471         //splitCandidates->clear(); 
    472  
    473     int requestedSize = 2*(int)node->mObjects.size(); 
    474          
    475         // creates a sorted split candidates array 
    476         if (splitCandidates->capacity() > 500000 && 
    477                 requestedSize < (int)(splitCandidates->capacity()/10) ) {                
    478                         delete splitCandidates; 
    479                         splitCandidates = new vector<SortableEntry *>; 
     473                                  KdLeaf *node, 
     474                                  const int axis 
     475                                  ) 
     476{ 
     477  CLEAR_CONTAINER(*splitCandidates); 
     478  //splitCandidates->clear(); 
     479   
     480  int requestedSize = 2*(int)node->mObjects.size(); 
     481   
     482  // creates a sorted split candidates array 
     483  if (splitCandidates->capacity() > 500000 && 
     484      requestedSize < (int)(splitCandidates->capacity()/10) ) {          
     485    delete splitCandidates; 
     486    splitCandidates = new vector<SortableEntry *>; 
    480487  } 
    481488   
     
    487494      mi++)  
    488495  { 
    489           AxisAlignedBox3 box = (*mi)->GetBox(); 
    490  
    491           splitCandidates->push_back(new SortableEntry(SortableEntry::BOX_MIN, 
    492                                                                 box.Min(axis), 
    493                                                                 *mi) 
    494                                                                 ); 
     496    AxisAlignedBox3 box = (*mi)->GetBox(); 
     497 
     498    splitCandidates->push_back(new SortableEntry(SortableEntry::BOX_MIN, 
     499                                                box.Min(axis), 
     500                                                *mi) 
     501                              ); 
    495502     
    496       splitCandidates->push_back(new SortableEntry(SortableEntry::BOX_MAX, 
    497                                                                 box.Max(axis), 
    498                                                                 *mi) 
    499                                                                 ); 
     503    splitCandidates->push_back(new SortableEntry(SortableEntry::BOX_MAX, 
     504                                                box.Max(axis), 
     505                                                *mi) 
     506                              ); 
    500507  } 
    501508   
     
    506513float 
    507514KdTree::BestCostRatio( 
    508                                           KdLeaf *node, 
    509                                           const AxisAlignedBox3 &box, 
    510                                           const int axis, 
    511                                           float &position, 
    512                                           int &objectsBack, 
    513                                           int &objectsFront 
    514                                           ) 
     515                      KdLeaf *node, 
     516                      const AxisAlignedBox3 &box, 
     517                      const int axis, 
     518                      float &position, 
     519                      int &objectsBack, 
     520                      int &objectsFront 
     521                      ) 
    515522{ 
    516523 
     
    531538   
    532539  if (nodeId < 100) 
    533         costStream.open(filename); 
     540    costStream.open(filename); 
    534541 
    535542#endif 
     
    577584      intersectionsRight -= (*ci)->intersectable->IntersectionComplexity(); 
    578585      break; 
    579     } 
     586    } // switch 
    580587 
    581588    if ((*ci)->value > minBand && (*ci)->value < maxBand) { 
     
    587594      float sum; 
    588595      if (mSahUseFaces) 
    589                 sum = intersectionsLeft*lbox.SurfaceArea() + intersectionsRight*rbox.SurfaceArea(); 
     596        sum = intersectionsLeft*lbox.SurfaceArea() + intersectionsRight*rbox.SurfaceArea(); 
    590597      else 
    591                 sum = objectsLeft*lbox.SurfaceArea() + objectsRight*rbox.SurfaceArea(); 
     598        sum = objectsLeft*lbox.SurfaceArea() + objectsRight*rbox.SurfaceArea(); 
    592599       
    593600      //      cout<<"pos="<<(*ci).value<<"\t q=("<<ql<<","<<qr<<")\t r=("<<rl<<","<<rr<<")"<<endl; 
     
    595602 
    596603#if DEBUG_COST 
    597   if (nodeId < 100) { 
     604      if (nodeId < 100) { 
    598605        float oldCost = mSahUseFaces ? totalIntersections : node->mObjects.size(); 
    599606        float newCost = mCt_div_ci + sum/boxArea; 
    600607        float ratio = newCost/oldCost; 
    601608        costStream<<(*ci)->value<<" "<<ratio<<endl; 
    602   } 
     609      } 
    603610#endif 
    604            
     611       
    605612      if (sum < minSum) { 
    606                 minSum = sum; 
    607                 position = (*ci)->value; 
    608                  
    609                 objectsBack = objectsLeft; 
    610                 objectsFront = objectsRight; 
    611       } 
    612     } 
    613   } 
     613        minSum = sum; 
     614        position = (*ci)->value; 
     615         
     616        objectsBack = objectsLeft; 
     617        objectsFront = objectsRight; 
     618      } 
     619    } 
     620  } // for ci 
    614621   
    615622  float oldCost = mSahUseFaces ? totalIntersections : node->mObjects.size(); 
     
    627634int 
    628635KdTree::CastRay( 
    629                                 Ray &ray 
    630                                 ) 
     636                Ray &ray 
     637                ) 
    631638{ 
    632639   
     
    666673 
    667674      if (entp[axis] <= position) { 
    668                 if (extp[axis] <= position) { 
    669                   node = in->mBack; 
    670                   // cases N1,N2,N3,P5,Z2,Z3 
    671                   continue; 
    672                 } else { 
    673                   // case N4 
    674                   node = in->mBack; 
    675                   farChild = in->mFront; 
    676                 } 
     675        if (extp[axis] <= position) { 
     676          node = in->mBack; 
     677          // cases N1,N2,N3,P5,Z2,Z3 
     678          continue; 
     679        } 
     680        else { 
     681          // case N4 
     682          node = in->mBack; 
     683          farChild = in->mFront; 
     684        } 
    677685      } 
    678686      else { 
    679                 if (position <= extp[axis]) { 
    680                   node = in->mFront; 
    681                   // cases P1,P2,P3,N5,Z1 
    682                   continue; 
    683                 } else { 
    684                   node = in->mFront; 
    685                   farChild = in->mBack; 
    686                   // case P4 
    687                 } 
    688           } 
     687        if (position <= extp[axis]) { 
     688          node = in->mFront; 
     689          // cases P1,P2,P3,N5,Z1 
     690          continue; 
     691        } 
     692        else { 
     693          node = in->mFront; 
     694          farChild = in->mBack; 
     695          // case P4 
     696        } 
     697      } 
    689698      // $$ modification 3.5.2004 - hints from Kamil Ghais 
    690699      // case N4 or P4 
     
    693702      extp = ray.GetLoc() + ray.GetDir()*tdist; 
    694703      maxt = tdist; 
    695         } else { 
    696           // compute intersection with all objects in this leaf 
    697           KdLeaf *leaf = (KdLeaf *) node; 
    698           if (ray.mFlags & Ray::STORE_KDLEAVES) 
    699                 ray.kdLeaves.push_back(leaf); 
     704    } 
     705    else { 
     706      // compute intersection with all objects in this leaf 
     707      KdLeaf *leaf = (KdLeaf *) node; 
     708      if (ray.mFlags & Ray::STORE_KDLEAVES) 
     709        ray.kdLeaves.push_back(leaf); 
    700710           
    701           ObjectContainer::const_iterator mi; 
    702           for ( mi = leaf->mObjects.begin(); 
    703                         mi != leaf->mObjects.end(); 
    704                         mi++) { 
    705                 Intersectable *object = *mi; 
    706                 if (!object->Mailed() ) { 
    707                   object->Mail(); 
    708                   if (ray.mFlags & Ray::STORE_TESTED_OBJECTS) 
     711      ObjectContainer::const_iterator mi; 
     712      for ( mi = leaf->mObjects.begin(); 
     713            mi != leaf->mObjects.end(); 
     714            mi++) { 
     715        Intersectable *object = *mi; 
     716        if (!object->Mailed() ) { 
     717          object->Mail(); 
     718          if (ray.mFlags & Ray::STORE_TESTED_OBJECTS) 
    709719                        ray.testedObjects.push_back(object); 
    710720                   
    711                   static int oi=1; 
    712                   if (MeshDebug)  
    713                         cout<<"Object "<<oi++; 
    714                    
    715                   hits += object->CastRay(ray); 
    716                    
    717                   if (MeshDebug) { 
    718                         if (!ray.intersections.empty())  
    719                           cout<<"nearest t="<<ray.intersections[0].mT<<endl; 
    720                         else 
    721                           cout<<"nearest t=-INF"<<endl; 
    722                   }        
    723                 } 
    724           } 
     721          static int oi=1; 
     722          if (MeshDebug)  
     723            cout<<"Object "<<oi++; 
    725724           
    726           if (hits && ray.GetType() == Ray::LOCAL_RAY) 
    727                 if (ray.intersections[0].mT <= maxt) 
    728                   break; 
     725          hits += object->CastRay(ray); 
    729726           
    730           // get the next node from the stack 
    731           if (tStack.empty()) 
    732                 break; 
     727          if (MeshDebug) { 
     728            if (!ray.intersections.empty())  
     729              cout<<"nearest t="<<ray.intersections[0].mT<<endl; 
     730            else 
     731              cout<<"nearest t=-INF"<<endl; 
     732          }        
     733        } 
     734      } 
    733735           
    734           entp = extp; 
    735           mint = maxt; 
    736           if (ray.GetType() == Ray::LINE_SEGMENT && mint > 1.0f) 
    737                 break; 
    738            
    739           RayTraversalData &s  = tStack.top(); 
    740           node = s.mNode; 
    741           extp = s.mExitPoint; 
    742           maxt = s.mMaxT; 
    743           tStack.pop(); 
    744         } 
     736      if (hits && ray.GetType() == Ray::LOCAL_RAY) 
     737        if (ray.intersections[0].mT <= maxt) 
     738          break; 
     739       
     740      // get the next node from the stack 
     741      if (tStack.empty()) 
     742        break; 
     743       
     744      entp = extp; 
     745      mint = maxt; 
     746      if (ray.GetType() == Ray::LINE_SEGMENT && mint > 1.0f) 
     747        break; 
     748       
     749      RayTraversalData &s  = tStack.top(); 
     750      node = s.mNode; 
     751      extp = s.mExitPoint; 
     752      maxt = s.mMaxT; 
     753      tStack.pop(); 
     754    } 
    745755  } 
    746756  return hits; 
     
    748758 
    749759int KdTree::CastLineSegment(const Vector3 &origin, 
    750                                                         const Vector3 &termination, 
    751                                                         ViewCellContainer &viewcells) 
    752 { 
    753         int hits = 0; 
    754  
    755         float mint = 0.0f, maxt = 1.0f; 
    756         const Vector3 dir = termination - origin; 
    757  
    758         stack<RayTraversalData> tStack; 
    759  
    760         Intersectable::NewMail(); 
    761  
    762         //maxt += Limits::Threshold; 
    763  
    764         Vector3 entp = origin; 
    765         Vector3 extp = termination; 
    766  
    767         KdNode *node = mRoot; 
    768         KdNode *farChild; 
    769  
    770         float position; 
    771         int axis; 
    772  
    773         while (1) 
     760                            const Vector3 &termination, 
     761                            ViewCellContainer &viewcells) 
     762{ 
     763  int hits = 0; 
     764 
     765  float mint = 0.0f, maxt = 1.0f; 
     766  const Vector3 dir = termination - origin; 
     767   
     768  stack<RayTraversalData> tStack; 
     769   
     770  Intersectable::NewMail(); 
     771   
     772  //maxt += Limits::Threshold; 
     773   
     774  Vector3 entp = origin; 
     775  Vector3 extp = termination; 
     776   
     777  KdNode *node = mRoot; 
     778  KdNode *farChild; 
     779   
     780  float position; 
     781  int axis; 
     782 
     783  while (1) 
     784  { 
     785    if (!node->IsLeaf()) 
     786    { 
     787      KdInterior *in = static_cast<KdInterior *>(node); 
     788      position = in->mPosition; 
     789      axis = in->mAxis; 
     790       
     791      if (entp[axis] <= position) 
     792      { 
     793        if (extp[axis] <= position) 
    774794        { 
    775                 if (!node->IsLeaf()) 
    776                 { 
    777                         KdInterior *in = static_cast<KdInterior *>(node); 
    778                         position = in->mPosition; 
    779                         axis = in->mAxis; 
    780  
    781                         if (entp[axis] <= position) 
    782                         { 
    783                                 if (extp[axis] <= position) 
    784                                 { 
    785                                         node = in->mBack; 
    786                                         // cases N1,N2,N3,P5,Z2,Z3 
    787                                         continue; 
    788                                 }  
    789                                 else 
    790                                 { 
    791                                         // case N4 
    792                                         node = in->mBack; 
    793                                         farChild = in->mFront; 
    794                                 } 
    795                         } 
    796                         else 
    797                         { 
    798                                 if (position <= extp[axis]) 
    799                                 { 
    800                                         node = in->mFront; 
    801                                         // cases P1,P2,P3,N5,Z1 
    802                                         continue; 
    803                                 } 
    804                                 else 
    805                                 { 
    806                                         node = in->mFront; 
    807                                         farChild = in->mBack; 
    808                                         // case P4 
    809                                 } 
    810                         } 
    811  
    812                         // $$ modification 3.5.2004 - hints from Kamil Ghais 
    813                         // case N4 or P4 
    814                         float tdist = (position - origin[axis]) / dir[axis]; 
    815                         //tStack.push(RayTraversalData(farChild, extp, maxt)); //TODO 
    816                         extp = origin + dir * tdist; 
    817                         maxt = tdist; 
    818                 } 
    819                 else 
    820                 { 
    821                         // compute intersection with all objects in this leaf 
    822                         KdLeaf *leaf = static_cast<KdLeaf *>(node); 
    823  
    824                         // add view cell to intersections 
    825                         ViewCell *vc = leaf->mViewCell; 
    826  
    827                         if (!vc->Mailed()) 
    828                         { 
    829                                 vc->Mail(); 
    830                                 viewcells.push_back(vc); 
    831                                 ++ hits; 
    832                         } 
    833  
    834                         // get the next node from the stack 
    835                         if (tStack.empty()) 
    836                                 break; 
    837  
    838                         entp = extp; 
    839                         mint = maxt; 
    840                          
    841                         RayTraversalData &s  = tStack.top(); 
    842                         node = s.mNode; 
    843                         extp = s.mExitPoint; 
    844                         maxt = s.mMaxT; 
    845                         tStack.pop(); 
    846                 } 
    847         } 
    848  
    849         return hits; 
     795          node = in->mBack; 
     796          // cases N1,N2,N3,P5,Z2,Z3 
     797          continue; 
     798        }  
     799        else 
     800        { 
     801          // case N4 
     802          node = in->mBack; 
     803          farChild = in->mFront; 
     804        } 
     805      } 
     806      else 
     807      { 
     808        if (position <= extp[axis]) 
     809        { 
     810          node = in->mFront; 
     811          // cases P1,P2,P3,N5,Z1 
     812          continue; 
     813        } 
     814        else 
     815        { 
     816          node = in->mFront; 
     817          farChild = in->mBack; 
     818          // case P4 
     819        } 
     820      } 
     821       
     822      // $$ modification 3.5.2004 - hints from Kamil Ghais 
     823      // case N4 or P4 
     824      float tdist = (position - origin[axis]) / dir[axis]; 
     825      //tStack.push(RayTraversalData(farChild, extp, maxt)); //TODO 
     826      extp = origin + dir * tdist; 
     827      maxt = tdist; 
     828    } 
     829    else 
     830    { 
     831      // compute intersection with all objects in this leaf 
     832      KdLeaf *leaf = static_cast<KdLeaf *>(node); 
     833       
     834      // add view cell to intersections 
     835      ViewCell *vc = leaf->mViewCell; 
     836       
     837      if (!vc->Mailed()) 
     838      { 
     839        vc->Mail(); 
     840        viewcells.push_back(vc); 
     841        ++ hits; 
     842      } 
     843       
     844      // get the next node from the stack 
     845      if (tStack.empty()) 
     846        break; 
     847       
     848      entp = extp; 
     849      mint = maxt; 
     850       
     851      RayTraversalData &s  = tStack.top(); 
     852      node = s.mNode; 
     853      extp = s.mExitPoint; 
     854      maxt = s.mMaxT; 
     855      tStack.pop(); 
     856    } 
     857  } 
     858  return hits; 
    850859} 
    851860 
    852861void 
    853862KdTree::CollectKdObjects(const AxisAlignedBox3 &box, 
    854                                                 ObjectContainer &objects 
    855                                                  ) 
     863                        ObjectContainer &objects 
     864                        ) 
    856865{ 
    857866  stack<KdNode *> nodeStack; 
     
    862871    KdNode *node = nodeStack.top(); 
    863872    nodeStack.pop(); 
    864         if (node->IsLeaf() || node->mPvsTermination == 1)  { 
    865           Intersectable *object = GetOrCreateKdIntersectable(node); 
    866           if (!node->Mailed()) { 
    867                 node->Mail(); 
    868                 objects.push_back(object); 
    869           } 
    870         } else { 
     873    if (node->IsLeaf() || node->mPvsTermination == 1)  { 
     874      Intersectable *object = GetOrCreateKdIntersectable(node); 
     875      if (!node->Mailed()) { 
     876        node->Mail(); 
     877        objects.push_back(object); 
     878      } 
     879    } 
     880    else { 
    871881      KdInterior *interior = (KdInterior *)node; 
    872882           
    873           if ( box.Max()[interior->mAxis] > interior->mPosition ) 
    874                 nodeStack.push(interior->mFront); 
    875            
    876           if (box.Min()[interior->mAxis] < interior->mPosition) 
    877                 nodeStack.push(interior->mBack); 
    878     } 
    879   } 
     883      if ( box.Max()[interior->mAxis] > interior->mPosition ) 
     884        nodeStack.push(interior->mFront); 
     885       
     886      if (box.Min()[interior->mAxis] < interior->mPosition) 
     887        nodeStack.push(interior->mBack); 
     888    } 
     889  } // while 
    880890} 
    881891 
    882892void 
    883893KdTree::CollectObjects(const AxisAlignedBox3 &box, 
    884                                            ObjectContainer &objects) 
     894                       ObjectContainer &objects) 
    885895{ 
    886896  stack<KdNode *> nodeStack; 
     
    894904      KdLeaf *leaf = (KdLeaf *)node; 
    895905      for (int j=0; j < leaf->mObjects.size(); j++) { 
    896                 Intersectable *object = leaf->mObjects[j]; 
    897                 if (!object->Mailed() && Overlap(box, object->GetBox())) { 
    898                   object->Mail(); 
    899                   objects.push_back(object); 
    900                 } 
     906        Intersectable *object = leaf->mObjects[j]; 
     907        if (!object->Mailed() && Overlap(box, object->GetBox())) { 
     908          object->Mail(); 
     909          objects.push_back(object); 
     910        } 
    901911      } 
    902912    } else { 
    903913      KdInterior *interior = (KdInterior *)node; 
    904914 
    905           if ( box.Max()[interior->mAxis] > interior->mPosition ) 
    906                 nodeStack.push(interior->mFront); 
    907   
    908           if (box.Min()[interior->mAxis] < interior->mPosition) 
    909                 nodeStack.push(interior->mBack); 
     915      if ( box.Max()[interior->mAxis] > interior->mPosition ) 
     916        nodeStack.push(interior->mFront); 
     917       
     918      if (box.Min()[interior->mAxis] < interior->mPosition) 
     919        nodeStack.push(interior->mBack); 
    910920    } 
    911921  } 
     
    925935      KdLeaf *leaf = (KdLeaf *)node; 
    926936      for (int j=0; j < leaf->mObjects.size(); j++) { 
    927                                 Intersectable *object = leaf->mObjects[j]; 
    928                                 if (!object->Mailed()) { 
    929                                         object->Mail(); 
    930                                         objects.push_back(object); 
    931                                 } 
     937        Intersectable *object = leaf->mObjects[j]; 
     938        if (!object->Mailed()) { 
     939          object->Mail(); 
     940          objects.push_back(object); 
     941        } 
    932942      } 
    933943    } else { 
     
    942952KdNode * 
    943953KdTree::FindRandomNeighbor(KdNode *n, 
    944                                                    bool onlyUnmailed 
    945                                                    ) 
     954                           bool onlyUnmailed 
     955                           ) 
    946956{ 
    947957  stack<KdNode *> nodeStack; 
     
    9971007      if ( node != n && (!onlyUnmailed || !node->Mailed()) )  
    9981008        neighbors.push_back(node); 
    999     } else { 
     1009    } 
     1010    else { 
    10001011      KdInterior *interior = (KdInterior *)node; 
    10011012      if (interior->mPosition > box.Max(interior->mAxis)) 
    1002                                 nodeStack.push(interior->mBack); 
    1003       else 
    1004                                 if (interior->mPosition < box.Min(interior->mAxis)) 
    1005                                         nodeStack.push(interior->mFront); 
    1006                                 else { 
    1007                                         // random decision 
    1008                                         nodeStack.push(interior->mBack); 
    1009                                         nodeStack.push(interior->mFront); 
    1010                                 } 
     1013        nodeStack.push(interior->mBack); 
     1014      else { 
     1015        if (interior->mPosition < box.Min(interior->mAxis)) 
     1016          nodeStack.push(interior->mFront); 
     1017        else { 
     1018          // random decision 
     1019          nodeStack.push(interior->mBack); 
     1020          nodeStack.push(interior->mFront); 
     1021        } 
     1022      } 
    10111023    } 
    10121024  } 
     
    11811193void KdTree::ExportBinLeaf(OUT_STREAM &stream, KdLeaf *leaf) 
    11821194{ 
    1183         ObjectContainer::const_iterator it, it_end = leaf->mObjects.end(); 
     1195  ObjectContainer::const_iterator it, it_end = leaf->mObjects.end(); 
     1196   
     1197  int type = TYPE_LEAF; 
     1198  int size = (int)leaf->mObjects.size(); 
     1199   
     1200  stream.write(reinterpret_cast<char *>(&type), sizeof(int)); 
     1201  stream.write(reinterpret_cast<char *>(&size), sizeof(int)); 
     1202   
     1203  for (it = leaf->mObjects.begin(); it != it_end; ++ it) 
     1204    {    
     1205      Intersectable *obj = *it; 
     1206      int id = obj->mId;                 
     1207       
     1208      //stream.write(reinterpret_cast<char *>(&origin), sizeof(Vector3)); 
     1209      stream.write(reinterpret_cast<char *>(&id), sizeof(int)); 
     1210    } 
     1211} 
     1212 
     1213 
     1214KdLeaf *KdTree::ImportBinLeaf(IN_STREAM &stream,  
     1215                              KdInterior *parent, 
     1216                              const ObjectContainer &objects) 
     1217{ 
     1218  int leafId = TYPE_LEAF; 
     1219  int objId = leafId; 
     1220  int size; 
     1221   
     1222  stream.read(reinterpret_cast<char *>(&size), sizeof(int)); 
     1223  KdLeaf *leaf = new KdLeaf(parent, size); 
     1224 
     1225  MeshInstance dummyInst(NULL); 
    11841226         
    1185         int type = TYPE_LEAF; 
    1186         int size = (int)leaf->mObjects.size(); 
    1187  
    1188         stream.write(reinterpret_cast<char *>(&type), sizeof(int)); 
    1189         stream.write(reinterpret_cast<char *>(&size), sizeof(int)); 
    1190  
    1191         for (it = leaf->mObjects.begin(); it != it_end; ++ it) 
    1192         {        
    1193                 Intersectable *obj = *it; 
    1194                 int id = obj->mId;               
    1195          
    1196                 //stream.write(reinterpret_cast<char *>(&origin), sizeof(Vector3)); 
    1197                 stream.write(reinterpret_cast<char *>(&id), sizeof(int)); 
    1198     } 
    1199 } 
    1200  
    1201  
    1202 KdLeaf *KdTree::ImportBinLeaf(IN_STREAM &stream,  
    1203                                                           KdInterior *parent, 
    1204                                                           const ObjectContainer &objects) 
    1205 { 
    1206         int leafId = TYPE_LEAF; 
    1207         int objId = leafId; 
    1208         int size; 
    1209  
    1210         stream.read(reinterpret_cast<char *>(&size), sizeof(int)); 
    1211         KdLeaf *leaf = new KdLeaf(parent, size); 
    1212  
    1213         MeshInstance dummyInst(NULL); 
    1214          
    1215         // read object ids 
    1216         // note: this can also be done geometrically 
    1217         for (int i = 0; i < size; ++ i) 
    1218         {        
    1219                 stream.read(reinterpret_cast<char *>(&objId), sizeof(int)); 
    1220                 dummyInst.SetId(objId); 
    1221  
    1222                 ObjectContainer::const_iterator oit = 
    1223                         lower_bound(objects.begin(), objects.end(), (Intersectable *)&dummyInst, ilt); 
    1224                                                                  
    1225                 if ((oit != objects.end()) && ((*oit)->GetId() == objId)) 
    1226                         leaf->mObjects.push_back(*oit); 
    1227                 else 
    1228                         Debug << "error: object with id " << objId << " does not exist" << endl; 
    1229         } 
    1230  
    1231         return leaf; 
     1227  // read object ids 
     1228  // note: this can also be done geometrically 
     1229  for (int i = 0; i < size; ++ i) 
     1230    {    
     1231      stream.read(reinterpret_cast<char *>(&objId), sizeof(int)); 
     1232      dummyInst.SetId(objId); 
     1233       
     1234      ObjectContainer::const_iterator oit = 
     1235        lower_bound(objects.begin(), objects.end(), (Intersectable *)&dummyInst, ilt); 
     1236       
     1237      if ((oit != objects.end()) && ((*oit)->GetId() == objId)) 
     1238        leaf->mObjects.push_back(*oit); 
     1239      else 
     1240        Debug << "error: object with id " << objId << " does not exist" << endl; 
     1241    } 
     1242   
     1243  return leaf; 
    12321244} 
    12331245 
     
    13191331bool KdTree::ImportBinTree(const string &filename, ObjectContainer &objects) 
    13201332{ 
    1321         // export binary version of mesh 
    1322         queue<TraversalData> tStack; 
    1323         IN_STREAM stream(filename.c_str(), IN_BIN_MODE); 
    1324  
    1325         if (!stream.is_open()) return false; 
    1326  
    1327         // sort objects by their id 
    1328 //      if (!is_sorted(objects.begin(), objects.end(), ilt)) 
    1329                 sort(objects.begin(), objects.end(), ilt); 
    1330  
    1331         mBox.Initialize(); 
    1332         ObjectContainer::const_iterator oit, oit_end = objects.end(); 
    1333  
    1334         /////////////////////////// 
    1335         //-- compute bounding box of object space 
    1336  
    1337     for (oit = objects.begin(); oit != oit_end; ++ oit) 
    1338         { 
    1339                 const AxisAlignedBox3 box = (*oit)->GetBox(); 
    1340                 mBox.Include(box); 
    1341         } 
    1342  
    1343         // hack: we make a new root 
    1344         DEL_PTR(mRoot); 
    1345    
    1346         mRoot = ImportNextNode(stream, NULL, objects); 
    1347  
    1348         tStack.push(TraversalData(mRoot, mBox, 0)); 
    1349         mStat.Reset(); 
    1350         mStat.nodes = 1; 
    1351  
    1352         while(!tStack.empty()) 
    1353         { 
    1354                 TraversalData tData = tStack.front(); 
    1355                 tStack.pop(); 
    1356  
    1357                 KdNode *node = tData.mNode; 
    1358  
    1359                 if (!node->IsLeaf()) 
    1360                 { 
    1361                         mStat.nodes += 2; 
    1362  
    1363                         //Debug << "i" ; 
    1364                         KdInterior *interior = static_cast<KdInterior *>(node); 
    1365                         interior->mBox = tData.mBox; 
    1366  
    1367             KdNode *front = ImportNextNode(stream, interior, objects); 
    1368                         KdNode *back = ImportNextNode(stream, interior, objects); 
    1369          
    1370                         interior->SetupChildLinks(back, front); 
    1371  
    1372                         ++ mStat.splits[interior->mAxis]; 
    1373  
    1374                         // compute new bounding box 
    1375                         AxisAlignedBox3 frontBox, backBox; 
    1376                          
    1377                         tData.mBox.Split(interior->mAxis,  
    1378                                                         interior->mPosition,  
    1379                                                         frontBox,  
    1380                                                         backBox); 
    1381  
    1382                         tStack.push(TraversalData(front, frontBox, tData.mDepth + 1));                   
    1383                         tStack.push(TraversalData(back, backBox, tData.mDepth + 1)); 
    1384                 } 
    1385                 else 
    1386                 { 
    1387                         EvaluateLeafStats(tData); 
    1388                         //cout << "l"; 
    1389                 } 
    1390         } 
    1391  
    1392         float area = GetBox().SurfaceArea()*mKdPvsArea; 
    1393          
    1394         SetPvsTerminationNodes(area); 
    1395  
    1396         Debug << mStat << endl; 
    1397  
    1398         return true; 
     1333  // export binary version of mesh 
     1334  queue<TraversalData> tStack; 
     1335  IN_STREAM stream(filename.c_str(), IN_BIN_MODE); 
     1336   
     1337  if (!stream.is_open()) return false; 
     1338   
     1339  // sort objects by their id 
     1340  //    if (!is_sorted(objects.begin(), objects.end(), ilt)) 
     1341  sort(objects.begin(), objects.end(), ilt); 
     1342   
     1343  mBox.Initialize(); 
     1344  ObjectContainer::const_iterator oit, oit_end = objects.end(); 
     1345   
     1346  /////////////////////////// 
     1347  //-- compute bounding box of object space 
     1348   
     1349  for (oit = objects.begin(); oit != oit_end; ++ oit) 
     1350  { 
     1351    const AxisAlignedBox3 box = (*oit)->GetBox(); 
     1352    mBox.Include(box); 
     1353  } 
     1354   
     1355  // hack: we make a new root 
     1356  DEL_PTR(mRoot); 
     1357   
     1358  mRoot = ImportNextNode(stream, NULL, objects); 
     1359   
     1360  tStack.push(TraversalData(mRoot, mBox, 0)); 
     1361  mStat.Reset(); 
     1362  mStat.nodes = 1; 
     1363   
     1364  while(!tStack.empty()) 
     1365  { 
     1366    TraversalData tData = tStack.front(); 
     1367    tStack.pop(); 
     1368     
     1369    KdNode *node = tData.mNode; 
     1370     
     1371    if (!node->IsLeaf()) 
     1372    { 
     1373      mStat.nodes += 2; 
     1374       
     1375      //Debug << "i" ; 
     1376      KdInterior *interior = static_cast<KdInterior *>(node); 
     1377      interior->mBox = tData.mBox; 
     1378       
     1379      KdNode *front = ImportNextNode(stream, interior, objects); 
     1380      KdNode *back = ImportNextNode(stream, interior, objects); 
     1381       
     1382      interior->SetupChildLinks(back, front); 
     1383       
     1384      ++ mStat.splits[interior->mAxis]; 
     1385       
     1386      // compute new bounding box 
     1387      AxisAlignedBox3 frontBox, backBox; 
     1388       
     1389      tData.mBox.Split(interior->mAxis,  
     1390                      interior->mPosition,  
     1391                      frontBox,  
     1392                      backBox); 
     1393       
     1394      tStack.push(TraversalData(front, frontBox, tData.mDepth + 1));                     
     1395      tStack.push(TraversalData(back, backBox, tData.mDepth + 1)); 
     1396    } 
     1397    else 
     1398    { 
     1399      EvaluateLeafStats(tData); 
     1400      //cout << "l"; 
     1401    } 
     1402  } 
     1403 
     1404  float area = GetBox().SurfaceArea()*mKdPvsArea; 
     1405   
     1406  SetPvsTerminationNodes(area); 
     1407   
     1408  Debug << mStat << endl; 
     1409   
     1410  return true; 
    13991411} 
    14001412 
     
    14031415KdTree::GetOrCreateKdIntersectable(KdNode *node) 
    14041416{ 
    1405         if (node == NULL) 
    1406                 return NULL; 
     1417  if (node == NULL) 
     1418    return NULL; 
    14071419 
    14081420        if (node->mIntersectable == NULL)  
     
    14151427                mKdIntersectables.push_back(kdObj); 
    14161428                kdObj->SetId(id); 
    1417  
    14181429#ifdef USE_BIT_PVS 
    1419                 // hack: for kd pvs the kd intersecables are the pvs objects 
    1420                 ObjectPvsIterator::sObjects.push_back(kdObj); 
     1430    // hack: for kd pvs the kd intersecables are the pvs objects 
     1431    ObjectPvsIterator::sObjects.push_back(kdObj); 
    14211432#endif 
    1422         } 
    1423  
    1424         return node->mIntersectable; 
     1433  } 
     1434 
     1435  return node->mIntersectable; 
    14251436} 
    14261437 
    14271438 
    14281439void 
    1429 KdTree::SetPvsTerminationNodes( 
    1430                                                            const float maxArea) 
     1440KdTree::SetPvsTerminationNodes(const float maxArea) 
    14311441{ 
    14321442  stack<KdNode *> nodeStack; 
     
    14401450  while (!nodeStack.empty()) { 
    14411451    KdNode *node = nodeStack.top(); 
    1442         nodeStack.pop(); 
    1443  
    1444         node->mPvsTermination = 0; 
    1445         if (node->IsLeaf() || (GetSurfaceArea(node) <= maxArea) ) { 
    1446           area += GetSurfaceArea(node); 
    1447           radius += GetBox(node).Radius(); 
    1448           nodes++; 
    1449           node->mPvsTermination = 1; 
    1450           // create dummy kd intersectable 
    1451           Intersectable *object = GetOrCreateKdIntersectable(node); 
    1452         } else { 
    1453           KdInterior *interior = (KdInterior *)node; 
    1454           nodeStack.push(interior->mFront); 
    1455           nodeStack.push(interior->mBack); 
    1456     } 
    1457   } 
    1458  
     1452    nodeStack.pop(); 
     1453 
     1454    node->mPvsTermination = 0; 
     1455    if (node->IsLeaf() || (GetSurfaceArea(node) <= maxArea) ) { 
     1456      area += GetSurfaceArea(node); 
     1457      radius += GetBox(node).Radius(); 
     1458      nodes++; 
     1459      node->mPvsTermination = 1; 
     1460      // create dummy kd intersectable 
     1461      Intersectable *object = GetOrCreateKdIntersectable(node); 
     1462    } else { 
     1463      KdInterior *interior = (KdInterior *)node; 
     1464      nodeStack.push(interior->mFront); 
     1465      nodeStack.push(interior->mBack); 
     1466    } 
     1467  } 
     1468   
    14591469  if (nodes) { 
    1460         area /= nodes; 
    1461         radius /= nodes; 
    1462         cout<<"Number of nodes for storing in the PVS = "<<nodes<<endl; 
    1463         cout<<"Average rel. node area = "<<area/GetSurfaceArea(mRoot)<<endl; 
    1464         cout<<"Average rel. node radius = "<<radius/GetBox(mRoot).Radius()<<endl; 
    1465         cout<<"Avg node radius = "<<radius<<endl; 
     1470    area /= nodes; 
     1471    radius /= nodes; 
     1472    cout<<"Number of nodes for storing in the PVS = "<<nodes<<endl; 
     1473    cout<<"Average rel. node area = "<<area/GetSurfaceArea(mRoot)<<endl; 
     1474    cout<<"Average rel. node radius = "<<radius/GetBox(mRoot).Radius()<<endl; 
     1475    cout<<"Avg node radius = "<<radius<<endl; 
    14661476  } 
    14671477   
     
    14741484   
    14751485  while (node->mPvsTermination == 0 ) { 
    1476         KdInterior *inter = (KdInterior *)node; 
    1477         if (point[inter->mAxis] < inter->mPosition) 
    1478           node = inter->mBack; 
    1479         else 
    1480           node = inter->mFront; 
     1486    KdInterior *inter = (KdInterior *)node; 
     1487    if (point[inter->mAxis] < inter->mPosition) 
     1488      node = inter->mBack; 
     1489    else 
     1490      node = inter->mFront; 
    14811491  } 
    14821492   
     
    14911501   
    14921502  while (!node->IsLeaf() && (GetSurfaceArea(node) > maxArea) ) { 
    1493         KdInterior *inter = (KdInterior *)node; 
    1494         if (point[inter->mAxis] < inter->mPosition) 
    1495           node = inter->mBack; 
    1496         else 
    1497           node = inter->mFront; 
     1503    KdInterior *inter = (KdInterior *)node; 
     1504    if (point[inter->mAxis] < inter->mPosition) 
     1505      node = inter->mBack; 
     1506    else 
     1507      node = inter->mFront; 
    14981508  } 
    14991509   
     
    15031513 
    15041514void KdTree::GetBoxIntersections(const AxisAlignedBox3 &box, 
    1505                                                                  vector<KdLeaf *> &leaves) 
    1506 { 
    1507         stack<KdNode *> tStack; 
    1508  
    1509         tStack.push(mRoot); 
    1510  
    1511         while (!tStack.empty()) 
     1515                                 vector<KdLeaf *> &leaves) 
     1516{ 
     1517  stack<KdNode *> tStack; 
     1518   
     1519  tStack.push(mRoot); 
     1520   
     1521  while (!tStack.empty()) 
     1522    { 
     1523      KdNode *node = tStack.top(); 
     1524      tStack.pop(); 
     1525       
     1526      if (node->IsLeaf()) 
    15121527        { 
    1513                 KdNode *node = tStack.top(); 
    1514                 tStack.pop(); 
    1515                  
    1516                 if (node->IsLeaf()) 
    1517                 { 
    1518                         leaves.push_back(static_cast<KdLeaf *>(node)); 
    1519                 } 
    1520                 else // interior 
    1521                 { 
    1522                         KdInterior *interior = static_cast<KdInterior *>(node); 
    1523  
    1524                         if (box.Max(interior->mAxis) >= interior->mPosition) 
    1525                         { 
    1526                                 tStack.push(interior->mFront); 
    1527                         } 
    1528  
    1529                         if (box.Min(interior->mAxis) < interior->mPosition) 
    1530                         { 
    1531                                 tStack.push(interior->mBack); 
    1532                         } 
    1533                 } 
    1534         } 
    1535 } 
    1536  
    1537  
    1538  
    1539 } 
     1528          leaves.push_back(static_cast<KdLeaf *>(node)); 
     1529        } 
     1530      else // interior 
     1531        { 
     1532          KdInterior *interior = static_cast<KdInterior *>(node); 
     1533           
     1534          if (box.Max(interior->mAxis) >= interior->mPosition) 
     1535            { 
     1536              tStack.push(interior->mFront); 
     1537            } 
     1538           
     1539          if (box.Min(interior->mAxis) < interior->mPosition) 
     1540            { 
     1541              tStack.push(interior->mBack); 
     1542            } 
     1543        } 
     1544    } 
     1545} 
     1546 
     1547 
     1548 
     1549} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.h

    r2539 r2575  
    99#include "Ray.h" 
    1010//#include "ObjectPvs.h" 
    11 #include "Viewcell.h" 
     11#include "ViewCell.h" 
    1212#include "VssRay.h" 
    1313//#include "IntersectableWrapper.h" 
     
    9696/** Abstract class for kd-tree node */ 
    9797class KdNode { 
    98 public: 
    99    
     98 
     99public:   
    100100  static int sMailId; 
    101101  static int sReservedMailboxes; 
     
    109109  
    110110  static void NewMail(const int reserve = 1) { 
    111                 sMailId += sReservedMailboxes; 
    112                 sReservedMailboxes = reserve; 
    113         } 
    114         void Mail(const int mailbox) { mMailbox = sMailId + mailbox; } 
    115         bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; } 
     111    sMailId += sReservedMailboxes; 
     112    sReservedMailboxes = reserve; 
     113  } 
     114  void Mail(const int mailbox) { mMailbox = sMailId + mailbox; } 
     115  bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; } 
    116116 
    117117  virtual ~KdNode(){}; 
     
    183183public: 
    184184  KdLeaf(KdInterior *parent, const int objects): 
    185           KdNode(parent), mViewCell(NULL), mVboId(-1), mIndexBufferStart(0), mIndexBufferSize(0) { 
     185          KdNode(parent), mViewCell(NULL), mVboId(-1), 
     186          mIndexBufferStart(0), mIndexBufferSize(0) { 
    186187    mObjects.reserve(objects); 
    187188  } 
     
    194195  ~KdLeaf(); 
    195196         
    196         void AddPassingRay2(const Ray &ray, 
    197                                                 const int objects, 
    198                                                 const int viewcells 
    199                                                 ) { 
     197  void AddPassingRay2(const Ray &ray, 
     198                      const int objects, 
     199                      const int viewcells 
     200                      ) { 
    200201    mPassingRays.AddRay2(ray, objects, viewcells); 
    201202                //              Debug << "adding passing ray" << endl; 
     
    246247     
    247248    TraversalData(KdNode *n, 
    248                    const AxisAlignedBox3 &b, 
    249                    const int d): 
     249                  const AxisAlignedBox3 &b, 
     250                  const int d): 
    250251      mNode(n), mBox(b), mDepth(d) {} 
    251252     
    252253 
    253     bool operator<( 
    254                                    const TraversalData &b) const { 
     254    bool operator<(const TraversalData &b) const { 
    255255      KdLeaf *leafa = (KdLeaf *) mNode; 
    256256      KdLeaf *leafb = (KdLeaf *) b.mNode; 
    257257      return  
    258                 leafa->mObjects.size()*mBox.SurfaceArea() 
    259                 < 
    260                 leafb->mObjects.size()*b.mBox.SurfaceArea(); 
     258        leafa->mObjects.size()*mBox.SurfaceArea() 
     259        < 
     260        leafb->mObjects.size()*b.mBox.SurfaceArea(); 
    261261    } 
    262262 
     
    267267       
    268268      bool operator()(const TraversalData a, const TraversalData b) { 
    269                                 return a.mPriority < b.mPriority; 
     269        return a.mPriority < b.mPriority; 
    270270      } 
    271271       
     
    329329  */ 
    330330  int CastLineSegment(const Vector3 &origin, 
    331                                           const Vector3 &termination, 
    332                                           vector<ViewCell *> &viewcells); 
     331                      const Vector3 &termination, 
     332                      vector<ViewCell *> &viewcells); 
    333333 
    334334 
     
    351351  void 
    352352  CollectKdObjects(const AxisAlignedBox3 &box, 
    353                                    ObjectContainer &objects 
    354                                    ); 
     353                   ObjectContainer &objects 
     354                   ); 
    355355 
    356356  void 
     
    359359  void 
    360360  CollectObjects(const AxisAlignedBox3 &box, 
    361                                 ObjectContainer &objects); 
     361                ObjectContainer &objects); 
    362362 
    363363  void 
     
    388388 
    389389  float GetSurfaceArea(const KdNode *node) const { 
    390         return GetBox(node).SurfaceArea(); 
     390    return GetBox(node).SurfaceArea(); 
    391391  } 
    392392 
     
    394394  KdNode * 
    395395  FindRandomNeighbor(KdNode *n, 
    396                                         bool onlyUnmailed 
    397                                         ); 
     396                    bool onlyUnmailed 
     397                    ); 
    398398   
    399399  KdNode * 
    400   KdTree::GetRandomLeaf(const Plane3 &halfspace); 
     400  GetRandomLeaf(const Plane3 &halfspace); 
    401401 
    402402  KdNode * 
     
    408408 
    409409  void GetBoxIntersections(const AxisAlignedBox3 &box,  
    410                                                    vector<KdLeaf *> &leaves); 
     410                           vector<KdLeaf *> &leaves); 
    411411 
    412412  int 
    413413  FindNeighbors(KdNode *n, 
    414                                 vector<KdNode *> &neighbors, 
    415                                 bool onlyUnmailed 
    416                                 ); 
     414                vector<KdNode *> &neighbors, 
     415                bool onlyUnmailed 
     416                ); 
    417417 
    418418  bool ExportBinTree(const std::string &filename); 
     
    439439#if USE_FIXEDPOINT_T 
    440440#define FIXEDPOINT_ONE 0x7FFE 
    441                           //                      tmax(0xFFFF) 
    442                           tmax(FIXEDPOINT_ONE) 
     441                    //                    tmax(0xFFFF) 
     442                    tmax(FIXEDPOINT_ONE) 
    443443#else 
    444444      tmax(1.0f) 
     
    531531     
    532532    SortableEntry() {} 
    533     SortableEntry(const int t, const float v, Intersectable *i):type(t), 
    534                                                                 value(v), 
    535                                                                 intersectable(i) {} 
     533    SortableEntry(const int t, const float v, Intersectable *i): 
     534      type(t), value(v), intersectable(i) 
     535    { } 
    536536     
    537537    bool operator<(const SortableEntry &b) const { 
     
    561561  void 
    562562  SortSubdivisionCandidates( 
    563                       KdLeaf *node, 
    564                       const int axis 
    565                       ); 
     563                            KdLeaf *node, 
     564                            const int axis 
     565                           ); 
    566566 
    567567  void 
     
    585585              ); 
    586586 
    587         /** does some post processing on the objects in the new child leaves. 
    588         */ 
    589         void ProcessMultipleRefs(KdLeaf *leaf) const; 
    590  
    591  
    592         ////////// 
    593         // binary import / export 
    594  
    595         void ExportBinLeaf(OUT_STREAM  &stream, KdLeaf *leaf); 
     587  /** does some post processing on the objects in the new child leaves. 
     588   */ 
     589  void ProcessMultipleRefs(KdLeaf *leaf) const; 
     590 
     591 
     592  ////////// 
     593  // binary import / export 
     594   
     595  void ExportBinLeaf(OUT_STREAM  &stream, KdLeaf *leaf); 
    596596         
    597         void ExportBinInterior(OUT_STREAM &stream, KdInterior *interior); 
    598  
    599         KdLeaf *ImportBinLeaf(IN_STREAM &stream, KdInterior *parent, const ObjectContainer &objects); 
     597  void ExportBinInterior(OUT_STREAM &stream, KdInterior *interior); 
     598   
     599  KdLeaf *ImportBinLeaf(IN_STREAM &stream, KdInterior *parent, 
     600                        const ObjectContainer &objects); 
    600601         
    601         KdInterior *ImportBinInterior(IN_STREAM  &stream, KdInterior *parent); 
     602  KdInterior *ImportBinInterior(IN_STREAM  &stream, KdInterior *parent); 
     603   
     604  KdNode *ImportNextNode(IN_STREAM  &stream, KdInterior *parent, 
     605                         const ObjectContainer &objects); 
    602606         
    603         KdNode *ImportNextNode(IN_STREAM  &stream, KdInterior *parent, const ObjectContainer &objects); 
    604          
    605         /** Adds this objects to the kd leaf objects. 
    606                 @warning: Can corrupt the tree 
    607         */ 
    608         void InsertObjects(KdNode *node, const ObjectContainer &objects); 
     607  /** Adds this objects to the kd leaf objects. 
     608      @warning: Can corrupt the tree 
     609  */ 
     610  void InsertObjects(KdNode *node, const ObjectContainer &objects); 
    609611 
    610612  int mTermMaxNodes; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Makefile

    r2574 r2575  
    11############################################################################# 
    22# Makefile for building: preprocessor 
    3 # Generated by qmake (2.00a) (Qt 4.1.2) on: so 22. XII 21:22:31 2007 
     3# Generated by qmake (2.00a) (Qt 4.1.2) on: ?t 3. I 15:47:31 2008 
    44# Project:  preprocessor.pro 
    55# Template: app 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Material.cpp

    r2515 r2575  
    33 
    44namespace GtpVisibilityPreprocessor { 
     5 
     6 
     7RgbColor 
     8RandomColor(const float a, const float b) 
     9{ 
     10  return RgbColor(a + Random(b), 
     11                                  a + Random(b), 
     12                                  a + Random(b)); 
     13} 
    514 
    615 
     
    1524 
    1625  return m; 
    17 } 
    18  
    19  
    20 RgbColor 
    21 RandomColor(const float a, const float b) 
    22 { 
    23   return RgbColor(a + Random(b), 
    24                                   a + Random(b), 
    25                                   a + Random(b)); 
    2626} 
    2727 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Material.h

    r2173 r2575  
    3030}; 
    3131 
     32 
     33// Forward declarations 
     34RgbColor RandomColor(const float a, const float b); 
     35 
     36// Mapping from interval 0.0-1.0 to RGB using "rainbow" color map 
     37// (range of hue from 0-240) 
     38RgbColor RainbowColorMapping(const float value); 
     39 
     40   
    3241 
    3342class Material  
     
    6877 
    6978 
     79extern Material RandomMaterial(); 
     80 
    7081} 
    7182 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Matrix4x4.h

    r2176 r2575  
    103103}; 
    104104 
     105// forward declaration 
     106Matrix4x4 IdentityMatrix(); 
     107Matrix4x4 Invert(const Matrix4x4 &M);   // Invert a given matrix 
     108Matrix4x4 Transpose(const Matrix4x4 &M);        // Transpose a given matrix 
     109 
     110// Create various types of matrix. 
     111Matrix4x4 IdentityMatrix(); 
     112Matrix4x4 ZeroMatrix(); 
     113Matrix4x4 TranslationMatrix(const Vector3 &Location); 
     114Matrix4x4 RotationXMatrix(float Angle); 
     115Matrix4x4 RotationYMatrix(float Angle); 
     116Matrix4x4 RotationZMatrix(float Angle); 
     117Matrix4x4 RotationYPRMatrix(float Yaw, float Pitch, float Roll); 
     118// about axis 'axis' by angle 'Angle' 
     119Matrix4x4 RotationAxisMatrix(const Vector3 &axis, float Angle); 
     120// create the rotation matrix that rotates 'vecFrom' to 'vecTo' 
     121Matrix4x4 RotationVectorsMatrix(const Vector3 &vecFrom, 
     122                                const Vector3 &vecTo); 
     123   
     124Matrix4x4 ScaleMatrix(float X, float Y, float Z); 
     125Matrix4x4 GenRotation(const Vector3 &x, const Vector3 &y, 
     126                      const Vector3 &z); 
     127Matrix4x4 QuadricMatrix(float a, float b, float c, float d, float e, 
     128                        float f, float g, float h, float j, float k); 
     129// returns matrix for transforming normal 
     130Matrix4x4 NormalTransformMatrix(const Matrix4x4 &M); 
     131 
     132Matrix4x4 MirrorX(); 
     133Matrix4x4 MirrorY(); 
     134Matrix4x4 MirrorZ(); 
     135Matrix4x4 RotationOnly(const Matrix4x4 &x); 
     136 
     137// Binary operators 
     138Matrix4x4 operator+ (const Matrix4x4 &A, const Matrix4x4 &B); 
     139Matrix4x4 operator- (const Matrix4x4 &A, const Matrix4x4 &B); 
     140Matrix4x4 operator* (const Matrix4x4 &A, float B); 
     141Matrix4x4 operator* (const Matrix4x4 &A, const Matrix4x4 &B); 
     142 
     143// friends returning Vector3 
     144Vector3 operator*(const Matrix4x4 &M, const Vector3 &v); 
     145Vector3 RotateOnly(const Matrix4x4 &M, const Vector3 &v); 
     146Vector3 TransformNormal(const Matrix4x4 &M, const Vector3 &v); 
     147Vector3 GetTranslation(const Matrix4x4 &M); 
     148 
     149   
    105150} 
    106151 
     152 
     153 
    107154#endif 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.h

    r2569 r2575  
    268268 
    269269        virtual int CastRay(Ray &ray); 
     270        virtual int CastSimpleRay(const SimpleRay &ray) { return 0;} 
     271        virtual int CastSimpleRay(const SimpleRay &ray, int IndexRay) 
     272        { return 0; } 
    270273 
    271274        virtual bool IsConvex() const { return mMesh->mIsConvex; } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ObjParser.cpp

    r2539 r2575  
    209209        const Vector3 cross_a_b = CrossProd(a, b); 
    210210 
    211         if (SqrMagnitude(cross_a_b) <= 0.000001 * FLT_EPSILON * FLT_EPSILON)  
     211#define SMALL_FLT   1e-5 
     212         
     213        if (SqrMagnitude(cross_a_b) <= 0.0001 * SMALL_FLT * SMALL_FLT)  
    212214        { 
    213215                // v0, v1 & v2 lies on a line (area == 0) 
     
    293295                                        for (tit = triangles.begin(); tit != tit_end; ++ tit) 
    294296                                        { 
    295                                                 // test if it is a valid triangle 
    296                                                 if (0 && !TriangleValid(*tit)) continue; 
    297  
    298                                                 TriangleIntersectable *obj = new TriangleIntersectable(*tit);    
    299                                                 root->mGeometry.push_back(obj); 
     297                                          // test if it is a valid triangle 
     298                                          if (!TriangleValid(*tit)) 
     299                                            continue; 
     300 
     301                                          TriangleIntersectable *obj = new TriangleIntersectable(*tit);  
     302                                          root->mGeometry.push_back(obj); 
    300303                                        } 
    301304                                } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ObjectPvs.cpp

    r2332 r2575  
    11#include <iostream> 
    22#include <stack> 
     3 
     4#include "Mesh.h" 
    35#include "ObjectPvs.h" 
    46#include "Intersectable.h" 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ObjectPvs.h

    r2176 r2575  
    44#include "common.h" 
    55#include "PvsDefinitions.h" 
     6#include "Intersectable.h" 
    67 
    78// 
  • GTP/trunk/Lib/Vis/Preprocessing/src/OcclusionQuery.cpp

    r2023 r2575  
    11#include "OcclusionQuery.h" 
    22#include <iostream> 
     3 
     4 
     5#ifdef _WIN32 
    36#include <glInterface.h> 
    4  
     7#else 
     8#include <GL/gl.h> 
     9#include <GL/glu.h> 
     10//#include <GL/glxext.h> 
     11#include <SDL/SDL_opengl.h> 
     12#endif 
    513 
    614using namespace std; 
     
    1725        if (sUseArbQueries) 
    1826        { 
    19                 glGenQueriesARB(1, &id); 
     27#ifdef _ARBGL 
     28          // VH 
     29          glGenQueriesARB(1, &id); 
     30#endif 
    2031        } 
    2132        else 
    2233        {                
     34#ifdef _ARBGL 
     35          // VH 
    2336                glGenOcclusionQueriesNV(1, &id); 
     37#endif 
    2438        } 
    2539} 
     
    3448        if (sUseArbQueries) 
    3549        { 
     50#ifdef _ARBGL 
     51          // VH 
    3652                glDeleteQueriesARB(1, &mId); 
     53#endif 
    3754        } 
    3855        else 
    3956        { 
     57#ifdef _ARBGL 
     58          // VH 
    4059                glDeleteOcclusionQueriesNV(1, &mId); 
     60#endif 
    4161        } 
    4262         
     
    4767        if (sUseArbQueries) 
    4868        { 
     69#ifdef _ARBGL 
     70          // VH 
    4971                glBeginQueryARB(GL_SAMPLES_PASSED_ARB, mId); 
     72#endif 
    5073        } 
    5174        else 
    5275        { 
     76#ifdef _ARBGL 
     77          // VH 
    5378                glBeginOcclusionQueryNV(mId); 
     79#endif 
    5480        } 
    5581} 
     
    5985        if (sUseArbQueries) 
    6086        { 
     87#ifdef _ARBGL 
     88          // VH 
    6189                glEndQueryARB(GL_SAMPLES_PASSED_ARB); 
     90#endif 
    6291        } 
    6392        else 
    6493        { 
     94#ifdef _ARBGL 
     95          // VH 
    6596                glEndOcclusionQueryNV();         
     97#endif 
    6698        } 
    6799} 
     
    79111        if (sUseArbQueries) 
    80112        { 
     113#ifdef _ARBGL 
     114          // VH 
    81115                //GLint available; 
    82116                glGetQueryObjectuivARB(mId, 
    83117                                                           GL_QUERY_RESULT_AVAILABLE_ARB, 
    84                                &available); 
     118                                       &available); 
     119#endif           
    85120                return available == GL_TRUE; 
    86121        } 
    87122        else 
    88123        { 
    89                  
    90                 glGetOcclusionQueryuivNV(mId, GL_PIXEL_COUNT_AVAILABLE_NV, &available); 
    91  
     124#ifdef _ARBGL 
     125          // VH 
     126          glGetOcclusionQueryuivNV(mId, GL_PIXEL_COUNT_AVAILABLE_NV, &available); 
     127#endif 
    92128                return available == GL_TRUE; 
    93129        } 
     
    102138        if (sUseArbQueries) 
    103139        { 
     140#ifdef _ARBGL 
     141          // VH 
    104142                glGetQueryObjectuivARB(mId, GL_QUERY_RESULT_ARB, &sampleCount); 
     143#endif 
    105144                return sampleCount; 
    106145        } 
    107146        else 
    108147        {        
    109  
     148#ifdef _ARBGL 
     149          // VH 
    110150                glGetOcclusionQueryuivNV(mId, GL_PIXEL_COUNT_NV, &sampleCount); 
     151#endif           
    111152                return sampleCount; 
    112153        }        
     
    124165                if (sUseArbQueries) 
    125166                { 
     167#ifdef _ARBGL 
     168          // VH 
    126169                        glGenQueriesARB(n, (unsigned int *)newQueries); 
     170#endif 
    127171                } 
    128172                else 
    129173                { 
    130                         glGenOcclusionQueriesNV(n, (unsigned int *)newQueries); 
     174#ifdef _ARBGL 
     175          // VH            
     176                  glGenOcclusionQueriesNV(n, (unsigned int *)newQueries); 
     177#endif             
    131178                } 
    132179 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Plane3.cpp

    r2124 r2575  
    4242  const float det = md.Det3x3(); 
    4343 
    44   if (abs(det)<TRASH) 
     44  if (fabs(det) < TRASH) 
    4545    return false; 
    4646 
  • GTP/trunk/Lib/Vis/Preprocessing/src/PlyParser.cpp

    r2176 r2575  
    11#include <iostream> 
    2 #include <ply.h> 
    3 #include <stdio.h> 
    4  
     2#include <cstdio> 
     3 
     4#include "ply.h" 
    55#include "PlyParser.h" 
    66 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp

    r2574 r2575  
    2020#include "VssRay.h" 
    2121#include "IntelRayCaster.h" 
     22#include "HavranRayCaster.h" 
    2223#include "InternalRayCaster.h" 
    2324#include "GlobalLinesRenderer.h" 
     
    408409        // intel ray caster can only trace triangles 
    409410        int rayCastMethod; 
    410         Environment::GetSingleton()->GetIntValue("Preprocessor.rayCastMethod", rayCastMethod); 
     411        Environment::GetSingleton()->GetIntValue("Preprocessor.rayCastMethod", 
     412                                                 rayCastMethod); 
     413 
    411414        vector<FaceParentInfo> *fi =  
    412415          ((rayCastMethod == RayCaster::INTEL_RAYCASTER) && mLoadMeshes) ? 
     
    10441047 
    10451048        if (!mUseKdTree) { 
    1046                 // create just a dummy KdTree 
    1047                 mKdTree = new KdTree; 
    1048                 return true; 
    1049         } 
     1049          // create just a dummy KdTree 
     1050          mKdTree = new KdTree; 
     1051          return true; 
     1052        } 
     1053 
     1054        int rayCastMethod; 
     1055        Environment::GetSingleton()-> 
     1056          GetIntValue("Preprocessor.rayCastMethod", rayCastMethod); 
     1057 
     1058        if (rayCastMethod == 2) { 
     1059          //HavranRayCaster *hr = 
     1060          //  dynamic_cast<HavranRayCaster*>(mRayCaster); 
     1061          HavranRayCaster *hr = 
     1062            reinterpret_cast<HavranRayCaster*>(mRayCaster); 
     1063          hr->Build(this->mObjects); 
     1064          return true; 
     1065        }        
    10501066 
    10511067        // always try to load the kd tree 
     
    11171133        int rayCastMethod; 
    11181134        Environment::GetSingleton()-> 
    1119                 GetIntValue("Preprocessor.rayCastMethod", rayCastMethod); 
     1135          GetIntValue("Preprocessor.rayCastMethod", rayCastMethod); 
    11201136 
    11211137        if (rayCastMethod == 0) 
    11221138        { 
    1123                 cout << "ray cast method: internal" << endl; 
    1124                 mRayCaster = new InternalRayCaster(*this); 
    1125         } 
    1126         else 
     1139          cout << "ray cast method: internal" << endl; 
     1140          mRayCaster = new InternalRayCaster(*this); 
     1141        } 
     1142        if (rayCastMethod == 1)  
    11271143        { 
    11281144#ifdef GTP_INTERNAL 
     
    11301146          mRayCaster = new IntelRayCaster(*this, externKdTree); 
    11311147#endif 
     1148        } 
     1149        if (rayCastMethod == 2)  
     1150        { 
     1151          cout << "ray cast method: havran" << endl; 
     1152          mRayCaster = new HavranRayCaster(*this); 
    11321153        } 
    11331154         
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h

    r2574 r2575  
    4949        friend class IntelRayCaster; 
    5050        friend class InternalRayCaster; 
     51        friend class HavranRayCaster; 
    5152 
    5253public: 
     
    193194 
    194195        static bool LoadObjects(const string &filename, 
    195                                     ObjectContainer &pvsObjects,  
    196                                                         const ObjectContainer &preprocessorObject); 
     196                                ObjectContainer &pvsObjects,  
     197                                const ObjectContainer &preprocessorObject); 
    197198 
    198199 
     
    275276        bool ExportBinaryObj(const std::string &filename, SceneGraphNode *root); 
    276277 
    277         void SetupRay(Ray &ray, const Vector3 &point, const Vector3 &direction) const; 
     278        void SetupRay(Ray &ray, const Vector3 &point, 
     279                      const Vector3 &direction) const; 
    278280 
    279281        void EvalPvsStat(); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Ray.h

    r2176 r2575  
    128128  // Inititalize the ray again when already constructed 
    129129  void Init(const Vector3 &wherefrom, 
    130                         const Vector3 &whichdir, 
    131                         const int _type,  
    132                         bool dirNormalized = false) { 
     130            const Vector3 &whichdir, 
     131            const int _type,  
     132            bool dirNormalized = false) { 
    133133    loc = wherefrom; 
    134134    dir = (dirNormalized || _type == LINE_SEGMENT) ? whichdir: Normalize(whichdir) ; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.cpp

    r2539 r2575  
    270270int 
    271271RayCaster::ProcessRay(const SimpleRay &simpleRay, 
    272                                           Intersection &hitA, 
    273                                           Intersection &hitB, 
    274                                           VssRayContainer &vssRays, 
    275                                           const AxisAlignedBox3 &box, 
    276                                           const bool castDoubleRay, 
    277                                           const bool pruneInvalidRays) 
     272                      Intersection &hitA, 
     273                      Intersection &hitB, 
     274                      VssRayContainer &vssRays, 
     275                      const AxisAlignedBox3 &box, 
     276                      const bool castDoubleRay, 
     277                      const bool pruneInvalidRays) 
    278278{ 
    279279  int hits = 0; 
     
    325325        Debug<<"PR2"<<flush; 
    326326#endif 
     327 
     328        // VH - I do not know what this is for, commented out temporarily 
     329        // !!!!!!!!!!!!!! !!!!!!!!!!!! !!!!!!!!!! 
     330#if 1 
    327331        const bool validSample = true; 
    328332        if (validSample) { 
     
    363367        { 
    364368                VssRay *vssRay = RequestRay( 
    365                                                                         clipA, 
    366                                                                         hitB.mPoint, 
    367                                                                         hitA.mObject, 
    368                                                                         hitB.mObject, 
    369                                                                         mPreprocessor.mPass, 
    370                                                                         1.0f //simpleRay.mPdf 
    371                                                                         ); 
     369                                            clipA, 
     370                                            hitB.mPoint, 
     371                                            hitA.mObject, 
     372                                            hitB.mObject, 
     373                                            mPreprocessor.mPass, 
     374                                            1.0f //simpleRay.mPdf 
     375                                            ); 
    372376 
    373377                if (validB) 
     
    383387          Debug<<"PR4"<<flush; 
    384388#endif 
    385         } 
     389        } // validSample 
     390#else 
     391        // Just pass if intersected or not 
     392        hits = (hitA.mObject != 0) ? 1 : 0; 
     393        intersect = hitA; 
     394#endif   
    386395         
    387396        return hits; 
     
    391400void 
    392401RayCaster::CastRays( 
    393                                         SimpleRayContainer &rays, 
    394                                         VssRayContainer &vssRays, 
    395                                         const AxisAlignedBox3 &sbox, 
    396                                         const bool castDoubleRay, 
    397                                         const bool pruneInvalidRays ) 
    398 { 
    399         SimpleRayContainer::const_iterator rit, rit_end = rays.end(); 
    400  
    401         for (rit = rays.begin(); rit != rit_end; ++ rit) { 
    402                  
    403                 CastRay( 
    404                         *rit,                            
    405                         vssRays, 
    406                         sbox, 
    407                         castDoubleRay, 
    408                         pruneInvalidRays); 
    409         } 
    410 } 
    411  
    412  
    413 } 
     402                    SimpleRayContainer &rays, 
     403                    VssRayContainer &vssRays, 
     404                    const AxisAlignedBox3 &sbox, 
     405                    const bool castDoubleRay, 
     406                    const bool pruneInvalidRays ) 
     407{ 
     408  SimpleRayContainer::const_iterator rit, rit_end = rays.end(); 
     409   
     410  for (rit = rays.begin(); rit != rit_end; ++ rit) { 
     411     
     412    CastRay( 
     413            *rit,                                
     414            vssRays, 
     415            sbox, 
     416            castDoubleRay, 
     417            pruneInvalidRays); 
     418        } 
     419} 
     420   
     421 
     422} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.h

    r2571 r2575  
    2020class Preprocessor; 
    2121struct SimpleRay; 
    22  
     22class RayPacket2x2; 
    2323 
    2424/** This class provides an interface for ray casting. 
     
    2929public: 
    3030         
    31         enum { 
    32           INTERNAL_RAYCASTER = 0, 
    33           INTEL_RAYCASTER 
    34         }; 
    35  
    36         RayCaster(const Preprocessor &preprocessor); 
    37  
    38         virtual ~RayCaster(); 
    39  
    40         virtual int Type() const = 0; 
    41  
    42         /** Wrapper for casting single ray. 
    43                 @returns ray or NULL if invalid 
    44         */ 
    45         VssRay *CastRay(const SimpleRay &simpleRay, 
    46                                         const AxisAlignedBox3 &box, 
    47                                         const bool castDoubleRay); 
    48  
    49         virtual int CastRay(const SimpleRay &simpleRay, 
    50                                                 VssRayContainer &vssRays, 
    51                                                 const AxisAlignedBox3 &box, 
    52                                                 const bool castDoubleRay, 
    53                                                 const bool pruneInvalidRays = true) = 0; 
    54  
    55         virtual void CastRays16(SimpleRayContainer &rays, 
    56                                                         VssRayContainer &vssRays, 
    57                                                         const AxisAlignedBox3 &sbox, 
    58                                                         const bool castDoubleRay, 
    59                                                         const bool pruneInvalidRays = true) = 0; 
    60  
     31  enum { 
     32    INTERNAL_RAYCASTER = 0, 
     33    INTEL_RAYCASTER = 1, 
     34    HAVRAN_RAYCASTER = 2 
     35  }; 
     36 
     37  RayCaster(const Preprocessor &preprocessor); 
     38 
     39  virtual ~RayCaster(); 
     40   
     41  virtual int Type() const = 0; 
     42 
     43  /** Wrapper for casting single ray. 
     44      @returns ray or NULL if invalid 
     45  */ 
     46  VssRay *CastRay(const SimpleRay &simpleRay, 
     47                  const AxisAlignedBox3 &box, 
     48                  const bool castDoubleRay); 
     49 
     50  virtual int CastRay(const SimpleRay &simpleRay, 
     51                      VssRayContainer &vssRays, 
     52                      const AxisAlignedBox3 &box, 
     53                      const bool castDoubleRay, 
     54                      const bool pruneInvalidRays = true) = 0; 
     55 
     56  virtual void CastRays16(SimpleRayContainer &rays, 
     57                          VssRayContainer &vssRays, 
     58                          const AxisAlignedBox3 &sbox, 
     59                          const bool castDoubleRay, 
     60                          const bool pruneInvalidRays = true) = 0; 
     61   
    6162  virtual void CastRays( 
    62                                                 SimpleRayContainer &rays, 
    63                                                 VssRayContainer &vssRays, 
    64                                                 const AxisAlignedBox3 &sbox, 
    65                                                 const bool castDoubleRay, 
    66                                                 const bool pruneInvalidRays = true); 
    67  
     63                        SimpleRayContainer &rays, 
     64                        VssRayContainer &vssRays, 
     65                        const AxisAlignedBox3 &sbox, 
     66                        const bool castDoubleRay, 
     67                        const bool pruneInvalidRays = true); 
     68 
     69  // Just for testing concept 
     70  virtual void CastRaysPacket2x2(RayPacket2x2 &raysPack, 
     71                                 bool castDoubleRay, 
     72                                 const bool pruneInvalidRays = true) 
     73  { } 
     74   
    6875  /*virtual void CastRaysEye4(SimpleRayContainer &rays, 
    69                                                           VssRayContainer &vssRays, 
    70                                                           const AxisAlignedBox3 &sbox, 
    71                                                           const bool castDoubleRay, 
    72                                                           const bool pruneInvalidRays = true) = 0; 
    73 */ 
    74         virtual void 
    75         SortRays(SimpleRayContainer &rays); 
    76  
    77  
    78         // pool of vss rays to be used in one pass of the sampling 
    79         struct VssRayPool  
    80         { 
    81                 VssRayPool(): mRays(NULL), mIndex(0), mNumber(0)  
    82                 {} 
    83  
    84                 ~VssRayPool()  
    85                 { 
    86                         DEL_PTR(mRays); 
    87                 } 
    88  
    89                 void Reserve(const int number)  
    90                 { 
    91                         DEL_PTR(mRays); 
    92                         mRays = new VssRay[number]; 
    93                         mNumber = number; 
    94                 } 
    95  
    96                 void Clear()  
    97                 { 
    98                         mIndex = 0; 
    99                 } 
    100                  
    101                 VssRay *Alloc()  
    102                 { 
    103                         // reset pool 
    104                         if (mIndex == mNumber) 
    105                                 mIndex = 0; 
    106                         return mRays + mIndex ++; 
    107                 } 
    108  
    109         protected: 
    110  
    111                 VssRay *mRays; 
    112                 int mIndex; 
    113                 int mNumber; 
    114         }; 
    115  
    116         VssRayPool mVssRayPool; 
    117  
    118         void ReserveVssRayPool(const int n)  
    119         { 
    120                 mVssRayPool.Reserve(n); 
    121         } 
    122  
    123         void InitPass()  
    124         { 
    125                 mVssRayPool.Clear(); 
    126         } 
    127  
    128  
     76    VssRayContainer &vssRays, 
     77    const AxisAlignedBox3 &sbox, 
     78    const bool castDoubleRay, 
     79    const bool pruneInvalidRays = true) = 0; 
     80  */ 
     81 
     82  virtual void 
     83  SortRays(SimpleRayContainer &rays); 
     84 
     85 
     86  // pool of vss rays to be used in one pass of the sampling 
     87  struct VssRayPool  
     88  { 
     89    VssRayPool(): mRays(NULL), mIndex(0), mNumber(0)  
     90    {} 
     91     
     92    ~VssRayPool()  
     93    { 
     94      delete []mRays; 
     95    } 
     96     
     97    void Reserve(const int number)  
     98    { 
     99      DEL_PTR(mRays); 
     100      mRays = new VssRay[number]; 
     101      mNumber = number; 
     102    } 
     103     
     104    void Clear()  
     105    { 
     106      mIndex = 0; 
     107    } 
     108     
     109    VssRay *Alloc()  
     110    { 
     111      // reset pool 
     112      if (mIndex == mNumber) 
     113        mIndex = 0; 
     114      return mRays + mIndex ++; 
     115    } 
     116  protected: 
     117    VssRay *mRays; 
     118    int mIndex; 
     119    int mNumber; 
     120  }; 
     121 
     122 
     123  VssRayPool mVssRayPool; 
     124   
     125  void ReserveVssRayPool(const int n)  
     126  { 
     127    mVssRayPool.Reserve(n); 
     128  } 
     129   
     130  void InitPass()  
     131  { 
     132    mVssRayPool.Clear(); 
     133  } 
     134   
     135   
    129136protected: 
    130  
    131         VssRay *RequestRay(const Vector3 &origin,  
    132                 const Vector3 &termination,  
    133                 Intersectable *originObject,  
    134                 Intersectable *terminationObject,  
    135                 const int pass,  
    136                 const float pdf); 
    137  
    138         void _SortRays(SimpleRayContainer &rays, 
    139                 const int l, 
    140                 const int r, 
    141                 const int depth, 
    142                 float box[12]); 
    143  
    144         struct Intersection 
    145         { 
    146                 Intersection(): mObject(NULL), mFaceId(0) 
    147                 {} 
    148  
    149                 Intersection(const Vector3 &p, const Vector3 &n, Intersectable *o, const int f): 
    150                 mPoint(p), mNormal(n), mObject(o), mFaceId(f) 
    151                 {} 
    152  
    153                 Intersection(const Vector3 &p): mPoint(p), mObject(NULL), mFaceId(0) 
    154                 {} 
    155  
    156  
    157                 //////////// 
    158  
    159                 Vector3 mPoint; 
    160                 Vector3 mNormal; 
    161                 Intersectable *mObject; 
    162                 int mFaceId; 
    163         }; 
    164  
    165  
    166         int ProcessRay(const SimpleRay &ray, 
    167                            Intersection &hitA, 
    168                                   Intersection &hitB, 
    169                                   VssRayContainer &vssRays, 
    170                                   const AxisAlignedBox3 &box, 
    171                                   const bool castDoubleRay, 
    172                                   const bool pruneInvalidRays = true); 
    173  
    174         /** Checks if ray is valid. 
    175         I.e., the ray is in valid view space. 
    176         @note: clamps the ray to valid view space. 
    177         */ 
    178         bool ValidateRay(const Vector3 &origin, 
    179                              const Vector3 &direction, 
    180                                         const AxisAlignedBox3 &box, 
    181                                         Intersection &hit); 
    182  
    183         bool ClipToViewSpaceBox(const Vector3 &origin, 
    184                             const Vector3 &termination, 
    185                                                         Vector3 &clippedOrigin, 
    186                                                         Vector3 &clippedTermination); 
    187  
    188  
    189  
    190  
    191  
    192  
    193         const Preprocessor &mPreprocessor; 
     137   
     138  VssRay *RequestRay(const Vector3 &origin,  
     139                     const Vector3 &termination,  
     140                     Intersectable *originObject,  
     141                     Intersectable *terminationObject,  
     142                     const int pass,  
     143                     const float pdf); 
     144   
     145  void _SortRays(SimpleRayContainer &rays, 
     146                 const int l, 
     147                 const int r, 
     148                 const int depth, 
     149                 float box[12]); 
     150   
     151  struct Intersection 
     152  { 
     153    Intersection(): mObject(NULL), mFaceId(0) 
     154    {} 
     155     
     156    Intersection(const Vector3 &p, const Vector3 &n, Intersectable *o, const int f): 
     157      mPoint(p), mNormal(n), mObject(o), mFaceId(f) 
     158    {} 
     159     
     160    Intersection(const Vector3 &p): mPoint(p), mObject(NULL), mFaceId(0) 
     161    {} 
     162     
     163     
     164    //////////// 
     165     
     166    Vector3 mPoint; 
     167    Vector3 mNormal; 
     168    Intersectable *mObject; 
     169    int mFaceId; 
     170  }; 
     171 
     172 
     173  int ProcessRay(const SimpleRay &ray, 
     174                 Intersection &hitA, 
     175                Intersection &hitB, 
     176                VssRayContainer &vssRays, 
     177                const AxisAlignedBox3 &box, 
     178                const bool castDoubleRay, 
     179                const bool pruneInvalidRays = true); 
     180   
     181  /** Checks if ray is valid. 
     182      I.e., the ray is in valid view space. 
     183      @note: clamps the ray to valid view space. 
     184  */ 
     185  bool ValidateRay(const Vector3 &origin, 
     186                   const Vector3 &direction, 
     187                  const AxisAlignedBox3 &box, 
     188                  Intersection &hit); 
     189   
     190  bool ClipToViewSpaceBox(const Vector3 &origin, 
     191                          const Vector3 &termination, 
     192                          Vector3 &clippedOrigin, 
     193                          Vector3 &clippedTermination); 
     194   
     195  const Preprocessor &mPreprocessor; 
     196#if 1 
     197public: 
     198  // Added by VH for debugging 
     199  Intersection intersect; 
     200#endif   
    194201}; 
    195202 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Rectangle3.h

    r2176 r2575  
    5151      v += CrossProd(mVertices[i], mVertices[i+1]); 
    5252     
    53     return 0.5f*abs(DotProd(GetNormal(), v)); 
     53    return 0.5f * fabs(DotProd(GetNormal(), v)); 
    5454  } 
    5555   
  • GTP/trunk/Lib/Vis/Preprocessing/src/RenderTexture.cpp

    r1940 r2575  
    240240  { 
    241241    // [Redge] 
    242 #if defined(_DEBUG) | defined(DEBUG) 
     242#if defined(_DEBUG) || defined(DEBUG) 
    243243    fprintf(stderr, "Warning: OpenGL extension GL_ARB_depth_texture not available.\n" 
    244244                    "         Using glReadPixels() to emulate behavior.\n"); 
     
    250250  } 
    251251  SetLastError(0); 
    252 #else 
     252#else // _WIN32 
    253253  if (!GLXEW_SGIX_pbuffer) 
    254254  { 
     
    270270    PrintExtensionError("Some GLX render texture extension"); 
    271271  } 
    272 #endif 
     272#endif // _WIN32 
    273273 
    274274  if (_bInitialized) 
     
    292292          PrintExtensionError("NV_float_buffer or ATI_texture_float"); 
    293293  } 
    294 #else 
     294#else // _WIN32 
    295295  if (_bFloat && _bIsTexture && !GLXEW_NV_float_buffer) 
    296296  { 
     
    298298    return false; 
    299299  } 
    300 #endif   
     300#endif // _WIN32 
    301301  if (!_bFloat && !GLEW_NV_texture_rectangle) 
    302302  { 
     
    461461          } 
    462462        } 
    463 #else if defined(DEBUG) || defined(_DEBUG) 
     463#else // _WIN32  
     464#if defined(DEBUG) || defined(_DEBUG) 
    464465        printf("RenderTexture Error: Render-to-Texture not supported in Linux\n"); 
    465 #endif     
     466#endif 
     467#endif // _WIN32  
    466468      } 
    467469    } 
     
    850852  _iBits[5] = (wglGetPixelFormatAttribivARB(_hDC, iFormat, 0, 1, &attrib, &value)) ? value : 0;  
    851853  
    852 #if defined(_DEBUG) | defined(DEBUG) 
     854#if defined(_DEBUG) || defined(DEBUG) 
    853855  fprintf(stderr, "Created a %dx%d RenderTexture with BPP(%d, %d, %d, %d)", 
    854856          _iWidth, _iHeight, _iBits[0], _iBits[1], _iBits[2], _iBits[3]); 
     
    857859  fprintf(stderr, "\n"); 
    858860#endif 
    859 #else 
     861#else // _WIN32  
    860862  _pDpy = glXGetCurrentDisplay(); 
    861863  GLXContext context = glXGetCurrentContext(); 
     
    936938  // XXX Query the color format 
    937939 
    938 #endif 
     940#endif // _WIN32  
    939941   
    940942  return true; 
     
    982984    return true; 
    983985  } 
    984 #else 
     986#else // _WIN32  
    985987  if ( _hPBuffer ) 
    986988  { 
     
    992994    return true; 
    993995  } 
    994 #endif 
     996#endif // _WIN32  
    995997  return false; 
    996998} 
     
    10801082    return false; 
    10811083  } 
    1082 #else 
     1084#else // _WIN32  
    10831085  _hPreviousContext = glXGetCurrentContext(); 
    10841086  _hPreviousDrawable = glXGetCurrentDrawable(); 
     
    10871089    return false; 
    10881090  } 
    1089 #endif 
     1091#endif // _WIN32  
    10901092   
    10911093  return true; 
     
    11961198    } 
    11971199  } 
    1198 #else 
     1200#else // _WIN32  
    11991201  assert(_bIsTexture); 
    12001202  glBindTexture(_iTextureTarget, _iTextureID); 
     
    12081210    } 
    12091211  } 
    1210 #endif 
     1212#endif // _WIN32  
    12111213  return true; 
    12121214} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ResourceManager.h

    r2542 r2575  
    44#include <vector> 
    55#include <string> 
     6#include <iterator> 
     7#include <fstream> 
     8#include <ostream> 
     9#include <iostream> 
    610 
    711//#include "Containers.h" 
     
    1317namespace GtpVisibilityPreprocessor { 
    1418 
     19using std::iterator; 
     20using std::map; 
     21   
    1522 
    1623/** Resource manager controlling loading and destroying of resources. 
     
    2532template <typename T> class ResourceManager 
    2633{ 
     34protected: 
     35  typedef map<unsigned int, T* > maptype; 
    2736 
     37  /// the resource container 
     38  maptype mEntries; 
     39   
    2840public: 
    2941 
     
    6577        T *FindEntry(const unsigned int id) const 
    6678        { 
    67                 std::map<unsigned int, T *>::const_iterator mit = mEntries.find(id); 
     79          typename maptype::const_iterator mit = mEntries.find(id); 
    6880 
    69                 if (mit != mEntries.end())  
    70                 { 
    71                         return (*mit).second; 
    72                 } 
     81          if (mit != mEntries.end())  
     82            { 
     83              return (*mit).second; 
     84            } 
    7385 
    7486                return NULL; 
     
    95107        bool ExportEntries(const std::string &filename) 
    96108        { 
    97                 ofstream stream(filename.c_str(), ios::binary); 
     109          std::ofstream stream(filename.c_str(), std::ios::binary); 
    98110         
    99111                if (!stream.is_open()) 
    100112                        return false; 
    101113 
    102                 std::map<unsigned int, T *>::const_iterator mit, mit_end = mEntries.end(); 
     114                typename std::map<unsigned int, T *>::const_iterator mit, mit_end = mEntries.end(); 
    103115 
    104116                for (mit = mEntries.begin(); mit != mit_end; ++ mit) 
     
    130142        ~ResourceManager<T>() 
    131143        { 
    132                 std::map<unsigned int, T *>::iterator mit, mit_end = mEntries.end(); 
     144          typename std::map<unsigned int, T *>::iterator mit, mit_end = mEntries.end(); 
    133145 
    134146                for (mit = mEntries.begin(); mit != mEntries.end(); ++ mit) 
     
    152164protected: 
    153165 
    154         /// the resource container 
    155         std::map<unsigned int, T *> mEntries; 
    156  
    157166private: 
    158167 
  • GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.cpp

    r2130 r2575  
    14811481void 
    14821482RssTree::RemoveRay(VssRay *ray, 
    1483                                    vector<RssTreeLeaf *> *affectedLeaves, 
    1484                                    const bool removeAllScheduledRays 
    1485                                    ) 
    1486 { 
    1487          
    1488   stack<RayTraversalData> tstack; 
    1489  
    1490   PushRoots(tstack, RssTreeLeaf::RayInfo(ray)); 
     1483                   vector<RssTreeLeaf *> *affectedLeaves, 
     1484                   const bool removeAllScheduledRays 
     1485                   ) 
     1486{        
     1487  TstackEntry tstack; 
     1488 
     1489  RssTreeNode::RayInfo ri(ray); 
     1490  PushRoots(tstack, ri); 
    14911491   
    14921492  RayTraversalData data; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.h

    r2176 r2575  
    10991099  PushRoots(std::stack<RssTreeNode *> &st) const; 
    11001100 
    1101   void 
    1102   PushRoots(std::stack<RayTraversalData> &st, RssTreeNode::RayInfo &info) const; 
     1101  typedef std::stack<RayTraversalData> TstackEntry; 
     1102 
     1103  void 
     1104  PushRoots(TstackEntry &st, RssTreeNode::RayInfo &info) const; 
    11031105 
    11041106  void 
  • GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp

    r2566 r2575  
     1 
    12#include "SamplingStrategy.h" 
    23#include "Ray.h" 
     
    78#include "RssTree.h" 
    89#include "Mutation.h" 
     10#include "FilterBasedDistribution.h" 
     11#include "DifferenceSampling.h" 
     12 
     13 
     14#ifdef PERFTIMER 
    915#include "Timer/PerfTimer.h" 
    10 #include "DifferenceSampling.h" 
    11  
    12  
     16#endif 
    1317 
    1418namespace GtpVisibilityPreprocessor { 
    1519 
     20 
     21#ifdef PERFTIMER 
    1622extern PerfTimer haltonTimer; 
    1723extern PerfTimer pvsTimer; 
    1824extern PerfTimer viewCellCastTimer; 
    19  
     25#endif 
     26   
    2027//HaltonSequence SamplingStrategy::sHalton; 
    2128 
     
    221228                                                                                                                                           r[4], 
    222229                                                                                                                                           r[5]) 
    223                                                                                                                                            ) - origin; 
     230                                                                                                                           ) - origin; 
    224231         
    225232        const float c = Magnitude(direction); 
     
    591598  if (1) 
    592599  { 
     600#ifdef PERFTIMER 
    593601          const float vcTime = viewCellCastTimer.TotalTime(); 
    594602          const float pvsTime = pvsTimer.TotalTime(); 
    595603          const float haltonTime = haltonTimer.TotalTime(); 
    596  
     604           
    597605          cout << "view cell cast time: " << vcTime << " s" << endl; 
    598606          cout << "pvs time: " << pvsTime << " s" << endl; 
     
    602610          Debug << "pvs time: " << pvsTime << " s" << endl; 
    603611          Debug << "halton time: "<< haltonTime << " s" << endl; 
     612#else 
     613          cout << "Timers not supported" << endl; 
     614          Debug << "Timers for PVS,Halton,Viewcell not supported" << endl; 
     615#endif 
    604616  } 
    605617} 
     
    712724                                        if (strcmp(curr, "mutation")==0) { 
    713725                                         mDistributions.push_back(new MutationBasedDistribution(mPreprocessor)); 
    714                                         } 
     726                                        } else 
     727                                          if (strcmp(curr, "filter_based")==0) { 
     728                                                mDistributions.push_back(new FilterBasedDistribution(mPreprocessor)); 
     729                                          } 
    715730                                        else if (strcmp(curr, "difference")==0) { 
    716731                                         mDistributions.push_back(new DifferenceSampling(mPreprocessor)); 
    717732                                        } 
     733         
    718734         
    719735         
  • GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.h

    r2548 r2575  
    4848                HW_GLOBAL_LINES_DISTRIBUTION, 
    4949                VIEWCELL_BASED_DISTRIBUTION, 
     50                FILTER_BASED_DISTRIBUTION, 
    5051                DIFFERENCE_SAMPLING_BASED_DISTRIBUTION, 
    5152        }; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/SimpleRay.h

    r2176 r2575  
    55using namespace std; 
    66#include "Vector3.h" 
     7#include "Ray.h" 
    78 
    89namespace GtpVisibilityPreprocessor { 
    910 
     11class Intersectable; 
     12 
     13// This is the result of ray tracing with a simple ray 
     14struct IntersectionStr { 
     15  Intersectable *intersectable; 
     16  float          tdist; 
     17  float          maxt; 
     18  int            pad1; // aligned to 16 bytes 
     19}; 
     20   
    1021struct SimpleRay 
    1122{ 
     23  // This is stored result for the rays in the container 
     24  // having 16 rays - shooting rays in both directions 
     25  static IntersectionStr IntersectionRes[32]; 
    1226   
    1327  Vector3 mOrigin; 
     
    2943  // 4B 
    3044 
    31   // TOTAL = 40B 
     45  // TOTAL = 40B - aligned by 8 Bytes only! - it might be 
     46  // padding to 48 Bytes here ! 
    3247 
    3348 
     
    3954   
    4055  SimpleRay(const Vector3 &o, 
    41                         const Vector3 &d, 
    42                         const unsigned char distribution, 
    43                         const float weight, 
    44                         const unsigned char flags = F_BIDIRECTIONAL 
    45                         ): 
    46         mOrigin(o), 
    47         mDirection(d), 
    48         mFlags(flags), 
    49         mType(Ray::LOCAL_RAY), 
    50         mDistribution(distribution) 
    51         //      , mWeight(weight) 
     56            const Vector3 &d, 
     57            const unsigned char distribution, 
     58            const float weight, 
     59            const unsigned char flags = F_BIDIRECTIONAL 
     60            ): 
     61    mOrigin(o), 
     62    mDirection(d), 
     63    mFlags(flags), 
     64    mType(Ray::LOCAL_RAY), 
     65    mDistribution(distribution) 
     66    //  , mWeight(weight) 
    5267  {      
    53         //      mId = sSimpleRayId++; 
     68    //  mId = sSimpleRayId++; 
    5469  } 
    5570 
     71  void 
     72  Set(const Vector3 &o, 
     73      const Vector3 &d, 
     74      const unsigned char distribution, 
     75      const float weight, 
     76      const unsigned char flags = F_BIDIRECTIONAL 
     77      ) 
     78  { 
     79    mOrigin = o; 
     80    mDirection = d, 
     81    mFlags = flags; 
     82    mType = Ray::LOCAL_RAY; 
     83    mDistribution = distribution; 
     84    //  , mWeight(weight) 
     85    //  mId = sSimpleRayId++; 
     86  } 
     87   
    5688  bool IsBidirectional() const { return mFlags & F_BIDIRECTIONAL; } 
    5789 
    5890  void SetBidirectional(const bool b) { 
    59         if (b) 
    60           mFlags |= F_BIDIRECTIONAL; 
    61         else 
    62           mFlags &= ~F_BIDIRECTIONAL; 
     91    if (b) 
     92      mFlags |= F_BIDIRECTIONAL; 
     93    else 
     94      mFlags &= ~F_BIDIRECTIONAL; 
    6395  } 
    6496   
    6597  float GetParam(const int axis) const { 
    66         if (axis < 3) 
    67           return mOrigin[axis]; 
    68         else 
    69           return mDirection[axis-3]; 
     98    if (axis < 3) 
     99      return mOrigin[axis]; 
     100    else 
     101      return mDirection[axis-3]; 
    70102  } 
    71103   
    72104  Vector3 Extrap(const float t) const { 
    73           return mOrigin + mDirection * t; 
     105    return mOrigin + mDirection * t; 
    74106  } 
    75107 
    76108  friend std::ostream &operator<<(std::ostream &s, const SimpleRay &r) 
    77109  { 
    78           return s << "origin=" << r.mOrigin << " dir=" << r.mDirection; 
     110    return s << "origin=" << r.mOrigin << " dir=" << r.mDirection; 
    79111  }; 
    80112}; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Trackball.cpp

    r2347 r2575  
    5050 * Gavin Bell 
    5151 */ 
    52 #include <math.h> 
    53 #include "trackball.h" 
     52#include <cmath> 
     53#include "Trackball.h" 
    5454 
    5555/* 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Triangle3.cpp

    r2542 r2575  
    11#include "Triangle3.h" 
    22#include "Ray.h" 
     3#include "SimpleRay.h" 
    34#include "AxisAlignedBox3.h" 
    45#include "Containers.h" 
     
    3334int 
    3435Triangle3::CastRay(const Ray &ray, 
    35                                    float &t, 
    36                                    const float nearestT, 
    37                                    Vector3 &normal) const 
    38 { 
    39         ////////////// 
    40         // specialised triangle ray casting version 
    41         // using ray-plane intersection 
    42          
    43         // get triangle edge vectors and plane normal 
    44         const Vector3 u = mVertices[0] - mVertices[1]; 
    45     const Vector3 v = mVertices[2] - mVertices[1]; 
    46  
    47         // cross product 
    48     normal = Normalize(CrossProd(v, u)); 
    49  
    50         // ray direction vector 
    51     const Vector3 dir = ray.GetDir(); 
    52     const Vector3 w0 = ray.GetLoc() - mVertices[1]; 
    53  
    54         // params to calc ray-plane intersect 
    55     const float a = -DotProd(normal, w0); 
    56     const float b = DotProd(normal, dir); 
    57  
    58         // check for division by zero 
    59         if (fabs(b) < Limits::Small)  
    60         {    
    61                 // ray is parallel to triangle plane 
    62         if (a == 0) 
    63                 { 
    64                         // ray lies in triangle plane 
    65             return Ray::INTERSECTION_OUT_OF_LIMITS; 
    66                 } 
    67         else 
    68                 { 
    69                         // ray disjoint from plane 
    70                         return Ray::NO_INTERSECTION; 
    71                 } 
    72     } 
    73  
    74     // distance from origin of ray to plane 
    75     t = a / b; 
    76  
    77     if (t <= Limits::Small) // ray goes away from triangle 
    78         { 
     36                   float &t, 
     37                   const float nearestT, 
     38                   Vector3 &normal) const 
     39{ 
     40  ////////////// 
     41  // specialised triangle ray casting version 
     42  // using ray-plane intersection 
     43   
     44  // get triangle edge vectors and plane normal 
     45  const Vector3 u = mVertices[0] - mVertices[1]; 
     46  const Vector3 v = mVertices[2] - mVertices[1]; 
     47   
     48  // cross product 
     49  normal = Normalize(CrossProd(v, u)); 
     50   
     51  // ray direction vector 
     52  const Vector3 dir = ray.GetDir(); 
     53  const Vector3 w0 = ray.GetLoc() - mVertices[1]; 
     54   
     55  // params to calc ray-plane intersect 
     56  const float a = -DotProd(normal, w0); 
     57  const float b = DotProd(normal, dir); 
     58   
     59  // check for division by zero 
     60  if (fabs(b) < Limits::Small)  
     61    {    
     62      // ray is parallel to triangle plane 
     63      if (a == 0) 
     64        { 
     65          // ray lies in triangle plane 
    7966          return Ray::INTERSECTION_OUT_OF_LIMITS; 
    8067        } 
    81         // already found nearer intersection 
    82         else if ((ray.GetType() == Ray::LOCAL_RAY) && (t >= nearestT)) 
    83         { 
    84                 return Ray::NO_INTERSECTION; 
    85         } 
    86  
    87         ///////////////// 
     68      else 
     69        { 
     70          // ray disjoint from plane 
     71          return Ray::NO_INTERSECTION; 
     72        } 
     73    } 
     74 
     75  // distance from origin of ray to plane 
     76  t = a / b; 
     77   
     78  if (t <= Limits::Small) // ray goes away from triangle 
     79    { 
     80      return Ray::INTERSECTION_OUT_OF_LIMITS; 
     81    } 
     82  // already found nearer intersection 
     83  else if ((ray.GetType() == Ray::LOCAL_RAY) && (t >= nearestT)) 
     84    { 
     85      return Ray::NO_INTERSECTION; 
     86    } 
     87   
     88  ///////////////// 
    8889    //-- found intersection point 
    89         //-- check if it is inside triangle 
    90    
    91         const Vector3 pt = ray.GetLoc() + t * dir;  
     90  //-- check if it is inside triangle 
     91   
     92  const Vector3 pt = ray.GetLoc() + t * dir;  
    9293#if GTP_DEBUG 
    93         if (!pt.CheckValidity()) 
    94         { 
    95                 cout << "tr: " << *this << endl; 
    96                 cout << "v: " << pt << " t: " << t << " a: " << a << " b: " << b << " n: " << normal << endl; 
    97         } 
     94  if (!pt.CheckValidity()) 
     95    { 
     96      cout << "tr: " << *this << endl; 
     97      cout << "v: " << pt << " t: " << t << " a: " << a << " b: " << b << " n: " << normal << endl; 
     98    } 
    9899#endif 
    99         const Vector3 w = pt - mVertices[1]; 
    100  
    101         const float uu = DotProd(u, u); 
    102     const float uv = DotProd(u, v); 
    103     const float vv = DotProd(v, v); 
     100  const Vector3 w = pt - mVertices[1]; 
     101   
     102  const float uu = DotProd(u, u); 
     103  const float uv = DotProd(u, v); 
     104  const float vv = DotProd(v, v); 
     105   
     106  const float wu = DotProd(w, u); 
     107  const float wv = DotProd(w, v); 
     108   
     109   
     110  const float D = uv * uv - uu * vv; 
     111   
     112  // get and test parametric coords 
     113  const float s = (uv * wv - vv * wu) / D; 
     114   
     115  if ((s < -Limits::Small) || (s > 1.0f + Limits::Small)) // pt is outside triangle 
     116    {    
     117      return Ray::NO_INTERSECTION; 
     118    } 
     119   
     120  const float s2 = (uv * wu - uu * wv) / D; 
     121   
     122  if ((s2 < -Limits::Small) || ((s + s2) > 1.0f + Limits::Small)) // pt is outside triangle 
     123    {    
     124      return Ray::NO_INTERSECTION; 
     125    } 
     126   
     127  return Ray::INTERSECTION; // I is in T 
     128} 
     129 
     130 
     131int 
     132Triangle3::CastSimpleRay(const SimpleRay &ray, 
     133                         float &t, 
     134                         const float nearestT) const 
     135{ 
     136  ////////////// 
     137  // specialised triangle ray casting version 
     138  // using ray-plane intersection 
     139   
     140  // get triangle edge vectors and plane normal 
     141  const Vector3 u = mVertices[0] - mVertices[1]; 
     142  const Vector3 v = mVertices[2] - mVertices[1]; 
     143 
     144  // cross product 
     145  const Vector3 normal = Normalize(CrossProd(v, u)); 
     146 
     147  // ray direction vector 
     148  const Vector3 dir = ray.mDirection; 
     149  const Vector3 w0 = ray.mOrigin - mVertices[1]; 
     150 
     151  // params to calc ray-plane intersect 
     152  const float a = -DotProd(normal, w0); 
     153  const float b = DotProd(normal, dir); 
     154 
     155  // check for division by zero 
     156  if (fabs(b) < Limits::Small)  
     157  {    
     158    // ray is parallel to triangle plane 
     159    if (a == 0) 
     160    { 
     161      // ray lies in triangle plane 
     162      return Ray::INTERSECTION_OUT_OF_LIMITS; 
     163    } 
     164    else { 
     165      // ray disjoint from plane 
     166      return Ray::NO_INTERSECTION; 
     167    } 
     168  } 
     169 
     170  // distance from origin of ray to plane 
     171  t = a / b; 
     172 
     173  if (t <= Limits::Small) // ray goes away from triangle 
     174  { 
     175    return Ray::INTERSECTION_OUT_OF_LIMITS; 
     176  } 
     177 
     178  // already found nearer intersection 
     179  if (t > nearestT + 1e-5) 
     180  { 
     181    return Ray::NO_INTERSECTION; 
     182  } 
     183 
     184  ///////////////// 
     185  //-- found intersection point 
     186  //-- check if it is inside triangle 
     187   
     188  const Vector3 pt = ray.mOrigin + t * dir;  
     189#if GTP_DEBUG 
     190  if (!pt.CheckValidity()) 
     191  { 
     192    cout << "tr: " << *this << endl; 
     193    cout << "v: " << pt << " t: " << t << " a: " << a << " b: " << b << " n: " << normal << endl; 
     194  } 
     195#endif 
     196  const Vector3 w = pt - mVertices[1]; 
     197 
     198  const float uu = DotProd(u, u); 
     199  const float uv = DotProd(u, v); 
     200  const float vv = DotProd(v, v); 
    104201     
    105         const float wu = DotProd(w, u); 
    106     const float wv = DotProd(w, v); 
    107  
    108  
    109         const float D = uv * uv - uu * vv; 
    110  
    111     // get and test parametric coords 
    112     const float s = (uv * wv - vv * wu) / D; 
    113  
    114     if ((s < -Limits::Small) || (s > 1.0f + Limits::Small)) // pt is outside triangle 
    115         {        
    116         return Ray::NO_INTERSECTION; 
    117         } 
    118  
    119         const float s2 = (uv * wu - uu * wv) / D; 
    120  
    121     if ((s2 < -Limits::Small) || ((s + s2) > 1.0f + Limits::Small)) // pt is outside triangle 
    122         {        
    123         return Ray::NO_INTERSECTION; 
    124         } 
    125  
    126         return Ray::INTERSECTION; // I is in T 
    127 } 
    128  
     202  const float wu = DotProd(w, u); 
     203  const float wv = DotProd(w, v); 
     204   
     205   
     206  const float D = uv * uv - uu * vv; 
     207   
     208  // get and test parametric coords 
     209  const float s = (uv * wv - vv * wu) / D; 
     210   
     211  if ((s < -Limits::Small) || 
     212      (s > 1.0f + Limits::Small)) // pt is outside triangle 
     213  {      
     214    return Ray::NO_INTERSECTION; 
     215  } 
     216 
     217  const float s2 = (uv * wu - uu * wv) / D; 
     218   
     219  if ((s2 < -Limits::Small) || 
     220      ((s + s2) > 1.0f + Limits::Small)) // pt is outside triangle 
     221  {      
     222    return Ray::NO_INTERSECTION; 
     223  } 
     224   
     225  return Ray::INTERSECTION; // I is in T 
     226} 
     227   
    129228 
    130229AxisAlignedBox3 Triangle3::GetBoundingBox() const 
     
    137236        box.Include(mVertices[2]); 
    138237 
     238        box.EnlargeToMinSize(); 
     239         
    139240        return box; 
    140241} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Triangle3.h

    r2176 r2575  
    99class AxisAlignedBox3; 
    1010class Ray; 
     11class SimpleRay; 
    1112class Plane3; 
    1213 
     
    3233        int CastRay(const Ray &ray, float &t, const float nearestT, Vector3 &normal) const; 
    3334 
     35        int CastSimpleRay(const SimpleRay &ray, float &t, const float nearestT) const; 
     36   
    3437        friend std::ostream& operator<< (std::ostream &s, const Triangle3 &A); 
    3538        friend std::istream& operator>> (std::istream &s, Triangle3 &A); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Vector3.cpp

    r1883 r2575  
    22#include "Vector3.h" 
    33#include "Halton.h" 
    4 #include "float.h" 
    5  
     4#include <float.h> 
    65 
    76namespace GtpVisibilityPreprocessor { 
     
    316315bool Vector3::CheckValidity() const 
    317316{ 
    318         return !(_isnan(x) || _isnan(y) || _isnan(z)); 
    319          //return ((x != x) || (y != y) || (z != z)); 
    320 } 
    321  
    322 } 
     317#ifdef _WIN32 
     318  return !(_isnan(x) || _isnan(y) || _isnan(z)); 
     319#else 
     320  return !(isnan(x) || isnan(y) || isnan(z)); 
     321#endif   
     322  //return ((x != x) || (y != y) || (z != z)); 
     323} 
     324 
     325} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Vector3.h

    r2176 r2575  
    250250}; 
    251251 
     252// forward declaration 
     253extern Vector3 UniformRandomVector(const Vector3 &normal); 
     254extern Vector3 UniformRandomVector(); 
     255extern Vector3 UniformRandomVector(const float r1, const float r2); 
     256   
    252257inline Vector3 
    253258ArbitraryNormal(const Vector3 &N) 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp

    r2569 r2575  
    33#include <stack> 
    44 
    5  
     5#include "Material.h" 
    66#include "ViewCell.h" 
    77#include "Mesh.h" 
     
    1414#include "Exporter.h" 
    1515#include "BvHierarchy.h" 
     16 
     17#ifdef PERFTIMER   
    1618#include "Timer/PerfTimer.h" 
    17  
     19#endif 
    1820 
    1921namespace GtpVisibilityPreprocessor { 
     
    2325#define TYPE_LEAF -3 
    2426 
     27#ifdef PERFTIMER   
    2528static PerfTimer sPvsTimer; 
    2629static PerfTimer sSearchTimer; 
    27  
    28  
     30#endif 
    2931 
    3032static inline bool ilt(Intersectable *obj1, Intersectable *obj2) 
     
    4547 
    4648typedef priority_queue<ViewCell *, vector<ViewCell *>,  
    47                                            myless<vector<ViewCell *>::value_type> > TraversalQueue; 
    48  
    49 int ViewCell::sMailId = 10000;//2147483647; 
    50 int ViewCell::sReservedMailboxes = 1; 
     49                       myless<vector<ViewCell *>::value_type> > TraversalQueue; 
     50 
     51int Intersectable::sMailId = 10000;//2147483647; 
     52int Intersectable::sReservedMailboxes = 1; 
    5153 
    5254float MergeCandidate::sRenderCostWeight = 0; 
     
    5557// pvs penalty can be different from pvs size 
    5658inline static float EvalPvsPenalty(const float pvs,  
    57                                                                    const float lower,  
    58                                                                    const float upper) 
     59                                   const float lower,  
     60                                   const float upper) 
    5961{ 
    6062        // clamp to minmax values 
     
    26862688        Intersectable *obj; 
    26872689 
     2690#ifdef PERFTIMER   
    26882691        sPvsTimer.Entry(); 
    2689  
     2692#endif 
    26902693        int pvsSize; 
    26912694        stream.read(reinterpret_cast<char *>(&pvsSize), sizeof(int)); 
     
    27032706        } 
    27042707 
     2708#ifdef PERFTIMER 
    27052709        sPvsTimer.Exit(); 
     2710#endif   
    27062711 
    27072712        return leaf; 
     
    27382743        queue<ViewCell *> tStack; 
    27392744 
     2745#ifdef PERFTIMER   
    27402746        sPvsTimer.Start(); 
    2741  
     2747#endif 
     2748         
    27422749        mPvsIds = new int[pvsObjects.size()]; 
    27432750 
     
    27742781        } 
    27752782 
     2783#ifdef PERFTIMER   
    27762784        Debug << "needed " << sPvsTimer.TotalTime() << " secs for pvs loading" << endl; 
    2777  
     2785#endif 
     2786         
    27782787        delete mPvsIds; 
    27792788 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.h

    r2176 r2575  
    303303        /** Sets parent node. 
    304304        */ 
    305         inline void BspNode::SetParent(BspInterior *parent) 
    306         { 
    307                 mParent = parent; 
     305        inline void SetParent(BspInterior *parent) 
     306        { 
     307          mParent = parent; 
    308308        } 
    309309 
     
    375375        /** Returns split plane. 
    376376        */ 
    377         Plane3 BspInterior::GetPlane() const 
     377        Plane3 GetPlane() const 
    378378        { 
    379379                return mPlane; 
     
    441441        /** @return true since it is an interior node  
    442442        */ 
    443         bool BspLeaf::IsLeaf() const  
     443        bool IsLeaf() const  
    444444        {  
    445445                return true;  
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r2571 r2575  
    2424#include "SamplingStrategy.h" 
    2525#include "SceneGraph.h" 
     26 
     27#ifdef PERFTIMER   
    2628#include "Timer/PerfTimer.h" 
    27  
     29#endif // PERFTIMER 
    2830 
    2931#define USE_RAY_LENGTH_AS_CONTRIBUTION 0 
     
    3941 
    4042 
     43#ifdef PERFTIMER   
    4144PerfTimer viewCellCastTimer; 
    4245PerfTimer pvsTimer; 
    4346PerfTimer objTimer; 
    44  
     47#endif 
     48   
    4549// HACK 
    4650const static bool SAMPLE_AFTER_SUBDIVISION = true; 
     
    6670}; 
    6771 
     72 
     73 
     74struct SortableViewCellEntry { 
     75 
     76        SortableViewCellEntry() {} 
     77        SortableViewCellEntry(const float v, ViewCell *cell):mValue(v), mViewCell(cell) {} 
     78 
     79        float mValue; 
     80        ViewCell *mViewCell; 
     81 
     82  friend bool operator<(const SortableViewCellEntry &a, const SortableViewCellEntry &b); 
     83}; 
     84 
     85 
     86inline bool 
     87operator<(const SortableViewCellEntry &a, const SortableViewCellEntry &b) { 
     88  return a.mValue < b.mValue; 
     89} 
    6890 
    6991ViewCellsManager::ViewCellsManager(ViewCellsTree *viewCellsTree): 
     
    10591081        int id; 
    10601082 
     1083#ifdef PERFTIMER   
    10611084        PerfTimer boxTimer; 
    10621085 
    10631086        boxTimer.Start(); 
    10641087        boxTimer.Entry(); 
    1065          
     1088#endif   
    10661089        for (int i = 0; i < numBoxes; ++ i) 
    10671090        { 
     
    10741097 
    10751098 
     1099#ifdef PERFTIMER   
    10761100        boxTimer.Exit(); 
    10771101 
    10781102        Debug << numBoxes << " boxes loaded in " << boxTimer.TotalTime() << " secs" << endl; 
     1103#endif 
    10791104} 
    10801105 
     
    16991724inline float EvalMergeCost(ViewCell *root, ViewCell *candidate) 
    17001725{ 
    1701         return root->GetPvs().GetPvsHomogenity(candidate->GetPvs()); 
     1726  return root->GetPvs().GetPvsHomogenity(candidate->GetPvs()); 
    17021727} 
    17031728 
     
    17731798} 
    17741799 
    1775  
    1776 struct SortableViewCellEntry { 
    1777  
    1778         SortableViewCellEntry() {} 
    1779         SortableViewCellEntry(const float v, ViewCell *cell):mValue(v), mViewCell(cell) {} 
    1780  
    1781         float mValue; 
    1782         ViewCell *mViewCell; 
    1783  
    1784         friend bool operator<(const SortableViewCellEntry &a, const SortableViewCellEntry &b) { 
    1785                 return a.mValue < b.mValue; 
    1786         } 
    1787 }; 
    17881800 
    17891801 
     
    21142126        } 
    21152127 
     2128#ifdef PERFTIMER   
    21162129        cout << "view cell cast time: " << viewCellCastTimer.TotalTime() << " s" << endl; 
    21172130        Debug << "view cell cast time: " << viewCellCastTimer.TotalTime() << " s" << endl; 
     
    21192132        cout << "pvs time: " << pvsTimer.TotalTime() << " s" << endl; 
    21202133        Debug << "pvs time: " << pvsTimer.TotalTime() << " s" << endl; 
    2121          
     2134#endif   
    21222135        return sum; 
    21232136} 
     
    28692882        ViewCell::NewMail(); 
    28702883 
     2884#ifdef PERFTIMER   
    28712885        viewCellCastTimer.Entry(); 
    2872  
     2886#endif 
    28732887        static ViewCellContainer viewCells; 
    28742888        static VssRay *lastVssRay = NULL; 
     
    28892903        } 
    28902904 
     2905#ifdef PERFTIMER   
    28912906        viewCellCastTimer.Exit(); 
    2892  
     2907#endif 
    28932908        mSamplesStat.mViewCells += (int)viewCells.size(); 
    28942909 
     
    29082923        Intersectable *terminationObj; 
    29092924 
     2925#ifdef PERFTIMER   
    29102926        objTimer.Entry(); 
    2911  
     2927#endif 
    29122928        // obtain pvs entry (can be different from hit object) 
    29132929        terminationObj = ray.mTerminationObject; 
    29142930 
     2931#ifdef PERFTIMER   
    29152932        objTimer.Exit(); 
    29162933 
    29172934        pvsTimer.Entry(); 
    2918  
     2935#endif 
     2936         
    29192937        ViewCellContainer::const_iterator it = viewCells.begin(); 
    29202938 
     
    29292947        } 
    29302948 
     2949#ifdef PERFTIMER   
    29312950        pvsTimer.Exit(); 
    2932  
     2951#endif 
     2952         
    29332953        mSamplesStat.mPvsContributions += ray.mPvsContribution; 
    29342954        if (ray.mPvsContribution) 
     
    34603480                                                           const float filterSize, 
    34613481                                                           ObjectPvs &pvs, 
    3462                                                            vector<AxisAlignedBox3> *filteredBoxes 
     3482                                                           vector<AxisAlignedBox3> *filteredBoxes, 
     3483                                                           const bool onlyNewObjects 
    34633484                                                           ) 
    34643485{ 
     
    34803501 
    34813502        if (!mUseKdPvs) 
    3482         {       // first mark all objects from this pvs 
    3483                 while (pit.HasMoreEntries())     
    3484                         pit.Next()->Mail(); 
    3485         } 
    3486  
     3503        { 
     3504          // first mark all objects from this pvs 
     3505          while (pit.HasMoreEntries())   
     3506                pit.Next()->Mail(); 
     3507        } 
     3508         
    34873509        int pvsSize = 0; 
    34883510        int nPvsSize = 0; 
     
    35483570 
    35493571                pit = basePvs.GetIterator(); 
    3550  
     3572                 
     3573                if (onlyNewObjects) { 
     3574                  while (pit.HasMoreEntries()) { 
     3575                        // mail all objects from the original not to include them in the 
     3576                        // resulting pvs 
     3577                        Intersectable *obj = pit.Next(pvsData); 
     3578                        obj->Mail(); 
     3579                  } 
     3580                  pit = basePvs.GetIterator(); 
     3581                } 
     3582                 
    35513583                while (pit.HasMoreEntries())  
    35523584                {                
     
    36313663                stats.mAvgFilterRadius /= (stats.mLocalFilterCount + stats.mGlobalFilterCount); 
    36323664        } 
    3633  
     3665         
    36343666        //Debug << " nPvs size = " << pvs.GetSize() << endl; 
    36353667 
    3636         if (!mUseKdPvs) 
     3668        if (!mUseKdPvs && !onlyNewObjects) 
    36373669        { 
    36383670                PvsData pvsData; 
     
    71627194        CLEAR_CONTAINER(tmpRays); 
    71637195 
     7196#ifdef PERFTIMER   
    71647197        cout << "view cell cast time: " << viewCellCastTimer.TotalTime() << " s" << endl; 
    71657198        Debug << "view cell cast time: " << viewCellCastTimer.TotalTime() << " s" << endl; 
    7166  
    71677199        cout << "pvs time: " << pvsTimer.TotalTime() << " s" << endl; 
    71687200        Debug << "pvs time: " << pvsTimer.TotalTime() << " s" << endl; 
     7201#endif 
    71697202         
    71707203        return sum; 
     
    71747207 
    71757208 
    7176 ViewCellsManager *ViewCellsManager::LoadViewCellsBinary(const string &filename,  
    7177                                                                                                                 ObjectContainer &pvsObjects, 
    7178                                                                                                                 bool finalizeViewCells, 
    7179                                                                                                                 BoundingBoxConverter *bconverter)                                                                                                 
    7180 { 
    7181         IN_STREAM stream(filename.c_str()); 
    7182  
    7183         if (!stream.is_open()) 
     7209ViewCellsManager * 
     7210ViewCellsManager::LoadViewCellsBinary(const string &filename,  
     7211                                                                          ObjectContainer &pvsObjects, 
     7212                                                                          bool finalizeViewCells, 
     7213                                                                          BoundingBoxConverter *bconverter)                                                                                               
     7214{ 
     7215  IN_STREAM stream(filename.c_str()); 
     7216   
     7217  if (!stream.is_open()) 
    71847218        { 
    71857219                Debug << "View cells loading failed: could not open file" << endl; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h

    r2574 r2575  
    364364        /** Creates mesh for this view cell. 
    365365        */ 
    366         virtual void CreateMesh(ViewCell *vc) = NULL; 
     366        virtual void CreateMesh(ViewCell *vc) = 0; 
    367367        /** Writes view cells to disc. 
    368368        */ 
    369369        virtual bool ExportViewCells(const string filename,  
    370                                                                 const bool exportPvs,  
    371                                                                 const ObjectContainer &objects); 
     370                                    const bool exportPvs,  
     371                                    const ObjectContainer &objects); 
    372372        /** Casts beam to collect view cells. 
    373373        */ 
     
    626626                                                                           const int maxRays, 
    627627                                                                           const string &prefix, 
    628                                                                            VssRayContainer *visRays = NULL) = NULL; 
     628                                                                           VssRayContainer *visRays = NULL) = 0; 
    629629 
    630630 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp

    r2543 r2575  
    147147                EndObjectSpaceHierarchy(); 
    148148                Debug << "object space hierarchy parsed" << endl; 
     149#ifdef PERFTIMER   
    149150                mObjectTimer.Exit(); 
     151#endif 
    150152        } 
    151153        // finished paring, create view cells manager 
     
    154156                CreateViewCellsManager(); 
    155157 
     158#ifdef PERFTIMER   
    156159                Debug << "pvs time: " << mPvsTimer.TotalTime() << endl; 
    157160                Debug << "object time: " << mObjectTimer.TotalTime() << endl; 
    158161                Debug << "box time: " << mBoxTimer.TotalTime() << endl; 
    159  
     162#endif 
    160163        } 
    161164        else if (element == "Interior") 
     
    298301        const long startTime = GetTime(); 
    299302         
     303#ifdef PERFTIMER   
    300304        mBoxTimer.Entry(); 
    301  
     305#endif 
    302306        if (mBoundingBoxConverter) 
    303307        { 
     
    320324                  << TimeDiff(startTime, GetTime()) * 1e-6 << " secs" << endl; 
    321325 
     326#ifdef PERFTIMER   
    322327        mBoxTimer.Exit(); 
     328#endif 
    323329} 
    324330 
     
    481487 
    482488                mCurrentState = PARSE_OBJECTSPACE_HIERARCHY; 
     489#ifdef PERFTIMER   
    483490                mObjectTimer.Entry(); 
     491#endif 
    484492                StartObjectSpaceHierarchy(attributes); 
    485493        } 
     
    539547        } 
    540548 
     549#ifdef PERFTIMER   
    541550        mPvsTimer.Entry(); 
    542  
     551#endif 
    543552        Intersectable::NewMail(); 
    544553 
     
    582591        } 
    583592         
     593#ifdef PERFTIMER   
    584594        mPvsTimer.Exit(); 
     595#endif 
    585596} 
    586597 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParserXerces.h

    r2227 r2575  
    88#include "Mesh.h" 
    99#include "BoundingBoxConverter.h" 
     10 
     11#ifdef __WINDOWS__ 
    1012#include <hash_map> 
    11  
     13#else 
     14#include <map> 
     15#endif 
     16 
     17#ifdef PERFTIMER   
    1218#include "Timer/PerfTimer.h" 
     19#endif 
    1320 
    1421namespace GtpVisibilityPreprocessor { 
     
    5461 
    5562 
     63#ifdef __WINDOWS__ 
    5664typedef stdext::hash_map<int, Intersectable *> pvs_hash; 
    57  
     65#else 
     66typedef std::map<int, Intersectable *> pvs_hash; 
     67#endif   
    5868 
    5969class ViewCellsParseHandlers: public HandlerBase 
     
    158168  int nObjects; 
    159169   
     170#ifdef PERFTIMER   
    160171  PerfTimer mBoxTimer; 
    161172  PerfTimer mPvsTimer; 
    162173  PerfTimer mObjectTimer; 
    163  
     174#endif 
     175   
    164176  pvs_hash mHashPvs; 
    165177 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp

    r2347 r2575  
    34783478                        BspInterior *in = static_cast<BspInterior *>(node); 
    34793479 
    3480                         Plane3 &splitPlane = in->GetPlane(); 
     3480                        Plane3 *splitPlane = &(in->GetPlane()); 
    34813481                         
    3482                         const int entSide = splitPlane.Side(entp, thresh); 
    3483                         const int extSide = splitPlane.Side(extp, thresh); 
     3482                        const int entSide = splitPlane->Side(entp, thresh); 
     3483                        const int extSide = splitPlane->Side(extp, thresh); 
    34843484 
    34853485                        if (entSide < 0)  
     
    35183518 
    35193519                        // find intersection of ray segment with plane 
    3520                         extp = splitPlane.FindIntersection(origin, extp, &t); 
     3520                        extp = splitPlane->FindIntersection(origin, extp, &t); 
    35213521                }  
    35223522                else 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp

    r2547 r2575  
    709709                                                        const bool globalCriteriaMet) 
    710710{ 
     711#ifdef PERFTIMER   
    711712        mSubdivTimer.Entry(); 
    712  
     713#endif 
     714         
    713715        // todo remove dynamic cast 
    714716        VspSubdivisionCandidate *sc =  
     
    788790        } 
    789791 
     792#ifdef PERFTIMER   
    790793        mSubdivTimer.Exit(); 
    791  
     794#endif 
    792795        return newNode; 
    793796} 
     
    797800                                                                           bool computeSplitPlane) 
    798801{ 
     802#ifdef PERFTIMER   
    799803        mPlaneTimer.Entry(); 
    800  
     804#endif 
     805         
    801806        if (computeSplitPlane) 
    802807        { 
     
    818823        } 
    819824         
     825#ifdef PERFTIMER   
    820826        mPlaneTimer.Exit(); 
    821827        mEvalTimer.Entry(); 
    822  
     828#endif 
     829         
    823830        VspLeaf *leaf = static_cast<VspLeaf *>(splitCandidate.mParentData.mNode); 
    824831 
     
    917924 
    918925        //cout << "vsp render cost decrease=" << renderCostDecr << endl; 
     926#ifdef PERFTIMER   
    919927        mEvalTimer.Exit(); 
     928#endif 
    920929} 
    921930 
     
    948957                                                                        VspTraversalData &backData) 
    949958{ 
     959#ifdef PERFTIMER   
    950960        mNodeTimer.Entry(); 
    951          
     961#endif   
    952962        VspLeaf *leaf = static_cast<VspLeaf *>(sc.mParentData.mNode); 
    953963 
     
    10421052        interior->mTimeStamp = mHierarchyManager->mTimeStamp ++; 
    10431053 
     1054#ifdef PERFTIMER   
    10441055        mNodeTimer.Exit(); 
    1045  
     1056#endif 
    10461057        return interior; 
    10471058} 
     
    11031114                                                                                float maxBand) 
    11041115{ 
     1116#ifdef PERFTIMER   
    11051117        mSortTimer.Entry(); 
    1106  
     1118#endif 
    11071119        mLocalSubdivisionCandidates->clear(); 
    11081120 
     
    11541166                sort(mLocalSubdivisionCandidates->begin(), mLocalSubdivisionCandidates->end()); 
    11551167 
     1168#ifdef PERFTIMER   
    11561169        mSortTimer.Exit(); 
     1170#endif 
    11571171} 
    11581172 
     
    15731587                                                                float &pBack) 
    15741588{ 
     1589#ifdef PERFTIMER   
    15751590        mSplitTimer.Entry(); 
    1576  
     1591#endif 
    15771592        float nPosition[3]; 
    15781593        float nCostRatio[3]; 
     
    16701685        pBack = nProbBack[bestAxis]; 
    16711686 
     1687#ifdef PERFTIMER   
    16721688        mSplitTimer.Exit(); 
    1673  
     1689#endif 
    16741690        return nCostRatio[bestAxis]; 
    16751691} 
     
    31583174void VspTree::GetViewCells(const VssRay &ray, ViewCellContainer &viewCells) 
    31593175{ 
     3176#ifdef PERFTIMER   
    31603177        mViewCellsTimer.Entry(); 
     3178#endif 
    31613179         
    31623180        static Ray hray; 
     
    31753193        CastLineSegment(origin, termination, viewCells, false); 
    31763194 
     3195#ifdef PERFTIMER   
    31773196        mViewCellsTimer.Exit(); 
     3197#endif 
    31783198} 
    31793199 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h

    r2547 r2575  
    1212#include "SubdivisionCandidate.h" 
    1313#include "HierarchyManager.h" 
     14#ifdef PERFTIMER 
    1415#include "Timer/PerfTimer.h" 
     16#endif // PERFTIMER 
    1517 
    1618 
     
    294296class VspLeaf: public VspNode  
    295297{ 
    296         friend VspTree; 
     298  friend class VspTree; 
    297299 
    298300public: 
     
    670672        //////////// 
    671673 
     674#ifdef PERFTIMER   
    672675        PerfTimer mSortTimer; 
    673676        PerfTimer mSplitTimer; 
     
    677680        PerfTimer mPlaneTimer; 
    678681        PerfTimer mViewCellsTimer; 
    679  
     682#endif  
     683   
    680684protected: 
    681685 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VssRay.h

    r2353 r2575  
    151151  float GetOpositeDirParametrization(const int axis) const; 
    152152 
    153   static float VssRay::GetDirParam(const int axis, const Vector3 dir); 
    154   static Vector3 VssRay::GetInvDirParam(const float alpha, const float beta); 
     153  static float GetDirParam(const int axis, const Vector3 dir); 
     154  static Vector3 GetInvDirParam(const float alpha, const float beta); 
    155155 
    156156  float GetSize() const { return  1.0f/mInvSize; } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VssTree.cpp

    r2105 r2575  
    17711771         
    17721772  sort(leaves.begin(), 
    1773            leaves.end(), 
    1774            GreaterContribution); 
     1773       leaves.end(), 
     1774       GreaterContribution); 
    17751775                          
    17761776 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VssTree.h

    r2176 r2575  
    493493  }; 
    494494   
    495   friend bool GreaterContribution(const VssTreeLeaf * a, const VssTreeLeaf *b) { 
    496         return a->GetAvgRayContribution() > b->GetAvgRayContribution(); 
    497   } 
     495  friend bool GreaterContribution(const VssTreeLeaf * a, const VssTreeLeaf *b); 
    498496   
    499497}; 
     
    504502  parent(p), axis(-1), depth(p ? p->depth + 1 : 0) {} 
    505503 
    506  
     504inline bool GreaterContribution(const VssTreeLeaf * a, const VssTreeLeaf *b) { 
     505  return a->GetAvgRayContribution() > b->GetAvgRayContribution(); 
     506} 
     507   
    507508 
    508509// --------------------------------------------------------------- 
  • GTP/trunk/Lib/Vis/Preprocessing/src/common.h

    r2176 r2575  
    2121#include <limits.h> 
    2222 
    23  
     23// use perftimer 
     24#define PERFTIMER 
    2425 
    2526namespace GtpVisibilityPreprocessor { 
    2627 
     28   
    2729 
    2830 
     
    4547 
    4648#if defined(__GNUC__) || defined(_MSC_VER) 
    47 #define DIRCAT '.' 
     49//#define DIRCAT '.' 
    4850#endif 
    4951 
  • GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp

    r2569 r2575  
    66 
    77#define NOMINMAX 
     8#ifdef __WINDOWS__ 
    89#include <windows.h> 
    9 #include <stdio.h> 
     10#ifdef _CRT_SET 
    1011#include <crtdbg.h> 
    11  
     12#endif // _CRT_SET 
     13#endif 
     14#include <cstdio> 
     15 
     16#include "Camera.h" 
    1217#include "PreprocessorFactory.h" 
    1318#include "Parser.h" 
     
    2025#include "SceneGraph.h" 
    2126#include "GlobalLinesRenderer.h" 
     27#include "RayCaster.h" 
     28//#include "testrt.h" 
    2229 
    2330#include "ViewCellsManager.h" 
     
    152159} 
    153160 
    154  
    155161int 
    156162main(int argc, char **argv) 
    157163{ 
    158         int returnCode = 0; 
     164#if 0 
     165  // Test code by VH 
     166  //TestRTcamera(argc, argv); 
     167  //TestRTfromFile(argc, argv); 
     168  TestRTfromFilePackets(argc, argv); 
     169  return 0; 
     170#endif 
     171 
     172  int returnCode = 0; 
     173 
     174  //Now just call this function at the start of your program and if you're 
     175  //compiling in debug mode (F5), any leaks will be displayed in the Output 
     176  //window when the program shuts down. If you're not in debug mode this will 
     177  //be ignored. Use it as you will! 
     178  //note: from GDNet Direct [3.8.04 - 3.14.04] void detectMemoryLeaks() { 
     179#ifdef _CRT_SET 
     180  _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF|_CRTDBG_ALLOC_MEM_DF); 
     181  _CrtSetReportMode(_CRT_ASSERT,_CRTDBG_MODE_FILE); 
     182  _CrtSetReportFile(_CRT_ASSERT,_CRTDBG_FILE_STDERR);  
     183#endif 
    159184 
    160185        //Now just call this function at the start of your program and if you're 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ply.h

    r749 r2575  
    132132 
    133133/* memory allocation */ 
    134 extern char *my_alloc(); 
     134extern char *my_alloc(int,int,char *); 
    135135#define myalloc(mem_size) my_alloc((mem_size), __LINE__, __FILE__) 
    136136 
     
    202202extern int equal_strings(char *, char *); 
    203203 
    204  
    205204#ifdef __cplusplus 
    206205} 
     
    208207#endif /* !__PLY_H__ */ 
    209208 
    210  
  • GTP/trunk/Lib/Vis/Preprocessing/src/preprocessor.pro

    r2574 r2575  
    117117Timer/BenchTimer.cpp Timer/merror.cpp \ 
    118118Intersectable.cpp TraversalTree.cpp ObjectPvs.cpp ObjectsParser.cpp \ 
    119 FilterBasedDistribution.cpp DifferenceSampling.cpp 
     119FilterBasedDistribution.cpp DifferenceSampling.cpp HavranRayCaster.cpp 
    120120 
    121121 
  • GTP/trunk/Lib/Vis/Preprocessing/src/run_test2

    r2574 r2575  
    33 
    44#COMMAND="./release/preprocessor.exe -preprocessor_quit_on_finish+" 
    5 COMMAND="../scripts/preprocessor.sh -preprocessor_quit_on_finish+ -preprocessor_use_gl_renderer- -preprocessor_evaluate_filter- -samples_per_evaluation=5000000 -samples_per_pass=500000 -total_samples=6000000" 
     5COMMAND="../scripts/preprocessor.sh -preprocessor_quit_on_finish+ -preprocessor_use_gl_renderer+ -preprocessor_evaluate_filter- -samples_per_evaluation=5000000 -samples_per_pass=500000 -total_samples=6000000" 
    66 
    77 
Note: See TracChangeset for help on using the changeset viewer.