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

Function main

Examples/DataManipulation/Cxx/Arrays.cxx:25–115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23#include <array>
24
25int main()
26{
27 vtkNew<vtkNamedColors> colors;
28
29 // Create a float array which represents the points.
30 vtkNew<vtkDoubleArray> pcoords;
31
32 // Note that by default, an array has 1 component.
33 // We have to change it to 3 for points.
34 pcoords->SetNumberOfComponents(3);
35 // We ask pcoords to allocate room for at least 4 tuples
36 // and set the number of tuples to 4.
37 pcoords->SetNumberOfTuples(4);
38 // Assign each tuple. There are 5 specialized versions of SetTuple:
39 // SetTuple1 SetTuple2 SetTuple3 SetTuple4 SetTuple9
40 // These take 1, 2, 3, 4 and 9 components respectively.
41 std::array<std::array<double, 3>, 4> pts = { { { { 0.0, 0.0, 0.0 } }, { { 0.0, 1.0, 0.0 } },
42 { { 1.0, 0.0, 0.0 } }, { { 1.0, 1.0, 0.0 } } } };
43 for (auto i = 0ul; i < pts.size(); ++i)
44 {
45 pcoords->SetTuple(i, pts[i].data());
46 }
47
48 // Create vtkPoints and assign pcoords as the internal data array.
49 vtkNew<vtkPoints> points;
50 points->SetData(pcoords);
51
52 // Create the cells. In this case, a triangle strip with 2 triangles
53 // (which can be represented by 4 points).
54 vtkNew<vtkCellArray> strips;
55 strips->InsertNextCell(4);
56 strips->InsertCellPoint(0);
57 strips->InsertCellPoint(1);
58 strips->InsertCellPoint(2);
59 strips->InsertCellPoint(3);
60
61 // Create an integer array with 4 tuples. Note that when using
62 // InsertNextValue (or InsertNextTuple1 which is equivalent in
63 // this situation), the array will expand automatically.
64 vtkNew<vtkIntArray> temperature;
65 temperature->SetName("Temperature");
66 temperature->InsertNextValue(10);
67 temperature->InsertNextValue(20);
68 temperature->InsertNextValue(30);
69 temperature->InsertNextValue(40);
70
71 // Create a double array.
72 vtkNew<vtkDoubleArray> vorticity;
73 vorticity->SetName("Vorticity");
74 vorticity->InsertNextValue(2.7);
75 vorticity->InsertNextValue(4.1);
76 vorticity->InsertNextValue(5.3);
77 vorticity->InsertNextValue(3.4);
78
79 // Create the dataset. In this case, we create a vtkPolyData
80 vtkNew<vtkPolyData> polydata;
81 // Assign points and cells
82 polydata->SetPoints(points);

Callers

nothing calls this directly

Calls 15

InsertCellPointMethod · 0.80
SetStripsMethod · 0.80
SetScalarsMethod · 0.80
GetColor3dMethod · 0.80
SetNumberOfComponentsMethod · 0.45
SetNumberOfTuplesMethod · 0.45
sizeMethod · 0.45
SetTupleMethod · 0.45
dataMethod · 0.45
SetDataMethod · 0.45
InsertNextCellMethod · 0.45
SetNameMethod · 0.45

Tested by

no test coverage detected