Fawkes API Fawkes Development Version
histogram_file.cpp
1
2/***************************************************************************
3 * histogram_file.cpp - Histogram file
4 *
5 * Created: Sat Mar 29 21:37:33 2008
6 * Copyright 2008 Daniel Beck
7 *
8 ****************************************************************************/
9
10/* This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version. A runtime exception applies to
14 * this software (see LICENSE.GPL_WRE file mentioned below for details).
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Library General Public License for more details.
20 *
21 * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22 */
23
24#include <core/exception.h>
25#include <fvutils/statistical/histogram_block.h>
26#include <fvutils/statistical/histogram_file.h>
27
28using namespace fawkes;
29
30namespace firevision {
31
32/** @class HistogramFile <fvutils/statistical/histogram_file.h>
33 * A fileformat for histograms. Such a file might contain multiple histograms, each for a
34 * a different type of object.
35 * @author Daniel Beck
36 */
37
38/** Constructor. */
40: FireVisionDataFile(FIREVISION_HISTOGRAM_MAGIC, FIREVISION_HISTOGRAM_CURVER)
41{
42 attached_histograms.clear();
43}
44
45/** Destructor. */
47{
48 attached_histograms.clear();
49}
50
51/** Adds a new histogram block to the file.
52 * @param block the histogram block
53 */
54void
56{
57 if (attached_histograms.find(block->object_type()) != attached_histograms.end()) {
58 throw Exception("Cannot add another histogram of type %d to the file", block->object_type());
59 }
60
61 attached_histograms[block->object_type()] = block;
62 add_block(block);
63}
64
65/** Generates a list of histogram blocks attached to the file.
66 * @return a list of all attached histogram blocks
67 */
70{
72 FireVisionDataFile::BlockList::iterator blit;
73
75
76 for (blit = bl.begin(); blit != bl.end(); ++blit) {
77 if ((*blit)->type() == FIREVISION_HISTOGRAM_TYPE_16
78 || (*blit)->type() == FIREVISION_HISTOGRAM_TYPE_32) {
79 HistogramBlock *hb = new HistogramBlock(*blit);
80 hbl.push_back(hb);
81 }
82 }
83
84 return hbl;
85}
86
87/** Get a value from a certain histogram.
88 * @param object_type the requested value is obtained from the histogram for this type of
89 * object
90 * @param x the x-coordinate
91 * @param y the y-coordinate
92 * @param z the z-coordinate
93 * @return value
94 */
95uint32_t
96HistogramFile::get_value(hint_t object_type, uint16_t x, uint16_t y, uint16_t z)
97{
98 if (attached_histograms.find(object_type) == attached_histograms.end()) {
99 throw Exception("File contains no histogram for type %d", object_type);
100 }
101
102 return attached_histograms[object_type]->get_value(x, y, z);
103}
104
105/** Set a value in a certain histogram.
106 * @param object_type this specifies the type for which the respective histogram is changed
107 * @param x the x-coordinate
108 * @param y the y-coordinate
109 * @param z the z-coordinate
110 * @param val the new value for the specified cell
111 */
112void
113HistogramFile::set_value(hint_t object_type, uint16_t x, uint16_t y, uint16_t z, uint32_t val)
114{
115 if (attached_histograms.find(object_type) == attached_histograms.end()) {
116 throw Exception("File contains no histogram for type %d", object_type);
117 }
118
119 attached_histograms[object_type]->set_value(x, y, z, val);
120}
121
122} // end namespace firevision
Base class for exceptions in Fawkes.
Definition: exception.h:36
FireVision File Format for data files.
Definition: fvfile.h:36
virtual void add_block(FireVisionDataFileBlock *block)
Add a block.
Definition: fvfile.cpp:225
std::list< FireVisionDataFileBlock * > BlockList
List of FireVision data file blocks.
Definition: fvfile.h:62
BlockList & blocks()
Get blocks.
Definition: fvfile.cpp:234
This class defines a file block for histograms.
hint_t object_type() const
Returns the type of the object the histogram is associated with.
HistogramBlockList histogram_blocks()
Generates a list of histogram blocks attached to the file.
uint32_t get_value(hint_t object_type, uint16_t x, uint16_t y, uint16_t z)
Get a value from a certain histogram.
void add_histogram_block(HistogramBlock *block)
Adds a new histogram block to the file.
void set_value(hint_t object_type, uint16_t x, uint16_t y, uint16_t z, uint32_t val)
Set a value in a certain histogram.
std::list< HistogramBlock * > HistogramBlockList
Convenience typdef for a STL list of pointers to histogram blocks.
Fawkes library namespace.