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

Method GetTupleIndex

Common/DataModel/vtkCartesianGrid.cxx:559–606  ·  view source on GitHub ↗

------------------------------------------------------------------------------ This Method returns an index to a location in the vtkImageData. Coordinates are in pixel units and are relative to the whole image origin.

Source from the content-addressed store, hash-verified

557// This Method returns an index to a location in the vtkImageData.
558// Coordinates are in pixel units and are relative to the whole image origin.
559vtkIdType vtkCartesianGrid::GetTupleIndex(vtkDataArray* array, int coordinate[3])
560{
561 vtkIdType incs[3];
562 vtkIdType idx;
563
564 if (array == nullptr)
565 {
566 return -1;
567 }
568
569 const int* extent = this->GetExtent();
570 // error checking: since most accesses will be from pointer arithmetic.
571 // this should not waste much time.
572 for (idx = 0; idx < 3; ++idx)
573 {
574 if (coordinate[idx] < extent[idx * 2] || coordinate[idx] > extent[idx * 2 + 1])
575 {
576 vtkErrorMacro(<< "GetPointer: Pixel (" << coordinate[0] << ", " << coordinate[1] << ", "
577 << coordinate[2] << ") not in current extent: (" << extent[0] << ", "
578 << extent[1] << ", " << extent[2] << ", " << extent[3] << ", " << extent[4]
579 << ", " << extent[5] << ")");
580 return -1;
581 }
582 }
583
584 // compute the index of the vector.
585
586 // Array increments incorporate the number of components, which is not how
587 // vtkDataArrays are indexed. Instead, compute the tuple increments.
588 {
589 incs[0] = 1;
590 incs[1] = (extent[1] - extent[0] + 1);
591 incs[2] = incs[1] * (extent[3] - extent[2] + 1);
592 }
593
594 idx = ((coordinate[0] - extent[0]) * incs[0] + (coordinate[1] - extent[2]) * incs[1] +
595 (coordinate[2] - extent[4]) * incs[2]);
596 // I could check to see if the array has the correct number
597 // of tuples for the extent, but that would be an extra multiply.
598 if (idx < 0 || idx > array->GetMaxId())
599 {
600 vtkErrorMacro("Coordinate (" << coordinate[0] << ", " << coordinate[1] << ", " << coordinate[2]
601 << ") out side of array (max = " << array->GetMaxId());
602 return -1;
603 }
604
605 return idx;
606}
607
608//-------------------------------------------------------------------------------
609vtkIdType vtkCartesianGrid::GetTupleIndex(vtkDataArray* array, int x, int y, int z)

Callers 4

GetValueIndexMethod · 0.95
GetInputArrayValueMethod · 0.80
GetScalarIndexMethod · 0.80

Calls 1

GetExtentMethod · 0.45

Tested by

no test coverage detected