blob: ee811002e8c514fb06e9b1a32cb2aaf6cbed4fe1 [file] [log] [blame]
Ytai Ben-Tsvicbee7d42021-06-15 00:39:31 -07001/*
2 * Copyright (C) 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#pragma once
17
18#include <optional>
19
20#include "media/Pose.h"
21
22namespace android {
23namespace media {
24
25/**
26 * Combines world-to-head pose with world-to-screen pose to obtain screen-to-head.
27 *
28 * Input poses may arrive separately. The last pose of each kind is taken into account. The
29 * timestamp of the output is the ealier (older) timestamp of the two inputs.
30 *
31 * Output may be nullopt in the following cases:
32 * - Either one of the inputs has not yet been provided.
33 * - It is estimated that the user is no longer facing the screen.
34 *
35 * Typical usage:
36 *
37 * ScreenHeadFusion fusion(...);
38 * fusion.setWorldToHeadPose(...);
39 * fusion.setWorldToScreenPose(...);
40 * auto output = fusion.calculate();
41 *
42 * This class is not thread-safe, but thread-compatible.
43 */
44class ScreenHeadFusion {
45 public:
46 struct TimestampedPose {
47 int64_t timestamp;
48 Pose3f pose;
49 };
50
51 void setWorldToHeadPose(int64_t timestamp, const Pose3f& worldToHead);
52
53 void setWorldToScreenPose(int64_t timestamp, const Pose3f& worldToScreen);
54
55 /**
56 * Returns the screen-to-head pose, or nullopt if invalid.
57 */
58 std::optional<TimestampedPose> calculate();
59
60 private:
61 std::optional<TimestampedPose> mWorldToHead;
62 std::optional<TimestampedPose> mWorldToScreen;
63};
64
65} // namespace media
66} // namespace android