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 @@ ...@@ -25,6 +25,7 @@
#include "vtkSmartPointer.h" #include "vtkSmartPointer.h"
#include "vtkTable.h" #include "vtkTable.h"
#include <cassert>
#include <vector> #include <vector>
vtkStandardNewMacro(vtkAttributeDataReductionFilter); vtkStandardNewMacro(vtkAttributeDataReductionFilter);
...@@ -135,16 +136,14 @@ static void vtkAttributeDataReductionFilterReduce(vtkDataSetAttributes* output, ...@@ -135,16 +136,14 @@ static void vtkAttributeDataReductionFilterReduce(vtkDataSetAttributes* output,
std::vector<vtkDataSetAttributes*> inputs, vtkAttributeDataReductionFilter* self) std::vector<vtkDataSetAttributes*> inputs, vtkAttributeDataReductionFilter* self)
{ {
int numInputs = static_cast<int>(inputs.size()); int numInputs = static_cast<int>(inputs.size());
assert(numInputs > 0);
vtkDataSetAttributes::FieldList fieldList(numInputs);
fieldList.InitializeFieldList(inputs[0]);
vtkDataSetAttributes* input0 = inputs[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 // Include only field that have any arrays
if (dsa->GetNumberOfArrays() > 0 && dsa->GetNumberOfTuples() == numTuples) if (dsa->GetNumberOfArrays() > 0 && dsa->GetNumberOfTuples() == numTuples)
{ {
...@@ -154,10 +153,7 @@ static void vtkAttributeDataReductionFilterReduce(vtkDataSetAttributes* output, ...@@ -154,10 +153,7 @@ static void vtkAttributeDataReductionFilterReduce(vtkDataSetAttributes* output,
output->CopyGlobalIdsOn(); output->CopyGlobalIdsOn();
output->CopyAllocate(fieldList, numTuples); output->CopyAllocate(fieldList, numTuples);
// Copy 0th data over first. // Copy 0th data over first.
for (vtkIdType idx = 0; idx < numTuples; ++idx) fieldList.CopyData(0, input0, 0, numTuples, output, 0);
{
output->CopyData(fieldList, input0, 0, idx, idx);
}
self->UpdateProgress(0.1); self->UpdateProgress(0.1);
double progress_offset = 0.1; double progress_offset = 0.1;
......
...@@ -41,31 +41,24 @@ class vtkIntegrateAttributes::vtkFieldList : public vtkDataSetAttributes::FieldL ...@@ -41,31 +41,24 @@ class vtkIntegrateAttributes::vtkFieldList : public vtkDataSetAttributes::FieldL
typedef vtkDataSetAttributes::FieldList Superclass; typedef vtkDataSetAttributes::FieldList Superclass;
public: public:
vtkFieldList(int numInputs) vtkFieldList(int numInputs = 0)
: vtkDataSetAttributes::FieldList(numInputs) : Superclass(numInputs)
{ {
} }
void SetFieldIndex(int i, int index)
{ protected:
this->vtkDataSetAttributes::FieldList::SetFieldIndex(i, index); // overridden to only create vtkDoubleArray for numeric arrays.
} vtkSmartPointer<vtkAbstractArray> CreateArray(int type) const override
// 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)
{ {
this->Superclass::InitializeFieldList(dsa); if (auto array = this->Superclass::CreateArray(type))
for (int i = vtkDataSetAttributes::NUM_ATTRIBUTES; i < this->GetNumberOfFields(); i++)
{ {
if (this->GetFieldIndex(i) >= 0) const int is_numeric = (array->IsNumeric());
if (is_numeric)
{ {
vtkAbstractArray* aa = dsa->GetAbstractArray(this->GetFieldName(i)); return vtkSmartPointer<vtkAbstractArray>::Take(vtkDoubleArray::New());
if (vtkDataArray::SafeDownCast(aa) == NULL)
{
this->SetFieldIndex(i, -1);
}
} }
} }
return nullptr;
} }
}; };
...@@ -352,35 +345,11 @@ int vtkIntegrateAttributes::RequestData( ...@@ -352,35 +345,11 @@ int vtkIntegrateAttributes::RequestData(
if (compositeInput) if (compositeInput)
{ {
vtkCompositeDataIterator* iter = compositeInput->NewIterator(); 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 // Create the intersection field list. This is list of arrays common
// to all blocks in the input. // to all blocks in the input.
vtkFieldList pdList(index); vtkFieldList pdList;
vtkFieldList cdList(index); vtkFieldList cdList;
index = 0;
for (iter->InitTraversal(); !iter->IsDoneWithTraversal(); iter->GoToNextItem()) for (iter->InitTraversal(); !iter->IsDoneWithTraversal(); iter->GoToNextItem())
{ {
vtkDataObject* dobj = iter->GetCurrentDataObject(); vtkDataObject* dobj = iter->GetCurrentDataObject();
...@@ -391,17 +360,8 @@ int vtkIntegrateAttributes::RequestData( ...@@ -391,17 +360,8 @@ int vtkIntegrateAttributes::RequestData(
{ {
continue; // skip empty datasets. continue; // skip empty datasets.
} }
if (index == 0) pdList.IntersectFieldList(ds->GetPointData());
{ cdList.IntersectFieldList(ds->GetCellData());
pdList.InitializeFieldListForDataArrays(ds->GetPointData());
cdList.InitializeFieldListForDataArrays(ds->GetCellData());
}
else
{
pdList.IntersectFieldList(ds->GetPointData());
cdList.IntersectFieldList(ds->GetCellData());
}
index++;
} }
else else
{ {
...@@ -417,7 +377,7 @@ int vtkIntegrateAttributes::RequestData( ...@@ -417,7 +377,7 @@ int vtkIntegrateAttributes::RequestData(
this->AllocateAttributes(pdList, output->GetPointData()); this->AllocateAttributes(pdList, output->GetPointData());
this->AllocateAttributes(cdList, output->GetCellData()); this->AllocateAttributes(cdList, output->GetCellData());
index = 0; int index = 0;
// Now execute for each block. // Now execute for each block.
for (iter->InitTraversal(); !iter->IsDoneWithTraversal(); iter->GoToNextItem()) for (iter->InitTraversal(); !iter->IsDoneWithTraversal(); iter->GoToNextItem())
{ {
...@@ -438,8 +398,8 @@ int vtkIntegrateAttributes::RequestData( ...@@ -438,8 +398,8 @@ int vtkIntegrateAttributes::RequestData(
// Set all values to 0. All output attributes are type double. // Set all values to 0. All output attributes are type double.
vtkFieldList pdList(1); vtkFieldList pdList(1);
vtkFieldList cdList(1); vtkFieldList cdList(1);
pdList.InitializeFieldListForDataArrays(dsInput->GetPointData()); pdList.InitializeFieldList(dsInput->GetPointData());
cdList.InitializeFieldListForDataArrays(dsInput->GetCellData()); cdList.InitializeFieldList(dsInput->GetCellData());
this->AllocateAttributes(pdList, output->GetPointData()); this->AllocateAttributes(pdList, output->GetPointData());
this->AllocateAttributes(cdList, output->GetCellData()); this->AllocateAttributes(cdList, output->GetCellData());
this->ExecuteBlock(dsInput, output, 0, pdList, cdList); this->ExecuteBlock(dsInput, output, 0, pdList, cdList);
...@@ -622,27 +582,24 @@ void vtkIntegrateAttributes::ReceivePiece(vtkUnstructuredGrid* mergeTo, int from ...@@ -622,27 +582,24 @@ void vtkIntegrateAttributes::ReceivePiece(vtkUnstructuredGrid* mergeTo, int from
void vtkIntegrateAttributes::AllocateAttributes( void vtkIntegrateAttributes::AllocateAttributes(
vtkIntegrateAttributes::vtkFieldList& fieldList, vtkDataSetAttributes* outda) vtkIntegrateAttributes::vtkFieldList& fieldList, vtkDataSetAttributes* outda)
{ {
int numArrays = fieldList.GetNumberOfFields(); outda->CopyAllocate(fieldList);
for (int i = 0; i < numArrays; ++i) for (int cc = 0, max = outda->GetNumberOfArrays(); cc < max; ++cc)
{ {
if (fieldList.GetFieldIndex(i) < 0) auto array = vtkDoubleArray::SafeDownCast(outda->GetAbstractArray(cc));
{ assert(array != nullptr);
continue; array->SetNumberOfTuples(1);
}
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));
// It cannot hurt to zero the arrays here. // It cannot hurt to zero the arrays here.
for (int j = 0; j < numComponents; ++j) array->FillValue(0.0);
{ }
outArray->SetComponent(0, j, 0.0);
} for (int cc = 0; cc < vtkDataSetAttributes::NUM_ATTRIBUTES; ++cc)
fieldList.SetFieldIndex(i, outda->AddArray(outArray)); {
outArray->Delete(); // this should not be necessary, however, the old version of
// Should we set scalars, vectors ... // 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( ...@@ -87,7 +87,7 @@ int vtkPExtractHistogram::RequestData(
} }
vtkTable* output = vtkTable::GetData(outputVector, 0); 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) if (oldExtents == NULL)
{ {
// Nothing to do if there is no data // Nothing to do if there is no data
...@@ -122,7 +122,7 @@ int vtkPExtractHistogram::RequestData( ...@@ -122,7 +122,7 @@ int vtkPExtractHistogram::RequestData(
vtkErrorMacro(<< "Reduced data has 0 arrays"); vtkErrorMacro(<< "Reduced data has 0 arrays");
return 0; return 0;
} }
output->GetRowData()->GetArray((int)0)->DeepCopy(oldExtents); output->GetRowData()->GetArray("bin_extents")->DeepCopy(oldExtents);
if (this->CalculateAverages) if (this->CalculateAverages)
{ {
vtkDataArray* bin_values = output->GetRowData()->GetArray("bin_values"); 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