Commit 69a06e4d authored by Cory Quammen's avatar Cory Quammen
Browse files

KW00001404: Major overhaul of vtkAppendFilter

The previous behavior of vtkAppendFilter was to append data arrays set
as attributes and then only secondarily append data arrays by
name. This could lead to unexpected behavior as illustrated in the
following scenario:

- set two datasets are set as inputs to the filter
- each dataset has a point array named "A" and another named "B"
- in the first input, "A" is set as the scalar attribute
- in the second input, "B" is set as the scalar attribute

Previously, the output of vtkAppendFilter would append the scalar
attribute array "A" from the first input to the scalar attribute array
"B" from the second, storing the result in an array named "A" and
setting that as the scalar attribute in the output dataset. If you
reversed the order of inputs, the resulting scalar attribute array
would be named "B" and the output array would have the contents of "B"
followed by the contents of "A".

This patch changes the behavior of the vtkAppendFilter to merge arrays
primarily by name, which is more in line with how the rest of VTK
works. In the scenario above, the "A" arrays from the input are
appended together and the "B" arrays from the input are appended
together. Because "A" is set as the scalar attribute in one input and
"B" is set as the scalar in the other, the inputs disagree on which
array is the scalar attribute, so in the output no scalar attribute is
set. More broadly, if both inputs have arrays with the same name,
number of components, and data type set as an attribute, then the
result of appending those attribute arrays from the inputs will be set
as the attribute in the output. If any of those conditions are not
met, then the attribute will not be set in the output.

A somewhat special case is possible where the scalar attribute in the
inputs is set to an array with NULL name. If all inputs have their
scalar attribute set to an array with a NULL name, then the output's
scalar attribute will be an array that is the result of appending the
input scalar attribute arrays into a new array with a NULL name.

This patch also contributes a fairly comprehensive test for
the vtkAppendFilter.

Finally, this patch makes the vtkDataSetAttributes::SetAttribute()
method public instead of private.

Change-Id: Id3914957b65bfcce346968dc8fba6a3df0861cd8
parent 94cb2b46
......@@ -188,6 +188,30 @@ public:
// which attribute.
int IsArrayAnAttribute(int idx);
// Description:
// Set an array to use as the given attribute type (i.e.,
// vtkDataSetAttributes::SCALAR, vtkDataSetAttributes::VECTOR,
// vtkDataSetAttributes::TENSOR, etc.). If this attribute was
// previously set to another array, that array is removed from the
// vtkDataSetAttributes object and the array aa is used as the
// attribute.
//
// Returns the index of aa within the vtkDataSetAttributes object
// (i.e., the index to pass to the method GetArray(int) to obtain
// aa) if the attribute was set to aa successfully. If aa was
// already set as the given attributeType, returns the index of
// aa.
//
// Returns -1 in the following cases:
//
// - aa is NULL (used to unset an attribute; not an error indicator)
// - aa is not a subclass of vtkDataArray, unless the attributeType
// is vtkDataSetAttributes::PEDIGREEIDS (error indicator)
// - aa has a number of components incompatible with the attribute type
// (error indicator)
//
int SetAttribute(vtkAbstractArray* aa, int attributeType);
// Description:
// Return an attribute given the attribute type
// (see vtkDataSetAttributes::AttributeTypes).
......@@ -591,7 +615,6 @@ protected:
static const char LongAttributeNames[NUM_ATTRIBUTES][35];
private:
int SetAttribute(vtkAbstractArray* da, int attributeType);
static int CheckNumberOfComponents(vtkAbstractArray* da, int attributeType);
vtkFieldData::BasicIterator ComputeRequiredArrays(vtkDataSetAttributes* pd, int ctype);
......@@ -675,5 +698,3 @@ public:
};
#endif
vtk_add_test_cxx(${vtk-module}CxxTests tests
TestAppendFilter.cxx,NO_VALID
TestAppendPolyData.cxx,NO_VALID
TestAppendSelection.cxx,NO_VALID
TestArrayCalculator.cxx,NO_VALID
......
This diff is collapsed.
This diff is collapsed.
......@@ -30,6 +30,7 @@
#include "vtkFiltersCoreModule.h" // For export macro
#include "vtkUnstructuredGridAlgorithm.h"
class vtkDataSetAttributes;
class vtkDataSetCollection;
class VTKFILTERSCORE_EXPORT vtkAppendFilter : public vtkUnstructuredGridAlgorithm
......@@ -87,15 +88,6 @@ protected:
virtual int FillInputPortInformation(int port, vtkInformation *info);
// Description:
// This function appends multiple blocks / pieces into a vtkUnstructuredGrid
// data by using a point locator to merge duplicate points (when ghost cell
// information is not available from the input data blocks / pieces).
// This function should be called by RequestData() only.
int AppendBlocksWithPointLocator( vtkInformationVector ** inputVector,
vtkInformationVector * outputVector );
// list of data sets to append together.
// Here as a convenience. It is a copy of the input array.
vtkDataSetCollection *InputList;
......@@ -109,6 +101,15 @@ protected:
private:
vtkAppendFilter(const vtkAppendFilter&); // Not implemented.
void operator=(const vtkAppendFilter&); // Not implemented.
// Get all input data sets that have points, cells, or both.
// Caller must delete the returned vtkDataSetCollection.
vtkDataSetCollection* GetNonEmptyInputs(vtkInformationVector ** inputVector);
void AppendArrays(vtkDataSetAttributes* (*selector)(vtkDataSet*),
vtkInformationVector **inputVector,
vtkIdType* globalIds,
vtkUnstructuredGrid* output);
};
......
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