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 #if defined (_MSC_VER) && !defined (__clang__)
67  #define TEMPL_SPEC_DECL template
68 #else
69  #define TEMPL_SPEC_DECL template <>
70 #endif // _MSC_VER && !__clang__
71 
72  #define SMART_POINTER(T) boost::shared_ptr< T >
73  #define SMART_IMAGE(T) SMART_POINTER( D_Image< T > )
74 
75  #define D_DEFAULT_IMAGE_WIDTH 512
76  #define D_DEFAULT_IMAGE_HEIGHT 512
77  #define D_DEFAULT_IMAGE_DEPTH 1
78 
79  #define D_DEFAULT_OUT_PIXEL_VAL 0
80 
81  #ifndef PI
82  #define PI 3.141592653589793
83  #endif // PI
84 
85  #ifndef MIN
86  #define MIN(a, b) (a < b ? a : b);
87  #endif // MIN
88  #ifndef MAX
89  #define MAX(a, b) (a > b ? a : b);
90  #endif // MAX
91 
92 #ifndef SWIG
94  {
95  template <typename Lhs, typename Rhs>
96  bool operator()(const Lhs& lhs, const Rhs& rhs) const
97  {
98  return lhs.second < rhs.second;
99  }
100  };
101 #endif // SWIG
102 
103  template <class T>
104  struct Point
105  {
106  T x;
107  T y;
108  T z;
109  Point() : x(0), y(0), z(0) {}
110  Point(const Point &pt) : x(pt.x), y(pt.y), z(pt.z) {}
111  Point(T _x, T _y, T _z) : x(_x), y(_y), z(_z) {}
112  Point(T _x, T _y) : x(_x), y(_y), z(0) {}
113  bool operator == (const Point &p2)
114  {
115  return (x==p2.x && y==p2.y && z==p2.z);
116  }
117  };
118 
119  typedef Point<double> DoublePoint;
120  typedef Point<int> IntPoint;
121  typedef Point<UINT> UintPoint;
122 
123  typedef vector<double> Vector_double;
124  typedef vector<Vector_double> Matrix_double;
125  typedef vector<UINT> Vector_UINT;
126  typedef vector<size_t> Vector_size_t;
127 
128  struct Rectangle
129  {
130  UINT x0, y0;
131  UINT xSzie, ySize;
132  };
133 
134  struct Box
135  {
136  UINT x0, y0, z0;
137  UINT x1, y1, z1;
138  Box()
139  {
140  x0 = x1 = y0 = y1 = z0 = z1 = 0;
141  }
142  Box(const Box &rhs)
143  {
144  x0 = rhs.x0;
145  x1 = rhs.x1;
146  y0 = rhs.y0;
147  y1 = rhs.y1;
148  z0 = rhs.z0;
149  z1 = rhs.z1;
150  }
151  UINT getWidth() const { return x1-x0+1; }
152  UINT getHeight() const { return y1-y0+1; }
153  UINT getDepth() const { return z1-z0+1; }
154  };
155 
156 
157  // Misc Macros
158 
159  #ifdef _MSC_VER
160 
161  #define __FUNC__ __FUNCTION__
162 
163  // Work-around to MSVC __VA_ARGS__ expanded as a single argument, instead of being broken down to multiple ones
164  #define EXPAND( ... ) __VA_ARGS__
165 
166  #define _GET_1ST_ARG(arg1, ...) arg1
167  #define _GET_2ND_ARG(arg1, arg2, ...) arg2
168  #define _GET_3RD_ARG(arg1, arg2, arg3, ...) arg3
169  #define _GET_4TH_ARG(arg1, arg2, arg3, arg4, ...) arg4
170  #define _GET_5TH_ARG(arg1, arg2, arg3, arg4, arg5, ...) arg5
171  #define _GET_6TH_ARG(arg1, arg2, arg3, arg4, arg5, arg6, ...) arg6
172  #define _GET_7TH_ARG(arg1, arg2, arg3, arg4, arg5, arg6, arg7, ...) arg7
173  #define _GET_8TH_ARG(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, ...) arg8
174  #define GET_1ST_ARG(...) EXPAND(_GET_1ST_ARG(__VA_ARGS__))
175  #define GET_2ND_ARG(...) EXPAND(_GET_2ND_ARG(__VA_ARGS__))
176  #define GET_3RD_ARG(...) EXPAND(_GET_3RD_ARG(__VA_ARGS__))
177  #define GET_4TH_ARG(...) EXPAND(_GET_4TH_ARG(__VA_ARGS__))
178  #define GET_5TH_ARG(...) EXPAND(_GET_5TH_ARG(__VA_ARGS__))
179  #define GET_6TH_ARG(...) EXPAND(_GET_6TH_ARG(__VA_ARGS__))
180  #define GET_7TH_ARG(...) EXPAND(_GET_7TH_ARG(__VA_ARGS__))
181  #define GET_8TH_ARG(...) EXPAND(_GET_8TH_ARG(__VA_ARGS__))
182 
183  #define _xPP_NARGS_IMPL(x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,N,...) N
184  #define PP_NARGS(...) \
185  EXPAND(_xPP_NARGS_IMPL(__VA_ARGS__,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0))
186 
187  #else // _MSC_VER
188 
189  #define __FUNC__ __func__
190 
191  #define GET_1ST_ARG(arg1, ...) arg1
192  #define GET_2ND_ARG(arg1, arg2, ...) arg2
193  #define GET_3RD_ARG(arg1, arg2, arg3, ...) arg3
194  #define GET_4TH_ARG(arg1, arg2, arg3, arg4, ...) arg4
195  #define GET_5TH_ARG(arg1, arg2, arg3, arg4, arg5, ...) arg5
196  #define GET_6TH_ARG(arg1, arg2, arg3, arg4, arg5, arg6, ...) arg6
197  #define GET_7TH_ARG(arg1, arg2, arg3, arg4, arg5, arg6, arg7, ...) arg7
198  #define GET_8TH_ARG(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, ...) arg8
199 
200  #define _xPP_NARGS_IMPL(x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,N,...) N
201  #define PP_NARGS(...) \
202  _xPP_NARGS_IMPL(__VA_ARGS__,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0)
203 
204  #endif // _MSC_VER
205 
206 } // namespace smil
207 
208 #endif // _DCOMMON_H
209 
Definition: DCommon.h:134
Definition: DColorConvert.h:38
Definition: DCommon.h:93
Definition: DCommon.h:128
Definition: DCommon.h:104