VTK/Examples/Cxx/Utilities/ColorTransferFunction

From KitwarePublic

Jump to: navigation, search

This example demonstrates how to map the values (0.0 to 10.0) to the colors (red to green).

ColorTransferFunction.cxx

#include <vtkSmartPointer.h>
#include <vtkColorTransferFunction.h>
 
int main(int, char *[])
{
  vtkSmartPointer<vtkColorTransferFunction> colorTransferFunction = 
    vtkSmartPointer<vtkColorTransferFunction>::New();
 
  colorTransferFunction->AddRGBPoint(0.0, 1, 0, 0);
  colorTransferFunction->AddRGBPoint(10.0, 0, 1, 0);
 
  double color[3];
  colorTransferFunction->GetColor(1.0, color);
  std::cout << color[0] << " " << color[1] << " " << color[2] << std::endl;
 
  colorTransferFunction->GetColor(5.0, color);
  std::cout << color[0] << " " << color[1] << " " << color[2] << std::endl;
 
  return EXIT_SUCCESS;
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.6)
 
PROJECT(ColorTransferFunction)
 
FIND_PACKAGE(VTK REQUIRED)
INCLUDE(${VTK_USE_FILE})
 
ADD_EXECUTABLE(ColorTransferFunction ColorTransferFunction.cxx)
TARGET_LINK_LIBRARIES(ColorTransferFunction vtkHybrid vtkInfovis)
Personal tools