Changeset 1867 for GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.cpp
- Timestamp:
- 12/08/06 17:10:14 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.cpp
r1841 r1867 352 352 leaf->dirBBox.Initialize(); 353 353 leaf->dirBBox.SetMin(2, 0.0f); 354 leaf->dirBBox.SetMax(2, 1.0f);354 leaf->dirBBox.SetMax(2, 0.0f); 355 355 mRoots[0] = leaf; 356 356 stat.nodes = 1; … … 1237 1237 node->axis = axis; 1238 1238 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); 1242 1242 1243 1243 RssTreeLeaf *back = new RssTreeLeaf(node, info.raysBack); … … 1245 1245 1246 1246 1247 // update halton generator1248 back->halton.index = leaf->halton.index;1249 front->halton.index = leaf->halton.index;1250 1247 1251 1248 // replace a link from node's parent … … 1810 1807 int leaves = 0; 1811 1808 1809 for (int i=0; i < mRoots.size(); i++) 1810 UpdateImportance(mRoots[i]); 1811 1812 1812 while (!tstack.empty()) { 1813 1813 RssTreeNode *node = tstack.top(); 1814 1815 1814 tstack.pop(); 1815 1816 1816 if (node->IsLeaf()) { 1817 1817 leaves++; 1818 1818 RssTreeLeaf *leaf = (RssTreeLeaf *)node; 1819 UpdatePvsSize(leaf); 1819 // updated above already 1820 // UpdatePvsSize(leaf); 1820 1821 1821 1822 sumPvsSize += leaf->GetPvsSize(); … … 1841 1842 sumImportance += imp; 1842 1843 1843 1844 1844 } else { 1845 1845 RssTreeInterior *in = (RssTreeInterior *)node; 1846 // both nodes for directional splits1847 1846 tstack.push(in->front); 1848 1847 tstack.push(in->back); … … 1858 1857 stat.avgWeightedRayContribution = sumWeightedRayContribution/(float)sumRays; 1859 1858 stat.rayRefs = (int)sumRays; 1860 } 1861 1862 1859 1860 } 1861 1862 void 1863 RssTree::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 1877 void 1878 RssTree::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 } 1863 1911 1864 1912 int … … 1867 1915 SimpleRayContainer &rays) 1868 1916 { 1917 1918 1919 1920 1869 1921 stack<RssTreeNode *> tstack; 1870 1922 PushRoots(tstack); … … 2195 2247 for (int i=0; i < numberOfRays; i++) { 2196 2248 // 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); 2262 2258 } 2263 2259 … … 2269 2265 rays[i].mPdf = p; 2270 2266 } 2267 } 2268 2269 void 2270 RssTree::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)); 2271 2299 } 2272 2300 … … 2378 2406 Vector3 dVector; 2379 2407 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 2402 2416 2403 2417 origin = box.GetPoint(pVector); … … 2625 2639 if (node->IsLeaf()) { 2626 2640 RssTreeLeaf *leaf = (RssTreeLeaf *)node; 2627 // 2641 // prunned += PruneRaysRandom(leaf, ratio); 2628 2642 prunned += PruneRaysContribution(leaf, ratio); 2629 2643 } else { … … 2653 2667 { 2654 2668 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 2656 2678 vector<RssTreeLeaf *> leaves; 2657 2679 … … 2864 2886 2865 2887 // $$ 2866 sumWeights = (float)leaf->mTotalRays;2888 // sumWeights = leaf->mTotalRays; 2867 2889 2868 2890 //$$ test 30.11. 2006 … … 2890 2912 2891 2913 float 2892 RssTree Leaf::GetImportance() const2914 RssTreeNode::GetImportance() const 2893 2915 { 2894 2916 // return sqr(mImportance); … … 3129 3151 3130 3152 3131 } 3153 3154 3155 3156 }
Note: See TracChangeset
for help on using the changeset viewer.