scalars to color mapping

Dingrong Yi yidingr at cim.mcgill.ca
Thu Mar 23 13:00:43 EST 2000


Hi David,

Thanks for you response. But I am not using vtkLookupTable in conjunction
with a vtktexture. I attached my CPP code. Or should I use vtkTexture ?

Thanks again.


#define VTK_USE_PATENTED
#include "/usr/data2/share/vtk2.4/vtk24include/vtk.h"
#include "/usr/data2/share/vtk2.4/vtk24include/vtkDecimate.h"


#include<stdlib.h>
#include<stdio.h>
#include<stream.h>
#include<fstream.h>
#include<math.h>

#define FALSE 0
#define TRUE 1

// Nasty Global Variables
// input parameters
float parLowThresh   = 0.5;
float parHighThresh  = 1.5;
float parColor[3]    = {1.0, 0.0, 0.0};
float parRotation[3] = {0.0, 0.0, 0.0};
float parCamPos[3]   = {0.0, 0.0, 0.0};
float parCamFoc[3]   = {0.0, 0.0, 0.0};
int   parCamera      = FALSE;
float parZoom        = 1.0;
int   parSmooth      = 100;
int   parIterations  = 9; 
char  outName[50];
char  inName[50];
int   outPPM         = TRUE;

int main (int argc, char * argv[])
{
  vtkRenderWindow *renWin;
  vtkRenderer *ren1;
  vtkRenderWindowInteractor *iren;

  // create a window, renderer and interactor
  renWin = vtkRenderWindow::New();
  ren1 = vtkRenderer::New();
  renWin->AddRenderer(ren1);
  renWin->SetSize(500,500);
  iren = vtkRenderWindowInteractor::New();
  iren->SetRenderWindow(renWin);

  // try to read the data
  vtkStructuredPointsReader *aReader;
  aReader = vtkStructuredPointsReader::New();
  aReader->SetFileName(argv[1]);
  aReader->Update();
 
  vtkStructuredPoints *aPoints;
  aPoints = vtkStructuredPoints::New();
  aPoints = aReader->GetOutput();

  float  max = 0;
 for (int i = 0; i < aPoints->GetNumberOfPoints(); i++)
	{
	  if ( aPoints->GetPointData()->GetScalars()->GetScalar(i) > max)
	    {

	      max = aPoints->GetPointData()->GetScalars()->GetScalar(i);
	    }
	}
 cout<<"Maximum value of the input data = "<<max<<endl;

 
 // Extract isosurface
  vtkContourFilter *aContour;
  aContour = vtkContourFilter::New();
  aContour->SetInput(aPoints);
  aContour->ComputeScalarsOff();
  aContour->ComputeGradientsOff();
  aContour->ComputeNormalsOff();
  aContour->UseScalarTreeOn();
  int count = 0;
  for (int i = 0; i <= max;  i = i + 3)
    {
      aContour->SetValue(count, i );
      count = count + 1;
      }



  cout<<"Number of Contours = "<<aContour->GetNumberOfContours()<<endl;
 
  //derive my own lookup table for scalars color mapping.
  vtkLookupTable *Lut = vtkLookupTable::New();
    Lut->SetHueRange (0.0, 0.667);
    Lut->SetSaturationRange (1.0, 1.0);
    Lut->SetValueRange (1.0, 1.0);
    Lut->SetAlphaRange( 1.0, 1.0);
    Lut->SetNumberOfColors(256);
    Lut->Build();
  
  //  map to graphics library
    vtkPolyDataMapper *mapper;
    mapper = vtkPolyDataMapper::New();
    mapper->SetInput(aContour->GetOutput());
    mapper->ScalarVisibilityOn();
    mapper->SetScalarRange(0, max);
    mapper->SetLookupTable(Lut);
  cout<<"Finish mapper to graphics library."<<endl;

  // actor coordinates geometry, properties, transformation
  vtkActor *aObject;
  aObject = vtkActor::New();
  aObject->SetMapper(mapper);
  aObject->Update();
  cout<<"Finish updating the actor."<<endl;

  // Create box around object
  // based on original dimensions of the image
  vtkOutlineFilter *outline;
  outline = vtkOutlineFilter::New();
  outline->SetInput(aReader->GetOutput());
  vtkPolyDataMapper *outlineMapper;
  outlineMapper = vtkPolyDataMapper::New();
  outlineMapper->SetInput(outline->GetOutput());
  vtkActor *outlineActor;
  outlineActor = vtkActor::New();
  outlineActor->SetMapper(outlineMapper);
  outlineActor->GetProperty()->SetColor(0.0, 0.0, 1.0);
  float * bounds;
  bounds = (float *) malloc(sizeof(float)*6);
  bounds = outlineActor->GetBounds();
  float xc = (bounds[1]-bounds[0])/2.0;
  float yc = (bounds[3]-bounds[2])/2.0;
  float zc = (bounds[5]-bounds[4])/2.0;

  cout<<"Origin xc, yc, zc = "<<xc<<"  "<<yc<<" "<<zc<<endl;

  
  // Set Origin of the objects at the same position
  aObject->SetOrigin(xc,yc,zc);
  outlineActor->SetOrigin(xc,yc,zc);

  // Initial rotation
  aObject->RotateWXYZ(parRotation[0],1,0,0);
  aObject->RotateWXYZ(parRotation[1],0,1,0);
  aObject->RotateWXYZ(parRotation[2],0,0,1);

  outlineActor->RotateWXYZ(parRotation[0],1,0,0);
  outlineActor->RotateWXYZ(parRotation[1],0,1,0);
  outlineActor->RotateWXYZ(parRotation[2],0,0,1);
  outlineActor->GetProperty()->SetOpacity(0.3);


  //add actors to the renderer
  ren1->AddActor(aObject);
  ren1->AddActor(outlineActor);

  ren1->SetBackground(1.0,1.0,1.0);  
  cout<<"Back ground color white"<<endl;
  cout<<"Outline color = blue"<<endl;
  cout<<"Ojbect color = Look up table"<<endl;

  //if camera not specified use automatically created setup
  if (parCamera==TRUE) {
    ren1->GetActiveCamera()->SetPosition  (parCamPos[0], parCamPos[1],
parCamPos[2]);
    ren1->GetActiveCamera()->SetFocalPoint(parCamFoc[0], parCamFoc[1],
parCamFoc[2]);
    ren1->GetActiveCamera()->SetViewUp(0,1,0);

  }

  // update the zoom
  ren1->GetActiveCamera()->Zoom(parZoom); 
  
  // Render  
  renWin->Render();
  cout<<"Render " <<endl;

  // Output PPM if asked
  if (outPPM == TRUE) {
    char Name1[50];
    float angle = 360.0/(float) parIterations;
    for (int i=0; i<=parIterations; i++) {  
         cout<<"save "<<i<<"th  scene. "<<endl;
	cout<<"Type in an file name for PPM file: "<<endl;
	cin>>outName;	
	renWin->SetFileName(outName);
      renWin->SaveImageAsPPM();
      aObject->RotateWXYZ((float) angle,0,1,0);
      outlineActor->RotateWXYZ((float)angle,0,1,0);
      //ren1->UpdateActors();
      renWin->Render();
    }
  }
  cout<<"Begin mouse interaction. "<<endl;
  //  Begin mouse interaction
  iren->Start();

  return 0;
}






