Drawable.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * NICE-Core - efficient algebra and computer vision methods
  3. * - libimage - An image/template for new NICE libraries
  4. * See file License for license information.
  5. */
  6. /*****************************************************************************/
  7. /*! \file Drawable.h
  8. \brief Drawable class declaration
  9. */
  10. /*****************************************************************************/
  11. /*
  12. * $Author: bajramov $
  13. * $Date: 2009/05/28 11:36:30 $
  14. * $Revision: 1.2 $
  15. */
  16. /*****************************************************************************/
  17. #ifndef _DRAWABLE_IMAGE_H
  18. #define _DRAWABLE_IMAGE_H
  19. #include <core/image/ippwrapper.h>
  20. #include <core/image/ColorT.h>
  21. namespace NICE {
  22. template<class P> class ColorImageT;
  23. template<class P> class ImageT;
  24. //! Base class for drawable geometric primitives.
  25. template<class P>
  26. class Drawable
  27. {
  28. protected:
  29. ColorT<P> defaultColor;
  30. public:
  31. //! Default constructor
  32. Drawable() : defaultColor(ColorT<P>(0,0,0)) {}
  33. //! Constructor with default color
  34. Drawable(const ColorT<P>& _defaultColor) : defaultColor(_defaultColor) {}
  35. //! Destructor of Drawable
  36. virtual ~Drawable() {}
  37. //! Draw the object using the default color.
  38. inline void draw(ColorImageT<P> &image) const {
  39. draw(image, defaultColor);
  40. }
  41. //! Draw the object using the default color.
  42. inline void draw(ImageT<P> &image) const {
  43. draw(image, defaultColor.gray());
  44. }
  45. //! Draw the object using the default color.
  46. inline void draw(ImageT<P> &image, const ColorT<P>& color) const {
  47. draw(image, color.gray());
  48. }
  49. inline void draw(ColorImageT<P> &image, const ColorT<P>& color) const {
  50. if(color.size()==1)
  51. draw(image, ColorT<P>(color.gray(), color.gray(), color.gray()));
  52. else if (color.size() < (unsigned int)image.channels())
  53. #ifdef NICE_USELIB_FBASICS
  54. fthrow(Exception,"color has to few channels");
  55. #else
  56. throw std::range_error("color has to few channels");
  57. #endif
  58. else
  59. doDraw(image, color);
  60. }
  61. inline void draw(ImageT<P> &image, const P& gray) const {
  62. doDraw(image, gray);
  63. }
  64. protected:
  65. //! Draw Object on image
  66. /*! \param image image
  67. * \param color The color. Needs to have at least as many channels as image!
  68. */
  69. virtual void doDraw(ColorImageT<P> &image, const ColorT<P>& color) const = 0;
  70. //! Draw Object on image
  71. /*! \param image image
  72. * \param gray the gray value
  73. */
  74. virtual void doDraw(ImageT<P> &image, const P& gray) const = 0;
  75. };
  76. } // namespace NICE
  77. #include "core/image/ColorImageT.h"
  78. #include "core/image/ImageT.h"
  79. #endif /* _DRAWABLE_IMAGE_H */
  80. /*****************************************************************************/
  81. /*
  82. * $Log: Drawable.h,v $
  83. * Revision 1.2 2009/05/28 11:36:30 bajramov
  84. * renamed a few things for consistency
  85. *
  86. * Revision 1.1.1.1 2007/05/22 19:26:35 bajramov
  87. * limun2
  88. *
  89. * Revision 1.6 2007/02/04 15:32:50 zimmermann
  90. * * added operator !=
  91. * * bugfix operator == : circle, color
  92. * * bugfix operator = : point, circle
  93. * * expended gray() in ColorT for size()==3
  94. * * expended draw for ColorImage, to draw gray Drawables
  95. * * added new constructor PointT(Coord)
  96. *
  97. * Revision 1.5 2006/11/02 14:25:25 zimmermann
  98. * * fixed wrong function call
  99. *
  100. * Revision 1.4 2006/11/01 16:05:24 bajramov
  101. * Further changes to Drawable and subclasses.
  102. * Methods draw() of ImageT/ColorImageT with iterator parameter renamed to drawIter().
  103. * New Drawable CrossT.
  104. *
  105. * Revision 1.3 2006/11/01 15:18:14 bajramov
  106. * added drawing methods with color/gray value parameter
  107. *
  108. * Revision 1.2 2006/07/13 11:53:51 mattern
  109. * - large bug fixes
  110. *
  111. * Revision 1.1 2006/06/29 10:16:03 bajramov
  112. * classes and functions for drawing points, lines, ellipses, ...
  113. *
  114. */