source: trunk/packages/vizservers/vtkvis/vtkRpAxisActor.cpp @ 3479

Last change on this file since 3479 was 3479, checked in by ldelgass, 10 years ago

Update custom axes to VTK 6 versions, use local customized classes instead of
patched VTK runtime versions.

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