Commit dbea2d5e authored by Cory Quammen's avatar Cory Quammen Committed by Kitware Robot
Browse files

Merge topic 'lookup_table_remove_mutex'

e61a328e

 Move table resizing out of core mapping routine
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !406
parents 74fad9c4 e61a328e
......@@ -18,7 +18,6 @@
#include "vtkBitArray.h"
#include "vtkMath.h"
#include "vtkMathConfigure.h"
#include "vtkMutexLock.h"
#include "vtkObjectFactory.h"
#include "vtkStringArray.h"
#include "vtkVariantArray.h"
......@@ -82,8 +81,6 @@ vtkLookupTable::vtkLookupTable(int sze, int ext)
this->Scale = VTK_SCALE_LINEAR;
this->OpaqueFlag=1;
this->ResizeMutex = vtkSimpleMutexLock::New();
}
//----------------------------------------------------------------------------
......@@ -91,7 +88,6 @@ vtkLookupTable::~vtkLookupTable()
{
this->Table->UnRegister( this );
this->Table = NULL;
this->ResizeMutex->Delete();
}
//----------------------------------------------------------------------------
......@@ -573,6 +569,7 @@ void vtkLookupTable::SetTable(vtkUnsignedCharArray *table)
this->Table = table;
this->Table->Register(this);
this->NumberOfColors = this->Table->GetNumberOfTuples();
this->ResizeTableForSpecialColors();
// If InsertTime is not modified the array will be rebuilt. So we
// use the same approach that the SetTableValue function does.
......@@ -644,7 +641,7 @@ namespace {
//----------------------------------------------------------------------------
template<class T>
void vtkLookupTableMapData(vtkLookupTable *self, vtkSimpleMutexLock *mutex,
void vtkLookupTableMapData(vtkLookupTable *self,
T *input, unsigned char *output, int length,
int inIncr, int outFormat, TableParameters & p)
{
......@@ -660,20 +657,6 @@ void vtkLookupTableMapData(vtkLookupTable *self, vtkSimpleMutexLock *mutex,
vtkUnsignedCharArray* lookupTable = self->GetTable();
vtkIdType numberOfColors = lookupTable->GetNumberOfTuples();
vtkIdType neededSize = (numberOfColors + vtkLookupTable::NUMBER_OF_SPECIAL_COLORS) *
lookupTable->GetNumberOfComponents();
// Since this involves a potential array resize and this function
// might be accessed concurently from more than one thread, we need a
// mutex here. This shouldn't affect performance much if this function
// is used to map many input values, but if it is called repeatedly
// with short input arrays, performance may be much worse.
mutex->Lock();
if (lookupTable->GetSize() < neededSize)
{
lookupTable->Resize(numberOfColors + vtkLookupTable::NUMBER_OF_SPECIAL_COLORS);
}
mutex->Unlock();
unsigned char* table = lookupTable->GetPointer(0);
......@@ -1172,8 +1155,7 @@ void vtkLookupTable::MapScalarsThroughTable2(void *input,
{
newInput->SetValue(i, bitArray->GetValue(id));
}
vtkLookupTableMapData(this, this->ResizeMutex,
static_cast<unsigned char*>(newInput->GetPointer(0)),
vtkLookupTableMapData(this, static_cast<unsigned char*>(newInput->GetPointer(0)),
output, numberOfValues,
inputIncrement, outputFormat, p);
newInput->Delete();
......@@ -1182,7 +1164,7 @@ void vtkLookupTable::MapScalarsThroughTable2(void *input,
break;
vtkTemplateMacro(
vtkLookupTableMapData(this, this->ResizeMutex, static_cast<VTK_TT*>(input),output,
vtkLookupTableMapData(this, static_cast<VTK_TT*>(input),output,
numberOfValues, inputIncrement, outputFormat, p)
);
default:
......@@ -1205,6 +1187,7 @@ void vtkLookupTable::SetNumberOfTableValues(vtkIdType number)
}
this->Modified();
this->NumberOfColors = number;
this->ResizeTableForSpecialColors();
this->Table->SetNumberOfTuples(number);
}
......@@ -1367,6 +1350,7 @@ void vtkLookupTable::DeepCopy(vtkScalarsToColors *obj)
this->NanColor[i] = lut->NanColor[i];
}
this->Table->DeepCopy(lut->Table);
this->ResizeTableForSpecialColors();
this->Superclass::DeepCopy(obj);
}
......@@ -1388,3 +1372,13 @@ void vtkLookupTable::GetIndexedColor(vtkIdType idx, double rgba[4])
}
this->GetNanColor(rgba);
}
//----------------------------------------------------------------------------
void vtkLookupTable::ResizeTableForSpecialColors()
{
vtkIdType neededColors = this->NumberOfColors + vtkLookupTable::NUMBER_OF_SPECIAL_COLORS;
if (this->Table->GetSize() < neededColors*this->Table->GetNumberOfComponents())
{
this->Table->Resize(neededColors);
}
}
......@@ -56,8 +56,6 @@
#include "vtkUnsignedCharArray.h" // Needed for inline method
class vtkSimpleMutexLock;
#define VTK_RAMP_LINEAR 0
#define VTK_RAMP_SCURVE 1
#define VTK_RAMP_SQRT 2
......@@ -361,7 +359,9 @@ protected:
int OpaqueFlag;
vtkTimeStamp OpaqueFlagBuildTime;
vtkSimpleMutexLock* ResizeMutex;
// Description:
// Resize the LookupTable to have enough room for the out-of-range colors
void ResizeTableForSpecialColors();
private:
vtkLookupTable(const vtkLookupTable&); // Not implemented.
......
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