1 #ifndef VISU_XYPLOTACTOR_HXX_
2 #define VISU_XYPLOTACTOR_HXX_
4 #include "VISUPipeline.hxx"
6 /*=========================================================================
8 Program: Visualization Toolkit
11 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
13 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
15 This software is distributed WITHOUT ANY WARRANTY; without even
16 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
17 PURPOSE. See the above copyright notice for more information.
19 =========================================================================*/
20 // .NAME vtkXYPlotActor - generate an x-y plot from input dataset(s) or field data
21 // .SECTION Description
22 // vtkXYPlotActor creates an x-y plot of data from one or more input data
23 // sets or field data. The class plots dataset scalar values (y-axis) against
24 // the points (x-axis). The x-axis values are generated by taking the point
25 // ids, computing a cumulative arc length, or a normalized arc length. More
26 // than one input data set can be specified to generate multiple plots.
27 // Alternatively, if field data is supplied as input, the class plots one
28 // component against another. (The user must specify which component to use
29 // as the x-axis and which for the y-axis.)
31 // To use this class to plot dataset(s), you must specify one or more
32 // input datasets containing scalar and point data. You'll probably also
33 // want to invoke a method to control how the point coordinates are converted
34 // into x values (by default point ids are used).
36 // To use this class to plot field data, you must specify one or more input
37 // data objects with its associated field data. You'll also want to specify
38 // which component to use as the x-axis and which to use as the y-axis.
39 // Note that when plotting field data, the x and y values are used directly
40 // (i.e., there are no options to normalize the components).
42 // Once you've set up the plot, you'll want to position it. The
43 // PositionCoordinate defines the lower-left location of the x-y plot
44 // (specified in normalized viewport coordinates) and the Position2Coordinate
45 // define the upper-right corner. (Note: the Position2Coordinate is relative
46 // to PositionCoordinate, so you can move the vtkXYPlotActor around the
47 // viewport by setting just the PositionCoordinate.) The combination of the
48 // two position coordinates specifies a rectangle in which the plot will lie.
50 // Optional features include the ability to specify axes labels, label
51 // format and plot title. You can also
52 // manually specify the x and y plot ranges (by default they are computed
53 // automatically). The Border instance variable is used to create space
54 // between the boundary of the plot window (specified by PositionCoordinate
55 // and Position2Coordinate) and the plot itself.
57 // The font property of the plot title can be modified through the
58 // TitleTextProperty attribute.
59 // The font property of the axes titles and labels can be modified through the
60 // AxisTitleTextProperty and AxisLabelTextProperty attributes. You may also
61 // use the GetXAxisActor2D or GetYAxisActor2D methods
62 // to access each individual axis actor to modify their font properties.
63 // In the same way, the GetLegendBoxActor method can be used to access
64 // the legend box actor to modify its font properties.
66 // There are several advanced features as well. You can assign per curve
67 // properties (such as color and a plot symbol). (Note that each input
68 // dataset and/or data object creates a single curve.) Another option is to
69 // add a plot legend that graphically indicates the correspondance between
70 // the curve, curve symbols, and the data source. You can also exchange the
71 // x and y axes if you prefer you plot orientation that way.
74 // If you are interested in plotting something other than scalar data, you
75 // can use the vtk data shuffling filters (e.g.,
76 // vtkAttributeDataToFieldDataFilter and vtkFieldDataToAttributeDataFilter)
77 // to convert the data into scalar data and/or points.
80 // vtkActor2D vtkTextMapper vtkScalarBarActor vtkAxisActor2D vtkCubeAxesActor2D
81 // vtkAttributeDataToFieldDataFilter vtkFieldDataToAttributeDataFilter
84 #include "vtkActor2D.h"
85 #include "vtkTransformPolyDataFilter.h" // RKV
87 #define VTK_XYPLOT_INDEX 0
88 #define VTK_XYPLOT_ARC_LENGTH 1
89 #define VTK_XYPLOT_NORMALIZED_ARC_LENGTH 2
90 #define VTK_XYPLOT_VALUE 3
92 #define VTK_XYPLOT_ROW 0
93 #define VTK_XYPLOT_COLUMN 1
95 class vtkAppendPolyData;
98 class vtkDataObjectCollection;
100 class vtkDataSetCollection;
102 class vtkGlyphSource2D;
104 class vtkLegendBoxActor;
107 class vtkPolyDataMapper2D;
109 class vtkTextProperty;
112 /** Location of the actor in the viewport.
113 * Axes and a curve is plotted according to the selected side.
114 * Axes origin is plotted at:
115 * VISU_XYPLOT_BOTTOM - the left bottom corner,
116 * VISU_XYPLOT_TOP - the left upper corner (Y axis is directed to the bottom),
117 * VISU_XYPLOT_LEFT - the left bottom corner (axes are exchanged),
118 * VISU_XYPLOT_RIGHT - the right bottom corner (X axis is directed to the top, Y - to the left)
120 enum VISU_XYPlotLocation { VISU_XYPLOT_BOTTOM = 0,
121 VISU_XYPLOT_TOP, VISU_XYPLOT_LEFT, VISU_XYPLOT_RIGHT };
124 class VISU_PIPELINE_EXPORT VISU_XYPlotActor : public vtkActor2D
127 vtkTypeRevisionMacro(VISU_XYPlotActor,vtkActor2D);
128 void PrintSelf(ostream& os, vtkIndent indent);
131 // Instantiate object with autorange computation; bold, italic, and shadows
132 // on; arial font family; the number of labels set to 5 for the x and y
133 // axes; a label format of "%-#6.3g"; and x coordinates computed from point
135 static VISU_XYPlotActor *New();
137 //---Data Set Input----------------------------------------------------------
138 // The following methods are used to plot input datasets. Datasets
139 // will be plotted if set as input; otherwise the input data objects
140 // will be plotted (if defined).
143 // Add a dataset to the list of data to append. The array name specifies
144 // which point array to plot. If the array name is NULL, then the default
145 // scalars are used. The array can have multiple components, but only the
146 // first component is ploted.
147 void AddInput(vtkDataSet *in, const char* arrayName, int component);
148 void AddInput(vtkDataSet *in) {this->AddInput(in, NULL, 0);}
151 // Remove a dataset from the list of data to append.
152 void RemoveInput(vtkDataSet *in, const char* arrayName, int component);
153 void RemoveInput(vtkDataSet *in) {this->RemoveInput(in, NULL, 0);}
156 // This removes all of the data set inputs,
157 // but does not change the data object inputs.
158 void RemoveAllInputs();
161 // Return the list of inputs to this filter.
162 vtkDataSetCollection *GetInputList() {return this->InputList;}
165 // If plotting points by value, which component to use to determine the
166 // value. This sets a value per each input dataset (i.e., the ith dataset).
167 void SetPointComponent(int i, int comp);
168 int GetPointComponent(int i);
169 //---end Data Set Input-----------------------------------------------------
172 // Specify how the independent (x) variable is computed from the points.
173 // The independent variable can be the scalar/point index (i.e., point id),
174 // the accumulated arc length along the points, the normalized arc length,
175 // or by component value. If plotting datasets (e.g., points), the value
176 // that is used is specified by the PointComponent ivar. (Note: these
177 // methods also control how field data is plotted. Field data is usually
178 // plotted by value or index, if plotting length 1-dimensional length
179 // measures are used.)
180 vtkSetClampMacro(XValues,int,VTK_XYPLOT_INDEX,VTK_XYPLOT_VALUE);
181 vtkGetMacro(XValues,int);
182 void SetXValuesToIndex(){this->SetXValues(VTK_XYPLOT_INDEX);};
183 void SetXValuesToArcLength() {this->SetXValues(VTK_XYPLOT_ARC_LENGTH);};
184 void SetXValuesToNormalizedArcLength()
185 {this->SetXValues(VTK_XYPLOT_NORMALIZED_ARC_LENGTH);};
186 void SetXValuesToValue() {this->SetXValues(VTK_XYPLOT_VALUE);};
187 const char *GetXValuesAsString();
189 //---Data Object Input------------------------------------------------------
190 // The following methods are used to plot input data objects. Datasets will
191 // be plotted in preference to data objects if set as input; otherwise the
192 // input data objects will be plotted (if defined).
195 // Add a dataset to the list of data to append.
196 void AddDataObjectInput(vtkDataObject *in);
199 // Remove a dataset from the list of data to append.
200 void RemoveDataObjectInput(vtkDataObject *in);
203 // Return the list of inputs to this filter.
204 vtkDataObjectCollection *GetDataObjectInputList()
205 {return this->DataObjectInputList;}
208 // Indicate whether to plot rows or columns. If plotting rows, then
209 // the dependent variables is taken from a specified row,
211 vtkSetClampMacro(DataObjectPlotMode,int,VTK_XYPLOT_ROW,VTK_XYPLOT_COLUMN);
212 vtkGetMacro(DataObjectPlotMode,int);
213 void SetDataObjectPlotModeToRows()
214 {this->SetDataObjectPlotMode(VTK_XYPLOT_ROW);}
215 void SetDataObjectPlotModeToColumns()
216 {this->SetDataObjectPlotMode(VTK_XYPLOT_COLUMN);}
217 const char *GetDataObjectPlotModeAsString();
220 // Specify which component of the input data object to use as the
221 // independent variable for the ith input data object. (This ivar is
222 // ignored if plotting the index.) Note that the value is interpreted
223 // differently depending on DataObjectPlotMode. If the mode is Rows, then
224 // the value of DataObjectXComponent is the row number; otherwise it's the
226 void SetDataObjectXComponent(int i, int comp);
227 int GetDataObjectXComponent(int i);
230 // Specify which component of the input data object to use as the
231 // dependent variable for the ith input data object. (This ivar is
232 // ignored if plotting the index.) Note that the value is interpreted
233 // differently depending on DataObjectPlotMode. If the mode is Rows, then
234 // the value of DataObjectYComponent is the row number; otherwise it's the
236 void SetDataObjectYComponent(int i, int comp);
237 int GetDataObjectYComponent(int i);
238 //---end Data Object Input--------------------------------------------------
240 //---Per Curve Properties---------------------------------------------------
241 // The following methods are used to set properties on each curve that is
242 // plotted. Each input dataset (or data object) results in one curve. The
243 // methods that follow have an index i that corresponds to the input dataset
245 void SetPlotColor(int i, double r, double g, double b);
246 void SetPlotColor(int i, const double color[3]) {
247 this->SetPlotColor(i, color[0], color[1], color[2]); };
248 double *GetPlotColor(int i);
249 void SetPlotSymbol(int i,vtkPolyData *input);
250 vtkPolyData *GetPlotSymbol(int i);
251 void SetPlotLabel(int i, const char *label);
252 const char *GetPlotLabel(int i);
254 // Allow per-curve specification of line and point rendering. These override
255 // global settings PlotPoints and PlotLines. If not on, the default behavior
256 // is governed by PlotPoints and PlotLines ivars.
257 vtkGetMacro(PlotCurvePoints, int);
258 vtkSetMacro(PlotCurvePoints, int);
259 vtkBooleanMacro(PlotCurvePoints, int);
261 vtkGetMacro(PlotCurveLines, int);
262 vtkSetMacro(PlotCurveLines, int);
263 vtkBooleanMacro(PlotCurveLines, int);
265 void SetPlotLines(int i, int);
266 int GetPlotLines(int i);
268 void SetPlotPoints(int i, int);
269 int GetPlotPoints(int i);
270 //---end Per Curve Properties-----------------------------------------------
273 // Enable/Disable exchange of the x-y axes (i.e., what was x becomes y, and
274 // vice-versa). Exchanging axes affects the labeling as well.
275 vtkSetMacro(ExchangeAxes, int);
276 vtkGetMacro(ExchangeAxes, int);
277 vtkBooleanMacro(ExchangeAxes, int);
280 // Normally the x-axis is plotted from minimum to maximum. Setting this instance
281 // variable causes the x-axis to be plotted from maximum to minimum. Note that
282 // boolean always applies to the x-axis even if ExchangeAxes is set.
283 vtkSetMacro(ReverseXAxis, int);
284 vtkGetMacro(ReverseXAxis, int);
285 vtkBooleanMacro(ReverseXAxis, int);
288 // Normally the y-axis is plotted from minimum to maximum. Setting this instance
289 // variable causes the y-axis to be plotted from maximum to minimum. Note that
290 // boolean always applies to the y-axis even if ExchangeAxes is set.
291 vtkSetMacro(ReverseYAxis, int);
292 vtkGetMacro(ReverseYAxis, int);
293 vtkBooleanMacro(ReverseYAxis, int);
296 // Retrieve handles to the legend box and glyph source. This is useful
297 // if you would like to change the default behavior of the legend box
298 // or glyph source. For example, the default glyph can be changed from
299 // a line to a vertex plus line, etc.)
300 vtkGetObjectMacro(LegendActor,vtkLegendBoxActor);
301 vtkGetObjectMacro(GlyphSource,vtkGlyphSource2D);
304 // Set/Get the title of the x-y plot, and the title along the
306 vtkSetStringMacro(Title);
307 vtkGetStringMacro(Title);
308 vtkSetStringMacro(XTitle);
309 vtkGetStringMacro(XTitle);
310 vtkSetStringMacro(YTitle);
311 vtkGetStringMacro(YTitle);
314 // Retrieve handles to the X and Y axis (so that you can set their text
315 // properties for example)
316 vtkAxisActor2D *GetXAxisActor2D()
317 {return this->XAxis;}
318 vtkAxisActor2D *GetYAxisActor2D()
319 {return this->YAxis;}
322 // Set the plot range (range of independent and dependent variables)
323 // to plot. Data outside of the range will be clipped. If the plot
324 // range of either the x or y variables is set to (v1,v2), where
325 // v1 == v2, then the range will be computed automatically. Note that
326 // the x-range values should be consistent with the way the independent
327 // variable is created (via INDEX, DISTANCE, or ARC_LENGTH).
328 vtkSetVector2Macro(XRange,double);
329 vtkGetVectorMacro(XRange,double,2);
330 vtkSetVector2Macro(YRange,double);
331 vtkGetVectorMacro(YRange,double,2);
332 void SetPlotRange(double xmin, double ymin, double xmax, double ymax)
333 {this->SetXRange(xmin,xmax); this->SetYRange(ymin,ymax);}
336 // Set/Get the number of annotation labels to show along the x and y axes.
337 // This values is a suggestion: the number of labels may vary depending
338 // on the particulars of the data. The convenience method
339 // SetNumberOfLables() sets the number of x and y labels to the same value.
340 vtkSetClampMacro(NumberOfXLabels, int, 0, 50);
341 vtkGetMacro(NumberOfXLabels, int);
342 vtkSetClampMacro(NumberOfYLabels, int, 0, 50);
343 vtkGetMacro(NumberOfYLabels, int);
344 void SetNumberOfLabels(int num)
345 {this->SetNumberOfXLabels(num); this->SetNumberOfYLabels(num);}
348 // Enable/Disable the creation of a legend. If on, the legend labels will
349 // be created automatically unless the per plot legend symbol has been
351 vtkSetMacro(Legend, int);
352 vtkGetMacro(Legend, int);
353 vtkBooleanMacro(Legend, int);
356 // Use these methods to control the position of the legend. The variables
357 // LegendPosition and LegendPosition2 define the lower-left and upper-right
358 // position of the legend. The coordinates are expressed as normalized
359 // values with respect to the rectangle defined by PositionCoordinate and
360 // Position2Coordinate. Note that LegendPosition2 is relative to
362 vtkSetVector2Macro(LegendPosition,double);
363 vtkGetVector2Macro(LegendPosition,double);
364 vtkSetVector2Macro(LegendPosition2,double);
365 vtkGetVector2Macro(LegendPosition2,double);
368 // Set/Get the title text property.
369 virtual void SetTitleTextProperty(vtkTextProperty *p);
370 vtkGetObjectMacro(TitleTextProperty,vtkTextProperty);
373 // Set/Get the title text property of all axes. Note that each axis can
374 // be controlled individually through the GetX/YAxisActor2D() methods.
375 virtual void SetAxisTitleTextProperty(vtkTextProperty *p);
376 vtkGetObjectMacro(AxisTitleTextProperty,vtkTextProperty);
379 // Set/Get the labels text property of all axes. Note that each axis can
380 // be controlled individually through the GetX/YAxisActor2D() methods.
381 virtual void SetAxisLabelTextProperty(vtkTextProperty *p);
382 vtkGetObjectMacro(AxisLabelTextProperty,vtkTextProperty);
385 // Enable/Disable plotting of Log of x-values.
386 vtkSetMacro(Logx, int);
387 vtkGetMacro(Logx, int);
388 vtkBooleanMacro(Logx, int);
391 // Set/Get the format with which to print the labels on the scalar
393 virtual void SetLabelFormat (const char* _arg);
394 vtkGetStringMacro(LabelFormat);
397 // Set/Get the spacing between the plot window and the plot. The value
398 // is specified in pixels.
399 vtkSetClampMacro(Border, int, 0, 50);
400 vtkGetMacro(Border, int);
403 // Set/Get whether the points are rendered. The point size can be set in
404 // the property object. This is a global flag which affects the plot only
405 // if per curve symbols are not defined.
406 vtkGetMacro(PlotPoints, int);
407 vtkSetMacro(PlotPoints, int);
408 vtkBooleanMacro(PlotPoints, int);
411 // Set/Get whether the lines are rendered. The line width can be set in
412 // the property object.
413 vtkGetMacro(PlotLines, int);
414 vtkSetMacro(PlotLines, int);
415 vtkBooleanMacro(PlotLines, int);
419 // Set/Get the location in the viewport
420 vtkGetMacro(PlotLocation, VISU_XYPlotLocation);
421 vtkSetMacro(PlotLocation, VISU_XYPlotLocation);
425 // Set/Get the factor that controls how big glyphs are in the plot.
426 // The number is expressed as a fraction of the length of the diagonal
427 // of the plot bounding box.
428 vtkSetClampMacro(GlyphSize, double, 0.0, 0.2);
429 vtkGetMacro(GlyphSize, double);
432 // Given a position within the viewport used by the plot, return the
433 // the plot coordinates (XAxis value, YAxis value)
434 void ViewportToPlotCoordinate(vtkViewport *viewport, double &u, double &v);
437 // An alternate form of ViewportToPlotCoordinate() above. This method
438 // inputs the viewport coordinate pair (defined by the ivar
439 // ViewportCoordinate)and then stores them in the ivar PlotCoordinate.
440 void ViewportToPlotCoordinate(vtkViewport *viewport);
441 vtkSetVector2Macro(PlotCoordinate,double);
442 vtkGetVector2Macro(PlotCoordinate,double);
445 // Given a plot coordinate, return the viewpoint position
446 void PlotToViewportCoordinate(vtkViewport *viewport, double &u, double &v);
449 // An alternate form of PlotToViewportCoordinate() above. This method
450 // inputs the plot coordinate pair (defined in the ivar PlotCoordinate)
451 // and then stores them in the ivar ViewportCoordinate. (This method
453 void PlotToViewportCoordinate(vtkViewport *viewport);
454 vtkSetVector2Macro(ViewportCoordinate,double);
455 vtkGetVector2Macro(ViewportCoordinate,double);
458 // Is the specified viewport position within the plot area (as opposed to the
459 // region used by the plot plus the labels)?
460 int IsInPlot(vtkViewport *viewport, double u, double v);
463 // Take into account the modified time of internal helper classes.
464 unsigned long GetMTime();
467 // Write the XY Ploat Actor as a CSV (comma separated value) representation.
468 void PrintAsCSV(ostream &os);
472 // WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE
473 // DO NOT USE THIS METHOD OUTSIDE OF THE RENDERING PROCESS.
474 // Draw the x-y plot.
475 int RenderOpaqueGeometry(vtkViewport*);
476 int RenderOverlay(vtkViewport*);
477 int RenderTranslucentGeometry(vtkViewport *) {return 0;}
480 // Release any graphics resources that are being consumed by this actor.
481 // The parameter window could be used to determine which graphic
482 // resources to release.
483 void ReleaseGraphicsResources(vtkWindow *);
490 vtkDataSetCollection *InputList; //list of data sets to plot
491 char** SelectedInputScalars; // list of data set arrays to plot
492 vtkIntArray* SelectedInputScalarsComponent; // list of componenents
493 vtkDataObjectCollection *DataObjectInputList; //list of data objects to plot
504 double XComputedRange[2]; //range actually used by plot
505 double YComputedRange[2]; //range actually used by plot
515 vtkTextMapper *TitleMapper;
516 vtkActor2D *TitleActor;
517 vtkTextProperty *TitleTextProperty;
519 vtkAxisActor2D *XAxis;
520 vtkAxisActor2D *YAxis;
522 vtkTextProperty *AxisTitleTextProperty;
523 vtkTextProperty *AxisLabelTextProperty;
525 double ViewportCoordinate[2];
526 double PlotCoordinate[2];
528 //Handle data objects and datasets
529 int DataObjectPlotMode;
530 vtkIntArray *XComponent;
531 vtkIntArray *YComponent;
532 vtkIntArray *LinesOn;
533 vtkIntArray *PointsOn;
535 //The data drawn within the axes. Each curve is one polydata.
536 //color is controlled by scalar data. The curves are appended
537 //together, possibly glyphed with point symbols.
539 vtkPolyData **PlotData;
540 vtkGlyph2D **PlotGlyph;
541 vtkAppendPolyData **PlotAppend;
542 vtkTransformPolyDataFilter **PlotTransform; // RKV
543 vtkPolyDataMapper2D **PlotMapper;
544 vtkActor2D **PlotActor;
545 void InitializeEntries();
547 // Legends and plot symbols. The legend also keeps track of
548 // the symbols and such.
550 double LegendPosition[2];
551 double LegendPosition2[2];
552 vtkLegendBoxActor *LegendActor;
553 vtkGlyphSource2D *GlyphSource;
554 vtkPlanes *ClipPlanes;
557 // Keep track of changes.
558 VISU_XYPlotLocation PlotLocation; // RKV
560 vtkTimeStamp BuildTime;
562 void ComputeXRange(double range[2], double *lengths);
563 void ComputeYRange(double range[2]);
564 void ComputeDORange(double xrange[2], double yrange[2], double *lengths);
566 virtual void CreatePlotData(int *pos, int *pos2, double xRange[2],
567 double yRange[2], double *norms,
568 int numDS, int numDO);
569 void PlaceAxes(vtkViewport *viewport, int *size, int pos[2], int pos2[2]);
570 void GenerateClipPlanes(int *pos, int *pos2);
571 double ComputeGlyphScale(int i, int *pos, int *pos2);
572 void ClipPlotData(int *pos, int *pos2, vtkPolyData *pd);
573 double *TransformPoint(int pos[2], int pos2[2], double x[3], double xNew[3]);
576 VISU_XYPlotActor(const VISU_XYPlotActor&); // Not implemented.
577 void operator=(const VISU_XYPlotActor&); // Not implemented.
581 #endif /*VISU_XYPLOTACTOR_HXX_*/