aboutsummaryrefslogtreecommitdiff
path: root/src/AMRPlus/testread.C
diff options
context:
space:
mode:
Diffstat (limited to 'src/AMRPlus/testread.C')
-rw-r--r--src/AMRPlus/testread.C170
1 files changed, 170 insertions, 0 deletions
diff --git a/src/AMRPlus/testread.C b/src/AMRPlus/testread.C
new file mode 100644
index 0000000..b0b7c29
--- /dev/null
+++ b/src/AMRPlus/testread.C
@@ -0,0 +1,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();
+}