Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * roidraw.cpp - Implementation of ROI draw filter 00004 * 00005 * Created: Thu Jul 14 16:01:37 2005 00006 * Copyright 2005-2007 Tim Niemueller [www.niemueller.de] 00007 * 00008 ****************************************************************************/ 00009 00010 /* This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. A runtime exception applies to 00014 * this software (see LICENSE.GPL_WRE file mentioned below for details). 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Library General Public License for more details. 00020 * 00021 * Read the full text in the LICENSE.GPL_WRE file in the doc directory. 00022 */ 00023 00024 #include <filters/roidraw.h> 00025 #include <fvutils/color/color_object_map.h> 00026 #include <fvutils/draw/drawer.h> 00027 00028 #include <cstddef> 00029 00030 namespace firevision { 00031 #if 0 /* just to make Emacs auto-indent happy */ 00032 } 00033 #endif 00034 00035 /** @class FilterROIDraw <filters/roidraw.h> 00036 * ROI Drawing filter. 00037 * This filter visually marks the given region of interest. 00038 * @author Tim Niemueller 00039 */ 00040 00041 /** Constructor. 00042 * @param rois optional list of ROIs to draw additionally to the dst_roi 00043 * @param style optional border style (default is INVERTED) 00044 */ 00045 FilterROIDraw::FilterROIDraw(const std::list<ROI> *rois, border_style_t style) 00046 : Filter("FilterROIDraw"), 00047 __rois(rois), 00048 __border_style(style) 00049 { 00050 __drawer = new Drawer; 00051 } 00052 00053 /** Destructor */ 00054 FilterROIDraw::~FilterROIDraw() { 00055 delete __drawer; 00056 } 00057 00058 void 00059 FilterROIDraw::draw_roi(const ROI *roi) 00060 { 00061 if (__border_style == DASHED_HINT) { 00062 YUV_t hint_color = ColorObjectMap::get_color(ColorObjectMap::get_instance().get(roi->hint)); 00063 __drawer->set_buffer(dst, roi->image_width, roi->image_height); 00064 bool draw_black = false; 00065 fawkes::point_t end; 00066 end.x = std::min(roi->image_width - 1, roi->start.x + roi->width); 00067 end.y = std::min(roi->image_height - 1, roi->start.y + roi->height); 00068 00069 //Top and bottom line 00070 for (unsigned int x = roi->start.x; x <= end.x ; ++x) { 00071 if (!(x % 2)) { 00072 __drawer->set_color(draw_black ? YUV_t::black() : hint_color); 00073 draw_black = !draw_black; 00074 } 00075 00076 __drawer->color_point(x, roi->start.y); 00077 __drawer->color_point(x, end.y); 00078 } 00079 00080 //Side lines 00081 for (unsigned int y = roi->start.y; y <= end.y; ++y) { 00082 if (!(y % 2)) { 00083 __drawer->set_color(draw_black ? YUV_t::black() : hint_color); 00084 draw_black = !draw_black; 00085 } 00086 00087 __drawer->color_point(roi->start.x, y); 00088 __drawer->color_point(end.x, y); 00089 } 00090 } 00091 else { 00092 // destination y-plane 00093 unsigned char *dyp = dst + (roi->start.y * roi->line_step) + (roi->start.x * roi->pixel_step); 00094 00095 // line starts 00096 unsigned char *ldyp = dyp; // destination y-plane 00097 00098 // top border 00099 for (unsigned int i = roi->start.x; i < (roi->start.x + roi->width); ++i) { 00100 *dyp = 255 - *dyp; 00101 dyp++; 00102 } 00103 00104 // left and right borders 00105 for (unsigned int i = roi->start.y; i < (roi->start.y + roi->height); ++i) { 00106 ldyp += roi->line_step; 00107 dyp = ldyp; 00108 *dyp = 255 - *dyp; 00109 dyp += roi->width; 00110 *dyp = 255 - *dyp; 00111 } 00112 ldyp += roi->line_step; 00113 dyp = ldyp; 00114 00115 // bottom border 00116 for (unsigned int i = roi->start.x; i < (roi->start.x + roi->width); ++i) { 00117 *dyp = 255 - *dyp; 00118 dyp++; 00119 } 00120 } 00121 } 00122 00123 void 00124 FilterROIDraw::apply() 00125 { 00126 if ( dst_roi ) { 00127 draw_roi(dst_roi); 00128 } 00129 if ( __rois ) { 00130 for (std::list<ROI>::const_iterator r = __rois->begin(); r != __rois->end(); ++r) { 00131 draw_roi(&(*r)); 00132 } 00133 } 00134 } 00135 00136 00137 /** Set ROIs. 00138 * Set a list of ROIs. The list must persist as long as the filter is applied with 00139 * this list. Set to NULL to have it ignored again. 00140 * @param rois list of ROIs to draw additionally to the dst_roi. 00141 */ 00142 void 00143 FilterROIDraw::set_rois(const std::list<ROI> *rois) 00144 { 00145 __rois = rois; 00146 } 00147 00148 00149 /** Sets the preferred style 00150 * @param style The preferred style 00151 */ 00152 void 00153 FilterROIDraw::set_style(border_style_t style) 00154 { 00155 __border_style = style; 00156 } 00157 00158 } // end namespace firevision