Commit 83046737 authored by Utkarsh Ayachit's avatar Utkarsh Ayachit Committed by Kitware Robot
Browse files

Merge topic 'map-scalars-14943' into pv-master

8c7db600 FIX: We don't select 2D annotations.
ac80e9a7 Merge topic 'analyzer-warnings3' into master
694642a9 Merge remote-tracking branch 'pvvtk/pv-master' into HEAD
2f4ed70c Merge topic 'point_picking' into master
c1eac93b Improve picking support in OpenGL2
8e12d088 Merge topic 'scalar_compile' into master
c03e97a3 Merge topic 'hdf5-fix-flags-for-non-gcc' into master
6aa60b92 Fixes so the recent scalar changes compile on OpenGL2
a5cee757 HDF5: Fix build errors for PGI on Linux
a70ba05d Merge topic 'update-hdf5' into master
55b75e42 Fix hdf5 library names for VTK (and ParaView).
8ce63bdc Merge topic 'update-hdf5' into master
6e45312b Merge topic 'es2_fix' into master
09f0204d Remove lib prefix from windows libraries and mangle additional symbols.
0d5d0493 trivial fix for es 2.0
04bf1a8a Merge topic 'map-scalars-14943' into master
...
parents 3ba0dd54 8c7db600
......@@ -412,10 +412,11 @@ void vtkDataArray::InterpolateTuple(vtkIdType i, vtkIdList *ptIndices,
// in case WriteVoidPointer reallocates memory and fromData ==
// this. The vtkBitArray implementation doesn't use pointers, so skip
// the resizing in this case.
void* vto = fromData->GetDataType() != VTK_BIT ?
int dataType = fromData->GetDataType();
void* vto = dataType != VTK_BIT ?
this->WriteVoidPointer(idx, numComp) : 0;
switch (fromData->GetDataType())
switch (dataType)
{
case VTK_BIT:
{
......
......@@ -15,6 +15,7 @@
#include "vtkScalarsToColors.h"
#include "vtkAbstractArray.h"
#include "vtkCharArray.h"
#include "vtkStringArray.h"
#include "vtkTemplateAliasMacro.h"
#include "vtkUnsignedCharArray.h"
......@@ -211,10 +212,10 @@ unsigned char *vtkScalarsToColors::MapValue(double v)
this->GetColor(v, rgb);
double alpha = this->GetOpacity(v);
this->RGBABytes[0] = static_cast<unsigned char>(rgb[0]*255 + 0.5);
this->RGBABytes[1] = static_cast<unsigned char>(rgb[1]*255 + 0.5);
this->RGBABytes[2] = static_cast<unsigned char>(rgb[2]*255 + 0.5);
this->RGBABytes[3] = static_cast<unsigned char>(alpha*255 + 0.5);
this->RGBABytes[0] = ColorToUChar(rgb[0]);
this->RGBABytes[1] = ColorToUChar(rgb[1]);
this->RGBABytes[2] = ColorToUChar(rgb[2]);
this->RGBABytes[3] = ColorToUChar(alpha);
return this->RGBABytes;
}
......@@ -225,15 +226,15 @@ vtkUnsignedCharArray *vtkScalarsToColors::MapScalars(vtkDataArray *scalars,
{
int numberOfComponents = scalars->GetNumberOfComponents();
vtkUnsignedCharArray *newColors;
vtkUnsignedCharArray *colors;
// map scalars through lookup table only if needed
if (colorMode == VTK_COLOR_MODE_DEFAULT &&
(colors=vtkUnsignedCharArray::SafeDownCast(scalars)) != NULL)
if ((colorMode == VTK_COLOR_MODE_DEFAULT &&
vtkUnsignedCharArray::SafeDownCast(scalars) != NULL) ||
colorMode == VTK_COLOR_MODE_DIRECT_SCALARS)
{
newColors = this->
ConvertUnsignedCharToRGBA(colors, colors->GetNumberOfComponents(),
scalars->GetNumberOfTuples());
ConvertToRGBA(scalars, scalars->GetNumberOfComponents(),
scalars->GetNumberOfTuples());
}
else
{
......@@ -483,7 +484,7 @@ void vtkScalarsToColorsLuminanceToLuminanceAlpha(
const unsigned char *inPtr, unsigned char *outPtr, vtkIdType count,
int numComponents, double alpha)
{
unsigned char a = static_cast<unsigned char>(alpha*255 + 0.5);
unsigned char a = vtkScalarsToColors::ColorToUChar(alpha);
do
{
......@@ -495,15 +496,17 @@ void vtkScalarsToColorsLuminanceToLuminanceAlpha(
while (--count);
}
template<typename T>
void vtkScalarsToColorsLuminanceToRGBA(
const unsigned char *inPtr, unsigned char *outPtr, vtkIdType count,
const T *inPtr, unsigned char *outPtr, vtkIdType count,
int numComponents, double alpha)
{
unsigned char a = static_cast<unsigned char>(alpha*255 + 0.5);
unsigned char a = vtkScalarsToColors::ColorToUChar(alpha);
do
{
unsigned char l = inPtr[0];
unsigned char l = vtkScalarsToColors::ColorToUChar(inPtr[0]);
outPtr[0] = l;
outPtr[1] = l;
outPtr[2] = l;
......@@ -518,7 +521,7 @@ void vtkScalarsToColorsRGBToLuminanceAlpha(
const unsigned char *inPtr, unsigned char *outPtr, vtkIdType count,
int numComponents, double alpha)
{
unsigned char a = static_cast<unsigned char>(alpha*255 + 0.5);
unsigned char a = vtkScalarsToColors::ColorToUChar(alpha);
do
{
......@@ -534,17 +537,18 @@ void vtkScalarsToColorsRGBToLuminanceAlpha(
while (--count);
}
template<typename T>
void vtkScalarsToColorsRGBToRGBA(
const unsigned char *inPtr, unsigned char *outPtr, vtkIdType count,
const T *inPtr, unsigned char *outPtr, vtkIdType count,
int numComponents, double alpha)
{
unsigned char a = static_cast<unsigned char>(alpha*255 + 0.5);
unsigned char a = vtkScalarsToColors::ColorToUChar(alpha);
do
{
outPtr[0] = inPtr[0];
outPtr[1] = inPtr[1];
outPtr[2] = inPtr[2];
outPtr[0] = vtkScalarsToColors::ColorToUChar(inPtr[0]);
outPtr[1] = vtkScalarsToColors::ColorToUChar(inPtr[1]);
outPtr[2] = vtkScalarsToColors::ColorToUChar(inPtr[2]);
outPtr[3] = a;
inPtr += numComponents;
outPtr += 4;
......@@ -581,16 +585,17 @@ void vtkScalarsToColorsLuminanceAlphaToLuminanceAlpha(
}
}
template<typename T>
void vtkScalarsToColorsLuminanceAlphaToRGBA(
const unsigned char *inPtr, unsigned char *outPtr, vtkIdType count,
const T *inPtr, unsigned char *outPtr, vtkIdType count,
int numComponents, double alpha)
{
if (alpha >= 1)
{
do
{
unsigned char l = inPtr[0];
unsigned char a = inPtr[1];
unsigned char l = vtkScalarsToColors::ColorToUChar(inPtr[0]);
unsigned char a = vtkScalarsToColors::ColorToUChar(inPtr[1]);
outPtr[0] = l;
outPtr[1] = l;
outPtr[2] = l;
......@@ -604,8 +609,8 @@ void vtkScalarsToColorsLuminanceAlphaToRGBA(
{
do
{
unsigned char l = inPtr[0];
unsigned char a = inPtr[1];
unsigned char l = vtkScalarsToColors::ColorToUChar(inPtr[0]);
unsigned char a = vtkScalarsToColors::ColorToUChar(inPtr[1]);
outPtr[0] = l;
outPtr[1] = l;
outPtr[2] = l;
......@@ -636,18 +641,19 @@ void vtkScalarsToColorsRGBAToLuminanceAlpha(
while (--count);
}
template<typename T>
void vtkScalarsToColorsRGBAToRGBA(
const unsigned char *inPtr, unsigned char *outPtr, vtkIdType count,
const T *inPtr, unsigned char *outPtr, vtkIdType count,
int numComponents, double alpha)
{
if (alpha >= 1)
{
do
{
outPtr[0] = inPtr[0];
outPtr[1] = inPtr[1];
outPtr[2] = inPtr[2];
outPtr[3] = inPtr[3];
outPtr[0] = vtkScalarsToColors::ColorToUChar(inPtr[0]);
outPtr[1] = vtkScalarsToColors::ColorToUChar(inPtr[1]);
outPtr[2] = vtkScalarsToColors::ColorToUChar(inPtr[2]);
outPtr[3] = vtkScalarsToColors::ColorToUChar(inPtr[3]);
inPtr += numComponents;
outPtr += 4;
}
......@@ -657,9 +663,9 @@ void vtkScalarsToColorsRGBAToRGBA(
{
do
{
outPtr[0] = inPtr[0];
outPtr[1] = inPtr[1];
outPtr[2] = inPtr[2];
outPtr[0] = vtkScalarsToColors::ColorToUChar(inPtr[0]);
outPtr[1] = vtkScalarsToColors::ColorToUChar(inPtr[1]);
outPtr[2] = vtkScalarsToColors::ColorToUChar(inPtr[2]);
outPtr[3] = static_cast<unsigned char>(inPtr[3]*alpha + 0.5);
inPtr += numComponents;
outPtr += 4;
......@@ -785,7 +791,7 @@ void vtkScalarsToColorsLuminanceToLuminanceAlpha(
const T *inPtr, unsigned char *outPtr, vtkIdType count,
int numComponents, double shift, double scale, double alpha)
{
unsigned char a = static_cast<unsigned char>(alpha*255 + 0.5);
unsigned char a = vtkScalarsToColors::ColorToUChar(alpha);
static double minval = 0;
static double maxval = 255.0;
......@@ -809,7 +815,7 @@ void vtkScalarsToColorsLuminanceToRGBA(
const T *inPtr, unsigned char *outPtr, vtkIdType count,
int numComponents, double shift, double scale, double alpha)
{
unsigned char a = static_cast<unsigned char>(alpha*255 + 0.5);
unsigned char a = vtkScalarsToColors::ColorToUChar(alpha);
static double minval = 0;
static double maxval = 255.0;
......@@ -835,7 +841,7 @@ void vtkScalarsToColorsRGBToLuminanceAlpha(
const T *inPtr, unsigned char *outPtr, vtkIdType count,
int numComponents, double shift, double scale, double alpha)
{
unsigned char a = static_cast<unsigned char>(alpha*255 + 0.5);
unsigned char a = vtkScalarsToColors::ColorToUChar(alpha);
static double minval = 0;
static double maxval = 255.0;
......@@ -867,7 +873,7 @@ void vtkScalarsToColorsRGBToRGBA(
const T *inPtr, unsigned char *outPtr, vtkIdType count,
int numComponents, double shift, double scale, double alpha)
{
unsigned char a = static_cast<unsigned char>(alpha*255 + 0.5);
unsigned char a = vtkScalarsToColors::ColorToUChar(alpha);
static double minval = 0;
static double maxval = 255.0;
......@@ -1493,17 +1499,38 @@ void vtkScalarsToColors::MapScalarsThroughTable2(
delete [] newPtr;
}
// The callForAnyType is used to write generic code that works with any
// vtkDataArray derived types.
//
// This macro calls a template function (on the data type stored in the
// array). Example usage:
// callForAnyType(array, myFunc(static_cast<VTK_TT*>(data), arg2));
// where 'array' is a vtkDataArray and
// 'data' could be: array->GetVoidPointer(0)
#define callForAnyType(array, call) \
switch(array->GetDataType()) \
{ \
vtkTemplateMacro(call); \
}
//----------------------------------------------------------------------------
vtkUnsignedCharArray *vtkScalarsToColors::ConvertUnsignedCharToRGBA(
vtkUnsignedCharArray *colors, int numComp, int numTuples)
vtkUnsignedCharArray *vtkScalarsToColors::ConvertToRGBA(
vtkDataArray *colors, int numComp, int numTuples)
{
if (numComp == 4 && this->Alpha >= 1.0)
if (vtkCharArray::SafeDownCast(colors) != NULL)
{
colors->Register(this);
return colors;
vtkErrorMacro(<<"char type does not have enough values to hold a color");
return NULL;
}
if (numComp == 4 && this->Alpha >= 1.0 &&
vtkUnsignedCharArray::SafeDownCast(colors) != NULL)
{
vtkUnsignedCharArray* c = vtkUnsignedCharArray::SafeDownCast(colors);
c->Register(this);
return c;
}
unsigned char *cptr = colors->GetPointer(0);
vtkUnsignedCharArray *newColors = vtkUnsignedCharArray::New();
newColors->SetNumberOfComponents(4);
newColors->SetNumberOfTuples(numTuples);
......@@ -1520,23 +1547,31 @@ vtkUnsignedCharArray *vtkScalarsToColors::ConvertUnsignedCharToRGBA(
switch (numComp)
{
case 1:
vtkScalarsToColorsLuminanceToRGBA(
cptr, nptr, numTuples, numComp, alpha);
callForAnyType(
colors, vtkScalarsToColorsLuminanceToRGBA(
static_cast<VTK_TT*>(colors->GetVoidPointer(0)),
nptr, numTuples, numComp, alpha));
break;
case 2:
vtkScalarsToColorsLuminanceAlphaToRGBA(
cptr, nptr, numTuples, numComp, alpha);
callForAnyType(
colors, vtkScalarsToColorsLuminanceAlphaToRGBA(
static_cast<VTK_TT*>(colors->GetVoidPointer(0)),
nptr, numTuples, numComp, alpha));
break;
case 3:
vtkScalarsToColorsRGBToRGBA(
cptr, nptr, numTuples, numComp, alpha);
callForAnyType(
colors, vtkScalarsToColorsRGBToRGBA(
static_cast<VTK_TT*>(colors->GetVoidPointer(0)),
nptr, numTuples, numComp, alpha));
break;
case 4:
vtkScalarsToColorsRGBAToRGBA(
cptr, nptr, numTuples, numComp, alpha);
callForAnyType(
colors, vtkScalarsToColorsRGBAToRGBA(
static_cast<VTK_TT*>(colors->GetVoidPointer(0)),
nptr, numTuples, numComp, alpha));
break;
default:
......
......@@ -120,7 +120,12 @@ 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. Note 'char' does
// not have enough values to represent a color so mapping this type is
// considered an error);
// 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 +213,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 +314,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 +351,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 +405,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
......
......@@ -703,7 +703,7 @@ vtkIdType vtkCellLocator::FindClosestPointWithinRadius(double x[3], double radiu
int closestCell = -1;
double radius2 = radius*radius;
double minDist2 = 1.1*radius2; // something slightly bigger....
double refinedRadius = radius;
double refinedRadius;
double refinedRadius2 = radius2;
// Find bucket point is in.
......@@ -778,7 +778,6 @@ vtkIdType vtkCellLocator::FindClosestPointWithinRadius(double x[3], double radiu
cachedPoint[0] = point[0];
cachedPoint[1] = point[1];
cachedPoint[2] = point[2];
refinedRadius = sqrt(dist2);
refinedRadius2 = dist2;
}
}
......
......@@ -783,47 +783,39 @@ void vtkKdTree::BuildLocator()
this->FreeSearchStructure();
// volume bounds - push out a little if flat
double setBounds[6], volBounds[6];
bool first = true;
vtkCollectionSimpleIterator cookie;
this->DataSets->InitTraversal(cookie);
for (vtkDataSet *iset = this->DataSets->GetNextDataSet(cookie);
iset != NULL; iset = this->DataSets->GetNextDataSet(cookie))
vtkDataSet *iset = this->DataSets->GetNextDataSet(cookie);
double volBounds[6];
iset->GetBounds(volBounds);
while ((iset = this->DataSets->GetNextDataSet(cookie)))
{
if (first)
double setBounds[6];
iset->GetBounds(setBounds);
if (setBounds[0] < volBounds[0])
{
iset->GetBounds(volBounds);
first = false;
volBounds[0] = setBounds[0];
}
else
if (setBounds[2] < volBounds[2])
{
iset->GetBounds(setBounds);
if (setBounds[0] < volBounds[0])
{
volBounds[0] = setBounds[0];
}
if (setBounds[2] < volBounds[2])
{
volBounds[2] = setBounds[2];
}
if (setBounds[4] < volBounds[4])
{
volBounds[4] = setBounds[4];
}
if (setBounds[1] > volBounds[1])
{
volBounds[1] = setBounds[1];
}
if (setBounds[3] > volBounds[3])
{
volBounds[3] = setBounds[3];
}
if (setBounds[5] > volBounds[5])
{
volBounds[5] = setBounds[5];
}
volBounds[2] = setBounds[2];
}
if (setBounds[4] < volBounds[4])
{
volBounds[4] = setBounds[4];
}
if (setBounds[1] > volBounds[1])
{
volBounds[1] = setBounds[1];
}
if (setBounds[3] > volBounds[3])
{
volBounds[3] = setBounds[3];
}
if (setBounds[5] > volBounds[5])
{
volBounds[5] = setBounds[5];
}
}
......
......@@ -1097,8 +1097,8 @@ void vtkAlgorithm::AddInputConnection(int port, vtkAlgorithmOutput* input)
vtkDebugMacro("Adding connection to input port index " << consumerPort
<< " from output port index " << producerPort
<< " on algorithm "
<< (producer? producer->GetAlgorithm()->GetClassName() : "")
<< "(" << (producer? producer->GetAlgorithm() : 0) << ").");
<< producer->GetAlgorithm()->GetClassName()
<< "(" << producer->GetAlgorithm() << ").");
// Get the information object from the producer of the new input.
vtkInformation* newInfo = producer->GetOutputInformation(producerPort);
......
......@@ -65,8 +65,8 @@ struct vtkImageThreadStruct
// This can be from 1 to "total".
// If 1 is returned, the extent cannot be split.
int vtkThreadedImageAlgorithm::SplitExtent(int splitExt[6],
int startExt[6],
int num, int total)
int startExt[6],
int num, int total)
{
int splitAxis;
int min, max;
......@@ -163,6 +163,7 @@ static VTK_THREAD_RETURN_TYPE vtkThreadedImageAlgorithmThreadedExecute( void *ar
{
// if there is no output, then use UE from input, use the first input
int inPort;
bool found = false;
for (inPort = 0; inPort < str->Filter->GetNumberOfInputPorts(); ++inPort)
{
if (str->Filter->GetNumberOfInputConnections(inPort))
......@@ -173,10 +174,11 @@ static VTK_THREAD_RETURN_TYPE vtkThreadedImageAlgorithmThreadedExecute( void *ar
->Get(vtkStreamingDemandDrivenPipeline::UPDATE_EXTENT(),
updateExtent);
memcpy(ext,updateExtent, sizeof(int)*6);
found = true;
break;
}
}
if (inPort >= str->Filter->GetNumberOfInputPorts())
if (!found)
{
return VTK_THREAD_RETURN_VALUE;
}
......
......@@ -812,9 +812,9 @@ namespace {
double xp[3], xm[3], factor;
xp[0] = xp[1] = xp[2] = xm[0] = xm[1] = xm[2] = factor = 0;
double xxi, yxi, zxi, xeta, yeta, zeta, xzeta, yzeta, zzeta;
xxi = yxi = zxi = xeta = yeta = zeta = xzeta = yzeta = zzeta = 0;
yxi = zxi = xeta = yeta = zeta = xzeta = yzeta = zzeta = 0;
double aj, xix, xiy, xiz, etax, etay, etaz, zetax, zetay, zetaz;
aj = xix = xiy = xiz = etax = etay = etaz = zetax = zetay = zetaz = 0;
xix = xiy = xiz = etax = etay = etaz = zetax = zetay = zetaz = 0;
// for finite differencing -- the values on the "plus" side and
// "minus" side of the point to be computed at
std::vector<double> plusvalues(numberOfInputComponents);
......
......@@ -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"
......
......@@ -18,6 +18,7 @@ vtk_add_test_cxx(${vtk-module}CxxTests tests
TestBackfaceCulling.cxx
TestBareScalarsToColors.cxx
TestBlockOpacity.cxx
TestDirectScalarsToColors.cxx
TestDiscretizableColorTransferFunction.cxx,NO_VALID
TestEdgeFlags.cxx
TestFollowerPicking.cxx
......@@ -38,6 +39,7 @@ vtk_add_test_cxx(${vtk-module}CxxTests tests
TestOrderedTriangulator.cxx
TestOpacity.cxx
TestOSConeCxx.cxx
TestPointSelection.cxx,NO_VALID
TestPolygonSelection.cxx
TestResetCameraVerticalAspectRatio.cxx
TestResetCameraVerticalAspectRatioParallel.cxx
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestDirectScalarsToColors.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.