Changeset 639 for GTP/trunk/Lib/Vis/Preprocessing/src
- Timestamp:
- 02/14/06 17:13:42 (19 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/Plane3.cpp
r256 r639 31 31 return true; 32 32 } 33 34 35 Vector3 Plane3::FindIntersection(const Vector3 &a, 36 const Vector3 &b, 37 float *t, 38 bool *coplanar) const 39 { 40 const Vector3 v = b - a; // line from A to B 41 float dv = DotProd(v, mNormal); 42 43 if (signum(dv) == 0) 44 { 45 if (coplanar) 46 (*coplanar) = true; 47 48 if (t) 49 (*t) = 0; 50 51 return a; 52 } 53 54 if (coplanar) 55 (*coplanar) = false; 56 57 float u = - Distance(a) / dv; // TODO: could be done more efficiently 58 59 if (t) 60 (*t) = u; 61 62 return a + u * v; 63 } 64 65 66 int Plane3::Side(const Vector3 &v, const float threshold) const 67 { 68 return signum(Distance(v), threshold); 69 } 70 71 72 float Plane3::FindT(const Vector3 &a, const Vector3 &b) const 73 { 74 const Vector3 v = b - a; // line from A to B 75 const float dv = DotProd(v, mNormal); 76 77 // does not intersect or coincident 78 79 if (signum(dv) == 0) 80 return 0; 81 82 return - Distance(a) / dv; // TODO: could be done more efficiently 83 } -
GTP/trunk/Lib/Vis/Preprocessing/src/Plane3.h
r504 r639 40 40 } 41 41 42 int Side(const Vector3 &v, const float threshold = 1e-6) const {43 return signum(Distance(v), threshold);44 }42 /** Returns 1 if v is on front side, -1 if on back side, 0 if on plane. 43 */ 44 int Side(const Vector3 &v, const float threshold = 1e-6) const; 45 45 46 46 /** Finds intersection of line segment between points a and b with plane. … … 53 53 const Vector3 &b, 54 54 float *t = NULL, 55 bool *coplanar = NULL) const 56 { 57 const Vector3 v = b - a; // line from A to B 58 float dv = DotProd(v, mNormal); 59 60 if (signum(dv) == 0) 61 { 62 if (coplanar) (*coplanar) = true; 63 if (t) (*t) = 0; 64 return a; 65 } 66 67 if (coplanar) (*coplanar) = false; 68 float u = - Distance(a) / dv; // TODO: could be done more efficiently 69 70 if (t) (*t) = u; 71 72 return a + u * v; 73 } 55 bool *coplanar = NULL) const; 74 56 75 57 /** Finds value of intersection parameter t on line segment from a to b. 76 @returns -1if coplanar, else parameter t58 @returns 0 if coplanar, else parameter t 77 59 */ 78 float FindT(const Vector3 &a, const Vector3 &b) const 79 { 80 const Vector3 v = b - a; // line from A to B 81 const float dv = DotProd(v, mNormal); 82 83 // does not intersect or coincident 84 if (signum(dv) == 0) 85 return 0; 86 87 return - Distance(a) / dv; // TODO: could be done more efficiently 88 } 60 float FindT(const Vector3 &a, const Vector3 &b) const; 89 61 90 62 friend bool -
GTP/trunk/Lib/Vis/Preprocessing/src/RayInfo.cpp
r508 r639 106 106 mMaxT = t; 107 107 } 108 109 108 #endif 109 110 110 111 111 int RayInfo::ComputeRayIntersection(const int axis, const float position, float &t) const … … 133 133 { 134 134 t = splitPlane.FindT(mRay->GetOrigin(), mRay->GetTermination()); 135 // Debug << "t: " << t << " mint " << GetMinT() << " maxt " << GetMaxT() << 136 // " orig: " << mRay->GetOrigin() << " term " << mRay->GetTermination() << endl; 135 136 if (0) 137 Debug << "t: " << t << " mint " << GetMinT() << " maxt " << GetMaxT() 138 << " orig: " << mRay->GetOrigin() << " term " << mRay->GetTermination() << endl; 137 139 138 140 // NOTE: if plane equals end point of ray, the ray should be classified 139 141 // non-intersecting, otherwise polygon-plane intersections of bsp tree 140 142 // approaches are not eliminating any rays intersecting the polygon! 141 #if 1 142 if (t >= GetMaxT() - 1e-20) 143 const float thresh = 1 ? 1e-6f : 0.0f; 144 145 // segment is not intersecting plane: fond out if on front or back side 146 if (t >= GetMaxT() - thresh) 147 { 143 148 return splitPlane.Side(ExtrapOrigin()); 144 if (t <= GetMinT() + 1e-20) 149 } 150 151 if (t <= GetMinT() + thresh) 152 { 145 153 return splitPlane.Side(ExtrapTermination()); 146 #else 147 if (t > GetMaxT()) 148 return splitPlane.Side(ExtrapOrigin()); 149 else if (t < GetMinT()) 150 return splitPlane.Side(ExtrapTermination()); 151 #endif 154 } 155 152 156 return 0; 153 157 } 158 154 159 155 160 float RayInfo::SegmentLength() const -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r612 r639 16 16 #include "RssPreprocessor.h" 17 17 18 #define SAMPLE_AFTER_SUBDIVISION 018 #define SAMPLE_AFTER_SUBDIVISION 1 19 19 20 20 … … 115 115 116 116 /// helper function which destroys rays or copies them into the output ray container 117 inline void addOutRays(VssRayContainer &rays, VssRayContainer *outRays)117 inline void disposeRays(VssRayContainer &rays, VssRayContainer *outRays) 118 118 { 119 119 cout << "disposing samples ... "; … … 132 132 else 133 133 { 134 CLEAR_CONTAINER(rays); 135 } 134 VssRayContainer::const_iterator it, it_end = rays.end(); 135 136 for (it = rays.begin(); it != it_end; ++ it) 137 { 138 //(*it)->Unref(); 139 if (!(*it)->IsActive()) 140 delete (*it); 141 } 142 } 143 136 144 cout << "finished" << endl; 137 145 Debug << "disposed " << n << " samples in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; … … 162 170 163 171 // rays can be passed or deleted 164 addOutRays(initialSamples, outRays);172 disposeRays(initialSamples, outRays); 165 173 166 174 … … 196 204 197 205 198 addOutRays(constructionSamples, outRays);206 disposeRays(constructionSamples, outRays); 199 207 200 208 cout << "total samples: " << numSamples << endl; … … 236 244 Visualize(preprocessor->mObjects, visualizationSamples); 237 245 238 addOutRays(visualizationSamples, outRays);246 disposeRays(visualizationSamples, outRays); 239 247 240 248 return numSamples; … … 3056 3064 const VssRayContainer &rays) 3057 3065 { 3058 const int leafOut = 10;3066 const int leafOut = 20; 3059 3067 3060 3068 ViewCell::NewMail(); 3061 3069 3062 cout << "visualization using " << mVisualizationSamples << " samples" << endl; 3070 cout << "visualization using " << (int)rays.size() << " samples" << endl; 3071 Debug << "visualization using " << (int)rays.size() << " samples" << endl; 3063 3072 Debug << "\nOutput view cells: " << endl; 3064 3073 … … 3066 3075 if (0) 3067 3076 stable_sort(mViewCells.begin(), mViewCells.end(), vc_gt); 3068 3077 3069 3078 int limit = min(leafOut, (int)mViewCells.size()); 3070 3079 3071 int raysOut ;3080 int raysOut = 0; 3072 3081 3073 3082 //-- some rays for output 3074 if (1)3075 raysOut = min((int)rays.size(), mVisualizationSamples);3076 3077 3083 for (int i = 0; i < limit; ++ i) 3078 3084 { 3079 3085 cout << "creating output for view cell " << i << " ... "; 3080 3086 3081 VssRayContainer vcRays; 3082 Intersectable::NewMail(); 3087 3083 3088 ViewCell *vc; 3084 3089 … … 3086 3091 vc = mViewCells[i]; 3087 3092 else 3088 vc = mViewCells[Random((int)mViewCells.size())]; 3089 3090 vector<ViewCell *> leaves; 3091 mViewCellsTree->CollectLeaves(vc, leaves); 3092 3093 if (1) 3094 { 3095 // check whether we can add the current ray to the output rays 3096 for (int k = 0; k < raysOut; ++ k) 3097 { 3098 VssRay *ray = rays[k]; 3099 for (int j = 0; j < (int)ray->mViewCells.size(); ++ j) 3100 { 3101 ViewCell *rayvc = ray->mViewCells[j]; 3102 3103 if (leaves[0] == rayvc) 3104 vcRays.push_back(ray); 3105 } 3106 } 3107 } 3093 vc = mViewCells[(int)RandomValue(0, (float)mViewCells.size() - 1)]; 3108 3094 3109 3095 //bspLeaves[j]->Mail(); 3110 3096 char s[64]; sprintf(s, "bsp-pvs%04d.x3d", i); 3111 3097 Exporter *exporter = Exporter::GetExporter(s); 3098 3099 Debug << i << ": pvs size=" << (int)mViewCellsTree->GetPvsSize(vc) << endl; 3100 3101 if (1 || mExportRays) 3102 { 3103 if (1) 3104 { 3105 VssRayContainer vcRays; 3106 VssRayContainer collectRays; 3107 3108 raysOut = min((int)rays.size(), 100); 3109 3110 // collect intial view cells 3111 ViewCellContainer leaves; 3112 mViewCellsTree->CollectLeaves(vc, leaves); 3113 3114 ViewCellContainer::const_iterator vit, vit_end = leaves.end(); 3115 3116 for (vit = leaves.begin(); vit != vit_end; ++ vit) 3117 { 3118 BspLeaf *vcLeaf = dynamic_cast<BspViewCell *>(*vit)->mLeaf; 3119 3120 VssRayContainer::const_iterator rit, rit_end = vcLeaf->mVssRays.end(); 3121 3122 for (rit = vcLeaf->mVssRays.begin(); rit != rit_end; ++ rit) 3123 { 3124 collectRays.push_back(*rit); 3125 } 3126 } 3127 3128 VssRayContainer::const_iterator rit, rit_end = collectRays.end(); 3129 3130 for (rit = collectRays.begin(); rit != rit_end; ++ rit) 3131 { 3132 float p = RandomValue(0.0f, (float)collectRays.size()); 3133 3134 if (p < raysOut) 3135 vcRays.push_back(*rit); 3136 } 3137 //-- export rays piercing this view cell 3138 exporter->ExportRays(vcRays, RgbColor(1, 1, 1)); 3139 } 3140 3141 3142 3143 if (0) 3144 { 3145 VssRayContainer vcRays; 3146 raysOut = min((int)rays.size(), mVisualizationSamples); 3147 // check whether we can add the current ray to the output rays 3148 for (int k = 0; k < raysOut; ++ k) 3149 { 3150 VssRay *ray = rays[k]; 3151 for (int j = 0; j < (int)ray->mViewCells.size(); ++ j) 3152 { 3153 ViewCell *rayvc = ray->mViewCells[j]; 3154 3155 if (rayvc == vc) 3156 vcRays.push_back(ray); 3157 } 3158 } 3159 3160 //-- export rays piercing this view cell 3161 exporter->ExportRays(vcRays, RgbColor(1, 1, 0)); 3162 } 3163 3164 } 3165 3166 3167 3168 3112 3169 exporter->SetWireframe(); 3113 3170 … … 3117 3174 3118 3175 ExportViewCellGeometry(exporter, vc); 3119 3120 3121 Debug << i << ": pvs size=" << (int)mViewCellsTree->GetPvsSize(vc)3122 << ", piercing rays=" << (int)vcRays.size() << endl;3123 // << ", leaves=" << (int)vc->mLeaves.size() << endl; 3124 3125 3126 //-- export rays piercing this view cell 3176 3177 3178 m.mDiffuseColor = RgbColor(1, 0, 0); 3179 exporter->SetForcedMaterial(m); 3180 3181 exporter->SetFilled(); 3182 3183 3127 3184 if (1) 3128 3185 { 3129 exporter->ExportRays(vcRays, RgbColor(1, 1, 1)); 3186 ObjectPvsMap::const_iterator oit, 3187 oit_end = vc->GetPvs().mEntries.end(); 3188 3189 3190 exporter->SetFilled(); 3191 3192 Intersectable::NewMail(); 3193 3194 // output PVS of view cell 3195 for (oit = vc->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) 3196 { 3197 Intersectable *intersect = (*oit).first; 3198 3199 if (!intersect->Mailed()) 3200 { 3201 //m = RandomMaterial(); 3202 //exporter->SetForcedMaterial(m); 3203 3204 exporter->ExportIntersectable(intersect); 3205 intersect->Mail(); 3206 } 3207 } 3130 3208 } 3131 3209 else 3132 3210 { 3133 3134 ViewCellContainer leaves; 3135 mViewCellsTree->CollectLeaves(vc, leaves); 3136 3137 ViewCellContainer::const_iterator lit, lit_end = leaves.end(); 3138 3139 for (lit = leaves.begin(); lit != lit_end; ++ lit) 3140 { 3141 BspLeaf *l = dynamic_cast<BspViewCell *>(*lit)->mLeaf; 3142 exporter->ExportRays(l->mVssRays); 3143 } 3144 } 3145 3146 3147 m.mDiffuseColor = RgbColor(1, 0, 0); 3148 exporter->SetForcedMaterial(m); 3149 3150 ObjectPvsMap::const_iterator it, 3151 it_end = vc->GetPvs().mEntries.end(); 3152 3153 exporter->SetFilled(); 3154 3155 3156 // output PVS of view cell 3157 for (it = vc->GetPvs().mEntries.begin(); it != it_end; ++ it) 3158 { 3159 3160 Intersectable *intersect = (*it).first; 3161 3162 if (!intersect->Mailed()) 3163 { 3164 Material m = RandomMaterial(); 3165 exporter->SetForcedMaterial(m); 3166 3167 exporter->ExportIntersectable(intersect); 3168 intersect->Mail(); 3169 } 3170 } 3171 3172 3211 exporter->ExportGeometry(objects); 3212 } 3213 3173 3214 DEL_PTR(exporter); 3174 3215 cout << "finished" << endl; -
GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp
r612 r639 18 18 #include "Beam.h" 19 19 20 #define USE_FIXEDPOINT_T 0 21 20 22 21 23 //-- static members … … 66 68 mViewCellsManager(NULL), 67 69 mOutOfBoundsCell(NULL), 68 mStoreRays( false),70 mStoreRays(true), 69 71 mRenderCostWeight(0.5), 70 72 mUseRandomAxis(false), … … 602 604 RayInfoContainer::const_iterator it, it_end = tData.mRays->end(); 603 605 for (it = tData.mRays->begin(); it != it_end; ++ it) 606 { 607 (*it).mRay->Ref(); 604 608 leaf->mVssRays.push_back((*it).mRay); 609 } 605 610 } 606 611 … … 1886 1891 1887 1892 1893 void VspBspTree::CollectRays(VssRayContainer &rays) 1894 { 1895 vector<BspLeaf *> leaves; 1896 1897 vector<BspLeaf *>::const_iterator lit, lit_end = leaves.end(); 1898 1899 for (lit = leaves.begin(); lit != lit_end; ++ lit) 1900 { 1901 BspLeaf *leaf = *lit; 1902 VssRayContainer::const_iterator rit, rit_end = leaf->mVssRays.end(); 1903 1904 for (rit = leaf->mVssRays.begin(); rit != rit_end; ++ rit) 1905 rays.push_back(*rit); 1906 } 1907 } 1908 1909 1888 1910 void VspBspTree::ValidateTree() 1889 1911 { … … 1988 2010 RayInfoContainer &rays, 1989 2011 RayInfoContainer &frontRays, 1990 RayInfoContainer &backRays) 2012 RayInfoContainer &backRays) const 1991 2013 { 1992 2014 int splits = 0; … … 2015 2037 { 2016 2038 //-- split ray 2017 // --test if start point behind or in front of plane2039 // test if start point behind or in front of plane 2018 2040 const int side = plane.Side(bRay.ExtrapOrigin()); 2019 2041 -
GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.h
r612 r639 310 310 void CollapseViewCells(); 311 311 312 /** Collects rays stored in the leaves. 313 */ 314 void CollectRays(VssRayContainer &rays); 315 316 312 317 ViewCellsTree *mViewCellsTree; 318 319 313 320 protected: 314 321 … … 502 509 RayInfoContainer &rays, 503 510 RayInfoContainer &frontRays, 504 RayInfoContainer &backRays) ;511 RayInfoContainer &backRays) const; 505 512 506 513 -
GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp
r605 r639 531 531 if (mUseViewSpaceBox) 532 532 { 533 if ( 0)533 if (1) 534 534 mViewSpaceBox = box; 535 535 else
Note: See TracChangeset
for help on using the changeset viewer.