histogram_file.cpp
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_file.h>
00025 #include <fvutils/statistical/histogram_block.h>
00026 #include <core/exception.h>
00027
00028 using namespace fawkes;
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 HistogramFile::HistogramFile()
00039 : FireVisionDataFile(FIREVISION_HISTOGRAM_MAGIC, FIREVISION_HISTOGRAM_CURVER)
00040 {
00041 attached_histograms.clear();
00042 }
00043
00044
00045
00046 HistogramFile::~HistogramFile()
00047 {
00048 attached_histograms.clear();
00049 }
00050
00051
00052
00053
00054
00055 void
00056 HistogramFile::add_histogram_block(HistogramBlock* block)
00057 {
00058 if ( attached_histograms.find( block->object_type() ) != attached_histograms.end() )
00059 { throw Exception("Cannot add another histogram of type %d to the file", block->object_type()); }
00060
00061 attached_histograms[ block->object_type() ] = block;
00062 add_block(block);
00063 }
00064
00065
00066
00067
00068
00069 HistogramFile::HistogramBlockList
00070 HistogramFile::histogram_blocks()
00071 {
00072 FireVisionDataFile::BlockList bl = blocks();
00073 FireVisionDataFile::BlockList::iterator blit;
00074
00075 HistogramBlockList hbl;
00076
00077 for (blit = bl.begin(); blit != bl.end(); ++blit)
00078 {
00079 if ((*blit)->type() == FIREVISION_HISTOGRAM_TYPE_16 ||
00080 (*blit)->type() == FIREVISION_HISTOGRAM_TYPE_32 )
00081 {
00082 HistogramBlock* hb = new HistogramBlock(*blit);
00083 hbl.push_back(hb);
00084 }
00085 }
00086
00087 return hbl;
00088 }
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098 uint32_t
00099 HistogramFile::get_value(hint_t object_type,
00100 uint16_t x, uint16_t y, uint16_t z)
00101 {
00102 if ( attached_histograms.find(object_type) == attached_histograms.end() )
00103 { throw Exception("File contains no histogram for type %d", object_type); }
00104
00105 return attached_histograms[object_type]->get_value(x, y, z);
00106 }
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116 void
00117 HistogramFile::set_value(hint_t object_type,
00118 uint16_t x, uint16_t y, uint16_t z,
00119 uint32_t val)
00120 {
00121 if ( attached_histograms.find(object_type) == attached_histograms.end() )
00122 { throw Exception("File contains no histogram for type %d", object_type); }
00123
00124 attached_histograms[object_type]->set_value(x, y, z, val);
00125 }