geometrySurface.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 "geometrySurface.H"
28 #include "stringOps.H"
29 #include "triSurface.H"
30 #include "runTimePostProcessing.H"
32 
33 // VTK includes
34 #include "vtkActor.h"
35 #include "vtkCellArray.h"
36 #include "vtkCellData.h"
37 #include "vtkDoubleArray.h"
38 #include "vtkPointData.h"
39 #include "vtkPoints.h"
40 #include "vtkPolyData.h"
41 #include "vtkPolyDataMapper.h"
42 #include "vtkProperty.h"
43 #include "vtkRenderer.h"
44 #include "vtkSmartPointer.h"
45 #include "vtkTriangle.h"
46 
47 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
48 
49 namespace Foam
50 {
51  defineTypeNameAndDebug(geometrySurface, 0);
52  addToRunTimeSelectionTable(surface, geometrySurface, dictionary);
53 }
54 
55 
56 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
57 
59 (
60  const scalar position,
61  vtkRenderer* renderer,
62  const fileName& fName
63 ) const
64 {
65  if (representation_ == rtGlyph)
66  {
68  << "Glyph representation not available for " << typeName
69  << "object" << exit(FatalError);
70  }
71 
72  triSurface surf(fName);
73 
74  const Field<point>& surfPoints = surf.points();
75  const Field<vector>& surfFaceNormals = surf.faceNormals();
76 
77  vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
78  vtkSmartPointer<vtkCellArray> triangles =
80  vtkSmartPointer<vtkDoubleArray> faceNormals =
82 
83  faceNormals->SetNumberOfComponents(3);
84 
85  forAll(surfPoints, i)
86  {
87  const point& pt = surfPoints[i];
88  points->InsertNextPoint(pt.x(), pt.y(), pt.z());
89  }
90 
91  forAll(surf, i)
92  {
93  const Foam::face& f = surf[i];
94 
95  vtkSmartPointer<vtkTriangle> triangle =
97  triangle->GetPointIds()->SetId(0, f[0]);
98  triangle->GetPointIds()->SetId(1, f[1]);
99  triangle->GetPointIds()->SetId(2, f[2]);
100  triangles->InsertNextCell(triangle);
101 
102  double n[3];
103  n[0] = surfFaceNormals[i].x();
104  n[1] = surfFaceNormals[i].y();
105  n[2] = surfFaceNormals[i].z();
106 
107  faceNormals->InsertNextTuple(n);
108  }
109 
110  surf.clearOut();
111 
112  vtkSmartPointer<vtkPolyData> polyData =
114  polyData->SetPoints(points);
115  polyData->SetPolys(triangles);
116  polyData->GetCellData()->SetNormals(faceNormals);
117 
118  vtkSmartPointer<vtkPolyDataMapper> mapper =
120  mapper->ScalarVisibilityOff();
121  mapper->SetInputData(polyData);
122 
123  addFeatureEdges(renderer, polyData);
124 
125  surfaceActor_->SetMapper(mapper);
126 
127  setRepresentation(surfaceActor_);
128 
129  renderer->AddActor(surfaceActor_);
130 }
131 
132 
133 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
134 
136 (
137  const runTimePostProcessing& parent,
138  const dictionary& dict,
139  const HashPtrTable<DataEntry<vector>, word>& colours
140 )
141 :
142  surface(parent, dict, colours),
143  fileNames_(dict.lookup("files"))
144 {}
145 
146 
148 (
149  const runTimePostProcessing& parent,
150  const dictionary& dict,
151  const HashPtrTable<DataEntry<vector>, word>& colours,
152  const List<fileName>& fileNames
153 )
154 :
155  surface(parent, dict, colours),
156  fileNames_(fileNames)
157 {}
158 
159 
160 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
161 
163 {}
164 
165 
166 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
167 
169 (
170  const scalar position,
171  vtkRenderer* renderer
172 )
173 {
174  if (!visible_)
175  {
176  return;
177  }
178 
179  forAll(fileNames_, i)
180  {
181  fileName fName = fileNames_[i].expand();
182  addGeometryToScene(position, renderer, fName);
183  }
184 }
185 
186 
187 void Foam::geometrySurface::updateActors(const scalar position)
188 {
189  if (!visible_)
190  {
191  return;
192  }
193 
194  surface::updateActors(position);
195 
196  surfaceActor_->GetProperty()->SetOpacity(opacity(position));
197 
198  vector sc = surfaceColour_->value(position);
199  surfaceActor_->GetProperty()->SetColor(sc[0], sc[1], sc[2]);
200 
201  vector ec = edgeColour_->value(position);
202  surfaceActor_->GetProperty()->SetEdgeColor(ec[0], ec[1], ec[2]);
203 }
204 
205 
206 // ************************************************************************* //
Foam::surface::updateActors
virtual void updateActors(const scalar position)
Update the actors.
Definition: surface.C:228
Foam::PrimitivePatch::points
const Field< PointType > & points() const
Return reference to global points.
Definition: PrimitivePatchTemplate.H:282
Foam::triSurface::clearOut
void clearOut()
Clear all data.
Definition: triSurface.C:757
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::fileName
A class for handling file names.
Definition: fileName.H:69
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
Foam::geometrySurface::addGeometryToScene
void addGeometryToScene(const scalar position, vtkRenderer *renderer, const fileName &fName) const
Add surface (file) to scene.
Definition: geometrySurface.C:59
Foam::runTimePostProcessing
Function object to generate images during run-time.
Definition: runTimePostProcessing.H:83
Foam::triangle
A triangle primitive used to calculate face normals and swept volumes.
Definition: triangle.H:59
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::Field< point >
Foam::triSurface
Triangulated surface description with patch information.
Definition: triSurface.H:57
Foam::geometrySurface::~geometrySurface
virtual ~geometrySurface()
Destructor.
Definition: geometrySurface.C:162
Foam::geometrySurface::geometrySurface
geometrySurface(const geometrySurface &)
Disallow default bitwise copy construct.
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::Vector::x
const Cmpt & x() const
Definition: VectorI.H:65
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
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::Vector::z
const Cmpt & z() const
Definition: VectorI.H:77
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
runTimePostProcessing.H
Foam::PrimitivePatch::faceNormals
const Field< PointType > & faceNormals() const
Return face normals for patch.
Definition: PrimitivePatchTemplate.C:520
Foam::HashPtrTable
A HashTable specialization for hashing pointers.
Definition: HashPtrTable.H:50
f
labelList f(nPoints)
Foam::Vector< scalar >
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::string::expand
string & expand(const bool allowEmpty=false)
Expand initial tildes and all occurences of environment variables.
Definition: string.C:98
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::surface
Definition: surface.H:55
Foam::geometrySurface::updateActors
virtual void updateActors(const scalar position)
Update actors.
Definition: geometrySurface.C:187
Foam::Vector::y
const Cmpt & y() const
Definition: VectorI.H:71
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
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
stringOps.H
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
geometrySurface.H