Berkeley SfM
observation.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015, The Regents of the University of California (Regents).
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above
13  * copyright notice, this list of conditions and the following
14  * disclaimer in the documentation and/or other materials provided
15  * with the distribution.
16  *
17  * 3. Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  *
33  * Please contact the author(s) of this library if you have any questions.
34  * Authors: Erik Nelson ( eanelson@eecs.berkeley.edu )
35  * David Fridovich-Keil ( dfk@eecs.berkeley.edu )
36  */
37 
38 #include "observation.h"
39 
40 #include "landmark.h"
41 #include "../sfm/view.h"
42 
43 namespace bsfm {
44 
45 // Factory method.
46 Observation::Ptr Observation::Create(const std::shared_ptr<View>& view_ptr,
47  const ::bsfm::Feature& feature,
48  const ::bsfm::Descriptor& descriptor) {
49  Observation::Ptr observation(new Observation(view_ptr, feature, descriptor));
50  view_ptr->AddObservation(observation);
51  return observation;
52 }
53 
55 
56 // Get the view that this observation was seen from.
57 std::shared_ptr<View> Observation::GetView() const {
58  if (view_index_ == kInvalidView) {
59  LOG(WARNING) << "View index is invalid. Returning a null pointer.";
60  return View::Ptr();
61  }
62 
64  CHECK_NOTNULL(view.get());
65  return view;
66 }
67 
68 // Get the landmark that this observation corresponds to. Returns a null
69 // pointer if the observation has not been matched with a landmark.
72  LOG(WARNING) << "Landmark index is invalid. Returning a null pointer.";
73  return Landmark::Ptr();
74  }
75 
77  CHECK_NOTNULL(landmark.get());
78  return landmark;
79 }
80 
81 // Sets the landmark as a potential match for this observation. The observation
82 // still has not been incorporated into the landmark.
84  CHECK_NE(kInvalidLandmark, landmark_index);
85  landmark_index_ = landmark_index;
86  is_matched_ = true;
87 }
88 
89 // Returns whether or not the observation has been matched with a landmark. If
90 // this returns false, 'GetLandmark()' will return a null pointer.
91 bool Observation::IsMatched() const {
92  return is_matched_;
93 }
94 
95 // Associates a landmark with this observation. This is called by
96 // Landmark::IncorporateObservation().
98  CHECK_NE(kInvalidLandmark, landmark_index);
99  landmark_index_ = landmark_index;
100  is_matched_ = true;
101  is_incorporated_ = true;
102 }
103 
104 // Returns whether or not the observation has been incorporated into a landmark.
106  return is_incorporated_;
107 }
108 
109 // Get this observation's feature.
110 const ::bsfm::Feature& Observation::Feature() const {
111  return feature_;
112 }
113 
114 // Get the descriptor corresponding to this observation's feature.
116  return descriptor_;
117 }
118 
119 // Constructor is private to enforce usage of factory method. Initialize an
120 // observation with the view that it came from, an image-space feature
121 // coordinate pair, and an associated descriptor. Implicitly initializes the
122 // landmark to be invalid, since the observation has not been matched with a 3D
123 // landmark yet.
124 Observation::Observation(const View::Ptr& view_ptr,
125  const ::bsfm::Feature& feature,
126  const ::bsfm::Descriptor& descriptor)
127  : landmark_index_(kInvalidLandmark),
128  is_matched_(false),
129  is_incorporated_(false),
130  feature_(feature),
131  descriptor_(descriptor) {
132  // Store the view's index to access it later.
133  CHECK_NOTNULL(view_ptr.get());
134  view_index_ = view_ptr->Index();
135 }
136 
137 } //\namespace bsfm
std::shared_ptr< Landmark > GetLandmark() const
Definition: observation.cpp:70
std::shared_ptr< Observation > Ptr
Definition: observation.h:65
bool IsMatched() const
Definition: observation.cpp:91
static Landmark::Ptr GetLandmark(LandmarkIndex landmark_index)
Definition: landmark.cpp:59
ViewIndex view_index_
Definition: observation.h:119
unsigned int LandmarkIndex
Definition: types.h:62
LandmarkIndex landmark_index_
Definition: observation.h:123
static constexpr LandmarkIndex kInvalidLandmark
Definition: types.h:66
static constexpr ViewIndex kInvalidView
Definition: types.h:65
const ::bsfm::Feature & Feature() const
static Observation::Ptr Create(const std::shared_ptr< View > &view_ptr, const ::bsfm::Feature &feature, const ::bsfm::Descriptor &descriptor)
Definition: observation.cpp:46
::bsfm::Feature feature_
Definition: observation.h:135
const ::bsfm::Descriptor & Descriptor() const
std::shared_ptr< View > GetView() const
Definition: observation.cpp:57
static View::Ptr GetView(ViewIndex view_index)
Definition: view.cpp:60
Definition: camera.cpp:50
::bsfm::Descriptor descriptor_
Definition: observation.h:138
void SetMatchedLandmark(LandmarkIndex landmark_index)
Definition: observation.cpp:83
std::shared_ptr< Landmark > Ptr
Definition: landmark.h:66
bool IsIncorporated() const
std::shared_ptr< View > Ptr
Definition: view.h:66
::Eigen::Matrix< double, Eigen::Dynamic, 1 > Descriptor
Definition: types.h:83
void SetIncorporatedLandmark(LandmarkIndex landmark_index)
Definition: observation.cpp:97