Commit ec48611c authored by Ken Martin's avatar Ken Martin

New lookuptable superclass

parent 4ff77c77
......@@ -51,15 +51,15 @@ vtkLookupTable::vtkLookupTable(int sze, int ext)
this->Table->SetNumberOfComponents(4);
this->Table->Allocate(4*sze,4*ext);
this->TableRange[0] = 0.0;
this->TableRange[1] = 1.0;
this->HueRange[0] = 0.0;
this->HueRange[1] = 0.66667;
this->SaturationRange[0] = 1.0;
this->SaturationRange[1] = 1.0;
this->TableRange[0] = 0.0;
this->TableRange[1] = 1.0;
this->ValueRange[0] = 1.0;
this->ValueRange[1] = 1.0;
......@@ -74,16 +74,6 @@ vtkLookupTable::~vtkLookupTable()
}
// Allocate a color table of specified size.
int vtkLookupTable::Allocate(int sz, int ext)
{
this->Modified();
this->NumberOfColors = sz;
return this->Table->Allocate(4*this->NumberOfColors,4*ext);
}
// Set the minimum/maximum scalar values for scalar mapping. Scalar values
// less than minimum range value are clamped to minimum range value.
// Scalar values greater than maximum range value are clamped to maximum
// range value.
void vtkLookupTable::SetTableRange(float r[2])
......@@ -95,7 +85,8 @@ void vtkLookupTable::SetTableRange(float r[2])
// less than minimum range value are clamped to minimum range value.
// Scalar values greater than maximum range value are clamped to maximum
// range value.
void vtkLookupTable::SetTableRange(float min, float max)
void vtkLookupTable
::SetTableRange(float min, float max)
{
if ( min >= max )
{
......@@ -107,6 +98,15 @@ void vtkLookupTable::SetTableRange(float min, float max)
this->TableRange[1] = max;
}
// Allocate a color table of specified size.
int vtkLookupTable::Allocate(int sz, int ext)
{
this->Modified();
this->NumberOfColors = sz;
return this->Table->Allocate(4*this->NumberOfColors,4*ext);
}
// Generate lookup table from hue, saturation, value, alpha min/max values.
// Table is built from linear ramp of each value.
void vtkLookupTable::Build()
......@@ -248,7 +248,7 @@ static void vtkLookupTableMapDataToRGBA(vtkLookupTable *self, T *input,
}
}
void vtkLookupTable::MapScalarsThroughTable(void *input,
void vtkLookupTable::MapScalarsThroughTable2(void *input,
unsigned char *output,
int inputDataType,
int numberOfValues,
......@@ -302,17 +302,6 @@ void vtkLookupTable::MapScalarsThroughTable(void *input,
}
}
// Map a set of scalar values through the table
void vtkLookupTable::MapScalarsThroughTable(vtkScalars *scalars,
unsigned char *output)
{
this->MapScalarsThroughTable(scalars->GetVoidPointer(0),
output,
scalars->GetDataType(),
scalars->GetNumberOfScalars(),
scalars->GetNumberOfComponents());
}
// Specify the number of values (i.e., colors) in the lookup
// table. This method simply allocates memory and prepares the table
// for use with SetTableValue(). It differs from Build() method in
......@@ -385,17 +374,17 @@ void vtkLookupTable::GetTableValue (int indx, float rgba[4])
void vtkLookupTable::PrintSelf(ostream& os, vtkIndent indent)
{
vtkObject::PrintSelf(os,indent);
vtkScalarsToColors::PrintSelf(os,indent);
os << indent << "Build Time: " <<this->BuildTime.GetMTime() << "\n";
os << indent << "Table Range: (" << this->TableRange[0] << ", "
<< this->TableRange[1] << ")\n";
os << indent << "Hue Range: (" << this->HueRange[0] << ", "
<< this->HueRange[1] << ")\n";
os << indent << "Insert Time: " <<this->InsertTime.GetMTime() << "\n";
os << indent << "Number Of Colors: " << this->GetNumberOfColors() << "\n";
os << indent << "Saturation Range: (" << this->SaturationRange[0] << ", "
<< this->SaturationRange[1] << ")\n";
os << indent << "Table Range: (" << this->TableRange[0] << ", "
<< this->TableRange[1] << ")\n";
os << indent << "Value Range: (" << this->ValueRange[0] << ", "
<< this->ValueRange[1] << ")\n";
os << indent << "Alpha Range: (" << this->AlphaRange[0] << ", "
......
......@@ -61,19 +61,17 @@ MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
#ifndef __vtkLookupTable_h
#define __vtkLookupTable_h
#include "vtkObject.h"
#include "vtkUnsignedCharArray.h"
#include "vtkScalarsToColors.h"
class vtkScalars;
class VTK_EXPORT vtkLookupTable : public vtkObject
class VTK_EXPORT vtkLookupTable : public vtkScalarsToColors
{
public:
// Description:
// Construct with range=(0,1); and hsv ranges set up for rainbow color table
// (from red to blue).
vtkLookupTable(int sze=256, int ext=256);
~vtkLookupTable();
// Description:
......@@ -135,10 +133,9 @@ public:
// Description:
// map a set of scalars through the lookup table
virtual void MapScalarsThroughTable(void *input, unsigned char *output,
virtual void MapScalarsThroughTable2(void *input, unsigned char *output,
int inputDataType, int numberOfValues,
int inputIncrement);
void MapScalarsThroughTable(vtkScalars *scalars, unsigned char *output);
// Description:
// Specify the number of values (i.e., colors) in the lookup
......@@ -179,6 +176,11 @@ public:
// wish to write into; number is the number of rgba values to write.
unsigned char *WritePointer(const int id, const int number);
// Description:
// Sets/Gets the range of scalars which will eb mapped.
virtual float *GetRange() {return this->GetTableRange();};
virtual void SetRange(float min, float max) {this->SetTableRange(min,max);};
protected:
int NumberOfColors;
vtkUnsignedCharArray *Table;
......
......@@ -225,7 +225,7 @@ double vtkScalars::GetDataTypeMax()
}
}
int vtkScalars::InitColorTraversal(float alpha, vtkLookupTable *lut,
int vtkScalars::InitColorTraversal(float alpha, vtkScalarsToColors *lut,
int colorMode)
{
int numComp=this->GetNumberOfComponents();
......
......@@ -73,6 +73,7 @@ class vtkIdList;
class vtkScalars;
class vtkLookupTable;
class vtkUnsignedCharArray;
class vtkScalarsToColors;
class VTK_EXPORT vtkScalars : public vtkAttributeData
{
......@@ -185,7 +186,7 @@ public:
// blending will occur. Also takes a lookup table used to map the
// scalar data. The color mode parameter controls how the scalar data
// is mapped to colors (see vtkMapper::ColorMode methods for a definition).
int InitColorTraversal(float alpha, vtkLookupTable *lut,
int InitColorTraversal(float alpha, vtkScalarsToColors *lut,
int colorMode=VTK_COLOR_MODE_DEFAULT);
// Description:
......@@ -210,7 +211,7 @@ protected:
// following stuff is used for converting scalars to colors
float CurrentAlpha;
vtkLookupTable *CurrentLookupTable;
vtkScalarsToColors *CurrentLookupTable;
//BTX
unsigned char *(vtkScalars::*CurrentColorFunction)(int id);
unsigned char *PassRGBA(int id);
......
......@@ -137,21 +137,17 @@ int vtkActor::GetIsOpaque()
{
if (this->Property->GetOpacity() >= 1.0)
{
float *ar = this->Mapper->GetLookupTable()->GetAlphaRange();
if ((ar[0] >= 1.0)&&(ar[1] >= 1.0))
if (this->Texture && this->Texture->GetInput())
{
if (this->Texture && this->Texture->GetInput())
{
this->Texture->GetInput()->Update();
if (this->Texture->GetInput()->GetPointData()->GetScalars()->GetNumberOfComponents()%2)
{
return 1;
}
}
else
{
return 1;
}
this->Texture->GetInput()->Update();
if (this->Texture->GetInput()->GetPointData()->GetScalars()->GetNumberOfComponents()%2)
{
return 1;
}
}
else
{
return 1;
}
}
return 0;
......
......@@ -200,6 +200,19 @@ void vtkColorTransferFunction::AddRGBSegment( float x1, float r1,
this->UpdateRange();
}
// Returns the RGB color evaluated at the specified location
unsigned char *vtkColorTransferFunction::MapValue( float x )
{
this->ColorValue2[0] = (unsigned char)
(255.0*this->Red->GetValue( x ));
this->ColorValue2[1] = (unsigned char)
(255.0*this->Green->GetValue( x ));
this->ColorValue2[2] = (unsigned char)
(255.0*this->Blue->GetValue( x ));
this->ColorValue2[3] = 1.0;
return( this->ColorValue2 );
}
// Returns the RGB color evaluated at the specified location
float *vtkColorTransferFunction::GetValue( float x )
{
......@@ -293,7 +306,7 @@ void vtkColorTransferFunction::GetTable( float x1, float x2,
// Print method for vtkColorTransferFunction
void vtkColorTransferFunction::PrintSelf(ostream& os, vtkIndent indent)
{
vtkObject::PrintSelf(os, indent);
vtkScalarsToColors::PrintSelf(os, indent);
os << indent << "Color Transfer Function Total Points: " << this->GetTotalSize() << "\n";
......@@ -330,3 +343,96 @@ void vtkColorTransferFunction::DeepCopy( vtkColorTransferFunction *f )
this->Clamping = f->Clamping;
this->UpdateRange();
}
// accelerate the mapping by copying the data in 32-bit chunks instead
// of 8-bit chunks
template<class T>
static void
vtkColorTransferFunctionMapDataToRGBA(vtkColorTransferFunction *self,
T *input,
unsigned char *output,
int length, int incr)
{
float findx;
int i = length;
vtkPiecewiseFunction *R, *G, *B;
R = self->GetRedFunction();
G = self->GetGreenFunction();
B = self->GetBlueFunction();
while (--i >= 0)
{
findx = *input;
*output++ = R->GetValue(findx);
*output++ = G->GetValue(findx);
*output++ = B->GetValue(findx);
*output++ = 255;
input += incr;
}
}
void vtkColorTransferFunction::MapScalarsThroughTable2(void *input,
unsigned char *output,
int inputDataType,
int numberOfValues,
int inputIncrement)
{
switch (inputDataType)
{
case VTK_CHAR:
vtkColorTransferFunctionMapDataToRGBA(this,(char *)input,output,
numberOfValues,inputIncrement);
break;
case VTK_UNSIGNED_CHAR:
vtkColorTransferFunctionMapDataToRGBA(this,(unsigned char *)input,
output,numberOfValues,
inputIncrement);
break;
case VTK_SHORT:
vtkColorTransferFunctionMapDataToRGBA(this,(short *)input,output,
numberOfValues,inputIncrement);
break;
case VTK_UNSIGNED_SHORT:
vtkColorTransferFunctionMapDataToRGBA(this,(unsigned short *)input,
output,numberOfValues,
inputIncrement);
break;
case VTK_INT:
vtkColorTransferFunctionMapDataToRGBA(this,(int *)input,output,
numberOfValues,inputIncrement);
break;
case VTK_UNSIGNED_INT:
vtkColorTransferFunctionMapDataToRGBA(this,(unsigned int *)input,output,
numberOfValues,inputIncrement);
break;
case VTK_LONG:
vtkColorTransferFunctionMapDataToRGBA(this,(long *)input,output,
numberOfValues,inputIncrement);
break;
case VTK_UNSIGNED_LONG:
vtkColorTransferFunctionMapDataToRGBA(this,(unsigned long *)input,output,
numberOfValues,inputIncrement);
break;
case VTK_FLOAT:
vtkColorTransferFunctionMapDataToRGBA(this,(float *)input,output,
numberOfValues,inputIncrement);
break;
case VTK_DOUBLE:
vtkColorTransferFunctionMapDataToRGBA(this,(double *)input,output,
numberOfValues,inputIncrement);
break;
default:
vtkErrorMacro(<< "MapImageThroughTable: Unknown input ScalarType");
return;
}
}
......@@ -50,10 +50,10 @@ MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
#ifndef __vtkColorTransferFunction_h
#define __vtkColorTransferFunction_h
#include "vtkObject.h"
#include "vtkScalarsToColors.h"
#include "vtkPiecewiseFunction.h"
class VTK_EXPORT vtkColorTransferFunction : public vtkObject
class VTK_EXPORT vtkColorTransferFunction : public vtkScalarsToColors
{
public:
vtkColorTransferFunction();
......@@ -116,15 +116,20 @@ public:
float GetGreenValue( float x ) { return this->Green->GetValue( x ); };
float GetBlueValue( float x ) { return this->Blue->GetValue( x ); };
// Description:
// Map one value through the lookup table.
virtual unsigned char *MapValue(float v);
// Description:
// Returns min and max position of all function points.
// The set method does nothing.
float *GetRange();
virtual void SetRange(float, float) {};
// Description:
// Fills in a table of n function values between x1 and x2
void GetTable( float x1, float x2, int n, float* table );
// Description:
// Sets and gets the clamping value for this transfer function.
void SetClamping(int val);
......@@ -135,6 +140,12 @@ public:
vtkPiecewiseFunction *GetRedFunction(){return this->Red;};
vtkPiecewiseFunction *GetGreenFunction(){return this->Green;};
vtkPiecewiseFunction *GetBlueFunction(){return this->Blue;};
// Description:
// map a set of scalars through the lookup table
virtual void MapScalarsThroughTable2(void *input, unsigned char *output,
int inputDataType, int numberOfValues,
int inputIncrement);
protected:
// Determines the function value outside of defined points
......@@ -151,6 +162,7 @@ protected:
// An evaluated color
float ColorValue[3];
unsigned char ColorValue2[4];
// The min and max point locations for all three transfer functions
float Range[2];
......
......@@ -39,6 +39,7 @@ MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
=========================================================================*/
#include "vtkMapper.h"
#include "vtkLookupTable.h"
// Initialize static member that controls global immediate mode rendering
static int vtkMapperGlobalImmediateModeRendering = 0;
......@@ -169,7 +170,7 @@ vtkScalars *vtkMapper::GetColors()
}
// Setup mapper/scalar object for color generation
this->LookupTable->SetTableRange(this->ScalarRange);
this->LookupTable->SetRange(this->ScalarRange);
if (this->Colors)
{
this->Colors->Delete();
......@@ -192,7 +193,7 @@ vtkScalars *vtkMapper::GetColors()
}
// Specify a lookup table for the mapper to use.
void vtkMapper::SetLookupTable(vtkLookupTable *lut)
void vtkMapper::SetLookupTable(vtkScalarsToColors *lut)
{
if ( this->LookupTable != lut )
{
......@@ -209,7 +210,7 @@ void vtkMapper::SetLookupTable(vtkLookupTable *lut)
}
}
vtkLookupTable *vtkMapper::GetLookupTable()
vtkScalarsToColors *vtkMapper::GetLookupTable()
{
if ( this->LookupTable == NULL )
{
......
......@@ -73,7 +73,7 @@ MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
#define __vtkMapper_h
#include "vtkAbstractMapper.h"
#include "vtkLookupTable.h"
#include "vtkScalarsToColors.h"
#include "vtkDataSet.h"
#define VTK_SCALAR_MODE_DEFAULT 0
......@@ -111,8 +111,8 @@ public:
// Description:
// Specify a lookup table for the mapper to use.
void SetLookupTable(vtkLookupTable *lut);
vtkLookupTable *GetLookupTable();
void SetLookupTable(vtkScalarsToColors *lut);
vtkScalarsToColors *GetLookupTable();
// Description:
// Create default lookup table. Generally used to create one when none
......@@ -213,14 +213,10 @@ public:
void SetRenderTime(float time) {this->RenderTime = time;}
vtkGetMacro(RenderTime, float);
// Description:
// For legacy compatibility. Do not use.
void SetLookupTable(vtkLookupTable& lut) {this->SetLookupTable(&lut);}
protected:
vtkScalars *Colors;
vtkLookupTable *LookupTable;
vtkScalarsToColors *LookupTable;
int ScalarVisibility;
vtkTimeStamp BuildTime;
float ScalarRange[2];
......
......@@ -88,7 +88,7 @@ static void vtkImageMapToRGBAExecute(vtkImageMapToRGBA *self,
int scalarSize = inData->GetScalarSize();
int numberOfComponents;
int rowLength;
vtkLookupTable *lookupTable = self->GetLookupTable();
vtkScalarsToColors *lookupTable = self->GetLookupTable();
unsigned char *outPtr1;
void *inPtr1;
......@@ -121,7 +121,7 @@ static void vtkImageMapToRGBAExecute(vtkImageMapToRGBA *self,
}
count++;
}
lookupTable->MapScalarsThroughTable(inPtr1,(unsigned char *)outPtr1,
lookupTable->MapScalarsThroughTable2(inPtr1,(unsigned char *)outPtr1,
dataType,extX,numberOfComponents);
outPtr1 += outIncY + extX*4;
inPtr1 = (void *) ((char *) inPtr1 + inIncY + rowLength);
......
......@@ -52,7 +52,7 @@ MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
#include "vtkImageFilter.h"
#include "vtkLookupTable.h"
#include "vtkScalarsToColors.h"
class VTK_EXPORT vtkImageMapToRGBA : public vtkImageFilter
{
......@@ -63,11 +63,11 @@ public:
const char *GetClassName() {return "vtkImageMapToRGBA";};
void PrintSelf(ostream& os, vtkIndent indent);
vtkSetObjectMacro(LookupTable,vtkLookupTable);
vtkGetObjectMacro(LookupTable,vtkLookupTable);
vtkSetObjectMacro(LookupTable,vtkScalarsToColors);
vtkGetObjectMacro(LookupTable,vtkScalarsToColors);
protected:
vtkLookupTable *LookupTable;
vtkScalarsToColors *LookupTable;
void ExecuteImageInformation();
void ThreadedExecute(vtkImageData *inData, vtkImageData *outData,
......
......@@ -50,6 +50,8 @@ MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
#include "vtkXPolyDataMapper2D.h"
#endif
#include "vtkLookupTable.h"
vtkPolyDataMapper2D::vtkPolyDataMapper2D()
{
this->Input = NULL;
......@@ -160,7 +162,7 @@ vtkScalars *vtkPolyDataMapper2D::GetColors()
}
// Setup mapper/scalar object for color generation
this->LookupTable->SetTableRange(this->ScalarRange);
this->LookupTable->SetRange(this->ScalarRange[0], this->ScalarRange[1]);
if (this->Colors)
{
this->Colors->Delete();
......@@ -183,7 +185,7 @@ vtkScalars *vtkPolyDataMapper2D::GetColors()
}
// Specify a lookup table for the mapper to use.
void vtkPolyDataMapper2D::SetLookupTable(vtkLookupTable *lut)
void vtkPolyDataMapper2D::SetLookupTable(vtkScalarsToColors *lut)
{
if ( this->LookupTable != lut )
{
......@@ -200,7 +202,7 @@ void vtkPolyDataMapper2D::SetLookupTable(vtkLookupTable *lut)
}
}
vtkLookupTable *vtkPolyDataMapper2D::GetLookupTable()
vtkScalarsToColors *vtkPolyDataMapper2D::GetLookupTable()
{
if ( this->LookupTable == NULL )
{
......
......@@ -61,7 +61,7 @@ MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
#include "vtkViewport.h"
#include "vtkActor2D.h"
#include "vtkProperty2D.h"
#include "vtkLookupTable.h"
#include "vtkScalarsToColors.h"
#include "vtkPolyData.h"
class VTK_EXPORT vtkPolyDataMapper2D : public vtkMapper2D
......@@ -80,8 +80,8 @@ public:
// Description:
// Specify a lookup table for the mapper to use.
void SetLookupTable(vtkLookupTable *lut);
vtkLookupTable *GetLookupTable();
void SetLookupTable(vtkScalarsToColors *lut);
vtkScalarsToColors *GetLookupTable();
// Description:
// Create default lookup table. Generally used to create one when none
......@@ -138,14 +138,10 @@ public:
vtkSetObjectMacro(TransformCoordinate, vtkCoordinate);
vtkGetObjectMacro(TransformCoordinate, vtkCoordinate);
// Description:
// Obsolete methods for legacy compatability. Do not use.
void SetLookupTable(vtkLookupTable& lut) {this->SetLookupTable(&lut);};
protected:
vtkPolyData* Input;
vtkScalars *Colors;
vtkLookupTable *LookupTable;
vtkScalarsToColors *LookupTable;
int ScalarVisibility;
vtkTimeStamp BuildTime;
float ScalarRange[2];
......
......@@ -249,11 +249,10 @@ int vtkScalarBarActor::RenderOpaqueGeometry(vtkViewport *viewport)
// Build scalar bar object
//
vtkLookupTable *lut = this->LookupTable;
int numLutColors = lut->GetNumberOfColors();
int numColors = (numLutColors > this->MaximumNumberOfColors ?
this->MaximumNumberOfColors : numLutColors);
float *range = lut->GetTableRange();
vtkScalarsToColors *lut = this->LookupTable;
// we hard code how many steps to display
int numColors = this->MaximumNumberOfColors;
float *range = lut->GetRange();
int numPts = 2*(numColors + 1);
vtkPoints *pts = vtkPoints::New();
......@@ -404,7 +403,8 @@ int vtkScalarBarActor::RenderOpaqueGeometry(vtkViewport *viewport)
ptIds[3] = ptIds[0] + 2;
polys->InsertNextCell(4,ptIds);
rgba = lut->GetPointer((int)((float)numLutColors*i/numColors));
rgba = lut->MapValue(range[0] + (range[1] - range[0])*
((float)i /(numColors-1.0)));
rgb = colorData->GetPointer(3*i); //write into array directly
rgb[0] = rgba[0];
rgb[1] = rgba[1];
......
......@@ -46,7 +46,7 @@ MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
// vtkScalarBarActor is a subclass of vtkActor2D, it is drawn in the image
// plane (i.e., in the renderer's viewport) on top of the 3D graphics window.
//
// To use vtkScalarBarActor you must associate a vtkLookupTable (or
// To use vtkScalarBarActor you must associate a vtkScalarsToColors (or
// subclass) with it. The lookup table defines the colors and the
// range of scalar values used to map scalar data. Typically, the
// number of colors shown in the scalar bar is not equal to the number
......@@ -73,7 +73,7 @@ MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
#define __vtkScalarBarActor_h
#include "vtkActor2D.h"
#include "vtkLookupTable.h"
#include "vtkScalarsToColors.h"
#include "vtkPolyDataMapper2D.h"
#include "vtkTextMapper.h"
......@@ -117,8 +117,8 @@ public:
// Set/Get the vtkLookupTable to use. The lookup table specifies the number
// of colors to use in the table (if not overridden), as well as the scalar
// range.
vtkSetObjectMacro(LookupTable,vtkLookupTable);
vtkGetObjectMacro(LookupTable,vtkLookupTable);
vtkSetObjectMacro(LookupTable,vtkScalarsToColors);
vtkGetObjectMacro(LookupTable,vtkScalarsToColors);
// Description:
// Set/Get the height and width of the scalar bar. The value is expressed
......@@ -190,7 +190,7 @@ public:
vtkGetStringMacro(Title);
protected:
vtkLookupTable *LookupTable;
vtkScalarsToColors *LookupTable;
int MaximumNumberOfColors;
int NumberOfLabels;
int NumberOfLabelsBuilt;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment