Commit 2ab68e7c authored by Charles Law's avatar Charles Law
Browse files

Not a perfect solution for switching interpolation, but it will work for now.

parent f085fd85
......@@ -50,7 +50,7 @@
#include "vtkPVRenderModule.h"
//----------------------------------------------------------------------------
vtkStandardNewMacro(vtkPVColorMap);
vtkCxxRevisionMacro(vtkPVColorMap, "1.93");
vtkCxxRevisionMacro(vtkPVColorMap, "1.94");
int vtkPVColorMapCommand(ClientData cd, Tcl_Interp *interp,
int argc, char *argv[]);
......@@ -108,6 +108,8 @@ public:
#define VTK_PV_COLOR_MAP_WHITE_SATURATION 0.0
#define VTK_PV_COLOR_MAP_WHITE_VALUE 1.0
#define VTK_USE_LAB_COLOR_MAP 1.1
//***************************************************************************
//===========================================================================
//vtkCxxSetObjectMacro(vtkPVColorMap,PVRenderView,vtkPVRenderView);
......@@ -465,6 +467,9 @@ void vtkPVColorMap::Create(vtkKWApplication *app)
this->PresetsMenuButton->AddCommand(
"Grayscale",
this, "SetColorSchemeToGrayscale", "Set Color Scheme to Grayscale");
this->PresetsMenuButton->AddCommand(
"CIELab Blue to Red",
this, "SetColorSchemeToLabBlueRed", "Set Color Scheme to Lab Blue To Red");
this->PresetsMenuButton->SetImageOption(image_presets,
image_presets_width,
......@@ -1185,33 +1190,73 @@ void vtkPVColorMap::UpdateLookupTable()
// The a hue is arbitrary, make is consistent
// so we do not get unexpected interpolated hues.
if (this->StartHSV[1] == 0.0)
if (this->StartHSV[0]<VTK_USE_LAB_COLOR_MAP)
{
this->StartHSV[0] = this->EndHSV[0];
if (this->StartHSV[1] == 0.0)
{
this->StartHSV[0] = this->EndHSV[0];
}
if (this->EndHSV[1] == 0.0)
{
this->EndHSV[0] = this->StartHSV[0];
}
pm->GetStream() << vtkClientServerStream::Invoke
<< this->LookupTableID << "SetNumberOfTableValues"
<< this->NumberOfColors
<< vtkClientServerStream::End;
pm->GetStream() << vtkClientServerStream::Invoke
<< this->LookupTableID << "SetHueRange"
<< this->StartHSV[0] << this->EndHSV[0]
<< vtkClientServerStream::End;
pm->GetStream() << vtkClientServerStream::Invoke
<< this->LookupTableID << "SetSaturationRange"
<< this->StartHSV[1] << this->EndHSV[1]
<< vtkClientServerStream::End;
pm->GetStream() << vtkClientServerStream::Invoke
<< this->LookupTableID << "SetValueRange"
<< this->StartHSV[2] << this->EndHSV[2]
<< vtkClientServerStream::End;
pm->GetStream() << vtkClientServerStream::Invoke
<< this->LookupTableID << "ForceBuild"
<< vtkClientServerStream::End;
}
if (this->EndHSV[1] == 0.0)
else
{
this->EndHSV[0] = this->StartHSV[0];
//now we need to loop through the number of colors setting the colors
//in the table
pm->GetStream() << vtkClientServerStream::Invoke
<< this->LookupTableID << "SetNumberOfTableValues"
<< this->NumberOfColors
<< vtkClientServerStream::End;
int i;
double rgba[4];
double xyz[3];
double lab[3];
//only use opaque colors
rgba[3]=1;
int numColors=this->NumberOfColors-1;
if (numColors<=0) numColors=1;
for (i=0;i<this->NumberOfColors;i++){
//get the color
for (int j=0;j<3;j++){
lab[j]=this->StartHSV[j]+(this->EndHSV[j]-this->StartHSV[j])/
(numColors)*i;
}
this->LabToXYZ(lab,xyz);
this->XYZToRGB(xyz,rgba);
pm->GetStream() << vtkClientServerStream::Invoke
<< this->LookupTableID << "SetTableValue"
<< i
<< rgba[0] << rgba[1] << rgba[2] << rgba[3]
<< vtkClientServerStream::End;
}
}
pm->GetStream() << vtkClientServerStream::Invoke
<< this->LookupTableID << "SetNumberOfTableValues"
<< this->NumberOfColors
<< vtkClientServerStream::End;
pm->GetStream() << vtkClientServerStream::Invoke
<< this->LookupTableID << "SetHueRange"
<< this->StartHSV[0] << this->EndHSV[0]
<< vtkClientServerStream::End;
pm->GetStream() << vtkClientServerStream::Invoke
<< this->LookupTableID << "SetSaturationRange"
<< this->StartHSV[1] << this->EndHSV[1]
<< vtkClientServerStream::End;
pm->GetStream() << vtkClientServerStream::Invoke
<< this->LookupTableID << "SetValueRange"
<< this->StartHSV[2] << this->EndHSV[2]
<< vtkClientServerStream::End;
pm->GetStream() << vtkClientServerStream::Invoke
<< this->LookupTableID << "ForceBuild"
<< vtkClientServerStream::End;
pm->SendStream(vtkProcessModule::CLIENT|vtkProcessModule::RENDER_SERVER);
if (this->MapWidth > 0 && this->MapHeight > 0)
......@@ -1305,6 +1350,46 @@ void vtkPVColorMap::SetColorSchemeToGrayscale()
this->AddTraceEntry("$kw(%s) SetColorSchemeToGrayscale", this->GetTclName());
}
//----------------------------------------------------------------------------
void vtkPVColorMap::SetColorSchemeToLabBlueRed()
{
this->StartHSV[0]=VTK_USE_LAB_COLOR_MAP;
//first calculate the gradient values
//LabBlue[0]=83.91;
//LabBlue[1]=-8.65;
//LabBlue[2]=-12.18;
this->StartHSV[0]=57.93;
this->StartHSV[1]=-26.85;
this->StartHSV[2]=-30.21;
//LabRed[0]=83.91;
//LabRed[1]=8.65;
//LabRed[2]=12.18;
this->EndHSV[0]=57.93;
this->EndHSV[1]=26.85;
this->EndHSV[2]=30.21;
//this->StartColorButton->SetColor(0.0, 0.0, 1.0);
//this->EndColorButton->SetColor(1.0, 0.0, 0.0);
double rgb[3];
double xyz[3];
double hsv[3];
this->LabToXYZ(this->StartHSV,xyz);
this->XYZToRGB(xyz,rgb);
this->RGBToHSV(rgb,hsv);
this->StartColorButton->SetColor(hsv[0],hsv[1],hsv[2]);
this->LabToXYZ(this->EndHSV,xyz);
this->XYZToRGB(xyz,rgb);
this->RGBToHSV(rgb,hsv);
this->EndColorButton->SetColor(hsv[0],hsv[1],hsv[2]);
//UpdateLookupTable actually makes all the changes
this->UpdateLookupTable();
this->AddTraceEntry("$kw(%s) SetColorSchemeToBlueRed", this->GetTclName());
}
//----------------------------------------------------------------------------
void vtkPVColorMap::StartColorButtonCallback(double r, double g, double b)
{
......@@ -2027,6 +2112,69 @@ void vtkPVColorMap::HSVToRGB(double hsv[3], double rgb[3])
}
}
//----------------------------------------------------------------------------
void vtkPVColorMap::LabToXYZ(double Lab[3], double xyz[3])
{
//LAB to XYZ
double var_Y = ( Lab[0] + 16 ) / 116;
double var_X = Lab[1] / 500 + var_Y;
double var_Z = var_Y - Lab[2] / 200;
if ( pow(var_Y,3) > 0.008856 ) var_Y = pow(var_Y,3);
else var_Y = ( var_Y - 16 / 116 ) / 7.787;
if ( pow(var_X,3) > 0.008856 ) var_X = pow(var_X,3);
else var_X = ( var_X - 16 / 116 ) / 7.787;
if ( pow(var_Z,3) > 0.008856 ) var_Z = pow(var_Z,3);
else var_Z = ( var_Z - 16 / 116 ) / 7.787;
double ref_X = 95.047;
double ref_Y = 100.000;
double ref_Z = 108.883;
xyz[0] = ref_X * var_X; //ref_X = 95.047 Observer= 2 Illuminant= D65
xyz[1] = ref_Y * var_Y; //ref_Y = 100.000
xyz[2] = ref_Z * var_Z; //ref_Z = 108.883
}
//----------------------------------------------------------------------------
void vtkPVColorMap::XYZToRGB(double xyz[3], double rgb[3])
{
double ref_X = 95.047; //Observer = 2 Illuminant = D65
double ref_Y = 100.000;
double ref_Z = 108.883;
double var_X = xyz[0] / 100; //X = From 0 to ref_X
double var_Y = xyz[1] / 100; //Y = From 0 to ref_Y
double var_Z = xyz[2] / 100; //Z = From 0 to ref_Y
double var_R = var_X * 3.2406 + var_Y * -1.5372 + var_Z * -0.4986;
double var_G = var_X * -0.9689 + var_Y * 1.8758 + var_Z * 0.0415;
double var_B = var_X * 0.0557 + var_Y * -0.2040 + var_Z * 1.0570;
if ( var_R > 0.0031308 ) var_R = 1.055 * ( pow(var_R, ( 1 / 2.4 )) ) - 0.055;
else var_R = 12.92 * var_R;
if ( var_G > 0.0031308 ) var_G = 1.055 * ( pow(var_G ,( 1 / 2.4 )) ) - 0.055;
else var_G = 12.92 * var_G;
if ( var_B > 0.0031308 ) var_B = 1.055 * ( pow(var_B, ( 1 / 2.4 )) ) - 0.055;
else var_B = 12.92 * var_B;
rgb[0] = var_R;
rgb[1] = var_G;
rgb[2] = var_B;
//clip colors. ideally we would do something different for colors
//out of gamut, but not really sure what to do atm.
if (rgb[0]<0) rgb[0]=0;
if (rgb[1]<0) rgb[1]=0;
if (rgb[2]<0) rgb[2]=0;
if (rgb[0]>1) rgb[0]=1;
if (rgb[1]>1) rgb[1]=1;
if (rgb[2]>1) rgb[2]=1;
}
//----------------------------------------------------------------------------
void vtkPVColorMap::MapConfigureCallback(int width, int height)
{
......
......@@ -132,6 +132,7 @@ public:
void SetColorSchemeToRedBlue();
void SetColorSchemeToBlueRed();
void SetColorSchemeToGrayscale();
void SetColorSchemeToLabBlueRed();
// Description:
// Choose which component to color with.
......@@ -281,6 +282,9 @@ protected:
void RGBToHSV(double rgb[3], double hsv[3]);
void HSVToRGB(double hsv[3], double rgb[3]);
void LabToXYZ(double Lab[3], double xyz[3]);
void XYZToRGB(double xyz[3], double rgb[3]);
vtkLookupTable* LookupTable;
vtkClientServerID LookupTableID;
......
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