AliceVision
Photogrammetric Computer Vision Framework
View.hpp
1 // This file is part of the AliceVision project.
2 // Copyright (c) 2016 AliceVision contributors.
3 // Copyright (c) 2012 openMVG contributors.
4 // This Source Code Form is subject to the terms of the Mozilla Public License,
5 // v. 2.0. If a copy of the MPL was not distributed with this file,
6 // You can obtain one at https://mozilla.org/MPL/2.0/.
7 
8 #pragma once
9 
10 #include <aliceVision/types.hpp>
11 #include <aliceVision/numeric/numeric.hpp>
12 #include <aliceVision/image/dcp.hpp>
13 #include <aliceVision/sensorDB/Datasheet.hpp>
14 #include <aliceVision/camera/IntrinsicInitMode.hpp>
15 #include <aliceVision/lensCorrectionProfile/lcp.hpp>
16 
17 #include <aliceVision/sfmData/ImageInfo.hpp>
18 #include <aliceVision/sfmData/exif.hpp>
19 #include <aliceVision/sfmData/ExposureSetting.hpp>
20 
21 #include <regex>
22 #include <string>
23 #include <utility>
24 
25 namespace aliceVision {
26 namespace sfmData {
27 
32 class View
33 {
34  public:
35  using sptr = std::shared_ptr<View>;
36  using ptr = View*;
37 
38  public:
51  View(const std::string& imagePath = "",
52  IndexT viewId = UndefinedIndexT,
53  IndexT intrinsicId = UndefinedIndexT,
54  IndexT poseId = UndefinedIndexT,
55  std::size_t width = 0,
56  std::size_t height = 0,
57  IndexT rigId = UndefinedIndexT,
58  IndexT subPoseId = UndefinedIndexT,
59  const std::map<std::string, std::string>& metadata = std::map<std::string, std::string>())
60  : _viewId(viewId),
61  _intrinsicId(intrinsicId),
62  _poseId(poseId),
63  _rigId(rigId),
64  _subPoseId(subPoseId),
65  _image(new ImageInfo(imagePath, width, height, metadata))
66  {}
67 
68  View(const View& v) = default;
69 
70 
75  View* shallowClone() { return new View(*this); }
76 
81  View* clone() const
82  {
83  View* v = new View(*this);
84  v->_image = std::make_shared<ImageInfo>(*this->_image);
85  return v;
86  }
87 
88  bool operator==(const View& other) const
89  {
90  // image paths can be different
91  return _viewId == other._viewId && _intrinsicId == other._intrinsicId && _poseId == other._poseId && _rigId == other._rigId &&
92  _subPoseId == other._subPoseId && _imageGroupId == other._imageGroupId;
93  }
94 
95  inline bool operator!=(const View& other) const { return !(*this == other); }
96 
101  const ImageInfo& getImage() const { return *_image; }
102 
107  ImageInfo& getImage() { return *_image; }
108 
113  std::shared_ptr<ImageInfo> getImageInfo() { return _image; }
114 
119  IndexT getViewId() const { return _viewId; }
120 
125  IndexT getImageGroupId() const { return _imageGroupId; }
126 
131  IndexT getIntrinsicId() const { return _intrinsicId; }
132 
137  IndexT getPoseId() const { return _poseId; }
138 
143  IndexT getRigId() const { return _rigId; }
144 
149  IndexT getSubPoseId() const { return _subPoseId; }
150 
155  IndexT getFrameId() const { return _frameId; }
156 
161  IndexT getResectionId() const { return _resectionId; }
162 
167  bool isPartOfRig() const { return _rigId != UndefinedIndexT; }
168 
175  bool isPoseIndependant() const { return (!isPartOfRig() || _isPoseIndependent); }
176 
181  void setViewId(IndexT viewId) { _viewId = viewId; }
182 
187  void setImageGroupId(IndexT imageGroupId) { _imageGroupId = imageGroupId; }
188 
193  void setIntrinsicId(IndexT intrinsicId) { _intrinsicId = intrinsicId; }
194 
199  void setPoseId(IndexT poseId) { _poseId = poseId; }
200 
205  void setIndependantPose(bool independent) { _isPoseIndependent = independent; }
206 
212  void setRigAndSubPoseId(IndexT rigId, IndexT subPoseId)
213  {
214  _rigId = rigId;
215  _subPoseId = subPoseId;
216  }
217 
222  void setFrameId(IndexT frameId) { _frameId = frameId; }
223 
228  const std::vector<IndexT>& getAncestors() const { return _ancestors; }
229 
238  void addAncestor(IndexT image)
239  {
240  if (std::find(_ancestors.begin(), _ancestors.end(), image) == _ancestors.end())
241  {
242  _ancestors.push_back(image);
243  }
244  }
245 
250  void setResectionId(IndexT resectionId) { _resectionId = resectionId; }
251 
257  {
258  return (getViewId() != UndefinedIndexT && getIntrinsicId() != UndefinedIndexT && getPoseId() == getViewId());
259  }
260 
261  private:
263  IndexT _viewId;
265  IndexT _intrinsicId;
267  IndexT _poseId;
269  IndexT _rigId;
271  IndexT _subPoseId;
273  IndexT _imageGroupId = UndefinedIndexT;
275  IndexT _frameId = UndefinedIndexT;
277  IndexT _resectionId = UndefinedIndexT;
279  bool _isPoseIndependent = true;
281  std::vector<IndexT> _ancestors;
283  std::shared_ptr<ImageInfo> _image;
284 };
285 
286 } // namespace sfmData
287 } // namespace aliceVision
aliceVision::sfmData::View::setFrameId
void setFrameId(IndexT frameId)
Set the given frame id.
Definition: View.hpp:222
aliceVision::sfmData::View::getAncestors
const std::vector< IndexT > & getAncestors() const
Definition: View.hpp:228
aliceVision::sfmData::View::getViewId
IndexT getViewId() const
Get the view id.
Definition: View.hpp:119
aliceVision::sfmData::View::setViewId
void setViewId(IndexT viewId)
Set the given view id.
Definition: View.hpp:181
aliceVision::sfmData::View::getPoseId
IndexT getPoseId() const
Get the pose id.
Definition: View.hpp:137
aliceVision::sfmData::View::setIndependantPose
void setIndependantPose(bool independent)
setIndependantPose
Definition: View.hpp:205
aliceVision::sfmData::View::getFrameId
IndexT getFrameId() const
Get the frame id.
Definition: View.hpp:155
aliceVision::sfmData::View::View
View(const std::string &imagePath="", IndexT viewId=UndefinedIndexT, IndexT intrinsicId=UndefinedIndexT, IndexT poseId=UndefinedIndexT, std::size_t width=0, std::size_t height=0, IndexT rigId=UndefinedIndexT, IndexT subPoseId=UndefinedIndexT, const std::map< std::string, std::string > &metadata=std::map< std::string, std::string >())
View Constructor.
Definition: View.hpp:51
aliceVision
Definition: checkerDetector.cpp:32
aliceVision::sfmData::View
A view define an image by a string and unique indexes for the view, the camera intrinsic,...
Definition: View.hpp:32
aliceVision::sfmData::View::isPoseIndependant
bool isPoseIndependant() const
If the view is part of a camera rig, the camera can be a sub-pose of the rig pose but can also be tem...
Definition: View.hpp:175
aliceVision::sfmData::View::getImage
ImageInfo & getImage()
Get Image info object.
Definition: View.hpp:107
aliceVision::sfmData::View::getRigId
IndexT getRigId() const
Get the rig id.
Definition: View.hpp:143
aliceVision::sfmData::View::isPartOfRig
bool isPartOfRig() const
Return if true or false the view is part of a rig.
Definition: View.hpp:167
aliceVision::sfmData::View::isFullySetup
bool isFullySetup()
Check if the view has the minimal identifiers required for processing.
Definition: View.hpp:256
aliceVision::sfmData::View::getIntrinsicId
IndexT getIntrinsicId() const
Get the intrinsic id.
Definition: View.hpp:131
aliceVision::sfmData::View::shallowClone
View * shallowClone()
Shallow View Copy return a pointer to a new View.
Definition: View.hpp:75
aliceVision::sfmData::View::setPoseId
void setPoseId(IndexT poseId)
Set the given pose id.
Definition: View.hpp:199
aliceVision::sfmData::View::setRigAndSubPoseId
void setRigAndSubPoseId(IndexT rigId, IndexT subPoseId)
Set the given rig id and the given sub-pose id.
Definition: View.hpp:212
aliceVision::sfmData::View::getImage
const ImageInfo & getImage() const
Get Image info object.
Definition: View.hpp:101
aliceVision::sfmData::View::getImageGroupId
IndexT getImageGroupId() const
Get the image group id.
Definition: View.hpp:125
aliceVision::sfmData::View::setResectionId
void setResectionId(IndexT resectionId)
Set the given resection id.
Definition: View.hpp:250
aliceVision::sfmData::View::setIntrinsicId
void setIntrinsicId(IndexT intrinsicId)
Set the given intrinsic id.
Definition: View.hpp:193
aliceVision::sfmData::View::getImageInfo
std::shared_ptr< ImageInfo > getImageInfo()
Get Image info pointer.
Definition: View.hpp:113
aliceVision::sfmData::View::clone
View * clone() const
Deep View Copy return a pointer to a new View.
Definition: View.hpp:81
aliceVision::sfmData::View::getSubPoseId
IndexT getSubPoseId() const
Get the sub-pose id.
Definition: View.hpp:149
aliceVision::sfmData::View::getResectionId
IndexT getResectionId() const
Get the resection id.
Definition: View.hpp:161
aliceVision::sfmData::View::addAncestor
void addAncestor(IndexT image)
Add an ancestor images to the existing ones. If an image is generated from multiple input images,...
Definition: View.hpp:238
aliceVision::sfmData::View::setImageGroupId
void setImageGroupId(IndexT imageGroupId)
Set the given image group id.
Definition: View.hpp:187
aliceVision::sfmData::ImageInfo
Definition: ImageInfo.hpp:23