Loading...
Searching...
No Matches
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\*---------------------------------------------------------------------------*/
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
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;Info<< "Write faMesh in vtk format:"<< nl;{ vtk::uindirectPatchWriter writer(aMesh.patch(), fileName(aMesh.time().globalPath()/vtkBaseFileName));writer.writeGeometry();globalIndex procAddr(aMesh.nFaces());labelList cellIDs;if(UPstream::master()) { cellIDs.resize(procAddr.totalSize());for(const labelRange &range :procAddr.ranges()) { auto slice=cellIDs.slice(range);slice=identity(range);} } writer.beginCellData(4);writer.writeProcIDs();writer.write("cellID", cellIDs);writer.write("area", aMesh.S().field());writer.write("normal", aMesh.faceAreaNormals());writer.beginPointData(1);writer.write("normal", aMesh.pointAreaNormals());Info<< " "<< writer.output().name()<< nl;}{ vtk::lineWriter writer(aMesh.points(), aMesh.edges(), fileName(aMesh.time().globalPath()/(vtkBaseFileName+"-edges")));writer.writeGeometry();writer.beginCellData(4);writer.writeProcIDs();{ Field< scalar > fld(faMeshTools::flattenEdgeField(aMesh.magLe(), true))
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
Definition Field.H:172
Output to string buffer, using a OSstream. Always UNCOMPRESSED.
Foam::string str() const
Get the string. As Foam::string instead of std::string (may change in future).
string min_
Min value. Note: stored as a string for convenience.
string max_
Max value. Note: stored as a string for convenience.
label componentType_
Component type.
static string getValueType()
Return the glTF value type for the given OpenFOAM type.
label count_
Data size.
string type_
Data type.
void set(const Field< Type > &fld, bool calcMinMax=true)
Set the accessor.
bool minMax_
Flag to indicate whether min and max values are available.
static string toString(const Type &val)
Stringify the value.
A traits class, which is primarily used for primitives and vector-space.
Definition pTraits.H:64
A class for handling character strings derived from std::string.
Definition string.H:76
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
constexpr auto key(const Type &t) noexcept
Helper function to return the enum value.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition hashSets.C:40
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:26
errorManip< error > abort(error &err)
Definition errorManip.H:139
uint8_t direction
Definition direction.H:49
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
static constexpr::Foam::expressions::valueTypeCode value
Definition exprTraits.H:151