Commit df508282 authored by Locatelli's avatar Locatelli
Browse files

Add multi-gauss and center of mass statistics

parent 82cfca57
......@@ -44,25 +44,21 @@ struct RoiRectangle {
class Stats {
public:
Stats(const std::string& aName, float64 aMin, float64 aMax, float64 anIntegral) :
name(aName), min(aMin), max(aMax), integral(anIntegral){
}
Stats() {
min = 0;
max = 0;
integral = 0;
}
std::string name;
float64 min;
float64 max;
float64 integral;
};
class FitGaussianStats : public Stats {
class CenterOfMassStats : public Stats {
public:
bool converged;
float64 position;
float64 amplitude;
};
class FitGaussianStats : public CenterOfMassStats {
public:
float64 fwhm;
};
......
This diff is collapsed.
......@@ -94,4 +94,60 @@ analysis::FitDataMessage AnalysisRequesterManager::getSimpleGaussianFitValue(con
return fitData;
}
/*
* getMultiGaussianFitValue
*/
analysis::FitDataMessage AnalysisRequesterManager::getMultiGaussianFitValue(const std::vector<float64>& x, const std::vector<float64>& y) throw (Error) {
analysis::Message message;
message.set_type(analysis::Message::GetFit);
analysis::DataToFitMessage dataToFit;
dataToFit.set_type(analysis::MultiGaussianFit);
for(auto val : x) {
dataToFit.add_xdata(val);
}
for(auto val : y) {
dataToFit.add_ydata(val);
}
std::string part1, part2;
message.SerializeToString(&part1);
dataToFit.SerializeToString(&part2);
m_AnalysisRequester->sendTwoBinaryParts(part1, part2);
std::string responseMessage;
m_AnalysisRequester->receiveBinary(responseMessage);
analysis::FitDataMessage fitData;
fitData.ParseFromString(responseMessage);
return fitData;
}
/*
* getCenterOfMassValue
*/
analysis::FitDataMessage AnalysisRequesterManager::getCenterOfMassValue(const std::vector<float64>& x, const std::vector<float64>& y) throw (Error) {
analysis::Message message;
message.set_type(analysis::Message::GetFit);
analysis::DataToFitMessage dataToFit;
dataToFit.set_type(analysis::CenterOfMass);
for(auto val : x) {
dataToFit.add_xdata(val);
}
for(auto val : y) {
dataToFit.add_ydata(val);
}
std::string part1, part2;
message.SerializeToString(&part1);
dataToFit.SerializeToString(&part2);
m_AnalysisRequester->sendTwoBinaryParts(part1, part2);
std::string responseMessage;
m_AnalysisRequester->receiveBinary(responseMessage);
analysis::FitDataMessage fitData;
fitData.ParseFromString(responseMessage);
return fitData;
}
}
......@@ -60,6 +60,24 @@ public:
*/
analysis::FitDataMessage getSimpleGaussianFitValue(const std::vector<float64>& x, const std::vector<float64>& y) throw (Error);
/*!
* \brief Get multi gaussian fit values
* \param[in] x The data of x to fit
* \param[in] y The data of y to fit
* \return Fit y data and stats values
* \throws Error
*/
analysis::FitDataMessage getMultiGaussianFitValue(const std::vector<float64>& x, const std::vector<float64>& y) throw (Error);
/*!
* \brief Get center of mass values
* \param[in] x The data of x to fit
* \param[in] y The data of y to fit
* \return Fit y data and stats values
* \throws Error
*/
analysis::FitDataMessage getCenterOfMassValue(const std::vector<float64>& x, const std::vector<float64>& y) throw (Error);
private:
/*!
......
......@@ -292,7 +292,6 @@ void InterfaceManager::showStatsCoord(const RectangleCoord& rect) {
}
}
/*
* gaussianFitStatistic
*/
......@@ -303,24 +302,59 @@ void InterfaceManager::gaussianFitStatistic(const std::string& color) throw (Err
}
/*
* dismissGaussianFitStats
* showGaussianFitStatsCoord
*/
void InterfaceManager::showGaussianFitStatsCoord(const RectangleCoord& rect) {
vector<FitGaussianStats> stats;
if (m_PropertyPlot) {
stats = m_PropertyPlot->updateGaussianFitStats(rect);
}
if (m_QtWindow) {
m_QtWindow->showGaussianFitCoord(rect, stats);
}
}
/*
* multiGaussianFitStatistic
*/
void InterfaceManager::dismissGaussianFitStats() throw (Error) {
void InterfaceManager::multiGaussianFitStatistic(const std::string& color) throw (Error) {
if (m_PropertyPlot) {
m_PropertyPlot->dismissGaussianFitStats();
m_PropertyPlot->multiGaussianFitStatistic(color);
}
}
/*
* showGaussianFitStatsCoord
* showMultiGaussianFitStatsCoord
*/
void InterfaceManager::showGaussianFitStatsCoord(const RectangleCoord& rect) {
void InterfaceManager::showMultiGaussianFitStatsCoord(const RectangleCoord& rect) {
vector<FitGaussianStats> stats;
if (m_PropertyPlot) {
stats = m_PropertyPlot->updateGaussianFitStats(rect);
stats = m_PropertyPlot->updateMultiGaussianFitStats(rect);
}
if (m_QtWindow) {
m_QtWindow->showGaussianFitCoord(rect, stats);
m_QtWindow->showMultiGaussianFitCoord(rect, stats);
}
}
/*
* multiGaussianFitStatistic
*/
void InterfaceManager::centerOfMassStatistic(const std::string& color) throw (Error) {
if (m_PropertyPlot) {
m_PropertyPlot->centerOfMassStatistic(color);
}
}
/*
* showMultiGaussianFitStatsCoord
*/
void InterfaceManager::showCenterOfMassStatsCoord(const RectangleCoord& rect) {
vector<CenterOfMassStats> stats;
if (m_PropertyPlot) {
stats = m_PropertyPlot->updateCenterOfMassStats(rect);
}
if (m_QtWindow) {
m_QtWindow->showCenterOfMassCoord(rect, stats);
}
}
......
......@@ -274,17 +274,36 @@ public:
void gaussianFitStatistic(const std::string& color) throw (Error);
/*!
* \brief Dissimiss the gaussian fit a roi
* \param[in] id The id of the roi
* \brief Show fit box coordinates
* \param[in] rect The rectangle coordinate
*/
void showGaussianFitStatsCoord(const RectangleCoord& rect);
/*!
* \brief Show multi gaussian fit
* \param[in] color The color of the fit
* \throws Error
*/
void dismissGaussianFitStats() throw (Error);
void multiGaussianFitStatistic(const std::string& color) throw (Error);
/*!
* \brief Show fit box coordinates
* \param[in] rect The rectangle coordinate
*/
void showGaussianFitStatsCoord(const RectangleCoord& rect);
void showMultiGaussianFitStatsCoord(const RectangleCoord& rect);
/*!
* \brief Show center of mass
* \param[in] color The color of the plot
* \throws Error
*/
void centerOfMassStatistic(const std::string& color) throw (Error);
/*!
* \brief Show fit box coordinates
* \param[in] rect The rectangle coordinate
*/
void showCenterOfMassStatsCoord(const RectangleCoord& rect);
/*!
* \brief Close stats windows
......
......@@ -116,5 +116,22 @@ vector<FitGaussianStats> PropertyEmptyPlot::updateGaussianFitStats(const Rectang
return stats;
}
/*
* updateMultiGaussianFitStats
*/
vector<FitGaussianStats> PropertyEmptyPlot::updateMultiGaussianFitStats(const RectangleCoord& rect) throw (Error) {
vector<FitGaussianStats> stats;
return stats;
}
/*
* updateCenterOfMassStats
*/
vector<CenterOfMassStats> PropertyEmptyPlot::updateCenterOfMassStats(const RectangleCoord& rect) throw (Error) {
vector<CenterOfMassStats> stats;
return stats;
}
}
}
......@@ -73,6 +73,10 @@ public:
virtual std::vector<FitGaussianStats> updateGaussianFitStats(const RectangleCoord& rect) throw (Error);
virtual std::vector<FitGaussianStats> updateMultiGaussianFitStats(const RectangleCoord& rect) throw (Error);
virtual std::vector<CenterOfMassStats> updateCenterOfMassStats(const RectangleCoord& rect) throw (Error);
private:
/*!
......
......@@ -369,11 +369,20 @@ void PropertyPlot::gaussianFitStatistic(const std::string& color) throw (Error)
}
/*
* dismissGaussianFitStats
* multiGaussianFitStatistic
*/
void PropertyPlot::dismissGaussianFitStats() throw (Error) {
void PropertyPlot::multiGaussianFitStatistic(const std::string& color) throw (Error) {
if (m_MplStatistics) {
m_MplStatistics->dismissStats();
m_MplStatistics->statistics(color, view::mpl::MplStatistics::MULTI_GAUSIAN_STATS);
}
}
/*
* centerOfMassStatistic
*/
void PropertyPlot::centerOfMassStatistic(const std::string& color) throw (Error) {
if (m_MplStatistics) {
m_MplStatistics->statistics(color, view::mpl::MplStatistics::CENTER_OF_MASS_STATS);
}
}
......
......@@ -102,7 +102,7 @@ public:
* \brief Dismiss Stats
* \throws Error
*/
void dismissStats() throw (Error);
virtual void dismissStats() throw (Error);
/*!
* \brief Update plot stats for the box rect
......@@ -120,19 +120,42 @@ public:
void gaussianFitStatistic(const std::string& color) throw (Error);
/*!
* \brief Dissimiss the gaussian fit a roi
* \param[in] id The id of the roi
* \brief Update simple gaussian fit stats for the box rect
* \param[in] rect The box coordinates
* \return Simple gaussian fit Stats of the plot in the box
* \throws Error
*/
virtual void dismissGaussianFitStats() throw (Error);
virtual std::vector<FitGaussianStats> updateGaussianFitStats(const RectangleCoord& rect) throw (Error) = 0;
/*!
* \brief Update simple gaussian fit stats for the box rect
* \brief Show multi gaussian fit
* \param[in] color The color of the fit
* \throws Error
*/
void multiGaussianFitStatistic(const std::string& color) throw (Error);
/*!
* \brief Update multi gaussian fit stats for the box rect
* \param[in] rect The box coordinates
* \return Simple gaussian fit Stats of the plot in the box
* \return Multi gaussian fit Stats of the plot in the box
* \throws Error
*/
virtual std::vector<FitGaussianStats> updateGaussianFitStats(const RectangleCoord& rect) throw (Error) = 0;
virtual std::vector<FitGaussianStats> updateMultiGaussianFitStats(const RectangleCoord& rect) throw (Error) = 0;
/*!
* \brief Show center of mass
* \param[in] color The color of the fit
* \throws Error
*/
void centerOfMassStatistic(const std::string& color) throw (Error);
/*!
* \brief Update center of mass stats for the box rect
* \param[in] rect The box coordinates
* \return Center of mass Stats of the plot in the box
* \throws Error
*/
virtual std::vector<CenterOfMassStats> updateCenterOfMassStats(const RectangleCoord& rect) throw (Error) = 0;
protected:
......
......@@ -516,6 +516,15 @@ vector<Stats> PropertyPlot1D::updateStats(const RectangleCoord& rect) throw (Err
return buf;
}
/*
* dismissStats
*/
void PropertyPlot1D::dismissStats() throw (Error) {
m_MplPlot1D.dismissFitPlots();
m_PlotWindow->repaint();
PropertyPlot::dismissStats();
}
/*
* updateGaussianFitStats
*/
......@@ -583,11 +592,134 @@ vector<FitGaussianStats> PropertyPlot1D::updateGaussianFitStats(const RectangleC
}
/*
* dismissGaussianFitStats
* updateMultiGaussianFitStats
*/
void PropertyPlot1D::dismissGaussianFitStats() throw (Error) {
m_MplPlot1D.dismissFitPlots();
m_PlotWindow->repaint();
vector<FitGaussianStats> PropertyPlot1D::updateMultiGaussianFitStats(const RectangleCoord& rect) throw (Error) {
vector<FitGaussianStats> buf;
for (uint32 i = 0; i < m_PlotYIds.size(); ++i) {
if (m_PlotYArrays[i].empty() == false) {
// find x min and max coordinates
int32 minind = 0;
int32 maxind = m_PlotYArrays[i].size() - 1;
if (m_PlotXArrays[i].empty() == false) {
for(uint32 j = 0; j < m_PlotXArrays[i].size();++j) {
if (m_PlotXArrays[i][j] < rect.p0.x) {
minind = j;
}
if (m_PlotXArrays[i][j] > rect.p1.x) {
maxind = j;
break;
}
}
if (minind < 0) {
minind = 0;
}
if (maxind > (m_PlotXArrays[i].size() - 1)) {
maxind = m_PlotXArrays[i].size() - 1;
}
}
else {
minind = (int32) rect.p0.x;
maxind = (int32) rect.p1.x;
if (minind < 0) {
minind = 0;
}
if (maxind > (m_PlotYArrays[i].size() - 1)) {
maxind = m_PlotYArrays[i].size() - 1;
}
}
vector<float64> xfit(m_PlotXArrays[i].begin() + minind, m_PlotXArrays[i].begin() + maxind);
vector<float64> yfit(m_PlotYArrays[i].begin() + minind, m_PlotYArrays[i].begin() + maxind);
FitGaussianStats stats;
stats.name = m_DataCont.keys[i];
analysis::FitDataMessage fitData = AnalysisRequesterManager::getInstance()->getMultiGaussianFitValue(xfit, yfit);
stats.converged = fitData.converged();
if (fitData.converged() == true) {
stats.min = fitData.min();
stats.max = fitData.max();
stats.integral = fitData.integral();
stats.position = fitData.position();
stats.amplitude = fitData.amplitude();
stats.fwhm = fitData.fwhm();
vector<float64> y;
for(auto val : fitData.fitydata()) {
y.push_back(val);
}
m_MplPlot1D.fitPlot(i, xfit, y, "Fit Multi Gaussian", string("#0ef139"), 0.5);
buf.push_back(stats);
}
else {
m_MplPlot1D.dismissFitPlots();
m_PlotWindow->repaint();
}
}
}
return buf;
}
/*
* updateCenterOfMassStats
*/
vector<CenterOfMassStats> PropertyPlot1D::updateCenterOfMassStats(const RectangleCoord& rect) throw (Error) {
vector<CenterOfMassStats> buf;
for (uint32 i = 0; i < m_PlotYIds.size(); ++i) {
if (m_PlotYArrays[i].empty() == false) {
// find x min and max coordinates
int32 minind = 0;
int32 maxind = m_PlotYArrays[i].size() - 1;
if (m_PlotXArrays[i].empty() == false) {
for(uint32 j = 0; j < m_PlotXArrays[i].size();++j) {
if (m_PlotXArrays[i][j] < rect.p0.x) {
minind = j;
}
if (m_PlotXArrays[i][j] > rect.p1.x) {
maxind = j;
break;
}
}
if (minind < 0) {
minind = 0;
}
if (maxind > (m_PlotXArrays[i].size() - 1)) {
maxind = m_PlotXArrays[i].size() - 1;
}
}
else {
minind = (int32) rect.p0.x;
maxind = (int32) rect.p1.x;
if (minind < 0) {
minind = 0;
}
if (maxind > (m_PlotYArrays[i].size() - 1)) {
maxind = m_PlotYArrays[i].size() - 1;
}
}
vector<float64> xfit(m_PlotXArrays[i].begin() + minind, m_PlotXArrays[i].begin() + maxind);
vector<float64> yfit(m_PlotYArrays[i].begin() + minind, m_PlotYArrays[i].begin() + maxind);
CenterOfMassStats stats;
stats.name = m_DataCont.keys[i];
analysis::FitDataMessage fitData = AnalysisRequesterManager::getInstance()->getCenterOfMassValue(xfit, yfit);
stats.converged = fitData.converged();
if (fitData.converged() == true) {
stats.min = fitData.min();
stats.max = fitData.max();
stats.integral = fitData.integral();
stats.position = fitData.position();
stats.amplitude = fitData.amplitude();
vector<float64> y;
for(auto val : fitData.fitydata()) {
y.push_back(val);
}
m_MplPlot1D.fitPlot(i, xfit, y, "Center Of Mass", string("#0ef139"), 0.5);
buf.push_back(stats);
}
else {
m_MplPlot1D.dismissFitPlots();
m_PlotWindow->repaint();
}
}
}
return buf;
}
}
......
......@@ -63,11 +63,10 @@ public:
virtual void update(int32 id);
/*!
* \brief Dissimiss the gaussian fit a roi
* \param[in] id The id of the roi
* \brief Dismiss Stats
* \throws Error
*/
virtual void dismissGaussianFitStats() throw (Error);
virtual void dismissStats() throw (Error);
/*!
* \brief Update plot stats for the box rect
......@@ -85,6 +84,22 @@ public:
*/
virtual std::vector<FitGaussianStats> updateGaussianFitStats(const RectangleCoord& rect) throw (Error);
/*!
* \brief Update multi gaussian fit stats for the box rect
* \param[in] rect The box coordinates
* \return Multi gaussian fit Stats of the plot in the box
* \throws Error
*/
virtual std::vector<FitGaussianStats> updateMultiGaussianFitStats(const RectangleCoord& rect) throw (Error);
/*!
* \brief Update center of mass stats for the box rect
* \param[in] rect The box coordinates
* \return Center of mass Stats of the plot in the box
* \throws Error
*/
virtual std::vector<CenterOfMassStats> updateCenterOfMassStats(const RectangleCoord& rect) throw (Error);
private:
/*!
......
......@@ -344,5 +344,27 @@ std::vector<FitGaussianStats> PropertyPlot2D::updateGaussianFitStats(const Recta
return buf;
}
/*
* updateMultiGaussianFitStats
*/
vector<FitGaussianStats> PropertyPlot2D::updateMultiGaussianFitStats(const RectangleCoord& rect) throw (Error) {
FitGaussianStats stats;
stats.name = m_DataCont.keys[0];
vector<FitGaussianStats> buf;
buf.push_back(stats);
return buf;
}
/*
* updateCenterOfMassStats
*/
vector<CenterOfMassStats> PropertyPlot2D::updateCenterOfMassStats(const RectangleCoord& rect) throw (Error) {
FitGaussianStats stats;
stats.name = m_DataCont.keys[0];
vector<CenterOfMassStats> buf;
buf.push_back(stats);
return buf;
}
}
}
......@@ -82,6 +82,22 @@ public:
*/
virtual std::vector<FitGaussianStats> updateGaussianFitStats(const RectangleCoord& rect) throw (Error);
/*!
* \brief Update multi gaussian fit stats for the box rect
* \param[in] rect The box coordinates
* \return Multi gaussian fit Stats of the plot in the box
* \throws Error
*/
virtual std::vector<FitGaussianStats> updateMultiGaussianFitStats(const RectangleCoord& rect) throw (Error);
/*!
* \brief Update center of mass stats for the box rect
* \param[in] rect The box coordinates
* \return Center of mass Stats of the plot in the box
* \throws Error
*/
virtual std::vector<CenterOfMassStats> updateCenterOfMassStats(const RectangleCoord& rect) throw (Error);
private: