From df18b8bb3ce01108140e5e798eeeaa697530a756 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 28 Jan 2022 12:59:04 +0100 Subject: [PATCH] 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. --- .../writers/gltf/gltfCoordSetWriter.C | 116 ++---------------- .../coordSet/writers/gltf/gltfSetWriter.H | 34 +---- .../filter/constant/particleTrackProperties | 10 +- .../constant/particleTrackProperties.animate | 10 +- .../constant/particleTrackProperties.static | 14 +-- .../reactingParcelFoam/filter/system/sample | 8 +- 6 files changed, 21 insertions(+), 171 deletions(-) diff --git a/src/meshTools/coordSet/writers/gltf/gltfCoordSetWriter.C b/src/meshTools/coordSet/writers/gltf/gltfCoordSetWriter.C index fbfebdf6fc..d7e60088b7 100644 --- a/src/meshTools/coordSet/writers/gltf/gltfCoordSetWriter.C +++ b/src/meshTools/coordSet/writers/gltf/gltfCoordSetWriter.C @@ -90,9 +90,7 @@ Foam::scalarMinMax Foam::gltfSetWriter::getFieldLimits template Foam::tmp Foam::gltfSetWriter::getAlphaField ( - const dictionary& dict, - const wordList& valueSetNames, - const List*>& valueSets + const dictionary& dict ) const { // Fallback value @@ -131,103 +129,11 @@ Foam::tmp Foam::gltfSetWriter::getAlphaField } case fieldOption::FIELD: { - const word alphaFieldName = dict.get("alphaField"); - const bool normalise = dict.get("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& alphaFld = *(valueSets[fieldi]); - - auto tresult = tmp::New(alphaFld.component(0)); - - if (normalise) - { - tresult.ref() /= mag(tresult() + ROOTVSMALL); - } - - return tresult; - } - } - } - - return tmp::New(1, alphaValue); -} - - -template -Foam::tmp Foam::gltfSetWriter::getTrackAlphaField -( - const dictionary& dict, - const wordList& valueSetNames, - const List>>& 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("alphaField"); - const bool normalise = dict.get("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& alphaFld = valueSets[fieldi][tracki]; - - // Note: selecting the first component! - auto tresult = tmp::New(alphaFld.component(0)); - - if (normalise) - { - tresult.ref() /= mag(tresult() + ROOTVSMALL); - } - - return tresult; - } } } @@ -422,7 +328,7 @@ void Foam::gltfSetWriter::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::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::writeAnimateTracks tracki ); - const auto talpha = - getTrackAlphaField - ( - animationDict_, - valueSetNames, - valueSets, - tracki - ); + const auto talpha = getAlphaField(animationDict_); const scalarField& alpha = talpha(); diff --git a/src/meshTools/coordSet/writers/gltf/gltfSetWriter.H b/src/meshTools/coordSet/writers/gltf/gltfSetWriter.H index d8f470b405..82aeeadeb1 100644 --- a/src/meshTools/coordSet/writers/gltf/gltfSetWriter.H +++ b/src/meshTools/coordSet/writers/gltf/gltfSetWriter.H @@ -60,15 +60,8 @@ Description min 0; max 1; - // Alpha channel [optional] ( | uniform | field) + // Alpha channel [optional] () 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] ( | uniform | field) + // Alpha channel [optional] () 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 getAlphaField - ( - const dictionary& dict, - const wordList& valueSetNames, - const List*>& valueSets - ) const; - - //- Return the alpha field for tracks - tmp getTrackAlphaField - ( - const dictionary& dict, - const wordList& valueSetNames, - const List>>& valueSets, - const label tracki - ) const; + tmp getAlphaField(const dictionary& dict) const; //- Return the animation colour when animating tracks vector getTrackAnimationColour diff --git a/tutorials/lagrangian/reactingParcelFoam/filter/constant/particleTrackProperties b/tutorials/lagrangian/reactingParcelFoam/filter/constant/particleTrackProperties index e70b4312de..b62f5c1304 100644 --- a/tutorials/lagrangian/reactingParcelFoam/filter/constant/particleTrackProperties +++ b/tutorials/lagrangian/reactingParcelFoam/filter/constant/particleTrackProperties @@ -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; } } diff --git a/tutorials/lagrangian/reactingParcelFoam/filter/constant/particleTrackProperties.animate b/tutorials/lagrangian/reactingParcelFoam/filter/constant/particleTrackProperties.animate index e70b4312de..b62f5c1304 100644 --- a/tutorials/lagrangian/reactingParcelFoam/filter/constant/particleTrackProperties.animate +++ b/tutorials/lagrangian/reactingParcelFoam/filter/constant/particleTrackProperties.animate @@ -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; } } diff --git a/tutorials/lagrangian/reactingParcelFoam/filter/constant/particleTrackProperties.static b/tutorials/lagrangian/reactingParcelFoam/filter/constant/particleTrackProperties.static index 76b844fff6..a3b169493a 100644 --- a/tutorials/lagrangian/reactingParcelFoam/filter/constant/particleTrackProperties.static +++ b/tutorials/lagrangian/reactingParcelFoam/filter/constant/particleTrackProperties.static @@ -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; } } } diff --git a/tutorials/lagrangian/reactingParcelFoam/filter/system/sample b/tutorials/lagrangian/reactingParcelFoam/filter/system/sample index 52fecdea3d..1c66955110 100644 --- a/tutorials/lagrangian/reactingParcelFoam/filter/system/sample +++ b/tutorials/lagrangian/reactingParcelFoam/filter/system/sample @@ -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; } } }