Changeset 1251 for GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp
- Timestamp:
- 08/21/06 18:39:49 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp
r1249 r1251 13 13 #include "Beam.h" 14 14 #include "GlRenderer.h" 15 //#include "ArchModeler2MLRT.hxx"16 15 #include "Intersectable.h" 17 16 #ifdef GTP_INTERNAL 17 #include "ArchModeler2MLRT.hxx" 18 #endif 18 19 19 20 namespace GtpVisibilityPreprocessor { … … 23 24 24 25 VssPreprocessor::VssPreprocessor(): 25 mPass(0),26 26 mVssRays(), 27 27 mViewSpaceBox(NULL) … … 61 61 62 62 void 63 VssPreprocessor::SetupRay(Ray &ray,64 const Vector3 &point,65 const Vector3 &direction66 )67 {68 ray.Clear();69 // do not store anything else then intersections at the ray70 ray.Init(point, direction, Ray::LOCAL_RAY);71 }72 73 74 void75 63 VssPreprocessor::CastRays( 76 64 SimpleRayContainer &rays, … … 78 66 ) 79 67 { 80 AxisAlignedBox3 &box = mViewSpaceBox ? *mViewSpaceBox : mKdTree->GetBox();68 const AxisAlignedBox3 box = mViewSpaceBox ? *mViewSpaceBox : mKdTree->GetBox(); 81 69 82 70 #if 1 83 for (int i=0; i < rays.size(); i++) 71 SimpleRayContainer::const_iterator rit, rit_end = rays.end(); 72 for (rit = rays.begin(); rit != rit_end; ++ rit) 84 73 { 85 CastRay( rays[i].mOrigin, rays[i].mDirection, vssRays, box);74 CastRay((*rit).mOrigin, (*rit).mDirection, 1, vssRays, box); 86 75 } 87 76 #else … … 99 88 const AxisAlignedBox3 &sbox) 100 89 { 90 #ifdef GTP_INTERNAL 101 91 /* 102 92 mlrtaStoreRayAS16(const float* pforg, const float* pfdir, int j); … … 118 108 119 109 mlrtaTraverseGroupAS16(const float* bbmin, const float* bbmax, int* hit_triangles, float* dist);*/ 120 } 121 122 123 int VssPreprocessor::CastIntelDoubleRay( 124 const Vector3 &viewPoint, 125 const Vector3 &direction, 126 VssRayContainer &vssRays, 127 const AxisAlignedBox3 &box) 128 { 129 VssRay *vssRay = NULL; 130 int hits = 0; 131 132 Vector3 pointA, pointB; 133 134 Intersectable *objectA = 135 CastIntelSingleRay(viewPoint, direction, pointA, box); 136 137 // cast ray into other direction 138 Intersectable *objectB = 139 CastIntelSingleRay(viewPoint, -direction, pointB, box); 140 141 const bool validSample = (objectA != objectB); 142 143 if (validSample) 144 { 145 if (objectA) 146 { 147 vssRay = new VssRay(pointB, 148 pointA, 149 objectB, 150 objectA, 151 mPass); 152 vssRays.push_back(vssRay); 153 hits ++; 154 } 155 156 if (objectB) 157 { 158 vssRay = new VssRay(pointA, 159 pointB, 160 objectA, 161 objectB, 162 mPass); 163 vssRays.push_back(vssRay); 164 hits ++; 165 } 166 //Debug << "intel ray: " << *vssRay << endl; 167 } 168 //cout << "a"; 169 return hits; 170 } 171 172 173 Intersectable *VssPreprocessor::CastIntelSingleRay(const Vector3 &viewPoint, 174 const Vector3 &direction, 175 Vector3 &tPoint, 176 const AxisAlignedBox3 &box 177 ) 178 { 179 AxisAlignedBox3 sbox = box; 180 sbox.Enlarge(Vector3(-Limits::Small)); 181 182 if (!sbox.IsInside(viewPoint)) 183 return 0; 184 185 float pforg[3]; 186 float pfdir[3]; 187 double pfnorm[3]; 188 189 pforg[0] = viewPoint[0]; pforg[1] = viewPoint[1]; pforg[2] = viewPoint[2]; 190 pfdir[0] = direction[0]; pfdir[1] = direction[1]; pfdir[2] = direction[2]; 191 192 float dist = 0; 193 const int hittriangle = -1;//mlrtaIntersectAS(pforg, pfdir, pfnorm, dist); 194 195 if (hittriangle == -1) 196 { 197 static Ray ray; 198 SetupRay(ray, viewPoint, direction); 199 200 float tmin = 0, tmax; 201 if (box.ComputeMinMaxT(ray, &tmin, &tmax) && tmin < tmax) 202 { 203 tPoint = ray.Extrap(tmax); 204 } 205 206 return NULL; 207 } 208 else 209 { 210 tPoint[0] = pforg[0] + pfdir[0] * dist; 211 tPoint[1] = pforg[1] + pfdir[1] * dist; 212 tPoint[2] = pforg[2] + pfdir[2] * dist; 213 214 return mFaceParents[hittriangle]; 215 } 216 } 217 218 219 int 220 VssPreprocessor::CastInternalRay( 221 const Vector3 &viewPoint, 222 const Vector3 &direction, 223 VssRayContainer &vssRays, 224 const AxisAlignedBox3 &box 225 ) 226 { 227 int hits = 0; 228 static Ray ray; 229 230 AxisAlignedBox3 sbox = box; 231 sbox.Enlarge(Vector3(-Limits::Small)); 232 233 if (!sbox.IsInside(viewPoint)) 234 return 0; 235 236 SetupRay(ray, viewPoint, direction); 237 238 // cast ray to KD tree to find intersection with other objects 239 Intersectable *objectA, *objectB; 240 241 Vector3 pointA; 242 Vector3 pointB; 243 244 //float bsize = Magnitude(box.Size()); 245 if (!mDetectEmptyViewSpace) 246 ray.mFlags &= ~Ray::CULL_BACKFACES; 247 else 248 ray.mFlags |= Ray::CULL_BACKFACES; 249 250 if (mKdTree->CastRay(ray)) 251 { 252 objectA = ray.intersections[0].mObject; 253 pointA = ray.Extrap(ray.intersections[0].mT); 254 } 255 else 256 { 257 objectA = NULL; 258 // compute intersection with the scene bounding box 259 float tmin, tmax; 260 if (box.ComputeMinMaxT(ray, &tmin, &tmax) && tmin < tmax) 261 pointA = ray.Extrap(tmax); 262 else 263 return 0; 264 } 265 266 // matt: point A could be undefined? 267 268 // cast ray into opposite direction 269 if (1 && mDetectEmptyViewSpace) { 270 SetupRay(ray, pointA, -direction); 271 } else 272 SetupRay(ray, viewPoint, -direction); 273 274 if (!mDetectEmptyViewSpace) 275 ray.mFlags &= ~Ray::CULL_BACKFACES; 276 else 277 ray.mFlags |= Ray::CULL_BACKFACES; 278 279 if (mKdTree->CastRay(ray)) 280 { 281 objectB = ray.intersections[0].mObject; 282 pointB = ray.Extrap(ray.intersections[0].mT); 283 } 284 else 285 { 286 objectB = NULL; 287 float tmin, tmax; 288 289 if (box.ComputeMinMaxT(ray, &tmin, &tmax) && tmin < tmax) 290 pointB = ray.Extrap(tmax); 291 else 292 return 0; 293 } 294 295 //bool thesame = objectA && (objectA == objectB); 296 297 // if (objectA == NULL && objectB != NULL) { 298 if (1 && mDetectEmptyViewSpace) 299 { 300 // cast again to ensure that there is no objectA 301 SetupRay(ray, pointB, direction); 302 ray.mFlags |= Ray::CULL_BACKFACES; 303 304 if (mKdTree->CastRay(ray)) 305 { 306 objectA = ray.intersections[0].mObject; 307 pointA = ray.Extrap(ray.intersections[0].mT); 308 } 309 } 310 311 312 VssRay *vssRay = NULL; 313 314 bool validSample = (objectA != objectB); 315 316 //if (validSample && thesame) Debug << "warning!!" << endl; 317 318 if (0 && mDetectEmptyViewSpace) 319 { 320 // consider all samples valid 321 // check if the viewpoint lies on the line segment AB 322 if (Distance(pointA, pointB) < 323 Distance(viewPoint, pointA) + Distance(viewPoint, pointB) - Limits::Small) 324 { 325 validSample = false; 326 } 327 } 328 329 if (validSample) 330 { 331 if (objectA) 332 { 333 vssRay = new VssRay(pointB, 334 pointA, 335 objectB, 336 objectA, 337 mPass); 338 vssRays.push_back(vssRay); 339 hits ++; 340 } 341 342 if (objectB) 343 { 344 vssRay = new VssRay(pointA, 345 pointB, 346 objectA, 347 objectB, 348 mPass); 349 vssRays.push_back(vssRay); 350 hits ++; 351 } 352 //Debug << "internal ray: " << *vssRay << endl << endl; 353 } 354 //cout << "b"; 355 return hits; 356 } 357 358 359 int 360 VssPreprocessor::CastRay( 361 const Vector3 &viewPoint, 362 const Vector3 &direction, 363 VssRayContainer &vssRays, 364 const AxisAlignedBox3 &box 365 ) 366 { 367 switch (mRayCastMethod) 368 { 369 case INTEL_RAYCASTER: 370 return CastIntelDoubleRay(viewPoint, direction, vssRays, box); 371 case INTERNAL_RAYCASTER: 372 default: 373 return CastInternalRay(viewPoint, direction, vssRays, box); 374 } 110 #endif 375 111 } 376 112 … … 828 564 Vector3 direction = GetDirection(viewpoint, mViewSpaceBox); 829 565 830 sampleContributions = CastRay(viewpoint, direction, mVssRays, vbox);566 sampleContributions = CastRay(viewpoint, direction, 1, mVssRays, vbox); 831 567 832 568 if (sampleContributions) { … … 959 695 960 696 for (int i=0; i < rays.size(); i++) 961 CastRay(rays[i].mOrigin, rays[i].mDirection, vssRays, vbox);697 CastRay(rays[i].mOrigin, rays[i].mDirection, 1, vssRays, vbox); 962 698 963 699 vssTree->AddRays(vssRays);
Note: See TracChangeset
for help on using the changeset viewer.