Image Component Library (ICL)
CLMemory.h
Go to the documentation of this file.
1 /********************************************************************
2  ** Image Component Library (ICL) **
3  ** **
4  ** Copyright (C) 2006-2013 CITEC, University of Bielefeld **
5  ** Neuroinformatics Group **
6  ** Website: www.iclcv.org and **
7  ** http://opensource.cit-ec.de/projects/icl **
8  ** **
9  ** File : ICLUtils/src/ICLUtils/CLMemory.h **
10  ** Module : ICLUtils **
11  ** Authors: Tobias Roehlig **
12  ** **
13  ** **
14  ** GNU LESSER GENERAL PUBLIC LICENSE **
15  ** This file may be used under the terms of the GNU Lesser General **
16  ** Public License version 3.0 as published by the **
17  ** **
18  ** Free Software Foundation and appearing in the file LICENSE.GPL **
19  ** included in the packaging of this file. Please review the **
20  ** following information to ensure the license requirements will **
21  ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt **
22  ** **
23  ** The development of this software was supported by the **
24  ** Excellence Cluster EXC 277 Cognitive Interaction Technology. **
25  ** The Excellence Cluster EXC 277 is a grant of the Deutsche **
26  ** Forschungsgemeinschaft (DFG) in the context of the German **
27  ** Excellence Initiative. **
28  ** **
29  ********************************************************************/
30 
31 #pragma once
32 
33 #ifdef ICL_HAVE_OPENCL
34 
35 #include <ICLUtils/SmartPtr.h>
36 #include <ICLUtils/CLException.h>
37 #include <vector>
38 
39 namespace icl {
40  namespace utils {
41 
42  class CLBuffer;
43  class CLImage2D;
44 
49 
50  public:
51 
54 
56  enum MemoryType {
59  Invalid
60  };
61 
62  protected:
63 
68  CLMemory(MemoryType const type = Invalid) : m_dimensions(3,1), m_size(1), m_type(type) {}
69 
71  std::vector<icl32s> m_dimensions;
76 
78  void setDimensions(icl32s const &x, icl32s const &y, icl32s const &z) {
79  m_dimensions[0] = x; m_dimensions[1] = y; m_dimensions[2] = z;
80  m_size = x*y*z;
81  }
82 
83  private:
84 
87 
88  public:
89 
94  CLMemory(CLMemory const &other) {
95  this->m_type = other.m_type;
96  this->m_dimensions = other.m_dimensions;
97  this->m_size = other.m_size;
98  this->m_byte_depth = other.m_byte_depth;
99  }
100 
106  CLMemory& operator=(CLMemory const& other) {
107  this->m_type = other.m_type;
108  this->m_dimensions = other.m_dimensions;
109  this->m_size = other.m_size;
110  this->m_byte_depth = other.m_byte_depth;
111  return *this;
112  }
113 
115  virtual ~CLMemory() {}
116 
121  inline CLBuffer *asCLBuffer() {
122  if (m_type != Buffer)
123  throw CLBufferException("Invalid cast from CLMemory to CLBuffer pointer");
124  return reinterpret_cast<CLBuffer*>(this);
125  }
126 
131  inline CLImage2D *asCLImage2D() {
132  if (m_type != Image2D)
133  throw CLBufferException("Invalid cast from CLMemory to CLImage2D pointer");
134  return reinterpret_cast<CLImage2D*>(this);
135  }
136 
138  const std::vector<icl32s> getDimensions() const { return m_dimensions; }
140  const icl64s getSize() const { return m_size; }
142  const icl32s getByteDepth() const { return m_byte_depth; }
143 
144  };
145 
146  }
147 }
148 
149 #endif
CLMemory(MemoryType const type=Invalid)
CLMemory Default constructor. Only inherit classes can use this constructor.
Definition: CLMemory.h:68
undocument this line if you encounter any issues!
Definition: Any.h:37
CLImage2D * asCLImage2D()
asCLImage2D Casting function to cast to CLImage2D pointer (reinterpret_cast)
Definition: CLMemory.h:131
#define ICLUtils_API
this macros are important for creating dll's
Definition: CompatMacros.h:171
MemoryType
Memorys type available.
Definition: CLMemory.h:56
CLMemory(CLMemory const &other)
CLMemory default copy constructor.
Definition: CLMemory.h:94
CLBuffer * asCLBuffer()
asCLBuffer Casting function to cast to CLBuffer pointer (reinterpret_cast)
Definition: CLMemory.h:121
MemoryType m_type
The memory type of this instance (CLBuffer or CLImage2D)
Definition: CLMemory.h:86
int64_t icl64s
64bit signed integer type for the ICL
Definition: BasicTypes.h:94
Ipp32s icl32s
32bit signed integer type for the ICL
Definition: BasicTypes.h:58
SmartPtr< CLMemory > Ptr
smart pointer to this class type
Definition: CLMemory.h:53
Wrapper for an OpenCL Buffer.
Definition: CLBuffer.h:52
CLMemory & operator=(CLMemory const &other)
operator = default assignment operator
Definition: CLMemory.h:106
std::vector< icl32s > m_dimensions
size of each dimension x,y,z
Definition: CLMemory.h:71
const std::vector< icl32s > getDimensions() const
returns the dimensions (3Dim-std::vector for x,y,z dimensions)
Definition: CLMemory.h:138
Wrapper for an OpenCL Image2D.
Definition: CLImage2D.h:57
Class for an OpenCL Exception associated with buffers.
Definition: CLException.h:63
icl64s m_size
size in total x*y*z
Definition: CLMemory.h:73
The CLMemory class is a base class for CLBuffer and CLImage2D.
Definition: CLMemory.h:48
icl32s m_byte_depth
byte depth of the data type used (e.g. float32 = 4byte)
Definition: CLMemory.h:75
const icl32s getByteDepth() const
returns the bytedepth of the used data type (e.g. float32 = 4byte)
Definition: CLMemory.h:142
const icl64s getSize() const
returns total size of the memory (x*y*z)
Definition: CLMemory.h:140
Specialization of the SmartPtrBase class for Pointers.
Definition: SmartPtr.h:75
virtual ~CLMemory()
Destructor.
Definition: CLMemory.h:115
void setDimensions(icl32s const &x, icl32s const &y, icl32s const &z)
sets the dimensions x,y,z and total size
Definition: CLMemory.h:78
Definition: CLMemory.h:58
Definition: CLMemory.h:57