foamGltfAccessorTemplates.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2021 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "foamGltfAccessor.H"
29 #include "exprTraits.H"
30 
31 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
32 
33 template<class Type>
35 {
37  {
40  {
41  return "SCALAR";
42  }
43 
45  {
46  return "VEC3";
47  }
48 
50  {
51  return "MAT3";
52  }
53 
54  default:
55  {
57  << "Unable to process "
58  << pTraits<Type>::typeName << " fields"
59  << abort(FatalError);
60  }
61  }
62 
63  return string();
64 }
65 
66 
67 template<class Type>
69 {
70  OStringStream buf;
71  buf << "[ ";
72  for (direction dir = 0; dir < pTraits<Type>::nComponents; ++dir)
73  {
74  if (dir) buf << ", ";
75  buf << float(component(val, dir));
76  }
77  buf << " ]";
78 
79  return buf.str();
80 }
81 
82 
83 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
84 
85 template<class Type>
86 void Foam::glTF::accessor::set(const Field<Type>& fld, bool calcMinMax)
87 {
88  count_ = fld.size();
89 
90  type_ = accessor::getValueType<Type>();
91 
92  componentType_ = key(componentTypes::FLOAT);
93 
94  minMax_ = calcMinMax;
95 
96  if (minMax_)
97  {
98  Type minValue = min(fld);
99  Type maxValue = max(fld);
100 
103  }
104 }
105 
106 
107 // ************************************************************************* //
Foam::component
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
Definition: FieldFieldFunctions.C:44
Foam::glTF::accessor::set
void set(const Field< Type > &fld, bool calcMinMax=true)
Set the accessor.
Definition: foamGltfAccessorTemplates.C:86
Foam::glTF::key
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
Definition: foamGltfBase.H:108
Foam::string
A class for handling character strings derived from std::string.
Definition: string.H:76
Foam::min
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
foamGltfAccessor.H
Foam::Field
Generic templated field type.
Definition: Field.H:63
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
fld
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< ' ';}gmvFile<< nl;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Definition: gmvOutputLagrangian.H:23
Foam::FatalError
error FatalError
Foam::glTF::accessor::toString
static string toString(const Type &val)
Stringify the value.
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::Detail::StringStreamAllocator::str
Foam::string str() const
Get the string - as Foam::string rather than std::string.
Definition: StringStream.H:88
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::pTraits
A traits class, which is primarily used for primitives.
Definition: pTraits.H:56
Foam::OStringStream
Output to string buffer, using a OSstream. Always UNCOMPRESSED.
Definition: StringStream.H:227
Foam::exprTypeTraits
Simple type identifiers for polymorphic expression values.
Definition: exprTraits.H:101
Foam::direction
uint8_t direction
Definition: direction.H:52
exprTraits.H
minValue
scalar minValue
Definition: LISASMDCalcMethod2.H:12
Foam::glTF::accessor::getValueType
static string getValueType()
Return the glTF value type for the given OpenFOAM type.
Foam::glTF::componentTypes::FLOAT
4 bytes
maxValue
scalar maxValue
Definition: LISASMDCalcMethod1.H:5