areaDetector  3-14
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 
28 typedef void *(*MallocFunc_t)(size_t size);
29 typedef void (*FreeFunc_t)(void *ptr);
32 
34 typedef enum
35 {
45 
50 typedef enum
51 {
55  NDBayerBGGR = 3
57 
59 typedef struct NDDimension {
60  size_t size;
61  size_t offset;
67  int binning;
71  int reverse;
76 
78 typedef struct NDArrayInfo {
79  size_t nElements;
81  size_t totalBytes;
85  int xDim;
86  int yDim;
87  int colorDim;
88  size_t xSize;
89  size_t ySize;
90  size_t colorSize;
91  size_t xStride;
92  size_t yStride;
93  size_t colorStride;
95 
100 public:
101  /* Methods */
102  NDArray();
103  NDArray(int ndims, size_t *dims, NDDataType_t dataType, size_t dataSize, void *pData);
104  virtual ~NDArray();
105  int initDimension (NDDimension_t *pDimension, size_t size);
106  static int computeArrayInfo(int ndims, size_t *dims, NDDataType_t dataType, NDArrayInfo *pInfo);
107  int getInfo (NDArrayInfo_t *pInfo);
108  int reserve();
109  int release();
110  int getReferenceCount() const {return referenceCount;}
111  int report(FILE *fp, int details);
112  friend class NDArrayPool;
113 
114 private:
115  ELLNODE node;
116  int referenceCount;
118 public:
121  int uniqueId;
122  double timeStamp;
124  epicsTimeStamp epicsTS;
126  int ndims;
129  size_t dataSize;
131  void *pData;
136  size_t compressedSize;
137 };
138 
139 // This class defines the object that is contained in the std::multilist for sorting NDArrays in the freeList_.
140 // It defines the < operator to use the NDArray::dataSize field as the sort key
141 
142 // We would like to hide this class definition in NDArrayPool.cpp and just forward reference it here.
143 // That works on Visual Studio, and on gcc if instantiating plugins as heap variables with "new", but fails on gcc
144 // if instantiating plugins as automatic variables.
145 //class sortedListElement;
146 
148  public:
149  freeListElement(NDArray *pArray, size_t dataSize) {
150  pArray_ = pArray;
151  dataSize_ = dataSize;}
152  friend bool operator<(const freeListElement& lhs, const freeListElement& rhs) {
153  return (lhs.dataSize_ < rhs.dataSize_);
154  }
156  size_t dataSize_;
157  private:
158  freeListElement(); // Default constructor is private so objects cannot be constructed without arguments
159 };
160 
169 public:
170  NDArrayPool (class asynNDArrayDriver *pDriver, size_t maxMemory);
171  virtual ~NDArrayPool() {}
172  NDArray* alloc(int ndims, size_t *dims, NDDataType_t dataType, size_t dataSize, void *pData);
173  NDArray* copy(NDArray *pIn, NDArray *pOut, bool copyData, bool copyDimensions=true, bool copyDataType=true);
174 
175  int reserve(NDArray *pArray);
176  int release(NDArray *pArray);
177  int convert(NDArray *pIn,
178  NDArray **ppOut,
179  NDDataType_t dataTypeOut,
180  NDDimension_t *outDims);
181  int convert(NDArray *pIn,
182  NDArray **ppOut,
183  NDDataType_t dataTypeOut);
184  int report(FILE *fp, int details);
185  int getNumBuffers();
186  size_t getMaxMemory();
187  size_t getMemorySize();
188  int getNumFree();
189  void emptyFreeList();
190  static void setDefaultFrameMemoryFunctions(MallocFunc_t newMalloc,
191  FreeFunc_t newFree);
192  virtual void* frameMalloc(size_t size);
193  virtual void frameFree(void *ptr);
194 
195 protected:
199  virtual NDArray* createArray();
200  virtual void onAllocateArray(NDArray *pArray);
201  virtual void onReserveArray(NDArray *pArray);
202  virtual void onReleaseArray(NDArray *pArray);
203 
204 private:
205  std::multiset<freeListElement> freeList_;
206  epicsMutexId listLock_;
207  int numBuffers_;
208  size_t maxMemory_;
209  size_t memorySize_;
210  class asynNDArrayDriver *pDriver_;
211 };
212 
213 #endif
#define ADCORE_API
Definition: ADCoreAPI.h:41
NDDataType_t dataType
Definition: ADPylon.cpp:60
NDColorMode_t
Enumeration of color modes for NDArray attribute "colorMode".
Definition: NDArray.h:35
@ NDColorModeBayer
Bayer pattern image, 1 value per pixel but with color filter on detector.
Definition: NDArray.h:37
@ NDColorModeYUV422
YUV image, 4 bytes encodes 2 RGB pixel.
Definition: NDArray.h:42
@ NDColorModeYUV444
YUV image, 3 bytes encodes 1 RGB pixel.
Definition: NDArray.h:41
@ NDColorModeMono
Monochromatic image.
Definition: NDArray.h:36
@ NDColorModeRGB1
RGB image with pixel color interleave, data array is [3, NX, NY].
Definition: NDArray.h:38
@ NDColorModeRGB3
RGB image with plane color interleave, data array is [NX, NY, 3]
Definition: NDArray.h:40
@ NDColorModeYUV411
YUV image, 6 bytes encodes 4 RGB pixels.
Definition: NDArray.h:43
@ NDColorModeRGB2
RGB image with row color interleave, data array is [NX, 3, NY]
Definition: NDArray.h:39
struct NDArrayInfo NDArrayInfo_t
Structure returned by NDArray::getInfo.
struct NDDimension NDDimension_t
Structure defining a dimension of an NDArray.
void(* FreeFunc_t)(void *ptr)
Definition: NDArray.h:29
MallocFunc_t defaultFrameMalloc
Definition: NDArrayPool.cpp:34
#define ND_ARRAY_MAX_DIMS
NDArray.h.
Definition: NDArray.h:26
FreeFunc_t defaultFrameFree
Definition: NDArrayPool.cpp:35
NDBayerPattern_t
Enumeration of Bayer patterns for NDArray attribute "bayerPattern".
Definition: NDArray.h:51
@ NDBayerBGGR
First line BGBG, second line GRGR...
Definition: NDArray.h:55
@ NDBayerGRBG
First line GRGR, second line BGBG...
Definition: NDArray.h:54
@ NDBayerGBRG
First line GBGB, second line RGRG...
Definition: NDArray.h:53
@ NDBayerRGGB
First line RGRG, second line GBGB...
Definition: NDArray.h:52
void *(* MallocFunc_t)(size_t size)
Definition: NDArray.h:28
NDDataType_t
Enumeration of NDArray data types.
Definition: NDAttribute.h:30
N-dimensional array class; each array has a set of dimensions, a data type, pointer to data,...
Definition: NDArray.h:99
epicsTimeStamp epicsTS
The epicsTimeStamp; this is set with pasynManager->updateTimeStamp(), and can come from a user-define...
Definition: NDArray.h:124
int ndims
The number of dimensions in this array; minimum=1.
Definition: NDArray.h:126
int uniqueId
A number that must be unique for all NDArrays produced by a driver after is has started.
Definition: NDArray.h:121
void * pData
Pointer to the array data.
Definition: NDArray.h:131
Codec_t codec
Definition of codec used to compress the data.
Definition: NDArray.h:135
size_t dataSize
Data size for this array; actual amount of memory allocated for *pData, may be more than required to ...
Definition: NDArray.h:129
int getReferenceCount() const
Definition: NDArray.h:110
double timeStamp
The time stamp in seconds for this array; seconds since EPICS epoch (00:00:00 UTC,...
Definition: NDArray.h:122
NDDataType_t dataType
Data type for this array.
Definition: NDArray.h:128
class asynNDArrayDriver * pDriver
The asynNDArrayDriver that created this array.
Definition: NDArray.h:120
size_t compressedSize
Size of the compressed data.
Definition: NDArray.h:136
class NDArrayPool * pNDArrayPool
The NDArrayPool object that created this array.
Definition: NDArray.h:119
NDAttributeList * pAttributeList
Linked list of attributes.
Definition: NDArray.h:134
The NDArrayPool class manages a free list (pool) of NDArray objects.
Definition: NDArray.h:168
virtual ~NDArrayPool()
Definition: NDArray.h:171
NDAttributeList.h.
Definition: NDAttributeList.h:21
This is the class from which NDArray drivers are derived; implements the asynGenericPointer functions...
Definition: asynNDArrayDriver.h:136
Definition: NDArray.h:147
size_t dataSize_
Definition: NDArray.h:156
freeListElement(NDArray *pArray, size_t dataSize)
Definition: NDArray.h:149
NDArray * pArray_
Definition: NDArray.h:155
friend bool operator<(const freeListElement &lhs, const freeListElement &rhs)
Definition: NDArray.h:152
Definition: Codec.h:20
Structure returned by NDArray::getInfo.
Definition: NDArray.h:78
int xDim
The array index which is the X dimension.
Definition: NDArray.h:85
size_t xSize
The X size of the array.
Definition: NDArray.h:88
NDColorMode_t colorMode
The color mode.
Definition: NDArray.h:84
size_t nElements
The total number of elements in the array.
Definition: NDArray.h:79
size_t colorSize
The color size of the array.
Definition: NDArray.h:90
size_t ySize
The Y size of the array.
Definition: NDArray.h:89
size_t yStride
The number of array elements between Y values.
Definition: NDArray.h:92
int colorDim
The array index which is the color dimension.
Definition: NDArray.h:87
size_t xStride
The number of array elements between X values.
Definition: NDArray.h:91
int yDim
The array index which is the Y dimension.
Definition: NDArray.h:86
size_t colorStride
The number of array elements between color values.
Definition: NDArray.h:93
size_t totalBytes
The total number of bytes required to hold the array; this may be less than NDArray::dataSize.
Definition: NDArray.h:81
int bytesPerElement
The number of bytes per element in the array.
Definition: NDArray.h:80
Structure defining a dimension of an NDArray.
Definition: NDArray.h:59
size_t offset
The offset relative to the origin of the original data source (detector, for example).
Definition: NDArray.h:61
int binning
The binning (pixel summation, 1=no binning) relative to original data source (detector,...
Definition: NDArray.h:67
size_t size
The number of elements in this dimension of the array.
Definition: NDArray.h:60
int reverse
The orientation (0=normal, 1=reversed) relative to the original data source (detector,...
Definition: NDArray.h:71