KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vanishing_point.h
Go to the documentation of this file.
1 /* $Id */
2 
3 /* =========================================================================== *
4 |
5 | Copyright (c) 1994-2008 by Kobus Barnard (author).
6 |
7 | Personal and educational use of this code is granted, provided that this
8 | header is kept intact, and that the authorship is not misrepresented, that
9 | its use is acknowledged in publications, and relevant papers are cited.
10 |
11 | For other use contact the author (kobus AT cs DOT arizona DOT edu).
12 |
13 | Please note that the code in this file has not necessarily been adequately
14 | tested. Naturally, there is no guarantee of performance, support, or fitness
15 | for any particular task. Nonetheless, I am interested in hearing about
16 | problems that you encounter.
17 |
18 | Author: Luca Del Pero
19 * =========================================================================== */
20 
21 #ifndef EDGE_VANISHING_POINT_H
22 #define EDGE_VANISHING_POINT_H
23 
24 #include "m_cpp/m_vector.h"
25 #include <l_cpp/l_readable.h>
26 #include <l_cpp/l_writeable.h>
27 #include <i_cpp/i_image.h>
28 #include <edge_cpp/line_segment.h>
29 
30 namespace kjb {
31 
37 class Vanishing_point : public Readable, public Writeable
38 {
39  public:
45  REGULAR = 0,
50  };
51 
54  Readable(), Writeable(), _point(2,0.0), _type(itype) { }
55 
56  Vanishing_point(double x, double y) : Readable(), Writeable(), _point(2,0.0)
57  {
58  _type = REGULAR;
59  _point(0) = x;
60  _point(1) = y;
61  }
62 
63  Vanishing_point(const kjb::Vector & position) : Readable(), Writeable(), _point(2,0.0)
64  {
65  if(position.size() != 2)
66  {
67  throw kjb::Illegal_argument("Vanishing point vector size must be 2");
68  }
69  _type = REGULAR;
70  _point = position;
71  }
72 
73  Vanishing_point(const char *filename) : Readable(), Writeable(), _point(2,0.0)
74  {
75  Readable::read(filename);
76  }
77 
78  Vanishing_point(std::istream& in) : Readable(), Writeable(), _point(2,0.0)
79  {
80  read(in);
81  }
82 
83 
85  : Readable(), Writeable(), _point(src._point), _type(src._type) { }
86 
88  {
89  _point = src._point;
90  _type = src._type;
91  return (*this);
92  }
93 
94  bool operator==(const Vanishing_point & vp);
95 
96 
98 
100  bool is_at_infinity() const
101  {
102  return(_type);
103  }
104 
107  {
108  return _type;
109  }
110 
112  double get_x() const
113  {
114  return _point(0);
115  }
116 
118  double get_y() const
119  {
120  return _point(1);
121  }
122 
123  void set_x(double ix)
124  {
125  _point(0) = ix;
126  }
127 
128  void set_y(double iy)
129  {
130  _point(1) = iy;
131  }
132 
134  void set_type(const Vanishing_point_type & itype)
135  {
136  _type = itype;
137  if(_type > REGULAR)
138  {
139  _point(0) = 0.0;
140  _point(1) = 0.0;
141  }
142  }
143 
145  void set_point(double x, double y)
146  {
147  _type = REGULAR;
148  _point(0) = x;
149  _point(1) = y;
150  }
151 
153  void set_position(const kjb::Vector & position)
154  {
155  if(position.size() != 2)
156  {
157  throw kjb::Illegal_argument("Vanishing point vector size must be 2");
158  }
159  _type = REGULAR;
160  _point = position;
161  }
162 
164  void read(std::istream& in);
165 
167  void write(std::ostream& out) const;
168 
169  private:
170 
171 #warning "[Code police] Please don't start identifiers with underscore."
172 
175  kjb::Vector _point;
176 
180  Vanishing_point_type _type;
181 
182 
183 };
184 
186 (
187  std::vector<Vanishing_point> & vpts,
188  double & focal_length,
189  std::string file_name
190 );
191 
192 
194 (
195  kjb::Image & img,
196  const Line_segment & segment,
197  const Vanishing_point & vpt,
198  double ir,
199  double ig,
200  double ib,
201  double width
202 );
203 
205 (
206  const kjb::Vanishing_point & vp1,
207  double focal,
208  unsigned int img_cols,
209  unsigned int img_rows,
210  const Line_segment & ls,
211  Vanishing_point & vpt
212 );
213 
215 (
216  const kjb::Vanishing_point & vp1,
217  const kjb::Vanishing_point & vp2,
218  double focal,
219  unsigned int img_rows,
220  unsigned int img_cols,
221  Vanishing_point & vpt
222 );
223 
225 (
226  std::vector<Vanishing_point> & vpts,
227  double & focal,
228  const std::string & file_path,
229  unsigned int num_cols,
230  unsigned int num_rows
231 );
232 
234 (
235  Vanishing_point & vp1,
236  Vanishing_point & vp2,
237  Vanishing_point & estimated_vertical,
238  unsigned int img_cols,
239  unsigned int img_rows
240 );
241 
242 }
243 #endif /*VANISHING_POINT_DETECTION */
void set_position(const kjb::Vector &position)
Sets the position of this Vanishing point.
Definition: vanishing_point.h:153
Vanishing_point(const kjb::Vector &position)
Definition: vanishing_point.h:63
double get_x() const
returns the x coordinate of this vanishing point
Definition: vanishing_point.h:112
Abstract class to write this object to an output stream.
Definition: l_writeable.h:41
bool read_hedau_vanishing_points(std::vector< Vanishing_point > &vpts, double &focal, const std::string &file_path, unsigned int num_cols, unsigned int num_rows)
Definition: vanishing_point.cpp:330
void set_y(double iy)
Definition: vanishing_point.h:128
size_type size() const
Alias to get_length(). Required to comply with stl Container concept.
Definition: m_vector.h:510
const Vanishing_point_type & get_type() const
returns the vanishing point type
Definition: vanishing_point.h:106
Abstract class to read this object from an input stream.
Definition: l_readable.h:39
bool operator==(const Vanishing_point &vp)
Definition: vanishing_point.cpp:85
Vanishing_point(Vanishing_point_type itype=REGULAR)
Default constructor, it initialize the vanishing point in (0,0)
Definition: vanishing_point.h:53
A vanishing point for a set of parallel lines in an image.
Definition: vanishing_point.h:37
Vanishing_point_type
the possible types of vanishing point. We need this to differentiate between vanishing points with fi...
Definition: vanishing_point.h:44
bool find_vanishing_point_given_one_and_line(const kjb::Vanishing_point &vp1, double focal, unsigned int img_cols, unsigned int img_rows, const Line_segment &ls, Vanishing_point &vpt)
Definition: vanishing_point.cpp:245
void set_x(double ix)
Definition: vanishing_point.h:123
This class implements vectors, in the linear-algebra sense, with real-valued elements.
Definition: m_vector.h:87
Definition: vanishing_point.h:47
Vanishing_point(double x, double y)
Definition: vanishing_point.h:56
void read_CMU_vanishing_points(std::vector< Vanishing_point > &vpts, double &focal_length, std::string file_name)
Definition: vanishing_point.cpp:111
Definition: vanishing_point.h:49
Vanishing_point(const char *filename)
Definition: vanishing_point.h:73
Vanishing_point & operator=(const Vanishing_point &src)
Definition: vanishing_point.h:87
Definition: vanishing_point.h:48
x
Definition: APPgetLargeConnectedEdges.m:100
Vanishing_point(const Vanishing_point &src)
Definition: vanishing_point.h:84
void set_point(double x, double y)
Sets the position of this Vanishing point.
Definition: vanishing_point.h:145
~Vanishing_point()
Definition: vanishing_point.h:97
void draw_mid_point_to_vanishing_point(kjb::Image &img, const Line_segment &segment, const Vanishing_point &vpt, double ir, double ig, double ib, double width)
Definition: vanishing_point.cpp:204
void set_type(const Vanishing_point_type &itype)
Sets the type of this Vanishing point.
Definition: vanishing_point.h:134
double get_y() const
returns the y coordinate of this vanishing point
Definition: vanishing_point.h:118
void read(std::istream &in)
Reads this Vanishing point from an input stream.
Definition: vanishing_point.cpp:39
Object thrown when an argument to a function is not acceptable.
Definition: l_exception.h:377
bool find_third_vanishing_point(const kjb::Vanishing_point &vp1, const kjb::Vanishing_point &vp2, double focal, unsigned int img_rows, unsigned int img_cols, Vanishing_point &vpt)
Definition: vanishing_point.cpp:290
Vanishing_point(std::istream &in)
Definition: vanishing_point.h:78
virtual void read(std::istream &in)=0
Reads this Readable from an input stream.
Code for a wrapper class around the C struct KJB_Image.
Definition: vanishing_point.h:45
Wrapped version of the C struct KJB_image.
Definition: i_image.h:76
Definition: vanishing_point.h:46
bool is_at_infinity() const
returns true is the vanishing point is at infinity
Definition: vanishing_point.h:100
Definition for the Vector class, a thin wrapper on the KJB Vector struct and its related functionalit...
bool find_vertical_vanishing_point(Vanishing_point &vp1, Vanishing_point &vp2, Vanishing_point &estimated_vertical, unsigned int img_cols, unsigned int img_rows)
Definition: vanishing_point.cpp:375
void write(std::ostream &out) const
Writes this Vanishing point to an output stream.
Definition: vanishing_point.cpp:79