functionObjectCloud.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 "functionObjectCloud.H"
28 #include "runTimePostProcessing.H"
30 
31 // VTK includes
32 #include "vtkActor.h"
33 #include "vtkRenderer.h"
34 #include "vtkSmartPointer.h"
35 #include "vtkPolyDataMapper.h"
36 #include "vtkPolyDataReader.h"
37 #include "vtkProperty.h"
38 
39 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
40 
41 namespace Foam
42 {
43  defineTypeNameAndDebug(functionObjectCloud, 0);
44  addToRunTimeSelectionTable(pointData, functionObjectCloud, 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  pointData(parent, dict, colours),
58  fieldVisualisationBase(parent, dict, colours),
59  cloudName_(dict.lookup("cloudName")),
60  functionObject_(dict.lookup("functionObject")),
61  colourFieldName_(dict.lookup("colourFieldName")),
62  actor_()
63 {
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& cloudDict =
89  (
90  cloudName_ + "OutputProperties"
91  );
92 
93  fileName fName;
94  if (cloudDict.found("cloudFunctionObject"))
95  {
96  const dictionary& foDict = cloudDict.subDict("cloudFunctionObject");
97  if (foDict.found(functionObject_))
98  {
99  foDict.subDict(functionObject_).readIfPresent("file", fName);
100  }
101  }
102 
103  if (fName.empty())
104  {
106  << "Unable to find function object " << functionObject_
107  << " output for field " << fieldName_
108  << ". Line will not be processed"
109  << endl;
110  return;
111  }
112 
113  if (fName.ext() == "vtk")
114  {
115  vtkSmartPointer<vtkPolyDataReader> points =
117  points->SetFileName(fName.c_str());
118  points->Update();
119 
120  vtkSmartPointer<vtkPolyDataMapper> mapper =
122 
123  actor_->SetMapper(mapper);
124 
125  addGlyphs
126  (
127  position,
128  fieldName_,
129  colourFieldName_,
130  maxGlyphLength_,
131  points->GetOutput(),
132  actor_,
133  renderer
134  );
135 
136  renderer->AddActor(actor_);
137  }
138 }
139 
140 
141 void Foam::functionObjectCloud::updateActors(const scalar position)
142 {
143  actor_->GetProperty()->SetOpacity(opacity(position));
144 
145  vector pc = pointColour_->value(position);
146  actor_->GetProperty()->SetColor(pc[0], pc[1], pc[2]);
147 }
148 
149 
150 // ************************************************************************* //
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:53
functionObjectCloud.H
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::pointData
Variant of pointEdgePoint with some transported additional data. WIP - should be templated on data li...
Definition: pointData.H:53
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::functionObjectCloud::~functionObjectCloud
virtual ~functionObjectCloud()
Destructor.
Definition: functionObjectCloud.C:70
Foam::runTimePostProcessing
Function object to generate images during run-time.
Definition: runTimePostProcessing.H:83
Foam::dictionary::found
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:304
Foam::functionObjectCloud::functionObjectCloud
functionObjectCloud(const functionObjectCloud &)
Disallow default bitwise copy construct.
Foam::functionObjectCloud::updateActors
virtual void updateActors(const scalar position)
Update actors.
Definition: functionObjectCloud.C:141
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
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::runTimePostProcessing::obr
virtual const objectRegistry & obr() const
Definition: runTimePostProcessing.H:163
Foam::functionObjectCloud::addGeometryToScene
virtual void addGeometryToScene(const scalar position, vtkRenderer *renderer)
Add tube(s) to scene.
Definition: functionObjectCloud.C:77
runTimePostProcessing.H
Foam::HashPtrTable
A HashTable specialization for hashing pointers.
Definition: HashPtrTable.H:50
Foam::Vector< scalar >
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::objectRegistry::lookupObject
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type.
Definition: objectRegistryTemplates.C:165
Foam::dictionary::subDict
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:631
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