Commit 01d492ba authored by Laurent Claustre's avatar Laurent Claustre

Merge branch '5-support-high-frame-rate' into 'master'

Resolve "Support high frame rate"

Closes #5

See merge request !62
parents e3724b73 5871a737
......@@ -24,21 +24,39 @@
set(NAME "simulator")
set(simu_srcs src/SimulatorFrameBuilder.cpp src/SimulatorCamera.cpp src/SimulatorInterface.cpp
src/SimulatorSyncCtrlObj.cpp src/SimulatorDetInfoCtrlObj.cpp src/SimulatorShutterCtrlObj.cpp)
set(SIMU_SRCS
src/SimulatorFrameBuilder.cpp
src/SimulatorFrameLoader.cpp
src/SimulatorFramePrefetcher.cpp
src/SimulatorCamera.cpp
src/SimulatorInterface.cpp
src/SimulatorSyncCtrlObj.cpp
src/SimulatorDetInfoCtrlObj.cpp
src/SimulatorShutterCtrlObj.cpp
src/SimulatorBinCtrlObj.cpp
)
add_library(lima${NAME} SHARED ${simu_srcs})
file(GLOB_RECURSE SIMU_INCS "${CMAKE_CURRENT_SOURCE_DIR}/include/*.h")
add_library(lima${NAME} SHARED ${SIMU_SRCS} ${SIMU_INCS})
limatools_set_library_soversion(lima${NAME} "VERSION")
target_include_directories(lima${NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
target_link_libraries(lima${NAME} limacore)
if(WIN32)
target_compile_definitions(lima${NAME} PRIVATE LIBSIMULATOR_EXPORTS)
target_compile_definitions(lima${NAME} PRIVATE LIBSIMULATOR_EXPORTS)
endif()
limatools_set_install_libdir(lima${NAME})
find_package(OpenMP)
if (OPENMP_FOUND)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
endif()
if (LIMA_ENABLE_PYTHON)
limatools_run_sip_for_camera(${NAME})
add_custom_command(TARGET lima${NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/python ${CMAKE_BINARY_DIR}/python/Lima/Simulator)
......@@ -46,5 +64,5 @@ if (LIMA_ENABLE_PYTHON)
endif()
if(LIMA_ENABLE_TESTS)
add_subdirectory(test)
add_subdirectory(test)
endif()
//###########################################################################
// This file is part of LImA, a Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//###########################################################################
#ifndef SIMUBINCTRLOBJ_H
#define SIMUBINCTRLOBJ_H
#include "lima/HwInterface.h"
#include "SimulatorCompatibility.h"
namespace lima
{
// Forward definitions
class HwInterface;
namespace Simulator
{
class Camera;
/// Control object providing simulator binning interface
class LIBSIMULATOR_API BinCtrlObj : public HwBinCtrlObj
{
public:
BinCtrlObj(Camera& simu) : m_simu(simu) {}
virtual void setBin(const Bin& bin);
virtual void getBin(Bin& bin);
virtual void checkBin(Bin& bin);
private:
Camera& m_simu;
};
} //namespace Simulator
} //namespace lima
#endif // SIMUBINCTRLOBJ_H
......@@ -22,12 +22,14 @@
#ifndef SIMULATOR_H
#define SIMULATOR_H
#include <ostream>
#include "lima/HwInterface.h"
#include "lima/HwBufferMgr.h"
#include "SimulatorFrameBuilder.h"
#include "lima/ThreadUtils.h"
#include "lima/SizeUtils.h"
#include <ostream>
#include "SimulatorCompatibility.h"
namespace lima
{
......@@ -35,20 +37,53 @@ namespace lima
namespace Simulator
{
// Forward definitions
struct FrameGetter;
class FrameBuilder;
class FrameLoader;
template <typename FrameGetter>
class FramePrefetcher;
class LIBSIMULATOR_API Camera
{
DEB_CLASS_NAMESPC(DebModCamera, "Camera", "Simulator");
DEB_CLASS_NAMESPC(DebModCamera, "Camera", "Simulator");
public:
Camera();
enum Mode {
MODE_GENERATOR, //<! Generate frames using a super smart multi-gaussian algorithm in realtime (default)
MODE_GENERATOR_PREFETCH, //<! Prebuild frames using a super smart multi-gaussian algorithm
MODE_LOADER, //<! Load frames from files in realtime
MODE_LOADER_PREFETCH, //<! Preload frames from files
};
enum SimuShutterMode {
FRAME,
MANUAL
};
static const char* DetectorModel[4];
Camera(const Mode& mode = Mode::MODE_GENERATOR);
~Camera();
HwBufferCtrlObj *getBufferCtrlObj();
FrameBuilder *getFrameBuilder();
HwBufferCtrlObj *getBufferCtrlObj() { return &m_buffer_ctrl_obj; }
FrameGetter* getFrameGetter() { return m_frame_getter; }
FrameBuilder* getFrameBuilder();
FramePrefetcher<FrameBuilder>* getFrameBuilderPrefetched();
FrameLoader* getFrameLoader();
FramePrefetcher<FrameLoader>* getFrameLoaderPrefetched();
/// Returns the detectof model (according to the current mode)
void getDetectorModel(std::string& det_model) const;
void prepareAcq();
void startAcq();
void stopAcq();
void setMode(const Mode& mode);
void getMode(Mode& mode) const { mode = m_mode; }
void setNbFrames(int nb_frames);
void getNbFrames(int& nb_frames);
......@@ -60,25 +95,17 @@ class LIBSIMULATOR_API Camera
void setTrigMode(TrigMode trig_mode) {m_trig_mode = trig_mode;};
void getTrigMode(TrigMode& trig_mode) {trig_mode = m_trig_mode;};
void setBin(const Bin& bin);
void getBin(Bin& bin);
void checkBin(Bin& bin);
void setFrameDim(const FrameDim& frame_dim);
void getFrameDim(FrameDim& frame_dim);
void setFrameDim(const FrameDim& frame_dim);
void getFrameDim(FrameDim& frame_dim);
void getMaxImageSize(Size& max_image_size) const;
HwInterface::StatusType::Basic getStatus();
int getNbAcquiredFrames();
void getMaxImageSize(Size& max_image_size);
void reset();
enum SimuShutterMode {
FRAME,
MANUAL
};
private:
class SimuThread : public CmdThread
{
......@@ -108,20 +135,32 @@ class LIBSIMULATOR_API Camera
virtual void init();
virtual void execCmd(int cmd);
private:
void execPrepareAcq();
void execStartAcq();
Camera* m_simu;
};
friend class SimuThread;
void init();
SoftBufferCtrlObj m_buffer_ctrl_obj;
FrameBuilder m_frame_builder;
void setDefaultProperties();
void constructFrameGetter();
double m_exp_time;
double m_lat_time;
int m_nb_frames;
TrigMode m_trig_mode;
SimuThread m_thread;
TrigMode m_trig_mode;
SoftBufferCtrlObj m_buffer_ctrl_obj;
SimuThread m_thread;
Mode m_mode; //<! The current mode of the simulateur
FrameGetter *m_frame_getter; //<! The current frame getter (according to the mode)
//unsigned int m_nb_prebuilt_frames; //<! In MODE_GENERATOR_PREBUILT mode, the number of frame to prebuilt
//std::string m_file_pattern; //<! In MODE_LOADER mode, the file pattern use to load the frames
//bool m_mis_cb_act; //<! Used by setMaxImageSizeCallbackActive
};
LIBSIMULATOR_API std::ostream& operator <<(std::ostream& os, Camera& simu);
......
......@@ -19,8 +19,10 @@
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//###########################################################################
#ifndef SIMULATORDETINFOCTRLOBJ_H
#define SIMULATORDETINFOCTRLOBJ_H
#include "SimulatorCompatibility.h"
#include "SimulatorCamera.h"
......@@ -28,16 +30,12 @@ namespace lima
{
namespace Simulator
{
/*******************************************************************
* \class DetInfoCtrlObj
* \brief Control object providing simulator detector info interface
*******************************************************************/
/// Control object providing simulator detector info interface
class LIBSIMULATOR_API DetInfoCtrlObj : public HwDetInfoCtrlObj
{
public:
DetInfoCtrlObj(Camera& simu);
virtual ~DetInfoCtrlObj();
DetInfoCtrlObj(Camera& simu) : m_simu(simu) {}
virtual void getMaxImageSize(Size& max_image_size);
virtual void getDetectorImageSize(Size& det_image_size);
......@@ -56,15 +54,11 @@ class LIBSIMULATOR_API DetInfoCtrlObj : public HwDetInfoCtrlObj
HwMaxImageSizeCallback& cb);
private:
class MaxImageSizeCallbackGen: public HwMaxImageSizeCallbackGen
{
protected:
virtual void setMaxImageSizeCallbackActive(bool cb_active);
};
Camera& m_simu;
MaxImageSizeCallbackGen m_mis_cb_gen;
Camera& m_simu;
};
}
}
#endif
} //namespace Simulator
} //namespace lima
#endif //SIMULATORDETINFOCTRLOBJ_H
......@@ -31,39 +31,41 @@
#define FRAMEBUILDER_H
#include <vector>
#include "SimulatorCompatibility.h"
#include "lima/SizeUtils.h"
#include "lima/Exceptions.h"
#include "SimulatorCompatibility.h"
#include "SimulatorFrameGetter.h"
namespace lima {
namespace Simulator {
struct LIBSIMULATOR_API GaussPeak {
double x0, y0; /// The center of the peak
double fwhm; /// Full Width at Half Maximum
double max; /// The maximum value
GaussPeak()
: x0(0), y0(0), fwhm(0)
{max = 0;}
GaussPeak(const GaussPeak& o)
: x0(o.x0), y0(o.y0), fwhm(o.fwhm)
{max = o.max;}
GaussPeak(double x, double y, double w, double m)
: x0(x), y0(y), fwhm(w)
{max = m;}
struct LIBSIMULATOR_API GaussPeak
{
double x0, y0; //<! The center of the peak
double fwhm; //<! Full Width at Half Maximum
double max; //<! The maximum value
GaussPeak() : x0(0), y0(0), fwhm(0), max(0) {}
GaussPeak(const GaussPeak& o) : x0(o.x0), y0(o.y0), fwhm(o.fwhm), max(o.max) {}
GaussPeak(double x, double y, double w, double m) : x0(x), y0(y), fwhm(w), max(m) {}
};
/***************************************************************//**
* @class FrameBuilder
*
* @brief This class configures and generates frames for the Simulator
*
*******************************************************************/
class LIBSIMULATOR_API FrameBuilder {
/// This class configures and generates frames for the Simulator
class LIBSIMULATOR_API FrameBuilder : public FrameGetter
{
DEB_CLASS_NAMESPC(DebModCamera, "FrameBuilder", "Simulator");
public:
static const bool is_thread_safe = true;
static const int max_dim = 1024;
public:
enum FillType {
Gauss, Diffraction,
};
......@@ -78,6 +80,8 @@ class LIBSIMULATOR_API FrameBuilder {
const PeakList &peaks, double grow_factor );
~FrameBuilder();
Camera::Mode getMode() const { return Camera::MODE_GENERATOR; }
void getFrameDim( FrameDim &dim ) const;
void setFrameDim( const FrameDim &dim );
......@@ -116,11 +120,15 @@ class LIBSIMULATOR_API FrameBuilder {
void getDiffractionSpeed( double &sx, double &sy ) const;
void setDiffractionSpeed( const double &sx, const double &sy );
void getNextFrame( unsigned char *ptr ) throw (Exception);
unsigned long getFrameNr();
void resetFrameNr( int frame_nr=0 );
bool getNextFrame( unsigned char *ptr ) throw (Exception);
void prepareAcq() {}
void getMaxImageSize(Size& max_size);
unsigned long getFrameNr() const;
void resetFrameNr(unsigned long frame_nr=0 );
/// Gets the maximum "hardware" image size
void getMaxImageSize(Size& max_size) const { max_size = Size(max_dim, max_dim); }
private:
FrameDim m_frame_dim; /// Generated frame dimensions
......@@ -147,8 +155,8 @@ class LIBSIMULATOR_API FrameBuilder {
void checkValid( const FrameDim &frame_dim, const Bin &bin,
const Roi &roi ) throw(Exception);
void checkPeaks( PeakList const &peaks );
double dataXY( const PeakList &peaks, int x, int y );
double dataDiffract( double x, double y );
double dataXY( const PeakList &peaks, int x, int y ) const;
double dataDiffract( double x, double y ) const;
template <class depth> void fillData( unsigned char *ptr );
PeakList getGaussPeaksFrom3d(double angle);
......@@ -157,9 +165,8 @@ class LIBSIMULATOR_API FrameBuilder {
};
} //namespace Simulator
}
}
} //namespace lima
#endif /* FRAMEBUILDER_H */
//###########################################################################
// This file is part of LImA, a Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//###########################################################################
#ifndef FRAMEGETTER_H
#define FRAMEGETTER_H
#include <lima/SizeUtils.h>
#include "SimulatorCamera.h"
namespace lima {
// Forward definitions
class FrameDim;
class Exception;
namespace Simulator {
/// This interface describes a way to get the next frame buffer
struct FrameGetter {
virtual Camera::Mode getMode() const = 0;
virtual void prepareAcq() = 0;
virtual bool getNextFrame(unsigned char *ptr) throw (Exception) = 0;
virtual unsigned long getFrameNr() const = 0;
virtual void resetFrameNr(unsigned long frame_nr = 0) = 0;
virtual void setFrameDim(const FrameDim& frame_dim) = 0;
virtual void getFrameDim(FrameDim& frame_dim) const = 0;
virtual void getMaxImageSize(Size& max_image_size) const = 0;
};
} //namespace Simulator
} //namespace lima
#endif /* FRAMEGETTER_H */
//###########################################################################
// This file is part of LImA, a Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//###########################################################################
#ifndef FRAMELOADER_H
#define FRAMELOADER_H
#include <string>
#include <fstream>
#include <memory>
#include "lima/Debug.h"
//#include "lima/SizeUtils.h"
//#include "lima/Exceptions.h"
#include "lima/HwInterface.h"
#include "SimulatorCompatibility.h"
#include "SimulatorFrameGetter.h"
namespace lima {
namespace Simulator {
class LIBSIMULATOR_API FrameLoader : public FrameGetter, public HwMaxImageSizeCallbackGen
{
DEB_CLASS_NAMESPC(DebModCamera, "FrameLoader", "Simulator");
public:
static const bool is_thread_safe = false;
FrameLoader() : m_frame_nr(0), m_mis_cb_act(false), m_current_stream(std::make_shared<std::ifstream>()) { }
Camera::Mode getMode() const { return Camera::MODE_LOADER; }
void setFilePattern(const std::string& file_pattern);
void getFilePattern(std::string& file_pattern) const { file_pattern = m_file_pattern; }
bool getNextFrame(unsigned char *ptr) throw (Exception);
void prepareAcq();
unsigned long getFrameNr() const { return m_frame_nr; }
void resetFrameNr(unsigned long frame_nr = 0) { m_frame_nr = frame_nr; }
void setFrameDim(const FrameDim& frame_dim) { LIMA_EXC(CameraPlugin, Error, "setFrameDim not supported with FrameLoader"); }
void getFrameDim(FrameDim& frame_dim) const { frame_dim = m_frame_dim; }
void getMaxImageSize(Size& max_image_size) const { max_image_size = m_frame_dim.getSize(); }
protected:
virtual void setMaxImageSizeCallbackActive(bool cb_active)
{
DEB_MEMBER_FUNCT();
m_mis_cb_act = cb_active;
}
private:
std::string m_file_pattern; //<! The file pattern use to load the frames
typedef std::vector<std::string> files_t;
std::string m_folder; //<! The folder where the files lives
files_t m_files; //<! The filenames that matche the pattern above
files_t::const_iterator m_it_current_file; //<! An iterator to the filename that is currently read
//std::ifstream m_current_stream; //<! The current stream
std::shared_ptr<std::ifstream> m_current_stream; //<! The current stream
unsigned long m_frame_nr;
FrameDim m_frame_dim;
bool m_mis_cb_act; //<! Used by setMaxImageSizeCallbackActive
};
} //namespace Simulator
} //namespace lima
#endif /* FRAMELOADER_H */
//###########################################################################
// This file is part of LImA, a Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//###########################################################################
#ifndef FRAMEPREFETCHER_H
#define FRAMEPREFETCHER_H
#include <sstream>
#include <vector>
#include "lima/SizeUtils.h"
#include "lima/Exceptions.h"
#include "SimulatorCompatibility.h"
#include "SimulatorFrameGetter.h"
namespace lima {
namespace Simulator {
/// A FrameGetter adapter that prefetches a given number of frames in memory from an underlying FrameGetter implementation
template <class FrameGetterImpl>
class FramePrefetcher : public FrameGetterImpl
{
DEB_CLASS_NAMESPC(DebModCamera, "FramePrefetcher", "Simulator");
public:
FramePrefetcher() : m_frame_nr(0) {}
~FramePrefetcher() { cleanupPrebuiltFrames(); }
Camera::Mode getMode() const { return static_cast<Camera::Mode>(FrameGetterImpl::getMode() + 1); }