gltfWriter Class Reference

A coordSet(s) writer in glTF v2 format, which is particularly useful for writing track data. More...

Inheritance diagram for gltfWriter:
[legend]
Collaboration diagram for gltfWriter:
[legend]

Public Types

enum class  fieldOption : char { NONE , UNIFORM , FIELD }
 Field option used for colours. More...
 

Public Member Functions

 TypeNameNoDebug ("gltf")
 Runtime type information (no debug) More...
 
 gltfWriter ()
 Default construct. More...
 
 gltfWriter (const dictionary &options)
 Default construct with specified options. More...
 
 gltfWriter (const coordSet &coords, const fileName &outputPath, const dictionary &options=dictionary())
 Construct from components. More...
 
 gltfWriter (const UPtrList< coordSet > &tracks, const fileName &outputPath, const dictionary &options=dictionary())
 Construct from components. More...
 
virtual ~gltfWriter ()
 Destructor. Calls close() More...
 
virtual fileName path () const
 Expected (characteristic) output file name - information only. More...
 
virtual void close (bool force=false)
 Close and reset, clears backend. More...
 
virtual void beginTime (const Time &t)
 Begin time step. Clears existing backend. More...
 
virtual void beginTime (const instant &inst)
 Begin time step. Clears existing backend. More...
 
virtual void endTime ()
 End time step. Clears existing backend. More...
 
 declareCoordSetWriterWriteMethod (label)
 
 declareCoordSetWriterWriteMethod (scalar)
 
 declareCoordSetWriterWriteMethod (vector)
 
 declareCoordSetWriterWriteMethod (sphericalTensor)
 
 declareCoordSetWriterWriteMethod (symmTensor)
 
 declareCoordSetWriterWriteMethod (tensor)
 
template<class Type >
Foam::fileName writeTemplate (const word &fieldName, const UPtrList< const Field< Type > > &fieldPtrs)
 
template<class Type >
Foam::fileName writeTemplate_animate (const word &fieldName, const UPtrList< const Field< Type > > &fieldPtrs)
 
template<class Type >
Foam::fileName writeTemplate (const word &fieldName, const Field< Type > &values)
 
template<class Type >
Foam::fileName writeTemplate (const word &fieldName, const List< Field< Type > > &fieldValues)
 
- Public Member Functions inherited from coordSetWriter
 TypeName ("coordSetWriter")
 Runtime type information. More...
 
 declareRunTimeSelectionTable (autoPtr, coordSetWriter, word,(),())
 
 declareRunTimeSelectionTable (autoPtr, coordSetWriter, wordDict,(const dictionary &writeOptions),(writeOptions))
 
 coordSetWriter ()
 Default construct. More...
 
 coordSetWriter (const dictionary &options)
 Default construct with specified options. More...
 
virtual ~coordSetWriter ()
 Destructor. Calls close() More...
 
virtual bool buffering () const
 True if the format uses internal buffering (eg, column output) More...
 
virtual bool buffering (const bool on)
 Turn internal buffering on/off (only if supported by the writer) More...
 
virtual bool enabled () const
 
virtual bool needsUpdate () const
 Does the writer need an update (eg, lagging behind other changes) More...
 
virtual bool wroteData () const
 Geometry or fields written since the last open? More...
 
virtual bool expire ()
 
virtual void clear ()
 
virtual void setCoordinates (const coordSet *coords)
 Set coordinates, can also be nullptr. More...
 
virtual void setCoordinates (const coordSet &coords)
 Set coordinates. More...
 
virtual void setTracks (const UPtrList< coordSet > &tracks)
 Set track coordinates. More...
 
virtual void setTrackTimes (const UList< scalarField > &times)
 Set track times. More...
 
label numPoints () const
 The number of associated points (local processor) More...
 
label numTracks () const
 The number of coordinate tracks. More...
 
bool hasCoords () const
 Writer is associated with content. More...
 
bool empty () const
 Writer is not associated with content. More...
 
