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

Merge topic 'new-field-list'

1c7c906b update ChartLoadNoVariablesB baseline.
63892d2b vtkPExtractHistogram: avoid depending on array order.
aec29ce8 vtkAttributeDataReductionFilter speed up data copying.
7f3b3871

 updates to vtkDataSetAttributes::FieldList.
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: Cory Quammen's avatarCory Quammen <cory.quammen@kitware.com>
Merge-request: !2574
parents 9a4a4bba 1c7c906b
Pipeline #109375 passed with stage
in 0 seconds
......@@ -25,6 +25,7 @@
#include "vtkSmartPointer.h"
#include "vtkTable.h"
#include <cassert>
#include <vector>
vtkStandardNewMacro(vtkAttributeDataReductionFilter);
......@@ -135,16 +136,14 @@ static void vtkAttributeDataReductionFilterReduce(vtkDataSetAttributes* output,
std::vector<vtkDataSetAttributes*> inputs, vtkAttributeDataReductionFilter* self)
{
int numInputs = static_cast<int>(inputs.size());
vtkDataSetAttributes::FieldList fieldList(numInputs);
fieldList.InitializeFieldList(inputs[0]);
assert(numInputs > 0);
vtkDataSetAttributes* input0 = inputs[0];
vtkIdType numTuples = inputs[0]->GetNumberOfTuples();
vtkIdType numTuples = input0->GetNumberOfTuples();
for (int cc = 1; cc < numInputs; ++cc)
vtkDataSetAttributes::FieldList fieldList;
for (vtkDataSetAttributes* dsa : inputs)
{
vtkDataSetAttributes* dsa = inputs[cc];
// Include only field that have any arrays
if (dsa->GetNumberOfArrays() > 0 && dsa->GetNumberOfTuples() == numTuples)
{
......@@ -154,10 +153,7 @@ static void vtkAttributeDataReductionFilterReduce(vtkDataSetAttributes* output,
output->CopyGlobalIdsOn();
output->CopyAllocate(fieldList, numTuples);
// Copy 0th data over first.
for (vtkIdType idx = 0; idx < numTuples; ++idx)
{
output->CopyData(fieldList, input0, 0, idx, idx);
}
fieldList.CopyData(0, input0, 0, numTuples, output, 0);
self->UpdateProgress(0.1);
double progress_offset = 0.1;
......
......@@ -41,31 +41,24 @@ class vtkIntegrateAttributes::vtkFieldList : public vtkDataSetAttributes::FieldL
typedef vtkDataSetAttributes::FieldList Superclass;
public:
vtkFieldList(int numInputs)
: vtkDataSetAttributes::FieldList(numInputs)
vtkFieldList(int numInputs = 0)
: Superclass(numInputs)
{
}
void SetFieldIndex(int i, int index)
{
this->vtkDataSetAttributes::FieldList::SetFieldIndex(i, index);
}
// This method is same as vtkFieldList::InitializeFieldList followed by logic
// to mark non-vtkDataArray fields are invalid. Thus, effectively skipping
// them.
void InitializeFieldListForDataArrays(vtkDataSetAttributes* dsa)
protected:
// overridden to only create vtkDoubleArray for numeric arrays.
vtkSmartPointer<vtkAbstractArray> CreateArray(int type) const override
{
this->Superclass::InitializeFieldList(dsa);
for (int i = vtkDataSetAttributes::NUM_ATTRIBUTES; i < this->GetNumberOfFields(); i++)
if (auto array = this->Superclass::CreateArray(type))
{
if (this->GetFieldIndex(i) >= 0)
const int is_numeric = (array->IsNumeric());
if (is_numeric)
{
vtkAbstractArray* aa = dsa->GetAbstractArray(this->GetFieldName(i));
if (vtkDataArray::SafeDownCast(aa) == NULL)
{
this->SetFieldIndex(i, -1);
}
return vtkSmartPointer<vtkAbstractArray>::Take(vtkDoubleArray::New());
}
}
return nullptr;
}
};
......@@ -352,35 +345,11 @@ int vtkIntegrateAttributes::RequestData(
if (compositeInput)
{
vtkCompositeDataIterator* iter = compositeInput->NewIterator();
int index = 0;
// vtkFieldList needs to know num of inputs, so determine that first.
for (iter->InitTraversal(); !iter->IsDoneWithTraversal(); iter->GoToNextItem())
{
vtkDataObject* dobj = iter->GetCurrentDataObject();
vtkDataSet* ds = vtkDataSet::SafeDownCast(dobj);
if (ds)
{
if (ds->GetNumberOfPoints() == 0)
{
continue; // skip empty datasets.
}
index++;
}
else
{
if (dobj)
{
vtkWarningMacro("This filter cannot handle sub-datasets of type : "
<< dobj->GetClassName() << ". Skipping block");
}
}
}
// Create the intersection field list. This is list of arrays common
// to all blocks in the input.
vtkFieldList pdList(index);
vtkFieldList cdList(index);
index = 0;
vtkFieldList pdList;
vtkFieldList cdList;
for (iter->InitTraversal(); !iter->IsDoneWithTraversal(); iter->GoToNextItem())
{
vtkDataObject* dobj = iter->GetCurrentDataObject();
......@@ -391,17 +360,8 @@ int vtkIntegrateAttributes::RequestData(
{
continue; // skip empty datasets.
}
if (index == 0)
{
pdList.InitializeFieldListForDataArrays(ds->GetPointData());
cdList.InitializeFieldListForDataArrays(ds->GetCellData());
}
else
{
pdList.IntersectFieldList(ds->GetPointData());
cdList.IntersectFieldList(ds->GetCellData());
}
index++;
pdList.IntersectFieldList(ds->GetPointData());
cdList.IntersectFieldList(ds->GetCellData());
}
else
{
......@@ -417,7 +377,7 @@ int vtkIntegrateAttributes::RequestData(
this->AllocateAttributes(pdList, output->GetPointData());
this->AllocateAttributes(cdList, output->GetCellData());
index = 0;
int index = 0;
// Now execute for each block.
for (iter->InitTraversal(); !iter->IsDoneWithTraversal(); iter->GoToNextItem())
{
......@@ -438,8 +398,8 @@ int vtkIntegrateAttributes::RequestData(
// Set all values to 0. All output attributes are type double.
vtkFieldList pdList(1);
vtkFieldList cdList(1);
pdList.InitializeFieldListForDataArrays(dsInput->GetPointData());
cdList.InitializeFieldListForDataArrays(dsInput->GetCellData());
pdList.InitializeFieldList(dsInput->GetPointData());
cdList.InitializeFieldList(dsInput->GetCellData());
this->AllocateAttributes(pdList, output->GetPointData());
this->AllocateAttributes(cdList, output->GetCellData());
this->ExecuteBlock(dsInput, output, 0, pdList, cdList);
......@@ -622,27 +582,24 @@ void vtkIntegrateAttributes::ReceivePiece(vtkUnstructuredGrid* mergeTo, int from
void vtkIntegrateAttributes::AllocateAttributes(
vtkIntegrateAttributes::vtkFieldList& fieldList, vtkDataSetAttributes* outda)
{
int numArrays = fieldList.GetNumberOfFields();
for (int i = 0; i < numArrays; ++i)
outda->CopyAllocate(fieldList);
for (int cc = 0, max = outda->GetNumberOfArrays(); cc < max; ++cc)
{
if (fieldList.GetFieldIndex(i) < 0)
{
continue;
}
int numComponents = fieldList.GetFieldComponents(i);
// All arrays are allocated double with one tuple.
vtkDoubleArray* outArray = vtkDoubleArray::New();
outArray->SetNumberOfComponents(numComponents);
outArray->SetNumberOfTuples(1);
outArray->SetName(fieldList.GetFieldName(i));
auto array = vtkDoubleArray::SafeDownCast(outda->GetAbstractArray(cc));
assert(array != nullptr);
array->SetNumberOfTuples(1);
// It cannot hurt to zero the arrays here.
for (int j = 0; j < numComponents; ++j)
{
outArray->SetComponent(0, j, 0.0);
}
fieldList.SetFieldIndex(i, outda->AddArray(outArray));
outArray->Delete();
// Should we set scalars, vectors ...
array->FillValue(0.0);
}
for (int cc = 0; cc < vtkDataSetAttributes::NUM_ATTRIBUTES; ++cc)
{
// this should not be necessary, however, the old version of
// vtkIntegrateAttributes didn't mark active attributes for any arrays. We
// preserve that behavior here. This is needed since filters like vtkGlyph3D
// love to drop active attributes (incorrectly, in my opinion). Until we
// resolve that, I am keeping this old behavior.
outda->SetActiveAttribute(-1, cc);
}
}
......
......@@ -87,7 +87,7 @@ int vtkPExtractHistogram::RequestData(
}
vtkTable* output = vtkTable::GetData(outputVector, 0);
vtkSmartPointer<vtkDataArray> oldExtents = output->GetRowData()->GetArray((int)0);
vtkSmartPointer<vtkDataArray> oldExtents = output->GetRowData()->GetArray("bin_extents");
if (oldExtents == NULL)
{
// Nothing to do if there is no data
......@@ -122,7 +122,7 @@ int vtkPExtractHistogram::RequestData(
vtkErrorMacro(<< "Reduced data has 0 arrays");
return 0;
}
output->GetRowData()->GetArray((int)0)->DeepCopy(oldExtents);
output->GetRowData()->GetArray("bin_extents")->DeepCopy(oldExtents);
if (this->CalculateAverages)
{
vtkDataArray* bin_values = output->GetRowData()->GetArray("bin_values");
......
b865e73285d1c0a6e9204c158ad9f2feae7ce3e80e4011485a91889c4961adfd3be56ce5d949f055ed4d286802bbbb7b99510fa5ed7084b3a4d15f84831b065b
10d6a0e561bb12a48da05da3f63b29d182217a8bb663ff639479ba2daefe7ec8cddb12e085f38857de47bb384e3edc6af84603dfd2259956687dc3c7aca9f769
Subproject commit 23ec83e4f681ce14e19f7bdbbcf61905cbf97717
Subproject commit d41d6d11927bee1fe0a6f3d40622c1c231ef7b75
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