Blender  V3.3
libmv/simple_pipeline/tracks.cc
Go to the documentation of this file.
1 // Copyright (c) 2011 libmv authors.
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to
5 // deal in the Software without restriction, including without limitation the
6 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 // sell copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19 // IN THE SOFTWARE.
20 
22 
23 #include <algorithm>
24 #include <iterator>
25 #include <vector>
26 
27 #include "libmv/numeric/numeric.h"
28 
29 namespace libmv {
30 
31 Tracks::Tracks(const Tracks& other) {
32  markers_ = other.markers_;
33 }
34 
36 }
37 
38 void Tracks::Insert(int image, int track, double x, double y, double weight) {
39  // TODO(keir): Wow, this is quadratic for repeated insertions. Fix this by
40  // adding a smarter data structure like a set<>.
41  for (int i = 0; i < markers_.size(); ++i) {
42  if (markers_[i].image == image && markers_[i].track == track) {
43  markers_[i].x = x;
44  markers_[i].y = y;
45  return;
46  }
47  }
48  Marker marker = {image, track, x, y, weight};
49  markers_.push_back(marker);
50 }
51 
53  return markers_;
54 }
55 
58  for (int i = 0; i < markers_.size(); ++i) {
59  if (image == markers_[i].image) {
60  markers.push_back(markers_[i]);
61  }
62  }
63  return markers;
64 }
65 
68  for (int i = 0; i < markers_.size(); ++i) {
69  if (track == markers_[i].track) {
70  markers.push_back(markers_[i]);
71  }
72  }
73  return markers;
74 }
75 
76 vector<Marker> Tracks::MarkersInBothImages(int image1, int image2) const {
78  for (int i = 0; i < markers_.size(); ++i) {
79  int image = markers_[i].image;
80  if (image == image1 || image == image2)
81  markers.push_back(markers_[i]);
82  }
83  return markers;
84 }
85 
87  int image2) const {
88  std::vector<int> image1_tracks;
89  std::vector<int> image2_tracks;
90 
91  for (int i = 0; i < markers_.size(); ++i) {
92  int image = markers_[i].image;
93  if (image == image1) {
94  image1_tracks.push_back(markers_[i].track);
95  } else if (image == image2) {
96  image2_tracks.push_back(markers_[i].track);
97  }
98  }
99 
100  std::sort(image1_tracks.begin(), image1_tracks.end());
101  std::sort(image2_tracks.begin(), image2_tracks.end());
102 
103  std::vector<int> intersection;
104  std::set_intersection(image1_tracks.begin(),
105  image1_tracks.end(),
106  image2_tracks.begin(),
107  image2_tracks.end(),
108  std::back_inserter(intersection));
109 
111  for (int i = 0; i < markers_.size(); ++i) {
112  if ((markers_[i].image == image1 || markers_[i].image == image2) &&
113  std::binary_search(
114  intersection.begin(), intersection.end(), markers_[i].track)) {
115  markers.push_back(markers_[i]);
116  }
117  }
118  return markers;
119 }
120 
122  for (int i = 0; i < markers_.size(); ++i) {
123  if (markers_[i].image == image && markers_[i].track == track) {
124  return markers_[i];
125  }
126  }
127  Marker null = {-1, -1, -1, -1, 0.0};
128  return null;
129 }
130 
132  int size = 0;
133  for (int i = 0; i < markers_.size(); ++i) {
134  if (markers_[i].track != track) {
135  markers_[size++] = markers_[i];
136  }
137  }
138  markers_.resize(size);
139 }
140 
141 void Tracks::RemoveMarker(int image, int track) {
142  int size = 0;
143  for (int i = 0; i < markers_.size(); ++i) {
144  if (markers_[i].image != image || markers_[i].track != track) {
145  markers_[size++] = markers_[i];
146  }
147  }
148  markers_.resize(size);
149 }
150 
151 int Tracks::MaxImage() const {
152  // TODO(MatthiasF): maintain a max_image_ member (updated on Insert)
153  int max_image = 0;
154  for (int i = 0; i < markers_.size(); ++i) {
155  max_image = std::max(markers_[i].image, max_image);
156  }
157  return max_image;
158 }
159 
160 int Tracks::MaxTrack() const {
161  // TODO(MatthiasF): maintain a max_track_ member (updated on Insert)
162  int max_track = 0;
163  for (int i = 0; i < markers_.size(); ++i) {
164  max_track = std::max(markers_[i].track, max_track);
165  }
166  return max_track;
167 }
168 
169 int Tracks::NumMarkers() const {
170  return markers_.size();
171 }
172 
174  int image,
175  Mat* coordinates) {
176  vector<Vec2> coords;
177  for (int i = 0; i < markers.size(); ++i) {
178  const Marker& marker = markers[i];
179  if (markers[i].image == image) {
180  coords.push_back(Vec2(marker.x, marker.y));
181  }
182  }
183  coordinates->resize(2, coords.size());
184  for (int i = 0; i < coords.size(); i++) {
185  coordinates->col(i) = coords[i];
186  }
187 }
188 
189 } // namespace libmv
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
void sort(btMatrix3x3 &U, btVector3 &sigma, btMatrix3x3 &V, int t)
Helper function of 3X3 SVD for sorting singular values.
void RemoveMarker(int image, int track)
Removes the marker in image belonging to track.
vector< Marker > MarkersInImage(int image) const
Returns all the markers visible in image.
vector< Marker > MarkersInBothImages(int image1, int image2) const
Returns all the markers visible in image1 and image2.
void RemoveMarkersForTrack(int track)
Removes all the markers belonging to track.
int MaxTrack() const
Returns the maximum track identifier used.
vector< Marker > AllMarkers() const
Returns all the markers.
vector< Marker > MarkersForTracksInBothImages(int image1, int image2) const
int MaxImage() const
Returns the maximum image identifier used.
void Insert(int image, int track, double x, double y, double weight=1.0)
vector< Marker > MarkersForTrack(int track) const
Returns all the markers belonging to a track.
int NumMarkers() const
Returns the number of markers.
Marker MarkerInImageForTrack(int image, int track) const
Returns the marker in image belonging to track.
depth_tx normal_tx diffuse_light_tx specular_light_tx volume_light_tx environment_tx ambient_occlusion_tx aov_value_tx in_weight_img image(1, GPU_R32F, Qualifier::WRITE, ImageType::FLOAT_2D_ARRAY, "out_weight_img") .image(3
const vector< Marker > & markers
Intersection< segment > intersection
Eigen::Vector2d Vec2
Definition: numeric.h:105
Eigen::MatrixXd Mat
Definition: numeric.h:60
void CoordinatesForMarkersInImage(const vector< Marker > &markers, int image, Mat *coordinates)
float max