geometryCloud.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) 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 "geometryCloud.H"
30 #include "cloud.H"
31 #include "fvMesh.H"
32 #include "runTimePostProcessing.H"
34 
35 // VTK includes
36 #include "vtkActor.h"
37 #include "vtkCompositeDataGeometryFilter.h"
38 #include "vtkCompositeDataSet.h"
39 #include "vtkCompositePolyDataMapper.h"
40 #include "vtkPolyData.h"
41 #include "vtkPolyDataMapper.h"
42 #include "vtkProperty.h"
43 #include "vtkRenderer.h"
44 #include "vtkSmartPointer.h"
45 
46 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
47 
48 namespace Foam
49 {
50 namespace functionObjects
51 {
52 namespace runTimePostPro
53 {
54  defineTypeName(geometryCloud);
55  addToRunTimeSelectionTable(pointData, geometryCloud, dictionary);
56 }
57 }
58 }
59 
60 
61 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
62 
64 (
65  vtkMultiPieceDataSet* multiPiece,
66  const objectRegistry& obrTmp,
67  const word& fieldName
68 ) const
69 {
70  const regIOobject* ioptr = obrTmp.cfindObject<regIOobject>(fieldName);
71 
72  return (multiPiece) &&
73  (
74  addCloudField<label>
75  (
76  multiPiece, ioptr, fieldName
77  )
78  || addCloudField<scalar>
79  (
80  multiPiece, ioptr, fieldName
81  )
82  || addCloudField<vector>
83  (
84  multiPiece, ioptr, fieldName
85  )
86  || addCloudField<sphericalTensor>
87  (
88  multiPiece, ioptr, fieldName
89  )
90  || addCloudField<symmTensor>
91  (
92  multiPiece, ioptr, fieldName
93  )
94  || addCloudField<tensor>
95  (
96  multiPiece, ioptr, fieldName
97  )
98  );
99 }
100 
101 
102 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
103 
105 (
106  const runTimePostProcessing& parent,
107  const dictionary& dict,
108  const HashPtrTable<Function1<vector>>& colours
109 )
110 :
111  pointData(parent, dict, colours),
112  fieldVisualisationBase(dict, colours),
113  cloudName_(dict.get<word>("cloud")),
114  colourFieldName_(dict.get<word>("colourField")),
115  actor_()
116 {}
117 
118 
119 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
120 
123 {}
124 
125 
126 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
127 
130 (
131  const scalar position,
132  vtkRenderer* renderer
133 )
134 {
135  if (!visible_)
136  {
137  return false;
138  }
139 
140 
141  // This is similar (almost identical) to vtkCloud
142 
143  const auto* objPtr = parent().mesh().cfindObject<cloud>(cloudName_);
144  if (!objPtr)
145  {
146  return false;
147  }
148 
149  objectRegistry obrTmp
150  (
151  IOobject
152  (
153  "runTimePostPro::cloud::" + cloudName_,
154  parent().mesh().time().constant(),
155  parent().mesh(),
158  false
159  )
160  );
161 
162  objPtr->writeObjects(obrTmp);
163 
164  const auto* pointsPtr = cloud::findIOPosition(obrTmp);
165 
166  if (!pointsPtr)
167  {
168  // This should be impossible
169  return false;
170  }
171 
172 
173  // Create a vtkMultiPieceDataSet with vtkPolyData on the leaves
174  auto multiPiece = gatherCloud(obrTmp);
175 
176  // Add in scaleField and colourField
177  addCloudField(multiPiece, obrTmp, fieldName_);
178  addCloudField(multiPiece, obrTmp, colourFieldName_);
179 
180 
181  // Not rendered on this processor?
182  // This is where we stop, but could also have an MPI barrier
183  if (!renderer)
184  {
185  return true;
186  }
187 
188  DebugInfo
189  << " Render cloud " << cloudName_ << endl;
190 
191 
192  // Rendering
193 
195 
196  {
197  fieldSummary scaleFieldInfo =
198  queryFieldSummary(fieldName_, multiPiece);
199 
200  fieldSummary colourFieldInfo =
201  queryFieldSummary(colourFieldName_, multiPiece);
202 
204 
205  polyData->SetInputData(multiPiece);
206  polyData->Update();
207 
209 
210  actor_->SetMapper(mapper);
211 
213 
214  addGlyphs
215  (
216  position,
217  fieldName_, scaleFieldInfo, // scaling
218  colourFieldName_, colourFieldInfo, // colour
219  maxGlyphLength_,
220  polyData->GetOutput(),
221  actor_,
222  renderer
223  );
224 
225  renderer->AddActor(actor_);
226  }
227 
228  return true;
229 }
230 
231 
234 (
235  const scalar position,
236  vtkRenderer* renderer
237 )
238 {
239  // Live source
240  addGeometry(position, renderer);
241 }
242 
243 
245 (
246  const scalar position
247 )
248 {
249  if (actor_)
250  {
251  const vector colour = pointColour_->value(position);
252 
253  vtkProperty* prop = actor_->GetProperty();
254 
255  prop->SetOpacity(opacity(position));
256 
257  prop->SetColor(colour[0], colour[1], colour[2]);
258  }
259 }
260 
261 
263 {
264  return false;
265 }
266 
267 
268 // ************************************************************************* //
Foam::functionObjects::runTimePostPro::geometryCloud::addCloudField
bool addCloudField(vtkMultiPieceDataSet *multiPiece, const IOField< Type > *fldptr, const word &fieldName) const
Add field.
Definition: geometryCloudTemplates.C:53
Foam::IOobject::NO_WRITE
Definition: IOobject.H:130
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
Foam::functionObjects::runTimePostPro::addToRunTimeSelectionTable
addToRunTimeSelectionTable(surface, contourFilter, dictionary)
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::functionObjects::runTimePostPro::fieldVisualisationBase::fieldSummary
General field characteristics.
Definition: fieldVisualisationBase.H:172
Foam::functionObjects::runTimePostPro::geometryCloud::updateActors
virtual void updateActors(const scalar position)
Update actors.
Definition: geometryCloud.C:245
cloud.H
Foam::functionObjects::runTimePostPro::geometryCloud::geometryCloud
geometryCloud(const geometryCloud &)=delete
No copy construct.
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
Foam::functionObjects::runTimePostPro::pointData
Visualisation of point data.
Definition: pointData.H:89
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::geometryCloud::addGeometry
bool addGeometry(const scalar position, vtkRenderer *renderer)
Add cloud to scene (from simulation)
Definition: geometryCloud.C:130
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
Foam::functionObjects::runTimePostProcessing
Generate images during run-time.
Definition: runTimePostProcessing.H:170
geometryCloud.H
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
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
fvMesh.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::functionObjects::runTimePostPro::geometryCloud::~geometryCloud
virtual ~geometryCloud()
Destructor.
Definition: geometryCloud.C:122
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::cloud
A cloud is a registry collection of lagrangian particles.
Definition: cloud.H:57
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:67
Foam::functionObjects::runTimePostPro::fieldVisualisationBase
Base class for scene objects.
Definition: fieldVisualisationBase.H:125
runTimePostProcessing.H
DebugInfo
#define DebugInfo
Report an information message using Foam::Info.
Definition: messageStream.H:350
Foam::objectRegistry::cfindObject
const Type * cfindObject(const word &name, const bool recursive=false) const
Return const pointer to the object of the given Type.
Definition: objectRegistryTemplates.C:390
Foam::HashPtrTable
A HashTable of pointers to objects of type <T>.
Definition: HashPtrTable.H:54
Foam::Vector< scalar >
Foam::functionObjects::runTimePostPro::defineTypeName
defineTypeName(contourFilter)
Foam::cloud::findIOPosition
static const IOField< point > * findIOPosition(const objectRegistry &obr)
Locate the "position" IOField within object registry.
Definition: cloud.H:153
Foam::functionObjects::runTimePostPro::geometryCloud::addGeometryToScene
virtual void addGeometryToScene(const scalar position, vtkRenderer *renderer)
Add cloud to scene.
Definition: geometryCloud.C:234
Foam::IOobject::NO_READ
Definition: IOobject.H:123
constant
constant condensation/saturation model.
Foam::functionObjects::runTimePostPro::geometryCloud::clear
virtual bool clear()
No-op.
Definition: geometryCloud.C:262
Foam::functionObjects::runTimePostProcessing::mesh
const fvMesh & mesh() const
Reference to the underlying OpenFOAM mesh.
Definition: runTimePostProcessing.H:259