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