Ocean
Loading...
Searching...
No Matches
Gravities.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_TRACKING_SLAM_GRAVITIES_H
9#define META_OCEAN_TRACKING_SLAM_GRAVITIES_H
10
13
14namespace Ocean
15{
16
17namespace Tracking
18{
19
20namespace SLAM
21{
22
23/**
24 * This class implements a container for gravity vectors associated with frame indices.
25 * The object is thread-safe.
26 * @ingroup trackingslam
27 */
28class OCEAN_TRACKING_SLAM_EXPORT Gravities
29{
30 public:
31
32 /**
33 * Definition of an unordered map mapping frame indices to gravity vectors.
34 */
35 using GravityMap = std::unordered_map<Index32, Vector3>;
36
37 public:
38
39 /**
40 * Sets the gravity vector for a specific frame index.
41 * @param frameIndex The index of the frame for which the gravity will be set, with range [0, infinity)
42 * @param gravity The gravity vector to set
43 * @return True, always
44 */
45 inline bool setGravity(const Index32 frameIndex, const Vector3& gravity);
46
47 /**
48 * Returns whether this container holds a gravity vector for a specific frame index.
49 * @param frameIndex The index of the frame for which the gravity will be checked, with range [0, infinity)
50 * @param gravity Optional pointer to receive the gravity vector if it exists, nullptr to skip
51 * @return True, if the gravity vector exists for the specified frame index
52 */
53 inline bool hasGravity(const Index32 frameIndex, Vector3* gravity) const;
54
55 protected:
56
57 /// The map mapping frame indices to gravity vectors.
59
60 /// The mutex of this object.
61 mutable Mutex mutex_;
62};
63
64inline bool Gravities::setGravity(const Index32 frameIndex, const Vector3& gravity)
65{
66 const WriteLock writeLock(mutex_);
67
68 gravityMap_[frameIndex] = gravity;
69
70 return true;
71}
72
73inline bool Gravities::hasGravity(const Index32 frameIndex, Vector3* gravity) const
74{
75 const ReadLock readLock(mutex_);
76
77 const GravityMap::const_iterator iGravity = gravityMap_.find(frameIndex);
78
79 if (iGravity == gravityMap_.cend())
80 {
81 return false;
82 }
83
84 if (gravity != nullptr)
85 {
86 *gravity = iGravity->second;
87 }
88
89 return true;
90}
91
92}
93
94}
95
96}
97
98#endif // META_OCEAN_TRACKING_SLAM_GRAVITIES_H
This class implements a container for gravity vectors associated with frame indices.
Definition Gravities.h:29
bool setGravity(const Index32 frameIndex, const Vector3 &gravity)
Sets the gravity vector for a specific frame index.
Definition Gravities.h:64
Mutex mutex_
The mutex of this object.
Definition Gravities.h:61
bool hasGravity(const Index32 frameIndex, Vector3 *gravity) const
Returns whether this container holds a gravity vector for a specific frame index.
Definition Gravities.h:73
GravityMap gravityMap_
The map mapping frame indices to gravity vectors.
Definition Gravities.h:58
std::unordered_map< Index32, Vector3 > GravityMap
Definition of an unordered map mapping frame indices to gravity vectors.
Definition Gravities.h:35
This class implements a scoped read lock for a shared mutex.
Definition Mutex.h:261
This class implements a scoped write lock for a shared mutex.
Definition Mutex.h:323
uint32_t Index32
Definition of a 32 bit index value.
Definition Base.h:84
std::shared_mutex Mutex
Definition of a mutex supporting read and write locks.
Definition Mutex.h:78
The namespace covering the entire Ocean framework.
Definition Accessor.h:15