Commit 81a8157e authored by Locatelli's avatar Locatelli
Browse files

Add stuff

- First ROI implementation (graphical stuff, missed connection to server
data plot)
- Remove as possible using of pointers: replace by refernce or smart
pointer
parent a14fcb2f
......@@ -2,12 +2,18 @@
* See possible using of CUDA acceleration
* Use async method for filling data vectors for accelerating process
* Create for offscreen empty spies, remove multiplot files at the start of server
* Multiclient options
- no offscreen log, webspy plots
- offscreen plots for spy and multiplot will be regenerated or taken form the nomad server computer
* Multiplot
- Try create a plot with all plots (subplot)
- For PN do something for detecting channel problem (using CPU of mpda_dpp?) or in nomad?
* ROI
* Cut windows
......@@ -17,4 +23,10 @@
- Problem to pass from empty plot to others
- Problem close a plot take a time in cameo, so if restarting a new before finishing previous does not worked
* Multithread:
- Create a poll of thread for doing works
* Does we limits x data for plot 1D (as doing in plot2d)?
* Spy
- Set log activated to offscreen for spy
\ No newline at end of file
icons/roi.png

452 Bytes

INCLUDES = -I$(top_srcdir)/src -I$(top_srcdir)/../NomadServer/src -I/usr/include/python3.5m -I/usr/include/x86_64-linux-gnu/qt5/QtWidgets -I/usr/include/x86_64-linux-gnu/qt5 -I/usr/include/x86_64-linux-gnu/qt5/QtGui -I/usr/include/x86_64-linux-gnu/qt5/QtCore
bin_PROGRAMS = ploty2 mplplot test test2
bin_PROGRAMS = ploty2 mplplot test test2 test3
QT = \
view/qt/QtColorMapWidget.cpp \
......@@ -9,6 +9,8 @@ QT = \
view/qt/moc_QtPlotDataWidget.cpp \
view/qt/QtPlotWidget.cpp \
view/qt/moc_QtPlotWidget.cpp \
view/qt/QtRoiWidget.cpp \
view/qt/moc_QtRoiWidget.cpp \
view/qt/QtStatusWidget.cpp \
view/qt/moc_QtStatusWidget.cpp \
view/qt/QtToolBar.cpp \
......@@ -56,6 +58,7 @@ MPLCPP = \
view/mpl/MplFigure.cpp \
view/mpl/MplPlot1D.cpp \
view/mpl/MplPlot2D.cpp \
view/mpl/MplRoi.cpp \
view/mpl/widgets/MplCursor.cpp \
view/mpl/widgets/MplLegend.cpp
......@@ -151,4 +154,20 @@ test2_LDADD = $(LIBS) $(RM_LIBS) \
$(BOOST_FILESYSTEM_LIB) \
$(BOOST_THREAD_LIB) \
-lm
test3_SOURCES = \
maintest3.cpp \
view/mpl/MplLock.cpp \
tests/Roi.cpp \
tests/mainwindow3.cpp \
tests/moc_mainwindow3.cpp \
tests/ToolBar.cpp
test3_CPPFLAGS = $(RM_CXXFLAGS) -DOFFSCREEN -DTRACEDEBUG
test3_LDFLAGS = $(RM_LDFLAGS)
test3_LDADD = $(LIBS) $(RM_LIBS) \
$(BOOST_SYSTEM_LIB) \
$(BOOST_FILESYSTEM_LIB) \
$(BOOST_THREAD_LIB) \
-lm
\ No newline at end of file
This diff is collapsed.
......@@ -60,37 +60,37 @@ PropertyPlotDataContainer::PropertyPlotDataContainer(const proto::PlotPropertyDa
dataZPropertyTypes[id] = ServerRequesterManager::getInstance()->getPropertyType(id);
}
}
for (float64 id : plotMessage.plottype_id()) {
for (int32 id : plotMessage.plottype_id()) {
plottypeId.push_back(id);
}
for (float64 id : plotMessage.x_id()) {
for (int32 id : plotMessage.x_id()) {
xId.push_back(id);
}
for (float64 id : plotMessage.y_id()) {
for (int32 id : plotMessage.y_id()) {
yId.push_back(id);
}
for (float64 id : plotMessage.channel_id()) {
for (int32 id : plotMessage.channel_id()) {
channelId.push_back(id);
}
for (float64 id : plotMessage.slice_id()) {
for (int32 id : plotMessage.slice_id()) {
sliceId.push_back(id);
}
for (float64 id : plotMessage.max_x_id()) {
for (int32 id : plotMessage.max_x_id()) {
maxXId.push_back(id);
}
for (float64 id : plotMessage.max_y_id()) {
for (int32 id : plotMessage.max_y_id()) {
maxYId.push_back(id);
}
for (float64 id : plotMessage.max_channel_id()) {
for (int32 id : plotMessage.max_channel_id()) {
maxChannelId.push_back(id);
}
for (float64 id : plotMessage.max_slice_id()) {
for (int32 id : plotMessage.max_slice_id()) {
maxSliceId.push_back(id);
}
for (float64 id : plotMessage.xphysical_size_id()) {
for (int32 id : plotMessage.xphysical_size_id()) {
xPhysicalSizeIds.push_back(id);
}
for (float64 id : plotMessage.yphysical_size_id()) {
for (int32 id : plotMessage.yphysical_size_id()) {
yPhysicalSizeIds.push_back(id);
}
for (bool errorbar: plotMessage.error_bars()) {
......
......@@ -39,8 +39,8 @@ using namespace cameo;
using namespace manager;
unique_ptr<application::Instance> nomadserver; //! Instance of nomad server
unique_ptr<application::Subscriber> logsubscriber; //! Subcriber on log publisher of the server
unique_ptr<application::Responder> requesterplot; //! Responder for nomad GUI request
shared_ptr<application::Subscriber> logsubscriber; //! Subcriber on log publisher of the server
shared_ptr<application::Responder> requesterplot; //! Responder for nomad GUI request
/*!
* \brief crash handler method
......@@ -60,7 +60,7 @@ void crash_handler(int32 sig) {
int main(int32 argc, char* argv[]) {
// Need to create Mpl in main thread
view::mpl::Mpl* mpl = new view::mpl::Mpl();
shared_ptr<view::mpl::Mpl> mpl = make_shared<view::mpl::Mpl>();
// Init cameo application
int32 err = EXIT_SUCCESS;
......@@ -86,7 +86,7 @@ int main(int32 argc, char* argv[]) {
}
// create a subscriber to the application applicationName
unique_ptr<application::Requester> requesterdb = application::Requester::create(*nomadserver, "database");
shared_ptr<application::Requester> requesterdb = application::Requester::create(*nomadserver, "database");
if (requesterdb.get() == 0) {
Error("mainplot", "Connection problem on database");
err = EXIT_FAILURE;
......@@ -111,14 +111,14 @@ int main(int32 argc, char* argv[]) {
signal(SIGINT, crash_handler);
// Init the nomad server requester manager
manager::ServerRequesterManager::getInstance()->init(requesterdb.get());
manager::ServerRequesterManager::getInstance()->init(requesterdb);
OffScreenPlotManager::getInstance()->init(mpl);
// Start thread waiting and managing log event
thread serverLogSubscriberThread(bind(&OffScreenPlotManager::loop, OffScreenPlotManager::getInstance(), logsubscriber.get()));
thread serverLogSubscriberThread(bind(&OffScreenPlotManager::loop, OffScreenPlotManager::getInstance(), logsubscriber));
// Start thread waiting and managing nomad gui request
thread plotRequestThread(bind(&manager::RequestDealerManager::loop, manager::RequestDealerManager::getInstance(), requesterplot.get()));
thread plotRequestThread(bind(&manager::RequestDealerManager::loop, manager::RequestDealerManager::getInstance(), requesterplot));
// Set cameo application running
application::This::setRunning();
......@@ -135,7 +135,10 @@ int main(int32 argc, char* argv[]) {
exit:
delete mpl;
mpl.reset();
logsubscriber.reset();
requesterplot.reset();
nomadserver.reset();
// Terminate cameo application
DBGMSG("terminate...");
application::This::terminate();
......
......@@ -34,6 +34,8 @@
#include "Error.h"
#include "tests/Test.h"
#include "view/mpl/Mpl.h"
#include "view/mpl/MplLock.h"
//#include "view/mpl/MplRoi.h"
#include <QApplication>
#include "manager/RequestDealerManager.h"
......@@ -47,9 +49,10 @@ using namespace cameo;
using namespace plot;
unique_ptr<application::Instance> nomadserver; //! Instance of nomad server
unique_ptr<application::Subscriber> datachangesubscriber; //! Subcriber on data change publisher of the server
QApplication* app = nullptr;
PlotWindow* window = nullptr;
shared_ptr<application::Subscriber> datachangesubscriber; //! Subcriber on data change publisher of the server
shared_ptr<QApplication> app;
unique_ptr<PlotWindow> window;
/*!
* \brief crash handler method
......@@ -68,7 +71,7 @@ void crash_handler(int32 sig) {
*/
void us1_signal(int32 sig) {
DBGMSG("receive us1_signal : " << sig);
if (window != nullptr) {
if (window.get() != nullptr) {
window->activateWindow();
}
}
......@@ -88,10 +91,10 @@ int32 main(int32 argc, char* argv[]) {
return EXIT_FAILURE;
}
app = new QApplication(argc, argv);
app = make_shared<QApplication>(argc, argv);
qRegisterMetaType<view::qt::QtUpdateContainer>();
// Create and init the Matplolib module
view::mpl::Mpl* mpl = new view::mpl::Mpl();
shared_ptr<view::mpl::Mpl> mpl = make_shared<view::mpl::Mpl>();
// Init the Mpl Event Manager
manager::mpl::MplEventManager::getInstance()->init(mpl);
......@@ -118,7 +121,7 @@ int32 main(int32 argc, char* argv[]) {
DBGMSG("Created requester " << *datachangesubscriber);
// create a requester on the nomad server database
unique_ptr<application::Requester> requesterdb = application::Requester::create(*nomadserver, "database");
shared_ptr<application::Requester> requesterdb = application::Requester::create(*nomadserver, "database");
if (requesterdb.get() == 0) {
Error("mainplot", "Connection problem on database");
err = EXIT_FAILURE;
......@@ -135,7 +138,7 @@ int32 main(int32 argc, char* argv[]) {
signal(SIGUSR1, us1_signal);
// Init the nomad server requester manager
manager::ServerRequesterManager::getInstance()->init(requesterdb.get());
manager::ServerRequesterManager::getInstance()->init(requesterdb);
// Set cameo application running
application::This::setRunning();
......@@ -175,9 +178,9 @@ int32 main(int32 argc, char* argv[]) {
DBGMSG("plotMessage.datay_ids_size() = " << plotMessage.datay_ids_size());
DBGMSG("plotMessage.dataz_ids_size() = " << plotMessage.dataz_ids_size());
window = new PlotWindow(mpl, plotMessage);
window = make_unique<PlotWindow>(mpl, plotMessage);
try {
window->create(*app, datachangesubscriber.get());
window->create(*app, datachangesubscriber);
window->display();
window->show();
}
......@@ -185,7 +188,7 @@ int32 main(int32 argc, char* argv[]) {
err = EXIT_FAILURE;
}
app->exec();
delete window;
window.reset();
}
}
else {
......@@ -210,8 +213,11 @@ int32 main(int32 argc, char* argv[]) {
exit:
manager::mpl::MplEventManager::resetInstance();
app->quit();
delete app;
delete mpl;
app.reset();
datachangesubscriber.reset();
mpl.reset();
nomadserver.reset();
datachangesubscriber.reset();
// Terminate cameo application
application::This::terminate();
return err;
......
......@@ -56,6 +56,17 @@ namespace bp = boost::python;
//}
//
//
//void onselect(const bp::object& eclick, const bp::object& erelease)
//{
//// std::cout << "not_mem_func !!!!!!" << std::endl;
//// view::mpl::MplRoi::x0 = bp::extract<float64>(eclick.attr("xdata"));
//// view::mpl::MplRoi::y0 = bp::extract<float64>(eclick.attr("ydata"));
//// view::mpl::MplRoi::x1 = bp::extract<float64>(erelease.attr("xdata"));
//// view::mpl::MplRoi::y1 = bp::extract<float64>(erelease.attr("ydata"));
//// if (view::mpl::MplRoi::x0 > view::mpl::MplRoi::x1) swap(view::mpl::MplRoi::x0, view::mpl::MplRoi::x1);
//// if (view::mpl::MplRoi::y0 > view::mpl::MplRoi::y1) swap(view::mpl::MplRoi::y0, view::mpl::MplRoi::y1);
//// DBGMSG("x0 = " << view::mpl::MplRoi::x0 << ", y0 = " << view::mpl::MplRoi::y0 << ", x1 = " << view::mpl::MplRoi::x1 << ", y1 = " << view::mpl::MplRoi::y1);
//}
/*!
......@@ -110,7 +121,7 @@ void SavePlot::stop()
void SavePlot::run() {
try {
unique_ptr<view::mpl::MplFigure> figure(new view::mpl::MplFigure(m_Mpl, false));
unique_ptr<view::mpl::MplFigure> figure(new view::mpl::MplFigure(*m_Mpl, false));
// boost::filesystem::path pbfile = m_Path;
// pbfile /= m_Pbfilename;
// pbfile.replace_extension("pb");
......
......@@ -38,6 +38,9 @@
using namespace std;
//void onselect(const bp::object& eclick, const bp::object& erelease)
//{
//}
/*!
* \brief main program function
......@@ -57,7 +60,7 @@ int main(int32 argc, char* argv[]) {
uint32 i = 0;
while(true) {
DBGMSG("SavePlot::savePlot file : " << m_Pbfilename);
view::mpl::MplFigure* figure = new view::mpl::MplFigure(m_Mpl, false);
view::mpl::MplFigure* figure = new view::mpl::MplFigure(*m_Mpl, false);
DBGMSG("SavePlot::savePlot 2 file : " << m_Pbfilename);
boost::filesystem::path pbfile = m_Path;
pbfile /= m_Pbfilename;
......@@ -97,7 +100,7 @@ int main(int32 argc, char* argv[]) {
// 2D
for (int32 i = 0; i < data.xdata_size(); ++i) {
try {
plot::offscreen::OffScreenPlot2D plot(figure, plotkey.str(), m_Mpl, &data);
plot::offscreen::OffScreenPlot2D plot(*figure, plotkey.str(), *m_Mpl, data);
plot.display();
plot.save(pbfile.parent_path().parent_path().string(), dpi, pad);
} catch (Error& e) {
......@@ -108,7 +111,7 @@ int main(int32 argc, char* argv[]) {
// 1D
for (int32 i = 0; i < data.xdata_size(); ++i) {
try {
plot::offscreen::OffScreenPlot1D plot(figure, plotkey.str(), m_Mpl, &data);
plot::offscreen::OffScreenPlot1D plot(*figure, plotkey.str(), *m_Mpl, data);
plot.display();
plot.save(pbfile.parent_path().parent_path().string(), dpi, pad);
} catch (Error& e) {
......@@ -117,7 +120,7 @@ int main(int32 argc, char* argv[]) {
}
} else {
try {
plot::offscreen::OffScreenEmptyPlot plot(figure, plotkey.str(), m_Mpl, &data);
plot::offscreen::OffScreenEmptyPlot plot(*figure, plotkey.str(), *m_Mpl, data);
plot.display();
plot.save(pbfile.parent_path().parent_path().string(), dpi, pad);
} catch (Error& e) {
......
/*
* Nomad Instrument Control Software
*
* Copyright 2011 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
#include <common/base/BaseTypes.h>
#include <iostream>
#include <random>
#include <algorithm>
#include <boost/python.hpp>
#include <python3.5/Python.h>
#include "tests/mainwindow3.h"
#include "tests/Roi.h"
#include <QApplication>
#include "view/Sip.h"
using namespace std;
namespace bp = boost::python;
void onselect(const bp::object& eclick, const bp::object& erelease)
{
std::cout << "not_mem_func !!!!!!" << std::endl;
Roi::x0 = bp::extract<float64>(eclick.attr("xdata"));
Roi::y0 = bp::extract<float64>(eclick.attr("ydata"));
Roi::x1 = bp::extract<float64>(erelease.attr("xdata"));
Roi::y1 = bp::extract<float64>(erelease.attr("ydata"));
if (Roi::x0 > Roi::x1) swap(Roi::x0, Roi::x1);
if (Roi::y0 > Roi::y1) swap(Roi::y0, Roi::y1);
cout << "x0 = " << Roi::x0 << ", y0 = " << Roi::y0 << ", x1 = " << Roi::x1 << ", y1 = " << Roi::y1 << endl;
}
BOOST_PYTHON_FUNCTION_OVERLOADS(onselect_overloads, onselect, 2, 2);
BOOST_PYTHON_MODULE(overloading)
{
bp::def("onselect", onselect, onselect_overloads());
}
/*!
* \brief main program function
* \return error code
*/
int main(int32 argc, char* argv[]) {
cout << "create Qapplication" << endl;
QApplication* app = new QApplication(argc, argv);
// Initialize the Python interpreter
Py_Initialize();
//
// // Initialize and acquire the global interpreter lock for multi-thread management
// PyEval_InitThreads();
bp::object m_PyPlot;
bp::object m_BackendsModule;
bp::object m_FigureModule;
cout << "import matplotlib" << endl;
// Import the matplotlib module
bp::object matplotlib;
try {
matplotlib = bp::import(bp::str("matplotlib"));
} catch(...) {
cerr << "Error when importing the module matplotlib" << endl;
return EXIT_FAILURE;
}
cout << "import pyplot" << endl;
// Import the pyplot of matplotlib module
try {
m_PyPlot = bp::import(bp::str("matplotlib.pyplot"));
} catch(...) {
cerr << "Error when importing the module matplotlib.pyplot" << endl;
return EXIT_FAILURE;
}
cout << "import figure" << endl;
try {
m_FigureModule = bp::import(bp::str("matplotlib.figure"));
} catch (...) {
cerr << "Error when getting the figure module" << endl;
}
cout << "use qtagg5" << endl;
// Use Qt5Agg for toolbar look and feel
auto args = bp::make_tuple("Qt5Agg");
try {
matplotlib.attr("use")(*args);
} catch(...) {
cerr << "Error when activating QT5Agg" << endl;
}
cout << "import pyqt5" << endl;
// Get Py QT5 for forcine QT5
try {
auto qt5Module = bp::import(bp::str("PyQt5"));
} catch (...) {
cerr << "Error when getting PyQt5" << endl;
}
cout << "import backend" << endl;
// Get matplotlib BackEnd for qt5
try {
m_BackendsModule = bp::import(bp::str("matplotlib.backends.backend_qt5agg"));
} catch (...) {
cerr << "Error when getting Qt5 AGG backend" << endl;
}
bp::object widgetsModule = bp::import(bp::str("matplotlib.widgets"));
bp::object patchesModule = bp::import(bp::str("matplotlib.patches"));
cout << "create figure" << endl;
bp::object m_Figure;
try {
m_Figure = m_FigureModule.attr("Figure")();
} catch (...) {
cerr << "Error when getting figure" << endl;
}
cout << "create FigureCanvas" << endl;
bp::object m_Canvas;
// Get matplotlib BackEnd for qt5
try {
m_Canvas = m_BackendsModule.attr("FigureCanvas")(m_Figure);
} catch (...) {
cerr << "Error when getting backends" << endl;
}
cout << "create subplots" << endl;
bp::object axis;
try {
axis = m_Figure.attr("subplots")();
} catch (...) {
cerr << "Error when executing subplots method" << endl;
}
///////////////////////////////////////////////////////////////////////////////////////
//// Create main image
////
default_random_engine dre;
uniform_real_distribution<float64> rd(100,20000);
vector<float64> data;
uint32 ysize = 256, xsize = 128;
for (uint32 i = 0; i < xsize * ysize; ++i) {
data.push_back(rd(dre));
}
// Create image
boost::python::list array;
for (int32 i = 0; i < ysize; ++i) {
boost::python::list listx;
for (int32 j = 0; j < xsize; ++j) {
listx.append(data.at(i + j * ysize));
}
array.append(listx);
}
bp::object m_AxisImage;
args = bp::make_tuple(array);
bp::dict kwargs;
kwargs["cmap"] = "jet";
kwargs["interpolation"] = "none";
kwargs["aspect"] = "auto";
try {
m_AxisImage = axis.attr("imshow")(*args, **kwargs);
} catch (...) {
throw Error("MplPlot2D", "plot", "Could not created imshow");
}
cout << "create Roi" << endl;
Roi* roi = new Roi(widgetsModule, patchesModule, axis, m_Canvas);
cout << "create MainWindow3" << endl;
unique_ptr<MainWindow3> window(new MainWindow3(view::extract<QWidget>(m_Canvas), roi));
cout << "window show" << endl;
window->show();
cout << "app run" << endl;
app->exec();
window.reset();
delete roi;
cout << "clear bp::object(s)" << endl;
m_AxisImage = bp::object();
axis = bp::object();
m_Canvas = bp::object();
m_Figure = bp::object();
m_PyPlot = bp::object();
m_FigureModule = bp::object();
m_BackendsModule = bp::object();
cout << "Py_Finalize" << endl;
Py_Finalize();
app->quit();
return EXIT_SUCCESS;
}
......@@ -45,14 +45,12 @@ using namespace cameo;
* constructor
*/
OffScreenPlotManager::OffScreenPlotManager() {
m_Mpl = nullptr;
}
/*
* constructor
*/
OffScreenPlotManager::~OffScreenPlotManager() {
delete m_Mpl;
}
/*
......@@ -72,7 +70,7 @@ void OffScreenPlotManager::resetInstance() {
void OffScreenPlotManager::reset() {
}
void OffScreenPlotManager::init(view::mpl::Mpl* mpl) {
void OffScreenPlotManager::init(std::shared_ptr<view::mpl::Mpl> mpl) {
m_Mpl = mpl;
}
......@@ -89,7 +87,7 @@ OffScreenPlotManager* OffScreenPlotManager::getInstance() {
/*
* loop
*/
void OffScreenPlotManager::loop(application::Subscriber* subscriber) {
void OffScreenPlotManager::loop(std::shared_ptr<cameo::application::Subscriber> subscriber) {
// Enable thread using GIL
view::mpl::MplEnableThreads mplenablethreads;
......@@ -103,7 +101,9 @@ void OffScreenPlotManager::loop(application::Subscriber* subscriber) {
notification::ImageDataReady messageImageReady;
try {
messageImageReady.ParseFromString(data2);
// run(messageImageReady.imagename(), messageImageReady.imagepath());
boost::thread td(boost::bind(&OffScreenPlotManager::run, m_Instance, messageImageReady.imagename(), messageImageReady.imagepath()));
td.detach();
// thread td(&OffScreenPlotManager::run, m_Instance, messageImageReady.imagename(), messageImageReady.imagepath());
// addThreadMapElement(m_Mpl, m_CounterId++, messageImageReady.imagename(), messageImageReady.imagepath());
}
......@@ -145,7 +145,7 @@ void OffScreenPlotManager::loop(application::Subscriber* subscriber) {
* OffScreenPlotManager
*/
void OffScreenPlotManager::run(std::string pbfilename, std::string path) {
unique_ptr<view::mpl::MplFigure> figure(new view::mpl::MplFigure(m_Mpl, false));
unique_ptr<view::mpl::MplFigure> figure(new view::mpl::MplFigure(*m_Mpl, false));
boost::filesystem::path pbfile = path;
pbfile /= pbfilename;
pbfile.replace_extension("pb");
......@@ -160,7 +160,7 @@ void OffScreenPlotManager::run(std::string pbfilename, std::string path) {