Changeset 245 for trunk/VUT


Ignore:
Timestamp:
08/22/05 21:07:44 (19 years ago)
Author:
bittner
Message:

Merged sources with ViewCellBsp?

Location:
trunk/VUT/GtpVisibilityPreprocessor/src
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/GtpVisibilityPreprocessor/src/Intersectable.h

    r224 r245  
    2020  static void NewMail() { mailID++; } 
    2121  bool Mailed() const { return mailbox == mailID; } 
    22    
     22  int IncMail() { return ++mailbox - mailID; } 
     23 
    2324  virtual AxisAlignedBox3 GetBox() = 0; 
    2425   
  • trunk/VUT/GtpVisibilityPreprocessor/src/KdTree.cpp

    r241 r245  
    596596      entp = extp; 
    597597      mint = maxt; 
     598      if (ray.GetType() == Ray::LINE_SEGMENT && mint > 1.0f) 
     599        break; 
     600       
    598601      RayTraversalData &s  = tStack.top(); 
    599602      node = s.mNode; 
     
    709712   
    710713  return neighbors.size(); 
     714} 
     715 
     716// Find random neighbor which was not mailed 
     717KdNode * 
     718KdTree::GetRandomLeaf(const Plane3 &plane) 
     719{ 
     720  stack<KdNode *> nodeStack; 
     721   
     722  nodeStack.push(mRoot); 
     723   
     724  int mask = rand(); 
     725   
     726  while (!nodeStack.empty()) { 
     727    KdNode *node = nodeStack.top(); 
     728    nodeStack.pop(); 
     729    if (node->IsLeaf()) { 
     730      return node; 
     731    } else { 
     732      KdInterior *interior = (KdInterior *)node; 
     733      KdNode *next; 
     734        if (GetBox(interior->mBack).Side(plane) < 0) 
     735          next = interior->mFront; 
     736        else 
     737          if (GetBox(interior->mFront).Side(plane) < 0) 
     738            next = interior->mBack; 
     739          else { 
     740            // random decision 
     741            if (mask&1) 
     742              next = interior->mBack; 
     743            else 
     744              next = interior->mFront; 
     745            mask = mask>>1; 
     746          } 
     747        nodeStack.push(next); 
     748    } 
     749  } 
     750   
     751   
     752  return NULL; 
    711753} 
    712754 
  • trunk/VUT/GtpVisibilityPreprocessor/src/KdTree.h

    r191 r245  
    307307                     ); 
    308308 
     309   
     310  KdNode * 
     311  KdTree::GetRandomLeaf(const Plane3 &halfspace); 
     312   
    309313  int 
    310314  FindNeighbors(KdNode *n, 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Makefile

    r209 r245  
    11############################################################################# 
    22# Makefile for building: preprocessor 
    3 # Generated by qmake (1.07a) (Qt 3.3.2) on: Thu Aug 04 20:06:06 2005 
     3# Generated by qmake (1.07a) (Qt 3.3.2) on: Mon Aug 22 21:02:28 2005 
    44# Project:  preprocessor.pro 
    55# Template: app 
     
    6565                Triangle3.cpp \ 
    6666                Rectangle3.cpp \ 
    67                 Plane3.cpp 
     67                Plane3.cpp \ 
     68                Polygon3.cpp \ 
     69                ViewCell.cpp \ 
     70                ViewCellBsp.cpp 
    6871OBJECTS =       Preprocessor.obj \ 
    6972                SamplingPreprocessor.obj \ 
     
    9194                Triangle3.obj \ 
    9295                Rectangle3.obj \ 
    93                 Plane3.obj 
     96                Plane3.obj \ 
     97                Polygon3.obj \ 
     98                ViewCell.obj \ 
     99                ViewCellBsp.obj 
    94100FORMS =  
    95101UICDECLS =       
     
    179185        -$(DEL_FILE) Rectangle3.obj 
    180186        -$(DEL_FILE) Plane3.obj 
     187        -$(DEL_FILE) Polygon3.obj 
     188        -$(DEL_FILE) ViewCell.obj 
     189        -$(DEL_FILE) ViewCellBsp.obj 
    181190 
    182191 
     
    195204                X3dParser.h \ 
    196205                Preprocessor.h \ 
     206                ViewCell.h \ 
     207                Environment.h \ 
    197208                Containers.h \ 
    198209                AxisAlignedBox3.h \ 
     
    311322                Mesh.h \ 
    312323                KdTree.h \ 
     324                ViewCellBsp.h \ 
     325                ViewCell.h \ 
     326                Polygon3.h \ 
    313327                Containers.h \ 
    314328                AxisAlignedBox3.h \ 
     
    486500                Mesh.h \ 
    487501                Triangle3.h \ 
     502                SceneGraph.h \ 
    488503                Containers.h \ 
    489504                Pvs.h \ 
     
    511526Plane3.obj: Plane3.cpp  \ 
    512527                Plane3.h \ 
    513                 Vector3.h \ 
    514                 common.h \ 
     528                Matrix4x4.h \ 
     529                Vector3.h \ 
     530                common.h \ 
     531                 
     532 
     533Polygon3.obj: Polygon3.cpp  \ 
     534                Polygon3.h \ 
     535                Mesh.h \ 
     536                Containers.h \ 
     537                Intersectable.h \ 
     538                Plane3.h \ 
     539                Matrix4x4.h \ 
     540                AxisAlignedBox3.h \ 
     541                Material.h \ 
     542                Pvs.h \ 
     543                Rectangle3.h \ 
     544                Vector3.h \ 
     545                common.h \ 
     546                 
     547 
     548ViewCell.obj: ViewCell.cpp  \ 
     549                ViewCell.h \ 
     550                Mesh.h \ 
     551                MeshKdTree.h \ 
     552                Triangle3.h \ 
     553                Intersectable.h \ 
     554                Containers.h \ 
     555                AxisAlignedBox3.h \ 
     556                Pvs.h \ 
     557                Rectangle3.h \ 
     558                Matrix4x4.h \ 
     559                Vector3.h \ 
     560                Plane3.h \ 
     561                common.h \ 
     562                Material.h \ 
     563                Ray.h \ 
     564                 
     565 
     566ViewCellBsp.obj: ViewCellBsp.cpp  \ 
     567                Plane3.h \ 
     568                ViewCellBsp.h \ 
     569                Mesh.h \ 
     570                common.h \ 
     571                ViewCell.h \ 
     572                Environment.h \ 
     573                Polygon3.h \ 
     574                Ray.h \ 
     575                AxisAlignedBox3.h \ 
     576                Vector3.h \ 
     577                Containers.h \ 
     578                Intersectable.h \ 
     579                Matrix4x4.h \ 
     580                Material.h \ 
     581                Pvs.h \ 
     582                Rectangle3.h \ 
    515583                 
    516584 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Matrix4x4.cpp

    r209 r245  
    88 
    99Matrix4x4::Matrix4x4(const Vector3 &a, const Vector3 &b, const Vector3 &c) 
     10{ 
     11  // first index is column [x], the second is row [y] 
     12  x[0][0] = a.x; 
     13  x[1][0] = b.x; 
     14  x[2][0] = c.x; 
     15  x[3][0] = 0.0f; 
     16 
     17  x[0][1] = a.y; 
     18  x[1][1] = b.y; 
     19  x[2][1] = c.y; 
     20  x[3][1] = 0.0f; 
     21 
     22  x[0][2] = a.z; 
     23  x[1][2] = b.z; 
     24  x[2][2] = c.z; 
     25  x[3][2] = 0.0f; 
     26 
     27  x[0][3] = 0.0f; 
     28  x[1][3] = 0.0f; 
     29  x[2][3] = 0.0f; 
     30  x[3][3] = 1.0f; 
     31 
     32} 
     33 
     34void 
     35Matrix4x4::SetColumns(const Vector3 &a, const Vector3 &b, const Vector3 &c) 
    1036{ 
    1137  // first index is column [x], the second is row [y] 
     
    2248  x[0][2] = c.x; 
    2349  x[1][2] = c.y; 
    24   x[2][2] = c.z; 
    25   x[3][2] = 0.0f; 
    26  
    27   x[0][3] = 0.0f; 
    28   x[1][3] = 0.0f; 
    29   x[2][3] = 0.0f; 
    30   x[3][3] = 1.0f; 
    31 } 
    32  
    33 void 
    34 Matrix4x4::SetColumns(const Vector3 &a, const Vector3 &b, const Vector3 &c) 
    35 { 
    36   // first index is column [x], the second is row [y] 
    37   x[0][0] = a.x; 
    38   x[1][0] = b.x; 
    39   x[2][0] = c.x; 
    40   x[3][0] = 0.0f; 
    41  
    42   x[0][1] = a.y; 
    43   x[1][1] = b.y; 
    44   x[2][1] = c.y; 
    45   x[3][1] = 0.0f; 
    46  
    47   x[0][2] = a.z; 
    48   x[1][2] = b.z; 
    4950  x[2][2] = c.z; 
    5051  x[3][2] = 0.0f; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Mesh.cpp

    r209 r245  
    6868      nearestFace = faceIndex; 
    6969      hit++; 
     70      break; 
     71    case Ray::LINE_SEGMENT: 
     72      if (t <= 1.0f) { 
     73        ray.intersections.push_back(Ray::Intersection(t, instance, faceIndex)); 
     74        hit++; 
     75      } 
    7076      break; 
    7177    } 
  • trunk/VUT/GtpVisibilityPreprocessor/src/MeshKdTree.cpp

    r177 r245  
    369369      entp = extp; 
    370370      mint = maxt; 
     371 
     372      if (ray.GetType() == Ray::LINE_SEGMENT && mint > 1.0f) 
     373        break; 
     374 
    371375      RayTraversalData &s  = tStack.top(); 
    372376      node = s.mNode; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/MutualVisibility.cpp

    r223 r245  
    99#include "Mesh.h" 
    1010#include "Triangle3.h" 
     11#include "SceneGraph.h" 
    1112 
    1213void 
     
    2627{ 
    2728  Vector3 origin, direction; 
    28   GetRay(rayIndex, origin, direction); 
    29   return origin + direction*mSamples[rayIndex].mIntersections[depth].mT; 
     29  Ray ray; 
     30  GetRaySegment(rayIndex, ray); 
     31  if (depth >= mSamples[rayIndex].mIntersections.size()) { 
     32    cerr<<"depth of sample out of limits"<<endl; 
     33    exit(1); 
     34  } 
     35  return ray.Extrap(mSamples[rayIndex].mIntersections[depth].mT); 
     36} 
     37 
     38void 
     39RayShaft::GetRaySegment(const int i, Ray &ray) const 
     40{ 
     41  Vector3 origin, direction; 
     42  GetRay(i, origin, direction); 
     43  ray.Init(origin, direction, Ray::LINE_SEGMENT); 
     44  if ( mSamples[i].IsValid() ) { 
     45    origin = ray.Extrap(mSamples[i].mMinT); 
     46    direction = ray.Extrap(mSamples[i].mMaxT) - origin; 
     47    ray.Init(origin, direction, Ray::LINE_SEGMENT); 
     48  } 
    3049} 
    3150 
     
    98117 
    99118float 
    100 MutualVisibilitySampler::GetSpatialAngle(const RayShaft &sample, 
     119MutualVisibilitySampler::GetSpatialAngle(const RayShaft &shaft, 
    101120                                         const Vector3 &point 
    102121                                         ) 
    103122{ 
    104   const int sampleIndices[][2]={ 
    105     (0,1,2), 
    106     (0,2,3) 
     123  const int sampleIndices[]={ 
     124    0,1,2, 
     125    0,2,3 
    107126  }; 
    108127   
    109128  float sum = 0.0f; 
    110   int i; 
    111    
     129  int i, j=0; 
     130 
     131  if (!shaft.IsValid()) 
     132    return 2.0f*mSolidAngleThreshold; 
     133 
    112134  for (i=0; i < 2; i++) { 
    113     Triangle3 triangle(sample.GetIntersectionPoint(sampleIndices[i][0], 0), 
    114                        sample.GetIntersectionPoint(sampleIndices[i][1], 0), 
    115                        sample.GetIntersectionPoint(sampleIndices[i][2], 0)); 
     135    Triangle3 triangle(shaft.GetIntersectionPoint(sampleIndices[j++], 0), 
     136                       shaft.GetIntersectionPoint(sampleIndices[j++], 0), 
     137                       shaft.GetIntersectionPoint(sampleIndices[j++], 0)); 
    116138    sum += triangle.GetSpatialAngle(point); 
    117139  } 
     
    122144 
    123145void 
    124 MutualVisibilitySampler::ComputeError(RayShaft &sample) 
     146MutualVisibilitySampler::ComputeError(RayShaft &shaft) 
    125147{ 
    126148  // evaluate minimal error which can be achieved by more precise evaluation 
    127149  // if this is above the threshold do not proceed further 
    128150 
    129   float maxAngle = GetSpatialAngle(sample, 
    130                                    sample.mSource.GetCenter()); 
    131    
    132   for (int i=0; i < 3; i++) { 
    133     float angle = GetSpatialAngle(sample, 
    134                                   sample.mSource.mVertices[i]); 
     151  // check whether the samples pierce the same mesh 
     152  Intersectable::NewMail(); 
     153  int i, j; 
     154  for (i=0; i < 4; i++) { 
     155    RaySample *sample = &shaft.mSamples[i]; 
     156    for (j=0; j < sample->mIntersections.size(); j++) 
     157      sample->mIntersections[j].mObject->Mail(); 
     158  } 
     159 
     160  for (i=0; i < 4; i++) { 
     161    RaySample *sample = &shaft.mSamples[i]; 
     162    for (j=0; j < sample->mIntersections.size(); j++) { 
     163      if (sample->mIntersections[j].mObject->IncMail() == 4) { 
     164        cerr<<"T"; 
     165        shaft.mError = 0.0f; 
     166        return; 
     167      } 
     168    } 
     169  } 
     170     
     171   
     172  float maxAngle = GetSpatialAngle(shaft, 
     173                                   shaft.mTarget.GetCenter()); 
     174   
     175  for (i=0; i < 3; i++) { 
     176    float angle = GetSpatialAngle(shaft, 
     177                                  shaft.mTarget.mVertices[i]); 
    135178    if (angle > maxAngle) 
    136179      maxAngle = angle; 
    137180  } 
    138    
    139   sample.mError = maxAngle; 
    140 } 
    141  
     181 
     182  maxAngle = MAX_FLOAT; 
     183  shaft.mError = maxAngle; 
     184} 
     185 
     186 
     187void 
     188MutualVisibilitySampler::ConstructInitialSamples2( 
     189                                                  const AxisAlignedBox3 &source, 
     190                                                  const AxisAlignedBox3 &target, 
     191                                                  vector<RayShaft *> &samples 
     192                                                  ) 
     193{ 
     194  // get all rectangles potentially visible from the source box 
     195  int i; 
     196  int sourceMask = 0; 
     197  for (i=0; i < 8; i++) 
     198    sourceMask |= source.GetFaceVisibilityMask(target.GetVertex(i)); 
     199 
     200  // now for each visble source face find all visible target faces 
     201  for (i=0; i < 6; i++) { 
     202    Rectangle3 sourceFace = source.GetFace(i); 
     203    if ( sourceMask &(1<<i) ) { 
     204      int mask = target.GetFaceVisibilityMask(sourceFace); 
     205      // construct triangle samples for all visible rectangles 
     206      for (int j=0; j < 6; j++) 
     207        if (mask & (1<<j)) { 
     208          AddInitialSamples2(sourceFace, target.GetFace(j), samples); 
     209        } 
     210    } 
     211  } 
     212} 
     213 
     214void 
     215MutualVisibilitySampler::ConstructInitialSamples3( 
     216                                                  const AxisAlignedBox3 &source, 
     217                                                  const AxisAlignedBox3 &target, 
     218                                                  vector<RayShaft *> &samples 
     219                                                  ) 
     220{ 
     221  // get all rectangles potentially visible from the source box 
     222  int i; 
     223  int sourceMask = 0; 
     224  for (i=0; i < 8; i++) 
     225    sourceMask |= source.GetFaceVisibilityMask(target.GetVertex(i)); 
     226 
     227  // now for each visble source face find all visible target faces 
     228  int face; 
     229  for (face=0; face < 6; face++) { 
     230    if ( sourceMask & (1<<face) ) { 
     231      Rectangle3 sourceRect = source.GetFace(face); 
     232 
     233      Vector3 targetCenter = target.Center(); 
     234       
     235      Vector3 normal = sourceRect.GetNormal(); 
     236       
     237      Plane3 sourcePlane(normal, sourceRect.GetVertex(0)); 
     238       
     239      Plane3 targetPlane(normal, target.GetVertex(0)); 
     240 
     241      int i; 
     242      for (i=1; i < 8; i++) { 
     243        Vector3 v = target.GetVertex(i); 
     244        if (targetPlane.Distance(v) < 0) 
     245          targetPlane = Plane3(normal, v); 
     246      } 
     247   
     248      Vector3 xBasis = Normalize(sourceRect.GetVertex(1) - sourceRect.GetVertex(0)); 
     249      Vector3 yBasis = Normalize(sourceRect.GetVertex(3) - sourceRect.GetVertex(0)); 
     250 
     251      // cast rays between the centers of the boxes 
     252      Vector3 targetRCenter = targetPlane.FindIntersection(sourceRect.GetCenter(), 
     253                                                           targetCenter); 
     254       
     255      Rectangle3 targetRect; 
     256       
     257      float targetDist[4]; 
     258      targetDist[0] = targetDist[1] = targetDist[2] = targetDist[3] = 0.0f; 
     259       
     260      // cast rays between corresponding vertices of the boxes 
     261      int j; 
     262      int intersections=0; 
     263      for (i=0; i < 4; i++) 
     264        for (j=0; j < 8; j++) { 
     265          Vector3 v; 
     266          Vector3 diff; 
     267          bool coplanar; 
     268          float dist; 
     269           
     270          v = targetPlane.FindIntersection(sourceRect.GetVertex(i), 
     271                                           target.GetVertex(j), 
     272                                           NULL, 
     273                                           &coplanar); 
     274          if (!coplanar) { 
     275            // evaluate target and  
     276            diff = targetRCenter - v; 
     277            dist = DotProd(diff, xBasis); 
     278            if (dist < targetDist[0]) 
     279              targetDist[0] = dist; 
     280            if (dist > targetDist[1]) 
     281              targetDist[1] = dist; 
     282 
     283            dist = DotProd(diff, yBasis); 
     284 
     285            if (dist < targetDist[2]) 
     286              targetDist[2] = dist; 
     287            if (dist > targetDist[3]) 
     288              targetDist[3] = dist; 
     289            intersections++; 
     290          } 
     291        } 
     292       
     293      if (intersections>=4) { 
     294        targetRect.mVertices[0] = targetRCenter + targetDist[0]*xBasis + targetDist[2]*yBasis; 
     295        targetRect.mVertices[1] = targetRCenter + targetDist[1]*xBasis + targetDist[2]*yBasis; 
     296        targetRect.mVertices[2] = targetRCenter + targetDist[1]*xBasis + targetDist[3]*yBasis; 
     297        targetRect.mVertices[3] = targetRCenter + targetDist[0]*xBasis + targetDist[3]*yBasis; 
     298         
     299        //      cout<<sourceRect<<targetRect<<endl; 
     300        AddInitialSamples(sourceRect, targetRect, samples); 
     301      } 
     302    } 
     303  } 
     304} 
    142305 
    143306void 
     
    173336    xBasis.Normalize(); 
    174337  else { 
    175     xBasis = CrossProd(Vector3(0,0,1), normal); 
     338    xBasis = Normalize(CrossProd(Vector3(0,0,1), normal)); 
    176339  } 
    177340 
     
    188351  Rectangle3 targetRect; 
    189352 
    190    
     353 
     354  if (0) { 
    191355  float scale = Magnitude(source.Size())*0.7f; 
    192356  sourceRect.mVertices[0] = sourceRCenter - scale*xBasis - scale*yBasis; 
     
    200364  targetRect.mVertices[2] = targetRCenter + scale*xBasis + scale*yBasis; 
    201365  targetRect.mVertices[3] = targetRCenter - scale*xBasis + scale*yBasis; 
    202  
     366  } 
     367 
     368 
     369  float sourceDist[4]; 
     370  float targetDist[4]; 
     371  sourceDist[0] = sourceDist[1] = sourceDist[2] = sourceDist[3] = 0.0f; 
     372  targetDist[0] = targetDist[1] = targetDist[2] = targetDist[3] = 0.0f; 
     373 
     374  // cast rays between corresponding vertices of the boxes 
     375  int j; 
     376  for (i=0; i < 8; i++) 
     377    for (j=0; j < 8; j++) { 
     378      Vector3 v; 
     379      Vector3 diff; 
     380      bool coplanar; 
     381      float dist; 
     382      v = sourcePlane.FindIntersection(source.GetVertex(i), 
     383                                       target.GetVertex(j), 
     384                                       NULL, 
     385                                       &coplanar); 
     386      if (!coplanar) { 
     387        // evaluate source and  
     388        diff = sourceRCenter - v; 
     389        dist = DotProd(diff, xBasis); 
     390        if (dist < sourceDist[0]) 
     391          sourceDist[0] = dist; 
     392        if (dist > sourceDist[1]) 
     393          sourceDist[1] = dist; 
     394 
     395        dist = DotProd(diff, yBasis); 
     396        if (dist < sourceDist[2]) 
     397          sourceDist[2] = dist; 
     398        if (dist > sourceDist[3]) 
     399          sourceDist[3] = dist; 
     400      } 
     401       
     402      v = targetPlane.FindIntersection(source.GetVertex(i), 
     403                                       target.GetVertex(j), 
     404                                       NULL, 
     405                                       &coplanar); 
     406      if (!coplanar) { 
     407        // evaluate target and  
     408        diff = targetRCenter - v; 
     409        dist = DotProd(diff, xBasis); 
     410        if (dist < targetDist[0]) 
     411          targetDist[0] = dist; 
     412        if (dist > targetDist[1]) 
     413          targetDist[1] = dist; 
     414        dist = DotProd(diff, yBasis); 
     415        if (dist < targetDist[2]) 
     416          targetDist[2] = dist; 
     417        if (dist > targetDist[3]) 
     418          targetDist[3] = dist; 
     419      } 
     420    } 
     421 
     422  sourceRect.mVertices[0] = sourceRCenter + sourceDist[0]*xBasis + sourceDist[2]*yBasis; 
     423  sourceRect.mVertices[1] = sourceRCenter + sourceDist[1]*xBasis + sourceDist[2]*yBasis; 
     424  sourceRect.mVertices[2] = sourceRCenter + sourceDist[1]*xBasis + sourceDist[3]*yBasis; 
     425  sourceRect.mVertices[3] = sourceRCenter + sourceDist[0]*xBasis + sourceDist[3]*yBasis; 
     426 
     427  targetRect.mVertices[0] = targetRCenter + targetDist[0]*xBasis + targetDist[2]*yBasis; 
     428  targetRect.mVertices[1] = targetRCenter + targetDist[1]*xBasis + targetDist[2]*yBasis; 
     429  targetRect.mVertices[2] = targetRCenter + targetDist[1]*xBasis + targetDist[3]*yBasis; 
     430  targetRect.mVertices[3] = targetRCenter + targetDist[0]*xBasis + targetDist[3]*yBasis; 
     431 
     432 
     433  cout<<sourceRect<<targetRect<<endl; 
    203434  AddInitialSamples(sourceRect, targetRect, samples); 
    204  
    205   //    Plane3 bottomPlane(xBasis, source.Center()); 
    206   //    Plane3 sidePlane(yBasis, source.Center()); 
    207    
    208   //    // cast rays between corresponding vertices of the boxes 
    209   //    for (i=0; i < 8; i++) { 
    210   //      Vector3 v; 
    211   //      bool coplanar; 
    212   //      v = sourcePlane.FindIntersection(source.GetVertex(i), 
    213   //                                 target.GetVertex(i), 
    214   //                                 NULL, 
    215   //                                 &coplanar); 
    216   //      if (!coplanar) { 
    217   //        // evaluate source and  
    218    
    219   //      } 
    220   //    } 
    221    
    222   //  AddInitialSamples(sourceRectangle, targetRectangle, samples); 
    223435} 
    224436 
     
    236448} 
    237449 
    238  
    239 void 
    240 MutualVisibilitySampler::ExportSamples(vector<RayShaft *> &samples) 
     450void 
     451MutualVisibilitySampler::AddInitialSamples2( 
     452                                            const Rectangle3 &sourceRect, 
     453                                            const Rectangle3 &targetRect, 
     454                                            vector<RayShaft *> &samples 
     455                                            ) 
     456{ 
     457  // align the rectangles properly 
     458  Rectangle3 sRect, tRect; 
     459  if (DotProd(sourceRect.GetNormal(), targetRect.GetNormal()) < -0.99f) { 
     460    int i; 
     461    for (i=0; i < 4; i++) { 
     462      tRect.mVertices[i] = targetRect.mVertices[( 7 - i )%4]; 
     463    } 
     464     
     465    RayShaft *sample = new RayShaft(sourceRect,  
     466                                    tRect); 
     467    samples.push_back(sample); 
     468  } 
     469   
     470  return; 
     471   
     472  float minDist = MAX_FLOAT; 
     473  int startI; 
     474  int startJ; 
     475  int i, j; 
     476 
     477   
     478  for (i=0; i < 4; i++) { 
     479    for (j=0; j < 4; j++) { 
     480      float dist = Distance(sourceRect.mVertices[i], targetRect.mVertices[j]); 
     481      if (dist < minDist) { 
     482        minDist = dist; 
     483        startI = i; 
     484        startJ = j; 
     485      } 
     486    } 
     487  } 
     488  for (i=0; i < 4; i++) { 
     489    sRect.mVertices[i] = sourceRect.mVertices[(startI + i )%4]; 
     490    tRect.mVertices[i] = targetRect.mVertices[(4 + startJ - i )%4]; 
     491  } 
     492   
     493  RayShaft *sample = new RayShaft(sRect,  
     494                                  tRect); 
     495  samples.push_back(sample); 
     496} 
     497 
     498 
     499void 
     500MutualVisibilitySampler::ExportShafts(vector<RayShaft *> &shafts, 
     501                                      const bool singleFile) 
    241502{ 
    242503  static int id = 0; 
     
    244505  if (id > 20) 
    245506    return; 
    246                              
    247   for (int i=0; i < samples.size(); i++) { 
    248     sprintf(filename, "samples%04d-%02d.x3d", id++, i); 
    249     Exporter *exporter = Exporter::GetExporter(filename); 
    250  
     507   
     508  Exporter *exporter = NULL; 
     509  for (int i=0; i < shafts.size(); i++) { 
     510    if (!exporter) { 
     511      if (singleFile) 
     512        sprintf(filename, "shafts-single-%04d.x3d", id++); 
     513      else 
     514        sprintf(filename, "shafts%04d-%02d.x3d", id++, i); 
     515      exporter = Exporter::GetExporter(filename); 
     516    } 
     517     
    251518    exporter->SetWireframe(); 
     519    //    exporter->ExportScene(mSceneGraph->mRoot); 
     520 
    252521    exporter->ExportBox(mSource); 
    253522    exporter->ExportBox(mTarget); 
     
    256525 
    257526 
    258     RayShaft *sample = samples[i]; 
     527    RayShaft *shaft = shafts[i]; 
    259528    Mesh *mesh = new Mesh; 
    260     mesh->AddRectangle(sample->mSource); 
    261     mesh->AddRectangle(sample->mTarget); 
     529    mesh->AddRectangle(shaft->mSource); 
     530    mesh->AddRectangle(shaft->mTarget); 
    262531    vector<Ray> rays; 
    263532    for (int j=0; j < 4; j++) { 
    264       Vector3 origin, direction; 
    265       sample->GetRay(j, origin, direction); 
    266       Ray ray(origin, direction, Ray::LINE_SEGMENT); 
     533      Ray ray; 
     534      shaft->GetRaySegment(j, ray); 
    267535      rays.push_back(ray); 
    268536    } 
     
    273541    exporter->ExportIntersectable(&mi); 
    274542    exporter->ExportRays(rays, -1.0f, m.mDiffuseColor); 
     543    if (!singleFile) { 
     544      delete exporter; 
     545      exporter = NULL; 
     546    } 
     547  } 
     548  if (exporter) 
    275549    delete exporter; 
    276   } 
     550   
    277551} 
    278552 
     
    283557  int i; 
    284558 
    285   for (i=0; i < 4; i++) { 
    286     Vector3 origin, direction; 
    287     shaft.GetRay(i, origin, direction); 
    288     // determine intersections with the boxes 
    289     ray.Init(origin, direction, Ray::LINE_SEGMENT); 
    290     float stmin, stmax, ttmin, ttmax; 
    291     if ( mSource.GetMinMaxT(ray, &stmin, &stmax) && mTarget.GetMinMaxT(ray, &ttmin, &ttmax) ) { 
    292       shaft.mSamples[i].mMinT = stmax; 
    293       shaft.mSamples[i].mMaxT = ttmin; 
    294       origin = ray.Extrap(stmax); 
    295       direction = ray.Extrap(ttmin) - origin; 
    296       // reinit the ray 
     559  for (i=0; i < 4; i++) 
     560    if (!shaft.mSamples[i].IsProcessed()) { 
     561      Vector3 origin, direction; 
     562      shaft.GetRay(i, origin, direction); 
     563      // determine intersections with the boxes 
    297564      ray.Init(origin, direction, Ray::LINE_SEGMENT); 
    298       if (!mKdTree->CastRay(ray)) 
    299         return VISIBLE; 
    300     } else { 
    301       shaft.mSamples[i].mMaxT = -1.0; 
    302     } 
    303   } 
     565      float stmin, stmax = 0.0f, ttmin=1.0f, ttmax; 
     566      bool valid = true; 
     567       
     568      if (mUseBoxes) { 
     569        if (mSource.GetMinMaxT(ray, &stmin, &stmax) && 
     570            mTarget.GetMinMaxT(ray, &ttmin, &ttmax)) { 
     571          shaft.mSamples[i].mMinT = stmax; 
     572          shaft.mSamples[i].mMaxT = ttmin; 
     573          origin = ray.Extrap(stmax); 
     574          direction = ray.Extrap(ttmin) - origin; 
     575          // reinit the ray 
     576          ray.Init(origin, direction, Ray::LINE_SEGMENT); 
     577        } else 
     578          valid = false; 
     579      } else { 
     580        shaft.mSamples[i].mMinT = 0.0f; 
     581        shaft.mSamples[i].mMaxT = 1.0f; 
     582      } 
     583      if (valid) { 
     584        if (!mKdTree->CastRay(ray)) { 
     585          cerr<<"V"<<endl; 
     586          return VISIBLE; 
     587        } 
     588        shaft.mSamples[i].mIntersections = ray.intersections; 
     589        cerr<<"I"; 
     590      } else { 
     591        cerr<<"X"; 
     592        shaft.mSamples[i].SetInvalid(); 
     593      } 
     594    } 
    304595  return INVISIBLE; 
    305596} 
     
    308599MutualVisibilitySampler::ComputeVisibility() 
    309600{ 
     601  int result = INVISIBLE; 
    310602 
    311603  vector<RayShaft *> shafts; 
    312   ConstructInitialSamples(mSource, mTarget, shafts); 
    313   ExportSamples(shafts); 
     604  ConstructInitialSamples3(mSource, mTarget, shafts); 
     605 
     606  if (1) 
     607    ExportShafts(shafts, false); 
    314608 
    315609  stack<RayShaft *> shaftStack; 
    316610   
    317    
    318    
     611  for (int i=0; i < shafts.size(); i++) 
     612    shaftStack.push(shafts[i]); 
     613 
     614  shafts.clear(); 
    319615  Ray ray; 
    320   // now process the shafts as long as we have something to do 
     616   
     617// now process the shafts as long as we have something to do 
    321618  while (!shaftStack.empty()) { 
    322619    RayShaft *shaft = shaftStack.top(); 
     
    326623//      int triangleSplitEdge = SetupExtremalRay(sample, source, ray); 
    327624     
    328     if (CastRays(*shaft) == VISIBLE) 
    329       return VISIBLE; 
    330      
    331     //      // generate 2 new samples 
    332     //      RayShaft newSamples[2]; 
    333     //      sample.Split(triangleSplitEdge, ray, newSamples[0], newSamples[1]); 
    334     //      for (i=0; i < 2; i++) { 
    335     //        newSamples[i].ComputeError(); 
    336     //        if (newSamples[i].mError > solidAngleThreshold) { 
    337     //          sampleStack.push(newSamples[i]); 
    338     //        } 
    339     //      } 
    340     //    } 
    341   } 
    342  
    343   for (int i=0; i < shafts.size(); i++) 
     625    if (CastRays(*shaft) == VISIBLE) { 
     626      result = VISIBLE; 
     627      break; 
     628    } 
     629 
     630    // compute error .... 
     631    ComputeError(*shaft); 
     632    cout<<shaft->mDepth<<"|"; 
     633    if (shaft->IsValid()) 
     634      shafts.push_back(shaft); 
     635 
     636    if (shaft->mDepth < 10 && 
     637        shaft->mError > mSolidAngleThreshold) { 
     638       
     639      // generate 2 new samples 
     640      RayShaft *newSamples[2]; 
     641      newSamples[0] = new RayShaft; 
     642      newSamples[1] = new RayShaft; 
     643       
     644      // chose what to split 
     645      bool splitSource = shaft->mSource.GetArea() > shaft->mTarget.GetArea(); 
     646      int axis; 
     647      if (splitSource) { 
     648        axis = shaft->mSource.DominantAxis(); 
     649      } else { 
     650        axis = shaft->mTarget.DominantAxis(); 
     651      } 
     652       
     653      PerformSplit(*shaft, splitSource, axis, *newSamples[0], *newSamples[1]); 
     654      //      delete shaft; 
     655      shaftStack.push(newSamples[0]); 
     656      shaftStack.push(newSamples[1]); 
     657    } else { 
     658      // store a terminal shaft 
     659    } 
     660 
     661  } 
     662   
     663  while (!shaftStack.empty()) { 
     664    RayShaft *shaft = shaftStack.top(); 
     665    shaftStack.pop(); 
     666    delete shaft; 
     667  } 
     668 
     669  if (0) 
     670    ExportShafts(shafts, true); 
     671 
     672  for (i=0; i < shafts.size(); i++) { 
    344673    delete shafts[i]; 
    345   return INVISIBLE; 
    346 } 
    347  
    348 MutualVisibilitySampler::MutualVisibilitySampler(KdTree *kdTree, 
     674  } 
     675 
     676  return result; 
     677} 
     678 
     679MutualVisibilitySampler::MutualVisibilitySampler(SceneGraph *sceneGraph, 
     680                                                 KdTree *kdTree, 
    349681                                                 AxisAlignedBox3 &source, 
    350682                                                 AxisAlignedBox3 &target, 
    351683                                                 const float solidAngleThreshold) 
    352684{ 
     685  mSceneGraph = sceneGraph; 
    353686  mKdTree = kdTree; 
    354687  mSource = source; 
    355688  mTarget = target; 
     689  mUseBoxes = true; 
    356690  mSolidAngleThreshold = solidAngleThreshold; 
    357691} 
     
    359693 
    360694int 
    361 ComputeBoxVisibility(KdTree *kdTree, 
     695ComputeBoxVisibility(SceneGraph *sceneGraph, 
     696                     KdTree *kdTree, 
    362697                     AxisAlignedBox3 &source, 
    363698                     AxisAlignedBox3 &target, 
    364699                     const float solidAngleThreshold) 
    365700{ 
    366   MutualVisibilitySampler sampler(kdTree, source, target, solidAngleThreshold); 
     701  MutualVisibilitySampler sampler(sceneGraph, kdTree, source, target, solidAngleThreshold); 
    367702 
    368703   
  • trunk/VUT/GtpVisibilityPreprocessor/src/MutualVisibility.h

    r223 r245  
    77class Intersectable; 
    88class AxisAlignedBox3; 
     9class SceneGraph; 
    910 
    10 struct SimpleRay { 
    11   Vector3 mOrigin; 
    12   Vector3 mDirection; 
    13 }; 
    1411 
    1512struct RaySample { 
     
    1714  float mMinT; 
    1815  float mMaxT; 
     16 
     17  RaySample():mMinT(-1.0f), mMaxT(-1.0f) {} 
    1918  /// intersections of the sample with the scene 
    2019  vector<Ray::Intersection> mIntersections; 
    21   bool IsValid() const { return mMaxT > 0.0; } 
     20  void SetInvalid() { 
     21    mMinT = 0.0f; 
     22    mMaxT = -1.0f; 
     23  } 
     24  bool IsValid() const { return mMaxT > 0.0f; } 
     25  bool IsProcessed() const { return mMinT != mMaxT; } 
    2226}; 
    2327 
     
    3741  void ComputeError(); 
    3842   
    39   RayShaft () {} 
     43  RayShaft() {} 
    4044   
    4145  RayShaft ( 
     
    4549    Init(source, target); 
    4650  } 
    47    
     51 
     52  bool IsValid() const { return 
     53                           mSamples[0].IsValid() && 
     54                           mSamples[1].IsValid() && 
     55                           mSamples[2].IsValid() && 
     56                           mSamples[3].IsValid(); 
     57  } 
     58 
    4859  // initial triangle sample 
    4960  void Init( 
     
    5869              Vector3 &origin, 
    5970              Vector3 &direction) const; 
     71 
     72  void 
     73  GetRaySegment(const int i, Ray &ray) const; 
     74 
    6075}; 
    6176 
     
    6580class MutualVisibilitySampler { 
    6681public: 
     82  SceneGraph *mSceneGraph; 
    6783  KdTree *mKdTree; 
    6884  AxisAlignedBox3 mSource; 
    6985  AxisAlignedBox3 mTarget; 
    7086  float mSolidAngleThreshold; 
     87  bool mUseBoxes; 
    7188 
    72  
    73   MutualVisibilitySampler(KdTree *kdTree, 
     89  MutualVisibilitySampler(SceneGraph *sceneGraph, 
     90                          KdTree *kdTree, 
    7491                          AxisAlignedBox3 &source, 
    7592                          AxisAlignedBox3 &target, 
     
    86103 
    87104  void 
     105  ConstructInitialSamples2( 
     106                          const AxisAlignedBox3 &source, 
     107                          const AxisAlignedBox3 &target, 
     108                          vector<RayShaft *> &samples 
     109                          ); 
     110 
     111  void 
     112  ConstructInitialSamples3( 
     113                           const AxisAlignedBox3 &source, 
     114                           const AxisAlignedBox3 &target, 
     115                           vector<RayShaft *> &samples 
     116                           ); 
     117 
     118  void 
    88119  AddInitialSamples( 
    89120                    const Rectangle3 &sourceRect, 
     
    91122                    vector<RayShaft *> &samples 
    92123                    ); 
     124 
     125  void 
     126  AddInitialSamples2( 
     127                     const Rectangle3 &sourceRect, 
     128                     const Rectangle3 &targetRect, 
     129                     vector<RayShaft *> &samples 
     130                     ); 
    93131 
    94132  // the split sample method contains a methodology to create new samples 
     
    126164   
    127165  void 
    128   ExportSamples(vector<RayShaft *> &samples); 
     166  ExportShafts(vector<RayShaft *> &samples, const bool singleFile); 
    129167 
    130168 
     
    132170   
    133171int 
    134 ComputeBoxVisibility(KdTree *kdTree, 
     172ComputeBoxVisibility(SceneGraph *sceneGraph, 
     173                     KdTree *kdTree, 
    135174                     AxisAlignedBox3 &source, 
    136175                     AxisAlignedBox3 &target, 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Plane3.h

    r241 r245  
    4343                           ) const  
    4444  { 
    45           const Vector3 v = b - a; // line from A to B 
    46           float dv = DotProd(mNormal, v); 
    47           
    48           if (signum(dv) == 0) 
    49           { 
    50                   if (coplanar)  
    51                           (*coplanar) = true;    
    52  
    53                   return a; 
    54           } 
    55            
    56           float u = - Distance(a) / dv; // TODO: could be done more efficiently 
    57           //Debug << "t: " << u << ", b - a: " << v << ", norm: " << mNormal << ", dist(a): " << - Distance(a) << ", dv: " << dv << endl; 
    58           if (coplanar)  
    59                   (*coplanar) = false; 
     45    const Vector3 v = b - a; // line from A to B 
     46    float dv = DotProd(mNormal, v); 
     47     
     48    if (signum(dv) == 0) 
     49      { 
     50        if (coplanar)  
     51          (*coplanar) = true;    
    6052         
    61           if (t)  
    62                   (*t) = u; 
    63                    
    64           return a + u * b - u * a; // NOTE: gives better precision than calclulating a + u * v 
    65           //return a + (u * v); 
     53        return a; 
     54      } 
     55     
     56    float u = - Distance(a) / dv; // TODO: could be done more efficiently 
     57    //Debug << "t: " << u << ", b - a: " << v << ", norm: " << mNormal << ", dist(a): " << - Distance(a) << ", dv: " << dv << endl; 
     58    if (coplanar)  
     59      (*coplanar) = false; 
     60     
     61    if (t)  
     62      (*t) = u; 
     63     
     64    return a + u * b - u * a; // NOTE: gives better precision than calclulating a + u * v 
     65    //return a + (u * v); 
    6666  } 
    67  
     67   
    6868  friend bool 
    6969  PlaneIntersection(const Plane3 &a, const Plane3 &b, const Plane3 &c, Vector3 &result); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Ray.h

    r209 r245  
    8686   
    8787  // Inititalize the ray again when already constructed 
    88   void Init(const Vector3 &wherefrom, const Vector3 &whichdir, 
     88  void Init(const Vector3 &wherefrom, 
     89            const Vector3 &whichdir, 
    8990            const int _type,  
    9091            bool dirNormalized = false) { 
    9192    loc = wherefrom; 
    92     dir = (dirNormalized) ? whichdir: Normalize(whichdir) ; 
     93    dir = (dirNormalized || _type == LINE_SEGMENT) ? whichdir: Normalize(whichdir) ; 
    9394    mType = _type; 
    9495    depth = 0; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Rectangle3.h

    r223 r245  
    11#ifndef __RECTANGLE3_H 
    22#define __RECTANGLE3_H 
    3  
     3#include <iostream> 
     4using namespace std; 
    45#include "Vector3.h" 
    56 
     
    1112  Vector3 mVertices[4]; 
    1213 
     14  Vector3 GetVertex(const int i) const { return mVertices[i]; } 
    1315  Rectangle3() {} 
    1416   
     
    2325  } 
    2426   
    25   Vector3 GetNormal() { 
     27  Vector3 GetNormal() const { 
    2628    return Normalize(CrossProd(mVertices[0]-mVertices[1], 
    2729                               mVertices[2]-mVertices[1] 
     
    2931  } 
    3032   
    31   Vector3 GetCenter() { 
     33  Vector3 GetCenter() const { 
    3234    return (mVertices[0] + mVertices[1] + mVertices[2] + mVertices[3])/4.0f; 
    3335  } 
    3436 
    35  
     37  int DominantAxis() const { 
     38    if (SqrMagnitude(mVertices[0] - mVertices[1]) >  SqrMagnitude(mVertices[0] - mVertices[3])) 
     39      return 0; 
     40    else 
     41      return 1; 
     42  } 
     43       
     44  float GetArea() const { 
     45    Vector3 v = CrossProd(mVertices[3], mVertices[0]); 
     46     
     47    for (int i=0; i < 3; i++) 
     48      v += CrossProd(mVertices[i], mVertices[i+1]); 
     49     
     50    return 0.5f*abs(DotProd(GetNormal(), v)); 
     51  } 
     52   
    3653  void 
    3754  Split(const int axis, 
     
    3956        Rectangle3 &r2 
    4057        ) const; 
    41    
     58 
     59  friend ostream& operator<< (ostream &s, const Rectangle3 &r) { 
     60    return s<<"Rectangle3:"<<r.mVertices[0]<<r.mVertices[1]<<r.mVertices[2]<<r.mVertices[3]; 
     61  } 
     62 
    4263}; 
    4364 
  • trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp

    r242 r245  
    1212  environment->GetIntValue("Sampling.totalSamples", mTotalSamples); 
    1313  mKdPvsDepth = 100; 
     14  mStats.open("stats.log"); 
    1415 
    1516} 
     
    6869} 
    6970 
     71//  void 
     72//  SamplingPreprocessor::AvsGenerateRandomRay(Ray &ray) 
     73//  { 
     74//    int objId = RandomValue(0, mObjects.size()); 
     75//    Intersectable *object = objects[objId]; 
     76//    object->GetRandomSurfacePoint(point, normal); 
     77//    direction = UniformRandomVector(normal); 
     78//    SetupRay(ray, point, direction); 
     79//  } 
     80 
     81//  void 
     82//  SamplingPreprocessor::AvsHandleRay(Ray &ray) 
     83//  { 
     84//    int sampleContributions = 0; 
     85 
     86//    mKdTree->CastRay(ray); 
     87   
     88//    if (ray.leaves.size()) { 
     89//      sampleContributions += AddNodeSamples(object, ray, pass); 
     90     
     91//      if (ray.intersections.size()) { 
     92//        sampleContributions += AddNodeSamples(ray.intersections[0].mObject, ray, pass); 
     93//      } 
     94//    } 
     95//  } 
     96 
     97//  void 
     98//  SamplingPreprocessor::AvsBorderSampling(Ray &ray) 
     99//  { 
     100   
     101 
     102//  } 
     103 
     104//  void 
     105//  SamplingPreprocessor::AvsPass() 
     106//  { 
     107//    Ray ray; 
     108//    while (1) { 
     109//      AvsGenerateRay(ray); 
     110//      HandleRay(ray); 
     111//      while ( !mRayQueue.empty() ) { 
     112//        Ray ray = mRayQueue.pop(); 
     113//        mRayQueue.pop(); 
     114//        AdaptiveBorderSampling(ray); 
     115//      } 
     116//    } 
     117   
     118   
     119 
     120//  } 
     121 
     122 
     123 
    70124bool 
    71125SamplingPreprocessor::ComputeVisibility() 
    72126{ 
    73  
     127   
    74128  // pickup an object 
    75129  ObjectContainer objects; 
     
    100154        KdNode *nodeToSample = NULL; 
    101155        Intersectable *object = objects[i]; 
    102                    
     156         
    103157        int pvsSize = object->mKdPvs.GetSize(); 
    104        
     158 
     159 
     160 
    105161        if (0 && pvsSize) { 
    106162          // mail all nodes from the pvs 
     
    125181          } 
    126182        } 
    127  
    128          
    129         if (pvsSize && pass == 50 ) { 
     183         
     184        if (0 && pvsSize && pass == 1000 ) { 
    130185          // mail all nodes from the pvs 
    131186          Intersectable::NewMail(); 
     
    144199            AxisAlignedBox3 box = object->GetBox(); 
    145200            for (int j=0; j < invisibleNeighbors.size(); j++) { 
    146               int visibility = ComputeBoxVisibility(mKdTree, 
     201              int visibility = ComputeBoxVisibility(mSceneGraph, 
     202                                                    mKdTree, 
    147203                                                    box, 
    148204                                                    mKdTree->GetBox(invisibleNeighbors[j]), 
    149                                                     1.0f); 
    150              
     205                                                    1e-6f); 
     206              //              exit(0); 
    151207            } 
    152208            // now rank all the neighbors according to probability that a new 
     
    155211        } 
    156212 
    157        
     213        object->GetRandomSurfacePoint(point, normal); 
     214        nodeToSample = mKdTree->GetRandomLeaf(Plane3(normal, point)); 
     215 
    158216        for (int k=0; k < mSamplesPerPass; k++) { 
    159           object->GetRandomSurfacePoint(point, normal); 
    160          
     217           
    161218          if (nodeToSample) { 
    162219            int maxTries = 5; 
    163            
     220             
    164221            for (int tries = 0; tries < maxTries; tries++) { 
    165222              direction = mKdTree->GetBox(nodeToSample).GetRandomPoint() - point; 
    166              
     223               
    167224              if (DotProd(direction, normal) > Limits::Small) 
    168225                break; 
    169226            } 
    170            
     227             
    171228            if (tries == maxTries) 
    172229              direction = UniformRandomVector(normal); 
    173           }  
    174           else 
     230          } 
     231          else { 
    175232            direction = UniformRandomVector(normal); 
    176          
     233          } 
     234           
    177235          // construct a ray 
    178236          SetupRay(ray, point, direction); 
    179237          mKdTree->CastRay(ray); 
    180  
    181           if (i < pvsOut) 
     238           
     239          if ( i < pvsOut ) 
    182240            rays[i].push_back(ray); 
    183          
     241           
    184242          int sampleContributions = 0; 
    185          
    186                    
     243           
    187244          if (ray.leaves.size()) { 
    188245            sampleContributions += AddNodeSamples(object, ray, pass); 
    189            
     246             
    190247            if (ray.intersections.size()) { 
    191248              sampleContributions += AddNodeSamples(ray.intersections[0].mObject, ray, pass); 
     
    222279      } 
    223280     
    224       cout << "pass " << pass<<" : t = " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 
    225       cout << "#totalSamples=" << totalSamples/1000  
    226            << "k   #sampleContributions=" << passSampleContributions << " ("  
     281      cout << "#Pass " << pass<<" : t = " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 
     282      cout << "#TotalSamples=" << totalSamples/1000  
     283           << "k   #SampleContributions=" << passSampleContributions << " ("  
    227284           << 100*passContributingSamples/(float)passSamples<<"%)" << " avgPVS=" 
    228285           << pvsSize/(float)objects.size() << endl  
    229286           << "avg ray contrib=" << passSampleContributions/(float)passContributingSamples << endl; 
     287 
     288 
     289      mStats << 
     290        "#Pass\n" <<pass<<endl<< 
     291        "#Time\n" << TimeDiff(startTime, GetTime())*1e-3 << endl<< 
     292        "#TotalSamples\n" << totalSamples<< endl<< 
     293        "#SampleContributions\n" << passSampleContributions << endl <<  
     294        "#PContributingSamples\n"<<100*passContributingSamples/(float)passSamples<<endl << 
     295        "#AvgPVS\n"<< pvsSize/(float)objects.size() << endl << 
     296        "#AvgRayContrib\n" << passSampleContributions/(float)passContributingSamples << endl; 
    230297    } 
    231298 
  • trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.h

    r191 r245  
    22#define _SamplingPreprocessor_H__ 
    33 
     4#include <fstream> 
     5using namespace std; 
     6 
    47#include "Preprocessor.h" 
    58 
     9struct SimpleRay { 
     10  Vector3 mOrigin; 
     11  Vector3 mDirection; 
     12}; 
    613 
    714/** Sampling based visibility preprocessing. The implementation is based on heuristical 
     
    1219  int mTotalSamples; 
    1320  int mKdPvsDepth; 
    14    
     21  ofstream mStats; 
     22  ObjectContainer mObjects; 
     23 
    1524  SamplingPreprocessor(); 
    1625 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.cpp

    r239 r245  
    5959{ 
    6060        // maximal max viewcells 
    61         int limit = maxViewCells > 0 ? std::min((int)objects.size(), maxViewCells) : (int)objects.size(); 
     61        int limit = maxViewCells > 0 ? Min((int)objects.size(), maxViewCells) : (int)objects.size(); 
    6262 
    6363        for (int i = 0; i < limit; ++i) 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r242 r245  
    350350        ObjectContainer::const_iterator it, it_end = objects.end(); 
    351351 
    352         int limit = (maxObjects > 0) ? min((int)objects.size(), maxObjects) : (int)objects.size(); 
     352        int limit = (maxObjects > 0) ? Min((int)objects.size(), maxObjects) : (int)objects.size(); 
    353353         
    354354        // initialise bounding box 
     
    463463        Plane3 *bestPlane = NULL; 
    464464         
    465         int limit = min((int)polygons->size(), maxTests); 
     465        int limit = Min((int)polygons->size(), maxTests); 
    466466 
    467467        for (int i = 0; i < limit; ++i) 
  • trunk/VUT/GtpVisibilityPreprocessor/src/default.env

    r209 r245  
    88#       filename glasgow1.x3d 
    99#       filename vienna.x3d 
    10         filename ../data/atlanta/atlanta2.x3d 
     10#       filename ../data/atlanta/atlanta2.x3d 
    1111#       filename ../data/soda/soda.dat 
    12 #       filename ../data/soda/soda5.dat 
     12        filename ../data/soda/soda5.dat 
    1313 
    1414} 
     
    5454 
    5555Sampling { 
    56         totalSamples    1000000 
    57         samplesPerPass  5 
     56        totalSamples    50000000 
     57        samplesPerPass  20 
    5858} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/preprocessor.pro

    r209 r245  
    1616 
    1717# RELEASE CONFIG 
    18 #CONFIG         += windows warn_on thread 
     18#CONFIG         += windows warn_on thread release 
    1919 
    2020# DEPENDPATH    = ../../include 
     
    3232Matrix4x4.cpp Vector3.cpp AxisAlignedBox3.cpp Ray.cpp main.cpp Mesh.cpp \ 
    3333Exporter.cpp Camera.cpp X3dParser.cpp MeshKdTree.cpp Pvs.cpp \ 
    34 MutualVisibility.cpp Triangle3.cpp Rectangle3.cpp Plane3.cpp 
     34MutualVisibility.cpp Triangle3.cpp Rectangle3.cpp Plane3.cpp Polygon3.cpp \ 
     35ViewCell.cpp ViewCellBsp.cpp 
    3536 
    3637 
Note: See TracChangeset for help on using the changeset viewer.