Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

Hybrid/vtkXYPlotActor.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkXYPlotActor.h,v $
00005   Language:  C++
00006 
00007   Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen 
00008   All rights reserved.
00009   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00010 
00011      This software is distributed WITHOUT ANY WARRANTY; without even 
00012      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00013      PURPOSE.  See the above copyright notice for more information.
00014 
00015 =========================================================================*/
00091 #ifndef __vtkXYPlotActor_h
00092 #define __vtkXYPlotActor_h
00093 
00094 #define VTK_XYPLOT_INDEX                 0
00095 #define VTK_XYPLOT_ARC_LENGTH            1
00096 #define VTK_XYPLOT_NORMALIZED_ARC_LENGTH 2
00097 #define VTK_XYPLOT_VALUE                 3
00098 
00099 #define VTK_XYPLOT_ROW 0
00100 #define VTK_XYPLOT_COLUMN 1
00101 
00102 #include "vtkActor2D.h"
00103 
00104 class vtkAppendPolyData;
00105 class vtkAxisActor2D;
00106 class vtkDataObject;
00107 class vtkDataObjectCollection;
00108 class vtkDataSet;
00109 class vtkDataSetCollection;
00110 class vtkGlyph2D;
00111 class vtkGlyphSource2D;
00112 class vtkIntArray;
00113 class vtkLegendBoxActor;
00114 class vtkPlanes;
00115 class vtkPolyData;
00116 class vtkPolyDataMapper2D;
00117 class vtkTextMapper;
00118 class vtkTextProperty;
00119 
00120 class VTK_HYBRID_EXPORT vtkXYPlotActor : public vtkActor2D
00121 {
00122 public:
00123   vtkTypeRevisionMacro(vtkXYPlotActor,vtkActor2D);
00124   void PrintSelf(ostream& os, vtkIndent indent);
00125 
00130   static vtkXYPlotActor *New();
00131 
00132   //---Data Set Input----------------------------------------------------------
00133   // The following methods are used to plot input datasets. Datasets
00134   // will be plotted if set as input; otherwise the input data objects
00135   // will be plotted (if defined).
00136   
00138 
00142   void AddInput(vtkDataSet *in, const char* arrayName, int component);
00143   void AddInput(vtkDataSet *in) {this->AddInput(in, NULL, 0);}
00145 
00147 
00148   void RemoveInput(vtkDataSet *in, const char* arrayName, int component);
00149   void RemoveInput(vtkDataSet *in) {this->RemoveInput(in, NULL, 0);}
00151 
00154   void RemoveAllInputs();
00155 
00157   vtkDataSetCollection *GetInputList() {return this->InputList;}
00158 
00160 
00163   void SetPointComponent(int i, int comp);
00164   int GetPointComponent(int i);
00165   //---end Data Set Input-----------------------------------------------------
00167 
00169 
00177   vtkSetClampMacro(XValues,int,VTK_XYPLOT_INDEX,VTK_XYPLOT_VALUE);
00178   vtkGetMacro(XValues,int);
00179   void SetXValuesToIndex(){this->SetXValues(VTK_XYPLOT_INDEX);};
00180   void SetXValuesToArcLength() {this->SetXValues(VTK_XYPLOT_ARC_LENGTH);};
00181   void SetXValuesToNormalizedArcLength()
00182     {this->SetXValues(VTK_XYPLOT_NORMALIZED_ARC_LENGTH);};
00183   void SetXValuesToValue() {this->SetXValues(VTK_XYPLOT_VALUE);};
00184   const char *GetXValuesAsString();
00186 
00187   //---Data Object Input------------------------------------------------------
00188   // The following methods are used to plot input data objects. Datasets will
00189   // be plotted in preference to data objects if set as input; otherwise the
00190   // input data objects will be plotted (if defined).
00191   
00193   void AddDataObjectInput(vtkDataObject *in);
00194 
00196   void RemoveDataObjectInput(vtkDataObject *in);
00197 
00199 
00200   vtkDataObjectCollection *GetDataObjectInputList() 
00201     {return this->DataObjectInputList;}
00203 
00205 
00207   vtkSetClampMacro(DataObjectPlotMode,int,VTK_XYPLOT_COLUMN,VTK_XYPLOT_ROW);
00208   vtkGetMacro(DataObjectPlotMode,int);
00209   void SetDataObjectPlotModeToRows()
00210     {this->SetDataObjectPlotMode(VTK_XYPLOT_ROW);}
00211   void SetDataObjectPlotModeToColumns()
00212     {this->SetDataObjectPlotMode(VTK_XYPLOT_COLUMN);}
00213   const char *GetDataObjectPlotModeAsString();
00215 
00217 
00223   void SetDataObjectXComponent(int i, int comp);
00224   int GetDataObjectXComponent(int i);
00226 
00228 
00234   void SetDataObjectYComponent(int i, int comp);
00235   int GetDataObjectYComponent(int i);
00236   //---end Data Object Input--------------------------------------------------
00238 
00239   //---Per Curve Properties---------------------------------------------------
00240   // The following methods are used to set properties on each curve that is
00241   // plotted. Each input dataset (or data object) results in one curve. The
00242   // methods that follow have an index i that corresponds to the input dataset
00243   // or data object. 
00244   void SetPlotColor(int i, float r, float g, float b);
00245   void SetPlotColor(int i, const float color[3]) {
00246     this->SetPlotColor(i, color[0], color[1], color[2]); };
00247   float *GetPlotColor(int i);
00248   void SetPlotSymbol(int i,vtkPolyData *input);
00249   vtkPolyData *GetPlotSymbol(int i);
00250   void SetPlotLabel(int i, const char *label);
00251   const char *GetPlotLabel(int i);
00252 
00253   // Allow per-curve specification of line and point rendering.  These override
00254   // global settings PlotPoints and PlotLines.  If not on, the default behavior
00255   // is governed by PlotPoints and PlotLines ivars.
00256   vtkGetMacro(PlotCurvePoints, int);
00257   vtkSetMacro(PlotCurvePoints, int);
00258   vtkBooleanMacro(PlotCurvePoints, int);
00259 
00260   vtkGetMacro(PlotCurveLines, int);
00261   vtkSetMacro(PlotCurveLines, int);
00262   vtkBooleanMacro(PlotCurveLines, int);
00263 
00264   void SetPlotLines(int i, int);
00265   int GetPlotLines(int i);
00266 
00267   void SetPlotPoints(int i, int);
00268   int GetPlotPoints(int i);
00269   //---end Per Curve Properties-----------------------------------------------
00270 
00272 
00274   vtkSetMacro(ExchangeAxes, int);
00275   vtkGetMacro(ExchangeAxes, int);
00276   vtkBooleanMacro(ExchangeAxes, int);
00278 
00280 
00284   vtkSetMacro(ReverseXAxis, int);
00285   vtkGetMacro(ReverseXAxis, int);
00286   vtkBooleanMacro(ReverseXAxis, int);
00288 
00290 
00294   vtkSetMacro(ReverseYAxis, int);
00295   vtkGetMacro(ReverseYAxis, int);
00296   vtkBooleanMacro(ReverseYAxis, int);
00298 
00300 
00304   vtkLegendBoxActor *GetLegendBoxActor()
00305     {return this->LegendActor;}
00306   vtkGlyphSource2D *GetGlyphSource()
00307     {return this->GlyphSource;}
00309 
00311 
00313   vtkSetStringMacro(Title);
00314   vtkGetStringMacro(Title);
00315   vtkSetStringMacro(XTitle);
00316   vtkGetStringMacro(XTitle);
00317   vtkSetStringMacro(YTitle);
00318   vtkGetStringMacro(YTitle);
00320 
00322 
00324   vtkAxisActor2D *GetXAxisActor2D()
00325     {return this->XAxis;}
00326   vtkAxisActor2D *GetYAxisActor2D()
00327     {return this->YAxis;}
00329 
00331 
00337   vtkSetVector2Macro(XRange,float);
00338   vtkGetVectorMacro(XRange,float,2);
00339   vtkSetVector2Macro(YRange,float);
00340   vtkGetVectorMacro(YRange,float,2);
00341   void SetPlotRange(float xmin, float ymin, float xmax, float ymax)
00342     {this->SetXRange(xmin,xmax); this->SetYRange(ymin,ymax);}
00344   
00346 
00351   vtkSetClampMacro(NumberOfXLabels, int, 0, 50);
00352   vtkGetMacro(NumberOfXLabels, int);
00353   vtkSetClampMacro(NumberOfYLabels, int, 0, 50);
00354   vtkGetMacro(NumberOfYLabels, int);
00355   void SetNumberOfLabels(int num)
00356     {this->SetNumberOfXLabels(num); this->SetNumberOfYLabels(num);}
00358   
00360 
00363   vtkSetMacro(Legend, int);
00364   vtkGetMacro(Legend, int);
00365   vtkBooleanMacro(Legend, int);
00367 
00369 
00375   vtkSetVector2Macro(LegendPosition,float);
00376   vtkGetVector2Macro(LegendPosition,float);
00377   vtkSetVector2Macro(LegendPosition2,float);
00378   vtkGetVector2Macro(LegendPosition2,float);
00380   
00382 
00383   virtual void SetTitleTextProperty(vtkTextProperty *p);
00384   vtkGetObjectMacro(TitleTextProperty,vtkTextProperty);
00386   
00388 
00390   virtual void SetAxisTitleTextProperty(vtkTextProperty *p);
00391   vtkGetObjectMacro(AxisTitleTextProperty,vtkTextProperty);
00393   
00395 
00397   virtual void SetAxisLabelTextProperty(vtkTextProperty *p);
00398   vtkGetObjectMacro(AxisLabelTextProperty,vtkTextProperty);
00400       
00401 #ifndef VTK_REMOVE_LEGACY_CODE
00402 
00403 
00407   virtual void SetFontFamily(int val);
00408   virtual int GetFontFamily();
00409   void SetFontFamilyToArial()   { this->SetFontFamily(VTK_ARIAL);  };
00410   void SetFontFamilyToCourier() { this->SetFontFamily(VTK_COURIER);};
00411   void SetFontFamilyToTimes()   { this->SetFontFamily(VTK_TIMES);  };
00413 #endif
00414 
00415 #ifndef VTK_REMOVE_LEGACY_CODE
00416 
00417 
00420   virtual void SetBold(int val);
00421   virtual int GetBold();
00422   vtkBooleanMacro(Bold, int);
00424 #endif
00425 
00426 #ifndef VTK_REMOVE_LEGACY_CODE
00427 
00428 
00431   virtual void SetItalic(int val);
00432   virtual int GetItalic();
00433   vtkBooleanMacro(Italic, int);
00435 #endif
00436 
00437 #ifndef VTK_REMOVE_LEGACY_CODE
00438 
00439 
00442   virtual void SetShadow(int val);
00443   virtual int GetShadow();
00444   vtkBooleanMacro(Shadow, int);
00446 #endif
00447 
00449 
00450   vtkSetMacro(Logx, int);
00451   vtkGetMacro(Logx, int);
00452   vtkBooleanMacro(Logx, int);
00454 
00456 
00457   virtual void SetLabelFormat (const char* _arg);
00458   vtkGetStringMacro(LabelFormat);
00460 
00462 
00464   vtkSetClampMacro(Border, int, 0, 50);
00465   vtkGetMacro(Border, int);
00467 
00469 
00472   vtkGetMacro(PlotPoints, int);
00473   vtkSetMacro(PlotPoints, int);
00474   vtkBooleanMacro(PlotPoints, int);
00476 
00478 
00480   vtkGetMacro(PlotLines, int);
00481   vtkSetMacro(PlotLines, int);
00482   vtkBooleanMacro(PlotLines, int);
00484   
00486 
00489   vtkSetClampMacro(GlyphSize, float, 0.0, 0.2);
00490   vtkGetMacro(GlyphSize, float);
00492 
00495   void ViewportToPlotCoordinate(vtkViewport *viewport, float &u, float &v);
00496 
00498 
00501   void ViewportToPlotCoordinate(vtkViewport *viewport);
00502   vtkSetVector2Macro(PlotCoordinate,float);
00503   vtkGetVector2Macro(PlotCoordinate,float);
00505 
00507   void PlotToViewportCoordinate(vtkViewport *viewport, float &u, float &v);
00508 
00510 
00514   void PlotToViewportCoordinate(vtkViewport *viewport);
00515   vtkSetVector2Macro(ViewportCoordinate,float);
00516   vtkGetVector2Macro(ViewportCoordinate,float);
00518 
00521   int IsInPlot(vtkViewport *viewport, float u, float v);
00522   
00524   unsigned long GetMTime();
00525   
00526 //BTX  
00528 
00530   int RenderOpaqueGeometry(vtkViewport*);
00531   int RenderOverlay(vtkViewport*);
00532   int RenderTranslucentGeometry(vtkViewport *) {return 0;}
00534 
00538   void ReleaseGraphicsResources(vtkWindow *);
00539 //ETX  
00540 
00541 protected:
00542   vtkXYPlotActor();
00543   ~vtkXYPlotActor();
00544 
00545   vtkDataSetCollection *InputList; //list of data sets to plot
00546   char** SelectedInputScalars; // list of data set arrays to plot
00547   vtkIntArray* SelectedInputScalarsComponent; // list of componenents
00548   vtkDataObjectCollection *DataObjectInputList; //list of data objects to plot
00549   char  *Title;
00550   char  *XTitle;
00551   char  *YTitle;
00552   int   XValues;
00553   int   NumberOfXLabels;
00554   int   NumberOfYLabels;
00555   int   Logx;
00556   char  *LabelFormat;
00557   float XRange[2];
00558   float YRange[2];
00559   float XComputedRange[2];  //range actually used by plot
00560   float YComputedRange[2];  //range actually used by plot
00561   int Border;
00562   int PlotLines;
00563   int PlotPoints;
00564   int PlotCurveLines;
00565   int PlotCurvePoints;
00566   int ExchangeAxes;
00567   int ReverseXAxis;
00568   int ReverseYAxis;
00569   
00570   vtkTextMapper   *TitleMapper;
00571   vtkActor2D      *TitleActor;
00572   vtkTextProperty *TitleTextProperty;
00573 
00574   vtkAxisActor2D      *XAxis;
00575   vtkAxisActor2D      *YAxis;
00576 
00577   vtkTextProperty *AxisTitleTextProperty;
00578   vtkTextProperty *AxisLabelTextProperty;
00579 
00580   float ViewportCoordinate[2];
00581   float PlotCoordinate[2];
00582   
00583   //Handle data objects and datasets
00584   int DataObjectPlotMode;
00585   vtkIntArray *XComponent;
00586   vtkIntArray *YComponent;
00587   vtkIntArray *LinesOn;
00588   vtkIntArray *PointsOn;
00589 
00590   //The data drawn within the axes. Each curve is one polydata.
00591   //color is controlled by scalar data. The curves are appended
00592   //together, possibly glyphed with point symbols.
00593   int NumberOfInputs;
00594   vtkPolyData             **PlotData; 
00595   vtkGlyph2D              **PlotGlyph;
00596   vtkAppendPolyData       **PlotAppend;
00597   vtkPolyDataMapper2D     **PlotMapper;
00598   vtkActor2D              **PlotActor;
00599   void                    InitializeEntries();
00600   
00601   // Legends and plot symbols. The legend also keeps track of
00602   // the symbols and such.
00603   int Legend;
00604   float LegendPosition[2];
00605   float LegendPosition2[2];
00606   vtkLegendBoxActor *LegendActor;
00607   vtkGlyphSource2D *GlyphSource;
00608   vtkPlanes *ClipPlanes;
00609   float GlyphSize;
00610 
00611   // Keep track of changes.
00612   int CachedSize[2];
00613   vtkTimeStamp  BuildTime;
00614 
00615   void ComputeXRange(float range[2], float *lengths);
00616   void ComputeYRange(float range[2]);
00617   void ComputeDORange(float xrange[2], float yrange[2], float *lengths);
00618 
00619   virtual void CreatePlotData(int *pos, int *pos2, float xRange[2], 
00620                               float yRange[2], float *norms, 
00621                               int numDS, int numDO);
00622   void PlaceAxes(vtkViewport *viewport, int *size, int pos[2], int pos2[2]);
00623   void GenerateClipPlanes(int *pos, int *pos2);
00624   float ComputeGlyphScale(int i, int *pos, int *pos2);
00625   void ClipPlotData(int *pos, int *pos2, vtkPolyData *pd);
00626   float *TransformPoint(int pos[2], int pos2[2], float x[3], float xNew[3]);
00627   
00628 private:
00629   vtkXYPlotActor(const vtkXYPlotActor&);  // Not implemented.
00630   void operator=(const vtkXYPlotActor&);  // Not implemented.
00631 };
00632 
00633 
00634 #endif
00635