vtkScalarBarActor.cxx 73.9 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
21
22
23
24
#include "vtkColor.h"
#include "vtkFloatArray.h"
#include "vtkPointData.h"
#include "vtkImageData.h"
#include "vtkMath.h"
25
#include "vtkObjectFactory.h"
26
#include "vtkPolyData.h"
27
#include "vtkPolyDataMapper2D.h"
28
29
#include "vtkProperty2D.h"
#include "vtkRenderer.h"
30
#include "vtkScalarsToColors.h"
31
32
#include "vtkSmartPointer.h"
#include "vtkTextActor.h"
Sebastien Barre's avatar
Sebastien Barre committed
33
#include "vtkTextProperty.h"
34
#include "vtkTexture.h"
35
36
#include "vtkViewport.h"
#include "vtkWindow.h"
37
#include "vtkMathTextUtilities.h"
38

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

#include <stdio.h> // for snprintf

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

51
52
#undef VTK_DBG_LAYOUT

Brad King's avatar
Brad King committed
53
vtkStandardNewMacro(vtkScalarBarActor);
54

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

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

71
72
  this->PositionCoordinate->SetCoordinateSystemToNormalizedViewport();
  this->PositionCoordinate->SetValue(0.82,0.1);
73

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

Sebastien Barre's avatar
Sebastien Barre committed
84
85
86
87
88
89
90
91
92
93
  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);

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

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

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

David Thompson's avatar
David Thompson committed
113
  this->DrawAnnotations = 1;
114
115
116
117
118
119
120
121
122
123
124
125
  this->DrawNanAnnotation = 0;
  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
126
  this->AnnotationLeaderPadding = 8.;
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
  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);
  this->P->AnnotationLabels = 0; // Can't allocate until we have a lookup table.
  this->P->AnnotationAnchors = 0; // Can't allocate until we have a lookup table.
  this->P->AnnotationColors = 0; // Can't allocate until we have a lookup table.
  this->P->NumberOfAnnotationLabelsBuilt = 0;
145

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

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

151
  this->TexturePolyData = vtkPolyData::New();
152
  vtkPolyDataMapper2D* textureMapper = vtkPolyDataMapper2D::New();
153
  textureMapper->SetInputData(this->TexturePolyData);
154
155
156
157
158
159
160
161
  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);
162
  tc->InsertComponent(0,0, 0.0);
163
164
  tc->InsertComponent(0,1, 0.0);
  tc->InsertComponent(1,1, 0.0);
165
  tc->InsertComponent(3,0, 0.0);
166
167
168
169
170
171
172
173
174
175
176
177
  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();

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

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

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

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

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

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

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

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

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

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

  this->DrawColorBar = 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
  if ( this->P->AnnotationLabels != NULL )
260
    {
261
    for ( int i = 0; i < this->P->NumberOfAnnotationLabelsBuilt; ++ i )
262
      {
263
      this->P->AnnotationLabels[i]->ReleaseGraphicsResources(win);
264
265
      }
    }
Ken Martin's avatar
Ken Martin committed
266
  this->ScalarBarActor->ReleaseGraphicsResources(win);
267
268
269
  this->P->NanSwatchActor->ReleaseGraphicsResources(win);
  this->P->AnnotationBoxesActor->ReleaseGraphicsResources(win);
  this->P->AnnotationLeadersActor->ReleaseGraphicsResources(win);
270
271
  this->BackgroundActor->ReleaseGraphicsResources(win);
  this->FrameActor->ReleaseGraphicsResources(win);
Ken Martin's avatar
Ken Martin committed
272
273
}

