surface.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 "surface.H"
30 #include "runTimePostProcessing.H"
31 
32 #include "foamVtkTools.H"
33 #include "polySurfaceFields.H"
34 #include "polySurfacePointFields.H"
35 
36 // VTK includes
37 #include "vtkActor.h"
38 #include "vtkCompositeDataGeometryFilter.h"
39 #include "vtkFeatureEdges.h"
40 #include "vtkMultiPieceDataSet.h"
41 #include "vtkPolyData.h"
42 #include "vtkPolyDataMapper.h"
43 #include "vtkProperty.h"
44 #include "vtkRenderer.h"
45 #include "vtkSmartPointer.h"
46 
47 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
48 
49 namespace Foam
50 {
51 namespace functionObjects
52 {
53 namespace runTimePostPro
54 {
55  defineTypeName(surface);
56  defineRunTimeSelectionTable(surface, dictionary);
57 }
58 }
59 }
60 
61 
62 const Foam::Enum
63 <
65 >
67 ({
68  { representationType::rtNone, "none" },
69  { representationType::rtGlyph, "glyph" },
70  { representationType::rtWireframe, "wireframe" },
71  { representationType::rtSurface, "surface" },
72  { representationType::rtSurfaceWithEdges, "surfaceWithEdges" },
73 });
74 
75 
76 // * * * * * * * * * * * * * * * Specializations * * * * * * * * * * * * * * //
77 
78 // These need to shift elsewhere
79 
80 vtkCellData* Foam::vtk::Tools::GetCellData(vtkDataSet* dataset)
81 {
82  if (dataset) return dataset->GetCellData();
83  return nullptr;
84 }
85 
86 vtkPointData* Foam::vtk::Tools::GetPointData(vtkDataSet* dataset)
87 {
88  if (dataset) return dataset->GetPointData();
89  return nullptr;
90 }
91 
92 
93 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
94 
96 (
97  vtkActor* actor
98 ) const
99 {
100  geometryBase::initialiseActor(actor);
101 
102  switch (representation_)
103  {
104  case rtNone:
105  {
106  actor->VisibilityOff();
107  break;
108  }
109  case rtWireframe:
110  {
111  // Note: colour is set using general SetColor, not SetEdgeColor
112  actor->GetProperty()->SetRepresentationToWireframe();
113  break;
114  }
115  case rtGlyph:
116  case rtSurface:
117  {
118  actor->GetProperty()->SetBackfaceCulling(backFaceCulling_);
119  actor->GetProperty()->SetFrontfaceCulling(frontFaceCulling_);
120  actor->GetProperty()->SetRepresentationToSurface();
121  break;
122  }
123  case rtSurfaceWithEdges:
124  {
125  actor->GetProperty()->SetBackfaceCulling(backFaceCulling_);
126  actor->GetProperty()->SetFrontfaceCulling(frontFaceCulling_);
127  actor->GetProperty()->SetRepresentationToSurface();
128  actor->GetProperty()->EdgeVisibilityOn();
129  break;
130  }
131  }
132 }
133 
134 
136 (
137  vtkRenderer* renderer,
138  vtkFeatureEdges* featureEdges
139 ) const
140 {
141  if (!featureEdges)
142  {
143  return;
144  }
145 
146  featureEdges->BoundaryEdgesOn();
147  featureEdges->FeatureEdgesOn();
148  featureEdges->ManifoldEdgesOff();
149  featureEdges->NonManifoldEdgesOff();
151  featureEdges->ColoringOff();
152  featureEdges->Update();
153 
155  mapper->SetInputConnection(featureEdges->GetOutputPort());
156  mapper->ScalarVisibilityOff();
157 
158  edgeActor_->GetProperty()->SetSpecular(0);
159  edgeActor_->GetProperty()->SetSpecularPower(20);
160  edgeActor_->GetProperty()->SetRepresentationToWireframe();
161  edgeActor_->SetMapper(mapper);
162 
163  renderer->AddActor(edgeActor_);
164 }
165 
166 
168 (
169  vtkRenderer* renderer,
170  vtkPolyData* data
171 ) const
172 {
173  if (featureEdges_)
174  {
175  auto featureEdges = vtkSmartPointer<vtkFeatureEdges>::New();
176  featureEdges->SetInputData(data);
177 
178  addFeatureEdges(renderer, featureEdges);
179  }
180 }
181 
182 
184 (
185  vtkRenderer* renderer,
186  vtkCompositeDataGeometryFilter* input
187 ) const
188 {
189  if (featureEdges_)
190  {
191  auto featureEdges = vtkSmartPointer<vtkFeatureEdges>::New();
192  featureEdges->SetInputConnection(input->GetOutputPort());
193 
194  addFeatureEdges(renderer, featureEdges);
195  }
196 }
197 
198 
199 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
200 
202 (
203  const runTimePostProcessing& parent,
204  const dictionary& dict,
205  const HashPtrTable<Function1<vector>>& colours
206 )
207 :
208  geometryBase(parent, dict, colours),
209  representation_
210  (
211  representationTypeNames.get("representation", dict)
212  ),
213  featureEdges_(dict.getOrDefault("featureEdges", false)),
214  backFaceCulling_(dict.getOrDefault("backFaceCulling", false)),
215  frontFaceCulling_(dict.getOrDefault("frontFaceCulling", true)),
216  surfaceColour_(nullptr),
217  edgeColour_(nullptr),
218  surfaceActor_(),
219  edgeActor_(),
220  maxGlyphLength_(0)
221 {
222  surfaceActor_ = vtkSmartPointer<vtkActor>::New();
223  edgeActor_ = vtkSmartPointer<vtkActor>::New();
224 
225  if (dict.found("surfaceColour"))
226  {
227  surfaceColour_.reset(Function1<vector>::New("surfaceColour", dict));
228  }
229  else
230  {
231  surfaceColour_.reset(colours["surface"]->clone().ptr());
232  }
233 
234  if (dict.found("edgeColour"))
235  {
236  edgeColour_.reset(Function1<vector>::New("edgeColour", dict));
237  }
238  else
239  {
240  edgeColour_.reset(colours["edge"]->clone().ptr());
241  }
242 
243  if (representation_ == rtGlyph)
244  {
245  dict.readEntry("maxGlyphLength", maxGlyphLength_);
246  }
247 }
248 
249 
250 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
251 
254 (
255  const runTimePostProcessing& parent,
256  const dictionary& dict,
257  const HashPtrTable<Function1<vector>>& colours,
258  const word& surfaceType
259 )
260 {
261  DebugInfo << "Selecting surface " << surfaceType << endl;
262 
263  auto cstrIter = dictionaryConstructorTablePtr_->cfind(surfaceType);
264 
265  if (!cstrIter.found())
266  {
268  (
269  dict,
270  "surface",
271  surfaceType,
272  *dictionaryConstructorTablePtr_
273  ) << exit(FatalIOError);
274  }
275 
276  return autoPtr<surface>(cstrIter()(parent, dict, colours));
277 }
278 
279 
280 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
281 
283 {}
284 
285 
286 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
287 
289 (
290  const scalar position
291 )
292 {
293  if (!featureEdges_)
294  {
295  return;
296  }
297 
298  vtkProperty* edgeProp = edgeActor_->GetProperty();
299 
300  edgeProp->SetLineWidth(2);
301  edgeProp->SetOpacity(opacity(position));
302 
303  const vector ec = edgeColour_->value(position);
304  edgeProp->SetColor(ec[0], ec[1], ec[2]);
305  edgeProp->SetEdgeColor(ec[0], ec[1], ec[2]);
306 }
307 
308 
309 // ************************************************************************* //
surface.H
Foam::Enum
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: IOstreamOption.H:51
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
foamVtkTools.H
polySurfaceFields.H
Fields for polySurface.
Foam::functionObjects::runTimePostPro::surface::addFeatureEdges
void addFeatureEdges(vtkRenderer *renderer, vtkFeatureEdges *featureEdges) const
Add feature edges to scene.
Definition: surface.C:136
polySurfacePointFields.H
Point fields for polySurface.
Foam::FatalIOError
IOerror FatalIOError
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
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
FatalIOErrorInLookup
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
Definition: error.H:380
Foam::functionObjects::runTimePostProcessing
Generate images during run-time.
Definition: runTimePostProcessing.H:170
Foam::functionObjects::runTimePostPro::surface::updateActors
virtual void updateActors(const scalar position)
Update the actors.
Definition: surface.C:289
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
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
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
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::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
runTimePostProcessing.H
DebugInfo
#define DebugInfo
Report an information message using Foam::Info.
Definition: messageStream.H:350
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::functionObjects::runTimePostPro::surface::~surface
virtual ~surface()
Destructor.
Definition: surface.C:282
Foam::vtk::Tools::GetCellData
vtkCellData * GetCellData(vtkDataSet *dataset)
Functional call with null-pointer check.
Definition: surface.C:80
Foam::functionObjects::runTimePostPro::defineRunTimeSelectionTable
defineRunTimeSelectionTable(pathline, dictionary)
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::vtk::Tools::GetPointData
vtkPointData * GetPointData(vtkDataSet *dataset)
Functional call with null-pointer check.
Definition: surface.C:86