rectinfo_lut_block.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <fvutils/rectification/rectinfo_lut_block.h>
00025
00026 #include <core/exceptions/software.h>
00027
00028 using namespace fawkes;
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 RectificationLutInfoBlock::RectificationLutInfoBlock(uint16_t width,
00043 uint16_t height,
00044 uint8_t camera)
00045 : RectificationInfoBlock(FIREVISION_RECTINFO_TYPE_LUT_16x16,
00046 camera,
00047 sizeof(rectinfo_lut_16x16_block_header_t) +
00048 (width * height * sizeof(rectinfo_lut_16x16_entry_t)))
00049 {
00050 _lut_block_header = (rectinfo_lut_16x16_block_header_t *)_data;
00051 _lut_data = (rectinfo_lut_16x16_entry_t *)((char *)_data +
00052 sizeof(rectinfo_lut_16x16_block_header_t));
00053
00054 _lut_block_header->width = width;
00055 _lut_block_header->height = height;
00056 }
00057
00058
00059
00060
00061
00062
00063
00064 RectificationLutInfoBlock::RectificationLutInfoBlock(FireVisionDataFileBlock *block)
00065 : RectificationInfoBlock(block)
00066 {
00067 _lut_block_header = (rectinfo_lut_16x16_block_header_t *)_data;
00068 _lut_data = (rectinfo_lut_16x16_entry_t *)((char *)_data +
00069 sizeof(rectinfo_lut_16x16_block_header_t));
00070 }
00071
00072
00073 void
00074 RectificationLutInfoBlock::mapping(uint16_t x, uint16_t y,
00075 uint16_t *to_x, uint16_t *to_y)
00076 {
00077 if ( x > _lut_block_header->width ) {
00078 throw OutOfBoundsException("RectLUT X (from)", x, 0, _lut_block_header->width);
00079 }
00080 if ( y > _lut_block_header->height ) {
00081 throw OutOfBoundsException("RectLUT Y (from)", y, 0, _lut_block_header->height);
00082 }
00083
00084 *to_x = _lut_data[y * _lut_block_header->width + x].x;
00085 *to_y = _lut_data[y * _lut_block_header->width + x].y;
00086 }
00087
00088
00089
00090
00091
00092
00093
00094
00095 void
00096 RectificationLutInfoBlock::set_mapping(uint16_t x, uint16_t y,
00097 uint16_t to_x, uint16_t to_y)
00098 {
00099 if ( x > _lut_block_header->width ) {
00100 throw OutOfBoundsException("RectLUT X (from)", x, 0, _lut_block_header->width);
00101 }
00102 if ( y > _lut_block_header->height ) {
00103 throw OutOfBoundsException("RectLUT Y (from)", y, 0, _lut_block_header->height);
00104 }
00105 if ( to_x > _lut_block_header->width ) {
00106 throw OutOfBoundsException("RectLUT X (to)", to_x, 0, _lut_block_header->width);
00107 }
00108 if ( to_y > _lut_block_header->height ) {
00109 throw OutOfBoundsException("RectLUT Y (to)", to_y, 0, _lut_block_header->height);
00110 }
00111
00112 _lut_data[y * _lut_block_header->width + x].x = to_x;
00113 _lut_data[y * _lut_block_header->width + x].y = to_y;
00114 }
00115
00116
00117
00118
00119
00120 uint16_t
00121 RectificationLutInfoBlock::pixel_width()
00122 {
00123 return _lut_block_header->width;
00124 }
00125
00126
00127
00128
00129
00130 uint16_t
00131 RectificationLutInfoBlock::pixel_height()
00132 {
00133 return _lut_block_header->height;
00134 }
00135
00136
00137
00138
00139
00140
00141 rectinfo_lut_16x16_entry_t *
00142 RectificationLutInfoBlock::lut_data()
00143 {
00144 return _lut_data;
00145 }