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 @@
#include "vtkCompositeDataIterator.h"
#include "vtkCompositeDataPipeline.h"
#include "vtkDataSetAttributes.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkObjectFactory.h"
#include "vtkSmartPointer.h"
#include "vtkTable.h"
#include "vtkVariant.h"
vtkStandardNewMacro(vtkPVMergeTables);
//----------------------------------------------------------------------------
......@@ -53,31 +53,35 @@ vtkExecutive* vtkPVMergeTables::CreateDefaultExecutive()
//----------------------------------------------------------------------------
static void vtkPVMergeTablesMerge(vtkTable* output, vtkTable* inputs[], int num_inputs)
{
vtkDataSetAttributes::FieldList fields;
for (int idx = 0; idx < num_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;
}
vtkIdType numRows = curTable->GetNumberOfRows();
vtkIdType numCols = curTable->GetNumberOfColumns();
for (vtkIdType i = 0; i < numRows; i++)
{
vtkIdType curRow = output->InsertNextBlankRow();
for (vtkIdType j = 0; j < numCols; j++)
{
output->SetValue(curRow, j, curTable->GetValue(i, j));
}
}
auto inRD = curTable->GetRowData();
const auto inNumRows = inRD->GetNumberOfTuples();
fields.CopyData(fieldsInputIdx, inRD, 0, inNumRows, outRD, outStartRow);
outStartRow += inNumRows;
++fieldsInputIdx;
}
}
......
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