Commit 2458878b authored by Karsten Tausche's avatar Karsten Tausche
Browse files

Test new vtkAssignAttribute behavior

parent 11d0d8f8
......@@ -18,6 +18,9 @@
#include "vtkCellArray.h"
#include "vtkCellData.h"
#include "vtkDoubleArray.h"
#include "vtkExecutive.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkMutableUndirectedGraph.h"
#include "vtkPointData.h"
#include "vtkPoints.h"
......@@ -27,6 +30,8 @@
#include "vtkRenderWindowInteractor.h"
#include "vtkSmartPointer.h"
#include <cstring>
#define VTK_CREATE(type, name) \
vtkSmartPointer<type> name = vtkSmartPointer<type>::New()
......@@ -42,6 +47,7 @@ int TestAssignAttribute(int, char *[])
VTK_CREATE(vtkDoubleArray, scalars);
scalars->SetName("scalars");
scalars->SetNumberOfComponents(3);
VTK_CREATE(vtkDoubleArray, tensors);
tensors->SetName(NULL); // no name.
......@@ -51,7 +57,7 @@ int TestAssignAttribute(int, char *[])
pts->InsertNextPoint(i, 0, 0);
verts->InsertNextCell(1, &i);
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.);
}
for (vtkIdType i = 0; i < 10; ++i)
......@@ -126,5 +132,96 @@ int TestAssignAttribute(int, char *[])
cerr << "Cell scalar not set when name is empty" << endl;
++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;
}
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