Berkeley SfM
observation.h
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 ///////////////////////////////////////////////////////////////////////////////
39 //
40 // The Observation struct defines an observation of a feature (with associated
41 // descriptor) from a specific camera view. This also includes the 3D point
42 // landmark that the feature corresponds to, if the observation has been
43 // matched.
44 //
45 ///////////////////////////////////////////////////////////////////////////////
46 
47 #ifndef BSFM_SLAM_OBSERVATION_H
48 #define BSFM_SLAM_OBSERVATION_H
49 
50 #include <gflags/gflags.h>
51 #include <glog/logging.h>
52 #include <memory>
53 
54 #include "../matching/distance_metric.h"
55 #include "../matching/feature.h"
56 #include "../util/types.h"
57 
58 namespace bsfm {
59 
60 class Landmark;
61 class View;
62 
63 class Observation {
64  public:
65  typedef std::shared_ptr<Observation> Ptr;
66  typedef std::shared_ptr<const Observation> ConstPtr;
67 
68  // Factory method. Creating an observation will automatically call
69  // view_ptr->AddObservation(this), to register the new observation with the
70  // view.
71  static Observation::Ptr Create(const std::shared_ptr<View>& view_ptr,
72  const ::bsfm::Feature& feature,
73  const ::bsfm::Descriptor& descriptor);
74  ~Observation();
75 
76  // Get the view that this observation was seen from.
77  std::shared_ptr<View> GetView() const;
78 
79  // Get the landmark that this observation corresponds to. Returns a null
80  // pointer if the observation has not been matched with a landmark.
81  std::shared_ptr<Landmark> GetLandmark() const;
82 
83  // Sets a landmark as a potential match for this observation. The observation
84  // has still not been incorporated into the landmark.
85  void SetMatchedLandmark(LandmarkIndex landmark_index);
86 
87  // Returns whether or not the observation has been matched with a landmark. If
88  // this returns false, 'GetLandmark()' will return a null pointer.
89  bool IsMatched() const;
90 
91  // Associates a landmark with this observation. This is called by
92  // Landmark::IncorporateObservation();
93  void SetIncorporatedLandmark(LandmarkIndex landmark_index);
94 
95  // Returns whether or not the observation has been incorporated with its
96  // landmark.
97  bool IsIncorporated() const;
98 
99  // Get this observation's feature.
100  const ::bsfm::Feature& Feature() const;
101 
102  // Get the descriptor corresponding to this observation's feature.
104 
105  private:
106  // No default constructor.
107  Observation();
108 
109  // Hide constructor to enforce use of factory method. Initialize an
110  // observation with the view that it came from, an image-space feature
111  // coordinate pair, and an associated descriptor. Implicitly initializes the
112  // landmark to be invalid, since the observation has not been matched with a
113  // 3D landmark yet.
114  Observation(const std::shared_ptr<View>& view_ptr,
115  const ::bsfm::Feature& feature,
116  const ::bsfm::Descriptor& descriptor);
117 
118  // The index corresponding to the view that this feature was observed from.
120 
121  // The 3D point landmark that this observation is made from. This index is
122  // undefined until the observation and a landmark have been matched.
124 
125  // A boolean flag describing whether or not this observation of a feature has
126  // been matched with a 3D point landmark.
128 
129  // A boolean flag describing whether or not this observation of a feature has
130  // been incorporated into its landmark, and used to triangulate that
131  // landmark's position.
133 
134  // A feature containing the (u, v) image space coordinates of the observation.
136 
137  // A descriptor associated with the feature.
139 }; //\class Observation
140 
141 } //\namespace bsfm
142 
143 #endif
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
unsigned int ViewIndex
Definition: types.h:58
ViewIndex view_index_
Definition: observation.h:119
unsigned int LandmarkIndex
Definition: types.h:62
LandmarkIndex landmark_index_
Definition: observation.h:123
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
std::shared_ptr< const Observation > ConstPtr
Definition: observation.h:66
const ::bsfm::Descriptor & Descriptor() const
std::shared_ptr< View > GetView() const
Definition: observation.cpp:57
Definition: camera.cpp:50
::bsfm::Descriptor descriptor_
Definition: observation.h:138
void SetMatchedLandmark(LandmarkIndex landmark_index)
Definition: observation.cpp:83
bool IsIncorporated() const
::Eigen::Matrix< double, Eigen::Dynamic, 1 > Descriptor
Definition: types.h:83
void SetIncorporatedLandmark(LandmarkIndex landmark_index)
Definition: observation.cpp:97