[vtk-developers] vtkDoubleArray::GetTuple(vtkIdType) returns float * but not doubl e * ??

Berk Geveci berk.geveci at kitware.com
Mon Nov 10 15:38:32 EST 2003


> Is there a reason why vtkDoubleArray::GetTuple(vtkIdType i) can return a
> pointer to floats but not to doubles?  This seems wrong, or at least a
> breach of completeness: if there's a version that returns a float array,
> shouldn't there be a version that returns a double array as well?  

Yes. There is a reason. The GetTuple interface is float only. Will
Schroeder recently posted a message explaining why we want to change
this to double. Until that happens, you should not add a method
that returns a pointer to double. Two reasons: 1. if you do, you
have to add the same to subclasses of vtkDataArray for consistency 
and we don't want to duplicate the same interface for both float and
double 2. GetTuple() should not return a pointer into the actual array,
this is mainly for consistency since you can not do it for vtkIntArray
etc. I know that vtkFloatArray currently does this. We will change
that.

The method you should use is:
double *vtkDoubleArray::GetPointer(const vtkIdType id);

The annoying thing about this method is that the id is not the
tuple id but the array index. To get the pointer to nth tuple,
you have to 

double* ptr=array->GetPointer(tupleIdx*array->GetNumberOfComponents());

It is possible to add a method (to all sub-classes of vtkDataArray)
like:

XXX* GetTuplePointer(const vtkIdType id)
{ return this->GetPointer(id*this->NumberOfComponents); }

We should probably do that for convenience.

-Berk





More information about the vtk-developers mailing list