From d5052f1c296dddf51b3e83d59bf3e3c1952cb2d0 Mon Sep 17 00:00:00 2001 From: cathook Date: Sun, 1 Jun 2014 13:56:57 +0800 Subject: big chnage --- doc/html/Bitmap_8h_source.html | 309 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 309 insertions(+) create mode 100644 doc/html/Bitmap_8h_source.html (limited to 'doc/html/Bitmap_8h_source.html') diff --git a/doc/html/Bitmap_8h_source.html b/doc/html/Bitmap_8h_source.html new file mode 100644 index 0000000..4956a0b --- /dev/null +++ b/doc/html/Bitmap_8h_source.html @@ -0,0 +1,309 @@ + + + + + + + +Templates -- Meow: meowpp/gra/Bitmap.h Source File + + + + + + + + + + + +
+
+ + + + + + + +
+
Templates -- Meow +  1.1.2 +
+
不能,也不應該先編譯成obj-file的templates
+
+
+ + +
+
+ +
+
+
+ +
+
+
+
Bitmap.h
+
+
+Go to the documentation of this file.
1 #ifndef gra_Bitmap_H__
+
2 #define gra_Bitmap_H__
+
3 
+
4 
+
5 #include "../Self.h"
+
6 
+
7 #include "../math/utility.h"
+
8 #include "../math/Matrix.h"
+
9 
+
10 #include "../oo/ObjBase.h"
+
11 
+
12 #include <vector>
+
13 #include <cmath>
+
14 #include <string>
+
15 #include <typeinfo>
+
16 #include <cstdlib>
+
17 
+
18 namespace meow{
+
19 
+
25 template<class Pixel>
+
26 class Bitmap: public ObjBase {
+
27 private:
+
28  Matrix<Pixel> matrix_;
+
29  //
+
30  static std::vector<double> gaussianFactor1(double sigma) {
+
31  double sigma2 = squ(sigma);
+
32  size_t width = std::max(ceil((double)(sigma * 2)), 0.0);
+
33  std::vector<double> factor(width + 1 + width);
+
34  for (size_t x = 0; x < width; x++) {
+
35  factor[width - x - 1] = exp(-(squ((double)x)) / (2.0 * sigma2));
+
36  factor[width + x + 1] = exp(-(squ((double)x)) / (2.0 * sigma2));
+
37  }
+
38  factor[width] = 1.0;
+
39  return factor;
+
40  }
+
41  static std::vector<double> gradianceFactor1(double sigma) {
+
42  double sigma2 = squ(sigma), ss = sigma * 2;
+
43  size_t width = std::max(ceil(ss), 1.0);
+
44  std::vector<double> factor(width + 1 + width);
+
45  for (size_t x = 0; x < width; x++) {
+
46  factor[width - x - 1] = (double)x * exp(-(squ((double)x))/(2.0*sigma2));
+
47  factor[width + x + 1] = -(double)x * exp(-(squ((double)x))/(2.0*sigma2));
+
48  }
+
49  factor[width] = 0.0;
+
50  return factor;
+
51  }
+
52  Bitmap xyBlur(std::vector<double> const& factor,
+
53  ssize_t dx, ssize_t dy) const {
+
54  Bitmap ret(*this);
+
55  if (factor.size() > 0) {
+
56  ssize_t w = factor.size() / 2;
+
57  for (size_t y = 0, Y = height(); y < Y; y++) {
+
58  for (size_t x = 0, X = width(); x < X; x++) {
+
59  Pixel sum(0);
+
60  double fsum(0);
+
61  for (ssize_t i = -w; i <= w; i++) {
+
62  ssize_t x2 = (ssize_t)x + dx * i;
+
63  ssize_t y2 = (ssize_t)y + dy * i;
+
64  if (0 <= x2 && x2 < (ssize_t)X && 0 <= y2 && y2 < (ssize_t)Y) {
+
65  sum = sum + pixel(y2, x2) * factor[i + w];
+
66  fsum = fsum + fabs(factor[i + w]);
+
67  }
+
68  }
+
69  ret.pixel(y, x, sum / fsum);
+
70  }
+
71  }
+
72  }
+
73  return ret;
+
74  }
+
75 public:
+
79  Bitmap() {
+
80  }
+
81 
+
85  Bitmap(Bitmap const& b): matrix_(b.matrix_) {
+
86  }
+
87 
+
95  Bitmap(size_t h, size_t w, Pixel const& p): matrix_(h, w, p) {
+
96  }
+
97 
+ +
102  }
+
103 
+
107  Bitmap& copyFrom(Bitmap const& b) {
+
108  matrix_.copyFrom(b.matrix_);
+
109  return *this;
+
110  }
+
111 
+ +
116  matrix_.referenceFrom(b.matrix_);
+
117  return *this;
+
118  }
+
119 
+
128  void reset(size_t h, size_t w, Pixel const& p) {
+
129  matrix_.reset(h, w, p);
+
130  }
+
131 
+
135  void clear() {
+
136  matrix_.size(0, 0, Pixel(0));
+
137  }
+
138 
+
142  size_t height() const {
+
143  return matrix_.rows();
+
144  }
+
145 
+
149  size_t width() const {
+
150  return matrix_.cols();
+
151  }
+
152 
+
156  size_t size() const {
+
157  return matrix_.size();
+
158  }
+
159 
+
167  size_t height(size_t h2, Pixel const& p) {
+
168  return matrix_.rows(h2, p);
+
169  }
+
170 
+
178  size_t width(size_t w2, Pixel const& p) {
+
179  return matrix_.cols(w2, p);
+
180  }
+
181 
+
190  size_t size(size_t h2, size_t w2, Pixel const& p) {
+
191  return matrix_.size(h2, w2, p);
+
192  }
+
193 
+
201  Pixel pixel(size_t y, size_t x) const {
+
202  return matrix_.entry(y, x);
+
203  }
+
204 
+
213  Pixel pixel(size_t y, size_t x, Pixel const& p) {
+
214  return matrix_.entry(y, x, p);
+
215  }
+
216 
+
229  void pixels(ssize_t yFirst, ssize_t yLast,
+
230  ssize_t xFirst, ssize_t xLast,
+
231  Pixel const& p) {
+
232  return matrix_.entries(yFirst, yLast, xFirst, xLast, p);
+
233  }
+
234 
+
242  Bitmap gaussian(double radiusY, double radiusX) const {
+
243  return (xyBlur(gaussianFactor1(radiusY), 1, 0).
+
244  xyBlur(gaussianFactor1(radiusX), 0, 1));
+
245  }
+
246 
+
254  Bitmap<Pixel>& gaussianed(double radiusY, double radiusX) {
+
255  copyFrom(gaussian(radiusY, radiusX));
+
256  return *this;
+
257  }
+
258 
+
266  Bitmap<Pixel> gradianceX(double radiusY, double radiusX) const {
+
267  return (xyBlur(gaussianFactor1(radiusY), 1, 0).
+
268  xyBlur(gradianceFactor1(radiusX), 0, 1));
+
269  }
+
270 
+
278  Bitmap<Pixel>& gradiancedX(double radiusY, double radiusX) {
+
279  return copyFrom(gradianceX(radiusY, radiusX));
+
280  }
+
281 
+
289  Bitmap<Pixel> gradianceY (double radiusY, double radiusX) const {
+
290  return (xyBlur(gaussianFactor1(radiusX), 0, 1).
+
291  xyBlur(gradianceFactor1(radiusY), 1, 0));
+
292  }
+
293 
+
301  Bitmap<Pixel>& gradiancedY(double radiusY, double radiusX) {
+
302  return copyFrom(gradianceY(radiusY, radiusX));
+
303  }
+
304 
+
308  Bitmap& operator=(Bitmap const& b) {
+
309  return copyFrom(b);
+
310  }
+
311 
+
315  Pixel operator()(size_t y, size_t x) const {
+
316  return pixel(y, x);
+
317  }
+
318 
+
322  Pixel const& operator()(size_t y, size_t x, Pixel const& p) const {
+
323  return pixel(y, x, p);
+
324  }
+
325 
+
330  bool write(FILE* f, bool bin, unsigned int fg) const {
+
331  size_t w = width(), h = height();
+
332  if (bin) {
+
333  if (fwrite(&h, sizeof(size_t), 1, f) < 1) return false;
+
334  if (fwrite(&w, sizeof(size_t), 1, f) < 1) return false;
+
335  }
+
336  else {
+
337  if (fprintf(f, "%lu %lu\n", h, w) < 2) return false;
+
338  }
+
339  if (fg) {
+
340  // TODO
+
341  return false;
+
342  }
+
343  return true;
+
344  //return propertyWrite(__f, __bin, __fg);
+
345  }
+
346 
+
351  bool read(FILE* f, bool bin, unsigned int fg) {
+
352  size_t w, h;
+
353  if (bin) {
+
354  if (fread(&h, sizeof(size_t), 1, f) < 1) return false;
+
355  if (fread(&w, sizeof(size_t), 1, f) < 1) return false;
+
356  }
+
357  else {
+
358  if (fscanf(f, "%lu %lu\n", &h, &w) < 2) return false;
+
359  }
+
360  if (fg) {
+
361  // TODO
+
362  return false;
+
363  }
+
364  else {
+
365  reset(h, w, Pixel(0));
+
366  }
+
367  return true;
+
368  }
+
369 
+
374  ObjBase* create() const {
+
375  return new Bitmap();
+
376  }
+
377 
+
387  ObjBase* copyFrom(ObjBase const* b) {
+
388  return &(copyFrom(*(Bitmap*)b));
+
389  }
+
390 
+
395  char const* ctype() const{
+
396  static char const* ptr = typeid(*this).name();
+
397  return ptr;
+
398  }
+
399 
+
404  std::string type() const {
+
405  return std::string(ctype());
+
406  }
+
407 };
+
408 
+
409 }
+
410 
+
411 #endif // gra_Bitmap_H__
+
+
+ + + + + -- cgit