[vtkusers] easy example 2
Dominik Paul
dpaul at ira.uka.de
Wed Mar 7 08:41:16 EST 2001
Helle there,
my last mail didnt contain the code for an easy example. Here it is now.
Can I write into an image Data like this? But Why cant I see anything?
#include <vtkImageData.h>
#include <vtkImageViewer.h>
#include <iostream.h>
#include <vtktiffreader.h>
#include <vtkimagereader.h>
main()
{
//vtkTiffReader* theReader = vtkTiffReader::New();
vtkImageData* volume = vtkImageData::New();
volume -> SetScalarType (VTK_UNSIGNED_SHORT);
volume -> SetDimensions(100,100,3);
volume -> SetNumberOfScalarComponents(1);
volume -> AllocateScalars();
unsigned short* voxels = (unsigned short*) volume -> GetScalarPointer();
//CAN I WRITE INTO IT LIKE THIS ???
int index = 0;
for (int z=0; z<3; z++)
for (int y=0; y<100; y++)
for (int x=0;x<100; x++)
{
*(voxels+index) = x+1;
index++;
}
volume -> Print(cout);
volume -> UpdateInformation();
volume -> Update();
volume -> Print(cout);
vtkImageViewer* theViewer = vtkImageViewer::New();
theViewer -> SetInput(volume);
theViewer -> SetZSlice(2);
theViewer -> Render();
while (1)
{
theViewer -> SetInput(volume);
theViewer -> SetZSlice(2);
theViewer -> Render();
int hallo;
cin >> hallo;
if (hallo == 1) break;
}
}
More information about the vtkusers
mailing list