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 namespace firevision {
00031 #if 0
00032 }
00033 #endif
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 RectificationLutInfoBlock::RectificationLutInfoBlock(uint16_t width,
00048 uint16_t height,
00049 uint8_t camera)
00050 : RectificationInfoBlock(FIREVISION_RECTINFO_TYPE_LUT_16x16,
00051 camera,
00052 sizeof(rectinfo_lut_16x16_block_header_t) +
00053 (width * height * sizeof(rectinfo_lut_16x16_entry_t)))
00054 {
00055 _lut_block_header = (rectinfo_lut_16x16_block_header_t *)_data;
00056 _lut_data = (rectinfo_lut_16x16_entry_t *)((char *)_data +
00057 sizeof(rectinfo_lut_16x16_block_header_t));
00058
00059 _lut_block_header->width = width;
00060 _lut_block_header->height = height;
00061 }
00062
00063
00064
00065
00066
00067
00068
00069 RectificationLutInfoBlock::RectificationLutInfoBlock(FireVisionDataFileBlock *block)
00070 : RectificationInfoBlock(block)
00071 {
00072 _lut_block_header = (rectinfo_lut_16x16_block_header_t *)_data;
00073 _lut_data = (rectinfo_lut_16x16_entry_t *)((char *)_data +
00074 sizeof(rectinfo_lut_16x16_block_header_t));
00075 }
00076
00077
00078 void
00079 RectificationLutInfoBlock::mapping(uint16_t x, uint16_t y,
00080 uint16_t *to_x, uint16_t *to_y)
00081 {
00082 if ( x > _lut_block_header->width ) {
00083 throw OutOfBoundsException("RectLUT X (from)", x, 0, _lut_block_header->width);
00084 }
00085 if ( y > _lut_block_header->height ) {
00086 throw OutOfBoundsException("RectLUT Y (from)", y, 0, _lut_block_header->height);
00087 }
00088
00089 *to_x = _lut_data[y * _lut_block_header->width + x].x;
00090 *to_y = _lut_data[y * _lut_block_header->width + x].y;
00091 }
00092
00093
00094
00095
00096
00097
00098
00099
00100 void
00101 RectificationLutInfoBlock::set_mapping(uint16_t x, uint16_t y,
00102 uint16_t to_x, uint16_t to_y)
00103 {
00104 if ( x > _lut_block_header->width ) {
00105 throw OutOfBoundsException("RectLUT X (from)", x, 0, _lut_block_header->width);
00106 }
00107 if ( y > _lut_block_header->height ) {
00108 throw OutOfBoundsException("RectLUT Y (from)", y, 0, _lut_block_header->height);
00109 }
00110 if ( to_x > _lut_block_header->width ) {
00111 throw OutOfBoundsException("RectLUT X (to)", to_x, 0, _lut_block_header->width);
00112 }
00113 if ( to_y > _lut_block_header->height ) {
00114 throw OutOfBoundsException("RectLUT Y (to)", to_y, 0, _lut_block_header->height);
00115 }
00116
00117 _lut_data[y * _lut_block_header->width + x].x = to_x;
00118 _lut_data[y * _lut_block_header->width + x].y = to_y;
00119 }
00120
00121
00122
00123
00124
00125 uint16_t
00126 RectificationLutInfoBlock::pixel_width()
00127 {
00128 return _lut_block_header->width;
00129 }
00130
00131
00132
00133
00134
00135 uint16_t
00136 RectificationLutInfoBlock::pixel_height()
00137 {
00138 return _lut_block_header->height;
00139 }
00140
00141
00142
00143
00144
00145
00146 rectinfo_lut_16x16_entry_t *
00147 RectificationLutInfoBlock::lut_data()
00148 {
00149 return _lut_data;
00150 }
00151
00152 }