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 <fvutils/statistical/histogram_block.h>
00025 #include <core/exceptions/software.h>
00026 #include <cstring>
00027
00028 using namespace fawkes;
00029
00030 namespace firevision {
00031 #if 0
00032 }
00033 #endif
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 HistogramBlock::HistogramBlock(histogram_block_type_t type, hint_t object_type,
00050 uint16_t width, uint16_t height, uint16_t depth)
00051 : FireVisionDataFileBlock(type, width * height * depth * sizeof(uint32_t),
00052 sizeof(histogram_block_header_t))
00053 {
00054 _block_header = (histogram_block_header_t*) _spec_header;
00055 _block_header->width = width;
00056 _block_header->height = height;
00057 _block_header->depth = depth;
00058 _block_header->object_type = object_type;
00059
00060 _histogram_data = (uint32_t*) _data;
00061 }
00062
00063
00064
00065
00066 HistogramBlock::HistogramBlock(FireVisionDataFileBlock* block)
00067 : FireVisionDataFileBlock(block)
00068 {
00069 _block_header = (histogram_block_header_t*) _spec_header;
00070 _histogram_data = (uint32_t*) _data;
00071 }
00072
00073
00074 HistogramBlock::~HistogramBlock()
00075 {
00076 }
00077
00078
00079
00080
00081 uint16_t
00082 HistogramBlock::width() const
00083 {
00084 return _block_header->width;
00085 }
00086
00087
00088
00089
00090 uint16_t
00091 HistogramBlock::height() const
00092 {
00093 return _block_header->height;
00094 }
00095
00096
00097
00098
00099 uint16_t
00100 HistogramBlock::depth() const
00101 {
00102 return _block_header->depth;
00103 }
00104
00105
00106
00107
00108 hint_t
00109 HistogramBlock::object_type() const
00110 {
00111 return (hint_t) _block_header->object_type;
00112 }
00113
00114
00115
00116
00117 void
00118 HistogramBlock::set_object_type(hint_t object_type)
00119 {
00120 _block_header->object_type = object_type;
00121 }
00122
00123
00124
00125
00126
00127 void
00128 HistogramBlock::set_data(uint32_t* data)
00129 {
00130 memcpy(_data, data, _data_size);
00131 }
00132
00133
00134
00135
00136
00137
00138 void
00139 HistogramBlock::set_value(uint16_t x, uint16_t y, uint32_t val)
00140 {
00141 if (_block_header->depth != 0)
00142 { throw Exception("Trying to acces a 3-dim histogram with a 2-dim access method"); }
00143
00144 if (x >= _block_header->width)
00145 {
00146 throw OutOfBoundsException("Given x value is too large (set_value, 2)",
00147 float(x), 0.0f, float(_block_header->width));
00148 }
00149
00150 if (y >= _block_header->height)
00151 {
00152 throw OutOfBoundsException("Given y value is too large (set_value, 2)",
00153 float(y), 0.0f, float(_block_header->height));
00154 }
00155
00156 _histogram_data[y * _block_header->width + x] = val;
00157 }
00158
00159
00160
00161
00162
00163
00164
00165 void
00166 HistogramBlock::set_value(uint16_t x, uint16_t y, uint16_t z, uint32_t val)
00167 {
00168 if ( x >= _block_header->width)
00169 {
00170 throw OutOfBoundsException("Given x value is too large (set_value, 3)",
00171 float(x), 0.0f, float(_block_header->width));
00172 }
00173
00174 if ( y >= _block_header->height)
00175 {
00176 throw OutOfBoundsException("Given y value is too large (set_value, 3)",
00177 float(y), 0.0f, float(_block_header->height));
00178 }
00179
00180 if ( z >= _block_header->depth)
00181 {
00182 throw OutOfBoundsException("Given z value is too large (set_value, 3)",
00183 float(z), 0.0f, float(_block_header->depth));
00184 }
00185
00186 _histogram_data[z * _block_header->width * _block_header->height + y * _block_header->width + x] = val;
00187 }
00188
00189
00190
00191
00192
00193
00194 uint32_t
00195 HistogramBlock::get_value(uint16_t x, uint16_t y)
00196 {
00197 if (_block_header->depth != 0)
00198 { throw Exception("Trying to acces a 3-dim histogram with a 2-dim access method"); }
00199
00200 if ( x >= _block_header->width)
00201 {
00202 throw OutOfBoundsException("Given x value is too large (get_value, 2)",
00203 float(x), 0.0f, float(_block_header->width));
00204 }
00205
00206 if ( y >= _block_header->height)
00207 {
00208 throw OutOfBoundsException("Given y value is too large (get_value, 2)",
00209 float(y), 0.0f, float(_block_header->height));
00210 }
00211
00212 return _histogram_data[y * _block_header->width + x];
00213 }
00214
00215
00216
00217
00218
00219
00220
00221 uint32_t
00222 HistogramBlock::get_value(uint16_t x, uint16_t y, uint16_t z)
00223 {
00224 if ( x >= _block_header->width)
00225 {
00226 throw OutOfBoundsException("Given x value is too large (get_value, 3)",
00227 float(x), 0.0f, _block_header->width - 1);
00228 }
00229
00230 if ( y >= _block_header->height)
00231 {
00232 throw OutOfBoundsException("Given y value is too large (get_value, 3)",
00233 float(y), 0.0f, _block_header->height - 1);
00234 }
00235
00236 if ( z >= _block_header->depth)
00237 {
00238 throw OutOfBoundsException("Given z value is too large (get_value, 3)",
00239 float(z), 0.0f, _block_header->depth - 1);
00240 }
00241
00242 return _histogram_data[z * _block_header->width * _block_header->height + y * _block_header->width + x];
00243 }
00244
00245
00246 void
00247 HistogramBlock::reset()
00248 {
00249 memset(_histogram_data, 0, _data_size);
00250 }
00251
00252 }