[vtk-developers] vtkStructuredGrid::GetCell(i,j,k)

David Doria daviddoria+vtk at gmail.com
Fri Feb 19 08:00:15 EST 2010


If you'll recall, we recently added a GetPoint(i,j,k,p[3], bool
adjustForExtent) function to vtkStructuredGrid. A question on the users list
last night made me realize that it should also be possible to access cells
in this style.

While I was writing a

vtkCell* vtkStructuredGrid::GetCell(int i, int j, int k)

I noticed that in vtkStructuredData there is a ComputeCellId as well as a
ComputeCellIdForExtent. I don't understand what the extent has anything to
do with the cell index? In ComputePointId vs ComputePointIdForExtent, the
difference is do we interpert (i,j,k) explicitly (as coordinates in the
grid) or as an offset from the grid origin. The cells, however, seem like
they should simply be numbered according to this (from the vtkStructuredGrid
documentation):

"The cell order increases in i fastest (from 0<=i<(dims[0]-1)), then j
(0<=j<(dims[1]-1)), then k (0<=k<(dims[2]-1)) The number of cells is
(dims[0]-1)*(dims[1]-1)*(dims[2]-1)."

So I don't understand when you would need to call vtkComputeCellForExtent?

If I'm right, here is my proposed function:

vtkCell* vtkStructuredGrid::GetCell(int i, int j, int k)
{
  int dims[3];
  this->GetDimensions(dims);

  if(i < 0 || i > dims[0] - 1 ||
     j < 0 || j > dims[1] - 1 ||
     k < 0 || k > dims[2] - 1 )
    {
    return NULL; // out of bounds!
    }

  int pos[3];
  pos[0] = i;
  pos[1] = j;
  pos[2] = k;

  vtkIdType id;
  id = vtkStructuredData::ComputeCellId(dims, pos);

  return this->GetCell(id);
}

Thanks,

David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtk-developers/attachments/20100219/f0135d61/attachment.htm>


More information about the vtk-developers mailing list