functionObjectLine.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2015-2019 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 // OpenFOAM includes
29 #include "functionObjectLine.H"
30 #include "runTimePostProcessing.H"
32 
33 // VTK includes
34 #include "vtkActor.h"
35 #include "vtkPolyData.h"
36 #include "vtkPolyDataMapper.h"
37 #include "vtkProperty.h"
38 #include "vtkRenderer.h"
39 #include "vtkSmartPointer.h"
40 
41 // VTK Readers
42 #include "vtkPolyDataReader.h"
43 #include "vtkXMLPolyDataReader.h"
44 
45 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 namespace functionObjects
50 {
51 namespace runTimePostPro
52 {
53  defineTypeName(functionObjectLine);
54  addToRunTimeSelectionTable(pathline, functionObjectLine, dictionary);
55 }
56 }
57 }
58 
59 
60 // * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
61 
62 namespace
63 {
64 
65 static vtkSmartPointer<vtkPolyData> getPolyDataFile(const Foam::fileName& fName)
66 {
67  // Not extremely elegant...
69 
70  if ("vtk" == fName.ext())
71  {
73 
74  reader->SetFileName(fName.c_str());
75  reader->Update();
76  dataset = reader->GetOutput();
77 
78  return dataset;
79  }
80 
81  if ("vtp" == fName.ext())
82  {
84 
85  reader->SetFileName(fName.c_str());
86  reader->Update();
87  dataset = reader->GetOutput();
88 
89  return dataset;
90  }
91 
92  return dataset;
93 }
94 
95 } // End anonymous namespace
96 
97 
98 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
99 
101 (
102  const runTimePostProcessing& parent,
103  const dictionary& dict,
104  const HashPtrTable<Function1<vector>>& colours
105 )
106 :
107  pathline(parent, dict, colours),
108  functionObjectBase(parent, dict, colours),
109  actor_()
110 {
112 }
113 
114 
115 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
116 
118 {}
119 
120 
121 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
122 
125 (
126  const scalar position,
127  vtkRenderer* renderer
128 )
129 {
130  // Currently master-only
131  if (!visible_ || !renderer || !Pstream::master())
132  {
133  return;
134  }
135 
136  fileName fName = getFileName("file", fieldName_);
137  if (fName.empty())
138  {
140  << "Unable to read file name from function object "
141  << functionObjectName_ << " for field " << fieldName_
142  << ". Line will not be processed"
143  << endl;
144  return;
145  }
146 
147 
148  auto polyData = getPolyDataFile(fName);
149 
150  if (!polyData || polyData->GetNumberOfPoints() == 0)
151  {
153  << "Could not read "<< fName << nl
154  << "Only VTK (.vtp, .vtk) files are supported"
155  << endl;
156  return;
157  }
158 
159  DebugInfo << " Resolved lines " << fName << endl;
160 
161 
163 
164  setField
165  (
166  position,
167  fieldName_,
168  queryFieldAssociation(fieldName_, polyData),
169  mapper,
170  renderer
171  );
172 
173  actor_->SetMapper(mapper);
174 
175  addLines(position, actor_, polyData);
176 
177  renderer->AddActor(actor_);
178 }
179 
180 
182 (
183  const scalar position
184 )
185 {
186  actor_->GetProperty()->SetLineWidth(2);
187  actor_->GetProperty()->SetOpacity(opacity(position));
188 }
189 
190 
192 {
194  {
195  return removeFile("file", fieldName_);
196  }
197 
198  return false;
199 }
200 
201 
202 // ************************************************************************* //
Foam::functionObjects::runTimePostPro::functionObjectLine::addGeometryToScene
virtual void addGeometryToScene(const scalar position, vtkRenderer *renderer)
Add tube(s) to scene.
Definition: functionObjectLine.C:125
Foam::functionObjects::runTimePostPro::addToRunTimeSelectionTable
addToRunTimeSelectionTable(surface, contourFilter, dictionary)
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::functionObjects::runTimePostPro::functionObjectLine::clear
virtual bool clear()
Clear files used to create the object(s)
Definition: functionObjectLine.C:191
Foam::functionObjects::runTimePostPro::functionObjectLine::updateActors
virtual void updateActors(const scalar position)
Update actors.
Definition: functionObjectLine.C:182
vtkSmartPointer
Definition: runTimePostProcessing.H:148
Foam::functionObjects::runTimePostPro::pathline
Visualisation of line data (eg, streamlines)
Definition: pathline.H:89
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
functionObjectLine.H
Foam::Function1
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: Function1.H:56
Foam::functionObjects::runTimePostPro::functionObjectBase
Base class for function object visualisation.
Definition: functionObjectBase.H:86
Foam::functionObjects::runTimePostProcessing
Generate images during run-time.
Definition: runTimePostProcessing.H:170
setField
surfacesMesh setField(triSurfaceToAgglom)
Foam::functionObjects::runTimePostPro::functionObjectBase::clear
virtual bool clear()
Clear files used to create the object(s)
Definition: functionObjectBase.C:88
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
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: fileNameI.H:228
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::UPstream::master
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:438
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
Foam::functionObjects::runTimePostPro::functionObjectLine::functionObjectLine
functionObjectLine(const functionObjectLine &)=delete
No copy construct.
runTimePostProcessing.H
DebugInfo
#define DebugInfo
Report an information message using Foam::Info.
Definition: messageStream.H:350
Foam::nl
constexpr char nl
Definition: Ostream.H:372
Foam::HashPtrTable
A HashTable of pointers to objects of type <T>.
Definition: HashPtrTable.H:54
Foam::functionObjects::runTimePostPro::defineTypeName
defineTypeName(contourFilter)
Foam::functionObjects::runTimePostPro::functionObjectLine::~functionObjectLine
virtual ~functionObjectLine()
Destructor.
Definition: functionObjectLine.C:117
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:294