Sebastien Barre's avatar
Sebastien Barre committed
274
//----------------------------------------------------------------------------
275
276
vtkScalarBarActor::~vtkScalarBarActor()
{
277
  if (this->LabelFormat)
Ken Martin's avatar
Ken Martin committed
278
279
280
281
    {
    delete [] this->LabelFormat;
    this->LabelFormat = NULL;
    }
282
283

  this->TitleActor->Delete();
284
  if (this->P->AnnotationLabels != NULL)
285
    {
286
    for (int i = 0; i < this->P->NumberOfAnnotationLabelsBuilt; ++i)
287
      {
288
      this->P->AnnotationLabels[i]->Delete();
289
      }
290
    delete [] this->P->AnnotationLabels;
291
    }
292
  if (this->P->AnnotationAnchors != NULL)
293
    {
294
    delete [] this->P->AnnotationAnchors;
295
    }
296
297
298
299
300
  if (this->P->AnnotationColors != NULL)
    {
    delete [] this->P->AnnotationColors;
    }
  this->SetNanAnnotation(NULL);
301

302
303
304
  this->ScalarBar->Delete();
  this->ScalarBarMapper->Delete();
  this->ScalarBarActor->Delete();
Ken Martin's avatar
Ken Martin committed
305

306
307
308
309
310
311
312
  this->P->NanSwatch->Delete();
  this->P->NanSwatchMapper->Delete();
  this->P->NanSwatchActor->Delete();

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

314
315
316
  this->P->AnnotationLeaders->Delete();
  this->P->AnnotationLeadersMapper->Delete();
  this->P->AnnotationLeadersActor->Delete();
317

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

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

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

Sebastien Barre's avatar
Sebastien Barre committed
347
//----------------------------------------------------------------------------
348
int vtkScalarBarActor::RenderOverlay(vtkViewport* viewport)
Ken Martin's avatar
Ken Martin committed
349
{
350
  int renderedSomething = 0;
Ken Martin's avatar
Ken Martin committed
351
  int i;
352

353
  // Everything is built, just have to render
354
355
356
357
  if (this->DrawBackground)
    {
    renderedSomething += this->BackgroundActor->RenderOverlay(viewport);
    }
358

359
  if (this->UseOpacity && this->DrawColorBar)
360
361
362
363
364
    {
    this->Texture->Render(vtkRenderer::SafeDownCast(viewport));
    renderedSomething += this->TextureActor->RenderOverlay(viewport);
    }

365
366
367
  // Draw either the scalar bar (non-indexed mode) or
  // the annotated value boxes (indexed mode).
  if (!this->LookupTable->GetIndexedLookup())
368
    {
369
370
    if (this->DrawColorBar)
      {
371
      renderedSomething += this->ScalarBarActor->RenderOverlay(viewport);
372
      }
373

374
375
376
377
378
    vtkScalarBarActorInternal::ActorVec::iterator it;
    for (
      it = this->P->TextActors.begin();
      it != this->P->TextActors.end();
      ++it)
379
      {
380
      renderedSomething += (*it)->RenderOverlay(viewport);
381
382
      }
    }
383
  else if (this->DrawColorBar)
384
    {
385
386
387
388
389
390
391
392
393
394
395
396
397
    renderedSomething +=
      this->P->AnnotationBoxesActor->RenderOverlay(viewport);
    }

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

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

400
401
402
403
404
405
406
  if (this->Title != NULL)
    {
    renderedSomething += this->TitleActor->RenderOverlay(viewport);
    }

  if (this->P->AnnotationLabels == NULL &&
    this->P->NumberOfAnnotationLabelsBuilt)
Ken Martin's avatar
Ken Martin committed
407
    {
408
409
    vtkWarningMacro(<<"Need a mapper to render the scalar bar");
    return renderedSomething;
Ken Martin's avatar
Ken Martin committed
410
    }
411

David Thompson's avatar
David Thompson committed
412
  if ( this->DrawAnnotations )
413
    {
414
415
416
417
418
419
    if ( this->P->NumberOfAnnotationLabelsBuilt )
      {
      renderedSomething +=
        this->P->AnnotationLeadersActor->RenderOverlay( viewport );
      }
    for ( i = 0; i < this->P->NumberOfAnnotationLabelsBuilt; ++ i )
David Thompson's avatar
David Thompson committed
420
      {
421
422
      renderedSomething +=
        this->P->AnnotationLabels[i]->RenderOverlay( viewport );
David Thompson's avatar
David Thompson committed
423
      }
424
    }
425

426
  renderedSomething = (renderedSomething > 0)?(1):(0);
427
  return renderedSomething;
Ken Martin's avatar
Ken Martin committed
428
429
}

Sebastien Barre's avatar
Sebastien Barre committed
430
//----------------------------------------------------------------------------
431
int vtkScalarBarActor::RenderOpaqueGeometry(vtkViewport* viewport)
432
{
433
  int renderedSomething = 0;
434
  int i;
435

Sebastien Barre's avatar
Sebastien Barre committed
436
  if (!this->LookupTable)
437
438
    {
    vtkWarningMacro(<<"Need a mapper to render a scalar bar");
439
    return 0;
440
441
    }

Sebastien Barre's avatar
Sebastien Barre committed
442
443
444
445
446
447
448
449
450
451
452
453
  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
454
  // Check to see whether we have to rebuild everything
455
  int positionsHaveChanged = 0;
456
457
  if (viewport->GetMTime() > this->BuildTime ||
      (viewport->GetVTKWindow() &&
Sebastien Barre's avatar
Sebastien Barre committed
458
       viewport->GetVTKWindow()->GetMTime() > this->BuildTime))
Ken Martin's avatar
Ken Martin committed
459
460
461
    {
    // if the viewport has changed we may - or may not need
    // to rebuild, it depends on if the projected coords chage
462
463
    int size[2];
    int* barOrigin;
Ken Martin's avatar
Ken Martin committed
464
    barOrigin = this->PositionCoordinate->GetComputedViewportValue(viewport);
465
    size[0] =
Ken Martin's avatar
Ken Martin committed
466
467
      this->Position2Coordinate->GetComputedViewportValue(viewport)[0] -
      barOrigin[0];
468
    size[1] =
Ken Martin's avatar
Ken Martin committed
469
470
      this->Position2Coordinate->GetComputedViewportValue(viewport)[1] -
      barOrigin[1];
471

472
473
    // Check if we have bounds on the maximum size
    size[0] = size[0] > this->MaximumWidthInPixels
474
            ? this->MaximumWidthInPixels : size[0];
475
    size[1] = size[1] > this->MaximumHeightInPixels
476
477
            ? this->MaximumHeightInPixels : size[1];

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

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

496
    {
497
    this->RebuildLayout(viewport);
498
499
500
    }

  // Everything is built, just have to render
Jim Miller's avatar
Style    
Jim Miller committed
501
502
  if (this->Title != NULL)
    {
503
504
    renderedSomething +=
      this->TitleActor->RenderOpaqueGeometry(viewport);
Jim Miller's avatar
Style    
Jim Miller committed
505
    }
506
507
  // Draw either the scalar bar (non-indexed mode) or
  // the annotated value boxes (indexed mode).
508
  if ( ! this->LookupTable->GetIndexedLookup() )
Jim Miller's avatar
Style    
Jim Miller committed
509
    {
510
511
    if (this->DrawColorBar)
      {
512
513
      renderedSomething +=
        this->ScalarBarActor->RenderOpaqueGeometry(viewport);
514
      }
515
516
517
518
519
    vtkScalarBarActorInternal::ActorVec::iterator ait;
    for (
      ait = this->P->TextActors.begin();
      ait != this->P->TextActors.end();
      ++ait)
David Thompson's avatar
David Thompson committed
520
      {
521
      renderedSomething += (*ait)->RenderOpaqueGeometry(viewport);
David Thompson's avatar
David Thompson committed
522
523
524
525
      }
    }
  else
    {
526
527
    if (this->DrawColorBar)
      {
528
529
530
531
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 )
    {
    if ( this->P->NumberOfAnnotationLabelsBuilt )
      {
      renderedSomething +=
        this->P->AnnotationLeadersActor->RenderOpaqueGeometry( viewport );
546
      }
547
    for ( i = 0; i < this->P->NumberOfAnnotationLabelsBuilt; ++ i )
David Thompson's avatar
David Thompson committed
548
      {
549
550
      renderedSomething +=
        this->P->AnnotationLabels[i]->RenderOpaqueGeometry( viewport );
David Thompson's avatar
David Thompson committed
551
      }
Jim Miller's avatar
Style    
Jim Miller committed
552
    }
553
554
555
556

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

  return renderedSomething;
557
558
}

559
560
561
562
//-----------------------------------------------------------------------------
// Description:
// Does this prop have some translucent polygonal geometry?
int vtkScalarBarActor::HasTranslucentPolygonalGeometry()
563
564
565
566
{ // 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.
567
568
569
  return 0;
}

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

  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
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
  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";
    }

605
  os << indent << "Title: " << (this->Title ? this->Title : "(none)") << "\n";
606
607
  os << indent << "ComponentTitle: "
    << (this->ComponentTitle ? this->ComponentTitle : "(none)") << "\n";
608
  os << indent << "Maximum Number Of Colors: "
609
610
     << this->MaximumNumberOfColors << "\n";
  os << indent << "Number Of Labels: " << this->NumberOfLabels << "\n";
611
  os << indent << "Number Of Labels Built: " << this->NumberOfLabelsBuilt << "\n";
612
613

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

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

640
  os << indent << "MaximumWidthInPixels: "
Karthik Krishnan's avatar
Karthik Krishnan committed
641
     << this->MaximumWidthInPixels << endl;
642
  os << indent << "MaximumHeightInPixels: "
Karthik Krishnan's avatar
Karthik Krishnan committed
643
     << this->MaximumHeightInPixels << endl;
644

David Thompson's avatar
David Thompson committed
645
646
  os << indent << "DrawAnnotations: "
    << this->DrawAnnotations << endl;
647
648
649
650
  os << indent << "DrawNanAnnotation: "
    << this->DrawNanAnnotation << endl;
  os << indent << "NanAnnotation: "
    << (this->NanAnnotation ? this->NanAnnotation : "(none)") << endl;
David Thompson's avatar
David Thompson committed
651
652
653
  os << indent << "AnnotationLeaderPadding: "
    << this->AnnotationLeaderPadding << endl;

654
655
656
657
658
659
  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());
660
}
Ken Martin's avatar
Ken Martin committed
661

