Computational Embodied Neuroscience Simulator  1.1
3D simulation library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
cens_pixelmap.h
Go to the documentation of this file.
1 // Computational Embodied Neuroscience Simulator (CENS) Library
2 // Copyright (c) 2010 Francesco Mannella
3 //
4 // cens_pixelmap.h
5 // Copyright (c) 2010 Francesco Mannella
6 //
7 // This file is part of CENS library.
8 //
9 // CENS library is free software: you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation, either version 3 of the License, or
12 // (at your option) any later version.
13 //
14 // CENS library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with CENS library. If not, see <http://www.gnu.org/licenses/>.
21 
22 #ifndef CENS_PIXELMAP_H
23 #define CENS_PIXELMAP_H
24 
25 #include "Magick++.h"
26 
27 using namespace Magick;
28 
29 namespace cens {
30 
40  class CENSPixelMap {
41 
42  public:
43  CENSPixelMap():m_pxWidth(0),m_pxHeight(0),isLoaded(false) {};
44 
45  CENSPixelMap(const CENSPixelMap &copy) {
46 
47  m_pxWidth=copy.m_pxWidth;
48  m_pxHeight=copy.m_pxHeight;
49  m_pxData=copy.m_pxData;
50  isLoaded=copy.isLoaded;
51 
52  }
53 
55 
56  m_pxWidth=copy.m_pxWidth;
57  m_pxHeight=copy.m_pxHeight;
58  m_pxData=copy.m_pxData;
59  isLoaded=copy.isLoaded;
60 
61  return *this;
62  }
63 
64  CENSPixelMap(std::string imgfile) {
65 
66  Image image(imgfile);
67  image.magick( "RGB" );
68  image.write( &m_pxData );
69  m_pxWidth=image.columns();
70  m_pxHeight=image.rows();
71  isLoaded=true;
72 
73  }
74 
76  }
77 
78  GLubyte operator()(int row, int col, int channel) {
79  return ((GLubyte*) m_pxData.data())[row*m_pxWidth + col*3 + channel];
80  }
81 
82  void setData(Blob &data, int width, int height) {
83  std::cout << "set data" << std::endl;
84  isLoaded=true;
85  m_pxData=data;
86  m_pxWidth=width;
87  m_pxHeight=height;
88  }
89  void setData(GLubyte *pixels, int width, int height) {
90  isLoaded=true;
91  m_pxData=Blob(pixels,width*height*3);
92  m_pxWidth=width;
93  m_pxHeight=height;
94  }
95  const GLubyte *getData() const {
96  if(isLoaded) {
97  return (GLubyte *)m_pxData.data();
98  }
99  return 0;
100  }
101 
102  Blob &getBlob() { return m_pxData; }
103  int getWidth() const { return m_pxWidth; }
104  int getHeight() const { return m_pxHeight; }
105 
106 
107  private:
108 
109  Blob m_pxData;
110  int m_pxWidth;
112  bool isLoaded;
113 
114  };
115 
116 }
117 
118 #endif //CENS_PIXELMAP_H
CENSPixelMap(std::string imgfile)
Definition: cens_pixelmap.h:64
void setData(GLubyte *pixels, int width, int height)
Definition: cens_pixelmap.h:89
int getHeight() const
Computational Embodied Neuroscience Simulator library.
Definition: cens_engine.cpp:29
CENSPixelMap(const CENSPixelMap &copy)
Definition: cens_pixelmap.h:45
int getWidth() const
CENSPixelMap & operator=(const CENSPixelMap &copy)
Definition: cens_pixelmap.h:54
void setData(Blob &data, int width, int height)
Definition: cens_pixelmap.h:82
Use a byte vector as a matrix.
Definition: cens_pixelmap.h:40
const GLubyte * getData() const
Definition: cens_pixelmap.h:95
GLubyte operator()(int row, int col, int channel)
Definition: cens_pixelmap.h:78