TestMultiBlock.cxx 5.11 KB
Newer Older
Berk Geveci's avatar
Berk Geveci committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/*=========================================================================

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

=========================================================================*/
15
// This example demonstrates how hierarchical box (uniform rectilinear)
16
17
// AMR datasets can be processed using the new vtkHierarchicalBoxDataSet class.
//
Berk Geveci's avatar
Berk Geveci committed
18
19
20
21
22
// The command line arguments are:
// -I        => run in interactive mode; unless this is used, the program will
//              not allow interaction and exit
// -D <path> => path to the data; the data should be in <path>/Data/

23
#include "vtkCamera.h"
24
#include "vtkCellDataToPointData.h"
25
#include "vtkCompositeDataPipeline.h"
Berk Geveci's avatar
Berk Geveci committed
26
27
#include "vtkContourFilter.h"
#include "vtkDebugLeaks.h"
28
29
#include "vtkExtractBlock.h"
#include "vtkCompositeDataGeometryFilter.h"
30
#include "vtkMultiBlockPLOT3DReader.h"
31
#include "vtkOutlineCornerFilter.h"
Berk Geveci's avatar
Berk Geveci committed
32
#include "vtkPolyDataMapper.h"
33
#include "vtkProperty.h"
Berk Geveci's avatar
Berk Geveci committed
34
35
36
37
#include "vtkRegressionTestImage.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
38
39
#include "vtkShrinkPolyData.h"
#include "vtkTestUtilities.h"
Berk Geveci's avatar
Berk Geveci committed
40

41
int TestMultiBlock(int argc, char* argv[])
Berk Geveci's avatar
Berk Geveci committed
42
{
43
44
45
46
  vtkCompositeDataPipeline* prototype = vtkCompositeDataPipeline::New();
  vtkAlgorithm::SetDefaultExecutivePrototype(prototype);
  prototype->Delete();

Berk Geveci's avatar
Berk Geveci committed
47
48
  // Standard rendering classes
  vtkRenderer *ren = vtkRenderer::New();
49
50
51
52
53
  vtkCamera* cam = ren->GetActiveCamera();
  cam->SetPosition(-5.1828, 5.89733, 8.97969);
  cam->SetFocalPoint(14.6491, -2.08677, -8.92362);
  cam->SetViewUp(0.210794, 0.95813, -0.193784);

Berk Geveci's avatar
Berk Geveci committed
54
  vtkRenderWindow *renWin = vtkRenderWindow::New();
55
  renWin->SetMultiSamples(0);
Berk Geveci's avatar
Berk Geveci committed
56
57
58
59
  renWin->AddRenderer(ren);
  vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
  iren->SetRenderWindow(renWin);

60
  char* xyzname =
61
    vtkTestUtilities::ExpandDataFileName(argc, argv, "Data/mbwavelet_ascii.xyz");
62
  char* qname =
63
    vtkTestUtilities::ExpandDataFileName(argc, argv, "Data/mbwavelet_ascii.q");
64

65
66
67
68
69
70
71
  vtkMultiBlockPLOT3DReader* reader = vtkMultiBlockPLOT3DReader::New();
  reader->SetXYZFileName(xyzname);
  reader->SetQFileName(qname);
  reader->SetMultiGrid(1);
  reader->SetBinaryFile(0);
  delete[] xyzname;
  delete[] qname;
72
73

  // geometry filter
74
  vtkCompositeDataGeometryFilter* geom =
75
    vtkCompositeDataGeometryFilter::New();
76
77
78
79
  geom->SetInputConnection(0, reader->GetOutputPort(0));

  vtkShrinkPolyData* shrink = vtkShrinkPolyData::New();
  shrink->SetShrinkFactor(0.2);
80
  shrink->SetInputConnection(0, geom->GetOutputPort(0));
81
82
83

  // Rendering objects
  vtkPolyDataMapper* shMapper = vtkPolyDataMapper::New();
84
  shMapper->SetInputConnection(0, shrink->GetOutputPort(0));
85
86
87
88
89
90
91
92
93
94
  vtkActor* shActor = vtkActor::New();
  shActor->SetMapper(shMapper);
  shActor->GetProperty()->SetColor(0, 0, 1);
  ren->AddActor(shActor);

  // corner outline
  vtkOutlineCornerFilter* ocf = vtkOutlineCornerFilter::New();
  ocf->SetInputConnection(0, reader->GetOutputPort(0));

  // geometry filter
95
  vtkCompositeDataGeometryFilter* geom2 =
96
    vtkCompositeDataGeometryFilter::New();
97
98
99
100
  geom2->SetInputConnection(0, ocf->GetOutputPort(0));

  // Rendering objects
  vtkPolyDataMapper* ocMapper = vtkPolyDataMapper::New();
101
  ocMapper->SetInputConnection(0, geom2->GetOutputPort(0));
102
103
104
105
106
  vtkActor* ocActor = vtkActor::New();
  ocActor->SetMapper(ocMapper);
  ocActor->GetProperty()->SetColor(1, 0, 0);
  ren->AddActor(ocActor);

107
  // extract a block
108
  vtkExtractBlock* eds = vtkExtractBlock::New();
109
  eds->SetInputConnection(0, reader->GetOutputPort(0));
110
  eds->AddIndex(2);
111

112
  // contour
113
  vtkContourFilter* contour = vtkContourFilter::New();
114
115
  contour->SetInputConnection(0, eds->GetOutputPort(0));
  contour->SetValue(0, 149);
116
117

  // geometry filter
118
  vtkCompositeDataGeometryFilter* geom3 =
119
    vtkCompositeDataGeometryFilter::New();
120
121
122
123
  geom3->SetInputConnection(0, contour->GetOutputPort(0));

  // Rendering objects
  vtkPolyDataMapper* contMapper = vtkPolyDataMapper::New();
124
  contMapper->SetInputConnection(0, geom3->GetOutputPort(0));
125
126
127
128
  vtkActor* contActor = vtkActor::New();
  contActor->SetMapper(contMapper);
  contActor->GetProperty()->SetColor(1, 0, 0);
  ren->AddActor(contActor);
129

Berk Geveci's avatar
Berk Geveci committed
130
  // Standard testing code.
131
  eds->Delete();
132
133
134
135
136
137
138
139
  ocf->Delete();
  geom2->Delete();
  ocMapper->Delete();
  ocActor->Delete();
  contour->Delete();
  geom3->Delete();
  contMapper->Delete();
  contActor->Delete();
Berk Geveci's avatar
Berk Geveci committed
140
141
142
143
144
145
146
147
  ren->SetBackground(1,1,1);
  renWin->SetSize(300,300);
  renWin->Render();
  int retVal = vtkRegressionTestImage( renWin );
  if ( retVal == vtkRegressionTester::DO_INTERACTOR)
    {
    iren->Start();
    }
148

Berk Geveci's avatar
Berk Geveci committed
149
  // Cleanup
150
151
152
  geom->Delete();
  shMapper->Delete();
  shActor->Delete();
Berk Geveci's avatar
Berk Geveci committed
153
154
155
  ren->Delete();
  renWin->Delete();
  iren->Delete();
156
157
  reader->Delete();
  shrink->Delete();
158

159
  vtkAlgorithm::SetDefaultExecutivePrototype(0);
Berk Geveci's avatar
Berk Geveci committed
160
161
  return !retVal;
}