CHAI3D  3.0.0
CMultiImage.h
Go to the documentation of this file.
1 //==============================================================================
2 /*
3  Software License Agreement (BSD License)
4  Copyright (c) 2003-2015, CHAI3D.
5  (www.chai3d.org)
6 
7  All rights reserved.
8 
9  Redistribution and use in source and binary forms, with or without
10  modification, are permitted provided that the following conditions
11  are met:
12 
13  * Redistributions of source code must retain the above copyright
14  notice, this list of conditions and the following disclaimer.
15 
16  * Redistributions in binary form must reproduce the above
17  copyright notice, this list of conditions and the following
18  disclaimer in the documentation and/or other materials provided
19  with the distribution.
20 
21  * Neither the name of CHAI3D nor the names of its contributors may
22  be used to endorse or promote products derived from this software
23  without specific prior written permission.
24 
25  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  POSSIBILITY OF SUCH DAMAGE.
37 
38  \author <http://www.chai3d.org>
39  \author Sebastien Grange
40  \version 3.0.0 $Rev: 1647 $
41 */
42 //==============================================================================
43 
44 //------------------------------------------------------------------------------
45 #ifndef CMultiImageH
46 #define CMultiImageH
47 //------------------------------------------------------------------------------
48 #include "graphics/CImage.h"
49 //------------------------------------------------------------------------------
50 #include <string>
51 #include <vector>
52 //------------------------------------------------------------------------------
53 namespace chai3d {
54 //------------------------------------------------------------------------------
55 
56 //==============================================================================
63 //==============================================================================
64 
65 //------------------------------------------------------------------------------
67 typedef std::shared_ptr<cMultiImage> cMultiImagePtr;
68 //------------------------------------------------------------------------------
69 
70 //==============================================================================
87 //==============================================================================
88 class cMultiImage : public cImage
89 {
90  //--------------------------------------------------------------------------
91  // CONSTRUCTOR & DESTRUCTOR:
92  //--------------------------------------------------------------------------
93 
94 public:
95 
97  cMultiImage();
98 
100  virtual ~cMultiImage();
101 
103  static cMultiImagePtr create() { return (std::make_shared<cMultiImage>()); }
104 
105 
106  //--------------------------------------------------------------------------
107  // PUBLIC METHODS - GENERAL COMMANDS:
108  //--------------------------------------------------------------------------
109 
110 public:
111 
113  cMultiImagePtr copy();
114 
116  bool allocate(const unsigned int a_width,
117  const unsigned int a_height,
118  const unsigned int a_slices,
119  const GLenum a_format = GL_RGB,
120  const GLenum a_type = GL_UNSIGNED_BYTE);
121 
123  void erase() { cleanup(); }
124 
126  virtual unsigned int getImageCount() const { return (m_imageCount); }
127 
129  bool convert(const unsigned int a_newFormat);
130 
131 
132  //--------------------------------------------------------------------------
133  // PUBLIC METHODS - MULTIMAGE SELECTION:
134  //--------------------------------------------------------------------------
135 
136 public:
137 
139  virtual unsigned long getCurrentIndex() { return m_currentIndex; }
140 
142  virtual bool selectImage(unsigned long a_index);
143 
145  bool addImage(cImage &a_image, unsigned long a_index=-1);
146 
148  bool removeImage(unsigned long a_index);
149 
150 
151  //--------------------------------------------------------------------------
152  // PUBLIC METHODS - MANIPULATING PIXELS:
153  //--------------------------------------------------------------------------
154 
155 public:
156 
158  virtual void setTransparentColor(const cColorb &a_color,
159  const unsigned char a_transparencyLevel);
160 
162  virtual void setTransparentColor(const unsigned char a_r,
163  const unsigned char a_g,
164  const unsigned char a_b,
165  const unsigned char a_transparencyLevel) { cColorb color(a_r, a_g, a_b); setTransparentColor(color, a_transparencyLevel); }
166 
168  virtual void setTransparency(const unsigned char a_transparencyLevel);
169 
171  virtual void flipHorizontal();
172 
173 
174  //--------------------------------------------------------------------------
175  // PUBLIC METHODS - MANIPULATING VOXELS:
176  //--------------------------------------------------------------------------
177 
178 public:
179 
181  virtual void getVoxelLocation(const cVector3d a_texCoord, int& a_voxelX, int& a_voxelY, int& a_voxelZ);
182 
184  virtual unsigned char* getVoxelData(const unsigned int a_x,
185  const unsigned int a_y,
186  const unsigned int a_z) const;
187 
189  virtual bool getVoxelColor(const unsigned int a_x,
190  const unsigned int a_y,
191  const unsigned int a_z,
192  cColorb& a_color) const;
193 
195  virtual void setVoxelColor(const unsigned int a_x,
196  const unsigned int a_y,
197  const unsigned int a_z,
198  const cColorb& a_color);
199 
201  virtual void setVoxelColor(const unsigned int a_x,
202  const unsigned int a_y,
203  const unsigned int a_z,
204  const unsigned char a_r,
205  const unsigned char a_g,
206  const unsigned char a_b) { cColorb color(a_r, a_g, a_b); setVoxelColor(a_x, a_y, a_z, color); }
207 
209  virtual void setVoxelColor(const unsigned int a_x,
210  const unsigned int a_y,
211  const unsigned int a_z,
212  const unsigned char a_grayLevel);
213 
214 
215  //--------------------------------------------------------------------------
216  // PUBLIC METHODS - MEMORY DATA:
217  //--------------------------------------------------------------------------
218 
219 public:
220 
222  inline unsigned char* getArray() { return (m_array); }
223 
224 
225  //--------------------------------------------------------------------------
226  // PUBLIC METHODS - FILES:
227  //--------------------------------------------------------------------------
228 
229 public:
230 
232  virtual bool loadFromFile(const std::string& a_filename);
233 
235  virtual int loadFromFiles(const std::vector<std::string>& a_filename);
236 
238  virtual int loadFromFiles(const std::string& a_basename, const std::string& a_extension, unsigned long a_max = 9999);
239 
241  virtual bool addFromFile(const std::string& a_filename, unsigned long a_index=-1);
242 
244  virtual bool saveToFiles(const std::string& a_basename, const std::string& a_extension);
245 
246 
247  //--------------------------------------------------------------------------
248  // PROTECTED METHODS:
249  //--------------------------------------------------------------------------
250 
251 protected:
252 
254  void defaults();
255 
257  void cleanup();
258 
260  virtual bool addFromFilePrealloc(const std::string& a_filename, unsigned long a_index);
261 
263  bool addImagePrealloc(cImage &a_image, unsigned long a_index);
264 
265 
266  //--------------------------------------------------------------------------
267  // PROTECTED MEMBERS:
268  //--------------------------------------------------------------------------
269 
270 protected:
271 
273  unsigned char* m_array;
274 
276  unsigned long m_imageCount;
277 
279  unsigned long m_currentIndex;
280 };
281 
282 //------------------------------------------------------------------------------
283 } // namespace chai3d
284 //------------------------------------------------------------------------------
285 
286 //------------------------------------------------------------------------------
287 #endif
288 //------------------------------------------------------------------------------
This class implements a 3D vector.
Definition: CVector3d.h:85
unsigned long m_currentIndex
Index of the currently selected image.
Definition: CMultiImage.h:279
virtual bool saveToFiles(const std::string &a_basename, const std::string &a_extension)
This method saves all images to a set of files.
Definition: CMultiImage.cpp:1037
virtual void flipHorizontal()
This method flips all images horizontally.
Definition: CMultiImage.cpp:806
virtual void setTransparentColor(const unsigned char a_r, const unsigned char a_g, const unsigned char a_b, const unsigned char a_transparencyLevel)
This method defines a pixel color to be transparent for all images.
Definition: CMultiImage.h:162
virtual unsigned char * getVoxelData(const unsigned int a_x, const unsigned int a_y, const unsigned int a_z) const
This method returns a pointer to voxel memory data.
Definition: CMultiImage.cpp:763
virtual void setVoxelColor(const unsigned int a_x, const unsigned int a_y, const unsigned int a_z, const cColorb &a_color)
This method sets the color of an image voxel at location (x,y,z).
Definition: CMultiImage.cpp:602
This class implements an array of 2D image structures.
Definition: CMultiImage.h:88
cMultiImage()
Default constructor of cMultiImage.
Definition: CMultiImage.cpp:63
cMultiImagePtr copy()
This method creates a copy itself.
Definition: CMultiImage.cpp:205
unsigned long m_imageCount
Number of images contained in the structure.
Definition: CMultiImage.h:276
virtual unsigned int getImageCount() const
This method returns the number of images stored.
Definition: CMultiImage.h:126
bool addImage(cImage &a_image, unsigned long a_index=-1)
This method adds an image to the set if size and format are compatible.
Definition: CMultiImage.cpp:341
virtual bool addFromFilePrealloc(const std::string &a_filename, unsigned long a_index)
Add an image file to a preallocated set if size and format are compatible.
Definition: CMultiImage.cpp:1006
void erase()
This method deletes all image data from memory.
Definition: CMultiImage.h:123
std::shared_ptr< cMultiImage > cMultiImagePtr
Definition: CMultiImage.h:66
virtual void setTransparentColor(const cColorb &a_color, const unsigned char a_transparencyLevel)
This method defines a pixel color for all images to be transparent.
Definition: CMultiImage.cpp:704
virtual void getVoxelLocation(const cVector3d a_texCoord, int &a_voxelX, int &a_voxelY, int &a_voxelZ)
This method retrieves a voxel location from a texture coordinate.
Definition: CMultiImage.cpp:516
unsigned char * m_array
The image array data that holds all images contiguously.
Definition: CMultiImage.h:273
void cleanup()
This method deletes memory and rid ourselves of any image previously stored.
Definition: CMultiImage.cpp:103
virtual bool loadFromFile(const std::string &a_filename)
This method loads an image file.
Definition: CMultiImage.cpp:829
bool convert(const unsigned int a_newFormat)
This method converts the image to a new format passed as argument.
Definition: CMultiImage.cpp:231
virtual void setVoxelColor(const unsigned int a_x, const unsigned int a_y, const unsigned int a_z, const unsigned char a_r, const unsigned char a_g, const unsigned char a_b)
This method sets the color of an image voxel at location (x,y,z).
Definition: CMultiImage.h:201
virtual bool getVoxelColor(const unsigned int a_x, const unsigned int a_y, const unsigned int a_z, cColorb &a_color) const
This method returns the color of an image voxel at location (x,y,z).
Definition: CMultiImage.cpp:541
virtual bool addFromFile(const std::string &a_filename, unsigned long a_index=-1)
This method adds an image file to the set if size and format are compatible.
Definition: CMultiImage.cpp:976
This class defines a color using a GLubyte representation for each component.
Definition: CColor.h:1184
virtual ~cMultiImage()
Destructor of cMultiImage.
Definition: CMultiImage.cpp:75
static cMultiImagePtr create()
Shared cMultiImage allocator.
Definition: CMultiImage.h:103
bool removeImage(unsigned long a_index)
This method removes an image from the set.
Definition: CMultiImage.cpp:470
virtual int loadFromFiles(const std::vector< std::string > &a_filename)
This method loads an image set from a set of files.
Definition: CMultiImage.cpp:919
bool allocate(const unsigned int a_width, const unsigned int a_height, const unsigned int a_slices, const GLenum a_format=GL_RGB, const GLenum a_type=GL_UNSIGNED_BYTE)
This method allocates a new multi image array by defining its size, pixel format and pixel type...
Definition: CMultiImage.cpp:132
virtual bool selectImage(unsigned long a_index)
This method sets the current image.
Definition: CMultiImage.cpp:311
Definition: CAudioBuffer.cpp:56
unsigned char * getArray()
This method returns a pointer to the actual image data array. Use with care!
Definition: CMultiImage.h:222
bool addImagePrealloc(cImage &a_image, unsigned long a_index)
Add an image to a preallocated set if size and format are compatible.
Definition: CMultiImage.cpp:427
Implements a 2D image data structure.
This class implements a 2D image data structure.
Definition: CImage.h:83
virtual unsigned long getCurrentIndex()
This method returns the index number of the current image.
Definition: CMultiImage.h:139
virtual void setTransparency(const unsigned char a_transparencyLevel)
This method defines a transparent level to all pixels of image set.
Definition: CMultiImage.cpp:733
void defaults()
This method initializes all member variables.
Definition: CMultiImage.cpp:87

CHAI3D 3.0.0 documentation
Please address any questions to support@chai3d.org
(C) 2003-2015 - CHAI3D
All Rights Reserved.