rock_widget_collection  0.1
Public Slots | Public Member Functions | Protected Member Functions | List of all members
Plot2d Class Reference

#include <Plot2d.h>

Inherits QVTKWidget, and QCustomPlot.

Public Slots

QObject * getGraph (int index) const
 
QObject * getLegend () const
 
QObject * addGraph (QObject *key_axis, QObject *value_axis)
 
void removeGraph (int index)
 
QObject * getXAxis () const
 
QObject * getXAxis2 () const
 
QObject * getYAxis () const
 
QObject * getYAxis2 () const
 
void setZoomAble (bool enabled, int yAxisIndex=0)
 
void setRangeAble (bool enabled, int yAxisIndex=0)
 
void setTitle (QString title)
 
void setXTitle (QString label)
 
void setYTitle (QString label)
 
void setStyle (int id, QString style)
 
void setColor (int id, int r, int g, int b)
 
void setPlotLabel (int id, QString label)
 
void setNumberOfXLabels (int i)
 
void setNumberOfYLabels (int i)
 
void showLegend (bool on)
 
void autoScroll (bool on)
 
void showPlotPoints (bool on)
 
void showPlotLines (bool on)
 
void setXValues (int id)
 
void setXRange (double min, double max)
 
void setYRange (double min, double max)
 
void addPoint (int id, double x, double y)
 
void addPoints (int id, const QList< double > &x, const QList< double > &y)
 
void clear (int id)
 
void render ()
 
bool isIdValid (int id)
 
void scrollTo (double x, double y)
 
- Public Slots inherited from QCustomPlot
QString title () const
 
QFont titleFont () const
 
QRect axisRect () const
 
int marginLeft () const
 
int marginRight () const
 
int marginTop () const
 
int marginBottom () const
 
bool autoMargin () const
 
QColor color () const
 
Qt::Orientations rangeDrag () const
 
Qt::Orientations rangeZoom () const
 
QCPAxisrangeDragAxis (Qt::Orientation orientation)
 
QCPAxisrangeZoomAxis (Qt::Orientation orientation)
 
double rangeZoomFactor (Qt::Orientation orientation)
 
const AntialiasedElements antialiasedElements () const
 
bool autoAddPlottableToLegend () const
 
QPixmap axisBackground () const
 
bool axisBackgroundScaled () const
 
Qt::AspectRatioMode axisBackgroundScaledMode () const
 
void setTitle (const QString &title)
 
void setTitleFont (const QFont &font)
 
void setAxisRect (const QRect &arect)
 
void setMarginLeft (int margin)
 
void setMarginRight (int margin)
 
void setMarginTop (int margin)
 
void setMarginBottom (int margin)
 
void setMargin (int left, int right, int top, int bottom)
 
void setAutoMargin (bool enabled)
 
void setColor (const QColor &color)
 
void setRangeDrag (Qt::Orientations orientations)
 
void setRangeZoom (Qt::Orientations orientations)
 
void setRangeDragAxes (QCPAxis *horizontal, QCPAxis *vertical)
 
void setRangeZoomAxes (QCPAxis *horizontal, QCPAxis *vertical)
 
void setRangeZoomFactor (double horizontalFactor, double verticalFactor)
 
void setRangeZoomFactor (double factor)
 
void setAntialiasedElements (const AntialiasedElements &antialiasedElements)
 
void setAntialiasedElement (AntialiasedElement antialiasedElement, bool enabled)
 
void setAutoAddPlottableToLegend (bool on)
 
void setAxisBackground (const QPixmap &pm)
 
void setAxisBackground (const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode=Qt::KeepAspectRatioByExpanding)
 
void setAxisBackgroundScaled (bool scaled)
 
void setAxisBackgroundScaledMode (Qt::AspectRatioMode mode)
 
QCPAbstractPlottableplottable (int index)
 
QCPAbstractPlottableplottable ()
 
bool addPlottable (QCPAbstractPlottable *plottable)
 
bool removePlottable (QCPAbstractPlottable *plottable)
 
bool removePlottable (int index)
 
int clearPlottables ()
 
int plottableCount () const
 
QCPGraphgraph (int index) const
 
