MCPcopy Create free account
hub / github.com/Kitware/VTK / IntersectBox

Method IntersectBox

Common/DataModel/vtkBox.cxx:308–423  ·  view source on GitHub ↗

------------------------------------------------------------------------------ Bounding box intersection modified from Graphics Gems Vol I. The method returns a non-zero value if the bounding box is hit. Origin[3] starts the ray, dir[3] is the vector components of the ray in the x-y-z directions, coord[3] is the location of hit, and t is the parametric coordinate along line. (Notes: the intersecti

Source from the content-addressed store, hash-verified

306// coordinate along line. (Notes: the intersection ray dir[3] is NOT
307// normalized. Valid intersections will only occur between 0<=t<=1.)
308char vtkBox::IntersectBox(const double bounds[6], const double origin[3], const double dir[3],
309 double coord[3], double& t, double tolerance)
310{
311 bool inside = true;
312 char quadrant[3];
313 int i, whichPlane = 0;
314 double maxT[3], candidatePlane[3];
315
316 // Make sure tolerance is non-zero
317 double tol = (tolerance <= 0 ? FLT_EPSILON : tolerance);
318
319 // Make sure bounds are not degenerate (i.e., have positive volume); pad by
320 // tolerance if it is.
321 double bds[6];
322 for (i = 0; i < 3; ++i)
323 {
324 if ((bounds[2 * i + 1] - bounds[2 * i]) > 0)
325 {
326 bds[2 * i] = bounds[2 * i];
327 bds[2 * i + 1] = bounds[2 * i + 1];
328 }
329 else
330 {
331 bds[2 * i] = bounds[2 * i] - tol;
332 bds[2 * i + 1] = bounds[2 * i + 1] + tol;
333 }
334 }
335
336 // First find closest planes
337 //
338 for (i = 0; i < 3; i++)
339 {
340 if (origin[i] < bds[2 * i])
341 {
342 quadrant[i] = VTK_LEFT;
343 candidatePlane[i] = bds[2 * i];
344 inside = false;
345 }
346 else if (origin[i] > bds[2 * i + 1])
347 {
348 quadrant[i] = VTK_RIGHT;
349 candidatePlane[i] = bds[2 * i + 1];
350 inside = false;
351 }
352 else
353 {
354 quadrant[i] = VTK_MIDDLE;
355 }
356 }
357
358 // Check whether origin of ray is inside bbox
359 //
360 if (inside)
361 {
362 coord[0] = origin[0];
363 coord[1] = origin[1];
364 coord[2] = origin[2];
365 t = 0;

Callers 5

ComputeBeginAndEndMethod · 0.45
FindPointsToSendFunction · 0.45
GridsIntersectMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected