rectinfo_lut_block.cpp

00001 
00002 /***************************************************************************
00003  *  rectinfo_lut_block.cpp - Rectification info block for 16x16 LUT
00004  *
00005  *  Created: Wed Oct 31 15:16:50 2007
00006  *  Copyright  2007  Tim Niemueller [www.niemueller.de]
00007  *
00008  ****************************************************************************/
00009 
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version. A runtime exception applies to
00014  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU Library General Public License for more details.
00020  *
00021  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
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 /* just to make Emacs auto-indent happy */
00032 }
00033 #endif
00034 
00035 /** @class RectificationLutInfoBlock <fvutils/rectification/rectinfo_lut_block.h>
00036  * Recitification Lookup Table Block.
00037  * This class defines a rectification lookup table info block that can be used
00038  * to define a LUT that maps rectified to unrectified pixels.
00039  * @author Tim Niemueller
00040  */
00041 
00042 /** Constructor.
00043  * @param width width of the image
00044  * @param height height of the image
00045  * @param camera camera identifier, see rectinfo_camera_t
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 /** Copy Constructor.
00065  * It is assumed that the block actually is a rectification LUT info block. Check that
00066  * before calling this method.
00067  * @param block block to copy
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 /** Set mapping.
00095  * @param x X pixel coordinate to get mapping for
00096  * @param y Y pixel coordinate to get mapping for
00097  * @param to_x X pixel coordinate of the unrectified image
00098  * @param to_y Y pixel coordinate of the unrectified image
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 /** Get width of the LUT.
00123  * @return width of LUT.
00124  */
00125 uint16_t
00126 RectificationLutInfoBlock::pixel_width()
00127 {
00128   return _lut_block_header->width;
00129 }
00130 
00131 
00132 /** Get height the LUT.
00133  * @return height of LUT.
00134  */
00135 uint16_t
00136 RectificationLutInfoBlock::pixel_height()
00137 {
00138   return _lut_block_header->height;
00139 }
00140 
00141 
00142 /** Get raw LUT data.
00143  * Use this to access the LUT.
00144  * @return pointer to raw LUT data
00145  */
00146 rectinfo_lut_16x16_entry_t *
00147 RectificationLutInfoBlock::lut_data()
00148 {
00149   return _lut_data;
00150 }
00151 
00152 } // end namespace firevision

Generated on 1 Mar 2011 for Fawkes API by  doxygen 1.6.1