[vtkusers] greyscale/color rendering
    anast.jm at pg.com 
    anast.jm at pg.com
       
    Mon Oct 28 10:26:10 EST 2002
    
    
  
Chunyan,
The reason your volume renders in color is that you have assigned colors to your
color transfer function. If you make all the rgb values equal (that is r=g=b)
you will get a grayscale rendering
vtkColorTransferFunction::New();
    colorTransferFunction->AddRGBPoint(0.0, 0.0, 0.0, 0.0);
    colorTransferFunction->AddRGBPoint(64.0, 1.0, 0.0, 0.0);  red => 1.0, 1.0,
1.0 white
    colorTransferFunction->AddRGBPoint(128.0, 0.0, 0.0, 1.0); blue => 1.0, 1.0,
1.0 white
    colorTransferFunction->AddRGBPoint(192.0, 0.0, 1.0, 0.0); green => 1.0, 1.0,
1.0 white
    colorTransferFunction->AddRGBPoint(255.0, 0.0, 0.2, 0.0); pale green => 0.2,
0.2, 0.2 light gray
You might want to try a gray ramp if this doesn't look very good
(0.0, 0.0, 0.0, 0.0);
(64.0, 0.2, 0.2, 0.2);
(128.0, 0.4, 0.4, 0.4);
(192.0, 0.7, 1.7, 0.7);
(255.0, 1.0, 1.0, 1.0);
john
                                                                
 Internet Mail Message                                          
 Received from host:      public.kitware.com                    
 [24.97.130.19]                                                 
                                                                
From: "Chunyan Jiang" <jiang at TI.FhG.DE>@public.kitware.com on 10/28/2002 11:37
AM CET
                                                                                           
    "Chunyan Jiang" <jiang at TI.FhG.DE>           To:   "VTK-User"                           
                  @public.kitware.com        <vtkusers at public.kitware.com>                 
                                                Cc:    (bcc: John Anast-JM/PGI)            
                                        Subject:      [vtkusers] greyscale/color           
                             Sent by:                                                      
    vtkusers-admin at public.kitware.com                                                      
                  10/28/2002 05:37 AM                                                      
                                                                                           
                                                                                           
Dear VTK friends,
I import the greyscale image data from memery to vtkImageImport, then
transform the vtkImageImport to vtkStructuredPoints by
vtkImageToStructuredPoints. After that I use vtkVolumeRayCastMapper to
render the volume. It works now, however, the greyscale image changes to
color image. How can I render grey image? I attach the code below. Is there
something wrong? Any help is appreciated.
Code:
     vtkImageImport *importer = vtkImageImport::New();
     importer->SetWholeExtent(1,dimensions[0],1,dimensions[1],1,dimensions[2]);
     importer->SetDataExtentToWholeExtent();
     importer->SetDataScalarTypeToUnsignedChar();
     importer->SetDataOrigin(0,0,0);
    importer->SetDataSpacing(1,1,1);
     importer->SetImportVoidPointer(data);//data is unsigned char* that storing
greyscale images data
     vtkStructuredPoints* structPts= vtkStructuredPoints::New();
     vtkImageToStructuredPoints* its=vtkImageToStructuredPoints::New();
     its->SetInput(importer->GetOutput());
     structPts=its->GetOutput();
// Create transfer mapping scalar value to opacity
     vtkPiecewiseFunction *opacityTransferFunction =
vtkPiecewiseFunction::New();
    opacityTransferFunction->AddPoint(20, 0.0);
    opacityTransferFunction->AddPoint(255, 0.2);
// Create transfer mapping scalar value to color
     vtkColorTransferFunction *colorTransferFunction =
vtkColorTransferFunction::New();
    colorTransferFunction->AddRGBPoint(0.0, 0.0, 0.0, 0.0);
    colorTransferFunction->AddRGBPoint(64.0, 1.0, 0.0, 0.0);
    colorTransferFunction->AddRGBPoint(128.0, 0.0, 0.0, 1.0);
    colorTransferFunction->AddRGBPoint(192.0, 0.0, 1.0, 0.0);
    colorTransferFunction->AddRGBPoint(255.0, 0.0, 0.2, 0.0);
// The property describes how the data will look
     vtkVolumeProperty *volumeProperty = vtkVolumeProperty::New();
    volumeProperty->SetColor(colorTransferFunction);
    volumeProperty->SetScalarOpacity(opacityTransferFunction);
// The mapper / ray cast function know how to render the data
     vtkVolumeRayCastCompositeFunction *compositeFunction=
vtkVolumeRayCastCompositeFunction::New();
     vtkVolumeRayCastMapper *volumeMapper=vtkVolumeRayCastMapper::New();
    volumeMapper->SetVolumeRayCastFunction(compositeFunction);
    volumeMapper->SetInput(structPts);//sp reader->GetOutput()
// The volume holds the mapper and the property and can be used to
position/orient the volume
     vtkVolume *volume = vtkVolume::New();
    volume->SetMapper(volumeMapper);
    volume->SetProperty(volumeProperty);
     renderer->AddActor(volume);
  // interact with data
  renWin->Render();
***********************************************************************
Chunyan Jiang, Dipl.-Inform.,
Institut for Telematic
Bahnhofstrasse 30-32, D-54292 Trier, Germany
Phone: (+49) (0)651-97551-34
Fax: (+49) (0)651-97551-12
***********************************************************************
_______________________________________________
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