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