ThreeB 1.1
utility.h
Go to the documentation of this file.
00001 #ifndef STORM_INCLUDE_UTILITY_H
00002 #define STORM_INCLUDE_UTILITY_H
00003 #include <cvd/image.h>
00004 #include <vector>
00005 #include <string>
00006 #include <cstring>
00007 #include <cerrno>
00008 #include <cstdlib>
00009 #include <utility>
00010 
00011 /**computes the sign of x
00012 @param x \e x
00013 @return \f$ \begin{cases}
00014                1  & x \ge 0\\
00015                -1 & x < 0
00016              \end{cases}\f$
00017 @ingroup gUtility
00018 */
00019 inline double sign(double x)
00020 {
00021     return x>=0?1:-1;
00022 }
00023 
00024 /**The ubiquitous square function
00025 @param f Number to square
00026 @return square of the number
00027 @ingroup gUtility
00028 */
00029 inline float sq(float f) { return f*f; }
00030 
00031 /**
00032     @overload
00033 */
00034 inline double sq(double f) { return f*f; }
00035 
00036 
00037 /**Cut sub images out of every member of a vector of images.
00038 @param im Images to be cut
00039 @param pos Top left corner
00040 @param size Size of the patch
00041 @returns subimages.
00042 @ingroup gUtility
00043 */
00044 const std::vector<CVD::SubImage<float> > sub_images(const std::vector<CVD::Image<float> >& im, CVD::ImageRef pos, CVD::ImageRef size);
00045 
00046 /** Deffinition of a pixel aligned bounding box
00047 @ingroup gUtility
00048 */
00049 typedef std::pair<CVD::ImageRef, CVD::ImageRef> BBox;
00050 
00051 /** Compute the bounding box of a set of points
00052 @param all_spots List of points
00053 @ingroup gUtility
00054 */
00055 std::pair<CVD::ImageRef, CVD::ImageRef> boundingbox(const std::vector<CVD::ImageRef> & all_spots);
00056 
00057 
00058 /**
00059 @param save_spots Stream
00060 @param save_spots_file File to open
00061 @ingroup gUtility
00062 */
00063 template<class Stream>
00064 void open_or_die(Stream& save_spots, const std::string& save_spots_file)
00065 {
00066     using std::cerr;
00067     using std::endl;
00068     using std::strerror;
00069     using std::exit;
00070     save_spots.open(save_spots_file.c_str());
00071     int err = errno;
00072 
00073     if(!save_spots.good())
00074     {
00075         cerr << "***********************************************************\n";
00076         cerr << "ERROR: failed to open " << save_spots_file << ": " <<strerror(err) << endl;
00077         cerr << "***********************************************************\n";
00078         exit(1);
00079     }
00080 }
00081 
00082 #endif