Fawkes API Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * rectinfo_block.cpp - Rectification info block encapsulation 00004 * 00005 * Created: Wed Oct 31 14:35:36 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_block.h> 00025 #include <core/exceptions/system.h> 00026 #include <core/exceptions/software.h> 00027 00028 #include <cstdlib> 00029 #include <cstring> 00030 00031 namespace firevision { 00032 #if 0 /* just to make Emacs auto-indent happy */ 00033 } 00034 #endif 00035 00036 /** @class RectificationInfoBlock <fvutils/rectification/rectinfo_block.h> 00037 * Rectification info block. 00038 * This base class defines the basic interface to interact with rectification 00039 * info blocks. It manages a small memory chunk that may later be used via 00040 * other recitification information classes in an easy manner. Concrete 00041 * implementations of a specific block type shall be derived from this 00042 * class. 00043 * @author Tim Niemueller 00044 */ 00045 00046 /** @var RectificationInfoBlock::_block_header 00047 * Rectification block header. 00048 * This is a pointer to the content-specific block header for rectification info blocks. 00049 */ 00050 00051 00052 00053 /** @fn void RectificationInfoBlock::mapping(uint16_t x, uint16_t y, uint16_t *to_x, uint16_t *to_y) = 0 00054 * Get mapping (to_x, to_y) for (x, y). 00055 * This can be used as a general method to access the RectificationInfoBlock mapping. 00056 * For many models there may be a better (faster) way to access the mapping information. 00057 * It performance matters (and it most probably will) exploit this and use the 00058 * provided shortcut. 00059 * @param x X pixel coordinate to get mapping for 00060 * @param y Y pixel coordinate to get mapping for 00061 * @param to_x Upon return contains the X pixel coordinate of the unrectified image 00062 * @param to_y Upon return contains the Y pixel coordinate of the unrectified image 00063 */ 00064 00065 00066 /** Recommended constructor. 00067 * With this constructor a chunk of memory is allocated that is sufficient 00068 * to hold the internal block header and the data of the given size. Note 00069 * that the size you give is only meant to hold your type specific header 00070 * and data. Some extra bytes are internally added for the type agnostic 00071 * block header. 00072 * @param block_type type of the block as defined per rectinfo_block_type_t 00073 * @param camera camera identifier 00074 * @param block_data_size size of the data block, this means only the sum of 00075 * the size of the type specific header and the data itself, NOT including 00076 * the type agnostic block header. 00077 */ 00078 RectificationInfoBlock::RectificationInfoBlock(uint8_t block_type, 00079 uint8_t camera, 00080 size_t block_data_size) 00081 : FireVisionDataFileBlock(block_type, block_data_size, sizeof(rectinfo_block_header_t)) 00082 { 00083 if ( _data_size > UINT32_MAX ) { 00084 throw fawkes::OutOfBoundsException("RectInfoBlock: block_data_size is too large", 00085 block_data_size, 0, UINT32_MAX); 00086 } 00087 00088 _block_header = (rectinfo_block_header_t *)_spec_header; 00089 _block_header->camera = camera; 00090 } 00091 00092 00093 /** Copy constructor. 00094 * Copies data from the given FireVisionDataFileBlock. It is assumed that this 00095 * actually is a rectification info block, check that before calling this 00096 * method. 00097 * @param block FireVision data file block 00098 */ 00099 RectificationInfoBlock::RectificationInfoBlock(FireVisionDataFileBlock *block) 00100 : FireVisionDataFileBlock(block) 00101 { 00102 _block_header = (rectinfo_block_header_t *)_spec_header; 00103 } 00104 00105 00106 /** Destructor. 00107 * Destructs the chunk, if and only if _free_block_chunk is true. 00108 */ 00109 RectificationInfoBlock::~RectificationInfoBlock() 00110 { 00111 _block_header = NULL; 00112 } 00113 00114 00115 /** Get block camera identifier. 00116 * @return camera identifier 00117 * @see rectinfo_block_header_t 00118 */ 00119 uint8_t 00120 RectificationInfoBlock::camera() const 00121 { 00122 if ( _block_header == NULL ) { 00123 throw fawkes::NullPointerException("No memory chunk loaded for rectinfo block"); 00124 } 00125 return _block_header->camera; 00126 } 00127 00128 } // end namespace firevision