Commit 658f2885 authored by Valentin Valls's avatar Valentin Valls
Browse files

Expose the frame to derivative camera simulator

parent c5016864
......@@ -31,6 +31,7 @@
#include <lima/HwBufferMgr.h>
#include <lima/ThreadUtils.h>
#include <lima/SizeUtils.h>
#include <processlib/Data.h>
#include <simulator_export.h>
......@@ -109,6 +110,8 @@ public:
void setHwMaxImageSizeCallback(HwMaxImageSizeCallback *cbk);
virtual void fillData(Data&);
private:
class SimuThread : public CmdThread {
DEB_CLASS_NAMESPC(DebModCamera, "Camera", "SimuThread");
......
......@@ -97,6 +97,8 @@ public:
void reset();
virtual void fillData(Data&);
SIP_PYOBJECT __repr__() const;
%MethodCode
LIMA_REPR_CODE
......
......@@ -101,6 +101,45 @@ void Camera::SimuThread::execPrepareAcq()
}
}
Data::TYPE dataTypeFromImageType(int imageType)
{
switch(imageType)
{
case ImageType::Bpp8:
return Data::UINT8;
case ImageType::Bpp8S:
return Data::INT8;
case ImageType::Bpp16:
return Data::UINT16;
case ImageType::Bpp16S:
return Data::INT16;
case ImageType::Bpp32:
return Data::UINT32;
case ImageType::Bpp32S:
return Data::INT32;
case ImageType::Bpp32F:
return Data::FLOAT;
case ImageType::Bpp64:
return Data::UINT64;
case ImageType::Bpp64S:
return Data::INT64;
case ImageType::Bpp1:
case ImageType::Bpp4:
case ImageType::Bpp6:
case ImageType::Bpp10:
case ImageType::Bpp10S:
case ImageType::Bpp12:
case ImageType::Bpp12S:
case ImageType::Bpp14:
case ImageType::Bpp14S:
case ImageType::Bpp24:
case ImageType::Bpp24S:
throw LIMA_HW_EXC(InvalidValue, "ImageType unsupported in the simulator");
default:
throw LIMA_HW_EXC(InvalidValue, "ImageType unknown");
}
}
void Camera::SimuThread::execStartAcq()
{
DEB_MEMBER_FUNCT();
......@@ -127,7 +166,7 @@ void Camera::SimuThread::execStartAcq()
setStatus(Readout);
unsigned char *ptr = reinterpret_cast<unsigned char *>(buffer_mgr.getFrameBufferPtr(frame_nb));
FrameDim frame_dim = buffer_mgr.getFrameDim();
DEB_TRACE() << DEB_VAR1(frame_dim);
......@@ -136,6 +175,22 @@ void Camera::SimuThread::execStartAcq()
if (!res)
throw LIMA_HW_EXC(InvalidValue, "Failed to get next frame");
{
Data *data = new Data();
Buffer *buffer = new Buffer();
buffer->data = ptr;
buffer->ref();
data->frameNumber = frame_nb;
data->type = dataTypeFromImageType(frame_dim.getImageType());
data->dimensions.push_back(frame_dim.getSize().getWidth());
data->dimensions.push_back(frame_dim.getSize().getHeight());
data->buffer = buffer;
m_simu->fillData(*data);
delete data;
buffer->data = NULL;
delete buffer;
}
HwFrameInfoType frame_info;
frame_info.acq_frame_nb = frame_nb;
......@@ -190,6 +245,16 @@ void Camera::setDefaultProperties()
m_nb_frames = 1;
}
/**
* Called after the framer builder to fill extra data.
*
* Provides an easy way to create custom simulator
* implemented in Python.
*/
void Camera::fillData(Data&)
{
}
void Camera::constructFrameGetter()
{
DEB_MEMBER_FUNCT();
......
......@@ -13,10 +13,15 @@ pytest test/test.py::test_internal_trigger
"""
import numpy
import time
import logging
from Lima import Core, Simulator
_logger = logging.getLogger(__name__)
class AcquisitionStatusFromImageStatusCallback(Core.CtControl.ImageStatusCallback):
def __init__(self):
super().__init__()
......@@ -195,3 +200,35 @@ def test_custom_pixel_size():
detInfo = hw.getHwCtrlObj(Core.HwCap.DetInfo)
pixelsize = detInfo.getPixelSize()
assert pixelsize == (1e-3, 1e-4)
def test_custom_frame():
process_count = 0
class MyCamera(Simulator.Camera):
def fillData(self, data):
nonlocal process_count
assert data.frameNumber == 0
assert data.buffer.shape == (1024, 1024)
assert data.buffer.dtype == numpy.uint32
# The buffer is writable
data.buffer[0, 0] = 1
data.buffer[-1, -1] = 1
process_count += 1
cam = MyCamera()
hw = Simulator.Interface(cam)
ct = Core.CtControl(hw)
ct.prepareAcq()
ct.startAcq()
for _ in range(20):
if ct.getStatus().AcquisitionStatus != Core.AcqRunning:
break
time.sleep(0.1)
else:
assert False, "Simulator is still running"
assert process_count == 1
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment