surface.H
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 Class
27  Foam::functionObjects::runTimePostPro::surface
28 
29 Description
30  Visualisation of surface data with additional routines for handling
31  parallel distributed data.
32 
33  Dictionary controls
34  \table
35  Property | Description | Required | Default
36  representation| none/glyph/wireframe/surface/surfaceWithEdges | yes |
37  surfaceColour | Override surface colour | no |
38  edgeColour | Override edge colour | no |
39  featureEdges | Display surface feature edges | no | false
40  maxGlyphLength | Limit for glyph representation | yes | 0
41  backFaceCulling | Cull back face | no | false
42  frontFaceCulling | Cull front face | no | true
43  \endtable
44 
45 SourceFiles
46  surface.C
47  surfaceGather.C
48  surfaceTemplates.C
49 
50 \*---------------------------------------------------------------------------*/
51 
52 #ifndef functionObjects_runTimePostPro_surface_H
53 #define functionObjects_runTimePostPro_surface_H
54 
55 #include "geometryBase.H"
56 #include "DimensionedField.H"
57 #include "Enum.H"
58 #include "runTimeSelectionTables.H"
59 
60 #include "vtkSmartPointer.h"
61 #include "vtkMultiPieceDataSet.h"
62 
63 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
64 
65 // Forward Declarations
66 class vtkActor;
67 class vtkRenderer;
68 class vtkCellData;
69 class vtkCompositeDataGeometryFilter;
70 class vtkFeatureEdges;
71 class vtkPointData;
72 class vtkPolyData;
73 
74 namespace Foam
75 {
76 // Forward Declarations
77 class polySurface;
78 class polySurfaceGeoMesh;
79 class polySurfacePointGeoMesh;
80 }
81 
82 
83 // These need to shift elsewhere
84 
85 namespace Foam
86 {
87 namespace vtk
88 {
89 namespace Tools
90 {
91 
92 //- Functional call with null-pointer check
93 vtkCellData* GetCellData(vtkDataSet* dataset);
94 
95 //- Functional call with null-pointer check
96 vtkPointData* GetPointData(vtkDataSet* dataset);
97 
98 
99 //- Default field access is vtkCellData
100 template<class Type>
101 struct FieldAccess
102 {
103  vtkCellData* operator()(vtkDataSet* dataset) const
104  {
105  return Tools::GetCellData(dataset);
106  }
107 };
108 
109 
110 // Specializations on OpenFOAM type
111 
112 //- PointAccess for point fields (on polySurfacePointGeoMesh)
113 template<>
114 struct FieldAccess<::Foam::polySurfacePointGeoMesh>
115 {
116  vtkPointData* operator()(vtkDataSet* dataset) const
117  {
118  return Tools::GetPointData(dataset);
119  }
120 };
121 
122 } // End namespace Tools
123 } // End namespace vtk
124 } // End namespace Foam
125 
126 
127 // More
128 
129 
130 namespace Foam
131 {
132 namespace functionObjects
133 {
134 namespace runTimePostPro
135 {
136 
137 /*---------------------------------------------------------------------------*\
138  Class surface Declaration
139 \*---------------------------------------------------------------------------*/
140 
141 class surface
142 :
143  public geometryBase
144 {
145 public:
146 
147  // Public enumerations
148 
149  //- Surface representation types
150  enum representationType
151  {
152  rtNone,
154  rtWireframe,
157  };
158 
159  //- Names for surface representation types
161 
162 
163 protected:
164 
165  // Protected Data
166 
167  //- Representation type
169 
170  //- Activate feature edges
171  bool featureEdges_;
172 
173  //- Back face culling option; default = off
174  bool backFaceCulling_;
175 
176  //- Front face culling option; default = on
177  bool frontFaceCulling_;
178 
179  //- Surface colour
181 
182  //- Edge colour
184 
185  //- Surface actor
187 
188  //- Edge actor
190 
191  //- Max glyph length for representation type rtGlyph
193 
194 
195  // Protected Member Functions
196 
197  //- Set the representation
198  void setRepresentation(vtkActor* actor) const;
199 
200  //- Add feature edges to scene
201  void addFeatureEdges
202  (
203  vtkRenderer* renderer,
204  vtkFeatureEdges* featureEdges
205  ) const;
206 
207  //- Add feature edges to scene
208  void addFeatureEdges
209  (
210  vtkRenderer* renderer,
211  vtkPolyData* data
212  ) const;
213 
214  //- Add feature edges to scene
215  void addFeatureEdges
216  (
217  vtkRenderer* renderer,
218  vtkCompositeDataGeometryFilter* input
219  ) const;
220 
221 
222  //- Gather and convert polySurface to multi-piece dataset with
223  //- vtkPolyData for the leaves.
224  // If VTK is also running in parallel, each surface is left
225  // as a processor-local piece. Otherwise all processor-local
226  // surfaces are gathered onto the master in their correponding
227  // slots.
229  gatherSurfacePieces(const polySurface* surf) const;
230 
231  //- Gather and convert polySurface to multi-piece dataset with
232  //- vtkPolyData for the leaves.
233  // If VTK is also running in parallel, each surface is left
234  // as a processor-local piece. Otherwise all processor-local
235  // surfaces are gathered onto the master in their correponding
236  // slots.
238  gatherFaceCentres(const polySurface* surf) const;
239 
240 
241  // Adding Fields - single-piece
242 
243  //- Add field of Type to piece as VTK field data in GeoMeshType slot.
244  // GeoMeshType distinguishes between vtkCellData and vtkPointData
245  template<class Type, class GeoMeshType>
246  bool addField
247  (
248  vtkDataSet* piece,
249  const Field<Type>& fld,
250  const word& fieldName
251  ) const;
252 
253  //- Attempt cast of regIOobject to DimensionedField<Type> and
254  //- add to piece as VTK field data in GeoMeshType slot.
255  // GeoMeshType distinguishes between vtkCellData and vtkPointData
256  template<class Type, class GeoMeshType>
257  bool addDimField
258  (
259  vtkDataSet* piece,
260  const regIOobject* ioptr,
261  const word& fieldName
262  ) const;
263 
264  //- Attempt cast of regIOobject to standard DimensionedField types
265  //- and add to piece when possible
266  template<class GeoMeshType>
267  bool addDimField
268  (
269  vtkDataSet* piece,
270  const regIOobject* ioptr,
271  const word& fieldName
272  ) const;
273 
274 
275  // Adding Fields - multi-piece
276 
277  //- Add DimensionedField of Type to multi-piece as VTK field data in
278  //- GeoMeshType slot (CELL | POINT).
279  template<class Type, class GeoMeshType>
280  bool addDimField
281  (
282  vtkMultiPieceDataSet* multiPiece,
284  const word& fieldName
285  ) const;
286 
287  //- Attempt cast of regIOobject to DimensionedField<Type> and
288  //- add in multi-piece as VTK field data in
289  //- GeoMeshType slot (CELL | POINT).
290  template<class Type, class GeoMeshType>
291  bool addDimField
292  (
293  vtkMultiPieceDataSet* multiPiece,
294  const regIOobject* ioptr,
295  const word& fieldName
296  ) const;
297 
298  //- Attempt cast of regIOobject to standard DimensionedField types
299  //- and add when possible in GeoMeshType slot (CELL | POINT).
300  template<class GeoMeshType>
301  bool addDimField
302  (
303  vtkMultiPieceDataSet* multiPiece,
304  const regIOobject* ioptr,
305  const word& fieldName
306  ) const;
307 
308  //- Add using regIOobject information obtained from surface
309  template<class GeoMeshType>
310  bool addDimField
311  (
312  vtkMultiPieceDataSet* multiPiece,
313  const polySurface* surf,
314  const word& fieldName
315  ) const;
316 
317 
318  //- No copy construct
319  surface(const surface&) = delete;
320 
321  //- No copy assignment
322  void operator=(const surface&) = delete;
323 
324 
325 public:
326 
327  //- Run-time type information
328  TypeNameNoDebug("surface");
329 
330 
331  // Declare run-time constructor selection table
332 
334  (
335  autoPtr,
336  surface,
337  dictionary,
338  (
340  const dictionary& dict,
342  ),
343  (parent, dict, colours)
344  );
345 
346 
347  // Constructors
348 
349  //- Construct from dictionary
350  surface
351  (
353  const dictionary& dict,
355  );
356 
357 
358  // Selectors
359 
360  //- Return selected surface
361  static autoPtr<surface> New
362  (
364  const dictionary& dict,
366  const word& surfaceName
367  );
368 
369 
370  //- Destructor
371  virtual ~surface();
372 
373 
374  // Member Functions
375 
376  //- Update the actors
377  virtual void updateActors(const scalar position);
378 };
379 
380 
381 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
382 
383 } // End namespace runTimePostPro
384 } // End namespace functionObjects
385 } // End namespace Foam
386 
387 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
388 
389 #ifdef NoRepository
390  #include "surfaceTemplates.C"
391 #endif
392 
393 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
394 
395 #endif
396 
397 // ************************************************************************* //
Foam::Enum< representationType >
Foam::functionObjects::runTimePostPro::surface::surface
surface(const surface &)=delete
No copy construct.
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::functionObjects::runTimePostPro::surface::gatherFaceCentres
vtkSmartPointer< vtkMultiPieceDataSet > gatherFaceCentres(const polySurface *surf) const
Definition: surfaceGather.C:135
Foam::vtk::Tools::FieldAccess::operator()
vtkCellData * operator()(vtkDataSet *dataset) const
Definition: surface.H:142
Foam::functionObjects::runTimePostPro::surface::addDimField
bool addDimField(vtkDataSet *piece, const regIOobject *ioptr, const word &fieldName) const
Definition: surfaceTemplates.C:62
surfaceTemplates.C
DimensionedField.H
Foam::vtk::Tools::FieldAccess
Default field access is vtkCellData.
Definition: surface.H:140
Foam::functionObjects::runTimePostPro::surface::rtGlyph
"glyph"
Definition: surface.H:192
Foam::functionObjects::runTimePostPro::surface::edgeColour_
autoPtr< Function1< vector > > edgeColour_
Edge colour.
Definition: surface.H:222
Foam::functionObjects::runTimePostPro::surface::addFeatureEdges
void addFeatureEdges(vtkRenderer *renderer, vtkFeatureEdges *featureEdges) const
Add feature edges to scene.
Definition: surface.C:136
geometryBase.H
vtkSmartPointer< vtkActor >
Foam::functionObjects::runTimePostPro::surface::featureEdges_
bool featureEdges_
Activate feature edges.
Definition: surface.H:210
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::surface::representationType
representationType
Surface representation types.
Definition: surface.H:189
Foam::polySurface
A surface mesh consisting of general polygon faces and capable of holding fields.
Definition: polySurface.H:67
Foam::Field
Generic templated field type.
Definition: Field.H:63
Foam::functionObjects::runTimePostProcessing
Generate images during run-time.
Definition: runTimePostProcessing.H:170
Foam::functionObjects::runTimePostPro::surface::maxGlyphLength_
scalar maxGlyphLength_
Max glyph length for representation type rtGlyph.
Definition: surface.H:231
Foam::functionObjects::runTimePostPro::surface
Visualisation of surface data with additional routines for handling parallel distributed data.
Definition: surface.H:180
Foam::functionObjects::runTimePostPro::surface::updateActors
virtual void updateActors(const scalar position)
Update the actors.
Definition: surface.C:289
Foam::functionObjects::runTimePostPro::geometryBase::parent
const runTimePostProcessing & parent() const
Return the reference to the parent function object.
Definition: geometryBase.C:141
Foam::functionObjects::runTimePostPro::surface::surfaceColour_
autoPtr< Function1< vector > > surfaceColour_
Surface colour.
Definition: surface.H:219
Foam::functionObjects::runTimePostPro::surface::New
static autoPtr< surface > New(const runTimePostProcessing &parent, const dictionary &dict, const HashPtrTable< Function1< vector >> &colours, const word &surfaceName)
Return selected surface.
Definition: surface.C:254
Foam::functionObjects::runTimePostPro::surface::rtNone
"none"
Definition: surface.H:191
Foam::functionObjects::runTimePostPro::surface::backFaceCulling_
bool backFaceCulling_
Back face culling option; default = off.
Definition: surface.H:213
fld
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< ' ';}gmvFile<< nl;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Definition: gmvOutputLagrangian.H:23
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
Foam::functionObjects::runTimePostPro::surface::rtWireframe
"wireframe"
Definition: surface.H:193
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::functionObjects::runTimePostPro::surface::surfaceActor_
vtkSmartPointer< vtkActor > surfaceActor_
Surface actor.
Definition: surface.H:225
Foam::functionObjects::runTimePostPro::surface::gatherSurfacePieces
vtkSmartPointer< vtkMultiPieceDataSet > gatherSurfacePieces(const polySurface *surf) const
Definition: surfaceGather.C:44
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::functionObjects::runTimePostPro::surface::representationTypeNames
static const Enum< representationType > representationTypeNames
Names for surface representation types.
Definition: surface.H:199
Foam::functionObjects::runTimePostPro::geometryBase
Base class for surface, text handling etc.
Definition: geometryBase.H:101
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:67
Foam::functionObjects::runTimePostPro::surface::rtSurface
"surface"
Definition: surface.H:194
Foam::functionObjects::runTimePostPro::surface::TypeNameNoDebug
TypeNameNoDebug("surface")
Run-time type information.
Foam::HashPtrTable
A HashTable of pointers to objects of type <T>.
Definition: HashPtrTable.H:54
runTimeSelectionTables.H
Macros to ease declaration of run-time selection tables.
Foam::functionObjects::runTimePostPro::surface::representation_
representationType representation_
Representation type.
Definition: surface.H:207
Foam::functionObjects::runTimePostPro::surface::addField
bool addField(vtkDataSet *piece, const Field< Type > &fld, const word &fieldName) const
Add field of Type to piece as VTK field data in GeoMeshType slot.
Definition: surfaceTemplates.C:36
Foam::functionObjects::runTimePostPro::surface::~surface
virtual ~surface()
Destructor.
Definition: surface.C:282
Foam::polySurfacePointGeoMesh
The polySurface GeoMesh (for holding point fields).
Definition: polySurfacePointGeoMesh.H:48
Foam::vtk::Tools::GetCellData
vtkCellData * GetCellData(vtkDataSet *dataset)
Functional call with null-pointer check.
Definition: surface.C:80
Foam::functionObjects::runTimePostPro::geometryBase::colours
const HashPtrTable< Function1< vector > > & colours() const
Return reference to the colours.
Definition: geometryBase.C:171
Foam::functionObjects::runTimePostPro::surface::frontFaceCulling_
bool frontFaceCulling_
Front face culling option; default = on.
Definition: surface.H:216
Foam::functionObjects::runTimePostPro::surface::operator=
void operator=(const surface &)=delete
No copy assignment.
Foam::functionObjects::runTimePostPro::surface::declareRunTimeSelectionTable
declareRunTimeSelectionTable(autoPtr, surface, dictionary,(const runTimePostProcessing &parent, const dictionary &dict, const HashPtrTable< Function1< vector >> &colours),(parent, dict, colours))
Foam::functionObjects::runTimePostPro::surface::setRepresentation
void setRepresentation(vtkActor *actor) const
Set the representation.
Definition: surface.C:96
Foam::data
Database for solution data, solver performance and other reduced data.
Definition: data.H:54
Foam::functionObjects::runTimePostPro::surface::rtSurfaceWithEdges
"surfaceWithEdges"
Definition: surface.H:195
Foam::functionObjects::runTimePostPro::surface::edgeActor_
vtkSmartPointer< vtkActor > edgeActor_
Edge actor.
Definition: surface.H:228
Foam::vtk::Tools::GetPointData
vtkPointData * GetPointData(vtkDataSet *dataset)
Functional call with null-pointer check.
Definition: surface.C:86
Foam::vtk::Tools::FieldAccess<::Foam::polySurfacePointGeoMesh >::operator()
vtkPointData * operator()(vtkDataSet *dataset) const
Definition: surface.H:155
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:54
Enum.H