Fawkes API  Fawkes Development Version
rectinfo_block.cpp
1 
2 /***************************************************************************
3  * rectinfo_block.cpp - Rectification info block encapsulation
4  *
5  * Created: Wed Oct 31 14:35:36 2007
6  * Copyright 2007 Tim Niemueller [www.niemueller.de]
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/rectification/rectinfo_block.h>
25 #include <core/exceptions/system.h>
26 #include <core/exceptions/software.h>
27 
28 #include <cstdlib>
29 #include <cstring>
30 
31 namespace firevision {
32 #if 0 /* just to make Emacs auto-indent happy */
33 }
34 #endif
35 
36 /** @class RectificationInfoBlock <fvutils/rectification/rectinfo_block.h>
37  * Rectification info block.
38  * This base class defines the basic interface to interact with rectification
39  * info blocks. It manages a small memory chunk that may later be used via
40  * other recitification information classes in an easy manner. Concrete
41  * implementations of a specific block type shall be derived from this
42  * class.
43  * @author Tim Niemueller
44  */
45 
46 /** @var RectificationInfoBlock::_block_header
47  * Rectification block header.
48  * This is a pointer to the content-specific block header for rectification info blocks.
49  */
50 
51 
52 
53 /** @fn void RectificationInfoBlock::mapping(uint16_t x, uint16_t y, uint16_t *to_x, uint16_t *to_y) = 0
54  * Get mapping (to_x, to_y) for (x, y).
55  * This can be used as a general method to access the RectificationInfoBlock mapping.
56  * For many models there may be a better (faster) way to access the mapping information.
57  * It performance matters (and it most probably will) exploit this and use the
58  * provided shortcut.
59  * @param x X pixel coordinate to get mapping for
60  * @param y Y pixel coordinate to get mapping for
61  * @param to_x Upon return contains the X pixel coordinate of the unrectified image
62  * @param to_y Upon return contains the Y pixel coordinate of the unrectified image
63  */
64 
65 
66 /** Recommended constructor.
67  * With this constructor a chunk of memory is allocated that is sufficient
68  * to hold the internal block header and the data of the given size. Note
69  * that the size you give is only meant to hold your type specific header
70  * and data. Some extra bytes are internally added for the type agnostic
71  * block header.
72  * @param block_type type of the block as defined per rectinfo_block_type_t
73  * @param camera camera identifier
74  * @param block_data_size size of the data block, this means only the sum of
75  * the size of the type specific header and the data itself, NOT including
76  * the type agnostic block header.
77  */
79  uint8_t camera,
80  size_t block_data_size)
81  : FireVisionDataFileBlock(block_type, block_data_size, sizeof(rectinfo_block_header_t))
82 {
83  if ( _data_size > UINT32_MAX ) {
84  throw fawkes::OutOfBoundsException("RectInfoBlock: block_data_size is too large",
85  block_data_size, 0, UINT32_MAX);
86  }
87 
90 }
91 
92 
93 /** Copy constructor.
94  * Copies data from the given FireVisionDataFileBlock. It is assumed that this
95  * actually is a rectification info block, check that before calling this
96  * method.
97  * @param block FireVision data file block
98  */
100  : FireVisionDataFileBlock(block)
101 {
103 }
104 
105 
106 /** Destructor.
107  * Destructs the chunk, if and only if _free_block_chunk is true.
108  */
110 {
111  _block_header = NULL;
112 }
113 
114 
115 /** Get block camera identifier.
116  * @return camera identifier
117  * @see rectinfo_block_header_t
118  */
119 uint8_t
121 {
122  if ( _block_header == NULL ) {
123  throw fawkes::NullPointerException("No memory chunk loaded for rectinfo block");
124  }
125  return _block_header->camera;
126 }
127 
128 } // end namespace firevision
RectificationInfoBlock(uint8_t block_type, uint8_t camera, size_t block_size)
Recommended constructor.
FireVision File Format data block.
Definition: fvfile_block.h:35
A NULL pointer was supplied where not allowed.
Definition: software.h:34
virtual ~RectificationInfoBlock()
Destructor.
The per-image rectification info block header.
Definition: rectinfo.h:111
void * _spec_header
Pointer to the content specific block header.
Definition: fvfile_block.h:57
rectinfo_block_header_t * _block_header
Rectification block header.
uint32_t camera
camera, as specified per rectinfo_camera_t
Definition: rectinfo.h:112
Index out of bounds.
Definition: software.h:88
size_t _data_size
Size of _data in bytes.
Definition: fvfile_block.h:56
uint8_t camera() const
Get block camera identifier.