AliceVision
Photogrammetric Computer Vision Framework
CameraPose.hpp
1 // This file is part of the AliceVision project.
2 // Copyright (c) 2018 AliceVision contributors.
3 // This Source Code Form is subject to the terms of the Mozilla Public License,
4 // v. 2.0. If a copy of the MPL was not distributed with this file,
5 // You can obtain one at https://mozilla.org/MPL/2.0/.
6 
7 #pragma once
8 
9 #include <aliceVision/types.hpp>
10 #include <aliceVision/geometry/Pose3.hpp>
11 
12 namespace aliceVision {
13 namespace sfmData {
14 
16 {
17  public:
18  using ptr = CameraPose*;
19  using sptr = std::shared_ptr<CameraPose>;
20  public:
24  CameraPose() = default;
25 
31  explicit CameraPose(const geometry::Pose3& transform, bool locked = false)
32  : _transform(transform),
33  _locked(locked)
34  {}
35 
36  CameraPose::ptr clone() const
37  {
38  return new CameraPose(*this);
39  }
40 
45  inline const geometry::Pose3& getTransform() const { return _transform; }
46 
51  inline bool isLocked() const { return _locked; }
52 
56  inline bool operator==(const CameraPose& other) const { return (_transform == other._transform && _locked == other._locked); }
57 
62  inline void setTransform(const geometry::Pose3& transform) { _transform = transform; }
63 
67  inline void lock() { _locked = true; }
68 
72  inline void unlock() { _locked = false; }
73 
74  void initializeState()
75  {
76  if (_locked)
77  {
78  _state = EEstimatorParameterState::CONSTANT;
79  }
80  else
81  {
82  _state = EEstimatorParameterState::REFINED;
83  }
84  }
85 
86  EEstimatorParameterState getState() const { return _state; }
87 
88  void setState(EEstimatorParameterState state) { _state = state; }
89 
90  bool isRotationOnly() const
91  {
92  return _rotationOnly;
93  }
94 
99  void setRotationOnly(bool partial)
100  {
101  _rotationOnly = partial;
102  }
103 
108  void setRemovable(bool removable)
109  {
110  _removable = removable;
111  }
112 
117  bool isRemovable() const
118  {
119  return _removable;
120  }
121 
122  inline void updateFromEstimator(const std::array<double, 6> & data)
123  {
124  // do not update a camera pose set as Ignored or Constant in the Local strategy
125  if (getState() != EEstimatorParameterState::REFINED)
126  {
127  return;
128  }
129 
130  const Vec3 r_refined(data.at(0), data.at(1), data.at(2));
131  const Vec3 c_refined(data.at(3), data.at(4), data.at(5));
132 
133  const Mat3 R_refined = SO3::expm(r_refined);
134 
135  // update the pose
136  setTransform(geometry::Pose3(R_refined, c_refined));
137  }
138 
139  private:
141  geometry::Pose3 _transform;
143  bool _locked = false;
145  bool _rotationOnly = false;
147  bool _removable = true;
149  EEstimatorParameterState _state = EEstimatorParameterState::REFINED;
150 };
151 
152 } // namespace sfmData
153 } // namespace aliceVision
aliceVision::sfmData::CameraPose::CameraPose
CameraPose(const geometry::Pose3 &transform, bool locked=false)
CameraPose constructor.
Definition: CameraPose.hpp:31
aliceVision::EEstimatorParameterState
EEstimatorParameterState
Defines the state of a parameter for an estimator.
Definition: types.hpp:38
aliceVision::sfmData::CameraPose::isLocked
bool isLocked() const
Get the lock state of the camera.
Definition: CameraPose.hpp:51
aliceVision::sfmData::CameraPose::getTransform
const geometry::Pose3 & getTransform() const
Get the 3d transformation of the camera.
Definition: CameraPose.hpp:45
aliceVision::sfmData::CameraPose::operator==
bool operator==(const CameraPose &other) const
operator ==
Definition: CameraPose.hpp:56
aliceVision
Definition: checkerDetector.cpp:32
aliceVision::sfmData::CameraPose::setRotationOnly
void setRotationOnly(bool partial)
Definition: CameraPose.hpp:99
aliceVision::sfmData::CameraPose
Definition: CameraPose.hpp:15
aliceVision::sfmData::CameraPose::unlock
void unlock()
unlock the camera pose
Definition: CameraPose.hpp:72
aliceVision::sfmData::CameraPose::CameraPose
CameraPose()=default
CameraPose default constructor.
aliceVision::sfmData::CameraPose::setTransform
void setTransform(const geometry::Pose3 &transform)
Set the 3d transformation of the camera.
Definition: CameraPose.hpp:62
aliceVision::sfmData::CameraPose::isRemovable
bool isRemovable() const
Can this pose be removed from sfmdata given heuristics ?
Definition: CameraPose.hpp:117
aliceVision::sfmData::CameraPose::lock
void lock()
lock the camera pose
Definition: CameraPose.hpp:67
aliceVision::sfmData::CameraPose::setRemovable
void setRemovable(bool removable)
Can this pose be removed from sfmdata given heuristics ?
Definition: CameraPose.hpp:108
aliceVision::geometry::Pose3
Definition: Pose3.hpp:18