Loading...
Searching...
No Matches
foamGltfAccessor.H
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
26Class
27 Foam::glTF::accessor
28
29Description
30 glTF accessor
31
32Note
33 Implements the glTF v2 specification
34
35SourceFiles
36 foamGltfAccessor.C
37 foamGltfAccessorTemplates.C
38
39\*---------------------------------------------------------------------------*/
40
41#ifndef foam_gltf_accessor_H
42#define foam_gltf_accessor_H
43
44#include "foamGltfBase.H"
45#include "Field.H"
46#include "label.H"
47#include "word.H"
49// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50
51namespace Foam
52{
53namespace glTF
54{
55 class accessor;
56}
57
59
60namespace glTF
61{
63/*---------------------------------------------------------------------------*\
64 Class glTF::accessor Declaration
65\*---------------------------------------------------------------------------*/
66
67class accessor
68:
69 public base
70{
71protected:
72
73 // Protected Data
74
75 //- Buffer view index
76 label bufferViewId_;
77
78 //- Byte offset
79 label byteOffset_;
80
81 //- Component type
82 label componentType_;
84 //- Data size
85 label count_;
86
87 //- Data type
88 string type_;
89
90 //- Max value. Note: stored as a string for convenience
91 string max_;
92
93 //- Min value. Note: stored as a string for convenience
94 string min_;
95
96 //- Flag to indicate whether min and max values are available
97 bool minMax_;
99
100 // Protected Member Functions
101
102 //- Return the glTF value type for the given OpenFOAM type
103 template<class Type>
104 static string getValueType();
105
106 //- Stringify the value
107 template<class Type>
108 static string toString(const Type& val);
109
110
111public:
112
113 // Constructors
114
115 //- Default construct
116 accessor();
118 //- Construct from name
119 explicit accessor(const word& name);
120
121
122 //- Destructor
123 ~accessor() = default;
124
125
126 // Public Member Functions
127
128 //- Return the buffer view index
129 label& bufferViewId() noexcept;
130
131 //- Return the byte offset
132 label& byteOffset() noexcept;
133
134 //- Return the component type
135 label& componentType() noexcept;
136
137 //- Return the data size
138 label& count() noexcept;
139
140 //- Return the type
141 string& type() noexcept;
142
143 //- Set the accessor
144 template<class Type>
145 void set(const Field<Type>& fld, bool calcMinMax = true);
146
147 //- Write
148 void write(Ostream& os) const;
149};
150
151
152// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
153
154} // End namespace glTF
155} // End namespace Foam
156
157// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
158
159#ifdef NoRepository
161#endif
162
163// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
164
165#endif
166
167// ************************************************************************* //
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
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
string min_
Min value. Note: stored as a string for convenience.
string max_
Max value. Note: stored as a string for convenience.
label & componentType() noexcept
Return the component type.
label & count() noexcept
Return the data size.
label componentType_
Component type.
accessor()
Default construct.
label bufferViewId_
Buffer view index.
static string getValueType()
Return the glTF value type for the given OpenFOAM type.
label count_
Data size.
~accessor()=default
Destructor.
string type_
Data type.
string & type() noexcept
Return the type.
void write(Ostream &os) const
Write.
label & byteOffset() noexcept
Return the byte offset.
label & bufferViewId() noexcept
Return the buffer view index.
void set(const Field< Type > &fld, bool calcMinMax=true)
Set the accessor.
bool minMax_
Flag to indicate whether min and max values are available.
label byteOffset_
Byte offset.
static string toString(const Type &val)
Stringify the value.
const word & name() const noexcept
Return const access to the name.
base()
Default construct.
A class for handling words, derived from Foam::string.
Definition word.H:66
OBJstream os(runTime.globalPath()/outputName)
Namespace for handling glTF creation. https://www.khronos.org/registry/glTF/.
Namespace for OpenFOAM.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces).
const direction noexcept
Definition scalarImpl.H:265