PICCANTE  0.4
The hottest HDR imaging library!
bbox.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_UTIL_BBOX_HPP
19 #define PIC_UTIL_BBOX_HPP
20 
21 #include "../base.hpp"
22 #include "../util/string.hpp"
23 
24 namespace pic {
25 
29 class BBox
30 {
31 public:
32  int x0, y0, z0, x1, y1, z1;
34 
38  BBox()
39  {
40 
41  }
42 
50  BBox(int width, int height)
51  {
52  setBox(0, width, 0, height, 0, 1, width, height, 1);
53  }
54 
64  BBox(int width, int height, int frames)
65  {
66  setBox(0, width, 0, height, 0, frames, width, height, frames);
67  }
68 
76  BBox(int x0, int x1, int y0, int y1)
77  {
78  setBox(x0, x1, y0, y1, 0, 1, -1, -1, 1);
79  }
80 
90  BBox(int x0, int x1, int y0, int y1, int width, int height)
91  {
92  setBox(x0, x1, y0, y1, 0, 1, width, height, 1);
93  }
94 
103  BBox(int x0, int y0, int size, int width, int height)
104  {
105  setCentered(x0, y0, size, width, height);
106  }
107 
112  int Size()
113  {
114  return (y1 - y0) * (x1 - x0) * (z1 - z0);
115  }
116 
129  void setBox(int x0, int x1, int y0, int y1, int z0, int z1, int width,
130  int height, int frames)
131  {
132  this->x0 = x0;
133  this->y0 = y0;
134  this->z0 = z0;
135 
136  this->x1 = x1;
137  this->y1 = y1;
138  this->z1 = z1;
139 
140  this->width = width;
141  this->height = height;
142  this->frames = frames;
143  }
144 
153  void setCentered(int x0, int y0, int size, int width, int height)
154  {
155  this->z0 = 0;
156  this->z1 = 1;
157 
158  int halfSize = size >> 1;
159 
160  this->x0 = x0 - halfSize;
161  this->x1 = x0 + halfSize;
162 
163  this->y0 = y0 - halfSize;
164  this->y1 = y0 + halfSize;
165 
166  this->width = width;
167  this->height = height;
168  this->frames = 1;
169  }
170 
177  void getFourBlocks(int width, int height, int i)
178  {
179  int halfWidth = width >> 1;
180  int halfHeight = height >> 1;
181 
182  int dataX[] = {0, 0, halfWidth, halfWidth};
183  int dataY[] = {0, halfHeight, 0, halfHeight};
184 
185  if((width % 2) == 1) {
186  halfWidth++;
187  }
188 
189  if((height % 2) == 1) {
190  halfHeight++;
191  }
192 
193  setBox(dataX[i], dataX[i] + halfWidth,
194  dataY[i], dataY[i] + halfHeight,
195  0, 1,
196  width, height, 1);
197  // print();
198  }
199 
204  std::string toString()
205  {
206  return "X = (" + fromNumberToString(x0) + ", " + fromNumberToString(x1) + ") " +
207  "Y = (" + fromNumberToString(y0) + ", " + fromNumberToString(y1) + ") " +
208  "Z = (" + fromNumberToString(z0) + ", " + fromNumberToString(z1) + ")";
209  }
210 };
211 
212 } // end namespace pic
213 
214 #endif /* PIC_UTIL_BBOX_HPP */
215 
The BBox class manages the creation of bounding boxes for images.
Definition: bbox.hpp:29
std::string fromNumberToString(T num)
fromNumberToString converts a number into a string.
Definition: string.hpp:102
int x0
Definition: bbox.hpp:32
void setBox(int x0, int x1, int y0, int y1, int z0, int z1, int width, int height, int frames)
setBox sets a BBox up.
Definition: bbox.hpp:129
BBox(int x0, int x1, int y0, int y1, int width, int height)
BBox is a constructor setting the BBox up.
Definition: bbox.hpp:90
void setCentered(int x0, int y0, int size, int width, int height)
SetCentered.
Definition: bbox.hpp:153
int Size()
Size computes the number of pixels in a bounding box.
Definition: bbox.hpp:112
int y0
Definition: bbox.hpp:32
BBox(int x0, int x1, int y0, int y1)
BBox is a constructor setting the BBox up.
Definition: bbox.hpp:76
void getFourBlocks(int width, int height, int i)
getFourBlocks sets the BBox as a quadrant of a given size.
Definition: bbox.hpp:177
BBox(int x0, int y0, int size, int width, int height)
BBox.
Definition: bbox.hpp:103
BBox(int width, int height, int frames)
BBox is a constructor setting the BBox up.
Definition: bbox.hpp:64
int x1
Definition: bbox.hpp:32
BBox(int width, int height)
BBox is a constructor setting the BBox up.
Definition: bbox.hpp:50
int y1
Definition: bbox.hpp:32
std::string toString()
toString returns a string representation of BBox
Definition: bbox.hpp:204
Definition: bilateral_separation.hpp:25
BBox()
BBox is a basic constructor. It does nothing.
Definition: bbox.hpp:38
int width
Definition: bbox.hpp:33
int z1
Definition: bbox.hpp:32
int height
Definition: bbox.hpp:33
int frames
Definition: bbox.hpp:33
int z0
Definition: bbox.hpp:32