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-------------------------------------------------------------------------------
10License
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
33template<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
67template<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
85template<class Type>
86void 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// ************************************************************************* //
scalar maxValue
scalar minValue
Info<< nl<< "Wrote faMesh in vtk format: "<< writer.output().name()<< nl;}{ vtk::lineWriter writer(aMesh.points(), aMesh.edges(), fileName(aMesh.mesh().time().globalPath()/"finiteArea-edges"));writer.writeGeometry();writer.beginCellData(4);writer.writeProcIDs();{ Field< scalar > fld(faMeshTools::flattenEdgeField(aMesh.magLe(), true))
Foam::string str() const
Get the string - as Foam::string rather than std::string.
Definition: StringStream.H:88
Generic templated field type.
Definition: Field.H:82
std::string toString() const
Definition: ITstream.C:320
Output to string buffer, using a OSstream. Always UNCOMPRESSED.
Definition: StringStream.H:231
static string getValueType()
Return the glTF value type for the given OpenFOAM type.
A traits class, which is primarily used for primitives.
Definition: pTraits.H:59
A class for handling character strings derived from std::string.
Definition: string.H:79
bool set() const
Are all the vector set.
Definition: triadI.H:76
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
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
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
errorManip< error > abort(error &err)
Definition: errorManip.H:144
uint8_t direction
Definition: direction.H:56
error FatalError
Simple type identifiers for polymorphic expression values.
Definition: exprTraits.H:102