aboutsummaryrefslogtreecommitdiff
path: root/src/AMRPlus/testread.C
blob: b0b7c2972379733892327cc6b44269d1e0c62b1c (plain)
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
132
133
134
135
136
137
138
139
140
141
142
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
// generated by Fast Light User Interface Designer (fluid) version 1.00

#include <vtk.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include "vtkAMRStructuredPointsReader.h"
vtkRenderer *renderer;
vtkRenderWindow* renWin;
vtkOutlineFilter *outline;
vtkContourFilter *contour;
vtkPolyDataMapper *outlineMapper;
vtkPolyDataMapper *contMapper;
vtkActor *outlineActor;
vtkActor *contActor;
vtkPolyData *t, *outlineOut, *contOut, *t1;
vtkStructuredPoints *temp, *out;
vtkAMRStructuredPointsReader* spr=0;



int main(int argc, char** argv) {
  // Make a window to put the rendering window in. FLTK interface.
  // Fl_Window* w;
  //{ Fl_Window* o = w = MainWin = 
  //    new Fl_Window(500, 500, "AMRTest");
  //  w = o;
  //  o->end();
  // }
  //renWin = vtkFlRenderWindow::New();
  renderer = vtkRenderer::New(); 

  // uncomment this to use the VTK rendering window
  //renderer->SetBackground(0.5, 0.5, 0.5);
  renWin = vtkRenderWindow::New();
  
  renWin->AddRenderer(renderer);

  // uncomment this to use VTK event handler
  vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
    iren->SetRenderWindow(renWin);

  //create a reader and open the file "amr.raw"
  spr = vtkAMRStructuredPointsReader::New();
  spr->SetFileName("/nfs/zeus/lcascr1/pushkare/work/amr.raw");
  cout<<"NLevels: "<<spr->GetNumLevels()<<endl;
  cout<<"NTime: "<<spr->GetNumTimeSteps()<<endl;
  int nlevel=0;
  if (argc>1) nlevel=atoi(argv[1]);
  spr->SelectLevel(nlevel);
  spr->SelectTimeStep(0);
  spr->Update();
  
  int n = spr->GetNumDatasets();
  cout<<"NDataSets: "<<n<<endl;
  //initialize the filters for isosurface and bounding box
  outline = vtkOutlineFilter::New();
  contour = vtkContourFilter::New();

  //initialize the data collections to collect data in the various stages of
  //the pipeline
  vtkDataSetCollection *Data = vtkDataSetCollection::New();
  vtkPolyDataCollection *PolyData = vtkPolyDataCollection::New();
  vtkPolyDataCollection *Outlines = vtkPolyDataCollection::New();

  // This loop reads the grids from a file and puts them into Data, the
  //dataset collection.
  for (int i=0; i<n; i++)
    {
      spr->SelectDataset(i);
      spr->Update();
      out = spr->GetOutput();
      temp = (vtkStructuredPoints*)out->MakeObject();
      
      temp->CopyStructure(out);
      temp->GetPointData()->DeepCopy(out->GetPointData());
      temp->GetCellData()->DeepCopy(out->GetCellData());
      temp->ForceUpdate();

      Data->AddItem(temp);
    }

  int NContours = 0;
  Data->InitTraversal();


  // This loop takes the grids from Data and processes them to get an outline
  // and isosurface for each grid. The isovalue for the dataset is set to 0.86
  // for now.
  for (int j=0; j<n; j++)
    { 
      float *x1, Iso;
      temp = (vtkStructuredPoints*)Data->GetNextItem();
      x1 = temp->GetPointData()->GetScalars()->GetRange();
      Iso = 0.86;

      //if the isovalue is out of bounds for a particular grid, then just
      //ignore that grid.
      if (Iso < x1[0] || Iso > x1[1])
	continue;
      NContours++;

      //produce the isosurface and stick it into the PolyData collection.
      contour->SetInput(temp);
      contour->SetValue(0, Iso);
      contour->Update();
      contOut = contour->GetOutput();

      t = (vtkPolyData*)contOut->MakeObject();

      t->CopyStructure(contOut);
      t->GetPointData()->DeepCopy(contOut->GetPointData());
      t->GetCellData()->DeepCopy(contOut->GetCellData());
      t->ForceUpdate();

      PolyData->AddItem(t);
      
      //produce a bounding box and put it into an Outlines collection
      outline->SetInput(temp);
      outline->Update();

      outlineOut = outline->GetOutput();
      
      t1 = (vtkPolyData*)outlineOut->MakeObject();
      t1->CopyStructure(outlineOut);

      Outlines->AddItem(t1);

    }

  PolyData->InitTraversal();
  Outlines->InitTraversal();


  //This loop takes care of the final mapper and actor steps of the pipeline
  for (int k=0; k<NContours; k++)
    {
      //produce and add the isosurface actor
      contMapper = vtkPolyDataMapper::New();
      contMapper->SetInput(PolyData->GetNextItem());
      contMapper->ImmediateModeRenderingOn();
      contActor = vtkActor::New();
      contActor->SetMapper(contMapper);
      contActor->GetProperty()->SetRepresentationToSurface();
      renderer->AddActor(contActor);
      
      //produce and add the bounding box actor, which is colored RED
      outlineMapper = vtkPolyDataMapper::New();
      outlineMapper->SetInput(Outlines->GetNextItem());
      outlineActor = vtkActor::New();
      outlineActor->SetMapper(outlineMapper);
      outlineActor->GetProperty()->SetColor(1.0, 0.0, 0.0);
      renderer->AddActor(outlineActor);

    } 
  
  // this part makes sure that something actually does show up on the screen
  //     w->show(argc, argv);
  // w->begin();
  // vtkwin = new Fl_vtk_Window( renWin, 1, 1, 498, 498);
  //   vtkwin->show(1, argv);
  //w->end();
  
  //return Fl::run();
  
  //uncomment this and comment the FLTK stuff to use VTK window and event loop.
  renWin->Render();
  iren->Start();
}