vtkScalarBarActor.cxx 74.1 KB
Newer Older
1
2
3
4
5
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkScalarBarActor.cxx

6
  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7
8
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
Will Schroeder's avatar
Will Schroeder committed
9

10
11
     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12
     PURPOSE.  See the above copyright notice for more information.
13
14
15

=========================================================================*/
#include "vtkScalarBarActor.h"
16
#include "vtkScalarBarActorInternal.h"
17

18
19
#include "vtkCellArray.h"
#include "vtkCellData.h"
20
#include "vtkColor.h"
21
#include "vtkCoordinate.h"
22
23
24
25
#include "vtkFloatArray.h"
#include "vtkPointData.h"
#include "vtkImageData.h"
#include "vtkMath.h"
26
#include "vtkObjectFactory.h"
27
#include "vtkPolyData.h"
28
#include "vtkPolyDataMapper2D.h"
29
30
#include "vtkProperty2D.h"
#include "vtkRenderer.h"
31
#include "vtkRenderWindow.h"
32
#include "vtkScalarsToColors.h"
33
34
#include "vtkSmartPointer.h"
#include "vtkTextActor.h"
Sebastien Barre's avatar
Sebastien Barre committed
35
#include "vtkTextProperty.h"
36
#include "vtkTexture.h"
37
38
#include "vtkViewport.h"
#include "vtkWindow.h"
39
#include "vtkMathTextUtilities.h"
40

41
42
#include <vector>
#include <set>
43
44
45
46
47
48
49
50
51
#include <map>

#include <stdio.h> // for snprintf

#if defined(_WIN32) && !defined(__CYGWIN__)
#  define SNPRINTF _snprintf
#else
#  define SNPRINTF snprintf
#endif
52

53
54
#undef VTK_DBG_LAYOUT

Brad King's avatar
Brad King committed
55
vtkStandardNewMacro(vtkScalarBarActor);
56

57
vtkCxxSetObjectMacro(vtkScalarBarActor,LookupTable,vtkScalarsToColors);
Sebastien Barre's avatar
Sebastien Barre committed
58
59
vtkCxxSetObjectMacro(vtkScalarBarActor,LabelTextProperty,vtkTextProperty);
vtkCxxSetObjectMacro(vtkScalarBarActor,TitleTextProperty,vtkTextProperty);
60
61
vtkCxxSetObjectMacro(vtkScalarBarActor,BackgroundProperty,vtkProperty2D);
vtkCxxSetObjectMacro(vtkScalarBarActor,FrameProperty,vtkProperty2D);
62

