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

mesh kd tree added

File:
1 edited

Legend:

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

    r165 r170  
    2525  environment->GetFloatValue("KdTree.Termination.ct_div_ci", mCt_div_ci); 
    2626  environment->GetFloatValue("KdTree.splitBorder", mSplitBorder); 
     27 
     28  environment->GetBoolValue("KdTree.sahUseFaces", mSahUseFaces); 
    2729 
    2830  char splitType[64]; 
     
    4244        exit(1); 
    4345      } 
    44  
    45   splitCandidates = new vector<SortableEntry>; 
     46  splitCandidates = NULL; 
    4647} 
    4748 
     
    4950KdTree::Construct() 
    5051{ 
     52  if (!splitCandidates) 
     53    splitCandidates = new vector<SortableEntry>; 
     54 
    5155  // first construct a leaf that will get subdivide 
    5256  KdLeaf *leaf = (KdLeaf *) mRoot; 
     
    6367  } 
    6468 
    65   cout <<"box:"<< mBox<<endl; 
    66  
    67    
     69  cout <<"KdTree Root Box:"<< mBox<<endl; 
    6870  mRoot = Subdivide(TraversalData(leaf, mBox, 0)); 
     71 
     72  // remove the allocated array 
     73  delete splitCandidates; 
    6974 
    7075  return true; 
     
    131136  //  cerr<<"\n OBJECTS="<<leaf->mObjects.size()<<endl; 
    132137  return 
    133     (leaf->mObjects.size() < mTermMinCost) || 
     138    (leaf->mObjects.size() <= mTermMinCost) || 
    134139    (leaf->mDepth >= mTermMaxDepth); 
    135140   
     
    424429  // C = ct_div_ci  + (ol + or)/queries 
    425430 
     431  int totalFaces = 0; 
     432  vector<SortableEntry>::const_iterator ci; 
     433 
     434  for(ci = splitCandidates->begin(); 
     435      ci < splitCandidates->end(); 
     436      ci++)  
     437    if ((*ci).type == SortableEntry::MESH_MIN) { 
     438      Mesh *mesh = ((MeshInstance *)(*ci).data)->GetMesh(); 
     439      totalFaces += mesh->mFaces.size(); 
     440    } 
     441 
     442  int facesLeft = 0; 
     443  int facesRight = totalFaces; 
     444 
    426445  int objectsLeft = 0, objectsRight = node->mObjects.size(); 
    427  
     446   
    428447  float minBox = box.Min(axis); 
    429448  float maxBox = box.Max(axis); 
    430449  float boxArea = box.SurfaceArea(); 
    431450   
    432    
    433    
    434451  float minBand = minBox + mSplitBorder*(maxBox - minBox); 
    435452  float maxBand = minBox + (1.0f - mSplitBorder)*(maxBox - minBox); 
     
    437454  float minSum = 1e20; 
    438455   
    439   for(vector<SortableEntry>::const_iterator ci = splitCandidates->begin(); 
     456  for(ci = splitCandidates->begin(); 
    440457      ci < splitCandidates->end(); 
    441458      ci++) { 
    442      
     459    Mesh *mesh = ((MeshInstance *)(*ci).data)->GetMesh(); 
    443460    switch ((*ci).type) { 
    444461    case SortableEntry::MESH_MIN: 
    445462      objectsLeft++; 
     463      facesLeft += mesh->mFaces.size(); 
    446464      break; 
    447465    case SortableEntry::MESH_MAX: 
    448466      objectsRight--; 
     467      facesRight -= mesh->mFaces.size(); 
    449468      break; 
    450469    } 
     
    456475      rbox.SetMin(axis, (*ci).value); 
    457476 
    458       float sum = objectsLeft*lbox.SurfaceArea() + objectsRight*rbox.SurfaceArea(); 
     477      float sum; 
     478      if (mSahUseFaces) 
     479        sum = facesLeft*lbox.SurfaceArea() + facesRight*rbox.SurfaceArea(); 
     480      else 
     481        sum = objectsLeft*lbox.SurfaceArea() + objectsRight*rbox.SurfaceArea(); 
    459482       
    460483      //      cout<<"pos="<<(*ci).value<<"\t q=("<<ql<<","<<qr<<")\t r=("<<rl<<","<<rr<<")"<<endl; 
     
    471494  } 
    472495   
    473   float oldCost = node->mObjects.size(); 
     496  float oldCost = mSahUseFaces ? totalFaces : node->mObjects.size(); 
    474497  float newCost = mCt_div_ci + minSum/boxArea; 
    475498  float ratio = newCost/oldCost; 
    476  
     499   
    477500#if 0 
    478501  cout<<"===================="<<endl; 
Note: See TracChangeset for help on using the changeset viewer.