Thank you very much. But I can’t understand how works this filter even in the simplest case.
I have vtkImageData like this
00 01 02 03 04
05 06 07 08 09
10 11 12 13 14
But origin of this data is (2, 3). So, (1):
vtkSmartPointer<vtkImageData> localImage = vtkSmartPointer<vtkImageData>::New();
int minExtentX = 0;
int maxExtentX = 4;
int minExtentY = 0;
int maxExtentY = 2;
localImage->SetExtent(minExtentX, maxExtentX, minExtentY, maxExtentY, 0, 0);
double originX = 2.0;
double originY = 3.0;
localImage->SetOrigin(originX, originY, 0.0);
vtkFloatArray* floats = vtkFloatArray::New();
int dataNumbers = (maxExtentY - minExtentY + 1) * (maxExtentX - minExtentX + 1);
for (int i = 0; i < dataNumbers; ++i)
{
floats->InsertNextTuple1(i);
}
localImage->GetPointData()->SetScalars(floats);
Next I create a default vtkTransformation and apply it to source image (2):
vtkSmartPointer<vtkTransform> localToGlobal = vtkSmartPointer<vtkTransform> ::New();
vtkSmartPointer<vtkMatrix4x4> m = vtkSmartPointer<vtkMatrix4x4>::New();
localToGlobal->GetMatrix(m);
vtkSmartPointer<vtkImageReslice> reslicedImage = vtkSmartPointer<vtkImageReslice>::New();
reslicedImage->SetInputData(localImage);
reslicedImage->SetResliceTransform(localToGlobal);
reslicedImage->GenerateStencilOutputOn();
reslicedImage->Update();
Then I check the results (4):
double* reslicedOutputOrigion = reslicedImage->GetOutputOrigin();
int* reslicedOutputExtents = reslicedImage->GetOutputExtent();
double* reslicedOutputSpacing = reslicedImage->GetOutputSpacing();
vtkImageStencilData* stencil = reslicedImage->GetStencilOutput();
int stencilExtentMinX, stencilExtentMaxX, stencilExtentMinY, stencilExtentMaxY, stencilExtentMinZ, stencilExtentMaxZ;
stencil->GetExtent(stencilExtentMinX, stencilExtentMaxX, stencilExtentMinY, stencilExtentMaxY, stencilExtentMinZ, stencilExtentMaxZ);
for (int x = stencilExtentMinX; x <= stencilExtentMaxX; ++x){
for (int y = stencilExtentMinY; y <= stencilExtentMaxY; ++y){
for (int z = stencilExtentMinZ; z <= stencilExtentMaxZ; ++z){
cout << "(" << x << ", " << y << ", " << z << ")" << (stencil->IsInside(x, y, z) ? " is inside" : " is outside") << endl;
if (stencil->IsInside(x, y, z)){
cout << *static_cast<float*>(reslicedImage->GetOutput()->GetScalarPointer(x, y, z)) << endl;
}
}
}
}
Stencil shows that data are the same but the origin of resliced image is (0, 0, 0).
But it is obviously that output origin has to be the same as before (i.e. (2, 3)).
All the extends are 0 as well. I do not understand why it is.
I tried to use reslicedImage->SetOutputExtends and reslicedImage->SetOutputOrigin but it confused me even more.
What I have missed?
How can I cut the part of transformed data and use them for new vtkImageData?