areaDetector  3-12-1
EPICS areaDetector framework
NDArray.h
Go to the documentation of this file.
1 
12 #ifndef NDArray_H
13 #define NDArray_H
14 
15 #include <set>
16 
17 #include <epicsMutex.h>
18 #include <epicsTime.h>
19 #include <ellLib.h>
20 
21 #include "NDAttribute.h"
22 #include "NDAttributeList.h"
23 #include "Codec.h"
24 
26 #define ND_ARRAY_MAX_DIMS 10
27 
29 typedef enum
30 {
40 
45 typedef enum
46 {
52 
54 typedef struct NDDimension {
55  size_t size;
56  size_t offset;
62  int binning;
66  int reverse;
71 
73 typedef struct NDArrayInfo {
74  size_t nElements;
76  size_t totalBytes;
80  int xDim;
81  int yDim;
82  int colorDim;
83  size_t xSize;
84  size_t ySize;
85  size_t colorSize;
86  size_t xStride;
87  size_t yStride;
88  size_t colorStride;
90 
95 public:
96  /* Methods */
97  NDArray();
98  NDArray(int ndims, size_t *dims, NDDataType_t dataType, size_t dataSize, void *pData);
99  virtual ~NDArray();
100  int initDimension (NDDimension_t *pDimension, size_t size);
101  static int computeArrayInfo(int ndims, size_t *dims, NDDataType_t dataType, NDArrayInfo *pInfo);
102  int getInfo (NDArrayInfo_t *pInfo);
103  int reserve();
104  int release();
105  int getReferenceCount() const {return referenceCount;}
106  int report(FILE *fp, int details);
107  friend class NDArrayPool;
108 
109 private:
110  ELLNODE node;
111  int referenceCount;
113 public:
116  int uniqueId;
117  double timeStamp;
119  epicsTimeStamp epicsTS;
121  int ndims;
124  size_t dataSize;
126  void *pData;
131  size_t compressedSize;
132 };
133 
134 // This class defines the object that is contained in the std::multilist for sorting NDArrays in the freeList_.
135 // It defines the < operator to use the NDArray::dataSize field as the sort key
136 
137 // We would like to hide this class definition in NDArrayPool.cpp and just forward reference it here.
138 // That works on Visual Studio, and on gcc if instantiating plugins as heap variables with "new", but fails on gcc
139 // if instantiating plugins as automatic variables.
140 //class sortedListElement;
141 
143  public:
144  freeListElement(NDArray *pArray, size_t dataSize) {
145  pArray_ = pArray;
146  dataSize_ = dataSize;}
147  friend bool operator<(const freeListElement& lhs, const freeListElement& rhs) {
148  return (lhs.dataSize_ < rhs.dataSize_);
149  }
151  size_t dataSize_;
152  private:
153  freeListElement(); // Default constructor is private so objects cannot be constructed without arguments
154 };
155 
164 public:
165  NDArrayPool (class asynNDArrayDriver *pDriver, size_t maxMemory);
166  virtual ~NDArrayPool() {}
167  NDArray* alloc(int ndims, size_t *dims, NDDataType_t dataType, size_t dataSize, void *pData);
168  NDArray* copy(NDArray *pIn, NDArray *pOut, bool copyData, bool copyDimensions=true, bool copyDataType=true);
169 
170  int reserve(NDArray *pArray);
171  int release(NDArray *pArray);
172  int convert(NDArray *pIn,
173  NDArray **ppOut,
174  NDDataType_t dataTypeOut,
175  NDDimension_t *outDims);
176  int convert(NDArray *pIn,
177  NDArray **ppOut,
178  NDDataType_t dataTypeOut);
179  int report(FILE *fp, int details);
180  int getNumBuffers();
181  size_t getMaxMemory();
182  size_t getMemorySize();
183  int getNumFree();
184  void emptyFreeList();
185 
186 protected:
190  virtual NDArray* createArray();
191  virtual void onAllocateArray(NDArray *pArray);
192  virtual void onReserveArray(NDArray *pArray);
193  virtual void onReleaseArray(NDArray *pArray);
194 
195 private:
196  std::multiset<freeListElement> freeList_;
197  epicsMutexId listLock_;
198  int numBuffers_;
199  size_t maxMemory_;
200  size_t memorySize_;
201  class asynNDArrayDriver *pDriver_;
202 };
203 
204 #endif
RGB image with row color interleave, data array is [NX, 3, NY].
Definition: NDArray.h:34
size_t colorSize
The color size of the array.
Definition: NDArray.h:85
NDDataType_t
Enumeration of NDArray data types.
Definition: NDAttribute.h:29
struct NDDimension NDDimension_t
Structure defining a dimension of an NDArray.
size_t colorStride
The number of array elements between color values.
Definition: NDArray.h:88
YUV image, 6 bytes encodes 4 RGB pixels.
Definition: NDArray.h:38
The NDArrayPool class manages a free list (pool) of NDArray objects.
Definition: NDArray.h:163
First line GBGB, second line RGRG...
Definition: NDArray.h:48
epicsTimeStamp epicsTS
The epicsTimeStamp; this is set with pasynManager->updateTimeStamp(), and can come from a user-define...
Definition: NDArray.h:119
size_t dataSize
Data size for this array; actual amount of memory allocated for *pData, may be more than required to ...
Definition: NDArray.h:124
#define ND_ARRAY_MAX_DIMS
NDArray.h.
Definition: NDArray.h:26
NDColorMode_t colorMode
The color mode.
Definition: NDArray.h:79
size_t xSize
The X size of the array.
Definition: NDArray.h:83
First line RGRG, second line GBGB...
Definition: NDArray.h:47
Structure returned by NDArray::getInfo.
Definition: NDArray.h:73
size_t ySize
The Y size of the array.
Definition: NDArray.h:84
size_t offset
The offset relative to the origin of the original data source (detector, for example).
Definition: NDArray.h:56
RGB image with pixel color interleave, data array is [3, NX, NY].
Definition: NDArray.h:33
int bytesPerElement
The number of bytes per element in the array.
Definition: NDArray.h:75
RGB image with plane color interleave, data array is [NX, NY, 3].
Definition: NDArray.h:35
Codec_t codec
Definition of codec used to compress the data.
Definition: NDArray.h:130
NDDataType_t dataType
Data type for this array.
Definition: NDArray.h:123
friend bool operator<(const freeListElement &lhs, const freeListElement &rhs)
Definition: NDArray.h:147
Structure defining a dimension of an NDArray.
Definition: NDArray.h:54
int uniqueId
A number that must be unique for all NDArrays produced by a driver after is has started.
Definition: NDArray.h:116
size_t size
The number of elements in this dimension of the array.
Definition: NDArray.h:55
int xDim
The array index which is the X dimension.
Definition: NDArray.h:80
struct NDArrayInfo NDArrayInfo_t
Structure returned by NDArray::getInfo.
int ndims
The number of dimensions in this array; minimum=1.
Definition: NDArray.h:121
This is the class from which NDArray drivers are derived; implements the asynGenericPointer functions...
Definition: asynNDArrayDriver.h:132
NDArray * pArray_
Definition: NDArray.h:150
class asynNDArrayDriver * pDriver
The asynNDArrayDriver that created this array.
Definition: NDArray.h:115
Definition: Codec.h:20
NDAttributeList.h.
Definition: NDAttributeList.h:21
NDBayerPattern_t
Enumeration of Bayer patterns for NDArray attribute "bayerPattern".
Definition: NDArray.h:45
NDColorMode_t
Enumeration of color modes for NDArray attribute "colorMode".
Definition: NDArray.h:29
size_t xStride
The number of array elements between X values.
Definition: NDArray.h:86
Bayer pattern image, 1 value per pixel but with color filter on detector.
Definition: NDArray.h:32
size_t nElements
The total number of elements in the array.
Definition: NDArray.h:74
First line GRGR, second line BGBG...
Definition: NDArray.h:49
int binning
The binning (pixel summation, 1=no binning) relative to original data source (detector,...
Definition: NDArray.h:62
void * pData
Pointer to the array data.
Definition: NDArray.h:126
virtual ~NDArrayPool()
Definition: NDArray.h:166
int getReferenceCount() const
Definition: NDArray.h:105
int reverse
The orientation (0=normal, 1=reversed) relative to the original data source (detector,...
Definition: NDArray.h:66
Definition: NDArray.h:142
size_t dataSize_
Definition: NDArray.h:151
size_t yStride
The number of array elements between Y values.
Definition: NDArray.h:87
YUV image, 3 bytes encodes 1 RGB pixel.
Definition: NDArray.h:36
First line BGBG, second line GRGR...
Definition: NDArray.h:50
size_t totalBytes
The total number of bytes required to hold the array; this may be less than NDArray::dataSize.
Definition: NDArray.h:76
N-dimensional array class; each array has a set of dimensions, a data type, pointer to data,...
Definition: NDArray.h:94
#define ADCORE_API
Definition: ADCoreAPI.h:41
class NDArrayPool * pNDArrayPool
The NDArrayPool object that created this array.
Definition: NDArray.h:114
NDAttributeList * pAttributeList
Linked list of attributes.
Definition: NDArray.h:129
double timeStamp
The time stamp in seconds for this array; seconds since EPICS epoch (00:00:00 UTC,...
Definition: NDArray.h:117
freeListElement(NDArray *pArray, size_t dataSize)
Definition: NDArray.h:144
YUV image, 4 bytes encodes 2 RGB pixel.
Definition: NDArray.h:37
int yDim
The array index which is the Y dimension.
Definition: NDArray.h:81
Monochromatic image.
Definition: NDArray.h:31
int colorDim
The array index which is the color dimension.
Definition: NDArray.h:82
size_t compressedSize
Size of the compressed data.
Definition: NDArray.h:131