Commit 3c3643ea authored by Cory Quammen's avatar Cory Quammen Committed by Kitware Robot
Browse files

Merge topic 'vtkAssignAttribute_pass_attribute_information'

2458878b Test new vtkAssignAttribute behavior
11d0d8f8

 Pass all available attribute information in vtkAssignAttribute
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !1908
parents 7fe30aa1 2458878b
...@@ -18,6 +18,9 @@ ...@@ -18,6 +18,9 @@
#include "vtkCellArray.h" #include "vtkCellArray.h"
#include "vtkCellData.h" #include "vtkCellData.h"
#include "vtkDoubleArray.h" #include "vtkDoubleArray.h"
#include "vtkExecutive.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkMutableUndirectedGraph.h" #include "vtkMutableUndirectedGraph.h"
#include "vtkPointData.h" #include "vtkPointData.h"
#include "vtkPoints.h" #include "vtkPoints.h"
...@@ -27,6 +30,8 @@ ...@@ -27,6 +30,8 @@
#include "vtkRenderWindowInteractor.h" #include "vtkRenderWindowInteractor.h"
#include "vtkSmartPointer.h" #include "vtkSmartPointer.h"
#include <cstring>
#define VTK_CREATE(type, name) \ #define VTK_CREATE(type, name) \
vtkSmartPointer<type> name = vtkSmartPointer<type>::New() vtkSmartPointer<type> name = vtkSmartPointer<type>::New()
...@@ -42,6 +47,7 @@ int TestAssignAttribute(int, char *[]) ...@@ -42,6 +47,7 @@ int TestAssignAttribute(int, char *[])
VTK_CREATE(vtkDoubleArray, scalars); VTK_CREATE(vtkDoubleArray, scalars);
scalars->SetName("scalars"); scalars->SetName("scalars");
scalars->SetNumberOfComponents(3);
VTK_CREATE(vtkDoubleArray, tensors); VTK_CREATE(vtkDoubleArray, tensors);
tensors->SetName(NULL); // no name. tensors->SetName(NULL); // no name.
...@@ -51,7 +57,7 @@ int TestAssignAttribute(int, char *[]) ...@@ -51,7 +57,7 @@ int TestAssignAttribute(int, char *[])
pts->InsertNextPoint(i, 0, 0); pts->InsertNextPoint(i, 0, 0);
verts->InsertNextCell(1, &i); verts->InsertNextCell(1, &i);
graph->AddVertex(); graph->AddVertex();
scalars->InsertNextValue(i); scalars->InsertNextTuple3(i, 0.5 * i, 0.1 * i);
tensors->InsertNextTuple9(1.,0.,0.,0.,1.,0.,0.,0.,1.); tensors->InsertNextTuple9(1.,0.,0.,0.,1.,0.,0.,0.,1.);
} }
for (vtkIdType i = 0; i < 10; ++i) for (vtkIdType i = 0; i < 10; ++i)
...@@ -126,5 +132,96 @@ int TestAssignAttribute(int, char *[]) ...@@ -126,5 +132,96 @@ int TestAssignAttribute(int, char *[])
cerr << "Cell scalar not set when name is empty" << endl; cerr << "Cell scalar not set when name is empty" << endl;
++errors; ++errors;
} }
vtkInformation *inInfo = assign->GetExecutive()->GetInputInformation()[0]->GetInformationObject(0);
vtkInformation *outInfo = assign->GetExecutive()->GetOutputInformation()->GetInformationObject(0);
outInfo->Clear();
vtkDataObject::SetActiveAttribute(inInfo, vtkDataObject::FIELD_ASSOCIATION_POINTS,
scalars->GetName(), vtkDataSetAttributes::SCALARS);
vtkDataObject::SetActiveAttributeInfo(inInfo, vtkDataObject::FIELD_ASSOCIATION_POINTS,
vtkDataSetAttributes::SCALARS, scalars->GetName(), scalars->GetDataType(),
scalars->GetNumberOfComponents(), scalars->GetNumberOfTuples());
assign->Assign(scalars->GetName(), vtkDataSetAttributes::VECTORS, vtkAssignAttribute::POINT_DATA);
assign->UpdateInformation();
vtkInformation *outFieldInfo = vtkDataObject::GetActiveFieldInformation(outInfo,
vtkDataObject::FIELD_ASSOCIATION_POINTS, vtkDataSetAttributes::VECTORS);
if (!outFieldInfo
|| !outFieldInfo->Has(vtkDataObject::FIELD_NAME())
|| std::strcmp(outFieldInfo->Get(vtkDataObject::FIELD_NAME()), scalars->GetName())
|| outFieldInfo->Get(vtkDataObject::FIELD_NUMBER_OF_COMPONENTS()) != scalars->GetNumberOfComponents()
|| outFieldInfo->Get(vtkDataObject::FIELD_NUMBER_OF_TUPLES()) != scalars->GetNumberOfTuples()
|| outFieldInfo->Get(vtkDataObject::FIELD_ARRAY_TYPE()) != scalars->GetDataType())
{
cerr << "Scalar information not passed when attribute is assigned by name." << endl;
++errors;
}
outInfo->Clear();
inInfo = assign->GetExecutive()->GetInputInformation()[0]->GetInformationObject(0);
vtkDataObject::SetActiveAttribute(inInfo, vtkDataObject::FIELD_ASSOCIATION_POINTS,
scalars->GetName(), vtkDataSetAttributes::SCALARS);
vtkDataObject::SetActiveAttributeInfo(inInfo, vtkDataObject::FIELD_ASSOCIATION_POINTS,
vtkDataSetAttributes::SCALARS, scalars->GetName(), scalars->GetDataType(),
scalars->GetNumberOfComponents(), scalars->GetNumberOfTuples());
assign->Assign(vtkDataSetAttributes::SCALARS, vtkDataSetAttributes::VECTORS, vtkAssignAttribute::POINT_DATA);
assign->UpdateInformation();
outInfo = assign->GetExecutive()->GetOutputInformation()->GetInformationObject(0);
outFieldInfo = vtkDataObject::GetActiveFieldInformation(outInfo,
vtkDataObject::FIELD_ASSOCIATION_POINTS, vtkDataSetAttributes::VECTORS);
if (!outFieldInfo
|| !outFieldInfo
|| !outFieldInfo->Has(vtkDataObject::FIELD_NAME())
|| std::strcmp(outFieldInfo->Get(vtkDataObject::FIELD_NAME()), scalars->GetName())
|| outFieldInfo->Get(vtkDataObject::FIELD_NUMBER_OF_COMPONENTS()) != scalars->GetNumberOfComponents()
|| outFieldInfo->Get(vtkDataObject::FIELD_NUMBER_OF_TUPLES()) != scalars->GetNumberOfTuples()
|| outFieldInfo->Get(vtkDataObject::FIELD_ARRAY_TYPE()) != scalars->GetDataType())
{
cerr << "Scalar information not passed when attribute is assigned by type." << endl;
++errors;
}
outInfo->Clear();
assign->SetInputData(graph);
tensors->SetName("tensors");
inInfo = assign->GetExecutive()->GetInputInformation()[0]->GetInformationObject(0);
vtkDataObject::SetActiveAttribute(inInfo, vtkDataObject::FIELD_ASSOCIATION_EDGES,
tensors->GetName(), vtkDataSetAttributes::TENSORS);
vtkDataObject::SetActiveAttributeInfo(inInfo, vtkDataObject::FIELD_ASSOCIATION_EDGES,
vtkDataSetAttributes::TENSORS, tensors->GetName(), tensors->GetDataType(),
tensors->GetNumberOfComponents(), tensors->GetNumberOfTuples());
assign->Assign(tensors->GetName(), vtkDataSetAttributes::SCALARS, vtkAssignAttribute::EDGE_DATA);
assign->UpdateInformation();
outInfo = assign->GetExecutive()->GetOutputInformation()->GetInformationObject(0);
outFieldInfo = vtkDataObject::GetActiveFieldInformation(outInfo,
vtkDataObject::FIELD_ASSOCIATION_EDGES, vtkDataSetAttributes::SCALARS);
if (!outFieldInfo
|| !outFieldInfo->Has(vtkDataObject::FIELD_NAME())
|| std::strcmp(outFieldInfo->Get(vtkDataObject::FIELD_NAME()), tensors->GetName())
|| outFieldInfo->Get(vtkDataObject::FIELD_NUMBER_OF_COMPONENTS()) != tensors->GetNumberOfComponents()
|| outFieldInfo->Get(vtkDataObject::FIELD_NUMBER_OF_TUPLES()) != tensors->GetNumberOfTuples()
|| outFieldInfo->Get(vtkDataObject::FIELD_ARRAY_TYPE()) != tensors->GetDataType())
{
cerr << "Tensor information not passed when attribute is assigned by name." << endl;
++errors;
}
outInfo->Clear();
inInfo = assign->GetExecutive()->GetInputInformation()[0]->GetInformationObject(0);
vtkDataObject::SetActiveAttribute(inInfo, vtkDataObject::FIELD_ASSOCIATION_EDGES,
tensors->GetName(), vtkDataSetAttributes::TENSORS);
vtkDataObject::SetActiveAttributeInfo(inInfo, vtkDataObject::FIELD_ASSOCIATION_EDGES,
vtkDataSetAttributes::TENSORS, tensors->GetName(), tensors->GetDataType(),
tensors->GetNumberOfComponents(), tensors->GetNumberOfTuples());
assign->Assign(vtkDataSetAttributes::TENSORS, vtkDataSetAttributes::SCALARS, vtkAssignAttribute::EDGE_DATA);
assign->UpdateInformation();
outInfo = assign->GetExecutive()->GetOutputInformation()->GetInformationObject(0);
outFieldInfo = vtkDataObject::GetActiveFieldInformation(outInfo,
vtkDataObject::FIELD_ASSOCIATION_EDGES, vtkDataSetAttributes::SCALARS);
if (!outFieldInfo
|| !outFieldInfo->Has(vtkDataObject::FIELD_NAME())
|| std::strcmp(outFieldInfo->Get(vtkDataObject::FIELD_NAME()), tensors->GetName())
|| outFieldInfo->Get(vtkDataObject::FIELD_NUMBER_OF_COMPONENTS()) != tensors->GetNumberOfComponents()
|| outFieldInfo->Get(vtkDataObject::FIELD_NUMBER_OF_TUPLES()) != tensors->GetNumberOfTuples()
|| outFieldInfo->Get(vtkDataObject::FIELD_ARRAY_TYPE()) != tensors->GetDataType())
{
cerr << "Tensor information not passed when attribute is assigned by type." << endl;
++errors;
}
return 0; return 0;
} }
...@@ -231,6 +231,17 @@ int vtkAssignAttribute::RequestInformation(vtkInformation *vtkNotUsed(request), ...@@ -231,6 +231,17 @@ int vtkAssignAttribute::RequestInformation(vtkInformation *vtkNotUsed(request),
{ {
vtkDataObject::SetActiveAttribute(outInfo, fieldAssociation, vtkDataObject::SetActiveAttribute(outInfo, fieldAssociation,
this->FieldName, this->AttributeType); this->FieldName, this->AttributeType);
vtkInformation *inputAttributeInfo = vtkDataObject::GetNamedFieldInformation(
inInfo, fieldAssociation, this->FieldName);
if (inputAttributeInfo)
{
const int type = inputAttributeInfo->Get(vtkDataObject::FIELD_ARRAY_TYPE());
const int numComponents = inputAttributeInfo->Get(vtkDataObject::FIELD_NUMBER_OF_COMPONENTS());
const int numTuples = inputAttributeInfo->Get(vtkDataObject::FIELD_NUMBER_OF_TUPLES());
vtkDataObject::SetActiveAttributeInfo(outInfo, fieldAssociation,
this->AttributeType, this->FieldName, type, numComponents, numTuples);
}
} }
else if (this->FieldTypeAssignment == vtkAssignAttribute::ATTRIBUTE && else if (this->FieldTypeAssignment == vtkAssignAttribute::ATTRIBUTE &&
this->InputAttributeType != -1) this->InputAttributeType != -1)
...@@ -239,9 +250,14 @@ int vtkAssignAttribute::RequestInformation(vtkInformation *vtkNotUsed(request), ...@@ -239,9 +250,14 @@ int vtkAssignAttribute::RequestInformation(vtkInformation *vtkNotUsed(request),
inInfo, fieldAssociation, this->InputAttributeType); inInfo, fieldAssociation, this->InputAttributeType);
if (inputAttributeInfo) // do we have an active field of requested type if (inputAttributeInfo) // do we have an active field of requested type
{ {
vtkDataObject::SetActiveAttribute(outInfo, fieldAssociation, const char * name = inputAttributeInfo->Get(vtkDataObject::FIELD_NAME());
inputAttributeInfo->Get( vtkDataObject::FIELD_NAME() ), const int type = inputAttributeInfo->Get(vtkDataObject::FIELD_ARRAY_TYPE());
this->AttributeType); const int numComponents = inputAttributeInfo->Get(vtkDataObject::FIELD_NUMBER_OF_COMPONENTS());
const int numTuples = inputAttributeInfo->Get(vtkDataObject::FIELD_NUMBER_OF_TUPLES());
vtkDataObject::SetActiveAttribute(outInfo, fieldAssociation, name, this->AttributeType);
vtkDataObject::SetActiveAttributeInfo(outInfo, fieldAssociation,
this->AttributeType, name, type, numComponents, numTuples);
} }
} }
} }
......
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