60 #include "QwtFunctionPlot.hh" 70 #include <qwt_curve_fitter.h> 71 #include <qwt_plot_panner.h> 72 #include <qwt_symbol.h> 75 #if QWT_VERSION >= 0x060000 76 #include <qwt_plot_histogram.h> 78 #include <qwt_interval_data.h> 83 #include "TextureMath.hh" 93 QwtFunctionPlot::QwtFunctionPlot(QWidget* _parent) :
95 Ui::QwtFunctionPlotBase(),
106 plot_zoomer_ =
new QwtPlotZoomer( qwtPlot->canvas());
107 plot_zoomer_->initKeyPattern();
108 connect(zoomInButton, SIGNAL( clicked() ),
this,SLOT( zoomIn() ) );
109 connect(zoomOutButton,SIGNAL( clicked() ),
this,SLOT( zoomOut() ) );
110 connect(clampButton, SIGNAL( clicked() ),
this,SLOT( clamp() ) );
112 QwtPlotPanner *panner =
new QwtPlotPanner( qwtPlot->canvas() );
113 panner->setMouseButton( Qt::MidButton );
116 setAttribute(Qt::WA_DeleteOnClose,
true);
118 #if QWT_VERSION >= 0x060000 129 void QwtFunctionPlot::setFunction( std::vector<double>& _values)
137 for ( uint i=0; i < values_.size(); i++){
138 min_ = std::min(min_, values_[i] );
139 max_ = std::max(max_, values_[i] );
146 void QwtFunctionPlot::setParameters(
const TexParameters& _parameters)
148 parameters_ = _parameters;
151 void QwtFunctionPlot::setParameters(
162 parameters_.repeat = _repeat;
163 parameters_.repeatMax = _repeatMax;
164 parameters_.clamp = _clamp;
165 parameters_.clampMin = _clampMin;
166 parameters_.clampMax = _clampMax;
167 parameters_.center = _center;
168 parameters_.abs = _absolute;
169 parameters_.scale = _scale;
175 void QwtFunctionPlot::setImage(QImage* _image)
182 void QwtFunctionPlot::zoomIn()
184 emit plot_zoomer_->zoom(1);
189 void QwtFunctionPlot::zoomOut()
191 emit plot_zoomer_->zoom(-1);
196 void QwtFunctionPlot::clamp()
198 QRectF clamped = plot_zoomer_->zoomRect();
199 clamped.setLeft( min_ );
200 clamped.setRight( max_ );
201 emit plot_zoomer_->zoom(clamped);
206 void QwtFunctionPlot::replot()
209 const int intervalCount = 100;
211 #if QWT_VERSION >= 0x060000 212 QVector<QwtIntervalSample> intervals(intervalCount);
214 QwtArray<QwtDoubleInterval> intervals(intervalCount);
215 QwtArray<double> count(intervalCount);
217 std::vector< QColor > colors;
220 double width = ( max_ - min_ ) / intervalCount;
222 QColor lastColor = Qt::black;
226 for (
int i = 0; i < (int)intervals.size(); i++ )
229 #if QWT_VERSION >= 0x060000 230 intervals[i] = QwtIntervalSample(0.0,pos, pos + width);
232 intervals[i] = QwtDoubleInterval(pos, pos + width);
239 const double intervalCenter = pos + (width/2.0);
241 const double value = convert.transform(intervalCenter);
242 int val = int( value * ( image_->width() - 1) );
244 val = val % image_->width();
245 colors.push_back( QColor( image_->pixel(val, 0) ) );
246 lastColor = colors.back();
251 for ( uint i=0; i < values_.size(); i++)
252 for (
int j = 0; j < (int)intervals.size(); j++ )
253 #
if QWT_VERSION >= 0x060000
254 if ( intervals[j].interval.contains( values_[i] ) )
255 intervals[j].value++;
257 if ( intervals[j].contains( values_[i] ) )
264 for (
int i = 0; i < (int)intervals.size(); i++ )
265 #
if QWT_VERSION >= 0x060000
266 maxCount = std::max(maxCount, intervals[i].value);
268 maxCount = std::max(maxCount, count[i]);
272 #if QWT_VERSION >= 0x060000 273 QwtIntervalSeriesData* data =
new QwtIntervalSeriesData(intervals);
274 histogram_->setData(data);
276 histogram_->setData(QwtIntervalData(intervals, count));
278 histogram_->setColors(colors);
279 histogram_->attach(qwtPlot);
281 qwtPlot->setAxisScale(QwtPlot::yLeft, 0.0, maxCount);
282 qwtPlot->setAxisScale(QwtPlot::xBottom, min_, max_);
284 qwtPlot->setAxisTitle(QwtPlot::yLeft,
"count" );
285 qwtPlot->setAxisTitle(QwtPlot::xBottom,
"values" );
288 plot_zoomer_->setZoomBase();
291 if ( parameters_.clamp ) {
292 if ( ! clampMinMarker_ ) {
293 clampMinMarker_ =
new QwtPlotMarker();
294 minSymbol_ =
new QwtSymbol(QwtSymbol::VLine);
295 minSymbol_->setColor(QColor(255,0,0));
296 minSymbol_->setSize(200,1000);
297 QPen pen = minSymbol_->pen();
299 minSymbol_->setPen(pen);
300 clampMinMarker_->setSymbol(minSymbol_);
301 clampMinMarker_->attach(qwtPlot);
305 if ( parameters_.clampMin < min_ )
306 clampMinMarker_->setXValue(min_);
308 clampMinMarker_->setXValue(parameters_.clampMin);
312 clampMinMarker_->show();
314 if ( ! clampMaxMarker_ ) {
315 clampMaxMarker_ =
new QwtPlotMarker();
316 maxSymbol_ =
new QwtSymbol(QwtSymbol::VLine);
317 maxSymbol_->setColor(QColor(0,255,0));
318 maxSymbol_->setSize(200,1000);
319 QPen pen = maxSymbol_->pen();
321 maxSymbol_->setPen(pen);
322 clampMaxMarker_->setSymbol(maxSymbol_);
323 clampMaxMarker_->attach(qwtPlot);
327 if ( parameters_.clampMax < max_ )
328 clampMaxMarker_->setXValue(parameters_.clampMax);
330 clampMaxMarker_->setXValue(max_);
332 clampMaxMarker_->show();
335 if ( clampMinMarker_ )
336 clampMinMarker_->hide();
338 if ( clampMaxMarker_ )
339 clampMaxMarker_->hide();
Histogram plotting widget.
Namespace providing different geometric functions concerning angles.