vtkImageData的GetScalarPointer参数范围和SetExtent的范围相关
根据VTK源码的
vtkIdType vtkImageData::GetTupleIndex(vtkDataArray* array, int coordinate[3]) { vtkIdType incs[3]; vtkIdType idx; if (array == nullptr) { return -1; } const int* extent = this->Extent; // error checking: since most accesses will be from pointer arithmetic. // this should not waste much time. for (idx = 0; idx < 3; ++idx) { if (coordinate[idx] < extent[idx * 2] || coordinate[idx] > extent[idx * 2 + 1]) { vtkErrorMacro(<< "GetPointer: Pixel (" << coordinate[0] << ", " << coordinate[1] << ", " << coordinate[2] << ") not in current extent: (" << extent[0] << ", " << extent[1] << ", " << extent[2] << ", " << extent[3] << ", " << extent[4] << ", " << extent[5] << ")"); return -1; } } // compute the index of the vector. // Array increments incorporate the number of components, which is not how // vtkDataArrays are indexed. Instead, compute the tuple increments. { incs[0] = 1; incs[1] = (extent[1] - extent[0] + 1); incs[2] = incs[1] * (extent[3] - extent[2] + 1); } idx = ((coordinate[0] - extent[0]) * incs[0] + (coordinate[1] - extent[2]) * incs[1] + (coordinate[2] - extent[4]) * incs[2]); // I could check to see if the array has the correct number // of tuples for the extent, but that would be an extra multiply. if (idx < 0 || idx > array->GetMaxId()) { vtkErrorMacro("Coordinate (" << coordinate[0] << ", " << coordinate[1] << ", " << coordinate[2] << ") out side of array (max = " << array->GetMaxId()); return -1; } return idx; }
最后idx索引的计算需要减去extent后,计算得到。

浙公网安备 33010602011771号