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

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 @@ ...@@ -24,21 +24,39 @@
set(NAME "simulator") set(NAME "simulator")
set(simu_srcs src/SimulatorFrameBuilder.cpp src/SimulatorCamera.cpp src/SimulatorInterface.cpp set(SIMU_SRCS
src/SimulatorSyncCtrlObj.cpp src/SimulatorDetInfoCtrlObj.cpp src/SimulatorShutterCtrlObj.cpp) 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") limatools_set_library_soversion(lima${NAME} "VERSION")
target_include_directories(lima${NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include") target_include_directories(lima${NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
target_link_libraries(lima${NAME} limacore) target_link_libraries(lima${NAME} limacore)
if(WIN32) if(WIN32)
target_compile_definitions(lima${NAME} PRIVATE LIBSIMULATOR_EXPORTS) target_compile_definitions(lima${NAME} PRIVATE LIBSIMULATOR_EXPORTS)
endif() endif()
limatools_set_install_libdir(lima${NAME}) 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) if (LIMA_ENABLE_PYTHON)
limatools_run_sip_for_camera(${NAME}) 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) 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) ...@@ -46,5 +64,5 @@ if (LIMA_ENABLE_PYTHON)
endif() endif()
if(LIMA_ENABLE_TESTS) if(LIMA_ENABLE_TESTS)
add_subdirectory(test) add_subdirectory(test)
endif() 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 @@ ...@@ -22,12 +22,14 @@
#ifndef SIMULATOR_H #ifndef SIMULATOR_H
#define SIMULATOR_H #define SIMULATOR_H
#include <ostream>
#include "lima/HwInterface.h" #include "lima/HwInterface.h"
#include "lima/HwBufferMgr.h" #include "lima/HwBufferMgr.h"
#include "SimulatorFrameBuilder.h"
#include "lima/ThreadUtils.h" #include "lima/ThreadUtils.h"
#include "lima/SizeUtils.h" #include "lima/SizeUtils.h"
#include <ostream>
#include "SimulatorCompatibility.h"
namespace lima namespace lima
{ {
...@@ -35,20 +37,53 @@ namespace lima ...@@ -35,20 +37,53 @@ namespace lima
namespace Simulator namespace Simulator
{ {
// Forward definitions
struct FrameGetter;
class FrameBuilder;
class FrameLoader;
template <typename FrameGetter>
class FramePrefetcher;
class LIBSIMULATOR_API Camera class LIBSIMULATOR_API Camera
{ {
DEB_CLASS_NAMESPC(DebModCamera, "Camera", "Simulator"); DEB_CLASS_NAMESPC(DebModCamera, "Camera", "Simulator");
public: 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(); ~Camera();
HwBufferCtrlObj *getBufferCtrlObj(); HwBufferCtrlObj *getBufferCtrlObj() { return &m_buffer_ctrl_obj; }
FrameBuilder *getFrameBuilder();
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 prepareAcq();
void startAcq(); void startAcq();
void stopAcq(); void stopAcq();
void setMode(const Mode& mode);
void getMode(Mode& mode) const { mode = m_mode; }
void setNbFrames(int nb_frames); void setNbFrames(int nb_frames);
void getNbFrames(int& nb_frames); void getNbFrames(int& nb_frames);
...@@ -60,25 +95,17 @@ class LIBSIMULATOR_API Camera ...@@ -60,25 +95,17 @@ class LIBSIMULATOR_API Camera
void setTrigMode(TrigMode trig_mode) {m_trig_mode = trig_mode;}; void setTrigMode(TrigMode trig_mode) {m_trig_mode = trig_mode;};
void getTrigMode(TrigMode& trig_mode) {trig_mode = m_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(); HwInterface::StatusType::Basic getStatus();
int getNbAcquiredFrames(); int getNbAcquiredFrames();
void getMaxImageSize(Size& max_image_size);
void reset(); void reset();
enum SimuShutterMode {
FRAME,
MANUAL
};
private: private:
class SimuThread : public CmdThread class SimuThread : public CmdThread
{ {
...@@ -108,20 +135,32 @@ class LIBSIMULATOR_API Camera ...@@ -108,20 +135,32 @@ class LIBSIMULATOR_API Camera
virtual void init(); virtual void init();
virtual void execCmd(int cmd); virtual void execCmd(int cmd);
private: private:
void execPrepareAcq();
void execStartAcq(); void execStartAcq();
Camera* m_simu; Camera* m_simu;
}; };
friend class SimuThread; friend class SimuThread;
void init();
SoftBufferCtrlObj m_buffer_ctrl_obj; void setDefaultProperties();
FrameBuilder m_frame_builder; void constructFrameGetter();
double m_exp_time; double m_exp_time;
double m_lat_time; double m_lat_time;
int m_nb_frames; 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); LIBSIMULATOR_API std::ostream& operator <<(std::ostream& os, Camera& simu);
......
...@@ -19,8 +19,10 @@ ...@@ -19,8 +19,10 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>. // along with this program; if not, see <http://www.gnu.org/licenses/>.
//########################################################################### //###########################################################################
#ifndef SIMULATORDETINFOCTRLOBJ_H #ifndef SIMULATORDETINFOCTRLOBJ_H
#define SIMULATORDETINFOCTRLOBJ_H #define SIMULATORDETINFOCTRLOBJ_H
#include "SimulatorCompatibility.h" #include "SimulatorCompatibility.h"
#include "SimulatorCamera.h" #include "SimulatorCamera.h"
...@@ -28,16 +30,12 @@ namespace lima ...@@ -28,16 +30,12 @@ namespace lima
{ {
namespace Simulator 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 class LIBSIMULATOR_API DetInfoCtrlObj : public HwDetInfoCtrlObj
{ {
public: public:
DetInfoCtrlObj(Camera& simu); DetInfoCtrlObj(Camera& simu) : m_simu(simu) {}
virtual ~DetInfoCtrlObj();
virtual void getMaxImageSize(Size& max_image_size); virtual void getMaxImageSize(Size& max_image_size);
virtual void getDetectorImageSize(Size& det_image_size); virtual void getDetectorImageSize(Size& det_image_size);
...@@ -56,15 +54,11 @@ class LIBSIMULATOR_API DetInfoCtrlObj : public HwDetInfoCtrlObj ...@@ -56,15 +54,11 @@ class LIBSIMULATOR_API DetInfoCtrlObj : public HwDetInfoCtrlObj
HwMaxImageSizeCallback& cb); HwMaxImageSizeCallback& cb);
private: private:
class MaxImageSizeCallbackGen: public HwMaxImageSizeCallbackGen Camera& m_simu;
{
protected:
virtual void setMaxImageSizeCallbackActive(bool cb_active);
};
Camera& m_simu;
MaxImageSizeCallbackGen m_mis_cb_gen;
}; };
}
} } //namespace Simulator
#endif
} //namespace lima
#endif //SIMULATORDETINFOCTRLOBJ_H
...@@ -31,39 +31,41 @@ ...@@ -31,39 +31,41 @@
#define FRAMEBUILDER_H #define FRAMEBUILDER_H
#include <vector> #include <vector>
#include "SimulatorCompatibility.h"
#include "lima/SizeUtils.h" #include "lima/SizeUtils.h"
#include "lima/Exceptions.h" #include "lima/Exceptions.h"
#include "SimulatorCompatibility.h"
#include "SimulatorFrameGetter.h"
namespace lima { namespace lima {
namespace Simulator { namespace Simulator {
struct LIBSIMULATOR_API GaussPeak {
double x0, y0; /// The center of the peak struct LIBSIMULATOR_API GaussPeak
double fwhm; /// Full Width at Half Maximum {
double max; /// The maximum value double x0, y0; //<! The center of the peak
GaussPeak() double fwhm; //<! Full Width at Half Maximum
: x0(0), y0(0), fwhm(0) double max; //<! The maximum value
{max = 0;}
GaussPeak(const GaussPeak& o) GaussPeak() : x0(0), y0(0), fwhm(0), max(0) {}
: x0(o.x0), y0(o.y0), fwhm(o.fwhm) GaussPeak(const GaussPeak& o) : x0(o.x0), y0(o.y0), fwhm(o.fwhm), max(o.max) {}
{max = o.max;} GaussPeak(double x, double y, double w, double m) : x0(x), y0(y), fwhm(w), max(m) {}
GaussPeak(double x, double y, double w, double m)
: x0(x), y0(y), fwhm(w)
{max = m;}
}; };
/***************************************************************//** /// This class configures and generates frames for the Simulator
* @class FrameBuilder class LIBSIMULATOR_API FrameBuilder : public FrameGetter
* {
* @brief This class configures and generates frames for the Simulator
* DEB_CLASS_NAMESPC(DebModCamera, "FrameBuilder", "Simulator");
*******************************************************************/
class LIBSIMULATOR_API FrameBuilder { public:
static const bool is_thread_safe = true;
static const int max_dim = 1024;
public:
enum FillType { enum FillType {
Gauss, Diffraction, Gauss, Diffraction,
}; };
...@@ -78,6 +80,8 @@ class LIBSIMULATOR_API FrameBuilder { ...@@ -78,6 +80,8 @@ class LIBSIMULATOR_API FrameBuilder {
const PeakList &peaks, double grow_factor ); const PeakList &peaks, double grow_factor );
~FrameBuilder(); ~FrameBuilder();
Camera::Mode getMode() const { return Camera::MODE_GENERATOR; }
void getFrameDim( FrameDim &dim ) const; void getFrameDim( FrameDim &dim ) const;
void setFrameDim( const FrameDim &dim ); void setFrameDim( const FrameDim &dim );
...@@ -116,11 +120,15 @@ class LIBSIMULATOR_API FrameBuilder { ...@@ -116,11 +120,15 @@ class LIBSIMULATOR_API FrameBuilder {
void getDiffractionSpeed( double &sx, double &sy ) const; void getDiffractionSpeed( double &sx, double &sy ) const;
void setDiffractionSpeed( const double &sx, const double &sy ); void setDiffractionSpeed( const double &sx, const double &sy );
void getNextFrame( unsigned char *ptr ) throw (Exception); bool getNextFrame( unsigned char *ptr ) throw (Exception);
unsigned long getFrameNr(); void prepareAcq() {}
void resetFrameNr( int frame_nr=0 );
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: private:
FrameDim m_frame_dim; /// Generated frame dimensions FrameDim m_frame_dim; /// Generated frame dimensions
...@@ -147,8 +155,8 @@ class LIBSIMULATOR_API FrameBuilder { ...@@ -147,8 +155,8 @@ class LIBSIMULATOR_API FrameBuilder {
void checkValid( const FrameDim &frame_dim, const Bin &bin, void checkValid( const FrameDim &frame_dim, const Bin &bin,
const Roi &roi ) throw(Exception); const Roi &roi ) throw(Exception);
void checkPeaks( PeakList const &peaks ); void checkPeaks( PeakList const &peaks );
double dataXY( const PeakList &peaks, int x, int y ); double dataXY( const PeakList &peaks, int x, int y ) const;
double dataDiffract( double x, double y ); double dataDiffract( double x, double y ) const;
template <class depth> void fillData( unsigned char *ptr ); template <class depth> void fillData( unsigned char *ptr );
PeakList getGaussPeaksFrom3d(double angle); PeakList getGaussPeaksFrom3d(double angle);
...@@ -157,9 +165,8 @@ class LIBSIMULATOR_API FrameBuilder { ...@@ -157,9 +165,8 @@ class LIBSIMULATOR_API FrameBuilder {
}; };
} //namespace Simulator
} } //namespace lima
}
#endif /* FRAMEBUILDER_H */ #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_