Follow this link to skip to the main content

camera_group.cc

Go to the documentation of this file.
00001 // -*-c++-*-
00002 //---------------------------< /-/ CLARAty /-/ >------------------------------
00003 /**
00004  * @file  camera_group.cc
00005  *
00006  * Implements non-inline functions of camera group
00007  *
00008  * <br>@b Designer(s):  Daniel Clouse, Clay Kunz, Issa Nesnas
00009  * <br>@b Author(s):    Issa A.D. Nesnas
00010  * <br>@b Date:         06/09/06
00011  *
00012  * <b>Software License:</b><br>
00013  * <code>  http://claraty.jpl.nasa.gov/license/open_src/  or
00014  *         file: license/open_src.txt  </code>
00015  *
00016  * &copy; 2006, Jet Propulsion Laboratory, California Institute of Technology<br>
00017  *
00018  * $Revision: 1.8 $
00019  */
00020 //-----------------------------------------------------------------------------
00021 
00022 #include "claraty/camera_group.h"
00023 #include "claraty/fdm_parse_tree.h"
00024 
00025 using namespace std;
00026 namespace claraty {
00027 
00028 //-----------------------------------------------------------------------------
00029 /**
00030  * Construct a group with two cameras
00031  *
00032  * @param[in] cam1 first camera to append to group
00033  * @param[in] cam2 second camera to append to group
00034  */
00035 Camera_Group::
00036 Camera_Group(Camera & cam1, Camera & cam2)
00037   : Device_Group(2)
00038 {
00039   append(cam1);
00040   append(cam2);
00041 }
00042 
00043 //-----------------------------------------------------------------------------
00044 /**
00045  * Construct a group with three cameras
00046  *
00047  * @param[in] cam1 first camera to append to group
00048  * @param[in] cam2 second camera to append to group
00049  * @param[in] cam3 third camera to append to group
00050  */
00051 Camera_Group::
00052 Camera_Group(Camera & cam1, Camera & cam2, Camera & cam3)
00053   : Device_Group(3)
00054 {
00055   append(cam1);
00056   append(cam2);
00057   append(cam3);
00058 }
00059 //-----------------------------------------------------------------------------
00060 /**
00061  * Construct a group with four cameras
00062  *
00063  * @param[in] cam1 first camera to append to group
00064  * @param[in] cam2 second camera to append to group
00065  * @param[in] cam3 third camera to append to group
00066  * @param[in] cam4 fourth camera to append to group
00067  */
00068 Camera_Group::
00069 Camera_Group(Camera & cam1, Camera & cam2, Camera & cam3, Camera & cam4)
00070   : Device_Group(4)
00071 {
00072   append(cam1);
00073   append(cam2);
00074   append(cam3);
00075   append(cam4);
00076 }
00077 
00078 //-----------------------------------------------------------------------------
00079 /**
00080  * Construct a group with two cameras
00081  *
00082  * @param[in] size 
00083  * @param[in] name 
00084  */
00085 Camera_Group::
00086 Camera_Group(int size, 
00087              const string & group_name)
00088   : Device_Group(size, group_name)
00089 { 
00090 };
00091 
00092 //-----------------------------------------------------------------------------
00093 /**
00094  * @param[in] camera_index
00095  * @return device group
00096  */
00097 Camera & Camera_Group::
00098 get_camera(unsigned int camera_index) const
00099   throw(out_of_range)
00100 { 
00101   return static_cast<Camera &> (Device_Group::get_device(camera_index));
00102 };
00103 
00104 //-----------------------------------------------------------------------------
00105 /**
00106  * Verify that all camera formats are either set to 8-bit pixels or
00107  * 16-bit pixels. If the current format (as set by set_format) of any
00108  * logical camera in this Camera_Group is not one of the 8 or 16 bit
00109  * known formats (see Camera class), then return throw an exception
00110  * 
00111  * @param[in] pixel_size format pixel format which is either set to
00112  * PIXEL_FORMAT::BIT8 or PIXEL_FORMAT::BIT16
00113  * @return true if all camera formats match requested format
00114  */
00115 void Camera_Group::
00116 _verify_pixel_format(size_t pixel_size)
00117 { 
00118   for (int i = 0; i < (int)get_size(); ++i) { // compiler warning chage
00119     Camera & cam = get_camera(i);
00120     cam._verify_pixel_format(pixel_size);
00121   }
00122 }
00123 
00124 //-----------------------------------------------------------------------------
00125 /**
00126  * Verify that all image sizes match all camera frame sizes.  If the image
00127  * sizes do not match the camera frame sizes, this function will resize
00128  * each image to the proper corresponding camera frame size.
00129  *
00130  * @param[in] img_vec Reference to an image object to be resized.
00131  */
00132 template< class Pixel_Type >
00133 void Camera_Group::
00134 _verify_resize_images(vector< Image<Pixel_Type> * > & img_vec)
00135 { 
00136    for (unsigned int i = 0; i < get_size(); ++i) {
00137      Camera & cam = get_camera(i);
00138      cam._verify_resize_image(*(img_vec[i]));
00139    }
00140 }
00141 
00142 //-----------------------------------------------------------------------------
00143 /**
00144  * @brief Acquire synchronized Images (unsigned char version).  
00145  * 
00146  * This function is defined to enable children to override this
00147  * default capability as necessary
00148  * For each physical camera, set the parameter settings to match
00149  * those of the corresponding logical camera. Resize each image to
00150  * match the pixel geometry expected by its corresponding camera. 
00151  * Acquire the synchronized images (this will need to be overwritten
00152  * in the specilized hardware group for true synchronization and
00153  * multi-thread safety.  Fill in each timestamp_vec entry with the
00154  * time the corresponding image was acquired.  Fill in
00155  * feature_map_vec entry with the camera parameter settings in
00156  * effect at the time the image was acquired.
00157  *    
00158  * @param [out] image_vec
00159  *              Returns newly acquired Images.  Each Image is resized
00160  *              to match the image size returned by the corresponding
00161  *              camera.  The size of the image_vec vector is not
00162  *              changed by this routine.  The number of images
00163  *              actually returned equals min(image_vec.size(), this.size()).
00164  *              Any images beyond this number are left unchanged.
00165  * @param [out] timestamp_vec
00166  *              Returns timestamps for each image.
00167  * @param [out] feature_map_vec
00168  *              Returns camera feature settings for each image.
00169  * @return      The number of valid images returned in image_vec.
00170  *              This value may be less than image_vec.size().  It is
00171  *              equal to min(image_vec.size(), this.size()).
00172  */
00173 int Camera_Group::
00174 acquire(vector< Image<uint8_t> * > & image_vec,
00175         vector< Time             > * timestamp_vec,
00176         vector< Feature_Map    * > * feature_map_vec)
00177   throw (exception)
00178 {
00179   return _acquire(image_vec, timestamp_vec, feature_map_vec);
00180 }
00181 
00182 //-------------------------------------------------------------------------
00183 /*
00184  * @brief Acquire synchronized Images (unsigned short version).
00185  *
00186  * Behavior is the same as that of the unsigned char version except
00187  * that this version works with MONO16 and RGB16 formats only.
00188  */
00189 int Camera_Group::
00190 acquire(vector< Image<uint16_t> * > & image_vec,
00191         vector< Time              > * timestamp_vec,
00192         vector< Feature_Map     * > * feature_map_vec)
00193     throw (exception)
00194 {
00195   return _acquire(image_vec, timestamp_vec, feature_map_vec);
00196 }
00197 
00198 //-----------------------------------------------------------------------------
00199 /**
00200  * [description]
00201  *
00202  * @param [in]   map
00203  * @return       true or false
00204  */
00205 inline bool 
00206 Camera_Group::io(FDM_Map map)
00207 {
00208   return Device_Group::io(map);
00209 }
00210 
00211 //-----------------------------------------------------------------------------
00212 /**
00213  * [description]
00214  *
00215  * @param [in]   os
00216  * @param [in]   rhs
00217  * @return       os
00218  */
00219 std::ostream & 
00220 operator << (std::ostream & os, const Camera_Group & rhs)
00221 {
00222   FDM_Parse_Tree::write_object(rhs, os);
00223   return os;
00224 }
00225 
00226 //-----------------------------------------------------------------------------
00227 /**
00228  * [description]
00229  *
00230  * @param [in]   is
00231  * @param [in]   rhs
00232  * @return       parse tree
00233  */
00234 std::istream & 
00235 operator >> (std::istream& is, Camera_Group & rhs)
00236 {
00237   FDM_Parse_Tree::read_object(rhs, is);
00238   return is;
00239 }
00240 //-----------------------------------------------------------------------------
00241 
00242 } // namespace claraty