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

