Commit 5d7ab890 authored by Ken Martin's avatar Ken Martin
Browse files

Add in support for below and above range LUTs

Copy changes Cory made to support below and above range
colors in lookup tables into the general Mapper routines.
The new OpenGL backend uses the code in Mapper as opposed
to the code in ScalarsToColorsPainter.  This fixed failing
tests in paraview.

Also a minor compiler warning fix.

Change-Id: Icff4a9804eb051ecccae2590dabe20da162c1747
parent 745b80c8
......@@ -18,6 +18,7 @@
#include "vtkColorSeries.h"
#include "vtkDataArray.h"
#include "vtkDataSet.h"
#include "vtkDoubleArray.h"
#include "vtkExecutive.h"
#include "vtkLookupTable.h"
#include "vtkFloatArray.h"
......@@ -619,9 +620,18 @@ void CreateColorTextureCoordinates(T* input, float* output,
vtkIdType numScalars, int numComps,
int component, double* range,
const double* table_range,
int tableNumberOfColors,
bool use_log_scale)
{
double inv_range_width = 1.0 / (range[1]-range[0]);
// We have to change the range used for computing texture
// coordinates slightly to accomodate the special above- and
// below-range colors that are the first and last texels,
// respectively.
double scalar_texel_width = (range[1] - range[0]) / static_cast<double>(tableNumberOfColors);
double padded_range[2];
padded_range[0] = range[0] - scalar_texel_width;
padded_range[1] = range[1] + scalar_texel_width;
double inv_range_width = 1.0 / (padded_range[1] - padded_range[0]);
if (component < 0 || component >= numComps)
{
......@@ -640,7 +650,7 @@ void CreateColorTextureCoordinates(T* input, float* output,
magnitude = vtkLookupTable::ApplyLogScale(
magnitude, table_range, range);
}
ScalarToTextureCoordinate(magnitude, range[0], inv_range_width,
ScalarToTextureCoordinate(magnitude, padded_range[0], inv_range_width,
output[0], output[1]);
output += 2;
}
......@@ -656,7 +666,7 @@ void CreateColorTextureCoordinates(T* input, float* output,
input_value = vtkLookupTable::ApplyLogScale(
input_value, table_range, range);
}
ScalarToTextureCoordinate(input_value, range[0], inv_range_width,
ScalarToTextureCoordinate(input_value, padded_range[0], inv_range_width,
output[0], output[1]);
output += 2;
input = input + numComps;
......@@ -666,7 +676,6 @@ void CreateColorTextureCoordinates(T* input, float* output,
} // end anonymous namespace
#define ColorTextureMapSize 256
// a side effect of this is that this->ColorCoordinates and
// this->ColorTexture are set.
void vtkMapper::MapScalarsToTexture(vtkDataArray* scalars, double alpha)
......@@ -708,24 +717,30 @@ void vtkMapper::MapScalarsToTexture(vtkDataArray* scalars, double alpha)
// Get the texture map from the lookup table.
// Create a dummy ramp of scalars.
// In the future, we could extend vtkScalarsToColors.
double k = (range[1]-range[0]) / (ColorTextureMapSize-1);
vtkFloatArray* tmp = vtkFloatArray::New();
tmp->SetNumberOfTuples(ColorTextureMapSize*2);
float* ptr = tmp->GetPointer(0);
for (int i = 0; i < ColorTextureMapSize; ++i)
vtkIdType numberOfColors = this->LookupTable->GetNumberOfAvailableColors();
numberOfColors += 2;
double k = (range[1]-range[0]) / (numberOfColors-1-2);
vtkDoubleArray* tmp = vtkDoubleArray::New();
tmp->SetNumberOfTuples(numberOfColors*2);
double* ptr = tmp->GetPointer(0);
for (int i = 0; i < numberOfColors; ++i)
{
*ptr = range[0] + i * k;
*ptr = range[0] + i * k - k; // minus k to start at below range color
if (use_log_scale)
{
*ptr = pow(10.0, *ptr);
}
++ptr;
}
// Dimension on NaN.
double nan = vtkMath::Nan();
for (int i = 0; i < ColorTextureMapSize; ++i)
for (int i = 0; i < numberOfColors; ++i)
{
*ptr = nan;
++ptr;
}
this->ColorTextureMap = vtkImageData::New();
this->ColorTextureMap->SetExtent(0,ColorTextureMapSize-1,
this->ColorTextureMap->SetExtent(0,numberOfColors-1,
0,1, 0,0);
this->ColorTextureMap->GetPointData()->SetScalars(
this->LookupTable->MapScalars(tmp, this->ColorMode, 0));
......@@ -777,10 +792,11 @@ void vtkMapper::MapScalarsToTexture(vtkDataArray* scalars, double alpha)
{
vtkTemplateMacro(
CreateColorTextureCoordinates(static_cast<VTK_TT*>(input),
output, num, numComps,
scalarComponent, range,
this->LookupTable->GetRange(),
use_log_scale)
output, num, numComps,
scalarComponent, range,
this->LookupTable->GetRange(),
this->LookupTable->GetNumberOfAvailableColors(),
use_log_scale)
);
case VTK_BIT:
vtkErrorMacro("Cannot color by bit array.");
......
......@@ -50,7 +50,7 @@ void vtkOpenGLActor::Render(vtkRenderer *ren, vtkMapper *mapper)
vtkOpenGLClearErrorMacro();
// get opacity
bool opaque = this->GetIsOpaque();
bool opaque = (this->GetIsOpaque() != 0);
if (opaque)
{
glDepthMask(GL_TRUE);
......
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