QCPGraphgraph () const
 
QCPGraphaddGraph (QCPAxis *keyAxis=0, QCPAxis *valueAxis=0)
 
bool removeGraph (QCPGraph *graph)
 
bool removeGraph (int index)
 
int clearGraphs ()
 
int graphCount () const
 
void replot ()
 
void setupFullAxesBox ()
 
void rescaleAxes ()
 
void savePdf (const QString &fileName, bool noCosmeticPen=false, int width=0, int height=0)
 
void savePng (const QString &fileName, int width=0, int height=0)
 
void savePngScaled (const QString &fileName, double scale, int width=0, int height=0)
 

Public Member Functions

 Plot2d (QWidget *parent=NULL)
 
virtual ~Plot2d ()
 
 Plot2d (QWidget *parent=NULL)
 
virtual ~Plot2d ()
 

Protected Member Functions

virtual void mouseMoveEvent (QMouseEvent *event)
 
void addPlot (int id)
 
field_t getField (int id)
 
- Protected Member Functions inherited from QCustomPlot
virtual void paintEvent (QPaintEvent *event)
 
virtual void resizeEvent (QResizeEvent *event)
 
virtual void mouseDoubleClickEvent (QMouseEvent *event)
 
virtual void mousePressEvent (QMouseEvent *event)
 
virtual void mouseReleaseEvent (QMouseEvent *event)
 
virtual void wheelEvent (QWheelEvent *event)
 
virtual void draw (QPainter *painter)
 
virtual void drawAxisBackground (QPainter *painter)
 
void updateAxisRect ()
 

Additional Inherited Members

- Signals inherited from QCustomPlot
void mouseDoubleClick (QMouseEvent *event)
 
void mousePress (QMouseEvent *event)
 
void mousePressOnLegendItem (QMouseEvent *event, QVariant itemIdx)
 
void mousePressOnPlotArea (QMouseEvent *event)
 
void mouseMove (QMouseEvent *event)
 
void mouseRelease (QMouseEvent *event)
 
void mouseWheel (QWheelEvent *event)
 
- Public Attributes inherited from QCustomPlot
QCPAxisxAxis
 
QCPAxisyAxis
 
QCPAxisxAxis2
 
QCPAxisyAxis2
 
QCPLegendlegend
 
- Protected Attributes inherited from QCustomPlot
QPixmap buffer
 
QString mTitle
 
QFont mTitleFont
 
QRect mViewport
 
QRect mAxisRect
 
int mMarginLeft
 
int mMarginRight
 
int mMarginTop
 
int mMarginBottom
 
bool mAutoMargin
 
bool mAutoAddPlottableToLegend
 
QColor mColor
 
QList< QCPAbstractPlottable * > mPlottables
 
QList< QCPGraph * > mGraphs
 
Qt::Orientations mRangeDrag
 
Qt::Orientations mRangeZoom
 
QCPAxismRangeDragHorzAxis
 
QCPAxismRangeDragVertAxis
 
QCPAxismRangeZoomHorzAxis
 
QCPAxismRangeZoomVertAxis
 
double mRangeZoomFactorHorz
 
double mRangeZoomFactorVert
 
bool mDragging
 
QPoint mDragStart
 
QCPRange mDragStartHorzRange
 
QCPRange mDragStartVertRange
 
QFlags< AntialiasedElement > mAntialiasedElements
 
QPixmap mAxisBackground
 
QPixmap mScaledAxisBackground
 
bool mAxisBackgroundScaled
 
Qt::AspectRatioMode mAxisBackgroundScaledMode
 

Detailed Description

Definition at line 14 of file Plot2d.h.

Constructor & Destructor Documentation

Plot2d::Plot2d ( QWidget *  parent = NULL)

Definition at line 9 of file Plot2d.cc.

9  :
10  QCustomPlot(parent),auto_scroll(true)
11 {
12 }
The central class which is also the QWidget which displays the plot and interacts with the user...
Definition: qcustomplot.h:895
Plot2d::~Plot2d ( )
virtual

Definition at line 14 of file Plot2d.cc.