Sebastien Barre's avatar
Sebastien Barre committed
63
64
//----------------------------------------------------------------------------
// Instantiate object with 64 maximum colors; 5 labels; %%-#6.3g label
65
66
67
68
// format, no title, and vertical orientation. The initial scalar bar
// size is (0.05 x 0.8) of the viewport size.
vtkScalarBarActor::vtkScalarBarActor()
{
69
  this->P = new vtkScalarBarActorInternal;
70
  this->LookupTable = NULL;
71
  this->Position2Coordinate->SetValue(0.17, 0.8);
72

73
74
  this->PositionCoordinate->SetCoordinateSystemToNormalizedViewport();
  this->PositionCoordinate->SetValue(0.82,0.1);
75

76
77
78
  this->TextPad = 1;
  this->TitleRatio = 0.5;
  this->BarRatio = 0.375;
79
80
  this->MaximumNumberOfColors = 64;
  this->NumberOfLabels = 5;
81
  this->NumberOfLabelsBuilt = 0;
82
83
  this->Orientation = VTK_ORIENT_VERTICAL;
  this->Title = NULL;
84
  this->ComponentTitle = NULL;
85

Sebastien Barre's avatar
Sebastien Barre committed
86
87
88
89
90
91
92
93
94
95
  this->LabelTextProperty = vtkTextProperty::New();
  this->LabelTextProperty->SetFontSize(12);
  this->LabelTextProperty->SetBold(1);
  this->LabelTextProperty->SetItalic(1);
  this->LabelTextProperty->SetShadow(1);
  this->LabelTextProperty->SetFontFamilyToArial();

  this->TitleTextProperty = vtkTextProperty::New();
  this->TitleTextProperty->ShallowCopy(this->LabelTextProperty);

96
  this->LabelFormat = new char[8];
97
98
  sprintf(this->LabelFormat,"%s","%-#6.3g");

99
  this->TitleActor = vtkTextActor::New();
100
101
  this->TitleActor->GetPositionCoordinate()->
    SetReferenceCoordinate(this->PositionCoordinate);
102

103
104
  this->ScalarBar = vtkPolyData::New();
  this->ScalarBarMapper = vtkPolyDataMapper2D::New();
105
  this->ScalarBarMapper->SetInputData(this->ScalarBar);
106
107
  this->ScalarBarActor = vtkActor2D::New();
  this->ScalarBarActor->SetMapper(this->ScalarBarMapper);
108
109
  this->ScalarBarActor->GetPositionCoordinate()->
    SetReferenceCoordinate(this->PositionCoordinate);
Ken Martin's avatar
Ken Martin committed
110
111
112
113
  this->LastOrigin[0] = 0;
  this->LastOrigin[1] = 0;
  this->LastSize[0] = 0;
  this->LastSize[1] = 0;
114

David Thompson's avatar
David Thompson committed
115
  this->DrawAnnotations = 1;
116
  this->DrawNanAnnotation = 0;
117
  this->AnnotationTextScaling = 0;
118
119
120
121
122
123
124
125
126
127
128
  this->FixedAnnotationLeaderLineColor = 0;
  this->NanAnnotation = 0;
  this->SetNanAnnotation("NaN");
  this->P->NanSwatch = vtkPolyData::New();
  this->P->NanSwatchMapper = vtkPolyDataMapper2D::New();
  this->P->NanSwatchActor = vtkActor2D::New();
  this->P->NanSwatchMapper->SetInputData(this->P->NanSwatch);
  this->P->NanSwatchActor->SetMapper(this->P->NanSwatchMapper);
  this->P->NanSwatchActor->GetPositionCoordinate()->
    SetReferenceCoordinate(this->PositionCoordinate);

David Thompson's avatar
David Thompson committed
129
  this->AnnotationLeaderPadding = 8.;
130
131
132
133
134
135
136
137
138
139
140
141
142
143
  this->P->AnnotationBoxes = vtkPolyData::New();
  this->P->AnnotationBoxesMapper = vtkPolyDataMapper2D::New();
  this->P->AnnotationBoxesActor = vtkActor2D::New();
  this->P->AnnotationBoxesMapper->SetInputData(this->P->AnnotationBoxes);
  this->P->AnnotationBoxesActor->SetMapper(this->P->AnnotationBoxesMapper);
  this->P->AnnotationBoxesActor->GetPositionCoordinate()->
    SetReferenceCoordinate(this->PositionCoordinate);
  this->P->AnnotationLeaders = vtkPolyData::New();
  this->P->AnnotationLeadersMapper = vtkPolyDataMapper2D::New();
  this->P->AnnotationLeadersActor = vtkActor2D::New();
  this->P->AnnotationLeadersMapper->SetInputData(this->P->AnnotationLeaders);
  this->P->AnnotationLeadersActor->SetMapper(this->P->AnnotationLeadersMapper);
  this->P->AnnotationLeadersActor->GetPositionCoordinate()->
    SetReferenceCoordinate(this->PositionCoordinate);
144

145
146
147
148
  // If opacity is on, a jail like texture is displayed behind it..

  this->UseOpacity       = 0;
  this->TextureGridWidth = 10.0;
149

150
  this->TexturePolyData = vtkPolyData::New();
151
  vtkPolyDataMapper2D* textureMapper = vtkPolyDataMapper2D::New();
152
  textureMapper->SetInputData(this->TexturePolyData);
153
154
155
156
157
158
159
160
  this->TextureActor = vtkActor2D::New();
  this->TextureActor->SetMapper(textureMapper);
  textureMapper->Delete();
  this->TextureActor->GetPositionCoordinate()->
    SetReferenceCoordinate(this->PositionCoordinate);
  vtkFloatArray* tc = vtkFloatArray::New();
  tc->SetNumberOfComponents(2);
  tc->SetNumberOfTuples(4);
161
  tc->InsertComponent(0,0, 0.0);
162
163
  tc->InsertComponent(0,1, 0.0);
  tc->InsertComponent(1,1, 0.0);
164
  tc->InsertComponent(3,0, 0.0);
165
166
167
168
169
170
171
172
173
174
175
176
  this->TexturePolyData->GetPointData()->SetTCoords(tc);
  tc->Delete();

  vtkCellArray* polys2 = vtkCellArray::New();
  polys2->InsertNextCell(4);
  polys2->InsertCellPoint(0);
  polys2->InsertCellPoint(1);
  polys2->InsertCellPoint(2);
  polys2->InsertCellPoint(3);
  this->TexturePolyData->SetPolys(polys2);
  polys2->Delete();

177
  vtkProperty2D* imageProperty = vtkProperty2D::New();
178
179
180
181
182
183
184
  imageProperty->SetOpacity(0.08);
  this->TextureActor->SetProperty(imageProperty);
  imageProperty->Delete();

  // Create the default texture. Just a "Jail" like grid

  const unsigned int dim = 128;
185
  vtkImageData* image = vtkImageData::New();
186
  image->SetDimensions(dim, dim, 1);
Berk Geveci's avatar
Berk Geveci committed
187
  image->AllocateScalars(VTK_UNSIGNED_CHAR, 1);
188

189
190
  for (unsigned int y = 0; y < dim; y++)
    {
191
192
    unsigned char* ptr =
      static_cast<unsigned char*>(image->GetScalarPointer(0, y, 0));
193
194
195
196
197
198
199
200
    for (unsigned int x = 0; x < dim; x++)
      {
      *ptr = ((x == y) || (x == (dim-y-1))) ? 255 : 0;
      ++ptr;
      }
    }

  this->Texture = vtkTexture::New();
201
  this->Texture->SetInputData( image );
202
203
  this->Texture->RepeatOn();
  image->Delete();
204
205
206
207

  // Default text position : Above scalar bar if orientation is horizontal
  //                         Right of scalar bar if orientation is vertical
  this->TextPosition = SucceedScalarBar;
208
209
210

  this->MaximumWidthInPixels = VTK_INT_MAX;
  this->MaximumHeightInPixels = VTK_INT_MAX;
211
212
213
214
215
216
217

  this->BackgroundProperty = vtkProperty2D::New();
  this->FrameProperty = vtkProperty2D::New();

  this->DrawBackground = 0;
  this->Background = vtkPolyData::New();
  this->BackgroundMapper = vtkPolyDataMapper2D::New();
218
  this->BackgroundMapper->SetInputData(this->Background);
219
220
  this->BackgroundActor = vtkActor2D::New();
  this->BackgroundActor->SetMapper(this->BackgroundMapper);
221
222
  this->BackgroundActor->GetPositionCoordinate()
    ->SetReferenceCoordinate(this->PositionCoordinate);
223

224
225
226
#ifdef VTK_DBG_LAYOUT
  this->DrawFrame = 1;
#else // VTK_DBG_LAYOUT
227
  this->DrawFrame = 0;
228
#endif // VTK_DBG_LAYOUT
229
230
  this->Frame = vtkPolyData::New();
  this->FrameMapper = vtkPolyDataMapper2D::New();
231
  this->FrameMapper->SetInputData(this->Frame);
232
233
  this->FrameActor = vtkActor2D::New();
  this->FrameActor->SetMapper(this->FrameMapper);
234
235
  this->FrameActor->GetPositionCoordinate()
    ->SetReferenceCoordinate(this->PositionCoordinate);
236
237

  this->DrawColorBar = true;
238
  this->DrawTickLabels = true;
239
240
}

Sebastien Barre's avatar
Sebastien Barre committed
241
//----------------------------------------------------------------------------
Ken Martin's avatar
Ken Martin committed
242
243
244
// Release any graphics resources that are being consumed by this actor.
// The parameter window could be used to determine which graphic
// resources to release.
245
void vtkScalarBarActor::ReleaseGraphicsResources(vtkWindow* win)
Ken Martin's avatar
Ken Martin committed
246
247
{
  this->TitleActor->ReleaseGraphicsResources(win);
248
  if (!this->P->TextActors.empty())
Ken Martin's avatar
Ken Martin committed
249
    {
250
251
252
253
254
    vtkScalarBarActorInternal::ActorVec::iterator it;
    for (
      it = this->P->TextActors.begin();
      it != this->P->TextActors.end();
      ++it)
Ken Martin's avatar
Ken Martin committed
255
      {
256
      (*it)->ReleaseGraphicsResources(win);
Ken Martin's avatar
Ken Martin committed
257
258
      }
    }
259
  for (vtkScalarBarActorInternal::ActorVec::size_type i = 0; i < this->P->AnnotationLabels.size(); ++ i )
260
    {
261
    this->P->AnnotationLabels[i]->ReleaseGraphicsResources(win);
262
    }
Ken Martin's avatar
Ken Martin committed
263
  this->ScalarBarActor->ReleaseGraphicsResources(win);
264
265
266
  this->P->NanSwatchActor->ReleaseGraphicsResources(win);
  this->P->AnnotationBoxesActor->ReleaseGraphicsResources(win);
  this->P->AnnotationLeadersActor->ReleaseGraphicsResources(win);
267
268
  this->BackgroundActor->ReleaseGraphicsResources(win);
  this->FrameActor->ReleaseGraphicsResources(win);
269
  this->Texture->ReleaseGraphicsResources(win);
Ken Martin's avatar
Ken Martin committed
270
271
}

