gltfSetWriter.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) 2021 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::gltfSetWriter
28 
29 Description
30  Writes point data in glTF v2 format
31 
32  Two files are generated:
33  - filename.bin : a binary file containing all scene entities
34  - filename.gltf : a JSON file that ties fields to the binary data
35 
36  The output can contain both geometry and fields, with additional support
37  for colours using a user-supplied colour map, and animation of particle
38  tracks.
39 
40  Controls are provided via the optional formatOptions dictionary.
41 
42  For non-particle track data:
43 
44  \verbatim
45  formatOptions
46  {
47  // Apply colours flag (yes | no ) [optional]
48  colours yes;
49 
50  // List of options per field
51  fieldInfo
52  {
53  p
54  {
55  // Colour map [optional]
56  colourMap <colourMap>;
57 
58  // Colour map minimum and maximum limits [optional]
59  // Uses field min and max if not specified
60  min 0;
61  max 1;
62 
63  // Alpha channel [optional] (uniform | field)
64  alpha uniform;
65  alphaValue 0.5;
66 
67  //alpha field;
68  //alphaField T;
69  //normalise yes;
70  }
71  }
72  }
73  \verbatim
74 
75  For particle tracks:
76 
77  \verbatim
78  formatOptions
79  {
80  // Apply colours flag (yes | no) [optional]
81  colours yes;
82 
83  // Animate tracks (yes | no) [optional]
84  animate yes;
85 
86  // Animation properties [optional]
87  animationInfo
88  {
89  // Colour map [optional]
90  colourMap <colourMap>;
91 
92  // Colour [optional] (uniform | field)
93  colour uniform;
94  colourValue (1 0 0); // RGB in range [0-1]
95 
96  //colour field;
97  //colourField d;
98 
99  // Colour map minimum and maximum limits [optional]
100  // Note: for colour = field option
101  // Uses field min and max if not specified
102  min 0;
103  max 1;
104 
105  // Alpha channel [optional] (uniform | field)
106  alpha uniform;
107  alphaValue 0.5;
108 
109  //alpha field;
110  //alphaField T;
111  //normalise yes;
112  }
113  }
114  \endverbatim
115 
116 Note
117  When writing particle animations, the particle field and colour properties
118  correspond to initial particle state (first data point) and cannot be
119  animated (limitation of the file format).
120 
121  For more information on the specification see
122  https://www.khronos.org/registry/glTF/
123 
124 SourceFiles
125  gltfSetWriter.C
126 
127 \*---------------------------------------------------------------------------*/
128 
129 #ifndef writers_gltfSetWriter_H
130 #define writers_gltfSetWriter_H
131 
132 #include "writer.H"
133 #include "colourTable.H"
134 
135 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
136 
137 namespace Foam
138 {
139 
140 /*---------------------------------------------------------------------------*\
141  Class gltfSetWriter Declaration
142 \*---------------------------------------------------------------------------*/
143 
144 template<class Type>
145 class gltfSetWriter
146 :
147  public writer<Type>
148 {
149 public:
150 
151  // Enumerations
152 
153  //- Field option used for colours
154  enum class fieldOption
155  {
156  UNIFORM,
157  FIELD
158  };
159 
160 
161  //- Strings corresponding to the field options
163 
164 
165 private:
166 
167  // Private Data
168 
169  //- Flag to animate - for particle tracks only
170  bool animate_;
171 
172  //- Flag to add field colours
173  bool colour_;
174 
175  //- Local field information
176  const dictionary fieldInfoDict_;
177 
178  //- Animation information
179  const dictionary animationDict_;
180 
181 
182  // Private Member Functions
183 
184  //- Return the colour map name
185  word getColourMap(const dictionary& dict) const;
186 
187  //- Return the colour table corresponding to the colour map
188  const colourTable& getColourTable(const dictionary& dict) const;
189 
190  //- Return the field minimum value
191  scalar getFieldMin(const word& fieldName) const;
192 
193  //- Return the field maximum value
194  scalar getFieldMax(const word& fieldName) const;
195 
196  //- Return the alpha field for mesh values
197  tmp<scalarField> getAlphaField
198  (
199  const dictionary& dict,
200  const wordList& valueSetNames,
201  const List<const Field<Type>*>& valueSets
202  ) const;
203 
204  //- Return the alpha field for tracks
205  tmp<scalarField> getTrackAlphaField
206  (
207  const dictionary& dict,
208  const wordList& valueSetNames,
209  const List<List<Field<Type>>>& valueSets,
210  const label tracki
211  ) const;
212 
213  //- Return the animation colour when animating tracks
214  vector getTrackAnimationColour
215  (
216  const colourTable& colours,
217  const wordList& valueSetNames,
218  const List<List<Field<Type>>>& valueSets,
219  const label tracki
220  ) const;
221 
222  //- Return track orientation/dirrections
224 
225 
226 public:
227 
228  //- Runtime type information
229  TypeName("gltf");
230 
231 
232  // Constructors
233 
234  //- Default construct
235  gltfSetWriter();
236 
237  //- Construct from dictionary
238  explicit gltfSetWriter(const dictionary& dict);
239 
240 
241  //- Destructor
242  virtual ~gltfSetWriter() = default;
243 
244 
245  // Member Functions
246 
247  //- Return the file name
248  virtual fileName getFileName
249  (
250  const coordSet&,
251  const wordList&
252  ) const;
253 
254  //- Write
255  virtual void write
256  (
257  const coordSet&,
258  const wordList&,
259  const List<const Field<Type>*>&,
260  Ostream&
261  ) const;
262 
263  //- Write tracks (main entry point)
264  virtual void write
265  (
266  const bool writeTracks,
267  const List<scalarField>& times,
268  const PtrList<coordSet>&,
269  const wordList& valueSetNames,
270  const List<List<Field<Type>>>&,
271  Ostream&
272  ) const;
273 
274  //- Write animated tracks
275  virtual void writeAnimateTracks
276  (
277  const bool writeTracks,
278  const List<scalarField>& times,
279  const PtrList<coordSet>& tracks,
280  const wordList& valueSetNames,
281  const List<List<Field<Type>>>& valueSets,
282  Ostream&
283  ) const;
284 
285  //- Write static tracks
286  virtual void writeStaticTracks
287  (
288  const bool writeTracks,
289  const List<scalarField>& times,
290  const PtrList<coordSet>& tracks,
291  const wordList& valueSetNames,
292  const List<List<Field<Type>>>& valueSets,
293  Ostream&
294  ) const;
295 };
296 
297 
298 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
299 
300 } // End namespace Foam
301 
302 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
303 
304 #ifdef NoRepository
305  #include "gltfSetWriter.C"
306 #endif
307 
308 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
309 
310 #endif
311 
312 // ************************************************************************* //
Foam::Enum< fieldOption >
Foam::gltfSetWriter::fieldOption::FIELD
field value
Foam::gltfSetWriter::gltfSetWriter
gltfSetWriter()
Default construct.
Definition: gltfSetWriter.C:290
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::gltfSetWriter::TypeName
TypeName("gltf")
Runtime type information.
Foam::gltfSetWriter::fieldOptionNames_
static const Enum< fieldOption > fieldOptionNames_
Strings corresponding to the field options.
Definition: gltfSetWriter.H:161
Foam::gltfSetWriter::getFileName
virtual fileName getFileName(const coordSet &, const wordList &) const
Return the file name.
Definition: gltfSetWriter.C:327
Foam::directions
Set of directions for each cell in the mesh. Either uniform and size=1 or one set of directions per c...
Definition: directions.H:67
Foam::gltfSetWriter
Writes point data in glTF v2 format.
Definition: gltfSetWriter.H:144
Foam::gltfSetWriter::fieldOption::UNIFORM
Uniform value.
Foam::gltfSetWriter::writeStaticTracks
virtual void writeStaticTracks(const bool writeTracks, const List< scalarField > &times, const PtrList< coordSet > &tracks, const wordList &valueSetNames, const List< List< Field< Type >>> &valueSets, Ostream &) const
Write static tracks.
Definition: gltfSetWriter.C:458
Foam::Field
Generic templated field type.
Definition: Field.H:63
Foam::gltfSetWriter::~gltfSetWriter
virtual ~gltfSetWriter()=default
Destructor.
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:59
colourTable.H
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:123
Foam::writer
Base class for graphics format writing. Entry points are.
Definition: writer.H:81
Foam::coordSet
Holds list of sampling positions.
Definition: coordSet.H:53
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::gltfSetWriter::writeAnimateTracks
virtual void writeAnimateTracks(const bool writeTracks, const List< scalarField > &times, const PtrList< coordSet > &tracks, const wordList &valueSetNames, const List< List< Field< Type >>> &valueSets, Ostream &) const
Write animated tracks.
Definition: gltfSetWriter.C:540
Foam::Vector< scalar >
Foam::List< word >
Foam::gltfSetWriter::fieldOption
fieldOption
Field option used for colours.
Definition: gltfSetWriter.H:153
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::colourTable
Base class for generating a colour table from node points.
Definition: colourTable.H:79
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::gltfSetWriter::write
virtual void write(const coordSet &, const wordList &, const List< const Field< Type > * > &, Ostream &) const
Write.
Definition: gltfSetWriter.C:338
writer.H
gltfSetWriter.C