-
Notifications
You must be signed in to change notification settings - Fork 4
/
ArrayCalculator.tar
94 lines (82 loc) · 10 KB
/
ArrayCalculator.tar
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
ArrayCalculator/ 0000755 0000765 0000024 00000000000 13424703035 015117 5 ustar lorensen staff 0000000 0000000 ArrayCalculator/ArrayCalculator.cxx 0000644 0000765 0000024 00000003577 13424703035 020747 0 ustar lorensen staff 0000000 0000000 #include <vtkArrayCalculator.h>
#include <vtkDoubleArray.h>
#include <vtkPointData.h>
#include <vtkPolyData.h>
#include <vtkSmartPointer.h>
int main(int, char *[])
{
vtkSmartPointer<vtkPoints> points =
vtkSmartPointer<vtkPoints>::New();
points->InsertNextPoint(1.0, 0.0, 0.0);
points->InsertNextPoint(2.0, 0.0, 0.0);
points->InsertNextPoint(3.0, 0.0, 0.0);
vtkSmartPointer<vtkDoubleArray> array =
vtkSmartPointer<vtkDoubleArray>::New();
array->SetName("orig");
array->InsertNextValue(1.0);
array->InsertNextValue(2.0);
array->InsertNextValue(3.0);
vtkSmartPointer<vtkPolyData> polydata =
vtkSmartPointer<vtkPolyData>::New();
polydata->SetPoints(points);
polydata->GetPointData()->AddArray(array);
vtkSmartPointer<vtkArrayCalculator> calc1 =
vtkSmartPointer<vtkArrayCalculator>::New();
calc1->SetInputData(polydata);
calc1->AddScalarArrayName("orig");
calc1->SetFunction("orig+1");
calc1->SetResultArrayName("orig");
calc1->Update();
vtkSmartPointer<vtkDoubleArray> output1 =
dynamic_cast<vtkDoubleArray*>(
calc1->GetPolyDataOutput()->GetPointData()->GetArray("orig"));
for(vtkIdType i = 0; i < output1->GetNumberOfTuples(); i++)
{
double val = output1->GetValue(i);
cout << "output1 value " << i << ": " << val << endl;
}
vtkSmartPointer<vtkArrayCalculator> calc2 =
vtkSmartPointer<vtkArrayCalculator>::New();
calc2->SetInputData(polydata);
calc2->AddScalarArrayName("orig");
calc2->SetFunction("if(orig=2,1,orig)");
calc2->SetResultArrayName("new");
calc2->Update();
vtkSmartPointer<vtkDoubleArray> output2 =
dynamic_cast<vtkDoubleArray*>(
calc2->GetPolyDataOutput()->GetPointData()->GetArray("new"));
for(vtkIdType i = 0; i < output2->GetNumberOfTuples(); i++)
{
double val = output2->GetValue(i);
cout << "output2 value " << i << ": " << val << endl;
}
return EXIT_SUCCESS;
}