PICCANTE  0.4
The hottest HDR imaging library!
pushpull.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_ALGORITHMS_PUSHPULL_HPP
19 #define PIC_GL_ALGORITHMS_PUSHPULL_HPP
20 
21 #include "../../gl/image.hpp"
22 #include "../../gl/image_vec.hpp"
23 
24 #include "../../util/array.hpp"
25 
26 #include "../../gl/filtering/filter_down_pp.hpp"
27 #include "../../gl/filtering/filter_up_pp.hpp"
28 
29 namespace pic {
30 
35 {
36 protected:
37 
40 
42 
46  void release() {
47  for(unsigned int i = 1; i < stack.size(); i++) {
48  if(stack[i] != NULL){
49  delete stack[i];
50  }
51  }
52 
53  stack.clear();
54  }
55 
56 public:
57 
62  {
63  flt_down = NULL;
64  flt_up = NULL;
65  }
66 
68  {
69  release();
70  }
71 
77  void update(float *value, float threshold = 1e-6f)
78  {
79  if(flt_down == NULL) {
80  flt_down = new FilterGLDownPP(value, threshold);
81  } else {
82  flt_down->update(value, threshold);
83  }
84 
85  if(flt_up == NULL) {
86  flt_up = new FilterGLUpPP(value, threshold);
87  } else {
88  flt_up->update(value, threshold);
89  }
90  }
91 
98  ImageGL *Process(ImageGL *imgIn, ImageGL *imgOut)
99  {
100  if(imgIn == NULL) {
101  return imgOut;
102  }
103 
104  if(imgOut == NULL) {
105  imgOut = imgIn->cloneGL();
106  } else {
107  *imgOut = *imgIn;
108  }
109 
110  ImageGL *work = imgOut;
111  if(stack.empty()) { //create the pyramid: Pull
112  stack.push_back(imgOut);
113 
114  while(MIN(work->width, work->height) > 1) {
115  ImageGL *tmp = flt_down->Process(SingleGL(work), NULL);
116 
117  if(tmp != NULL) {
118  stack.push_back(tmp);
119  work = tmp;
120  }
121  }
122  } else { //update previously created pyramid: Pull
123  int c = 1;
124  while(MIN(work->width, work->height) > 1) {
125  flt_down->Process(DoubleGL(work, stack[c]), stack[c]);
126 
127  work = stack[c];
128  c++;
129  }
130  }
131 
132  //sampling from the pyramid (stack): Push
133  int n = int(stack.size() - 2);
134 
135  for(int i = n; i >= 0; i--) {
136  flt_up->Process(DoubleGL(stack[i + 1], stack[i]), stack[i]);
137  }
138 
139  return imgOut;
140  }
141 
149  static ImageGL *execute(ImageGL *img, ImageGL *imgOut, float value)
150  {
151  PushPullGL pp;
152 
153  float *tmp_value = new float[img->channels];
154  Arrayf::assign(value, tmp_value, img->channels);
155 
156  pp.update(tmp_value, 1e-4f);
157  imgOut = pp.Process(img, imgOut);
158 
159  delete[] tmp_value;
160 
161  return imgOut;
162  }
163 };
164 
165 } // end namespace pic
166 
167 #endif /* PIC_GL_ALGORITHMS_PUSHPULL_HPP */
168 
int channels
Definition: filter_radial_basis_function.hpp:80
FilterGLUpPP * flt_up
Definition: pushpull.hpp:39
~PushPullGL()
Definition: pushpull.hpp:67
PIC_INLINE ImageGLVec SingleGL(ImageGL *img)
SingleGL creates a single for filters input.
Definition: image_vec.hpp:39
ImageGL * cloneGL()
cloneGL
static ImageGL * execute(ImageGL *img, ImageGL *imgOut, float value)
Execute.
Definition: pushpull.hpp:149
The ImageGL class.
Definition: image.hpp:42
void update(float *value, float threshold)
update
Definition: filter_down_pp.hpp:111
virtual ImageGL * Process(ImageGLVec imgIn, ImageGL *imgOut)
Process.
Definition: display.hpp:258
FilterGLDownPP * flt_down
Definition: pushpull.hpp:38
void update(float *value, float threshold=1e-6f)
update
Definition: pushpull.hpp:77
ImageGLVec stack
Definition: pushpull.hpp:41
ImageGL * Process(ImageGL *imgIn, ImageGL *imgOut)
Process computes push-pull.
Definition: pushpull.hpp:98
int width
Definition: filter_radial_basis_function.hpp:80
#define MIN(a, b)
Definition: math.hpp:69
void release()
release
Definition: pushpull.hpp:46
PIC_INLINE ImageGLVec DoubleGL(ImageGL *img1, ImageGL *img2)
DoubleGL creates a couple for filters input.
Definition: image_vec.hpp:52
Definition: bilateral_separation.hpp:25
The FilterGLUpPP class.
Definition: filter_up_pp.hpp:31
void update(float *value, float threshold)
update
Definition: filter_up_pp.hpp:91
static T * assign(T *data, int size, T *ret)
assign
Definition: array.hpp:464
The FilterGLDownPP class.
Definition: filter_down_pp.hpp:30
PushPullGL()
PushPullGL.
Definition: pushpull.hpp:61
The PushPullGL class.
Definition: pushpull.hpp:34
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