SMIL  0.9.1
DCommon.h
1 /*
2  * Copyright (c) 2011-2016, Matthieu FAESSEL and ARMINES
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of Matthieu FAESSEL, or ARMINES nor the
14  * names of its contributors may be used to endorse or promote products
15  * derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY
18  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 
30 #ifndef _DCOMMON_H
31 #define _DCOMMON_H
32 
33 
34 #include <cstring>
35 #include <memory>
36 #include <limits>
37 #include <vector>
38 #include <map>
39 #include <cmath>
40 #include <cstdarg>
41 
42 
43 #include "private/DTypes.hpp"
44 
45 using namespace std;
46 
47 namespace smil
48 {
49  #define VERBOSE 1
50 
51  #if VERBOSE > 1
52  #define MESSAGE(msg) cout << msg << endl;
53  #else // VERBOSE
54  #define MESSAGE(msg)
55  #endif // VERBOSE
56 
57 #if defined __GNUC__ || defined __clang__
58 #define SMIL_UNUSED __attribute__((__unused__))
59 #else // MSVC et al.
60 #define SMIL_UNUSED
61 #endif
62 
63 
64  #define INLINE inline
65 
66  // Generate template specializations (or instanciations?) for
67  // ImageHandler subclasses (in IO/DImageIO_{BMP,JPG,PBM,PNG,TIFF})
68 #define IMAGEFILEHANDLER_TEMP_SPEC(FORMAT, PIXELTYPE) \
69  template <> \
70  class FORMAT##ImageFileHandler<PIXELTYPE> \
71  : public ImageFileHandler<PIXELTYPE> \
72  { \
73  public: \
74  FORMAT##ImageFileHandler() : ImageFileHandler<PIXELTYPE>(#FORMAT) \
75  { \
76  } \
77  RES_T read(const char *filename, Image<PIXELTYPE> &image); \
78  RES_T write(const Image<PIXELTYPE> &image, const char *filename); \
79  };
80 
81  #define SMART_POINTER(T) boost::shared_ptr< T >
82  #define SMART_IMAGE(T) SMART_POINTER( D_Image< T > )
83 
84  #define D_DEFAULT_IMAGE_WIDTH 512
85  #define D_DEFAULT_IMAGE_HEIGHT 512
86  #define D_DEFAULT_IMAGE_DEPTH 1
87 
88  #define D_DEFAULT_OUT_PIXEL_VAL 0
89 
90  #ifndef PI
91  #define PI 3.141592653589793
92  #endif // PI
93 
94  #ifndef MIN
95  #define MIN(a, b) (a < b ? a : b);
96  #endif // MIN
97  #ifndef MAX
98  #define MAX(a, b) (a > b ? a : b);
99  #endif // MAX
100 
101 #ifndef SWIG
103  {
104  template <typename Lhs, typename Rhs>
105  bool operator()(const Lhs& lhs, const Rhs& rhs) const
106  {
107  return lhs.second < rhs.second;
108  }
109  };
110 #endif // SWIG
111 
112  template <class T>
113  struct Point
114  {
115  T x;
116  T y;
117  T z;
118  Point() : x(0), y(0), z(0) {}
119  Point(const Point &pt) : x(pt.x), y(pt.y), z(pt.z) {}
120  Point(T _x, T _y, T _z) : x(_x), y(_y), z(_z) {}
121  Point(T _x, T _y) : x(_x), y(_y), z(0) {}
122  bool operator == (const Point &p2)
123  {
124  return (x==p2.x && y==p2.y && z==p2.z);
125  }
126  };
127 
128  typedef Point<double> DoublePoint;
129  typedef Point<int> IntPoint;
130  typedef Point<UINT> UintPoint;
131 
132  typedef vector<double> Vector_double;
133  typedef vector<Vector_double> Matrix_double;
134  typedef vector<UINT> Vector_UINT;
135  typedef vector<size_t> Vector_size_t;
136 
137  struct Rectangle
138  {
139  UINT x0, y0;
140  UINT xSzie, ySize;
141  };
142 
143  struct Box
144  {
145  UINT x0, y0, z0;
146  UINT x1, y1, z1;
147  Box()
148  {
149  x0 = x1 = y0 = y1 = z0 = z1 = 0;
150  }
151  Box(const Box &rhs)
152  {
153  x0 = rhs.x0;
154  x1 = rhs.x1;
155  y0 = rhs.y0;
156  y1 = rhs.y1;
157  z0 = rhs.z0;
158  z1 = rhs.z1;
159  }
160  UINT getWidth() const { return x1-x0+1; }
161  UINT getHeight() const { return y1-y0+1; }
162  UINT getDepth() const { return z1-z0+1; }
163  };
164 
165 
166  // Misc Macros
167 
168  #ifdef _MSC_VER
169 
170  #define __FUNC__ __FUNCTION__
171 
172  // Work-around to MSVC __VA_ARGS__ expanded as a single argument, instead of being broken down to multiple ones
173  #define EXPAND( ... ) __VA_ARGS__
174 
175  #define _GET_1ST_ARG(arg1, ...) arg1
176  #define _GET_2ND_ARG(arg1, arg2, ...) arg2
177  #define _GET_3RD_ARG(arg1, arg2, arg3, ...) arg3
178  #define _GET_4TH_ARG(arg1, arg2, arg3, arg4, ...) arg4
179  #define _GET_5TH_ARG(arg1, arg2, arg3, arg4, arg5, ...) arg5
180  #define _GET_6TH_ARG(arg1, arg2, arg3, arg4, arg5, arg6, ...) arg6
181  #define _GET_7TH_ARG(arg1, arg2, arg3, arg4, arg5, arg6, arg7, ...) arg7
182  #define _GET_8TH_ARG(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, ...) arg8
183  #define GET_1ST_ARG(...) EXPAND(_GET_1ST_ARG(__VA_ARGS__))
184  #define GET_2ND_ARG(...) EXPAND(_GET_2ND_ARG(__VA_ARGS__))
185  #define GET_3RD_ARG(...) EXPAND(_GET_3RD_ARG(__VA_ARGS__))
186  #define GET_4TH_ARG(...) EXPAND(_GET_4TH_ARG(__VA_ARGS__))
187  #define GET_5TH_ARG(...) EXPAND(_GET_5TH_ARG(__VA_ARGS__))
188  #define GET_6TH_ARG(...) EXPAND(_GET_6TH_ARG(__VA_ARGS__))
189  #define GET_7TH_ARG(...) EXPAND(_GET_7TH_ARG(__VA_ARGS__))
190  #define GET_8TH_ARG(...) EXPAND(_GET_8TH_ARG(__VA_ARGS__))
191 
192  #define _xPP_NARGS_IMPL(x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,N,...) N
193  #define PP_NARGS(...) \
194  EXPAND(_xPP_NARGS_IMPL(__VA_ARGS__,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0))
195 
196  #else // _MSC_VER
197 
198  #define __FUNC__ __func__
199 
200  #define GET_1ST_ARG(arg1, ...) arg1
201  #define GET_2ND_ARG(arg1, arg2, ...) arg2
202  #define GET_3RD_ARG(arg1, arg2, arg3, ...) arg3
203  #define GET_4TH_ARG(arg1, arg2, arg3, arg4, ...) arg4
204  #define GET_5TH_ARG(arg1, arg2, arg3, arg4, arg5, ...) arg5
205  #define GET_6TH_ARG(arg1, arg2, arg3, arg4, arg5, arg6, ...) arg6
206  #define GET_7TH_ARG(arg1, arg2, arg3, arg4, arg5, arg6, arg7, ...) arg7
207  #define GET_8TH_ARG(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, ...) arg8
208 
209  #define _xPP_NARGS_IMPL(x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,N,...) N
210  #define PP_NARGS(...) \
211  _xPP_NARGS_IMPL(__VA_ARGS__,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0)
212 
213  #endif // _MSC_VER
214 
215 } // namespace smil
216 
217 #endif // _DCOMMON_H
218 
Definition: DCommon.h:143
Author Vincent Morard Date : 7 march 2011 See : Morard V. and Dokladal P. and Decenciere E...
Definition: DApplyThreshold.hpp:36
Definition: DCommon.h:102
Definition: DCommon.h:137
Definition: DCommon.h:113