bool is_open () const noexcept
 Test if outputPath has been set. More...
 
label nFields () const noexcept
 The number of expected output fields. More...
 
label nFields (const label n) noexcept
 Set the number of expected output fields. More...
 
bool useTracks () const noexcept
 Prefer tracks to points during single set writing. More...
 
bool useTracks (const bool on) noexcept
 Enable/disable tracks preference. More...
 
bool useTimeDir () const noexcept
 Should a time directory be spliced into the output path? More...
 
bool useTimeDir (const bool on) noexcept
 Enable/disable use of spliced output path. More...
 
bool verbose () const noexcept
 Get output verbosity. More...
 
bool verbose (bool on) noexcept
 Enable/disable verbose output. More...
 
bool hasTime () const
 True if there is a known time. More...
 
const wordtimeName () const
 The current time value/name. More...
 
scalar timeValue () const
 The current time value/name. More...
 
void setTime (const instant &inst)
 Set the current time. More...
 
void setTime (scalar timeValue)
 Set current time from timeValue, auto generating the name. More...
 
void setTime (scalar timeValue, const word &timeName)
 Set current time from timeValue and timeName. More...
 
void unsetTime ()
 Clear the current time. More...
 
virtual void beginTime (const Time &t)
 Begin a time-step. More...
 
virtual void beginTime (const instant &inst)
 Begin a time-step. More...
 
virtual void endTime ()
 End a time-step. More...
 
virtual fileName path () const =0
 
virtual void open (const fileName &outputPath)
 Write separate geometry to file. More...
 
virtual void open (const coordSet &coords, const fileName &outputPath)
 Open from components. More...
 
virtual void open (const UPtrList< coordSet > &tracks, const fileName &outputPath)
 Open from components. More...
 
virtual void close (bool force=false)
 Finish output, performing any necessary cleanup. More...
 
virtual InfoProxy< coordSetWriterinfo () const
 Return info proxy. More...
 
virtual fileName write (const word &fieldName, const Field< label > &field)=0
 Write field of label (point data) More...
 
virtual fileName write (const word &fieldName, const List< Field< label > > &fieldValues)=0
 Write track fields of label (point data) More...
 
virtual fileName write (const word &fieldName, const Field< scalar > &field)=0
 Write field of scalar (point data) More...
 
virtual fileName write (const word &fieldName, const List< Field< scalar > > &fieldValues)=0
 Write track fields of scalar (point data) More...
 
virtual fileName write (const word &fieldName, const Field< vector > &field)=0
 Write field of vector (point data) More...
 
virtual fileName write (const word &fieldName, const List< Field< vector > > &fieldValues)=0
 Write track fields of vector (point data) More...
 
virtual fileName write (const word &fieldName, const Field< sphericalTensor > &field)=0
 Write field of sphericalTensor (point data) More...
 
virtual fileName write (const word &fieldName, const List< Field< sphericalTensor > > &fieldValues)=0
 Write track fields of sphericalTensor (point data) More...
 
virtual fileName write (const word &fieldName, const Field< symmTensor > &field)=0
 Write field of symmTensor (point data) More...
 
virtual fileName write (const word &fieldName, const List< Field< symmTensor > > &fieldValues)=0
 Write track fields of symmTensor (point data) More...
 
virtual fileName write (const word &fieldName, const Field< tensor > &field)=0
 Write field of tensor (point data) More...
 
virtual fileName write (const word &fieldName, const List< Field< tensor > > &fieldValues)=0
 Write track fields of tensor (point data) More...
 
template<class Type >
Foam::UPtrList< const Foam::Field< Type > > repackageFields (const Field< Type > &field)
 
template<class Type >
Foam::UPtrList< const Foam::Field< Type > > repackageFields (const UList< Field< Type > > &fieldValues)
 

Static Public Attributes

static const Enum< fieldOptionfieldOptionNames_
 Strings corresponding to the field options. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from coordSetWriter
