Commit f4ed0718 authored by papillon's avatar papillon
Browse files

prepare for soft ops



git-svn-id: https://scm.blissgarden.org/svn/lima/trunk@118 45c4679d-1946-429d-baad-37912b19538b
parent 33094906
sub-dirs = software_operation src
sub-dirs = software_operation src test
include ../global.inc
run:
cd test ; simutest
......@@ -9,7 +9,7 @@
namespace lima {
class CtAcquisition {
friend class CtControl;
friend class CtControl;
public:
......
......@@ -2,12 +2,26 @@
#define CTBUFFER_H
#include "Constants.h"
#include "SizeUtils.h"
#include "CtAcquisition.h"
#include "CtImage.h"
#include "HwInterface.h"
#include "HwCap.h"
#include "HwFrameCallback.h"
#include "Data.h"
namespace lima {
class CtBufferFrameCB : public HwFrameCallback
{
public:
CtBufferFrameCB(CtControl *ct): m_ct(ct) {}
protected:
bool newFrameReady(const HwFrameInfoType& frame_info);
private:
CtControl *m_ct;
};
class CtBuffer {
public:
......@@ -34,10 +48,14 @@ class CtBuffer {
void setMaxMemory(short max_memory);
void getMaxMemory(short& max_memory) const;
void setup(CtAcquisition *ct_acq, FrameDim& fdim);
void registerFrameCallback(CtControl *ct);
void unregisterFrameCallback();
void setup(CtControl *ct);
private:
HwBufferCtrlObj *m_hw_buffer;
CtBufferFrameCB *m_frame_cb;
Parameters m_pars;
};
......
#ifndef CTCONTROL_H
#define CTCONTROL_H
#include "ThreadUtils.h"
#include "HwInterface.h"
#include "SoftOpInternalMgr.h"
#include "ThreadUtils.h"
#include "Data.h"
namespace lima {
......@@ -11,9 +14,11 @@ namespace lima {
class CtAcquisition;
class CtImage;
class CtBuffer;
class CtBufferFrameCB;
class CtSaving;
class CtControl {
friend class CtBufferFrameCB;
public:
enum ApplyPolicy {
......@@ -58,7 +63,22 @@ namespace lima {
void reset();
protected:
void newFrameReady(Data& data);
void newFrameToSave(Data& data);
private:
struct SoftOpStage {
SoftOpStage() { reset(); }
void reset();
int getNb() { return internal+ext_link+ext_sink; };
int getNbLink() { return internal+ext_link; };
int internal;
int ext_link;
int ext_sink;
};
HwInterface *m_hw;
mutable Cond m_cond;
ImageStatus m_img_status;
......@@ -67,8 +87,12 @@ namespace lima {
CtImage *m_ct_image;
CtBuffer *m_ct_buffer;
CtDebug *m_ct_debug;
SoftOpInternalMgr *m_op_int;
SoftOpStage m_op_stage;
ApplyPolicy m_policy;
bool m_ready;
bool m_autosave;
};
} // namespace lima
......
......@@ -8,9 +8,9 @@
namespace lima {
class SwBinRoi {
class CtSwBinRoi {
public:
SwBinRoi(Size& size);
CtSwBinRoi(Size& size);
void setMaxSize(Size& size);
void setBin(Bin& bin);
......@@ -40,8 +40,6 @@ class CtImage {
HardAndSoft,
};
// Size, Type, Bin, XY from common
CtImage(HwInterface *hw);
~CtImage();
......@@ -54,7 +52,7 @@ class CtImage {
// --- soft
void getSoft(SwBinRoi *& soft) const;
void getSoft(CtSwBinRoi *& soft) const;
//bool getHard(HwBinRoi *& hard) const;
/* void setHardRoi(Roi roi);
......@@ -77,7 +75,7 @@ class CtImage {
// --- effective
void getRoi(Roi& roi) const;
void setBin(Bin& bin) const;
void getBin(Bin& bin) const;
void reset();
......@@ -92,7 +90,7 @@ class CtImage {
bool m_has_hw_bin, m_has_hw_roi, m_has_hw_flip;
Size m_max_size, m_hw_size, m_sw_size;
ImageType m_img_type;
SwBinRoi *m_sw;
CtSwBinRoi *m_sw;
ImageOpMode m_mode;
// BinRoi m_hw_binroi, m_sw_binroi;
......
......@@ -7,7 +7,6 @@
#include <fstream>
#include "ThreadUtils.h"
#include "CtControl.h"
class Data;
......@@ -78,6 +77,8 @@ namespace lima {
void setSavingMode(SavingMode mode);
void getSavingMode(SavingMode& mode) const;
bool hasAutoSaveMode() { return m_pars.savingMode != Manual; };
void setOverwritePolicy(OverwritePolicy policy);
void getOverwritePolicy(OverwritePolicy& policy) const;
......
......@@ -2,6 +2,40 @@
using namespace lima;
bool CtBufferFrameCB::newFrameReady(const HwFrameInfoType& frame_info)
{
Data fdata;
ImageType ftype;
Size fsize;
ftype= frame_info.frame_dim->getImageType();
switch (ftype) {
case Bpp8:
fdata.type= Data::UINT8; break;
case Bpp10:
case Bpp12:
case Bpp14:
case Bpp16:
fdata.type= Data::UINT16; break;
case Bpp32:
fdata.type= Data::UINT32; break;
}
fsize= frame_info.frame_dim->getSize();
fdata.width= fsize.getWidth();
fdata.height= fsize.getHeight();
fdata.frameNumber= frame_info.acq_frame_nb;
Buffer *fbuf = new Buffer();
fbuf->owner = Buffer::MAPPED;
fbuf->data = frame_info.frame_ptr;
fdata.setBuffer(fbuf);
fbuf->unref();
m_ct->newFrameReady(fdata);
return true;
}
CtBuffer::CtBuffer(HwInterface *hw)
{
if (!hw->getHwCtrlObj(m_hw_buffer))
......@@ -10,6 +44,20 @@ CtBuffer::CtBuffer(HwInterface *hw)
CtBuffer::~CtBuffer()
{
unregisterFrameCallback();
}
void CtBuffer::registerFrameCallback(CtControl *ct) {
m_frame_cb= new CtBufferFrameCB(ct);
m_hw_buffer->registerFrameCallback(*m_frame_cb);
}
void CtBuffer::unregisterFrameCallback() {
if (m_frame_cb != NULL) {
m_hw_buffer->unregisterFrameCallback(*m_frame_cb);
delete m_frame_cb;
m_frame_cb= NULL;
}
}
void CtBuffer::setPars(Parameters pars) {
......@@ -56,13 +104,20 @@ void CtBuffer::getMaxMemory(short& max_memory) const
max_memory= m_pars.maxMemory;
}
void CtBuffer::setup(CtAcquisition *ct_acq, FrameDim& fdim)
void CtBuffer::setup(CtControl *ct)
{
CtAcquisition *acq;
CtImage *img;
AcqMode mode;
FrameDim fdim;
int acq_nframes, acc_nframes, concat_nframes;
ct_acq->getAcqMode(mode);
ct_acq->getAcqNbFrames(acq_nframes);
acq= ct->acquisition();
acq->getAcqMode(mode);
acq->getAcqNbFrames(acq_nframes);
img= ct->image();
img->getHwImageDim(fdim);
switch (mode) {
case Single:
......@@ -70,18 +125,20 @@ void CtBuffer::setup(CtAcquisition *ct_acq, FrameDim& fdim)
concat_nframes= 1;
break;
case Accumulation:
ct_acq->getAccNbFrames(acc_nframes);
acq->getAccNbFrames(acc_nframes);
concat_nframes= 0;
break;
case Concatenation:
acc_nframes= 0;
ct_acq->getConcatNbFrames(concat_nframes);
acq->getConcatNbFrames(concat_nframes);
break;
}
m_hw_buffer->setFrameDim(fdim);
m_hw_buffer->setNbAccFrames(acc_nframes);
m_hw_buffer->setNbConcatFrames(concat_nframes);
m_hw_buffer->setNbBuffers(acq_nframes);
registerFrameCallback(ct);
}
// -----------------
......
#include <string>
#include <sstream>
#include "CtControl.h"
#include "CtSaving.h"
#include "CtAcquisition.h"
......@@ -5,6 +8,9 @@
#include "CtBuffer.h"
#include "CtDebug.h"
#include "PoolThreadMgr.h"
using namespace lima;
CtControl::CtControl(HwInterface *hw) :
......@@ -14,6 +20,8 @@ CtControl::CtControl(HwInterface *hw) :
m_ct_acq= new CtAcquisition(hw);
m_ct_image= new CtImage(hw);
m_ct_buffer= new CtBuffer(hw);
m_ct_saving= new CtSaving(*this);
m_op_int= new SoftOpInternalMgr();
}
CtControl::~CtControl()
......@@ -48,15 +56,20 @@ void CtControl::getApplyPolicy(ApplyPolicy &policy) const
void CtControl::prepareAcq()
{
FrameDim hw_fdim;
m_img_status.reset();
m_ct_debug->trace("prepareAcq", "Apply Acquisition Parameters");
m_ct_acq->apply(m_policy);
m_ct_debug->trace("prepareAcq", "Setup Acquisition Buffers");
m_ct_image->getHwImageDim(hw_fdim);
m_ct_buffer->setup(m_ct_acq, hw_fdim);
m_ct_buffer->setup(this);
m_ct_debug->trace("prepareAcq", "Prepare Hardware for Acquisition");
m_hw->prepareAcq();
// set softtop bin/roi
// set ext op
m_autosave= m_ct_saving->hasAutoSaveMode();
if (!m_autosave)
m_ct_debug->trace("prepareAcq", "No auto save activated");
m_ready= true;
}
......@@ -91,7 +104,49 @@ void CtControl::reset()
{
}
//Struct ImageStatus
void CtControl::newFrameReady(Data& fdata)
{
std::stringstream str;
str << "Frame acq.nb " << fdata.frameNumber << " received";
m_ct_debug->trace("newFrameReady", str.str());
m_img_status.LastImageAcquired= fdata.frameNumber;
TaskMgr mgr= TaskMgr();
mgr.setInputData(fdata);
m_op_int->addTo(mgr, m_op_stage.internal);
// m_ct_extop->addTo(mgr, first_stage, last_link, last_sink);
m_op_stage.ext_link= 0;
m_op_stage.ext_sink= 0;
if (m_op_stage.getNb())
PoolThreadMgr::get().addProcess(&mgr);
if (m_autosave && !m_op_stage.getNbLink())
newFrameToSave(fdata);
}
void CtControl::newFrameToSave(Data& fdata)
{
std::stringstream str;
str << "Add frame acq.nr " << fdata.frameNumber << " to saving";
m_ct_debug->trace("newFrameToSave", str.str());
m_ct_saving->frameReady(fdata);
}
// ----------------------------------------------------------------------------
// Struct SoftOpStage
// ----------------------------------------------------------------------------
void CtControl::SoftOpStage::reset()
{
internal= 0;
ext_link= 0;
ext_sink= 0;
}
// ----------------------------------------------------------------------------
// Struct ImageStatus
// ----------------------------------------------------------------------------
CtControl::ImageStatus::ImageStatus()
{
reset();
......
......@@ -4,16 +4,16 @@
using namespace lima;
// ----------------------------------------------------------------------------
// CLASS SwBinRoi
// CLASS CtSwBinRoi
// ----------------------------------------------------------------------------
SwBinRoi::SwBinRoi(Size& size)
CtSwBinRoi::CtSwBinRoi(Size& size)
: m_size(), m_bin(), m_roi(), m_max_roi()
{
m_max_roi= Roi(Point(0,0), size);
setMaxSize(size);
}
void SwBinRoi::setMaxSize(Size& size)
void CtSwBinRoi::setMaxSize(Size& size)
{
m_max_size= size;
m_max_roi.setSize(m_max_size / m_bin);
......@@ -26,7 +26,7 @@ void SwBinRoi::setMaxSize(Size& size)
}
}
void SwBinRoi::setBin(Bin& bin)
void CtSwBinRoi::setBin(Bin& bin)
{
if (bin != m_bin) {
m_roi= m_roi.getUnbinned(m_bin);
......@@ -37,7 +37,7 @@ void SwBinRoi::setBin(Bin& bin)
}
}
void SwBinRoi::setRoi(Roi& roi)
void CtSwBinRoi::setRoi(Roi& roi)
{
if (roi != m_roi) {
if (m_max_roi.containsRoi(roi)) {
......@@ -49,7 +49,7 @@ void SwBinRoi::setRoi(Roi& roi)
}
}
const Size& SwBinRoi::getSize()
const Size& CtSwBinRoi::getSize()
{
if (m_roi.isEmpty())
m_size= m_max_size / m_size;
......@@ -76,7 +76,7 @@ CtImage::CtImage(HwInterface *hw)
m_hw_det->getMaxImageSize(m_max_size);
m_hw_det->getCurrImageType(m_img_type);
m_sw= new SwBinRoi(m_max_size);
m_sw= new CtSwBinRoi(m_max_size);
m_hw_size= m_max_size;
m_sw_size= m_max_size;
......@@ -132,7 +132,7 @@ void CtImage::getHwImageDim(FrameDim& dim) const
dim= FrameDim(m_max_size, m_img_type);
}
void CtImage::getSoft(SwBinRoi *& soft) const
void CtImage::getSoft(CtSwBinRoi *& soft) const
{
soft= m_sw;
}
......
......@@ -2,7 +2,7 @@
#include "CtSaving.h"
#include "TaskMgr.h"
//#include "TaskMgr.h"
#include "SinkTask.h"
using namespace lima;
......
......@@ -5,6 +5,7 @@ SRCS = CtSaving.cpp CtControl.cpp CtAcquisition.cpp CtBuffer.cpp \
CtDebug.cpp CtImage.cpp
INCLUDES = -I../include -I../../common/include -I../../hardware/include \
-I../software_operation/include \
-I../../third-party/Processlib/core/include
CXXFLAGS += $(INCLUDES) -fPIC -Wall -pthread
......
......@@ -7,6 +7,7 @@ simutest-ext-objs = $(lima-objs) $(simu-objs)
INC = -I../include -I../../common/include -I../control/include \
-I../../hardware/include -I../../camera/simulator/include \
-I../software_operation/include \
-I../../third-party/Processlib/core/include
CXXFLAGS += $(INC) -Wall -pthread
......
......@@ -7,34 +7,58 @@
using namespace lima;
using namespace std;
void simulator_test()
void simulator_test(double expo, long nframe)
{
Simulator simu;
HwInterface *hw;
CtControl *ct;
CtAcquisition *acq;
CtControl::ImageStatus img_status;
long frame= -1;
hw= new SimuHwInterface(simu);
ct= new CtControl(hw);
ct->setDebug(0xff);
acq= ct->acquisition();
cout << "ACQ: 0.5 sec / 5 frames" << endl;
cout << "SIMUTEST: " << expo <<" sec / " << nframe << " frames" << endl;
acq->setAcqMode(Single);
acq->setAcqExpoTime(0.5);
acq->setAcqNbFrames(5);
acq->setAcqExpoTime(expo);
acq->setAcqNbFrames(nframe);
ct->prepareAcq();
ct->startAcq();
sleep(2);
cout << "SIMUTEST: acq started" << endl;
while (frame < (nframe-1)) {
usleep(100000);
ct->getImageStatus(img_status);
if (frame!=img_status.LastImageAcquired) {
frame= img_status.LastImageAcquired;
cout << "SIMUTEST: frame nr " << frame << endl;
}
}
cout << "SIMUTEST: acq finished" << endl;
ct->stopAcq();
cout << "SIMUTEST: acq stopped" << endl;
}
int main(int argc, char *argv[])
{
double expo;
long nframe;
if (argc != 3) {
expo= 0.5;
nframe= 5;
} else {
expo= atof(argv[1]);
nframe= atoi(argv[2]);
}
try {
simulator_test();
simulator_test(expo, nframe);
} catch (Exception e) {
cerr << "LIMA Exception:" << e << endl;
}
......
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