KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gr_renderable_model.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
52 |
53 * =========================================================================== */
54 
55 
67 #ifndef GR_RENDERABLE_MODEL_H_
68 #define GR_RENDERABLE_MODEL_H_
69 
70 #include <gr_cpp/gr_renderable.h>
71 #include <l_cpp/l_cloneable.h>
72 
73 namespace kjb
74 {
75  class Base_gl_interface;
76 
77  /*
78  * @class Renderable_model This class implements basic functionalities for a parametric model
79  * with the capability of being renderable. This assumes that a model has some parameters and
80  * a representation used for rendering that need to be consistent with the value of
81  * the model parameters. Since updating the rendering interface to match the model
82  * parameters is usually expensive, we do it only when it is strictly necessary, that is
83  * to say before calling any rendering method. This class provides basic rendering
84  * methods (wireframe, solid, wireframe with occluded edges removed) that check whether
85  * the rendering interface is updated before calling the appropriate rendering method,
86  * and update it if it is the case
87  */
89  {
90  public:
91 
97  Renderable_model(bool istatus = false) : Cloneable()
98  {
99  _rendering_representation_updated = istatus;
100  }
101 
104  {
105  (*this) = src;
106  }
107 
109  inline Renderable_model & operator=(const Renderable_model & /* src */)
110  {
111  _rendering_representation_updated = false;
112  return (*this);
113  }
114 
115  virtual ~Renderable_model() { }
116 
118  virtual void wire_render() const throw(kjb::KJB_error);
120  virtual void wire_occlude_render() const throw(kjb::KJB_error);
122  virtual void solid_render() const throw(kjb::KJB_error);
124  virtual void render_occluded_wireframe() const throw(kjb::KJB_error);
125 
127  virtual void silhouette_render(const kjb::Base_gl_interface &, double width = 1.0) const;
128 
130  inline void update_if_needed() const
131  {
132  if(!_rendering_representation_updated)
133  {
135  _rendering_representation_updated = true;
136  }
137  }
138 
139  inline void force_update() const
140  {
142  _rendering_representation_updated = true;
143  }
144 
145  protected:
147  virtual Abstract_renderable & get_rendering_interface() const = 0;
148 
151  virtual void update_rendering_representation() const throw(kjb::KJB_error) = 0;
152 
159  {
160  _rendering_representation_updated = false;
161  }
162 
163  private:
167  mutable bool _rendering_representation_updated;
168  };
169 }
170 
171 #endif
virtual void wire_occlude_render() const
Renders this model into the depth buffer.
Definition: gr_renderable_model.cpp:70
Definition: gr_renderable_model.h:88
virtual void solid_render() const
Renders this model as a solid.
Definition: gr_renderable_model.cpp:76
virtual void update_rendering_representation() const =0
Updates the rendering interface so that it reflects the paremeter values of this model to the renderi...
virtual Abstract_renderable & get_rendering_interface() const =0
Returns a reference to the rendering interface used to render this model.
Abstract class to clone this object.
Definition: l_cloneable.h:45
Abstract class to render this object with GL.
Definition: gr_renderable.h:151
Renderable_model & operator=(const Renderable_model &)
Assignment operator.
Definition: gr_renderable_model.h:109
virtual void wire_render() const
Renders this model as a wireframe.
Definition: gr_renderable_model.cpp:58
virtual ~Renderable_model()
Definition: gr_renderable_model.h:115
void update_if_needed() const
Definition: gr_renderable_model.h:130
Abstract class to clone this object.
Renderable_model(bool istatus=false)
Constructor.
Definition: gr_renderable_model.h:97
Exception often thrown when wrapped C functions return error codes.
Definition: l_exception.h:262
void set_rendering_representation_dirty() const
This method is called to whenever the model parameters where changed without updating the rendering i...
Definition: gr_renderable_model.h:158
Definition: gr_camera.h:103
void force_update() const
Definition: gr_renderable_model.h:139
virtual void silhouette_render(const kjb::Base_gl_interface &, double width=1.0) const
renders the silhouette of this object
Definition: gr_renderable_model.cpp:82
Renderable_model(const Renderable_model &src)
Copy constructor.
Definition: gr_renderable_model.h:103
virtual void render_occluded_wireframe() const
Renders this model as a wireframe by removing occluded edges.
Definition: gr_renderable_model.cpp:64