Sebastien Barre's avatar
Sebastien Barre committed
662
//----------------------------------------------------------------------------
663
void vtkScalarBarActor::ShallowCopy(vtkProp* prop)
Will Schroeder's avatar
Will Schroeder committed
664
{
665
  vtkScalarBarActor* a = vtkScalarBarActor::SafeDownCast(prop);
Will Schroeder's avatar
Will Schroeder committed
666
667
668
669
670
671
  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
672
673
    this->SetLabelTextProperty(a->GetLabelTextProperty());
    this->SetTitleTextProperty(a->GetTitleTextProperty());
Will Schroeder's avatar
Will Schroeder committed
674
675
676
    this->SetLabelFormat(a->GetLabelFormat());
    this->SetTitle(a->GetTitle());
    this->GetPositionCoordinate()->SetCoordinateSystem(
677
      a->GetPositionCoordinate()->GetCoordinateSystem());
Will Schroeder's avatar
Will Schroeder committed
678
679
680
    this->GetPositionCoordinate()->SetValue(
      a->GetPositionCoordinate()->GetValue());
    this->GetPosition2Coordinate()->SetCoordinateSystem(
681
      a->GetPosition2Coordinate()->GetCoordinateSystem());
Will Schroeder's avatar
Will Schroeder committed
682
683
    this->GetPosition2Coordinate()->SetValue(
      a->GetPosition2Coordinate()->GetValue());
684
685
686
687
    this->SetDrawBackground(a->GetDrawBackground());
    this->SetBackgroundProperty(a->GetBackgroundProperty());
    this->SetDrawFrame(a->GetDrawFrame());
    this->SetFrameProperty(a->GetFrameProperty());
Will Schroeder's avatar
Will Schroeder committed
688
689
690
691
692
    }

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

