KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
turntable_camera.h
Go to the documentation of this file.
1 /* $Id: turntable_camera.h 18278 2014-11-25 01:42:10Z ksimek $ */
2 /* =========================================================================== *
3  |
4  | Copyright (c) 1994-2010 by Kobus Barnard (author)
5  |
6  | Personal and educational use of this code is granted, provided that this
7  | header is kept intact, and that the authorship is not misrepresented, that
8  | its use is acknowledged in publications, and relevant papers are cited.
9  |
10  | For other use contact the author (kobus AT cs DOT arizona DOT edu).
11  |
12  | Please note that the code in this file has not necessarily been adequately
13  | tested. Naturally, there is no guarantee of performance, support, or fitness
14  | for any particular task. Nonetheless, I am interested in hearing about
15  | problems that you encounter.
16  |
17  | Author: Kyle Simek
18  * =========================================================================== */
19 
20 #ifndef KJB_ST_TURNTABLE_CAMERA_H
21 #define KJB_ST_TURNTABLE_CAMERA_H
22 
23 #include <vector>
24 #include <string>
25 #include <m_cpp/m_vector.h>
27 
28 
29 #ifdef KJB_HAVE_BST_SERIAL
30 #include <boost/serialization/access.hpp>
31 #include <boost/serialization/vector.hpp>
32 #endif
33 
34 namespace kjb
35 {
36  class Calibrated_camera;
52 {
53 #ifdef KJB_HAVE_BST_SERIAL
54  friend class boost::serialization::access;
55 #endif
56 
57 public:
65 
78  const Perspective_camera& cam,
79  const Vector& rotation_axis,
80  const Vector& turntable_origin,
81  int num_positions,
82  bool clockwise = true);
83 
122  template <typename Iterator>
124  const Perspective_camera& cam,
125  const Vector& rotation_axis,
126  const Vector& turntable_origin,
127  Iterator angles_begin,
128  Iterator angles_end) :
129  neutral_camera_(cam),
130  turntable_origin_(turntable_origin),
131  rotation_axis_(rotation_axis),
132  angles_(angles_begin, angles_end),
133  true_angles_(angles_),
134  current_index_(0),
135  current_camera_(neutral_camera_),
136  indices_()
137  {
138 
139  indices_.resize(angles_.size());
140  for(size_t i = 0; i < angles_.size(); ++i)
141  indices_[i] = i;
142  }
143 
147  Turntable_camera(const Turntable_camera& other);
148 
153  {
154  Turntable_camera result(other);
155  swap(result);
156  return *this;
157  }
158 
162  virtual void swap(Turntable_camera& other);
163 
168  {
169  assert(angles_.size() > 0);
170  return neutral_camera_.get_principal_point();
171  }
172 
176  void set_principal_point(const Vector& pt)
177  {
178  assert(angles_.size() > 0);
179  neutral_camera_.set_principal_point(pt);
180  }
181 
190  void set_active_camera(size_t i) const;
191 
198  void set_next();
199 
206  void set_previous();
207 
216  void pass_to_opengl(bool clean_buffers = false) const
217  {
218  // ensure this has been initialized (not constructed with Default ctor)
219  assert(angles_.size() > 0);
220  current_camera_.prepare_for_rendering(clean_buffers);
221  }
222 
227  {
228  assert(angles_.size() > 0);
229  return neutral_camera_;
230  }
231 
232 
233  const Vector& get_origin() const
234  {
235  return turntable_origin_;
236  }
237 
238  const Vector& get_rotation_axis() const
239  {
240  return rotation_axis_;
241  }
242 
243  const std::vector<double>& get_angles() const
244  {
245  return angles_;
246  }
247 
248  size_t get_current_index() const
249  {
250  return current_index_;
251  }
252 
254  {
255  return current_camera_;
256  }
257 
258  size_t size() const
259  {
260  return angles_.size();
261  }
262 
263  const std::vector<size_t>& index_list()
264  {
265  return indices_;
266  }
267 
269  void set_index_list(const Index_range& indices);
270 
271  void evenly_space_cameras(size_t n);
272 
273  virtual const Perspective_camera operator[](int i) const;
274 
275  std::vector<Perspective_camera> to_cameras() const;
276 
277 
278 private:
279  Perspective_camera neutral_camera_;
280  Vector turntable_origin_;
281  Vector rotation_axis_;
282  std::vector<double> angles_;
283  std::vector<double> true_angles_;
284 
285  mutable size_t current_index_;
286  mutable Perspective_camera current_camera_;
287 
288  std::vector<size_t> indices_;
289 
290 private:
291 
292  template<class Archive>
293  void serialize(Archive &ar, const unsigned int version)
294  {
295 #ifdef KJB_HAVE_BST_SERIAL
296  if(version == 0)
297  {
298  // no saving to old formats!
299  assert(Archive::is_loading::value);
300 
301  using namespace boost;
302  ar & neutral_camera_;
303  ar & turntable_origin_;
304  ar & rotation_axis_;
305  ar & angles_;
306 
307  ar & current_index_;
308  ar & current_camera_;
309 
310  // fill-in fields added since version 1
311  true_angles_ = angles_;
312  indices_.resize(angles_.size());
313  for(size_t i =0; i < angles_.size(); ++i)
314  {
315  indices_[i] = i;
316  }
317  }
318  else
319  {
320  // version 1
321  using namespace boost;
322  ar & neutral_camera_;
323  ar & turntable_origin_;
324  ar & rotation_axis_;
325  ar & angles_;
326  ar & true_angles_;
327 
328  ar & current_index_;
329  ar & current_camera_;
330  ar & indices_;
331  }
332 #else
333  KJB_THROW_2(Missing_dependency, "boost::serialization");
334 #endif
335  }
336 };
337 
344 Turntable_camera regularize_turntable_cameras(const std::vector<Calibrated_camera>& cameras);
345 
346 
347 } // namespace kjb
348 
349 #ifdef KJB_HAVE_BST_SERIAL
350 // set serializaztion version
351 namespace boost {
352 namespace serialization {
353  template <>
354  struct version<kjb::Turntable_camera >
355  {
356  typedef mpl::int_<1> type;
357  typedef mpl::integral_c_tag tag;
358  BOOST_STATIC_CONSTANT(int, value = version::type::value);
359  };
360 }
361 }
362 #endif
363 
364 #endif
void set_previous()
Definition: turntable_camera.cpp:133
std::vector< Perspective_camera > to_cameras() const
Definition: turntable_camera.cpp:197
void evenly_space_cameras(size_t n)
Definition: turntable_camera.cpp:177
const Vector & get_origin() const
Definition: turntable_camera.h:233
Turntable_camera(const Perspective_camera &cam, const Vector &rotation_axis, const Vector &turntable_origin, Iterator angles_begin, Iterator angles_end)
Definition: turntable_camera.h:123
size_t get_current_index() const
Definition: turntable_camera.h:248
virtual void prepare_for_rendering(bool clean_buffers) const
Definition: perspective_camera.cpp:1103
const std::vector< double > & get_angles() const
Definition: turntable_camera.h:243
const Perspective_camera & get_neutral_camera() const
Definition: turntable_camera.h:226
Turntable_camera & operator=(const Turntable_camera &other)
Definition: turntable_camera.h:152
This class implements vectors, in the linear-algebra sense, with real-valued elements.
Definition: m_vector.h:87
void pass_to_opengl(bool clean_buffers=false) const
Definition: turntable_camera.h:216
void set_next()
Definition: turntable_camera.cpp:122
void set_active_camera(size_t i) const
Definition: turntable_camera.cpp:96
St_perspective_camera for modeling a perspective camera using the classic Forsyth and Ponce parametri...
Definition: perspective_camera.h:93
Definition: turntable_camera.h:51
const kjb::Vector & get_principal_point() const
returns the principal point
Definition: perspective_camera.h:221
const Vector & get_principal_point() const
Definition: turntable_camera.h:167
Turntable_camera regularize_turntable_cameras(const std::vector< Calibrated_camera > &cameras_)
Definition: turntable_camera.cpp:218
void set_principal_point(const Vector &pt)
Definition: turntable_camera.h:176
virtual void set_principal_point(const kjb::Vector &ip)
sets the principal point
Definition: perspective_camera.cpp:897
const Perspective_camera & get_current_camera() const
Definition: turntable_camera.h:253
Turntable_camera()
Definition: turntable_camera.cpp:38
#define KJB_THROW_2(ex, msg)
Definition: l_exception.h:48
Definition: l_index.h:65
virtual const Perspective_camera operator[](int i) const
Definition: turntable_camera.cpp:185
const Vector & get_rotation_axis() const
Definition: turntable_camera.h:238
const std::vector< size_t > & index_list()
Definition: turntable_camera.h:263
get the indices of edges in each direction for i
Definition: APPgetLargeConnectedEdges.m:48
Definition for the Vector class, a thin wrapper on the KJB Vector struct and its related functionalit...
void set_index_list(const Index_range &indices)
If not all angles should be used, use this to specify the indices of angles to use.
Definition: turntable_camera.cpp:145
virtual void swap(Turntable_camera &other)
Definition: turntable_camera.cpp:83
size_t size() const
Definition: turntable_camera.h:258