PICCANTE  0.4
The hottest HDR imaging library!
filter_sampler_1d.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_FILTERING_FILTER_SAMPLER_1D_HPP
19 #define PIC_FILTERING_FILTER_SAMPLER_1D_HPP
20 
21 #define X_DIRECTION 0
22 #define Y_DIRECTION 1
23 #define Z_DIRECTION 2
24 
25 #include "../filtering/filter.hpp"
26 #include "../image_samplers/image_sampler_bilinear.hpp"
27 #include "../image_samplers/image_sampler_bsplines.hpp"
28 #include "../image_samplers/image_sampler_gaussian.hpp"
29 #include "../image_samplers/image_sampler_nearest.hpp"
30 
31 namespace pic {
32 
36 class FilterSampler1D: public Filter
37 {
38 protected:
41  int dirs[3];
42  int size;
43  bool swh;
44 
51  void ProcessBBox(Image *dst, ImageVec src, BBox *box);
52 
57  void setDirection(int direction);
58 
64 
65 public:
72  FilterSampler1D(float scale, int direction, ImageSampler *isb);
73 
80  FilterSampler1D(int size, int direction, ImageSampler *isb);
81 
88  void update(float scale, int direction, ImageSampler *isb);
89 
96  void update(int size, int direction, ImageSampler *isb);
97 
106  void OutputSize(ImageVec imgIn, int &width, int &height, int &channels, int &frames)
107  {
108  if(swh) {
109  float scaleX = (dirs[X_DIRECTION] == 1) ? scale : 1.0f;
110  float scaleY = (dirs[Y_DIRECTION] == 1) ? scale : 1.0f;
111 
112  width = int(imgIn[0]->widthf * scaleX);
113  height = int(imgIn[0]->heightf * scaleY);
114  } else {
115  width = (dirs[X_DIRECTION] == 1) ? size : imgIn[0]->width;
116  height = (dirs[Y_DIRECTION] == 1) ? size : imgIn[0]->height;
117  }
118 
119  channels = imgIn[0]->channels;
120  frames = imgIn[0]->frames;
121  }
122 
132  static Image *execute(Image *imgIn, Image *imgOut, float scale,
133  int direction, ImageSampler *isb)
134  {
135  FilterSampler1D filter(scale, direction, isb);
136  return filter.Process(Single(imgIn), imgOut);
137  }
138 };
139 
140 PIC_INLINE FilterSampler1D::FilterSampler1D(float scale, int direction = 0,
141  ImageSampler *isb = NULL) : Filter()
142 {
143  this->isb = NULL;
144  update(scale, direction, isb);
145 }
146 
147 PIC_INLINE FilterSampler1D::FilterSampler1D(int size, int direction = 0,
148  ImageSampler *isb = NULL) : Filter()
149 {
150  this->isb = NULL;
151  update(size, direction, isb);
152 }
153 
154 PIC_INLINE void FilterSampler1D::update(float scale, int direction,
155  ImageSampler *isb)
156 {
157  this->scale = scale;
158  this->swh = true;
159 
160  setDirection(direction);
162 }
163 
164 PIC_INLINE void FilterSampler1D::update(int size, int direction,
165  ImageSampler *isb)
166 {
167  this->size = size;
168  this->swh = false;
169 
170  setDirection(direction);
172 }
173 
175 {
176  dirs[ direction % 3] = 1;
177  dirs[(direction + 1) % 3] = 0;
178  dirs[(direction + 2) % 3] = 0;
179 }
180 
182 {
183  if(isb == NULL) {
184  if(this->isb == NULL) {
185  this->isb = &isb_default;
186  }
187  } else {
188  this->isb = isb;
189  }
190 }
191 
193  BBox *box)
194 {
195  float width1f = float(box->width - 1);
196  float height1f = float(box->height - 1);
197 
198  for(int j = box->y0; j < box->y1; j++) {
199  float y = float(j) / height1f;
200 
201  for(int i = box->x0; i < box->x1; i++) {
202  float x = float(i) / width1f;
203 
204  float *tmp_data = (*dst)(i, j);
205  isb->SampleImage(src[0], x, y, tmp_data);
206  }
207  }
208 }
209 
210 } // end namespace pic
211 
212 #endif /* PIC_FILTERING_FILTER_SAMPLER_1D_HPP */
213 
The FilterSampler1D class.
Definition: filter_sampler_1d.hpp:36
The BBox class manages the creation of bounding boxes for images.
Definition: bbox.hpp:29
void setDirection(int direction)
setDirection
Definition: filter_sampler_1d.hpp:174
void update(float scale, int direction, ImageSampler *isb)
update
Definition: filter_sampler_1d.hpp:154
FilterSampler1D(float scale, int direction, ImageSampler *isb)
FilterSampler1D.
Definition: filter_sampler_1d.hpp:140
#define X_DIRECTION
Definition: filter_sampler_1d.hpp:21
std::vector< Image * > ImageVec
ImageVec an std::vector of pic::Image.
Definition: image_vec.hpp:29
int x0
Definition: bbox.hpp:32
The ImageSampler class.
Definition: image_sampler.hpp:29
The Filter class.
Definition: filter.hpp:50
void OutputSize(ImageVec imgIn, int &width, int &height, int &channels, int &frames)
OutputSize.
Definition: filter_sampler_1d.hpp:106
virtual Image * Process(ImageVec imgIn, Image *imgOut)
Process.
Definition: filter.hpp:390
void ProcessBBox(Image *dst, ImageVec src, BBox *box)
ProcessBBox.
Definition: filter_sampler_1d.hpp:192
int dirs[3]
Definition: filter_sampler_1d.hpp:41
float scale
Definition: filter_radial_basis_function.hpp:53
bool swh
Definition: filter_sampler_1d.hpp:43
int y0
Definition: bbox.hpp:32
#define Y_DIRECTION
Definition: filter_sampler_1d.hpp:22
ImageSampler * isb
Definition: filter_sampler_1d.hpp:40
int size
Definition: filter_sampler_1d.hpp:42
static Image * execute(Image *imgIn, Image *imgOut, float scale, int direction, ImageSampler *isb)
execute
Definition: filter_sampler_1d.hpp:132
#define PIC_INLINE
Definition: base.hpp:33
void setImageSampler(ImageSampler *isb)
setImageSampler
Definition: filter_sampler_1d.hpp:181
ImageSamplerNearest isb_default
Definition: filter_sampler_1d.hpp:39
The Image class stores an image as buffer of float.
Definition: image.hpp:60
virtual void f(FilterFData *data)
f
Definition: filter_radial_basis_function.hpp:69
PIC_INLINE ImageVec Single(Image *img)
Single creates an std::vector which contains img; this is for filters input.
Definition: image_vec.hpp:36
Definition: bilateral_separation.hpp:25
virtual void SampleImage(Image *img, float x, float y, float *vOut)
SampleImage samples an image in uniform coordiantes.
Definition: image_sampler.hpp:57
int width
Definition: bbox.hpp:33
int height
Definition: bbox.hpp:33
The ImageSamplerNearest class.
Definition: image_sampler_nearest.hpp:28