Commit c1c3954f authored by Ken Martin's avatar Ken Martin Committed by Code Review
Browse files

Merge topic 'lut_changes' into master

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