1 /*=========================================================================
3 Program: Visualization Toolkit
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
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.
14 *** Modified by OPEN CASCADE
16 =========================================================================*/
17 #include "VISU_XYPlotActor.hxx"
19 #include "vtkAppendPolyData.h"
20 #include "vtkAxisActor2D.h"
21 #include "vtkCellArray.h"
22 #include "vtkDataObjectCollection.h"
23 #include "vtkDataSetCollection.h"
24 #include "vtkFieldData.h"
25 #include "vtkDoubleArray.h"
26 #include "vtkGlyph2D.h"
27 #include "vtkGlyphSource2D.h"
28 #include "vtkIntArray.h"
29 #include "vtkLegendBoxActor.h"
31 #include "vtkObjectFactory.h"
33 #include "vtkPlanes.h"
34 #include "vtkPointData.h"
35 #include "vtkPolyData.h"
36 #include "vtkPolyDataMapper2D.h"
37 #include "vtkProperty2D.h"
38 #include "vtkTextMapper.h"
39 #include "vtkTextProperty.h"
40 #include "vtkViewport.h"
41 #include "vtkTransformPolyDataFilter.h" // RKV
42 #include "vtkTransform.h" // RKV
44 #define VTK_MAX_PLOTS 50
46 #if !defined(VTK_XVERSION)
47 #define VTK_XVERSION (VTK_MAJOR_VERSION<<16)+(VTK_MINOR_VERSION<<8)+(VTK_BUILD_VERSION)
52 vtkCxxRevisionMacro(VISU_XYPlotActor, "$Revision$");
53 vtkStandardNewMacro(VISU_XYPlotActor);
55 vtkCxxSetObjectMacro(VISU_XYPlotActor,TitleTextProperty,vtkTextProperty);
56 vtkCxxSetObjectMacro(VISU_XYPlotActor,AxisLabelTextProperty,vtkTextProperty);
57 vtkCxxSetObjectMacro(VISU_XYPlotActor,AxisTitleTextProperty,vtkTextProperty);
59 //----------------------------------------------------------------------------
61 VISU_XYPlotActor::VISU_XYPlotActor()
63 this->PositionCoordinate->SetCoordinateSystemToNormalizedViewport();
64 this->PositionCoordinate->SetValue(0.25,0.25);
65 this->Position2Coordinate->SetValue(0.5, 0.5);
67 this->InputList = vtkDataSetCollection::New();
68 this->SelectedInputScalars = NULL;
69 this->SelectedInputScalarsComponent = vtkIntArray::New();
70 this->DataObjectInputList = vtkDataObjectCollection::New();
73 this->XTitle = new char[7];
74 sprintf(this->XTitle,"%s","X Axis");
75 this->YTitle = new char[7];
76 sprintf(this->YTitle,"%s","Y Axis");
78 this->XValues = VTK_XYPLOT_INDEX;
79 this->PlotLocation = VISU_XYPLOT_BOTTOM; // RKV
81 this->NumberOfXLabels = 5;
82 this->NumberOfYLabels = 5;
84 this->TitleTextProperty = vtkTextProperty::New();
85 this->TitleTextProperty->SetBold(1);
86 this->TitleTextProperty->SetItalic(1);
87 this->TitleTextProperty->SetShadow(1);
88 this->TitleTextProperty->SetFontFamilyToArial();
90 this->AxisLabelTextProperty = vtkTextProperty::New();
91 this->AxisLabelTextProperty->ShallowCopy(this->TitleTextProperty);
93 this->AxisTitleTextProperty = vtkTextProperty::New();
94 this->AxisTitleTextProperty->ShallowCopy(this->AxisLabelTextProperty);
96 this->LabelFormat = new char[8];
97 sprintf(this->LabelFormat,"%s","%-#6.3g");
101 this->XRange[0] = 0.0;
102 this->XRange[1] = 0.0;
103 this->YRange[0] = 0.0;
104 this->YRange[1] = 0.0;
108 this->PlotPoints = 0;
109 this->PlotCurveLines = 0;
110 this->PlotCurvePoints = 0;
111 this->ExchangeAxes = 0;
112 this->ReverseXAxis = 0;
113 this->ReverseYAxis = 0;
115 this->TitleMapper = vtkTextMapper::New();
116 this->TitleActor = vtkActor2D::New();
117 this->TitleActor->SetMapper(this->TitleMapper);
118 this->TitleActor->GetPositionCoordinate()->SetCoordinateSystemToViewport();
120 this->XAxis = vtkAxisActor2D::New();
121 this->XAxis->GetPositionCoordinate()->SetCoordinateSystemToViewport();
122 this->XAxis->GetPosition2Coordinate()->SetCoordinateSystemToViewport();
123 this->XAxis->SetProperty(this->GetProperty());
125 this->YAxis = vtkAxisActor2D::New();
126 this->YAxis->GetPositionCoordinate()->SetCoordinateSystemToViewport();
127 this->YAxis->GetPosition2Coordinate()->SetCoordinateSystemToViewport();
128 this->YAxis->SetProperty(this->GetProperty());
130 this->NumberOfInputs = 0;
131 this->PlotData = NULL;
132 this->PlotGlyph = NULL;
133 this->PlotAppend = NULL;
134 this->PlotTransform = NULL; // RKV
135 this->PlotMapper = NULL;
136 this->PlotActor = NULL;
138 this->ViewportCoordinate[0] = 0.0;
139 this->ViewportCoordinate[1] = 0.0;
140 this->PlotCoordinate[0] = 0.0;
141 this->PlotCoordinate[1] = 0.0;
143 this->DataObjectPlotMode = VTK_XYPLOT_COLUMN;
144 this->XComponent = vtkIntArray::New();
145 this->XComponent->SetNumberOfValues(VTK_MAX_PLOTS);
146 this->YComponent = vtkIntArray::New();
147 this->YComponent->SetNumberOfValues(VTK_MAX_PLOTS);
149 this->LinesOn = vtkIntArray::New();
150 this->LinesOn->SetNumberOfValues(VTK_MAX_PLOTS);
151 this->PointsOn = vtkIntArray::New();
152 this->PointsOn->SetNumberOfValues(VTK_MAX_PLOTS);
153 for (int i=0; i<VTK_MAX_PLOTS; i++)
155 this->XComponent->SetValue(i,0);
156 this->YComponent->SetValue(i,0);
157 this->LinesOn->SetValue(i,this->PlotLines);
158 this->PointsOn->SetValue(i,this->PlotPoints);
162 this->LegendPosition[0] = 0.85;
163 this->LegendPosition[1] = 0.75;
164 this->LegendPosition2[0] = 0.15;
165 this->LegendPosition2[1] = 0.20;
166 this->LegendActor = vtkLegendBoxActor::New();
167 this->LegendActor->GetPositionCoordinate()->SetCoordinateSystemToViewport();
168 this->LegendActor->GetPosition2Coordinate()->SetCoordinateSystemToViewport();
169 this->LegendActor->GetPosition2Coordinate()->SetReferenceCoordinate(NULL);
170 this->LegendActor->BorderOff();
171 this->LegendActor->SetNumberOfEntries(VTK_MAX_PLOTS); //initial allocation
172 this->GlyphSource = vtkGlyphSource2D::New();
173 this->GlyphSource->SetGlyphTypeToNone();
174 this->GlyphSource->DashOn();
175 this->GlyphSource->FilledOff();
176 this->GlyphSize = 0.020;
178 this->ClipPlanes = vtkPlanes::New();
179 vtkPoints *pts = vtkPoints::New();
180 pts->SetNumberOfPoints(4);
181 this->ClipPlanes->SetPoints(pts);
183 vtkDoubleArray *n = vtkDoubleArray::New();
184 n->SetNumberOfComponents(3);
185 n->SetNumberOfTuples(4);
186 this->ClipPlanes->SetNormals(n);
189 this->CachedSize[0] = 0;
190 this->CachedSize[1] = 0;
193 //----------------------------------------------------------------------------
194 VISU_XYPlotActor::~VISU_XYPlotActor()
196 // Get rid of the list of array names.
197 int num = this->InputList->GetNumberOfItems();
198 if (this->SelectedInputScalars)
200 for (int i = 0; i < num; ++i)
202 if (this->SelectedInputScalars[i])
204 delete [] this->SelectedInputScalars[i];
205 this->SelectedInputScalars[i] = NULL;
208 delete [] this->SelectedInputScalars;
209 this->SelectedInputScalars = NULL;
211 this->SelectedInputScalarsComponent->Delete();
212 this->SelectedInputScalarsComponent = NULL;
214 // Now we can get rid of the inputs.
215 this->InputList->Delete();
216 this->InputList = NULL;
218 this->DataObjectInputList->Delete();
219 this->DataObjectInputList = NULL;
221 this->TitleMapper->Delete();
222 this->TitleMapper = NULL;
223 this->TitleActor->Delete();
224 this->TitleActor = NULL;
229 this->SetLabelFormat(0);
231 this->XAxis->Delete();
232 this->YAxis->Delete();
234 this->InitializeEntries();
236 this->LegendActor->Delete();
237 this->GlyphSource->Delete();
238 this->ClipPlanes->Delete();
240 this->XComponent->Delete();
241 this->YComponent->Delete();
243 this->LinesOn->Delete();
244 this->PointsOn->Delete();
246 this->SetTitleTextProperty(NULL);
247 this->SetAxisLabelTextProperty(NULL);
248 this->SetAxisTitleTextProperty(NULL);
251 //----------------------------------------------------------------------------
252 void VISU_XYPlotActor::InitializeEntries()
254 if ( this->NumberOfInputs > 0 )
256 for (int i=0; i<this->NumberOfInputs; i++)
258 this->PlotData[i]->Delete();
259 this->PlotGlyph[i]->Delete();
260 this->PlotAppend[i]->Delete();
261 this->PlotTransform[i]->Delete(); // RKV
262 this->PlotMapper[i]->Delete();
263 this->PlotActor[i]->Delete();
265 delete [] this->PlotData; this->PlotData = NULL;
266 delete [] this->PlotGlyph; this->PlotGlyph = NULL;
267 delete [] this->PlotAppend; this->PlotAppend = NULL;
268 delete [] this->PlotTransform; this->PlotTransform = NULL; // RKV
269 delete [] this->PlotMapper; this->PlotMapper = NULL;
270 delete [] this->PlotActor; this->PlotActor = NULL;
271 this->NumberOfInputs = 0;
272 }//if entries have been defined
275 //----------------------------------------------------------------------------
276 // Add a dataset and array to the list of data to plot.
277 void VISU_XYPlotActor::AddInput(vtkDataSet *ds, const char *arrayName, int component)
282 // I cannot change the input list, because the user has direct
283 // access to the collection. I cannot store the index of the array,
284 // because the index might change from render to render ...
285 // I have to store the list of string array names.
287 // I believe idx starts at 1 and goes to "NumberOfItems".
288 idx = this->InputList->IsItemPresent(ds);
290 { // Return if arrays are the same.
291 if (arrayName == NULL && this->SelectedInputScalars[idx-1] == NULL &&
292 component == this->SelectedInputScalarsComponent->GetValue(idx-1))
296 if (arrayName != NULL && this->SelectedInputScalars[idx-1] != NULL &&
297 strcmp(arrayName, this->SelectedInputScalars[idx-1]) == 0 &&
298 component == this->SelectedInputScalarsComponent->GetValue(idx-1))
304 // The input/array/component must be a unique combination. Add it to our input list.
306 // Now reallocate the list of strings and add the new value.
307 num = this->InputList->GetNumberOfItems();
308 newNames = new char*[num+1];
309 for (idx = 0; idx < num; ++idx)
311 newNames[idx] = this->SelectedInputScalars[idx];
313 if (arrayName == NULL)
315 newNames[num] = NULL;
319 newNames[num] = new char[strlen(arrayName)+1];
320 strcpy(newNames[num],arrayName);
322 delete [] this->SelectedInputScalars;
323 this->SelectedInputScalars = newNames;
325 // Save the component in the int array.
326 this->SelectedInputScalarsComponent->InsertValue(num, component);
328 // Add the data set to the collection
329 this->InputList->AddItem(ds);
331 // In case of multiple use of a XYPlotActor the NumberOfEntries could be set
332 // to n. Then when a call to SetEntryString(n+1, bla) was done the string was lost
333 // Need to update the number of entries for the legend actor
334 this->LegendActor->SetNumberOfEntries(this->LegendActor->GetNumberOfEntries()+1);
339 //----------------------------------------------------------------------------
340 void VISU_XYPlotActor::RemoveAllInputs()
344 num = this->InputList->GetNumberOfItems();
345 this->InputList->RemoveAllItems();
347 for (idx = 0; idx < num; ++idx)
349 if (this->SelectedInputScalars[idx])
351 delete [] this->SelectedInputScalars[idx];
352 this->SelectedInputScalars[idx] = NULL;
355 this->SelectedInputScalarsComponent->Reset();
357 this->DataObjectInputList->RemoveAllItems();
360 //----------------------------------------------------------------------------
361 // Remove a dataset from the list of data to plot.
362 void VISU_XYPlotActor::RemoveInput(vtkDataSet *ds, const char *arrayName, int component)
368 // This is my own find routine, because the array names have to match also.
369 num = this->InputList->GetNumberOfItems();
370 vtkCollectionSimpleIterator dsit;
371 this->InputList->InitTraversal(dsit);
372 for (idx = 0; idx < num && found == -1; ++idx)
374 input = this->InputList->GetNextDataSet(dsit);
377 if (arrayName == NULL && this->SelectedInputScalars[idx] == NULL &&
378 component == this->SelectedInputScalarsComponent->GetValue(idx))
382 if (arrayName != NULL && this->SelectedInputScalars[idx] != NULL &&
383 strcmp(arrayName, this->SelectedInputScalars[idx]) == 0 &&
384 component == this->SelectedInputScalarsComponent->GetValue(idx))
397 // Collections index their items starting at 1.
398 this->InputList->RemoveItem(found);
400 // Do not bother reallocating the SelectedInputScalars
401 // string array to make it smaller.
402 if (this->SelectedInputScalars[found])
404 delete [] this->SelectedInputScalars[found];
405 this->SelectedInputScalars[found] = NULL;
407 for (idx = found+1; idx < num; ++idx)
409 this->SelectedInputScalars[idx-1] = this->SelectedInputScalars[idx];
410 this->SelectedInputScalarsComponent->SetValue(idx-1,
411 this->SelectedInputScalarsComponent->GetValue(idx));
413 // Reseting the last item is not really necessary,
414 // but to be clean we do it anyway.
415 this->SelectedInputScalarsComponent->SetValue(num-1, -1);
416 this->SelectedInputScalars[num-1] = NULL;
419 //----------------------------------------------------------------------------
420 // Add a data object to the list of data to plot.
421 void VISU_XYPlotActor::AddDataObjectInput(vtkDataObject *in)
423 if ( ! this->DataObjectInputList->IsItemPresent(in) )
426 this->DataObjectInputList->AddItem(in);
430 //----------------------------------------------------------------------------
431 // Remove a data object from the list of data to plot.
432 void VISU_XYPlotActor::RemoveDataObjectInput(vtkDataObject *in)
434 if ( this->DataObjectInputList->IsItemPresent(in) )
437 this->DataObjectInputList->RemoveItem(in);
441 //----------------------------------------------------------------------------
442 // Plot scalar data for each input dataset.
443 int VISU_XYPlotActor::RenderOverlay(vtkViewport *viewport)
445 int renderedSomething = 0;
447 // Make sure input is up to date.
448 if ( this->InputList->GetNumberOfItems() < 1 &&
449 this->DataObjectInputList->GetNumberOfItems() < 1 )
451 vtkErrorMacro(<< "Nothing to plot!");
455 renderedSomething += this->XAxis->RenderOverlay(viewport);
456 renderedSomething += this->YAxis->RenderOverlay(viewport);
459 renderedSomething += this->TitleActor->RenderOverlay(viewport);
461 for (int i=0; i < this->NumberOfInputs; i++)
463 renderedSomething += this->PlotActor[i]->RenderOverlay(viewport);
467 renderedSomething += this->LegendActor->RenderOverlay(viewport);
470 return renderedSomething;
473 //----------------------------------------------------------------------------
474 // Plot scalar data for each input dataset.
475 int VISU_XYPlotActor::RenderOpaqueGeometry(vtkViewport *viewport)
477 unsigned long mtime, dsMtime;
480 int numDS, numDO, renderedSomething=0;
483 // Make sure input is up to date.
484 numDS = this->InputList->GetNumberOfItems();
485 numDO = this->DataObjectInputList->GetNumberOfItems();
488 vtkDebugMacro(<<"Plotting input data sets");
489 vtkCollectionSimpleIterator dsit;
490 for (mtime=0, this->InputList->InitTraversal(dsit);
491 (ds = this->InputList->GetNextDataSet(dsit)); )
494 dsMtime = ds->GetMTime();
495 if ( dsMtime > mtime )
501 else if ( numDO > 0 )
503 vtkDebugMacro(<<"Plotting input data objects");
504 vtkCollectionSimpleIterator doit;
505 for (mtime=0, this->DataObjectInputList->InitTraversal(doit);
506 (dobj = this->DataObjectInputList->GetNextDataObject(doit)); )
509 dsMtime = dobj->GetMTime();
510 if ( dsMtime > mtime )
518 vtkErrorMacro(<< "Nothing to plot!");
522 if (this->Title && this->Title[0] && !this->TitleTextProperty)
524 vtkErrorMacro(<< "Need a title text property to render plot title");
528 // Check modified time to see whether we have to rebuild.
529 // Pay attention that GetMTime() has been redefined (see below)
531 int *size=viewport->GetSize();
532 if (mtime > this->BuildTime ||
533 size[0] != this->CachedSize[0] || size[1] != this->CachedSize[1] ||
534 this->GetMTime() > this->BuildTime ||
535 (this->Title && this->Title[0] &&
536 this->TitleTextProperty->GetMTime() > this->BuildTime) ||
537 (this->AxisLabelTextProperty &&
538 this->AxisLabelTextProperty->GetMTime() > this->BuildTime) ||
539 (this->AxisTitleTextProperty &&
540 this->AxisTitleTextProperty->GetMTime() > this->BuildTime))
542 double range[2], yrange[2], xRange[2], yRange[2], interval, *lengths=NULL;
543 int pos[2], pos2[2], numTicks;
545 int num = ( numDS > 0 ? numDS : numDO );
547 vtkDebugMacro(<<"Rebuilding plot");
548 this->CachedSize[0] = size[0];
549 this->CachedSize[1] = size[1];
552 if ((this->PlotLocation == VISU_XYPLOT_RIGHT) || (this->PlotLocation == VISU_XYPLOT_LEFT))
553 this->ReverseYAxis = 1;
555 this->ReverseYAxis = 0;
559 vtkDebugMacro(<<"Rebuilding legend");
562 int legPos[2], legPos2[2];
563 int *p1 = this->PositionCoordinate->GetComputedViewportValue(viewport);
564 int *p2 = this->Position2Coordinate->GetComputedViewportValue(viewport);
565 legPos[0] = (int)(p1[0] + this->LegendPosition[0]*(p2[0]-p1[0]));
566 legPos2[0] = (int)(legPos[0] + this->LegendPosition2[0]*(p2[0]-p1[0]));
567 legPos[1] = (int)(p1[1] + this->LegendPosition[1]*(p2[1]-p1[1]));
568 legPos2[1] = (int)(legPos[1] + this->LegendPosition2[1]*(p2[1]-p1[1]));
570 this->LegendActor->GetPositionCoordinate()->SetValue(
571 (double)legPos[0], (double)legPos[1]);
572 this->LegendActor->GetPosition2Coordinate()->SetValue(
573 (double)legPos2[0], (double)legPos2[1]);
574 this->LegendActor->SetNumberOfEntries(num);
575 for (int i=0; i<num; i++)
577 if ( ! this->LegendActor->GetEntrySymbol(i) )
579 this->LegendActor->SetEntrySymbol(i,this->GlyphSource->GetOutput());
581 if ( ! this->LegendActor->GetEntryString(i) )
583 static char legendString[12];
584 sprintf(legendString, "%s%d", "Curve ", i);
585 this->LegendActor->SetEntryString(i,legendString);
589 this->LegendActor->SetPadding(2);
590 this->LegendActor->GetProperty()->DeepCopy(this->GetProperty());
591 this->LegendActor->ScalarVisibilityOff();
595 // Perform shallow copy here since each individual axis can be
596 // accessed through the class API (i.e. each individual axis text prop
597 // can be changed). Therefore, we can not just assign pointers otherwise
598 // each individual axis text prop would point to the same text prop.
600 if (this->AxisLabelTextProperty &&
601 this->AxisLabelTextProperty->GetMTime() > this->BuildTime)
603 if (this->XAxis->GetLabelTextProperty())
605 this->XAxis->GetLabelTextProperty()->ShallowCopy(
606 this->AxisLabelTextProperty);
608 if (this->YAxis->GetLabelTextProperty())
610 this->YAxis->GetLabelTextProperty()->ShallowCopy(
611 this->AxisLabelTextProperty);
615 if (this->AxisTitleTextProperty &&
616 this->AxisTitleTextProperty->GetMTime() > this->BuildTime)
618 if (this->XAxis->GetTitleTextProperty())
620 this->XAxis->GetTitleTextProperty()->ShallowCopy(
621 this->AxisTitleTextProperty);
623 if (this->YAxis->GetTitleTextProperty())
625 this->YAxis->GetTitleTextProperty()->ShallowCopy(
626 this->AxisTitleTextProperty);
631 vtkDebugMacro(<<"Rebuilding x-axis");
633 this->XAxis->SetTitle(this->XTitle);
634 this->XAxis->SetNumberOfLabels(this->NumberOfXLabels);
635 this->XAxis->SetProperty(this->GetProperty());
637 vtkDebugMacro(<<"xrange = (" << range[0] << ", " << range[1] << ")"); // RKV
638 lengths = new double[num];
639 if ( numDS > 0 ) //plotting data sets
641 this->ComputeXRange(range, lengths);
645 this->ComputeDORange(range, yrange, lengths);
647 if ( this->XRange[0] < this->XRange[1] )
649 range[0] = this->XRange[0];
650 range[1] = this->XRange[1];
653 /* RKV vtkAxisActor2D::ComputeRange(range, xRange, this->NumberOfXLabels,
656 vtkDebugMacro(<<"XRange = (" << XRange[0] << ", " << XRange[1] << ")");
657 vtkDebugMacro(<<"xrange = (" << range[0] << ", " << range[1] << ")");
658 xRange[0] = range[0];
659 xRange[1] = range[1];
661 if ( !this->ExchangeAxes )
663 this->XComputedRange[0] = xRange[0];
664 this->XComputedRange[1] = xRange[1];
665 if ( this->ReverseXAxis )
667 this->XAxis->SetRange(range[1],range[0]);
671 this->XAxis->SetRange(range[0],range[1]);
676 this->XComputedRange[1] = xRange[0];
677 this->XComputedRange[0] = xRange[1];
678 if ( this->ReverseYAxis )
680 this->XAxis->SetRange(range[0],range[1]);
684 this->XAxis->SetRange(range[1],range[0]);
689 vtkDebugMacro(<<"Rebuilding y-axis");
690 this->YAxis->SetTitle(this->YTitle);
691 this->YAxis->SetNumberOfLabels(this->NumberOfYLabels);
693 vtkDebugMacro(<<"yrange = (" << yrange[0] << ", " << yrange[1] << ")"); // RKV
694 if ( this->YRange[0] >= this->YRange[1] )
696 if ( numDS > 0 ) //plotting data sets
698 this->ComputeYRange(yrange);
703 yrange[0] = this->YRange[0];
704 yrange[1] = this->YRange[1];
706 /* RKV vtkAxisActor2D::ComputeRange(yrange, yRange, this->NumberOfYLabels,
710 vtkDebugMacro(<<"YRange = (" << YRange[0] << ", " << YRange[1] << ")");
711 vtkDebugMacro(<<"yrange = (" << yrange[0] << ", " << yrange[1] << ")");
712 yRange[0] = yrange[0];
713 yRange[1] = yrange[1];
716 if ( !this->ExchangeAxes )
718 this->YComputedRange[0] = yRange[0];
719 this->YComputedRange[1] = yRange[1];
720 if ( this->ReverseYAxis )
722 this->YAxis->SetRange(yrange[0],yrange[1]);
726 this->YAxis->SetRange(yrange[1],yrange[0]);
731 this->YComputedRange[1] = yRange[0];
732 this->YComputedRange[0] = yRange[1];
733 if ( this->ReverseXAxis )
735 this->YAxis->SetRange(yrange[1],yrange[0]);
739 this->YAxis->SetRange(yrange[0],yrange[1]);
744 this->PlaceAxes(viewport, size, pos, pos2);
747 if (this->Title != NULL && this->Title[0])
749 this->TitleMapper->SetInput(this->Title);
750 if (this->TitleTextProperty->GetMTime() > this->BuildTime)
752 this->TitleMapper->GetTextProperty()->ShallowCopy(
753 this->TitleTextProperty);
757 #if (VTK_XVERSION < 0x050100)
758 //VSV: Function is not supported in VTK 5.2 and high
759 vtkAxisActor2D::SetFontSize(viewport,
766 this->TitleActor->GetPositionCoordinate()->SetValue(
767 pos[0] + 0.5 * (pos2[0] - pos[0]) - stringSize[0] / 2.0,
768 pos2[1] - stringSize[1] / 2.0);
770 this->TitleActor->SetProperty(this->GetProperty());
773 vtkDebugMacro(<<"Creating Plot Data");
774 // Okay, now create the plot data and set up the pipeline
775 this->CreatePlotData(pos, pos2, xRange, yRange, lengths, numDS, numDO);
778 this->BuildTime.Modified();
780 }//if need to rebuild the plot
782 vtkDebugMacro(<<"Rendering Axes");
783 renderedSomething += this->XAxis->RenderOpaqueGeometry(viewport);
784 renderedSomething += this->YAxis->RenderOpaqueGeometry(viewport);
785 for (int i=0; i < this->NumberOfInputs; i++)
787 vtkDebugMacro(<<"Rendering plotactors");
788 renderedSomething += this->PlotActor[i]->RenderOpaqueGeometry(viewport);
792 vtkDebugMacro(<<"Rendering titleactors");
793 renderedSomething += this->TitleActor->RenderOpaqueGeometry(viewport);
797 vtkDebugMacro(<<"Rendering legendeactors");
798 renderedSomething += this->LegendActor->RenderOpaqueGeometry(viewport);
801 return renderedSomething;
804 //----------------------------------------------------------------------------
805 const char *VISU_XYPlotActor::GetXValuesAsString()
807 switch (this->XValues)
809 case VTK_XYPLOT_INDEX:
811 case VTK_XYPLOT_ARC_LENGTH:
813 case VTK_XYPLOT_NORMALIZED_ARC_LENGTH:
814 return "NormalizedArcLength";
820 //----------------------------------------------------------------------------
821 const char *VISU_XYPlotActor::GetDataObjectPlotModeAsString()
823 if ( this->DataObjectPlotMode == VTK_XYPLOT_ROW )
829 return "Plot Columns";
833 //----------------------------------------------------------------------------
834 // Release any graphics resources that are being consumed by this actor.
835 // The parameter window could be used to determine which graphic
836 // resources to release.
837 void VISU_XYPlotActor::ReleaseGraphicsResources(vtkWindow *win)
839 this->TitleActor->ReleaseGraphicsResources(win);
840 this->XAxis->ReleaseGraphicsResources(win);
841 this->YAxis->ReleaseGraphicsResources(win);
842 for (int i=0; i < this->NumberOfInputs; i++)
844 this->PlotActor[i]->ReleaseGraphicsResources(win);
846 this->LegendActor->ReleaseGraphicsResources(win);
849 //----------------------------------------------------------------------------
850 unsigned long VISU_XYPlotActor::GetMTime()
852 unsigned long mtime, mtime2;
853 mtime = this->vtkActor2D::GetMTime();
857 mtime2 = this->LegendActor->GetMTime();
867 //----------------------------------------------------------------------------
868 void VISU_XYPlotActor::PrintSelf(ostream& os, vtkIndent indent)
870 vtkIndent i2 = indent.GetNextIndent();
876 this->Superclass::PrintSelf(os,indent);
878 vtkCollectionSimpleIterator dsit;
879 this->InputList->InitTraversal(dsit);
880 num = this->InputList->GetNumberOfItems();
881 os << indent << "DataSetInputs: " << endl;
882 for (idx = 0; idx < num; ++idx)
884 input = this->InputList->GetNextDataSet(dsit);
885 array = this->SelectedInputScalars[idx];
886 component = this->SelectedInputScalarsComponent->GetValue((vtkIdType)idx);
889 os << i2 << "(" << input << ") Default Scalars, Component = " << component << endl;
893 os << i2 << "(" << input << ") " << array << ", Component = " << component << endl;
897 os << indent << "Input DataObjects:\n";
898 this->DataObjectInputList->PrintSelf(os,indent.GetNextIndent());
900 if (this->TitleTextProperty)
902 os << indent << "Title Text Property:\n";
903 this->TitleTextProperty->PrintSelf(os,indent.GetNextIndent());
907 os << indent << "Title Text Property: (none)\n";
910 if (this->AxisTitleTextProperty)
912 os << indent << "Axis Title Text Property:\n";
913 this->AxisTitleTextProperty->PrintSelf(os,indent.GetNextIndent());
917 os << indent << "Axis Title Text Property: (none)\n";
920 if (this->AxisLabelTextProperty)
922 os << indent << "Axis Label Text Property:\n";
923 this->AxisLabelTextProperty->PrintSelf(os,indent.GetNextIndent());
927 os << indent << "Axis Label Text Property: (none)\n";
930 os << indent << "Data Object Plot Mode: " << this->GetDataObjectPlotModeAsString() << endl;
932 os << indent << "Title: " << (this->Title ? this->Title : "(none)") << "\n";
933 os << indent << "X Title: "
934 << (this->XTitle ? this->XTitle : "(none)") << "\n";
935 os << indent << "Y Title: "
936 << (this->YTitle ? this->YTitle : "(none)") << "\n";
938 os << indent << "X Values: " << this->GetXValuesAsString() << endl;
939 os << indent << "Log X Values: " << (this->Logx ? "On\n" : "Off\n");
941 os << indent << "Plot global-points: " << (this->PlotPoints ? "On\n" : "Off\n");
942 os << indent << "Plot global-lines: " << (this->PlotLines ? "On\n" : "Off\n");
943 os << indent << "Plot per-curve points: " << (this->PlotCurvePoints ? "On\n" : "Off\n");
944 os << indent << "Plot per-curve lines: " << (this->PlotCurveLines ? "On\n" : "Off\n");
945 os << indent << "Exchange Axes: " << (this->ExchangeAxes ? "On\n" : "Off\n");
946 os << indent << "Reverse X Axis: " << (this->ReverseXAxis ? "On\n" : "Off\n");
947 os << indent << "Reverse Y Axis: " << (this->ReverseYAxis ? "On\n" : "Off\n");
949 os << indent << "Number Of X Labels: " << this->NumberOfXLabels << "\n";
950 os << indent << "Number Of Y Labels: " << this->NumberOfYLabels << "\n";
952 os << indent << "Label Format: " << this->LabelFormat << "\n";
953 os << indent << "Border: " << this->Border << "\n";
955 os << indent << "X Range: ";
956 if ( this->XRange[0] >= this->XRange[1] )
958 os << indent << "(Automatically Computed)\n";
962 os << "(" << this->XRange[0] << ", " << this->XRange[1] << ")\n";
965 os << indent << "Y Range: ";
966 if ( this->XRange[0] >= this->YRange[1] )
968 os << indent << "(Automatically Computed)\n";
972 os << "(" << this->YRange[0] << ", " << this->YRange[1] << ")\n";
975 os << indent << "Viewport Coordinate: ("
976 << this->ViewportCoordinate[0] << ", "
977 << this->ViewportCoordinate[1] << ")\n";
979 os << indent << "Plot Coordinate: ("
980 << this->PlotCoordinate[0] << ", "
981 << this->PlotCoordinate[1] << ")\n";
983 os << indent << "Legend: " << (this->Legend ? "On\n" : "Off\n");
984 os << indent << "Legend Position: ("
985 << this->LegendPosition[0] << ", "
986 << this->LegendPosition[1] << ")\n";
987 os << indent << "Legend Position2: ("
988 << this->LegendPosition2[0] << ", "
989 << this->LegendPosition2[1] << ")\n";
991 os << indent << "Glyph Size: " << this->GlyphSize << endl;
993 os << indent << "Legend Actor:";
994 this->LegendActor->PrintSelf( os << endl, i2);
995 os << indent << "Glyph Source:";
996 this->GlyphSource->PrintSelf( os << endl, i2);
999 //----------------------------------------------------------------------------
1000 void VISU_XYPlotActor::ComputeXRange(double range[2], double *lengths)
1003 vtkIdType numPts, ptId, maxNum;
1004 double maxLength=0.0, xPrev[3], x[3];
1007 range[0] = VTK_DOUBLE_MAX, range[1] = VTK_DOUBLE_MIN;
1009 vtkCollectionSimpleIterator dsit;
1010 for ( dsNum=0, maxNum=0, this->InputList->InitTraversal(dsit);
1011 (ds = this->InputList->GetNextDataSet(dsit)); dsNum++)
1013 numPts = ds->GetNumberOfPoints();
1016 vtkErrorMacro(<<"No scalar data to plot!");
1020 if ( this->XValues != VTK_XYPLOT_INDEX )
1022 ds->GetPoint(0, xPrev);
1023 for ( lengths[dsNum]=0.0, ptId=0; ptId < numPts; ptId++ )
1025 ds->GetPoint(ptId, x);
1026 switch (this->XValues)
1028 case VTK_XYPLOT_VALUE:
1029 if (this->GetLogx() == 0)
1031 if ( x[this->XComponent->GetValue(dsNum)] < range[0] )
1033 range[0] = x[this->XComponent->GetValue(dsNum)];
1035 if ( x[this->XComponent->GetValue(dsNum)] > range[1] )
1037 range[1] = x[this->XComponent->GetValue(dsNum)];
1042 //ensure range strictly > 0 for log
1043 if ( (x[this->XComponent->GetValue(dsNum)]) < range[0] &&
1044 (x[this->XComponent->GetValue(dsNum)] > 0))
1046 range[0] = x[this->XComponent->GetValue(dsNum)];
1048 if ( (x[this->XComponent->GetValue(dsNum)] > range[1]) &&
1049 (x[this->XComponent->GetValue(dsNum)] > 0))
1051 range[1] = x[this->XComponent->GetValue(dsNum)];
1056 lengths[dsNum] += sqrt(vtkMath::Distance2BetweenPoints(x,xPrev));
1057 xPrev[0] = x[0]; xPrev[1] = x[1]; xPrev[2] = x[2];
1060 if ( lengths[dsNum] > maxLength )
1062 maxLength = lengths[dsNum];
1064 }//if need to visit all points
1066 else //if ( this->XValues == VTK_XYPLOT_INDEX )
1068 if ( numPts > maxNum )
1073 }//over all datasets
1075 // determine the range
1076 switch (this->XValues)
1078 case VTK_XYPLOT_ARC_LENGTH:
1080 range[1] = maxLength;
1082 case VTK_XYPLOT_NORMALIZED_ARC_LENGTH:
1086 case VTK_XYPLOT_INDEX:
1088 range[1] = (double)(maxNum - 1);
1090 case VTK_XYPLOT_VALUE:
1091 if (this->GetLogx() == 1)
1093 if (range[0] > range[1])
1100 range[0] = log10(range[0]);
1101 range[1] = log10(range[1]);
1104 break; //range computed in for loop above
1106 vtkErrorMacro(<< "Unkown X-Value option.");
1111 //----------------------------------------------------------------------------
1112 void VISU_XYPlotActor::ComputeYRange(double range[2])
1115 vtkDataArray *scalars;
1120 range[0]=VTK_DOUBLE_MAX, range[1]=VTK_DOUBLE_MIN;
1122 vtkCollectionSimpleIterator dsit;
1123 for ( this->InputList->InitTraversal(dsit), count = 0;
1124 (ds = this->InputList->GetNextDataSet(dsit)); ++count)
1126 scalars = ds->GetPointData()->GetScalars(this->SelectedInputScalars[count]);
1127 component = this->SelectedInputScalarsComponent->GetValue(count);
1130 vtkErrorMacro(<<"No scalar data to plot!");
1133 if ( component < 0 || component >= scalars->GetNumberOfComponents())
1135 vtkErrorMacro(<<"Bad component!");
1139 scalars->GetRange(sRange, component);
1140 if ( sRange[0] < range[0] )
1142 range[0] = sRange[0];
1145 if ( sRange[1] > range[1] )
1147 range[1] = sRange[1];
1149 }//over all datasets
1152 //----------------------------------------------------------------------------
1153 static inline int VISU_XYPlotActorGetComponent(vtkFieldData* field,
1154 vtkIdType tuple, int component, double* val)
1157 int array_index = field->GetArrayContainingComponent(component, array_comp);
1158 if (array_index < 0)
1162 vtkDataArray* da = field->GetArray(array_index);
1165 // non-numeric array.
1168 *val = da->GetComponent(tuple, array_comp);
1172 //----------------------------------------------------------------------------
1173 void VISU_XYPlotActor::ComputeDORange(double xrange[2], double yrange[2],
1177 vtkDataObject *dobj;
1178 vtkFieldData *field;
1179 int doNum, numColumns;
1180 vtkIdType numTuples, numRows, num, ptId, maxNum;
1181 double maxLength=0.0;
1185 vtkDataArray *array;
1187 // NOTE: FieldData can have non-numeric arrays. However, XY plot can only
1188 // work on numeric arrays (or vtkDataArray subclasses).
1190 xrange[0] = yrange[0] = VTK_DOUBLE_MAX;
1191 xrange[1] = yrange[1] = -VTK_DOUBLE_MAX;
1192 vtkCollectionSimpleIterator doit;
1193 for ( doNum=0, maxNum=0, this->DataObjectInputList->InitTraversal(doit);
1194 (dobj = this->DataObjectInputList->GetNextDataObject(doit)); doNum++)
1197 lengths[doNum] = 0.0;
1198 field = dobj->GetFieldData();
1199 numColumns = field->GetNumberOfComponents(); //number of "columns"
1200 // numColumns includes the components for non-numeric arrays as well.
1201 for (numRows = VTK_LARGE_ID, i=0; i<field->GetNumberOfArrays(); i++)
1203 array = field->GetArray(i);
1206 // non-numeric array, skip.
1209 numTuples = array->GetNumberOfTuples();
1210 if ( numTuples < numRows )
1212 numRows = numTuples;
1216 num = (this->DataObjectPlotMode == VTK_XYPLOT_ROW ?
1217 numColumns : numRows);
1219 if ( this->XValues != VTK_XYPLOT_INDEX )
1221 // gather the information to form a plot
1222 for ( ptId=0; ptId < num; ptId++ )
1226 if ( this->DataObjectPlotMode == VTK_XYPLOT_ROW )
1228 // x = field->GetComponent(this->XComponent->GetValue(doNum), ptId);
1229 status = ::VISU_XYPlotActorGetComponent(field,
1230 this->XComponent->GetValue(doNum), ptId, &x);
1232 else //if ( this->DataObjectPlotMode == VTK_XYPLOT_COLUMN )
1234 // x = field->GetComponent(ptId, this->XComponent->GetValue(doNum));
1235 status = ::VISU_XYPlotActorGetComponent(field,
1236 ptId, this->XComponent->GetValue(doNum), &x);
1240 // requested component falls in a non-numeric array, skip it.
1248 switch (this->XValues)
1250 case VTK_XYPLOT_VALUE:
1251 if (this->GetLogx() == 0)
1253 if ( x < xrange[0] )
1257 if ( x > xrange[1] )
1262 else //ensure positive values
1264 if ( (x < xrange[0]) && (x > 0) )
1268 if ( x > xrange[1] && (x > 0) )
1275 lengths[doNum] += fabs(x-xPrev);
1279 if ( lengths[doNum] > maxLength )
1281 maxLength = lengths[doNum];
1283 }//if all data has to be visited
1285 else //if (this->XValues == VTK_XYPLOT_INDEX)
1294 for ( ptId=0; ptId < num; ptId++ )
1297 if ( this->DataObjectPlotMode == VTK_XYPLOT_ROW )
1299 //y = field->GetComponent(this->YComponent->GetValue(doNum), ptId);
1300 status = ::VISU_XYPlotActorGetComponent(field,
1301 this->YComponent->GetValue(doNum), ptId, &y);
1303 else //if ( this->DataObjectPlotMode == VTK_XYPLOT_COLUMN )
1305 //y = field->GetComponent(ptId, this->YComponent->GetValue(doNum));
1306 status = ::VISU_XYPlotActorGetComponent(field,
1307 ptId, this->YComponent->GetValue(doNum), &y);
1311 // requested component falls in non-numeric array.
1315 if ( y < yrange[0] )
1319 if ( y > yrange[1] )
1323 }//over all y values
1324 }//over all dataobjects
1326 // determine the range
1327 switch (this->XValues)
1329 case VTK_XYPLOT_ARC_LENGTH:
1331 xrange[1] = maxLength;
1333 case VTK_XYPLOT_NORMALIZED_ARC_LENGTH:
1337 case VTK_XYPLOT_INDEX:
1339 xrange[1] = (double)(maxNum - 1);
1341 case VTK_XYPLOT_VALUE:
1342 if (this->GetLogx() == 1)
1344 xrange[0] = log10(xrange[0]);
1345 xrange[1] = log10(xrange[1]);
1349 vtkErrorMacro(<< "Unknown X-Value option");
1354 //----------------------------------------------------------------------------
1355 /* RKV void VISU_XYPlotActor::CreatePlotData(int *pos, int *pos2, double xRange[2],
1356 double yRange[2], double *lengths,
1357 int numDS, int numDO) */
1359 void VISU_XYPlotActor::CreatePlotData(int *pos, int *pos2Extern, double xRange[2],
1360 double yRange[2], double *lengths,
1361 int numDS, int numDO)
1364 double xyz[3]; xyz[2] = 0.0;
1365 int i, numLinePts, dsNum, doNum, num;
1366 vtkIdType numPts, ptId, id;
1367 double length, x[3], xPrev[3];
1368 vtkDataArray *scalars;
1371 vtkCellArray *lines;
1373 int clippingRequired = 0;
1375 // Allocate resources for the polygonal plots
1377 num = (numDS > numDO ? numDS : numDO);
1378 this->InitializeEntries();
1379 this->NumberOfInputs = num;
1380 this->PlotData = new vtkPolyData* [num];
1381 this->PlotGlyph = new vtkGlyph2D* [num];
1382 this->PlotAppend = new vtkAppendPolyData* [num];
1383 this->PlotTransform = new vtkTransformPolyDataFilter* [num]; // RKV
1384 this->PlotMapper = new vtkPolyDataMapper2D* [num];
1385 this->PlotActor = new vtkActor2D* [num];
1388 // Prepare the transformation of the curve according to the plot location
1389 vtkTransform *tf = vtkTransform::New();
1390 tf->Translate(pos[0], pos[1], 0);
1391 if ((this->PlotLocation == VISU_XYPLOT_LEFT) || (this->PlotLocation == VISU_XYPLOT_RIGHT))
1393 tf->Translate(-pos[0], -pos[1], 0);
1395 // Compute the position2 to build the curve before the transformation
1397 vtkDebugMacro(<< "pos = (" << pos[0] << ", " << pos[1] << ")");
1398 vtkDebugMacro(<< "pos2 = (" << pos2Extern[0] << ", " << pos2Extern[1] << ")");
1399 if ((this->PlotLocation == VISU_XYPLOT_LEFT) || (this->PlotLocation == VISU_XYPLOT_RIGHT))
1401 pos2[0] = pos[0] + pos2Extern[1] - pos[1];
1402 pos2[1] = pos[1] + pos[0] - pos2Extern[0];
1406 pos2[0] = pos2Extern[0];
1407 pos2[1] = pos2Extern[1];
1411 for (i=0; i<num; i++)
1413 this->PlotData[i] = vtkPolyData::New();
1414 this->PlotGlyph[i] = vtkGlyph2D::New();
1415 this->PlotGlyph[i]->SetInput(this->PlotData[i]);
1416 this->PlotGlyph[i]->SetScaleModeToDataScalingOff();
1417 this->PlotAppend[i] = vtkAppendPolyData::New();
1418 this->PlotAppend[i]->AddInput(this->PlotData[i]);
1419 if ( this->LegendActor->GetEntrySymbol(i) != NULL &&
1420 this->LegendActor->GetEntrySymbol(i) != this->GlyphSource->GetOutput() )
1422 this->PlotGlyph[i]->SetSource(this->LegendActor->GetEntrySymbol(i));
1423 this->PlotGlyph[i]->SetScaleFactor(this->ComputeGlyphScale(i,pos,pos2));
1424 this->PlotAppend[i]->AddInput(this->PlotGlyph[i]->GetOutput());
1426 this->PlotMapper[i] = vtkPolyDataMapper2D::New();
1429 // Insert a transformation filter into the pipeline to
1430 // take into account a plot location.
1431 this->PlotTransform[i] = vtkTransformPolyDataFilter::New();
1432 this->PlotTransform[i]->SetInput(this->PlotAppend[i]->GetOutput());
1433 this->PlotTransform[i]->SetTransform(tf);
1434 this->PlotMapper[i]->SetInput(this->PlotTransform[i]->GetOutput());
1437 // RKV this->PlotMapper[i]->SetInput(this->PlotAppend[i]->GetOutput());
1438 this->PlotMapper[i]->ScalarVisibilityOff();
1439 this->PlotActor[i] = vtkActor2D::New();
1440 this->PlotActor[i]->SetMapper(this->PlotMapper[i]);
1441 this->PlotActor[i]->GetProperty()->DeepCopy(this->GetProperty());
1442 if ( this->LegendActor->GetEntryColor(i)[0] < 0.0 )
1444 this->PlotActor[i]->GetProperty()->SetColor(
1445 this->GetProperty()->GetColor());
1449 this->PlotActor[i]->GetProperty()->SetColor(
1450 this->LegendActor->GetEntryColor(i));
1454 tf->Delete(); // RKV
1456 // Prepare to receive data
1457 this->GenerateClipPlanes(pos,pos2);
1458 for (i=0; i<this->NumberOfInputs; i++)
1460 lines = vtkCellArray::New();
1461 pts = vtkPoints::New();
1463 lines->Allocate(10,10);
1464 pts->Allocate(10,10);
1465 this->PlotData[i]->SetPoints(pts);
1466 this->PlotData[i]->SetVerts(lines);
1467 this->PlotData[i]->SetLines(lines);
1473 // Okay, for each input generate plot data. Depending on the input
1474 // we use either dataset or data object.
1478 vtkCollectionSimpleIterator dsit;
1479 for ( dsNum=0, this->InputList->InitTraversal(dsit);
1480 (ds = this->InputList->GetNextDataSet(dsit)); dsNum++ )
1482 clippingRequired = 0;
1483 numPts = ds->GetNumberOfPoints();
1484 scalars = ds->GetPointData()->GetScalars(this->SelectedInputScalars[dsNum]);
1489 component = this->SelectedInputScalarsComponent->GetValue(dsNum);
1490 if ( component < 0 || component >= scalars->GetNumberOfComponents())
1495 pts = this->PlotData[dsNum]->GetPoints();
1496 lines = this->PlotData[dsNum]->GetLines();
1497 lines->InsertNextCell(0); //update the count later
1499 ds->GetPoint(0, xPrev);
1500 for ( numLinePts=0, length=0.0, ptId=0; ptId < numPts; ptId++ )
1502 xyz[1] = scalars->GetComponent(ptId, component);
1503 ds->GetPoint(ptId, x);
1504 switch (this->XValues)
1506 case VTK_XYPLOT_NORMALIZED_ARC_LENGTH:
1507 length += sqrt(vtkMath::Distance2BetweenPoints(x,xPrev));
1508 xyz[0] = length / lengths[dsNum];
1509 xPrev[0] = x[0]; xPrev[1] = x[1]; xPrev[2] = x[2];
1511 case VTK_XYPLOT_INDEX:
1512 xyz[0] = (double)ptId;
1514 case VTK_XYPLOT_ARC_LENGTH:
1515 length += sqrt(vtkMath::Distance2BetweenPoints(x,xPrev));
1517 xPrev[0] = x[0]; xPrev[1] = x[1]; xPrev[2] = x[2];
1519 case VTK_XYPLOT_VALUE:
1520 xyz[0] = x[this->XComponent->GetValue(dsNum)];
1523 vtkErrorMacro(<< "Unknown X-Component option");
1526 if ( this->GetLogx() == 1 )
1530 xyz[0] = log10(xyz[0]);
1531 // normalize and position
1532 if ( xyz[0] < xRange[0] || xyz[0] > xRange[1] ||
1533 xyz[1] < yRange[0] || xyz[1] > yRange[1] )
1535 clippingRequired = 1;
1539 xyz[0] = fabs( xRange[1] - xRange[0] ) < 1.0 / VTK_LARGE_FLOAT ? pos[0] : pos[0] +
1540 (xyz[0]-xRange[0])/(xRange[1]-xRange[0])*(pos2[0]-pos[0]);
1541 xyz[1] = fabs( yRange[1] - yRange[0] ) < 1.0 / VTK_LARGE_FLOAT ? pos[1] : pos[1] +
1542 (xyz[1]-yRange[0])/(yRange[1]-yRange[0])*(pos2[1]-pos[1]);
1543 id = pts->InsertNextPoint(xyz);
1544 lines->InsertCellPoint(id);
1549 // normalize and position
1550 if ( xyz[0] < xRange[0] || xyz[0] > xRange[1] ||
1551 xyz[1] < yRange[0] || xyz[1] > yRange[1] )
1553 clippingRequired = 1;
1557 xyz[0] = fabs( xRange[1] - xRange[0] ) < 1.0 / VTK_LARGE_FLOAT ? pos[0] : pos[0] +
1558 (xyz[0]-xRange[0])/(xRange[1]-xRange[0])*(pos2[0]-pos[0]);
1559 xyz[1] = fabs( yRange[1] - yRange[0] ) < 1.0 / VTK_LARGE_FLOAT ? pos[1] : pos[1] +
1560 (xyz[1]-yRange[0])/(yRange[1]-yRange[0])*(pos2[1]-pos[1]);
1561 id = pts->InsertNextPoint(xyz);
1562 lines->InsertCellPoint(id);
1564 }//for all input points
1566 lines->UpdateCellCount(numLinePts);
1567 if ( clippingRequired )
1569 this->ClipPlotData(pos,pos2,this->PlotData[dsNum]);
1571 }//loop over all input data sets
1572 }//if plotting datasets
1574 else //plot data from data objects
1576 vtkDataObject *dobj;
1578 vtkIdType numRows, numTuples;
1579 vtkDataArray *array;
1580 vtkFieldData *field;
1581 vtkCollectionSimpleIterator doit;
1582 for ( doNum=0, this->DataObjectInputList->InitTraversal(doit);
1583 (dobj = this->DataObjectInputList->GetNextDataObject(doit));
1586 // determine the shape of the field
1587 field = dobj->GetFieldData();
1588 numColumns = field->GetNumberOfComponents(); //number of "columns"
1589 // numColumns also includes non-numeric array components.
1590 for (numRows = VTK_LARGE_ID, i=0; i<field->GetNumberOfArrays(); i++)
1592 array = field->GetArray(i);
1595 // skip non-numeric arrays.
1598 numTuples = array->GetNumberOfTuples();
1599 if ( numTuples < numRows )
1601 numRows = numTuples;
1605 pts = this->PlotData[doNum]->GetPoints();
1606 lines = this->PlotData[doNum]->GetLines();
1607 lines->InsertNextCell(0); //update the count later
1609 numPts = (this->DataObjectPlotMode == VTK_XYPLOT_ROW ?
1610 numColumns : numRows);
1612 // gather the information to form a plot
1613 for ( numLinePts=0, length=0.0, ptId=0; ptId < numPts; ptId++ )
1615 int status1, status2;
1616 if ( this->DataObjectPlotMode == VTK_XYPLOT_ROW )
1618 //x[0] = field->GetComponent(this->XComponent->GetValue(doNum),ptId);
1619 //xyz[1] = field->GetComponent(this->YComponent->GetValue(doNum),ptId);
1620 status1 = ::VISU_XYPlotActorGetComponent(field,
1621 this->XComponent->GetValue(doNum), ptId, &x[0]);
1622 status2 = ::VISU_XYPlotActorGetComponent(field,
1623 this->YComponent->GetValue(doNum), ptId, &xyz[1]);
1625 else //if ( this->DataObjectPlotMode == VTK_XYPLOT_COLUMN )
1627 //x[0] = field->GetComponent(ptId, this->XComponent->GetValue(doNum));
1628 //xyz[1] = field->GetComponent(ptId, this->YComponent->GetValue(doNum));
1630 status1 = ::VISU_XYPlotActorGetComponent(field,
1631 ptId, this->XComponent->GetValue(doNum), &x[0]);
1635 vtkWarningMacro(<< this->XComponent->GetValue(doNum) << " is a non-numeric component.");
1638 status2 = ::VISU_XYPlotActorGetComponent(field,
1639 ptId, this->YComponent->GetValue(doNum), &xyz[1]);
1643 vtkWarningMacro(<< this->YComponent->GetValue(doNum) << " is a non-numeric component.");
1646 if (!status1 || !status2)
1648 // component is non-numeric.
1653 switch (this->XValues)
1655 case VTK_XYPLOT_NORMALIZED_ARC_LENGTH:
1656 length += fabs(x[0]-xPrev[0]);
1657 xyz[0] = length / lengths[doNum];
1660 case VTK_XYPLOT_INDEX:
1661 xyz[0] = (double)ptId;
1663 case VTK_XYPLOT_ARC_LENGTH:
1664 length += fabs(x[0]-xPrev[0]);
1668 case VTK_XYPLOT_VALUE:
1672 vtkErrorMacro(<< "Unknown X-Value option");
1675 if ( this->GetLogx() == 1 )
1679 xyz[0] = log10(xyz[0]);
1680 // normalize and position
1681 if ( xyz[0] < xRange[0] || xyz[0] > xRange[1] ||
1682 xyz[1] < yRange[0] || xyz[1] > yRange[1] )
1684 clippingRequired = 1;
1687 xyz[0] = fabs( xRange[1] - xRange[0] ) < 1.0 / VTK_LARGE_FLOAT ? pos[0] : pos[0] +
1688 (xyz[0]-xRange[0])/(xRange[1]-xRange[0])*(pos2[0]-pos[0]);
1689 xyz[1] = fabs( yRange[1] - yRange[0] ) < 1.0 / VTK_LARGE_FLOAT ? pos[1] : pos[1] +
1690 (xyz[1]-yRange[0])/(yRange[1]-yRange[0])*(pos2[1]-pos[1]);
1691 id = pts->InsertNextPoint(xyz);
1692 lines->InsertCellPoint(id);
1697 // normalize and position
1698 if ( xyz[0] < xRange[0] || xyz[0] > xRange[1] ||
1699 xyz[1] < yRange[0] || xyz[1] > yRange[1] )
1701 clippingRequired = 1;
1704 xyz[0] = fabs( xRange[1] - xRange[0] ) < 1.0 / VTK_LARGE_FLOAT ? pos[0] : pos[0] +
1705 (xyz[0]-xRange[0])/(xRange[1]-xRange[0])*(pos2[0]-pos[0]);
1706 xyz[1] = fabs( yRange[1] - yRange[0] ) < 1.0 / VTK_LARGE_FLOAT ? pos[1] : pos[1] +
1707 (xyz[1]-yRange[0])/(yRange[1]-yRange[0])*(pos2[1]-pos[1]);
1708 id = pts->InsertNextPoint(xyz);
1709 lines->InsertCellPoint(id);
1711 }//for all input points
1713 lines->UpdateCellCount(numLinePts);
1714 if ( clippingRequired )
1716 this->ClipPlotData(pos,pos2,this->PlotData[doNum]);
1718 }//loop over all input data sets
1721 // Remove points/lines as directed by the user
1722 for ( i = 0; i < num; i++)
1724 if (!this->PlotCurveLines)
1726 if ( !this->PlotLines )
1728 this->PlotData[i]->SetLines(NULL);
1733 if ( this->GetPlotLines(i) == 0)
1735 this->PlotData[i]->SetLines(NULL);
1739 if (!this->PlotCurvePoints)
1741 if ( !this->PlotPoints || (this->LegendActor->GetEntrySymbol(i) &&
1742 this->LegendActor->GetEntrySymbol(i) !=
1743 this->GlyphSource->GetOutput()))
1745 this->PlotData[i]->SetVerts(NULL);
1750 if ( this->GetPlotPoints(i) == 0 ||
1751 (this->LegendActor->GetEntrySymbol(i) &&
1752 this->LegendActor->GetEntrySymbol(i) !=
1753 this->GlyphSource->GetOutput()))
1755 this->PlotData[i]->SetVerts(NULL);
1761 //----------------------------------------------------------------------------
1762 // Position the axes taking into account the expected padding due to labels
1763 // and titles. We want the result to fit in the box specified. This method
1764 // knows something about how the vtkAxisActor2D functions, so it may have
1765 // to change if that class changes dramatically.
1767 void VISU_XYPlotActor::PlaceAxes(vtkViewport *viewport, int *size,
1768 int pos[2], int pos2[2])
1770 int titleSizeX[2], titleSizeY[2], labelSizeX[2], labelSizeY[2];
1771 double labelFactorX, labelFactorY;
1772 double fontFactorX, fontFactorY;
1773 double tickOffsetX, tickOffsetY;
1774 double tickLengthX, tickLengthY;
1776 vtkAxisActor2D *axisX;
1777 vtkAxisActor2D *axisY;
1779 char str1[512], str2[512];
1781 if (this->ExchangeAxes)
1783 axisX = this->YAxis;
1784 axisY = this->XAxis;
1788 axisX = this->XAxis;
1789 axisY = this->YAxis;
1793 // Take into account a location of the plot.
1794 if ((this->PlotLocation == VISU_XYPLOT_LEFT) || (this->PlotLocation == VISU_XYPLOT_RIGHT))
1796 vtkAxisActor2D *axisBid;
1804 fontFactorY = axisY->GetFontFactor();
1805 fontFactorX = axisX->GetFontFactor();
1807 labelFactorY = axisY->GetLabelFactor();
1808 labelFactorX = axisX->GetLabelFactor();
1810 // Create a dummy text mapper for getting font sizes
1811 vtkTextMapper *textMapper = vtkTextMapper::New();
1812 vtkTextProperty *tprop = textMapper->GetTextProperty();
1814 // Get the location of the corners of the box
1815 int *p1 = this->PositionCoordinate->GetComputedViewportValue(viewport);
1816 int *p2 = this->Position2Coordinate->GetComputedViewportValue(viewport);
1818 // Estimate the padding around the X and Y axes
1819 tprop->ShallowCopy(axisX->GetTitleTextProperty());
1820 textMapper->SetInput(axisX->GetTitle());
1822 #if (VTK_XVERSION < 0x050100)
1823 //VSV: Function is not supported in VTK 5.2 and high
1824 vtkAxisActor2D::SetFontSize(
1825 viewport, textMapper, size, fontFactorX, titleSizeX);
1828 tprop->ShallowCopy(axisY->GetTitleTextProperty());
1829 textMapper->SetInput(axisY->GetTitle());
1831 #if (VTK_XVERSION < 0x050100)
1832 //VSV: Function is not supported in VTK 5.2 and high
1833 vtkAxisActor2D::SetFontSize(
1834 viewport, textMapper, size, fontFactorY, titleSizeY);
1837 // At this point the thing to do would be to actually ask the Y axis
1838 // actor to return the largest label.
1839 // In the meantime, let's try with the min and max
1840 sprintf(str1, axisY->GetLabelFormat(), axisY->GetAdjustedRange()[0]);
1841 sprintf(str2, axisY->GetLabelFormat(), axisY->GetAdjustedRange()[1]);
1842 tprop->ShallowCopy(axisY->GetLabelTextProperty());
1843 textMapper->SetInput(strlen(str1) > strlen(str2) ? str1 : str2);
1845 #if (VTK_XVERSION < 0x050100)
1846 //VSV: Function is not supported in VTK 5.2 and high
1847 vtkAxisActor2D::SetFontSize(
1848 viewport, textMapper, size, labelFactorY * fontFactorY, labelSizeY);
1851 // We do only care of the height of the label in the X axis, so let's
1852 // use the min for example
1853 sprintf(str1, axisX->GetLabelFormat(), axisX->GetAdjustedRange()[0]);
1854 tprop->ShallowCopy(axisX->GetLabelTextProperty());
1855 textMapper->SetInput(str1);
1857 #if (VTK_XVERSION < 0x050100)
1858 //VSV: Function is not supported in VTK 5.2 and high
1859 vtkAxisActor2D::SetFontSize(
1860 viewport, textMapper, size, labelFactorX * fontFactorX, labelSizeX);
1863 tickOffsetX = axisX->GetTickOffset();
1864 tickOffsetY = axisY->GetTickOffset();
1865 tickLengthX = axisX->GetTickLength();
1866 tickLengthY = axisY->GetTickLength();
1868 // Okay, estimate the size
1869 /* RKV pos[0] = (int)(p1[0] + titleSizeY[0] + 2.0 * tickOffsetY + tickLengthY +
1870 labelSizeY[0] + this->Border);
1872 pos[1] = (int)(p1[1] + titleSizeX[1] + 2.0 * tickOffsetX + tickLengthX +
1873 labelSizeX[1] + this->Border);
1875 pos2[0] = (int)(p2[0] - labelSizeY[0] / 2 - tickOffsetY - this->Border);
1877 pos2[1] = (int)(p2[1] - labelSizeX[1] / 2 - tickOffsetX - this->Border);
1880 pos[0] = (int)(p1[0]);
1882 pos[1] = (int)(p1[1]);
1884 pos2[0] = (int)(p2[0]);
1886 pos2[1] = (int)(p2[1]);
1889 // Now specify the location of the axes
1890 axisX->GetPositionCoordinate()->SetValue(
1891 (double)pos[0], (double)pos[1]);
1892 axisX->GetPosition2Coordinate()->SetValue(
1893 (double)pos2[0], (double)pos[1]);
1894 axisY->GetPositionCoordinate()->SetValue(
1895 (double)pos[0], (double)pos2[1]);
1896 axisY->GetPosition2Coordinate()->SetValue(
1897 (double)pos[0], (double)pos[1]);
1899 textMapper->Delete();
1902 //----------------------------------------------------------------------------
1903 void VISU_XYPlotActor::ViewportToPlotCoordinate(vtkViewport *viewport, double &u, double &v)
1907 // XAxis, YAxis are in viewport coordinates already
1908 p0 = this->XAxis->GetPositionCoordinate()->GetComputedViewportValue(viewport);
1909 p1 = this->XAxis->GetPosition2Coordinate()->GetComputedViewportValue(viewport);
1910 p2 = this->YAxis->GetPositionCoordinate()->GetComputedViewportValue(viewport);
1912 u = ((u - p0[0]) / (double)(p1[0] - p0[0]))
1913 *(this->XComputedRange[1] - this->XComputedRange[0])
1914 + this->XComputedRange[0];
1915 v = ((v - p0[1]) / (double)(p2[1] - p0[1]))
1916 *(this->YComputedRange[1] - this->YComputedRange[0])
1917 + this->YComputedRange[0];
1920 //----------------------------------------------------------------------------
1921 void VISU_XYPlotActor::PlotToViewportCoordinate(vtkViewport *viewport,
1922 double &u, double &v)
1926 // XAxis, YAxis are in viewport coordinates already
1927 p0 = this->XAxis->GetPositionCoordinate()->GetComputedViewportValue(viewport);
1928 p1 = this->XAxis->GetPosition2Coordinate()->GetComputedViewportValue(viewport);
1929 p2 = this->YAxis->GetPositionCoordinate()->GetComputedViewportValue(viewport);
1931 u = (((u - this->XComputedRange[0])
1932 / (this->XComputedRange[1] - this->XComputedRange[0]))
1933 * (double)(p1[0] - p0[0])) + p0[0];
1934 v = (((v - this->YComputedRange[0])
1935 / (this->YComputedRange[1] - this->YComputedRange[0]))
1936 * (double)(p2[1] - p0[1])) + p0[1];
1939 //----------------------------------------------------------------------------
1940 void VISU_XYPlotActor::ViewportToPlotCoordinate(vtkViewport *viewport)
1942 this->ViewportToPlotCoordinate(viewport,
1943 this->ViewportCoordinate[0],
1944 this->ViewportCoordinate[1]);
1947 //----------------------------------------------------------------------------
1948 void VISU_XYPlotActor::PlotToViewportCoordinate(vtkViewport *viewport)
1950 this->PlotToViewportCoordinate(viewport,
1951 this->PlotCoordinate[0],
1952 this->PlotCoordinate[1]);
1955 //----------------------------------------------------------------------------
1956 int VISU_XYPlotActor::IsInPlot(vtkViewport *viewport, double u, double v)
1960 // Bounds of the plot are based on the axes...
1961 p0 = this->XAxis->GetPositionCoordinate()->GetComputedViewportValue(viewport);
1962 p1 = this->XAxis->GetPosition2Coordinate()->GetComputedViewportValue(viewport);
1963 p2 = this->YAxis->GetPositionCoordinate()->GetComputedViewportValue(viewport);
1965 if (u >= p0[0] && u <= p1[0] && v >= p0[1] && v <= p2[1])
1973 //----------------------------------------------------------------------------
1974 void VISU_XYPlotActor::SetPlotLines(int i, int isOn)
1976 i = ( i < 0 ? 0 : (i >=VTK_MAX_PLOTS ? VTK_MAX_PLOTS-1 : i));
1977 int val = this->LinesOn->GetValue(i);
1981 this->LinesOn->SetValue(i, isOn);
1985 //----------------------------------------------------------------------------
1986 int VISU_XYPlotActor::GetPlotLines(int i)
1988 i = ( i < 0 ? 0 : (i >=VTK_MAX_PLOTS ? VTK_MAX_PLOTS-1 : i));
1989 return this->LinesOn->GetValue(i);
1992 //----------------------------------------------------------------------------
1993 void VISU_XYPlotActor::SetPlotPoints(int i, int isOn)
1995 i = ( i < 0 ? 0 : (i >=VTK_MAX_PLOTS ? VTK_MAX_PLOTS-1 : i));
1996 int val = this->PointsOn->GetValue(i);
2000 this->PointsOn->SetValue(i, isOn);
2004 //----------------------------------------------------------------------------
2005 int VISU_XYPlotActor::GetPlotPoints(int i)
2007 i = ( i < 0 ? 0 : (i >=VTK_MAX_PLOTS ? VTK_MAX_PLOTS-1 : i));
2008 return this->PointsOn->GetValue(i);
2011 //----------------------------------------------------------------------------
2012 void VISU_XYPlotActor::SetPlotColor(int i, double r, double g, double b)
2014 this->LegendActor->SetEntryColor(i, r, g, b);
2017 //----------------------------------------------------------------------------
2018 double *VISU_XYPlotActor::GetPlotColor(int i)
2020 return this->LegendActor->GetEntryColor(i);
2023 //----------------------------------------------------------------------------
2024 void VISU_XYPlotActor::SetPlotSymbol(int i,vtkPolyData *input)
2026 this->LegendActor->SetEntrySymbol(i, input);
2029 //----------------------------------------------------------------------------
2030 vtkPolyData *VISU_XYPlotActor::GetPlotSymbol(int i)
2032 return this->LegendActor->GetEntrySymbol(i);
2035 //----------------------------------------------------------------------------
2036 void VISU_XYPlotActor::SetPlotLabel(int i, const char *label)
2038 this->LegendActor->SetEntryString(i, label);
2041 //----------------------------------------------------------------------------
2042 const char *VISU_XYPlotActor::GetPlotLabel(int i)
2044 return this->LegendActor->GetEntryString(i);
2047 //----------------------------------------------------------------------------
2048 void VISU_XYPlotActor::GenerateClipPlanes(int *pos, int *pos2)
2051 vtkPoints *pts=this->ClipPlanes->GetPoints();
2052 vtkDataArray *normals=this->ClipPlanes->GetNormals();
2059 normals->SetTuple(0,n);
2060 x[0] = (double)0.5*(pos[0]+pos2[0]);
2061 x[1] = (double)pos[1];
2067 normals->SetTuple(1,n);
2068 x[0] = (double)pos2[0];
2069 x[1] = (double)0.5*(pos[1]+pos2[1]);
2075 normals->SetTuple(2,n);
2076 x[0] = (double)0.5*(pos[0]+pos2[0]);
2077 x[1] = (double)pos2[1];
2083 normals->SetTuple(3,n);
2084 x[0] = (double)pos[0];
2085 x[1] = (double)0.5*(pos[1]+pos2[1]);
2089 //----------------------------------------------------------------------------
2090 double VISU_XYPlotActor::ComputeGlyphScale(int i, int *pos, int *pos2)
2092 vtkPolyData *pd=this->LegendActor->GetEntrySymbol(i);
2094 double length=pd->GetLength();
2095 double sf = this->GlyphSize * sqrt((double)(pos[0]-pos2[0])*(pos[0]-pos2[0]) +
2096 (pos[1]-pos2[1])*(pos[1]-pos2[1])) / length;
2101 //----------------------------------------------------------------------------
2102 //This assumes that there are multiple polylines
2103 void VISU_XYPlotActor::ClipPlotData(int *pos, int *pos2, vtkPolyData *pd)
2105 vtkPoints *points=pd->GetPoints();
2106 vtkPoints *newPoints;
2107 vtkCellArray *lines=pd->GetLines();
2108 vtkCellArray *newLines, *newVerts;
2109 vtkIdType numPts=pd->GetNumberOfPoints();
2111 vtkIdType newPts[2];
2115 double x1[3], x2[3], px[3], n[3], xint[3], t;
2116 double p1[2], p2[2];
2118 p1[0] = (double)pos[0]; p1[1] = (double)pos[1];
2119 p2[0] = (double)pos2[0]; p2[1] = (double)pos2[1];
2121 newPoints = vtkPoints::New();
2122 newPoints->Allocate(numPts);
2123 newVerts = vtkCellArray::New();
2124 newVerts->Allocate(lines->GetSize());
2125 newLines = vtkCellArray::New();
2126 newLines->Allocate(2*lines->GetSize());
2127 int *pointMap = new int [numPts];
2128 for (i=0; i<numPts; i++)
2133 //Loop over polyverts eliminating those that are outside
2134 for ( lines->InitTraversal(); lines->GetNextCell(npts,pts); )
2136 //loop over verts keeping only those that are not clipped
2137 for (i=0; i<npts; i++)
2139 points->GetPoint(pts[i], x1);
2141 if (x1[0] >= p1[0] && x1[0] <= p2[0] && x1[1] >= p1[1] && x1[1] <= p2[1] )
2143 id = newPoints->InsertNextPoint(x1);
2146 newVerts->InsertNextCell(1,newPts);
2151 //Loop over polylines clipping each line segment
2152 for ( lines->InitTraversal(); lines->GetNextCell(npts,pts); )
2154 //loop over line segment making up the polyline
2155 for (i=0; i<(npts-1); i++)
2157 points->GetPoint(pts[i], x1);
2158 points->GetPoint(pts[i+1], x2);
2160 //intersect each segment with the four planes
2161 if ( (x1[0] < p1[0] && x2[0] < p1[0]) || (x1[0] > p2[0] && x2[0] > p2[0]) ||
2162 (x1[1] < p1[1] && x2[1] < p1[1]) || (x1[1] > p2[1] && x2[1] > p2[1]) )
2164 ;//trivial rejection
2166 else if (x1[0] >= p1[0] && x2[0] >= p1[0] && x1[0] <= p2[0] && x2[0] <= p2[0] &&
2167 x1[1] >= p1[1] && x2[1] >= p1[1] && x1[1] <= p2[1] && x2[1] <= p2[1] )
2168 {//trivial acceptance
2169 newPts[0] = pointMap[pts[i]];
2170 newPts[1] = pointMap[pts[i+1]];
2171 newLines->InsertNextCell(2,newPts);
2176 if (x1[0] >= p1[0] && x1[0] <= p2[0] && x1[1] >= p1[1] && x1[1] <= p2[1] )
2178 newPts[0] = pointMap[pts[i]];
2180 else if (x2[0] >= p1[0] && x2[0] <= p2[0] && x2[1] >= p1[1] && x2[1] <= p2[1] )
2182 newPts[0] = pointMap[pts[i+1]];
2185 //only create cell if either x1 or x2 is inside the range
2190 this->ClipPlanes->GetPoints()->GetPoint(j, px);
2191 this->ClipPlanes->GetNormals()->GetTuple(j, n);
2192 if ( vtkPlane::IntersectWithLine(x1,x2,n,px,t,xint) && t >= 0 && t <= 1.0 )
2194 newPts[1] = newPoints->InsertNextPoint(xint);
2198 newLines->InsertNextCell(2,newPts);
2206 pd->SetPoints(newPoints);
2207 pd->SetVerts(newVerts);
2208 pd->SetLines(newLines);
2210 newPoints->Delete();
2216 //----------------------------------------------------------------------------
2217 void VISU_XYPlotActor::SetDataObjectXComponent(int i, int comp)
2219 i = ( i < 0 ? 0 : (i >=VTK_MAX_PLOTS ? VTK_MAX_PLOTS-1 : i));
2220 int val=this->XComponent->GetValue(i);
2224 this->XComponent->SetValue(i,comp);
2228 //----------------------------------------------------------------------------
2229 int VISU_XYPlotActor::GetDataObjectXComponent(int i)
2231 i = ( i < 0 ? 0 : (i >=VTK_MAX_PLOTS ? VTK_MAX_PLOTS-1 : i));
2232 return this->XComponent->GetValue(i);
2235 //----------------------------------------------------------------------------
2236 void VISU_XYPlotActor::SetDataObjectYComponent(int i, int comp)
2238 i = ( i < 0 ? 0 : (i >=VTK_MAX_PLOTS ? VTK_MAX_PLOTS-1 : i));
2239 int val=this->YComponent->GetValue(i);
2243 this->YComponent->SetValue(i,comp);
2247 //----------------------------------------------------------------------------
2248 int VISU_XYPlotActor::GetDataObjectYComponent(int i)
2250 i = ( i < 0 ? 0 : (i >=VTK_MAX_PLOTS ? VTK_MAX_PLOTS-1 : i));
2251 return this->YComponent->GetValue(i);
2254 //----------------------------------------------------------------------------
2255 void VISU_XYPlotActor::SetPointComponent(int i, int comp)
2257 i = ( i < 0 ? 0 : (i >=VTK_MAX_PLOTS ? VTK_MAX_PLOTS-1 : i));
2258 int val = this->XComponent->GetValue(i);
2262 this->XComponent->SetValue(i,comp);
2266 //----------------------------------------------------------------------------
2267 int VISU_XYPlotActor::GetPointComponent(int i)
2269 i = ( i < 0 ? 0 : (i >=VTK_MAX_PLOTS ? VTK_MAX_PLOTS-1 : i));
2270 return this->XComponent->GetValue(i);
2273 //----------------------------------------------------------------------------
2274 double *VISU_XYPlotActor::TransformPoint(int pos[2], int pos2[2],
2275 double x[3], double xNew[3])
2277 // First worry about exchanging axes
2278 if ( this->ExchangeAxes )
2280 double sx = (x[0]-pos[0]) / (pos2[0]-pos[0]);
2281 double sy = (x[1]-pos[1]) / (pos2[1]-pos[1]);
2282 xNew[0] = sy*(pos2[0]-pos[0]) + pos[0];
2283 xNew[1] = sx*(pos2[1]-pos[1]) + pos[1];
2293 // Okay, now swap the axes around if reverse is on
2294 if ( this->ReverseXAxis )
2296 xNew[0] = pos[0] + (pos2[0]-xNew[0]);
2298 if ( this->ReverseYAxis )
2300 xNew[1] = pos[1] + (pos2[1]-xNew[1]);
2306 //----------------------------------------------------------------------------
2307 void VISU_XYPlotActor::SetLabelFormat(const char* _arg)
2309 if (this->LabelFormat == NULL && _arg == NULL)
2314 if (this->LabelFormat && _arg && (!strcmp(this->LabelFormat,_arg)))
2319 if (this->LabelFormat)
2321 delete [] this->LabelFormat;
2326 this->LabelFormat = new char[strlen(_arg)+1];
2327 strcpy(this->LabelFormat,_arg);
2331 this->LabelFormat = NULL;
2334 this->XAxis->SetLabelFormat(this->LabelFormat);
2335 this->YAxis->SetLabelFormat(this->LabelFormat);
2340 //----------------------------------------------------------------------------
2341 void VISU_XYPlotActor::PrintAsCSV(ostream &os)
2343 vtkDataArray *scalars;
2345 vtkCollectionSimpleIterator dsit;
2347 int dsNum,component;
2348 for ( dsNum=0, this->InputList->InitTraversal(dsit);
2349 (ds = this->InputList->GetNextDataSet(dsit)); dsNum++ )
2351 vtkIdType numPts = ds->GetNumberOfPoints();
2352 scalars = ds->GetPointData()->GetScalars(this->SelectedInputScalars[dsNum]);
2353 component = this->SelectedInputScalarsComponent->GetValue(dsNum);
2354 for ( vtkIdType ptId=0; ptId < numPts; ptId++ )
2356 s = scalars->GetComponent(ptId, component);