53 #include "QwtFunctionPlot.hh" 63 #include <qwt_curve_fitter.h> 64 #include <qwt_plot_panner.h> 65 #include <qwt_symbol.h> 66 #include <qwt_plot_histogram.h> 68 #include <ACG/Utils/ColorCoder.hh> 80 QwtFunctionPlot::QwtFunctionPlot(QWidget* _parent) :
82 Ui::QwtFunctionPlotBase(),
93 qwtPlot->setAxisTitle(QwtPlot::yLeft,
"count" );
95 plot_zoomer_ =
new QwtPlotZoomer( qwtPlot->canvas());
96 plot_zoomer_->initKeyPattern();
98 QwtPlotPanner *panner =
new QwtPlotPanner( qwtPlot->canvas() );
99 panner->setMouseButton( Qt::MidButton );
102 setAttribute(Qt::WA_DeleteOnClose,
true);
109 void QwtFunctionPlot::setFunction(
const std::vector<double>& _values)
116 void QwtFunctionPlot::replot()
119 const int intervalCount = 100;
121 QVector<QwtIntervalSample> intervals(intervalCount);
122 std::vector< QColor > colors;
124 double realMin = FLT_MAX;
125 double realMax = -FLT_MAX;
127 for (
unsigned int i=0; i < values_.size(); i++) {
128 realMin = std::min(realMin,values_[i]);
129 realMax = std::max(realMax,values_[i]);
132 double pos = realMin;
133 double width = ( realMax - realMin ) / intervalCount;
135 QColor lastColor = Qt::black;
139 for (
int i = 0; i < (int)intervals.size(); i++ )
142 intervals[i] = QwtIntervalSample(0.0,pos, pos + width);
146 const double intervalCenter = pos + (width/2.0);
148 colors.push_back( cCoder.color_qcolor(intervalCenter) );
149 lastColor = colors.back();
154 for ( uint i=0; i < values_.size(); i++)
155 for (
int j = 0; j < (int)intervals.size(); j++ )
156 if ( intervals[j].interval.contains( values_[i] ) ) {
157 intervals[j].value++;
164 for (
int i = 0; i < (int)intervals.size(); i++ )
165 maxCount = std::max(maxCount, intervals[i].value);
168 QwtIntervalSeriesData* data =
new QwtIntervalSeriesData(intervals);
169 histogram_->setData(data);
170 histogram_->setColors(colors);
171 histogram_->attach(qwtPlot);
173 qwtPlot->setAxisScale(QwtPlot::yLeft, 0.0, maxCount);
174 qwtPlot->setAxisScale(QwtPlot::xBottom, realMin, realMax);
177 plot_zoomer_->setZoomBase();
180 if ( min_ > realMin ) {
181 if ( ! clampMinMarker_ ) {
182 clampMinMarker_ =
new QwtPlotMarker();
183 minSymbol_ =
new QwtSymbol(QwtSymbol::VLine);
184 minSymbol_->setColor(cCoder.color_qcolor(std::max(min_,realMin)));
185 minSymbol_->setSize(200,1000);
186 QPen pen = minSymbol_->pen();
188 minSymbol_->setPen(pen);
189 clampMinMarker_->setSymbol(minSymbol_);
190 clampMinMarker_->attach(qwtPlot);
191 clampMinMarker_->show();
195 clampMinMarker_->setXValue(std::max(min_,realMin));
198 if ( clampMinMarker_ ) {
199 clampMinMarker_->detach();
200 delete clampMinMarker_;
206 if ( max_ < realMax ) {
207 if ( ! clampMaxMarker_ ) {
208 clampMaxMarker_ =
new QwtPlotMarker();
209 maxSymbol_ =
new QwtSymbol(QwtSymbol::VLine);
210 maxSymbol_->setColor(cCoder.color_qcolor(std::min(max_,realMax)));
211 maxSymbol_->setSize(200,1000);
212 QPen pen = maxSymbol_->pen();
214 maxSymbol_->setPen(pen);
215 clampMaxMarker_->setSymbol(maxSymbol_);
216 clampMaxMarker_->attach(qwtPlot);
217 clampMaxMarker_->show();
221 clampMaxMarker_->setXValue(std::min(max_,realMax));
224 if ( clampMaxMarker_ ) {
225 clampMaxMarker_->detach();
226 delete clampMaxMarker_;
235 void QwtFunctionPlot::setMinMax(
double _min,
double _max) {
Class for generating nice colors for doubles.