[vtkusers] LookupTable show greyscale colour only
    Clement.Chu at csiro.au 
    Clement.Chu at csiro.au
       
    Thu Jul 28 08:24:18 EDT 2011
    
    
  
Hi,
   I used the following code to display image data, but I have no idea why I cannot show colour.
         unsigned char* ptr;  // used defined data
         int nx, ny, nx;
	vtkImageData vtkData = vtkImageData::New();
        vtkData->SetDimensions(nx, ny, nz);
	vtkData->GetPointData()->GetScalars()->SetVoidArray(ptr, (nx * ny * nz), 1);
	vtkData->SetScalarTypeToUnsignedChar();
	vtkData->AllocateScalars();
	vtkLookupTable vtkColourMap = vtkLookupTable::New();
	vtkColourMap->SetNumberOfTableValues(256);
	vtkColourMap->SetTableRange(0, 255);
	vtkDataSetMapper vtkMapper = vtkDataSetMapper::New();
	vtkMapper->SetInput(vtkData);
	vtkMapper->SetLookupTable(vtkColourMap);
	vtkActor vtkMapperActor = vtkActor::New();
	vtkMapperActor->SetMapper(vtkMapper);
	
        vtkRenderer vtkRender = vtkRenderer::New();
	vtkRender->AddActor(vtkMapperActor);
	vtkRender->SetBackground(0.0, 0.0, 0.0);
	
	vtkWin32OpenGLRenderWindow vtkViewer = vtkWin32OpenGLRenderWindow::New();
	vtkViewer->SetParentId(m_hWnd);
	vtkViewer->AddRenderer(vtkRender);
	vtkWin32RenderWindowInteractor *renderWindowInteractor = vtkWin32RenderWindowInteractor::New();
	renderWindowInteractor->SetRenderWindow(vtkViewer);
	renderWindowInteractor->Initialize();
   The above codes are used to initial the viewer.  After that, I will create colour map table by "SetTableValue" function.  Then I will read my data file and assign the unsiged char value into "ptr".  Finally calling the following codes to update the data.
		vtkData->GetPointData()->GetScalars()->Modified();
		vtkViewer->Render();
   My problem is that the above codes can show greyscale colour.  If I used vtkVolumeRayCastMapper and vtkColorTransferFunction, I can display the colour I wanted.  I wonder why I can't use lookup table to set colour.
Clement
    
    
More information about the vtkusers
mailing list