[vtk-developers] Add GetPoint function to vtkStructuredGrid
David Doria
daviddoria+vtk at gmail.com
Fri Feb 5 18:06:54 EST 2010
>
> Close but still no cigar. Don't use "int", use vtkIdType instead.
> Otherwise your code will not be 64-bit safe. In fact, to make it
> 64-bit safe you need to do this:
>
> vtkIdType xrel = x - extent[0];
> vtkIdType yrel = y - extent[2];
> vtkIdType zrel = z - extent[4];
> vtkIdType ind = zrel*dims[1]*dims[0] + yrel*dims[0] + xrel;
>
> Unless xrel, yrel, and zrel are also vtkIdType, the mathematical
> computation of "zrel*dims[1]*dims[0] + yrel*dims[0] + xrel" will be
> done in 32-bit regardless the type of the variable it gets stored in.
>
> This is all kind of moot, though, because you are kinda reinventing
> the wheel here. After you do the bounds check you should just call
> the following function that will do the rest for you:
>
> vtkStructuredData::ComputePointIdForExtent(int extent[6], int ijk[3]);
>
> It already does everything but the bounds check.
>
> David
>
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.
Thanks,
David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20100205/5daead80/attachment.html>
More information about the vtk-developers
mailing list