On Thu, 23 Mar 2000, David Gobbi wrote:

> Hi Dingrong,
> 
> If you are using the vtkLookupTable in conjunction with a
> vtkTexture, you have to use
> 
> texture.MapColorScalarsThroughLookupTableOn()
> 
> otherwise, if you send unsigned-char data to the texture it
> will assume that the data has already been passed through a
> lookup table.
> 
>  - David
> 
> --
>   David Gobbi, MSc                    dgobbi at irus.rri.on.ca
>   Advanced Imaging Research Group
>   Robarts Research Institute, University of Western Ontario
> 
> On Thu, 23 Mar 2000, Dingrong Yi wrote:
> 
> > Hi there,
> > 
> > I noticed one problem of vtk on scalars to color mapping. I have a
> > Structured data sets, with dimensions 63 151 164. I displayed with color
> > table hue range set to 0 0.667, or 0 1 , or 0.667  0. No matter what color
> > range, the displayed image is just gray scale image (indeed, my value
> > range is set to cnstant 1 1). With the same CPP code, several small volume
> > image (16 16 7)  got correct colors.  Is that true that VTK color mapping
> > works incorrectly for bigger volume images ? 
> > 
> > Any body has the same experience ? 
> > 
> > Thanks.
> > 
> > Dingrong
> > 
> > 
> > 
> > --------------------------------------------------------------------
> > This is the private VTK discussion list. Please keep messages on-topic.
> > Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
> > To UNSUBSCRIBE, send message body containing "unsubscribe vtkusers" to
> > <majordomo at public.kitware.com>. For help, send message body containing
> > "info vtkusers" to the same address.
> > --------------------------------------------------------------------
> > 
> 
> 
> 

--------------------------------------------------------------------
This is the private VTK discussion list. Please keep messages on-topic.
Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
To UNSUBSCRIBE, send message body containing "unsubscribe vtkusers" to
<majordomo at public.kitware.com>. For help, send message body containing
"info vtkusers" to the same address.
--------------------------------------------------------------------



More information about the vtkusers mailing list