SMIL  0.9.1
DBaseImageOperations.hpp
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 _BASE_IMAGE_OPERATIONS_HPP
31 #define _BASE_IMAGE_OPERATIONS_HPP
32 
33 #include "Core/include/private/DImage.hpp"
34 #include "Core/include/private/DMemory.hpp"
35 
36 #include "DBaseLineOperations.hpp"
37 
38 namespace smil
39 {
40 
41  template <class T>
43  {
44  public:
45  typedef Image<T> imageType;
46  typedef typename imageType::sliceType sliceType;
47  typedef typename imageType::lineType lineType;
48  typedef typename imageType::pixelType pixelType;
49 
50  sliceType alignedBuffers;
51  size_t bufferNumber;
52  size_t bufferLength;
53  size_t bufferSize;
54 
55  RES_T retVal;
56 
57  imageFunctionBase() : alignedBuffers ( NULL ) {}
59  {
60  deleteAlignedBuffers();
61  }
62 
63  lineType *createAlignedBuffers ( size_t nbr, size_t len );
64  void deleteAlignedBuffers();
65  inline void copyLineToBuffer ( T *line, size_t bufIndex );
66  inline void copyBufferToLine ( size_t bufIndex, T *line );
67 
68  operator RES_T() { return retVal; }
69  };
70 
71  template <class T, class lineFunction_T, class T_out=T>
73  {
74  public:
76  typedef Image<T> imageInType;
77  typedef typename imageInType::pixelType pixelInType;
78  typedef typename imageInType::lineType lineInType;
79  typedef typename imageInType::sliceType sliceInType;
80 
81  typedef Image<T_out> imageOutType;
82  typedef typename imageOutType::pixelType pixelOutType;
83  typedef typename imageOutType::lineType lineOutType;
84  typedef typename imageOutType::sliceType sliceOutType;
85 
87  unaryImageFunction( const imageInType &imIn, imageOutType &ImOut )
88  {
89  this->retVal = this->_exec ( imIn, ImOut );
90  }
91  unaryImageFunction( imageOutType &imOut, const T_out &value )
92  {
93  this->retVal = this->_exec (imOut, value);
94  }
95 
96  inline RES_T operator() ( const imageInType &imIn, imageOutType &ImOut )
97  {
98  return this->_exec ( imIn, ImOut );
99  }
100  inline RES_T operator() ( imageOutType &ImOut, const T_out &value )
101  {
102  return this->_exec ( ImOut, value );
103  }
104 
105  RES_T _exec ( const imageInType &imIn, imageOutType &imOut );
106  RES_T _exec ( imageOutType &imOut, const T_out &value );
107 
108  // protected:
109  lineFunction_T lineFunction;
110  };
111 
112 
113  template <class T, class lineFunction_T>
115  {
116  public:
118  typedef Image<T> imageType;
119  typedef typename imageType::pixelType pixelType;
120  typedef typename imageType::lineType lineType;
121  typedef typename imageType::sliceType sliceType;
122 
124  binaryImageFunction ( const imageType &imIn1, const imageType &imIn2, imageType &ImOut )
125  {
126  this->retVal = this->_exec ( imIn1, imIn2, ImOut );
127  }
128  binaryImageFunction ( const imageType &imIn, const T &value, imageType &ImOut )
129  {
130  this->retVal = this->_exec ( imIn, value, ImOut );
131  }
132  binaryImageFunction ( const T &value, const imageType &imIn, imageType &ImOut )
133  {
134  this->retVal = this->_exec ( value, imIn, ImOut );
135  }
136 
137  inline RES_T operator() ( const imageType &imIn1, const imageType &imIn2, imageType &ImOut )
138  {
139  return this->_exec ( imIn1, imIn2, ImOut );
140  }
141  inline RES_T operator() ( const imageType &imIn, const T &value, imageType &ImOut )
142  {
143  return this->_exec ( imIn, value, ImOut );
144  }
145 
146  inline RES_T operator() (const T &value, const imageType &imIn, imageType &ImOut )
147  {
148  return this->_exec ( value, imIn, ImOut );
149  }
150 
151  RES_T _exec ( const imageType &imIn1, const imageType &imIn2, imageType &imOut );
152  RES_T _exec ( const imageType &imIn, imageType &imInOut );
153  RES_T _exec ( const imageType &imIn, const T &value, imageType &imOut );
154  RES_T _exec ( const T &value, const imageType &imIn, imageType &imOut );
155 
156  // protected:
157  lineFunction_T lineFunction;
158  };
159 
160  template <class T, class lineFunction_T>
162  {
163  public:
165  typedef Image<T> imageType;
166  typedef typename imageType::pixelType pixelType;
167  typedef typename imageType::lineType lineType;
168  typedef typename imageType::sliceType sliceType;
169 
171 
172  template <class T2>
173  tertiaryImageFunction( const imageType &imIn, const T2 &value1, const T2 &value2, Image<T2> &ImOut )
174  {
175  this->retVal = this->_exec ( imIn, value1, value2, ImOut );
176  }
177  template <class T2>
178  tertiaryImageFunction( const imageType &imIn, const T2 &value1, const Image<T2> &imIn2, Image<T2> &ImOut )
179  {
180  this->retVal = this->_exec ( imIn, value1, imIn2, ImOut );
181  }
182  template <class T2>
183  tertiaryImageFunction( const imageType &imIn, const Image<T2> &imIn1, const T2 &value2, Image<T2> &ImOut )
184  {
185  this->retVal = this->_exec ( imIn, imIn1, value2, ImOut );
186  }
187  template <class T2>
188  tertiaryImageFunction( const imageType &imIn, const Image<T2> &imIn1, const Image<T2> &imIn2, Image<T2> &ImOut )
189  {
190  this->retVal = this->_exec ( imIn, imIn1, imIn2, ImOut );
191  }
192 
193 
194  template <class T2>
195  inline RES_T operator() ( const imageType &imIn1, const Image<T2> &imIn2, const Image<T2> &imIn3, Image<T2> &ImOut )
196  {
197  return this->_exec ( imIn1, imIn2, imIn3, ImOut );
198  }
199  template <class T2>
200  inline RES_T operator() ( const imageType &imIn1, const T2 &value, const Image<T2> &imIn2, Image<T2> &ImOut )
201  {
202  return this->_exec ( imIn1, value, imIn2, ImOut );
203  }
204  template <class T2>
205  inline RES_T operator() ( const imageType &imIn1, const Image<T2> &imIn2, const T2 &value, Image<T2> &ImOut )
206  {
207  return this->_exec ( imIn1, imIn2, value, ImOut );
208  }
209  template <class T2>
210  inline RES_T operator() ( const imageType &imIn, const T2 &value1, const T2 &value2, Image<T2> &ImOut )
211  {
212  return this->_exec ( imIn, value1, value2, ImOut );
213  }
214 
215  template <class T2>
216  RES_T _exec ( const imageType &imIn1, const Image<T2> &imIn2, const Image<T2> &imIn3, Image<T2> &imOut );
217  template <class T2>
218  RES_T _exec ( const imageType &imIn1, const T2 &value, const Image<T2> &imIn2, Image<T2> &imOut );
219  template <class T2>
220  RES_T _exec ( const imageType &imIn1, const Image<T2> &imIn2, const T2 &value, Image<T2> &imOut );
221  template <class T2>
222  RES_T _exec ( const imageType &imIn, const T2 &value1, const T2 &value2, Image<T2> &imOut );
223  // protected:
224  lineFunction_T lineFunction;
225  };
226 
227 
228 
229 } // namespace smil
230 
231 
232 #include "DBaseImageOperations.hxx"
233 
234 #endif
Definition: DBaseImageOperations.hpp:42
Definition: DColorConvert.h:38
Definition: DBaseImageOperations.hpp:72
Definition: DBaseImageOperations.hpp:114
Main Image class.
Definition: DQVtkViewer.hpp:44
Definition: DBaseImageOperations.hpp:161