[vtkusers] vtkTexture mapping with grayscale
Tim Hutton
T.Hutton at eastman.ucl.ac.uk
Thu Feb 28 08:09:03 EST 2002
If that doesn't work, try filling the image with vtkUnsignedCharArray
instead of vtkFloatArray. This triggers VTK to treat it as 0-255 grey-level
data and it will render correctly without requiring a lookup table at all.
It took me ages to work this out.
This answer works in vtk4.0. It seems you are using vtk3.2 or earlier, try
calling
scalars->SetDataTypeToUnsignedChar();
before filling with 0-255 grey-levels.
Tim.
At 11:35 28/02/2002 +0100, Fabrice Vincent wrote:
>I don't know where the color comes from but
>you can try to assign the lookuptable to the texture (
>texture->SetLookUpTable(lut))
>instead of the mapper
>
>
>Fabrice
>
>William Jacob Proctor wrote:
>
>>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();
>>
>>}
>>
>>
>>
>>
>>_______________________________________________
>>This is the private VTK discussion list. Please keep messages on-topic.
>>Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
>>Follow this link to subscribe/unsubscribe:
>>http://public.kitware.com/mailman/listinfo/vtkusers
>>
>
>
>
>_______________________________________________
>This is the private VTK discussion list. Please keep messages on-topic.
>Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
>Follow this link to subscribe/unsubscribe:
>http://public.kitware.com/mailman/listinfo/vtkusers
More information about the vtkusers
mailing list