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

Method ComputeStructuredCoordinates

Common/DataModel/vtkRectilinearGrid.cxx:360–419  ·  view source on GitHub ↗

------------------------------------------------------------------------------ Convenience function computes the structured coordinates for a point x[3]. The cell is specified by the array ijk[3], and the parametric coordinates in the cell are specified with pcoords[3]. The function returns a 0 if the point x is outside of the grid, and a 1 if inside the grid.

Source from the content-addressed store, hash-verified

358// in the cell are specified with pcoords[3]. The function returns a 0 if the
359// point x is outside of the grid, and a 1 if inside the grid.
360int vtkRectilinearGrid::ComputeStructuredCoordinates(
361 const double x[3], int ijk[3], double pcoords[3])
362{
363 int i, j;
364 double xPrev, xNext, tmp;
365 vtkDataArray* scalars[3];
366
367 int dims[3];
368 this->GetDimensions(dims);
369
370 scalars[0] = this->XCoordinates;
371 scalars[1] = this->YCoordinates;
372 scalars[2] = this->ZCoordinates;
373 //
374 // Find locations in x-y-z direction
375 //
376 ijk[0] = ijk[1] = ijk[2] = 0;
377 pcoords[0] = pcoords[1] = pcoords[2] = 0.0;
378
379 for (j = 0; j < 3; j++)
380 {
381 xPrev = scalars[j]->GetComponent(0, 0);
382 xNext = scalars[j]->GetComponent(scalars[j]->GetNumberOfTuples() - 1, 0);
383 if (xNext < xPrev)
384 {
385 tmp = xNext;
386 xNext = xPrev;
387 xPrev = tmp;
388 }
389 if (x[j] < xPrev || x[j] > xNext)
390 {
391 return 0;
392 }
393 if (x[j] == xNext && dims[j] != 1)
394 {
395 return 0;
396 }
397
398 for (i = 1; i < scalars[j]->GetNumberOfTuples(); i++)
399 {
400 xNext = scalars[j]->GetComponent(i, 0);
401 if (x[j] >= xPrev && x[j] < xNext)
402 {
403 ijk[j] = i - 1;
404 pcoords[j] = (x[j] - xPrev) / (xNext - xPrev);
405 break;
406 }
407
408 else if (x[j] == xNext)
409 {
410 ijk[j] = i - 1;
411 pcoords[j] = 1.0;
412 break;
413 }
414 xPrev = xNext;
415 }
416 }
417

Callers 1

FindCellMethod · 0.95

Calls 3

GetDimensionsMethod · 0.45
GetComponentMethod · 0.45
GetNumberOfTuplesMethod · 0.45

Tested by

no test coverage detected