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