PICCANTE  0.4
The hottest HDR imaging library!
filter_npasses.hpp
Go to the documentation of this file.
1 /*
2 
3 PICCANTE
4 The hottest HDR imaging library!
5 http://vcg.isti.cnr.it/piccante
6 
7 Copyright (C) 2014
8 Visual Computing Laboratory - ISTI CNR
9 http://vcg.isti.cnr.it
10 First author: Francesco Banterle
11 
12 This Source Code Form is subject to the terms of the Mozilla Public
13 License, v. 2.0. If a copy of the MPL was not distributed with this
14 file, You can obtain one at http://mozilla.org/MPL/2.0/.
15 
16 */
17 
18 #ifndef PIC_GL_FILTERING_FILTER_NPASSES_HPP
19 #define PIC_GL_FILTERING_FILTER_NPASSES_HPP
20 
21 #include "../../base.hpp"
22 
23 #include "../../util/std_util.hpp"
24 
25 #include "../../util/array.hpp"
26 
27 #include "../../util/gl/fbo.hpp"
28 
29 #include "../../gl/filtering/filter.hpp"
30 
31 namespace pic {
32 
37 {
38 protected:
42 
48  virtual void PreProcess(ImageGLVec imgIn, ImageGL *imgOut){}
49 
56  ImageGL *setupAuxNGen(ImageGLVec imgIn, ImageGL *imgOut);
57 
64  ImageGL *setupAuxNSame(ImageGLVec imgIn, ImageGL *imgOut);
65 
71  virtual FilterGL* getFilter(int i);
72 
77  virtual int getIterations();
78 
82  void releaseAux();
83 
90  ImageGL *ProcessGen(ImageGLVec imgIn, ImageGL *imgOut);
91 
98  ImageGL *ProcessSame(ImageGLVec imgIn, ImageGL *imgOut);
99 
100 public:
101 
105  FilterGLNPasses();
106 
108 
117  void OutputSize(ImageGLVec imgIn, int &width, int &height, int &frames, int &channels);
118 
124  {
125  return filters.back()->getFbo();
126  }
127 
134  ImageGL *Process(ImageGLVec imgIn, ImageGL *imgOut);
135 };
136 
138 {
139  imgAllocated = NULL;
140 
141  for(int i = 0; i < 2; i++) {
142  imgTmpSame[i] = NULL;
143  }
144 
145  target = GL_TEXTURE_2D;
146 }
147 
149 {
150  release();
151 }
152 
154 {
156 
157  imgTmpSame[0] = NULL;
158  imgTmpSame[1] = NULL;
159 
160  stdVectorClear<ImageGL>(imgTmp);
161 }
162 
164 {
165  int j = i % filters.size();
166  return filters[j];
167 }
168 
170 {
171  return int(filters.size());
172 }
173 
174 PIC_INLINE void FilterGLNPasses::OutputSize(ImageGLVec imgIn, int &width, int &height, int &frames, int &channels)
175 {
176  ImageGL *imgIn0 = new ImageGL(imgIn[0], false);
177 
178  auto *tmp = imgIn[0];
179  imgIn[0] = imgIn0;
180 
181  int n = getIterations();
182 
183  for(int i = 0; i < n; i++) {
184  auto flt_i = getFilter(i);
185  flt_i->changePass(i, n);
186  flt_i->OutputSize(imgIn, width, height, channels, frames);
187 
188  imgIn0->width = width;
189  imgIn0->height = height;
190  imgIn0->channels = channels;
191  imgIn0->frames = frames;
192  imgIn0->allocateAux();
193  }
194 
195  imgIn[0] = tmp;
196 
197  delete imgIn0;
198 }
199 
201  ImageGL *imgOut)
202 {
203  int width, height, frames, channels;
204  OutputSize(imgIn, width, height, frames, channels);
205 
206  int n = getIterations();
207 
208  if(imgTmp.empty()) {
209  setToANullVector<ImageGL>(imgTmp, n);
210  } else {
211  int tw, th, tf, tc;
212 
213  filters[0]->OutputSize(imgIn, tw, th, tf, tc);
214 
215  if(tw != imgTmp[0]->width ||
216  th != imgTmp[0]->height ||
217  tf != imgTmp[0]->frames ||
218  tc != imgTmp[0]->channels) {
219  stdVectorClear<ImageGL>(imgTmp);
220 
221  setToANullVector<ImageGL>(imgTmp, n);
222  }
223  }
224 
225  //output
226  if(imgOut == NULL) {
227  imgOut = new ImageGL(frames, width, height, channels, IMG_GPU, GL_TEXTURE_2D);
228  } else {
229  if(imgOut->height != height ||
230  imgOut->width != width ||
231  imgOut->channels != channels ||
232  imgOut->frames != frames) {
233  imgOut = new ImageGL(frames, width, height, channels, IMG_GPU, GL_TEXTURE_2D);
234  }
235  }
236 
237  return imgOut;
238 }
239 
241  ImageGL *imgOut)
242 {
243  if(imgOut == NULL) {
244  imgOut = imgIn[0]->allocateSimilarOneGL();
245  } else {
246  if(!imgOut->isSimilarType(imgIn[0])) {
247  imgOut = imgIn[0]->allocateSimilarOneGL();
248  }
249  }
250 
251  if(imgAllocated == NULL) {
252  imgAllocated = imgIn[0]->allocateSimilarOneGL();
253  } else {
254  if(!imgAllocated->isSimilarType(imgIn[0])) {
255  delete imgAllocated;
256  imgAllocated = imgIn[0]->allocateSimilarOneGL();
257  }
258  }
259 
260  int nIterations = getIterations();
261  if((nIterations % 2) == 0) {
263  imgTmpSame[1] = imgOut;
264  } else {
265  imgTmpSame[0] = imgOut;
267  }
268 
269  return imgOut;
270 }
271 
273 {
274  if(imgIn.empty() || filters.empty()) {
275  return imgOut;
276  }
277 
278  imgOut = setupAuxNGen(imgIn, imgOut);
279 
280  int n = getIterations();
281  int n2 = n - 1;
282 
283  for(int i = 0; i < n2; i++) {
284  auto flt_i = getFilter(i);
285  flt_i->changePass(i, n);
286  imgTmp[i] = flt_i->Process(imgIn, imgTmp[i]);
287 
288  imgIn[0] = imgTmp[i];
289  }
290 
291  auto flt_n = getFilter(n2);
292  flt_n->changePass(n2, n);
293  imgOut = filters[n2]->Process(imgIn, imgOut);
294 
295  return imgOut;
296 }
297 
299 {
300  if((imgIn.size() <= 0) || (filters.size() < 1)) {
301  return imgOut;
302  }
303 
304  //setup
305  imgOut = setupAuxNSame(imgIn, imgOut);
306 
307  int n = getIterations();
308  auto flt_0 = getFilter(0);
309  flt_0->changePass(0, n);
310  flt_0->Process(imgIn, imgTmpSame[0]);
311 
312  for(auto i = 1; i < n; i++) {
313  auto flt_i = getFilter(0);
314  flt_i->changePass(i, n);
315 
316  imgIn[0] = imgTmpSame[(i + 1) % 2];
317  flt_i->Process(imgIn, imgTmpSame[i % 2]);
318  }
319 
320  return imgOut;
321 }
322 
324  ImageGL *imgOut)
325 {
326  if(imgIn.empty() || filters.empty()) {
327  return imgOut;
328  }
329 
330  PreProcess(imgIn, imgOut);
331 
332  int width, height, frames, channels;
333  OutputSize(imgIn, width, height, frames, channels);
334 
335  bool bSame = (imgIn[0]->width == width) &&
336  (imgIn[0]->height == height) &&
337  (imgIn[0]->channels == channels) &&
338  (imgIn[0]->frames == frames);
339 
340  if(bSame) {
341  imgOut = ProcessSame(imgIn, imgOut);
342  } else {
343  imgOut = ProcessGen(imgIn, imgOut);
344  }
345 
346  return imgOut;
347 }
348 
349 /*
350 if(fbo==NULL)
351  fbo = new Fbo();
352 
353 fbo->create(imgOut->width,imgOut->height,imgOut->frames, false, imgOut->getTexture());
354 
355 for(unsigned int i=0;i<filters.size();i++)
356  filters[i]->setFbo(fbo);*/
357 
358 } // end namespace pic
359 
360 #endif /* PIC_GL_FILTERING_FILTER_NPASSES_HPP */
361 
ImageGL * imgTmpSame[2]
Definition: filter_npasses.hpp:40
int channels
Definition: filter_radial_basis_function.hpp:80
int frames
Definition: filter_radial_basis_function.hpp:80
T * delete_s(T *data)
delete_s
Definition: std_util.hpp:123
void allocateAux()
allocateAux computes extra information after allocation; e.g. strides.
Definition: filter_radial_basis_function.hpp:1057
ImageGL * allocateSimilarOneGL()
allocateSimilarOneGL
Definition: image.hpp:848
The Fbo class.
Definition: fbo.hpp:32
virtual void PreProcess(ImageGLVec imgIn, ImageGL *imgOut)
PreProcess.
Definition: filter_npasses.hpp:48
GLenum target
Definition: display.hpp:47
bool isSimilarType(const Image *img)
isSimilarType checks if the current image is similar to img; i.e. if they have the same width...
Definition: filter_radial_basis_function.hpp:1125
ImageGL * ProcessSame(ImageGLVec imgIn, ImageGL *imgOut)
ProcessSame.
The FilterGLNPasses class.
Definition: filter_npasses.hpp:36
ImageGL * ProcessGen(ImageGLVec imgIn, ImageGL *imgOut)
ProcessGen.
ImageGL * setupAuxNSame(ImageGLVec imgIn, ImageGL *imgOut)
setupAuxNSame
The ImageGL class.
Definition: image.hpp:42
Fbo * getFbo()
getFbo
Definition: filter_npasses.hpp:123
virtual int getIterations()
getIterations
ImageGL * allocateSimilarOneGL()
allocateSimilarOneGL
ImageGL * Process(ImageGLVec imgIn, ImageGL *imgOut)
Process.
void OutputSize(ImageGLVec imgIn, int &width, int &height, int &frames, int &channels)
OutputSize.
std::vector< FilterGL *> filters
Definition: display.hpp:55
The FilterGL class.
Definition: filter.hpp:35
ImageGLVec imgTmp
Definition: filter_npasses.hpp:41
ImageGL * setupAuxNGen(ImageGLVec imgIn, ImageGL *imgOut)
setupAuxNGen
ImageGL * imgAllocated
Definition: filter_npasses.hpp:39
FilterGLNPasses()
FilterGLNPasses.
The FilterGL class.
Definition: display.hpp:35
#define PIC_INLINE
Definition: base.hpp:33
The ImageGL class.
Definition: display.hpp:42
int width
Definition: filter_radial_basis_function.hpp:80
void releaseAux()
releaseAux
Definition: bilateral_separation.hpp:25
std::vector< ImageGL * > ImageGLVec
ImageGLVec an std::vector of pic::ImageGL.
Definition: display.hpp:32
Definition: image.hpp:37
virtual FilterGL * getFilter(int i)
getFilter
std::vector< ImageGL * > ImageGLVec
ImageGLVec an std::vector of pic::ImageGL.
Definition: image_vec.hpp:32
int height
Definition: filter_radial_basis_function.hpp:80
void release()
release
Definition: display.hpp:85