VTK
dox/Rendering/Annotation/vtkXYPlotActor.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkXYPlotActor.h
00005 
00006   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00007   All rights reserved.
00008   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00009 
00010      This software is distributed WITHOUT ANY WARRANTY; without even
00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012      PURPOSE.  See the above copyright notice for more information.
00013 
00014 =========================================================================*/
00093 #ifndef __vtkXYPlotActor_h
00094 #define __vtkXYPlotActor_h
00095 
00096 #define VTK_XYPLOT_INDEX                 0
00097 #define VTK_XYPLOT_ARC_LENGTH            1
00098 #define VTK_XYPLOT_NORMALIZED_ARC_LENGTH 2
00099 #define VTK_XYPLOT_VALUE                 3
00100 
00101 #define VTK_XYPLOT_ROW 0
00102 #define VTK_XYPLOT_COLUMN 1
00103 
00104 #define VTK_XYPLOT_Y_AXIS_TOP     0
00105 #define VTK_XYPLOT_Y_AXIS_HCENTER 1
00106 #define VTK_XYPLOT_Y_AXIS_VCENTER 2 // rotate by 90 degrees (y-axis aligned)
00107 
00108 #include "vtkRenderingAnnotationModule.h" // For export macro
00109 #include "vtkActor2D.h"
00110 #include <vtkSmartPointer.h> // For SP
00111 
00112 class vtkXYPlotActorConnections;
00113 class vtkAlgorithmOutput;
00114 class vtkAppendPolyData;
00115 class vtkAxisActor2D;
00116 class vtkDataObject;
00117 class vtkDataObjectCollection;
00118 class vtkDataSet;
00119 class vtkDataSetCollection;
00120 class vtkDoubleArray;
00121 class vtkGlyph2D;
00122 class vtkGlyphSource2D;
00123 class vtkIntArray;
00124 class vtkLegendBoxActor;
00125 class vtkPlanes;
00126 class vtkPolyData;
00127 class vtkPolyDataMapper2D;
00128 class vtkTextActor;
00129 class vtkTextMapper;
00130 class vtkTextProperty;
00131 
00132 class VTKRENDERINGANNOTATION_EXPORT vtkXYPlotActor : public vtkActor2D
00133 {
00134 public:
00135   vtkTypeMacro(vtkXYPlotActor,vtkActor2D);
00136   void PrintSelf(ostream& os, vtkIndent indent);
00137 
00142   static vtkXYPlotActor *New();
00143 
00144   //---Data Set Input----------------------------------------------------------
00145   // The following methods are used to plot input datasets. Datasets
00146   // will be plotted if set as input; otherwise the input data objects
00147   // will be plotted (if defined).
00148 
00150 
00156   void AddDataSetInput(vtkDataSet *ds, const char* arrayName, int component);
00157   void AddDataSetInput(vtkDataSet *ds) {this->AddDataSetInput(ds, NULL, 0);}
00158   void AddDataSetInputConnection(vtkAlgorithmOutput *in, const char* arrayName, int component);
00159   void AddDataSetInputConnection(vtkAlgorithmOutput *in) {this->AddDataSetInputConnection(in, NULL, 0);}
00161 
00163 
00164   void RemoveDataSetInput(vtkDataSet *ds, const char* arrayName, int component);
00165   void RemoveDataSetInput(vtkDataSet *ds) {this->RemoveDataSetInput(ds, NULL, 0);}
00166   void RemoveDataSetInputConnection(vtkAlgorithmOutput *in, const char* arrayName, int component);
00167   void RemoveDataSetInputConnection(vtkAlgorithmOutput *in)
00168   {
00169     this->RemoveDataSetInputConnection(in, NULL, 0);
00170   }
00172 
00175   void RemoveAllDataSetInputConnections();
00176 
00178 
00181   void SetPointComponent(int i, int comp);
00182   int GetPointComponent(int i);
00183   //---end Data Set Input-----------------------------------------------------
00185 
00187 
00195   vtkSetClampMacro(XValues,int,VTK_XYPLOT_INDEX,VTK_XYPLOT_VALUE);
00196   vtkGetMacro(XValues,int);
00197   void SetXValuesToIndex(){this->SetXValues(VTK_XYPLOT_INDEX);};
00198   void SetXValuesToArcLength() {this->SetXValues(VTK_XYPLOT_ARC_LENGTH);};
00199   void SetXValuesToNormalizedArcLength()
00200     {this->SetXValues(VTK_XYPLOT_NORMALIZED_ARC_LENGTH);};
00201   void SetXValuesToValue() {this->SetXValues(VTK_XYPLOT_VALUE);};
00202   const char *GetXValuesAsString();
00204 
00205   //---Data Object Input------------------------------------------------------
00206   // The following methods are used to plot input data objects. Datasets will
00207   // be plotted in preference to data objects if set as input; otherwise the
00208   // input data objects will be plotted (if defined).
00209 
00211 
00212   void AddDataObjectInput(vtkDataObject *in);
00213   void AddDataObjectInputConnection(vtkAlgorithmOutput *alg);
00215 
00217 
00218   void RemoveDataObjectInputConnection(vtkAlgorithmOutput *aout);
00219   void RemoveDataObjectInput(vtkDataObject *in);
00221 
00223 
00225   vtkSetClampMacro(DataObjectPlotMode,int,VTK_XYPLOT_ROW,VTK_XYPLOT_COLUMN);
00226   vtkGetMacro(DataObjectPlotMode,int);
00227   void SetDataObjectPlotModeToRows()
00228     {this->SetDataObjectPlotMode(VTK_XYPLOT_ROW);}
00229   void SetDataObjectPlotModeToColumns()
00230     {this->SetDataObjectPlotMode(VTK_XYPLOT_COLUMN);}
00231   const char *GetDataObjectPlotModeAsString();
00233 
00235 
00241   void SetDataObjectXComponent(int i, int comp);
00242   int GetDataObjectXComponent(int i);
00244 
00246 
00252   void SetDataObjectYComponent(int i, int comp);
00253   int GetDataObjectYComponent(int i);
00254   //---end Data Object Input--------------------------------------------------
00256 
00257   //---Per Curve Properties---------------------------------------------------
00258   // The following methods are used to set properties on each curve that is
00259   // plotted. Each input dataset (or data object) results in one curve. The
00260   // methods that follow have an index i that corresponds to the input dataset
00261   // or data object.
00262   void SetPlotColor(int i, double r, double g, double b);
00263   void SetPlotColor(int i, const double color[3]) {
00264     this->SetPlotColor(i, color[0], color[1], color[2]); };
00265   double *GetPlotColor(int i);
00266   void SetPlotSymbol(int i,vtkPolyData *input);
00267   vtkPolyData *GetPlotSymbol(int i);
00268   void SetPlotLabel(int i, const char *label);
00269   const char *GetPlotLabel(int i);
00270 
00271   // Allow per-curve specification of line and point rendering.  These override
00272   // global settings PlotPoints and PlotLines.  If not on, the default behavior
00273   // is governed by PlotPoints and PlotLines ivars.
00274   vtkGetMacro(PlotCurvePoints, int);
00275   vtkSetMacro(PlotCurvePoints, int);
00276   vtkBooleanMacro(PlotCurvePoints, int);
00277 
00278   vtkGetMacro(PlotCurveLines, int);
00279   vtkSetMacro(PlotCurveLines, int);
00280   vtkBooleanMacro(PlotCurveLines, int);
00281 
00282   void SetPlotLines(int i, int);
00283   int GetPlotLines(int i);
00284 
00285   void SetPlotPoints(int i, int);
00286   int GetPlotPoints(int i);
00287   //---end Per Curve Properties-----------------------------------------------
00288 
00290 
00292   vtkSetMacro(ExchangeAxes, int);
00293   vtkGetMacro(ExchangeAxes, int);
00294   vtkBooleanMacro(ExchangeAxes, int);
00296 
00298 
00302   vtkSetMacro(ReverseXAxis, int);
00303   vtkGetMacro(ReverseXAxis, int);
00304   vtkBooleanMacro(ReverseXAxis, int);
00306 
00308 
00312   vtkSetMacro(ReverseYAxis, int);
00313   vtkGetMacro(ReverseYAxis, int);
00314   vtkBooleanMacro(ReverseYAxis, int);
00316 
00318 
00322   vtkGetObjectMacro(LegendActor,vtkLegendBoxActor);
00323   vtkGetObjectMacro(GlyphSource,vtkGlyphSource2D);
00325 
00327 
00328   vtkSetStringMacro(Title);
00329   vtkGetStringMacro(Title);
00331 
00333 
00334   vtkSetStringMacro(XTitle);
00335   vtkGetStringMacro(XTitle);
00337 
00339 
00340   virtual void SetYTitle( const char* );
00341   char* GetYTitle();
00343 
00345 
00347   vtkAxisActor2D *GetXAxisActor2D()
00348     {
00349     return this->XAxis;
00350     }
00351   vtkAxisActor2D *GetYAxisActor2D()
00352     {
00353     return this->YAxis;
00354     }
00356 
00358 
00364   vtkSetVector2Macro(XRange,double);
00365   vtkGetVectorMacro(XRange,double,2);
00366   vtkSetVector2Macro(YRange,double);
00367   vtkGetVectorMacro(YRange,double,2);
00368   void SetPlotRange(double xmin, double ymin, double xmax, double ymax)
00369     {this->SetXRange(xmin,xmax); this->SetYRange(ymin,ymax);}
00371 
00373 
00378   vtkSetClampMacro(NumberOfXLabels, int, 0, 50);
00379   vtkGetMacro(NumberOfXLabels, int);
00380   vtkSetClampMacro(NumberOfYLabels, int, 0, 50);
00381   vtkGetMacro(NumberOfYLabels, int);
00382   void SetNumberOfLabels(int num)
00383     {this->SetNumberOfXLabels(num); this->SetNumberOfYLabels(num);}
00385 
00387 
00392   void SetAdjustXLabels(int adjust);
00393   vtkGetMacro( AdjustXLabels, int );
00394   void SetAdjustYLabels(int adjust);
00395   vtkGetMacro( AdjustYLabels, int );
00397 
00399 
00400   void SetNumberOfXMinorTicks(int num);
00401   int GetNumberOfXMinorTicks();
00402   void SetNumberOfYMinorTicks(int num);
00403   int GetNumberOfYMinorTicks();
00405 
00407 
00410   vtkSetMacro(Legend, int);
00411   vtkGetMacro(Legend, int);
00412   vtkBooleanMacro(Legend, int);
00414 
00416 
00418   vtkSetVector2Macro(TitlePosition,double);
00419   vtkGetVector2Macro(TitlePosition,double);
00421 
00423 
00425   vtkSetMacro(AdjustTitlePosition, int);
00426   vtkGetMacro(AdjustTitlePosition, int);
00427   vtkBooleanMacro(AdjustTitlePosition, int);
00429 
00430 //BTX
00431 enum Alignment {
00432   AlignLeft = 0x1,
00433   AlignRight = 0x2,
00434   AlignHCenter = 0x4,
00435   AlignTop = 0x10,
00436   AlignBottom = 0x20,
00437   AlignVCenter = 0x40,
00438   AlignAxisLeft = 0x100,
00439   AlignAxisRight = 0x200,
00440   AlignAxisHCenter = 0x400,
00441   AlignAxisTop = 0x1000,
00442   AlignAxisBottom = 0x2000,
00443   AlignAxisVCenter = 0x4000
00444 };
00445 //ETX
00447 
00452   vtkSetMacro(AdjustTitlePositionMode, int);
00453   vtkGetMacro(AdjustTitlePositionMode, int);
00455 
00457 
00463   vtkSetVector2Macro(LegendPosition,double);
00464   vtkGetVector2Macro(LegendPosition,double);
00465   vtkSetVector2Macro(LegendPosition2,double);
00466   vtkGetVector2Macro(LegendPosition2,double);
00468 
00470 
00471   virtual void SetTitleTextProperty(vtkTextProperty *p);
00472   vtkGetObjectMacro(TitleTextProperty,vtkTextProperty);
00474 
00476 
00478   virtual void SetAxisTitleTextProperty(vtkTextProperty *p);
00479   vtkGetObjectMacro(AxisTitleTextProperty,vtkTextProperty);
00481 
00483 
00485   virtual void SetAxisLabelTextProperty(vtkTextProperty *p);
00486   vtkGetObjectMacro(AxisLabelTextProperty,vtkTextProperty);
00488 
00490 
00491   vtkSetMacro(Logx, int);
00492   vtkGetMacro(Logx, int);
00493   vtkBooleanMacro(Logx, int);
00495 
00497 
00499   virtual void SetLabelFormat ( const char* );
00500   const char* GetLabelFormat()
00501     {
00502     return this->GetXLabelFormat();
00503     }
00505 
00507 
00508   virtual void SetXLabelFormat ( const char* );
00509   vtkGetStringMacro(XLabelFormat);
00511 
00513 
00514   virtual void SetYLabelFormat ( const char* );
00515   vtkGetStringMacro(YLabelFormat);
00517 
00519 
00521   vtkSetClampMacro(Border, int, 0, 50);
00522   vtkGetMacro(Border, int);
00524 
00526 
00529   vtkGetMacro(PlotPoints, int);
00530   vtkSetMacro(PlotPoints, int);
00531   vtkBooleanMacro(PlotPoints, int);
00533 
00535 
00537   vtkGetMacro(PlotLines, int);
00538   vtkSetMacro(PlotLines, int);
00539   vtkBooleanMacro(PlotLines, int);
00541 
00543 
00546   vtkSetClampMacro(GlyphSize, double, 0.0, 0.2);
00547   vtkGetMacro(GlyphSize, double);
00549 
00552   void ViewportToPlotCoordinate(vtkViewport *viewport, double &u, double &v);
00553 
00555 
00558   void ViewportToPlotCoordinate(vtkViewport *viewport);
00559   vtkSetVector2Macro(PlotCoordinate,double);
00560   vtkGetVector2Macro(PlotCoordinate,double);
00562 
00564   void PlotToViewportCoordinate(vtkViewport *viewport, double &u, double &v);
00565 
00567 
00571   void PlotToViewportCoordinate(vtkViewport *viewport);
00572   vtkSetVector2Macro(ViewportCoordinate,double);
00573   vtkGetVector2Macro(ViewportCoordinate,double);
00575 
00578   int IsInPlot(vtkViewport *viewport, double u, double v);
00579 
00581 
00583   vtkSetMacro(ChartBox, int);
00584   vtkGetMacro(ChartBox, int);
00585   vtkBooleanMacro(ChartBox, int);
00587 
00589 
00591   vtkSetMacro(ChartBorder, int);
00592   vtkGetMacro(ChartBorder, int);
00593   vtkBooleanMacro(ChartBorder, int);
00595 
00597   vtkProperty2D* GetChartBoxProperty() { return this->ChartBoxActor->GetProperty(); };
00598 
00600 
00601   vtkSetMacro(ShowReferenceXLine, int);
00602   vtkGetMacro(ShowReferenceXLine, int);
00603   vtkBooleanMacro(ShowReferenceXLine, int);
00605 
00607 
00608   vtkSetMacro(ReferenceXValue, double);
00609   vtkGetMacro(ReferenceXValue, double);
00611 
00613 
00614   vtkSetMacro(ShowReferenceYLine, int);
00615   vtkGetMacro(ShowReferenceYLine, int);
00616   vtkBooleanMacro(ShowReferenceYLine, int);
00618 
00620 
00621   vtkSetMacro(ReferenceYValue, double);
00622   vtkGetMacro(ReferenceYValue, double);
00624 
00626   unsigned long GetMTime();
00627 
00630   void PrintAsCSV(ostream &os);
00631 
00632 //BTX
00634 
00636   int RenderOpaqueGeometry(vtkViewport*);
00637   int RenderOverlay(vtkViewport*);
00638   virtual int RenderTranslucentPolygonalGeometry(vtkViewport *) {return 0;}
00640 
00642   virtual int HasTranslucentPolygonalGeometry();
00643 
00645 
00648   void ReleaseGraphicsResources(vtkWindow *);
00649 //ETX
00651 
00653 
00654   void SetXTitlePosition(double position);
00655   double GetXTitlePosition();
00657 
00659 
00660   vtkSetMacro(YTitlePosition,int);
00661   vtkGetMacro(YTitlePosition,int);
00662   void SetYTitlePositionToTop()
00663   {
00664     this->SetYTitlePosition( VTK_XYPLOT_Y_AXIS_TOP );
00665   }
00666   void SetYTitlePositionToHCenter()
00667   {
00668     this->SetYTitlePosition( VTK_XYPLOT_Y_AXIS_HCENTER );
00669   }
00670   void SetYTitlePositionToVCenter()
00671   {
00672     this->SetYTitlePosition( VTK_XYPLOT_Y_AXIS_VCENTER );
00673   }
00675 
00677 
00678   virtual void SetPlotGlyphType( int, int );
00679   virtual void SetLineWidth( double );
00680   virtual void AddUserCurvesPoint( double, double, double );
00681   virtual void RemoveAllActiveCurves();
00683 
00685 
00686   virtual void SetLegendBorder( int );
00687   virtual void SetLegendBox( int );
00688   virtual void SetLegendUseBackground( int );
00689   virtual void SetLegendBackgroundColor( double, double, double );
00691 
00693 
00694   virtual void SetTitleColor( double, double, double );
00695   virtual void SetTitleFontFamily( int );
00696   virtual void SetTitleBold( int );
00697   virtual void SetTitleItalic( int );
00698   virtual void SetTitleShadow( int );
00699   virtual void SetTitleFontSize( int );
00700   virtual void SetTitleJustification( int );
00701   virtual void SetTitleVerticalJustification( int );
00703 
00705 
00706   virtual void SetXAxisColor( double, double, double );
00707   virtual void SetYAxisColor( double, double, double );
00709 
00711 
00712   virtual void SetAxisTitleColor( double, double, double );
00713   virtual void SetAxisTitleFontFamily( int );
00714   virtual void SetAxisTitleBold( int );
00715   virtual void SetAxisTitleItalic( int );
00716   virtual void SetAxisTitleShadow( int );
00717   virtual void SetAxisTitleFontSize( int );
00718   virtual void SetAxisTitleJustification( int );
00719   virtual void SetAxisTitleVerticalJustification( int );
00721 
00723 
00724   virtual void SetAxisLabelColor( double, double, double );
00725   virtual void SetAxisLabelFontFamily( int );
00726   virtual void SetAxisLabelBold( int );
00727   virtual void SetAxisLabelItalic( int );
00728   virtual void SetAxisLabelShadow( int );
00729   virtual void SetAxisLabelFontSize( int );
00730   virtual void SetAxisLabelJustification( int );
00731   virtual void SetAxisLabelVerticalJustification( int );
00733 
00734 protected:
00735   vtkXYPlotActor();
00736   ~vtkXYPlotActor();
00737 
00738   vtkXYPlotActorConnections* InputConnectionHolder;
00739   char** SelectedInputScalars; // list of data set arrays to plot
00740   vtkIntArray* SelectedInputScalarsComponent; // list of components
00741   vtkXYPlotActorConnections *DataObjectInputConnectionHolder; //list of data objects to plot
00742   char*  Title;
00743   char*  XTitle;
00744   vtkTextActor* YTitleActor;
00745   int   XValues;
00746   int   NumberOfXLabels;
00747   int   NumberOfYLabels;
00748   int   Logx;
00749   char* XLabelFormat;
00750   char* YLabelFormat;
00751   double XRange[2];
00752   double YRange[2];
00753   double XComputedRange[2];  //range actually used by plot
00754   double YComputedRange[2];  //range actually used by plot
00755   int Border;
00756   int PlotLines;
00757   int PlotPoints;
00758   int PlotCurveLines;
00759   int PlotCurvePoints;
00760   int ExchangeAxes;
00761   int ReverseXAxis;
00762   int ReverseYAxis;
00763   int AdjustXLabels;
00764   int AdjustYLabels;
00765   int AdjustTitlePosition;
00766   double TitlePosition[2];
00767   int AdjustTitlePositionMode;
00768 
00769   vtkTextMapper*   TitleMapper;
00770   vtkActor2D*      TitleActor;
00771   vtkTextProperty* TitleTextProperty;
00772 
00773   vtkAxisActor2D*  XAxis;
00774   vtkAxisActor2D*  YAxis;
00775 
00776   vtkTextProperty* AxisTitleTextProperty;
00777   vtkTextProperty* AxisLabelTextProperty;
00778 
00779   double ViewportCoordinate[2];
00780   double PlotCoordinate[2];
00781 
00782   //Handle data objects and datasets
00783   int DataObjectPlotMode;
00784   vtkIntArray* XComponent;
00785   vtkIntArray* YComponent;
00786   vtkIntArray* LinesOn;
00787   vtkIntArray* PointsOn;
00788 
00789   //The data drawn within the axes. Each curve is one polydata.
00790   //color is controlled by scalar data. The curves are appended
00791   //together, possibly glyphed with point symbols.
00792   int NumberOfInputs;
00793   vtkPolyData             **PlotData;
00794   vtkGlyph2D              **PlotGlyph;
00795   vtkAppendPolyData       **PlotAppend;
00796   vtkPolyDataMapper2D     **PlotMapper;
00797   vtkActor2D              **PlotActor;
00798   void                    InitializeEntries();
00799 
00800   // Legends and plot symbols. The legend also keeps track of
00801   // the symbols and such.
00802   int Legend;
00803   double LegendPosition[2];
00804   double LegendPosition2[2];
00805   vtkLegendBoxActor *LegendActor;
00806   vtkGlyphSource2D *GlyphSource;
00807   vtkPlanes *ClipPlanes;
00808   double GlyphSize;
00809 
00810   // Background box
00811   int ChartBox;
00812   vtkPolyData                *ChartBoxPolyData;
00813   vtkPolyDataMapper2D        *ChartBoxMapper;
00814   vtkActor2D                 *ChartBoxActor;
00815   int ChartBorder;
00816   vtkPolyData                *ChartBorderPolyData;
00817   vtkPolyDataMapper2D        *ChartBorderMapper;
00818   vtkActor2D                 *ChartBorderActor;
00819 
00820   // Reference lines
00821   int ShowReferenceXLine;
00822   int ShowReferenceYLine;
00823   double ReferenceXValue;
00824   double ReferenceYValue;
00825 
00826   vtkPolyData                *ReferenceLinesPolyData;
00827   vtkPolyDataMapper2D        *ReferenceLinesMapper;
00828   vtkActor2D                 *ReferenceLinesActor;
00829 
00830   // Keep track of changes.
00831   int CachedSize[2];
00832   vtkTimeStamp  BuildTime;
00833 
00834   void ComputeXRange(double range[2], double *lengths);
00835   void ComputeYRange(double range[2]);
00836   void ComputeDORange(double xrange[2], double yrange[2], double *lengths);
00837 
00838   virtual void CreatePlotData(int *pos, int *pos2, double xRange[2],
00839                               double yRange[2], double *norms,
00840                               int numDS, int numDO);
00841   void PlaceAxes(vtkViewport *viewport, int *size, int pos[2], int pos2[2]);
00842   void GenerateClipPlanes(int *pos, int *pos2);
00843   double ComputeGlyphScale(int i, int *pos, int *pos2);
00844   void ClipPlotData(int *pos, int *pos2, vtkPolyData *pd);
00845   double *TransformPoint(int pos[2], int pos2[2], double x[3], double xNew[3]);
00846 
00847 //BTX
00848   vtkSmartPointer<vtkDoubleArray> ActiveCurve;
00849 //ETX
00850   int YAxisTitleSize;
00851   int ActiveCurveIndex;
00852   int PlotColorIndex;
00853 
00854 private:
00855   vtkXYPlotActor(const vtkXYPlotActor&);  // Not implemented.
00856   void operator=(const vtkXYPlotActor&);  // Not implemented.
00857 
00858   bool DoesConnectionMatch(int i, vtkAlgorithmOutput* in);
00859 
00860   int IsInputPresent(vtkAlgorithmOutput* in,
00861                      const char* arrayName,
00862                      int component);
00863 
00865   int YTitleSize[2];
00866 
00868   int YTitlePosition;
00869 
00871 
00872   int YTitleDelta;
00873 };
00875 
00876 
00877 #endif