00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <models/scanlines/line_grid.h>
00025
00026 #include <fvutils/base/roi.h>
00027 #include <fvutils/draw/drawer.h>
00028 #include <core/exceptions/software.h>
00029
00030 #include <cstring>
00031
00032 using fawkes::point_t;
00033
00034 namespace firevision {
00035 #if 0
00036 }
00037 #endif
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 ScanlineLineGrid::ScanlineLineGrid(unsigned int width, unsigned int height,
00061 unsigned int offset_hor, unsigned int offset_ver,
00062 ROI* roi, unsigned int gap)
00063 {
00064 __roi = NULL;
00065 __next_pixel = gap + 1;
00066 set_grid_params(width, height,
00067 offset_hor, offset_ver, roi);
00068
00069 }
00070
00071
00072
00073 ScanlineLineGrid::~ScanlineLineGrid()
00074 {
00075 delete __roi;
00076 }
00077
00078 point_t
00079 ScanlineLineGrid::operator*()
00080 {
00081 return *__cur;
00082 }
00083
00084 point_t*
00085 ScanlineLineGrid::operator->()
00086 {
00087 return &*__cur;
00088 }
00089
00090 void
00091 ScanlineLineGrid::calc_coords()
00092 {
00093 __point_list.clear();
00094 bool more_to_come = true;
00095 point_t coord;
00096 unsigned int next_px;
00097
00098 if (__offset_hor > 0)
00099 {
00100 more_to_come = true;
00101 next_px = std::min(__next_pixel, __offset_ver ? __offset_ver : __width);
00102 coord.x = __roi->start.x;
00103 coord.y = __roi->start.y + ((__roi->height - 1) % __offset_hor) / 2;
00104 __point_list.push_back(coord);
00105
00106 while (more_to_come) {
00107 if (coord.x < (__roi->image_width - next_px))
00108 {
00109 coord.x += next_px;
00110 }
00111 else
00112 {
00113 if (coord.y < (__roi->image_height - __offset_hor))
00114 {
00115 coord.x = __roi->start.x;
00116 coord.y += __offset_hor;
00117 }
00118 else
00119 {
00120 more_to_come = false;
00121 }
00122 }
00123
00124 if (more_to_come) __point_list.push_back(coord);
00125 }
00126 }
00127
00128 if (__offset_ver > 0)
00129 {
00130 more_to_come = true;
00131 next_px = std::min(__next_pixel, __offset_hor ? __offset_hor : __height);
00132 coord.x = __roi->start.x + ((__roi->width - 1) % __offset_ver) / 2;
00133 coord.y = __roi->start.y;
00134 __point_list.push_back(coord);
00135
00136 while (more_to_come) {
00137 if (coord.y < (__roi->image_height - next_px))
00138 {
00139 coord.y += next_px;
00140 }
00141 else
00142 {
00143 if (coord.x < (__roi->image_width - __offset_ver))
00144 {
00145 coord.x += __offset_ver;
00146 coord.y = __roi->start.y;
00147 }
00148 else
00149 {
00150 more_to_come = false;
00151 }
00152 }
00153
00154 if (more_to_come) __point_list.push_back(coord);
00155 }
00156 }
00157
00158 reset();
00159 }
00160
00161 point_t *
00162 ScanlineLineGrid::operator++()
00163 {
00164 if (__cur != __point_list.end()) ++__cur;
00165 return __cur != __point_list.end() ? &*__cur : &__point_list.back();
00166 }
00167
00168 point_t *
00169 ScanlineLineGrid::operator++(int)
00170 {
00171 if (__cur != __point_list.end()) {
00172 point_t *res = &*__cur++;
00173 return res;
00174 }
00175 else return &__point_list.back();
00176 }
00177
00178 bool
00179 ScanlineLineGrid::finished()
00180 {
00181 return __cur == __point_list.end();
00182 }
00183
00184 void
00185 ScanlineLineGrid::reset()
00186 {
00187 __cur = __point_list.begin();
00188 }
00189
00190 const char *
00191 ScanlineLineGrid::get_name()
00192 {
00193 return "ScanlineModel::LineGrid";
00194 }
00195
00196
00197 unsigned int
00198 ScanlineLineGrid::get_margin()
00199 {
00200 return std::max(__offset_ver, __offset_hor);
00201 }
00202
00203
00204 void
00205 ScanlineLineGrid::set_robot_pose(float x, float y, float ori)
00206 {
00207
00208 }
00209
00210
00211 void
00212 ScanlineLineGrid::set_pan_tilt(float pan, float tilt)
00213 {
00214
00215 }
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227 void
00228 ScanlineLineGrid::set_dimensions(unsigned int width, unsigned int height, ROI* roi)
00229 {
00230 __width = width;
00231 __height = height;
00232
00233 set_roi(roi);
00234 }
00235
00236
00237
00238
00239
00240
00241 void
00242 ScanlineLineGrid::set_roi(ROI* roi)
00243 {
00244 delete __roi;
00245
00246 if (!roi) __roi = new ROI(0, 0, __width, __height, __width, __height);
00247 else
00248 {
00249 __roi = roi;
00250
00251 __roi->set_image_width(__roi->start.x + __roi->width);
00252 __roi->set_image_height(__roi->start.y + __roi->height);
00253
00254 if (__roi->image_width > __width)
00255 throw fawkes::OutOfBoundsException("ScanlineLineGrid: ROI is out of grid bounds!", __roi->image_width, 0, __width);
00256 if (__roi->image_height > __height)
00257 throw fawkes::OutOfBoundsException("ScanlineLineGrid: ROI is out of grid bounds!", __roi->image_height, 0, __height);
00258 }
00259
00260 calc_coords();
00261 }
00262
00263
00264
00265
00266
00267
00268
00269
00270 void
00271 ScanlineLineGrid::set_offset(unsigned int offset_hor, unsigned int offset_ver)
00272 {
00273 __offset_hor = offset_hor;
00274 __offset_ver = offset_ver;
00275
00276 calc_coords();
00277 }
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293 void
00294 ScanlineLineGrid::set_grid_params(unsigned int width, unsigned int height,
00295 unsigned int offset_hor, unsigned int offset_ver,
00296 ROI* roi)
00297 {
00298 __offset_hor = offset_hor;
00299 __offset_ver = offset_ver;
00300
00301 set_dimensions(width, height, roi);
00302 }
00303
00304 }