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
|
/*=========================================================================
Program: Visualization Toolkit
Module: TestSimplePointsReaderWriter.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.
=========================================================================*/
#include <vtkSmartPointer.h>
#include <vtkProperty.h>
#include <vtkUnstructuredGrid.h>
#include <vtkPointData.h>
#include <vtkCellData.h>
#include <vtkDataSetMapper.h>
#include <vtkOpenFOAMReader.h>
#include <vtkMultiBlockDataSet.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkTestUtilities.h>
#include <vtkRegressionTestImage.h>
int TestOpenFOAMReader(int argc, char* argv[])
{
// Read file name.
char* filename =
vtkTestUtilities::ExpandDataFileName(argc, argv,
"Data/OpenFOAM/cavity/cavity.foam");
// Read the file
vtkSmartPointer<vtkOpenFOAMReader> reader =
vtkSmartPointer<vtkOpenFOAMReader>::New();
reader->SetFileName(filename);
delete [] filename;
reader->Update();
reader->SetTimeValue(.5);
// reader->CreateCellToPointOn();
reader->ReadZonesOn();
reader->Update();
reader->Print(std::cout);
reader->GetOutput()->Print(std::cout);
reader->GetOutput()->GetBlock(0)->Print(std::cout);
// 1) Default array settings
int numberOfCellArrays = reader->GetNumberOfCellArrays();
std::cout << "----- Default array settings" << std::endl;
for (int i = 0; i < numberOfCellArrays; ++i)
{
const char * name = reader->GetCellArrayName(i);
std::cout << " Cell Array: " << i
<< " is named " << name
<< " and is "
<< (reader->GetCellArrayStatus(name) ? "Enabled" : "Disabled")
<< std::endl;
}
int numberOfPointArrays = reader->GetNumberOfPointArrays();
std::cout << "----- Default array settings" << std::endl;
for (int i = 0; i < numberOfPointArrays; ++i)
{
const char * name = reader->GetPointArrayName(i);
std::cout << " Point Array: " << i
<< " is named " << name
<< " and is "
<< (reader->GetPointArrayStatus(name) ? "Enabled" : "Disabled")
<< std::endl;
}
int numberOfLagrangianArrays = reader->GetNumberOfLagrangianArrays();
std::cout << "----- Default array settings" << std::endl;
for (int i = 0; i < numberOfLagrangianArrays; ++i)
{
const char * name = reader->GetLagrangianArrayName(i);
std::cout << " Lagrangian Array: " << i
<< " is named " << name
<< " and is "
<< (reader->GetLagrangianArrayStatus(name) ? "Enabled" : "Disabled")
<< std::endl;
}
int numberOfPatchArrays = reader->GetNumberOfPatchArrays();
std::cout << "----- Default array settings" << std::endl;
for (int i = 0; i < numberOfPatchArrays; ++i)
{
const char * name = reader->GetPatchArrayName(i);
std::cout << " Patch Array: " << i
<< " is named " << name
<< " and is "
<< (reader->GetPatchArrayStatus(name) ? "Enabled" : "Disabled")
<< std::endl;
}
vtkUnstructuredGrid *block0 = vtkUnstructuredGrid::SafeDownCast(reader->GetOutput()->GetBlock(0));
block0->GetCellData()->SetActiveScalars("p");
std::cout << "Scalar range: "
<< block0->GetCellData()->GetScalars()->GetRange()[0] << ", "
<< block0->GetCellData()->GetScalars()->GetRange()[1] << std::endl;
// Visualize
vtkSmartPointer<vtkDataSetMapper> mapper =
vtkSmartPointer<vtkDataSetMapper>::New();
mapper->SetInputData(block0);
mapper->SetScalarRange(block0->GetScalarRange());
vtkSmartPointer<vtkActor> actor =
vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
renderer->AddActor(actor);
renderer->SetBackground(.2, .4, .6);
renderWindow->Render();
int retVal = vtkRegressionTestImage( renderWindow );
if ( retVal == vtkRegressionTester::DO_INTERACTOR)
{
renderWindowInteractor->Start();
}
return EXIT_SUCCESS;
}
|