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 <fvutils/statistical/histogram_file.h>
25 #include <fvutils/statistical/histogram_block.h>
26 #include <core/exception.h>
27 
28 using namespace fawkes;
29 
30 namespace firevision {
31 #if 0 /* just to make Emacs auto-indent happy */
32 }
33 #endif
34 
35 /** @class HistogramFile <fvutils/statistical/histogram_file.h>
36  * A fileformat for histograms. Such a file might contain multiple histograms, each for a
37  * a different type of object.
38  * @author Daniel Beck
39  */
40 
41 /** Constructor. */
42 HistogramFile::HistogramFile()
43  : FireVisionDataFile(FIREVISION_HISTOGRAM_MAGIC, FIREVISION_HISTOGRAM_CURVER)
44 {
45  attached_histograms.clear();
46 }
47 
48 
49 /** Destructor. */
51 {
52  attached_histograms.clear();
53 }
54 
55 
56 /** Adds a new histogram block to the file.
57  * @param block the histogram block
58  */
59 void
61 {
62  if ( attached_histograms.find( block->object_type() ) != attached_histograms.end() )
63  { throw Exception("Cannot add another histogram of type %d to the file", block->object_type()); }
64 
65  attached_histograms[ block->object_type() ] = block;
66  add_block(block);
67 }
68 
69 
70 /** Generates a list of histogram blocks attached to the file.
71  * @return a list of all attached histogram blocks
72  */
75 {
77  FireVisionDataFile::BlockList::iterator blit;
78 
80 
81  for (blit = bl.begin(); blit != bl.end(); ++blit)
82  {
83  if ((*blit)->type() == FIREVISION_HISTOGRAM_TYPE_16 ||
84  (*blit)->type() == FIREVISION_HISTOGRAM_TYPE_32 )
85  {
86  HistogramBlock* hb = new HistogramBlock(*blit);
87  hbl.push_back(hb);
88  }
89  }
90 
91  return hbl;
92 }
93 
94 
95 /** Get a value from a certain histogram.
96  * @param object_type the requested value is obtained from the histogram for this type of
97  * object
98  * @param x the x-coordinate
99  * @param y the y-coordinate
100  * @param z the z-coordinate
101  * @return value
102  */
103 uint32_t
104 HistogramFile::get_value(hint_t object_type,
105  uint16_t x, uint16_t y, uint16_t z)
106 {
107  if ( attached_histograms.find(object_type) == attached_histograms.end() )
108  { throw Exception("File contains no histogram for type %d", object_type); }
109 
110  return attached_histograms[object_type]->get_value(x, y, z);
111 }
112 
113 
114 /** Set a value in a certain histogram.
115  * @param object_type this specifies the type for which the respective histogram is changed
116  * @param x the x-coordinate
117  * @param y the y-coordinate
118  * @param z the z-coordinate
119  * @param val the new value for the specified cell
120  */
121 void
122 HistogramFile::set_value(hint_t object_type,
123  uint16_t x, uint16_t y, uint16_t z,
124  uint32_t val)
125 {
126  if ( attached_histograms.find(object_type) == attached_histograms.end() )
127  { throw Exception("File contains no histogram for type %d", object_type); }
128 
129  attached_histograms[object_type]->set_value(x, y, z, val);
130 }
131 
132 } // end namespace firevision
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.
virtual void add_block(FireVisionDataFileBlock *block)
Add a block.
Definition: fvfile.cpp:242
Fawkes library namespace.
hint_t object_type() const
Returns the type of the object the histogram is associated with.
std::list< FireVisionDataFileBlock * > BlockList
List of FireVision data file blocks.
Definition: fvfile.h:64
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.
Base class for exceptions in Fawkes.
Definition: exception.h:36
void add_histogram_block(HistogramBlock *block)
Adds a new histogram block to the file.
std::list< HistogramBlock * > HistogramBlockList
Convenience typdef for a STL list of pointers to histogram blocks.
FireVision File Format for data files.
Definition: fvfile.h:37
This class defines a file block for histograms.
BlockList & blocks()
Get blocks.
Definition: fvfile.cpp:252