DEFEATURE: remove alpha-field support (partly broken) from gltf output

- when used with *any* alphaField and normalised (the usual case)
  would largely give a 0-1 corresponding to the min/max of the first
  component, but could also yield negative values.

- if the alpha field corresponds identically to colour field, it is
  readily possible to combine as into RGBA sequences. However, if the
  fields are different it potentially means referencing an opacity
  field that has not yet been sampled.  This impedes using the format
  for a streaming sampler without additional overhead and/or rewriting
  the alpha channel later.
This commit is contained in:
Mark Olesen 2022-01-28 12:59:04 +01:00
parent 2a61606251
commit df18b8bb3c
6 changed files with 21 additions and 171 deletions

View File

@ -90,9 +90,7 @@ Foam::scalarMinMax Foam::gltfSetWriter<Type>::getFieldLimits
template<class Type>
Foam::tmp<Foam::scalarField> Foam::gltfSetWriter<Type>::getAlphaField
(
const dictionary& dict,
const wordList& valueSetNames,
const List<const Field<Type>*>& valueSets
const dictionary& dict
) const
{
// Fallback value
@ -131,103 +129,11 @@ Foam::tmp<Foam::scalarField> Foam::gltfSetWriter<Type>::getAlphaField
}
case fieldOption::FIELD:
{
const word alphaFieldName = dict.get<word>("alphaField");
const bool normalise = dict.get<bool>("normalise");
const label fieldi = valueSetNames.find(alphaFieldName);
if (fieldi == -1)
{
FatalErrorInFunction
<< "Unable to find field " << alphaFieldName
<< ". Valid field names are:" << valueSetNames
<< exit(FatalError);
}
const Field<Type>& alphaFld = *(valueSets[fieldi]);
auto tresult = tmp<scalarField>::New(alphaFld.component(0));
if (normalise)
{
tresult.ref() /= mag(tresult() + ROOTVSMALL);
}
return tresult;
}
}
}
return tmp<scalarField>::New(1, alphaValue);
}
template<class Type>
Foam::tmp<Foam::scalarField> Foam::gltfSetWriter<Type>::getTrackAlphaField
(
const dictionary& dict,
const wordList& valueSetNames,
const List<List<Field<Type>>>& valueSets,
const label tracki
) const
{
// Fallback value
scalar alphaValue(1);
const entry* eptr = dict.findEntry("alpha", keyType::LITERAL);
if (!eptr)
{
// Not specified
}
else if (!eptr->stream().peek().isString())
{
// Value specified
ITstream& is = eptr->stream();
is >> alphaValue;
dict.checkITstream(is, "alpha");
}
else
{
// Enumeration
const auto option = fieldOptionNames_.get("alpha", dict);
switch (option)
{
case fieldOption::NONE:
{
WarningInFunction
<< "Unsupported 'field' specification for alpha values"
<< endl;
break;
}
case fieldOption::UNIFORM:
{
dict.readEntry("alphaValue", alphaValue);
break;
}
case fieldOption::FIELD:
{
const word alphaFieldName = dict.get<word>("alphaField");
const bool normalise = dict.get<bool>("normalise");
const label fieldi = valueSetNames.find(alphaFieldName);
if (fieldi == -1)
{
FatalErrorInFunction
<< "Unable to find field " << alphaFieldName
<< ". Valid field names are:" << valueSetNames
<< exit(FatalError);
}
const Field<Type>& alphaFld = valueSets[fieldi][tracki];
// Note: selecting the first component!
auto tresult = tmp<scalarField>::New(alphaFld.component(0));
if (normalise)
{
tresult.ref() /= mag(tresult() + ROOTVSMALL);
}
return tresult;
}
}
}
@ -422,7 +328,7 @@ void Foam::gltfSetWriter<Type>::write
const dictionary dict = fieldInfoDict_.subOrEmptyDict(fieldName);
const auto& colours = getColourTable(dict);
const auto talpha = getAlphaField(dict, valueSetNames, valueSets);
const auto talpha = getAlphaField(dict);
const scalarField& alpha = talpha();
const scalarMinMax valLimits = getFieldLimits(fieldName);
@ -558,8 +464,7 @@ void Foam::gltfSetWriter<Type>::writeStaticTracks
fieldInfoDict_.subOrEmptyDict(fieldName);
const auto& colours = getColourTable(dict);
const auto talpha =
getTrackAlphaField(dict, valueSetNames, valueSets, tracki);
const auto talpha = getAlphaField(dict);
const scalarField& alpha = talpha();
const scalarMinMax valLimits = getFieldLimits(fieldName);
@ -679,14 +584,7 @@ void Foam::gltfSetWriter<Type>::writeAnimateTracks
tracki
);
const auto talpha =
getTrackAlphaField
(
animationDict_,
valueSetNames,
valueSets,
tracki
);
const auto talpha = getAlphaField(animationDict_);
const scalarField& alpha = talpha();

View File

@ -60,15 +60,8 @@ Description
min 0;
max 1;
// Alpha channel [optional] (<scalar> | uniform | field)
// Alpha channel [optional] (<scalar>)
alpha 0.5;
//alpha uniform;
//alphaValue 0.5;
//alpha field;
//alphaField T;
//normalise yes;
}
}
}
@ -106,15 +99,8 @@ Description
min 0;
max 1;
// Alpha channel [optional] (<scalar> | uniform | field)
// Alpha channel [optional] (<scalar>)
alpha 0.5;
//alpha uniform;
//alphaValue 0.5;
//alpha field;
//alphaField T;
//normalise yes;
}
}
\endverbatim
@ -199,21 +185,7 @@ private:
scalarMinMax getFieldLimits(const word& fieldName) const;
//- Return the alpha field for mesh values
tmp<scalarField> getAlphaField
(
const dictionary& dict,
const wordList& valueSetNames,
const List<const Field<Type>*>& valueSets
) const;
//- Return the alpha field for tracks
tmp<scalarField> getTrackAlphaField
(
const dictionary& dict,
const wordList& valueSetNames,
const List<List<Field<Type>>>& valueSets,
const label tracki
) const;
tmp<scalarField> getAlphaField(const dictionary& dict) const;
//- Return the animation colour when animating tracks
vector getTrackAnimationColour

View File

@ -1,7 +1,7 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2112 |
| \\ / O peration | Version: v2206 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
@ -35,13 +35,7 @@ formatOptions
colourField d;
//min 0;
//max 0.002;
//alpha uniform;
//alphaValue 1;
alpha field;
alphaField d;
normalise yes;
//alpha 1.0;
}
}

View File

@ -1,7 +1,7 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2112 |
| \\ / O peration | Version: v2206 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
@ -35,13 +35,7 @@ formatOptions
colourField d;
//min 0;
//max 0.002;
//alpha uniform;
//alphaValue 1;
alpha field;
alphaField d;
normalise yes;
//alpha 1.0;
}
}

View File

@ -1,7 +1,7 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2112 |
| \\ / O peration | Version: v2206 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
@ -33,14 +33,10 @@ formatOptions
{
d
{
colourMap rainbow;
min 0;
max 0.001;
alpha field; // uniform | field;
//alphaValue 0.1; // uniform alpha value
alphaField d;
normalise yes;
colourMap rainbow;
min 0;
max 0.001;
//alpha 1.0;
}
}
}

View File

@ -18,12 +18,8 @@ sample1
{
T
{
colourMap fire;
alpha field; // uniform | field;
//alphaValue 0.1; // uniform alpha value
alphaField T;
normalise yes;
colourMap fire;
//alpha 1.0;
}
}
}