Ocean
Field1D.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_SCENEDESCRIPTION_FIELD_1D_H
9 #define META_OCEAN_SCENEDESCRIPTION_FIELD_1D_H
10 
14 
15 #include <vector>
16 
17 namespace Ocean
18 {
19 
20 namespace SceneDescription
21 {
22 
23 // Forward declaration.
24 template <typename T> class Field1D;
25 
26 /**
27  * Definition of a multi field with boolean values.
28  * @ingroup scenedescription
29  */
31 
32 /**
33  * Definition of a multi field with color values.
34  * @ingroup scenedescription
35  */
37 
38 /**
39  * Definition of a multi field with float values.
40  * @ingroup scenedescription
41  */
43 
44 /**
45  * Definition of a multi field with integer values.
46  * @ingroup scenedescription
47  */
49 
50 /**
51  * Definition of a multi field with node values.
52  * @ingroup scenedescription
53  */
55 
56 /**
57  * Definition of a multi field with 3x3 matrix values.
58  * @ingroup scenedescription
59  */
61 
62 /**
63  * Definition of a multi field with 4x4 matrix values.
64  * @ingroup scenedescription
65  */
67 
68 /**
69  * Definition of a multi field with rotation values.
70  * @ingroup scenedescription
71  */
73 
74 /**
75  * Definition of a multi field with string values.
76  * @ingroup scenedescription
77  */
79 
80 /**
81  * Definition of a multi field with time values.
82  * @ingroup scenedescription
83  */
85 
86 /**
87  * Definition of a multi field with 2D vector values.
88  * @ingroup scenedescription
89  */
91 
92 /**
93  * Definition of a multi field with 3D vector values.
94  * @ingroup scenedescription
95  */
97 
98 /**
99  * Definition of a multi field with 4D vector values.
100  * @ingroup scenedescription
101  */
103 
104 /**
105  * This class implements all 1D fields (fields holding an array of single values).
106  * @ingroup scenedescription
107  */
108 template <typename T>
109 class Field1D : public Field
110 {
111  public:
112 
113  /// Scalar type of this multi field.
114  static constexpr Type fieldType = TypeMapper<T>::type();
115 
116  /// Dimension of this multi field.
117  static constexpr unsigned int fieldDimension = 1u;
118 
119  /**
120  * Definition of a vector holding the single values.
121  */
122  typedef std::vector<T> Values;
123 
124  public:
125 
126  /**
127  * Creates a new multi value field with no value.
128  */
129  Field1D() = default;
130 
131  /**
132  * Creates a new multi value field by a given initialization value.
133  * The modification timestamp will be set to zero.
134  * @param value Initialization value
135  */
136  inline Field1D(const T& value);
137 
138  /**
139  * Creates a new multi value field by a given initialization value.
140  * @param value Initialization value
141  * @param timestamp Explicit field timestamp
142  */
143  inline Field1D(const T& value, const Timestamp timestamp);
144 
145  /**
146  * Creates a new multi value field by given initilization values.
147  * The modification timestamp will be set to zero.
148  * @param values Initialization values
149  */
150  inline Field1D(const Values& values);
151 
152  /**
153  * Creates a new multi value field by given initilization values.
154  * @param values Initialization values
155  * @param timestamp Explicit field timestamp
156  */
157  inline Field1D(const Values& values, const Timestamp timestamp);
158 
159  /**
160  * Returns the type of this field.
161  * @see Field::type().
162  */
163  Type type() const override;
164 
165  /**
166  * Returns the dimension of this field.
167  * @see Field::dimension().
168  */
169  unsigned int dimension() const override;
170 
171  /**
172  * Returns the values of this field.
173  * @return Field values
174  */
175  inline const Values& values() const;
176 
177  /**
178  * Returns the values of this field.
179  * @return Field values
180  */
181  inline Values& values();
182 
183  /**
184  * Sets the values of this field and changes the timestamp to the current time.
185  * @param value Values to set
186  */
187  inline void setValues(const Values& value);
188 
189  /**
190  * Sets the values of this field and defines an explicit modification timestamp.
191  * @param value Values to set
192  * @param timestamp Explicit modification timestamp
193  */
194  inline void setValues(const Values& value, const Timestamp timestamp);
195 
196  /**
197  * Assigns a field to this field if both field have the identical field type
198  * @see Field::assignField().
199  */
200  bool assign(const Field& field) override;
201 
202  protected:
203 
204  /**
205  * Returns a new instance of this field.
206  * @see Field::copy().
207  */
208  Field* copy() const override;
209 
210  protected:
211 
212  /// Field values.
214 };
215 
216 template <typename T>
217 inline Field1D<T>::Field1D(const T& value) :
218  values_(1, value)
219 {
220  // nothing to do here
221 }
222 
223 template <typename T>
224 inline Field1D<T>::Field1D(const T& value, const Timestamp timestamp) :
225  Field(timestamp),
226  values_(1, value)
227 {
228  // nothing to do here
229 }
230 
231 template <typename T>
232 inline Field1D<T>::Field1D(const Values& values) :
233  values_(values)
234 {
235  // nothing to do here
236 }
237 
238 template <typename T>
239 inline Field1D<T>::Field1D(const Values& values, const Timestamp timestamp) :
240  Field(timestamp),
241  values_(values)
242 {
243  // nothing to do here
244 }
245 
246 template <typename T>
248 {
249  return TypeMapper<T>::type();
250 }
251 
252 template <typename T>
253 unsigned int Field1D<T>::dimension() const
254 {
255  return 1;
256 }
257 
258 template <typename T>
259 inline const typename Field1D<T>::Values& Field1D<T>::values() const
260 {
261  return values_;
262 }
263 
264 template <typename T>
266 {
267  return values_;
268 }
269 
270 template <typename T>
271 inline void Field1D<T>::setValues(const Values& values)
272 {
273  values_ = values;
274  timestamp_.toNow();
275 }
276 
277 template <typename T>
278 inline void Field1D<T>::setValues(const Values& values, const Timestamp timestamp)
279 {
280  values_ = values;
281  timestamp_ = timestamp;
282 }
283 
284 template <typename T>
286 {
287  return new Field1D<T>(values_);
288 }
289 
290 template <typename T>
291 bool Field1D<T>::assign(const Field& field)
292 {
293  if (fieldType != field.type() || fieldDimension != field.dimension())
294  {
295  return false;
296  }
297 
298  values_ = dynamic_cast<const Field1D<T>&>(field).values_;
299  timestamp_ = field.timestamp();
300 
301  return true;
302 }
303 
304 }
305 
306 }
307 
308 #endif // META_OCEAN_SCENEDESCRIPTION_FIELD_1D_H
This class implements all 1D fields (fields holding an array of single values).
Definition: Field1D.h:110
std::vector< T > Values
Definition of a vector holding the single values.
Definition: Field1D.h:122
void setValues(const Values &value)
Sets the values of this field and changes the timestamp to the current time.
Definition: Field1D.h:271
Values & values()
Returns the values of this field.
Definition: Field1D.h:265
static constexpr unsigned int fieldDimension
Dimension of this multi field.
Definition: Field1D.h:117
Field1D()=default
Creates a new multi value field with no value.
Values values_
Field values.
Definition: Field1D.h:213
Type type() const override
Returns the type of this field.
Definition: Field1D.h:247
unsigned int dimension() const override
Returns the dimension of this field.
Definition: Field1D.h:253
Field1D(const Values &values, const Timestamp timestamp)
Creates a new multi value field by given initilization values.
Definition: Field1D.h:239
Field1D(const Values &values)
Creates a new multi value field by given initilization values.
Definition: Field1D.h:232
Field1D(const T &value)
Creates a new multi value field by a given initialization value.
Definition: Field1D.h:217
static constexpr Type fieldType
Scalar type of this multi field.
Definition: Field1D.h:114
Field * copy() const override
Returns a new instance of this field.
Definition: Field1D.h:285
void setValues(const Values &value, const Timestamp timestamp)
Sets the values of this field and defines an explicit modification timestamp.
Definition: Field1D.h:278
bool assign(const Field &field) override
Assigns a field to this field if both field have the identical field type.
Definition: Field1D.h:291
const Values & values() const
Returns the values of this field.
Definition: Field1D.h:259
Field1D(const T &value, const Timestamp timestamp)
Creates a new multi value field by a given initialization value.
Definition: Field1D.h:224
This class is the base class for all scene description fields.
Definition: Field.h:36
Timestamp timestamp() const
Returns the most recent field modification timestamp.
Definition: Field.h:197
Type
Definition of scalar field types.
Definition: Field.h:43
virtual Type type() const =0
Returns the type of this field.
virtual unsigned int dimension() const =0
Returns the dimension of this field.
static constexpr Field::Type type()
Returns the scalar field type for this mapper object.
Definition: FieldTyper.h:37
This class implements a timestamp.
Definition: Timestamp.h:36
Field1D< NodeRef > MultiNode
Definition of a multi field with node values.
Definition: Field1D.h:54
Field1D< Vector3 > MultiVector3
Definition of a multi field with 3D vector values.
Definition: Field1D.h:96
Field1D< int > MultiInt
Definition of a multi field with integer values.
Definition: Field1D.h:48
Field1D< bool > MultiBool
Definition of a multi field with boolean values.
Definition: Field1D.h:24
Field1D< Scalar > MultiFloat
Definition of a multi field with float values.
Definition: Field1D.h:42
Field1D< Vector2 > MultiVector2
Definition of a multi field with 2D vector values.
Definition: Field1D.h:90
Field1D< SquareMatrix3 > MultiMatrix3
Definition of a multi field with 3x3 matrix values.
Definition: Field1D.h:60
Field1D< Timestamp > MultiTime
Definition of a multi field with time values.
Definition: Field1D.h:84
Field1D< Vector4 > MultiVector4
Definition of a multi field with 4D vector values.
Definition: Field1D.h:102
Field1D< RGBAColor > MultiColor
Definition of a multi field with color values.
Definition: Field1D.h:36
Field1D< Rotation > MultiRotation
Definition of a multi field with rotation values.
Definition: Field1D.h:72
Field1D< SquareMatrix4 > MultiMatrix4
Definition of a multi field with 4x4 matrix values.
Definition: Field1D.h:66
Field1D< std::string > MultiString
Definition of a multi field with string values.
Definition: Field1D.h:78
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15