Changeset 1135 for GTP/trunk/Lib/Vis/Preprocessing
- Timestamp:
- 07/17/06 09:59:26 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/scripts/Preprocessor.vcproj
r1106 r1135 206 206 </File> 207 207 <File 208 RelativePath="..\src\KdIntersectable.cpp"> 209 </File> 210 <File 211 RelativePath="..\src\KdIntersectable.h"> 212 </File> 213 <File 208 214 RelativePath="..\src\KdTree.cpp"> 209 215 </File> -
GTP/trunk/Lib/Vis/Preprocessing/src/Intersectable.h
r1133 r1135 33 33 //set<KdLeaf *> mKdLeaves; 34 34 35 enum { MESH_INSTANCE, TRANSFORMED_MESH_INSTANCE, SPHERE, VIEW_CELL, OGRE_MESH_INSTANCE }; 35 /// # of object references 36 int mObjectRefs; 37 38 enum { MESH_INSTANCE, 39 TRANSFORMED_MESH_INSTANCE, 40 SPHERE, 41 VIEW_CELL, 42 OGRE_MESH_INSTANCE, 43 KD_INTERSECTABLE 44 }; 36 45 37 Intersectable():mMailbox(0) {}46 Intersectable():mMailbox(0), mObjectRefs(0) {} 38 47 39 48 void SetId(const int id) { mId = id; } … … 88 97 }; 89 98 99 90 100 } 91 101 -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
r1112 r1135 39 39 for (int j = 0; j < n; ++ j) 40 40 { 41 const Vector3 scale2((float)j * 0.8 / n + 0.1, 0.05, (float)i * 0.8 / (float)n + 0.1);41 const Vector3 scale2((float)j * 0.8f / n + 0.1f, 0.05f, (float)i * 0.8f / (float)n + 0.1f); 42 42 43 43 const Vector3 pt2 = sceneBox.Min() + scale2 * (sceneBox.Max() - sceneBox.Min()); … … 58 58 for (int j = 0; j < n; ++ j) 59 59 { 60 const Vector3 scale2(0.15 , (float)j * 0.8 / n + 0.1, (float)i * 0.8 / (float)n + 0.1);60 const Vector3 scale2(0.15f, (float)j * 0.8f / n + 0.1f, (float)i * 0.8f / (float)n + 0.1f); 61 61 62 62 Vector3 pt2 = sceneBox.Min() + scale2 * (sceneBox.Max() - sceneBox.Min()); 63 63 64 Vector3 boxSize = sceneBox.Size() * Vector3(0.0025 , 0.01, 0.0025);64 Vector3 boxSize = sceneBox.Size() * Vector3(0.0025f, 0.01f, 0.0025f); 65 65 AxisAlignedBox3 box(pt2, pt2 + boxSize); 66 66 Mesh *mesh = CreateMeshFromBox(box); … … 75 75 for (int i = 0; i < n; ++ i) 76 76 { 77 const Vector3 scale2(2, 0.2 , (float)i * 0.8 / (float)n + 0.1);77 const Vector3 scale2(2, 0.2f, (float)i * 0.8f / (float)n + 0.1f); 78 78 79 79 Vector3 pt2 = sceneBox.Min() + scale2 * (sceneBox.Max() - sceneBox.Min()); 80 80 81 81 //Vector3 boxSize = sceneBox.Size() * Vector3(0.0025, 0.01, 0.0025); 82 Vector3 boxSize = sceneBox.Size() * Vector3(0.005 , 0.02, 0.005);83 84 AxisAlignedBox3 box(pt2 + 0.1 , pt2 + boxSize);82 Vector3 boxSize = sceneBox.Size() * Vector3(0.005f, 0.02f, 0.005f); 83 84 AxisAlignedBox3 box(pt2 + 0.1f, pt2 + boxSize); 85 85 Mesh *mesh = CreateMeshFromBox(box); 86 86 … … 97 97 if (1) 98 98 { 99 const Vector3 scale(1.0 , 0.0, 0);99 const Vector3 scale(1.0f, 0.0, 0); 100 100 101 101 Vector3 pt = sceneBox.Min() + scale * (sceneBox.Max() - sceneBox.Min()); -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
r1133 r1135 265 265 { 266 266 const bool result = mKdPvs.AddSample(sample, pdf, contribution); 267 268 267 return result; 269 268 } -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1133 r1135 5490 5490 obj->Mail(); 5491 5491 } 5492 5492 // TODO matt§§ 5493 #if TODO 5493 5494 // collect kd leaves 5494 5495 //KdLeaf = … … 5505 5506 } 5506 5507 } 5508 #endif 5507 5509 } 5508 5510 -
GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp
r1133 r1135 47 47 48 48 49 50 49 void VspTreeStatistics::Print(ostream &app) const 51 50 { … … 443 442 444 443 445 void VspTree::PrepareConstruction(const VssRayContainer &sampleRays, 446 AxisAlignedBox3 *forcedBoundingBox) 447 { 448 // store pointer to this tree 449 VspSplitCandidate::sVspTree = this; 450 451 mVspStats.nodes = 1; 452 444 void VspTree::ComputeBoundingBox(const RayInfoContainer &rays, 445 AxisAlignedBox3 *forcedBoundingBox) 446 { 453 447 if (forcedBoundingBox) 454 448 { … … 459 453 mBoundingBox.Initialize(); 460 454 461 VssRayContainer::const_iterator rit, rit_end = sampleRays.end();455 RayInfoContainer::const_iterator rit, rit_end = rays.end(); 462 456 463 457 //-- compute bounding box 464 for (rit = sampleRays.begin(); rit != rit_end; ++ rit)465 { 466 VssRay *ray = *rit;458 for (rit = rays.begin(); rit != rit_end; ++ rit) 459 { 460 VssRay *ray = (*rit).mRay; 467 461 468 462 // compute bounding box of view space … … 471 465 } 472 466 } 473 474 mTermMinProbability *= mBoundingBox.GetVolume();475 mGlobalCostMisses = 0;476 467 } 477 468 … … 697 688 698 689 frontData.mDepth = tData.mDepth + 1; 690 backData.mDepth = tData.mDepth + 1; 691 699 692 frontData.mRays = new RayInfoContainer(); 700 701 backData.mDepth = tData.mDepth + 1;702 693 backData.mRays = new RayInfoContainer(); 703 694 704 695 //-- subdivide rays 705 696 SplitRays(splitPlane, … … 707 698 *frontData.mRays, 708 699 *backData.mRays); 709 710 700 711 701 //Debug << "f: " << frontData.mRays->size() << " b: " << backData.mRays->size() << "d: " << tData.mRays->size() << endl; … … 889 879 890 880 // potentially visible kd cells 891 const bool termination = true; 892 vc->AddKdPvsSample(GetKdLeaf(ray, termination)); 881 KdLeaf *leaf = 882 mOspTree->GetLeaf(ray->mTermination, ray->mTerminationNode); 883 float kdcontri; 884 vc->AddKdPvsSample(leaf, 1, kdcontri); 893 885 } 894 886 … … 903 895 904 896 sc += contribution; 905 897 906 898 // potentially visible kd cells 907 const bool termination = false; 908 vc->AddKdPvsSample(GetKdLeaf(ray, termination)); 909 } 910 899 const bool origin = true; 900 KdLeaf *leaf = 901 mOspTree->GetLeaf(ray->mOrigin, ray->mOriginNode); 902 float kdcontri; 903 vc->AddKdPvsSample(leaf, 1, kdcontri); 904 } 911 905 912 906 if (madeContrib) … … 987 981 988 982 int VspTree::PrepareHeuristics(Intersectable *object) 989 { 983 { 984 int pvsSize = 0; 985 // TODO matt§§ 986 #if TODO 990 987 set<KdLeaf *>::const_iterator kit, kit_end = object->mKdLeaves.end(); 991 992 int pvsSize = 0;993 988 994 989 for (kit = object->mKdLeaves.begin(); kit != kit_end; ++ kit) … … 1029 1024 } 1030 1025 } 1031 1026 #endif 1032 1027 return pvsSize; 1033 1028 } … … 1177 1172 else // per kd node 1178 1173 { 1174 // TODO matt§§ 1175 #if TODO 1179 1176 set<KdLeaf *>::const_iterator kit, kit_end = oObject->mKdLeaves.end(); 1180 1177 … … 1193 1190 } 1194 1191 } 1192 #endif 1195 1193 } 1196 1194 … … 1218 1216 else // per kd node 1219 1217 { 1218 // TODO matt§§ 1219 #if TODO 1220 1220 set<KdLeaf *>::const_iterator kit, kit_end = tObject->mKdLeaves.end(); 1221 1221 … … 1233 1233 } 1234 1234 } 1235 } 1236 } 1237 } 1238 1239 1240 float VspTree::EvalLocalCostHeuristics(const RayInfoContainer &rays, 1235 #endif 1236 } 1237 } 1238 } 1239 1240 1241 float VspTree::EvalLocalCostHeuristics(const VspTraversalData &tData, 1241 1242 const AxisAlignedBox3 &box, 1242 int pvsSize,1243 1243 const int axis, 1244 1244 float &position) 1245 1245 { 1246 RayInfoContainer *rays = tData.mRays; 1247 int pvsSize = tData.mPvs; 1248 1246 1249 const float minBox = box.Min(axis); 1247 1250 const float maxBox = box.Max(axis); … … 1252 1255 const float maxBand = minBox + mMaxBand * sizeBox; 1253 1256 1254 SortSplitCandidates( rays, axis, minBand, maxBand);1257 SortSplitCandidates(*rays, axis, minBand, maxBand); 1255 1258 1256 1259 // prepare the sweep 1257 1260 // (note: returns pvs size, so there would be no need 1258 1261 // to give pvs size as argument) 1259 pvsSize = PrepareHeuristics( rays);1262 pvsSize = PrepareHeuristics(*rays); 1260 1263 1261 1264 // go through the lists, count the number of objects left and right … … 1385 1388 //-- place split plane using heuristics 1386 1389 nCostRatio[axis] = 1387 EvalLocalCostHeuristics( *tData.mRays,1390 EvalLocalCostHeuristics(tData, 1388 1391 box, 1389 tData.mPvs,1390 1392 axis, 1391 1393 nPosition[axis]); … … 2453 2455 const int side = bRay.ComputeRayIntersection(plane.mAxis, plane.mPosition, t); 2454 2456 2455 2456 #if 12457 2457 if (side == 0) 2458 2458 { … … 2478 2478 backRays.push_back(bRay); 2479 2479 } 2480 #else2481 if (side == 0)2482 {2483 ++ splits;2484 2485 if (ray->HasPosDir(plane.mAxis))2486 {2487 backRays.push_back(RayInfo(ray, bRay.GetMaxT(), t));2488 frontRays.push_back(RayInfo(ray, t, bRay.GetMinT()));2489 }2490 else2491 {2492 frontRays.push_back(RayInfo(ray, bRay.GetMaxT(), t));2493 backRays.push_back(RayInfo(ray, t, bRay.GetMinT()));2494 }2495 }2496 else if (side == 1)2497 {2498 backRays.push_back(bRay);2499 }2500 else2501 {2502 frontRays.push_back(bRay);2503 2504 }2505 #endif2506 2480 } 2507 2481 … … 2582 2556 2583 2557 2584 2585 2586 2558 void VspTree::CollectDirtyCandidates(VspSplitCandidate *sc, 2587 2559 vector<SplitCandidate *> &dirtyList) … … 2598 2570 { 2599 2571 Intersectable *obj = (*oit).first; 2600 2572 // TODO matt§§ 2573 #if TODO 2601 2574 set<KdLeaf *>::const_iterator kit, kit_end = obj->mKdLeaves.end(); 2602 2575 2603 2576 for (kit = obj->mKdLeaves.begin(); kit != kit_end; ++ kit) 2604 2577 { … … 2611 2584 } 2612 2585 } 2613 } 2586 #endif 2587 } 2588 } 2589 2590 2591 void VspTree::ProcessRays(const VssRayContainer &sampleRays, 2592 RayInfoContainer &rays) 2593 { 2594 VssRayContainer::const_iterator rit, rit_end = sampleRays.end(); 2595 2596 long startTime = GetTime(); 2597 2598 cout << "storing rays ... "; 2599 2600 Intersectable::NewMail(); 2601 2602 //-- store rays and objects 2603 for (rit = sampleRays.begin(); rit != rit_end; ++ rit) 2604 { 2605 VssRay *ray = *rit; 2606 float minT, maxT; 2607 static Ray hray; 2608 2609 hray.Init(*ray); 2610 2611 // TODO: not very efficient to implictly cast between rays types 2612 if (GetBoundingBox().GetRaySegment(hray, minT, maxT)) 2613 { 2614 float len = ray->Length(); 2615 2616 if (!len) 2617 len = Limits::Small; 2618 2619 rays.push_back(RayInfo(ray, minT / len, maxT / len)); 2620 } 2621 } 2622 2623 cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 2614 2624 } 2615 2625 … … 2707 2717 for (oit = objects.begin(); oit != oit_end; ++ oit) 2708 2718 { 2719 Intersectable *object = *oit; 2720 2709 2721 // determine the side of this ray with respect to the plane 2710 const AxisAlignedBox3 box = (*oit)->GetBox();2722 const AxisAlignedBox3 box = object->GetBox(); 2711 2723 2712 2724 if (box.Max(splitPlane.mAxis) >= splitPlane.mPosition) 2713 front.push_back(*oit); 2714 2725 { 2726 front.push_back(object); 2727 ++ object->mObjectRefs; 2728 } 2729 2715 2730 if (box.Min(splitPlane.mAxis) < splitPlane.mPosition) 2716 back.push_back(*oit); 2731 { 2732 back.push_back(object); 2733 ++ object->mObjectRefs; 2734 } 2735 2736 // remove parent reference 2737 -- object->mObjectRefs; 2717 2738 } 2718 2739 … … 2755 2776 // TODO matt: compute pvs 2756 2777 frontData.mPvs = 999; // ComputePvsSize(*frontData.mRays); 2757 backData.mPvs = -999; //ComputePvsSize(*backData.mRays);2778 backData.mPvs = 999; //ComputePvsSize(*backData.mRays); 2758 2779 2759 2780 frontData.mProbability = frontData.mBoundingBox.GetVolume(); 2760 2781 2761 2762 // classify objects 2782 2783 //-- subdivide rays 2784 frontData.mRays = new RayInfoContainer(); 2785 backData.mRays = new RayInfoContainer(); 2786 2787 SplitRays(splitPlane, 2788 *tData.mRays, 2789 *frontData.mRays, 2790 *backData.mRays); 2791 2792 2793 //-- classify objects 2763 2794 int objectsBack = 0; 2764 2795 int objectsFront = 0; … … 2951 2982 2952 2983 2953 float OspTree::EvalLocalCostHeuristics( KdLeaf *node,2984 float OspTree::EvalLocalCostHeuristics(const OspTraversalData &tData, 2954 2985 const AxisAlignedBox3 &box, 2955 2986 const int axis, … … 2958 2989 int &objectsBack) 2959 2990 { 2960 // sort so we can use a sweep2961 SortSplitCandidates(node, axis);2962 2963 2991 // go through the lists, count the number of objects left and right 2964 2992 // and evaluate the following cost funcion: 2965 2993 // C = ct_div_ci + (ol + or)/queries 2966 2994 2967 float totalVol = PrepareHeuristics(node->mObjects); 2995 const float minBox = box.Min(axis); 2996 const float maxBox = box.Max(axis); 2997 2998 const float sizeBox = maxBox - minBox; 2999 3000 float minBand = minBox + mSplitBorder * (maxBox - minBox); 3001 float maxBand = minBox + (1.0f - mSplitBorder) * (maxBox - minBox); 3002 3003 //-- sort so we can use a sweep 3004 SortSplitCandidates(tData, axis, minBand, maxBand); 3005 3006 float totalVol = PrepareHeuristics(tData.mNode->mObjects); 2968 3007 float voll = 0; 2969 3008 float volr = totalVol; 2970 3009 2971 const int totalPvs = (int)node->mObjects.size(); 2972 2973 const float minBox = box.Min(axis); 2974 const float maxBox = box.Max(axis); 2975 2976 const float sizeBox = maxBox - minBox; 3010 const int totalPvs = tData.mNode->mObjects.size(); 3011 2977 3012 2978 3013 // if no good split can be found, take mid split … … 2982 3017 float ratio = 99999999.0f; 2983 3018 bool splitPlaneFound = false; 2984 2985 float minBand = minBox + mSplitBorder * (maxBox - minBox); 2986 float maxBand = minBox + (1.0f - mSplitBorder) * (maxBox - minBox); 2987 3019 2988 3020 float minSum = 1e20f; 2989 3021 … … 2993 3025 float sum = (float)totalVol * sizeBox; 2994 3026 3027 int currentPvs = 0; 3028 3029 Intersectable::NewMail(); 3030 3031 //-- traverse through visibility events 3032 2995 3033 vector<SortableEntry>::const_iterator ci, ci_end = mSplitCandidates->end(); 2996 3034 2997 2998 //-- traverse through visibility events 2999 for (ci = mSplitCandidates->begin(); ci != ci_end; ++ ci) 3000 { 3035 for (ci = mSplitCandidates->begin(); ci != ci_end; ++ ci, ++ currentPvs) 3036 { 3037 Intersectable *object = (*ci).mObject; 3038 3039 // new object in this node -> add to the pvs 3040 if (!object->Mailed()) 3041 { 3042 object->Mail(); 3043 ++ currentPvs; 3044 } 3045 3001 3046 EvalViewCellVolumeIncr(*ci, voll, volr); 3002 3047 … … 3005 3050 3006 3051 // Note: sufficient to compare size of bounding boxes of front and back side? 3007 if (((*ci). value >= minBand) && ((*ci).value<= maxBand))3052 if (((*ci).mPos >= minBand) && ((*ci).mPos <= maxBand)) 3008 3053 { 3009 3054 //sum = costl * ((*ci).value - minBox) + costr * (maxBox - (*ci).value); 3010 sum = voll * (*ci).value +volr * (totalPvs - (*ci).value);3011 3012 cout << "pos=" << (*ci).value<< "\t volt=(" << voll << ","3055 sum = voll * currentPvs + volr * (totalPvs - currentPvs); 3056 3057 cout << "pos=" << currentPvs << "\t volt=(" << voll << "," 3013 3058 << volr << ")" << "\t volt= " << sum << endl; 3014 3059 … … 3018 3063 3019 3064 minSum = sum; 3020 pvsBack = (*ci).value;3065 pvsBack = currentPvs; 3021 3066 3022 3067 volBack = voll; … … 3057 3102 3058 3103 3059 void OspTree::SortSplitCandidates(KdLeaf *node, const int axis) 3104 void OspTree::SortSplitCandidates(const OspTraversalData &tData, 3105 const int axis, 3106 float minBand, 3107 float maxBand) 3108 3060 3109 { 3061 3110 mSplitCandidates->clear(); 3062 3111 3063 int requestedSize = 2 * (int)node->mObjects.size(); 3064 3112 RayInfoContainer *rays = tData.mRays; 3113 KdLeaf *leaf = tData.mNode; 3114 3115 int requestedSize = 2 * (int)rays->size(); 3116 3065 3117 // creates a sorted split candidates array 3066 3118 if (mSplitCandidates->capacity() > 500000 && 3067 requestedSize < (int)(mSplitCandidates->capacity() /10))3068 { 3069 3070 mSplitCandidates = new vector<SortableEntry>;3119 requestedSize < (int)(mSplitCandidates->capacity() / 10) ) 3120 { 3121 delete mSplitCandidates; 3122 mSplitCandidates = new vector<SortableEntry>; 3071 3123 } 3072 3124 3073 3125 mSplitCandidates->reserve(requestedSize); 3074 3075 ObjectContainer::const_iterator mi, mi_end = node->mObjects.end(); 3076 3077 // insert all queries 3078 int pvs = 0; 3079 for(mi = node->mObjects.begin(); mi != mi_end; ++ mi, ++ pvs) 3080 { 3081 AxisAlignedBox3 box = (*mi)->GetBox(); 3082 3083 // only first event should be sufficient 3084 // but maybe introduces problems with symmetry ... 3085 mSplitCandidates->push_back(SortableEntry(SortableEntry::BOX_MIN, 3086 pvs, *mi)); 3087 3088 //mSplitCandidates->push_back(SortableEntry(SortableEntry::BOX_MAX, 3089 // pvs, *mi)); 3126 3127 float pos; 3128 3129 //-- insert all queries 3130 for (RayInfoContainer::const_iterator ri = rays->begin(); ri < rays->end(); ++ ri) 3131 { 3132 const bool positive = (*ri).mRay->HasPosDir(axis); 3133 3134 pos = (*ri).ExtrapOrigin(axis); 3135 3136 3137 //if (mOspTree->GetLeaf() == leaf) 3138 3139 /* mSplitCandidates->push_back(SortableEntry(positive ? SortableEntry::ERayMin : SortableEntry::ERayMax, 3140 pos, (*ri).mRay)); 3141 3142 pos = (*ri).ExtrapTermination(axis); 3143 3144 mSplitCandidates->push_back(SortableEntry(positive ? SortableEntry::ERayMax : SortableEntry::ERayMin, 3145 pos, (*ri).mRay));*/ 3090 3146 } 3091 3147 … … 3144 3200 Intersectable *obj = ci.mObject; 3145 3201 3146 switch (ci. type)3202 switch (ci.mType) 3147 3203 { 3148 3204 case SortableEntry::BOX_MIN: … … 3356 3412 3357 3413 3358 void OspTree::PrepareConstruction(const ObjectContainer &objects, 3359 AxisAlignedBox3 *forcedBoundingBox) 3360 { 3361 // store pointer to this tree 3362 OspSplitCandidate::sOspTree = this; 3363 3364 mOspStats.nodes = 1; 3365 3414 void OspTree::ComputeBoundingBox(const ObjectContainer &objects, 3415 AxisAlignedBox3 *forcedBoundingBox) 3416 { 3366 3417 if (forcedBoundingBox) 3367 3418 { … … 3384 3435 } 3385 3436 } 3386 3387 mTermMinProbability *= mBoundingBox.GetVolume(); 3388 mGlobalCostMisses = 0; 3389 } 3437 } 3438 3390 3439 3391 3440 #if DEPRECATED … … 3583 3632 3584 3633 3634 KdNode *OspTree::GetRoot() const 3635 { 3636 return mRoot; 3637 } 3638 3639 3585 3640 KdLeaf *OspTree::GetLeaf(const Vector3 &pt, KdNode *node) const 3586 3641 { 3587 3642 if (node == NULL) 3643 { 3588 3644 node = mRoot; 3645 } 3589 3646 3590 3647 stack<KdNode *> nodeStack; … … 3608 3665 // random decision 3609 3666 if (interior->mPosition < pt[interior->mAxis]) 3667 { 3610 3668 nodeStack.push(interior->mBack); 3669 } 3611 3670 else 3671 { 3612 3672 nodeStack.push(interior->mFront); 3673 } 3613 3674 } 3614 3675 } … … 3618 3679 3619 3680 3620 KdNode *OspTree::GetRoot() const 3621 { 3622 return mRoot; 3623 } 3681 void OspTree::ProcessRays(const VssRayContainer &sampleRays, 3682 RayInfoContainer &rays) 3683 { 3684 VssRayContainer::const_iterator rit, rit_end = sampleRays.end(); 3685 3686 long startTime = GetTime(); 3687 3688 cout << "storing rays ... "; 3689 3690 Intersectable::NewMail(); 3691 3692 //-- store rays and objects 3693 for (rit = sampleRays.begin(); rit != rit_end; ++ rit) 3694 { 3695 VssRay *ray = *rit; 3696 float minT, maxT; 3697 static Ray hray; 3698 3699 hray.Init(*ray); 3700 3701 // TODO: not very efficient to implictly cast between rays types 3702 if (GetBoundingBox().GetRaySegment(hray, minT, maxT)) 3703 { 3704 float len = ray->Length(); 3705 3706 if (!len) 3707 len = Limits::Small; 3708 3709 rays.push_back(RayInfo(ray, minT / len, maxT / len)); 3710 } 3711 } 3712 3713 cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 3714 } 3715 3716 3717 3718 int OspTree::SplitRays(const AxisAlignedPlane &plane, 3719 RayInfoContainer &rays, 3720 RayInfoContainer &frontRays, 3721 RayInfoContainer &backRays) const 3722 { 3723 int splits = 0; 3724 3725 RayInfoContainer::const_iterator rit, rit_end = rays.end(); 3726 3727 for (rit = rays.begin(); rit != rit_end; ++ rit) 3728 { 3729 RayInfo bRay = *rit; 3730 3731 VssRay *ray = bRay.mRay; 3732 float t; 3733 3734 // get classification and receive new t 3735 //-- test if start point behind or in front of plane 3736 const int side = bRay.ComputeRayIntersection(plane.mAxis, plane.mPosition, t); 3737 3738 if (side == 0) 3739 { 3740 ++ splits; 3741 3742 if (ray->HasPosDir(plane.mAxis)) 3743 { 3744 backRays.push_back(RayInfo(ray, bRay.GetMinT(), t)); 3745 frontRays.push_back(RayInfo(ray, t, bRay.GetMaxT())); 3746 } 3747 else 3748 { 3749 frontRays.push_back(RayInfo(ray, bRay.GetMinT(), t)); 3750 backRays.push_back(RayInfo(ray, t, bRay.GetMaxT())); 3751 } 3752 } 3753 else if (side == 1) 3754 { 3755 frontRays.push_back(bRay); 3756 } 3757 else 3758 { 3759 backRays.push_back(bRay); 3760 } 3761 } 3762 3763 return splits; 3764 } 3765 3766 3624 3767 3625 3768 … … 3650 3793 3651 3794 3652 void HierarchyManager::ProcessRays(const VssRayContainer &sampleRays,3653 RayInfoContainer &rays)3654 {3655 VssRayContainer::const_iterator rit, rit_end = sampleRays.end();3656 3657 long startTime = GetTime();3658 3659 cout << "storing rays ... ";3660 3661 Intersectable::NewMail();3662 3663 //-- store rays and objects3664 for (rit = sampleRays.begin(); rit != rit_end; ++ rit)3665 {3666 VssRay *ray = *rit;3667 float minT, maxT;3668 static Ray hray;3669 3670 hray.Init(*ray);3671 3672 // TODO: not very efficient to implictly cast between rays types3673 if (mVspTree.GetBoundingBox().GetRaySegment(hray, minT, maxT))3674 {3675 float len = ray->Length();3676 3677 if (!len)3678 len = Limits::Small;3679 3680 rays.push_back(RayInfo(ray, minT / len, maxT / len));3681 }3682 }3683 3684 cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;3685 }3686 3687 3688 3795 SplitCandidate *HierarchyManager::PrepareVsp(const VssRayContainer &sampleRays, 3689 3796 AxisAlignedBox3 *forcedViewSpace, 3690 RayInfoContainer &rays 3691 ) 3692 { 3797 RayInfoContainer &rays) 3798 { 3799 // get clipped rays 3800 mVspTree.ProcessRays(sampleRays, rays); 3801 3802 // store pointer to this tree 3803 VspTree::VspSplitCandidate::sVspTree = &mVspTree; 3804 mVspTree.mVspStats.nodes = 1; 3805 3693 3806 // prepare bounding box 3694 mVspTree.PrepareConstruction(sampleRays, forcedViewSpace); 3695 3696 // get clipped rays 3697 ProcessRays(sampleRays, rays); 3807 mVspTree.ComputeBoundingBox(rays, forcedViewSpace); 3808 3809 mVspTree.mTermMinProbability *= mBoundingBox.GetVolume(); 3810 mVspTree.mGlobalCostMisses = 0; 3811 3698 3812 3699 3813 const int pvsSize = mVspTree.ComputePvsSize(rays); … … 3740 3854 3741 3855 3742 SplitCandidate * HierarchyManager::PrepareOsp(const ObjectContainer &objects, 3743 AxisAlignedBox3 *forcedViewSpace) 3744 { 3745 mOspTree.PrepareConstruction(objects, forcedViewSpace); 3856 SplitCandidate * HierarchyManager::PrepareOsp(const VssRayContainer &sampleRays, 3857 const ObjectContainer &objects, 3858 AxisAlignedBox3 *forcedObjectSpace, 3859 RayInfoContainer &rays) 3860 { 3861 // get clipped rays 3862 mOspTree.ProcessRays(sampleRays, rays); 3863 3864 // store pointer to this tree 3865 OspTree::OspSplitCandidate::sOspTree = &mOspTree; 3866 mOspTree.mOspStats.nodes = 1; 3867 3868 mOspTree.ComputeBoundingBox(objects, forcedObjectSpace); 3869 3870 mOspTree.mTermMinProbability *= mBoundingBox.GetVolume(); 3871 mGlobalCostMisses = 0; 3872 3746 3873 3747 3874 // add first candidate for view space partition … … 3759 3886 OspTree::OspTraversalData oData(kdleaf, 3760 3887 0, 3888 &rays, 3761 3889 pvsSize, 3762 3890 prop, … … 3778 3906 const ObjectContainer &objects, 3779 3907 AxisAlignedBox3 *forcedViewSpace, 3780 RayInfoContainer &rays) 3781 { 3782 mTQueue.Push(PrepareVsp(sampleRays, forcedViewSpace, rays)); 3783 mTQueue.Push(PrepareOsp(objects, forcedViewSpace)); 3908 RayInfoContainer &viewSpaceRays, 3909 RayInfoContainer &objectSpaceRays) 3910 { 3911 SplitCandidate *vsc = 3912 PrepareVsp(sampleRays, forcedViewSpace, viewSpaceRays); 3913 mTQueue.Push(vsc); 3914 3915 SplitCandidate *osc = 3916 PrepareOsp(sampleRays, objects, forcedViewSpace, objectSpaceRays); 3917 3918 mTQueue.Push(osc); 3784 3919 } 3785 3920 … … 3796 3931 AxisAlignedBox3 *forcedViewSpace) 3797 3932 { 3798 RayInfoContainer *rays = new RayInfoContainer(); 3933 RayInfoContainer *viewSpaceRays = new RayInfoContainer(); 3934 RayInfoContainer *objectSpaceRays = new RayInfoContainer(); 3799 3935 3800 3936 // makes no sense otherwise because only one kd cell available … … 3803 3939 mVspTree.mPvsCountMethod = VspTree::PER_OBJECT; 3804 3940 3805 mTQueue.Push(PrepareVsp(sampleRays, forcedViewSpace, * rays));3941 mTQueue.Push(PrepareVsp(sampleRays, forcedViewSpace, *viewSpaceRays)); 3806 3942 3807 3943 long startTime = GetTime(); … … 3844 3980 3845 3981 //-- object space partition 3846 mTQueue.Push(PrepareOsp(objects, forcedViewSpace)); 3982 SplitCandidate *osc = 3983 PrepareOsp(sampleRays, objects, forcedViewSpace, *objectSpaceRays); 3984 3985 mTQueue.Push(osc); 3986 3847 3987 3848 3988 i = 0; … … 3884 4024 AxisAlignedBox3 *forcedViewSpace) 3885 4025 { 3886 RayInfoContainer *rays = new RayInfoContainer(); 3887 4026 RayInfoContainer *objectSpaceRays = new RayInfoContainer(); 4027 RayInfoContainer *viewSpaceRays = new RayInfoContainer(); 4028 3888 4029 // prepare vsp and osp trees for traversal 3889 PrepareConstruction(sampleRays, objects, forcedViewSpace, * rays);4030 PrepareConstruction(sampleRays, objects, forcedViewSpace, *viewSpaceRays, *objectSpaceRays); 3890 4031 3891 4032 mVspTree.mVspStats.Reset(); … … 3930 4071 } 3931 4072 3932 // reevaluate affected candidates 4073 // reevaluate candidates affected by the split 4074 // for view space splits, this would be object space splits 4075 // and other way round 3933 4076 RepairQueue(); 3934 4077 -
GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.h
r1133 r1135 549 549 } 550 550 551 // deletes contents and sets them to NULL551 /// deletes contents and sets them to NULL 552 552 void Clear() 553 553 { … … 748 748 */ 749 749 void AddViewCellReferences(ViewCell *vc) const; 750 751 750 752 751 … … 794 793 float &pBack) const; 795 794 796 void PrepareConstruction(const VssRayContainer &sampleRays,797 795 void ComputeBoundingBox(const RayInfoContainer &rays, 796 AxisAlignedBox3 *forcedBoundingBox); 798 797 799 798 /** Evaluates candidate for splitting. … … 901 900 /** Computes best cost for axis aligned planes. 902 901 */ 903 float EvalLocalCostHeuristics(const RayInfoContainer &rays,902 float EvalLocalCostHeuristics(const VspTraversalData &data, 904 903 const AxisAlignedBox3 &box, 905 int pvsSize,906 904 const int axis, 907 905 float &position); … … 1010 1008 KdNode *GetKdNode(VssRay &ray, const bool termination) const; 1011 1009 1010 void ProcessRays(const VssRayContainer &sampleRays, 1011 RayInfoContainer &rays); 1012 1012 1013 1013 protected: 1014 1014 1015 1015 int mPvsCountMethod; 1016 1016 1017 enum {PER_OBJECT, PER_KDLEAF}; 1017 1018 … … 1030 1031 /// box around the whole view domain 1031 1032 AxisAlignedBox3 mBoundingBox; 1033 1032 1034 1033 1035 … … 1123 1125 int mDepth; 1124 1126 /// rays piercing this node 1125 //RayInfoContainer *mRays;1127 RayInfoContainer *mRays; 1126 1128 /// the probability that this node contains view point 1127 1129 float mProbability; … … 1140 1142 OspTraversalData(): 1141 1143 mNode(NULL), 1144 mRays(NULL), 1142 1145 mDepth(0), 1143 1146 mPvs(0), … … 1149 1152 1150 1153 OspTraversalData(KdLeaf *node, 1151 const int depth, 1154 const int depth, 1155 RayInfoContainer *rays, 1152 1156 const int pvs, 1153 1157 const float p, 1154 1158 const AxisAlignedBox3 &box): 1155 1159 mNode(node), 1156 mDepth(depth), 1160 mDepth(depth), 1161 mRays(rays), 1157 1162 mPvs(pvs), 1158 1163 mProbability(p), … … 1164 1169 1165 1170 OspTraversalData(const int depth, 1166 const AxisAlignedBox3 &box): 1171 RayInfoContainer *rays, 1172 const AxisAlignedBox3 &box): 1167 1173 mNode(NULL), 1168 mDepth(depth), 1174 mDepth(depth), 1175 mRays(rays), 1169 1176 mPvs(0), 1170 1177 mProbability(0), … … 1182 1189 } 1183 1190 1184 // deletes contents and sets them to NULL1191 /// deletes contents and sets them to NULL 1185 1192 void Clear() 1186 1193 { 1194 DEL_PTR(mRays); 1187 1195 } 1196 1188 1197 1189 1198 friend bool operator<(const OspTraversalData &a, const OspTraversalData &b) … … 1342 1351 int ComputePvsSize(const ObjectContainer &objects) const; 1343 1352 1344 1345 1353 KdLeaf *GetLeaf(const Vector3 &pt, KdNode *node) const; 1346 1354 … … 1355 1363 // For sorting objects 1356 1364 // -------------------------------------------------------------- 1357 struct 1365 struct SortableEntry 1358 1366 { 1359 enum 1367 enum EType 1360 1368 { 1361 BOX_MIN,1362 BOX_MAX1369 ERayMin, 1370 ERayMax 1363 1371 }; 1364 1372 1365 int type; 1366 float value; 1373 int mType; 1374 //int mPvs; 1375 float mPos; 1376 1367 1377 Intersectable *mObject; 1368 1378 1369 1379 SortableEntry() {} 1370 1380 1371 SortableEntry(const int t, const float v, Intersectable *obj): 1372 type(t), value(v), mObject(obj) 1381 SortableEntry(const int type, 1382 //const float pvs, 1383 const float pos, 1384 Intersectable *obj): 1385 mType(type), 1386 //mPvs(pvs), 1387 mPos(pos), 1388 mObject(obj) 1373 1389 {} 1374 1390 1375 1391 bool operator<(const SortableEntry &b) const 1376 1392 { 1377 return value < b.value;1393 return mPos < b.mPos; 1378 1394 } 1379 1395 }; … … 1467 1483 @param axis the current split axis 1468 1484 */ 1469 void SortSplitCandidates(KdLeaf *node, const int axis); 1485 void SortSplitCandidates(const OspTraversalData &data, 1486 const int axis, 1487 float minBand, 1488 float maxBand); 1470 1489 1471 1490 /** Computes best cost for axis aligned planes. 1472 1491 */ 1473 float EvalLocalCostHeuristics( KdLeaf *node,1492 float EvalLocalCostHeuristics(const OspTraversalData &data, 1474 1493 const AxisAlignedBox3 &box, 1475 1494 const int axis, … … 1570 1589 /** Prepares construction for vsp and osp trees. 1571 1590 */ 1572 void PrepareConstruction(const ObjectContainer &objects,1591 void ComputeBoundingBox(const ObjectContainer &objects, 1573 1592 AxisAlignedBox3 *forcedBoundingBox); 1574 1593 … … 1580 1599 void CollectViewCells(KdLeaf *leaf, 1581 1600 ViewCellContainer &viewCells); 1601 1602 void ProcessRays(const VssRayContainer &sampleRays, 1603 RayInfoContainer &rays); 1582 1604 1583 1605 … … 1721 1743 1722 1744 void PrepareConstruction(const VssRayContainer &sampleRays, 1723 const ObjectContainer &objects, 1724 AxisAlignedBox3 *forcedViewSpace, 1725 RayInfoContainer &rays); 1745 const ObjectContainer &objects, 1746 AxisAlignedBox3 *forcedViewSpace, 1747 RayInfoContainer &viewSpaceRays, 1748 RayInfoContainer &objectSpaceRays); 1726 1749 1727 1750 bool FinishedConstruction(); … … 1733 1756 void CollectDirtyCandidates(vector<SplitCandidate *> &dirtyList); 1734 1757 1735 SplitCandidate * PrepareVsp(const VssRayContainer &sampleRays, 1736 AxisAlignedBox3 *forcedViewSpace, 1737 RayInfoContainer &rays); 1738 1739 SplitCandidate * PrepareOsp(const ObjectContainer &objects, 1740 AxisAlignedBox3 *forcedViewSpace); 1741 1742 void ProcessRays(const VssRayContainer &sampleRays, 1758 SplitCandidate *PrepareVsp(const VssRayContainer &sampleRays, 1759 AxisAlignedBox3 *forcedViewSpace, 1760 RayInfoContainer &rays); 1761 1762 SplitCandidate *PrepareOsp(const VssRayContainer &sampleRays, 1763 const ObjectContainer &objects, 1764 AxisAlignedBox3 *forcedObjectSpace, 1743 1765 RayInfoContainer &rays); 1744 1766
Note: See TracChangeset
for help on using the changeset viewer.