Smart PolyDataToImageData

Greetings,

I have been trying to create a simple PolyDataToImageData, but I’m unable to update the extent of the image properly!

In fact, there’s only one thing that makes me unable to do it right. What blocks me is… I need to define the pixel size of the resulting image to be equal to, for example, {1, 1, 1}. This means that a PolyData of bounds {10, 20, 10} will be converted to an image of resolution {10, 20, 10}. So, I proceed to update the RequestInformation method to include the usual methods for setting the extent using my calculated values:

outInfo->Set(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(),
	                                   0, scaledResolution[0],
	                                   0, scaledResolution[1],
	                                   0, scaledResolution[2]);

outInfo->Set(vtkDataObject::ORIGIN(), scaledOrigin, 3);
outInfo->Set(vtkDataObject::SPACING(), scaledSpacing, 3);

…and that works when I instantiate my filter… BUT, if I load a state file containing this filter, the RequestInformation execution gives different results because the input is not yet well defined, and this means that input->GetBounds() = {0, 0, 0, 0, 0, 0}. Therefore, the newly evaluated extent resolution will be {0, 0, 0}.

I did try to transfer that logic to RequestUpdateExtent but nothing happened. Perhaps, it is already too late.

I could also try to store hidden values in the state file such as the resolution ({10, 20, 10}), the spacing and the origin, but it won’t work in the context of batch processing, where my sources are continually updated with different polydata.

Are there any other solutions/approaches/workarounds I can try?

Thank you,

Patrick Laurin

Patrick,

Can you post a small, compilable example, CMakeLists.txt file and sample data?

It is difficult to diagnose your problem from a few excerpts.

Thanks,

Bill

1 Like

You cannot rely on the input data object being available during RequestInformation and RequestUpdateExtent. Everything you compute there, needs to be derived from the information keys.

As far as I know, the only solution to your problem would be to output a vtkMultiBlockDataSet, which contains the vtkImageData. As long as your output is not vtkImageData, you don’t need to specify a WHOLE_EXTENT.

1 Like

PolyDataToImageData.zip (4.4 KB)

Tested and working with Paraview 5.6.

It should work with any kind of input. I’ve tested with a vtkSphereSource of radius = 5mm, theta resolution = 20 and phi resolution = 20.

So…I tried inserting a filter between the image filter and its input that generates a vtkInformationDoubleVectorKey containing the bounds, but realized this is not going to work because the first pass in my ImageAlgorithm’s RequestInformation happens before my new filter populates the key with the bounds value. I guess I’ll set my extent to {0, VTK_INT_MAX - 1} on the first pass for now.