00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
00031
00032
00033
00034
00035
00036
00037
00038 inline double sign(double x)
00039 {
00040 return x>=0?1:-1;
00041 }
00042
00043
00044
00045
00046
00047
00048 inline float sq(float f) { return f*f; }
00049
00050
00051
00052
00053 inline double sq(double f) { return f*f; }
00054
00055
00056
00057
00058
00059
00060
00061
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
00066
00067
00068 typedef std::pair<CVD::ImageRef, CVD::ImageRef> BBox;
00069
00070
00071
00072
00073
00074 std::pair<CVD::ImageRef, CVD::ImageRef> boundingbox(const std::vector<CVD::ImageRef> & all_spots);
00075
00076
00077
00078
00079
00080
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