272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
//----------------------------------------------------------------------------
void vtkScalarBarActor::GetScalarBarRect(int rect[4], vtkViewport* viewport)
{
  vtkCoordinate *origin = this->ScalarBarActor->GetPositionCoordinate();
  int * vpPos = origin->GetComputedViewportValue(viewport);
  rect[0] = vpPos[0];
  rect[1] = vpPos[1];

  double *bounds = this->ScalarBar->GetBounds();
  rect[0] += static_cast<int>(bounds[0] + 0.5);
  rect[1] += static_cast<int>(bounds[2] + 0.5);
  rect[2] = static_cast<int>(bounds[1] - bounds[0] + 0.5);
  rect[3] = static_cast<int>(bounds[3] - bounds[2] + 0.5);
}

Sebastien Barre's avatar
Sebastien Barre committed
287
//----------------------------------------------------------------------------
288
289
vtkScalarBarActor::~vtkScalarBarActor()
{
290
  if (this->LabelFormat)
Ken Martin's avatar
Ken Martin committed
291
292
293
294
    {
    delete [] this->LabelFormat;
    this->LabelFormat = NULL;
    }
295
296

  this->TitleActor->Delete();
297
  this->SetNanAnnotation(NULL);
298

299
300
301
  this->ScalarBar->Delete();
  this->ScalarBarMapper->Delete();
  this->ScalarBarActor->Delete();
Ken Martin's avatar
Ken Martin committed
302

303
304
305
306
307
308
309
  this->P->NanSwatch->Delete();
  this->P->NanSwatchMapper->Delete();
  this->P->NanSwatchActor->Delete();

  this->P->AnnotationBoxes->Delete();
  this->P->AnnotationBoxesMapper->Delete();
  this->P->AnnotationBoxesActor->Delete();
310

311
312
313
  this->P->AnnotationLeaders->Delete();
  this->P->AnnotationLeadersMapper->Delete();
  this->P->AnnotationLeadersActor->Delete();
314

Ken Martin's avatar
Ken Martin committed
315
316
317
318
319
  if (this->Title)
    {
    delete [] this->Title;
    this->Title = NULL;
    }
320
321
322
323
324
325

  if ( this->ComponentTitle )
    {
    delete [] this->ComponentTitle;
    this->ComponentTitle = NULL;
    }
326

327
  this->SetLookupTable(NULL);
Sebastien Barre's avatar
Sebastien Barre committed
328
329
  this->SetLabelTextProperty(NULL);
  this->SetTitleTextProperty(NULL);
330
331
332
  this->Texture->Delete();
  this->TextureActor->Delete();
  this->TexturePolyData->Delete();
333
334
335
336
337
338
339
340
  this->Background->Delete();
  this->BackgroundMapper->Delete();
  this->BackgroundActor->Delete();
  this->Frame->Delete();
  this->FrameMapper->Delete();
  this->FrameActor->Delete();
  this->SetBackgroundProperty(NULL);
  this->SetFrameProperty(NULL);
341
  delete this->P;
342
343
}

Sebastien Barre's avatar
Sebastien Barre committed
344
//----------------------------------------------------------------------------
345
int vtkScalarBarActor::RenderOverlay(vtkViewport* viewport)
Ken Martin's avatar
Ken Martin committed
346
{
347
  int renderedSomething = 0;
348

349
350
351
352
353
354
355
356
357
358
359
360
361
  // Is the viewport's RenderWindow capturing GL2PS-special props? We'll need
  // to handle this specially to get the texture to show up right.
  if (vtkRenderer *renderer = vtkRenderer::SafeDownCast(viewport))
    {
    if (vtkRenderWindow *renderWindow = renderer->GetRenderWindow())
      {
      if (renderWindow->GetCapturingGL2PSSpecialProps())
        {
        renderer->CaptureGL2PSSpecialProp(this);
        }
      }
    }

362
  // Everything is built, just have to render
363
364
365
366
  if (this->DrawBackground)
    {
    renderedSomething += this->BackgroundActor->RenderOverlay(viewport);
    }
367

368
  if (this->UseOpacity && this->DrawColorBar)
369
370
371
372
373
    {
    this->Texture->Render(vtkRenderer::SafeDownCast(viewport));
    renderedSomething += this->TextureActor->RenderOverlay(viewport);
    }

374
375
376
  // Draw either the scalar bar (non-indexed mode) or
  // the annotated value boxes (indexed mode).
  if (!this->LookupTable->GetIndexedLookup())
377
    {
378
379
    if (this->DrawColorBar)
      {
380
      renderedSomething += this->ScalarBarActor->RenderOverlay(viewport);
381
      }
382

383
    if (this->DrawTickLabels)
384
      {
385
386
387
388
389
390
391
392
      vtkScalarBarActorInternal::ActorVec::iterator it;
      for (
           it = this->P->TextActors.begin();
           it != this->P->TextActors.end();
           ++it)
        {
        renderedSomething += (*it)->RenderOverlay(viewport);
        }
393
394
      }
    }
395
  else if (this->DrawColorBar)
396
    {
397
398
399
400
401
402
403
404
405
406
407
408
409
    renderedSomething +=
      this->P->AnnotationBoxesActor->RenderOverlay(viewport);
    }

  if (this->DrawNanAnnotation)
    {
    renderedSomething +=
      this->P->NanSwatchActor->RenderOverlay(viewport);
    }

  if (this->DrawFrame)
    {
    renderedSomething += this->FrameActor->RenderOverlay(viewport);
410
    }
411

412
413
414
415
416
  if (this->Title != NULL)
    {
    renderedSomething += this->TitleActor->RenderOverlay(viewport);
    }

417
  if (this->DrawAnnotations)
418
    {
419
    if (!this->P->AnnotationLabels.empty())
420
421
422
      {
      renderedSomething +=
        this->P->AnnotationLeadersActor->RenderOverlay( viewport );
423
424
425
426
427
      for (vtkScalarBarActorInternal::ActorVec::size_type i = 0; i < this->P->AnnotationLabels.size(); ++ i )
        {
        renderedSomething +=
          this->P->AnnotationLabels[i]->RenderOverlay( viewport );
        }
David Thompson's avatar
David Thompson committed
428
      }
429
    }
430

431
  renderedSomething = (renderedSomething > 0)?(1):(0);
432
  return renderedSomething;
Ken Martin's avatar
Ken Martin committed
433
434
}

