Welcome to mirror list, hosted at ThFree Co, Russian Federation.

reconstruction.h « simple_pipeline « libmv « libmv « intern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 544aeac042e33e7e375d0eb36d62919ce35b34af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
// Copyright (c) 2011 libmv authors.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.

#ifndef LIBMV_SIMPLE_PIPELINE_RECONSTRUCTION_H_
#define LIBMV_SIMPLE_PIPELINE_RECONSTRUCTION_H_

#include "libmv/base/vector.h"
#include "libmv/base/map.h"
#include "libmv/numeric/numeric.h"

namespace libmv {

/*!
    A EuclideanCamera is the location and rotation of the camera viewing \a image.

    \a image identify which image from \link Tracks this camera represents.
    \a R is a 3x3 matrix representing the rotation of the camera.
    \a t is a translation vector representing its positions.

    \sa Reconstruction
*/
struct EuclideanCamera {
  EuclideanCamera() : image(-1) {}
  EuclideanCamera(const EuclideanCamera &c) : image(c.image), R(c.R), t(c.t) {}

  int image;
  Mat3 R;
  Vec3 t;
};

/*!
    A Point is the 3D location of a track.

    \a track identify which track from \link Tracks this point corresponds to.
    \a X represents the 3D position of the track.

    \sa Reconstruction
*/
struct EuclideanPoint {
  EuclideanPoint() : track(-1) {}
  EuclideanPoint(const EuclideanPoint &p) : track(p.track), X(p.X) {}
  int track;
  Vec3 X;
};

/*!
    The EuclideanReconstruction class stores \link EuclideanCamera cameras
    \endlink and \link EuclideanPoint points \endlink.

    The EuclideanReconstruction container is intended as the store of 3D
    reconstruction data to be used with the MultiView API.

    The container has lookups to query a \a EuclideanCamera from an \a image or
    a \a EuclideanPoint from a \a track.

    \sa Camera, Point
*/
class EuclideanReconstruction {
 public:
  // Default constructor starts with no cameras.
  EuclideanReconstruction();

  /// Copy constructor.
  EuclideanReconstruction(const EuclideanReconstruction &other);

  EuclideanReconstruction &operator=(const EuclideanReconstruction &other);

  /*!
      Insert a camera into the set. If there is already a camera for the given
      \a image, the existing camera is replaced. If there is no camera for the
      given \a image, a new one is added.

      \a image is the key used to retrieve the cameras with the other methods
      in this class.

      \note You should use the same \a image identifier as in \link Tracks.
  */
  void InsertCamera(int image, const Mat3 &R, const Vec3 &t);

  /*!
      Insert a point into the reconstruction. If there is already a point for
      the given \a track, the existing point is replaced. If there is no point
      for the given \a track, a new one is added.

      \a track is the key used to retrieve the points with the
      other methods in this class.

      \note You should use the same \a track identifier as in \link Tracks.
  */
  void InsertPoint(int track, const Vec3 &X);

  /// Returns a pointer to the camera corresponding to \a image.
  EuclideanCamera *CameraForImage(int image);
  const EuclideanCamera *CameraForImage(int image) const;

  /// Returns all cameras.
  vector<EuclideanCamera> AllCameras() const;

  /// Returns a pointer to the point corresponding to \a track.
  EuclideanPoint *PointForTrack(int track);
  const EuclideanPoint *PointForTrack(int track) const;

  /// Returns all points.
  vector<EuclideanPoint> AllPoints() const;

 private:
  // Indexed by frame number.
  typedef map<int, EuclideanCamera> ImageToCameraMap;
  ImageToCameraMap image_to_cameras_map_;

  // Insxed by track.
  vector<EuclideanPoint> points_;
};

/*!
    A ProjectiveCamera is the projection matrix for the camera of \a image.

    \a image identify which image from \link Tracks this camera represents.
    \a P is the 3x4 projection matrix.

    \sa ProjectiveReconstruction
*/
struct ProjectiveCamera {
  ProjectiveCamera() : image(-1) {}
  ProjectiveCamera(const ProjectiveCamera &c) : image(c.image), P(c.P) {}

  int image;
  Mat34 P;
};

/*!
    A Point is the 3D location of a track.

    \a track identifies which track from \link Tracks this point corresponds to.
    \a X is the homogeneous 3D position of the track.

    \sa Reconstruction
*/
struct ProjectivePoint {
  ProjectivePoint() : track(-1) {}
  ProjectivePoint(const ProjectivePoint &p) : track(p.track), X(p.X) {}
  int track;
  Vec4 X;
};

/*!
    The ProjectiveReconstruction class stores \link ProjectiveCamera cameras
    \endlink and \link ProjectivePoint points \endlink.

    The ProjectiveReconstruction container is intended as the store of 3D
    reconstruction data to be used with the MultiView API.

    The container has lookups to query a \a ProjectiveCamera from an \a image or
    a \a ProjectivePoint from a \a track.

    \sa Camera, Point
*/
class ProjectiveReconstruction {
 public:
  /*!
      Insert a camera into the set. If there is already a camera for the given
      \a image, the existing camera is replaced. If there is no camera for the
      given \a image, a new one is added.

      \a image is the key used to retrieve the cameras with the other methods
      in this class.

      \note You should use the same \a image identifier as in \link Tracks.
  */
  void InsertCamera(int image, const Mat34 &P);

  /*!
      Insert a point into the reconstruction. If there is already a point for
      the given \a track, the existing point is replaced. If there is no point
      for the given \a track, a new one is added.

      \a track is the key used to retrieve the points with the
      other methods in this class.

      \note You should use the same \a track identifier as in \link Tracks.
  */
  void InsertPoint(int track, const Vec4 &X);

  /// Returns a pointer to the camera corresponding to \a image.
  ProjectiveCamera *CameraForImage(int image);
  const ProjectiveCamera *CameraForImage(int image) const;

  /// Returns all cameras.
  vector<ProjectiveCamera> AllCameras() const;

  /// Returns a pointer to the point corresponding to \a track.
  ProjectivePoint *PointForTrack(int track);
  const ProjectivePoint *PointForTrack(int track) const;

  /// Returns all points.
  vector<ProjectivePoint> AllPoints() const;

 private:
  // Indexed by frame number.
  typedef map<int, ProjectiveCamera> ImageToCameraMap;
  ImageToCameraMap image_to_cameras_map_;

  // Indexed by track.
  vector<ProjectivePoint> points_;
};

}  // namespace libmv

#endif  // LIBMV_SIMPLE_PIPELINE_RECONSTRUCTION_H_