Commit 00de9a94 authored by Dan Lipsa's avatar Dan Lipsa

Add VTK_COLOR_MODE_DIRECT_SCALARS. See vtkScalarsToColors::MapScalars.

Change-Id: I0fa7d8dde623b19204397d259e0c63f7d5bc4b66
parent 29309955
This diff is collapsed.
......@@ -120,7 +120,10 @@ public:
// unsigned char RGBA array. The color mode determines the behavior
// of mapping. If VTK_COLOR_MODE_DEFAULT is set, then unsigned char
// data arrays are treated as colors (and converted to RGBA if
// necessary); otherwise, the data is mapped through this instance
// necessary); If VTK_COLOR_MODE_DIRECT_SCALARS is set, then all arrays
// are treated as colors (integer types are clamped in the range 0-255,
// floating point arrays are clamped in the range 0.0-1.0);
// otherwise, the data is mapped through this instance
// of ScalarsToColors. The component argument is used for data
// arrays with more than one component; it indicates which component
// to use to do the blending. When the component argument is -1,
......@@ -208,13 +211,6 @@ public:
int inputIncrement,
int outputFormat);
// Description:
// An internal method used to convert a color array to RGBA. The
// method instantiates a vtkUnsignedCharArray and returns it. The user is
// responsible for managing the memory.
virtual vtkUnsignedCharArray *ConvertUnsignedCharToRGBA(
vtkUnsignedCharArray *colors, int numComp, int numTuples);
// Description:
// Copy the contents from another object.
virtual void DeepCopy(vtkScalarsToColors *o);
......@@ -316,6 +312,24 @@ public:
vtkGetMacro(IndexedLookup,int);
vtkBooleanMacro(IndexedLookup,int);
// Description:
// Converts a color from numeric type T to uchar. We assume the integral type
// is already in the range 0-255. If it is not, it is going to be truncated.
// Floating point types are assumed to be in interval 0.0-1.0
template<typename T> static
unsigned char ColorToUChar(T t)
{
return t;
}
template<typename T> static
void ColorToUChar(T t, unsigned char* dest)
{
*dest = ColorToUChar(t);
}
protected:
vtkScalarsToColors();
~vtkScalarsToColors();
......@@ -335,6 +349,14 @@ protected:
int numberOfComponents, int vectorSize,
int outputFormat);
// Description:
// An internal method used to convert a color array to RGBA. The
// method instantiates a vtkUnsignedCharArray and returns it. The user is
// responsible for managing the memory.
vtkUnsignedCharArray *ConvertToRGBA(
vtkDataArray *colors, int numComp, int numTuples);
// Description:
// An internal method for converting vectors to magnitudes, used as
// a preliminary step before doing magnitude mapping.
......@@ -381,4 +403,20 @@ private:
void operator=(const vtkScalarsToColors&); // Not implemented.
};
// Description:
// Specializations of vtkScalarsToColors::ColorToUChar
// Converts from a color in a floating point type in range 0.0-1.0 to a uchar
// in range 0-255.
template<> inline
unsigned char vtkScalarsToColors::ColorToUChar(double t)
{
return static_cast<unsigned char>(t*255 + 0.5);
}
template<> inline
unsigned char vtkScalarsToColors::ColorToUChar(float t)
{
return static_cast<unsigned char>(t*255 + 0.5);
}
#endif
......@@ -95,6 +95,7 @@
#define VTK_COLOR_MODE_DEFAULT 0
#define VTK_COLOR_MODE_MAP_SCALARS 1
#define VTK_COLOR_MODE_DIRECT_SCALARS 2
// Constants for InterpolationType
#define VTK_NEAREST_INTERPOLATION 0
......
......@@ -29,6 +29,7 @@
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkScalarBarActor.h"
#include "vtkScalarsToColors.h"
#include "vtkStructuredGrid.h"
#include "vtkStructuredGridGeometryFilter.h"
#include "vtkTextProperty.h"
......
......@@ -25,6 +25,7 @@
#include "vtkProperty.h"
#include "vtkRenderWindow.h"
#include "vtkRenderer.h"
#include "vtkScalarsToColors.h"
#include "vtkTexture.h"
#include <math.h>
......
......@@ -22,6 +22,7 @@
#include "vtkObjectFactory.h"
#include "vtkPolyData.h"
#include "vtkPolyDataMapper.h"
#include "vtkScalarsToColors.h"
vtkStandardNewMacro(vtkDataSetMapper);
......
......@@ -336,8 +336,10 @@ vtkUnsignedCharArray* vtkDiscretizableColorTransferFunction::MapScalars(
// if direct scalar mapping is enabled (and possible), the LUT is not used for
// color and we won't use it for opacity either.
bool direct_scalar_mapping = (colorMode == VTK_COLOR_MODE_DEFAULT &&
vtkUnsignedCharArray::SafeDownCast(scalars) != NULL);
bool direct_scalar_mapping =
((colorMode == VTK_COLOR_MODE_DEFAULT &&
vtkUnsignedCharArray::SafeDownCast(scalars) != NULL) ||
colorMode == VTK_COLOR_MODE_DIRECT_SCALARS);
vtkUnsignedCharArray *colors = (this->Discretize || this->IndexedLookup) ?
this->LookupTable->MapScalars(scalars, colorMode, component):
......
......@@ -316,8 +316,9 @@ vtkUnsignedCharArray *vtkMapper::MapScalars(double alpha)
{
// Only use texture color if we are mapping scalars.
// Directly coloring with RGB unsigned chars should not use texture.
if ( this->ColorMode != VTK_COLOR_MODE_DEFAULT ||
(vtkUnsignedCharArray::SafeDownCast(scalars)) == 0 )
if ( (this->ColorMode != VTK_COLOR_MODE_DEFAULT ||
(vtkUnsignedCharArray::SafeDownCast(scalars)) == 0) &&
this->ColorMode != VTK_COLOR_MODE_DIRECT_SCALARS)
{ // Texture color option.
this->MapScalarsToTexture(scalars, alpha);
return 0;
......
......@@ -54,7 +54,7 @@
#include "vtkRenderingCoreModule.h" // For export macro
#include "vtkAbstractMapper3D.h"
#include "vtkScalarsToColors.h" // For VTK_COLOR_MODE_DEFAULT and _MAP_SCALARS
#include "vtkSystemIncludes.h" // For VTK_COLOR_MODE_DEFAULT and _MAP_SCALARS
#define VTK_RESOLVE_OFF 0
#define VTK_RESOLVE_POLYGON_OFFSET 1
......@@ -74,6 +74,8 @@ class vtkActor;
class vtkDataSet;
class vtkFloatArray;
class vtkImageData;
class vtkScalarsToColors;
class vtkUnsignedCharArray;
class VTKRENDERINGCORE_EXPORT vtkMapper : public vtkAbstractMapper3D
{
......@@ -126,20 +128,25 @@ public:
vtkGetMacro(Static, int);
vtkBooleanMacro(Static, int);
// Description:
// Control how the scalar data is mapped to colors. By default
// (ColorModeToDefault), unsigned char scalars are treated as colors, and
// NOT mapped through the lookup table, while everything else is. Setting
// ColorModeToMapScalars means that all scalar data will be mapped through
// the lookup table. (Note that for multi-component scalars, the
// particular component to use for mapping can be specified using the
// SelectColorArray() method.)
// Description: Control how the scalar data is mapped to colors. By
// default (ColorModeToDefault), unsigned char scalars are treated
// as colors, and NOT mapped through the lookup table, while
// everything else is. ColorModeToDirectScalar extends
// ColorModeToDefault such that all integer types are treated as
// colors with values in the range 0-255 and floating types are
// treated as colors with values in the range 0.0-1.0. Setting
// ColorModeToMapScalars means that all scalar data will be mapped
// through the lookup table. (Note that for multi-component
// scalars, the particular component to use for mapping can be
// specified using the SelectColorArray() method.)
vtkSetMacro(ColorMode, int);
vtkGetMacro(ColorMode, int);
void SetColorModeToDefault()
{ this->SetColorMode(VTK_COLOR_MODE_DEFAULT); }
void SetColorModeToMapScalars()
{ this->SetColorMode(VTK_COLOR_MODE_MAP_SCALARS); }
void SetColorModeToDirectScalars()
{ this->SetColorMode(VTK_COLOR_MODE_DIRECT_SCALARS); }
// Description:
// Return the method of coloring scalar data.
......
......@@ -337,6 +337,13 @@ void vtkPolyDataMapper2D::SetColorModeToMapScalars()
this->SetColorMode(VTK_COLOR_MODE_MAP_SCALARS);
}
//----------------------------------------------------------------------------
void vtkPolyDataMapper2D::SetColorModeToDirectScalars()
{
this->SetColorMode(VTK_COLOR_MODE_DIRECT_SCALARS);
}
//----------------------------------------------------------------------------
int vtkPolyDataMapper2D::FillInputPortInformation(
int vtkNotUsed(port), vtkInformation* info)
......
......@@ -69,8 +69,12 @@ public:
// Description:
// Control how the scalar data is mapped to colors. By default
// (ColorModeToDefault), unsigned char scalars are treated as colors, and
// NOT mapped through the lookup table, while everything else is. Setting
// (ColorModeToDefault), unsigned char scalars are treated as
// colors, and NOT mapped through the lookup table, while everything
// else is. ColorModeToDirectScalar extends ColorModeToDefault such
// that all integer types are treated as colors with values in the
// range 0-255 and floating types are treated as colors with values
// in the range 0.0-1.0. Setting
// ColorModeToMapScalars means that all scalar data will be mapped through
// the lookup table. (Note that for multi-component scalars, the
// particular component to use for mapping can be specified using the
......@@ -79,6 +83,7 @@ public:
vtkGetMacro(ColorMode, int);
void SetColorModeToDefault();
void SetColorModeToMapScalars();
void SetColorModeToDirectScalars();
// Description:
// Return the method of coloring scalar data.
......
......@@ -30,6 +30,7 @@
#include "vtkPolyDataPainter.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkScalarsToColors.h"
#include "vtkScalarsToColorsPainter.h"
#include "vtkSmartPointer.h"
#include "vtkUnsignedCharArray.h"
......@@ -115,8 +116,9 @@ bool vtkCompositePolyDataMapper2::GetIsOpaque()
return this->LastOpaqueCheckValue;
}
this->LastOpaqueCheckTime = lastMTime;
if (this->ScalarVisibility &&
this->ColorMode == VTK_COLOR_MODE_DEFAULT && input)
if (this->ScalarVisibility && input &&
(this->ColorMode == VTK_COLOR_MODE_DEFAULT ||
this->ColorMode == VTK_COLOR_MODE_DIRECT_SCALARS))
{
vtkSmartPointer<vtkCompositeDataIterator> iter;
iter.TakeReference(input->NewIterator());
......@@ -129,14 +131,22 @@ bool vtkCompositePolyDataMapper2::GetIsOpaque()
vtkDataArray* scalars = this->GetScalars(pd,
this->ScalarMode, this->ArrayAccessMode, this->ArrayId,
this->ArrayName, cellFlag);
if (scalars && scalars->IsA("vtkUnsignedCharArray") &&
if (scalars &&
(scalars->IsA("vtkUnsignedCharArray") ||
this->ColorMode == VTK_COLOR_MODE_DIRECT_SCALARS) &&
(scalars->GetNumberOfComponents() == 4 /*(RGBA)*/ ||
scalars->GetNumberOfComponents() == 2 /*(LuminanceAlpha)*/))
{
vtkUnsignedCharArray* colors =
static_cast<vtkUnsignedCharArray*>(scalars);
if ((colors->GetNumberOfComponents() == 4 && colors->GetValueRange(3)[0] < 255) ||
(colors->GetNumberOfComponents() == 2 && colors->GetValueRange(1)[0] < 255))
int opacityIndex = scalars->GetNumberOfComponents() - 1;
unsigned char opacity = 0;
switch (scalars->GetDataType())
{
vtkTemplateMacro(
vtkScalarsToColors::ColorToUChar(
static_cast<VTK_TT>(scalars->GetRange(opacityIndex)[0]),
&opacity));
}
if (opacity < 255)
{
// If the opacity is 255, despite the fact that the user specified
// RGBA, we know that the Alpha is 100% opaque. So treat as opaque.
......
......@@ -33,6 +33,7 @@
#include "vtkPrimitivePainter.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkScalarsToColors.h"
#include "vtkScalarsToColorsPainter.h"
#include "vtkStandardPolyDataPainter.h"
......@@ -399,7 +400,8 @@ void vtkPainterPolyDataMapper::ComputeBounds()
bool vtkPainterPolyDataMapper::GetIsOpaque()
{
if (this->ScalarVisibility &&
this->ColorMode == VTK_COLOR_MODE_DEFAULT)
(this->ColorMode == VTK_COLOR_MODE_DEFAULT ||
this->ColorMode == VTK_COLOR_MODE_DIRECT_SCALARS))
{
vtkPolyData* input =
vtkPolyData::SafeDownCast(this->GetInputDataObject(0, 0));
......@@ -409,14 +411,23 @@ bool vtkPainterPolyDataMapper::GetIsOpaque()
vtkDataArray* scalars = this->GetScalars(input,
this->ScalarMode, this->ArrayAccessMode, this->ArrayId,
this->ArrayName, cellFlag);
if (scalars && scalars->IsA("vtkUnsignedCharArray") &&
if (scalars &&
(scalars->IsA("vtkUnsignedCharArray") ||
this->ColorMode == VTK_COLOR_MODE_DIRECT_SCALARS) &&
(scalars->GetNumberOfComponents() == 4 /*(RGBA)*/ ||
scalars->GetNumberOfComponents() == 2 /*(LuminanceAlpha)*/))
{
vtkUnsignedCharArray* colors =
static_cast<vtkUnsignedCharArray*>(scalars);
if ((colors->GetNumberOfComponents() == 4 && colors->GetValueRange(3)[0] < 255) ||
(colors->GetNumberOfComponents() == 2 && colors->GetValueRange(1)[0] < 255))
int opacityIndex = scalars->GetNumberOfComponents() - 1;
unsigned char opacity = 0;
switch (scalars->GetDataType())
{
vtkTemplateMacro(
vtkScalarsToColors::ColorToUChar(
static_cast<VTK_TT>(scalars->GetRange(opacityIndex)[0]),
&opacity));
}
if (opacity < 255)
{
// If the opacity is 255, despite the fact that the user specified
// RGBA, we know that the Alpha is 100% opaque. So treat as opaque.
......
......@@ -376,8 +376,9 @@ int vtkScalarsToColorsPainter::CanUseTextureMapForColoring(vtkDataObject* input)
return 0; // cell data colors, don't use textures.
}
if (this->ColorMode == VTK_COLOR_MODE_DEFAULT &&
vtkUnsignedCharArray::SafeDownCast(scalars))
if ((this->ColorMode == VTK_COLOR_MODE_DEFAULT &&
vtkUnsignedCharArray::SafeDownCast(scalars)) ||
this->ColorMode == VTK_COLOR_MODE_DIRECT_SCALARS)
{
// Don't use texture is direct coloring using RGB unsigned chars is
// requested.
......
......@@ -274,8 +274,9 @@ bool vtkCompositePolyDataMapper2::GetIsOpaque()
return this->LastOpaqueCheckValue;
}
this->LastOpaqueCheckTime = lastMTime;
if (this->ScalarVisibility &&
this->ColorMode == VTK_COLOR_MODE_DEFAULT && input)
if (this->ScalarVisibility && input
(this->ColorMode == VTK_COLOR_MODE_DEFAULT ||
this->ColorMode == VTK_COLOR_MODE_DIRECT_SCALARS))
{
vtkSmartPointer<vtkCompositeDataIterator> iter;
iter.TakeReference(input->NewIterator());
......@@ -288,14 +289,22 @@ bool vtkCompositePolyDataMapper2::GetIsOpaque()
vtkDataArray* scalars = this->GetScalars(pd,
this->ScalarMode, this->ArrayAccessMode, this->ArrayId,
this->ArrayName, cellFlag);
if (scalars && scalars->IsA("vtkUnsignedCharArray") &&
(scalars->GetNumberOfComponents() == 4 /*(RGBA)*/ ||
scalars->GetNumberOfComponents() == 2 /*(LuminanceAlpha)*/))
if (scalars &&
(scalars->IsA("vtkUnsignedCharArray") ||
this->ColorMode == VTK_COLOR_MODE_DIRECT_SCALARS) &&
(scalars->GetNumberOfComponents() == 4 /*(RGBA)*/ ||
scalars->GetNumberOfComponents() == 2 /*(LuminanceAlpha)*/))
{
vtkUnsignedCharArray* colors =
static_cast<vtkUnsignedCharArray*>(scalars);
if ((colors->GetNumberOfComponents() == 4 && colors->GetValueRange(3)[0] < 255) ||
(colors->GetNumberOfComponents() == 2 && colors->GetValueRange(1)[0] < 255))
int opacityIndex = scalars->GetNumberOfComponents() - 1;
unsigned char opacity = 0;
switch (scalars->GetDataType())
{
vtkTemplateMacro(
vtkScalarsToColors::ColorToUChar(
static_cast<VTK_TT>(scalars->GetRange(opacityIndex)[0]),
&opacity));
}
if (opacity < 255)
{
// If the opacity is 255, despite the fact that the user specified
// RGBA, we know that the Alpha is 100% opaque. So treat as opaque.
......
......@@ -1532,7 +1532,8 @@ bool vtkOpenGLPolyDataMapper::GetIsOpaque()
{
// Straight copy of what the vtkPainterPolyDataMapper was doing.
if (this->ScalarVisibility &&
this->ColorMode == VTK_COLOR_MODE_DEFAULT)
(this->ColorMode == VTK_COLOR_MODE_DEFAULT ||
this->ColorMode == VTK_COLOR_MODE_DIRECT_SCALARS))
{
vtkPolyData* input =
vtkPolyData::SafeDownCast(this->GetInputDataObject(0, 0));
......@@ -1542,14 +1543,22 @@ bool vtkOpenGLPolyDataMapper::GetIsOpaque()
vtkDataArray* scalars = this->GetScalars(input,
this->ScalarMode, this->ArrayAccessMode, this->ArrayId,
this->ArrayName, cellFlag);
if (scalars && scalars->IsA("vtkUnsignedCharArray") &&
if (scalars &&
(scalars->IsA("vtkUnsignedCharArray") ||
this->ColorMode == VTK_COLOR_MODE_DIRECT_SCALARS) &&
(scalars->GetNumberOfComponents() == 4 /*(RGBA)*/ ||
scalars->GetNumberOfComponents() == 2 /*(LuminanceAlpha)*/))
{
vtkUnsignedCharArray* colors =
static_cast<vtkUnsignedCharArray*>(scalars);
if ((colors->GetNumberOfComponents() == 4 && colors->GetValueRange(3)[0] < 255) ||
(colors->GetNumberOfComponents() == 2 && colors->GetValueRange(1)[0] < 255))
int opacityIndex = scalars->GetNumberOfComponents() - 1;
unsigned char opacity = 0;
switch (scalars->GetDataType())
{
vtkTemplateMacro(
vtkScalarsToColors::ColorToUChar(
static_cast<VTK_TT>(scalars->GetRange(opacityIndex)[0]),
&opacity));
}
if (opacity < 255)
{
// If the opacity is 255, despite the fact that the user specified
// RGBA, we know that the Alpha is 100% opaque. So treat as opaque.
......
......@@ -29,6 +29,7 @@
#include "vtkPoints.h"
#include "vtkPolyDataNormals.h"
#include "vtkProperty.h"
#include "vtkScalarsToColors.h"
#include "vtkSmartPointer.h"
#include "vtkTriangleFilter.h"
#include "vtkWebGLDataSet.h"
......@@ -701,7 +702,10 @@ void vtkWebGLPolyData::GetColorsFromPointData(unsigned char* color, vtkPointData
array = vtkAbstractMapper::GetScalars(polydata, actor->GetMapper()->GetScalarMode(),
actor->GetMapper()->GetArrayAccessMode(), actor->GetMapper()->GetArrayId(),
actor->GetMapper()->GetArrayName(), celldata);
if (actor->GetMapper()->GetScalarVisibility() && actor->GetMapper()->GetColorMode() == VTK_COLOR_MODE_DEFAULT && array)
if (actor->GetMapper()->GetScalarVisibility() &&
(actor->GetMapper()->GetColorMode() == VTK_COLOR_MODE_DEFAULT ||
actor->GetMapper()->GetColorMode() == VTK_COLOR_MODE_DIRECT_SCALARS) &&
array)
{
vtkScalarsToColors* table = actor->GetMapper()->GetLookupTable();
vtkUnsignedCharArray* cor = table->MapScalars(array, table->GetVectorMode(), table->GetVectorComponent());
......
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