Ignore:
Timestamp:
12/08/06 17:10:14 (18 years ago)
Author:
bittner
Message:

merge, global lines, rss sampling updates

File:
1 edited

Legend:

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

    r1841 r1867  
    352352        leaf->dirBBox.Initialize(); 
    353353        leaf->dirBBox.SetMin(2, 0.0f); 
    354         leaf->dirBBox.SetMax(2, 1.0f); 
     354        leaf->dirBBox.SetMax(2, 0.0f); 
    355355        mRoots[0] = leaf; 
    356356        stat.nodes = 1; 
     
    12371237  node->axis = axis; 
    12381238  node->position = info.position; 
    1239   //  node->bbox = box; 
    1240   //  node->dirBBox = GetDirBBox(leaf); 
    1241    
     1239 
     1240  node->bbox = GetBBox(leaf); 
     1241  node->dirBBox = GetDirBBox(leaf); 
    12421242   
    12431243  RssTreeLeaf *back = new RssTreeLeaf(node, info.raysBack); 
     
    12451245 
    12461246   
    1247   // update halton generator 
    1248   back->halton.index = leaf->halton.index; 
    1249   front->halton.index = leaf->halton.index; 
    12501247   
    12511248  // replace a link from node's parent 
     
    18101807  int leaves = 0; 
    18111808 
     1809  for (int i=0; i < mRoots.size(); i++) 
     1810        UpdateImportance(mRoots[i]); 
     1811   
    18121812  while (!tstack.empty()) { 
    18131813    RssTreeNode *node = tstack.top(); 
    1814     tstack.pop(); 
    1815                  
     1814        tstack.pop(); 
     1815         
    18161816    if (node->IsLeaf()) { 
    18171817          leaves++; 
    18181818          RssTreeLeaf *leaf = (RssTreeLeaf *)node; 
    1819           UpdatePvsSize(leaf); 
     1819          // updated above already 
     1820          //      UpdatePvsSize(leaf); 
    18201821           
    18211822          sumPvsSize += leaf->GetPvsSize(); 
     
    18411842          sumImportance += imp; 
    18421843           
    1843  
    18441844        } else { 
    18451845          RssTreeInterior *in = (RssTreeInterior *)node; 
    1846           // both nodes for directional splits 
    18471846          tstack.push(in->front); 
    18481847          tstack.push(in->back); 
     
    18581857  stat.avgWeightedRayContribution = sumWeightedRayContribution/(float)sumRays; 
    18591858  stat.rayRefs = (int)sumRays; 
    1860 } 
    1861  
    1862  
     1859   
     1860} 
     1861 
     1862void 
     1863RssTree::UpdateImportance( 
     1864                                                  RssTreeNode *node) 
     1865{ 
     1866  if (node->IsLeaf()) { 
     1867        UpdatePvsSize((RssTreeLeaf *)node); 
     1868  } else { 
     1869        RssTreeInterior *in = (RssTreeInterior *)node; 
     1870        UpdateImportance(in->front); 
     1871        UpdateImportance(in->back); 
     1872        node->mImportance = in->front->mImportance + in->back->mImportance; 
     1873  } 
     1874} 
     1875 
     1876// generate a single ray described by parameters in a unit cube 
     1877void 
     1878RssTree::GenerateRay(float *params, SimpleRayContainer &rays) 
     1879{ 
     1880  RssTreeNode *node; 
     1881   
     1882  // works only with single root now! 
     1883  node = mRoots[0]; 
     1884   
     1885  while (!node->IsLeaf()) { 
     1886        RssTreeInterior *in = (RssTreeInterior *)node; 
     1887        // decide whether to go left or right 
     1888        int axis = in->axis; 
     1889        float pos = in->GetRelativePosition();  
     1890         
     1891        float r = in->back->GetImportance()/(in->back->GetImportance() + in->front->GetImportance()); 
     1892         
     1893        //      cout<<"axis="<<axis<<" pos="<<pos<<endl; 
     1894        //      cout<<GetBBox(in)<<endl; 
     1895        //      cout<<GetDirBBox(in)<<endl; 
     1896        //      cout<<"********"<<endl; 
     1897         
     1898        if (params[axis] < r) { 
     1899          node = in->back; 
     1900          params[axis] = params[axis] / pos; 
     1901        } else { 
     1902          node = in->front; 
     1903          params[axis] = (params[axis] - pos) / ( 1.0f - pos); 
     1904        } 
     1905  } 
     1906 
     1907  //  cout<<params[0]<<" "<<params[1]<<" "<<params[2]<<" "<<params[3]<<" "<<params[4]<<endl; 
     1908   
     1909  GenerateLeafRay(params, rays, node->bbox, node->dirBBox); 
     1910} 
    18631911 
    18641912int 
     
    18671915                                          SimpleRayContainer &rays) 
    18681916{ 
     1917 
     1918   
     1919 
     1920 
    18691921  stack<RssTreeNode *> tstack; 
    18701922  PushRoots(tstack); 
     
    21952247  for (int i=0; i < numberOfRays; i++) { 
    21962248        //      Debug<<i<<flush; 
    2197  
    2198         Vector3 origin, direction; 
    2199         Vector3 dirVector; 
    2200          
    2201         Vector3 pVector; 
    2202         Vector3 dVector; 
    2203          
    2204         bool useHalton = false; 
    2205          
    2206          
    2207         if (useHalton) { 
    2208           // generate a random 5D vector 
    2209           pVector = Vector3(leaf->halton.GetNumber(1), 
    2210                                                 leaf->halton.GetNumber(2), 
    2211                                                 leaf->halton.GetNumber(3)); 
    2212            
    2213           dVector = Vector3(leaf->halton.GetNumber(4), 
    2214                                                 leaf->halton.GetNumber(5), 
    2215                                                 0.0f); 
    2216            
    2217           leaf->halton.GenerateNext(); 
    2218         } else { 
    2219           pVector = Vector3(RandomValue(0.0f, 1.0f), 
    2220                                                 RandomValue(0.0f, 1.0f), 
    2221                                                 RandomValue(0.0f, 1.0f)); 
    2222            
    2223           dVector = Vector3(RandomValue(0.0f, 1.0f), 
    2224                                                 RandomValue(0.0f, 1.0f), 
    2225                                                 0.0f); 
    2226         } 
    2227          
    2228         origin = box.GetPoint(pVector); 
    2229         dirVector = dirBox.GetPoint(dVector); 
    2230          
    2231         direction = VssRay::GetInvDirParam(dirVector.x, dirVector.y); 
    2232          
    2233         //      float dist = Min(avgLength*0.5f, Magnitude(GetBBox(leaf).Size())); 
    2234         float dist = 0.0f; 
    2235         float minT, maxT; 
    2236  
    2237         // compute interection of the ray with the box 
    2238 #if 1 
    2239         if (box.ComputeMinMaxT(origin, direction, &minT, &maxT) && minT < maxT) 
    2240           dist = (maxT + 1e-2*boxSize); 
    2241 #else 
    2242         dist = 0.5f*boxSize; 
    2243 #endif 
    2244  
    2245         origin += direction*dist; 
    2246          
    2247 #if 0 
    2248         static int counter = 0; 
    2249         //      Debug<<counter++<<flush; 
    2250  
    2251         if (counter > 10374968) { 
    2252           Debug<<"size="<<rays.size()<<endl; 
    2253           Debug<<"capacity="<<rays.capacity()<<endl; 
    2254           Debug<<"o="<<origin<<endl; 
    2255           Debug<<"d="<<direction<<endl; 
    2256         } 
    2257 #endif   
    2258         //Debug<<"dir vector.x="<<dirVector.x<<"direction'.x="<<atan2(direction.x, direction.y)<<endl; 
    2259         rays.push_back(SimpleRay(origin, direction)); 
    2260         //      Debug<<endl; 
    2261          
     2249        float r[5]; 
     2250         
     2251        r[0] = RandomValue(0.0f, 1.0f); 
     2252        r[1] = RandomValue(0.0f, 1.0f); 
     2253        r[2] = RandomValue(0.0f, 1.0f); 
     2254        r[3] = RandomValue(0.0f, 1.0f); 
     2255        r[4] = RandomValue(0.0f, 1.0f); 
     2256         
     2257        GenerateLeafRay(r, rays, box, dirBox); 
    22622258  } 
    22632259 
     
    22692265        rays[i].mPdf = p; 
    22702266  } 
     2267} 
     2268 
     2269void 
     2270RssTree::GenerateLeafRay( 
     2271                                                 float *params, 
     2272                                                 SimpleRayContainer &rays, 
     2273                                                 const AxisAlignedBox3 &box, 
     2274                                                 const AxisAlignedBox3 &dirBBox 
     2275                                                 ) 
     2276{ 
     2277  Vector3 origin = bbox.GetPoint(Vector3(params[0], params[1], params[2])); 
     2278  Vector3 dirVector = dirBBox.GetPoint(Vector3(params[3], params[4], 0.0f)); 
     2279  Vector3 direction = VssRay::GetInvDirParam(dirVector.x, dirVector.y); 
     2280   
     2281  //    float dist = Min(avgLength*0.5f, Magnitude(GetBBox(leaf).Size())); 
     2282  float dist = 0.0f; 
     2283  float minT, maxT; 
     2284   
     2285  float boxSize = Magnitude(bbox.Size()); 
     2286  // compute interection of the ray with the box 
     2287#if 1 
     2288  if (bbox.ComputeMinMaxT(origin, direction, &minT, &maxT) && minT < maxT) 
     2289        dist = (maxT + 1e-2*boxSize); 
     2290#else 
     2291  dist = 0.5f*boxSize; 
     2292#endif 
     2293   
     2294  origin += direction*dist; 
     2295   
     2296   
     2297  //Debug<<"dir vector.x="<<dirVector.x<<"direction'.x="<<atan2(direction.x, direction.y)<<endl; 
     2298  rays.push_back(SimpleRay(origin, direction)); 
    22712299} 
    22722300 
     
    23782406          Vector3 dVector; 
    23792407 
    2380           bool useHalton = true; 
    2381            
    2382           if (useHalton) { 
    2383                 // generate a random 5D vector 
    2384                 pVector = Vector3(leaf->halton.GetNumber(1), 
    2385                                                   leaf->halton.GetNumber(2), 
    2386                                                   leaf->halton.GetNumber(3)); 
    2387                  
    2388                 dVector = Vector3(leaf->halton.GetNumber(4), 
    2389                                                   leaf->halton.GetNumber(5), 
    2390                                                   0.0f); 
    2391                  
    2392                 leaf->halton.GenerateNext(); 
    2393           } else { 
    2394                 pVector = Vector3(RandomValue(0.0f, 1.0f), 
    2395                                                   RandomValue(0.0f, 1.0f), 
    2396                                                   RandomValue(0.0f, 1.0f)); 
    2397                  
    2398                 dVector = Vector3(RandomValue(0.0f, 1.0f), 
    2399                                                   RandomValue(0.0f, 1.0f), 
    2400                                                   0.0f); 
    2401           } 
     2408          pVector = Vector3(RandomValue(0.0f, 1.0f), 
     2409                                                RandomValue(0.0f, 1.0f), 
     2410                                                RandomValue(0.0f, 1.0f)); 
     2411           
     2412          dVector = Vector3(RandomValue(0.0f, 1.0f), 
     2413                                                RandomValue(0.0f, 1.0f), 
     2414                                                0.0f); 
     2415           
    24022416           
    24032417          origin = box.GetPoint(pVector); 
     
    26252639          if (node->IsLeaf()) { 
    26262640                RssTreeLeaf *leaf = (RssTreeLeaf *)node; 
    2627                 //              prunned += PruneRaysRandom(leaf, ratio); 
     2641                // prunned += PruneRaysRandom(leaf, ratio); 
    26282642                prunned += PruneRaysContribution(leaf, ratio); 
    26292643          } else { 
     
    26532667{ 
    26542668 
    2655  
     2669  float param[5]; 
     2670 
     2671  for (int i=0; i < numberOfRays; i++) { 
     2672        halton.GetNext(param); 
     2673        GenerateRay(param, rays); 
     2674  } 
     2675 
     2676  return rays.size(); 
     2677   
    26562678  vector<RssTreeLeaf *> leaves; 
    26572679 
     
    28642886         
    28652887        // $$  
    2866         sumWeights = (float)leaf->mTotalRays; 
     2888        // sumWeights = leaf->mTotalRays; 
    28672889 
    28682890        //$$ test 30.11. 2006  
     
    28902912 
    28912913float 
    2892 RssTreeLeaf::GetImportance()  const 
     2914RssTreeNode::GetImportance()  const 
    28932915{ 
    28942916  //  return sqr(mImportance); 
     
    31293151 
    31303152 
    3131 } 
     3153 
     3154 
     3155 
     3156} 
Note: See TracChangeset for help on using the changeset viewer.