14 {}
Plot2d::Plot2d ( QWidget *  parent = NULL)
virtual Plot2d::~Plot2d ( )
virtual

Member Function Documentation

QObject* Plot2d::addGraph ( QObject *  key_axis,
QObject *  value_axis 
)
inlineslot

Definition at line 26 of file Plot2d.h.

27  {return QCustomPlot::addGraph(dynamic_cast<QCPAxis*>(key_axis),dynamic_cast<QCPAxis*>(value_axis));}
QCPGraph * addGraph(QCPAxis *keyAxis=0, QCPAxis *valueAxis=0)
void Plot2d::addPlot ( int  id)
protected

Definition at line 179 of file Plot2d.cc.

180 {
181  if(id < 0)
182  throw std::runtime_error("addPlot: Bad id. Id must be positive.");
183 
184  while((unsigned int)id >= field_data.size())
185  {
186  array_t array = vtkSmartPointer<vtkDoubleArray>::New();
187  array_t array2 = vtkSmartPointer<vtkDoubleArray>::New();
188  field_t field = vtkSmartPointer<vtkFieldData>::New();
189  vtkSmartPointer<vtkDataObject> data = vtkSmartPointer<vtkDataObject>::New();
190 
191  field->AddArray(array);
192  field->AddArray(array2);
193  data->SetFieldData(field);
194  plot->AddDataObjectInput(data);
195  plot->SetDataObjectXComponent(id,0);
196  plot->SetDataObjectYComponent(id,1);
197  field_data.push_back(field);
198  }
199 }
vtkSmartPointer< vtkFieldData > field_t
Definition: Plot2d.h:22
vtkSmartPointer< vtkDoubleArray > array_t
Definition: Plot2d.h:21
void Plot2d::addPoint ( int  id,
double  x,
double  y 
)
slot

Definition at line 95 of file Plot2d.cc.

96 {
97  field_t field = getField(id);
98  array_t array = (vtkDoubleArray*)field->GetArray(0);
99  array_t array2 = (vtkDoubleArray*)field->GetArray(1);
100  array->InsertNextValue(x);
101  array2->InsertNextValue(y);
102  array->Modified();
103  array2->Modified();
104  if(auto_scroll)
105  scrollTo(x,y);
106 }
vtkSmartPointer< vtkFieldData > field_t
Definition: Plot2d.h:22
void scrollTo(double x, double y)
Definition: Plot2d.cc:85
field_t getField(int id)
Definition: Plot2d.cc:201
vtkSmartPointer< vtkDoubleArray > array_t
Definition: Plot2d.h:21
void Plot2d::addPoints ( int  id,
const QList< double > &  x,
const QList< double > &  y 
)
slot

Definition at line 108 of file Plot2d.cc.

109 {
110  if(x.size() != y.size())
111  std::runtime_error("addValues: Size mismatch. Both lists must have the same size.");
112 
113  if(x.size() == 0)
114  return;
115 
116  field_t field = getField(id);
117  array_t array = (vtkDoubleArray*)field->GetArray(0);
118  array_t array2 = (vtkDoubleArray*)field->GetArray(1);
119 
120  QList<double>::const_iterator iter_x = x.constBegin();
121  QList<double>::const_iterator iter_y = y.constBegin();
122  for(;iter_x != x.constEnd();++iter_x,++iter_y)
123  {
124  array->InsertNextValue(*iter_x);
125  array2->InsertNextValue(*iter_y);
126  }
127  array->Modified();
128  array2->Modified();
129  if(auto_scroll)
130  scrollTo(*(--iter_x),*(--iter_y));
131 }
vtkSmartPointer< vtkFieldData > field_t
Definition: Plot2d.h:22
void scrollTo(double x, double y)
Definition: Plot2d.cc:85
field_t getField(int id)
Definition: Plot2d.cc:201
vtkSmartPointer< vtkDoubleArray > array_t
Definition: Plot2d.h:21
void Plot2d::autoScroll ( bool  on)
slot

Definition at line 70 of file Plot2d.cc.

70 {auto_scroll = on;}
void Plot2d::clear ( int  id)
slot

Definition at line 78 of file Plot2d.cc.

