Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
clfImage3D.hh
1 /*
2  This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4  Copyright (C) 2003, 2004 (see file CONTACTS for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10  BIAS is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation; either version 2.1 of the License, or
13  (at your option) any later version.
14 
15  BIAS is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with BIAS; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23  */
24 
25 #ifndef CLFIMAGE3D_HH_
26 #define CLFIMAGE3D_HH_
27 
28 #include <bias_config.h>
29 #include <Base/Common/BIASpragmaStart.hh>
30 #include <OpenCLFramework/clfOpenCL.hh>
31 #include <OpenCLFramework/clfMemory.hh>
32 #include <OpenGLFramework/Base/glfTexture3D.hh>
33 
34 namespace BIAS {
35 
36  /**
37  *
38  * @brief OpenCL Image3D wrapper
39  *
40  * An clfImage3D is used for both cl::Images, host and GL objects.
41  * All buffers are created from a valid clfContext, hence the constructor is protected.
42  *
43  * @author fkellner 06/11
44  */
45  class BIASOpenCLFramework_EXPORT clfImage3D : public clfMemory {
46  public:
47 
48  virtual ~clfImage3D();
49 
50  /**
51  * @brief Allocation of a memory buffer as 3D image, either call directly or use wrapper for BIAS::ImageBase
52  */
53  void Allocate(
55  unsigned int width, unsigned int height, unsigned int levels, unsigned int stride=0,
56  bool readonly=false, bool writeonly=false, const void *hostptr = NULL, bool copy = false);
57 
58  /**
59  * @brief Allocation of a memory buffer as 3D image (2d+level), biasimage is used as template for one level
60  */
61  void AllocateFromBiasTemplate(const BIAS::ImageBase &image, unsigned int levels, bool readonly=false, bool writeonly=false);
62 
63  void AllocateFromTemplate(const clfImage3D &src, bool readonly=false, bool writeonly=false);
64 
65  /**
66  * @brief Allocation of a memory buffer from a GL Texture3D (works only on shared context!)
67  */
68  void AllocateFromTexture3D(BIAS::glfTexture3D &tex, bool readonly=false, bool writeonly=false);
69 
70  inline unsigned int Width() { return width_; }
71  inline unsigned int Height() { return height_; }
72  inline unsigned int Levels() { return depth_; }
73  inline unsigned int Stride() { return stride_; }
74  inline unsigned int SlideStride() { return slideStride_; }
75 
76  /// @brief write from host memory to image
77  void WriteToImage(const void *data,
78  unsigned int originX=0, unsigned int originY=0, unsigned int originZ=0,
79  unsigned int regionX=0, unsigned int regionY=0, unsigned int regionZ=0);
80 
81  /// @brief read from image to host memory
82  void ReadFromImage(void *data,
83  unsigned int originX=0, unsigned int originY=0, unsigned int originZ=0,
84  unsigned int regionX=0, unsigned int regionY=0, unsigned int regionZ=0);
85 
86  void CopyToImage(clfImage3D &outputimage,
87  unsigned int srcoriginX=0, unsigned int srcoriginY=0, unsigned int srcoriginZ=0,
88  unsigned int dstoriginX=0, unsigned int dstoriginY=0, unsigned int dstoriginZ=0,
89  unsigned int regionX=0, unsigned int regionY=0, unsigned int regionZ=0);
90 
91  void* MapImage(bool write = false,
92  unsigned int originX=0, unsigned int originY=0, unsigned int originZ=0,
93  unsigned int regionX=0, unsigned int regionY=0, unsigned int regionZ=0
94  );
95 
96  void CopyToBiasImage(BIAS::ImageBase &image, unsigned int level,
97  unsigned int originX=0, unsigned int originY=0,
98  unsigned int regionX=0, unsigned int regionY=0
99  );
100 
101  std::vector<std::string> GetSupportedImageFormats(bool readonly=false, bool writeonly=false);
102 
103  void GetImageDim(unsigned int &width, unsigned int &height, unsigned int &levels) {
104  width = width_;
105  height = height_;
106  levels = depth_;
107  }
108 
109  protected:
110  clfImage3D(cl::Context *context, cl::CommandQueue *queue);
111  cl::Image3D& image();
112 
113  private:
114  friend class clfContext;
115  friend class clfProgram;
116 
117  cl::ImageFormat DetermineImageFormat_(BIAS::ImageBase::EStorageType st, BIAS::ImageBase::EColorModel cm);
118  bool GetFormatSupported_(cl::ImageFormat test, bool readonly, bool writeonly);
119  void MakeDim_(cl::size_t<3> &dest, int x, int y, int z);
120 
121  unsigned int width_, height_, depth_, stride_, slideStride_;
122 
125 
126  static std::vector<cl::ImageFormat> imageFormatsReadable_;
127  static std::vector<cl::ImageFormat> imageFormatsWritable_;
128  static std::vector<cl::ImageFormat> imageFormatsReadWrite_;
129 
130  };
131 }
132 #include <Base/Common/BIASpragmaEnd.hh>
133 #endif /* CLFIMAGE3D_HH_ */
EColorModel
These are the most often used color models.
Definition: ImageBase.hh:127
unsigned int Levels()
Definition: clfImage3D.hh:72
void GetImageDim(unsigned int &width, unsigned int &height, unsigned int &levels)
Definition: clfImage3D.hh:103
unsigned int Height()
Definition: clfImage3D.hh:71
OpenCL Program wrapper.
Definition: clfProgram.hh:53
OpenCL Context wrapper.
Definition: clfContext.hh:49
unsigned int Width()
Definition: clfImage3D.hh:70
OpenCL Image3D wrapper.
Definition: clfImage3D.hh:45
unsigned int SlideStride()
Definition: clfImage3D.hh:74
This is the base class for images in BIAS.
Definition: ImageBase.hh:102
unsigned int Stride()
Definition: clfImage3D.hh:73