[vtkusers] Example: display 2d 8bit image from memory
Aaron Boxer
boxerab at yahoo.com
Fri Jan 25 17:04:00 EST 2002
int dimensions[3];
dimensions[0]=200;
dimensions[1]=200;
dimensions[2] = 1;
// export the data into the array
BYTE *data = new BYTE[ dimensions[0]*dimensions[1] ];
// do a little something to the data
long i,j,k;
for (i = 0; i < dimensions[2]; i++)
{
for (j = 0; j < dimensions[1]; j++)
{
for (k = 0; k < dimensions[0]; k++)
{
if (k % 10 == 0)
{
data[k + dimensions[0]*(j + dimensions[1]*i)] =
0;
}
if (j % 10 == 0)
{
data[k + dimensions[0]*(j + dimensions[1]*i)] =
200;
}
}
}
}
// create an importer to read the data back in
vtkImageImport *importer = vtkImageImport::New();
importer->SetDataExtent(1,dimensions[0],1,dimensions[1],1,dimensions[2]);
importer->SetWholeExtent(1,dimensions[0],1,dimensions[1],1,dimensions[2]);
importer->SetDataScalarTypeToUnsignedChar();
importer->SetImportVoidPointer(data);
// Create the datasetMapper
vtkDataSetMapper* polydata = vtkDataSetMapper::New();
polydata->SetInput(importer->GetOutput() );
// create a b/w lookup table
vtkLookupTable *bwLut = vtkLookupTable::New();
bwLut->SetTableRange (0, 256);
bwLut->SetSaturationRange (0, 0);
bwLut->SetHueRange (0, 0);
bwLut->SetValueRange (0, 1);
bwLut->Build ();
//used to shift image
long shiftx = 350;
long shifty = -100;
// create texture class
vtkTexture *axialTexture = vtkTexture::New();
axialTexture->SetInput(importer->GetOutput());
axialTexture->InterpolateOn();
axialTexture->SetLookupTable (bwLut);
axialTexture->MapColorScalarsThroughLookupTableOn();
vtkPlaneSource *axialPlane = vtkPlaneSource::New();
axialPlane->SetXResolution(1);
axialPlane->SetYResolution(1);
axialPlane->SetOrigin(shiftx, shifty, 0);
axialPlane->SetPoint1(1000+ shiftx, shifty, 0);
axialPlane->SetPoint2(shiftx, 750+shifty, 0);
vtkPolyDataMapper *axialMapper =
vtkPolyDataMapper::New();
axialMapper->SetInput(axialPlane->GetOutput());
axialMapper->ImmediateModeRenderingOn();
vtkActor *axial = vtkActor::New();
axial->SetMapper(axialMapper);
axial->SetTexture(axialTexture);
.
.
.
//add actor to renderer
__________________________________________________
Do You Yahoo!?
Great stuff seeking new owners in Yahoo! Auctions!
http://auctions.yahoo.com
More information about the vtkusers
mailing list