xref: /aosp_15_r20/frameworks/av/media/libheadtracking/PoseBias.h (revision ec779b8e0859a360c3d303172224686826e6e0e1)
1*ec779b8eSAndroid Build Coastguard Worker /*
2*ec779b8eSAndroid Build Coastguard Worker  * Copyright (C) 2022 The Android Open Source Project
3*ec779b8eSAndroid Build Coastguard Worker  *
4*ec779b8eSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*ec779b8eSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*ec779b8eSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*ec779b8eSAndroid Build Coastguard Worker  *
8*ec779b8eSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*ec779b8eSAndroid Build Coastguard Worker  *
10*ec779b8eSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*ec779b8eSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*ec779b8eSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*ec779b8eSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*ec779b8eSAndroid Build Coastguard Worker  * limitations under the License.
15*ec779b8eSAndroid Build Coastguard Worker  */
16*ec779b8eSAndroid Build Coastguard Worker #pragma once
17*ec779b8eSAndroid Build Coastguard Worker 
18*ec779b8eSAndroid Build Coastguard Worker #include "media/Pose.h"
19*ec779b8eSAndroid Build Coastguard Worker 
20*ec779b8eSAndroid Build Coastguard Worker namespace android {
21*ec779b8eSAndroid Build Coastguard Worker namespace media {
22*ec779b8eSAndroid Build Coastguard Worker 
23*ec779b8eSAndroid Build Coastguard Worker /**
24*ec779b8eSAndroid Build Coastguard Worker  * Biasing for a stream of poses.
25*ec779b8eSAndroid Build Coastguard Worker  *
26*ec779b8eSAndroid Build Coastguard Worker  * This filter takes a stream of poses and at any time during the stream, can change the frame of
27*ec779b8eSAndroid Build Coastguard Worker  * reference for the stream to be that of the last pose received, via the recenter() operation.
28*ec779b8eSAndroid Build Coastguard Worker  *
29*ec779b8eSAndroid Build Coastguard Worker  * Typical usage:
30*ec779b8eSAndroid Build Coastguard Worker  * PoseBias bias;
31*ec779b8eSAndroid Build Coastguard Worker  *
32*ec779b8eSAndroid Build Coastguard Worker  * bias.setInput(...);
33*ec779b8eSAndroid Build Coastguard Worker  * output = bias.getOutput();
34*ec779b8eSAndroid Build Coastguard Worker  * bias.setInput(...);
35*ec779b8eSAndroid Build Coastguard Worker  * output = bias.getOutput();
36*ec779b8eSAndroid Build Coastguard Worker  * bias.setInput(...);
37*ec779b8eSAndroid Build Coastguard Worker  * output = bias.getOutput();
38*ec779b8eSAndroid Build Coastguard Worker  * bias.recenter();  // Reference frame is now equal to the last input.
39*ec779b8eSAndroid Build Coastguard Worker  * output = bias.getOutput();  // This is now the identity pose.
40*ec779b8eSAndroid Build Coastguard Worker  *
41*ec779b8eSAndroid Build Coastguard Worker  * There doesn't need to be a 1:1 correspondence between setInput() and getOutput() calls.
42*ec779b8eSAndroid Build Coastguard Worker  * The initial bias point is identity.
43*ec779b8eSAndroid Build Coastguard Worker  *
44*ec779b8eSAndroid Build Coastguard Worker  * This implementation is thread-compatible, but not thread-safe.
45*ec779b8eSAndroid Build Coastguard Worker  */
46*ec779b8eSAndroid Build Coastguard Worker class PoseBias {
47*ec779b8eSAndroid Build Coastguard Worker   public:
48*ec779b8eSAndroid Build Coastguard Worker     void setInput(const Pose3f& input);
49*ec779b8eSAndroid Build Coastguard Worker 
50*ec779b8eSAndroid Build Coastguard Worker     void recenter();
51*ec779b8eSAndroid Build Coastguard Worker 
52*ec779b8eSAndroid Build Coastguard Worker     Pose3f getOutput() const;
53*ec779b8eSAndroid Build Coastguard Worker 
54*ec779b8eSAndroid Build Coastguard Worker   private:
55*ec779b8eSAndroid Build Coastguard Worker     Pose3f mLastWorldToInput;
56*ec779b8eSAndroid Build Coastguard Worker     Pose3f mBiasToWorld;
57*ec779b8eSAndroid Build Coastguard Worker };
58*ec779b8eSAndroid Build Coastguard Worker 
59*ec779b8eSAndroid Build Coastguard Worker }  // namespace media
60*ec779b8eSAndroid Build Coastguard Worker }  // namespace android
61