Commits (27)
......@@ -50,8 +50,8 @@ public:
virtual void *GetGenericParentId() = 0;
virtual void *GetGenericContext() = 0;
virtual void *GetGenericDrawable() = 0;
virtual void SetWindowInfo(char *) = 0;
virtual void SetParentInfo(char *) = 0;
virtual void SetWindowInfo(const char *) = 0;
virtual void SetParentInfo(const char *) = 0;
//@}
//@{
......
......@@ -40,6 +40,7 @@ set(Module_SRCS
vtkDataObjectTree.cxx
vtkDataObjectTreeIterator.cxx
vtkDataSetAttributes.cxx
vtkDataSetAttributesFieldList.cxx
vtkDataSetCollection.cxx
vtkDataSet.cxx
vtkDirectedAcyclicGraph.cxx
......
......@@ -12,6 +12,7 @@ vtk_add_test_cxx(vtkCommonDataModelCxxTests tests
TestDataArrayDispatcher.cxx
TestDataObject.cxx
TestDispatchers.cxx
TestFieldList.cxx
TestGenericCell.cxx
TestGraph.cxx
TestGraph2.cxx
......
#include "vtkDataSetAttributes.h"
#include "vtkDoubleArray.h"
#include "vtkIntArray.h"
#include "vtkNew.h"
#include "vtkSmartPointer.h"
#include <string>
namespace
{
template <typename T>
vtkSmartPointer<T> CreateArray(const char* aname, int num_comps, vtkIdType numTuples)
{
auto array = vtkSmartPointer<T>::New();
array->SetName(aname);
array->SetNumberOfComponents(num_comps);
array->SetNumberOfTuples(numTuples);
array->FillValue(typename T::ValueType());
return array;
}
#define EXPECT_THAT(v, m) \
if ((v) != (m)) \
{ \
cerr << "FAILED at line " << __LINE__ << ": \n " << #v << " must match " << #m << endl; \
return EXIT_FAILURE; \
}
}
int TestFieldList(int, char* [])
{
{
// For arrays without names, ensure we are doing a order-dependent matching.
// For attributes, the attribute flag is preserved if the same arrays is
// consistently flagged as an attribute on all DSA instances.
vtkNew<vtkDataSetAttributes> dsa0;
dsa0->SetScalars(CreateArray<vtkDoubleArray>(nullptr, 1, 20));
dsa0->AddArray(CreateArray<vtkDoubleArray>(nullptr, 2, 20));
dsa0->SetVectors(CreateArray<vtkDoubleArray>(nullptr, 3, 20));
EXPECT_THAT(dsa0->GetNumberOfArrays(), 3);
vtkNew<vtkDataSetAttributes> dsa1;
dsa1->SetScalars(CreateArray<vtkDoubleArray>(nullptr, 1, 20));
dsa1->AddArray(CreateArray<vtkDoubleArray>(nullptr, 3, 20));
dsa1->AddArray(CreateArray<vtkDoubleArray>(nullptr, 3, 20));
EXPECT_THAT(dsa1->GetNumberOfArrays(), 3);
vtkDataSetAttributes::FieldList fl;
fl.InitializeFieldList(dsa0);
fl.IntersectFieldList(dsa1);
vtkNew<vtkDataSetAttributes> output;
fl.CopyAllocate(output, vtkDataSetAttributes::COPYTUPLE, 0, 0);
EXPECT_THAT(output->GetNumberOfArrays(), 2);
EXPECT_THAT(output->GetArray(0)->GetNumberOfComponents(), 1);
EXPECT_THAT(output->GetArray(1)->GetNumberOfComponents(), 3);
EXPECT_THAT(output->GetVectors(), nullptr);
EXPECT_THAT(output->GetScalars() != nullptr, true);
fl.InitializeFieldList(dsa0);
fl.UnionFieldList(dsa1);
output->Initialize();
fl.CopyAllocate(output, vtkDataSetAttributes::COPYTUPLE, 0, 0);
EXPECT_THAT(output->GetNumberOfArrays(), 4);
EXPECT_THAT(output->GetArray(0)->GetNumberOfComponents(), 1);
EXPECT_THAT(output->GetArray(1)->GetNumberOfComponents(), 2);
EXPECT_THAT(output->GetArray(2)->GetNumberOfComponents(), 3);
EXPECT_THAT(output->GetArray(3)->GetNumberOfComponents(), 3);
EXPECT_THAT(output->GetVectors(), nullptr);
EXPECT_THAT(output->GetScalars() != nullptr, true);
// just to increase coverage.
fl.PrintSelf(cout, vtkIndent());
}
{
// If inputs arrays with different names for attributes,
// make sure output doesn't have either of the arrays flagged as attributes.
vtkNew<vtkDataSetAttributes> dsa0;
dsa0->SetScalars(CreateArray<vtkDoubleArray>("scalars", 1, 20));
dsa0->AddArray(CreateArray<vtkDoubleArray>("vectors", 3, 20));
dsa0->AddArray(CreateArray<vtkDoubleArray>("common", 1, 20));
dsa0->AddArray(CreateArray<vtkDoubleArray>("uncommon0", 1, 20));
vtkNew<vtkDataSetAttributes> dsa1;
dsa1->AddArray(CreateArray<vtkDoubleArray>("scalars", 1, 20));
dsa1->SetVectors(CreateArray<vtkDoubleArray>("vectors", 3, 20));
dsa1->AddArray(CreateArray<vtkDoubleArray>("common", 1, 20));
dsa0->AddArray(CreateArray<vtkDoubleArray>("uncommon1", 1, 20));
vtkDataSetAttributes::FieldList fl;
fl.InitializeFieldList(dsa0);
fl.IntersectFieldList(dsa1);
vtkNew<vtkDataSetAttributes> output;
fl.CopyAllocate(output, vtkDataSetAttributes::COPYTUPLE, 0, 0);
EXPECT_THAT(output->GetNumberOfArrays(), 3);
EXPECT_THAT(output->GetArray("uncommon0"), nullptr);
EXPECT_THAT(output->GetArray("uncommon1"), nullptr);
EXPECT_THAT(output->GetScalars(), nullptr);
EXPECT_THAT(output->GetVectors(), nullptr);
EXPECT_THAT(output->GetArray("scalars") != nullptr, true);
EXPECT_THAT(output->GetArray("vectors") != nullptr, true);
fl.InitializeFieldList(dsa0);
fl.UnionFieldList(dsa1);
output->Initialize();
fl.CopyAllocate(output, vtkDataSetAttributes::COPYTUPLE, 0, 0);
EXPECT_THAT(output->GetNumberOfArrays(), 5);
EXPECT_THAT(output->GetScalars(), nullptr);
EXPECT_THAT(output->GetVectors(), nullptr);
}
return EXIT_SUCCESS;
}
This diff is collapsed.
......@@ -44,7 +44,8 @@
#ifndef vtkDataSetAttributes_h
#define vtkDataSetAttributes_h
#include "vtkCommonDataModelModule.h" // For export macro
#include "vtkCommonDataModelModule.h" // For export macro
#include "vtkDataSetAttributesFieldList.h" // for vtkDataSetAttributesFieldList
#include "vtkFieldData.h"
class vtkLookupTable;
......@@ -546,7 +547,7 @@ public:
vtkDataSetAttributes *from2,
vtkIdType id, double t);
class FieldList;
using FieldList = vtkDataSetAttributesFieldList;
// field list copy operations ------------------------------------------
......@@ -591,8 +592,6 @@ public:
int idx, vtkIdType toId,
vtkIdList *ids, double *weights);
friend class vtkDataSetAttributes::FieldList;
protected:
vtkDataSetAttributes();
~vtkDataSetAttributes() override;
......@@ -604,11 +603,6 @@ protected:
int shallowCopyArrays=0,
bool createNewArrays=true);
void InternalCopyAllocate(
vtkDataSetAttributes::FieldList& list,
int ctype,
vtkIdType sze, vtkIdType ext);
/**
* Initialize all of the object's data to nullptr
*/
......@@ -635,79 +629,7 @@ private:
vtkDataSetAttributes(const vtkDataSetAttributes&) = delete;
void operator=(const vtkDataSetAttributes&) = delete;
public:
// This public class is used to perform set operations, other misc.
// operations on fields. For example, vtkAppendFilter uses it to
// determine which attributes the input datasets share in common.
class vtkInternalComponentNames;
class VTKCOMMONDATAMODEL_EXPORT FieldList
{
public:
FieldList(int numInputs);
~FieldList();
void PrintSelf(ostream &os, vtkIndent indent);
void InitializeFieldList(vtkDataSetAttributes* dsa);
void IntersectFieldList(vtkDataSetAttributes* dsa);
/**
* Similar to IntersectFieldList() except that it builds a union of the
* array list. To determine the active attributes, it still, however, takes
* an intersection.
* WARNING!!!-IntersectFieldList() and UnionFieldList() should not be
* intermixed.
*/
void UnionFieldList(vtkDataSetAttributes* dsa);
//Determine whether data is available
int IsAttributePresent(int attrType); //true/false attributes specified
// Accessor methods.
int GetNumberOfFields() { return this->NumberOfFields; }
int GetFieldIndex(int i) { return this->FieldIndices[i]; }
const char* GetFieldName(int i) { return this->Fields[i]; }
int GetFieldComponents(int i) { return this->FieldComponents[i]; }
int GetDSAIndex(int index, int i) { return this->DSAIndices[index][i]; }
friend class vtkDataSetAttributes;
protected:
void SetFieldIndex(int i, int index)
{ this->FieldIndices[i] = index; }
private:
FieldList(const FieldList&) = delete;
void operator=(const FieldList&) = delete;
void SetField(int index, vtkAbstractArray *da);
void RemoveField(const char *name);
void ClearFields();
void GrowBy(unsigned int delta);
int NumberOfFields; //the number of fields (including five named attributes)
// These keep track of what is common across datasets. The first
// six items are always named attributes.
char** Fields; // the names of the fields
int *FieldTypes; // the types of the fields
int *FieldComponents; // the number of components in field
int *FieldIndices; // output data array index
vtkLookupTable **LUT; // luts associated with each array
vtkInformation **FieldInformation; // Information map associated with each array
vtkInternalComponentNames **FieldComponentsNames; // the name for each component in the field
vtkIdType NumberOfTuples; // a running total of values
//For every vtkDataSetAttributes that are processed, keep track of the
//indices into various things. The indices are organized so that the
//first NUM_ATTRIBUTES refer to attributes, the next refer to the
//non-attribute fields, for a total of NUM_ATTRIBUTES + NumberOfFields.
//CurrentInput is the current input being processed.
int **DSAIndices;
int NumberOfDSAIndices;
int CurrentInput;
};
friend class vtkDataSetAttributesFieldList;
};
#endif
This diff is collapsed.
/*=========================================================================
Program: Visualization Toolkit
Module: vtkDataSetAttributesFieldList.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
/**
* @class vtkDataSetAttributesFieldList
* @brief helps manage arrays from multiple vtkDataSetAttributes.
*
* vtkDataSetAttributesFieldList, also called vtkDataSetAttributes::FieldList,
* is used to help with filters when dealing with arrays from multiple
* vtkDataSetAttributes instances, potentially from multiple inputs.
*
* Consider a filter that appends multiple inputs, e.g. vtkAppendPolyData.
* Besides appending mesh elements, such a filter also needs to combine field
* arrays (point, and cell data) from inputs to pass on to the output.
* Now if all the inputs had exactly the same set of arrays, we're all set.
* However, more often than not, the inputs will have different sets of arrays.
* The filter will need to match up from various inputs to combine together,
* potentially dropping arrays not in all inputs. Furthermore, it needs to
* ensure arrays in the output are flagged as attributes consistently. All of
* this can be done using vtkDataSetAttributesFieldList.
*
* @section Usage Usage
*
* Typical usage is as follows:
* 1. call `IntersectFieldList` or `UnionFieldList` for all input vtkDataSetAttributes
* instances,
* 2. allocate arrays for the output vtkDataSetAttributes by using `CopyAllocate`,
* 3. call `CopyData` per input (preserving the input order used in step 1) to
* copy tuple(s) from input to the output.
*
* `vtkDataSetAttributes::InitializeFieldList` is provided for API compatibility
* with previous implementation of this class and it not required to be called.
* Simply calling `UnionFieldList` or `IntersectFieldList` for the first
* vtkDataSetAttributes instance is sufficient.
*
* `CopyAllocate, `CopyData`, and `InterpolatePoint` methods on this class
* are called by similarly named variants on vtkDataSetAttributes that take in a
* FieldList instance as an argument. Hence, either forms may be used.
*
* Calls to `UnionFieldList` and `IntersectFieldList` cannot be mixed. Use
* `Reset` or `InitializeFieldList` to change mode and start reinitialization.
*/
#ifndef vtkDataSetAttributesFieldList_h
#define vtkDataSetAttributesFieldList_h
#include "vtkCommonDataModelModule.h" // For export macro
#include "vtkSystemIncludes.h"
#include "vtkSmartPointer.h" // for vtkSmartPointer
#include <memory> // for unique_ptr
class vtkAbstractArray;
class vtkDataSetAttributes;
class vtkIdList;
class VTKCOMMONDATAMODEL_EXPORT vtkDataSetAttributesFieldList
{
public:
/**
* `number_of_inputs` parameter is not required and only provided for
* backwards compatibility.
*/
vtkDataSetAttributesFieldList(int number_of_inputs = 0);
virtual ~vtkDataSetAttributesFieldList();
void PrintSelf(ostream& os, vtkIndent indent);
/**
* Initializes the field list to empty.
*/
void Reset();
/**
* Initialize the field list. This also adds the first input.
* Calling this method is optional. The first call to `IntersectFieldList` or
* `UnionFieldList` on a new instance or after calling `Reset()` will have the
* same effect.
*/
void InitializeFieldList(vtkDataSetAttributes* dsa);
/**
* Update the field list for an intersection of arrays registered so far and
* those in `dsa`.
*/
void IntersectFieldList(vtkDataSetAttributes* dsa);
/**
* Update the field list for an union of arrays registered so far and
* those in `dsa`.
*/
void UnionFieldList(vtkDataSetAttributes* dsa);
//@{
/**
* These methods can called to generate and update the output
* vtkDataSetAttributes. These match corresponding API on vtkDataSetAttributes
* and can be called via the output vtkDataSetAttributes instance
* instead as well.
*/
void CopyAllocate(vtkDataSetAttributes* output, int ctype, vtkIdType sz, vtkIdType ext) const;
void CopyData(int inputIndex, vtkDataSetAttributes* input, vtkIdType fromId,
vtkDataSetAttributes* output, vtkIdType toId) const;
void CopyData(int inputIdx, vtkDataSetAttributes* input, vtkIdType inputStart,
vtkIdType numValues, vtkDataSetAttributes* output, vtkIdType outStart) const;
void InterpolatePoint(int inputIdx, vtkDataSetAttributes* input, vtkIdList* inputIds,
double* weights, vtkDataSetAttributes* output, vtkIdType toId) const;
//@}
//@{
/**
* vtkDataSetAttributes::FieldList used a different internal data structure in
* older versions of VTK. This exposes that API for legacy applications.
* It may be deprecated in the future.
*
* Using these methods should be avoided in new code.
*/
int IsAttributePresent(int attrType) const;
int GetNumberOfFields() const;
int GetFieldIndex(int i) const;
const char* GetFieldName(int i) const;
int GetFieldComponents(int i) const;
int GetDSAIndex(int index, int i) const;
//@}
protected:
/**
* Called to create an output array for the given type.
* Default implementation calls `vtkAbstractArray::CreateArray()`.
*/
virtual vtkSmartPointer<vtkAbstractArray> CreateArray(int type) const;
private:
class vtkInternals;
std::unique_ptr<vtkInternals> Internals;
vtkDataSetAttributesFieldList(const vtkDataSetAttributesFieldList&) = delete;
void operator=(vtkDataSetAttributesFieldList&) = delete;
};
#endif
// VTK-HeaderTest-Exclude: vtkDataSetAttributesFieldList.h
......@@ -17,7 +17,6 @@
#include "vtkBoundingBox.h"
#include "vtkCellData.h"
#include "vtkCell.h"
#include "vtkDataSetAttributes.h"
#include "vtkDataSetCollection.h"
#include "vtkExecutive.h"
#include "vtkIncrementalOctreePointLocator.h"
......@@ -30,7 +29,6 @@
#include "vtkUnstructuredGrid.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include <set>
#include <string>
vtkStandardNewMacro(vtkAppendFilter);
......@@ -391,251 +389,42 @@ void vtkAppendFilter::AppendArrays(int attributesType,
return;
}
//////////////////////////////////////////////////////////////////
// Phase 1 - Find arrays to append based on name
//////////////////////////////////////////////////////////////////
// Store the set of data arrays common to all inputs. This set is
// initialized with the data arrays from the first input and is
// updated to be the intersection of it with the arrays from
// subsequent inputs.
std::set<std::string> dataArrayNames;
vtkDataSetAttributes* outputData = output->GetAttributes(attributesType);
bool isFirstInputData = true;
vtkDataSetAttributes* firstInputData = nullptr;
vtkSmartPointer<vtkDataSetCollection> inputs;
inputs.TakeReference(this->GetNonEmptyInputs(inputVector));
vtkDataSetAttributes::FieldList fieldList;
auto inputs = vtkSmartPointer<vtkDataSetCollection>::Take(this->GetNonEmptyInputs(inputVector));
vtkCollectionSimpleIterator iter;
inputs->InitTraversal(iter);
vtkDataSet* dataSet = nullptr;
while ((dataSet = inputs->GetNextDataSet(iter)))
{
vtkDataSetAttributes* inputData = dataSet->GetAttributes(attributesType);
if (isFirstInputData)
{
isFirstInputData = false;
firstInputData = inputData;
for (int arrayIndex = 0; arrayIndex < inputData->GetNumberOfArrays(); ++arrayIndex)
{
vtkAbstractArray* array = inputData->GetAbstractArray(arrayIndex);
if (array && array->GetName())
{
// NOTE - it is possible for an array to not have a name,
// but be an active attribute. We'll deal with that case
// later on.
dataArrayNames.insert(std::string(array->GetName()));
}
}
}
else
{
std::set<std::string>::iterator it = dataArrayNames.begin();
while (it != dataArrayNames.end())
{
const char* arrayName = it->c_str();
vtkAbstractArray* array = inputData->GetAbstractArray(arrayName);
vtkAbstractArray* firstArray = firstInputData->GetAbstractArray(arrayName);
if (!array ||
array->GetDataType() != firstArray->GetDataType() ||
array->GetNumberOfComponents() != firstArray->GetNumberOfComponents())
{
// Incompatible array in this input. We can't append it.
dataArrayNames.erase(it++);
}
else
{
++it;
}
}
}
}
// Allocate arrays for the output
for (std::set<std::string>::iterator it = dataArrayNames.begin(); it != dataArrayNames.end(); ++it)
{
vtkAbstractArray* srcArray = firstInputData->GetAbstractArray((*it).c_str());
vtkAbstractArray* dstArray = vtkAbstractArray::CreateArray(srcArray->GetDataType());
dstArray->CopyInformation(srcArray->GetInformation());
dstArray->SetName(srcArray->GetName());
dstArray->SetNumberOfComponents(srcArray->GetNumberOfComponents());
for (int j = 0; j < srcArray->GetNumberOfComponents(); ++j)
{
if (srcArray->GetComponentName(j))
{
dstArray->SetComponentName(j, srcArray->GetComponentName(j));
}
}
dstArray->SetNumberOfTuples(totalNumberOfElements);
outputData->AddArray(dstArray);
dstArray->Delete();
}
//////////////////////////////////////////////////////////////////
// Phase 2 - Set up arrays as attributes
//////////////////////////////////////////////////////////////////
// Set active attributes in the outputs only if all the inputs have
// the same active attributes name (or the name is nullptr).
vtkAbstractArray* attributeArrays[vtkDataSetAttributes::NUM_ATTRIBUTES];
// Initialize with the active attribute from the first input
for (int attribute = 0; attribute < vtkDataSetAttributes::NUM_ATTRIBUTES; ++attribute)
{
attributeArrays[attribute] = firstInputData->GetAbstractAttribute(attribute);
}
inputs->InitTraversal(iter);
while ((dataSet = inputs->GetNextDataSet(iter)))
{
for (int attributeIndex = 0; attributeIndex < vtkDataSetAttributes::NUM_ATTRIBUTES; ++attributeIndex)
{
if (attributeArrays[attributeIndex])
{
vtkDataSetAttributes* inputData = dataSet->GetAttributes(attributesType);
vtkAbstractArray* thisArray = inputData->GetAbstractAttribute(attributeIndex);
bool matches = thisArray &&
((attributeArrays[attributeIndex]->GetName() == nullptr && thisArray->GetName() == nullptr) ||
strcmp(attributeArrays[attributeIndex]->GetName(), thisArray->GetName()) == 0);
if (!matches)
{
// This input doesn't agree on the active attribute, so unset it.
attributeArrays[attributeIndex] = nullptr;
}
}
}
}
// Set the active attributes
for (int attributeIndex = 0; attributeIndex < vtkDataSetAttributes::NUM_ATTRIBUTES; ++attributeIndex)
for (dataSet = nullptr, inputs->InitTraversal(iter); (dataSet = inputs->GetNextDataSet(iter)); )
{
if (attributeArrays[attributeIndex])
if (auto inputData = dataSet->GetAttributes(attributesType))
{
const char* arrayName = attributeArrays[attributeIndex]->GetName();
if (arrayName)
{
outputData->SetActiveAttribute(arrayName, attributeIndex);
}
fieldList.IntersectFieldList(inputData);
}
}
//////////////////////////////////////////////////////////////////
// Phase 3 - Handle attributes with no name
//////////////////////////////////////////////////////////////////
// Now check if we need nullptr-named arrays for the special case where
// the active attributes are set to an array with a nullptr name. It's
// important to point out that vtkFieldData can have more than one
// array with a nullptr name. We append only those arrays with a nullptr
// name that are set as the active attribute because otherwise we
// have no information about how to append nullptr-named arrays.
bool attributeNeedsNullArray[vtkDataSetAttributes::NUM_ATTRIBUTES];
for (int attributeIndex = 0; attributeIndex < vtkDataSetAttributes::NUM_ATTRIBUTES; ++attributeIndex)
{
attributeNeedsNullArray[attributeIndex] = true;
}
inputs->InitTraversal(iter);
while ((dataSet = inputs->GetNextDataSet(iter)))
{
for (int attributeIndex = 0; attributeIndex < vtkDataSetAttributes::NUM_ATTRIBUTES; ++attributeIndex)
{
// Check if the attribute array name is nullptr. If attribute is
// not set or the name is not nullptr, we do not need a nullptr
// array.
vtkDataSetAttributes *inputData = dataSet->GetAttributes(attributesType);
vtkDataArray* attributeArray = inputData->GetAttribute(attributeIndex);
vtkDataArray* firstAttributeArray = firstInputData->GetAttribute(attributeIndex);
if (!attributeArray || attributeArray->GetName() ||
(attributeArray->GetNumberOfComponents() != firstAttributeArray->GetNumberOfComponents()) ||
(attributeArray->GetDataType() != firstAttributeArray->GetDataType()))
{
attributeNeedsNullArray[attributeIndex] = false;
}
}
}
// Now allocate the attribute arrays we need
for (int attributeIndex = 0; attributeIndex < vtkDataSetAttributes::NUM_ATTRIBUTES; ++attributeIndex)
{
if (attributeNeedsNullArray[attributeIndex])
{
vtkAbstractArray* srcArray = firstInputData->GetAttribute(attributeIndex);
vtkAbstractArray* dstArray = vtkAbstractArray::CreateArray(srcArray->GetDataType());
dstArray->SetNumberOfComponents(srcArray->GetNumberOfComponents());
for (int j = 0; j < srcArray->GetNumberOfComponents(); ++j)
{
if (srcArray->GetComponentName(j))
{
dstArray->SetComponentName(j, srcArray->GetComponentName(j));
}
}
dstArray->SetNumberOfTuples(totalNumberOfElements);
outputData->SetAttribute(dstArray, attributeIndex);
dstArray->Delete();
}
}
vtkDataSetAttributes* outputData = output->GetAttributes(attributesType);
outputData->CopyAllocate(fieldList, totalNumberOfElements);
//////////////////////////////////////////////////////////////
// Phase 4 - Copy data
//////////////////////////////////////////////////////////////
// copy arrays.
int inputIndex;
vtkIdType offset = 0;
inputs->InitTraversal(iter);
while ((dataSet = inputs->GetNextDataSet(iter)))
for (inputIndex = 0, dataSet = nullptr, inputs->InitTraversal(iter); (dataSet = inputs->GetNextDataSet(iter));)
{
vtkDataSetAttributes* inputData = dataSet->GetAttributes(attributesType);
for (std::set<std::string>::iterator it = dataArrayNames.begin(); it != dataArrayNames.end(); ++it)
if (auto inputData = dataSet->GetAttributes(attributesType))
{
const char* arrayName = it->c_str();
vtkAbstractArray* srcArray = inputData->GetAbstractArray(arrayName);
vtkAbstractArray* dstArray = outputData->GetAbstractArray(arrayName);
for (vtkIdType id = 0; id < srcArray->GetNumberOfTuples(); ++id)
const auto numberOfInputTuples = inputData->GetNumberOfTuples();
if (globalIds != nullptr)
{
if (globalIds)
{
dstArray->SetTuple(globalIds[id + offset], id, srcArray);
}
else
for (vtkIdType id=0; id < numberOfInputTuples; ++id)
{
dstArray->SetTuple(id + offset, id, srcArray);
fieldList.CopyData(inputIndex, inputData, id, outputData, offset + id);
}
}
}
// Copy attributes
for (int attribute = 0; attribute < vtkDataSetAttributes::NUM_ATTRIBUTES; ++attribute)
{
vtkAbstractArray* srcArray = inputData->GetAbstractAttribute(attribute);
vtkAbstractArray* dstArray = outputData->GetAbstractAttribute(attribute);
// Copy if only the array name is nullptr. If the array name is non-nullptr, it will
// have been copied in the loop above.
if (srcArray && !srcArray->GetName() &&
dstArray && !dstArray->GetName())
else
{
for (vtkIdType id = 0; id < srcArray->GetNumberOfTuples(); ++id)
{
if (globalIds)
{
dstArray->SetTuple(globalIds[id + offset], id, srcArray);
}
else
{
dstArray->SetTuple(id + offset, id, srcArray);
}
}
fieldList.CopyData(inputIndex, inputData, 0, numberOfInputTuples, outputData, offset);
}
}
if (attributesType == vtkDataObject::POINT)
{
offset += dataSet->GetNumberOfPoints();
}
else if (attributesType == vtkDataObject::CELL)
{
offset += dataSet->GetNumberOfCells();
offset += numberOfInputTuples;
++inputIndex;
}
}
}
......
......@@ -143,11 +143,6 @@ int vtkAppendPolyData::ExecuteAppend(vtkPolyData* output,
vtkCellData *inCD = nullptr;
vtkPointData *outputPD = output->GetPointData();
vtkCellData *outputCD = output->GetCellData();
vtkDataArray *newPtScalars = nullptr;
vtkDataArray *newPtVectors = nullptr;
vtkDataArray *newPtNormals = nullptr;
vtkDataArray *newPtTCoords = nullptr;
vtkDataArray *newPtTensors = nullptr;
vtkIdType *pStrips, *pLines, *pPolys,*pVerts;
vtkDebugMacro(<<"Appending polydata");
......@@ -336,80 +331,6 @@ int vtkAppendPolyData::ExecuteAppend(vtkPolyData* output,
return 0;
}
// These are created manually for faster execution
// Uses the properties of the last input
vtkDataArray *inDA=nullptr;
if ( ptList.IsAttributePresent(vtkDataSetAttributes::SCALARS) > -1 )
{
inDA=inPD->GetScalars();
outputPD->CopyScalarsOff();
newPtScalars = inDA->NewInstance();
newPtScalars->SetNumberOfComponents(inDA->GetNumberOfComponents());
newPtScalars->CopyComponentNames( inDA );
newPtScalars->SetName(inDA->GetName());
newPtScalars->SetNumberOfTuples(numPts);
if (inDA->HasInformation())
{
newPtScalars->CopyInformation(inDA->GetInformation(),/*deep=*/1);
}
}
if ( ptList.IsAttributePresent(vtkDataSetAttributes::VECTORS) > -1 )
{
inDA=inPD->GetVectors();
outputPD->CopyVectorsOff();
newPtVectors = inDA->NewInstance();
newPtVectors->SetNumberOfComponents(inDA->GetNumberOfComponents());
newPtVectors->CopyComponentNames( inDA );
newPtVectors->SetName(inDA->GetName());
newPtVectors->SetNumberOfTuples(numPts);
if (inDA->HasInformation())
{
newPtVectors->CopyInformation(inDA->GetInformation(),/*deep=*/1);
}
}
if ( ptList.IsAttributePresent(vtkDataSetAttributes::TENSORS) > -1 )
{
inDA=inPD->GetTensors();
outputPD->CopyTensorsOff();
newPtTensors = inDA->NewInstance();
newPtTensors->SetNumberOfComponents(inDA->GetNumberOfComponents());
newPtTensors->CopyComponentNames( inDA );
newPtTensors->SetName(inDA->GetName());
newPtTensors->SetNumberOfTuples(numPts);
if (inDA->HasInformation())
{
newPtTensors->CopyInformation(inDA->GetInformation(),/*deep=*/1);
}
}
if ( ptList.IsAttributePresent(vtkDataSetAttributes::NORMALS) > -1 )
{
inDA=inPD->GetNormals();
outputPD->CopyNormalsOff();
newPtNormals = inDA->NewInstance();
newPtNormals->SetNumberOfComponents(inDA->GetNumberOfComponents());
newPtNormals->CopyComponentNames( inDA );
newPtNormals->SetName(inDA->GetName());
newPtNormals->SetNumberOfTuples(numPts);
if (inDA->HasInformation())
{
newPtNormals->CopyInformation(inDA->GetInformation(),/*deep=*/1);
}
}
if ( ptList.IsAttributePresent(vtkDataSetAttributes::TCOORDS) > -1 )
{
inDA=inPD->GetTCoords();
outputPD->CopyTCoordsOff();
newPtTCoords = inDA->NewInstance();
newPtTCoords->SetNumberOfComponents(inDA->GetNumberOfComponents());
newPtTCoords->CopyComponentNames( inDA );
newPtTCoords->SetName(inDA->GetName());
newPtTCoords->SetNumberOfTuples(numPts);
if (inDA->HasInformation())
{
newPtTCoords->CopyInformation(inDA->GetInformation(),/*deep=*/1);
}
}
// Allocate the point and cell data
outputPD->CopyAllocate(ptList,numPts);
outputCD->CopyAllocate(cellList,numCells);
......@@ -447,35 +368,7 @@ int vtkAppendPolyData::ExecuteAppend(vtkPolyData* output,
if (ds->GetNumberOfPoints() > 0)
{
// copy points directly
this->AppendData(newPts->GetData(),
inPts->GetData(), ptOffset);
// copy scalars directly
if (newPtScalars)
{
this->AppendData(newPtScalars, inPD->GetScalars(), ptOffset);
}
// copy normals directly
if (newPtNormals)
{
this->AppendData(newPtNormals, inPD->GetNormals(), ptOffset);
}
// copy vectors directly
if (newPtVectors)
{
this->AppendData(newPtVectors, inPD->GetVectors(), ptOffset);
}
// copy tcoords directly
if (newPtTCoords)
{
this->AppendData(newPtTCoords, inPD->GetTCoords() , ptOffset);
}
// copy tensors directly
if (newPtTensors)
{
this->AppendData(newPtTensors, inPD->GetTensors(), ptOffset);
}
// append the remainder of the field data
this->AppendData(newPts->GetData(), inPts->GetData(), ptOffset);
outputPD->CopyData(ptList, inPD, countPD, ptOffset, numPts, 0);
++countPD;
}
......@@ -514,32 +407,6 @@ int vtkAppendPolyData::ExecuteAppend(vtkPolyData* output,
output->SetPoints(newPts);
newPts->Delete();
if (newPtScalars)
{
output->GetPointData()->SetScalars(newPtScalars);
newPtScalars->Delete();
}
if (newPtNormals)
{
output->GetPointData()->SetNormals(newPtNormals);
newPtNormals->Delete();
}
if (newPtVectors)
{
output->GetPointData()->SetVectors(newPtVectors);
newPtVectors->Delete();
}
if (newPtTCoords)
{
output->GetPointData()->SetTCoords(newPtTCoords);
newPtTCoords->Delete();
}
if (newPtTensors)
{
output->GetPointData()->SetTensors(newPtTensors);
newPtTensors->Delete();
}
if ( newVerts->GetNumberOfCells() > 0 )
{
output->SetVerts(newVerts);
......
......@@ -46,7 +46,8 @@ int vtkCompositeDataProbeFilter::FillInputPortInformation(
{
// We have to save vtkDataObject since this filter can work on vtkDataSet
// and vtkCompositeDataSet consisting of vtkDataSet leaf nodes.
info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkDataObject");
info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkCompositeDataSet");
info->Append(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkDataSet");
}
return 1;
}
......
......@@ -440,7 +440,7 @@ void vtkDataObjectToDataSetFilter::PrintSelf(ostream& os, vtkIndent indent)
// Stuff related to points --------------------------------------------
//
void vtkDataObjectToDataSetFilter::SetPointComponent(int comp,
char *arrayName,
const char *arrayName,
int arrayComp,
int min, int max,
int normalize)
......@@ -724,7 +724,7 @@ vtkIdType vtkDataObjectToDataSetFilter::ConstructPoints(vtkDataObject *input,
//----------------------------------------------------------------------------
// Stuff related to vtkPolyData --------------------------------------------
//
void vtkDataObjectToDataSetFilter::SetVertsComponent(char *arrayName,
void vtkDataObjectToDataSetFilter::SetVertsComponent(const char *arrayName,
int arrayComp,
int min, int max)
{
......@@ -772,7 +772,7 @@ int vtkDataObjectToDataSetFilter::GetVertsComponentMaxRange()
}
//----------------------------------------------------------------------------
void vtkDataObjectToDataSetFilter::SetLinesComponent(char *arrayName,
void vtkDataObjectToDataSetFilter::SetLinesComponent(const char *arrayName,
int arrayComp,
int min, int max)
{
......@@ -820,7 +820,7 @@ int vtkDataObjectToDataSetFilter::GetLinesComponentMaxRange()
}
//----------------------------------------------------------------------------
void vtkDataObjectToDataSetFilter::SetPolysComponent(char *arrayName,
void vtkDataObjectToDataSetFilter::SetPolysComponent(const char *arrayName,
int arrayComp,
int min, int max)
{
......@@ -868,7 +868,7 @@ int vtkDataObjectToDataSetFilter::GetPolysComponentMaxRange()
}
//----------------------------------------------------------------------------
void vtkDataObjectToDataSetFilter::SetStripsComponent(char *arrayName,
void vtkDataObjectToDataSetFilter::SetStripsComponent(const char *arrayName,
int arrayComp,
int min, int max)
{
......@@ -917,7 +917,7 @@ int vtkDataObjectToDataSetFilter::GetStripsComponentMaxRange()
//----------------------------------------------------------------------------
// Stuff related to vtkUnstructuredGrid --------------------------------------
void vtkDataObjectToDataSetFilter::SetCellTypeComponent(char *arrayName, int arrayComp,
void vtkDataObjectToDataSetFilter::SetCellTypeComponent(const char *arrayName, int arrayComp,
int min, int max)
{
vtkFieldDataToAttributeDataFilter::SetArrayName(
......@@ -965,7 +965,7 @@ int vtkDataObjectToDataSetFilter::GetCellTypeComponentMaxRange()
//----------------------------------------------------------------------------
void vtkDataObjectToDataSetFilter::SetCellConnectivityComponent(
char *arrayName, int arrayComp, int min, int max)
const char *arrayName, int arrayComp, int min, int max)
{
vtkFieldDataToAttributeDataFilter::SetArrayName(
this, this->CellConnectivityArray, arrayName);
......@@ -1269,7 +1269,7 @@ vtkCellArray *vtkDataObjectToDataSetFilter::ConstructCellArray(
//----------------------------------------------------------------------------
// Alternative methods for Dimensions, Spacing, and Origin -------------------
//
void vtkDataObjectToDataSetFilter::SetDimensionsComponent(char *arrayName,
void vtkDataObjectToDataSetFilter::SetDimensionsComponent(const char *arrayName,
int arrayComp,
int min, int max)
{
......@@ -1293,7 +1293,7 @@ void vtkDataObjectToDataSetFilter::SetDimensionsComponent(char *arrayName,
}
//----------------------------------------------------------------------------
void vtkDataObjectToDataSetFilter::SetSpacingComponent(char *arrayName,
void vtkDataObjectToDataSetFilter::SetSpacingComponent(const char *arrayName,
int arrayComp,
int min, int max)
{
......@@ -1317,7 +1317,7 @@ void vtkDataObjectToDataSetFilter::SetSpacingComponent(char *arrayName,
}
//----------------------------------------------------------------------------
void vtkDataObjectToDataSetFilter::SetOriginComponent(char *arrayName,
void vtkDataObjectToDataSetFilter::SetOriginComponent(const char *arrayName,
int arrayComp,
int min, int max)
{
......
......@@ -138,9 +138,9 @@ public:
* provided which does not require setting the (min,max) component range or
* the normalize flag (normalize is set to DefaulatNormalize value).
*/
void SetPointComponent(int comp, char *arrayName, int arrayComp,
void SetPointComponent(int comp, const char *arrayName, int arrayComp,
int min, int max, int normalize);
void SetPointComponent(int comp, char *arrayName, int arrayComp)
void SetPointComponent(int comp, const char *arrayName, int arrayComp)
{this->SetPointComponent(comp, arrayName, arrayComp, -1, -1, this->DefaultNormalize);};
const char *GetPointComponentArrayName(int comp);
int GetPointComponentArrayComponent(int comp);
......@@ -159,29 +159,29 @@ public:
* points per cell, and then the cell connectivity. (This is the vtk file
* format described in in the textbook or User's Guide.)
*/
void SetVertsComponent(char *arrayName, int arrayComp, int min, int max);
void SetVertsComponent(char *arrayName, int arrayComp)
void SetVertsComponent(const char *arrayName, int arrayComp, int min, int max);
void SetVertsComponent(const char *arrayName, int arrayComp)
{this->SetVertsComponent(arrayName, arrayComp, -1, -1);};
const char *GetVertsComponentArrayName();
int GetVertsComponentArrayComponent();
int GetVertsComponentMinRange();
int GetVertsComponentMaxRange();
void SetLinesComponent(char *arrayName, int arrayComp, int min, int max);
void SetLinesComponent(char *arrayName, int arrayComp)
void SetLinesComponent(const char *arrayName, int arrayComp, int min, int max);
void SetLinesComponent(const char *arrayName, int arrayComp)
{this->SetLinesComponent(arrayName, arrayComp, -1, -1);};
const char *GetLinesComponentArrayName();
int GetLinesComponentArrayComponent();
int GetLinesComponentMinRange();
int GetLinesComponentMaxRange();
void SetPolysComponent(char *arrayName, int arrayComp, int min, int max);
void SetPolysComponent(char *arrayName, int arrayComp)
void SetPolysComponent(const char *arrayName, int arrayComp, int min, int max);
void SetPolysComponent(const char *arrayName, int arrayComp)
{this->SetPolysComponent(arrayName, arrayComp, -1, -1);};
const char *GetPolysComponentArrayName();
int GetPolysComponentArrayComponent();
int GetPolysComponentMinRange();
int GetPolysComponentMaxRange();
void SetStripsComponent(char *arrayName, int arrayComp, int min, int max);
void SetStripsComponent(char *arrayName, int arrayComp)
void SetStripsComponent(const char *arrayName, int arrayComp, int min, int max);
void SetStripsComponent(const char *arrayName, int arrayComp)
{this->SetStripsComponent(arrayName, arrayComp, -1, -1);};
const char *GetStripsComponentArrayName();
int GetStripsComponentArrayComponent();
......@@ -199,17 +199,17 @@ public:
* then the cell connectivity. (This is the vtk file format described in
* in the textbook or User's Guide.)
*/
void SetCellTypeComponent(char *arrayName, int arrayComp,
void SetCellTypeComponent(const char *arrayName, int arrayComp,
int min, int max);
void SetCellTypeComponent(char *arrayName, int arrayComp)
void SetCellTypeComponent(const char *arrayName, int arrayComp)
{this->SetCellTypeComponent(arrayName, arrayComp, -1, -1);};
const char *GetCellTypeComponentArrayName();
int GetCellTypeComponentArrayComponent();
int GetCellTypeComponentMinRange();
int GetCellTypeComponentMaxRange();
void SetCellConnectivityComponent(char *arrayName, int arrayComp,
void SetCellConnectivityComponent(const char *arrayName, int arrayComp,
int min, int max);
void SetCellConnectivityComponent(char *arrayName, int arrayComp)
void SetCellConnectivityComponent(const char *arrayName, int arrayComp)
{this->SetCellConnectivityComponent(arrayName, arrayComp, -1, -1);};
const char *GetCellConnectivityComponentArrayName();
int GetCellConnectivityComponentArrayComponent();
......@@ -262,14 +262,14 @@ public:
* the component of the array, and the range of the array (min,max). These methods
* will override the information given by the previous methods.
*/
void SetDimensionsComponent(char *arrayName, int arrayComp, int min, int max);
void SetDimensionsComponent(char *arrayName, int arrayComp)
void SetDimensionsComponent(const char *arrayName, int arrayComp, int min, int max);
void SetDimensionsComponent(const char *arrayName, int arrayComp)
{this->SetDimensionsComponent(arrayName, arrayComp, -1, -1);};
void SetSpacingComponent(char *arrayName, int arrayComp, int min, int max);
void SetSpacingComponent(char *arrayName, int arrayComp)
void SetSpacingComponent(const char *arrayName, int arrayComp, int min, int max);
void SetSpacingComponent(const char *arrayName, int arrayComp)
{this->SetSpacingComponent(arrayName, arrayComp, -1, -1);};
void SetOriginComponent(char *arrayName, int arrayComp, int min, int max);
void SetOriginComponent(char *arrayName, int arrayComp)
void SetOriginComponent(const char *arrayName, int arrayComp, int min, int max);
void SetOriginComponent(const char *arrayName, int arrayComp)
{this->SetOriginComponent(arrayName, arrayComp, -1, -1);};
//@}
......
......@@ -1054,7 +1054,8 @@ int vtkFieldDataToAttributeDataFilter::GetComponentsType(int numComp, vtkDataArr
}
vtkDataArray *vtkFieldDataToAttributeDataFilter::GetFieldArray(vtkFieldData *fd,
char *name, int comp)
const char *name,
int comp)
{
vtkDataArray *da = nullptr;
int numComp;
......
......@@ -237,7 +237,7 @@ public:
/**
* Return an array of a particular name from field data and do error checking.
*/
static vtkDataArray *GetFieldArray(vtkFieldData *fd, char *name, int comp);
static vtkDataArray *GetFieldArray(vtkFieldData *fd, const char *name, int comp);
/**
* Specify an array name for one of the components.
......
......@@ -297,7 +297,10 @@ void vtkProbeFilter::InitializeForProbing(vtkDataSet* input,
outPD->InterpolateAllocate((*this->PointList), numPts, numPts);
vtkCellData* tempCellData = vtkCellData::New();
tempCellData->InterpolateAllocate( (*this->CellList), numPts, numPts);
// We're okay with copying global ids for cells. we just don't flag them as
// such.
tempCellData->CopyAllOn(vtkDataSetAttributes::COPYTUPLE);
tempCellData->CopyAllocate((*this->CellList), numPts, numPts);
this->CellArrays->clear();
int numCellArrays = tempCellData->GetNumberOfArrays();
......
......@@ -2565,7 +2565,9 @@ namespace vtkYoungsMaterialInterfaceCellCutInternals
#endif
)
{
ALLOC_LOCAL_ARRAY( derivatives, REAL2, nv-1 );
// only need nv-1 derivs but allocate nv as gcc freaks out
// with nv-1 as an argument
ALLOC_LOCAL_ARRAY( derivatives, REAL2, nv );
ALLOC_LOCAL_ARRAY( index, unsigned char, nv );
ALLOC_LOCAL_ARRAY( rindex, unsigned char, nv );
......
......@@ -161,12 +161,12 @@ void vtkDSPFilterDefinition::PushBackForwardNumeratorWeight(double a_value)
}
//----------------------------------------------------------------------------
void vtkDSPFilterDefinition::SetInputVariableName(char *a_value)
void vtkDSPFilterDefinition::SetInputVariableName(const char *a_value)
{
this->InputVariableName->m_string = a_value;
}
//----------------------------------------------------------------------------
void vtkDSPFilterDefinition::SetOutputVariableName(char *a_value)
void vtkDSPFilterDefinition::SetOutputVariableName(const char *a_value)
{
this->OutputVariableName->m_string = a_value;
}
......
......@@ -57,8 +57,8 @@ class VTKFILTERSHYBRID_EXPORT vtkDSPFilterDefinition : public vtkObject
void PushBackNumeratorWeight(double a_value);
void PushBackDenominatorWeight(double a_value);
void PushBackForwardNumeratorWeight(double a_value);
void SetInputVariableName(char *a_value);
void SetOutputVariableName(char *a_value);
void SetInputVariableName(const char *a_value);
void SetOutputVariableName(const char *a_value);
const char *GetInputVariableName();
const char *GetOutputVariableName();
......
......@@ -149,7 +149,7 @@ void vtkDSPFilterGroup::AddFilter(vtkDSPFilterDefinition *filter)
}
//----------------------------------------------------------------------------
void vtkDSPFilterGroup::RemoveFilter(char *a_outputVariableName)
void vtkDSPFilterGroup::RemoveFilter(const char *a_outputVariableName)
{
std::vector<vtkDSPFilterDefinition *>::iterator l_iter;
std::vector< std::vector<vtkFloatArray *> >::iterator l_cachedOutputsIter = this->CachedOutputs->m_vector.begin();
......