27 #ifndef improc_milkImage_hpp
28 #define improc_milkImage_hpp
36 #include <ImageStreamIO/ImageStreamIO.h>
38 #include "../mxException.hpp"
46 template<
typename typeT>
47 struct ImageStructTypeCode;
50 struct ImageStructTypeCode<uint8_t>
52 constexpr
static int TypeCode = _DATATYPE_UINT8;
56 struct ImageStructTypeCode<int8_t>
58 constexpr
static int TypeCode = _DATATYPE_INT8;
62 struct ImageStructTypeCode<char>
64 constexpr
static int TypeCode = _DATATYPE_INT8;
68 struct ImageStructTypeCode<uint16_t>
70 constexpr
static int TypeCode = _DATATYPE_UINT16;
74 struct ImageStructTypeCode<int16_t>
76 constexpr
static int TypeCode = _DATATYPE_INT16;
80 struct ImageStructTypeCode<uint32_t>
82 constexpr
static int TypeCode = _DATATYPE_UINT32;
86 struct ImageStructTypeCode<int32_t>
88 constexpr
static int TypeCode = _DATATYPE_INT32;
92 struct ImageStructTypeCode<uint64_t>
94 constexpr
static int TypeCode = _DATATYPE_UINT64;
97 struct ImageStructTypeCode<int64_t>
99 constexpr
static int TypeCode = _DATATYPE_INT64;
102 struct ImageStructTypeCode<float>
104 constexpr
static int TypeCode = _DATATYPE_FLOAT;
108 struct ImageStructTypeCode<double>
110 constexpr
static int TypeCode = _DATATYPE_DOUBLE;
114 struct ImageStructTypeCode<std::complex<float>>
116 constexpr
static int TypeCode = _DATATYPE_COMPLEX_FLOAT;
120 struct ImageStructTypeCode<std::complex<double>>
122 constexpr
static int TypeCode = _DATATYPE_COMPLEX_DOUBLE;
145 template<
typename _dataT>
158 dataT * m_raw {
nullptr};
176 void open(
const std::string & imname );
182 void create(
const std::string & imname,
233 template<
typename dataT>
238 template<
typename dataT>
244 template<
typename dataT>
249 ImageStreamIO_closeIm(m_image);
256 errno_t rv = ImageStreamIO_openIm(m_image, imname.c_str());
258 if(rv != IMAGESTREAMIO_SUCCESS)
262 throw err::mxException(
"", 0,
"", 0,
"", 0,
"ImageStreamIO_openIm returned an error");
265 if(ImageStructTypeCode<dataT>::TypeCode != m_image->md->datatype)
269 throw std::invalid_argument(
"shmim datatype does not match template type");
273 m_raw = (
dataT*) m_image->array.raw;
274 m_size_0 = m_image->md->size[0];
275 m_size_1 = m_image->md->size[1];
278 template<
typename dataT>
286 ImageStreamIO_closeIm(m_image);
298 errno_t rv = ImageStreamIO_createIm_gpu(m_image, imname.c_str(), 3, imsize, ImageStructTypeCode<dataT>::TypeCode,
299 -1, 1, IMAGE_NB_SEMAPHORE, 0, CIRCULAR_BUFFER | ZAXIS_TEMPORAL, 0);
301 if(rv != IMAGESTREAMIO_SUCCESS)
305 throw err::mxException(
"", 0,
"", 0,
"", 0,
"ImageStreamIO_createIm_gpu returned an error");
308 if(ImageStructTypeCode<dataT>::TypeCode != m_image->md->datatype)
312 throw std::invalid_argument(
"shmim datatype does not match template type");
316 m_raw = (
dataT*) m_image->array.raw;
317 m_size_0 = m_image->md->size[0];
318 m_size_1 = m_image->md->size[1];
322 template<
typename dataT>
325 if(m_image ==
nullptr)
338 template<
typename dataT>
345 template<
typename dataT>
348 if(m_image ==
nullptr)
353 errno_t rv = ImageStreamIO_closeIm(m_image);
357 if(rv != IMAGESTREAMIO_SUCCESS)
throw err::mxException(
"", 0,
"", 0,
"", 0,
"ImageStreamIO_closeIm returned an error");
360 template<
typename dataT>
363 if(m_image ==
nullptr)
368 if( m_raw != (
dataT*) m_image->array.raw ||
369 m_size_0 != m_image->md->size[0] ||
370 m_size_1 != m_image->md->size[1] ||
371 ImageStructTypeCode<dataT>::TypeCode != m_image->md->datatype )
379 template<
typename dataT>
382 if(m_image ==
nullptr)
387 errno_t rv = ImageStreamIO_UpdateIm(m_image);
389 if(rv != IMAGESTREAMIO_SUCCESS)
throw err::mxException(
"", 0,
"", 0,
"", 0,
"ImageStreamIO_closeIm returned an error");
The mxlib exception class.
Class to interface with an ImageStreamIO image in shared memory.
milkImage()
Default c'tor.
uint64_t m_size_1
The size[1] of the image when last opened.
void create(const std::string &imname, uint32_t sz0, uint32_t sz1)
Create and connect to an image, allocating the eigenMap.
IMAGE * m_image
Pointer to the ImageStreamIO IMAGE structure.
_dataT dataT
The data type.
std::string m_name
The image name, from name.im.shm (the .im.shm should not be given).
bool valid()
Checks if the image is connected and is still the same format as when connected.
void reopen()
Reopens the image.
void post()
Update the metadata and post all semaphores.
void open(const std::string &imname)
Open and connect to an image, allocating the eigenMap.
uint64_t m_size_0
The size[0] of the image when last opened.
Tools for using the eigen library for image processing.
Eigen::Map< Eigen::Array< scalarT, -1, -1 > > eigenMap
Definition of the eigenMap type, which is an alias for Eigen::Map<Array>.