Sebastien Barre's avatar
Sebastien Barre committed
435
//----------------------------------------------------------------------------
436
int vtkScalarBarActor::RenderOpaqueGeometry(vtkViewport* viewport)
437
{
438
  int renderedSomething = 0;
439

Sebastien Barre's avatar
Sebastien Barre committed
440
  if (!this->LookupTable)
441
442
    {
    vtkWarningMacro(<<"Need a mapper to render a scalar bar");
443
    return 0;
444
445
    }

Sebastien Barre's avatar
Sebastien Barre committed
446
447
448
449
450
451
452
453
454
455
456
457
  if (!this->TitleTextProperty)
    {
    vtkErrorMacro(<<"Need title text property to render a scalar bar");
    return 0;
    }

  if (!this->LabelTextProperty)
    {
    vtkErrorMacro(<<"Need label text property to render a scalar bar");
    return 0;
    }

Ken Martin's avatar
Ken Martin committed
458
  // Check to see whether we have to rebuild everything
459
  int positionsHaveChanged = 0;
460
461
  if (viewport->GetMTime() > this->BuildTime ||
      (viewport->GetVTKWindow() &&
Sebastien Barre's avatar
Sebastien Barre committed
462
       viewport->GetVTKWindow()->GetMTime() > this->BuildTime))
Ken Martin's avatar
Ken Martin committed
463
464
465
    {
    // if the viewport has changed we may - or may not need
    // to rebuild, it depends on if the projected coords chage
466
467
    int size[2];
    int* barOrigin;
Ken Martin's avatar
Ken Martin committed
468
    barOrigin = this->PositionCoordinate->GetComputedViewportValue(viewport);
469
    size[0] =
Ken Martin's avatar
Ken Martin committed
470
471
      this->Position2Coordinate->GetComputedViewportValue(viewport)[0] -
      barOrigin[0];
472
    size[1] =
Ken Martin's avatar
Ken Martin committed
473
474
      this->Position2Coordinate->GetComputedViewportValue(viewport)[1] -
      barOrigin[1];
475

476
477
    // Check if we have bounds on the maximum size
    size[0] = size[0] > this->MaximumWidthInPixels
478
            ? this->MaximumWidthInPixels : size[0];
479
    size[1] = size[1] > this->MaximumHeightInPixels
480
481
            ? this->MaximumHeightInPixels : size[1];

482
    if (this->LastSize[0] != size[0] ||
Sebastien Barre's avatar
Sebastien Barre committed
483
        this->LastSize[1] != size[1] ||
484
        this->LastOrigin[0] != barOrigin[0] ||
485
        this->LastOrigin[1] != barOrigin[1])
Ken Martin's avatar
Ken Martin committed
486
      {
487
      positionsHaveChanged = 1;
Ken Martin's avatar
Ken Martin committed
488
489
      }
    }
490

491
  // Check to see whether we have to rebuild everything
492
  if (positionsHaveChanged ||
493
      this->GetMTime() > this->BuildTime ||
Sebastien Barre's avatar
Sebastien Barre committed
494
495
      this->LookupTable->GetMTime() > this->BuildTime ||
      this->LabelTextProperty->GetMTime() > this->BuildTime ||
496
497
498
499
      this->TitleTextProperty->GetMTime() > this->BuildTime ||
      this->BackgroundProperty->GetMTime() > this->BuildTime ||
      this->FrameProperty->GetMTime() > this->BuildTime)

500
    {
501
    this->RebuildLayout(viewport);
502
503
504
    }

  // Everything is built, just have to render
Jim Miller's avatar
Style    
Jim Miller committed
505
506
  if (this->Title != NULL)
    {
507
508
    renderedSomething +=
      this->TitleActor->RenderOpaqueGeometry(viewport);
Jim Miller's avatar
Style    
Jim Miller committed
509
    }
510
511
  // Draw either the scalar bar (non-indexed mode) or
  // the annotated value boxes (indexed mode).
512
  if ( ! this->LookupTable->GetIndexedLookup() )
Jim Miller's avatar
Style    
Jim Miller committed
513
    {
514
515
    if (this->DrawColorBar)
      {
516
517
      renderedSomething +=
        this->ScalarBarActor->RenderOpaqueGeometry(viewport);
518
      }
519
520
521
522
523
    vtkScalarBarActorInternal::ActorVec::iterator ait;
    for (
      ait = this->P->TextActors.begin();
      ait != this->P->TextActors.end();
      ++ait)
David Thompson's avatar
David Thompson committed
524
      {
525
      renderedSomething += (*ait)->RenderOpaqueGeometry(viewport);
David Thompson's avatar
David Thompson committed
526
527
528
529
      }
    }
  else
    {
530
531
    if (this->DrawColorBar)
      {
532
533
534
535
536
537
538
539
540
541
542
543
544
545
      renderedSomething +=
        this->P->AnnotationBoxesActor->RenderOpaqueGeometry( viewport );
      }
    }

  if (this->DrawNanAnnotation)
    {
    renderedSomething +=
      this->P->NanSwatchActor->RenderOpaqueGeometry(viewport);
    }

  // Draw the annotation leaders and labels
  if ( this->DrawAnnotations )
    {
546
    if (!this->P->AnnotationLabels.empty())
547
548
549
      {
      renderedSomething +=
        this->P->AnnotationLeadersActor->RenderOpaqueGeometry( viewport );
550
551
552
553
554
      for (vtkScalarBarActorInternal::ActorVec::size_type i = 0; i < this->P->AnnotationLabels.size(); ++ i )
        {
        renderedSomething +=
          this->P->AnnotationLabels[i]->RenderOpaqueGeometry( viewport );
        }
David Thompson's avatar
David Thompson committed
555
      }
Jim Miller's avatar
Style    
Jim Miller committed
556
    }
557
558
559
560

  renderedSomething = (renderedSomething > 0)?(1):(0);

  return renderedSomething;
561
562
}

563
564
565
566
//-----------------------------------------------------------------------------
// Description:
// Does this prop have some translucent polygonal geometry?
int vtkScalarBarActor::HasTranslucentPolygonalGeometry()
567
568
569
570
{ // TODO: Handle case when IndexedLookup is true and any colors in the palette
  // have an alpha value, as the color swatches drawn by
  // this->P->AnnotationBoxesActor have 1 translucent triangle for each
  // alpha-swatch.
571
572
573
  return 0;
}

