Follow this link to skip to the main content

camera_group.ipp

Go to the documentation of this file.
00001 //-*-c++-*- 
00002 //---------------------------< /-/ CLARAty /-/ >------------------------------
00003 /** 
00004  * @file  camera_group.ipp
00005  *
00006  * Implementation of camera group template functions
00007  *
00008  * <br>@b Designer(s):  Issa A.D. Nesnas, Daniel Clouse
00009  * <br>@b Author(s):    Issa A.D. Nesnas, Daniel Clouse
00010  * <br>@b Date:         November 28, 2006
00011  *
00012  * <b>Software License:</b><br>
00013  * 
00014  * <code>  http://claraty.jpl.nasa.gov/license/open_src.html  or
00015  *         file: ../share/license.txt  </code>
00016  *
00017  * &copy; 2006, Jet Propulsion Laboratory, California Institute of Technology
00018  * [your institution copyright if applicable]
00019  *
00020  * $Revision: 1.3 $
00021 **/ 
00022 //-----------------------------------------------------------------------------
00023 
00024 namespace claraty {
00025 /**
00026  * @brief Acquire synchronized Images (unsigned char version).
00027  * All vectors (even empty vectors) grow or shrink to match the number
00028  * of cameras in the camera group, except for the default argument values
00029  * which are left empty by this routine.
00030  *
00031  * This version of acquire treats the default values differently from
00032  * the NULL (or empty) vector.  If an empty vector is passed in, it is
00033  * grown to match the number of cameras in the group.  The default
00034  * values are checked for explicitly, and are used to signify that the
00035  * user does not want this result returned.
00036  *    
00037  * @param[out] image_vec
00038  *             Returns newly acquired Images.  Each Image is resized
00039  *             to match the image size returned by the corresponding
00040  *             camera.  The size of the image_vec vector is not
00041  *             changed by this routine.  The number of images
00042  *             actually returned equals min(image_vec.size(), this.size()).
00043  *             Any images beyond this number are left unchanged.
00044  * @param[out] timestamp_vec
00045  *             Returns timestamps for each image.
00046  * @param[out] feature_map_vec
00047  *             Returns camera feature settings for each image.
00048  * @return     The number of valid images returned in image_vec.
00049  *             This value may be less than image_vec.size().  It is
00050  *             equal to min(image_vec.size(), this.size()).
00051  */
00052 template <class Pixel_Type>
00053 int Camera_Group::
00054 _acquire(std::vector< Image<Pixel_Type> * > & image_vec,
00055          std::vector< Time                > * timestamp_vec,
00056          std::vector< Feature_Map       * > * feature_map_vec)
00057   throw (std::exception)
00058 {
00059   if (image_vec.size()        != get_size() ||
00060       timestamp_vec->size()   != get_size() ||
00061       feature_map_vec->size() != get_size()) {
00062     std::ostringstream os;
00063     os << AT_FUNCTION << "camera group acquire failed: invalid argument"
00064        << "image vector size does not match group size" << std::endl;
00065     throw std::invalid_argument(os.str());    
00066   }
00067 
00068   // Verify that all cameras have proper pixel format
00069   _verify_pixel_format(sizeof(Pixel_Type));
00070 
00071   // Verify and resize images if necessary
00072   _verify_resize_images(image_vec);
00073 
00074   // Default implementation - loop through each camera and acquire image
00075   for (unsigned int i = 0; i < image_vec.size(); ++i) {
00076      Camera & cam = get_camera(i);
00077      if (timestamp_vec && feature_map_vec) 
00078        cam.acquire(*image_vec[i], &(*timestamp_vec)[i], (*feature_map_vec)[i]);
00079      else if (timestamp_vec)
00080        cam.acquire(*image_vec[i], &(*timestamp_vec)[i]);
00081      else
00082        cam.acquire(*image_vec[i]);
00083    }
00084   return image_vec.size();
00085 }
00086 
00087 
00088 //-------------------------------------------------------------------------
00089 /** 
00090  * The vector arguments are not resized (to match the number of cameras
00091  * in the group).  However, each image is resized to match the image
00092  * size implied by the current Camera state.  The return value is the
00093  * number of valid images returned in cam_img_ptr_vec.  This value may be
00094  * less than cam_img_ptr_vec.size().  It is equal to
00095  * min(image_vec.size(), this.get_size()).
00096  */
00097 template <class Pixel_Type> 
00098 int Camera_Group::
00099 acquire(std::vector< Camera_Image<Pixel_Type> * > & cam_img_ptr_vec)
00100 {
00101   std::vector< Image< Pixel_Type > * > img_ptr_vec(cam_img_ptr_vec.size());
00102   std::vector< Time >                 time_ptr_vec(cam_img_ptr_vec.size());
00103   std::vector< Feature_Map * > feature_map_ptr_vec(cam_img_ptr_vec.size());
00104   for (unsigned int i = 0; i < cam_img_ptr_vec.size(); ++i) {
00105     img_ptr_vec[i]         = cam_img_ptr_vec[i];
00106     time_ptr_vec[i]        = &cam_img_ptr_vec[i]->_timestamp;
00107     feature_map_ptr_vec[i] = &cam_img_ptr_vec[i]->_feature_map;
00108   }
00109   return _acquire(img_ptr_vec, time_ptr_vec, feature_map_ptr_vec);
00110 }
00111 
00112 //-------------------------------------------------------------------------
00113 /** The vector (even if empty) grows or shrinks to match the number of
00114  * cameras in the camera group.
00115  */
00116 template <class Pixel_Type> 
00117 int Camera_Group::
00118 acquire(std::vector< Camera_Image<Pixel_Type> > & cam_img_vec)
00119 {
00120   if (cam_img_vec.size() != get_size()) cam_img_vec.resize(get_size());
00121   std::vector< Image< Pixel_Type > * > img_ptr_vec(get_size());
00122   std::vector< Time * > time_ptr_vec(get_size());
00123   std::vector< Feature_Map * > feature_map_ptr_vec(get_size());
00124   for (unsigned int i = 0; i < get_size(); ++i) {
00125     img_ptr_vec[i] = &cam_img_vec[i];
00126     time_ptr_vec[i] = &cam_img_vec[i]._timestamp;
00127     feature_map_ptr_vec[i] = &cam_img_vec[i]._feature_map;
00128   }
00129   return _acquire(img_ptr_vec, time_ptr_vec, feature_map_ptr_vec);
00130 }
00131 
00132 //-------------------------------------------------------------------------
00133 
00134 } // namespace claraty