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

Method FindCell

Common/DataModel/vtkImageData.cxx:357–441  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

355
356//------------------------------------------------------------------------------
357vtkIdType vtkImageData::FindCell(double x[3], vtkCell* vtkNotUsed(cell),
358 vtkIdType vtkNotUsed(cellId), double tol2, int& subId, double pcoords[3], double* weights)
359{
360 int idx[3];
361
362 // Compute the voxel index
363 if (this->ComputeStructuredCoordinates(x, idx, pcoords) == 0)
364 {
365 // If voxel index is out of bounds, check point "x" against the
366 // bounds to see if within tolerance of the bounds.
367 const int* extent = this->GetExtent();
368 const double* spacing = this->Spacing;
369
370 // Compute squared distance of point x from the boundary
371 double dist2 = 0.0;
372
373 for (int i = 0; i < 3; i++)
374 {
375 int minIdx = extent[i * 2];
376 int maxIdx = extent[i * 2 + 1];
377
378 if (idx[i] < minIdx)
379 {
380 double dist = (idx[i] + pcoords[i] - minIdx) * spacing[i];
381 idx[i] = minIdx;
382 pcoords[i] = 0.0;
383 dist2 += dist * dist;
384 }
385 else if (idx[i] >= maxIdx)
386 {
387 double dist = (idx[i] + pcoords[i] - maxIdx) * spacing[i];
388 if (maxIdx == minIdx)
389 {
390 idx[i] = minIdx;
391 pcoords[i] = 0.0;
392 }
393 else
394 {
395 idx[i] = maxIdx - 1;
396 pcoords[i] = 1.0;
397 }
398 dist2 += dist * dist;
399 }
400 }
401
402 // Check squared distance against the tolerance
403 if (dist2 > tol2)
404 {
405 return -1;
406 }
407 }
408
409 if (weights)
410 {
411 // Shift parametric coordinates for XZ/YZ planes
412 int descr = this->GetDataDescription();
413 if (descr == vtkStructuredData::VTK_STRUCTURED_XZ_PLANE)
414 {

Callers

nothing calls this directly

Calls 5

ComputeCellIdMethod · 0.95
GetDataDescriptionMethod · 0.80
GetExtentMethod · 0.45
IsCellVisibleMethod · 0.45

Tested by

no test coverage detected