[vtk-developers] Add GetPoint function to vtkStructuredGrid

David Gobbi david.gobbi at gmail.com
Fri Feb 5 19:27:39 EST 2010


On Fri, Feb 5, 2010 at 4:06 PM, David Doria <daviddoria+vtk at gmail.com> wrote:

> Ah, even better. What about something like this (surely the flag name should
> change...):
> void vtkStructuredGrid::GetPoint(int x, int y, int z, bool
> adjustForNonZeroExtentBeginning, double p[3])
> {
>   int extent[6];
>   this->GetExtent(extent);
>   if(x < extent[0] || x > extent[1] ||
>      y < extent[2] || y > extent[3] ||
>      z < extent[4] || z > extent[5])
>     {
>     return; // out of bounds!
>     }
>
>   int pos[3];
>   pos[0] = x;
>   pos[1] = y;
>   pos[2] = z;
>   vtkIdType id;
>   if(adjustForNonZeroExtentBeginning)
>     {
>     id = vtkStructuredData::ComputePointIdForExtent(extent, pos);
>     }
>   else
>     {
>     int dim[3];
>     this->GetDimensions(dim);
>     id = vtkStructuredData::ComputePointId(dim, pos);
>     }
>   grid->GetPoint(id, p);
> }
> The point is just to access the point via GetPoint as you would with
> PolyData and UnstructuredGrid, but rather than a linear index, here (as with
> ImageData) a (x,y,z) index is needed. This is opposed to using static
> vtkStructuredData functions, which don't seem to be pointed to anywhere in
> the vtkStructuredGrid documentation.

Personally, I think that's fine.  The flag will make people stop and
think instead of just assuming that it works one way or another.

Honestly the structured data types are a bit confused about what the
(x,y,z) integer structured coordinates are defined.  Originally
(meaning 15+ years ago, before vtkImageData even existed) the indices
started at zero by definition, and all the "structured" data classes
were written under the assumption that the the indices would always
start at zero.

Then came vtkImageData and a bunch of changes to the pipeline that
added some great new features and also messed things up a bit.  And
after that came the merging of vtkImageData and vtkStructuredPoints,
which was necessary, but also problematic because the two classes
weren't quite compatible with each other.

To make a long story short, I think you are correct to have that flag
there, because it allows people to choose between the "original" way
of indexing into structured data (could I call it "as Bill
intended??"), and the "new" way of indexing that was introduced to VTK
with vtkImageData.

  David



More information about the vtk-developers mailing list