Sebastien Barre's avatar
Sebastien Barre committed
574
//----------------------------------------------------------------------------
575
void vtkScalarBarActor::PrintSelf(ostream& os, vtkIndent indent)
576
{
Brad King's avatar
Brad King committed
577
  this->Superclass::PrintSelf(os,indent);
578
579
580
581
582
583
584
585
586
587
588

  if ( this->LookupTable )
    {
    os << indent << "Lookup Table:\n";
    this->LookupTable->PrintSelf(os,indent.GetNextIndent());
    }
  else
    {
    os << indent << "Lookup Table: (none)\n";
    }

Sebastien Barre's avatar
Sebastien Barre committed
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
  if (this->TitleTextProperty)
    {
    os << indent << "Title Text Property:\n";
    this->TitleTextProperty->PrintSelf(os,indent.GetNextIndent());
    }
  else
    {
    os << indent << "Title Text Property: (none)\n";
    }

  if (this->LabelTextProperty)
    {
    os << indent << "Label Text Property:\n";
    this->LabelTextProperty->PrintSelf(os,indent.GetNextIndent());
    }
  else
    {
    os << indent << "Label Text Property: (none)\n";
    }

609
  os << indent << "Title: " << (this->Title ? this->Title : "(none)") << "\n";
610
611
  os << indent << "ComponentTitle: "
    << (this->ComponentTitle ? this->ComponentTitle : "(none)") << "\n";
612
  os << indent << "Maximum Number Of Colors: "
613
614
     << this->MaximumNumberOfColors << "\n";
  os << indent << "Number Of Labels: " << this->NumberOfLabels << "\n";
615
  os << indent << "Number Of Labels Built: " << this->NumberOfLabelsBuilt << "\n";
616
617

  os << indent << "Orientation: ";
Jim Miller's avatar
Style    
Jim Miller committed
618
619
620
621
622
623
624
625
  if ( this->Orientation == VTK_ORIENT_HORIZONTAL )
    {
    os << "Horizontal\n";
    }
  else
    {
    os << "Vertical\n";
    }
626
627

  os << indent << "Label Format: " << this->LabelFormat << "\n";
628
629
630
631
  os << indent << "UseOpacity: " << this->UseOpacity << "\n";
  if (this->UseOpacity)
    {
    os << indent << "TextureGridWidth: " << this->TextureGridWidth << "\n";
Karthik Krishnan's avatar
Karthik Krishnan committed
632
633
    os << indent << "TextureActor:\n";
    this->TextureActor->PrintSelf(os, indent.GetNextIndent());
634
    }
635
636
637
638
639
640
641
642
  if (this->TextPosition == vtkScalarBarActor::PrecedeScalarBar)
    {
    os << indent << "TextPosition: PrecedeScalarBar\n";
    }
  else
    {
    os << indent << "TextPosition: SucceedScalarBar\n";
    }
Karthik Krishnan's avatar
Karthik Krishnan committed
643

644
  os << indent << "MaximumWidthInPixels: "
Karthik Krishnan's avatar
Karthik Krishnan committed
645
     << this->MaximumWidthInPixels << endl;
646
  os << indent << "MaximumHeightInPixels: "
Karthik Krishnan's avatar
Karthik Krishnan committed
647
     << this->MaximumHeightInPixels << endl;
648

David Thompson's avatar
David Thompson committed
649
650
  os << indent << "DrawAnnotations: "
    << this->DrawAnnotations << endl;
651
652
653
654
  os << indent << "DrawNanAnnotation: "
    << this->DrawNanAnnotation << endl;
  os << indent << "NanAnnotation: "
    << (this->NanAnnotation ? this->NanAnnotation : "(none)") << endl;
David Thompson's avatar
David Thompson committed
655
656
  os << indent << "AnnotationLeaderPadding: "
    << this->AnnotationLeaderPadding << endl;
657
658
  os << indent << "AnnotationTextScaling: "
    << this->AnnotationTextScaling << endl;
David Thompson's avatar
David Thompson committed
659

660
661
662
663
664
665
  os << indent << "DrawBackground: " << this->DrawBackground << "\n";
  os << indent << "Background Property:\n";
  this->BackgroundProperty->PrintSelf(os,indent.GetNextIndent());
  os << indent << "DrawFrame: " << this->DrawFrame << "\n";
  os << indent << "Frame Property:\n";
  this->FrameProperty->PrintSelf(os,indent.GetNextIndent());
666
}
Ken Martin's avatar
Ken Martin committed
667

Sebastien Barre's avatar
Sebastien Barre committed
668
//----------------------------------------------------------------------------
669
void vtkScalarBarActor::ShallowCopy(vtkProp* prop)
Will Schroeder's avatar
Will Schroeder committed
670
{
671
  vtkScalarBarActor* a = vtkScalarBarActor::SafeDownCast(prop);
Will Schroeder's avatar
Will Schroeder committed
672
673
674
675
676
677
  if ( a != NULL )
    {
    this->SetPosition2(a->GetPosition2());
    this->SetLookupTable(a->GetLookupTable());
    this->SetMaximumNumberOfColors(a->GetMaximumNumberOfColors());
    this->SetOrientation(a->GetOrientation());
Sebastien Barre's avatar
Sebastien Barre committed
678
679
    this->SetLabelTextProperty(a->GetLabelTextProperty());
    this->SetTitleTextProperty(a->GetTitleTextProperty());
Will Schroeder's avatar
Will Schroeder committed
680
681
682
    this->SetLabelFormat(a->GetLabelFormat());
    this->SetTitle(a->GetTitle());
    this->GetPositionCoordinate()->SetCoordinateSystem(
683
      a->GetPositionCoordinate()->GetCoordinateSystem());
Will Schroeder's avatar
Will Schroeder committed
684
685
686
    this->GetPositionCoordinate()->SetValue(
      a->GetPositionCoordinate()->GetValue());
    this->GetPosition2Coordinate()->SetCoordinateSystem(
687
      a->GetPosition2Coordinate()->GetCoordinateSystem());
Will Schroeder's avatar
Will Schroeder committed
688
689
    this->GetPosition2Coordinate()->SetValue(
      a->GetPosition2Coordinate()->GetValue());
690
691
692
693
    this->SetDrawBackground(a->GetDrawBackground());
    this->SetBackgroundProperty(a->GetBackgroundProperty());
    this->SetDrawFrame(a->GetDrawFrame());
    this->SetFrameProperty(a->GetFrameProperty());
Will Schroeder's avatar
Will Schroeder committed
694
695
696
697
698
    }

  // Now do superclass
  this->vtkActor2D::ShallowCopy(prop);
}
Ken Martin's avatar
Ken Martin committed
699

