Commit 396c934b authored by Alejandro Homs Puron's avatar Alejandro Homs Puron Committed by Samuel Debionne
Browse files

Move test_simulator to Lima generic test application framework

* Add I/O stream serialization operators for Camera::Mode
* Add cam params: mode, nb-prefetched-frames, file-pattern, frame-dim
parent 57e94675
......@@ -178,6 +178,9 @@ private:
SIMULATOR_EXPORT std::ostream &operator<<(std::ostream &os, Camera &simu);
SIMULATOR_EXPORT std::ostream &operator<<(std::ostream &os, Camera::Mode mode);
SIMULATOR_EXPORT std::istream &operator>>(std::istream &is, Camera::Mode &mode);
} // namespace Simulator
} // namespace lima
......
......@@ -539,3 +539,43 @@ std::ostream &lima::Simulator::operator<<(std::ostream &os, Camera &simu)
os << "<status=" << status << ">";
return os;
}
std::ostream &lima::Simulator::operator<<(std::ostream &os, Camera::Mode mode)
{
std::string s;
switch (mode) {
case Camera::MODE_GENERATOR:
s = "GENERATOR";
break;
case Camera::MODE_GENERATOR_PREFETCH:
s = "GENERATOR_PREFETCH";
break;
case Camera::MODE_LOADER:
s = "LOADER";
break;
case Camera::MODE_LOADER_PREFETCH:
s = "LOADER_PREFETCH";
break;
default:
s = "Unknown";
}
os << s;
return os;
}
std::istream &lima::Simulator::operator>>(std::istream &is, Camera::Mode &mode)
{
std::string s;
is >> s;
if (s == "GENERATOR")
mode = Camera::MODE_GENERATOR;
else if (s == "GENERATOR_PREFETCH")
mode = Camera::MODE_GENERATOR_PREFETCH;
else if (s == "LOADER")
mode = Camera::MODE_LOADER;
else if (s == "LOADER_PREFETCH")
mode = Camera::MODE_LOADER_PREFETCH;
else
throw LIMA_HW_EXC(InvalidValue, "Invalid Camera::Mode: ") << s;
return is;
}
......@@ -4,6 +4,12 @@ add_executable(test_edf_parser
target_link_libraries(test_edf_parser PUBLIC limacore)
add_executable(test_simulator
test_simulator.cpp
)
target_link_libraries(test_simulator PUBLIC limacore simulator)
add_test(
NAME basic_test
COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/test.py
......
......@@ -19,90 +19,126 @@
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//###########################################################################
#include "SimulatorInterface.h"
#include "lima/CtControl.h"
#include "lima/CtAcquisition.h"
#include "lima/CtSaving.h"
#include "lima/CtImage.h"
#include <iostream>
#include <unistd.h>
#include "simulator/SimulatorInterface.h"
#include "simulator/SimulatorFrameGetter.h"
#include "simulator/SimulatorFrameLoader.h"
#include "simulator/SimulatorFrameBuilder.h"
#include "simulator/SimulatorFramePrefetcher.h"
#include "lima/CtTestApp.h"
DEB_GLOBAL(DebModTest);
using namespace lima;
using namespace lima::Simulator;
using namespace std;
void simulator_test(double expo, long nframe)
auto MODE_GENERATOR = Camera::MODE_GENERATOR;
auto MODE_GENERATOR_PREFETCH = Camera::MODE_GENERATOR_PREFETCH;
auto MODE_LOADER = Camera::MODE_LOADER;
auto MODE_LOADER_PREFETCH = Camera::MODE_LOADER_PREFETCH;
class TestApp : public CtTestApp
{
DEB_CLASS_NAMESPC(DebModTest, "TestApp", "Simulator");
public:
class Pars : public CtTestApp::Pars
{
DEB_CLASS_NAMESPC(DebModTest, "TestApp::Pars", "Simulator");
public:
Camera::Mode cam_mode{MODE_GENERATOR};
int cam_nb_prefetched_frames{10};
std::string cam_file_pattern{"./data/test_*.edf"};
FrameDim cam_frame_dim;
Pars();
};
TestApp(int argc, char *argv[]) : CtTestApp(argc, argv) {}
protected:
virtual CtTestApp::Pars *getPars();
virtual CtControl *getCtControl();
virtual index_map getIndexMap() { return {}; }
virtual void configureAcq(const index_map& indexes);
AutoPtr<Pars> m_pars;
AutoPtr<Camera> m_cam;
AutoPtr<HwInterface> m_interface;
AutoPtr<CtControl> m_ct;
};
TestApp::Pars::Pars()
{
DEB_CONSTRUCTOR();
#define AddOpt(var, opt, par) \
m_opt_list.insert(MakeOpt(var, "", opt, par))
AddOpt(cam_mode, "--cam-mode", "camera mode");
AddOpt(cam_nb_prefetched_frames, "--cam-nb-prefetched-frames",
"nb prefetched frames");
AddOpt(cam_file_pattern, "--cam-file-pattern", "image file pattern");
AddOpt(cam_frame_dim, "--cam-frame-dim", "generated frame dim");
}
CtTestApp::Pars *TestApp::getPars()
{
Camera simu;
AutoPtr<HwInterface> hw;
AutoPtr<CtControl> ct;
CtAcquisition *acq;
CtSaving *save;
CtImage *image;
CtControl::ImageStatus img_status;
long frame= -1;
hw= new Interface(simu);
ct= new CtControl(hw);
save= ct->saving();
save->setDirectory("./data");
save->setPrefix("test_");
save->setSuffix(".edf");
save->setNextNumber(100);
save->setFormat(CtSaving::EDF);
save->setSavingMode(CtSaving::AutoFrame);
save->setOverwritePolicy(CtSaving::Overwrite);
save->setFramesPerFile(100);
Bin bin(2,2);
image= ct->image();
image->setBin(bin);
cout << "SIMUTEST: " << expo <<" sec / " << nframe << " frames" << endl;
acq= ct->acquisition();
acq->setAcqMode(Single);
acq->setAcqExpoTime(expo);
acq->setAcqNbFrames(nframe);
ct->prepareAcq();
ct->startAcq();
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;
}
m_pars = new Pars();
return m_pars;
}
CtControl *TestApp::getCtControl()
{
DEB_MEMBER_FUNCT();
m_cam = new Camera();
DEB_ALWAYS() << "Camera: " << DEB_VAR1(m_pars->cam_mode);
m_cam->setMode(m_pars->cam_mode);
if ((m_pars->cam_mode == MODE_GENERATOR_PREFETCH) ||
(m_pars->cam_mode == MODE_LOADER_PREFETCH)) {
DEB_ALWAYS() << DEB_VAR1(m_pars->cam_nb_prefetched_frames);
FramePrefetcher<FrameBuilder> *fbp= m_cam->getFrameBuilderPrefetched();
fbp->setNbPrefetchedFrames(m_pars->cam_nb_prefetched_frames);
}
if ((m_pars->cam_mode == MODE_LOADER) ||
(m_pars->cam_mode == MODE_LOADER_PREFETCH)) {
DEB_ALWAYS() << DEB_VAR1(m_pars->cam_file_pattern);
FrameLoader *fl= m_cam->getFrameLoader();
fl->setFilePattern(m_pars->cam_file_pattern);
}
cout << "SIMUTEST: acq finished" << endl;
ct->stopAcq();
cout << "SIMUTEST: acq stopped" << endl;
if (m_pars->cam_frame_dim.isValid())
m_cam->setFrameDim(m_pars->cam_frame_dim);
m_interface = new Interface(*m_cam);
m_ct = new CtControl(m_interface);
return m_ct;
}
void TestApp::configureAcq(const index_map& indexes)
{
DEB_MEMBER_FUNCT();
FrameDim effective_dim;
FrameGetter *fg = m_cam->getFrameGetter();
fg->getEffectiveFrameDim(effective_dim);
DEB_ALWAYS() << DEB_VAR1(effective_dim);
}
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]);
}
DEB_GLOBAL_FUNCT();
try {
simulator_test(expo, nframe);
} catch (Exception e) {
cerr << "LIMA Exception:" << e.getErrMsg() << endl;
TestApp app(argc, argv);
app.run();
} catch (Exception& e) {
DEB_ERROR() << "LIMA Exception:" << e.getErrMsg();
}
return 0;
return 0;
}
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