camera.cc
Go to the documentation of this file.00001 //-*-c++-*- 00002 //---------------------------< /-/ CLARAty /-/ >------------------------------ 00003 /** 00004 * @file camera.cc 00005 * 00006 * Implements the generic base camera class that serves as a parent 00007 * for logical and physical cameras. 00008 * 00009 * <br>@b Designer(s): Daniel Clouse, Clay Kunz, Issa Nesnas 00010 * <br>@b Author(s): Daniel Clouse 00011 * <br>@b Date: June 9, 2006 00012 * 00013 * <b>Software License:</b><br> 00014 * <code> http://claraty.jpl.nasa.gov/license/open_src/ or 00015 * file: license/open_src.txt </code> 00016 * 00017 * © 2006, Jet Propulsion Laboratory, California Institute of Technology 00018 * 00019 * $Revision: 1.6 $ 00020 */ 00021 //----------------------------------------------------------------------------- 00022 00023 #include "claraty/camera.h" 00024 #include "claraty/fdm_parse_tree.h" 00025 00026 using namespace std; 00027 00028 namespace claraty { 00029 00030 //----------------------------------------------------------------------------- 00031 /** 00032 * Constructs a camera with an optional camera model that captures camera 00033 * calibration information 00034 * 00035 * @param[in] name an optional name for the camera object 00036 * @param[in] camera_model_ptr a pointer to a camera model 00037 */ 00038 Camera:: 00039 Camera(const string & name, 00040 Camera_Model * camera_model_ptr) 00041 : Device(name), 00042 _camera_model_ptr(camera_model_ptr) 00043 { 00044 } 00045 00046 //----------------------------------------------------------------------------- 00047 /** 00048 * Serializes a camera. Camera id, name and camera model that captures 00049 * lens parameters are all option 00050 * 00051 * @param[in] map a map that holds the content of a serialized camera 00052 */ 00053 bool Camera:: 00054 io(FDM_Map map) 00055 { 00056 bool ok = Device::io(map); 00057 // Check to make sure that the the output is read back in will 00058 // operator >> construct the camera model. Check who owns it 00059 // Need to add an IO to the Camera Model object 00060 // ok &= map.field("_camera_model_ptr", _camera_model_ptr); 00061 return ok; 00062 } 00063 00064 //----------------------------------------------------------------------------- 00065 /** 00066 * Capture comment from device function. 00067 * 00068 * @param[in] os 00069 * @param[in] rhs 00070 * @return output stream 00071 */ 00072 00073 std::ostream & 00074 operator << (std::ostream & os, const Camera & rhs) 00075 { 00076 FDM_Parse_Tree::write_object(rhs, os); 00077 return os; 00078 } 00079 00080 //----------------------------------------------------------------------------- 00081 /** 00082 * Capture comment from device function. 00083 * 00084 * @param[in] is 00085 * @param[in] rhs 00086 * @return stream 00087 */ 00088 inline std::istream & 00089 operator >> (std::istream & is, Camera & rhs) 00090 { 00091 FDM_Parse_Tree::read_object(rhs, is); 00092 return is; 00093 } 00094 00095 //----------------------------------------------------------------------------- 00096 /** 00097 * Verify that the camera format matches the pixel size (either 8-bit or 00098 * 16-bit/pixel (see IMAGE_FORMAT). Throw exception if mismatched 00099 * 00100 * @param[in] pixel_size number of bytes used for image pixels 00101 * 00102 */ 00103 00104 void Camera:: 00105 _verify_pixel_format(size_t pixel_size) 00106 { 00107 IMAGE_FORMAT format = get_format(); 00108 00109 switch(pixel_size) { 00110 00111 case 1: // 8 Bits 00112 if (format != MONO8 && format != YUV411 && 00113 format != YUV422 && format != YUV444 && 00114 format != RGB8) { 00115 std::ostringstream os; 00116 os << AT_FUNCTION << " camera: " << (*this) 00117 << " acquiring 16 bit-format images with camera set to 8 bit format" 00118 << endl; 00119 throw (os.str()); 00120 } 00121 break; 00122 00123 case 2: // 16 bits 00124 if (format != MONO16 && format != RGB16) { 00125 std::ostringstream os; 00126 os << AT_FUNCTION << " camera: " << (*this) 00127 << " acquiring 8 bit-format images with camera set to 16 bit format" 00128 << endl; 00129 throw (os.str()); 00130 } 00131 break; 00132 } 00133 } 00134 00135 } // namespace claraty 00136 00137 //----------------------------------------------------------------------------- 00138