fill vtkImageData with user data

John Biddiscombe j.biddiscombe at rl.ac.uk
Wed Nov 17 05:59:32 EST 1999


Try this...


vtkImageData *outData = get imagedata pointer here

vtkScalars *Newscalars = vtkScalars::New(VTK_FLOAT,1); // or similar
VTK_CHAR,3 for RGB etc etc
outData->SetSpacing(3.6,3.6,1); or similar
// always use 1 for unused 3rd axes, vtk dies if you don't
outData->SetDimensions(512,512,1); or similar
outData->SetOrigin(0,0,0); or similar

Newscalars->SetNumberOfScalars(512*512);

for (int i=0; i<512; i++) {
  for (int j=0; j<512; j++) {
    Newscalars->SetScalar(i*512+j, your number);
  }
}

of course it'd be better to get pointer to array and write data without
using SetScalar(...) but most of the time, its hardly matters.

Now do

outData->SetScalars(Newscalars);
Newscalars->Delete();

voila, data.

Hope this helps

John B




-----------------------------------------------------------------------------
This is the private VTK discussion list.  Please keep messages on-topic.
Check the FAQ at: <http://www.automatrix.com/cgi-bin/vtkfaq>
To UNSUBSCRIBE, send message body containing "unsubscribe vtkusers" to
<majordomo at gsao.med.ge.com>.  For help, send message body containing
"info vtkusers" to the same address.     Live long and prosper.
-----------------------------------------------------------------------------




More information about the vtkusers mailing list