Skip to content

Commit

Permalink
Replace SafeDownCast calls on arrays with vtkArrayDownCast.
Browse files Browse the repository at this point in the history
SafeDownCast performs a series of virtual calls and string comparisons,
which is quite slow, especially when used in worker functions.

vtkArrayDownCast will switch between SafeDownCast and the more
efficient FastDownCast (only available for common vtkAbstractArray
subclasses) depending on whether or not FastDownCast is defined for
the specific array type.
  • Loading branch information
David C. Lonie committed May 6, 2016
1 parent d97bea9 commit 0d71a30
Show file tree
Hide file tree
Showing 330 changed files with 1,042 additions and 1,039 deletions.
2 changes: 1 addition & 1 deletion Accelerators/Piston/vtkDataSetToPiston.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ int vtkDataSetToPiston::RequestData(vtkInformation *vtkNotUsed(request),
return 1;
}
int association;
vtkFloatArray *inArray = vtkFloatArray::SafeDownCast(
vtkFloatArray *inArray = vtkArrayDownCast<vtkFloatArray>(
this->GetInputArrayToProcess(0,id, association));
//this filter expects that input has point associated float scalars
if (!inArray
Expand Down
6 changes: 3 additions & 3 deletions Accelerators/Piston/vtkPistonMapper.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,15 @@ void vtkPistonMapper::RenderOnCPU()

int vertsPer = vtkpiston::QueryVertsPer(id);

vtkFloatArray *normals = vtkFloatArray::SafeDownCast(
vtkFloatArray *normals = vtkArrayDownCast<vtkFloatArray>(
od->GetPointData()->GetNormals());
if (!normals)
{
normals = vtkFloatArray::SafeDownCast(
normals = vtkArrayDownCast<vtkFloatArray>(
od->GetPointData()->GetArray("Normals"));
}

vtkFloatArray *scalars = vtkFloatArray::SafeDownCast(
vtkFloatArray *scalars = vtkArrayDownCast<vtkFloatArray>(
od->GetPointData()->GetScalars());
if (scalars)
{
Expand Down
4 changes: 2 additions & 2 deletions Charts/Core/vtkChartBox.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void vtkChartBox::Update()
for (int i = 0; i < nbCols; ++i)
{
vtkDataArray* array =
vtkDataArray::SafeDownCast(table->GetColumnByName(
vtkArrayDownCast<vtkDataArray>(table->GetColumnByName(
this->VisibleColumns->GetValue(i)));
if (array)
{
Expand Down Expand Up @@ -172,7 +172,7 @@ bool vtkChartBox::Paint(vtkContext2D *painter)
this->AnnotationLink->GetMTime() > this->Storage->Plot->GetMTime())
{
vtkSelectionNode *node = selection->GetNode(0);
idArray = vtkIdTypeArray::SafeDownCast(node->GetSelectionList());
idArray = vtkArrayDownCast<vtkIdTypeArray>(node->GetSelectionList());
this->Storage->Plot->SetSelection(idArray);
}
}
Expand Down
6 changes: 4 additions & 2 deletions Charts/Core/vtkChartParallelCoordinates.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ void vtkChartParallelCoordinates::Update()
{
double range[2];
vtkDataArray* array =
vtkDataArray::SafeDownCast(table->GetColumnByName(this->VisibleColumns->GetValue(i)));
vtkArrayDownCast<vtkDataArray>(table->GetColumnByName(
this->VisibleColumns->GetValue(i)));
if (array)
{
array->GetRange(range);
Expand Down Expand Up @@ -181,7 +182,8 @@ bool vtkChartParallelCoordinates::Paint(vtkContext2D *painter)
{
vtkSelectionNode *node = selection->GetNumberOfNodes() > 0?
selection->GetNode(0) : NULL;
idArray = node? vtkIdTypeArray::SafeDownCast(node->GetSelectionList()) : NULL;
idArray = node? vtkArrayDownCast<vtkIdTypeArray>(node->GetSelectionList())
: NULL;
this->Storage->Plot->SetSelection(idArray);
}
}
Expand Down
8 changes: 4 additions & 4 deletions Charts/Core/vtkChartXY.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ void vtkChartXY::Update()
vtkSelectionNode *node = selection->GetNumberOfNodes() > 0?
selection->GetNode(0) : NULL;
vtkIdTypeArray *idArray = node?
vtkIdTypeArray::SafeDownCast(node->GetSelectionList()) : NULL;
vtkArrayDownCast<vtkIdTypeArray>(node->GetSelectionList()) : NULL;
std::vector<vtkPlot*>::iterator it =
this->ChartPrivate->plots.begin();
for ( ; it != this->ChartPrivate->plots.end(); ++it)
Expand All @@ -238,7 +238,7 @@ void vtkChartXY::Update()
{
vtkSelectionNode *node = selection->GetNode(i);
vtkIdTypeArray *idArray =
vtkIdTypeArray::SafeDownCast(node->GetSelectionList());
vtkArrayDownCast<vtkIdTypeArray>(node->GetSelectionList());
vtkPlot *selectionPlot =
vtkPlot::SafeDownCast(node->GetProperties()->Get(vtkSelectionNode::PROP()));
// Now iterate through the plots to update selection data
Expand All @@ -261,7 +261,7 @@ void vtkChartXY::Update()
{
vtkSelectionNode *node = selection->GetNode(i);
vtkIdTypeArray *selectedColumns =
vtkIdTypeArray::SafeDownCast(node->GetSelectionList());
vtkArrayDownCast<vtkIdTypeArray>(node->GetSelectionList());
vtkIdType* ptr = reinterpret_cast<vtkIdType*>(selectedColumns->GetVoidPointer(0));
for (vtkIdType j = 0; j < selectedColumns->GetNumberOfTuples(); ++j)
{
Expand Down Expand Up @@ -2062,7 +2062,7 @@ bool vtkChartXY::MouseButtonReleaseEvent(const vtkContextMouseEvent &mouse)
selection->GetNode(0) : NULL;
if (node)
{
oldSelection->DeepCopy(vtkIdTypeArray::SafeDownCast(node->GetSelectionList()));
oldSelection->DeepCopy(vtkArrayDownCast<vtkIdTypeArray>(node->GetSelectionList()));
}
}
vtkNew<vtkIdTypeArray> plotSelection;
Expand Down
2 changes: 1 addition & 1 deletion Charts/Core/vtkChartXYZ.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ void vtkChartXYZ::Update()
{
vtkSelectionNode *node = selection->GetNode(0);
vtkIdTypeArray *idArray =
vtkIdTypeArray::SafeDownCast(node->GetSelectionList());
vtkArrayDownCast<vtkIdTypeArray>(node->GetSelectionList());
for (size_t i = 0; i < this->Plots.size(); ++i)
{
this->Plots[i]->SetSelection(idArray);
Expand Down
8 changes: 4 additions & 4 deletions Charts/Core/vtkPlot3D.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ void vtkPlot3D::SetInputData(vtkTable *input, const vtkStdString &xName,
{
// Copy the points into our data structure for rendering - pack x, y, z...
vtkDataArray *xArr =
vtkDataArray::SafeDownCast(input->GetColumnByName(xName.c_str()));
vtkArrayDownCast<vtkDataArray>(input->GetColumnByName(xName.c_str()));
vtkDataArray *yArr =
vtkDataArray::SafeDownCast(input->GetColumnByName(yName.c_str()));
vtkArrayDownCast<vtkDataArray>(input->GetColumnByName(yName.c_str()));
vtkDataArray *zArr =
vtkDataArray::SafeDownCast(input->GetColumnByName(zName.c_str()));
vtkArrayDownCast<vtkDataArray>(input->GetColumnByName(zName.c_str()));

// Ensure that we have valid data arrays, and that they are of the same length.
assert(xArr);
Expand Down Expand Up @@ -190,7 +190,7 @@ void vtkPlot3D::SetInputData(vtkTable *input, const vtkStdString &xName,
this->SetInputData(input, xName, yName, zName);

vtkDataArray *colorArr =
vtkDataArray::SafeDownCast(input->GetColumnByName(colorName.c_str()));
vtkArrayDownCast<vtkDataArray>(input->GetColumnByName(colorName.c_str()));
this->SetColors(colorArr);
}

Expand Down
2 changes: 1 addition & 1 deletion Charts/Core/vtkPlotArea.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ void vtkPlotArea::Update()

cache.Reset();
cache.ValidPointMask = (this->ValidPointMaskName.empty() == false)?
vtkCharArray::SafeDownCast(table->GetColumnByName(this->ValidPointMaskName)) : NULL;
vtkArrayDownCast<vtkCharArray>(table->GetColumnByName(this->ValidPointMaskName)) : NULL;
cache.SetPoints(
this->UseIndexForXSeries? NULL: this->Data->GetInputArrayToProcess(0, table),
this->Data->GetInputArrayToProcess(1, table),
Expand Down
8 changes: 4 additions & 4 deletions Charts/Core/vtkPlotBag.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void vtkPlotBag::Update()

// Check if we have an input
vtkTable *table = this->Data->GetInput();
vtkDataArray *density = vtkDataArray::SafeDownCast(
vtkDataArray *density = vtkArrayDownCast<vtkDataArray>(
this->Data->GetInputAbstractArrayToProcess(2, this->GetInput()));
if (!table || !density)
{
Expand Down Expand Up @@ -311,7 +311,7 @@ vtkStringArray* vtkPlotBag::GetLabels()
else if (this->Data->GetInput())
{
this->AutoLabels = vtkSmartPointer<vtkStringArray>::New();
vtkDataArray *density = vtkDataArray::SafeDownCast(
vtkDataArray *density = vtkArrayDownCast<vtkDataArray>(
this->Data->GetInputAbstractArrayToProcess(2, this->GetInput()));
if (density)
{
Expand All @@ -332,7 +332,7 @@ vtkStdString vtkPlotBag::GetTooltipLabel(const vtkVector2d &plotPos,
this->TooltipDefaultLabelFormat : this->TooltipLabelFormat;
// Parse TooltipLabelFormat and build tooltipLabel
bool escapeNext = false;
vtkDataArray *density = vtkDataArray::SafeDownCast(
vtkDataArray *density = vtkArrayDownCast<vtkDataArray>(
this->Data->GetInputAbstractArrayToProcess(2, this->GetInput()));
for (size_t i = 0; i < format.length(); ++i)
{
Expand Down Expand Up @@ -372,7 +372,7 @@ vtkStdString vtkPlotBag::GetTooltipLabel(const vtkVector2d &plotPos,
break;
case 'C':
{
vtkAbstractArray *colName = vtkAbstractArray::SafeDownCast(
vtkAbstractArray *colName = vtkArrayDownCast<vtkAbstractArray>(
this->GetInput()->GetColumnByName("ColName"));
std::stringstream ss;
if (colName)
Expand Down
12 changes: 6 additions & 6 deletions Charts/Core/vtkPlotBar.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,11 @@ class vtkPlotBarSegment : public vtkObject {
painter->ApplyBrush(brush);
int n = this->Points->GetNumberOfPoints();
float *f =
vtkFloatArray::SafeDownCast(this->Points->GetData())->GetPointer(0);
vtkArrayDownCast<vtkFloatArray>(this->Points->GetData())->GetPointer(0);
float *p = NULL;
if (this->Previous)
{
p = vtkFloatArray::SafeDownCast(
p = vtkArrayDownCast<vtkFloatArray>(
this->Previous->Points->GetData())->GetPointer(0);
}

Expand Down Expand Up @@ -689,7 +689,7 @@ void vtkPlotBar::GetBounds(double bounds[4], bool unscaled)
for ( it = this->Private->AdditionalSeries.begin(); it !=
this->Private->AdditionalSeries.end(); ++it )
{
y = vtkDataArray::SafeDownCast(table->GetColumnByName((*it).second.c_str()));
y = vtkArrayDownCast<vtkDataArray>(table->GetColumnByName((*it).second.c_str()));
y->GetRange(yRange);
bounds[valuesHigh] += yRange[1];
}
Expand Down Expand Up @@ -870,7 +870,7 @@ bool vtkPlotBar::UpdateTableCache(vtkTable *table)
if (this->ScalarVisibility && !this->ColorArrayName.empty())
{
vtkDataArray* c =
vtkDataArray::SafeDownCast(table->GetColumnByName(this->ColorArrayName));
vtkArrayDownCast<vtkDataArray>(table->GetColumnByName(this->ColorArrayName));
// TODO: Should add support for categorical coloring & try enum lookup
if (c)
{
Expand All @@ -896,7 +896,7 @@ bool vtkPlotBar::UpdateTableCache(vtkTable *table)
for ( it = this->Private->AdditionalSeries.begin();
it != this->Private->AdditionalSeries.end(); ++it )
{
y = vtkDataArray::SafeDownCast(table->GetColumnByName((*it).second.c_str()));
y = vtkArrayDownCast<vtkDataArray>(table->GetColumnByName((*it).second.c_str()));
prev = this->Private->AddSegment(x,y, this->GetXAxis(), this->GetYAxis(),prev);
}

Expand Down Expand Up @@ -1025,7 +1025,7 @@ void vtkPlotBar::SelectColorArray(vtkIdType arrayNum)
vtkWarningMacro(<< "SelectColorArray called with no input table set.");
return;
}
vtkDataArray *col = vtkDataArray::SafeDownCast(table->GetColumn(arrayNum));
vtkDataArray *col = vtkArrayDownCast<vtkDataArray>(table->GetColumn(arrayNum));
// TODO: Should add support for categorical coloring & try enum lookup
if (!col)
{
Expand Down
2 changes: 1 addition & 1 deletion Charts/Core/vtkPlotBox.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ bool vtkPlotBox::UpdateTableCache(vtkTable *table)
std::vector<double>& col = this->Storage->at(i);
col.resize(rows);
vtkSmartPointer<vtkDataArray> data =
vtkDataArray::SafeDownCast(table->GetColumnByName(cols->GetValue(i)));
vtkArrayDownCast<vtkDataArray>(table->GetColumnByName(cols->GetValue(i)));
if (!data)
{
continue;
Expand Down
2 changes: 1 addition & 1 deletion Charts/Core/vtkPlotFunctionalBag.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ bool vtkPlotFunctionalBag::UpdateTableCache(vtkTable *table)
{
// The input array has 2 components, this must be a bag
// with {miny,maxy} tuples
vtkDoubleArray* darr = vtkDoubleArray::SafeDownCast(array[1]);
vtkDoubleArray* darr = vtkArrayDownCast<vtkDoubleArray>(array[1]);

this->LogX = this->XAxis->GetLogScaleActive();
this->LogY = this->YAxis->GetLogScaleActive();
Expand Down
10 changes: 5 additions & 5 deletions Charts/Core/vtkPlotParallelCoordinates.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ bool vtkPlotParallelCoordinates::UpdateTableCache(vtkTable *table)
vtkAxis* axis = parent->GetAxis(i);
col.resize(rows);
vtkSmartPointer<vtkDataArray> data =
vtkDataArray::SafeDownCast(table->GetColumnByName(cols->GetValue(i)));
vtkArrayDownCast<vtkDataArray>(table->GetColumnByName(cols->GetValue(i)));
if (!data)
{
if (table->GetColumnByName(cols->GetValue(i))->IsA("vtkStringArray"))
Expand All @@ -341,12 +341,12 @@ bool vtkPlotParallelCoordinates::UpdateTableCache(vtkTable *table)
vtkTable* stringTable = vtkTable::SafeDownCast(stoc->GetOutput(1));
if (table2)
{
data = vtkDataArray::SafeDownCast(table2->GetColumnByName("enumPC"));
data = vtkArrayDownCast<vtkDataArray>(table2->GetColumnByName("enumPC"));
}
if (stringTable && stringTable->GetColumnByName("Strings"))
{
vtkStringArray* strings =
vtkStringArray::SafeDownCast(stringTable->GetColumnByName("Strings"));
vtkArrayDownCast<vtkStringArray>(stringTable->GetColumnByName("Strings"));
vtkSmartPointer<vtkDoubleArray> arr =
vtkSmartPointer<vtkDoubleArray>::New();
for (vtkIdType j = 0; j < strings->GetNumberOfTuples(); ++j)
Expand Down Expand Up @@ -389,7 +389,7 @@ bool vtkPlotParallelCoordinates::UpdateTableCache(vtkTable *table)
if (this->ScalarVisibility && !this->ColorArrayName.empty())
{
vtkDataArray* c =
vtkDataArray::SafeDownCast(table->GetColumnByName(this->ColorArrayName));
vtkArrayDownCast<vtkDataArray>(table->GetColumnByName(this->ColorArrayName));
// TODO: Should add support for categorical coloring & try enum lookup
if (c)
{
Expand Down Expand Up @@ -497,7 +497,7 @@ void vtkPlotParallelCoordinates::SelectColorArray(vtkIdType arrayNum)
vtkDebugMacro(<< "SelectColorArray called with no input table set.");
return;
}
vtkDataArray *col = vtkDataArray::SafeDownCast(table->GetColumn(arrayNum));
vtkDataArray *col = vtkArrayDownCast<vtkDataArray>(table->GetColumn(arrayNum));
// TODO: Should add support for categorical coloring & try enum lookup
if (!col)
{
Expand Down
8 changes: 4 additions & 4 deletions Charts/Core/vtkPlotPoints.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void vtkPlotPoints::Update()
if (table && !this->ValidPointMaskName.empty() &&
table->GetColumnByName(this->ValidPointMaskName))
{
this->ValidPointMask = vtkCharArray::SafeDownCast(
this->ValidPointMask = vtkArrayDownCast<vtkCharArray>(
table->GetColumnByName(this->ValidPointMaskName));
}
else
Expand Down Expand Up @@ -238,7 +238,7 @@ bool vtkPlotPoints::Paint(vtkContext2D *painter)
if (this->Selection->GetMTime() > this->SelectedPoints->GetMTime() ||
this->GetMTime() > this->SelectedPoints->GetMTime())
{
float *f = vtkFloatArray::SafeDownCast(
float *f = vtkArrayDownCast<vtkFloatArray>(
this->Points->GetData())->GetPointer(0);
int nSelected(static_cast<int>(this->Selection->GetNumberOfTuples()));
this->SelectedPoints->SetNumberOfComponents(2);
Expand Down Expand Up @@ -731,7 +731,7 @@ bool vtkPlotPoints::UpdateTableCache(vtkTable *table)
if (this->ScalarVisibility && !this->ColorArrayName.empty())
{
vtkDataArray* c =
vtkDataArray::SafeDownCast(table->GetColumnByName(this->ColorArrayName));
vtkArrayDownCast<vtkDataArray>(table->GetColumnByName(this->ColorArrayName));
// TODO: Should add support for categorical coloring & try enum lookup
if (c)
{
Expand Down Expand Up @@ -1008,7 +1008,7 @@ void vtkPlotPoints::SelectColorArray(vtkIdType arrayNum)
vtkDebugMacro(<< "SelectColorArray called with no input table set.");
return;
}
vtkDataArray *col = vtkDataArray::SafeDownCast(table->GetColumn(arrayNum));
vtkDataArray *col = vtkArrayDownCast<vtkDataArray>(table->GetColumn(arrayNum));
// TODO: Should add support for categorical coloring & try enum lookup
if (!col)
{
Expand Down
6 changes: 3 additions & 3 deletions Charts/Core/vtkPlotStacked.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,10 @@ class vtkPlotStackedSegment : public vtkObject {
painter->ApplyPen(pen);
painter->ApplyBrush(brush);
int n = this->Points->GetNumberOfPoints();
float *data_extent = vtkFloatArray::SafeDownCast(this->Points->GetData())->GetPointer(0);
float *data_extent = vtkArrayDownCast<vtkFloatArray>(this->Points->GetData())->GetPointer(0);
float *data_base = 0;
if (this->Previous)
data_base = vtkFloatArray::SafeDownCast(this->Previous->Points->GetData())->GetPointer(0);
data_base = vtkArrayDownCast<vtkFloatArray>(this->Previous->Points->GetData())->GetPointer(0);

if (n >= 2)
{
Expand Down Expand Up @@ -796,7 +796,7 @@ bool vtkPlotStacked::UpdateTableCache(vtkTable *table)

for ( it = this->Private->AdditionalSeries.begin(); it != this->Private->AdditionalSeries.end(); ++it )
{
y = vtkDataArray::SafeDownCast(table->GetColumnByName((*it).second.c_str()));
y = vtkArrayDownCast<vtkDataArray>(table->GetColumnByName((*it).second.c_str()));
prev = this->Private->AddSegment(x,y,prev);
}

Expand Down
10 changes: 5 additions & 5 deletions Charts/Core/vtkScatterPlotMatrix.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ bool PopulateHistograms(vtkTable *input, vtkTable *output, vtkStringArray *s,
double minmax[2] = { 0.0, 0.0 };
vtkStdString name(s->GetValue(i));
vtkDataArray *in =
vtkDataArray::SafeDownCast(input->GetColumnByName(name.c_str()));
vtkArrayDownCast<vtkDataArray>(input->GetColumnByName(name.c_str()));
if (in)
{
// The bin values are the centers, extending +/- half an inc either side
Expand All @@ -231,7 +231,7 @@ bool PopulateHistograms(vtkTable *input, vtkTable *output, vtkStringArray *s,
double inc = (minmax[1] - minmax[0]) / (NumberOfBins) * 1.001;
double halfInc = inc / 2.0;
vtkSmartPointer<vtkFloatArray> extents =
vtkFloatArray::SafeDownCast(
vtkArrayDownCast<vtkFloatArray>(
output->GetColumnByName(vtkStdString(name + "_extents").c_str()));
if (!extents)
{
Expand All @@ -246,7 +246,7 @@ bool PopulateHistograms(vtkTable *input, vtkTable *output, vtkStringArray *s,
extents->SetValue(j, min + j * inc);
}
vtkSmartPointer<vtkIntArray> populations =
vtkIntArray::SafeDownCast(
vtkArrayDownCast<vtkIntArray>(
output->GetColumnByName(vtkStdString(name + "_pops").c_str()));
if (!populations)
{
Expand Down Expand Up @@ -829,7 +829,7 @@ void vtkScatterPlotMatrix::SetColumnVisibility(const vtkStdString &name,
}
// Add the column to the end of the list if it is a numeric column
if (this->Input && this->Input->GetColumnByName(name.c_str()) &&
vtkDataArray::SafeDownCast(this->Input->GetColumnByName(name.c_str())))
vtkArrayDownCast<vtkDataArray>(this->Input->GetColumnByName(name.c_str())))
{
this->VisibleColumns->InsertNextValue(name);
this->Private->VisibleColumnsModified = true;
Expand Down Expand Up @@ -1300,7 +1300,7 @@ void vtkScatterPlotMatrix::UpdateAxes()
double range[2] = { 0, 0 };
std::string name(this->VisibleColumns->GetValue(i));
vtkDataArray *arr =
vtkDataArray::SafeDownCast(this->Input->GetColumnByName(name.c_str()));
vtkArrayDownCast<vtkDataArray>(this->Input->GetColumnByName(name.c_str()));
if (arr)
{
PIMPL::ColumnSetting settings;
Expand Down
Loading

0 comments on commit 0d71a30

Please sign in to comment.