Commit b060829b authored by Locatelli's avatar Locatelli
Browse files

Implement statistics

parent 5099889a
/*
* 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.
*/
#ifndef GLOBAL_H
#define GLOBAL_H
#include <common/base/BaseTypes.h>
struct Point2DCoord {
float64 x;
float64 y;
};
struct Point3DCoord {
float64 x;
float64 y;
float64 z;
};
struct RectangleCoord {
Point2DCoord p0;
Point2DCoord p1;
};
struct RoiRectangle {
RectangleCoord rect;
float64 sum;
};
struct Stats {
std::string name;
float64 min;
float64 max;
float64 integral;
};
#endif
......@@ -2,6 +2,7 @@ INCLUDES = -I$(top_srcdir)/src -I$(top_srcdir)/../NomadServer/src -I/usr/include
bin_PROGRAMS = ploty2 mplplot test test2 test3
#export QT_SELECT=5
QT = \
view/qt/QtColorMapWidget.cpp \
view/qt/moc_QtColorMapWidget.cpp \
......@@ -11,6 +12,8 @@ QT = \
view/qt/moc_QtPlotWidget.cpp \
view/qt/QtRoiWidget.cpp \
view/qt/moc_QtRoiWidget.cpp \
view/qt/QtStatisticWidget.cpp \
view/qt/moc_QtStatisticWidget.cpp \
view/qt/QtStatusWidget.cpp \
view/qt/moc_QtStatusWidget.cpp \
view/qt/QtToolBar.cpp \
......@@ -59,8 +62,10 @@ MPLCPP = \
view/mpl/MplPlot1D.cpp \
view/mpl/MplPlot2D.cpp \
view/mpl/MplRoi.cpp \
view/mpl/MplStatistics.cpp \
view/mpl/widgets/MplCursor.cpp \
view/mpl/widgets/MplLegend.cpp
view/mpl/widgets/MplLegend.cpp \
view/mpl/widgets/MplRectangleSelector.cpp
JSON = \
json/HttpConnection.cpp \
......
This diff is collapsed.
......@@ -160,15 +160,15 @@ datacontainer::PropertyPlotDataContainer& InterfaceManager::getPropertyPlotDataC
/*
* toDataCoord
*/
vector<float64> InterfaceManager::toDataCoord(float64 x, float64 y, int32 devicePixelRatio) throw (Error) {
return m_PlotWindow->toDataCoord(x, y, devicePixelRatio);
Point3DCoord InterfaceManager::toDataCoord(const Point2DCoord& point, int32 devicePixelRatio) throw (Error) {
return m_PlotWindow->toDataCoord(point, devicePixelRatio);
}
/*
* checkLegendPick
*/
void InterfaceManager::checkLegendPick(float64 x, float64 y) throw (Error) {
m_PlotWindow->checkLegendPick(x , y);
void InterfaceManager::checkLegendPick(const Point2DCoord& point) throw (Error) {
m_PlotWindow->checkLegendPick(point);
}
/*
......@@ -189,6 +189,15 @@ void InterfaceManager::newRoiStart(uint32 id, const std::string& color) throw (E
}
}
/*
* newRoiCancel
*/
void InterfaceManager::newRoiCancel() throw (Error) {
if (m_PropertyPlot) {
m_PropertyPlot->newRoiCancel();
}
}
/*
* modifyRoiStart
*/
......@@ -219,16 +228,16 @@ void InterfaceManager::deleteRoi(uint32 id) throw (Error) {
/*
* showRoiCoord
*/
void InterfaceManager::showRoiCoord(uint32 id, float64 x0, float64 y0, float64 x1, float64 y1) {
void InterfaceManager::showRoiCoord(uint32 id, const RectangleCoord& rect) {
if (m_QtWindow) {
m_QtWindow->showRoiCoord(id, x0, y0, x1, y1);
m_QtWindow->showRoiCoord(id, rect);
}
}
/*
* updateRoi
*/
void InterfaceManager::updateRoi(const std::vector<std::vector<float64>>& rects) {
void InterfaceManager::updateRoi(const std::vector<RoiRectangle>& rects) {
if (m_QtWindow) {
m_QtWindow->updateRoi(rects);
}
......@@ -237,9 +246,9 @@ void InterfaceManager::updateRoi(const std::vector<std::vector<float64>>& rects)
/*
* updateRoi
*/
void InterfaceManager::updateRoi(int32 n, const std::vector<float64>& vect) {
void InterfaceManager::updateRoi(int32 n, const RectangleCoord& rect) {
if (m_QtWindow) {
m_QtWindow->updateRoi(n ,vect);
m_QtWindow->updateRoi(n ,rect);
}
}
......@@ -252,4 +261,35 @@ void InterfaceManager::updateSum(uint32 id, float64 sum) {
}
}
/*
* statistic
*/
void InterfaceManager::statistic(const std::string& color) throw (Error) {
if (m_PropertyPlot) {
m_PropertyPlot->statistic(color);
}
}
/*
* deleteStats
*/
void InterfaceManager::dismissStats() throw (Error) {
if (m_PropertyPlot) {
m_PropertyPlot->dismissStats();
}
}
/*
* showStatsCoord
*/
void InterfaceManager::showStatsCoord(const RectangleCoord& rect) {
vector<Stats> stats;
if (m_PropertyPlot) {
stats = m_PropertyPlot->updateStats(rect);
}
if (m_QtWindow) {
m_QtWindow->showStatsCoord(rect, stats);
}
}
}
......@@ -24,6 +24,7 @@
#include <vector>
#include <map>
#include "Error.h"
#include "Global.h"
namespace plot {
class PlotWindow;
......@@ -162,7 +163,7 @@ public:
* \return The plot coordinates of the mouse pointer
* \throws Error
*/
std::vector<float64> toDataCoord(float64 x, float64 y, int32 devicePixelRatio) throw (Error) ;
Point3DCoord toDataCoord(const Point2DCoord& point, int32 devicePixelRatio) throw (Error) ;
/*!
* \brief Check mouse click if in legend box
......@@ -170,7 +171,7 @@ public:
* \param[in] ymouse The y mouse coordinate
* \throws Error
*/
void checkLegendPick(float64 x, float64 y) throw (Error) ;
void checkLegendPick(const Point2DCoord& point) throw (Error) ;
/*!
* \brief Allow Roi Functionnalities on the Qt interface
......@@ -185,6 +186,12 @@ public:
*/
void newRoiStart(uint32 id, const std::string& color) throw (Error);
/*!
* \brief Cancel of sequence add a roi
* \throws Error
*/
void newRoiCancel() throw (Error);
/*!
* \brief Start of sequence modify a roi
* \param[in] id The id of the roi
......@@ -216,20 +223,20 @@ public:
* \param[in] y1 The y1 roi coordinate
* \throws Error
*/
void showRoiCoord(uint32 id, float64 x0, float64 y0, float64 x1, float64 y1);
void showRoiCoord(uint32 id, const RectangleCoord& rect);
/*!
* \brief Update all roi
* \param[in] rects The roi rectangles coordinates
*/
void updateRoi(const std::vector<std::vector<float64>>& rects);
void updateRoi(const std::vector<RoiRectangle>& rects);
/*!
* \brief Update a roi n
* \param[in] n The roi indice to update
* \param[in] rects The roi rectangles coordinates
*/
void updateRoi(int32 n, const std::vector<float64>& vect);
void updateRoi(int32 n, const RectangleCoord& rect);
/*!
* \brief Update a roi sum n
......@@ -238,6 +245,30 @@ public:
*/
void updateSum(uint32 id, float64 sum);
/*!
* \brief Start of sequence add a roi
* \param[in] color The color of the roi box
* \throws Error
*/
void statistic(const std::string& color) throw (Error);
/*!
* \brief Delete a roi
* \param[in] id The id of the roi
* \throws Error
*/
void dismissStats() throw (Error);
/*!
* \brief Show roi coordinates
* \param[in] x0 The x0 roi coordinate
* \param[in] y0 The x1 roi coordinate
* \param[in] x1 The y0 roi coordinate
* \param[in] y1 The y1 roi coordinate
* \throws Error
*/
void showStatsCoord(const RectangleCoord& rect);
private:
/*!
......
......@@ -91,14 +91,14 @@ void EmptyPlot::aspectRatio(bool state) throw (Error) {
/*
* getLimits
*/
std::vector<float64> EmptyPlot::checkLimits(const std::pair<float64, float64>& coords) throw (Error) {
return vector<float64>{};
Point3DCoord EmptyPlot::checkLimits(const Point2DCoord& coords) throw (Error) {
return Point3DCoord();
}
/*
* checkBoxLegend
*/
void EmptyPlot::checkBoxLegend(float64 xmouse, float64 ymouse) throw (Error) {
void EmptyPlot::checkBoxLegend(const Point2DCoord& coords) throw (Error) {
}
}
......@@ -84,7 +84,7 @@ public:
* \return The coordinates x y z in plot cordinates
* \throws Error
*/
virtual std::vector<float64> checkLimits(const std::pair<float64, float64>& coords) throw (Error) ;
virtual Point3DCoord checkLimits(const Point2DCoord& coords) throw (Error) ;
/*!
* \brief Check mouse if in legend box
......@@ -92,7 +92,7 @@ public:
* \param[in] ymouse The y mouse coordinate
* \throws Error
*/
virtual void checkBoxLegend(float64 xmouse, float64 ymouse) throw (Error) ;
virtual void checkBoxLegend(const Point2DCoord& coords) throw (Error) ;
/*!
* \brief Select currect axis plot which is over the mouse
......@@ -100,7 +100,7 @@ public:
* \param[in] ymouse The y mouse coordinate
* \throws Error
*/
virtual void selectCurrentAxis(float64 xmouse, float64 ymouse) throw (Error) {
virtual void selectCurrentAxis(const Point2DCoord& coords) throw (Error) {
}
......
......@@ -25,6 +25,7 @@
#include <common/base/BaseTypes.h>
#include "Error.h"
#include "Global.h"
#include "PlotType.h"
namespace view {
......@@ -97,7 +98,7 @@ public:
* \return The coordinates x y z in plot cordinates
* \throws Error
*/
virtual std::vector<float64> checkLimits(const std::pair<float64, float64>& coords) throw (Error) = 0;
virtual Point3DCoord checkLimits(const Point2DCoord& coords) throw (Error) = 0;
/*!
* \brief Check mouse if in legend box
......@@ -105,7 +106,7 @@ public:
* \param[in] ymouse The y mouse coordinate
* \throws Error
*/
virtual void checkBoxLegend(float64 xmouse, float64 ymouse) throw (Error) = 0;
virtual void checkBoxLegend(const Point2DCoord& coords) throw (Error) = 0;
/*!
* \brief Select currect axis plot which is over the mouse
......@@ -113,7 +114,7 @@ public:
* \param[in] ymouse The y mouse coordinate
* \throws Error
*/
virtual void selectCurrentAxis(float64 xmouse, float64 ymouse) throw (Error) = 0;
virtual void selectCurrentAxis(const Point2DCoord& coords) throw (Error) = 0;
/*!
* \brief set color map
......@@ -138,7 +139,7 @@ public:
* \return The z value
* \throws Error
*/
virtual float64 getZDataValue(const std::string& axisname, float64& x, float64& y) const throw (Error) {
virtual float64 getZDataValue(const std::string& axisname, const Point2DCoord& point) const throw (Error) {
// No z data by default
return std::nanf("");
}
......
......@@ -288,24 +288,23 @@ void Plot1D::aspectRatio(bool state) throw (Error) {
/*
* getLimits
*/
std::vector<float64> Plot1D::checkLimits(const std::pair<float64, float64>& coords) throw (Error) {
Point3DCoord Plot1D::checkLimits(const Point2DCoord& coords) throw (Error) {
try {
std::pair<float64, float64> xlims(m_MplPlot1D.get_xlim());
std::pair<float64, float64> ylims(m_MplPlot1D.get_ylim());
float64 coordx = coords.first;
float64 coordy = coords.second;
float64 finalx = std::nanf("");
float64 finaly = std::nanf("");
float64 finalz = std::nanf("");
if ((coordx < xlims.first) || (coordx > xlims.second) || (coordy < ylims.first) || (coordy > ylims.second)) {
Point3DCoord point;
point.x = std::nanf("");
point.y = std::nanf("");
point.z = std::nanf("");
if ((coords.x < xlims.first) || (coords.x > xlims.second) || (coords.y < ylims.first) || (coords.y > ylims.second)) {
// no data
}
else {
finalx = coordx;
finaly = coordy;
finalz = getZDataValue("", finalx, finaly);
point.x = coords.x;
point.y = coords.y;
point.z = getZDataValue("", coords);
}
return vector<float64>{finalx, finaly, finalz};
return point;
}
catch(Error& e) {
throw Error("Plot1D", "checkLimits", "Failed to check limits of mouse coordinate in the plot axis");
......@@ -316,9 +315,9 @@ std::vector<float64> Plot1D::checkLimits(const std::pair<float64, float64>& coor
/*
* checkBoxLegend
*/
void Plot1D::checkBoxLegend(float64 xmouse, float64 ymouse) throw (Error) {
void Plot1D::checkBoxLegend(const Point2DCoord& coords) throw (Error) {
try {
m_MplPlot1D.checkBoxLegend(xmouse, ymouse);
m_MplPlot1D.checkBoxLegend(coords);
}
catch(Error& e) {
throw Error("Plot1D", "checkBoxLegend", "Failed to check if the mouse click was into the box legend");
......
......@@ -86,7 +86,7 @@ public:
* \return The coordinates x y z in plot cordinates
* \throws Error
*/
virtual std::vector<float64> checkLimits(const std::pair<float64, float64>& coords) throw (Error) ;
virtual Point3DCoord checkLimits(const Point2DCoord& coords) throw (Error) ;
/*!
* \brief Check mouse if in legend box
......@@ -94,7 +94,7 @@ public:
* \param[in] ymouse The y mouse coordinate
* \throws Error
*/
virtual void checkBoxLegend(float64 xmouse, float64 ymouse) throw (Error) ;
virtual void checkBoxLegend(const Point2DCoord& coords) throw (Error) ;
/*!
* \brief Select currect axis plot which is over the mouse
......@@ -102,7 +102,7 @@ public:
* \param[in] ymouse The y mouse coordinate
* \throws Error
*/
virtual void selectCurrentAxis(float64 xmouse, float64 ymouse) throw (Error) {
virtual void selectCurrentAxis(const Point2DCoord& coords) throw (Error) {
}
......
......@@ -297,18 +297,18 @@ void Plot2D::aspectRatio(bool state) throw (Error) {
/*
* getZDataValue
*/
float64 Plot2D::getZDataValue(const std::string& axisname, float64& x, float64& y) const throw (Error) {
float64 Plot2D::getZDataValue(const std::string& axisname, const Point2DCoord& coords) const throw (Error) {
float64 z = std::nanf("");
if ((x == std::nanf("")) || (y == std::nanf(""))) {
if ((coords.x == std::nanf("")) || (coords.y == std::nanf(""))) {
// Keep nan for z
}
else if (axisname.find(plot::PLOT2D_MAINAXIS_NAME) != string::npos) {
CImg<float64> img(m_dataz.data(), m_datay.size(), m_datax.size());
z = img._atXY(y, x);
z = img._atXY(coords.y, coords.x);
}
else if (axisname.find(plot::PLOT2D_COLORBARAXIS_NAME) != string::npos) {
x = std::nanf("");
y = std::nanf("");
// coords.x = std::nanf("");
// coords.y = std::nanf("");
}
return z;
}
......@@ -344,25 +344,24 @@ void Plot2D::colorLimits(float64 min, float64 max) throw (Error) {
/*
* checkLimits
*/
std::vector<float64> Plot2D::checkLimits(const std::pair<float64, float64>& coords) throw (Error) {
Point3DCoord Plot2D::checkLimits(const Point2DCoord& coords) throw (Error) {
try {
std::pair<float64, float64> xlims(m_MplPlot2D.get_xlim());
std::pair<float64, float64> ylims(m_MplPlot2D.get_ylim());
float64 coordx = coords.first;
float64 coordy = coords.second;
float64 finalx = std::nanf("");
float64 finaly = std::nanf("");
float64 finalz = std::nanf("");
if ((coordx < xlims.first) || (coordx > xlims.second) || (coordy < ylims.first) || (coordy > ylims.second)) {
Point3DCoord point;
point.x = std::nanf("");
point.y = std::nanf("");
point.z = std::nanf("");
if ((coords.x < xlims.first) || (coords.x > xlims.second) || (coords.y < ylims.first) || (coords.y > ylims.second)) {
// no data
}
else {
finalx = coordx;
finaly = coordy;
finalz = getZDataValue(m_CurrentAxis, coordx, coordy);
point.x = coords.x;
point.y = coords.y;
point.z = getZDataValue(m_CurrentAxis, coords);
}
return vector<float64>{finalx, finaly, finalz};
return point;
}
catch(Error& e) {
throw Error("Plot2D", "checkLimits", "Failed to check limits of mouse coordinate in the plot axis");
......@@ -373,9 +372,9 @@ std::vector<float64> Plot2D::checkLimits(const std::pair<float64, float64>& coor
/*
* selectCurrentAxis
*/
void Plot2D::selectCurrentAxis(float64 xmouse, float64 ymouse) throw (Error) {
void Plot2D::selectCurrentAxis(const Point2DCoord& coords) throw (Error) {
try {
m_CurrentAxis = m_MplPlot2D.selectCurrentAxis(xmouse, ymouse);
m_CurrentAxis = m_MplPlot2D.selectCurrentAxis(coords);
} catch(Error& e) {
Error("Plot2D", "selectCurrentAxis", "Failed to set current axis");
}
......@@ -384,7 +383,7 @@ void Plot2D::selectCurrentAxis(float64 xmouse, float64 ymouse) throw (Error) {
/*
* checkBoxLegend
*/
void Plot2D::checkBoxLegend(float64 xmouse, float64 ymouse) throw (Error) {
void Plot2D::checkBoxLegend(const Point2DCoord& coords) throw (Error) {
// Empty
}
......
......@@ -102,7 +102,7 @@ public:
* \return The z value
* \throws Error
*/
virtual float64 getZDataValue(const std::string& axisname, float64& x, float64& y) const throw (Error);
virtual float64 getZDataValue(const std::string& axisname, const Point2DCoord& coords) const throw (Error);
/*!
* \brief Check Limits on plot for actual mouse coordinates
......@@ -110,7 +110,7 @@ public:
* \return The coordinates x y z in plot cordinates
* \throws Error
*/
virtual std::vector<float64> checkLimits(const std::pair<float64, float64>& coords) throw (Error) ;
virtual Point3DCoord checkLimits(const Point2DCoord& coords) throw (Error) ;
/*!
* \brief Check mouse if in legend box
......@@ -118,7 +118,7 @@ public:
* \param[in] ymouse The y mouse coordinate
* \throws Error
*/
virtual void checkBoxLegend(float64 xmouse, float64 ymouse) throw (Error) ;
virtual void checkBoxLegend(const Point2DCoord& coords) throw (Error) ;
/*!
* \brief Select currect axis plot which is over the mouse
......@@ -126,7 +126,7 @@ public:
* \param[in] ymouse The y mouse coordinate
* \throws Error
*/
virtual void selectCurrentAxis(float64 xmouse, float64 ymouse) throw (Error) ;
virtual void selectCurrentAxis(const Point2DCoord& coords) throw (Error) ;
/*!
* \brief Update projection plots
......
......@@ -90,15 +90,14 @@ void PlotHisto::aspectRatio(bool state) throw (Error) {
/*
* getLimits
*/
std::vector<float64> PlotHisto::checkLimits(const std::pair<float64, float64>& coords) throw (Error) {
vector<float64> buf;
return buf;
Point3DCoord PlotHisto::checkLimits(const Point2DCoord& coords) throw (Error) {
return Point3DCoord();
}
/*
* checkBoxLegend
*/
void PlotHisto::checkBoxLegend(float64 xmouse, float64 ymouse) throw (Error) {
void PlotHisto::checkBoxLegend(const Point2DCoord& coords) throw (Error) {
}
}
......@@ -88,7 +88,7 @@ public:
* \return The coordinates x y z in plot cordinates
* \throws Error
*/
virtual std::vector<float64> checkLimits(const std::pair<float64, float64>& coords) throw (Error) ;
virtual Point3DCoord checkLimits(const Point2DCoord& coords) throw (Error) ;
/*!
* \brief Check mouse if in legend box
......@@ -96,7 +96,7 @@ public:
* \param[in] ymouse The y mouse coordinate
* \throws Error
*/
virtual void checkBoxLegend(float64 xmouse, float64 ymouse) throw (Error) ;
virtual void checkBoxLegend(const Point2DCoord& coords) throw (Error) ;
/*!
* \brief Select currect axis plot which is over the mouse
......@@ -104,7 +104,7 @@ public:
* \param[in] ymouse The y mouse coordinate
* \throws Error
*/
virtual void selectCurrentAxis(float64 xmouse, float64 ymouse) throw (Error) {
virtual void selectCurrentAxis(const Point2DCoord& coords) throw (Error) {
}
......