KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
camera_frustum.h
Go to the documentation of this file.
1 
35 /* =========================================================================== *
36 |
37 | Copyright (c) 1994-2008 by Kobus Barnard (author).
38 |
39 | Personal and educational use of this code is granted, provided that this
40 | header is kept intact, and that the authorship is not misrepresented, that
41 | its use is acknowledged in publications, and relevant papers are cited.
42 |
43 | For other use contact the author (kobus AT cs DOT arizona DOT edu).
44 |
45 | Please note that the code in this file has not necessarily been adequately
46 | tested. Naturally, there is no guarantee of performance, support, or fitness
47 | for any particular task. Nonetheless, I am interested in hearing about
48 | problems that you encounter.
49 |
50 | Authors:
51 | Luca Del Pero, Yuanliu Liu
52 |
53 * =========================================================================== */
54 
55 
67 #ifndef CAMERA_CPP_CAMERA_FRUSTUM_H_
68 #define CAMERA_CPP_CAMERA_FRUSTUM_H_
69 
71 #include <g_cpp/g_quaternion.h>
72 #include <m_cpp/m_vector.h>
74 
75 #define CAMERA_FRUSTUM_PITCH 0
76 #define CAMERA_FRUSTUM_YAW 1
77 #define CAMERA_FRUSTUM_ROLL 2
78 
79 #define CAMERA_FRUSTUM_WIDTH 0
80 #define CAMERA_FRUSTUM_LENGTH 1
81 #define CAMERA_FRUSTUM_TOP_RADIUS 2
82 #define CAMERA_FRUSTUM_HEIGHT 3
83 
84 namespace kjb
85 {
86 
87 class Perspective_camera;
88 class Manhattan_corner;
89 
101 {
102 public:
103 
104  Parametric_frustum( unsigned int inv = 6, double ix = 0.0, double iy = 0.0,
105  double iz = 0.0, double iw = 1.0, double il = 1.0, double iratio_top_bottom
106  = 1.0, double ih = 1.0,
107  double ipitch = 0.0, double iyaw = 0.0, double iroll = 0.0) throw(kjb::Illegal_argument);
108 
110  Parametric_frustum(const char* fname) throw (kjb::Illegal_argument,
111  kjb::IO_error);
112 
114  Parametric_frustum(std::istream& in) throw (kjb::Illegal_argument,
115  kjb::IO_error);
116 
119 
121  virtual void read(std::istream& in) throw (kjb::Illegal_argument,
122  kjb::IO_error);
123 
125  virtual void read(const char * fname) throw (kjb::IO_error, kjb::Illegal_argument)
126  {
127  Readable::read(fname);
128  }
129 
131  virtual void write(std::ostream& out) const
132  throw (kjb::IO_error);
133 
135  virtual void write(const char * fname) const
136  throw (kjb::IO_error)
137  {
138  Writeable::write(fname);
139  }
140 
143 
146  {
148  return rendering_interface;
149  }
150 
155  virtual void update_rendering_representation() const throw(kjb::KJB_error);
156 
157  virtual Parametric_frustum * clone() const;
158  virtual ~Parametric_frustum() { }
159 
161  inline double get_width() const {return height; }
163  inline double get_length() const {return length; }
165  inline double get_ratio_top_bottom() const {return ratio_top_bottom; }
167  inline double get_height() const {return height; }
168 
170  inline double get_pitch() const {return rotation_angles(CAMERA_FRUSTUM_PITCH);}
172  inline double get_yaw() const {return rotation_angles(CAMERA_FRUSTUM_YAW);}
174  inline double get_roll() const {return rotation_angles(CAMERA_FRUSTUM_ROLL);}
175 
177  inline const Vector & get_centre() const {return centre;}
179  inline double get_centre_x() const {return centre(0); }
181  inline double get_centre_y() const {return centre(1); }
183  inline double get_centre_z() const {return centre(2); }
184 
186  void set_width(double iwidth) throw(kjb::Illegal_argument);
188  void set_length(double ilength)throw(kjb::Illegal_argument);
190  void set_ratio_top_bottom(double iratio_top_bottom)throw(kjb::Illegal_argument);
192  void set_height(double iheight) throw(kjb::Illegal_argument);
193 
195  void set_pitch(double ip);
197  void set_yaw(double iy);
199  void set_roll(double ir);
200 
202  virtual void rotate_around_x_axis(double theta);
203 
205  virtual void rotate_around_y_axis(double theta);
206 
208  virtual void rotate_around_z_axis(double theta);
209 
211  virtual void rotate_around_frustum_axes(double thetax, double thetay, double thetaz);
212 
214  void set_centre(const kjb::Vector & icentre) throw(kjb::Illegal_argument);
216  void set_centre_x(double ix) throw(kjb::Illegal_argument);
218  void set_centre_y(double iy) throw(kjb::Illegal_argument);
220  void set_centre_z(double iz) throw(kjb::Illegal_argument);
221 
223  virtual void set_angles_from_quaternion(const kjb::Quaternion & q);
224 
227  {
229  return rendering_interface.get_orientation();
230  }
231 
241  {
242  KJB(UNTESTED_CODE());
243  rendering_interface.set_rotation_mode(imode);
244  }
245 
246  void stretch_along_axis(unsigned int axis, double amount, bool direction);
247 
252  (
253  const kjb::Vector & point_in_world_coordinates,
254  kjb::Vector & point_in_parapiped_coordinates
255  ) const;
256 
260  (
261  const kjb::Vector & point_in_parapiped_coordinates,
262  kjb::Vector & point_in_world_coordinates
263  ) const;
264 
265 /* void draw_orientation_map() const;
266 
267  void draw_left_right_orientation_map() const;
268 
269  void draw_geometric_context_map() const;*/
270 
271  void get_lines(std::vector<Line3d> & lines);
272 
273  void get_vertices(std::vector<Vector> & vertices);
274 
275  static int get_num_rendering_interface_edges(int num_facets)
276  {
277  return Frustum::get_num_edges(num_facets);
278  }
279 
281  (
282  std::vector<int> & base_edge_indexes,
283  std::vector<int> & vertical_edge_indexes,
284  std::vector<int> & top_edge_indexes,
285  int num_facets
286  )
287  {
288  return Frustum::get_edge_indexes(base_edge_indexes,
289  vertical_edge_indexes, top_edge_indexes, num_facets);
290  }
291 
292 private:
293 
296  void compute_new_euler_angles_on_rotations(double dpitch, double dyaw, double droll);
297 
298  unsigned int num_vertices;
299  //double radius_bottom;
300  //double radius_top;
301  double width; // the diameter of the bottom ellipse along the x axis
302  double length; // the diameter of the bottom ellipse along the z axis
303  double ratio_top_bottom;
304  double height;
305 
306  kjb::Vector centre;
307 
308  /* The rotation angle around the object's x axis (pitch), the
309  * object's y axis (yaw) and the object's z axis (roll). Stored
310  * in this order */
311  kjb::Vector rotation_angles;
312 
316  mutable kjb::Frustum rendering_interface;
317 
318 };
319 
320 
321 }
322 
323 #endif /* CAMERA_CPP_CAMERA_FRUSTUM_H_ */
virtual void rotate_around_frustum_axes(double thetax, double thetay, double thetaz)
rotates the parapiped around its x,y,z axes in this order
Definition: camera_frustum.cpp:306
void set_length(double ilength)
Sets the length of the base of this Parametric_frustum.
Definition: camera_frustum.cpp:217
#define CAMERA_FRUSTUM_ROLL
Definition: camera_frustum.h:77
double get_roll() const
Returns the roll of this parametric frustum.
Definition: camera_frustum.h:174
void get_lines(std::vector< Line3d > &lines)
Definition: camera_frustum.cpp:682
Abstract class to write this object to an output stream.
Definition: l_writeable.h:41
#define CAMERA_FRUSTUM_YAW
Definition: camera_frustum.h:76
virtual void rotate_around_y_axis(double theta)
rotates the truncated cone around its x-axis
Definition: camera_frustum.cpp:282
frustum: a polyhedron of which each torso face is a trapezoid and the top and bottom surfaces are pol...
Definition: gr_parametric_frustum.h:82
function lines
Definition: APPgetLargeConnectedEdges.m:1
Abstract class to read this object from an input stream.
Definition: l_readable.h:39
void set_rotation_mode(kjb::Quaternion::Euler_mode imode)
Definition: camera_frustum.h:240
Definition: gr_renderable_model.h:88
virtual Abstract_renderable & get_rendering_interface() const
returns the rendering interface used to render this Parametric_frustum
Definition: camera_frustum.cpp:395
theta
Definition: APPgetLargeConnectedEdges.m:108
#define KJB(x)
Definition: l_util.h:9
double get_ratio_top_bottom() const
Returns the ratio of the top and bottom surface of this parametric frustum.
Definition: camera_frustum.h:165
virtual void write(const char *fname) const
Writes this Parametric_frustum to an output stream.
Definition: camera_frustum.h:135
This class implements vectors, in the linear-algebra sense, with real-valued elements.
Definition: m_vector.h:87
virtual void write(std::ostream &out) const =0
Writes this Writeable to an output stream.
Euler_mode
Definition: g_quaternion.h:55
Parametric_frustum(unsigned int inv=6, double ix=0.0, double iy=0.0, double iz=0.0, double iw=1.0, double il=1.0, double iratio_top_bottom=1.0, double ih=1.0, double ipitch=0.0, double iyaw=0.0, double iroll=0.0)
Definition: camera_frustum.cpp:76
virtual void update_rendering_representation() const
updates the rendering representation so that it reflects the current values of the parameters...
Definition: camera_frustum.cpp:384
virtual void read(std::istream &in)
Reads this Parametric_frustum from an input stream.
Definition: camera_frustum.cpp:404
double get_centre_z() const
Returns the x coordinate of the centre of this Parametric_frustum.
Definition: camera_frustum.h:183
double get_centre_x() const
Returns the x coordinate of the centre of this Parametric_frustum.
Definition: camera_frustum.h:179
double get_centre_y() const
Returns the x coordinate of the centre of this Parametric_frustum.
Definition: camera_frustum.h:181
Definition: gr_renderable.h:151
static int get_rendering_interface_edge_indexes(std::vector< int > &base_edge_indexes, std::vector< int > &vertical_edge_indexes, std::vector< int > &top_edge_indexes, int num_facets)
Definition: camera_frustum.h:281
void set_height(double iheight)
Sets the height of this Parametric_frustum.
Definition: camera_frustum.cpp:189
void set_centre_y(double iy)
Sets the y coordinate of the centre of this parametric_frustum.
Definition: camera_frustum.cpp:350
Definition: g_quaternion.h:40
void set_centre_x(double ix)
Sets the x coordinate of the centre of this parametric_frustum.
Definition: camera_frustum.cpp:341
void stretch_along_axis(unsigned int axis, double amount, bool direction)
Definition: camera_frustum.cpp:564
const kjb::Quaternion & get_orientation() const
returns the quaternion defining this object's orientation
Definition: gr_rigid_object.h:174
Polymesh & get_polymesh() const
returns the polymesh used to render this Parametric_frustum
Definition: camera_frustum.h:145
void update_if_needed() const
Definition: gr_renderable_model.h:130
virtual void rotate_around_z_axis(double theta)
rotates the parapiped around its x-axis
Definition: camera_frustum.cpp:291
static int get_edge_indexes(std::vector< int > &base_edge_indexes, std::vector< int > &vertical_edge_indexes, std::vector< int > &top_edge_indexes, int num_facets)
Definition: gr_parametric_frustum.h:188
Definition: camera_frustum.h:100
void get_point_in_world_coordinates(const kjb::Vector &point_in_parapiped_coordinates, kjb::Vector &point_in_world_coordinates) const
Transforms a point in parapiped coordinates to world coordinates.
Definition: camera_frustum.cpp:662
Abstract class of connected polygons (faces) forming a mesh. We assume that each edge is shared betwe...
Definition: gr_polymesh.h:89
virtual void read(const char *fname)
Reads this Parametric_frustum from a file.
Definition: camera_frustum.h:125
const kjb::Quaternion & get_rotations_as_a_quaternion() const
returns the rotations of this parapiped as a quaternion
Definition: camera_frustum.h:226
virtual void set_angles_from_quaternion(const kjb::Quaternion &q)
sets the rotation angles from an input quaternion
Definition: camera_frustum.cpp:370
Exception often thrown when wrapped C functions return error codes.
Definition: l_exception.h:262
void set_centre_z(double iz)
Sets the z coordinate of the centre of this parametric_frustum.
Definition: camera_frustum.cpp:359
double get_height() const
Returns the height of this parametric frustum.
Definition: camera_frustum.h:167
void set_width(double iwidth)
Sets the width of the base of this Parametric_frustum.
Definition: camera_frustum.cpp:174
double get_yaw() const
Returns the yaw of this parametric frustum.
Definition: camera_frustum.h:172
void set_centre(const kjb::Vector &icentre)
Sets the centre of this parametric_frustum.
Definition: camera_frustum.cpp:314
void set_ratio_top_bottom(double iratio_top_bottom)
Sets the ratio between the top and the base of this Parametric_frustum.
Definition: camera_frustum.cpp:203
static int get_num_edges(int num_facets)
Definition: gr_parametric_frustum.h:181
void set_roll(double ir)
Sets the roll of this Parametric_frustum.
Definition: camera_frustum.cpp:249
Parametric_frustum & operator=(const Parametric_frustum &src)
Definition: camera_frustum.cpp:144
frustum: a hexahedron of which each face is a parallelegram.
Object thrown when an argument to a function is not acceptable.
Definition: l_exception.h:377
void set_pitch(double ip)
Sets the pitch of this Parametric_frustum.
Definition: camera_frustum.cpp:231
void get_vertices(std::vector< Vector > &vertices)
Definition: camera_frustum.cpp:688
virtual void read(std::istream &in)=0
Reads this Readable from an input stream.
double get_width() const
Returns the width of this parametric frustum.
Definition: camera_frustum.h:161
Object thrown when input or output fails.
Definition: l_exception.h:496
virtual void write(std::ostream &out) const
Writes this Parametric_frustum to a file.
Definition: camera_frustum.cpp:545
St_renderable_model Base class for a structure model with a renderable representation.
virtual void rotate_around_x_axis(double theta)
rotates the truncated cone around its x-axis
Definition: camera_frustum.cpp:273
const Vector & get_centre() const
Returns the centre of this Parametric_frustum.
Definition: camera_frustum.h:177
static int get_num_rendering_interface_edges(int num_facets)
Definition: camera_frustum.h:275
double get_length() const
Returns the length of this parametric frustum.
Definition: camera_frustum.h:163
#define CAMERA_FRUSTUM_PITCH
Definition: camera_frustum.h:75
Definition for the Vector class, a thin wrapper on the KJB Vector struct and its related functionalit...
void get_point_in_parapiped_coordinates(const kjb::Vector &point_in_world_coordinates, kjb::Vector &point_in_parapiped_coordinates) const
Definition: camera_frustum.cpp:640
void set_rotation_mode(kjb::Quaternion::Euler_mode imode)
Definition: gr_rigid_object.h:168
void set_yaw(double iy)
Sets the yaw of this Parametric_frustum.
Definition: camera_frustum.cpp:240
double get_pitch() const
Returns the pitch of this parametric frustum.
Definition: camera_frustum.h:170
virtual Parametric_frustum * clone() const
Processes an Option from program command-line arguments.
Definition: camera_frustum.cpp:166