Sebastien Barre's avatar
Sebastien Barre committed
700
//----------------------------------------------------------------------------
701
void vtkScalarBarActor::RebuildLayout(vtkViewport* viewport)
Ken Martin's avatar
Ken Martin committed
702
{
703
  vtkDebugMacro(<<"Rebuilding subobjects");
Sebastien Barre's avatar
Sebastien Barre committed
704

705
706
  this->P->Viewport = viewport;
  this->FreeLayoutStorage();
Sebastien Barre's avatar
Sebastien Barre committed
707

708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
  // Permute indices used to measure width and height
  // so that thickness and length according to the orientation
  // of the scalar bar instead.
  if (this->Orientation == VTK_ORIENT_VERTICAL)
    {
    this->P->TL[0] = 0;
    this->P->TL[1] = 1;
    }
  else
    {
    this->P->TL[0] = 1;
    this->P->TL[1] = 0;
    }
  this->P->NumNotes = this->LookupTable->GetNumberOfAnnotatedValues();

  // Warning: The order of these calls is extremely important
  // as each updates members of this->P used by later methods!
  this->ComputeFrame();
  this->ComputeScalarBarThickness();
  this->LayoutNanSwatch();
  this->PrepareTitleText();
  this->LayoutTitle();
  this->ComputeScalarBarLength();
  this->LayoutTicks();
  this->LayoutAnnotations();

  // Now generate/configure the VTK datasets and actors that
  // illustrate the scalar bar when rendered using the
  // layout computed above.
  this->ConfigureAnnotations();
  this->ConfigureFrame();
  this->ConfigureScalarBar();
  this->ConfigureTitle();
  this->ConfigureTicks();
  this->ConfigureNanSwatch();
743
744
745
#ifdef VTK_DBG_LAYOUT
  this->DrawBoxes();
#endif // VTK_DBG_LAYOUT
746
  this->BuildTime.Modified();
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
}

namespace {

void AddBox(vtkPoints* pts, vtkCellArray* lines, vtkScalarBarBox& box, int tl[2])
{
  vtkIdType pid[5];

  pid[0] = pts->InsertNextPoint(box.Posn[0], box.Posn[1], 0.);
  pid[1] = pts->InsertNextPoint(box.Posn[0] + box.Size[tl[0]], box.Posn[1], 0.);
  pid[2] = pts->InsertNextPoint(box.Posn[0] + box.Size[tl[0]], box.Posn[1] + box.Size[tl[1]], 0.);
  pid[3] = pts->InsertNextPoint(box.Posn[0], box.Posn[1] + box.Size[tl[1]], 0.);

  pid[4] = pid[0];
  for (int i = 0; i < 4; ++i)
    {
    lines->InsertNextCell(2, pid + i);
    }
}

}

void vtkScalarBarActor::DrawBoxes()
{
  vtkPoints* pts = this->Frame->GetPoints();
  vtkCellArray* lines = this->Frame->GetLines();

  AddBox(pts, lines, this->P->ScalarBarBox, this->P->TL);
  AddBox(pts, lines, this->P->NanBox, this->P->TL);
  AddBox(pts, lines, this->P->TitleBox, this->P->TL);
  if (this->NumberOfLabels > 0)
    {
    AddBox(pts, lines, this->P->TickBox, this->P->TL);
    }
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
}

//----------------------------------------------------------------------------
void vtkScalarBarActor::ComputeFrame()
{
  // get the viewport size in display coordinates
  int* p0;
  int* p1;
  int size[2];
  p0 = this->PositionCoordinate->GetComputedViewportValue(this->P->Viewport);
  p1 = this->Position2Coordinate->GetComputedViewportValue(this->P->Viewport);
  for (int i = 0; i < 2; ++i)
    {
    //this->P->Frame.Posn[i] = p0[i];
    this->P->Frame.Posn[i] = 0; // Translate the frame's coordinate system to p0
    size[i] = p1[i] - p0[i];
    }

  // Check if we have bounds on the maximum size
  size[0] = size[0] > this->MaximumWidthInPixels
          ? this->MaximumWidthInPixels : size[0];
  size[1] = size[1] > this->MaximumHeightInPixels
          ? this->MaximumHeightInPixels : size[1];

  for (int i = 0; i < 2; ++i)
    {
    this->P->Frame.Size[i] = size[this->P->TL[i]];
    }

  this->LastOrigin[0] = p0[0];
  this->LastOrigin[1] = p0[1];
  this->LastSize[0] = size[0];
  this->LastSize[1] = size[1];
}

//----------------------------------------------------------------------------
void vtkScalarBarActor::ComputeScalarBarThickness()
{
  // We do not set Size[1] (length), since the title bounds may encroach
  // on it in the vertical orientation.
  this->P->ScalarBarBox.Size[0] =
822
    static_cast<int>(ceil(this->P->Frame.Size[0] * this->BarRatio));
823
824
825
826
827
828
829
830
831
832
833
834
835
836

  // The lower-left corner of the scalar bar may be estimated here
  // as identical to the Frame position in one or both coordinates,
  // depending on whether tick marks should precede the scalar bar or
  // not and on the orientation.
  //
  // It will be altered later in this->LayoutTicks to account
  // for the half-height/width of tick labels.
  this->P->ScalarBarBox.Posn = this->P->Frame.Posn;
  if (this->TextPosition == PrecedeScalarBar)
    {
    this->P->ScalarBarBox.Posn[this->P->TL[0]] +=
      this->P->Frame.Size[0] - this->P->ScalarBarBox.Size[0];
    }
837
838

  // Now knock the thickness down and nudge the bar so the bar doesn't hug the frame.
839
840
841
842
843
  double nudge = this->P->ScalarBarBox.Size[0] / 8.;
  if (nudge > this->TextPad)
    {
    nudge = this->TextPad;
    }
844
  this->P->ScalarBarBox.Size[0] -= nudge;
845
846
  this->P->ScalarBarBox.Posn[this->P->TL[0]] += nudge *
    (this->TextPosition == PrecedeScalarBar ? -1 : +1);
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
}