Sebastien Barre's avatar
Sebastien Barre committed
694
//----------------------------------------------------------------------------
695
void vtkScalarBarActor::RebuildLayout(vtkViewport* viewport)
Ken Martin's avatar
Ken Martin committed
696
{
697
  vtkDebugMacro(<<"Rebuilding subobjects");
Sebastien Barre's avatar
Sebastien Barre committed
698

699
700
  this->P->Viewport = viewport;
  this->FreeLayoutStorage();
Sebastien Barre's avatar
Sebastien Barre committed
701

702
703
704
705
706
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
  // 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();
737
738
739
740
741
742
743
744
745
746
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
#ifdef VTK_DBG_LAYOUT
  this->DrawBoxes();
#endif // VTK_DBG_LAYOUT
}

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);
    }
774
775
776
777
778
779
780
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
}

//----------------------------------------------------------------------------
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] =
815
    static_cast<int>(ceil(this->P->Frame.Size[0] * this->BarRatio));
816
817
818
819
820
821
822
823
824
825
826
827
828
829

  // 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];
    }
830
831

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

//----------------------------------------------------------------------------
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];
866
    this->P->NanBox.Posn[1] = this->P->Frame.Posn[1] + this->TextPad;
867
868
869
870
871
872
873
874
875
876
877
    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;
878
879
880
881
  if (this->P->NanBox.Size[1] > 2 * this->TextPad)
    {
    this->P->NanBox.Size[1] -= this->TextPad;
    }
882
883
884
885
886
887
888
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
}

//----------------------------------------------------------------------------
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.
929
  targetWidth = static_cast<int>(this->P->Frame.Size[this->P->TL[0]]) - 2 * this->TextPad;
930
931
932
933
934
935
936
937
938
  // 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()) ?
939
940
941
942
943
    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);
944
945
946
947
948
949
950
951

  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);
952
  this->TitleActor->GetTextProperty()->SetVerticalJustificationToTop();
953
954
955
956
957
  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
958

959
960
961
962
963
964
965
966
967
  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)
    {
968
    this->P->TitleBox.Posn[1] -= this->P->TitleBox.Size[this->P->TL[1]] + this->TextPad;
969
970
971
    }
  else
    {
972
    this->P->TitleBox.Posn[1] = this->P->Frame.Posn[1] + this->TextPad;
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
    }
}

