GJK_nD
 All Classes Files Functions Typedefs Friends Pages
utils.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012 Laurent Provot <provot.research@gmail.com>,
3  * Yan Gerard <yan.gerard@free.fr> and Fabien Feschet <research@feschet.fr>
4  * All rights reserved.
5  *
6  * This is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef UTILS_HPP
21 #define UTILS_HPP
22 
23 #include <sstream>
24 #include "png++/png.hpp"
25 
26 namespace Utils {
27 
40 template <typename T>
41 inline T square(T value)
42 {
43  return value * value;
44 }
45 
46 
55 template <typename T>
56 int sign(T value)
57 {
58  return (T(0) < value) - (value < T(0));
59 }
60 
61 
66 template<typename T>
67 inline std::string toString(T value)
68 {
69  std::ostringstream oss;
70  oss << value;
71  return oss.str();
72 }
73 
74 
80 void otsuThresholding(png::image<png::gray_pixel> & image);
81 
82 
86 void binaryImageToNegative(png::image<png::gray_pixel> & image);
87 
88 
92 template <typename pixel_type>
93 void fillImage(png::image<pixel_type> & image, const pixel_type & pixel)
94 {
95  for (size_t i = 0; i < image.get_width(); ++i)
96  for (size_t j = 0; j < image.get_height(); ++j)
97  image.set_pixel(i,j, pixel);
98 }
99 
100 } // namespace Utils
101 
102 #endif // UTILS_HPP