text.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 |
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 "text.H"
28 #include "runTimePostProcessing.H"
29 
30 // VTK includes
31 #include "vtkRenderer.h"
32 #include "vtkSmartPointer.h"
33 #include "vtkTextActor.h"
34 #include "vtkTextProperty.h"
35 
36 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
37 
39 (
40  const runTimePostProcessing& parent,
41  const dictionary& dict,
42  const HashPtrTable<DataEntry<vector>, word>& colours
43 )
44 :
45  geometryBase(parent, dict, colours),
46  string_(dict.lookup("string")),
47  position_(dict.lookup("position")),
48  size_(readScalar(dict.lookup("size"))),
49  colour_(NULL),
50  bold_(readBool(dict.lookup("bold")))
51 {
52  if (dict.found("colour"))
53  {
54  colour_.reset(DataEntry<vector>::New("colour", dict).ptr());
55  }
56  else
57  {
58  colour_.reset(colours["text"]->clone().ptr());
59  }
60 }
61 
62 
63 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
64 
66 {}
67 
68 
69 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
70 
72 (
73  const scalar position,
74  vtkRenderer* renderer
75 )
76 {
77  if (!visible_)
78  {
79  return;
80  }
81 
82  vtkSmartPointer<vtkTextActor> actor = vtkSmartPointer<vtkTextActor>::New();
83 
84  actor->SetInput(string_.c_str());
85  actor->GetTextProperty()->SetFontFamilyToArial();
86  actor->GetTextProperty()->SetFontSize(size_);
87  actor->GetTextProperty()->SetJustificationToLeft();
88  actor->GetTextProperty()->SetVerticalJustificationToBottom();
89  actor->GetTextProperty()->SetBold(bold_);
90 
91  const vector colour = colour_->value(position);
92  actor->GetTextProperty()->SetColor(colour[0], colour[1], colour[2]);
93  actor->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
94  actor->GetPositionCoordinate()->SetValue
95  (
96  position_.first(),
97  position_.second()
98  );
99 
100  renderer->AddActor2D(actor);
101 }
102 
103 
104 void Foam::text::updateActors(const scalar position)
105 {
106  // do nothing - all handled by addGeometryToScene
107 }
108 
109 
110 // ************************************************************************* //
Foam::text::~text
virtual ~text()
Destructor.
Definition: text.C:65
Foam::text::updateActors
virtual void updateActors(const scalar position)
Update actors.
Definition: text.C:104
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::geometryBase
Definition: geometryBase.H:56
Foam::runTimePostProcessing
Function object to generate images during run-time.
Definition: runTimePostProcessing.H:83
text.H
Foam::text::addGeometryToScene
virtual void addGeometryToScene(const scalar position, vtkRenderer *renderer)
Add surface(s) to scene.
Definition: text.C:72
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
readScalar
#define readScalar
Definition: doubleScalar.C:38
runTimePostProcessing.H
Foam::HashPtrTable
A HashTable specialization for hashing pointers.
Definition: HashPtrTable.H:50
Foam::Vector< scalar >
Foam::text::text
text(const text &)
Disallow default bitwise copy construct.
Foam::readBool
bool readBool(Istream &)
Definition: boolIO.C:60
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