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 -------------------------------------------------------------------------------
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 Class
27  Foam::glTF::accessor
28 
29 Description
30  glTF accessor
31 
32 Note
33  Implements the glTF v2 specification
34 
35 SourceFiles
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"
48 
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 
51 namespace Foam
52 {
53 namespace glTF
54 {
55  class accessor;
56 }
57 
59 
60 namespace glTF
61 {
62 
63 /*---------------------------------------------------------------------------*\
64  Class glTF::accessor Declaration
65 \*---------------------------------------------------------------------------*/
66 
67 class accessor
68 :
69  public base
70 {
71 protected:
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_;
83 
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_;
98 
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 
111 public:
112 
113  // Constructors
114 
115  //- Default construct
116  accessor();
117 
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
160  #include "foamGltfAccessorTemplates.C"
161 #endif
162 
163 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
164 
165 #endif
166 
167 // ************************************************************************* //
label byteOffset_
Byte offset.
label bufferViewId_
Buffer view index.
static string toString(const Type &val)
Stringify the value.
string type_
Data type.
label & count() noexcept
Return the data size.
Generic templated field type.
Definition: Field.H:62
A class for handling words, derived from Foam::string.
Definition: word.H:63
label componentType_
Component type.
label & bufferViewId() noexcept
Return the buffer view index.
label & componentType() noexcept
Return the component type.
static string getValueType()
Return the glTF value type for the given OpenFOAM type.
~accessor()=default
Destructor.
const word & name() const noexcept
Return const access to the name.
Definition: foamGltfBase.H:174
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
const direction noexcept
Definition: Scalar.H:258
OBJstream os(runTime.globalPath()/outputName)
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))
bool minMax_
Flag to indicate whether min and max values are available.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
void set(const Field< Type > &fld, bool calcMinMax=true)
Set the accessor.
string & type() noexcept
Return the type.
Base class for glTF entities.
Definition: foamGltfBase.H:116
accessor()
Default construct.
void write(Ostream &os) const
Write.
label count_
Data size.
string min_
Min value. Note: stored as a string for convenience.
label & byteOffset() noexcept
Return the byte offset.
string max_
Max value. Note: stored as a string for convenience.
Namespace for OpenFOAM.