ThreeB 1.1
|
00001 /* 00002 This file is part of B-cubed. 00003 00004 Copyright (C) 2009, 2010, 2011, Edward Rosten and Susan Cox 00005 00006 B-cubed is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Lesser General Public 00008 License as published by the Free Software Foundation; either 00009 version 3.0 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Lesser General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program. If not, see <http://www.gnu.org/licenses/> 00018 */ 00019 00020 #ifndef STORM_INCLUDE_UTILITY_H 00021 #define STORM_INCLUDE_UTILITY_H 00022 #include <cvd/image.h> 00023 #include <vector> 00024 #include <string> 00025 #include <cstring> 00026 #include <cerrno> 00027 #include <cstdlib> 00028 #include <utility> 00029 00030 /**computes the sign of x 00031 @param x \e x 00032 @return \f$ \begin{cases} 00033 1 & x \ge 0\\ 00034 -1 & x < 0 00035 \end{cases}\f$ 00036 @ingroup gUtility 00037 */ 00038 inline double sign(double x) 00039 { 00040 return x>=0?1:-1; 00041 } 00042 00043 /**The ubiquitous square function 00044 @param f Number to square 00045 @return square of the number 00046 @ingroup gUtility 00047 */ 00048 inline float sq(float f) { return f*f; } 00049 00050 /** 00051 @overload 00052 */ 00053 inline double sq(double f) { return f*f; } 00054 00055 00056 /**Cut sub images out of every member of a vector of images. 00057 @param im Images to be cut 00058 @param pos Top left corner 00059 @param size Size of the patch 00060 @returns subimages. 00061 @ingroup gUtility 00062 */ 00063 const std::vector<CVD::SubImage<float> > sub_images(const std::vector<CVD::Image<float> >& im, CVD::ImageRef pos, CVD::ImageRef size); 00064 00065 /** Deffinition of a pixel aligned bounding box 00066 @ingroup gUtility 00067 */ 00068 typedef std::pair<CVD::ImageRef, CVD::ImageRef> BBox; 00069 00070 /** Compute the bounding box of a set of points 00071 @param all_spots List of points 00072 @ingroup gUtility 00073 */ 00074 std::pair<CVD::ImageRef, CVD::ImageRef> boundingbox(const std::vector<CVD::ImageRef> & all_spots); 00075 00076 00077 /** 00078 @param save_spots Stream 00079 @param save_spots_file File to open 00080 @ingroup gUtility 00081 */ 00082 template<class Stream> 00083 void open_or_die(Stream& save_spots, const std::string& save_spots_file) 00084 { 00085 using std::cerr; 00086 using std::endl; 00087 using std::strerror; 00088 using std::exit; 00089 save_spots.open(save_spots_file.c_str()); 00090 int err = errno; 00091 00092 if(!save_spots.good()) 00093 { 00094 cerr << "***********************************************************\n"; 00095 cerr << "ERROR: failed to open " << save_spots_file << ": " <<strerror(err) << endl; 00096 cerr << "***********************************************************\n"; 00097 exit(1); 00098 } 00099 } 00100 00101 #endif