[vtkusers] What to use: 'vtkDataArray' or 'vtkDoubleArray'?

Michael Jackson mike.jackson at bluequartz.net
Mon Oct 27 09:24:32 EDT 2008


vtkDoubleArray is a high level class that hides the actual array  
implementation.

What you probably want to do is this:
vtkDoubleArray* myArray=vtkDoubleArray::SafeDownCast(myPolyData- 
 >GetPoints());
if (NULL == myArray)
{
	Error ....
}
vtkIdType nPoints = myArray->GetNumberOfTuples();
double pt[3];
for (vtkIdType i = 0; i < nPoints; ++i)
{
     myArray->GetTuple(i,pt);
// Do something with pt.
}


The above code is from memory but should be pretty close.

If you really just want to access the data from the Data array then  
you can do the following:

vtkDoubleArray* myArray=vtkDoubleArray::SafeDownCast(myPolyData- 
 >GetPoints());
if (NULL == myArray)
{
    Error...
}
double* pts = static_cast<double*>(myArray->GetVoidPointer());

That should get you a raw pointer to the data. So as long as you  
understand the how the data is stored in that pointer you can iterate  
over the pointer.

_________________________________________________________
Mike Jackson                  mike.jackson at bluequartz.net
BlueQuartz Software                    www.bluequartz.net
Principal Software Engineer                  Dayton, Ohio



On Oct 27, 2008, at 6:41 AM, B. C. wrote:

> Hi everyone.
> I want to save the values of the points of a polydata in an array  
> and then access to each one. I used this:
>
> double curveValue;
> vtkDoubleArray *myArray;
> for (int i=0; i<myPolydata->GetNumberOfPoints(); i++)
> {
>   myArray[i] = myPolyData->GetPoints()->GetPoint(i);
>   curveValue = myArray->GetValue(i);
> }
>
> I have this error:
> binary '=' : no operator defined which takes a right-hand operand of  
> type 'double *'
>
> When i change the array type to 'vtkDataArray', i have this code:
> double *curveValue;
> vtkDataArray *myArray = myPolyData->GetPoints()->GetData();
> for (int i=0; i<myPolyData->GetNumberOfPoints(); i++)
> {
>   curveValue = myArray->GetTuple(i);
> }
>
> I have no more errors, but when i run the program, i have a bug and  
> the cursor indicates this line:
> vtkDataArray *myArray = myPolyData->GetPoints()->GetData();
>
> I don't understand any one of the 2 error cases!!!
> Please, can someone tell me what type of array should i use? and how  
> to rectify the code
> to have no more errors?
>
> Thank you for you help
>
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers




More information about the vtkusers mailing list