TestHyperTreeGrid.cxx 6.15 KB
Newer Older
1
2
/*=========================================================================

3
4
Copyright (c) Kitware Inc.
All rights reserved.
5
6

=========================================================================*/
Philippe Pébay's avatar
Philippe Pébay committed
7
8
9
// .SECTION Thanks
// This test was written by Charles Law and Philippe Pebay, Kitware 2012

10
#include "vtkHyperTreeGrid.h"
11
#include "vtkHyperTreeGridAxisCut.h"
12
#include "vtkHyperTreeGridSource.h"
13
#include "vtkHyperTreeGridGeometry.h"
14

15
#include "vtkCellData.h"
Philippe Pébay's avatar
Philippe Pébay committed
16
#include "vtkContourFilter.h"
17
#include "vtkCutter.h"
18
#include "vtkDataSetWriter.h"
Philippe Pébay's avatar
Philippe Pébay committed
19
#include "vtkNew.h"
20
21
#include "vtkPlane.h"
#include "vtkPolyDataWriter.h"
Philippe Pébay's avatar
Philippe Pébay committed
22
#include "vtkRenderer.h"
23
24
#include "vtkShrinkFilter.h"
#include "vtkUnstructuredGrid.h"
25
26
27
#include "vtkUnstructuredGridWriter.h"
#include "vtkXMLUnstructuredGridWriter.h"

28
29
#include "vtksys/CommandLineArguments.hxx"

