Ignore:
Timestamp:
08/08/05 02:29:55 (19 years ago)
Author:
mattausch
Message:

fixed line indent (was messed up with the visual studio)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp

    r209 r218  
    9090  vector<Ray> rays[10]; 
    9191   
    92   while (totalSamples < mTotalSamples) { 
    93  
    94     int passContributingSamples = 0; 
    95     int passSampleContributions = 0; 
    96     int passSamples = 0; 
    97     int index = 0; 
    98  
    99     for (i =0; i < objects.size(); i++) { 
    100       KdNode *nodeToSample = NULL; 
    101       Intersectable *object = objects[i]; 
    102        
    103       int pvsSize = object->mKdPvs.GetSize(); 
    104        
    105       if (0 && pvsSize) { 
    106         // mail all nodes from the pvs 
    107         Intersectable::NewMail(); 
    108         KdPvsMap::iterator i = object->mKdPvs.mEntries.begin(); 
    109         for (; i != object->mKdPvs.mEntries.end(); i++) { 
    110           KdNode *node = (*i).first; 
    111           node->Mail(); 
     92  while (totalSamples < mTotalSamples) 
     93  { 
     94          int passContributingSamples = 0; 
     95          int passSampleContributions = 0; 
     96          int passSamples = 0; 
     97          int index = 0; 
     98 
     99          for (i =0; i < objects.size(); i++) { 
     100                  KdNode *nodeToSample = NULL; 
     101                  Intersectable *object = objects[i]; 
     102                   
     103                  int pvsSize = object->mKdPvs.GetSize(); 
     104       
     105                  if (0 && pvsSize) { 
     106                          // mail all nodes from the pvs 
     107                          Intersectable::NewMail(); 
     108                          KdPvsMap::iterator i = object->mKdPvs.mEntries.begin(); 
     109                           
     110                          for (; i != object->mKdPvs.mEntries.end(); i++) { 
     111                                  KdNode *node = (*i).first; 
     112                                  node->Mail(); 
     113                          } 
     114 
     115                          int maxTries = 2*pvsSize; 
     116         
     117                          for (int tries = 0; tries < 10; tries++) { 
     118                                  index = RandomValue(0, pvsSize - 1); 
     119                                  KdPvsData data; 
     120                                  KdNode *node; 
     121                                  object->mKdPvs.GetData(index, node, data); 
     122                                  nodeToSample = mKdTree->FindRandomNeighbor(node, true); 
     123                                  if (nodeToSample) 
     124                                          break; 
     125                          } 
     126                  } 
     127       
     128              if (0 && pvsSize && pass == 50)  { 
     129                          // mail all nodes from the pvs 
     130                          Intersectable::NewMail(); 
     131                          KdPvsMap::iterator i = object->mKdPvs.mEntries.begin(); 
     132                          for (; i != object->mKdPvs.mEntries.end(); i++) { 
     133                                  KdNode *node = (*i).first; 
     134                                  node->Mail(); 
     135                          } 
     136 
     137                          vector<KdNode *> invisibleNeighbors; 
     138                          // get all neighbors of all PVS nodes 
     139                          i = object->mKdPvs.mEntries.begin(); 
     140 
     141                          for (; i != object->mKdPvs.mEntries.end(); i++) { 
     142                                  KdNode *node = (*i).first; 
     143                                  mKdTree->FindNeighbors(node, invisibleNeighbors, true); 
     144                                  AxisAlignedBox3 box = object->GetBox(); 
     145                                   
     146                                  for (int j=0; j < invisibleNeighbors.size(); j++)  
     147                                  { 
     148                                          int visibility = ComputeBoxVisibility(mKdTree, 
     149                                                                                                                        box, 
     150                                                                                                                        mKdTree->GetBox(invisibleNeighbors[j]), 
     151                                                                                                                        1.0f); 
     152                                  } 
     153                                  // now rank all the neighbors according to probability that a new 
     154                                  // sample creates some contribution 
     155                          } 
     156                  } 
     157 
     158                  for (int k=0; k < mSamplesPerPass; k++) { 
     159                          object->GetRandomSurfacePoint(point, normal); 
     160                           
     161                          if (nodeToSample) { 
     162                                  int maxTries = 5; 
     163                                   
     164                                  for (int tries = 0; tries < maxTries; tries++) { 
     165                                          direction = mKdTree->GetBox(nodeToSample).GetRandomPoint() - point; 
     166 
     167                                          if (DotProd(direction, normal) > Limits::Small) 
     168                                                  break; 
     169                                  } 
     170                 
     171                                  if (tries == maxTries) 
     172                                          direction = UniformRandomVector(normal); 
     173                          }  
     174                          else 
     175                                  direction = UniformRandomVector(normal); 
     176         
     177                          // construct a ray 
     178                          SetupRay(ray, point, direction); 
     179                          mKdTree->CastRay(ray); 
     180 
     181                          if (i < pvsOut) 
     182                                  rays[i].push_back(ray); 
     183         
     184                          int sampleContributions = 0; 
     185         
     186                   
     187                          if (ray.leaves.size()) { 
     188                                  sampleContributions += AddNodeSamples(object, ray, pass); 
     189           
     190                                  if (ray.intersections.size()) { 
     191                                          sampleContributions += AddNodeSamples(ray.intersections[0].mObject, ray, pass); 
     192                                          // check whether we can add this to the rays 
     193                                          for (int j = 0; j < pvsOut; j++) { 
     194                                                  if (objects[j] == ray.intersections[0].mObject) { 
     195                                                          rays[j].push_back(ray); 
     196                                                  } 
     197                                          } 
     198                                  } 
     199 
     200                                  passSamples++; 
     201                         
     202                                  if (sampleContributions) { 
     203                                          passContributingSamples++; 
     204                                          passSampleContributions += sampleContributions; 
     205                                  } 
     206                          } 
     207                  } 
    112208        } 
    113         int maxTries = 2*pvsSize; 
    114          
    115         for (int tries = 0; tries < 10; tries++) { 
    116           index = RandomValue(0, pvsSize - 1); 
    117           KdPvsData data; 
    118           KdNode *node; 
    119           object->mKdPvs.GetData(index, node, data); 
    120           nodeToSample = mKdTree->FindRandomNeighbor(node, true); 
    121           if (nodeToSample) 
    122             break; 
    123         } 
    124       } 
    125        
    126       if (0 && pvsSize && pass == 50 ) { 
    127         // mail all nodes from the pvs 
    128         Intersectable::NewMail(); 
    129         KdPvsMap::iterator i = object->mKdPvs.mEntries.begin(); 
    130         for (; i != object->mKdPvs.mEntries.end(); i++) { 
    131           KdNode *node = (*i).first; 
    132           node->Mail(); 
    133         } 
    134          
    135         vector<KdNode *> invisibleNeighbors; 
    136         // get all neighbors of all PVS nodes 
    137         i = object->mKdPvs.mEntries.begin(); 
    138         for (; i != object->mKdPvs.mEntries.end(); i++) { 
    139           KdNode *node = (*i).first; 
    140           mKdTree->FindNeighbors(node, invisibleNeighbors, true); 
    141           AxisAlignedBox3 box = object->GetBox(); 
    142           for (int j=0; j < invisibleNeighbors.size(); j++) { 
    143             int visibility = ComputeBoxVisibility(mKdTree, 
    144                                                   box, 
    145                                                   mKdTree->GetBox(invisibleNeighbors[j]), 
    146                                                   1.0f); 
    147              
    148           } 
    149           // now rank all the neighbors according to probability that a new 
    150           // sample creates some contribution 
    151         } 
    152       } 
    153  
    154       for (int k=0; k < mSamplesPerPass; k++) { 
    155         object->GetRandomSurfacePoint(point, normal); 
    156         if (nodeToSample) { 
    157           int maxTries = 5; 
    158           for (int tries = 0; tries < maxTries; tries++) { 
    159             direction = mKdTree->GetBox(nodeToSample).GetRandomPoint() - point; 
    160             if (DotProd(direction, normal) > Limits::Small) 
    161               break; 
    162           } 
    163                  
    164           if (tries == maxTries) 
    165             direction = UniformRandomVector(normal); 
    166         } else 
    167           direction = UniformRandomVector(normal); 
    168          
    169         // construct a ray 
    170         SetupRay(ray, point, direction); 
    171         mKdTree->CastRay(ray); 
    172  
    173         if (i < pvsOut) 
    174           rays[i].push_back(ray); 
    175          
    176         int sampleContributions = 0; 
    177          
    178                    
    179         if (ray.leaves.size()) { 
    180           sampleContributions += AddNodeSamples(object, ray, pass); 
    181            
    182           if (ray.intersections.size()) { 
    183             sampleContributions += AddNodeSamples(ray.intersections[0].mObject, ray, pass); 
    184             // check whether we can add this to the rays 
    185             for (int j = 0; j < pvsOut; j++) { 
    186               if (objects[j] == ray.intersections[0].mObject) { 
    187                 rays[j].push_back(ray); 
    188               } 
    189             } 
    190           } 
    191                  
    192           passSamples++; 
    193                          
    194           if (sampleContributions) { 
    195             passContributingSamples++; 
    196             passSampleContributions += sampleContributions; 
    197           } 
    198         } 
    199       } 
    200     } 
    201  
    202209 
    203210    totalSamples += passSamples; 
     
    211218    int pvsSize = 0; 
    212219    for (i=0; i < objects.size(); i++) { 
    213       Intersectable *object = objects[i]; 
    214       pvsSize += object->mKdPvs.GetSize(); 
     220                Intersectable *object = objects[i]; 
     221                pvsSize += object->mKdPvs.GetSize(); 
    215222    } 
    216223     
    217     cout<<"pass "<<pass<<" : t = "<<TimeDiff(startTime, GetTime())*1e-3<<"s"<<endl; 
    218     cout<<"#totalSamples="<<totalSamples/1000<< 
    219       "k   #sampleContributions="<<passSampleContributions<< 
    220       " ("<<100*passContributingSamples/(float)passSamples<<"%)"<< 
    221       " avgPVS="<<pvsSize/(float)objects.size()<<endl<< 
    222       "avg ray contrib="<<passSampleContributions/(float)passContributingSamples<< 
    223       endl; 
     224        cout << "pass " << pass<<" : t = " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 
     225        cout << "#totalSamples=" << totalSamples/1000  
     226                 << "k   #sampleContributions=" << passSampleContributions << " ("  
     227                 << 100*passContributingSamples/(float)passSamples<<"%)" << " avgPVS=" 
     228                 << pvsSize/(float)objects.size() << endl  
     229                 << "avg ray contrib=" << passSampleContributions/(float)passContributingSamples << endl; 
    224230  } 
    225231 
    226232  int totalPvsSize = mKdTree->CollectLeafPvs(); 
    227   cout<<"#totalPvsSize="<<totalPvsSize<<endl; 
     233  cout << "#totalPvsSize=" << totalPvsSize << endl; 
    228234   
    229235  //  HoleSamplingPass(); 
    230236  if (1) { 
    231     Exporter *exporter = Exporter::GetExporter("ray-density.x3d"); 
    232     exporter->SetExportRayDensity(true); 
    233     exporter->ExportKdTree(*mKdTree); 
    234     delete exporter; 
     237          Exporter *exporter = Exporter::GetExporter("ray-density.x3d"); 
     238          exporter->SetExportRayDensity(true); 
     239          exporter->ExportKdTree(*mKdTree); 
     240          delete exporter; 
    235241  } 
    236242   
    237243  bool exportRays = false; 
    238244  if (exportRays) { 
    239     Exporter *exporter = NULL; 
    240     exporter = Exporter::GetExporter("sample-rays.x3d"); 
    241     exporter->SetWireframe(); 
    242     exporter->ExportKdTree(*mKdTree); 
    243     for (i=0; i < pvsOut; i++)  
    244       exporter->ExportRays(rays[i], 1000, RgbColor(1, 0, 0)); 
    245     exporter->SetFilled(); 
    246     delete exporter; 
     245          Exporter *exporter = NULL; 
     246          exporter = Exporter::GetExporter("sample-rays.x3d"); 
     247          exporter->SetWireframe(); 
     248          exporter->ExportKdTree(*mKdTree); 
     249 
     250          for (i=0; i < pvsOut; i++)  
     251                  exporter->ExportRays(rays[i], 1000, RgbColor(1, 0, 0)); 
     252          exporter->SetFilled(); 
     253           
     254          delete exporter; 
    247255  } 
    248256 
    249257  if (1) { 
    250     for (int k=0; k < pvsOut; k++) { 
    251       Intersectable *object = objects[k]; 
    252       char s[64]; 
    253       sprintf(s, "sample-pvs%04d.x3d", k); 
    254       Exporter *exporter = Exporter::GetExporter(s); 
    255       exporter->SetWireframe(); 
    256       KdPvsMap::iterator i = object->mKdPvs.mEntries.begin(); 
    257       Intersectable::NewMail(); 
    258       // avoid adding the object to the list 
    259       object->Mail(); 
    260       ObjectContainer visibleObjects; 
    261       for (; i != object->mKdPvs.mEntries.end(); i++) { 
    262         KdNode *node = (*i).first; 
    263         exporter->ExportBox(mKdTree->GetBox(node)); 
    264         mKdTree->CollectObjects(node, visibleObjects); 
    265       } 
    266        
    267       exporter->ExportRays(rays[k], 1000, RgbColor(0, 1, 0)); 
    268       exporter->SetFilled(); 
    269  
    270       for (int j = 0; j < visibleObjects.size(); j++) 
    271         exporter->ExportIntersectable(visibleObjects[j]); 
    272          
    273       Material m; 
    274       m.mDiffuseColor = RgbColor(1, 0, 0); 
    275       exporter->SetForcedMaterial(m); 
    276       exporter->ExportIntersectable(object); 
    277        
    278       delete exporter; 
    279     } 
    280      
     258          for (int k=0; k < pvsOut; k++) { 
     259                  Intersectable *object = objects[k]; 
     260                  char s[64]; 
     261                  sprintf(s, "sample-pvs%04d.x3d", k); 
     262                  Exporter *exporter = Exporter::GetExporter(s); 
     263                  exporter->SetWireframe(); 
     264                  KdPvsMap::iterator i = object->mKdPvs.mEntries.begin(); 
     265                   
     266                  Intersectable::NewMail(); 
     267                   
     268                  // avoid adding the object to the list 
     269                  object->Mail(); 
     270                  ObjectContainer visibleObjects; 
     271                  for (; i != object->mKdPvs.mEntries.end(); i++) { 
     272                          KdNode *node = (*i).first; 
     273                          exporter->ExportBox(mKdTree->GetBox(node)); 
     274                          mKdTree->CollectObjects(node, visibleObjects); 
     275                  } 
     276       
     277                  exporter->ExportRays(rays[k], 1000, RgbColor(0, 1, 0)); 
     278                  exporter->SetFilled(); 
     279 
     280                  for (int j = 0; j < visibleObjects.size(); j++) 
     281                          exporter->ExportIntersectable(visibleObjects[j]); 
     282         
     283                  Material m; 
     284                  m.mDiffuseColor = RgbColor(1, 0, 0); 
     285                  exporter->SetForcedMaterial(m); 
     286                  exporter->ExportIntersectable(object); 
     287       
     288                  delete exporter; 
     289          } 
    281290  } 
    282291   
Note: See TracChangeset for help on using the changeset viewer.