Changeset 1984


Ignore:
Timestamp:
01/15/07 21:59:52 (17 years ago)
Author:
bittner
Message:

ray sort updates

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

Legend:

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

    r1966 r1984  
    7474         
    7575        mMixtureDistribution->GenerateSamples(mSamplesPerPass, rays); 
    76          
    77         CastRays(rays, vssRays, true, pruneInvalidRays); 
     76 
     77        bool doubleRays = true; 
     78        CastRays(rays, vssRays, doubleRays, pruneInvalidRays); 
    7879        totalVssRays += (int)vssRays.size(); 
    7980 
  • GTP/trunk/Lib/Vis/Preprocessing/src/IntelRayCaster.cpp

    r1983 r1984  
    2828bool IntelRayCaster::InitRayCast(const string externKdTree) 
    2929{ 
    30         cout<<"Ray Cast file: " << externKdTree << endl; 
    31         return mlrtaLoadAS(externKdTree.c_str()); 
     30  cout<<"Ray Cast file: " << externKdTree << endl; 
     31  return mlrtaLoadAS(externKdTree.c_str()); 
    3232} 
    3333 
     
    5151 
    5252        hittriangle = mlrtaIntersectAS( 
    53                 &simpleRay.mOrigin.x, 
    54                 &simpleRay.mDirection.x, 
    55                 normal, 
    56                 dist); 
    57  
     53                                                                   &simpleRay.mOrigin.x, 
     54                                                                   &simpleRay.mDirection.x, 
     55                                                                   normal, 
     56                                                                   dist); 
     57         
    5858        if (hittriangle != -1 ) { 
    5959                Intersectable *intersect = mPreprocessor.GetParentObject(hittriangle); 
     
    7373        if (castDoubleRay) 
    7474        { 
    75                 Vector3 dir = -simpleRay.mDirection; 
     75          cerr<<"HERE"<<endl; 
     76          Vector3 dir = -simpleRay.mDirection; 
    7677                hittriangle = mlrtaIntersectAS( 
    7778                                                                                &simpleRay.mOrigin.x, 
     
    122123#endif 
    123124 
    124         int forward_hit_triangles[16]; 
    125         float forward_dist[16]; 
    126  
    127         int backward_hit_triangles[16]; 
    128         float backward_dist[16]; 
     125        static int forward_hit_triangles[16]; 
     126        static float forward_dist[16]; 
     127 
     128        static int backward_hit_triangles[16]; 
     129        static float backward_dist[16]; 
    129130 
    130131         
     
    185186                Debug<<"FH\n"<<flush; 
    186187#endif 
     188 
    187189                Intersectable *intersect = mPreprocessor.GetParentObject(forward_hit_triangles[i]); 
    188190 
  • GTP/trunk/Lib/Vis/Preprocessing/src/InternalRayCaster.cpp

    r1972 r1984  
    4949  mPreprocessor.SetupRay(ray, simpleRay.mOrigin, simpleRay.mDirection); 
    5050  ray.mFlags &= ~Ray::CULL_BACKFACES; 
    51    
    52   if (mKdTree->CastRay(ray))  
    53         { 
    54           hitA.mObject = ray.intersections[0].mObject; 
    55           hitA.mPoint = ray.Extrap(ray.intersections[0].mT); 
    56           hitA.mNormal = ray.intersections[0].mNormal;  
    57           //    cout << "hita: " << hitA.mPoint << " !obj: " << hitA.mObject << endl; 
    58         } 
    59    
    60         mPreprocessor.SetupRay(ray, simpleRay.mOrigin, -simpleRay.mDirection); 
    61         ray.mFlags &= ~Ray::CULL_BACKFACES; 
    62    
    63   if (castDoubleRay && mKdTree->CastRay(ray))  
    64                 { 
    65                         hitB.mObject = ray.intersections[0].mObject; 
    66                         hitB.mPoint = ray.Extrap(ray.intersections[0].mT); 
    67                         hitB.mNormal = ray.intersections[0].mNormal; 
    68                 } 
     51 
     52   
     53  if (mKdTree->CastRay(ray)) { 
     54        hitA.mObject = ray.intersections[0].mObject; 
     55        hitA.mPoint = ray.Extrap(ray.intersections[0].mT); 
     56        hitA.mNormal = ray.intersections[0].mNormal;  
     57        //      cout << "hita: " << hitA.mPoint << " !obj: " << hitA.mObject << endl; 
     58  } 
     59   
     60  mPreprocessor.SetupRay(ray, simpleRay.mOrigin, -simpleRay.mDirection); 
     61  ray.mFlags &= ~Ray::CULL_BACKFACES; 
     62   
     63  if (castDoubleRay && mKdTree->CastRay(ray)) { 
     64        hitB.mObject = ray.intersections[0].mObject; 
     65        hitB.mPoint = ray.Extrap(ray.intersections[0].mT); 
     66        hitB.mNormal = ray.intersections[0].mNormal; 
     67  } 
    6968   
    7069  return ProcessRay( 
    71                                                                                 simpleRay, 
    72                                                                                 hitA, 
    73                                                                                 hitB, 
    74                                                                                 vssRays, 
    75                                                                                 box, 
    76                                                                                 castDoubleRay, 
    77                                                                                 pruneInvalidRays 
    78                                                                                 ); 
     70                                        simpleRay, 
     71                                        hitA, 
     72                                        hitB, 
     73                                        vssRays, 
     74                                        box, 
     75                                        castDoubleRay, 
     76                                        pruneInvalidRays 
     77                                        ); 
    7978} 
    8079 
  • GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp

    r1974 r1984  
    606606                                ) 
    607607{ 
     608   
    608609  int hits = 0; 
    609610   
     
    614615 
    615616  //  ray.ComputeInvertedDir(); 
    616  
    617617  Intersectable::NewMail(); 
    618618 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Makefile

    r1983 r1984  
    11############################################################################# 
    22# Makefile for building: preprocessor 
    3 # Generated by qmake (2.00a) (Qt 4.1.2) on: po 15. I 15:33:12 2007 
     3# Generated by qmake (2.00a) (Qt 4.1.2) on: po 15. I 21:59:19 2007 
    44# Project:  preprocessor.pro 
    55# Template: app 
     
    6363        $(MAKE) -f $(MAKEFILE).Debug uninstall 
    6464 
    65 Makefile: preprocessor.pro  C:/Qt/4.1.2/mkspecs/win32-msvc2005\qmake.conf C:/Qt/4.1.2/mkspecs/qconfig.pri \ 
     65Makefile: preprocessor.pro  C:/Qt/4.1.2/mkspecs/win32-msvc.net\qmake.conf C:/Qt/4.1.2/mkspecs/qconfig.pri \ 
    6666                C:\Qt\4.1.2\mkspecs\features\qt_config.prf \ 
    6767                C:\Qt\4.1.2\mkspecs\features\exclusive_builds.prf \ 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp

    r1978 r1984  
    404404{ 
    405405        if (index == -1) 
    406                 return NULL; 
     406          return NULL; 
    407407         
    408408        if (!mFaceParents.empty()) 
     
    419419        } 
    420420        else 
    421         { 
    422                 if (index >= (int)mObjects.size()) 
    423                 { 
    424                         cerr << "Warning: triangle index out of range! " << index << endl; 
    425                         return NULL; 
    426                 } 
    427                 else 
    428                 { 
    429                         return mObjects[index]; 
    430                 } 
    431         } 
     421          { 
     422          if (index >= (int)mObjects.size()) { 
     423                cerr<<"Warning: triangle  index out of range! "<<index<<endl; 
     424                return NULL; 
     425          } 
     426          else 
     427                { 
     428                  return mObjects[index]; 
     429                } 
     430          } 
    432431} 
    433432 
     
    11561155  mRayCaster->SortRays(rays); 
    11571156  cout<<"Rays sorted in "<<TimeDiff(t1, GetTime())<<" s."<<endl; 
     1157 
     1158  if (1) { 
     1159        VssRayContainer tmpRays; 
     1160        for (int i=0; i < 200; i++) { 
     1161          tmpRays.push_back(new VssRay(rays[i].mOrigin, 
     1162                                                                   rays[i].mOrigin + 100.0f*rays[i].mDirection, 
     1163                                                                   NULL, 
     1164                                                                   NULL 
     1165                                                                   ) 
     1166                                                ); 
     1167           
     1168        } 
     1169        ExportRays("sorted_rays.x3d", tmpRays, 200); 
     1170  } 
    11581171#endif 
    11591172   
     
    11881201         
    11891202                if ((int)rays.size() > 10000 && i % 10000 == 0) 
    1190                         cout<<"\r"<<i<<"/"<<(int)rays.size()<<"\r"; 
     1203                  cout<<"\r"<<i<<"/"<<(int)rays.size()<<"\r"; 
    11911204        } 
    11921205     
  • GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlViewer.h

    r1983 r1984  
    1111class QtGlViewer : public QGLWidget 
    1212{ 
     13 
    1314  Q_OBJECT 
    1415 
  • GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.cpp

    r1974 r1984  
    123123RayCaster::SortRays(SimpleRayContainer &rays) 
    124124{ 
    125   _SortRays(rays, 0, rays.size()-1, 0); 
     125  AxisAlignedBox3 box = 
     126        mPreprocessor.mViewCellsManager->GetViewSpaceBox(); 
     127         
     128  float b[12]={ 
     129        box.Min().x, 
     130        box.Min().y, 
     131        box.Min().z, 
     132        -1, 
     133        -1, 
     134        -1, 
     135        box.Max().x, 
     136        box.Max().y, 
     137        box.Max().z, 
     138        1, 
     139        1, 
     140        1 
     141  }; 
     142 
     143  _SortRays(rays, 
     144                        0, 
     145                        rays.size()-1, 
     146                        0, 
     147                        b 
     148                        ); 
    126149} 
    127150                                         
     
    130153                                         const int l, 
    131154                                         const int r, 
    132                                          const int axis) 
     155                                         const int depth, 
     156                                         float box[12]) 
    133157{ 
    134158  // pick-up a pivot 
    135   int     i=l,j=r; 
    136   float x = rays[(l+r)/2].GetParam(axis); 
     159  int axis; 
     160   
     161  float maxDiff = -1.0f; 
     162  // get the largest axis 
     163  int offset = 0; 
     164 
     165  if (depth%5==0) 
     166        offset = 3; 
     167   
     168  for (int i=offset; i < offset+3; i++) { 
     169        float diff = box[i+6] - box[i]; 
     170        if (diff > maxDiff) { 
     171          maxDiff = diff; 
     172          axis = i; 
     173        } 
     174  } 
     175 
     176  //  cout<<depth<<" "<<axis<<endl; 
     177   
     178  int i=l,j=r; 
     179  float x = (box[axis] + box[axis+6])*0.5f; 
     180  //  float x = rays[(l+r)/2].GetParam(axis); 
    137181  do { 
    138         while(rays[i].GetParam(axis) < x) 
     182        while(rays[i].GetParam(axis) < x && i<=j) 
    139183          i++; 
    140         while(x < rays[j].GetParam(axis)) 
     184        while(x < rays[j].GetParam(axis) && i<=j) 
    141185          j--; 
    142186         
     
    148192  } while (i<=j); 
    149193   
    150   if (l + 16 < j ) 
    151         _SortRays(rays, l, j, (axis+1)%6); 
    152    
    153   if (i + 16 < r) 
    154     _SortRays(rays, i, r, (axis+1)%6);  
     194  if (l + 64 < j ) { 
     195        // set new max 
     196        float save = box[axis+6]; 
     197        box[axis+6] = x; 
     198        _SortRays(rays, l, j, depth+1, box); 
     199        box[axis+6] = save; 
     200  } 
     201   
     202  if (i + 64 < r) { 
     203        // set new min 
     204        box[axis] = x; 
     205    _SortRays(rays, i, r, depth+1, box); 
     206  } 
    155207} 
    156208   
     
    166218                                          const bool pruneInvalidRays) 
    167219{ 
    168         int hits = 0; 
     220  int hits = 0; 
    169221 
    170222#if DEBUG_RAYCAST 
  • GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.h

    r1974 r1984  
    6868 
    6969protected: 
    70   void 
    71   _SortRays(SimpleRayContainer &rays, 
    72                         const int l, 
    73                         const int r, 
    74                         const int axis); 
    75  
     70  void _SortRays(SimpleRayContainer &rays, 
     71                                 const int l, 
     72                                 const int r, 
     73                                 const int depth, 
     74                                 float box[12]); 
     75         
    7676  struct Intersection 
    7777        { 
Note: See TracChangeset for help on using the changeset viewer.