static bool supportedType (const word &writeType)
 True if New is likely to succeed for this writeType. More...
 
static autoPtr< coordSetWriterNew (const word &writeFormat)
 Return a reference to the selected writer. More...
 
static autoPtr< coordSetWriterNew (const word &writeFormat, const dictionary &writeOptions)
 Return a reference to the selected writer. More...
 
static word suffix (const word &fldName, const word &fileExt=word::null)
 Name suffix based on fieldName (underscore separator) More...
 
static word suffix (const wordList &fieldNames, const word &fileExt=word::null)
 Name suffix based on fieldNames (underscore separator) More...
 
- Protected Member Functions inherited from coordSetWriter
void appendField (const word &fieldName, const Field< label > &vals)
 
void appendField (const word &fieldName, const Field< scalar > &vals)
 
void appendField (const word &fieldName, const Field< vector > &vals)
 
void appendField (const word &fieldName, const Field< sphericalTensor > &vals)
 
void appendField (const word &fieldName, const Field< symmTensor > &vals)
 
void appendField (const word &fieldName, const Field< tensor > &vals)
 
void clearBuffers ()
 Clear out buffering. More...
 
label nDataColumns () const
 The number of buffer data columns, after splitting into components. More...
 
virtual bool writeBuffered ()
 Write buffered data. More...
 
void writeBufferContents (Ostream &os, const coordSet &coords, const char *sep) const
 Write buffered data. More...
 
void getBufferLine (DynamicList< scalar > &buf, const coordSet &coords, const label pointi) const
 Get buffered data line (components) More...
 
fileName getExpectedPath (const word &fileExt=word::null) const
 Get expected (characteristic) output file name - information only. More...
 
fileName getFieldPrefixedPath (const word &fieldName, const word &fileExt=word::null) const
 Get field-prefixed output file name. More...
 
void checkOpen () const
 Verify that the outputPath_ has been set or FatalError. More...
 
virtual bool merge () const
 
template<class Type >
fileName writeTemplate (const word &fieldName, const Field< Type > &values)
 Dummy templated write operation. More...
 
template<class Type >
fileName writeTemplate (const word &fieldName, const List< Field< Type > > &fieldValues)
 Dummy templated write operation. Multiple tracks. More...
 
 coordSetWriter (const coordSetWriter &)=delete
 No copy construct. More...
 
void operator= (const coordSetWriter &)=delete
 No copy assignment. More...
 
- Static Protected Member Functions inherited from coordSetWriter
static void writeLine (Ostream &, const UList< word > &, const char *sep)
 Write line contents (eg, buffered) More...
 
static void writeLine (Ostream &, const UList< scalar > &, const char *sep)
 Write line contents (eg, buffered) More...
 
template<class Type >
static UPtrList< const Field< Type > > repackageFields (const Field< Type > &field)
 Repackage field into a UPtrList. More...
 
template<class Type >
static UPtrList< const Field< Type > > repackageFields (const UList< Field< Type > > &fieldValues)
 Repackage multiple fields into a UPtrList. More...
 
template<class Type >
static void writeTable (Ostream &os, const coordSet &coords, const UList< Type > &values, const char *sep)
 Write coordinates and values. More...
 
- Protected Attributes inherited from coordSetWriter
UPtrList< const coordSetcoords_
 Reference to coordinate set(s) More...
 
List< scalarFieldtrackTimes_
 Track times (eg, streamlines), one per coords_ entry. More...
 
bool upToDate_
 The content is up-to-date? More...
 
bool wroteGeom_
 Track if geometry has been written since the last open. More...
 
bool buffering_
 Writer with buffering output. More...
 
bool useTracks_
 Prefer tracks to points during single set writing. More...
 
bool useTimeDir_
 Insert additional time sub-directory in the output path. More...
 
bool verbose_
 Additional output verbosity. More...
 
label nFields_
 The number of fields. More...
 
instant currTime_
 The current time value/name. More...
 
fileName outputPath_
 The full output directory and file (coords) name. More...
 
DynamicList< wordlabelNames_
 
PtrDynList< Field< label > > labelFields_
 
DynamicList< wordscalarNames_
 
PtrDynList< Field< scalar > > scalarFields_
 
DynamicList< wordvectorNames_
 
PtrDynList< Field< vector > > vectorFields_
 
DynamicList< wordsphericalTensorNames_
 
PtrDynList< Field< sphericalTensor > > sphericalTensorFields_
 
DynamicList< wordsymmTensorNames_
 
PtrDynList< Field< symmTensor > > symmTensorFields_
 
DynamicList< wordtensorNames_
 
PtrDynList< Field< tensor > > tensorFields_
 

Detailed Description

A coordSet(s) writer in glTF v2 format, which is particularly useful for writing track data.

Two files are generated:

  • filename.bin : a binary file containing all scene entities
  • filename.gltf : a JSON file that ties fields to the binary data

The output can contain both geometry and fields, with additional support for colours using a user-supplied colour map, and animation of particle tracks.

Controls are provided via the optional formatOptions dictionary.

For non-particle track data:

formatOptions
{
    // Apply colours flag (yes | no ) [optional]
    colours     yes;

    // List of options per field
    fieldInfo
    {
        p
        {
            // Colour map [optional]
            colourMap       <colourMap>;

            // Colour map minimum and maximum limits [optional]
            // Uses field min and max if not specified
            min             0;
            max             1;

            // Alpha channel [optional] (<scalar>)
            alpha           0.5;
        }
    }
}
\verbatim

For particle tracks:

\verbatim
formatOptions
{
    // Apply colours flag (yes | no) [optional]
    colours     yes;

    // Animate tracks (yes | no) [optional]
    animate     yes;

    // Animation properties [optional]
    animationInfo
    {
        // Colour map [optional]
        colourMap       <colourMap>;

        // Colour [optional] (<vector> | uniform | field)
        colour          (1 0 0); // RGB in range [0-1]

        //colour          uniform;
        //colourValue     (1 0 0); // RGB in range [0-1]

        //colour          field;
        //colourField     d;

        // Colour map minimum and maximum limits [optional]
        // Note: for colour = field option
        // Uses field min and max if not specified
        min             0;
        max             1;

        // Alpha channel [optional] (<scalar>)
        alpha           0.5;
    }
}
Note
When writing particle animations, the particle field and colour properties correspond to initial particle state (first data point) and cannot be animated (limitation of the file format).

For more information on the specification see https://www.khronos.org/registry/glTF/

Source files

Definition at line 140 of file gltfCoordSetWriter.H.

Member Enumeration Documentation

◆ fieldOption

enum class fieldOption : char
strong

Field option used for colours.

Enumerator
NONE 

Placeholder type (unnamed)

UNIFORM 

Uniform value.

FIELD 

Field value.

Definition at line 149 of file gltfCoordSetWriter.H.

Constructor & Destructor Documentation

◆ gltfWriter() [1/4]

Default construct.

Definition at line 294 of file gltfCoordSetWriter.C.

◆ gltfWriter() [2/4]

gltfWriter ( const dictionary options)
explicit

Default construct with specified options.

Definition at line 308 of file gltfCoordSetWriter.C.

◆ gltfWriter() [3/4]

gltfWriter ( const coordSet coords,
const fileName outputPath,
const dictionary options = dictionary() 
)

Construct from components.

Definition at line 333 of file gltfCoordSetWriter.C.

References coordSetWriter::open().

Here is the call graph for this function:

◆ gltfWriter() [4/4]

gltfWriter ( const UPtrList< coordSet > &  tracks,
const fileName outputPath,
const dictionary options = dictionary() 
)

Construct from components.

Definition at line 346 of file gltfCoordSetWriter.C.

References coordSetWriter::open().

Here is the call graph for this function:

◆ ~gltfWriter()

~gltfWriter ( )
virtual

Destructor. Calls close()

