[vtkusers] Rapid access to scalar data in vtkImageData

Jothy jothybasu at gmail.com
Wed Oct 12 06:16:36 EDT 2011


Hi David,

With GetScalarPointer<x,y,z) I get the address.

But I have to add to a std::vector<double>.

I tried like this

std::vector<double>result;
double *pixel=static_cast<double*>(img->GetScalarPointer(x,y,z));
result.push_back(pixel[0]);

Its only pushing the address of the pointer, how to copy the value of the
pointer?

I have just started c++ and pointer seem to be useful but tricky!

Thanks

Jothy


On Tue, Oct 11, 2011 at 9:17 PM, David Doria <daviddoria at gmail.com> wrote:

> On Mon, Oct 10, 2011 at 11:41 AM, Martijn Steenwijk
> <martijnsteenwijk at gmail.com> wrote:
> > You might be looking for an iterator, something like this:
> > reader->Update();
> > ImagePointer img = reader->GetOutput();
> > ImageIteratorType img_it(img, img->GetLargestPossibleRegion() );
> > for(img_it.GoToBegin(); !img_it.IsAtEnd(); ++img_it){
> >     double value = img_it.Get();
> > }
> > Best,
> > Martijn
>
> Martijn, this is the VTK list :)
>
> Jothy, I think you're looking for imageData->GetScalarPointer(). Then
> you can access the data with normal pointer arithmetic.
>
> David
>



-- 
Jothybasu K Selvaraj
PhD Student
University of Liverpool
Liverpool,UK
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20111012/9a1fc800/attachment.htm>


More information about the vtkusers mailing list