Fawkes API  Fawkes Development Version
rectinfo_lut_block.cpp
1 
2 /***************************************************************************
3  * rectinfo_lut_block.cpp - Rectification info block for 16x16 LUT
4  *
5  * Created: Wed Oct 31 15:16:50 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_lut_block.h>
25 
26 #include <core/exceptions/software.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 RectificationLutInfoBlock <fvutils/rectification/rectinfo_lut_block.h>
36  * Recitification Lookup Table Block.
37  * This class defines a rectification lookup table info block that can be used
38  * to define a LUT that maps rectified to unrectified pixels.
39  * @author Tim Niemueller
40  */
41 
42 /** Constructor.
43  * @param width width of the image
44  * @param height height of the image
45  * @param camera camera identifier, see rectinfo_camera_t
46  */
47 RectificationLutInfoBlock::RectificationLutInfoBlock(uint16_t width,
48  uint16_t height,
49  uint8_t camera)
50  : RectificationInfoBlock(FIREVISION_RECTINFO_TYPE_LUT_16x16,
51  camera,
53  (width * height * sizeof(rectinfo_lut_16x16_entry_t)))
54 {
55  _lut_block_header = (rectinfo_lut_16x16_block_header_t *)_data;
56  _lut_data = (rectinfo_lut_16x16_entry_t *)((char *)_data +
58 
59  _lut_block_header->width = width;
60  _lut_block_header->height = height;
61 }
62 
63 
64 /** Copy Constructor.
65  * It is assumed that the block actually is a rectification LUT info block. Check that
66  * before calling this method.
67  * @param block block to copy
68  */
70  : RectificationInfoBlock(block)
71 {
72  _lut_block_header = (rectinfo_lut_16x16_block_header_t *)_data;
73  _lut_data = (rectinfo_lut_16x16_entry_t *)((char *)_data +
75 }
76 
77 
78 void
79 RectificationLutInfoBlock::mapping(uint16_t x, uint16_t y,
80  uint16_t *to_x, uint16_t *to_y)
81 {
82  if ( x > _lut_block_header->width ) {
83  throw OutOfBoundsException("RectLUT X (from)", x, 0, _lut_block_header->width);
84  }
85  if ( y > _lut_block_header->height ) {
86  throw OutOfBoundsException("RectLUT Y (from)", y, 0, _lut_block_header->height);
87  }
88 
89  *to_x = _lut_data[y * _lut_block_header->width + x].x;
90  *to_y = _lut_data[y * _lut_block_header->width + x].y;
91 }
92 
93 
94 /** Set mapping.
95  * @param x X pixel coordinate to get mapping for
96  * @param y Y pixel coordinate to get mapping for
97  * @param to_x X pixel coordinate of the unrectified image
98  * @param to_y Y pixel coordinate of the unrectified image
99  */
100 void
102  uint16_t to_x, uint16_t to_y)
103 {
104  if ( x > _lut_block_header->width ) {
105  throw OutOfBoundsException("RectLUT X (from)", x, 0, _lut_block_header->width);
106  }
107  if ( y > _lut_block_header->height ) {
108  throw OutOfBoundsException("RectLUT Y (from)", y, 0, _lut_block_header->height);
109  }
110  if ( to_x > _lut_block_header->width ) {
111  throw OutOfBoundsException("RectLUT X (to)", to_x, 0, _lut_block_header->width);
112  }
113  if ( to_y > _lut_block_header->height ) {
114  throw OutOfBoundsException("RectLUT Y (to)", to_y, 0, _lut_block_header->height);
115  }
116 
117  _lut_data[y * _lut_block_header->width + x].x = to_x;
118  _lut_data[y * _lut_block_header->width + x].y = to_y;
119 }
120 
121 
122 /** Get width of the LUT.
123  * @return width of LUT.
124  */
125 uint16_t
127 {
128  return _lut_block_header->width;
129 }
130 
131 
132 /** Get height the LUT.
133  * @return height of LUT.
134  */
135 uint16_t
137 {
138  return _lut_block_header->height;
139 }
140 
141 
142 /** Get raw LUT data.
143  * Use this to access the LUT.
144  * @return pointer to raw LUT data
145  */
148 {
149  return _lut_data;
150 }
151 
152 } // end namespace firevision
uint16_t height
height of the LUT file and image
Definition: rectinfo.h:130
uint16_t pixel_width()
Get width of the LUT.
uint16_t width
width of the LUT file and image
Definition: rectinfo.h:129
Fawkes library namespace.
void * _data
Pointer to the internal data segment.
Definition: fvfile_block.h:55
Block header for rectification LUTs wit 16-bit values.
Definition: rectinfo.h:128
FireVision File Format data block.
Definition: fvfile_block.h:35
RectificationLutInfoBlock(uint16_t width, uint16_t height, uint8_t camera)
Constructor.
Data type used to build a rectification LUT.
Definition: rectinfo.h:142
virtual void mapping(uint16_t x, uint16_t y, uint16_t *to_x, uint16_t *to_y)
Get mapping (to_x, to_y) for (x, y).
uint16_t pixel_height()
Get height the LUT.
Rectification info block.
void set_mapping(uint16_t x, uint16_t y, uint16_t to_x, uint16_t to_y)
Set mapping.
uint16_t y
map to y pixel coordinate
Definition: rectinfo.h:144
rectinfo_lut_16x16_entry_t * lut_data()
Get raw LUT data.
Index out of bounds.
Definition: software.h:88
uint16_t x
map to x pixel coordinate
Definition: rectinfo.h:143