iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Geometry.H
Go to the documentation of this file.
1 /*! @file
2  @author Randolph Voorhies
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_IMAGEPROC_DRAWING_GEOMETRY_H
37 #define INCLUDE_NRT_IMAGEPROC_DRAWING_GEOMETRY_H
38 
39 #include <nrt/config.h>
40 #include <nrt/Core/Image/Image.H>
41 #include <nrt/Core/Geometry/Line.H>
46 
47 namespace nrt
48 {
49  /*! @defgroup imagedrawing Image Drawing
50  Methods for drawing on Images, cutting and pasting, writing text, etc.
51  \ingroup imageproc
52  \see image */
53 
54  /*! @defgroup geometrydrawing Geometry Drawing
55  These methods are used to draw geometric primitives onto Images
56 
57  \ingroup imagedrawing */
58 
59  /*! @{ */ // **********************************************************************
60 
61  //! Draw a Line in the Image
62  /*! @param image The image onto which to draw a Line
63  @param line The line to draw
64  @param outlineColor The color of the Line
65  @param thickness The thickness of the Line */
66  template <class T, template<typename> class PixDest,
67  class U, template<typename> class PixOutline>
68  void drawLine(Image<PixDest<T> > & image, Line<int32> const& line, PixOutline<U> const& outlineColor,
69  uint thickness = 1);
70 
71  //! Draw an antialiased Line in the Image
72  /*! @param image The image onto which to draw a Line
73  @param line The line to draw
74  @param outlineColor The color of the Line */
75  template <class T, class U>
76  void drawLineAA(Image<T> & image, Line<int32> const& line, U const& outlineColor);
77 
78  //! Draw a Polygon in the image
79  /*! @param image The image onto which to draw a Polygon
80  @param polygon The Polygon to draw
81  @param outlineColor The color of the Polygon's outline
82  @param thickness The thickness of the Polygon's outline
83  @param fillColor The color of the Polygon's fill
84 
85  \warning Only specify a fill color if you know that your Polygon is convex. */
86  template <class T, template<typename> class SourceColorT,
87  class U, template<typename> class OutlineColorT,
88  class V=byte, template<typename> class FillColorT=PixRGBA >
89  void drawPolygon(Image<SourceColorT<T>> & image, Polygon<int32> const& polygon, OutlineColorT<U> const& outlineColor,
90  uint thickness = 1, FillColorT<V> const& fillColor = PixRGBA<byte>(0,0,0,0));
91 
92  //! Draw an antialiased Polygon in the image
93  /*! @param image The image onto which to draw a Polygon
94  @param polygon The Polygon to draw
95  @param outlineColor The color of the Polygon's outline */
96  template <class T, class U>
97  void drawPolygonAA(Image<T> & image, Polygon<int32> const& polygon, U const& outlineColor);
98 
99  //! Draw a Disk (filled-in circle)
100  /*! @param dst The image onto which to draw a disk
101  @param circle The circle which defines the disk to draw
102  @param fillColor The color of the disk
103 
104  \todo Merge this into drawCircle, a-la drawRectangle */
105  template <class T, template<typename> class PixDest,
106  class U, template<typename> class PixFill>
107  void drawDisk(Image<PixDest<T> >& dst, Circle<int32> const & circle, PixFill<U> const& fillColor);
108 
109  //! Draw a Circle in the image
110  /*! @param image The image onto which to draw a Circle
111  @param circle The circle to draw
112  @param outlineColor The color of the Circle's outline
113  @param thickness The thickness of the Circle's outline */
114  template <class T, class U>
115  void drawCircle(Image<T> & image, Circle<int32> const& circle, U const& outlineColor, uint thickness=1);
116 
117  //! Draw a Ellipse in the image
118  /*! @param image The image onto which to draw a ellipse
119  @param center The center of the ellipse
120  @param radiusx The radius of the ellipse in the x dimension
121  @param radiusy The radius of the ellipse in the y dimension
122  @param skew How much the ellipse is skewed. This is a cheap approximation to rotation.
123  @param outlineColor The color of the ellipse's outline
124  @param thickness The thickness of the ellipse's outline
125  @param fillColor the color to use to fill the ellipse (use PixRGBA if you need transparency) */
126  template <class T, class U, class V=PixRGBA<byte> >
127  void drawEllipse(Image<T> & image, Point2D<int32> const& center, const float radiusx, const float radiusy,
128  const float skew, U const& outlineColor, uint thickness=1,
129  V const& fillColor = PixRGBA<byte>(0,0,0,0));
130 
131  //! Draw a Rectangle in the Image
132  /*! To omit either the outline or the fill, you can specify a color type with an alpha channel set to 0 (for example,
133  the default fill is a PixRGBA<byte>(0,0,0,0), and thus will be drawn as only an outline).
134 
135  @param image The image onto which to draw a Rectangle
136  @param rect The rectangle to draw
137  @param outlineColor The outline color of the Rectangle
138  @param thickness The thickness of the outline
139  @param fillColor The filled color of the inside of the Rectangle
140 
141  @code
142  Image<PixRGB<byte>> myImage(Dims<int32>(640,480), nrt::ImageInitPolicy::Zeros);
143  Rectangle<int32> myRect(Point2D<int32>(320,240), Dims<int32>(50,50));
144 
145  // Draw a rectangle with a red 1px outline and no fill
146  drawRectangle(myImage, myRect, PixRGB<byte>(255,0,0));
147 
148  // Draw a rectangle with a red 1px outline and a blue fill
149  drawRectangle(myImage, myRect-Point2D<int>(50,0), PixRGB<byte>(255,0,0), 1, PixRGB<byte>(0,0,255));
150 
151  // Draw a rectangle with a red 4px outline with 50% opacity and a blue fill with 25% opacity
152  drawRectangle(myImage, myRect+Point2D<int>(50,0), PixRGBA<byte>(255,0,0,128), 4, PixRGBA<byte>(0,0,255,64));
153  @endcode */
154  template <class T, template<typename> class SourceColorT,
155  class U, template<typename> class OutlineColorT,
156  class V=byte, template<typename> class FillColorT=PixRGBA>
157  void drawRectangle(Image<SourceColorT<T>> & image, Rectangle<int32> const& rect,
158  OutlineColorT<U> const& outlineColor, uint thickness=1,
159  FillColorT<V> const& fillColor=PixRGBA<byte>(0,0,0,0));
160 
161  //! Draw a cross in the Image
162  /*! @param image The image onto which to draw a cross
163  @param center The center of the cross
164  @param outlineColor The color of the cross
165  @param radius The radius of the cross (the distance from the tip of one line to the center point)
166  @param thickness The line3 thickness
167  @param angle The rotation angle (in radians) */
168  template <class T, class OutlineColorT>
169  void drawCross(Image<T> & image, Point2D<int32> const& center, OutlineColorT const& outlineColor,
170  uint32 radius, uint32 thickness=1, float angle=0);
171 
172  //! Draw an arrow in the Image
173  /*! @param image The image onto which to draw a cross
174  @param xs start column location on the image
175  @param ys start row location on the image
176  @param xe end column location on the image
177  @param ye end row location on the image
178  @param thickness the line3 thickness
179  @param outlineColor the color of the cross
180  @param headSizeRatio the ratio of the head size to the length of the arrow
181  @param headAngle the angle between the arrow lines and the main body */
182  template <class T, class OutlineColorT>
183  void DrawArrow(Image<T> & image, int32 xs, int32 ys, int32 xe, int32 ye,
184  uint32 thickness = 1, OutlineColorT const& outlineColor = PixRGB<byte>(0, 0, 255),
185  float headSizeRatio = 0.35f, float headAngle = 15.0f);
186 
187  //! Draw a Grid in the image
188  /*! @param[in,out] image The image onto which to draw a Line
189  @param[in] spacingX the x spacing
190  @param[in] spacingY the y spacing
191  @param[in] thickX the thickness of the grid in X direction
192  @param[in] thickY the thickness of the grid in Y direction
193  @param[in] outlineColor the color of the grid */
194  template <class T, class OutlineColorT>
195  void drawGrid( Image<T> & image, const int32 spacingX, const int32 spacingY,
196  const uint32 thickX = 1, const uint32 thickY = 1,
197  OutlineColorT const& outlineColor = PixRGB<byte>(0, 0, 0) );
198 
199  //! Draw a regular Grid in the image
200  /*! Draws an nx * ny grid that exactly partitions the image
201  @param[in,out] image The image onto which to draw a Line
202  @param[in] nx Number of lines in x direction
203  @param[in] ny Number of lines in y direction
204  @param[in] thickness thickness of grid
205  @param[in] outlineColor the color of the grid */
206  template <class T, class OutlineColorT>
207  void drawGrid( Image<T> & image, const uint32 nx, const uint32 ny,
208  const uint32 thickness = 1,
209  OutlineColorT const& outlineColor = PixRGB<byte>(0, 0, 0) );
210 
211  /*! @} */ // **********************************************************************
212 
215 }
216 
217 #endif // INCLUDE_NRT_IMAGEPROC_DRAWING_GEOMETRY_H