1 /*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkAxisActor.cxx
5 Thanks: Kathleen Bonnell, B Division, Lawrence Livermore Nat'l Laboratory
6
7 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
8 All rights reserved.
9 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
10
11 This software is distributed WITHOUT ANY WARRANTY; without even
12 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 PURPOSE. See the above copyright notice for more information.
14 =========================================================================*/
15 #include "vtkAxisActor.h"
16
17 #include "vtkAxisFollower.h"
18 #include "vtkCamera.h"
19 #include "vtkCellArray.h"
20 #include "vtkCoordinate.h"
21 #include "vtkFollower.h"
22 #include "vtkTextRenderer.h"
23 #include "vtkMath.h"
24 #include "vtkObjectFactory.h"
25 #include "vtkPolyData.h"
26 #include "vtkPolyDataMapper.h"
27 #include "vtkProp3DAxisFollower.h"
28 #include "vtkProperty.h"
29 #include "vtkProperty2D.h"
30 #include "vtkStringArray.h"
31 #include "vtkTextActor.h"
32 #include "vtkTextActor3D.h"
33 #include "vtkTextProperty.h"
34 #include "vtkVectorText.h"
35 #include "vtkViewport.h"
36
37 vtkStandardNewMacro(vtkAxisActor);
38 vtkCxxSetObjectMacro(vtkAxisActor, Camera, vtkCamera);
39 vtkCxxSetObjectMacro(vtkAxisActor,LabelTextProperty,vtkTextProperty);
40 vtkCxxSetObjectMacro(vtkAxisActor,TitleTextProperty,vtkTextProperty);
41
42 // ****************************************************************
43 // Instantiate this object.
44 // ****************************************************************
45
vtkAxisActor()46 vtkAxisActor::vtkAxisActor()
47 {
48 this->Point1Coordinate = vtkCoordinate::New();
49 this->Point1Coordinate->SetCoordinateSystemToWorld();
50 this->Point1Coordinate->SetValue(0.0, 0.0, 0.0);
51
52 this->Point2Coordinate = vtkCoordinate::New();
53 this->Point2Coordinate->SetCoordinateSystemToWorld();
54 this->Point2Coordinate->SetValue(0.75, 0.0, 0.0);
55
56 this->Camera = NULL;
57 this->Title = NULL;
58 this->MinorTicksVisible = 1;
59 this->MajorTickSize = 1.0;
60 this->MinorTickSize = 0.5;
61 this->TickLocation = VTK_TICKS_INSIDE;
62 this->Range[0] = 0.0;
63 this->Range[1] = 1.0;
64 this->ScreenSize = 10.;
65 this->LabelOffset = 20.;
66 this->TitleOffset = 20.;
67
68 this->Bounds[0] = this->Bounds[2] = this->Bounds[4] = -1;
69 this->Bounds[1] = this->Bounds[3] = this->Bounds[5] = 1;
70
71 this->UseTextActor3D = 0;
72 this->LabelFormat = new char[8];
73 sprintf(this->LabelFormat, "%s", "%-#6.3g");
74
75 this->TitleTextProperty = vtkTextProperty::New();
76 this->TitleTextProperty->SetColor(0.,0.,0.);
77 this->TitleTextProperty->SetFontFamilyToArial();
78 this->TitleTextProperty->SetFontSize(18);
79 this->TitleTextProperty->SetVerticalJustificationToCentered();
80 this->TitleTextProperty->SetJustificationToCentered();
81
82 this->TitleVector = vtkVectorText::New();
83 this->TitleMapper = vtkPolyDataMapper::New();
84 this->TitleMapper->SetInputConnection(
85 this->TitleVector->GetOutputPort());
86 this->TitleActor = vtkAxisFollower::New();
87 this->TitleActor->SetAxis(this);
88 this->TitleActor->SetMapper(this->TitleMapper);
89 this->TitleActor->SetEnableDistanceLOD(0);
90 this->TitleProp3D = vtkProp3DAxisFollower::New();
91 this->TitleProp3D->SetAxis(this);
92 this->TitleProp3D->SetEnableDistanceLOD(0);
93 this->TitleActor3D = vtkTextActor3D::New();
94 this->TitleProp3D->SetProp3D(this->TitleActor3D);
95 this->TitleActor2D = vtkTextActor::New();
96
97 this->NumberOfLabelsBuilt = 0;
98 this->LabelVectors = NULL;
99 this->LabelMappers = NULL;
100 this->LabelActors = NULL;
101 this->LabelProps3D = NULL;
102 this->LabelActors3D = NULL;
103 this->LabelActors2D = NULL;
104
105 this->LabelTextProperty = vtkTextProperty::New();
106 this->LabelTextProperty->SetColor(0.,0.,0.);
107 this->LabelTextProperty->SetFontFamilyToArial();
108 this->LabelTextProperty->SetFontSize(14);
109 this->LabelTextProperty->SetVerticalJustificationToBottom();
110 this->LabelTextProperty->SetJustificationToLeft();
111
112 this->AxisLines = vtkPolyData::New();
113 this->AxisLinesMapper = vtkPolyDataMapper::New();
114 this->AxisLinesMapper->SetInputData(this->AxisLines);
115 this->AxisLinesActor = vtkActor::New();
116 this->AxisLinesActor->SetMapper(this->AxisLinesMapper);
117 this->Gridlines = vtkPolyData::New();
118 this->GridlinesMapper = vtkPolyDataMapper::New();
119 this->GridlinesMapper->SetInputData(this->Gridlines);
120 this->GridlinesActor = vtkActor::New();
121 this->GridlinesActor->SetMapper(this->GridlinesMapper);
122 this->InnerGridlines = vtkPolyData::New();
123 this->InnerGridlinesMapper = vtkPolyDataMapper::New();
124 this->InnerGridlinesMapper->SetInputData(this->InnerGridlines);
125 this->InnerGridlinesActor = vtkActor::New();
126 this->InnerGridlinesActor->SetMapper(this->InnerGridlinesMapper);
127 this->Gridpolys = vtkPolyData::New();
128 this->GridpolysMapper = vtkPolyDataMapper::New();
129 this->GridpolysMapper->SetInputData(this->Gridpolys);
130 this->GridpolysActor = vtkActor::New();
131 this->GridpolysActor->SetMapper(this->GridpolysMapper);
132
133 this->AxisVisibility = 1;
134 this->TickVisibility = 1;
135 this->LabelVisibility = 1;
136 this->TitleVisibility = 1;
137
138 this->DrawGridlines = 0;
139 this->DrawGridlinesOnly = 0;
140 this->GridlineXLength = 1.;
141 this->GridlineYLength = 1.;
142 this->GridlineZLength = 1.;
143
144 this->DrawInnerGridlines = 0;
145
146 this->DrawGridpolys = 0;
147
148 this->AxisType = VTK_AXIS_TYPE_X;
149 //
150 // AxisPosition denotes which of the four possibilities in relation
151 // to the bounding box. An x-Type axis with min min, means the x-axis
152 // at minimum y and minimum z values of the bbox.
153 //
154 this->AxisPosition = VTK_AXIS_POS_MINMIN;
155
156 this->LastLabelStart = 100000;
157
158 this->LastAxisPosition = -1;
159 this->LastTickLocation = -1;
160 this->LastTickVisibility = -1;
161 this->LastDrawGridlines = -1;
162 this->LastDrawInnerGridlines = -1;
163 this->LastDrawGridpolys = -1;
164 this->LastMinorTicksVisible = -1;
165 this->LastRange[0] = -1.0;
166 this->LastRange[1] = -1.0;
167
168 this->MinorTickPts = vtkPoints::New();
169 this->MajorTickPts = vtkPoints::New();
170 this->GridlinePts = vtkPoints::New();
171 this->InnerGridlinePts = vtkPoints::New();
172 this->GridpolyPts = vtkPoints::New();
173
174 this->AxisHasZeroLength = false;
175
176 this->MinorStart = 0.;
177 //this->MajorStart = 0.;
178 for(int i=0;i<3;i++)
179 {
180 this->MajorStart[i] = 0.;
181 }
182 this->DeltaMinor = 1.;
183 //this->DeltaMajor = 1.;
184 for(int i=0;i<3;i++)
185 {
186 this->DeltaMajor[i] = 1.;
187 }
188
189 this->MinorRangeStart = 0.;
190 this->MajorRangeStart = 0.;
191 this->DeltaRangeMinor = 1.;
192 this->DeltaRangeMajor = 1.;
193
194 this->CalculateTitleOffset = 1;
195 this->CalculateLabelOffset = 1;
196
197 // Instance variables specific to 2D mode
198 this->Use2DMode = 0;
199 this->SaveTitlePosition = 0;
200 this->TitleConstantPosition[0] = this->TitleConstantPosition[1] = 0.;
201 this->VerticalOffsetXTitle2D = -40.;
202 this->HorizontalOffsetYTitle2D = -50.;
203 this->LastMinDisplayCoordinate[0] = 0;
204 this->LastMinDisplayCoordinate[1] = 0;
205 this->LastMinDisplayCoordinate[2] = 0;
206 this->LastMaxDisplayCoordinate[0] = 0;
207 this->LastMaxDisplayCoordinate[1] = 0;
208 this->LastMaxDisplayCoordinate[2] = 0;
209
210 // 0: All locations
211 this->DrawGridlinesLocation = this->LastDrawGridlinesLocation = 0;
212
213 // reset the base
214 for(int i=0;i<3;i++)
215 {
216 this->AxisBaseForX[i] = this->AxisBaseForY[i] = this->AxisBaseForZ[i] = 0.0;
217 }
218 this->AxisBaseForX[0] = this->AxisBaseForY[1] = this->AxisBaseForZ[2] = 1.0;
219 this->AxisOnOrigin = 0;
220 }
221
222 // ****************************************************************
~vtkAxisActor()223 vtkAxisActor::~vtkAxisActor()
224 {
225 this->SetCamera(NULL);
226
227 if (this->Point1Coordinate)
228 {
229 this->Point1Coordinate->Delete();
230 this->Point1Coordinate = NULL;
231 }
232
233 if (this->Point2Coordinate)
234 {
235 this->Point2Coordinate->Delete();
236 this->Point2Coordinate = NULL;
237 }
238
239 delete [] this->LabelFormat;
240 this->LabelFormat = NULL;
241
242 if (this->TitleVector)
243 {
244 this->TitleVector->Delete();
245 this->TitleVector = NULL;
246 }
247 if (this->TitleMapper)
248 {
249 this->TitleMapper->Delete();
250 this->TitleMapper = NULL;
251 }
252 if (this->TitleActor)
253 {
254 this->TitleActor->Delete();
255 this->TitleActor = NULL;
256 }
257 this->TitleProp3D->Delete();
258 this->TitleProp3D = NULL;
259 this->TitleActor3D->Delete();
260 this->TitleActor3D = NULL;
261 if (this->TitleActor2D)
262 {
263 this->TitleActor2D->Delete();
264 this->TitleActor2D = NULL;
265 }
266
267 delete [] this->Title;
268 this->Title = NULL;
269
270 if (this->TitleTextProperty)
271 {
272 this->TitleTextProperty->Delete();
273 this->TitleTextProperty = NULL;
274 }
275
276 if (this->LabelMappers != NULL)
277 {
278 for (int i=0; i < this->NumberOfLabelsBuilt; i++)
279 {
280 this->LabelVectors[i]->Delete();
281 this->LabelMappers[i]->Delete();
282 this->LabelActors[i]->Delete();
283 this->LabelProps3D[i]->Delete();
284 this->LabelActors3D[i]->Delete();
285 this->LabelActors2D[i]->Delete();
286 }
287 this->NumberOfLabelsBuilt = 0;
288 delete [] this->LabelVectors;
289 delete [] this->LabelMappers;
290 delete [] this->LabelActors;
291 delete [] this->LabelProps3D;
292 delete [] this->LabelActors3D;
293 delete [] this->LabelActors2D;
294 this->LabelVectors = NULL;
295 this->LabelMappers = NULL;
296 this->LabelActors = NULL;
297 this->LabelProps3D = NULL;
298 this->LabelActors3D = NULL;
299 this->LabelActors2D = NULL;
300 }
301 if (this->LabelTextProperty)
302 {
303 this->LabelTextProperty->Delete();
304 this->LabelTextProperty = NULL;
305 }
306
307 if (this->AxisLines)
308 {
309 this->AxisLines->Delete();
310 this->AxisLines = NULL;
311 }
312 if (this->AxisLinesMapper)
313 {
314 this->AxisLinesMapper->Delete();
315 this->AxisLinesMapper = NULL;
316 }
317 if (this->AxisLinesActor)
318 {
319 this->AxisLinesActor->Delete();
320 this->AxisLinesActor = NULL;
321 }
322
323 if (this->Gridlines)
324 {
325 this->Gridlines->Delete();
326 this->Gridlines = NULL;
327 }
328 if (this->GridlinesMapper)
329 {
330 this->GridlinesMapper->Delete();
331 this->GridlinesMapper = NULL;
332 }
333 if (this->GridlinesActor)
334 {
335 this->GridlinesActor->Delete();
336 this->GridlinesActor = NULL;
337 }
338
339 if (this->InnerGridlines)
340 {
341 this->InnerGridlines->Delete();
342 this->InnerGridlines = NULL;
343 }
344 if (this->InnerGridlinesMapper)
345 {
346 this->InnerGridlinesMapper->Delete();
347 this->InnerGridlinesMapper = NULL;
348 }
349 if (this->InnerGridlinesActor)
350 {
351 this->InnerGridlinesActor->Delete();
352 this->InnerGridlinesActor = NULL;
353 }
354
355 if (this->Gridpolys)
356 {
357 this->Gridpolys->Delete();
358 this->Gridpolys = NULL;
359 }
360 if (this->GridpolysMapper)
361 {
362 this->GridpolysMapper->Delete();
363 this->GridpolysMapper = NULL;
364 }
365 if (this->GridpolysActor)
366 {
367 this->GridpolysActor->Delete();
368 this->GridpolysActor = NULL;
369 }
370
371 if (this->MinorTickPts)
372 {
373 this->MinorTickPts ->Delete();
374 this->MinorTickPts = NULL;
375 }
376 if (this->MajorTickPts)
377 {
378 this->MajorTickPts->Delete();
379 this->MajorTickPts = NULL;
380 }
381 if (this->GridlinePts)
382 {
383 this->GridlinePts->Delete();
384 this->GridlinePts = NULL;
385 }
386 if (this->InnerGridlinePts)
387 {
388 this->InnerGridlinePts->Delete();
389 this->InnerGridlinePts = NULL;
390 }
391 if (this->GridpolyPts)
392 {
393 this->GridpolyPts->Delete();
394 this->GridpolyPts = NULL;
395 }
396 }
397
398 // ****************************************************************
ReleaseGraphicsResources(vtkWindow * win)399 void vtkAxisActor::ReleaseGraphicsResources(vtkWindow *win)
400 {
401 this->TitleActor->ReleaseGraphicsResources(win);
402 this->TitleProp3D->ReleaseGraphicsResources(win);
403 this->TitleActor3D->ReleaseGraphicsResources(win);
404 this->TitleActor2D->ReleaseGraphicsResources(win);
405 for (int i=0; i < this->NumberOfLabelsBuilt; i++)
406 {
407 this->LabelActors[i]->ReleaseGraphicsResources(win);
408 this->LabelProps3D[i]->ReleaseGraphicsResources(win);
409 this->LabelActors3D[i]->ReleaseGraphicsResources(win);
410 this->LabelActors2D[i]->ReleaseGraphicsResources(win);
411 }
412 this->AxisLinesActor->ReleaseGraphicsResources(win);
413 this->GridlinesActor->ReleaseGraphicsResources(win);
414 this->InnerGridlinesActor->ReleaseGraphicsResources(win);
415 this->GridpolysActor->ReleaseGraphicsResources(win);
416 }
417
418 // ****************************************************************
RenderOpaqueGeometry(vtkViewport * viewport)419 int vtkAxisActor::RenderOpaqueGeometry(vtkViewport *viewport)
420 {
421 int i, renderedSomething=0;
422
423 this->BuildAxis(viewport, false);
424
425 // Everything is built, just have to render
426
427 if (!this->AxisHasZeroLength)
428 {
429 if(this->DrawGridlinesOnly && this->DrawGridlines)
430 {
431 // Exit !!!!
432 return this->GridlinesActor->RenderOpaqueGeometry(viewport);
433 }
434 if (this->Title != NULL && this->Title[0] != 0 && this->TitleVisibility)
435 {
436 if (this->Use2DMode)
437 {
438 renderedSomething += this->TitleActor2D->RenderOpaqueGeometry(viewport);
439 }
440 else if (this->UseTextActor3D)
441 {
442 renderedSomething += this->TitleProp3D->RenderOpaqueGeometry(viewport);
443 }
444 else
445 {
446 renderedSomething += this->TitleActor->RenderOpaqueGeometry(viewport);
447 }
448 }
449 if (this->AxisVisibility || this->TickVisibility)
450 {
451 renderedSomething += this->AxisLinesActor->RenderOpaqueGeometry(viewport);
452 }
453 if(this->DrawGridlines)
454 {
455 renderedSomething += this->GridlinesActor->RenderOpaqueGeometry(viewport);
456 }
457 if(this->DrawInnerGridlines)
458 {
459 renderedSomething += this->InnerGridlinesActor->RenderOpaqueGeometry(viewport);
460 }
461 if (this->LabelVisibility)
462 {
463 for (i=0; i<this->NumberOfLabelsBuilt; i++)
464 {
465 if (this->Use2DMode)
466 {
467 renderedSomething +=
468 this->LabelActors2D[i]->RenderOpaqueGeometry(viewport);
469 }
470 else if (this->UseTextActor3D)
471 {
472 renderedSomething +=
473 this->LabelActors3D[i]->RenderOpaqueGeometry(viewport);
474 }
475 else
476 {
477 renderedSomething +=
478 this->LabelActors[i]->RenderOpaqueGeometry(viewport);
479 }
480 }
481 }
482 }
483
484 return renderedSomething;
485 }
486
487 // ****************************************************************
488 // Build the translucent poly actors and render.
489 // ****************************************************************
RenderTranslucentGeometry(vtkViewport * viewport)490 int vtkAxisActor::RenderTranslucentGeometry(vtkViewport *viewport)
491 {
492 return this->RenderTranslucentPolygonalGeometry(viewport);
493 }
494
495 // ****************************************************************
496 // Build the translucent poly actors and render.
497 // ****************************************************************
RenderTranslucentPolygonalGeometry(vtkViewport * viewport)498 int vtkAxisActor::RenderTranslucentPolygonalGeometry(vtkViewport *viewport)
499 {
500
501 int renderedSomething=0;
502
503 this->BuildAxis(viewport, false);
504
505 // Everything is built, just have to render
506
507 if (!this->AxisHasZeroLength && !this->DrawGridlinesOnly)
508 {
509 if(this->DrawGridpolys)
510 {
511 renderedSomething += this->GridpolysActor->RenderTranslucentPolygonalGeometry(viewport);
512 }
513 if (this->Title != NULL && this->Title[0] != 0 && this->TitleVisibility)
514 {
515 if (this->Use2DMode)
516 {
517 renderedSomething += this->TitleActor2D->RenderTranslucentPolygonalGeometry(viewport);
518 }
519 else if (this->UseTextActor3D)
520 {
521 renderedSomething += this->TitleProp3D->RenderTranslucentPolygonalGeometry(viewport);
522 }
523 else
524 {
525 renderedSomething += this->TitleActor->RenderTranslucentPolygonalGeometry(viewport);
526 }
527 }
528 if (this->LabelVisibility)
529 {
530 for (int i=0; i<this->NumberOfLabelsBuilt; i++)
531 {
532 if (this->Use2DMode)
533 {
534 renderedSomething +=
535 this->LabelActors2D[i]->RenderTranslucentPolygonalGeometry(viewport);
536 }
537 else if (this->UseTextActor3D)
538 {
539 renderedSomething +=
540 this->LabelProps3D[i]->RenderTranslucentPolygonalGeometry(viewport);
541 }
542 else
543 {
544 renderedSomething +=
545 this->LabelActors[i]->RenderTranslucentPolygonalGeometry(viewport);
546 }
547 }
548 }
549 }
550 return renderedSomething;
551 }
552
553 // ****************************************************************
554 // Render the 2d annotations.
555 // ****************************************************************
RenderOverlay(vtkViewport * viewport)556 int vtkAxisActor::RenderOverlay(vtkViewport *viewport)
557 {
558 int i, renderedSomething=0;
559
560 // Everything is built, just have to render
561 if (!this->AxisHasZeroLength && !this->DrawGridlinesOnly)
562 {
563 if (this->Use2DMode)
564 {
565 renderedSomething += this->TitleActor2D->RenderOverlay(viewport);
566 }
567 else if (this->UseTextActor3D)
568 {
569 renderedSomething += this->TitleProp3D->RenderOverlay(viewport);
570 }
571 else
572 {
573 renderedSomething += this->TitleActor->RenderOverlay(viewport);
574 }
575 if (this->LabelVisibility)
576 {
577 for (i=0; i<this->NumberOfLabelsBuilt; i++)
578 {
579 if (this->Use2DMode)
580 {
581 renderedSomething += this->LabelActors2D[i]->RenderOverlay(viewport);
582 }
583 else if (this->UseTextActor3D)
584 {
585 renderedSomething += this->LabelProps3D[i]->RenderOverlay(viewport);
586 }
587 else
588 {
589 renderedSomething += this->LabelActors[i]->RenderOverlay(viewport);
590 }
591 }
592 }
593 }
594
595 return renderedSomething;
596 }
597
598 // **************************************************************************
HasTranslucentPolygonalGeometry()599 int vtkAxisActor::HasTranslucentPolygonalGeometry()
600 {
601 if (this->Visibility && !this->AxisHasZeroLength)
602 {
603
604 if (this->TitleVisibility)
605 {
606 if (this->Use2DMode)
607 {
608 if (this->TitleActor2D->HasTranslucentPolygonalGeometry())
609 {
610 return 1;
611 }
612 }
613 else if (this->UseTextActor3D)
614 {
615 if (this->TitleProp3D->HasTranslucentPolygonalGeometry())
616 {
617 return 1;
618 }
619 }
620 else
621 {
622 if (this->TitleActor->HasTranslucentPolygonalGeometry())
623 {
624 return 1;
625 }
626 }
627 }
628
629 if (this->LabelVisibility)
630 {
631 if (this->Use2DMode)
632 {
633 for (int i = 0; i < this->NumberOfLabelsBuilt; ++i)
634 {
635 if (this->LabelActors2D[i]->HasTranslucentPolygonalGeometry())
636 {
637 return 1;
638 } // end if
639 } // end for
640 } // end 2D
641 else if (this->UseTextActor3D)
642 {
643 for (int i = 0; i < this->NumberOfLabelsBuilt; ++i)
644 {
645 //if (this->LabelActors3D[i]->HasTranslucentPolygonalGeometry())
646 if (this->LabelProps3D[i]->HasTranslucentPolygonalGeometry())
647 {
648 return 1;
649 } // end if
650 } // end for
651 } // end 3D
652 else
653 {
654 for (int i = 0; i < this->NumberOfLabelsBuilt; ++i)
655 {
656 if (this->LabelActors[i]->HasTranslucentPolygonalGeometry())
657 {
658 return 1;
659 } // end if
660 } // end for
661 } // end 3D
662 } // end label vis
663
664 if (this->AxisLinesActor->HasTranslucentPolygonalGeometry())
665 {
666 return 1;
667 }
668
669 if (this->DrawGridlines &&
670 this->GridlinesActor->HasTranslucentPolygonalGeometry())
671 {
672 return 1;
673 }
674
675 if (this->DrawInnerGridlines &&
676 this->InnerGridlinesActor->HasTranslucentPolygonalGeometry())
677 {
678 return 1;
679 }
680
681 if (this->DrawGridpolys &&
682 this-GridpolysActor->HasTranslucentPolygonalGeometry())
683 {
684 return 1;
685 }
686
687 return this->Superclass::HasTranslucentPolygonalGeometry();
688
689 } // end this vis
690
691 return 0;
692 }
693
694 // **************************************************************************
695 // Perform some initialization, determine which Axis type we are
696 // **************************************************************************
BuildAxis(vtkViewport * viewport,bool force)697 void vtkAxisActor::BuildAxis(vtkViewport *viewport, bool force)
698 {
699 // We'll do our computation in world coordinates. First determine the
700 // location of the endpoints.
701 double *x, p1[3], p2[3];
702 x = this->Point1Coordinate->GetValue();
703 p1[0] = x[0]; p1[1] = x[1]; p1[2] = x[2];
704 x = this->Point2Coordinate->GetValue();
705 p2[0] = x[0]; p2[1] = x[1]; p2[2] = x[2];
706
707 //
708 // Test for axis of zero length.
709 //
710 if (p1[0] == p2[0] && p1[1] == p2[1] && p1[2] == p2[2])
711 {
712 vtkDebugMacro(<<"Axis has zero length, not building.");
713 this->AxisHasZeroLength = true;
714 return;
715 }
716 this->AxisHasZeroLength = false;
717
718 if (!force && this->GetMTime() < this->BuildTime.GetMTime() &&
719 viewport->GetMTime() < this->BuildTime.GetMTime())
720 {
721 return; //already built
722 }
723
724 vtkDebugMacro(<<"Rebuilding axis");
725
726 if (force || this->GetProperty()->GetMTime() > this->BuildTime.GetMTime())
727 {
728 //this->AxisLinesActor->SetProperty(this->GetProperty());
729 this->TitleActor->SetProperty(this->GetProperty());
730 this->TitleActor->GetProperty()->SetColor(this->TitleTextProperty->GetColor());
731 this->TitleActor->GetProperty()->SetOpacity(this->TitleTextProperty->GetOpacity());
732 if (this->UseTextActor3D)
733 {
734 this->TitleActor3D->GetTextProperty()->ShallowCopy(this->TitleTextProperty);
735 }
736 }
737
738 //
739 // Generate the axis and tick marks.
740 //
741 bool ticksRebuilt;
742 ticksRebuilt = this->BuildTickPoints(p1, p2, force);
743
744 bool tickVisChanged = this->TickVisibilityChanged();
745
746 if (force || ticksRebuilt || tickVisChanged || this->LastDrawGridlinesLocation != this->DrawGridlinesLocation)
747 {
748 this->LastDrawGridlinesLocation = this->DrawGridlinesLocation;
749 this->SetAxisPointsAndLines();
750 }
751
752 // If the ticks have been rebuilt it is more than likely
753 // that the labels should follow...
754 this->BuildLabels(viewport, force || ticksRebuilt);
755 if (this->Use2DMode == 1)
756 {
757 this->BuildLabels2D(viewport, force || ticksRebuilt);
758 }
759
760 if (this->Title != NULL && this->Title[0] != 0)
761 {
762 this->BuildTitle(force || ticksRebuilt);
763 if( this->Use2DMode == 1 )
764 {
765 this->BuildTitle2D(viewport, force || ticksRebuilt);
766 }
767 }
768
769 this->LastAxisPosition = this->AxisPosition;
770
771 this->LastRange[0] = this->Range[0];
772 this->LastRange[1] = this->Range[1];
773 this->BuildTime.Modified();
774 }
775
776 // ****************************************************************
777 // Set label values and properties.
778 // ****************************************************************
779 void
BuildLabels(vtkViewport * viewport,bool force)780 vtkAxisActor::BuildLabels(vtkViewport *viewport, bool force)
781 {
782 if (!force && !this->LabelVisibility)
783 {
784 return;
785 }
786
787 for (int i = 0; i < this->NumberOfLabelsBuilt; i++)
788 {
789 this->LabelActors[i]->SetCamera(this->Camera);
790 this->LabelProps3D[i]->SetCamera(this->Camera);
791 this->LabelActors[i]->GetProperty()->SetColor(this->LabelTextProperty->GetColor());
792 this->LabelActors[i]->GetProperty()->SetOpacity(this->LabelTextProperty->GetOpacity());
793 this->LabelActors[i]->SetOrientation(0., 0., this->LabelTextProperty->GetOrientation());
794 this->LabelProps3D[i]->SetOrientation(0., 0., this->LabelTextProperty->GetOrientation());
795
796 if (this->UseTextActor3D)
797 {
798 this->LabelActors3D[i]->GetTextProperty()->ShallowCopy(this->LabelTextProperty);
799
800 double labelActorsBounds[6];
801 this->LabelActors[i]->GetMapper()->GetBounds(labelActorsBounds);
802 const double labelActorsWidth = (labelActorsBounds[1] - labelActorsBounds[0]);
803
804 int labelActors3DBounds[4];
805 this->LabelActors3D[i]->GetBoundingBox(labelActors3DBounds);
806 const double labelActors3DWidth =
807 static_cast<double>(labelActors3DBounds[1] - labelActors3DBounds[0]);
808
809 this->LabelActors3D[i]->SetScale( labelActorsWidth / labelActors3DWidth );
810 }
811 if(!this->GetCalculateLabelOffset())
812 {
813 this->LabelActors[i]->SetAutoCenter(1);
814 this->LabelProps3D[i]->SetAutoCenter(1);
815 }
816 }
817
818 if (force || this->BuildTime.GetMTime() < this->BoundsTime.GetMTime() ||
819 this->AxisPosition != this->LastAxisPosition ||
820 this->LastRange[0] != this->Range[0] ||
821 this->LastRange[1] != this->Range[1])
822 {
823 this->SetLabelPositions(viewport, force);
824 }
825 }
826
827 static const int vtkAxisActorMultiplierTable1[4] = { -1, -1, 1, 1};
828 static const int vtkAxisActorMultiplierTable2[4] = { -1, 1, 1, -1};
829
830 // *******************************************************************
831 // Determine and set scale factor and position for labels.
832 // *******************************************************************
SetLabelPositions(vtkViewport * viewport,bool force)833 void vtkAxisActor::SetLabelPositions(vtkViewport *viewport, bool force)
834 {
835 if (!force && (!this->LabelVisibility || this->NumberOfLabelsBuilt == 0))
836 {
837 return;
838 }
839
840 double bounds[6], center[3], tick[3], pos[3];
841 int i = 0;
842 int xmult = 0;
843 int ymult = 0;
844 double labelAngle = vtkMath::RadiansFromDegrees(this->LabelTextProperty->GetOrientation());
845 double labelCos = fabs(cos(labelAngle));
846 double labelSin = fabs(sin(labelAngle));
847
848
849 switch (this->AxisType)
850 {
851 case VTK_AXIS_TYPE_X :
852 xmult = 0;
853 ymult = vtkAxisActorMultiplierTable1[this->AxisPosition];
854 break;
855 case VTK_AXIS_TYPE_Y :
856 xmult = vtkAxisActorMultiplierTable1[this->AxisPosition];
857 ymult = 0;
858 break;
859 case VTK_AXIS_TYPE_Z :
860 xmult = vtkAxisActorMultiplierTable1[this->AxisPosition];
861 ymult = vtkAxisActorMultiplierTable2[this->AxisPosition];
862 break;
863 }
864
865 int ptIdx;
866 //
867 // xadjust & yadjust are used for positioning the label correctly
868 // depending upon the 'orientation' of the axis as determined
869 // by its position in view space (via transformed bounds).
870 //
871 double displayBounds[6] = { 0., 0., 0., 0., 0., 0.};
872 this->TransformBounds(viewport, displayBounds);
873 double xadjust = (displayBounds[0] > displayBounds[1] ? -1 : 1);
874 double yadjust = (displayBounds[2] > displayBounds[3] ? -1 : 1);
875
876 for (i=0; i < this->NumberOfLabelsBuilt &&
877 i < this->MajorTickPts->GetNumberOfPoints(); i++)
878 {
879 ptIdx = 4*i + 1;
880 this->MajorTickPts->GetPoint(ptIdx, tick);
881
882 this->LabelActors[i]->GetMapper()->GetBounds(bounds);
883
884 if(this->CalculateLabelOffset)
885 {
886 double halfWidth = 0.5 * ((bounds[1] - bounds[0]) * labelCos + (bounds[3] - bounds[2]) * labelSin);
887 double halfHeight = 0.5 * ((bounds[1] - bounds[0]) * labelSin + (bounds[3] - bounds[2]) * labelCos);
888
889 center[0] = tick[0] + xmult * (halfWidth + this->MinorTickSize);
890 center[1] = tick[1] + ymult * (halfHeight + this->MinorTickSize);
891 center[2] = tick[2];
892
893 pos[0] = (center[0] - xadjust *halfWidth);
894 pos[1] = (center[1] - yadjust *halfHeight);
895 pos[2] = center[2];
896 }
897 else
898 {
899 pos[0] = tick[0];
900 pos[1] = tick[1];
901 pos[2] = tick[2];
902
903 double delta = 0.5 * ((bounds[1] - bounds[0]) * labelSin + (bounds[3] - bounds[2]) * labelCos);
904 this->LabelActors[i]->SetScreenOffset(this->LabelOffset + (delta) * this->ScreenSize);
905 this->LabelProps3D[i]->SetScreenOffset(this->LabelOffset + (delta) * this->ScreenSize);
906 }
907
908 this->LabelActors[i]->SetPosition(pos[0], pos[1], pos[2]);
909 this->LabelProps3D[i]->SetPosition(pos[0], pos[1], pos[2]);
910 }
911 }
912
913 // *******************************************************************
914 // Set 2D label values and properties.
915 // *******************************************************************
916 void
BuildLabels2D(vtkViewport * viewport,bool force)917 vtkAxisActor::BuildLabels2D(vtkViewport *viewport, bool force)
918 {
919 if (!force && (!this->LabelVisibility || this->NumberOfLabelsBuilt == 0))
920 return;
921
922 for (int i = 0; i < this->NumberOfLabelsBuilt; i++)
923 {
924 this->LabelActors2D[i]->GetProperty()->SetColor(this->LabelTextProperty->GetColor());
925 this->LabelActors2D[i]->GetProperty()->SetOpacity(this->LabelTextProperty->GetOpacity());
926 this->LabelActors2D[i]->GetTextProperty()->ShallowCopy(this->LabelTextProperty);
927 }
928
929 this->NeedBuild2D = this->BoundsDisplayCoordinateChanged(viewport);
930 if (force || this->NeedBuild2D)
931 {
932 this->SetLabelPositions2D(viewport, force);
933 }
934 }
935
936
937 // *******************************************************************
938 // Determine and set scale factor and position for 2D labels.
939 // *******************************************************************
940 void
SetLabelPositions2D(vtkViewport * viewport,bool force)941 vtkAxisActor::SetLabelPositions2D(vtkViewport *viewport, bool force)
942 {
943 if (!force && (!this->LabelVisibility || this->NumberOfLabelsBuilt == 0) )
944 return;
945
946 int xmult = 0;
947 int ymult = 0;
948 double xcoeff = 0.;
949 double ycoeff = 0.;
950
951 // we are in 2D mode, so no Z axis
952 switch (this->AxisType)
953 {
954 case VTK_AXIS_TYPE_X :
955 xmult = 0;
956 ymult = vtkAxisActorMultiplierTable1[this->AxisPosition];
957 xcoeff = 0.5;
958 ycoeff = 1.0;
959 break;
960 case VTK_AXIS_TYPE_Y :
961 xmult = vtkAxisActorMultiplierTable1[this->AxisPosition];
962 ymult = 0;
963 xcoeff = 1.0;
964 ycoeff = 0.5;
965 break;
966 }
967
968
969 int ptIdx;
970 //
971 // xadjust & yadjust are used for positioning the label correctly
972 // depending upon the 'orientation' of the axis as determined
973 // by its position in view space (via transformed bounds).
974 //
975 double displayBounds[6] = { 0., 0., 0., 0., 0., 0.};
976 this->TransformBounds(viewport, displayBounds);
977 double xadjust = (displayBounds[0] > displayBounds[1] ? -1 : 1);
978 double yadjust = (displayBounds[2] > displayBounds[3] ? -1 : 1);
979 double transpos[3] = {0., 0., 0.};
980 double center[3], tick[3], pos[2];
981
982 vtkTextRenderer *tren = vtkTextRenderer::GetInstance();
983 if (!tren)
984 {
985 vtkErrorMacro(<< "Unable to obtain the vtkTextRenderer instance!");
986 return;
987 }
988
989 for (int i = 0; i < this->NumberOfLabelsBuilt; i++)
990 {
991 ptIdx = 4*i + 1;
992
993 this->MajorTickPts->GetPoint(ptIdx, tick);
994
995 center[0] = tick[0] + xmult * this->MinorTickSize;
996 center[1] = tick[1] + ymult * this->MinorTickSize;
997 center[2] = tick[2];
998
999 viewport->SetWorldPoint(center[0], center[1], center[2], 1.0);
1000 viewport->WorldToDisplay();
1001 viewport->GetDisplayPoint(transpos);
1002
1003 int bbox[4];
1004 if (!tren->GetBoundingBox(this->LabelActors2D[i]->GetTextProperty(),
1005 this->LabelActors2D[i]->GetInput(), bbox))
1006 {
1007 vtkErrorMacro(<< "Unable to calculate bounding box for label "
1008 << this->LabelActors2D[i]->GetInput());
1009 continue;
1010 }
1011
1012 double width = (bbox[1]-bbox[0]);
1013 double height = (bbox[3]-bbox[2]);
1014
1015 pos[0] = (transpos[0] - xadjust*width*xcoeff);
1016 pos[1] = (transpos[1] - yadjust*height*ycoeff);
1017 this->LabelActors2D[i]->SetPosition( pos[0], pos[1] );
1018 }
1019 }
1020
1021
1022 // **********************************************************************
1023 // Determines scale and position for the Title. Currently,
1024 // title can only be centered with respect to its axis.
1025 // **********************************************************************
BuildTitle(bool force)1026 void vtkAxisActor::BuildTitle(bool force)
1027 {
1028 this->NeedBuild2D = false;
1029 if (!force && !this->TitleVisibility)
1030 {
1031 return;
1032 }
1033 double labBounds[6], titleBounds[6], center[3], pos[3];
1034 double labHeight, maxHeight = 0, labWidth, maxWidth = 0;
1035 double halfTitleWidth, halfTitleHeight;
1036 double labelAngle = vtkMath::RadiansFromDegrees(this->LabelTextProperty->GetOrientation());
1037 double labelCos = fabs(cos(labelAngle));
1038 double labelSin = fabs(sin(labelAngle));
1039
1040 double *p1 = this->Point1Coordinate->GetValue();
1041 double *p2 = this->Point2Coordinate->GetValue();
1042 int xmult = 0;
1043 int ymult = 0;
1044
1045 if (!force && this->LabelBuildTime.GetMTime() < this->BuildTime.GetMTime() &&
1046 this->BoundsTime.GetMTime() < this->BuildTime.GetMTime() &&
1047 this->AxisPosition == this->LastAxisPosition &&
1048 this->TitleTextTime.GetMTime() < this->BuildTime.GetMTime())
1049 {
1050 return;
1051 }
1052
1053 this->NeedBuild2D = true;
1054 switch (this->AxisType)
1055 {
1056 case VTK_AXIS_TYPE_X :
1057 xmult = 0;
1058 ymult = vtkAxisActorMultiplierTable1[this->AxisPosition];
1059 break;
1060 case VTK_AXIS_TYPE_Y :
1061 xmult = vtkAxisActorMultiplierTable1[this->AxisPosition];
1062 ymult = 0;
1063 break;
1064 case VTK_AXIS_TYPE_Z :
1065 xmult = vtkAxisActorMultiplierTable1[this->AxisPosition];
1066 ymult = vtkAxisActorMultiplierTable2[this->AxisPosition];
1067 break;
1068 }
1069 //
1070 // Title should be in relation to labels (if any)
1071 // so find out information about them.
1072 //
1073 for (int i = 0; i < this->NumberOfLabelsBuilt; i++)
1074 {
1075 this->LabelActors[i]->GetMapper()->GetBounds(labBounds);
1076 labWidth = (labBounds[1] - labBounds[0]) * labelCos + (labBounds[3] - labBounds[2]) * labelSin;
1077 maxWidth = (labWidth > maxWidth ? labWidth : maxWidth);
1078 labHeight = (labBounds[1] - labBounds[0]) * labelSin + (labBounds[3] - labBounds[2]) * labelCos;
1079 maxHeight = (labHeight > maxHeight ? labHeight : maxHeight);
1080 }
1081
1082 this->TitleVector->SetText(this->Title);
1083 this->TitleActor3D->SetInput( this->Title );
1084
1085 this->TitleActor->GetProperty()->SetColor(this->TitleTextProperty->GetColor());
1086 this->TitleActor->SetCamera(this->Camera);
1087 this->TitleProp3D->SetCamera(this->Camera);
1088 this->TitleActor->GetMapper()->GetBounds(titleBounds);
1089
1090 if(!this->GetCalculateTitleOffset())
1091 {
1092 this->TitleActor->SetAutoCenter(1);
1093 this->TitleProp3D->SetAutoCenter(1);
1094 }
1095
1096 if (this->UseTextActor3D)
1097 {
1098 double titleActorBounds[6];
1099 this->TitleActor->GetMapper()->GetBounds(titleActorBounds);
1100 const double titleActorWidth = (titleActorBounds[1] - titleActorBounds[0]);
1101
1102 int titleActor3DBounds[4];
1103 this->TitleActor3D->GetBoundingBox(titleActor3DBounds);
1104 const double titleActor3DWidth =
1105 static_cast<double>(titleActor3DBounds[1] - titleActor3DBounds[0]);
1106
1107 // Convert from font coordinate system to world coordinate system:
1108 this->TitleActor3D->SetScale(
1109 titleActorWidth / titleActor3DWidth);
1110 }
1111
1112 center[0] = p1[0] + (p2[0] - p1[0]) / 2.0;
1113 center[1] = p1[1] + (p2[1] - p1[1]) / 2.0;
1114 center[2] = p1[2] + (p2[2] - p1[2]) / 2.0;
1115
1116 halfTitleHeight = (titleBounds[3] - titleBounds[2]) * 0.5;
1117 if(this->CalculateTitleOffset)
1118 {
1119 halfTitleWidth = (titleBounds[1] - titleBounds[0]) * 0.5;
1120 center[0] += xmult * (halfTitleWidth + maxWidth);
1121 center[1] += ymult * (halfTitleHeight + 2*maxHeight);
1122 }
1123 else
1124 {
1125 this->TitleActor->SetScreenOffset(this->TitleOffset +
1126 this->LabelOffset + this->ScreenSize * (maxHeight + halfTitleHeight));
1127 this->TitleProp3D->SetScreenOffset(this->TitleOffset +
1128 this->LabelOffset + this->ScreenSize * (maxHeight + halfTitleHeight));
1129 }
1130
1131 pos[0] = center[0];
1132 pos[1] = center[1];
1133 pos[2] = center[2];
1134
1135 this->TitleActor->SetPosition(pos[0], pos[1], pos[2]);
1136 this->TitleProp3D->SetPosition(pos[0], pos[1], pos[2]);
1137 }
1138
1139 // **********************************************************************
1140 // Determines scale and position for the 2D Title. Currently,
1141 // title can only be centered with respect to its axis.
1142 // **********************************************************************
1143 void
BuildTitle2D(vtkViewport * viewport,bool force)1144 vtkAxisActor::BuildTitle2D(vtkViewport *viewport, bool force)
1145 {
1146 if (!this->NeedBuild2D && !force && !this->TitleVisibility)
1147 {
1148 return;
1149 }
1150
1151 // for textactor instead of follower
1152 this->TitleActor2D->SetInput( this->TitleVector->GetText() );
1153 this->TitleActor2D->GetProperty()->SetColor( this->TitleTextProperty->GetColor() );
1154 this->TitleActor2D->GetProperty()->SetOpacity( this->TitleTextProperty->GetOpacity() );
1155 this->TitleActor2D->GetTextProperty()->ShallowCopy(this->TitleTextProperty);
1156
1157 if (this->AxisType == VTK_AXIS_TYPE_Y)
1158 {
1159 if (strlen(this->TitleActor2D->GetInput()) > 2)
1160 {
1161 // warning : orientation have to be set on vtkTextActor and not on the vtkTextActor's vtkTextProperty
1162 // otherwise there is a strange effect (first letter is not align with the others)
1163 this->TitleActor2D->SetOrientation(90);
1164 }
1165 else
1166 {
1167 // if in the previous rendering, the orientation was set.
1168 this->TitleActor2D->SetOrientation(0);
1169 }
1170 }
1171
1172 // stuff for 2D axis with TextActor
1173 double transpos[3];
1174 double* pos = this->TitleActor->GetPosition();
1175 viewport->SetWorldPoint(pos[0], pos[1], pos[2], 1.0);
1176 viewport->WorldToDisplay();
1177 viewport->GetDisplayPoint(transpos);
1178 if (this->AxisType == VTK_AXIS_TYPE_X)
1179 {
1180 transpos[1] += this->VerticalOffsetXTitle2D;
1181 }
1182 else if (this->AxisType == VTK_AXIS_TYPE_Y)
1183 {
1184 transpos[0] += this->HorizontalOffsetYTitle2D;
1185 }
1186 if (transpos[1] < 10.) transpos[1] = 10.;
1187 if (transpos[0] < 10.) transpos[0] = 10.;
1188 if (this->SaveTitlePosition == 0)
1189 {
1190 this->TitleActor2D->SetPosition(transpos[0], transpos[1]);
1191 }
1192 else
1193 {
1194 if (this->SaveTitlePosition == 1)
1195 {
1196 TitleConstantPosition[0] = transpos[0];
1197 TitleConstantPosition[1] = transpos[1];
1198 this->SaveTitlePosition = 2;
1199 }
1200 this->TitleActor2D->SetPosition(TitleConstantPosition[0], TitleConstantPosition[1]);
1201 }
1202 }
1203
1204 //
1205 // Transform the bounding box to display coordinates. Used
1206 // in determining orientation of the axis.
1207 //
TransformBounds(vtkViewport * viewport,double bnds[6])1208 void vtkAxisActor::TransformBounds(vtkViewport *viewport, double bnds[6])
1209 {
1210 double minPt[3], maxPt[3], transMinPt[3], transMaxPt[3];
1211 minPt[0] = this->Bounds[0];
1212 minPt[1] = this->Bounds[2];
1213 minPt[2] = this->Bounds[4];
1214 maxPt[0] = this->Bounds[1];
1215 maxPt[1] = this->Bounds[3];
1216 maxPt[2] = this->Bounds[5];
1217
1218 viewport->SetWorldPoint(minPt[0], minPt[1], minPt[2], 1.0);
1219 viewport->WorldToDisplay();
1220 viewport->GetDisplayPoint(transMinPt);
1221 viewport->SetWorldPoint(maxPt[0], maxPt[1], maxPt[2], 1.0);
1222 viewport->WorldToDisplay();
1223 viewport->GetDisplayPoint(transMaxPt);
1224
1225 bnds[0] = transMinPt[0];
1226 bnds[2] = transMinPt[1];
1227 bnds[4] = transMinPt[2];
1228 bnds[1] = transMaxPt[0];
1229 bnds[3] = transMaxPt[1];
1230 bnds[5] = transMaxPt[2];
1231 }
1232
ffix(double value)1233 inline double ffix(double value)
1234 {
1235 int ivalue = static_cast<int>(value);
1236 return static_cast<double>(ivalue);
1237 }
1238
fsign(double value,double sign)1239 inline double fsign(double value, double sign)
1240 {
1241 value = fabs(value);
1242 if (sign < 0.)
1243 {
1244 value *= -1.;
1245 }
1246 return value;
1247 }
1248
1249 // ****************************************************************
PrintSelf(ostream & os,vtkIndent indent)1250 void vtkAxisActor::PrintSelf(ostream& os, vtkIndent indent)
1251 {
1252 this->Superclass::PrintSelf(os,indent);
1253
1254 os << indent << "Title: " << (this->Title ? this->Title : "(none)") << "\n";
1255 os << indent << "Number Of Labels Built: "
1256 << this->NumberOfLabelsBuilt << "\n";
1257 os << indent << "Range: ("
1258 << this->Range[0] << ", "
1259 << this->Range[1] << ")\n";
1260
1261 os << indent << "UseTextActor3D: " << this->UseTextActor3D << "\n";
1262 os << indent << "Label Format: " << this->LabelFormat << "\n";
1263
1264 os << indent << "Axis Visibility: "
1265 << (this->AxisVisibility ? "On\n" : "Off\n");
1266
1267 os << indent << "Tick Visibility: "
1268 << (this->TickVisibility ? "On\n" : "Off\n");
1269
1270 os << indent << "Label Visibility: "
1271 << (this->LabelVisibility ? "On\n" : "Off\n");
1272
1273 os << indent << "Title Visibility: "
1274 << (this->TitleVisibility ? "On\n" : "Off\n");
1275
1276 os << indent << "Point1 Coordinate: " << this->Point1Coordinate << "\n";
1277 this->Point1Coordinate->PrintSelf(os, indent.GetNextIndent());
1278
1279 os << indent << "Point2 Coordinate: " << this->Point2Coordinate << "\n";
1280 this->Point2Coordinate->PrintSelf(os, indent.GetNextIndent());
1281
1282 os << indent << "AxisType: ";
1283 switch (this->AxisType)
1284 {
1285 case VTK_AXIS_TYPE_X:
1286 os << "X Axis" << endl;
1287 break;
1288 case VTK_AXIS_TYPE_Y:
1289 os << "Y Axis" << endl;
1290 break;
1291 case VTK_AXIS_TYPE_Z:
1292 os << "Z Axis" << endl;
1293 break;
1294 default:
1295 // shouldn't get here
1296 ;
1297 }
1298
1299 os << indent << "DeltaMajor: "
1300 << this->DeltaMajor[0] << ","
1301 << this->DeltaMajor[1] << ","
1302 << this->DeltaMajor[2] << endl;
1303 os << indent << "DeltaMinor: " << this->DeltaMinor << endl;
1304 os << indent << "DeltaRangeMajor: " << this->DeltaRangeMajor << endl;
1305 os << indent << "DeltaRangeMinor: " << this->DeltaRangeMinor << endl;
1306 os << indent << "MajorRangeStart: " << this->MajorRangeStart << endl;
1307 os << indent << "MinorRangeStart: " << this->MinorRangeStart << endl;
1308
1309 os << indent << "MinorTicksVisible: " << this->MinorTicksVisible << endl;
1310
1311 os << indent << "TitleActor: ";
1312 if(this->TitleActor)
1313 {
1314 os << indent << "TitleActor: (" << this->TitleActor << ")\n";
1315 }
1316 else
1317 {
1318 os << "(none)" << endl;
1319 }
1320
1321 os << indent << "Camera: ";
1322 if (this->Camera)
1323 {
1324 this->Camera->PrintSelf(os, indent);
1325 }
1326 else
1327 {
1328 os << "(none)" << endl;
1329 }
1330
1331 os << indent << "MajorTickSize: " << this->MajorTickSize << endl;
1332 os << indent << "MinorTickSize: " << this->MinorTickSize << endl;
1333
1334 os << indent << "DrawGridlines: " << this->DrawGridlines << endl;
1335
1336 os << indent << "MajorStart: "
1337 << this->MajorStart[0] << ","
1338 << this->MajorStart[1] << ","
1339 << this->MajorStart[2] << endl;
1340
1341 os << indent << "AxisPosition: " << this->AxisPosition << endl;
1342
1343 os << indent << "GridlineXLength: " << this->GridlineXLength << endl;
1344 os << indent << "GridlineYLength: " << this->GridlineYLength << endl;
1345 os << indent << "GridlineZLength: " << this->GridlineZLength << endl;
1346
1347 os << indent << "DrawInnerGridpolys: " << this->DrawGridpolys << endl;
1348 os << indent << "DrawInnerGridlines: " << this->DrawInnerGridlines << endl;
1349
1350 os << indent << "TickLocation: " << this->TickLocation << endl;
1351
1352 os << indent << "CalculateLabelOffset: " << this->CalculateLabelOffset << std::endl;
1353 os << indent << "CalculateTitleOffset: " << this->CalculateTitleOffset << std::endl;
1354
1355 os << indent << "LabelTextProperty: " << this->LabelTextProperty << endl;
1356 os << indent << "TitleTextProperty: " << this->TitleTextProperty << endl;
1357
1358 os << indent << "Use2DMode: " << this->Use2DMode << endl;
1359 os << indent << "SaveTitlePosition: " << this->SaveTitlePosition << endl;
1360 os << indent << "VerticalOffsetXTitle2D" << this->VerticalOffsetXTitle2D << endl;
1361 os << indent << "HorizontalOffsetYTitle2D" << this->HorizontalOffsetYTitle2D << endl;
1362 os << indent << "LastMinDisplayCoordinates: ("
1363 << this->LastMinDisplayCoordinate[0] << ", "
1364 << this->LastMinDisplayCoordinate[1] << ", "
1365 << this->LastMinDisplayCoordinate[2] << ")" << endl;
1366 os << indent << "LastMaxDisplayCoordinates: ("
1367 << this->LastMaxDisplayCoordinate[0] << ", "
1368 << this->LastMaxDisplayCoordinate[1] << ", "
1369 << this->LastMaxDisplayCoordinate[2] << ")" << endl;
1370 }
1371
1372 // **************************************************************************
1373 // Sets text string for label vectors. Allocates memory if necessary.
1374 // **************************************************************************
SetLabels(vtkStringArray * labels)1375 void vtkAxisActor::SetLabels(vtkStringArray *labels)
1376 {
1377 //
1378 // If the number of labels has changed, re-allocate the correct
1379 // amount of memory.
1380 //
1381 int i, numLabels = labels->GetNumberOfValues();
1382 if (numLabels < 0)
1383 {
1384 vtkErrorMacro(<< "Number of labels " << numLabels << " is invalid");
1385 return;
1386 }
1387 if (this->NumberOfLabelsBuilt != numLabels)
1388 {
1389 if (this->LabelMappers != NULL)
1390 {
1391 for (i = 0; i < this->NumberOfLabelsBuilt; i++)
1392 {
1393 this->LabelVectors[i]->Delete();
1394 this->LabelMappers[i]->Delete();
1395 this->LabelActors[i]->Delete();
1396 this->LabelProps3D[i]->Delete();
1397 this->LabelActors3D[i]->Delete();
1398 this->LabelActors2D[i]->Delete();
1399 }
1400 delete [] this->LabelVectors;
1401 delete [] this->LabelMappers;
1402 delete [] this->LabelActors;
1403 delete [] this->LabelProps3D;
1404 delete [] this->LabelActors3D;
1405 delete [] this->LabelActors2D;
1406 }
1407
1408 this->LabelVectors = new vtkVectorText * [numLabels];
1409 this->LabelMappers = new vtkPolyDataMapper * [numLabels];
1410 this->LabelActors = new vtkAxisFollower * [numLabels];
1411 this->LabelProps3D = new vtkProp3DAxisFollower * [numLabels];
1412 this->LabelActors3D = new vtkTextActor3D * [numLabels];
1413 this->LabelActors2D = new vtkTextActor * [numLabels];
1414
1415 for (i = 0; i < numLabels; i++)
1416 {
1417 this->LabelVectors[i] = vtkVectorText::New();
1418 this->LabelMappers[i] = vtkPolyDataMapper::New();
1419 this->LabelMappers[i]->SetInputConnection(
1420 this->LabelVectors[i]->GetOutputPort());
1421 this->LabelActors[i] = vtkAxisFollower::New();
1422 this->LabelActors[i]->SetAxis(this);
1423 this->LabelActors[i]->SetMapper(this->LabelMappers[i]);
1424 this->LabelActors[i]->SetEnableDistanceLOD(0);
1425 this->LabelActors[i]->GetProperty()->SetAmbient(1.);
1426 this->LabelActors[i]->GetProperty()->SetDiffuse(0.);
1427 this->LabelActors[i]->GetProperty()->SetColor(this->LabelTextProperty->GetColor());
1428 this->LabelActors[i]->GetProperty()->SetOpacity(this->LabelTextProperty->GetOpacity());
1429 this->LabelProps3D[i] = vtkProp3DAxisFollower::New();
1430 this->LabelProps3D[i]->SetAxis(this);
1431 this->LabelProps3D[i]->SetEnableDistanceLOD(0);
1432 this->LabelActors3D[i] = vtkTextActor3D::New();
1433 this->LabelProps3D[i]->SetProp3D(this->LabelActors3D[i]);
1434 this->LabelActors2D[i] = vtkTextActor::New();
1435 }
1436 }
1437
1438 //
1439 // Set the label vector text.
1440 //
1441 for (i = 0; i < numLabels; i++)
1442 {
1443 this->LabelVectors[i]->SetText(labels->GetValue(i).c_str());
1444 this->LabelActors3D[i]->SetInput(this->LabelVectors[i]->GetText());
1445 this->LabelActors2D[i]->SetInput(this->LabelVectors[i]->GetText());
1446 }
1447 this->NumberOfLabelsBuilt = numLabels;
1448 this->LabelBuildTime.Modified();
1449 }
1450
1451 // **************************************************************************
1452 // Creates Poly data (lines) from tickmarks (minor/major), gridlines, and axis.
1453 // **************************************************************************
SetAxisPointsAndLines()1454 void vtkAxisActor::SetAxisPointsAndLines()
1455 {
1456 vtkPoints *pts = vtkPoints::New();
1457 vtkCellArray *lines = vtkCellArray::New();
1458 vtkCellArray *gridlines = vtkCellArray::New();
1459 vtkCellArray *innerGridlines = vtkCellArray::New();
1460 vtkCellArray *polys = vtkCellArray::New();
1461 this->AxisLines->SetPoints(pts);
1462 this->AxisLines->SetLines(lines);
1463 this->Gridlines->SetPoints(this->GridlinePts);
1464 this->Gridlines->SetLines(gridlines);
1465 this->InnerGridlines->SetPoints(this->InnerGridlinePts);
1466 this->InnerGridlines->SetLines(innerGridlines);
1467 this->Gridpolys->SetPoints(this->GridpolyPts);
1468 this->Gridpolys->SetPolys(polys);
1469 pts->Delete();
1470 lines->Delete();
1471 gridlines->Delete();
1472 innerGridlines->Delete();
1473 polys->Delete();
1474 int i, numMinorTickPts, numGridlines, numInnerGridlines, numMajorTickPts, numGridpolys, numLines;
1475 vtkIdType ptIds[2];
1476 vtkIdType polyPtIds[4];
1477
1478 if (this->TickVisibility)
1479 {
1480 if (this->MinorTicksVisible)
1481 {
1482 // In 2D mode, the minorTickPts for yz portion or xz portion have been removed.
1483 numMinorTickPts = this->MinorTickPts->GetNumberOfPoints();
1484 for (i = 0; i < numMinorTickPts; i++)
1485 {
1486 pts->InsertNextPoint(this->MinorTickPts->GetPoint(i));
1487 }
1488 }
1489 numMajorTickPts = this->MajorTickPts->GetNumberOfPoints();
1490 if (this->Use2DMode == 0)
1491 {
1492 for (i = 0; i < numMajorTickPts; i++)
1493 {
1494 pts->InsertNextPoint(this->MajorTickPts->GetPoint(i));
1495 }
1496 }
1497 else
1498 {
1499 // In 2D mode, we don't need the pts for the xz portion or yz portion of the major tickmarks
1500 // majorTickPts not modified because all points are used for labels' positions.
1501 for (i = 0; i < numMajorTickPts; i+=4)
1502 {
1503 pts->InsertNextPoint(this->MajorTickPts->GetPoint(i));
1504 pts->InsertNextPoint(this->MajorTickPts->GetPoint(i+1));
1505 }
1506 }
1507 }
1508
1509 // create lines
1510 numLines = pts->GetNumberOfPoints() / 2;
1511 for (i=0; i < numLines; i++)
1512 {
1513 ptIds[0] = 2*i;
1514 ptIds[1] = 2*i + 1;
1515 lines->InsertNextCell(2, ptIds);
1516 }
1517
1518 if (this->AxisVisibility)
1519 {
1520 //first axis point
1521 ptIds[0] = pts->InsertNextPoint(this->Point1Coordinate->GetValue());
1522 //last axis point
1523 ptIds[1] = pts->InsertNextPoint(this->Point2Coordinate->GetValue());
1524 lines->InsertNextCell(2, ptIds);
1525 }
1526 // create grid lines
1527 if (this->DrawGridlines && this->AxisOnOrigin == 0)
1528 {
1529 numGridlines = this->GridlinePts->GetNumberOfPoints()/2;
1530 int start =
1531 (this->DrawGridlinesLocation == 0 || this->DrawGridlinesLocation == 1)
1532 ? 0 : 1;
1533 int increment = (this->DrawGridlinesLocation == 0) ? 1 : 2;
1534 for (i = start; i < numGridlines; i+=increment)
1535 {
1536 ptIds[0] = 2*i;
1537 ptIds[1] = 2*i + 1;
1538 gridlines->InsertNextCell(2, ptIds);
1539 }
1540 }
1541
1542 // create inner grid lines
1543 if (this->DrawInnerGridlines && this->AxisOnOrigin == 0)
1544 {
1545 numInnerGridlines = this->InnerGridlinePts->GetNumberOfPoints()/2;
1546 for (i=0; i < numInnerGridlines; i++)
1547 {
1548 ptIds[0] = 2*i;
1549 ptIds[1] = 2*i + 1;
1550 innerGridlines->InsertNextCell(2, ptIds);
1551 }
1552 }
1553
1554 // create polys (grid polys)
1555 if (this->DrawGridpolys && this->AxisOnOrigin == 0)
1556 {
1557 numGridpolys = this->GridpolyPts->GetNumberOfPoints()/4;
1558 for (i = 0; i < numGridpolys; i++)
1559 {
1560 polyPtIds[0] = 4*i;
1561 polyPtIds[1] = 4*i + 1;
1562 polyPtIds[2] = 4*i + 2;
1563 polyPtIds[3] = 4*i + 3;
1564 polys->InsertNextCell(4,polyPtIds);
1565 }
1566 }
1567 }
1568
1569 // *********************************************************************
1570 // Returns true if any tick vis attribute has changed since last check.
1571 // *********************************************************************
TickVisibilityChanged()1572 bool vtkAxisActor::TickVisibilityChanged()
1573 {
1574 bool retVal = (this->TickVisibility != this->LastTickVisibility) ||
1575 (this->DrawGridlines != this->LastDrawGridlines) ||
1576 (this->MinorTicksVisible != this->LastMinorTicksVisible);
1577
1578 this->LastTickVisibility = this->TickVisibility;
1579 this->LastDrawGridlines = this->DrawGridlines;
1580 this->LastMinorTicksVisible = this->MinorTicksVisible;
1581
1582 return retVal;
1583 }
1584
1585 // *********************************************************************
1586 // Set the bounds for this actor to use. Sets timestamp BoundsModified.
1587 // *********************************************************************
1588 void
SetBounds(const double b[6])1589 vtkAxisActor::SetBounds(const double b[6])
1590 {
1591 if ((this->Bounds[0] != b[0]) ||
1592 (this->Bounds[1] != b[1]) ||
1593 (this->Bounds[2] != b[2]) ||
1594 (this->Bounds[3] != b[3]) ||
1595 (this->Bounds[4] != b[4]) ||
1596 (this->Bounds[5] != b[5]) )
1597 {
1598 for (int i = 0; i < 6; i++)
1599 {
1600 this->Bounds[i] = b[i];
1601 }
1602 this->BoundsTime.Modified();
1603 }
1604 }
1605
1606 // *********************************************************************
1607 // Retrieves the bounds of this actor.
1608 // *********************************************************************
1609 void vtkAxisActor::
SetBounds(double xmin,double xmax,double ymin,double ymax,double zmin,double zmax)1610 SetBounds(double xmin, double xmax, double ymin, double ymax, double zmin, double zmax)
1611 {
1612 if ((this->Bounds[0] != xmin) ||
1613 (this->Bounds[1] != xmax) ||
1614 (this->Bounds[2] != ymin) ||
1615 (this->Bounds[3] != ymax) ||
1616 (this->Bounds[4] != zmin) ||
1617 (this->Bounds[5] != zmax) )
1618 {
1619 this->Bounds[0] = xmin;
1620 this->Bounds[1] = xmax;
1621 this->Bounds[2] = ymin;
1622 this->Bounds[3] = ymax;
1623 this->Bounds[4] = zmin;
1624 this->Bounds[5] = zmax;
1625
1626 this->BoundsTime.Modified();
1627 }
1628 }
1629
1630 // *********************************************************************
1631 // Retrieves the bounds of this actor.
1632 // *********************************************************************
GetBounds()1633 double* vtkAxisActor::GetBounds()
1634 {
1635 return this->Bounds;
1636 }
1637
1638 // *********************************************************************
1639 // Retrieves the bounds of this actor.
1640 // *********************************************************************
1641
GetBounds(double b[6])1642 void vtkAxisActor::GetBounds(double b[6])
1643 {
1644 for (int i = 0; i < 6; i++)
1645 {
1646 b[i] = this->Bounds[i];
1647 }
1648 }
1649
1650 // *********************************************************************
1651 // Method: vtkAxisActor::ComputeMaxLabelLength
1652 // *********************************************************************
ComputeMaxLabelLength(const double vtkNotUsed (center)[3])1653 double vtkAxisActor::ComputeMaxLabelLength(const double vtkNotUsed(center)[3])
1654 {
1655 double bounds[6];
1656 double xsize, ysize;
1657 vtkProperty *newProp = this->NewLabelProperty();
1658 double maxXSize = 0;
1659 double maxYSize = 0;
1660 for (int i = 0; i < this->NumberOfLabelsBuilt; i++)
1661 {
1662 if (this->UseTextActor3D)
1663 {
1664 this->LabelProps3D[i]->SetCamera(this->Camera);
1665 this->LabelActors3D[i]->GetBounds(bounds);
1666 }
1667 else
1668 {
1669 this->LabelActors[i]->SetCamera(this->Camera);
1670 this->LabelActors[i]->SetProperty(newProp);
1671 this->LabelActors[i]->GetMapper()->GetBounds(bounds);
1672 }
1673 xsize = bounds[1] - bounds[0];
1674 ysize = bounds[3] - bounds[2];
1675 maxXSize = (xsize > maxXSize ? xsize : maxXSize);
1676 maxYSize = (ysize > maxYSize ? ysize : maxYSize);
1677 }
1678 newProp->Delete();
1679 return sqrt(maxXSize*maxXSize + maxYSize*maxYSize);
1680 }
1681
1682 // *********************************************************************
1683 // Method: vtkAxisActor::ComputeTitleLength
1684 // *********************************************************************
ComputeTitleLength(const double vtkNotUsed (center)[3])1685 double vtkAxisActor::ComputeTitleLength(const double vtkNotUsed(center)[3])
1686 {
1687 double bounds[6];
1688 double xsize, ysize;
1689 double length;
1690
1691 if (this->UseTextActor3D)
1692 {
1693 this->TitleActor3D->SetInput(this->Title);
1694 this->TitleProp3D->SetCamera(this->Camera);
1695 this->TitleActor3D->GetBounds(bounds);
1696 }
1697 else
1698 {
1699 this->TitleVector->SetText(this->Title);
1700 this->TitleActor->SetCamera(this->Camera);
1701 vtkProperty * newProp = this->NewTitleProperty();
1702 this->TitleActor->SetProperty(newProp);
1703 newProp->Delete();
1704 this->TitleActor->GetMapper()->GetBounds(bounds);
1705 }
1706 xsize = bounds[1] - bounds[0];
1707 ysize = bounds[3] - bounds[2];
1708 length = sqrt(xsize*xsize + ysize*ysize);
1709
1710 return length;
1711 }
1712
1713 // *********************************************************************
SetLabelScale(const double s)1714 void vtkAxisActor::SetLabelScale(const double s)
1715 {
1716 for (int i=0; i < this->NumberOfLabelsBuilt; i++)
1717 {
1718 this->SetLabelScale(i, s);
1719 }
1720 }
1721
1722 // *********************************************************************
SetLabelScale(int label,const double s)1723 void vtkAxisActor::SetLabelScale(int label, const double s)
1724 {
1725 this->LabelActors[label]->SetScale(s);
1726 this->LabelProps3D[label]->SetScale(s);
1727 }
1728
1729 // *********************************************************************
SetTitleScale(const double s)1730 void vtkAxisActor::SetTitleScale(const double s)
1731 {
1732 this->TitleActor->SetScale(s);
1733 this->TitleProp3D->SetScale(s);
1734 }
1735
1736 // *********************************************************************
SetTitle(const char * t)1737 void vtkAxisActor::SetTitle(const char *t)
1738 {
1739 if (this->Title == NULL && t == NULL)
1740 {
1741 return;
1742 }
1743 if (this->Title && (!strcmp(this->Title, t)))
1744 {
1745 return;
1746 }
1747 delete [] this->Title;
1748 if (t)
1749 {
1750 this->Title = new char[strlen(t)+1];
1751 strcpy(this->Title, t);
1752 }
1753 else
1754 {
1755 this->Title = NULL;
1756 }
1757 this->TitleTextTime.Modified();
1758 this->Modified();
1759 }
1760
1761 // ****************************************************************************
SetAxisLinesProperty(vtkProperty * prop)1762 void vtkAxisActor::SetAxisLinesProperty(vtkProperty *prop)
1763 {
1764 this->AxisLinesActor->SetProperty(prop);
1765 this->Modified();
1766 }
1767
1768 // ****************************************************************************
GetAxisLinesProperty()1769 vtkProperty* vtkAxisActor::GetAxisLinesProperty()
1770 {
1771 return this->AxisLinesActor->GetProperty();
1772 }
1773
1774 // ****************************************************************************
SetGridlinesProperty(vtkProperty * prop)1775 void vtkAxisActor::SetGridlinesProperty(vtkProperty *prop)
1776 {
1777 this->GridlinesActor->SetProperty(prop);
1778 this->Modified();
1779 }
1780
1781 // ****************************************************************************
GetGridlinesProperty()1782 vtkProperty* vtkAxisActor::GetGridlinesProperty()
1783 {
1784 return this->GridlinesActor->GetProperty();
1785 }
1786
1787 // ****************************************************************************
SetInnerGridlinesProperty(vtkProperty * prop)1788 void vtkAxisActor::SetInnerGridlinesProperty(vtkProperty *prop)
1789 {
1790 this->InnerGridlinesActor->SetProperty(prop);
1791 this->Modified();
1792 }
1793
1794 // ****************************************************************************
GetInnerGridlinesProperty()1795 vtkProperty* vtkAxisActor::GetInnerGridlinesProperty()
1796 {
1797 return this->InnerGridlinesActor->GetProperty();
1798 }
1799
1800 // ****************************************************************************
SetGridpolysProperty(vtkProperty * prop)1801 void vtkAxisActor::SetGridpolysProperty(vtkProperty *prop)
1802 {
1803 this->GridpolysActor->SetProperty(prop);
1804 this->Modified();
1805 }
1806
1807 // ****************************************************************************
GetGridpolysProperty()1808 vtkProperty* vtkAxisActor::GetGridpolysProperty()
1809 {
1810 return this->GridpolysActor->GetProperty();
1811 }
1812
1813 // ****************************************************************************
NewTitleProperty()1814 vtkProperty* vtkAxisActor::NewTitleProperty()
1815 {
1816 vtkProperty *newProp = vtkProperty::New();
1817 newProp->DeepCopy(this->GetProperty());
1818 newProp->SetColor(this->TitleTextProperty->GetColor());
1819 // We pass the opacity in the line offset.
1820 //newProp->SetOpacity(this->TitleTextProperty->GetLineOffset());
1821 return newProp;
1822 }
1823
1824 // ****************************************************************************
NewLabelProperty()1825 vtkProperty* vtkAxisActor::NewLabelProperty()
1826 {
1827 vtkProperty *newProp = vtkProperty::New();
1828 newProp->DeepCopy(this->GetProperty());
1829 newProp->SetColor(this->LabelTextProperty->GetColor());
1830 // We pass the opacity in the line offset.
1831 //newProp->SetOpacity(this->LabelTextProperty->GetLineOffset());
1832 return newProp;
1833 }
1834
1835
1836 // ****************************************************************************
GetDeltaMajor(int axis)1837 double vtkAxisActor::GetDeltaMajor(int axis){
1838 if(axis>=0 && axis<=2)
1839 {
1840 return (this->DeltaMajor[axis]);
1841 }
1842 return 0;
1843 }
1844
SetDeltaMajor(int axis,double value)1845 void vtkAxisActor::SetDeltaMajor(int axis, double value){
1846 if(axis>=0 && axis<=2)
1847 {
1848 this->DeltaMajor[axis] = value;
1849 }
1850 }
1851
1852 // ****************************************************************************
GetMajorStart(int axis)1853 double vtkAxisActor::GetMajorStart(int axis){
1854 if(axis>=0 && axis<=2)
1855 {
1856 return (this->MajorStart[axis]);
1857 }
1858 return 0;
1859 }
1860
1861 // ****************************************************************************
SetMajorStart(int axis,double value)1862 void vtkAxisActor::SetMajorStart(int axis, double value){
1863 if(axis>=0 && axis<=2)
1864 {
1865 this->MajorStart[axis] = value;
1866 }
1867 }
1868
1869 // ****************************************************************************
BoundsDisplayCoordinateChanged(vtkViewport * viewport)1870 bool vtkAxisActor::BoundsDisplayCoordinateChanged(vtkViewport *viewport)
1871 {
1872 double transMinPt[3], transMaxPt[3];
1873 viewport->SetWorldPoint(this->Bounds[0], this->Bounds[2], this->Bounds[4], 1.0);
1874 viewport->WorldToDisplay();
1875 viewport->GetDisplayPoint(transMinPt);
1876 viewport->SetWorldPoint(this->Bounds[1], this->Bounds[3], this->Bounds[5], 1.0);
1877 viewport->WorldToDisplay();
1878 viewport->GetDisplayPoint(transMaxPt);
1879
1880 if( this->LastMinDisplayCoordinate[0] != transMinPt[0]
1881 || this->LastMinDisplayCoordinate[1] != transMinPt[1]
1882 || this->LastMinDisplayCoordinate[2] != transMinPt[2]
1883 || this->LastMaxDisplayCoordinate[0] != transMaxPt[0]
1884 || this->LastMaxDisplayCoordinate[1] != transMaxPt[1]
1885 || this->LastMaxDisplayCoordinate[2] != transMaxPt[2] )
1886 {
1887 int i = 0;
1888 for( i=0 ; i<3 ; ++i )
1889 {
1890 this->LastMinDisplayCoordinate[i] = transMinPt[i];
1891 this->LastMaxDisplayCoordinate[i] = transMaxPt[i];
1892 }
1893 return true;
1894 }
1895
1896 return false;
1897 }
1898 //---------------------------------------------------------------------------
1899 // endpoint-related methods
GetPoint1Coordinate()1900 vtkCoordinate* vtkAxisActor::GetPoint1Coordinate()
1901 {
1902 vtkDebugMacro(<< this->GetClassName() << " (" << this
1903 << "): returning Point1 Coordinate address "
1904 << this->Point1Coordinate );
1905 return this->Point1Coordinate;
1906 }
1907
1908 //---------------------------------------------------------------------------
GetPoint2Coordinate()1909 vtkCoordinate* vtkAxisActor::GetPoint2Coordinate()
1910 {
1911 vtkDebugMacro(<< this->GetClassName() << " (" << this
1912 << "): returning Point2 Coordinate address "
1913 << this->Point2Coordinate );
1914 return this->Point2Coordinate;
1915 }
1916
1917 //---------------------------------------------------------------------------
SetPoint1(double x,double y,double z)1918 void vtkAxisActor::SetPoint1(double x, double y, double z)
1919 {
1920 this->Point1Coordinate->SetValue(x, y, z);
1921 }
1922
1923 //---------------------------------------------------------------------------
SetPoint2(double x,double y,double z)1924 void vtkAxisActor::SetPoint2(double x, double y, double z)
1925 {
1926 this->Point2Coordinate->SetValue(x, y, z);
1927 }
1928
1929 //---------------------------------------------------------------------------
GetPoint1()1930 double* vtkAxisActor::GetPoint1()
1931 {
1932 return this->Point1Coordinate->GetValue();
1933 }
1934
1935 //---------------------------------------------------------------------------
GetPoint2()1936 double* vtkAxisActor::GetPoint2()
1937 {
1938 return this->Point2Coordinate->GetValue();
1939 }
1940 // **************************************************************************
1941 // Creates points for ticks (minor, major, gridlines) in correct position
1942 // for a generic axis.
1943 // **************************************************************************
BuildTickPoints(double p1[3],double p2[3],bool force)1944 bool vtkAxisActor::BuildTickPoints(double p1[3], double p2[3], bool force)
1945 {
1946 // Prevent any unwanted computation
1947 if (!force && (this->AxisPosition == this->LastAxisPosition) &&
1948 (this->TickLocation == this->LastTickLocation ) &&
1949 (this->BoundsTime.GetMTime() < this->BuildTime.GetMTime()) &&
1950 (this->Point1Coordinate->GetMTime() < this->BuildTickPointsTime.GetMTime()) &&
1951 (this->Point2Coordinate->GetMTime() < this->BuildTickPointsTime.GetMTime()) &&
1952 (this->Range[0] == this->LastRange[0]) &&
1953 (this->Range[1] == this->LastRange[1]))
1954 {
1955 return false;
1956 }
1957
1958 // Local tmp vars
1959 double uPointInside[3], vPointInside[3], uPointOutside[3], vPointOutside[3];
1960 double gridPointClosest[3], gridPointFarest[3], gridPointU[3], gridPointV[3];
1961 double innerGridPointClosestU[3], innerGridPointClosestV[3];
1962 double innerGridPointFarestU[3], innerGridPointFarestV[3];
1963 double deltaVector[3];
1964 double axisLength, axisShift, rangeScale, nbIterationAsDouble;
1965 int nbTicks, i, nbIteration, uIndex, vIndex;
1966 uIndex = vIndex = 0;
1967 bool hasOrthogonalVectorBase =
1968 (this->AxisBaseForX[0] == 1 && this->AxisBaseForX[1] == 0 && this->AxisBaseForX[2] == 0
1969 && this->AxisBaseForY[0] == 0 && this->AxisBaseForY[1] == 1 && this->AxisBaseForY[2] == 0
1970 && this->AxisBaseForZ[0] == 0 && this->AxisBaseForZ[1] == 0 && this->AxisBaseForZ[2] == 1);
1971
1972 // Reset previous objects
1973 this->MinorTickPts->Reset();
1974 this->MajorTickPts->Reset();
1975 this->GridlinePts->Reset();
1976 this->InnerGridlinePts->Reset();
1977 this->GridpolyPts->Reset();
1978
1979 // As we assume that the Axis is not necessery alined to the absolute X/Y/Z
1980 // axis, we will convert the absolut XYZ information to relative one
1981 // using a base composed as follow (axis, u, v)
1982 double uGridLength, vGridLength;
1983 uGridLength = vGridLength = 0;
1984 double *axisVector, *uVector, *vVector;
1985 axisVector = uVector = vVector = NULL;
1986 int uMult = vtkAxisActorMultiplierTable1[this->AxisPosition];
1987 int vMult = vtkAxisActorMultiplierTable2[this->AxisPosition];
1988
1989 switch(this->AxisType)
1990 {
1991 case VTK_AXIS_TYPE_X:
1992 uGridLength = this->GridlineYLength;
1993 vGridLength = this->GridlineZLength;
1994 axisVector = this->AxisBaseForX;
1995 uVector = this->AxisBaseForY;
1996 vVector = this->AxisBaseForZ;
1997 uIndex = 1; vIndex = 2;
1998 break;
1999 case VTK_AXIS_TYPE_Y:
2000 uGridLength = this->GridlineXLength;
2001 vGridLength = this->GridlineZLength;
2002 uVector = this->AxisBaseForX;
2003 axisVector = this->AxisBaseForY;
2004 vVector = this->AxisBaseForZ;
2005 uIndex = 0; vIndex = 2;
2006 break;
2007 case VTK_AXIS_TYPE_Z:
2008 uGridLength = this->GridlineXLength;
2009 vGridLength = this->GridlineYLength;
2010 uVector = this->AxisBaseForX;
2011 vVector = this->AxisBaseForY;
2012 axisVector = this->AxisBaseForZ;
2013 uIndex = 0; vIndex = 1;
2014 break;
2015 }
2016
2017 // **************************************************************************
2018 // Build Minor Ticks
2019 // **************************************************************************
2020 {
2021 // - Initialize all points to be on the axis
2022 for(i=0;i<3;i++)
2023 {
2024 uPointInside[i] = vPointInside[i] = uPointOutside[i] = vPointOutside[i] = p1[i];
2025 deltaVector[i] = (p2[i] - p1[i]);
2026 }
2027 axisLength = vtkMath::Norm(deltaVector);
2028 rangeScale = axisLength/(this->Range[1] - this->Range[0]);
2029
2030 // - Reduce the deltaVector to correspond to a tick step
2031 vtkMath::Normalize(deltaVector);
2032 for(i=0;i<3;i++)
2033 {
2034 deltaVector[i] *= this->DeltaMinor;
2035 }
2036
2037 // - Move outside points if needed (Axis -> Outside)
2038 if (this->TickLocation == VTK_TICKS_OUTSIDE || this->TickLocation == VTK_TICKS_BOTH)
2039 {
2040 for(i=0;i<3;i++)
2041 {
2042 uPointOutside[i] += uVector[i] * uMult * this->MinorTickSize;
2043 vPointOutside[i] += vVector[i] * vMult * this->MinorTickSize;
2044 }
2045 }
2046
2047 // - Move inside points if needed (Axis -> Inside)
2048 if (this->TickLocation == VTK_TICKS_INSIDE || this->TickLocation == VTK_TICKS_BOTH)
2049 {
2050 for(i=0;i<3;i++)
2051 {
2052 uPointInside[i] -= uVector[i] * uMult * this->MinorTickSize;
2053 vPointInside[i] -= vVector[i] * vMult * this->MinorTickSize;
2054 }
2055 }
2056
2057 // - Add the initial shift if any
2058 axisShift = (this->MinorRangeStart - this->Range[0])*rangeScale;
2059 for(i=0;i<3;i++)
2060 {
2061 uPointInside[i] += axisVector[i] * axisShift;
2062 vPointInside[i] += axisVector[i] * axisShift;
2063 uPointOutside[i] += axisVector[i] * axisShift;
2064 vPointOutside[i] += axisVector[i] * axisShift;
2065 }
2066
2067 // - Insert tick points along the axis using the deltaVector
2068 nbIterationAsDouble = axisLength / vtkMath::Norm(deltaVector);
2069 nbIteration = vtkMath::Floor(nbIterationAsDouble+2*DBL_EPSILON);
2070 nbIteration = (nbIteration < VTK_MAX_TICKS) ? nbIteration : VTK_MAX_TICKS;
2071 for (nbTicks = 0; nbTicks < nbIteration; nbTicks++)
2072 {
2073 // axis/u side
2074 this->MinorTickPts->InsertNextPoint(uPointInside);
2075 this->MinorTickPts->InsertNextPoint(uPointOutside);
2076 vtkMath::Add(deltaVector, uPointInside, uPointInside);
2077 vtkMath::Add(deltaVector, uPointOutside, uPointOutside);
2078 if( this->Use2DMode == 0 )
2079 {
2080 // axis/v side
2081 this->MinorTickPts->InsertNextPoint(vPointInside);
2082 this->MinorTickPts->InsertNextPoint(vPointOutside);
2083 vtkMath::Add(deltaVector, vPointInside, vPointInside);
2084 vtkMath::Add(deltaVector, vPointOutside, vPointOutside);
2085 }
2086 }
2087 }
2088 // **************************************************************************
2089 // Build Gridline + GridPoly points + InnerGrid (Only for Orthonormal base)
2090 // **************************************************************************
2091 {
2092 // - Initialize all points to be on the axis
2093 for(i=0;i<3;i++)
2094 {
2095 gridPointClosest[i] = gridPointFarest[i] = gridPointU[i] = gridPointV[i] = p1[i];
2096 deltaVector[i] = (p2[i] - p1[i]);
2097 }
2098
2099 // - Reduce the deltaVector to correspond to a major tick step
2100 vtkMath::Normalize(deltaVector);
2101 for(i=0;i<3;i++)
2102 {
2103 deltaVector[i] *= this->DeltaMajor[this->AxisType];
2104 }
2105
2106 // - Move base points
2107 for(i=0;i<3;i++)
2108 {
2109 gridPointU[i] -= uVector[i] * uMult * uGridLength;
2110 gridPointV[i] -= vVector[i] * vMult * vGridLength;
2111 gridPointFarest[i] -= uVector[i] * uMult * uGridLength + vVector[i] * vMult * vGridLength;
2112 }
2113
2114 // - Add the initial shift if any
2115 axisShift = (this->MajorRangeStart - this->Range[0])*rangeScale;
2116 for(i=0;i<3;i++)
2117 {
2118 gridPointU[i] += axisVector[i] * axisShift;
2119 gridPointV[i] += axisVector[i] * axisShift;
2120 gridPointFarest[i] += axisVector[i] * axisShift;
2121 gridPointClosest[i] += axisVector[i] * axisShift;
2122 }
2123
2124 // - Insert Gridlines points along the axis using the DeltaMajor vector
2125 nbIterationAsDouble = (axisLength - axisShift) / vtkMath::Norm(deltaVector);
2126 nbIteration = vtkMath::Floor(nbIterationAsDouble+2*FLT_EPSILON) + 1;
2127 nbIteration = (nbIteration < VTK_MAX_TICKS) ? nbIteration : VTK_MAX_TICKS;
2128 for (nbTicks = 0; nbTicks < nbIteration; nbTicks++)
2129 {
2130 // Closest U
2131 this->GridlinePts->InsertNextPoint(gridPointClosest);
2132 this->GridlinePts->InsertNextPoint(gridPointU);
2133
2134 // Farest U
2135 this->GridlinePts->InsertNextPoint(gridPointFarest);
2136 this->GridlinePts->InsertNextPoint(gridPointU);
2137
2138 // Closest V
2139 this->GridlinePts->InsertNextPoint(gridPointClosest);
2140 this->GridlinePts->InsertNextPoint(gridPointV);
2141
2142 // Farest V
2143 this->GridlinePts->InsertNextPoint(gridPointFarest);
2144 this->GridlinePts->InsertNextPoint(gridPointV);
2145
2146 // PolyPoints
2147 this->GridpolyPts->InsertNextPoint(gridPointClosest);
2148 this->GridpolyPts->InsertNextPoint(gridPointU);
2149 this->GridpolyPts->InsertNextPoint(gridPointFarest);
2150 this->GridpolyPts->InsertNextPoint(gridPointV);
2151
2152 // Move forward along the axis
2153 for(i=0;i<3;i++)
2154 {
2155 gridPointClosest[i] += deltaVector[i];
2156 gridPointU[i] += deltaVector[i];
2157 gridPointFarest[i] += deltaVector[i];
2158 gridPointV[i] += deltaVector[i];
2159 }
2160 }
2161
2162 // - Insert InnerGridLines points
2163
2164 // We can only handle inner grid line with orthonormal base, otherwise
2165 // we would need to change the API of AxisActor which we don't want for
2166 // backward compatibility.
2167 if(hasOrthogonalVectorBase)
2168 {
2169 double axis, u, v;
2170 axis = this->MajorStart[this->AxisType];
2171 innerGridPointClosestU[vIndex] = this->GetBounds()[vIndex*2];
2172 innerGridPointFarestU[vIndex] = this->GetBounds()[vIndex*2+1];
2173 innerGridPointClosestV[uIndex] = this->GetBounds()[uIndex*2];
2174 innerGridPointFarestV[uIndex] = this->GetBounds()[uIndex*2+1];
2175 while (axis <= p2[this->AxisType])
2176 {
2177 innerGridPointClosestU[this->AxisType]
2178 = innerGridPointClosestV[this->AxisType]
2179 = innerGridPointFarestU[this->AxisType]
2180 = innerGridPointFarestV[this->AxisType]
2181 = axis;
2182
2183 // u lines
2184 u = this->MajorStart[uIndex];
2185 while (u <= p2[uIndex] && this->DeltaMajor[uIndex] > 0)
2186 {
2187 innerGridPointClosestU[uIndex]
2188 = innerGridPointFarestU[uIndex]
2189 = u;
2190 this->InnerGridlinePts->InsertNextPoint(innerGridPointClosestU);
2191 this->InnerGridlinePts->InsertNextPoint(innerGridPointFarestU);
2192 u += this->DeltaMajor[uIndex];
2193 }
2194
2195 // v lines
2196 v = this->MajorStart[vIndex];
2197 while (v <= p2[vIndex] && this->DeltaMajor[vIndex] > 0)
2198 {
2199 innerGridPointClosestV[vIndex]
2200 = innerGridPointFarestV[vIndex]
2201 = v;
2202 this->InnerGridlinePts->InsertNextPoint(innerGridPointClosestV);
2203 this->InnerGridlinePts->InsertNextPoint(innerGridPointFarestV);
2204 v += this->DeltaMajor[vIndex];
2205 }
2206
2207 axis += this->DeltaMajor[this->AxisType];
2208 }
2209 }
2210 }
2211 // **************************************************************************
2212 // Build Major ticks
2213 // **************************************************************************
2214 {
2215 // Delta vector is already initialized with the Major tick scale
2216 // - Initialize all points to be on the axis
2217 for(i=0;i<3;i++)
2218 {
2219 uPointInside[i] = vPointInside[i] = uPointOutside[i] = vPointOutside[i] = p1[i];
2220 }
2221
2222 // - Move outside points if needed (Axis -> Outside)
2223 if (this->TickLocation == VTK_TICKS_OUTSIDE || this->TickLocation == VTK_TICKS_BOTH)
2224 {
2225 for(i=0;i<3;i++)
2226 {
2227 uPointOutside[i] += uVector[i] * uMult * this->MajorTickSize;
2228 vPointOutside[i] += vVector[i] * vMult * this->MajorTickSize;
2229 }
2230 }
2231
2232 // - Move inside points if needed (Axis -> Inside)
2233 if (this->TickLocation == VTK_TICKS_INSIDE || this->TickLocation == VTK_TICKS_BOTH)
2234 {
2235 for(i=0;i<3;i++)
2236 {
2237 uPointInside[i] -= uVector[i] * uMult * this->MajorTickSize;
2238 vPointInside[i] -= vVector[i] * vMult * this->MajorTickSize;
2239 }
2240 }
2241
2242 // - Add the initial shift if any
2243 for(i=0;i<3;i++)
2244 {
2245 uPointInside[i] += axisVector[i] * axisShift;
2246 vPointInside[i] += axisVector[i] * axisShift;
2247 uPointOutside[i] += axisVector[i] * axisShift;
2248 vPointOutside[i] += axisVector[i] * axisShift;
2249 }
2250
2251 // - Insert tick points along the axis using the deltaVector
2252 for (nbTicks = 0; nbTicks < nbIteration; nbTicks++)
2253 {
2254 // axis/u side
2255 this->MajorTickPts->InsertNextPoint(uPointInside);
2256 this->MajorTickPts->InsertNextPoint(uPointOutside);
2257 vtkMath::Add(deltaVector, uPointInside, uPointInside);
2258 vtkMath::Add(deltaVector, uPointOutside, uPointOutside);
2259
2260 // axis/v side
2261 this->MajorTickPts->InsertNextPoint(vPointInside);
2262 this->MajorTickPts->InsertNextPoint(vPointOutside);
2263 vtkMath::Add(deltaVector, vPointInside, vPointInside);
2264 vtkMath::Add(deltaVector, vPointOutside, vPointOutside);
2265 }
2266 }
2267
2268 this->BuildTickPointsTime.Modified();
2269 this->LastTickLocation = this->TickLocation;
2270 return true;
2271 }
2272