[vtkusers] vtkTexture mapping with grayscale
William Jacob Proctor
wjprocto at uncc.edu
Wed Feb 27 14:34:02 EST 2002
I am trying to map a 2D texture onto a plane in grayscale but I can't seem
to keep it from mapping to colors. Can anyone tell me where the color is
coming from in the code below and how I could make the mapping grayscale?
Thanks!
-- Jake
#include <stdio.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkInteractorStyleTrackball.h>
#include <vtkScalars.h>
#include <vtkStructuredPoints.h>
#include <vtkPlaneSource.h>
#include <vtkLookupTable.h>
main()
{
vtkStructuredPoints *image2d = vtkStructuredPoints::New();
image2d->SetDimensions (256,256,1);
vtkScalars *s = vtkScalars::New(VTK_INT, 1);
s->SetNumberOfScalars (65536);
int j, k;
for (j = k = 0; k < 65536; k++)
{
s->SetScalar (j++, k);
}
image2d->GetPointData()->SetScalars (s);
vtkPlaneSource *plane2d = vtkPlaneSource::New();
plane2d->SetXResolution (1);
plane2d->SetYResolution (1);
vtkLookupTable *lut = vtkLookupTable::New();
// lut->SetTableRange (0, 1000);
lut->SetHueRange (0., 0.);
lut->SetSaturationRange (0., 0.);
lut->SetValueRange(0., 1.);
vtkPolyDataMapper *mapper2d = vtkPolyDataMapper::New();
mapper2d->SetInput (plane2d->GetOutput());
mapper2d->ScalarVisibilityOff();
mapper2d->ImmediateModeRenderingOn();
mapper2d->SetLookupTable (lut);
vtkTexture *texture2d = vtkTexture::New();
texture2d->SetInput (image2d);
texture2d->MapColorScalarsThroughLookupTableOff();
vtkActor *actor2d = vtkActor::New();
actor2d->SetMapper (mapper2d);
actor2d->SetTexture (texture2d);
// actor2d->GetProperty()->SetColor (0., 0., 1.);
vtkRenderer *renderer2d = vtkRenderer::New();
renderer2d->SetBackground (0.1, 0.1, 0.1);
renderer2d->AddActor (actor2d);
vtkRenderWindow *canvas2d = vtkRenderWindow::New();
canvas2d->AddRenderer (renderer2d);
canvas2d->SetSize (256, 256);
vtkInteractorStyleTrackball
*trackball2d = vtkInteractorStyleTrackball::New();
trackball2d->SetTrackballModeToTrackball();
vtkRenderWindowInteractor
*interactor2d =
vtkRenderWindowInteractor::New();
interactor2d->SetRenderWindow (canvas2d);
interactor2d->SetInteractorStyle (trackball2d);
interactor2d->Start();
}
More information about the vtkusers
mailing list