//-----------------------------------------------------------------------------
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;
    }
996

997
998
999
  // find the best size for the ticks
  double* range = this->LookupTable->GetRange();
  char string[512];
Ken Martin's avatar
Ken Martin committed
1000
  double val;
Ken Martin's avatar
Ken Martin committed
1001
  int i;
1002

Sebastien Barre's avatar
Sebastien Barre committed
1003
1004
1005
1006
1007
  // 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).
1008
  this->P->TextActors.resize(this->NumberOfLabels);
1009

1010
  // Does this map have its scale set to log?
1011
  int isLogTable = this->LookupTable->UsingLogScale();
1012

1013
  for (i = 0; i < this->NumberOfLabels; i++)
Ken Martin's avatar
Ken Martin committed
1014
    {
1015
    this->P->TextActors[i].TakeReference(vtkTextActor::New());
Sebastien Barre's avatar
Sebastien Barre committed
1016

1017
1018
    if ( isLogTable )
      {
Ken Martin's avatar
Ken Martin committed
1019
      double lval;
Ken Martin's avatar
Ken Martin committed
1020
1021
      if (this->NumberOfLabels > 1)
        {
1022
1023
        lval = log10(range[0]) +
          static_cast<double>(i)/(this->NumberOfLabels-1) *
Ken Martin's avatar
Ken Martin committed
1024
1025
1026
1027
1028
1029
          (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
1030
      val = pow(10.0,lval);
1031
1032
1033
      }
    else
      {
Ken Martin's avatar
Ken Martin committed
1034
1035
      if (this->NumberOfLabels > 1)
        {
1036
        val = range[0] +
1037
          static_cast<double>(i)/(this->NumberOfLabels-1)
1038
          * (range[1]-range[0]);
Ken Martin's avatar
Ken Martin committed
1039
1040
1041
1042
1043
        }
      else
        {
        val = range[0] + 0.5*(range[1]-range[0]);
        }
1044
1045
      }

1046
1047
    SNPRINTF(string, 511, this->LabelFormat, val);
    this->P->TextActors[i]->SetInput(string);
Sebastien Barre's avatar
Sebastien Barre committed
1048
1049
1050
1051
1052
1053
1054

    // 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.
1055
    this->P->TextActors[i]->GetTextProperty()->ShallowCopy(
Sebastien Barre's avatar
Sebastien Barre committed
1056
1057
      this->LabelTextProperty);

1058
1059
    this->P->TextActors[i]->SetProperty(this->GetProperty());
    this->P->TextActors[i]->GetPositionCoordinate()->
Ken Martin's avatar
Ken Martin committed
1060
1061
      SetReferenceCoordinate(this->PositionCoordinate);
    }
Sebastien Barre's avatar
Sebastien Barre committed
1062

Ken Martin's avatar
Ken Martin committed
1063
1064
  if (this->NumberOfLabels)
    {
1065
1066
    int labelSize[2];
    labelSize[0] = labelSize[1] = 0;
Sebastien Barre's avatar
Sebastien Barre committed
1067
1068
    int targetWidth, targetHeight;

1069
1070
1071
1072
1073
    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] =
1074
1075
        this->P->Frame.Size[0] - this->P->ScalarBarBox.Size[0] -
        this->TextPad * 3;
1076
1077
1078
      // 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] -
1079
        this->P->TitleBox.Size[1] - 3 * this->TextPad;
1080
1081
1082
1083
1084
1085
1086
1087
1088
      // 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)
        {
1089
        this->P->TickBox.Posn[0] = this->TextPad;
1090
1091
1092
        }
      else
        {
1093
        this->P->TickBox.Posn[0] += this->P->ScalarBarBox.Size[0] + 2 * this->TextPad;
1094
1095
1096
1097
        }

      targetWidth = this->P->TickBox.Size[0];
      targetHeight = static_cast<int>((this->P->TickBox.Size[1] -
1098
          this->TextPad * (this->NumberOfLabels - 1)) /
1099
1100
1101
1102
1103
1104
1105
1106
1107
        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] -
1108
        4 * this->TextPad - this->P->TitleBox.Size[0];
1109
1110
1111

      if (this->TextPosition == vtkScalarBarActor::PrecedeScalarBar)
        {
1112
1113
        this->P->TickBox.Posn[1] =
          this->P->TitleBox.Size[0] + 2 * this->TextPad;
1114
1115
        /* or equivalently: Posn[1] -=
          this->P->Frame.Size[0] -
1116
          this->P->TitleBox.Size[0] - this->TextPad -
1117
1118
1119
1120