-
Notifications
You must be signed in to change notification settings - Fork 5
/
utility.h
82 lines (71 loc) · 1.84 KB
/
utility.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#ifndef STORM_INCLUDE_UTILITY_H
#define STORM_INCLUDE_UTILITY_H
#include <cvd/image.h>
#include <vector>
#include <string>
#include <cstring>
#include <cerrno>
#include <cstdlib>
#include <utility>
/**computes the sign of x
@param x \e x
@return \f$ \begin{cases}
1 & x \ge 0\\
-1 & x < 0
\end{cases}\f$
@ingroup gUtility
*/
inline double sign(double x)
{
return x>=0?1:-1;
}
/**The ubiquitous square function
@param f Number to square
@return square of the number
@ingroup gUtility
*/
inline float sq(float f) { return f*f; }
/**
@overload
*/
inline double sq(double f) { return f*f; }
/**Cut sub images out of every member of a vector of images.
@param im Images to be cut
@param pos Top left corner
@param size Size of the patch
@returns subimages.
@ingroup gUtility
*/
const std::vector<CVD::SubImage<float> > sub_images(const std::vector<CVD::Image<float> >& im, CVD::ImageRef pos, CVD::ImageRef size);
/** Deffinition of a pixel aligned bounding box
@ingroup gUtility
*/
typedef std::pair<CVD::ImageRef, CVD::ImageRef> BBox;
/** Compute the bounding box of a set of points
@param all_spots List of points
@ingroup gUtility
*/
std::pair<CVD::ImageRef, CVD::ImageRef> boundingbox(const std::vector<CVD::ImageRef> & all_spots);
/**
@param save_spots Stream
@param save_spots_file File to open
@ingroup gUtility
*/
template<class Stream>
void open_or_die(Stream& save_spots, const std::string& save_spots_file)
{
using std::cerr;
using std::endl;
using std::strerror;
using std::exit;
save_spots.open(save_spots_file.c_str());
int err = errno;
if(!save_spots.good())
{
cerr << "***********************************************************\n";
cerr << "ERROR: failed to open " << save_spots_file << ": " <<strerror(err) << endl;
cerr << "***********************************************************\n";
exit(1);
}
}
#endif