gltfCoordSetWriter.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-2022 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
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
26Class
27 Foam::coordSetWriters::gltfWriter
28
29Description
30 A coordSet(s) writer in glTF v2 format, which is particularly
31 useful for writing track data.
32
33 Two files are generated:
34 - filename.bin : a binary file containing all scene entities
35 - filename.gltf : a JSON file that ties fields to the binary data
36
37 The output can contain both geometry and fields, with additional support
38 for colours using a user-supplied colour map, and animation of particle
39 tracks.
40
41 Controls are provided via the optional formatOptions dictionary.
42
43 For non-particle track data:
44
45 \verbatim
46 formatOptions
47 {
48 // Apply colours flag (yes | no ) [optional]
49 colours yes;
50
51 // List of options per field
52 fieldInfo
53 {
54 p
55 {
56 // Colour map [optional]
57 colourMap <colourMap>;
58
59 // Colour map minimum and maximum limits [optional]
60 // Uses field min and max if not specified
61 min 0;
62 max 1;
63
64 // Alpha channel [optional] (<scalar>)
65 alpha 0.5;
66 }
67 }
68 }
69 \verbatim
70
71 For particle tracks:
72
73 \verbatim
74 formatOptions
75 {
76 // Apply colours flag (yes | no) [optional]
77 colours yes;
78
79 // Animate tracks (yes | no) [optional]
80 animate yes;
81
82 // Animation properties [optional]
83 animationInfo
84 {
85 // Colour map [optional]
86 colourMap <colourMap>;
87
88 // Colour [optional] (<vector> | uniform | field)
89 colour (1 0 0); // RGB in range [0-1]
90
91 //colour uniform;
92 //colourValue (1 0 0); // RGB in range [0-1]
93
94 //colour field;
95 //colourField d;
96
97 // Colour map minimum and maximum limits [optional]
98 // Note: for colour = field option
99 // Uses field min and max if not specified
100 min 0;
101 max 1;
102
103 // Alpha channel [optional] (<scalar>)
104 alpha 0.5;
105 }
106 }
107 \endverbatim
108
109Note
110 When writing particle animations, the particle field and colour properties
111 correspond to initial particle state (first data point) and cannot be
112 animated (limitation of the file format).
113
114 For more information on the specification see
115 https://www.khronos.org/registry/glTF/
116
117SourceFiles
118 gltfCoordSetWriter.C
119
120\*---------------------------------------------------------------------------*/
121
122#ifndef Foam_coordSetWriters_gltfWriter_H
123#define Foam_coordSetWriters_gltfWriter_H
124
125#include "coordSetWriter.H"
126#include "colourTable.H"
127#include "foamGltfFwd.H"
128#include "MinMax.H"
129
130// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
131
132namespace Foam
133{
134namespace coordSetWriters
135{
136
137/*---------------------------------------------------------------------------*\
138 Class gltfWriter Declaration
139\*---------------------------------------------------------------------------*/
141class gltfWriter
142:
143 public coordSetWriter
144{
145public:
146
147 // Enumerations
148
149 //- Field option used for colours
150 enum class fieldOption : char
151 {
152 NONE,
153 UNIFORM,
154 FIELD
155 };
156
157
158 //- Strings corresponding to the field options
160
161
162private:
163
164 // Private Data
165
166 //- Backend output
168
169 //- Flag to animate - for particle tracks only
170 bool animate_;
171
172 //- Flag to add field colours
173 bool colour_;
174
175 //- Animation colour option
176 fieldOption animateColourOption_;
177
178 //- Animation colour field name
179 word animateColourName_;
180
181 //- Animation colour value
182 vector animateColourValue_;
183
184 //- Local field information
185 const dictionary fieldInfoDict_;
186
187 //- Animation information
188 const dictionary animationDict_;
189
190 //- The mesh indices in glTF scene
191 labelList meshes_;
192
193
194 // Private Member Functions
195
196 //- Return the colour map name
197 word getColourMap(const dictionary& dict) const;
198
199 //- Return the colour table corresponding to the colour map
200 const colourTable& getColourTable(const dictionary& dict) const;
201
202 //- Return the named min/max field limits (from sub-dictionary)
203 scalarMinMax getFieldLimits(const word& fieldName) const;
204
205 //- Setup animation colour or field to search for
206 void setupAnimationColour();
207
208 //- Return the alpha field for mesh values
209 tmp<scalarField> getAlphaField(const dictionary& dict) const;
210
211
212 //- Templated write operation (static tracks)
213 template<class Type>
214 fileName writeTemplate
215 (
216 const word& fieldName,
217 const UPtrList<const Field<Type>>& fieldPtrs
218 );
219
220 //- Write animated tracks
221 template<class Type>
222 fileName writeTemplate_animate
223 (
224 const word& fieldName,
225 const UPtrList<const Field<Type>>& fieldPtrs
226 );
227
228 //- Templated write operation
229 template<class Type>
230 fileName writeTemplate
231 (
232 const word& fieldName,
233 const Field<Type>& vals
234 );
235
236 //- Templated write operation
237 template<class Type>
238 fileName writeTemplate
239 (
240 const word& fieldName,
241 const List<Field<Type>>& fieldValues
242 );
243
244
245public:
246
247 //- Runtime type information (no debug)
248 TypeNameNoDebug("gltf");
249
250
251 // Constructors
252
253 //- Default construct
254 gltfWriter();
255
256 //- Default construct with specified options
257 explicit gltfWriter(const dictionary& options);
258
259 //- Construct from components
261 (
262 const coordSet& coords,
263 const fileName& outputPath,
264 const dictionary& options = dictionary()
265 );
266
267 //- Construct from components
269 (
270 const UPtrList<coordSet>& tracks,
271 const fileName& outputPath,
272 const dictionary& options = dictionary()
273 );
274
275
276 //- Destructor. Calls close()
277 virtual ~gltfWriter();
278
279
280 // Member Functions
281
282 //- Expected (characteristic) output file name - information only
283 virtual fileName path() const; // override
284
285 //- Close and reset, clears backend.
286 virtual void close(bool force = false); // override
287
288 //- Begin time step. Clears existing backend.
289 virtual void beginTime(const Time& t); // override
290
291 //- Begin time step. Clears existing backend.
292 virtual void beginTime(const instant& inst); // override
293
294 //- End time step. Clears existing backend.
295 virtual void endTime(); // override
296
297
298 // Write
306};
307
308
309// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
310
311} // End namespace coordSetWriters
312} // End namespace Foam
313
314// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
315
316#endif
317
318// ************************************************************************* //
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: Enum.H:61
Generic templated field type.
Definition: Field.H:82
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:80
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
Definition: UPtrList.H:71
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
Base class for generating a colour table from node points.
Definition: colourTable.H:80
Base class for writing coordSet(s) and tracks with fields.
A coordSet(s) writer in glTF v2 format, which is particularly useful for writing track data.
fieldOption
Field option used for colours.
virtual void endTime()
End time step. Clears existing backend.
virtual void beginTime(const Time &t)
Begin time step. Clears existing backend.
declareCoordSetWriterWriteMethod(sphericalTensor)
static const Enum< fieldOption > fieldOptionNames_
Strings corresponding to the field options.
virtual fileName path() const
Expected (characteristic) output file name - information only.
virtual ~gltfWriter()
Destructor. Calls close()
TypeNameNoDebug("gltf")
Runtime type information (no debug)
virtual void close(bool force=false)
Close and reset, clears backend.
Holds list of sampling positions.
Definition: coordSet.H:56
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
A class for handling file names.
Definition: fileName.H:76
An instant of time. Contains the time value and name. Uses Foam::Time when formatting the name.
Definition: instant.H:56
A class for managing temporary objects.
Definition: tmp.H:65
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define declareCoordSetWriterWriteMethod(Type)
Forward declarations for exposed glTF interfaces.
Namespace for OpenFOAM.
dictionary dict
#define TypeNameNoDebug(TypeNameString)
Declare a ClassNameNoDebug() with extra virtual type info.
Definition: typeInfo.H:68