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