30
int TestHyperTreeGrid( int argc, char* argv[] )
31
{
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
  // Default parameters and options
  int dim = 3;
  int nX = 3;
  int nY = 4;
  int nZ = 2;
  bool skipAxisCut = false;
  bool skipContour = false;
  bool skipCut = false;
  bool skipGeometry = false;
  bool skipShrink = false;

  // Initialize command line argument parser
  vtksys::CommandLineArguments clArgs;
  clArgs.Initialize( argc, argv );
  clArgs.StoreUnusedArguments( false );

  // Parse command line parameters and options
49
50
51
  clArgs.AddArgument( "--dimension",
                      vtksys::CommandLineArguments::SPACE_ARGUMENT,
                      &dim, "Dimension of hyper tree grid" );
52

53
54
55
  clArgs.AddArgument( "--grid-size-X",
                      vtksys::CommandLineArguments::SPACE_ARGUMENT,
                      &nX, "Size of hyper tree grid in X direction" );
56

57
58
59
  clArgs.AddArgument( "--grid-size-Y",
                      vtksys::CommandLineArguments::SPACE_ARGUMENT,
                      &nY, "Size of hyper tree grid in Y direction" );
60

61
62
63
  clArgs.AddArgument( "--grid-size-Z",
                      vtksys::CommandLineArguments::SPACE_ARGUMENT,
                      &nZ, "Size of hyper tree grid in Z direction" );
64

65
66
67
  clArgs.AddArgument( "--skip-Axis-Cut",
                      vtksys::CommandLineArguments::NO_ARGUMENT,
                      &skipAxisCut, "Skip axis cut filter" );
68

69
70
71
  clArgs.AddArgument( "--skip-Contour",
                      vtksys::CommandLineArguments::NO_ARGUMENT,
                      &skipAxisCut, "Skip contour filter" );
72

73
74
75
  clArgs.AddArgument( "--skip-Cut",
                      vtksys::CommandLineArguments::NO_ARGUMENT,
                      &skipCut, "Skip cut filter" );
76

77
78
79
  clArgs.AddArgument( "--skip-Geometry",
                      vtksys::CommandLineArguments::NO_ARGUMENT,
                      &skipGeometry, "Skip geometry filter" );
80

81
82
83
  clArgs.AddArgument( "--skip-Shrink",
                      vtksys::CommandLineArguments::NO_ARGUMENT,
                      &skipShrink, "Skip shrink filter" );
84
85
86
87
88
89
90
91
92

  // If incorrect arguments were provided, provide some help and terminate in error.
  if ( ! clArgs.Parse() )
    {
    cerr << "Usage: "
         << clArgs.GetHelp()
         << "\n";
    }

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
  // Ensure that parsed dimensionality makes sense
  if ( dim > 3 )
    {
    dim = 3;
    }
  else if ( dim < 1 )
    {
    dim = 1;
    }
    
  // Ensure that parsed grid sizes make sense
  if ( nX < 1 )
    {
    nX = 1;
    }
  if ( nY < 1 )
    {
    nY = 1;
    }
  if ( nZ < 1 )
    {
    nZ = 1;
    }

  // Ensure that parsed grid sizes are consistent with dimensionality
  if ( dim < 3 )
    {
    nZ = 1;
    if ( dim < 2 )
      {
      nY = 1;
      }
    }
 
127
128
129
  // Initialize return value of test
  int testIntValue = 0;

130
  // Create hyper tree grid source
131
  vtkNew<vtkHyperTreeGridSource> fractal;
132
  fractal->SetMaximumLevel( 3 );
133
  fractal->DualOn();
134
135
  if ( dim == 3 )
    {
136
    fractal->SetGridSize( nX, nY, nZ );
137
    }
138
  fractal->SetGridSize( nX, nY, nZ );
139
  fractal->SetDimension( dim );
140
  fractal->SetAxisBranchFactor( 3 );
141
142
  fractal->Update();
  vtkHyperTreeGrid* htGrid = fractal->GetOutput();
143

144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
  if ( ! skipGeometry )
    {
    cerr << "# Geometry" << endl;
    vtkNew<vtkHyperTreeGridGeometry> geometry;
    geometry->SetInputConnection( fractal->GetOutputPort() );
    vtkNew<vtkPolyDataWriter> writer4;
    writer4->SetFileName( "./hyperTreeGridGeometry.vtk" );
    writer4->SetInputConnection( geometry->GetOutputPort() );
    writer4->Write();
    }

  if ( ! skipContour )
    {
    cerr << "# Contour" << endl;
    vtkNew<vtkContourFilter> contour;
    contour->SetInputData( htGrid );
    contour->SetNumberOfContours( 2 );
    contour->SetValue( 0, 4. );
    contour->SetValue( 1, 18. );
    contour->SetInputArrayToProcess( 0, 0, 0,
                                     vtkDataObject::FIELD_ASSOCIATION_POINTS,
                                     "Cell Value" );
    vtkNew<vtkPolyDataWriter> writer0;
    writer0->SetFileName( "./hyperTreeGridContour.vtk" );
    writer0->SetInputConnection( contour->GetOutputPort() );
    writer0->Write();
    }

  if ( ! skipShrink )
    {
    cerr << "# Shrink" << endl;
    vtkNew<vtkShrinkFilter> shrink;
    shrink->SetInputData( htGrid );
    shrink->SetShrinkFactor( 1. );
    vtkNew<vtkUnstructuredGridWriter> writer1;
    writer1->SetFileName( "./hyperTreeGridShrink.vtk" );
    writer1->SetInputConnection( shrink->GetOutputPort() );
    writer1->Write();
    }

  if ( ! skipAxisCut )
185
    {
186
187
188
189
190
191
192
193
194
195
196
197
198
    // Axis-aligned cut works only in 3D for now
    if ( dim == 3 )
      {
      cerr << "# HyperTreeGridAxisCut" << endl;
      vtkNew<vtkHyperTreeGridAxisCut> axisCut;
      axisCut->SetInputConnection( fractal->GetOutputPort() );
      axisCut->SetPlaneNormalAxis( 2 );
      axisCut->SetPlanePosition( .1 );
      vtkNew<vtkPolyDataWriter> writer2;
      writer2->SetFileName( "./hyperTreeGridAxisCut.vtk" );
      writer2->SetInputConnection( axisCut->GetOutputPort() );
      writer2->Write();
      }
199
    }
Philippe Pébay's avatar
Philippe Pébay committed
200

201
  if ( ! skipCut )
Philippe Pébay's avatar
Philippe Pébay committed
202
    {
203
204
205
206
207
208
209
210
211
212
213
    cerr << "# Cut" << endl;
    vtkNew<vtkCutter> cut;
    vtkNew<vtkPlane> plane;
    plane->SetOrigin( .5, .5, .15 );
    plane->SetNormal( 0, 0, 1 );
    cut->SetInputData( htGrid );
    cut->SetCutFunction( plane.GetPointer() );
    vtkNew<vtkPolyDataWriter> writer3;
    writer3->SetFileName( "./hyperTreeGridCut.vtk" );
    writer3->SetInputConnection( cut->GetOutputPort() );
    writer3->Write();
Philippe Pébay's avatar
Philippe Pébay committed
214
    }
215

216
  return testIntValue;
217
}