Commit 97c36612 authored by Utkarsh Ayachit's avatar Utkarsh Ayachit
Browse files

vtkPVMergeTables: improve code robustness

vtkPVMergeTables assumes columns in multiple tables were exactly in the
same order. This is a tall order and an unnecessary one.
`vtkDataSetAttributes::FieldList` makes it fairly easy to remove this
restriction. Hence updating the code and make it more robust to column
order variations.
parent 9f906607
...@@ -16,13 +16,13 @@ ...@@ -16,13 +16,13 @@
#include "vtkCompositeDataIterator.h" #include "vtkCompositeDataIterator.h"
#include "vtkCompositeDataPipeline.h" #include "vtkCompositeDataPipeline.h"
#include "vtkDataSetAttributes.h"
#include "vtkInformation.h" #include "vtkInformation.h"
#include "vtkInformationVector.h" #include "vtkInformationVector.h"
#include "vtkMultiBlockDataSet.h" #include "vtkMultiBlockDataSet.h"
#include "vtkObjectFactory.h" #include "vtkObjectFactory.h"
#include "vtkSmartPointer.h" #include "vtkSmartPointer.h"
#include "vtkTable.h" #include "vtkTable.h"
#include "vtkVariant.h"
vtkStandardNewMacro(vtkPVMergeTables); vtkStandardNewMacro(vtkPVMergeTables);
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
...@@ -53,31 +53,35 @@ vtkExecutive* vtkPVMergeTables::CreateDefaultExecutive() ...@@ -53,31 +53,35 @@ vtkExecutive* vtkPVMergeTables::CreateDefaultExecutive()
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
static void vtkPVMergeTablesMerge(vtkTable* output, vtkTable* inputs[], int num_inputs) static void vtkPVMergeTablesMerge(vtkTable* output, vtkTable* inputs[], int num_inputs)
{ {
vtkDataSetAttributes::FieldList fields;
for (int idx = 0; idx < num_inputs; ++idx) for (int idx = 0; idx < num_inputs; ++idx)
{ {
vtkTable* curTable = inputs[idx]; vtkTable* curTable = inputs[idx];
if (!curTable || curTable->GetNumberOfRows() == 0 || curTable->GetNumberOfColumns() == 0) if (curTable && curTable->GetNumberOfRows() > 0 && curTable->GetNumberOfColumns() > 0)
{ {
continue; fields.IntersectFieldList(curTable->GetRowData());
} }
}
if (output->GetNumberOfRows() == 0) auto outRD = output->GetRowData();
// passing sz=0 ensures that fields simply uses the accumulated counts for
// number of rows.
fields.CopyAllocate(outRD, vtkDataSetAttributes::PASSDATA, /*sz=*/0, /*ext=*/0);
vtkIdType outStartRow = 0;
for (int idx = 0, fieldsInputIdx = 0; idx < num_inputs; ++idx)
{
vtkTable* curTable = inputs[idx];
if (!curTable || curTable->GetNumberOfRows() == 0 || curTable->GetNumberOfColumns() == 0)
{ {
// Copy output structure from the first non-empty input.
output->DeepCopy(curTable);
continue; continue;
} }
vtkIdType numRows = curTable->GetNumberOfRows(); auto inRD = curTable->GetRowData();
vtkIdType numCols = curTable->GetNumberOfColumns(); const auto inNumRows = inRD->GetNumberOfTuples();
for (vtkIdType i = 0; i < numRows; i++) fields.CopyData(fieldsInputIdx, inRD, 0, inNumRows, outRD, outStartRow);
{ outStartRow += inNumRows;
vtkIdType curRow = output->InsertNextBlankRow(); ++fieldsInputIdx;
for (vtkIdType j = 0; j < numCols; j++)
{
output->SetValue(curRow, j, curTable->GetValue(i, j));
}
}
} }
} }
......
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