MCPcopy Create free account
hub / github.com/Kitware/VTK / TestDataSetGradient

Function TestDataSetGradient

Filters/General/Testing/Cxx/TestDataSetGradient.cxx:28–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26#include "vtkTestUtilities.h"
27
28int TestDataSetGradient(int argc, char* argv[])
29{
30 char* fileName = vtkTestUtilities::ExpandDataFileName(argc, argv, "Data/hexa.vtk");
31
32 // Read the data
33 vtkSmartPointer<vtkUnstructuredGridReader> reader =
34 vtkSmartPointer<vtkUnstructuredGridReader>::New();
35 reader->SetFileName(fileName);
36 delete[] fileName;
37
38 // This class computes the gradient for each cell
39 vtkSmartPointer<vtkDataSetGradient> gradient = vtkSmartPointer<vtkDataSetGradient>::New();
40 gradient->SetInputConnection(reader->GetOutputPort());
41 gradient->SetInputArrayToProcess(0, 0, 0, 0, "scalars");
42 gradient->Update();
43
44 // Create a polydata
45 // Points at the parametric center of each cell
46 // PointData contains the gradient
47 vtkDoubleArray* gradientAtCenters =
48 vtkDoubleArray::SafeDownCast(gradient->GetOutput()->GetCellData()->GetArray("gradient"));
49
50 vtkSmartPointer<vtkDoubleArray> gradients = vtkSmartPointer<vtkDoubleArray>::New();
51 gradients->ShallowCopy(gradientAtCenters);
52
53 vtkSmartPointer<vtkPolyData> polyData = vtkSmartPointer<vtkPolyData>::New();
54 vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
55 points->SetNumberOfPoints(gradient->GetOutput()->GetNumberOfCells());
56
57 vtkSmartPointer<vtkGenericCell> aCell = vtkSmartPointer<vtkGenericCell>::New();
58 for (vtkIdType cellId = 0; cellId < gradient->GetOutput()->GetNumberOfCells(); ++cellId)
59 {
60 gradient->GetOutput()->GetCell(cellId, aCell);
61 reader->GetOutput()->GetCell(cellId, aCell);
62
63 double pcenter[3], center[3];
64 aCell->GetParametricCenter(pcenter);
65 std::vector<double> cweights(aCell->GetNumberOfPoints());
66 int pSubId = 0;
67 aCell->EvaluateLocation(pSubId, pcenter, center, &(*cweights.begin()));
68 points->SetPoint(cellId, center);
69 }
70 polyData->SetPoints(points);
71 polyData->GetPointData()->SetVectors(gradientAtCenters);
72
73 // Select a small percentage of the gradients
74 // Use 10% of the points
75 int onRatio =
76 reader->GetOutput()->GetNumberOfPoints() / (reader->GetOutput()->GetNumberOfPoints() * .1);
77
78 vtkSmartPointer<vtkMaskPoints> maskPoints = vtkSmartPointer<vtkMaskPoints>::New();
79 maskPoints->SetInputData(polyData);
80 maskPoints->RandomModeOff();
81 maskPoints->SetOnRatio(onRatio);
82
83 // Create the Glyphs for the gradient
84 vtkSmartPointer<vtkArrowSource> arrowSource = vtkSmartPointer<vtkArrowSource>::New();
85

Callers

nothing calls this directly

Calls 15

SetVectorsMethod · 0.80
SetScaleFactorMethod · 0.80
GetActiveCameraMethod · 0.80
RenderMethod · 0.65
NewFunction · 0.50
SetFileNameMethod · 0.45
SetInputConnectionMethod · 0.45
GetOutputPortMethod · 0.45
UpdateMethod · 0.45
GetArrayMethod · 0.45
GetCellDataMethod · 0.45

Tested by

no test coverage detected