//----------------------------------------------------------------------------
void vtkScalarBarActor::LayoutNanSwatch()
{
  // We don't have ScalarBarBox.Size[1] set yet; use the frame width instead.
  this->P->NanSwatchSize = static_cast<double>(
    this->P->ScalarBarBox.Size[0] > this->P->Frame.Size[1] / 4 ?
    this->P->Frame.Size[1] / 4 : this->P->ScalarBarBox.Size[0]);
  if (this->P->NanSwatchSize < 4 && this->P->Frame.Size[1] > 16)
    this->P->NanSwatchSize = 4;
  if (!this->DrawNanAnnotation)
    this->P->NanSwatchSize = 0;
  if (this->P->NumNotes)
    {
    this->P->SwatchPad = this->P->Frame.Size[1] / this->P->NumNotes > 16. ?
      4. : ( this->P->Frame.Size[1] / this->P->NumNotes / 4. );
    }
  else
    {
    this->P->SwatchPad = 4.;
    }

  if (this->Orientation == VTK_ORIENT_VERTICAL)
    {
    this->P->NanBox.Posn[0] = this->P->ScalarBarBox.Posn[0];
873
    this->P->NanBox.Posn[1] = this->P->Frame.Posn[1] + this->TextPad;
874
875
876
877
878
879
880
881
882
883
884
    this->P->ScalarBarBox.Posn[1] +=
      this->P->NanSwatchSize + this->P->SwatchPad;
    }
  else // HORIZONTAL
    {
    this->P->NanBox.Posn = this->P->ScalarBarBox.Posn;
    this->P->NanBox.Posn[this->P->TL[1]] +=
      this->P->Frame.Size[1] - this->P->NanSwatchSize;
    }
  this->P->NanBox.Size[0] = this->P->ScalarBarBox.Size[0];
  this->P->NanBox.Size[1] = this->P->NanSwatchSize;
885
886
887
888
  if (this->P->NanBox.Size[1] > 2 * this->TextPad)
    {
    this->P->NanBox.Size[1] -= this->TextPad;
    }
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
}

//----------------------------------------------------------------------------
void vtkScalarBarActor::PrepareTitleText()
{
  // Update actor with the latest title/subtitle
  if (this->ComponentTitle && strlen(this->ComponentTitle) > 0)
    {
    //need to account for a space between title & component and null term
    char* combinedTitle =
      new char[strlen(this->Title) + strlen(this->ComponentTitle) + 2];
    strcpy(combinedTitle, this->Title );
    strcat(combinedTitle, " ");
    strcat(combinedTitle, this->ComponentTitle);
    this->TitleActor->SetInput(combinedTitle);
    delete [] combinedTitle;
    }
  else
    {
    this->TitleActor->SetInput(this->Title);
    }

  if (this->TitleTextProperty->GetMTime() > this->BuildTime)
    {
    // Shallow copy here so that the size of the title prop is not affected
    // by the automatic adjustment of its text mapper's size (i.e. its
    // mapper's text property is identical except for the font size
    // which will be modified later). This allows text actors to
    // share the same text property, and in that case specifically allows
    // the title and label text prop to be the same.
    this->TitleActor->GetTextProperty()->ShallowCopy(this->TitleTextProperty);
    this->TitleActor->GetTextProperty()->SetJustificationToCentered();
    this->TitleActor->GetTextProperty()->SetVerticalJustification(
      this->TextPosition == PrecedeScalarBar ? VTK_TEXT_BOTTOM : VTK_TEXT_TOP);
    }
}

//----------------------------------------------------------------------------
void vtkScalarBarActor::LayoutTitle()
{
  if (this->Title == NULL || !strlen(this->Title))
    {
    return;
    }

  int targetWidth, targetHeight;
  // Title spans entire width of frame at top, regardless of orientation.
936
  targetWidth = static_cast<int>(this->P->Frame.Size[this->P->TL[0]]) - 2 * this->TextPad;
937
938
939
940
941
942
943
944
945
  // Height is either: at most half the frame height or
  // a fixed portion of the frame remaining after subtracting the
  // scalar bar's thickness.
  //
  // When laid out horizontally, ticks share vertical space with title.
  // We want the title to be larger (18pt vs 14pt).
  targetHeight = static_cast<int>((
    this->Orientation == VTK_ORIENT_VERTICAL ||
    this->LookupTable->GetIndexedLookup()) ?
946
947
948
949
950
    ceil(this->P->Frame.Size[this->P->TL[1]] / 2. - this->TextPad) :
    (this->P->Frame.Size[0] - this->P->ScalarBarBox.Size[0] -
     (this->TextPosition == SucceedScalarBar ?
     this->P->ScalarBarBox.Posn[this->P->TL[0]] : 0) - this->TextPad) *
     this->TitleRatio);
951
952
953
954
955
956
957
958

  this->TitleActor->SetConstrainedFontSize(
    this->P->Viewport, targetWidth, targetHeight);

  // Now fetch the actual size from the actor and use it to
  // update the box size and position.
  double titleSize[2] = {0, 0};
  this->TitleActor->GetSize(this->P->Viewport, titleSize);
959
  this->TitleActor->GetTextProperty()->SetVerticalJustificationToTop();
960
961
962
963
964
  for (int i = 0; i < 2; ++i)
    {
    this->P->TitleBox.Size[this->P->TL[i]] =
      static_cast<int>(ceil(titleSize[i]));
    }
Sebastien Barre's avatar
Sebastien Barre committed
965

966
967
968
969
970
971
972
973
974
  this->P->TitleBox.Posn[0] =
    this->P->Frame.Posn[0] +
    (this->P->Frame.Size[this->P->TL[0]] - titleSize[0]) / 2;
  this->P->TitleBox.Posn[1] =
    this->P->Frame.Posn[1] + this->P->Frame.Size[this->P->TL[1]];
  if (
    this->Orientation == VTK_ORIENT_VERTICAL ||
    this->TextPosition == vtkScalarBarActor::SucceedScalarBar)
    {
975
    this->P->TitleBox.Posn[1] -= this->P->TitleBox.Size[this->P->TL[1]] + this->TextPad;
976
977
978
    }
  else
    {
979
    this->P->TitleBox.Posn[1] = this->P->Frame.Posn[1] + this->TextPad;
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
    }
}

//-----------------------------------------------------------------------------
void vtkScalarBarActor::ComputeScalarBarLength()
{
  this->P->ScalarBarBox.Size[1] =
    this->Orientation == VTK_ORIENT_VERTICAL ?
      this->P->Frame.Size[1] - this->P->TitleBox.Size[1] :
      this->P->Frame.Size[1];

  // The scalar bar does not include the Nan Swatch.
  this->P->ScalarBarBox.Size[1] -= this->P->NanSwatchSize + this->P->SwatchPad;
}

