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> template<class Type>
Foam::tmp<Foam::scalarField> Foam::gltfSetWriter<Type>::getAlphaField Foam::tmp<Foam::scalarField> Foam::gltfSetWriter<Type>::getAlphaField
( (
const dictionary& dict, const dictionary& dict
const wordList& valueSetNames,
const List<const Field<Type>*>& valueSets
) const ) const
{ {
// Fallback value // Fallback value
@ -131,103 +129,11 @@ Foam::tmp<Foam::scalarField> Foam::gltfSetWriter<Type>::getAlphaField
} }
case fieldOption::FIELD: case fieldOption::FIELD:
{ {
const word alphaFieldName = dict.get<word>("alphaField"); WarningInFunction
const bool normalise = dict.get<bool>("normalise"); << "Unsupported 'field' specification for alpha values"
const label fieldi = valueSetNames.find(alphaFieldName); << endl;
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:
{
break; 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 dictionary dict = fieldInfoDict_.subOrEmptyDict(fieldName);
const auto& colours = getColourTable(dict); const auto& colours = getColourTable(dict);
const auto talpha = getAlphaField(dict, valueSetNames, valueSets); const auto talpha = getAlphaField(dict);
const scalarField& alpha = talpha(); const scalarField& alpha = talpha();
const scalarMinMax valLimits = getFieldLimits(fieldName); const scalarMinMax valLimits = getFieldLimits(fieldName);
@ -558,8 +464,7 @@ void Foam::gltfSetWriter<Type>::writeStaticTracks
fieldInfoDict_.subOrEmptyDict(fieldName); fieldInfoDict_.subOrEmptyDict(fieldName);
const auto& colours = getColourTable(dict); const auto& colours = getColourTable(dict);
const auto talpha = const auto talpha = getAlphaField(dict);
getTrackAlphaField(dict, valueSetNames, valueSets, tracki);
const scalarField& alpha = talpha(); const scalarField& alpha = talpha();
const scalarMinMax valLimits = getFieldLimits(fieldName); const scalarMinMax valLimits = getFieldLimits(fieldName);
@ -679,14 +584,7 @@ void Foam::gltfSetWriter<Type>::writeAnimateTracks
tracki tracki
); );
const auto talpha = const auto talpha = getAlphaField(animationDict_);
getTrackAlphaField
(
animationDict_,
valueSetNames,
valueSets,
tracki
);
const scalarField& alpha = talpha(); const scalarField& alpha = talpha();

View File

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

View File

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

View File

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

View File

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

View File

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