Blender  V3.3
test_data_sets.cc
Go to the documentation of this file.
1 // Copyright (c) 2007, 2008 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 <cmath>
24 
27 #include "libmv/numeric/numeric.h"
28 
29 namespace libmv {
30 
33 
34  // clang-format off
35  d.K1 << 320, 0, 160,
36  0, 320, 120,
37  0, 0, 1;
38  // clang-format on
39  if (same_K) {
40  d.K2 = d.K1;
41  } else {
42  // clang-format off
43  d.K2 << 360, 0, 170,
44  0, 360, 110,
45  0, 0, 1;
46  // clang-format on
47  }
48  d.R1 = RotationAroundZ(-0.1);
49  d.R2 = RotationAroundX(-0.1);
50  d.t1 << 1, 1, 10;
51  d.t2 << -2, -1, 10;
52  P_From_KRt(d.K1, d.R1, d.t1, &d.P1);
53  P_From_KRt(d.K2, d.R2, d.t2, &d.P2);
54 
55  FundamentalFromProjections(d.P1, d.P2, &d.F);
56 
57  d.X.resize(3, 30);
58  d.X.setRandom();
59 
60  Project(d.P1, d.X, &d.x1);
61  Project(d.P2, d.X, &d.x2);
62 
63  return d;
64 }
65 
67  int fx, int fy, int cx, int cy, double distance, double jitter_amount) {
68  _fx = fx;
69  _fy = fy;
70  _cx = cx;
71  _cy = cy;
72  _dist = distance;
73  _jitter_amount = jitter_amount;
74 }
75 
77  int npoints,
78  const nViewDatasetConfigator config) {
79  NViewDataSet d;
80  d.n = nviews;
81  d.K.resize(nviews);
82  d.R.resize(nviews);
83  d.t.resize(nviews);
84  d.C.resize(nviews);
85  d.x.resize(nviews);
86  d.x_ids.resize(nviews);
87 
88  d.X.resize(3, npoints);
89  d.X.setRandom();
90  d.X *= 0.6;
91 
92  Vecu all_point_ids(npoints);
93  for (size_t j = 0; j < npoints; ++j)
94  all_point_ids[j] = j;
95 
96  for (size_t i = 0; i < nviews; ++i) {
97  Vec3 camera_center, t, jitter, lookdir;
98 
99  double theta = i * 2 * M_PI / nviews;
100  camera_center << sin(theta), 0.0, cos(theta);
101  camera_center *= config._dist;
102  d.C[i] = camera_center;
103 
104  jitter.setRandom();
105  jitter *= config._jitter_amount / camera_center.norm();
106  lookdir = -camera_center + jitter;
107 
108  // clang-format off
109  d.K[i] << config._fx, 0, config._cx,
110  0, config._fy, config._cy,
111  0, 0, 1;
112  // clang-format on
113  d.R[i] = LookAt(lookdir);
114  d.t[i] = -d.R[i] * camera_center;
115  d.x[i] = Project(d.P(i), d.X);
116  d.x_ids[i] = all_point_ids;
117  }
118  return d;
119 }
120 
122  int npoints,
123  float view_ratio,
124  unsigned min_projections,
125  const nViewDatasetConfigator config) {
126  assert(view_ratio <= 1.0);
127  assert(view_ratio > 0.0);
128  assert(min_projections <= npoints);
129  NViewDataSet d;
130  d.n = nviews;
131  d.K.resize(nviews);
132  d.R.resize(nviews);
133  d.t.resize(nviews);
134  d.C.resize(nviews);
135  d.x.resize(nviews);
136  d.x_ids.resize(nviews);
137 
138  d.X.resize(3, npoints);
139  d.X.setRandom();
140  d.X *= 0.6;
141 
142  Mat visibility(nviews, npoints);
143  visibility.setZero();
144  Mat randoms(nviews, npoints);
145  randoms.setRandom();
146  randoms = (randoms.array() + 1) / 2.0;
147  unsigned num_visibles = 0;
148  for (size_t i = 0; i < nviews; ++i) {
149  num_visibles = 0;
150  for (size_t j = 0; j < npoints; j++) {
151  if (randoms(i, j) <= view_ratio) {
152  visibility(i, j) = true;
153  num_visibles++;
154  }
155  }
156  if (num_visibles < min_projections) {
157  unsigned num_projections_to_add = min_projections - num_visibles;
158  for (size_t j = 0; j < npoints && num_projections_to_add > 0; ++j) {
159  if (!visibility(i, j)) {
160  num_projections_to_add--;
161  }
162  }
163  num_visibles += num_projections_to_add;
164  }
165  d.x_ids[i].resize(num_visibles);
166  d.x[i].resize(2, num_visibles);
167  }
168 
169  size_t j_visible = 0;
170  Vec3 X;
171  for (size_t i = 0; i < nviews; ++i) {
172  Vec3 camera_center, t, jitter, lookdir;
173 
174  double theta = i * 2 * M_PI / nviews;
175  camera_center << sin(theta), 0.0, cos(theta);
176  camera_center *= config._dist;
177  d.C[i] = camera_center;
178 
179  jitter.setRandom();
180  jitter *= config._jitter_amount / camera_center.norm();
181  lookdir = -camera_center + jitter;
182 
183  // clang-format off
184  d.K[i] << config._fx, 0, config._cx,
185  0, config._fy, config._cy,
186  0, 0, 1;
187  // clang-format on
188  d.R[i] = LookAt(lookdir);
189  d.t[i] = -d.R[i] * camera_center;
190  j_visible = 0;
191  for (size_t j = 0; j < npoints; j++) {
192  if (visibility(i, j)) {
193  X = d.X.col(j);
194  d.x[i].col(j_visible) = Project(d.P(i), X);
195  d.x_ids[i][j_visible] = j;
196  j_visible++;
197  }
198  }
199  }
200  return d;
201 }
202 
203 } // namespace libmv
#define M_PI
Definition: BLI_math_base.h:20
_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 GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble t
#define X
Definition: GeomUtils.cpp:199
INLINE Rall1d< T, V, S > cos(const Rall1d< T, V, S > &arg)
Definition: rall1d.h:319
INLINE Rall1d< T, V, S > sin(const Rall1d< T, V, S > &arg)
Definition: rall1d.h:311
T distance(const T &a, const T &b)
NViewDataSet NRealisticCamerasSparse(int nviews, int npoints, float view_ratio, unsigned min_projections, const nViewDatasetConfigator config)
void FundamentalFromProjections(const Mat34 &P1, const Mat34 &P2, Mat3 *F)
Definition: fundamental.cc:54
TwoViewDataSet TwoRealisticCameras(bool same_K)
Mat3 RotationAroundX(double angle)
Definition: numeric.cc:25
Eigen::MatrixXd Mat
Definition: numeric.h:60
Vec2 Project(const Mat34 &P, const Vec3 &X)
Eigen::Matrix< unsigned int, Eigen::Dynamic, 1 > Vecu
Definition: numeric.h:67
Eigen::Vector3d Vec3
Definition: numeric.h:106
Mat3 RotationAroundZ(double angle)
Definition: numeric.cc:49
NViewDataSet NRealisticCamerasFull(int nviews, int npoints, const nViewDatasetConfigator config)
void P_From_KRt(const Mat3 &K, const Mat3 &R, const Vec3 &t, Mat34 *P)
Definition: projection.cc:26
Mat3 LookAt(Vec3 center)
Definition: numeric.cc:69
double _dist
Camera random position parameters.
int _fx
Internal camera parameters.
nViewDatasetConfigator(int fx=1000, int fy=1000, int cx=500, int cy=500, double distance=1.5, double jitter_amount=0.01)