[vtkusers] memcpy for a vector stored in vtkStructuredGrid

Hal Canary hal at cs.unc.edu
Mon May 21 07:06:21 EDT 2012


On Mon, May 21, 2012 at 4:43 AM, cel02000 wrote:
> I have a vtkStructuredGrid dataset which has a vector of three components. I
> want to copy the first component of the vector by using memcpy. I tried the
> following but it copies all the components. Could someone help me how to do
> it?
>
> vtkIdType numberOfTuples = sgrid->GetNumberOfPoints();
> double* data;
> data = sgrid->GetPointData()->GetArray( "Vel3D" )->GetTupleN( 0,
> numberOfTuples-1);
> memcpy( (void *)(mxGetPr(pa2)), (void *) data, sizeof(data));


I don't think that will work.  Correct me if I'm wrong, but doesn't a
vtkDoubleArray store all of the components of a single tuple in a
contiguous block?  Also, GetTupleN doesn't seem to be in the
documentation for

I think you're going to have to use a for loop.

char arrayName[] ="Vel3D"
int componentIndex = 0;
double * dest = mxGetPr(pa2);

vtkDataArray * array = sgrid->GetPointData()->GetArray( arrayName );
assert (componentIndex < (array->GetNumberOfComponents()));
vtkIdType numberOfTuples = array->GetNumberOfTuples();
for (vtkIdType  i = 0; i < numberOfTuples; i++)
   dest[i] = array->GetComponent(vtkIdType i, componentIndex);


--
Hal Canary



More information about the vtkusers mailing list