KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
manhattan_world.h
Go to the documentation of this file.
1 /* $Id $ */
2 
15 #ifndef EDGE_MANHATTAN_WORLD_H
16 #define EDGE_MANHATTAN_WORLD_H
17 
19 #include "edge_cpp/line_segment.h"
22 #include <l_cpp/l_readable.h>
23 #include <l_cpp/l_writeable.h>
24 #include <fstream>
25 
26 
27 
28 #define MW_OUTLIER_THRESHOLD 0.16
29 #define MAX_CORNER_SEGMENT_STRETCH 35 /*25 */
30 #define MAX_CORNER_PERP_SEGMENT_STRETCH 3 /*3 */
31 #define MW_FOCAL_INIT_VALUE 150
32 #define MW_MIN_FOCAL_INIT_VALUE 50
33 
34 namespace kjb {
35 
43 {
44  public:
45  Manhattan_segment(const Edge_segment & isegment, Vanishing_point * ivp = 0)
46  : _segment(isegment), _vp(ivp)
47  {
48  if(!ivp)
49  {
50  _outlier = true;
51  alpha = 0.0;
52  }
53  else
54  {
55  alpha = Vanishing_point_detector::compute_alpha( *_vp, &_segment);
56  _outlier = false;
57  }
58  }
59 
61  : _segment(src._segment), _vp(src._vp),
62  alpha(src.alpha), _outlier(src._outlier) { }
63 
65  const Edge_segment & get_edge_segment() const { return _segment;}
66 
68  const Vanishing_point * get_vanishing_point() const { return _vp; }
69 
71  {
72  if(!ivp)
73  {
74  _outlier = true;
75  _vp = NULL;
76  alpha = 0;
77  }
78  else
79  {
80  _outlier = false;
81  _vp = ivp;
82  alpha = Vanishing_point_detector::compute_alpha( *_vp, &_segment);
83  }
84  }
85 
89  {
90  _outlier = true;
91  _vp = 0;
92  alpha = 0.0;
93  }
94 
99  bool is_outlier() const
100  {
101  return _outlier;
102  }
103 
105  double get_alpha() const
106  {
107  return alpha;
108  }
109 
111 
113  void draw( kjb::Image & img, double ir, double ig, double ib, double width = 1.0) const
114  {
115  _segment.draw(img, ir, ig, ib, width);
116  }
117 
119  void randomly_color(kjb::Image & img, double width = 1.0) const
120  {
121  _segment.randomly_color(img, width);
122  }
123 
126  void draw_mid_point_to_vanishing_point(kjb::Image & img, double ir, double ig, double ib, double width = 1.0) const;
127 
128  friend std::ostream & operator<<(std::ostream& out, const Manhattan_segment& ms);
129  private:
130 
131 #warning "[Code police] Please don't start identifiers with underscore."
132 
133  Edge_segment _segment;
134 
136  Vanishing_point * _vp;
137 
141  double alpha;
142 
147  bool _outlier;
148 
149 };
150 
151 /* @class Manhattan_corner_segment This class contains a line segment part
152  * of a corner in Manhattan world. Such corners are formed by three line segments,
153  * each converging to a different vanishing point (orthogonal corner).
154  */
156 {
157 public:
158 
160  double idist = 0.0, double iperp_dist = 0.0) :
161  segment(isegment), distance_to_centre(idist), perpendicular_distance(iperp_dist)
162  {
163 
164  }
165 
166 
168  segment(src.segment),
169  distance_to_centre(src.distance_to_centre),
170  perpendicular_distance(src.perpendicular_distance)
171  {
172 
173  }
174 
176  {
177 
178  }
179 
181  {
182  return segment;
183  }
184 
185  inline const Edge_segment & get_edge_segment() const
186  {
187  return segment.get_edge_segment();
188  }
189 
190  inline double get_fitting_error() const
191  {
193  }
194 
195  inline double get_strength() const
196  {
197  return segment.get_edge_segment().get_strength();
198  }
199 
204  inline double get_distance() const
205  {
206  return distance_to_centre;
207  }
208 
213  inline double get_perpendicular_distance() const
214  {
215  return perpendicular_distance;
216  }
217 
218  //TODO to be implemented
219  double compute_penalty() const;
220 
221  friend std::ostream & operator<<(std::ostream& out, const Manhattan_corner_segment& mcs);
222 
223 private:
224 
225  Manhattan_corner_segment & operator=(const Manhattan_corner_segment & src)
226  {
228  distance_to_centre = src.distance_to_centre;
229  perpendicular_distance = src.perpendicular_distance;
230  return (*this);
231  }
232 
233  const Manhattan_segment & segment;
234 
235  double distance_to_centre;
236 
237  double perpendicular_distance;
238 
239 };
240 
241 /* @class Manhattan_cornert This class represents a corner in Manhattan world.
242  * Such corners are formed by three line segments, each converging to a different
243  * vanishing point (orthogonal corner). Each corner is created when two or three
244  * line_segments detected in the image and converging to different vanishing points
245  * intersect. If there are only two segments intersecting, we compute the third
246  * as the line between the corner position and the only vanishing point that was
247  * not used in creating this corner (such segment is marked as unavailable)
248  */
250 {
251 public:
252  Manhattan_corner(std::vector<Vanishing_point> * ivpts) :
253  position(2, 0.0), segments(3,(Manhattan_corner_segment *) NULL), available(3, false), indexes(3, 0),
254  orthogonal_segments(3), v_pts(ivpts)
255  {
256 
257  }
258 
260  position(src.position), segments(3, (Manhattan_corner_segment *)NULL), available(src.available),
261  indexes(src.indexes), orthogonal_segments(src.orthogonal_segments), v_pts(src.v_pts)
262  {
263  for(unsigned int i = 0; i < 3; i++)
264  {
265  if(available[i])
266  {
267  segments[i] = new Manhattan_corner_segment(*(src.segments[i]));
268  }
269  }
270  }
271 
273  {
274  available = src.available;
275  for(unsigned int i = 0; i < 3; i++)
276  {
277  if(available[i])
278  {
279  segments[i] = new Manhattan_corner_segment(*(src.segments[i]));
280  }
281  }
282  orthogonal_segments = src.orthogonal_segments;
283  v_pts = src.v_pts;
284  position = src.position;
285  indexes = src.indexes;
286  return (*this);
287  }
288 
290  {
291  for(unsigned int i = 0; i < 3; i++)
292  {
293  if(available[i])
294  {
295  delete segments[i];
296  }
297  }
298  }
299 
303  bool is_available(unsigned int i) const
304  {
305  if(i >= 3)
306  {
307  KJB_THROW_2(Illegal_argument,"Manhattan corners only have 3 segments");
308  }
309  return available[i];
310  }
311 
312  const Manhattan_corner_segment * get_segment(unsigned int i) const
313  {
314  if(!is_available(i))
315  {
316  KJB_THROW_2(Illegal_argument,"Manhattan corners, the requested segment is not available!");
317  }
318  return segments[i];
319  }
320 
323  unsigned int get_index(unsigned int i) const
324  {
325  if(!is_available(i))
326  {
327  KJB_THROW_2(Illegal_argument,"Manhattan corners, the requested segment is not available!");
328  }
329  return indexes[i];
330  }
331 
333  const kjb::Vector & get_position() const
334  {
335  return position;
336  }
337 
339  void set_position(const kjb::Vector & iposition)
340  {
341  if(iposition.size() < 2)
342  {
343  KJB_THROW_2(Illegal_argument, "Corner position vector must be of size 2");
344  }
345  position = iposition;
346  for(unsigned int i =0; i < 3; i++)
347  {
348  delete_segment(i);
349  }
350  }
351 
352  void set_segment(const Manhattan_corner_segment & segment, unsigned int i)
353  {
354  if(is_available(i))
355  {
356  delete segments[i];
357  }
358  segments[i] = new Manhattan_corner_segment(segment);
359  available[i] = true;
361  }
362 
363  void set_segment(unsigned int i,const Manhattan_segment & segment, double dist = 0.0, double perp_dist = 0)
364  {
365  if(is_available(i))
366  {
367  delete segments[i];
368  }
369  segments[i] = new Manhattan_corner_segment(segment, dist, perp_dist);
370  available[i] = true;
372  }
373 
374  void set_index(unsigned int i, unsigned int iindex)
375  {
376  if(is_available(i))
377  {
378  indexes[i] = iindex;
379  }
380  }
381 
382 
383  void delete_segment(unsigned int i)
384  {
385  if(is_available(i))
386  {
387  delete segments[i];
388  }
389  segments[i] = NULL;
390  available[i] = false;
391  indexes[i] = 0;
392  }
393 
394  inline const Line_segment & get_orthogonal_segment(unsigned int i) const
395  {
396  if(i > 2)
397  {
398  KJB_THROW_2(Illegal_argument,"Manhattan corner, get orthogonal segment, index out of bounds");
399  }
400  return orthogonal_segments[i];
401  }
402 
403  unsigned int num_available_segments() const;
404 
405  void draw(kjb::Image & img, bool draw_full_segments = false, double width = 1.0) const;
406 
407  void get_3D_corner
408  (
409  double z_distance,
410  double focal_length,
411  double princ_x,
412  double princ_y,
413  kjb::Vector & corner3D_1,
414  kjb::Vector & corner3D_2,
415  kjb::Vector & corner3D_3,
416  kjb::Vector & position_3D
417  ) const;
418 
419  friend std::ostream & operator<<(std::ostream& out, const Manhattan_corner& mc);
420 
421  void get_direction(unsigned int segment_index, kjb::Vector & direction) const;
422 
423  bool is_up_corner() const;
424 
425  double get_avg_segment_size() const;
426 
428 
429  void init_missing_orthogonal_segment(int iindex, double start_x, double start_y, double end_x, double end_y);
430 
431  void compute_orthogonal_segment(unsigned int i);
432 
433 private:
434 
435  bool is_right_segment(unsigned int i);
436 
437  kjb::Vector position;
438 
439  std::vector<Manhattan_corner_segment *> segments;
440 
441  std::vector<bool> available;
442 
443  std::vector<unsigned int> indexes;
444 
445  std::vector<Line_segment> orthogonal_segments;
446 
447  std::vector<Vanishing_point> * v_pts;
448 };
449 
450 
461 {
462 public:
463 
464  Manhattan_world(double ifocal = MW_FOCAL_INIT_VALUE) : _assignments(4), _vpts(3), focal_length(ifocal) { }
465 
466  Manhattan_world(const std::vector<Vanishing_point> & ivpts, double ifocal = MW_FOCAL_INIT_VALUE )
467  : _assignments(4), _vpts(ivpts), focal_length(ifocal)
468  {
469  if(focal_length < MW_MIN_FOCAL_INIT_VALUE)
470  {
471  focal_length = MW_MIN_FOCAL_INIT_VALUE;
472  }
473  if(ivpts.size() != 3)
474  {
475  KJB_THROW_2(Illegal_argument,"Manhattan world requires three vanishing points");
476  }
477  }
478 
479  Manhattan_world(const Edge_segment_set & isegments, const std::vector<Vanishing_point> & ivpts,
480  double ifocal = MW_FOCAL_INIT_VALUE, double outlier_threshold = MW_OUTLIER_THRESHOLD);
481 
482  Manhattan_world(const char *filename, const Edge_segment_set & isegments,
483  double outlier_threshold = MW_OUTLIER_THRESHOLD) :
484  _assignments(4), _vpts(3), focal_length(MW_FOCAL_INIT_VALUE)
485  {
486  read(filename, isegments, outlier_threshold);
487  }
488 
489  Manhattan_world(const char *filename) : _assignments(4), _vpts(3), focal_length(MW_FOCAL_INIT_VALUE)
490  {
491  read(filename);
492  }
493 
494  Manhattan_world(std::istream& in, const Edge_segment_set & isegments,
495  double outlier_threshold = MW_OUTLIER_THRESHOLD) :
496  _assignments(4), _vpts(3), focal_length(MW_FOCAL_INIT_VALUE)
497  {
498  read(in, isegments, outlier_threshold);
499  }
500 
501  Manhattan_world(const Manhattan_world & src) : _assignments(src._assignments),
502  _corners2(src._corners2), _corners3(src._corners3),
503  _vpts(src._vpts), focal_length(src.focal_length) { }
504 
506  {
507  _assignments = src._assignments;
508  _vpts = src._vpts;
509  _corners2 = src._corners2;
510  _corners3 = src._corners3;
511  focal_length = src.focal_length;
512  return (*this);
513  }
514 
516  inline double get_focal_length() const
517  {
518  return focal_length;
519  }
520 
522  inline void set_focal_length(double ifocal)
523  {
524  focal_length = ifocal;
525  }
526 
527  void reset_vanishing_points(const std::vector<Vanishing_point> & vpts)
528  {
529  _vpts = vpts;
530  for(unsigned int i = 0; i < 4; i++)
531  {
532  _assignments[i].clear();
533  }
534  _corners2.clear();
535  _corners3.clear();
536  }
537 
540  void assign_segments_to_vpts(const Edge_segment_set & , double outlier_threshold = MW_OUTLIER_THRESHOLD );
541 
544  const std::vector < std::vector<Manhattan_segment> > & get_assignments() const {return _assignments; }
545 
547  unsigned num_lines_assigned_to_vp(unsigned vpindex) const { return _assignments[vpindex].size(); }
548 
550  const std::vector<Vanishing_point> & get_vanishing_points() const { return _vpts; }
551 
552  const std::vector<Vanishing_point> get_value_vanishing_points() const { return _vpts; }
553 
558  void draw_segments_with_vp_assignments(kjb::Image & img, double width = 1.0) const;
559 
566  void draw_lines_from_segments_midpoint_to_vp(kjb::Image & img, double width = 1.0) const;
567 
569  void read(std::istream& in, const Edge_segment_set & isegments, double outlier_threshold = MW_OUTLIER_THRESHOLD);
570 
572  void read(const char *filename, const Edge_segment_set & isegments, double outlier_threshold = MW_OUTLIER_THRESHOLD);
573 
574  void read(const char * filename);
575  void read(std::istream& in);
576 
578  void write(std::ostream& out) const;
579 
581  void write(const char * out_file) const
582  {
583  std::ofstream ofs(out_file);
584  if(ofs.fail())
585  {
586  KJB_THROW_2(kjb::IO_error, "Could not open file to write Manhattan world");
587  }
588  write(ofs);
589  ofs.close();
590  }
591 
593  const Manhattan_corner & get_corner_2(unsigned int i) const
594  {
595  if(i >= _corners2.size())
596  {
597  KJB_THROW_2(Illegal_argument,"Corner2 index out of bounds");
598  }
599  return _corners2[i];
600  }
601 
603  const Manhattan_corner & get_corner_3(unsigned int i) const
604  {
605  if(i >= _corners3.size())
606  {
607  KJB_THROW_2(Illegal_argument,"Corner3 index out of bounds");
608  }
609  return _corners3[i];
610  }
611 
612  const Manhattan_corner & get_extra_corner(unsigned int i) const
613  {
614  if(i >= _extra_corners.size())
615  {
616  KJB_THROW_2(Illegal_argument,"Extra corner index out of bounds");
617  }
618  return _extra_corners[i];
619  }
620 
621 
622 
623  const Manhattan_segment & get_manhattan_segment(unsigned int vp_index, unsigned int segment_index) const;
624 
625  void write_manhattan_corner(const Manhattan_corner & corner, std::ostream& out) const;
626 
627  void read_manhattan_corner(Manhattan_corner & corner, std::istream& in) const;
628 
629  void write_corners(std::ostream& out) const;
630 
631  void read_corners(std::istream& in);
632 
633  void draw_corners(kjb::Image & img, bool draw_full_segments = false, double width = 1.0) const;
634 
635  void draw_corners2(kjb::Image & img, bool draw_full_segments = false, double width = 1.0) const;
636 
637  void draw_corners2up(kjb::Image & img, bool draw_full_segments = false, double width = 1.0) const;
638 
639  void draw_corners3(kjb::Image & img, bool draw_full_segments = false, double width = 1.0) const;
640 
641  void draw_corners3up(kjb::Image & img, bool draw_full_segments = false, double width = 1.0) const;
642 
643  void draw_corners2smart(kjb::Image & img, bool draw_full_segments = false, double width = 1.0) const;
644 
645  void draw_corners3smart(kjb::Image & img, bool draw_full_segments = false, double width = 1.0) const;
646 
647  void draw_extra_corners(kjb::Image & img, bool draw_full_segments = false, double width = 1.0) const;
648 
649 
653  static bool create_corner
654  (
655  Manhattan_corner & corner,
656  const Manhattan_segment & seg1,
657  const Manhattan_segment & seg2,
658  unsigned int index1,
659  unsigned int index2,
660  double max_stretch = MAX_CORNER_SEGMENT_STRETCH
661  );
662 
666  static bool create_corner3
667  (
668  Manhattan_corner & corner,
669  const Manhattan_segment & seg3,
670  unsigned int index3,
671  double max_stretch = MAX_CORNER_SEGMENT_STRETCH,
672  double max_perp_stretch = MAX_CORNER_PERP_SEGMENT_STRETCH
673  );
674 
676  (
677  Manhattan_corner & corner,
678  unsigned int index3,
679  bool towards_vp,
680  const kjb::Vector & position,
681  bool check_consistency = true
682  );
683 
684 
687  void create_corners2();
688 
691  void create_corners3();
692 
695  void create_corners();
696 
697  inline unsigned int get_num_corners2() const
698  {
699  return _corners2.size();
700  }
701 
702  inline unsigned int get_num_corners3() const
703  {
704  return _corners3.size();
705  }
706 
707  inline unsigned int get_num_extra_corners() const
708  {
709  return _extra_corners.size();
710  }
711 
712  void print_corners(std::ostream& out) const
713  {
714  print_corners2(out);
715  print_corners3(out);
716  }
717 
718  void print_corners2(std::ostream& out) const;
719 
720  void print_corners3(std::ostream& out) const;
721 
722  void print_vanishing_points(std::ostream& out) const;
723 
724  void get_3D_corner
725  (
726  double z_distance,
727  double princ_x,
728  double princ_y,
729  unsigned int index,
730  bool usecorner3,
731  kjb::Vector & corner3D_1,
732  kjb::Vector & corner3D_2,
733  kjb::Vector & corner3D_3,
734  kjb::Vector & position_3D
735  ) const;
736 
737  const std::vector<Manhattan_corner> & get_corners3() const
738  {
739  return _corners3;
740  }
741 
742  const std::vector<Manhattan_corner> & get_corners2() const
743  {
744  return _corners2;
745  }
746 
747  const std::vector<Manhattan_corner> & get_extra_corners() const
748  {
749  return _extra_corners;
750  }
751 
752  void set_extra_corners_from_vertical_pairs(const std::vector<Segment_pair> & vpairs);
753 
754 private:
755 
756  bool corner3_exists(const Manhattan_corner & c);
757 
763  std::vector < std::vector<Manhattan_segment> > _assignments;
764 
765  std::vector<Manhattan_corner> _corners2;
766 
767  std::vector<Manhattan_corner> _corners3;
768 
769  std::vector<Manhattan_corner> _extra_corners;
770 
772  std::vector <Vanishing_point> _vpts;
773 
774  double focal_length;
775 
776 };
777 
778 std::ostream& operator<<(std::ostream& out, const Manhattan_corner& mc);
779 std::ostream & operator<<(std::ostream& out, const Manhattan_corner_segment& mcs);
780 std::ostream & operator<<(std::ostream& out, const Manhattan_segment& ms);
781 
782 Manhattan_world * create_manhattan_world_from_CMU_file(const std::string & file_name);
783 
785 (
786  const std::string & file_name,
787  const kjb::Edge_segment_set & iset,
788  unsigned int num_rows,
789  unsigned int num_cols
790 );
791 
792 }
793 
794 #endif
void create_corners3()
Creates corners by checking all possible intersections of three line segments.
Definition: manhattan_world.cpp:1218
void draw_corners3smart(kjb::Image &img, bool draw_full_segments=false, double width=1.0) const
Definition: manhattan_world.cpp:760
void write(const char *out_file) const
Writes this Manhattan world to an output file.
Definition: manhattan_world.h:581
Definition: edge_segment.h:36
#define MW_FOCAL_INIT_VALUE
Definition: manhattan_world.h:31
double get_strength() const
returns the average gradient magnitude of this edge
Definition: edge_segment.h:135
void reset_vanishing_points(const std::vector< Vanishing_point > &vpts)
Definition: manhattan_world.h:527
void draw(kjb::Image &img, bool draw_full_segments=false, double width=1.0) const
Definition: manhattan_world.cpp:100
friend std::ostream & operator<<(std::ostream &out, const Manhattan_segment &ms)
Manhattan_corner_segment(const Manhattan_segment &isegment, double idist=0.0, double iperp_dist=0.0)
Definition: manhattan_world.h:159
void compute_orthogonal_segments()
Definition: manhattan_world.cpp:529
const Manhattan_corner_segment * get_segment(unsigned int i) const
Definition: manhattan_world.h:312
size_type size() const
Alias to get_length(). Required to comply with stl Container concept.
Definition: m_vector.h:510
void create_corners()
Creates corners by checking all possible intersections of two and three line segments.
Definition: manhattan_world.cpp:1290
~Manhattan_corner()
Definition: manhattan_world.h:289
#define MW_OUTLIER_THRESHOLD
Definition: manhattan_world.h:28
Manhattan_corner(const Manhattan_corner &src)
Definition: manhattan_world.h:259
void draw_corners3up(kjb::Image &img, bool draw_full_segments=false, double width=1.0) const
Definition: manhattan_world.cpp:968
Manhattan_world(const std::vector< Vanishing_point > &ivpts, double ifocal=MW_FOCAL_INIT_VALUE)
Definition: manhattan_world.h:466
const Manhattan_segment & get_manhattan_segment() const
Definition: manhattan_world.h:180
void set_index(unsigned int i, unsigned int iindex)
Definition: manhattan_world.h:374
unsigned int get_num_corners3() const
Definition: manhattan_world.h:702
void read(std::istream &in, const Edge_segment_set &isegments, double outlier_threshold=MW_OUTLIER_THRESHOLD)
Reads this Manhattan world from an input stream.
Definition: manhattan_world.cpp:284
static bool create_corner3(Manhattan_corner &corner, const Manhattan_segment &seg3, unsigned int index3, double max_stretch=MAX_CORNER_SEGMENT_STRETCH, double max_perp_stretch=MAX_CORNER_PERP_SEGMENT_STRETCH)
Creates a corner from an already existing corner and a line segment. Returns false if the segment doe...
Definition: manhattan_world.cpp:1046
void draw_corners2smart(kjb::Image &img, bool draw_full_segments=false, double width=1.0) const
Definition: manhattan_world.cpp:749
#define MAX_CORNER_PERP_SEGMENT_STRETCH
Definition: manhattan_world.h:30
Manhattan_world * create_manhattan_world_from_CMU_file(const std::string &file_name)
Definition: manhattan_world.cpp:1572
void randomly_color(kjb::Image &img, double width=1.0) const
Randomly colors this line segment on an image.
Definition: gr_line_segment.cpp:438
void draw_extra_corners(kjb::Image &img, bool draw_full_segments=false, double width=1.0) const
Definition: manhattan_world.cpp:771
Definition: manhattan_world.h:249
const std::vector< Manhattan_corner > & get_extra_corners() const
Definition: manhattan_world.h:747
const std::vector< Vanishing_point > get_value_vanishing_points() const
Definition: manhattan_world.h:552
A vanishing point for a set of parallel lines in an image.
Definition: vanishing_point.h:37
unsigned num_lines_assigned_to_vp(unsigned vpindex) const
returns the length of the vector of the segments assigned to the vanishing point
Definition: manhattan_world.h:547
#define MW_MIN_FOCAL_INIT_VALUE
Definition: manhattan_world.h:32
const Manhattan_corner & get_corner_3(unsigned int i) const
Returns the ith corner consisting of the intersection of three line segments.
Definition: manhattan_world.h:603
This class implements vectors, in the linear-algebra sense, with real-valued elements.
Definition: m_vector.h:87
double get_strength() const
Definition: manhattan_world.h:195
void draw_mid_point_to_vanishing_point(kjb::Image &img, double ir, double ig, double ib, double width=1.0) const
Draws a line between the line segment mid point and the vanishing point it converges to Mostly for de...
Definition: manhattan_world.cpp:43
void write_corners(std::ostream &out) const
Definition: manhattan_world.cpp:874
void init_missing_orthogonal_segment(int iindex, double start_x, double start_y, double end_x, double end_y)
Definition: manhattan_world.cpp:407
void set_segment(unsigned int i, const Manhattan_segment &segment, double dist=0.0, double perp_dist=0)
Definition: manhattan_world.h:363
void set_extra_corners_from_vertical_pairs(const std::vector< Segment_pair > &vpairs)
Definition: manhattan_world.cpp:1386
const Edge_segment & get_edge_segment() const
Definition: manhattan_world.h:185
void read_manhattan_corner(Manhattan_corner &corner, std::istream &in) const
Definition: manhattan_world.cpp:779
double get_least_squares_fitting_error() const
returns the sum of square residuals between the edge points and the fitted line segment.
Definition: edge_segment.h:129
Manhattan_segment(const Edge_segment &isegment, Vanishing_point *ivp=0)
Definition: manhattan_world.h:45
bool is_outlier() const
Returns true if this segment is an outlier, ie it is not aligned with one of the three orthogonal dir...
Definition: manhattan_world.h:99
Definition: manhattan_world.h:155
const Manhattan_segment & get_manhattan_segment(unsigned int vp_index, unsigned int segment_index) const
Definition: manhattan_world.cpp:247
void print_corners(std::ostream &out) const
Definition: manhattan_world.h:712
const kjb::Vector & get_position() const
Returns the position of the corner in the image plane.
Definition: manhattan_world.h:333
void write_manhattan_corner(const Manhattan_corner &corner, std::ostream &out) const
Definition: manhattan_world.cpp:729
double dist(const pt a, const pt b)
compute approx. Great Circle distance between two UTM points
Definition: layer.cpp:45
friend std::ostream & operator<<(std::ostream &out, const Manhattan_corner &mc)
void draw(kjb::Image &img, double ir, double ig, double ib, double width=1.0) const
Draws this line segment.
Definition: gr_line_segment.cpp:423
~Manhattan_corner_segment()
Definition: manhattan_world.h:175
Manhattan_world * create_mw_from_CMU_file_and_compute_focal_length(const std::string &file_name, const kjb::Edge_segment_set &iset, unsigned int num_rows, unsigned int num_cols)
Definition: manhattan_world.cpp:1581
friend std::ostream & operator<<(std::ostream &out, const Manhattan_corner_segment &mcs)
bool create_corner3_from_incomplete(Manhattan_corner &corner, unsigned int index3, bool towards_vp, const kjb::Vector &position, bool check_consistency=true)
Definition: manhattan_world.cpp:1076
const Line_segment & get_orthogonal_segment(unsigned int i) const
Definition: manhattan_world.h:394
void write(std::ostream &out) const
Writes this Manhattan world to an output stream.
Definition: manhattan_world.cpp:396
void delete_segment(unsigned int i)
Definition: manhattan_world.h:383
Declarations for Line segment set classes.
void randomly_color(kjb::Image &img, double width=1.0) const
Randomly colors this Manhattan segment on an image.
Definition: manhattan_world.h:119
Manhattan_world(const char *filename, const Edge_segment_set &isegments, double outlier_threshold=MW_OUTLIER_THRESHOLD)
Definition: manhattan_world.h:482
void draw_corners(kjb::Image &img, bool draw_full_segments=false, double width=1.0) const
Definition: manhattan_world.cpp:935
const std::vector< Manhattan_corner > & get_corners2() const
Definition: manhattan_world.h:742
~Manhattan_segment()
Definition: manhattan_world.h:110
Manhattan_corner_segment(const Manhattan_corner_segment &src)
Definition: manhattan_world.h:167
unsigned int get_num_corners2() const
Definition: manhattan_world.h:697
double get_perpendicular_distance() const
Definition: manhattan_world.h:213
const Manhattan_corner & get_extra_corner(unsigned int i) const
Definition: manhattan_world.h:612
void read_corners(std::istream &in)
Definition: manhattan_world.cpp:888
bool is_up_corner() const
Definition: manhattan_world.cpp:681
Manhattan_world(const char *filename)
Definition: manhattan_world.h:489
const std::vector< std::vector< Manhattan_segment > > & get_assignments() const
returns the vector of the segments assigned to the correct vanishing point (outliers in the last vect...
Definition: manhattan_world.h:544
void set_focal_length(double ifocal)
returns the focal length
Definition: manhattan_world.h:522
void set_vanishing_point(Vanishing_point *ivp)
Definition: manhattan_world.h:70
void draw_corners2up(kjb::Image &img, bool draw_full_segments=false, double width=1.0) const
Definition: manhattan_world.cpp:957
double get_distance() const
Definition: manhattan_world.h:204
void draw_corners3(kjb::Image &img, bool draw_full_segments=false, double width=1.0) const
Definition: manhattan_world.cpp:949
void mark_as_outlier()
Marks this segment as an outlier.
Definition: manhattan_world.h:88
std::ofstream & operator<<(std::ofstream &out, const Quaternion &q)
Definition: turntable_camera.cpp:77
Manhattan_corner operator=(const Manhattan_corner &src)
Definition: manhattan_world.h:272
#define KJB_THROW_2(ex, msg)
Definition: l_exception.h:48
void draw_lines_from_segments_midpoint_to_vp(kjb::Image &img, double width=1.0) const
Draws a line between the mid point of each segment (excluding outliers) and the vanishing point the s...
Definition: manhattan_world.cpp:200
unsigned int num_available_segments() const
Definition: manhattan_world.cpp:87
void create_corners2()
Creates corners by checking all possible intersections of two line segments.
Definition: manhattan_world.cpp:1145
Manhattan_world(double ifocal=MW_FOCAL_INIT_VALUE)
Definition: manhattan_world.h:464
bool is_available(unsigned int i) const
Returns true if the ith corner segment was detected in the image, false if it is missing.
Definition: manhattan_world.h:303
This class contains the three orthogonal vanishing points defining a Manhattan scene, where most or all planes are aligned with three main orthogonal directions. This class optionally contains a set of segments from the scene, assigned to the correct vanishing point.
Definition: manhattan_world.h:460
Manhattan_world & operator=(const Manhattan_world &src)
Definition: manhattan_world.h:505
const std::vector< Vanishing_point > & get_vanishing_points() const
Returns the vanishing points.
Definition: manhattan_world.h:550
Manhattan_world(const Manhattan_world &src)
Definition: manhattan_world.h:501
void get_3D_corner(double z_distance, double princ_x, double princ_y, unsigned int index, bool usecorner3, kjb::Vector &corner3D_1, kjb::Vector &corner3D_2, kjb::Vector &corner3D_3, kjb::Vector &position_3D) const
Definition: manhattan_world.cpp:1339
double get_focal_length() const
returns the focal length
Definition: manhattan_world.h:516
void set_segment(const Manhattan_corner_segment &segment, unsigned int i)
Definition: manhattan_world.h:352
void print_corners2(std::ostream &out) const
Definition: manhattan_world.cpp:1296
double get_avg_segment_size() const
Definition: manhattan_world.cpp:706
const Edge_segment & get_edge_segment() const
returns the edge segment defining this manhattan segment
Definition: manhattan_world.h:65
Object thrown when an argument to a function is not acceptable.
Definition: l_exception.h:377
void compute_orthogonal_segment(unsigned int i)
Definition: manhattan_world.cpp:413
const std::vector< Manhattan_corner > & get_corners3() const
Definition: manhattan_world.h:737
void print_vanishing_points(std::ostream &out) const
Definition: manhattan_world.cpp:1321
double get_fitting_error() const
Definition: manhattan_world.h:190
void assign_segments_to_vpts(const Edge_segment_set &, double outlier_threshold=MW_OUTLIER_THRESHOLD)
Assigns each input segment to the vanishing point it converges to, or mark it as an outlier if it doe...
Definition: manhattan_world.cpp:166
const Manhattan_corner & get_corner_2(unsigned int i) const
Returns the ith corner consisting of the intersection of two line segments.
Definition: manhattan_world.h:593
void print_corners3(std::ostream &out) const
Definition: manhattan_world.cpp:1305
Manhattan_segment(const Manhattan_segment &src)
Definition: manhattan_world.h:60
get the indices of edges in each direction for i
Definition: APPgetLargeConnectedEdges.m:48
Object thrown when input or output fails.
Definition: l_exception.h:496
static double compute_alpha(const kjb::Vanishing_point &vp, const Line_segment *line)
Compute the angle between the line segment and the line through the vanishing point and the line segm...
Definition: vanishing_point_detector.cpp:126
void draw_corners2(kjb::Image &img, bool draw_full_segments=false, double width=1.0) const
Definition: manhattan_world.cpp:941
double get_alpha() const
returns alpha
Definition: manhattan_world.h:105
Class to manipulate a set of edge segments.
Definition: line_segment_set.h:128
void draw_segments_with_vp_assignments(kjb::Image &img, double width=1.0) const
draws the line segments with different colors according to the vanishing point they are assigned to (...
Definition: manhattan_world.cpp:227
Wrapped version of the C struct KJB_image.
Definition: i_image.h:76
unsigned int get_index(unsigned int i) const
Returns the index in the edge_segments vector stored in the Manahattan_world class corresponding to t...
Definition: manhattan_world.h:323
void set_position(const kjb::Vector &iposition)
Sets the position of the corner in the image plane.
Definition: manhattan_world.h:339
unsigned int get_num_extra_corners() const
Definition: manhattan_world.h:707
double compute_penalty() const
Definition: manhattan_world.cpp:261
static bool create_corner(Manhattan_corner &corner, const Manhattan_segment &seg1, const Manhattan_segment &seg2, unsigned int index1, unsigned int index2, double max_stretch=MAX_CORNER_SEGMENT_STRETCH)
Creates a corner from two line segments. Returns false if the segments do not intersect.
Definition: manhattan_world.cpp:991
A manhattan segment defined by a line segment and the vanishing point it converges to...
Definition: manhattan_world.h:42
Class to manipulate a line segment The class is parametrized in terms the position of the centre...
Definition: gr_line_segment.h:62
void get_direction(unsigned int segment_index, kjb::Vector &direction) const
Definition: manhattan_world.cpp:664
const Vanishing_point * get_vanishing_point() const
Returns the vanishing point this Manhattan segment converges to.
Definition: manhattan_world.h:68
Manhattan_world(std::istream &in, const Edge_segment_set &isegments, double outlier_threshold=MW_OUTLIER_THRESHOLD)
Definition: manhattan_world.h:494
void draw(kjb::Image &img, double ir, double ig, double ib, double width=1.0) const
Draws this Manhattan segment.
Definition: manhattan_world.h:113
#define MAX_CORNER_SEGMENT_STRETCH
Definition: manhattan_world.h:29
void get_3D_corner(double z_distance, double focal_length, double princ_x, double princ_y, kjb::Vector &corner3D_1, kjb::Vector &corner3D_2, kjb::Vector &corner3D_3, kjb::Vector &position_3D) const
Definition: manhattan_world.cpp:538
Manhattan_corner(std::vector< Vanishing_point > *ivpts)
Definition: manhattan_world.h:252