KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pt_scene.h
Go to the documentation of this file.
1 /* =========================================================================== *
2  |
3  | Copyright (c) 1994-2011 by Kobus Barnard (author)
4  |
5  | Personal and educational use of this code is granted, provided that this
6  | header is kept intact, and that the authorship is not misrepresented, that
7  | its use is acknowledged in publications, and relevant papers are cited.
8  |
9  | For other use contact the author (kobus AT cs DOT arizona DOT edu).
10  |
11  | Please note that the code in this file has not necessarily been adequately
12  | tested. Naturally, there is no guarantee of performance, support, or fitness
13  | for any particular task. Nonetheless, I am interested in hearing about
14  | problems that you encounter.
15  |
16  | Author: Ernesto Brau
17  * =========================================================================== */
18 
19 /* $Id: pt_scene.h 18971 2015-04-29 23:31:48Z jguan1 $ */
20 
21 #ifndef PT_SCENE_H
22 #define PT_SCENE_H
23 
28 #include <string>
29 #include <iterator>
30 #include <boost/format.hpp>
31 
32 namespace kjb {
33 namespace pt {
34 
40 class Scene
41 {
42 public:
43  Scene
44  (
45  const Ascn& assoc,
46  const Perspective_camera& cam,
47  double k,
48  double t,
49  double l
50  ) :
51  association(assoc),
52  camera(cam),
53  kappa(k),
54  theta(t),
55  lambda(l)
56  //ns_faces(0)
57  {}
58 
61  double kappa;
62  double theta;
63  double lambda;
64  //mutable size_t ns_faces;
65 };
66 
68 inline
69 void swap(Scene& s1, Scene& s2)
70 {
71  using std::swap;
72 
74  swap(s1.camera, s2.camera);
75  swap(s1.kappa, s2.kappa);
76  swap(s1.theta, s2.theta);
77  swap(s1.lambda, s2.lambda);
78  //swap(s1.ns_faces, s2.ns_faces);
79 }
80 
82 size_t dims
83 (
84  const Scene& scene,
85  bool respect_changed = true,
86  bool infer_head = true
87 );
88 
94 (
95  const Scene& scene,
96  const Facemark_data& fmdata,
97  bool infer_head = true,
98  bool refine = true
99 );
100 
112 void read_scene
113 (
114  Scene& s,
115  const std::string& tracks_dp,
116  const std::string& ass_fp,
117  const std::string& cam_fp,
118  const std::string& params_fp,
119  bool infer_head = true
120 );
121 
129 inline
130 void read_scene
131 (
132  Scene& scene,
133  const std::string& tracks_dp,
134  bool infer_head = true
135 )
136 {
137  read_scene(
138  scene,
139  tracks_dp,
140  tracks_dp + "/association.txt",
141  tracks_dp + "/camera.txt",
142  tracks_dp + "/params.txt",
143  infer_head);
144 }
145 
158 void write_scene
159 (
160  const Scene& s,
161  const std::string& tracks_dp,
162  const std::string& ass_fp,
163  const std::string& cam_fp,
164  const std::string& params_fp
165 );
166 
174 inline
175 void write_scene(const Scene& scene, const std::string& tracks_dp)
176 {
177  write_scene(
178  scene,
179  tracks_dp,
180  tracks_dp + "/association.txt",
181  tracks_dp + "/camera.txt",
182  tracks_dp + "/params.txt");
183 }
184 
185 
188 {
189 public:
190  Scene_recorder(const std::string& dir) : parent_dir(dir), i(1){}
191 
193  void operator()(const Scene& scene) const
194  {
195  std::string cur_dir = boost::str(boost::format("/%04d") % i++);
196  write_scene(scene, parent_dir + cur_dir);
197  }
198 
200  void reset() const
201  {
202  i = 1;
203  }
204 
205 private:
206  std::string parent_dir;
207  mutable size_t i;
208 };
209 
212  public std::iterator<std::output_iterator_tag, void, void, void, void>
213 {
214 public:
217  {
218  typedef Scene value_type;
219  };
220 
222  Write_scene_iterator(const std::string& dir) : parent_dir(dir), i(1), n(i){}
223 
225  Write_scene_iterator(const std::string& dir, size_t& sn) :
226  parent_dir(dir), n(sn){}
227 
229  void operator=(const Scene& scene)
230  {
231  std::string cur_dir = boost::str(boost::format("/%04d") % n);
232  write_scene(scene, parent_dir + cur_dir);
233  }
234 
241  {
242  return *this;
243  }
244 
247  {
248  n++;
249  return *this;
250  }
251 
254  {
255  return (*this)++;
256  }
257 
259  void reset()
260  {
261  n = 1;
262  }
263 
264 private:
265  std::string parent_dir;
266  size_t i;
267  size_t& n;
268 };
269 
275 (
276  const Scene& scene,
277  const Target& target,
278  size_t frame,
279  const Vector3& v,
280  bool vis_off,
281  bool infer_head = true
282 );
283 
289 (
290  const Scene& scene,
291  const Target& target1,
292  const Target& target2,
293  size_t frame1,
294  size_t frame2,
295  const Vector3& v1,
296  const Vector3& v2,
297  bool vis_off,
298  bool infer_head = true
299 );
300 
305 inline
307 (
308  const Scene& scene,
309  const Target& target,
310  size_t frame,
311  const Vector3& dv,
312  bool vis_off,
313  bool infer_head = true
314 )
315 {
316  const Vector3& v = target.trajectory()[frame - 1]->value.position;
317  set_trajectory_at_frame(scene, target, frame, v + dv, vis_off, infer_head);
318 }
319 
324 inline
326 (
327  const Scene& scene,
328  const Target& target1,
329  const Target& target2,
330  size_t frame1,
331  size_t frame2,
332  const Vector3& dv1,
333  const Vector3& dv2,
334  bool vis_off,
335  bool infer_head = true
336 )
337 {
338  const Vector3& v1 = target1.trajectory()[frame1 - 1]->value.position;
339  const Vector3& v2 = target2.trajectory()[frame2 - 1]->value.position;
340 
342  target1, target2,
343  frame1, frame2,
344  v1 + dv1, v2 + dv2,
345  vis_off,
346  infer_head);
347 }
348 
354 (
355  const Scene& scene,
356  const Target& target,
357  size_t frame,
358  double dir,
359  bool vis_off
360 );
361 
367 (
368  const Scene& scene,
369  const Target& target1,
370  const Target& target2,
371  size_t frame1,
372  size_t frame2,
373  double dir1,
374  double dir2,
375  bool vis_off
376 );
377 
382 inline
384 (
385  const Scene& scene,
386  const Target& target,
387  size_t frame,
388  double dd,
389  bool vis_off
390 )
391 {
392  double d = target.trajectory()[frame - 1]->value.body_dir;
393  set_trajectory_dir_at_frame(scene, target, frame, d + dd, vis_off);
394 }
395 
400 inline
402 (
403  const Scene& scene,
404  const Target& target1,
405  const Target& target2,
406  size_t frame1,
407  size_t frame2,
408  double dd1,
409  double dd2,
410  bool vis_off
411 )
412 {
413  double d1 = target1.trajectory()[frame1 - 1]->value.body_dir;
414  double d2 = target2.trajectory()[frame2 - 1]->value.body_dir;
415 
417  target1, target2,
418  frame1, frame2,
419  d1 + dd1, d2 + dd2,
420  vis_off);
421 }
422 
428 (
429  const Scene& scene,
430  const Target& target,
431  size_t frame,
432  const Vector2& dir,
433  bool vis_off
434 );
435 
441 (
442  const Scene& scene,
443  const Target& target1,
444  const Target& target2,
445  size_t frame1,
446  size_t frame2,
447  const Vector2& dir1,
448  const Vector2& dir2,
449  bool vis_off
450 );
451 
456 inline
458 (
459  const Scene& scene,
460  const Target& target,
461  size_t frame,
462  const Vector2& dd,
463  bool vis_off
464 )
465 {
466  const Vector2& d = target.trajectory()[frame - 1]->value.face_dir;
467  set_trajectory_face_dir_at_frame(scene, target, frame, d + dd, vis_off);
468 }
469 
474 inline
476 (
477  const Scene& scene,
478  const Target& target1,
479  const Target& target2,
480  size_t frame1,
481  size_t frame2,
482  const Vector2& dd1,
483  const Vector2& dd2,
484  bool vis_off
485 )
486 {
487  const Vector2& d1 = target1.trajectory()[frame1 - 1]->value.face_dir;
488  const Vector2& d2 = target2.trajectory()[frame2 - 1]->value.face_dir;
489 
491  target1, target2,
492  frame1, frame2,
493  d1 + dd1, d2 + dd2,
494  vis_off);
495 }
496 
499 (
500  const Target& target,
501  size_t frame,
502  const Perspective_camera& cam
503 );
504 
507 (
508  const Target& target,
509  size_t frame,
510  const Perspective_camera& cam
511 );
512 
514 inline void update_model_directions
515 (
516  const Target& target,
517  size_t frame,
518  const Perspective_camera& cam
519 )
520 {
521  update_body_model_directions(target, frame, cam);
522  update_face_model_directions(target, frame, cam);
523 }
524 
525 }} //namespace kjb::pt
526 
527 #endif /*PT_SCENE_H */
528 
void set_trajectory_face_dir_at_frame(const Scene &scene, const Target &target, size_t frame, const Vector2 &dir, bool vis_off)
Function that changes a single face direction at a single frame, and performs all the necessary updat...
Definition: pt_scene.cpp:373
Scene_recorder(const std::string &dir)
Definition: pt_scene.h:190
Scene value_type
Definition: pt_scene.h:218
void update_scene_state(const Scene &scene, const Facemark_data &fmdata, bool infer_head=true, bool refine=true)
Update the (mostly) 3D state of a scene. To be called after an association change.
Definition: pt_scene.cpp:40
void update_model_directions(const Target &target, size_t frame, const Perspective_camera &cam)
Helper function for the set_trajectory_* functions.
Definition: pt_scene.h:515
Scene(const Ascn &assoc, const Perspective_camera &cam, double k, double t, double l)
Definition: pt_scene.h:44
Trajectory & trajectory() const
Get this target's current 3D positions.
Definition: pt_target.h:85
double lambda
Definition: pt_scene.h:63
Class that represents a full scene in the PT universe.
Definition: pt_scene.h:40
Ascn association
Definition: pt_scene.h:59
for k
Definition: APPgetLargeConnectedEdges.m:61
void read_scene(Scene &s, const std::string &tracks_dp, const std::string &ass_fp, const std::string &cam_fp, const std::string &params_fp, bool infer_head=true)
Read a scene.
Definition: pt_scene.cpp:144
void reset()
Reset current sample number.
Definition: pt_scene.h:259
void swap(Scene &s1, Scene &s2)
Swap two scenes.
Definition: pt_scene.h:69
int refine
Definition: triangle.c:716
double theta
Definition: pt_scene.h:62
Write_scene_iterator & operator++()
Increments scene index.
Definition: pt_scene.h:253
void update_face_model_directions(const Target &target, size_t frame, const Perspective_camera &cam)
Helper function for the set_trajectory_* functions.
Definition: pt_scene.cpp:504
Fake container type. Needed for recorder to find the type.
Definition: pt_scene.h:216
Record a series of scenes to a directory.
Definition: pt_scene.h:187
Write_scene_iterator & operator++(int)
Increments scene index.
Definition: pt_scene.h:246
size_t dims(const Scene &scene, bool respect_changed=true, bool infer_head=true)
Computes the number of variables in this scene.
Definition: pt_scene.cpp:106
St_perspective_camera for modeling a perspective camera using the classic Forsyth and Ponce parametri...
std::vector< std::vector< Deva_facemark > > Facemark_data
Definition: pt_data.h:129
void move_trajectory_at_frame(const Scene &scene, const Target &target, size_t frame, const Vector3 &dv, bool vis_off, bool infer_head=true)
Function that moves a single trajectory at a single frame, and performs all the necessary updates...
Definition: pt_scene.h:307
void reset() const
Reset current sample number.
Definition: pt_scene.h:200
void move_trajectory_face_dirs_at_frames(const Scene &scene, const Target &target1, const Target &target2, size_t frame1, size_t frame2, const Vector2 &dd1, const Vector2 &dd2, bool vis_off)
Function that moves a pair of directions at a pair of frames, and performs all the necessary updates...
Definition: pt_scene.h:476
Definition: perspective_camera.h:93
void operator=(const Scene &scene)
Upon assignment, write a scene.
Definition: pt_scene.h:229
void set_trajectory_at_frame(const Scene &scene, const Target &target, size_t frame, const Vector3 &v, bool vis_off, bool infer_head=true)
Function that changes a single trajectory at a single frame, and performs all the necessary updates...
Definition: pt_scene.cpp:210
Write_scene_iterator(const std::string &dir)
Construct an iterator.
Definition: pt_scene.h:222
Class that represents a target moving through space.
Definition: pt_target.h:50
void set_trajectory_face_dirs_at_frames(const Scene &scene, const Target &target1, const Target &target2, size_t frame1, size_t frame2, const Vector2 &dir1, const Vector2 &dir2, bool vis_off)
Function that changes a pair of face directions at a pair of frames, and performs all the necessary u...
Definition: pt_scene.cpp:434
void update_body_model_directions(const Target &target, size_t frame, const Perspective_camera &cam)
Helper function for the set_trajectory_* functions.
Definition: pt_scene.cpp:465
Perspective_camera camera
Definition: pt_scene.h:60
void set_trajectory_dirs_at_frames(const Scene &scene, const Target &target1, const Target &target2, size_t frame1, size_t frame2, double dir1, double dir2, bool vis_off)
Function that changes a pair of directions at a pair of frames, and performs all the necessary update...
Definition: pt_scene.cpp:342
void move_trajectory_face_dir_at_frame(const Scene &scene, const Target &target, size_t frame, const Vector2 &dd, bool vis_off)
Function that moves a single face direction at a single frame, and performs all the necessary updates...
Definition: pt_scene.h:458
void swap(kjb::Gsl_Multimin_fdf &m1, kjb::Gsl_Multimin_fdf &m2)
Swap two wrapped multimin objects.
Definition: gsl_multimin.h:693
Write_scene_iterator(const std::string &dir, size_t &sn)
Construct an iterator.
Definition: pt_scene.h:225
void operator()(const Scene &scene) const
Record a scene.
Definition: pt_scene.h:193
void set_trajectory_dir_at_frame(const Scene &scene, const Target &target, size_t frame, double dir, bool vis_off)
Function that changes a single direction at a single frame, and performs all the necessary updates...
Definition: pt_scene.cpp:295
void move_trajectories_at_frames(const Scene &scene, const Target &target1, const Target &target2, size_t frame1, size_t frame2, const Vector3 &dv1, const Vector3 &dv2, bool vis_off, bool infer_head=true)
Function that moves a pair of trajectories at a pair of frames, and performs all the necessary update...
Definition: pt_scene.h:326
void set_trajectories_at_frames(const Scene &scene, const Target &target1, const Target &target2, size_t frame1, size_t frame2, const Vector3 &v1, const Vector3 &v2, bool vis_off, bool infer_head=true)
Function that changes a pair of trajectories at a pair of frames, and performs all the necessary upda...
Definition: pt_scene.cpp:263
Write_scene_iterator & operator*()
Return itself on redirection. This complies with the output iterator concept, as *it = sc produces th...
Definition: pt_scene.h:240
void move_trajectory_dirs_at_frames(const Scene &scene, const Target &target1, const Target &target2, size_t frame1, size_t frame2, double dd1, double dd2, bool vis_off)
Function that moves a pair of directions at a pair of frames, and performs all the necessary updates...
Definition: pt_scene.h:402
Record a series of scenes to a directory.
Definition: pt_scene.h:211
void move_trajectory_dir_at_frame(const Scene &scene, const Target &target, size_t frame, double dd, bool vis_off)
Function that moves a single direction at a single frame, and performs all the necessary updates...
Definition: pt_scene.h:384
void write_scene(const Scene &s, const std::string &tracks_dp, const std::string &ass_fp, const std::string &cam_fp, const std::string &params_fp)
Write a scene.
Definition: pt_scene.cpp:182
double kappa
Definition: pt_scene.h:61