File: RGrid.cxx

package info (click to toggle)
paraview 5.4.1%2Bdfsg4-3.1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 218,616 kB
  • sloc: cpp: 2,331,508; ansic: 322,365; python: 111,051; xml: 79,203; tcl: 47,013; yacc: 4,877; java: 4,438; perl: 3,238; sh: 2,920; lex: 1,908; f90: 748; makefile: 273; pascal: 228; objc: 83; fortran: 31
file content (131 lines) | stat: -rw-r--r-- 4,492 bytes parent folder | download
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
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    RGrid.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.

=========================================================================*/
// This example shows how to create a rectilinear grid.
//

#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkFloatArray.h"
#include "vtkRectilinearGrid.h"
#include "vtkRectilinearGridGeometryFilter.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkProperty.h"
#include "vtkCamera.h"

int main()
{
  int i;
  static double x[47]={
         -1.22396, -1.17188, -1.11979, -1.06771, -1.01562, -0.963542,
         -0.911458, -0.859375, -0.807292, -0.755208, -0.703125, -0.651042,
         -0.598958, -0.546875, -0.494792, -0.442708, -0.390625, -0.338542,
         -0.286458, -0.234375, -0.182292, -0.130209, -0.078125, -0.026042,
          0.0260415, 0.078125, 0.130208, 0.182291, 0.234375, 0.286458,
          0.338542, 0.390625, 0.442708, 0.494792, 0.546875, 0.598958,
          0.651042, 0.703125, 0.755208, 0.807292, 0.859375, 0.911458,
          0.963542, 1.01562, 1.06771, 1.11979, 1.17188};
  static double y[33]={-1.25, -1.17188, -1.09375, -1.01562, -0.9375, -0.859375,
         -0.78125, -0.703125, -0.625, -0.546875, -0.46875, -0.390625,
         -0.3125, -0.234375, -0.15625, -0.078125, 0, 0.078125,
          0.15625, 0.234375, 0.3125, 0.390625, 0.46875, 0.546875,
          0.625, 0.703125, 0.78125, 0.859375, 0.9375, 1.01562,
          1.09375, 1.17188, 1.25};
  static double z[44]={0, 0.1, 0.2, 0.3, 0.4, 0.5,
         0.6, 0.7, 0.75, 0.8, 0.9, 1,
         1.1, 1.2, 1.3, 1.4, 1.5, 1.6,
         1.7, 1.75, 1.8, 1.9, 2, 2.1,
         2.2, 2.3, 2.4, 2.5, 2.6, 2.7,
         2.75, 2.8, 2.9, 3, 3.1, 3.2,
         3.3, 3.4, 3.5, 3.6, 3.7, 3.75,
         3.8, 3.9};

  // Create a rectilinear grid by defining three arrays specifying the
  // coordinates in the x-y-z directions.
  vtkFloatArray *xCoords = vtkFloatArray::New();
  for (i=0; i<47; i++)
  {
    xCoords->InsertNextValue(x[i]);
  }
  vtkFloatArray *yCoords = vtkFloatArray::New();
  for (i=0; i<33; i++)
  {
    yCoords->InsertNextValue(y[i]);
  }

  vtkFloatArray *zCoords = vtkFloatArray::New();
  for (i=0; i<44; i++)
  {
    zCoords->InsertNextValue(z[i]);
  }

  // The coordinates are assigned to the rectilinear grid. Make sure that
  // the number of values in each of the XCoordinates, YCoordinates,
  // and ZCoordinates is equal to what is defined in SetDimensions().
  //
  vtkRectilinearGrid *rgrid = vtkRectilinearGrid::New();
    rgrid->SetDimensions(47,33,44);
    rgrid->SetXCoordinates(xCoords);
    rgrid->SetYCoordinates(yCoords);
    rgrid->SetZCoordinates(zCoords);

    // Extract a plane from the grid to see what we've got.
  vtkRectilinearGridGeometryFilter *plane = vtkRectilinearGridGeometryFilter::New();
    plane->SetInputData(rgrid);
    plane->SetExtent(0,46, 16,16, 0,43);

  vtkPolyDataMapper *rgridMapper = vtkPolyDataMapper::New();
      rgridMapper->SetInputConnection(plane->GetOutputPort());

  vtkActor *wireActor = vtkActor::New();
      wireActor->SetMapper(rgridMapper);
      wireActor->GetProperty()->SetRepresentationToWireframe();
      wireActor->GetProperty()->SetColor(0,0,0);

  // Create the usual rendering stuff.
  vtkRenderer *renderer = vtkRenderer::New();
  vtkRenderWindow *renWin = vtkRenderWindow::New();
    renWin->AddRenderer(renderer);
  vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
    iren->SetRenderWindow(renWin);

  renderer->AddActor(wireActor);
  renderer->SetBackground(1,1,1);
  renderer->ResetCamera();
  renderer->GetActiveCamera()->Elevation(60.0);
  renderer->GetActiveCamera()->Azimuth(30.0);
  renderer->GetActiveCamera()->Zoom(1.0);

  renWin->SetSize(300,300);

  // interact with data
  renWin->Render();
  iren->Start();

  // Clean up
  plane->Delete();
  renderer->Delete();
  renWin->Delete();
  iren->Delete();
  xCoords->Delete();
  yCoords->Delete();
  zCoords->Delete();
  rgrid->Delete();
  rgridMapper->Delete();
  wireActor->Delete();

  return 0;
}