60 #include "QwtFunctionPlot.hh"
70 #include <qwt_curve_fitter.h>
71 #include <qwt_plot_panner.h>
72 #include <qwt_symbol.h>
73 #include <qwt_plot_histogram.h>
75 #include <ACG/Utils/ColorCoder.hh>
87 QwtFunctionPlot::QwtFunctionPlot(QWidget* _parent) :
89 Ui::QwtFunctionPlotBase(),
100 qwtPlot->setAxisTitle(QwtPlot::yLeft,
"count" );
102 plot_zoomer_ =
new QwtPlotZoomer( qwtPlot->canvas());
103 plot_zoomer_->initKeyPattern();
105 QwtPlotPanner *panner =
new QwtPlotPanner( qwtPlot->canvas() );
106 panner->setMouseButton( Qt::MidButton );
109 setAttribute(Qt::WA_DeleteOnClose,
true);
116 void QwtFunctionPlot::setFunction(
const std::vector<double>& _values)
123 void QwtFunctionPlot::replot()
126 const int intervalCount = 100;
128 QVector<QwtIntervalSample> intervals(intervalCount);
129 std::vector< QColor > colors;
131 double realMin = FLT_MAX;
132 double realMax = -FLT_MAX;
134 for (
unsigned int i=0; i < values_.size(); i++) {
135 realMin = std::min(realMin,values_[i]);
136 realMax = std::max(realMax,values_[i]);
139 double pos = realMin;
140 double width = ( realMax - realMin ) / intervalCount;
142 QColor lastColor = Qt::black;
146 for (
int i = 0; i < (int)intervals.size(); i++ )
149 intervals[i] = QwtIntervalSample(0.0,pos, pos + width);
153 const double intervalCenter = pos + (width/2.0);
155 colors.push_back( cCoder.color_qcolor(intervalCenter) );
156 lastColor = colors.back();
161 for ( uint i=0; i < values_.size(); i++)
162 for (
int j = 0; j < (int)intervals.size(); j++ )
163 if ( intervals[j].interval.contains( values_[i] ) ) {
164 intervals[j].value++;
171 for (
int i = 0; i < (int)intervals.size(); i++ )
172 maxCount = std::max(maxCount, intervals[i].value);
175 QwtIntervalSeriesData* data =
new QwtIntervalSeriesData(intervals);
176 histogram_->setData(data);
177 histogram_->setColors(colors);
178 histogram_->attach(qwtPlot);
180 qwtPlot->setAxisScale(QwtPlot::yLeft, 0.0, maxCount);
181 qwtPlot->setAxisScale(QwtPlot::xBottom, realMin, realMax);
184 plot_zoomer_->setZoomBase();
187 if ( min_ > realMin ) {
188 if ( ! clampMinMarker_ ) {
189 clampMinMarker_ =
new QwtPlotMarker();
190 minSymbol_ =
new QwtSymbol(QwtSymbol::VLine);
191 minSymbol_->setColor(cCoder.color_qcolor(std::max(min_,realMin)));
192 minSymbol_->setSize(200,1000);
193 QPen pen = minSymbol_->pen();
195 minSymbol_->setPen(pen);
196 clampMinMarker_->setSymbol(minSymbol_);
197 clampMinMarker_->attach(qwtPlot);
198 clampMinMarker_->show();
202 clampMinMarker_->setXValue(std::max(min_,realMin));
205 if ( clampMinMarker_ ) {
206 clampMinMarker_->detach();
207 delete clampMinMarker_;
213 if ( max_ < realMax ) {
214 if ( ! clampMaxMarker_ ) {
215 clampMaxMarker_ =
new QwtPlotMarker();
216 maxSymbol_ =
new QwtSymbol(QwtSymbol::VLine);
217 maxSymbol_->setColor(cCoder.color_qcolor(std::min(max_,realMax)));
218 maxSymbol_->setSize(200,1000);
219 QPen pen = maxSymbol_->pen();
221 maxSymbol_->setPen(pen);
222 clampMaxMarker_->setSymbol(maxSymbol_);
223 clampMaxMarker_->attach(qwtPlot);
224 clampMaxMarker_->show();
228 clampMaxMarker_->setXValue(std::min(max_,realMax));
231 if ( clampMaxMarker_ ) {
232 clampMaxMarker_->detach();
233 delete clampMaxMarker_;
242 void QwtFunctionPlot::setMinMax(
double _min,
double _max) {
Class for generating nice colors for doubles.