42namespace coordSetWriters
54 { fieldOption::UNIFORM,
"uniform" },
55 { fieldOption::FIELD,
"field" },
69 const scalar boundMin,
73 const label boundDelta = (boundMax - boundMin + ROOTVSMALL);
76 auto& result = tresult.ref();
80 const Type& val =
field[i];
90 result[i] = colours.
value((
f - boundMin)/boundDelta);
126 const scalar fraction =
128 (refValue - valLimits.
min())
129 / (valLimits.
max() - valLimits.
min() + ROOTVSMALL)
133 return colours.
value(fraction);
142Foam::word Foam::coordSetWriters::gltfWriter::getColourMap
144 const dictionary&
dict
156 const dictionary&
dict
165 const word& fieldName
168 const dictionary fieldDict = fieldInfoDict_.subOrEmptyDict(fieldName);
172 fieldDict.readIfPresent(
"min", limits.min());
173 fieldDict.readIfPresent(
"max", limits.max());
180Foam::coordSetWriters::gltfWriter::getAlphaField
182 const dictionary&
dict
186 scalar alphaValue(1);
194 else if (!eptr->stream().peek().isString())
198 ITstream& is = eptr->stream();
200 dict.checkITstream(is,
"alpha");
206 const auto option = fieldOptionNames_.get(
"alpha",
dict);
210 case fieldOption::NONE:
214 case fieldOption::UNIFORM:
216 dict.readEntry(
"alphaValue", alphaValue);
219 case fieldOption::FIELD:
222 <<
"Unsupported 'field' specification for alpha values"
233void Foam::coordSetWriters::gltfWriter::setupAnimationColour()
235 const dictionary&
dict = animationDict_;
239 if (!eptr || !eptr->isStream())
242 <<
"Missing 'colour' entry"
245 else if (!eptr->stream().peek().isString())
249 ITstream& is = eptr->stream();
250 is >> animateColourValue_;
251 dict.checkITstream(is,
"colour");
254 animateColourOption_ = fieldOption::UNIFORM;
260 const auto option = fieldOptionNames_.get(
"colour",
dict);
264 case fieldOption::NONE:
267 <<
"Cannot select 'none' for colour entry!" <<
nl
268 <<
"... possible programming error"
272 case fieldOption::UNIFORM:
274 dict.readEntry(
"colourValue", animateColourValue_);
277 animateColourOption_ = fieldOption::UNIFORM;
280 case fieldOption::FIELD:
283 animateColourName_ =
dict.get<word>(
"colourField");
284 animateColourOption_ = fieldOption::FIELD;
301 animateColourName_(),
302 animateColourValue_(
Zero),
312 animate_(options.getOrDefault(
"animate", false)),
313 colour_(options.getOrDefault(
"colour", false)),
315 animateColourName_(),
316 animateColourValue_(
Zero),
317 fieldInfoDict_(options.subOrEmptyDict(
"fieldInfo")),
318 animationDict_(options.subOrEmptyDict(
"animationInfo"))
342 open(coords, outputPath);
355 open(tracks, outputPath);
374 return getExpectedPath(
"gltf");
380 writer_.reset(
nullptr);
387 writer_.reset(
nullptr);
394 writer_.reset(
nullptr);
401 writer_.reset(
nullptr);
411 const word& fieldName,
415 if (coords_.size() != fieldPtrs.size())
418 <<
"Attempted to write field: " << fieldName
419 <<
" (" << fieldPtrs.size() <<
" entries) for "
420 << coords_.size() <<
" sets" <<
nl
424 const auto& tracks = coords_;
438 auto& scene = writer_->getScene();
440 meshes_.resize(tracks.size());
445 if (tracks.size() == 1)
450 meshes_[tracki] = scene.addMesh(tracks[tracki], meshName);
455 auto& scene = writer_->getScene();
459 const label meshi = meshes_[tracki];
460 const auto&
field = fieldPtrs[tracki];
462 scene.addFieldToMesh(
field, fieldName, meshi);
467 const auto& colours = getColourTable(
dict);
469 const auto talpha = getAlphaField(
dict);
472 const scalarMinMax valLimits = getFieldLimits(fieldName);
500 scene.addColourToMesh
503 "Colour:" + fieldName,
510 return writer_().path();
517 const word& fieldName,
521 if (coords_.size() != fieldPtrs.size())
524 <<
"Attempted to write field: " << fieldName
525 <<
" (" << fieldPtrs.size() <<
" entries) for "
526 << coords_.size() <<
" sets" <<
nl
530 const auto& tracks = this->coords_;
531 const auto& times = this->trackTimes_;
543 auto& scene = writer_->getScene();
545 meshes_.resize(tracks.size());
547 const label animationi = scene.createAnimation(
"animation");
551 const auto& track = tracks[tracki];
555 meshes_[tracki] = -1;
568 const label meshi = meshes_[tracki];
572 scene.addField(times[tracki],
"time:" +
Foam::name(tracki));
576 const label translationId =
577 scene.addField(translation,
"translation");
579 scene.addToAnimation(animationi, timeId, translationId, meshi);
584 auto& scene = writer_->getScene();
590 const auto& track = tracks[tracki];
591 const label meshi = meshes_[tracki];
594 if (track.empty() || meshi < 0)
609 if (animateColourOption_ == fieldOption::NONE)
612 setupAnimationColour();
615 switch (animateColourOption_)
617 case fieldOption::NONE:
622 case fieldOption::UNIFORM:
629 const auto talpha = getAlphaField(animationDict_);
631 if (talpha && talpha().size())
633 alphaChannel[0] = talpha()[0];
638 const auto& track = tracks[tracki];
639 const label meshi = meshes_[tracki];
641 if (track.empty() || meshi < 0)
646 scene.addColourToMesh
656 animateColourName_.clear();
657 animateColourOption_ = fieldOption::FIELD;
660 case fieldOption::FIELD:
664 !animateColourName_.empty()
665 && animateColourName_ == fieldName
670 const auto& colours = getColourTable(animationDict_);
675 const auto talpha = getAlphaField(animationDict_);
677 if (talpha && talpha().size())
679 alphaChannel[0] = talpha()[0];
684 const auto& track = tracks[tracki];
685 const label meshi = meshes_[tracki];
688 if (track.empty() || meshi < 0)
696 scene.addColourToMesh
706 animateColourName_.clear();
707 animateColourOption_ = fieldOption::FIELD;
714 return writer_().path();
721 const word& fieldName,
732 return writeTemplate(fieldName, fieldPtrs);
739 const word& fieldName,
751 if (animate_ && trackTimes_.size() >= coords_.size())
753 return writeTemplate_animate(fieldName, fieldPtrs);
756 return writeTemplate(fieldName, fieldPtrs);
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
const List< word > & names() const noexcept
The list of enum names, in construction order. Same as toc()
Generic templated field type.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
const T & max() const noexcept
The max value (second)
const T & min() const noexcept
The min value (first)
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
Base class for generating a colour table from node points.
vector value(const scalar x) const
Return the colour at x. The input is clipped to 0-1 range.
static const Enum< predefinedType > predefinedNames
Enumeration names for predefinedType.
Base class for writing coordSet(s) and tracks with fields.
virtual void open(const fileName &outputPath)
Write separate geometry to file.
virtual void endTime()
End a time-step.
virtual void beginTime(const Time &t)
Begin a time-step.
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.
gltfWriter()
Default construct.
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()
Holds list of sampling positions.
reference ref() const
A reference to the entry (Error if not found)
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
A class for handling file names.
static const fileName null
An empty fileName.
Wrapper for glTF scene for file output.
An instant of time. Contains the time value and name. Uses Foam::Time when formatting the name.
A traits class, which is primarily used for primitives.
A class for managing temporary objects.
A class for handling words, derived from Foam::string.
#define defineTypeName(Type)
Define the typeName.
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
Convenience macros for instantiating coordSetWriter methods.
#define defineCoordSetWriterWriteFields(ThisClass)
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
#define WarningInFunction
Report a warning using Foam::Warning.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
static vector getAnimationColour(const dictionary &dict, const colourTable &colours, const Field< Type > &field)
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
MinMax< scalar > scalarMinMax
A scalar min/max range.
static tmp< vectorField > getBoundedColours(const colourTable &colours, const Field< Type > &field, const scalar boundMin, const scalar boundMax)
MinMax< label > minMax(const labelHashSet &set)
Find the min/max values of labelHashSet.
Ostream & endl(Ostream &os)
Add newline and flush stream.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Field< vector > vectorField
Specialisation of Field<T> for vector.
static constexpr const zero Zero
Global zero (0)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
dimensioned< scalarMinMax > minMaxMag(const DimensionedField< Type, GeoMesh > &df)
errorManipArg< error, int > exit(error &err, const int errNo=1)
constexpr char nl
The newline '\n' character (0x0a)
#define forAll(list, i)
Loop across all elements in list.
static constexpr char close