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

Function main

Examples/DataManipulation/Cxx/SGrid.cxx:29–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27#include <array>
28
29int main()
30{
31 vtkNew<vtkNamedColors> colors;
32
33 float rMin = 0.5, rMax = 1.0, deltaRad, deltaZ;
34 std::array<int, 3> dims = { { 13, 11, 11 } };
35
36 // Create the structured grid.
37 vtkNew<vtkStructuredGrid> sgrid;
38 sgrid->SetDimensions(dims.data());
39
40 // We also create the points and vectors. The points
41 // form a hemi-cylinder of data.
42 vtkNew<vtkFloatArray> vectors;
43 vectors->SetNumberOfComponents(3);
44 vectors->SetNumberOfTuples(dims[0] * dims[1] * dims[2]);
45 vtkNew<vtkPoints> points;
46 points->Allocate(dims[0] * dims[1] * dims[2]);
47
48 deltaZ = 2.0 / (dims[2] - 1);
49 deltaRad = (rMax - rMin) / (dims[1] - 1);
50 float x[3], v[3];
51 v[2] = 0.0;
52 for (auto k = 0; k < dims[2]; k++)
53 {
54 x[2] = -1.0 + k * deltaZ;
55 int kOffset = k * dims[0] * dims[1];
56 for (auto j = 0; j < dims[1]; j++)
57 {
58 float radius = rMin + j * deltaRad;
59 int jOffset = j * dims[0];
60 for (auto i = 0; i < dims[0]; i++)
61 {
62 float theta = i * vtkMath::RadiansFromDegrees(15.0);
63 x[0] = radius * cos(theta);
64 x[1] = radius * sin(theta);
65 v[0] = -x[1];
66 v[1] = x[0];
67 int offset = i + jOffset + kOffset;
68 points->InsertPoint(offset, x);
69 vectors->InsertTuple(offset, v);
70 }
71 }
72 }
73 sgrid->SetPoints(points);
74 sgrid->GetPointData()->SetVectors(vectors);
75
76 // We create a simple pipeline to display the data.
77 vtkNew<vtkHedgeHog> hedgehog;
78 hedgehog->SetInputData(sgrid);
79 hedgehog->SetScaleFactor(0.1);
80
81 vtkNew<vtkPolyDataMapper> sgridMapper;
82 sgridMapper->SetInputConnection(hedgehog->GetOutputPort());
83 vtkNew<vtkActor> sgridActor;
84 sgridActor->SetMapper(sgridMapper);
85 sgridActor->GetProperty()->SetColor(colors->GetColor3d("Indigo").GetData());
86

Callers

nothing calls this directly

Calls 15

SetVectorsMethod · 0.80
SetScaleFactorMethod · 0.80
GetColor3dMethod · 0.80
GetActiveCameraMethod · 0.80
RenderMethod · 0.65
cosFunction · 0.50
sinFunction · 0.50
SetDimensionsMethod · 0.45
dataMethod · 0.45
SetNumberOfComponentsMethod · 0.45
SetNumberOfTuplesMethod · 0.45
AllocateMethod · 0.45

Tested by

no test coverage detected