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 // ************************************************************************* //
uint8_t direction
Definition: direction.H:46
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
Foam::string str() const
Get the string - as Foam::string rather than std::string.
Definition: StringStream.H:96
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
scalar minValue
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:40
static string toString(const Type &val)
Stringify the value.
A traits class, which is primarily used for primitives and vector-space.
Definition: pTraits.H:75
::Foam::direction nComponents(const expressions::valueTypeCode) noexcept
The number of components associated with given valueTypeCode.
Definition: exprTraits.C:40
scalar maxValue
Generic templated field type.
Definition: Field.H:62
static string getValueType()
Return the glTF value type for the given OpenFOAM type.
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:26
errorManip< error > abort(error &err)
Definition: errorManip.H:139
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))
Simple type identifiers for polymorphic expression values. The definitions are similar to std::integr...
Definition: exprTraits.H:143
void set(const Field< Type > &fld, bool calcMinMax=true)
Set the accessor.
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
Definition: foamGltfBase.H:103
A class for handling character strings derived from std::string.
Definition: string.H:72
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
Output to string buffer, using a OSstream. Always UNCOMPRESSED.
Definition: StringStream.H:256