I got a issue with my VTK pipeline but i don’t understand what did i do wrong.
Currently I want to display an image of a 3D volume and on this image I want some 3D glyph arrows.
But when I display it, any arrows aren’t oriented …
If your imageVectorMem data set has vectors and normals, they will be ignored by vtkImageReslice. It only works on scalar data. You might have to try using vtkProbeFilter instead.
There are some vtkProbeFilter examples here. The new vtkResampleToImage filter might be easier to use (it is designed to output vtkImageData, and it uses vtkProbeFilter internally).
What I want is to be able to see my vectors, and to be able to change the slice of my volume displayed. And for this I have a matrix 4x4 to set the orientation and the position of my slice displayed.
Seems that the vtkProbeFilter doesn’t work with me …
The probe filter works the other way around: the “Source” has the attributes you want (the vectors), and the “Input” has the point grid to use for the output. But I’ve been thinking, and the probe filter is probably not the best solution for you, since you already have something that almost works with vtkImageReslice (and ImageReslice is also much faster than Probe, since it is designed specifically for image data).
I remembered some old code that I wrote that does something similar to what you want. In my case, I had tensor values for every voxel in my image volume and I displayed them with vtkImageReslice and vtkTensorGlyph. The code is here and the resulting image looked like this:
The trick was to create a temporary image where the “Tensors” were moved to the “Scalars” so that vtkImageReslice would reslice them. Something like the following:
# make a new data set where tensors are scalars
vtkSmartPointer<vtkImageData> tensorsAsScalars =
vtkSmartPointer<vtkImageData>::New();
tensorsAsScalars->CopyStructure(tensorData);
tensorsAsScalars->GetPointData()->SetScalars(
tensorData->GetPointData()->GetTensors());
# reslice works because the data is stored as Scalars
tensorReslice->SetInputData(tensorsAsScalars);
# put the scalar data back into "Tensors" for use by vtkTensorGlyph
vtkSmartPointer<vtkImageData> tensorsData2 =
vtkSmartPointer<vtkImageData>::New();
tensorsData2->CopyStructure(tensorReslice->GetOutput());
tensorsData2->GetPointData()->SetTensors(
tensorReslice->GetOutput()->GetPointData()->GetScalars());
In my case, I wasn’t applying any rotation when I was reslicing, so I didn’t have to rotate the tensors after resampling them.
Since the code that creates imageVectorMem2 calls AllocateScalars() and GetScalarPointer(), your vector data is already stored as Scalars, so you do not need imageVectorMem2, and you do not need this before using vtkImageReslice:
I only get these 4 arrows when I’m supposed to get 672 400 arrows
And I don’t know why they seem to still be not oriented in the 3D space, they lose there color and the image isn’t fix anymore like if, the arrow wasn’t assign to they point in the image. Really strange …
Also, never call AllocateScalars() immediately after calling New(). It’s always necessary to set the Extent (or Dimensions) of the data before AllocateScalars(). Internally, y->CopyStructure(x) sets the Extent, Spacing, and Origin of y to the Extent, Spacing, and Origin of x.
Ok ! It seems that the AllocateScalars() was bugging my code, so now I place it after the : imageVectorSliceMem->CopyStructure(imageResliceMem->GetOutput());
And now I get some result at the output but my arrows still do not display: