VTK
vtkXYPlotActor.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkXYPlotActor.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
87 #ifndef __vtkXYPlotActor_h
88 #define __vtkXYPlotActor_h
89 
90 #define VTK_XYPLOT_INDEX 0
91 #define VTK_XYPLOT_ARC_LENGTH 1
92 #define VTK_XYPLOT_NORMALIZED_ARC_LENGTH 2
93 #define VTK_XYPLOT_VALUE 3
94 
95 #define VTK_XYPLOT_ROW 0
96 #define VTK_XYPLOT_COLUMN 1
97 
98 #include "vtkRenderingAnnotationModule.h" // For export macro
99 #include "vtkActor2D.h"
100 
101 class vtkXYPlotActorConnections;
102 class vtkAlgorithmOutput;
103 class vtkAppendPolyData;
104 class vtkAxisActor2D;
105 class vtkDataObject;
107 class vtkDataSet;
109 class vtkGlyph2D;
110 class vtkGlyphSource2D;
111 class vtkIntArray;
112 class vtkLegendBoxActor;
113 class vtkPlanes;
114 class vtkPolyData;
115 class vtkPolyDataMapper2D;
116 class vtkTextMapper;
117 class vtkTextProperty;
118 
119 class VTKRENDERINGANNOTATION_EXPORT vtkXYPlotActor : public vtkActor2D
120 {
121 public:
122  vtkTypeMacro(vtkXYPlotActor,vtkActor2D);
123  void PrintSelf(ostream& os, vtkIndent indent);
124 
129  static vtkXYPlotActor *New();
130 
131  //---Data Set Input----------------------------------------------------------
132  // The following methods are used to plot input datasets. Datasets
133  // will be plotted if set as input; otherwise the input data objects
134  // will be plotted (if defined).
135 
137 
143  void AddDataSetInput(vtkDataSet *ds, const char* arrayName, int component);
144  void AddDataSetInput(vtkDataSet *ds) {this->AddDataSetInput(ds, NULL, 0);}
145  void AddDataSetInputConnection(vtkAlgorithmOutput *in, const char* arrayName, int component);
148 
150 
151  void RemoveDataSetInput(vtkDataSet *ds, const char* arrayName, int component);
152  void RemoveDataSetInput(vtkDataSet *ds) {this->RemoveDataSetInput(ds, NULL, 0);}
153  void RemoveDataSetInputConnection(vtkAlgorithmOutput *in, const char* arrayName, int component);
154  void RemoveDataSetInputConnection(vtkAlgorithmOutput *in)
155  {
156  this->RemoveDataSetInputConnection(in, NULL, 0);
157  }
159 
162  void RemoveAllDataSetInputConnections();
163 
165 
168  void SetPointComponent(int i, int comp);
169  int GetPointComponent(int i);
170  //---end Data Set Input-----------------------------------------------------
172 
174 
182  vtkSetClampMacro(XValues,int,VTK_XYPLOT_INDEX,VTK_XYPLOT_VALUE);
183  vtkGetMacro(XValues,int);
184  void SetXValuesToIndex(){this->SetXValues(VTK_XYPLOT_INDEX);};
185  void SetXValuesToArcLength() {this->SetXValues(VTK_XYPLOT_ARC_LENGTH);};
186  void SetXValuesToNormalizedArcLength()
187  {this->SetXValues(VTK_XYPLOT_NORMALIZED_ARC_LENGTH);};
188  void SetXValuesToValue() {this->SetXValues(VTK_XYPLOT_VALUE);};
189  const char *GetXValuesAsString();
191 
192  //---Data Object Input------------------------------------------------------
193  // The following methods are used to plot input data objects. Datasets will
194  // be plotted in preference to data objects if set as input; otherwise the
195  // input data objects will be plotted (if defined).
196 
198 
199  void AddDataObjectInput(vtkDataObject *in);
200  void AddDataObjectInputConnection(vtkAlgorithmOutput *alg);
202 
204 
205  void RemoveDataObjectInputConnection(vtkAlgorithmOutput *aout);
206  void RemoveDataObjectInput(vtkDataObject *in);
208 
210 
212  vtkSetClampMacro(DataObjectPlotMode,int,VTK_XYPLOT_ROW,VTK_XYPLOT_COLUMN);
213  vtkGetMacro(DataObjectPlotMode,int);
214  void SetDataObjectPlotModeToRows()
215  {this->SetDataObjectPlotMode(VTK_XYPLOT_ROW);}
216  void SetDataObjectPlotModeToColumns()
217  {this->SetDataObjectPlotMode(VTK_XYPLOT_COLUMN);}
218  const char *GetDataObjectPlotModeAsString();
220 
222 
228  void SetDataObjectXComponent(int i, int comp);
229  int GetDataObjectXComponent(int i);
231 
233 
239  void SetDataObjectYComponent(int i, int comp);
240  int GetDataObjectYComponent(int i);
241  //---end Data Object Input--------------------------------------------------
243 
244  //---Per Curve Properties---------------------------------------------------
245  // The following methods are used to set properties on each curve that is
246  // plotted. Each input dataset (or data object) results in one curve. The
247  // methods that follow have an index i that corresponds to the input dataset
248  // or data object.
249  void SetPlotColor(int i, double r, double g, double b);
250  void SetPlotColor(int i, const double color[3]) {
251  this->SetPlotColor(i, color[0], color[1], color[2]); };
252  double *GetPlotColor(int i);
253  void SetPlotSymbol(int i,vtkPolyData *input);
254  vtkPolyData *GetPlotSymbol(int i);
255  void SetPlotLabel(int i, const char *label);
256  const char *GetPlotLabel(int i);
257 
258  // Allow per-curve specification of line and point rendering. These override
259  // global settings PlotPoints and PlotLines. If not on, the default behavior
260  // is governed by PlotPoints and PlotLines ivars.
261  vtkGetMacro(PlotCurvePoints, int);
262  vtkSetMacro(PlotCurvePoints, int);
263  vtkBooleanMacro(PlotCurvePoints, int);
264 
265  vtkGetMacro(PlotCurveLines, int);
266  vtkSetMacro(PlotCurveLines, int);
267  vtkBooleanMacro(PlotCurveLines, int);
268 
269  void SetPlotLines(int i, int);
270  int GetPlotLines(int i);
271 
272  void SetPlotPoints(int i, int);
273  int GetPlotPoints(int i);
274  //---end Per Curve Properties-----------------------------------------------
275 
277 
279  vtkSetMacro(ExchangeAxes, int);
280  vtkGetMacro(ExchangeAxes, int);
281  vtkBooleanMacro(ExchangeAxes, int);
283 
285 
289  vtkSetMacro(ReverseXAxis, int);
290  vtkGetMacro(ReverseXAxis, int);
291  vtkBooleanMacro(ReverseXAxis, int);
293 
295 
299  vtkSetMacro(ReverseYAxis, int);
300  vtkGetMacro(ReverseYAxis, int);
301  vtkBooleanMacro(ReverseYAxis, int);
303 
305 
309  vtkGetObjectMacro(LegendActor,vtkLegendBoxActor);
310  vtkGetObjectMacro(GlyphSource,vtkGlyphSource2D);
312 
314 
316  vtkSetStringMacro(Title);
317  vtkGetStringMacro(Title);
318  vtkSetStringMacro(XTitle);
319  vtkGetStringMacro(XTitle);
320  vtkSetStringMacro(YTitle);
321  vtkGetStringMacro(YTitle);
323 
325 
327  vtkAxisActor2D *GetXAxisActor2D()
328  {return this->XAxis;}
329  vtkAxisActor2D *GetYAxisActor2D()
330  {return this->YAxis;}
332 
334 
340  vtkSetVector2Macro(XRange,double);
341  vtkGetVectorMacro(XRange,double,2);
342  vtkSetVector2Macro(YRange,double);
343  vtkGetVectorMacro(YRange,double,2);
344  void SetPlotRange(double xmin, double ymin, double xmax, double ymax)
345  {this->SetXRange(xmin,xmax); this->SetYRange(ymin,ymax);}
347 
349 
354  vtkSetClampMacro(NumberOfXLabels, int, 0, 50);
355  vtkGetMacro(NumberOfXLabels, int);
356  vtkSetClampMacro(NumberOfYLabels, int, 0, 50);
357  vtkGetMacro(NumberOfYLabels, int);
358  void SetNumberOfLabels(int num)
359  {this->SetNumberOfXLabels(num); this->SetNumberOfYLabels(num);}
361 
363 
368  void SetAdjustXLabels(int adjust);
369  vtkGetMacro( AdjustXLabels, int );
370  void SetAdjustYLabels(int adjust);
371  vtkGetMacro( AdjustYLabels, int );
373 
375 
376  void SetXTitlePosition(double position);
377  double GetXTitlePosition();
378  void SetYTitlePosition(double position);
379  double GetYTitlePosition();
381 
383 
384  void SetNumberOfXMinorTicks(int num);
385  int GetNumberOfXMinorTicks();
386  void SetNumberOfYMinorTicks(int num);
387  int GetNumberOfYMinorTicks();
389 
391 
394  vtkSetMacro(Legend, int);
395  vtkGetMacro(Legend, int);
396  vtkBooleanMacro(Legend, int);
398 
400 
402  vtkSetVector2Macro(TitlePosition,double);
403  vtkGetVector2Macro(TitlePosition,double);
405 
407 
409  vtkSetMacro(AdjustTitlePosition, int);
410  vtkGetMacro(AdjustTitlePosition, int);
411  vtkBooleanMacro(AdjustTitlePosition, int);
413 
414 //BTX
415 enum Alignment {
416  AlignLeft = 0x1,
417  AlignRight = 0x2,
418  AlignHCenter = 0x4,
419  AlignTop = 0x10,
420  AlignBottom = 0x20,
421  AlignVCenter = 0x40,
422  AlignAxisLeft = 0x100,
423  AlignAxisRight = 0x200,
424  AlignAxisHCenter = 0x400,
425  AlignAxisTop = 0x1000,
426  AlignAxisBottom = 0x2000,
427  AlignAxisVCenter = 0x4000,
428 };
429 //ETX
431 
436  vtkSetMacro(AdjustTitlePositionMode, int);
437  vtkGetMacro(AdjustTitlePositionMode, int);
439 
441 
447  vtkSetVector2Macro(LegendPosition,double);
448  vtkGetVector2Macro(LegendPosition,double);
449  vtkSetVector2Macro(LegendPosition2,double);
450  vtkGetVector2Macro(LegendPosition2,double);
452 
454 
455  virtual void SetTitleTextProperty(vtkTextProperty *p);
456  vtkGetObjectMacro(TitleTextProperty,vtkTextProperty);
458 
460 
462  virtual void SetAxisTitleTextProperty(vtkTextProperty *p);
463  vtkGetObjectMacro(AxisTitleTextProperty,vtkTextProperty);
465 
467 
469  virtual void SetAxisLabelTextProperty(vtkTextProperty *p);
470  vtkGetObjectMacro(AxisLabelTextProperty,vtkTextProperty);
472 
474 
475  vtkSetMacro(Logx, int);
476  vtkGetMacro(Logx, int);
477  vtkBooleanMacro(Logx, int);
479 
481 
483  virtual void SetLabelFormat (const char* _arg);
484  const char* GetLabelFormat()
485  {
486  return this->GetXLabelFormat();
487  }
489 
491 
492  virtual void SetXLabelFormat (const char* _arg);
493  vtkGetStringMacro(XLabelFormat);
495 
497 
498  virtual void SetYLabelFormat (const char* _arg);
499  vtkGetStringMacro(YLabelFormat);
501 
503 
505  vtkSetClampMacro(Border, int, 0, 50);
506  vtkGetMacro(Border, int);
508 
510 
513  vtkGetMacro(PlotPoints, int);
514  vtkSetMacro(PlotPoints, int);
515  vtkBooleanMacro(PlotPoints, int);
517 
519 
521  vtkGetMacro(PlotLines, int);
522  vtkSetMacro(PlotLines, int);
523  vtkBooleanMacro(PlotLines, int);
525 
527 
530  vtkSetClampMacro(GlyphSize, double, 0.0, 0.2);
531  vtkGetMacro(GlyphSize, double);
533 
536  void ViewportToPlotCoordinate(vtkViewport *viewport, double &u, double &v);
537 
539 
542  void ViewportToPlotCoordinate(vtkViewport *viewport);
543  vtkSetVector2Macro(PlotCoordinate,double);
544  vtkGetVector2Macro(PlotCoordinate,double);
546 
548  void PlotToViewportCoordinate(vtkViewport *viewport, double &u, double &v);
549 
551 
555  void PlotToViewportCoordinate(vtkViewport *viewport);
556  vtkSetVector2Macro(ViewportCoordinate,double);
557  vtkGetVector2Macro(ViewportCoordinate,double);
559 
562  int IsInPlot(vtkViewport *viewport, double u, double v);
563 
565 
567  vtkSetMacro(ChartBox, int);
568  vtkGetMacro(ChartBox, int);
569  vtkBooleanMacro(ChartBox, int);
571 
573 
575  vtkSetMacro(ChartBorder, int);
576  vtkGetMacro(ChartBorder, int);
577  vtkBooleanMacro(ChartBorder, int);
579 
581  vtkProperty2D* GetChartBoxProperty() { return this->ChartBoxActor->GetProperty(); };
582 
584 
585  vtkSetMacro(ShowReferenceXLine, int);
586  vtkGetMacro(ShowReferenceXLine, int);
587  vtkBooleanMacro(ShowReferenceXLine, int);
589 
591 
592  vtkSetMacro(ReferenceXValue, double);
593  vtkGetMacro(ReferenceXValue, double);
595 
597 
598  vtkSetMacro(ShowReferenceYLine, int);
599  vtkGetMacro(ShowReferenceYLine, int);
600  vtkBooleanMacro(ShowReferenceYLine, int);
602 
604 
605  vtkSetMacro(ReferenceYValue, double);
606  vtkGetMacro(ReferenceYValue, double);
608 
610  unsigned long GetMTime();
611 
614  void PrintAsCSV(ostream &os);
615 
616 //BTX
618 
624 
626  virtual int HasTranslucentPolygonalGeometry();
627 
629 
633 //ETX
635 
636 protected:
637  vtkXYPlotActor();
638  ~vtkXYPlotActor();
639 
640  vtkXYPlotActorConnections* InputConnectionHolder;
641  char** SelectedInputScalars; // list of data set arrays to plot
642  vtkIntArray* SelectedInputScalarsComponent; // list of componenents
643  vtkXYPlotActorConnections *DataObjectInputConnectionHolder; //list of data objects to plot
644  char *Title;
645  char *XTitle;
646  char *YTitle;
647  int XValues;
650  int Logx;
653  double XRange[2];
654  double YRange[2];
655  double XComputedRange[2]; //range actually used by plot
656  double YComputedRange[2]; //range actually used by plot
657  int Border;
668  double TitlePosition[2];
670 
674 
677 
680 
681  double ViewportCoordinate[2];
682  double PlotCoordinate[2];
683 
684  //Handle data objects and datasets
690 
691  //The data drawn within the axes. Each curve is one polydata.
692  //color is controlled by scalar data. The curves are appended
693  //together, possibly glyphed with point symbols.
700  void InitializeEntries();
701 
702  // Legends and plot symbols. The legend also keeps track of
703  // the symbols and such.
704  int Legend;
705  double LegendPosition[2];
706  double LegendPosition2[2];
710  double GlyphSize;
711 
712  // Background box
713  int ChartBox;
721 
722  // Reference lines
727 
731 
732  // Keep track of changes.
733  int CachedSize[2];
735 
736  void ComputeXRange(double range[2], double *lengths);
737  void ComputeYRange(double range[2]);
738  void ComputeDORange(double xrange[2], double yrange[2], double *lengths);
739 
740  virtual void CreatePlotData(int *pos, int *pos2, double xRange[2],
741  double yRange[2], double *norms,
742  int numDS, int numDO);
743  void PlaceAxes(vtkViewport *viewport, int *size, int pos[2], int pos2[2]);
744  void GenerateClipPlanes(int *pos, int *pos2);
745  double ComputeGlyphScale(int i, int *pos, int *pos2);
746  void ClipPlotData(int *pos, int *pos2, vtkPolyData *pd);
747  double *TransformPoint(int pos[2], int pos2[2], double x[3], double xNew[3]);
748 
749 private:
750  vtkXYPlotActor(const vtkXYPlotActor&); // Not implemented.
751  void operator=(const vtkXYPlotActor&); // Not implemented.
752 
753  bool DoesConnectionMatch(int i, vtkAlgorithmOutput* in);
754 
755  int IsInputPresent(vtkAlgorithmOutput* in,
756  const char* arrayName,
757  int component);
758 };
759 
760 
761 #endif