KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gr_frustum.h
Go to the documentation of this file.
1 /* $Id: gr_frustum.h 18301 2014-11-26 19:17:13Z ksimek $ */
2 /* {{{=========================================================================== *
3  |
4  | Copyright (c) 1994-2012 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 // vim: tabstop=4 shiftwidth=4 foldmethod=marker
21 
22 #ifdef KJB_HAVE_OPENGL
23 #ifndef KJB_GR_CPP_GR_FRUSTUM
24 #define KJB_GR_CPP_GR_FRUSTUM
25 
26 #include <m_cpp/m_matrix.h>
27 #include <m_cpp/m_vector_d.h>
28 #include <i_cpp/i_image.h>
30 #include <gr_cpp/gr_renderable.h>
31 
32 #include <boost/shared_ptr.hpp>
33 
34 namespace kjb
35 {
36 namespace opengl
37 {
51 class Frustum_display : public kjb::Renderable
52 {
53 public:
54 
63  Frustum_display(
64  const kjb::Vector& center,
65  const kjb::Matrix& cam,
66  double image_width,
67  double image_height,
68  double near,
69  double far) :
70  center_(),
71  z_near_(near),
72  z_far_(far),
73  image_(),
74  m_inv_(),
75  width_(image_width),
76  height_(image_height),
77  show_frame_(true),
78  image_alpha_(0.5)
79  {
80  set_camera(center, cam);
81  }
82 
83  void show_frame(bool b)
84  {
85  show_frame_ = b;
86  }
87 
88  void set_image_opacity(double alpha)
89  {
90  image_alpha_ = alpha;
91  }
92 
93  void set_camera(const kjb::Vector& center, const kjb::Matrix& cam)
94  {
95  assert(center.size() >= 3 && center.size() <= 4);
96  std::copy(center.begin(), center.begin() + 3, center_.begin());
97 
98  m_inv_ = cam;
99  m_inv_ = kjb::matrix_inverse(m_inv_.resize(3,3));
100  m_inv_.resize(4,4,0.0);
101  m_inv_(3,3) = 1.0;
102 
103  }
104 
105  void set_image(const kjb::Image& img)
106  {
107  image_.reset(new kjb::opengl::Texture());
108  image_->set(img);
109  }
110 
111  void set_near(double near)
112  {
113  z_near_ = near;
114  }
115 
116  void render() const;
117 
118 private:
119  kjb::Vector3 center_;
120  double z_near_;
121  double z_far_;
122  boost::shared_ptr<kjb::opengl::Texture> image_;
123 
124  kjb::Matrix m_inv_;
125  double width_;
126  double height_;
127  bool show_frame_;
128  double image_alpha_;
129 };
130 
131 }
132 }
133 #endif
134 #endif /* KJB_HAVE_OPENGL */
Definition for the Matrix class, a thin wrapper on the KJB Matrix struct and its related functionalit...
size_type size() const
Alias to get_length(). Required to comply with stl Container concept.
Definition: m_vector.h:510
Abstract class to render this object with GL.
Definition: gr_renderable.h:78
This class implements vectors, in the linear-algebra sense, with real-valued elements.
Definition: m_vector.h:87
Matrix matrix_inverse(const Matrix &op1)
Invert this matrix.
Definition: m_matrix.cpp:730
Abstract class to render this object with GL.
iterator begin()
Definition: m_vector.h:537
void render(const Cuboid &c)
Definition: psi_weighted_box.cpp:56
Matrix & resize(int new_rows, int new_cols, Value_type pad=Value_type(0))
Resize this matrix, retaining previous values. Space is reused if possible. Otherwise requires a new ...
Definition: m_matrix.cpp:457
This class implements matrices, in the linear-algebra sense, with real-valued elements.
Definition: m_matrix.h:94
Code for a wrapper class around the C struct KJB_Image.
Wrapped version of the C struct KJB_image.
Definition: i_image.h:76