camera_image.ipp
Go to the documentation of this file.00001 // -*-c++-*- 00002 //---------------------------< /-/ CLARAty /-/ >------------------------------ 00003 /** 00004 * @file camera_image.ipp 00005 * 00006 * Implementation of template functions for Camera_Image class 00007 * 00008 * <br>@b Designer(s): Issa A.D. Nesnas 00009 * <br>@b Author(s): Issa A.D. Nesnas 00010 * <br>@b Date: February 23, 2007 00011 * 00012 * <b>Software License:</b><br> 00013 * <code> http://claraty.jpl.nasa.gov/license/open_src.html or 00014 * file: ../share/license.txt </code> 00015 * 00016 * © 2007, Jet Propulsion Laboratory, California Institute of Technology 00017 * 00018 * $Revision: 1.3 $ 00019 */ 00020 //----------------------------------------------------------------------------- 00021 00022 #include <memory> 00023 #include <stdexcept> 00024 #include <sstream> 00025 00026 namespace claraty { 00027 00028 //----------------------------------------------------------------------------- 00029 //----------------------------------------------------------------------------- 00030 /** 00031 * Creates a Camera_Image using default Image constructor with (0,0) image 00032 * size. If no camera model is given, it will be initialized to NULL. 00033 * Paramters such as timestamp are similarly set 00034 * 00035 * @param[in] model the Camera_Model to use (if non-NULL). The model will be 00036 * copied. 00037 * @param[in] timestamp the time the image was acquired (zero if not provided) 00038 * @param[in] properties the frame number used to reconstruct a video stream 00039 */ 00040 template< typename Pixel_Type > 00041 Camera_Image<Pixel_Type >:: 00042 Camera_Image(const Camera_Model * model, 00043 Time timestamp, 00044 Camera_Image_Properties * properties) : 00045 _model(model == NULL ? NULL : new Camera_Model(model)), 00046 _timestamp(timestamp), 00047 _properties((properties==NULL) ? NULL : new Camera_Image_Properties(properties)) 00048 { 00049 } 00050 00051 //----------------------------------------------------------------------------- 00052 /** 00053 * Creates a new Camera_Image of the specified width and height. 00054 * Initializes Camera_Image w/ given values. If timestamp or frame_num are 00055 * not provided, they are initialized to zero. 00056 * 00057 * @param[in] nrows the width of the Camera_Image 00058 * @param[in] ncols the heigh to the Camera_Image 00059 * @param[in] model the Camera_Model to use 00060 * @param[in] timestamp the timestamp (zero if not provided) 00061 template< typename Pixel_Type > 00062 Camera_Image<Pixel_Type >:: 00063 Camera_Image(int nrows, int ncols, 00064 const Camera_Model *model, 00065 Time timestamp) 00066 : Image<Pixel_Type>(nrows, ncols), _model(model == NULL ? NULL : model->clone()), 00067 _timestamp(timestamp), _frame_num(frame_num), _feature_map() 00068 { 00069 } 00070 */ 00071 00072 //----------------------------------------------------------------------------- 00073 /** 00074 * Creates a new Camera_Image from the provided source Image. 00075 * Deep copies the source Image (all data) to the new Camera_Image. 00076 * @param[in] src_image The Image to copy into the new Camera_Image. 00077 * @param[in] model The Camera_Model to use. 00078 * @param[in] timestamp The timestamp (zero if not provided). 00079 * @param[in] properties Camera image properties. 00080 */ 00081 template< typename Pixel_Type > 00082 Camera_Image<Pixel_Type>:: 00083 Camera_Image(const Image<Pixel_Type> & src_image, 00084 const Camera_Model * model, 00085 Time timestamp, 00086 Camera_Image_Properties * properties) 00087 : Image<Pixel_Type >(src_image), 00088 _model(model == NULL ? NULL : new Camera_Model(model)), 00089 _timestamp(timestamp), 00090 _properties((properties==NULL) ? NULL : 00091 new Camera_Image_Properties(properties)) 00092 { 00093 } 00094 00095 //----------------------------------------------------------------------------- 00096 /** 00097 * Copy constructor: creates a new Camera_Image from a source Camera_Image. 00098 * Does a deep copy of the src_image to the new image. 00099 * 00100 * @param[in] src_image Camera_Image to use to construct the new Camera_Image. 00101 */ 00102 template< typename Pixel_Type > 00103 Camera_Image<Pixel_Type >:: 00104 Camera_Image(const Camera_Image<Pixel_Type> & src_image) 00105 : Image<Pixel_Type>(src_image), 00106 _model(src_image._model == NULL ? NULL : src_image._model->clone()), 00107 _timestamp(src_image._timestamp), 00108 _properties(src_image._properties) 00109 { 00110 } 00111 00112 //----------------------------------------------------------------------------- 00113 /** 00114 * Destructor. 00115 */ 00116 template< typename Pixel_Type > 00117 Camera_Image<Pixel_Type>:: 00118 ~Camera_Image() 00119 { 00120 delete _model; 00121 delete _properties; 00122 } 00123 00124 //----------------------------------------------------------------------------- 00125 00126 template < typename Pixel_Type > 00127 Camera_Image<Pixel_Type> & Camera_Image<Pixel_Type>:: 00128 operator=(const Camera_Image & rhs) 00129 { 00130 if (this != &rhs) { 00131 Image<Pixel_Type>::operator=(rhs); 00132 /* 00133 resize(rhs.nrows(), rhs.ncols()); 00134 if (rhs.is_subarray()) 00135 _copy(rhs.begin()); 00136 else 00137 _copy(rhs.get_raster()); 00138 set_maximum_value(rhs.get_maximum_value()); 00139 set_interpolation_type(rhs.get_interpolation_type()); 00140 */ 00141 set_camera_model(rhs._model); 00142 _timestamp = rhs._timestamp; 00143 _properties = rhs._properties; 00144 } 00145 return *this; 00146 } 00147 00148 //----------------------------------------------------------------------------- 00149 /** 00150 * @return the Frame associated w/ the Camera_Model of the image. 00151 template< typename Pixel_Type> 00152 Frame Camera_Image<Pixel_Type>::get_frame() const 00153 { 00154 if(_model!=NULL) { 00155 return _model->get_frame(); 00156 } 00157 else { 00158 Frame_l ret; // return empty frame 00159 return(ret); 00160 } 00161 } 00162 */ 00163 00164 //----------------------------------------------------------------------------- 00165 /** 00166 * Sets the image's Camera_Model. 00167 * 00168 * @param[in] model The Camera_Model to associate w/ the image. 00169 */ 00170 template < typename Pixel_Type > 00171 void Camera_Image<Pixel_Type>:: 00172 set_camera_model(const Camera_Model & model) 00173 { 00174 delete _model; 00175 _model = model;//->clone(); 00176 } 00177 00178 //----------------------------------------------------------------------------- 00179 /** 00180 * Serializing and unserializing camera images. 00181 * @param[out] m A flexible data marshalling map that contains the 00182 * serializable format 00183 * @return true if the operation is successful, otherwise false 00184 */ 00185 template < typename Pixel_Type > 00186 bool Camera_Image<Pixel_Type>::io(FDM_Map m) 00187 { 00188 bool ret = io_image(m, (Image<Pixel_Type>&)(*this)); 00189 00190 if (m.is_read()) { 00191 delete _model; 00192 std::string cmString; 00193 ret &= m.peekfield("model", cmString); 00194 if (cmString == "none") { 00195 ret &= m.field("model", cmString); // swallow it 00196 _model = NULL; 00197 } else { 00198 std::auto_ptr<Camera_Model> cm; 00199 ret &= m.field("model", cm); 00200 _model = cm.release(); 00201 } 00202 } else { // write 00203 if (_model) 00204 ret &= m.field("model", *_model); 00205 else { 00206 std::string none("none"); 00207 ret &= m.field("model", none); 00208 } 00209 } 00210 00211 ret &= m.field("timestamp", _timestamp); 00212 // ret &= m.field("features", _feature_map); 00213 return ret; 00214 } 00215 00216 //----------------------------------------------------------------------------- 00217 /** 00218 * Remove lens distortion and update models 00219 */ 00220 template < typename Pixel_Type > 00221 Camera_Image<Pixel_Type> 00222 rectify(Camera_Image<Pixel_Type> & image) throw(std::exception) 00223 { 00224 Camera_Image<Pixel_Type> ret_image; 00225 00226 if (image.get_model()) { 00227 Camera_Model * new_model; 00228 /* Rectify_Op rectify; 00229 if (!this->linearize_model(*_model, rectify)) 00230 return false; 00231 delete _model; 00232 _model = new_model; 00233 Image<Pixel_Type> rect; 00234 rectify.rectify_image(*this, rect); 00235 resize(rect.nrows(), rect.ncols()); 00236 assert(!rect.is_subarray()); 00237 _copy(rect.get_raster()); 00238 */ 00239 } 00240 else { 00241 std::ostringstream os; 00242 os << AT_FUNCTION << " camera model was not initialized" << std::endl; 00243 throw std::exception(os); 00244 } 00245 } 00246 //----------------------------------------------------------------------------- 00247 00248 } // namespace claraty