iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ShapeRenderer.H
Go to the documentation of this file.
1 /*! @file
2  @author Laurent Itti
3  @copyright GNU Public License (GPL v3)
4  @section License
5  @verbatim
6  // ////////////////////////////////////////////////////////////////////////
7  // The iLab Neuromorphic Robotics Toolkit (NRT) //
8  // Copyright 2010-2012 by the University of Southern California (USC) //
9  // and the iLab at USC. //
10  // //
11  // iLab - University of Southern California //
12  // Hedco Neurociences Building, Room HNB-10 //
13  // Los Angeles, Ca 90089-2520 - USA //
14  // //
15  // See http://ilab.usc.edu for information about this project. //
16  // ////////////////////////////////////////////////////////////////////////
17  // This file is part of The iLab Neuromorphic Robotics Toolkit. //
18  // //
19  // The iLab Neuromorphic Robotics Toolkit is free software: you can //
20  // redistribute it and/or modify it under the terms of the GNU General //
21  // Public License as published by the Free Software Foundation, either //
22  // version 3 of the License, or (at your option) any later version. //
23  // //
24  // The iLab Neuromorphic Robotics Toolkit is distributed in the hope //
25  // that it will be useful, but WITHOUT ANY WARRANTY; without even the //
26  // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //
27  // PURPOSE. See the GNU General Public License for more details. //
28  // //
29  // You should have received a copy of the GNU General Public License //
30  // along with The iLab Neuromorphic Robotics Toolkit. If not, see //
31  // <http://www.gnu.org/licenses/>. //
32  // ////////////////////////////////////////////////////////////////////////
33  @endverbatim */
34 
35 
36 #ifndef INCLUDE_NRT_GRAPHICS_SHAPERENDERER_H
37 #define INCLUDE_NRT_GRAPHICS_SHAPERENDERER_H
38 
39 #include <nrt/Core/Geometry/Dims.H>
41 #include <nrt/Eigen/Eigen.H>
42 #include <nrt/Graphics/Camera.H>
45 #include <X11/X.h>
46 #ifdef None
47 int const X11_None = None;
48 #undef None
49 #endif
50 #include <X11/keysym.h>
51 
52 namespace nrt
53 {
54  namespace graphics
55  {
56  namespace mocap { class Skeleton; }
57 
58  //! Base class for a graphics shape renderer. See, for example, ShapeRendererBasic for derived classes.
59  /*! The shape renderer is a simplified front-end to OpenGL rendering of shapes in a 3D scene. \ingroup graphics */
61  {
62  public:
63  //! Default constructor
64  /*! This should do very little, most initialization should happen in preStart(). \see Component */
65  ShapeRenderer(std::string const & instanceName = "");
66 
67  //! Virtual destructor for safe inheritance
68  virtual ~ShapeRenderer();
69 
70  //! A key pressed on the keyboard, along with whether this was a release (true) or press (false)
72  {
73  KeyboardPress(KeySym k, bool r) : key(k), release(r) { }
74  KeySym key;
75  bool release;
76  };
77 
78  //! Access our DisplayListManager to create/delete/access display lists
79  /*! \note All displaylists are erased on stop() */
81 
82  //! Access our TextureManager to create/delete/access textures
83  /*! \note All textures are erased on stop() */
85 
86  //! Access our map of skeletons
87  std::map<std::string, nrt::graphics::mocap::Skeleton> & skeletons();
88 
89  //! Get dimensions of renderer
90  virtual Dims<int32> dims() const = 0;
91 
92  //! Primitive shapes optimized as DisplayLists
93  /*! Before you call any of these functions, you should already have obtained a glX context lock. Mainly, these
94  functions are for the use of programmers that code complex shapes as assemblages of these elementary shapes;
95  end users should just use Shape objects instead. For example, use render() on a Sphere shape instead of
96  calling drawSphere() here (indeed, render() for a Sphere just calls drawSphere() internally after setting up
97  the transform, Brush, Pen, etc). */
98  //!@{
99  //! Draw a unit sphere
100  virtual void drawSphere() const = 0;
101 
102  //! Draw a unit cylinder
103  virtual void drawCylinder(bool capped) const = 0;
104 
105  //!@}
106 
107  protected:
108  std::shared_ptr<nrt::graphics::Camera> itsCamera; //!< Our camera, defines projection and view matrices
109 
110  //! Function called when a window resize event is received
111  /*! Overload this to resize your display to the given width and height */
112  virtual void resizeCallback(int width, int height) = 0;
113 
114  //! Abstract mouse movement function
115  virtual void mouseCallback(unsigned int button, int x, int y, bool pushed, bool motion) = 0;
116 
117  //! Abstract keyboard callback function
118  /*! It is important to realize that the way XEvents happen, this callback will be called with a single key press
119  at a time (either a release or press) in temporal order.
120  @param[in] keys All keys pressed or released in the current time interval */
121  virtual void keyboardCallback(std::vector<KeyboardPress> const & keys) = 0;
122 
123  //! Function called when a 3D mouse (3dConnexion SpacePilot Pro for example) event is received
124  virtual void mouse3dCallback(double const x, double const y, double const z,
125  double const a, double const b, double const c, int const period) = 0;
126 
127  private:
128  DisplayListManager itsDLmanager;
129  TextureManager itsTmanager;
130  std::map<std::string, nrt::graphics::mocap::Skeleton> itsSkeletons;
131  };
132 
133  } // namespace graphics
134 } // namespace nrt
135 
136 #endif // INCLUDE_NRT_GRAPHICS_SHAPERENDERER_H
137