79 {
80  if(!isIdValid(id))
81  return;
82  getField(id)->Reset();
83 }
bool isIdValid(int id)
Definition: Plot2d.cc:141
field_t getField(int id)
Definition: Plot2d.cc:201
field_t Plot2d::getField ( int  id)
protected

Definition at line 201 of file Plot2d.cc.

202 {
203  addPlot(id);
204  return field_data[id];
205 }
void addPlot(int id)
Definition: Plot2d.cc:179
QObject* Plot2d::getGraph ( int  index) const
inlineslot

Definition at line 24 of file Plot2d.h.

24 {return graph(index);}
QCPGraph * graph() const
QObject* Plot2d::getLegend ( ) const
inlineslot

Definition at line 25 of file Plot2d.h.

25 {return legend;}
QCPLegend * legend
Definition: qcustomplot.h:1007
QObject* Plot2d::getXAxis ( ) const
inlineslot

Definition at line 29 of file Plot2d.h.

29 {return xAxis;}
QCPAxis * xAxis
Definition: qcustomplot.h:1006
QObject* Plot2d::getXAxis2 ( ) const
inlineslot

Definition at line 30 of file Plot2d.h.

30 {return xAxis2;}
QCPAxis * xAxis2
Definition: qcustomplot.h:1006
QObject* Plot2d::getYAxis ( ) const
inlineslot

Definition at line 31 of file Plot2d.h.

31 {return yAxis;}
QCPAxis * yAxis
Definition: qcustomplot.h:1006
QObject* Plot2d::getYAxis2 ( ) const
inlineslot

Definition at line 32 of file Plot2d.h.

32 {return yAxis2;}
QCPAxis * yAxis2
Definition: qcustomplot.h:1006
bool Plot2d::isIdValid ( int  id)
slot

Definition at line 141 of file Plot2d.cc.

142 {
143  if (id >=0 && (unsigned int)id < field_data.size())
144  return true;
145  return false;
146 }
void Plot2d::mouseMoveEvent ( QMouseEvent *  event)
protectedvirtual

Reimplemented from QCustomPlot.

Definition at line 160 of file Plot2d.cc.

161 {
162  QVTKWidget::mouseMoveEvent(event);
163 
164  int x,y;
165  double x2,y2;
166  std::stringstream ss;
167 
168  GetRenderWindow()->GetInteractor()->GetLastEventPosition(x,y);
169  plot->SetViewportCoordinate(x,y);
170  plot->ViewportToPlotCoordinate(renderer);
171  plot->GetViewportCoordinate(x2,y2);
172 
173  ss << x2 << " / " << y2 << "\n";
174  text->SetInput(ss.str().c_str());
175  text->Modified();
176  update();
177 }
void Plot2d::removeGraph ( int  index)
slot

Definition at line 17 of file Plot2d.cc.

18 {
20 }
bool removePlottable(QCPAbstractPlottable *plottable)
void Plot2d::render ( )
slot

Definition at line 148 of file Plot2d.cc.

149 {
150 // data2->Update();
151 // cachedImageDirty();
152 // GetRenderWindow()->GetInteractor()->Render();
153 // update();
154 }
void Plot2d::scrollTo ( double  x,
double  y 
)
slot

Definition at line 85 of file Plot2d.cc.

86 {
87  double* xrange = plot->GetXRange();
88  double width = (xrange[1]-xrange[0]);
89  double* yrange = plot->GetYRange();
90  double height = (yrange[1]-yrange[0]);
91  setXRange(x-width*0.8,x+width*0.2);
92  setYRange(y-height*0.8,y+height*0.2);
93 }
void setYRange(double min, double max)
Definition: Plot2d.cc:63
void setXRange(double min, double max)
Definition: Plot2d.cc:62
void Plot2d::setColor ( int  id,
int  r,
int  g,
int  b 
)
slot

Definition at line 61 of file Plot2d.cc.

61 {addPlot(id);plot->SetPlotColor(id,c_norm*r,c_norm*g,c_norm*b);}
void addPlot(int id)
Definition: Plot2d.cc:179
const double c_norm
Definition: Plot2d.cc:21
void Plot2d::setNumberOfXLabels ( int  i)
slot

Definition at line 68 of file Plot2d.cc.

68 {plot->SetNumberOfXLabels(i);}
void Plot2d::setNumberOfYLabels ( int  i)
slot

Definition at line 69 of file Plot2d.cc.

69 {plot->SetNumberOfYLabels(i);}
void Plot2d::setPlotLabel ( int  id,
QString  label 
)
slot

Definition at line 64 of file Plot2d.cc.

64 {addPlot(id);plot->SetPlotLabel(id,label.toStdString().c_str());}
void addPlot(int id)
Definition: Plot2d.cc:179
void Plot2d::setRangeAble ( bool  enabled,
int  yAxisIndex = 0 
)
inlineslot

Definition at line 45 of file Plot2d.h.

46  {
47  if(yAxisIndex == 0)
49  else
51 
52  if(enabled)
53  setRangeZoom(Qt::Horizontal | Qt::Vertical);
54  else setRangeZoom(0);
55  }
void setRangeZoomAxes(QCPAxis *horizontal, QCPAxis *vertical)
void setRangeZoom(Qt::Orientations orientations)
QCPAxis * yAxis2
Definition: qcustomplot.h:1006
QCPAxis * xAxis
Definition: qcustomplot.h:1006
QCPAxis * yAxis
Definition: qcustomplot.h:1006
void Plot2d::setStyle ( int  id,
QString  style 
)
slot

Definition at line 60 of file Plot2d.cc.

60 {}
void Plot2d::setTitle ( QString  title)
slot

Definition at line 57 of file Plot2d.cc.

57 {plot->SetTitle(title.toStdString().c_str());}
QString title() const
Definition: qcustomplot.h:935
void Plot2d::setXRange ( double  min,
double  max 
)
slot

Definition at line 62 of file Plot2d.cc.

62 {plot->SetXRange(min,max);}
void Plot2d::setXTitle ( QString  label)
slot

Definition at line 58 of file Plot2d.cc.

58 {plot->SetXTitle(title.toStdString().c_str());}
QString title() const
Definition: qcustomplot.h:935
void Plot2d::setXValues ( int  id)
slot

Definition at line 133 of file Plot2d.cc.

134 {
135  if(isIdValid(id))
136  plot->SetXValues(id);
137  else
138  plot->SetXValuesToIndex();
139 }
bool isIdValid(int id)
Definition: Plot2d.cc:141
void Plot2d::setYRange ( double  min,
double  max 
)
slot

Definition at line 63 of file Plot2d.cc.

63 {plot->SetYRange(min,max);}
void Plot2d::setYTitle ( QString  label)
slot

Definition at line 59 of file Plot2d.cc.

59 {plot->SetYTitle(title.toStdString().c_str());}
QString title() const
Definition: qcustomplot.h:935
void Plot2d::setZoomAble ( bool  enabled,
int  yAxisIndex = 0 
)
inlineslot

Definition at line 34 of file Plot2d.h.

35  {
36  if(yAxisIndex == 0)
38  else
40 
41  if(enabled)
42  setRangeDrag(Qt::Horizontal | Qt::Vertical);
43  else setRangeDrag(0);
44  }
void setRangeDrag(Qt::Orientations orientations)
QCPAxis * yAxis2
Definition: qcustomplot.h:1006
QCPAxis * xAxis
Definition: qcustomplot.h:1006
QCPAxis * yAxis
Definition: qcustomplot.h:1006
void setRangeDragAxes(QCPAxis *horizontal, QCPAxis *vertical)
void Plot2d::showLegend ( bool  on)
slot

Definition at line 65 of file Plot2d.cc.

65 {if(on){plot->LegendOn();}else{plot->LegendOff();}}
void Plot2d::showPlotLines ( bool  on)
slot

Definition at line 67 of file Plot2d.cc.

67 {if(on){plot->PlotLinesOn();}else{plot->PlotLinesOff();}}
void Plot2d::showPlotPoints ( bool  on)
slot

Definition at line 66 of file Plot2d.cc.

66 {if(on){plot->PlotPointsOn();}else{plot->PlotPointsOff();}}

The documentation for this class was generated from the following files: