1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
|
/*=========================================================================
Program: Visualization Toolkit
Module: TestDataSetSurfaceMultiBlockFieldData.cxx
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.
=========================================================================*/
#include <cstdio>
#include <vtkDataSetSurfaceFilter.h>
#include <vtkFieldData.h>
#include <vtkFloatArray.h>
#include <vtkImageData.h>
#include <vtkIntArray.h>
#include <vtkNew.h>
#include <vtkPointData.h>
#include <vtkPolyData.h>
#include <vtkStructuredGrid.h>
#include <vtkUnstructuredGrid.h>
// Test to ensure that field data is copied for different data types in vtkDataSetSurface
namespace
{
//----------------------------------------------------------------------------
int TestDataSet(vtkDataSet* ds, int expectedValue)
{
vtkNew<vtkDataSetSurfaceFilter> surfacer;
surfacer->SetInputData(ds);
surfacer->Update();
if (!surfacer->GetOutput())
{
std::cout << "No output!\n";
return EXIT_FAILURE;
}
vtkFieldData* fieldData = surfacer->GetOutput()->GetFieldData();
const char* className = ds->GetClassName();
if (fieldData == NULL || fieldData->GetNumberOfArrays() == 0)
{
std::cerr << "No field data was associated with data set type " << className << "\n";
return EXIT_FAILURE;
}
else
{
std::cout << "Have field data for surface from data set type " << className << "\n";
vtkIntArray* array = vtkArrayDownCast<vtkIntArray>(fieldData->GetArray(0));
if (!array)
{
std::cerr << "Field data array was not of type vtkIntArray for data set type"
<< className << "\n";
return EXIT_FAILURE;
}
else if (array->GetNumberOfTuples() < 1)
{
std::cerr << "No tuples in field data array for surface from data set type "
<< className << "\n";
return EXIT_FAILURE;
}
else
{
int value = 0;
array->GetTypedTuple(0, &value);
std::cout << "Block value " << value << "\n";
if (value != expectedValue)
{
std::cerr << "Unexpected block field array value " << value
<< " for surface from data set type " << className
<< ". Expected " << expectedValue << "\n";
return EXIT_FAILURE;
}
}
}
return EXIT_SUCCESS;
}
//----------------------------------------------------------------------------
void AddFieldData(vtkDataSet* ds, int id)
{
vtkNew<vtkIntArray> array;
array->SetName("ID");
array->SetNumberOfComponents(1);
array->SetNumberOfTuples(1);
array->SetTypedTuple(0, &id);
ds->GetFieldData()->AddArray(array.GetPointer());
}
//----------------------------------------------------------------------------
int TestImageData()
{
// Create image data
vtkNew<vtkImageData> imageData;
imageData->Initialize();
imageData->SetSpacing(1, 1, 1);
imageData->SetOrigin(0, 0, 0);
imageData->SetDimensions(10, 10, 10);
int id = 1;
AddFieldData(imageData.GetPointer(), id);
// Add point data
vtkNew<vtkFloatArray> pa;
pa->SetName("pd");
pa->SetNumberOfComponents(1);
pa->SetNumberOfTuples(10 * 10 * 10);
imageData->GetPointData()->AddArray(pa.GetPointer());
return TestDataSet(imageData.GetPointer(), id);
}
//----------------------------------------------------------------------------
int TestPolyData()
{
// Create polydata
vtkNew<vtkPolyData> polyData;
polyData->Initialize();
int id = 2;
AddFieldData(polyData.GetPointer(), id);
return TestDataSet(polyData.GetPointer(), id);
}
//----------------------------------------------------------------------------
int TestStructuredGrid()
{
// Create structured grid data
vtkNew<vtkStructuredGrid> structuredGrid;
structuredGrid->Initialize();
int id = 3;
AddFieldData(structuredGrid.GetPointer(), id);
return TestDataSet(structuredGrid.GetPointer(), id);
}
//----------------------------------------------------------------------------
int TestUnstructuredGrid()
{
// Create unstructured grid data
vtkNew<vtkUnstructuredGrid> unstructuredGrid;
unstructuredGrid->Initialize();
int id = 4;
AddFieldData(unstructuredGrid.GetPointer(), id);
return TestDataSet(unstructuredGrid.GetPointer(), id);
}
} // end anonymous namespace
//----------------------------------------------------------------------------
int TestDataSetSurfaceFieldData(int vtkNotUsed(argc), char* vtkNotUsed(argv)[])
{
if (TestImageData() != EXIT_SUCCESS)
{
std::cerr << "TestImageData failed\n";
return EXIT_FAILURE;
}
if (TestPolyData() != EXIT_SUCCESS)
{
std::cerr << "TestPolyData failed\n";
return EXIT_FAILURE;
}
if (TestStructuredGrid() != EXIT_SUCCESS)
{
std::cerr << "TestStructuredGrid failed\n";
return EXIT_FAILURE;
}
if (TestUnstructuredGrid() != EXIT_SUCCESS)
{
std::cerr << "TestUnstructuredGrid failed\n";
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
|