source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/Superpixels/SourceCode/segment/image.h @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 2.2 KB
Line 
1/*
2Copyright (C) 2006 Pedro Felzenszwalb
3
4This program is free software; you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation; either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program; if not, write to the Free Software
16Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17*/
18
19/* a simple image class */
20
21#ifndef IMAGE_H
22#define IMAGE_H
23
24#include <cstring>
25
26template <class T>
27class image {
28 public:
29  /* create an image */
30  image(const int width, const int height, const bool init = true);
31
32  /* delete an image */
33  ~image();
34
35  /* init an image */
36  void init(const T &val);
37
38  /* copy an image */
39  image<T> *copy() const;
40 
41  /* get the width of an image. */
42  int width() const { return w; }
43 
44  /* get the height of an image. */
45  int height() const { return h; }
46 
47  /* image data. */
48  T *data;
49 
50  /* row pointers. */
51  T **access;
52 
53 private:
54  int w, h;
55};
56
57/* use imRef to access image data. */
58#define imRef(im, x, y) (im->access[y][x])
59 
60/* use imPtr to get pointer to image data. */
61#define imPtr(im, x, y) &(im->access[y][x])
62
63template <class T>
64image<T>::image(const int width, const int height, const bool init) {
65  w = width;
66  h = height;
67  data = new T[w * h];  // allocate space for image data
68  access = new T*[h];   // allocate space for row pointers
69 
70  // initialize row pointers
71  for (int i = 0; i < h; i++)
72    access[i] = data + (i * w); 
73 
74  if (init)
75    memset(data, 0, w * h * sizeof(T));
76}
77
78template <class T>
79image<T>::~image() {
80  delete [] data; 
81  delete [] access;
82}
83
84template <class T>
85void image<T>::init(const T &val) {
86  T *ptr = imPtr(this, 0, 0);
87  T *end = imPtr(this, w-1, h-1);
88  while (ptr <= end)
89    *ptr++ = val;
90}
91
92
93template <class T>
94image<T> *image<T>::copy() const {
95  image<T> *im = new image<T>(w, h, false);
96  memcpy(im->data, data, w * h * sizeof(T));
97  return im;
98}
99
100#endif
101 
Note: See TracBrowser for help on using the repository browser.