//-----------------------------------------------------------------------------
void vtkScalarBarActor::LayoutTicks()
{
  if (this->LookupTable->GetIndexedLookup())
    { // no tick marks in indexed lookup mode.
    this->NumberOfLabelsBuilt = 0;
    return;
    }
1003

1004
1005
1006
  // find the best size for the ticks
  double* range = this->LookupTable->GetRange();
  char string[512];
Ken Martin's avatar
Ken Martin committed
1007
  double val;
Ken Martin's avatar
Ken Martin committed
1008
  int i;
1009

Sebastien Barre's avatar
Sebastien Barre committed
1010
1011
1012
1013
1014
  // TODO: this should be optimized, maybe by keeping a list of
  // allocated mappers, in order to avoid creation/destruction of
  // their underlying text properties (i.e. each time a mapper is
  // created, text properties are created and shallow-assigned a font size
  // which value might be "far" from the target font size).
1015
  this->P->TextActors.resize(this->NumberOfLabels);
1016

1017
  // Does this map have its scale set to log?
1018
  int isLogTable = this->LookupTable->UsingLogScale();
1019

1020
  for (i = 0; i < this->NumberOfLabels; i++)
Ken Martin's avatar
Ken Martin committed
1021
    {
1022
    this->P->TextActors[i].TakeReference(vtkTextActor::New());
Sebastien Barre's avatar
Sebastien Barre committed
1023

1024
1025
    if ( isLogTable )
      {
Ken Martin's avatar
Ken Martin committed
1026
      double lval;
Ken Martin's avatar
Ken Martin committed
1027
1028
      if (this->NumberOfLabels > 1)
        {
1029
1030
        lval = log10(range[0]) +
          static_cast<double>(i)/(this->NumberOfLabels-1) *
Ken Martin's avatar
Ken Martin committed
1031
1032
1033
1034
1035
1036
          (log10(range[1])-log10(range[0]));
        }
      else
        {
        lval = log10(range[0]) + 0.5*(log10(range[1])-log10(range[0]));
        }
Ken Martin's avatar
Ken Martin committed
1037
      val = pow(10.0,lval);
1038
1039
1040
      }
    else
      {
Ken Martin's avatar
Ken Martin committed
1041
1042
      if (this->NumberOfLabels > 1)
        {
1043
        val = range[0] +
1044
          static_cast<double>(i)/(this->NumberOfLabels-1)
1045
          * (range[1]-range[0]);
Ken Martin's avatar
Ken Martin committed
1046
1047
1048
1049
1050
        }
      else
        {
        val = range[0] + 0.5*(range[1]-range[0]);
        }
1051
1052
      }

1053
1054
    SNPRINTF(string, 511, this->LabelFormat, val);
    this->P->TextActors[i]->SetInput(string);
Sebastien Barre's avatar
Sebastien Barre committed
1055
1056
1057
1058
1059
1060
1061

    // Shallow copy here so that the size of the label prop is not affected
    // by the automatic adjustment of its text mapper's size (i.e. its
    // mapper's text property is identical except for the font size
    // which will be modified later). This allows text actors to
    // share the same text property, and in that case specifically allows
    // the title and label text prop to be the same.
1062
    this->P->TextActors[i]->GetTextProperty()->ShallowCopy(
Sebastien Barre's avatar
Sebastien Barre committed
1063
1064
      this->LabelTextProperty);

1065
1066
    this->P->TextActors[i]->SetProperty(this->GetProperty());
    this->P->TextActors[i]->GetPositionCoordinate()->
Ken Martin's avatar
Ken Martin committed
1067
1068
      SetReferenceCoordinate(this->PositionCoordinate);
    }
Sebastien Barre's avatar
Sebastien Barre committed
1069

Ken Martin's avatar
Ken Martin committed
1070
1071
  if (this->NumberOfLabels)
    {
1072
1073
    int labelSize[2];
    labelSize[0] = labelSize[1] = 0;
Sebastien Barre's avatar
Sebastien Barre committed
1074
1075
    int targetWidth, targetHeight;

1076
1077
1078
1079
1080
    this->P->TickBox.Posn = this->P->ScalarBarBox.Posn;
    if ( this->Orientation == VTK_ORIENT_VERTICAL )
      { // NB. Size[0] = width, Size[1] = height
      // Ticks share the width with the scalar bar
      this->P->TickBox.Size[0] =
1081
1082
        this->P->Frame.Size[0] - this->P->ScalarBarBox.Size[0] -
        this->TextPad * 3;
1083
1084
1085
      // Tick height could be adjusted if title text is
      // lowered by box constraints, but we won't bother:
      this->P->TickBox.Size[1] = this->P->Frame.Size[1] -
1086
        this->P->TitleBox.Size[1] - 3 * this->TextPad;
1087
1088
1089
1090
1091
1092
1093
1094
1095
      // Tick box height also reduced by NaN swatch size, if present:
      if (this->DrawNanAnnotation)
        {
        this->P->TickBox.Size[1] -=
          this->P->NanBox.Size[1] + this->P->SwatchPad;
        }

      if (this->TextPosition == vtkScalarBarActor::PrecedeScalarBar)
        {
1096
        this->P->TickBox.Posn[0] = this->TextPad;
1097
1098
1099
        }
      else
        {
1100
        this->P->TickBox.Posn[0] += this->P->ScalarBarBox.Size[0] + 2 * this->TextPad;
1101
1102
1103
1104
        }

      targetWidth = this->P->TickBox.Size[0];
      targetHeight = static_cast<int>((this->P->TickBox.Size[1] -
1105
          this->TextPad * (this->NumberOfLabels - 1)) /
1106
1107
1108
1109
1110
1111
1112
1113
1114
        this->NumberOfLabels);
      }
    else
      { // NB. Size[1] = width, Size[0] = height
      // Ticks span the entire width of the frame
      this->P->TickBox.Size[1] = this->P->ScalarBarBox.Size[1];
      // Ticks share vertical space with title and scalar bar.
      this->P->TickBox.Size[0] =
        this->P->Frame.Size[0] - this->P->ScalarBarBox.Size[0] -
1115
        4 * this->TextPad - this->P->TitleBox.Size[0];
1116
1117
1118

      if (this->TextPosition == vtkScalarBarActor::PrecedeScalarBar)
        {
1119
1120
        this->P->TickBox.Posn[1] =
          this->P->TitleBox.Size[0] + 2 * this->TextPad;
1121
1122
        /* or equivalently: Posn[1] -=
          this->P->Frame.Size[0] -
1123
          this->P->TitleBox.Size[0] - this->TextPad -
1124
1125
1126
1127
1128
1129
1130
1131
1132
          this->P->ScalarBarBox.Size[0];
          */
        }
      else
        {
        this->P->TickBox.Posn[1] += this->P->ScalarBarBox.Size[0];
        }

      targetWidth = static_cast<int>((this->P->TickBox.Size[1] -
1133
          this->TextPad * (this->NumberOfLabels - 1)) /
1134
1135
1136
1137
1138
1139