PhotonVision C++ v2027.0.0-alpha-2
Loading...
Searching...
No Matches
RotTrlTransform3d.h
Go to the documentation of this file.
1/*
2 * Copyright (C) Photon Vision.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18#pragma once
19
20#include <vector>
21
22#include <wpi/math/geometry/Pose3d.hpp>
23#include <wpi/math/geometry/Rotation3d.hpp>
24#include <wpi/math/geometry/Translation3d.hpp>
25
26namespace photon {
28 public:
29 RotTrlTransform3d(const wpi::math::Rotation3d& newRot,
30 const wpi::math::Translation3d& newTrl)
31 : trl{newTrl}, rot{newRot} {}
32
33 RotTrlTransform3d(const wpi::math::Pose3d& initial,
34 const wpi::math::Pose3d& last)
35 : trl{last.Translation() -
36 initial.Translation().RotateBy(
37 last.Rotation().RelativeTo(initial.Rotation()))},
38 rot{last.Rotation().RelativeTo(initial.Rotation())} {}
39 explicit RotTrlTransform3d(const wpi::math::Transform3d& trf)
40 : RotTrlTransform3d(trf.Rotation(), trf.Translation()) {}
42 : RotTrlTransform3d(wpi::math::Rotation3d{}, wpi::math::Translation3d{}) {
43 }
44
45 static RotTrlTransform3d MakeRelativeTo(const wpi::math::Pose3d& pose) {
46 return RotTrlTransform3d{pose.Rotation(), pose.Translation()}.Inverse();
47 }
48
50 wpi::math::Rotation3d invRot = rot.Inverse();
51 wpi::math::Translation3d invTrl = -(trl.RotateBy(invRot));
52 return RotTrlTransform3d{invRot, invTrl};
53 }
54
55 wpi::math::Transform3d GetTransform() const {
56 return wpi::math::Transform3d{trl, rot};
57 }
58
59 wpi::math::Translation3d GetTranslation() const { return trl; }
60
61 wpi::math::Rotation3d GetRotation() const { return rot; }
62
63 wpi::math::Translation3d Apply(
64 const wpi::math::Translation3d& trlToApply) const {
65 return trlToApply.RotateBy(rot) + trl;
66 }
67
68 std::vector<wpi::math::Translation3d> ApplyTrls(
69 const std::vector<wpi::math::Translation3d>& trls) const {
70 std::vector<wpi::math::Translation3d> retVal;
71 retVal.reserve(trls.size());
72 for (const auto& currentTrl : trls) {
73 retVal.emplace_back(Apply(currentTrl));
74 }
75 return retVal;
76 }
77
78 wpi::math::Rotation3d Apply(const wpi::math::Rotation3d& rotToApply) const {
79 return rotToApply.RotateBy(rot);
80 }
81
82 std::vector<wpi::math::Rotation3d> ApplyTrls(
83 const std::vector<wpi::math::Rotation3d>& rots) const {
84 std::vector<wpi::math::Rotation3d> retVal;
85 retVal.reserve(rots.size());
86 for (const auto& currentRot : rots) {
87 retVal.emplace_back(Apply(currentRot));
88 }
89 return retVal;
90 }
91
92 wpi::math::Pose3d Apply(const wpi::math::Pose3d& poseToApply) const {
93 return wpi::math::Pose3d{Apply(poseToApply.Translation()),
94 Apply(poseToApply.Rotation())};
95 }
96
97 std::vector<wpi::math::Pose3d> ApplyPoses(
98 const std::vector<wpi::math::Pose3d>& poses) const {
99 std::vector<wpi::math::Pose3d> retVal;
100 retVal.reserve(poses.size());
101 for (const auto& currentPose : poses) {
102 retVal.emplace_back(Apply(currentPose));
103 }
104 return retVal;
105 }
106
107 private:
108 const wpi::math::Translation3d trl;
109 const wpi::math::Rotation3d rot;
110};
111} // namespace photon
Definition RotTrlTransform3d.h:27
RotTrlTransform3d Inverse() const
Definition RotTrlTransform3d.h:49
wpi::math::Translation3d Apply(const wpi::math::Translation3d &trlToApply) const
Definition RotTrlTransform3d.h:63
static RotTrlTransform3d MakeRelativeTo(const wpi::math::Pose3d &pose)
Definition RotTrlTransform3d.h:45
std::vector< wpi::math::Rotation3d > ApplyTrls(const std::vector< wpi::math::Rotation3d > &rots) const
Definition RotTrlTransform3d.h:82
wpi::math::Transform3d GetTransform() const
Definition RotTrlTransform3d.h:55
wpi::math::Pose3d Apply(const wpi::math::Pose3d &poseToApply) const
Definition RotTrlTransform3d.h:92
RotTrlTransform3d(const wpi::math::Transform3d &trf)
Definition RotTrlTransform3d.h:39
RotTrlTransform3d()
Definition RotTrlTransform3d.h:41
wpi::math::Rotation3d Apply(const wpi::math::Rotation3d &rotToApply) const
Definition RotTrlTransform3d.h:78
RotTrlTransform3d(const wpi::math::Rotation3d &newRot, const wpi::math::Translation3d &newTrl)
Definition RotTrlTransform3d.h:29
std::vector< wpi::math::Translation3d > ApplyTrls(const std::vector< wpi::math::Translation3d > &trls) const
Definition RotTrlTransform3d.h:68
std::vector< wpi::math::Pose3d > ApplyPoses(const std::vector< wpi::math::Pose3d > &poses) const
Definition RotTrlTransform3d.h:97
wpi::math::Translation3d GetTranslation() const
Definition RotTrlTransform3d.h:59
wpi::math::Rotation3d GetRotation() const
Definition RotTrlTransform3d.h:61
RotTrlTransform3d(const wpi::math::Pose3d &initial, const wpi::math::Pose3d &last)
Definition RotTrlTransform3d.h:33
Definition VisionEstimation.h:30
Definition TimeSyncServer.h:32