Definition at line 361 of file gltfCoordSetWriter.C.

Member Function Documentation

◆ TypeNameNoDebug()

TypeNameNoDebug ( "gltf"  )

Runtime type information (no debug)

◆ path()

Foam::fileName path ( ) const
virtual

Expected (characteristic) output file name - information only.

Implements coordSetWriter.

Definition at line 369 of file gltfCoordSetWriter.C.

◆ close()

void close ( bool  force = false)
virtual

Close and reset, clears backend.

Reimplemented from coordSetWriter.

Definition at line 378 of file gltfCoordSetWriter.C.

References Decorators< OpenChar, CloseChar, SepChar >::close.

◆ beginTime() [1/2]

void beginTime ( const Time t)
virtual

Begin time step. Clears existing backend.

Reimplemented from coordSetWriter.

Definition at line 385 of file gltfCoordSetWriter.C.

References coordSetWriter::beginTime().

Here is the call graph for this function:

◆ beginTime() [2/2]

void beginTime ( const instant inst)
virtual

Begin time step. Clears existing backend.

Reimplemented from coordSetWriter.

Definition at line 392 of file gltfCoordSetWriter.C.

References coordSetWriter::beginTime().

Here is the call graph for this function:

◆ endTime()

void endTime ( )
virtual

End time step. Clears existing backend.

Reimplemented from coordSetWriter.

Definition at line 399 of file gltfCoordSetWriter.C.

References coordSetWriter::endTime().

Here is the call graph for this function:

◆ declareCoordSetWriterWriteMethod() [1/6]

declareCoordSetWriterWriteMethod ( label  )

◆ declareCoordSetWriterWriteMethod() [2/6]

declareCoordSetWriterWriteMethod ( scalar  )

◆ declareCoordSetWriterWriteMethod() [3/6]

declareCoordSetWriterWriteMethod ( vector  )

◆ declareCoordSetWriterWriteMethod() [4/6]

declareCoordSetWriterWriteMethod ( sphericalTensor  )

◆ declareCoordSetWriterWriteMethod() [5/6]

declareCoordSetWriterWriteMethod ( symmTensor  )

◆ declareCoordSetWriterWriteMethod() [6/6]

declareCoordSetWriterWriteMethod ( tensor  )

◆ writeTemplate() [1/3]

Foam::fileName writeTemplate ( const word fieldName,
const UPtrList< const Field< Type > > &  fieldPtrs 
)

Definition at line 409 of file gltfCoordSetWriter.C.

References alpha, Foam::component(), dict, Foam::exit(), Foam::FatalError, FatalErrorInFunction, field(), forAll, Foam::getBoundedColours(), MinMax< T >::max(), Foam::max(), MinMax< T >::min(), Foam::min(), Foam::minMax(), Foam::minMaxMag(), Foam::name(), Foam::nl, and path().

Here is the call graph for this function:

◆ writeTemplate_animate()

Foam::fileName writeTemplate_animate ( const word fieldName,
const UPtrList< const Field< Type > > &  fieldPtrs 
)

Definition at line 515 of file gltfCoordSetWriter.C.

References Foam::exit(), Foam::FatalError, FatalErrorInFunction, field(), forAll, Foam::getAnimationColour(), Foam::name(), Foam::nl, path(), and Foam::Zero.

Here is the call graph for this function:

◆ writeTemplate() [2/3]

Foam::fileName writeTemplate ( const word fieldName,
const Field< Type > &  values 
)

Definition at line 719 of file gltfCoordSetWriter.C.

References fileName::null.

◆ writeTemplate() [3/3]

Foam::fileName writeTemplate ( const word fieldName,
const List< Field< Type > > &  fieldValues 
)

Definition at line 737 of file gltfCoordSetWriter.C.

References fileName::null.

Member Data Documentation

◆ fieldOptionNames_

Strings corresponding to the field options.

Definition at line 158 of file gltfCoordSetWriter.H.


The documentation for this class was generated from the following files: