Ignore:
Timestamp:
08/18/06 19:28:12 (18 years ago)
Author:
mattausch
Message:

added intel ray tracing

File:
1 edited

Legend:

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

    r1145 r1221  
    1313#include "Beam.h" 
    1414#include "GlRenderer.h" 
    15 #include "ViewCellBsp.h" 
     15#include "ArchModeler2MLRT.hxx" 
     16#include "Intersectable.h" 
     17 
    1618 
    1719namespace GtpVisibilityPreprocessor { 
     
    7678                                                  ) 
    7779{ 
    78   for (int i=0; i < rays.size(); i++) 
    79         CastRay(rays[i].mOrigin, rays[i].mDirection, vssRays); 
     80        AxisAlignedBox3 &box =  mViewSpaceBox ? *mViewSpaceBox : mKdTree->GetBox(); 
     81         
     82#if 1 
     83        for (int i=0; i < rays.size(); i++) 
     84        { 
     85                CastRay(rays[i].mOrigin, rays[i].mDirection, vssRays, box); 
     86        } 
     87#else 
     88        for (int i = 0; i < rays.size(); i += 16) 
     89        { 
     90                CastRay(rays[i].mOrigin, rays[i].mDirection, vssRays, box); 
     91        } 
     92 
     93#endif 
     94} 
     95 
     96 
     97void VssPreprocessor::CastRays16(SimpleRayContainer &rays,  
     98                                                                 VssRayContainer &vssRays, 
     99                                                                 const AxisAlignedBox3 &sbox) 
     100{ 
     101/* 
     102        mlrtaStoreRayAS16(const float* pforg, const float* pfdir, int j); 
     103 
     104 
     105        // input parameters 
     106        const RTVec3f& org = *reinterpret_cast<const RTVec3f*> (pforg); 
     107        const RTVec3f& rd  = *reinterpret_cast<const RTVec3f*> (pfdir); 
     108 
     109        int ri = j/4; 
     110        int ci = j%4; 
     111        *((float*)&ibp4.ray4X[ri].m_origin.t[0] + ci) = org[0]; 
     112        *((float*)&ibp4.ray4X[ri].m_origin.t[1] + ci) = org[1]; 
     113        *((float*)&ibp4.ray4X[ri].m_origin.t[2] + ci) = org[2]; 
     114 
     115        *((float*)&ibp4.ray4X[ri].m_direction.t[0] + ci) = rd[0]; 
     116        *((float*)&ibp4.ray4X[ri].m_direction.t[1] + ci) = rd[1]; 
     117        *((float*)&ibp4.ray4X[ri].m_direction.t[2] + ci) = rd[2]; 
     118 
     119        mlrtaTraverseGroupAS16(const float* bbmin, const float* bbmax, int* hit_triangles, float* dist);*/ 
     120} 
     121 
     122 
     123int VssPreprocessor::CastIntelDoubleRay( 
     124                                                                                const Vector3 &viewPoint, 
     125                                                                                const Vector3 &direction, 
     126                                                                                VssRayContainer &vssRays, 
     127                                                                                const AxisAlignedBox3 &box) 
     128{ 
     129        VssRay *vssRay  = NULL; 
     130        int hits = 0; 
     131 
     132        Vector3 pointA, pointB; 
     133         
     134        Intersectable *objectA =  
     135                CastIntelSingleRay(viewPoint, direction, pointA, box); 
     136         
     137        // cast ray into other direction 
     138        Intersectable *objectB =  
     139                CastIntelSingleRay(viewPoint, -direction, pointB, box); 
     140 
     141        const bool validSample = (objectA != objectB); 
     142         
     143        if (validSample)  
     144        {        
     145                if (objectA)  
     146                { 
     147                        vssRay = new VssRay(pointB, 
     148                                                                pointA, 
     149                                                                objectB, 
     150                                                                objectA, 
     151                                                                mPass); 
     152                        vssRays.push_back(vssRay); 
     153                        hits ++; 
     154                } 
     155 
     156                if (objectB)  
     157                { 
     158                        vssRay = new VssRay(pointA, 
     159                                                                pointB, 
     160                                                                objectA, 
     161                                                                objectB, 
     162                                                                mPass); 
     163                        vssRays.push_back(vssRay); 
     164                        hits ++; 
     165                } 
     166                //Debug << "intel ray: " << *vssRay << endl; 
     167        } 
     168//cout << "a"; 
     169        return hits; 
     170} 
     171 
     172 
     173Intersectable *VssPreprocessor::CastIntelSingleRay(const Vector3 &viewPoint, 
     174                                                                                                   const Vector3 &direction, 
     175                                                                                                   Vector3 &tPoint, 
     176                                                                                                   const AxisAlignedBox3 &box 
     177                                                                                                   ) 
     178{ 
     179        AxisAlignedBox3 sbox = box; 
     180        sbox.Enlarge(Vector3(-Limits::Small)); 
     181 
     182        if (!sbox.IsInside(viewPoint)) 
     183                return 0; 
     184         
     185        float pforg[3]; 
     186        float pfdir[3]; 
     187        double pfnorm[3]; 
     188 
     189        pforg[0] = viewPoint[0]; pforg[1] = viewPoint[1]; pforg[2] = viewPoint[2]; 
     190        pfdir[0] = direction[0]; pfdir[1] = direction[1]; pfdir[2] = direction[2]; 
     191 
     192        float dist = 0; 
     193        const int hittriangle = mlrtaIntersectAS(pforg, pfdir, pfnorm, dist); 
     194 
     195        if (hittriangle == -1) 
     196        { 
     197                static Ray ray; 
     198                SetupRay(ray, viewPoint, direction); 
     199 
     200                float tmin = 0, tmax; 
     201                if (box.ComputeMinMaxT(ray, &tmin, &tmax) && tmin < tmax) 
     202                { 
     203                        tPoint = ray.Extrap(tmax); 
     204                } 
     205 
     206                return NULL; 
     207        } 
     208        else 
     209        { 
     210                tPoint[0] = pforg[0] + pfdir[0] * dist; 
     211                tPoint[1] = pforg[1] + pfdir[1] * dist; 
     212                tPoint[2] = pforg[2] + pfdir[2] * dist; 
     213 
     214                return mFaceParents[hittriangle]; 
     215        } 
    80216} 
    81217 
    82218 
    83219int 
    84 VssPreprocessor::CastRay( 
    85                                                 Vector3 &viewPoint, 
    86                                                 Vector3 &direction, 
    87                                                  VssRayContainer &vssRays 
    88                                                  ) 
    89 { 
    90  
     220VssPreprocessor::CastInternalRay( 
     221                                                                 const Vector3 &viewPoint, 
     222                                                                 const Vector3 &direction, 
     223                                                                 VssRayContainer &vssRays, 
     224                                                                 const AxisAlignedBox3 &box  
     225                                                                 ) 
     226{ 
    91227    int hits = 0; 
    92228        static Ray ray; 
    93          
    94         AxisAlignedBox3 box =  mViewSpaceBox ? *mViewSpaceBox : mKdTree->GetBox(); 
     229 
    95230        AxisAlignedBox3 sbox = box; 
    96      
    97231        sbox.Enlarge(Vector3(-Limits::Small)); 
    98          
     232 
    99233        if (!sbox.IsInside(viewPoint)) 
    100234                return 0; 
     
    109243 
    110244        //float bsize = Magnitude(box.Size()); 
    111  
    112245        if (!mDetectEmptyViewSpace) 
    113246                ray.mFlags &= ~Ray::CULL_BACKFACES; 
     
    132265 
    133266        // matt: point A could be undefined? 
     267 
     268        // cast ray into opposite direction 
    134269        if (1 && mDetectEmptyViewSpace) { 
    135270                SetupRay(ray, pointA, -direction); 
     
    215350                        hits ++; 
    216351                } 
    217         } 
    218          
     352                //Debug << "internal ray: " << *vssRay << endl << endl; 
     353        } 
     354//cout << "b"; 
    219355        return hits; 
     356} 
     357 
     358 
     359int 
     360VssPreprocessor::CastRay( 
     361                                                 const Vector3 &viewPoint, 
     362                                                 const Vector3 &direction, 
     363                                                 VssRayContainer &vssRays, 
     364                                                 const AxisAlignedBox3 &box 
     365                                                 ) 
     366{ 
     367        switch (mRayCastMethod) 
     368        { 
     369        case INTEL_RAYCASTER: 
     370                return CastIntelDoubleRay(viewPoint, direction, vssRays, box); 
     371        case INTERNAL_RAYCASTER: 
     372        default: 
     373                return CastInternalRay(viewPoint, direction, vssRays, box); 
     374        } 
    220375} 
    221376 
     
    565720        box.SetMax(1, box.Min(1)); 
    566721 
    567   cout << "use view space box=" << mUseViewSpaceBox<<endl; 
     722  cout << "use view space box=" << mUseViewSpaceBox << endl; 
    568723 
    569724   
    570725  if (mUseViewSpaceBox) 
    571726  { 
     727        //mViewSpaceBox = ConstructViewSpaceBox(); 
     728 
    572729          if (!mEnlargeViewSpace) 
    573730          { 
     
    671828                        Vector3 direction = GetDirection(viewpoint, mViewSpaceBox); 
    672829 
    673                         sampleContributions = CastRay(viewpoint, direction, mVssRays); 
     830                        sampleContributions = CastRay(viewpoint, direction, mVssRays, vbox); 
    674831 
    675832                        if (sampleContributions) { 
     
    802959 
    803960        for (int i=0; i < rays.size(); i++) 
    804           CastRay(rays[i].mOrigin, rays[i].mDirection, vssRays); 
     961          CastRay(rays[i].mOrigin, rays[i].mDirection, vssRays, vbox); 
    805962 
    806963        vssTree->AddRays(vssRays); 
     
    842999  } 
    8431000 
    844   if (0) 
    845           Debug << vssTree->stat << endl; 
     1001  if (0)  Debug << vssTree->stat << endl; 
    8461002 
    8471003  if (0) 
    8481004  { 
    8491005        VssRayContainer viewCellRays; 
    850    
    851         // compute rays used for view cells construction 
     1006        // compute rays used for view cells construction 
    8521007        const int numRays = mViewCellsManager->GetVisualizationSamples(); 
    853  
    8541008        vssTree->CollectRays(viewCellRays, numRays); 
    8551009  } 
Note: See TracChangeset for help on using the changeset viewer.