[vtkusers] Creating an ImageData from the bounds of a PolyData

David Gobbi david.gobbi at gmail.com
Tue Dec 8 15:42:00 EST 2009


On Tue, Dec 8, 2009 at 1:09 PM, David Doria <daviddoria+vtk at gmail.com> wrote:
> I want to do the following:
>
>  vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New();
> // ... fill polydata here ...
>
>  //create a grid spanning the point set
>  double bounds[6];
>  polydata->GetBounds(bounds);
>  vtkSmartPointer<vtkImageData> grid = vtkSmartPointer<vtkImageData>::New();
>  grid->SetExtent(bounds);
>  grid->SetDimensions(10, 10, 10);
>
> I guess I am confused by the terminology. I know GetBounds returns the
> min/max x,y,z values of the points. I want to use these values to set
> the location of the image data. Then I manually set the number of
> voxels in the image data to 10x10x10. SetExtent seems to be expecting
> int's while I am passing it doubles - leading me to believe that it is
> not expecting to be given coordinates of its extreme edges.
>
> Can anyone clarify what Extents is and/or see what I need to change to
> get this effect?

You've spent too much time with VTK to not know how extents work yet.
Is the documentation really that bad?  I put together a VTK course a
few years ago that explains the details... I should put it online
sometime.

The extent is integers.  It says what the first and last pixel indices
are in each of the three directions.  E.g.

double extent[6] = { i_min, i_max, j_min, j_max, k_min, k_max };

VTK images do not always start at (i,j,k) = (0,0,0).  They can start
anywhere.  They can even start at negative indices.  One of the
beautiful things about the VTK streaming pipeline is that VTK can take
just one slice of an image e.g. at k=10 and pass just that one slice
along the pipeline.

The Bounds of an image are

bounds = { i_min*Spacing[0] + Origin[0], i_max*Spacing[1] + Origin[1], etc. };

You can't directly set the bounds.  First you need to decide how many
pixels across you image will be (i.e. what the extent should be), and
then you must set find the origin and spacing that will produce the
bounds that you need from the extent that you have.  This is simple
algebra.

In general, always set the extent to start at zero, e.g. [0, 9, 0, 9,
0, 9] for a 10x10x10 image.  Calling SetDimensions(10,10,10) does
exactly the same thing as SetExtent(0,9,0,9,0,9) but you should always
do the latter to be explicit about where your extent starts.  You
should also look into WholeExtent and UpdateExtent and understand what
they mean, since they control how the streaming pipeline can change
the extent.

   David



More information about the vtkusers mailing list