iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Shape.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_SHAPE_H
37 #define INCLUDE_NRT_GRAPHICS_SHAPE_H
38 
39 #include <nrt/Graphics/Pen.H>
40 #include <nrt/Graphics/Brush.H>
41 #include <nrt/Eigen/Eigen.H>
42 #include <nrt/Core/Typing/Time.H>
44 #include <nrt/External/cereal/types/chrono.hpp>
45 
46 /*! \defgroup graphics Graphics-related classes and functions
47 
48  The nrt graphics primitives allow one to draw spheres, cubes, cylinders, extruded contours, etc into an OpenGL
49  display, possibly using different 3D effects such as texture mapping. */
50 
51 namespace nrt
52 {
53  namespace graphics
54  {
55 
56  //! Base class for a graphics shape
57  /*! \ingroup graphics */
58  class Shape
59  {
60  public:
61  //! Constructor using a lifetime duration
62  Shape(Eigen::Affine3f const & frame_ = Eigen::Affine3f::Identity(),
63  nrt::Duration const & lifetime_ = nrt::forev(),
64  nrt::graphics::Pen const & pen_ = nrt::graphics::Pen(),
65  nrt::graphics::Brush const & brush_ = nrt::graphics::Brush());
66 
67  //! Constructor using an end-of-life time point
68  Shape(Eigen::Affine3f const & frame_,
69  nrt::Time const & endtime_,
70  nrt::graphics::Pen const & pen_ = nrt::graphics::Pen(),
71  nrt::graphics::Brush const & brush_ = nrt::graphics::Brush());
72 
73  //! Virtual destructor for safe inheritance
74  virtual ~Shape();
75 
76  //! Render this shape into a ShapeRenderer (e.g., OpenGL window)
77  /*! This method is pure virtual in the base class and must be implemented in derived classes */
78  virtual void render(nrt::graphics::ShapeRenderer & sr) const = 0;
79 
80  //! Returns true if this shape is past its lifetime
81  bool expired() const;
82 
83  protected:
84  Eigen::Affine3f frame; //!< Coordinate frame of this shape
85  nrt::Time endtime; //!< Time after which this shape should be discarded
86  nrt::graphics::Pen pen; //!< Pen to use to draw edges
87  nrt::graphics::Brush brush; //!< Brush to use to draw surfaces
88 
89  //! Set frame, pen, brush, etc, return false if dead
90  bool prerender(nrt::graphics::ShapeRenderer & sr) const;
91 
92  //! End rendering of a given shape
94 
95  public:
96  //! Serialization
97  template <class Archive> inline void serialize(Archive & ar)
98  { ar( frame, endtime, pen, brush ); }
99  };
100 
101  } // namespace graphics
102 } // namespace nrt
103 
104 #endif // INCLUDE_NRT_GRAPHICS_SHAPE_H
105