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 *** Modified by OPEN CASCADE
21 =========================================================================*/
22 // .NAME vtkXYPlotActor - generate an x-y plot from input dataset(s) or field data
23 // .SECTION Description
24 // vtkXYPlotActor creates an x-y plot of data from one or more input data
25 // sets or field data. The class plots dataset scalar values (y-axis) against
26 // the points (x-axis). The x-axis values are generated by taking the point
27 // ids, computing a cumulative arc length, or a normalized arc length. More
28 // than one input data set can be specified to generate multiple plots.
29 // Alternatively, if field data is supplied as input, the class plots one
30 // component against another. (The user must specify which component to use
31 // as the x-axis and which for the y-axis.)
33 // To use this class to plot dataset(s), you must specify one or more
34 // input datasets containing scalar and point data. You'll probably also
35 // want to invoke a method to control how the point coordinates are converted
36 // into x values (by default point ids are used).
38 // To use this class to plot field data, you must specify one or more input
39 // data objects with its associated field data. You'll also want to specify
40 // which component to use as the x-axis and which to use as the y-axis.
41 // Note that when plotting field data, the x and y values are used directly
42 // (i.e., there are no options to normalize the components).
44 // Once you've set up the plot, you'll want to position it. The
45 // PositionCoordinate defines the lower-left location of the x-y plot
46 // (specified in normalized viewport coordinates) and the Position2Coordinate
47 // define the upper-right corner. (Note: the Position2Coordinate is relative
48 // to PositionCoordinate, so you can move the vtkXYPlotActor around the
49 // viewport by setting just the PositionCoordinate.) The combination of the
50 // two position coordinates specifies a rectangle in which the plot will lie.
52 // Optional features include the ability to specify axes labels, label
53 // format and plot title. You can also
54 // manually specify the x and y plot ranges (by default they are computed
55 // automatically). The Border instance variable is used to create space
56 // between the boundary of the plot window (specified by PositionCoordinate
57 // and Position2Coordinate) and the plot itself.
59 // The font property of the plot title can be modified through the
60 // TitleTextProperty attribute.
61 // The font property of the axes titles and labels can be modified through the
62 // AxisTitleTextProperty and AxisLabelTextProperty attributes. You may also
63 // use the GetXAxisActor2D or GetYAxisActor2D methods
64 // to access each individual axis actor to modify their font properties.
65 // In the same way, the GetLegendBoxActor method can be used to access
66 // the legend box actor to modify its font properties.
68 // There are several advanced features as well. You can assign per curve
69 // properties (such as color and a plot symbol). (Note that each input
70 // dataset and/or data object creates a single curve.) Another option is to
71 // add a plot legend that graphically indicates the correspondance between
72 // the curve, curve symbols, and the data source. You can also exchange the
73 // x and y axes if you prefer you plot orientation that way.
76 // If you are interested in plotting something other than scalar data, you
77 // can use the vtk data shuffling filters (e.g.,
78 // vtkAttributeDataToFieldDataFilter and vtkFieldDataToAttributeDataFilter)
79 // to convert the data into scalar data and/or points.
82 // vtkActor2D vtkTextMapper vtkScalarBarActor vtkAxisActor2D vtkCubeAxesActor2D
83 // vtkAttributeDataToFieldDataFilter vtkFieldDataToAttributeDataFilter
86 #include "vtkActor2D.h"
87 #include "vtkTransformPolyDataFilter.h" // RKV
89 #define VTK_XYPLOT_INDEX 0
90 #define VTK_XYPLOT_ARC_LENGTH 1
91 #define VTK_XYPLOT_NORMALIZED_ARC_LENGTH 2
92 #define VTK_XYPLOT_VALUE 3
94 #define VTK_XYPLOT_ROW 0
95 #define VTK_XYPLOT_COLUMN 1
97 class vtkAppendPolyData;
100 class vtkDataObjectCollection;
102 class vtkDataSetCollection;
104 class vtkGlyphSource2D;
106 class vtkLegendBoxActor;
109 class vtkPolyDataMapper2D;
111 class vtkTextProperty;
114 /** Location of the actor in the viewport.
115 * Axes and a curve is plotted according to the selected side.
116 * Axes origin is plotted at:
117 * VISU_XYPLOT_BOTTOM - the left bottom corner,
118 * VISU_XYPLOT_TOP - the left upper corner (Y axis is directed to the bottom),
119 * VISU_XYPLOT_LEFT - the left bottom corner (axes are exchanged),
120 * VISU_XYPLOT_RIGHT - the right bottom corner (X axis is directed to the top, Y - to the left)
122 enum VISU_XYPlotLocation { VISU_XYPLOT_BOTTOM = 0,
123 VISU_XYPLOT_TOP, VISU_XYPLOT_LEFT, VISU_XYPLOT_RIGHT };
126 class VISU_PIPELINE_EXPORT VISU_XYPlotActor : public vtkActor2D
129 vtkTypeRevisionMacro(VISU_XYPlotActor,vtkActor2D);
130 void PrintSelf(ostream& os, vtkIndent indent);
133 // Instantiate object with autorange computation; bold, italic, and shadows
134 // on; arial font family; the number of labels set to 5 for the x and y
135 // axes; a label format of "%-#6.3g"; and x coordinates computed from point
137 static VISU_XYPlotActor *New();
139 //---Data Set Input----------------------------------------------------------
140 // The following methods are used to plot input datasets. Datasets
141 // will be plotted if set as input; otherwise the input data objects
142 // will be plotted (if defined).
145 // Add a dataset to the list of data to append. The array name specifies
146 // which point array to plot. If the array name is NULL, then the default
147 // scalars are used. The array can have multiple components, but only the
148 // first component is ploted.
149 void AddInput(vtkDataSet *in, const char* arrayName, int component);
150 void AddInput(vtkDataSet *in) {this->AddInput(in, NULL, 0);}
153 // Remove a dataset from the list of data to append.
154 void RemoveInput(vtkDataSet *in, const char* arrayName, int component);
155 void RemoveInput(vtkDataSet *in) {this->RemoveInput(in, NULL, 0);}
158 // This removes all of the data set inputs,
159 // but does not change the data object inputs.
160 void RemoveAllInputs();
163 // Return the list of inputs to this filter.
164 vtkDataSetCollection *GetInputList() {return this->InputList;}
167 // If plotting points by value, which component to use to determine the
168 // value. This sets a value per each input dataset (i.e., the ith dataset).
169 void SetPointComponent(int i, int comp);
170 int GetPointComponent(int i);
171 //---end Data Set Input-----------------------------------------------------
174 // Specify how the independent (x) variable is computed from the points.
175 // The independent variable can be the scalar/point index (i.e., point id),
176 // the accumulated arc length along the points, the normalized arc length,
177 // or by component value. If plotting datasets (e.g., points), the value
178 // that is used is specified by the PointComponent ivar. (Note: these
179 // methods also control how field data is plotted. Field data is usually
180 // plotted by value or index, if plotting length 1-dimensional length
181 // measures are used.)
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 //---Data Object Input------------------------------------------------------
192 // The following methods are used to plot input data objects. Datasets will
193 // be plotted in preference to data objects if set as input; otherwise the
194 // input data objects will be plotted (if defined).
197 // Add a dataset to the list of data to append.
198 void AddDataObjectInput(vtkDataObject *in);
201 // Remove a dataset from the list of data to append.
202 void RemoveDataObjectInput(vtkDataObject *in);
205 // Return the list of inputs to this filter.
206 vtkDataObjectCollection *GetDataObjectInputList()
207 {return this->DataObjectInputList;}
210 // Indicate whether to plot rows or columns. If plotting rows, then
211 // the dependent variables is taken from a specified row,
213 vtkSetClampMacro(DataObjectPlotMode,int,VTK_XYPLOT_ROW,VTK_XYPLOT_COLUMN);
214 vtkGetMacro(DataObjectPlotMode,int);
215 void SetDataObjectPlotModeToRows()
216 {this->SetDataObjectPlotMode(VTK_XYPLOT_ROW);}
217 void SetDataObjectPlotModeToColumns()
218 {this->SetDataObjectPlotMode(VTK_XYPLOT_COLUMN);}
219 const char *GetDataObjectPlotModeAsString();
222 // Specify which component of the input data object to use as the
223 // independent variable for the ith input data object. (This ivar is
224 // ignored if plotting the index.) Note that the value is interpreted
225 // differently depending on DataObjectPlotMode. If the mode is Rows, then
226 // the value of DataObjectXComponent is the row number; otherwise it's the
228 void SetDataObjectXComponent(int i, int comp);
229 int GetDataObjectXComponent(int i);
232 // Specify which component of the input data object to use as the
233 // dependent variable for the ith input data object. (This ivar is
234 // ignored if plotting the index.) Note that the value is interpreted
235 // differently depending on DataObjectPlotMode. If the mode is Rows, then
236 // the value of DataObjectYComponent is the row number; otherwise it's the
238 void SetDataObjectYComponent(int i, int comp);
239 int GetDataObjectYComponent(int i);
240 //---end Data Object Input--------------------------------------------------
242 //---Per Curve Properties---------------------------------------------------
243 // The following methods are used to set properties on each curve that is
244 // plotted. Each input dataset (or data object) results in one curve. The
245 // methods that follow have an index i that corresponds to the input dataset
247 void SetPlotColor(int i, double r, double g, double b);
248 void SetPlotColor(int i, const double color[3]) {
249 this->SetPlotColor(i, color[0], color[1], color[2]); };
250 double *GetPlotColor(int i);
251 void SetPlotSymbol(int i,vtkPolyData *input);
252 vtkPolyData *GetPlotSymbol(int i);
253 void SetPlotLabel(int i, const char *label);
254 const char *GetPlotLabel(int i);
256 // Allow per-curve specification of line and point rendering. These override
257 // global settings PlotPoints and PlotLines. If not on, the default behavior
258 // is governed by PlotPoints and PlotLines ivars.
259 vtkGetMacro(PlotCurvePoints, int);
260 vtkSetMacro(PlotCurvePoints, int);
261 vtkBooleanMacro(PlotCurvePoints, int);
263 vtkGetMacro(PlotCurveLines, int);
264 vtkSetMacro(PlotCurveLines, int);
265 vtkBooleanMacro(PlotCurveLines, int);
267 void SetPlotLines(int i, int);
268 int GetPlotLines(int i);
270 void SetPlotPoints(int i, int);
271 int GetPlotPoints(int i);
272 //---end Per Curve Properties-----------------------------------------------
275 // Enable/Disable exchange of the x-y axes (i.e., what was x becomes y, and
276 // vice-versa). Exchanging axes affects the labeling as well.
277 vtkSetMacro(ExchangeAxes, int);
278 vtkGetMacro(ExchangeAxes, int);
279 vtkBooleanMacro(ExchangeAxes, int);
282 // Normally the x-axis is plotted from minimum to maximum. Setting this instance
283 // variable causes the x-axis to be plotted from maximum to minimum. Note that
284 // boolean always applies to the x-axis even if ExchangeAxes is set.
285 vtkSetMacro(ReverseXAxis, int);
286 vtkGetMacro(ReverseXAxis, int);
287 vtkBooleanMacro(ReverseXAxis, int);
290 // Normally the y-axis is plotted from minimum to maximum. Setting this instance
291 // variable causes the y-axis to be plotted from maximum to minimum. Note that
292 // boolean always applies to the y-axis even if ExchangeAxes is set.
293 vtkSetMacro(ReverseYAxis, int);
294 vtkGetMacro(ReverseYAxis, int);
295 vtkBooleanMacro(ReverseYAxis, int);
298 // Retrieve handles to the legend box and glyph source. This is useful
299 // if you would like to change the default behavior of the legend box
300 // or glyph source. For example, the default glyph can be changed from
301 // a line to a vertex plus line, etc.)
302 vtkGetObjectMacro(LegendActor,vtkLegendBoxActor);
303 vtkGetObjectMacro(GlyphSource,vtkGlyphSource2D);
306 // Set/Get the title of the x-y plot, and the title along the
308 vtkSetStringMacro(Title);
309 vtkGetStringMacro(Title);
310 vtkSetStringMacro(XTitle);
311 vtkGetStringMacro(XTitle);
312 vtkSetStringMacro(YTitle);
313 vtkGetStringMacro(YTitle);
316 // Retrieve handles to the X and Y axis (so that you can set their text
317 // properties for example)
318 vtkAxisActor2D *GetXAxisActor2D()
319 {return this->XAxis;}
320 vtkAxisActor2D *GetYAxisActor2D()
321 {return this->YAxis;}
324 // Set the plot range (range of independent and dependent variables)
325 // to plot. Data outside of the range will be clipped. If the plot
326 // range of either the x or y variables is set to (v1,v2), where
327 // v1 == v2, then the range will be computed automatically. Note that
328 // the x-range values should be consistent with the way the independent
329 // variable is created (via INDEX, DISTANCE, or ARC_LENGTH).
330 vtkSetVector2Macro(XRange,double);
331 vtkGetVectorMacro(XRange,double,2);
332 vtkSetVector2Macro(YRange,double);
333 vtkGetVectorMacro(YRange,double,2);
334 void SetPlotRange(double xmin, double ymin, double xmax, double ymax)
335 {this->SetXRange(xmin,xmax); this->SetYRange(ymin,ymax);}
338 // Set/Get the number of annotation labels to show along the x and y axes.
339 // This values is a suggestion: the number of labels may vary depending
340 // on the particulars of the data. The convenience method
341 // SetNumberOfLables() sets the number of x and y labels to the same value.
342 vtkSetClampMacro(NumberOfXLabels, int, 0, 50);
343 vtkGetMacro(NumberOfXLabels, int);
344 vtkSetClampMacro(NumberOfYLabels, int, 0, 50);
345 vtkGetMacro(NumberOfYLabels, int);
346 void SetNumberOfLabels(int num)
347 {this->SetNumberOfXLabels(num); this->SetNumberOfYLabels(num);}
350 // Enable/Disable the creation of a legend. If on, the legend labels will
351 // be created automatically unless the per plot legend symbol has been
353 vtkSetMacro(Legend, int);
354 vtkGetMacro(Legend, int);
355 vtkBooleanMacro(Legend, int);
358 // Use these methods to control the position of the legend. The variables
359 // LegendPosition and LegendPosition2 define the lower-left and upper-right
360 // position of the legend. The coordinates are expressed as normalized
361 // values with respect to the rectangle defined by PositionCoordinate and
362 // Position2Coordinate. Note that LegendPosition2 is relative to
364 vtkSetVector2Macro(LegendPosition,double);
365 vtkGetVector2Macro(LegendPosition,double);
366 vtkSetVector2Macro(LegendPosition2,double);
367 vtkGetVector2Macro(LegendPosition2,double);
370 // Set/Get the title text property.
371 virtual void SetTitleTextProperty(vtkTextProperty *p);
372 vtkGetObjectMacro(TitleTextProperty,vtkTextProperty);
375 // Set/Get the title text property of all axes. Note that each axis can
376 // be controlled individually through the GetX/YAxisActor2D() methods.
377 virtual void SetAxisTitleTextProperty(vtkTextProperty *p);
378 vtkGetObjectMacro(AxisTitleTextProperty,vtkTextProperty);
381 // Set/Get the labels text property of all axes. Note that each axis can
382 // be controlled individually through the GetX/YAxisActor2D() methods.
383 virtual void SetAxisLabelTextProperty(vtkTextProperty *p);
384 vtkGetObjectMacro(AxisLabelTextProperty,vtkTextProperty);
387 // Enable/Disable plotting of Log of x-values.
388 vtkSetMacro(Logx, int);
389 vtkGetMacro(Logx, int);
390 vtkBooleanMacro(Logx, int);
393 // Set/Get the format with which to print the labels on the scalar
395 virtual void SetLabelFormat (const char* _arg);
396 vtkGetStringMacro(LabelFormat);
399 // Set/Get the spacing between the plot window and the plot. The value
400 // is specified in pixels.
401 vtkSetClampMacro(Border, int, 0, 50);
402 vtkGetMacro(Border, int);
405 // Set/Get whether the points are rendered. The point size can be set in
406 // the property object. This is a global flag which affects the plot only
407 // if per curve symbols are not defined.
408 vtkGetMacro(PlotPoints, int);
409 vtkSetMacro(PlotPoints, int);
410 vtkBooleanMacro(PlotPoints, int);
413 // Set/Get whether the lines are rendered. The line width can be set in
414 // the property object.
415 vtkGetMacro(PlotLines, int);
416 vtkSetMacro(PlotLines, int);
417 vtkBooleanMacro(PlotLines, int);
421 // Set/Get the location in the viewport
422 vtkGetMacro(PlotLocation, VISU_XYPlotLocation);
423 vtkSetMacro(PlotLocation, VISU_XYPlotLocation);
427 // Set/Get the factor that controls how big glyphs are in the plot.
428 // The number is expressed as a fraction of the length of the diagonal
429 // of the plot bounding box.
430 vtkSetClampMacro(GlyphSize, double, 0.0, 0.2);
431 vtkGetMacro(GlyphSize, double);
434 // Given a position within the viewport used by the plot, return the
435 // the plot coordinates (XAxis value, YAxis value)
436 void ViewportToPlotCoordinate(vtkViewport *viewport, double &u, double &v);
439 // An alternate form of ViewportToPlotCoordinate() above. This method
440 // inputs the viewport coordinate pair (defined by the ivar
441 // ViewportCoordinate)and then stores them in the ivar PlotCoordinate.
442 void ViewportToPlotCoordinate(vtkViewport *viewport);
443 vtkSetVector2Macro(PlotCoordinate,double);
444 vtkGetVector2Macro(PlotCoordinate,double);
447 // Given a plot coordinate, return the viewpoint position
448 void PlotToViewportCoordinate(vtkViewport *viewport, double &u, double &v);
451 // An alternate form of PlotToViewportCoordinate() above. This method
452 // inputs the plot coordinate pair (defined in the ivar PlotCoordinate)
453 // and then stores them in the ivar ViewportCoordinate. (This method
455 void PlotToViewportCoordinate(vtkViewport *viewport);
456 vtkSetVector2Macro(ViewportCoordinate,double);
457 vtkGetVector2Macro(ViewportCoordinate,double);
460 // Is the specified viewport position within the plot area (as opposed to the
461 // region used by the plot plus the labels)?
462 int IsInPlot(vtkViewport *viewport, double u, double v);
465 // Take into account the modified time of internal helper classes.
466 unsigned long GetMTime();
469 // Write the XY Ploat Actor as a CSV (comma separated value) representation.
470 void PrintAsCSV(ostream &os);
474 // WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE
475 // DO NOT USE THIS METHOD OUTSIDE OF THE RENDERING PROCESS.
476 // Draw the x-y plot.
477 int RenderOpaqueGeometry(vtkViewport*);
478 int RenderOverlay(vtkViewport*);
479 int RenderTranslucentGeometry(vtkViewport *) {return 0;}
482 // Release any graphics resources that are being consumed by this actor.
483 // The parameter window could be used to determine which graphic
484 // resources to release.
485 void ReleaseGraphicsResources(vtkWindow *);
492 vtkDataSetCollection *InputList; //list of data sets to plot
493 char** SelectedInputScalars; // list of data set arrays to plot
494 vtkIntArray* SelectedInputScalarsComponent; // list of componenents
495 vtkDataObjectCollection *DataObjectInputList; //list of data objects to plot
506 double XComputedRange[2]; //range actually used by plot
507 double YComputedRange[2]; //range actually used by plot
517 vtkTextMapper *TitleMapper;
518 vtkActor2D *TitleActor;
519 vtkTextProperty *TitleTextProperty;
521 vtkAxisActor2D *XAxis;
522 vtkAxisActor2D *YAxis;
524 vtkTextProperty *AxisTitleTextProperty;
525 vtkTextProperty *AxisLabelTextProperty;
527 double ViewportCoordinate[2];
528 double PlotCoordinate[2];
530 //Handle data objects and datasets
531 int DataObjectPlotMode;
532 vtkIntArray *XComponent;
533 vtkIntArray *YComponent;
534 vtkIntArray *LinesOn;
535 vtkIntArray *PointsOn;
537 //The data drawn within the axes. Each curve is one polydata.
538 //color is controlled by scalar data. The curves are appended
539 //together, possibly glyphed with point symbols.
541 vtkPolyData **PlotData;
542 vtkGlyph2D **PlotGlyph;
543 vtkAppendPolyData **PlotAppend;
544 vtkTransformPolyDataFilter **PlotTransform; // RKV
545 vtkPolyDataMapper2D **PlotMapper;
546 vtkActor2D **PlotActor;
547 void InitializeEntries();
549 // Legends and plot symbols. The legend also keeps track of
550 // the symbols and such.
552 double LegendPosition[2];
553 double LegendPosition2[2];
554 vtkLegendBoxActor *LegendActor;
555 vtkGlyphSource2D *GlyphSource;
556 vtkPlanes *ClipPlanes;
559 // Keep track of changes.
560 VISU_XYPlotLocation PlotLocation; // RKV
562 vtkTimeStamp BuildTime;
564 void ComputeXRange(double range[2], double *lengths);
565 void ComputeYRange(double range[2]);
566 void ComputeDORange(double xrange[2], double yrange[2], double *lengths);
568 virtual void CreatePlotData(int *pos, int *pos2, double xRange[2],
569 double yRange[2], double *norms,
570 int numDS, int numDO);
571 void PlaceAxes(vtkViewport *viewport, int *size, int pos[2], int pos2[2]);
572 void GenerateClipPlanes(int *pos, int *pos2);
573 double ComputeGlyphScale(int i, int *pos, int *pos2);
574 void ClipPlotData(int *pos, int *pos2, vtkPolyData *pd);
575 double *TransformPoint(int pos[2], int pos2[2], double x[3], double xNew[3]);
578 VISU_XYPlotActor(const VISU_XYPlotActor&); // Not implemented.
579 void operator=(const VISU_XYPlotActor&); // Not implemented.
583 #endif /*VISU_XYPLOTACTOR_HXX_*/