functionObjectSurface.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
6  \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 // OpenFOAM includes
27 #include "functionObjectSurface.H"
28 #include "runTimePostProcessing.H"
30 
31 // VTK includes
32 #include "vtkActor.h"
33 #include "vtkPolyDataMapper.h"
34 #include "vtkPolyDataReader.h"
35 #include "vtkProperty.h"
36 #include "vtkRenderer.h"
37 #include "vtkSmartPointer.h"
38 
39 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
40 
41 namespace Foam
42 {
43  defineTypeNameAndDebug(functionObjectSurface, 0);
44  addToRunTimeSelectionTable(surface, functionObjectSurface, dictionary);
45 }
46 
47 
48 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
49 
51 (
52  const runTimePostProcessing& parent,
53  const dictionary& dict,
54  const HashPtrTable<DataEntry<vector>, word>& colours
55 )
56 :
57  geometrySurface(parent, dict, colours, List<fileName>()),
58  fieldVisualisationBase(parent, dict, colours),
59  functionObject_("")
60 {
61  if (visible_)
62  {
63  dict.lookup("functionObject") >> functionObject_;
64  }
65 }
66 
67 
68 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
69 
71 {}
72 
73 
74 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
75 
77 (
78  const scalar position,
79  vtkRenderer* renderer
80 )
81 {
82  if (!visible_)
83  {
84  return;
85  }
86 
87  const dictionary dict =
89  (
90  functionObject_,
91  fieldName_,
93  );
94 
95  fileName fName;
96  if (!dict.readIfPresent("file", fName))
97  {
99  << "Unable to find function object " << functionObject_
100  << " output for field " << fieldName_
101  << ". Surface will not be processed"
102  << endl;
103  return;
104  }
105 
106 
107  if (representation_ == rtGlyph)
108  {
109  vtkSmartPointer<vtkPolyDataReader> surf =
111  surf->SetFileName(fName.c_str());
112  surf->Update();
113 
114  addGlyphs
115  (
116  position,
117  fieldName_,
118  fieldName_,
119  maxGlyphLength_,
120  surf->GetOutput(),
121  surfaceActor_,
122  renderer
123  );
124  }
125  else
126  {
127  if ((colourBy_ == cbField) && (fName.ext() == "vtk"))
128  {
129  vtkSmartPointer<vtkPolyDataReader> surf =
131  surf->SetFileName(fName.c_str());
132  surf->Update();
133 
134  addFeatureEdges(renderer, surf->GetOutput());
135 
136  vtkSmartPointer<vtkPolyDataMapper> mapper =
138  mapper->SetInputConnection(surf->GetOutputPort());
139 
140  setField(position, fieldName_, mapper, renderer);
141 
142  surfaceActor_->SetMapper(mapper);
143 
144  setRepresentation(surfaceActor_);
145 
146  renderer->AddActor(surfaceActor_);
147  }
148  else
149  {
150  geometrySurface::addGeometryToScene(position, renderer);
151  }
152  }
153 }
154 
155 
156 // ************************************************************************* //
Foam::geometryBase::parent_
const runTimePostProcessing & parent_
Reference to the parent function object.
Definition: geometryBase.H:89
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::compressible::New
autoPtr< BasicCompressibleTurbulenceModel > New(const volScalarField &rho, const volVectorField &U, const surfaceScalarField &phi, const typename BasicCompressibleTurbulenceModel::transportModel &transport, const word &propertiesName)
Definition: turbulentFluidThermoModel.C:36
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::dictionary::readIfPresent
bool readIfPresent(const word &, T &, bool recursive=false, bool patternMatch=true) const
Find an entry if present, and assign to T.
Definition: dictionaryTemplates.C:94
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
Foam::geometrySurface::addGeometryToScene
void addGeometryToScene(const scalar position, vtkRenderer *renderer, const fileName &fName) const
Add surface (file) to scene.
Definition: geometrySurface.C:59
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::runTimePostProcessing
Function object to generate images during run-time.
Definition: runTimePostProcessing.H:83
functionObjectSurface.H
Foam::geometrySurface
Definition: geometrySurface.H:49
Foam::functionObjectSurface::functionObjectSurface
functionObjectSurface(const functionObjectSurface &)
Disallow default bitwise copy construct.
setField
surfacesMesh setField(triSurfaceToAgglom)
Foam::fieldVisualisationBase
Definition: fieldVisualisationBase.H:65
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::fileName::ext
word ext() const
Return file name extension (part after last .)
Definition: fileName.C:329
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
runTimePostProcessing.H
Foam::HashPtrTable
A HashTable specialization for hashing pointers.
Definition: HashPtrTable.H:50
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::functionObjectSurface::~functionObjectSurface
virtual ~functionObjectSurface()
Destructor.
Definition: functionObjectSurface.C:70
Foam::functionObjectState::getObjectProperty
Type getObjectProperty(const word &objectName, const word &entryName, const Type &defaultValue=pTraits< Type >::zero) const
Retrieve generic property from named object.
Definition: functionObjectStateTemplates.C:83
Foam::functionObjectSurface::addGeometryToScene
virtual void addGeometryToScene(const scalar position, vtkRenderer *renderer)
Add surface(s) to scene.
Definition: functionObjectSurface.C:77
Foam::DataEntry
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: DataEntry.H:52
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:259
Foam::dictionary::null
static const dictionary null
Null dictionary.
Definition: dictionary.H:193