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 | 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 "surface.H"
28 #include "runTimePostProcessing.H"
29 
30 // VTK includes
31 #include "vtkActor.h"
32 #include "vtkFeatureEdges.h"
33 #include "vtkPolyData.h"
34 #include "vtkPolyDataMapper.h"
35 #include "vtkProperty.h"
36 #include "vtkRenderer.h"
37 #include "vtkSmartPointer.h"
38 
39 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
40 
41 namespace Foam
42 {
43  template<>
45  {
46  "none",
47  "wireframe",
48  "surface",
49  "surfaceWithEdges",
50  "glyph"
51  };
52 
55 }
56 
59 
60 
61 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
62 
63 void Foam::surface::setRepresentation(vtkActor* actor) const
64 {
66 
67  switch (representation_)
68  {
69  case rtNone:
70  {
71  actor->VisibilityOff();
72  break;
73  }
74  case rtWireframe:
75  {
76  // note: colour is set using general SetColour, not setEdgeColor
77  actor->GetProperty()->SetRepresentationToWireframe();
78  break;
79  }
80  case rtGlyph:
81  case rtSurface:
82  {
83  actor->GetProperty()->SetRepresentationToSurface();
84  break;
85  }
86  case rtSurfaceWithEdges:
87  {
88  actor->GetProperty()->SetRepresentationToSurface();
89  actor->GetProperty()->EdgeVisibilityOn();
90  break;
91  }
92  }
93 }
94 
95 
97 (
98  vtkRenderer* renderer,
99  vtkPolyData* data
100 ) const
101 {
102  if (!featureEdges_)
103  {
104  return;
105  }
106 
107  vtkSmartPointer<vtkFeatureEdges> featureEdges =
109  featureEdges->SetInputData(data);
110  featureEdges->BoundaryEdgesOn();
111  featureEdges->FeatureEdgesOn();
112  featureEdges->ManifoldEdgesOff();
113  featureEdges->NonManifoldEdgesOff();
114 // featureEdges->SetFeatureAngle(60);
115  featureEdges->ColoringOff();
116  featureEdges->Update();
117 
118  vtkSmartPointer<vtkPolyDataMapper> mapper =
120  mapper->SetInputConnection(featureEdges->GetOutputPort());
121  mapper->ScalarVisibilityOff();
122 
123  edgeActor_->GetProperty()->SetSpecular(0);
124  edgeActor_->GetProperty()->SetSpecularPower(20);
125  edgeActor_->GetProperty()->SetRepresentationToWireframe();
126  edgeActor_->SetMapper(mapper);
127 
128  renderer->AddActor(edgeActor_);
129 }
130 
131 
132 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
133 
135 (
136  const runTimePostProcessing& parent,
137  const dictionary& dict,
138  const HashPtrTable<DataEntry<vector>, word>& colours
139 )
140 :
141  geometryBase(parent, dict, colours),
142  representation_
143  (
144  representationTypeNames.read(dict.lookup("representation"))
145  ),
146  featureEdges_(false),
147  surfaceColour_(NULL),
148  edgeColour_(NULL),
149  surfaceActor_(),
150  edgeActor_(),
151  maxGlyphLength_(0.0)
152 {
153  surfaceActor_ = vtkSmartPointer<vtkActor>::New();
154  edgeActor_ = vtkSmartPointer<vtkActor>::New();
155 
156  if (dict.found("surfaceColour"))
157  {
158  surfaceColour_.reset
159  (
160  DataEntry<vector>::New("surfaceColour", dict).ptr()
161  );
162  }
163  else
164  {
165  surfaceColour_.reset(colours["surface"]->clone().ptr());
166  }
167 
168  if (dict.found("edgeColour"))
169  {
170  edgeColour_.reset(DataEntry<vector>::New("edgeColour", dict).ptr());
171  }
172  else
173  {
174  edgeColour_.reset(colours["edge"]->clone().ptr());
175  }
176 
177  if (representation_ == rtGlyph)
178  {
179  dict.lookup("maxGlyphLength") >> maxGlyphLength_;
180  }
181  else
182  {
183  dict.lookup("featureEdges") >> featureEdges_;
184  }
185 }
186 
187 
188 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
189 
191 (
192  const runTimePostProcessing& parent,
193  const dictionary& dict,
194  const HashPtrTable<DataEntry<vector>, word>& colours,
195  const word& surfaceType
196 )
197 {
198  if (debug)
199  {
200  Info<< "Selecting surface " << surfaceType << endl;
201  }
202 
203  dictionaryConstructorTable::iterator cstrIter =
204  dictionaryConstructorTablePtr_->find(surfaceType);
205 
206  if (cstrIter == dictionaryConstructorTablePtr_->end())
207  {
209  << "Unknown surface type "
210  << surfaceType << nl << nl
211  << "Valid surface types are:" << endl
212  << dictionaryConstructorTablePtr_->sortedToc()
213  << exit(FatalError);
214  }
215 
216  return autoPtr<surface>(cstrIter()(parent, dict, colours));
217 }
218 
219 
220 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
221 
223 {}
224 
225 
226 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
227 
228 void Foam::surface::updateActors(const scalar position)
229 {
230  if (!featureEdges_)
231  {
232  return;
233  }
234 
235  edgeActor_->GetProperty()->SetLineWidth(2);
236  edgeActor_->GetProperty()->SetOpacity(opacity(position));
237 
238  const vector colour = edgeColour_->value(position);
239  edgeActor_->GetProperty()->SetColor
240  (
241  colour[0],
242  colour[1],
243  colour[2]
244  );
245  edgeActor_->GetProperty()->SetEdgeColor
246  (
247  colour[0],
248  colour[1],
249  colour[2]
250  );
251 }
252 
253 
254 // ************************************************************************* //
Foam::surface::rtGlyph
@ rtGlyph
Definition: surface.H:69
Foam::surface::updateActors
virtual void updateActors(const scalar position)
Update the actors.
Definition: surface.C:228
surface.H
Foam::surface::surface
surface(const surface &)
Disallow default bitwise copy construct.
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::surface::representationTypeNames
static const NamedEnum< representationType, 5 > representationTypeNames
Definition: surface.H:72
Foam::defineRunTimeSelectionTable
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
Foam::dictionary::lookup
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:449
Foam::surface::representation_
representationType representation_
Representation type.
Definition: surface.H:91
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::geometryBase
Definition: geometryBase.H:56
Foam::surface::~surface
virtual ~surface()
Destructor.
Definition: surface.C:222
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::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::surface::New
static autoPtr< surface > New(const runTimePostProcessing &parent, const dictionary &dict, const HashPtrTable< DataEntry< vector >, word > &colours, const word &surfaceName)
Return a reference to the selected RAS model.
Definition: surface.C:191
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::surface::rtSurfaceWithEdges
@ rtSurfaceWithEdges
Definition: surface.H:68
Foam::surface::rtSurface
@ rtSurface
Definition: surface.H:67
Foam::autoPtr
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
Foam::surface::setRepresentation
void setRepresentation(vtkActor *actor) const
Set the representation.
Definition: surface.C:63
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
runTimePostProcessing.H
Foam::HashPtrTable
A HashTable specialization for hashing pointers.
Definition: HashPtrTable.H:50
Foam::Vector< scalar >
Foam::surface::rtWireframe
@ rtWireframe
Definition: surface.H:66
Foam::surface
Definition: surface.H:55
Foam::surface::addFeatureEdges
void addFeatureEdges(vtkRenderer *renderer, vtkPolyData *data) const
Add feature edges to scene.
Definition: surface.C:97
Foam::surface::rtNone
@ rtNone
Definition: surface.H:65
Foam::geometryBase::initialiseActor
void initialiseActor(vtkActor *actor) const
Initialse actor.
Definition: geometryBase.C:52
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)
Foam::data
Database for solution data, solver performance and other reduced data.
Definition: data.H:52
Foam::NamedEnum
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:52