1 // Copyright (C) 2007-2019 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SMESH_ScalarBarActor.cxx
23 // Author : Roman NIKOLAEV
27 #include "SMESH_ScalarBarActor.h"
29 #include <vtkCellArray.h>
30 #include <vtkCellData.h>
31 #include <vtkLookupTable.h>
32 #include <vtkObjectFactory.h>
33 #include <vtkPolyData.h>
34 #include <vtkPolyDataMapper2D.h>
35 #include <vtkProperty2D.h>
36 #include <vtkScalarsToColors.h>
37 #include <vtkTextMapper.h>
38 #include <vtkTextProperty.h>
39 #include <vtkViewport.h>
40 #include <vtkWindow.h>
42 #define SHRINK_COEF 0.08;
44 vtkStandardNewMacro(SMESH_ScalarBarActor);
46 vtkCxxSetObjectMacro(SMESH_ScalarBarActor,LookupTable,vtkScalarsToColors);
47 vtkCxxSetObjectMacro(SMESH_ScalarBarActor,LabelTextProperty,vtkTextProperty);
48 vtkCxxSetObjectMacro(SMESH_ScalarBarActor,TitleTextProperty,vtkTextProperty);
50 //----------------------------------------------------------------------------
51 // Instantiate object with 64 maximum colors; 5 labels; %%-#6.3g label
52 // format, no title, and vertical orientation. The initial scalar bar
53 // size is (0.05 x 0.8) of the viewport size.
54 SMESH_ScalarBarActor::SMESH_ScalarBarActor()
56 this->LookupTable = NULL;
57 this->Position2Coordinate->SetValue(0.17, 0.8);
59 this->PositionCoordinate->SetCoordinateSystemToNormalizedViewport();
60 this->PositionCoordinate->SetValue(0.82,0.1);
62 this->MaximumNumberOfColors = 64;
63 this->NumberOfLabels = 5;
64 this->NumberOfLabelsBuilt = 0;
65 this->Orientation = VTK_ORIENT_VERTICAL;
68 this->LabelTextProperty = vtkTextProperty::New();
69 this->LabelTextProperty->SetFontSize(12);
70 this->LabelTextProperty->SetBold(1);
71 this->LabelTextProperty->SetItalic(1);
72 this->LabelTextProperty->SetShadow(1);
73 this->LabelTextProperty->SetFontFamilyToArial();
75 this->TitleTextProperty = vtkTextProperty::New();
76 this->TitleTextProperty->ShallowCopy(this->LabelTextProperty);
78 this->LabelFormat = new char[8];
79 sprintf(this->LabelFormat,"%s","%-#6.3g");
81 this->TitleMapper = vtkTextMapper::New();
82 this->TitleActor = vtkActor2D::New();
83 this->TitleActor->SetMapper(this->TitleMapper);
84 this->TitleActor->GetPositionCoordinate()->
85 SetReferenceCoordinate(this->PositionCoordinate);
87 this->TextMappers = NULL;
88 this->TextActors = NULL;
90 this->ScalarBar = vtkPolyData::New();
91 this->ScalarBarMapper = vtkPolyDataMapper2D::New();
92 this->ScalarBarMapper->SetInputData(this->ScalarBar);
93 this->ScalarBarActor = vtkActor2D::New();
94 this->ScalarBarActor->SetMapper(this->ScalarBarMapper);
95 this->ScalarBarActor->GetPositionCoordinate()->
96 SetReferenceCoordinate(this->PositionCoordinate);
97 this->LastOrigin[0] = 0;
98 this->LastOrigin[1] = 0;
99 this->LastSize[0] = 0;
100 this->LastSize[1] = 0;
104 // Customization of the vtkScalarBarActor to show distribution histogram.
105 myDistribution = vtkPolyData::New();
106 myDistributionMapper = vtkPolyDataMapper2D::New();
107 myDistributionMapper->SetInputData(this->myDistribution);
109 myDistributionActor = vtkActor2D::New();
110 myDistributionActor->SetMapper(this->myDistributionMapper);
111 myDistributionActor->GetPositionCoordinate()->
112 SetReferenceCoordinate(this->PositionCoordinate);
114 // By default distribution histogram is invisible
115 myDistributionActor->SetVisibility(0);
117 // By default monocolor
118 myDistributionColoringType = SMESH_MONOCOLOR_TYPE;
120 // By default scalar map is shown
121 myTitleOnlyVisibility = false;
125 //----------------------------------------------------------------------------
126 // Release any graphics resources that are being consumed by this actor.
127 // The parameter window could be used to determine which graphic
128 // resources to release.
129 void SMESH_ScalarBarActor::ReleaseGraphicsResources(vtkWindow *win)
131 this->TitleActor->ReleaseGraphicsResources(win);
132 if (this->TextMappers != NULL )
134 for (int i=0; i < this->NumberOfLabelsBuilt; i++)
136 this->TextActors[i]->ReleaseGraphicsResources(win);
139 this->ScalarBarActor->ReleaseGraphicsResources(win);
141 // Customization of the vtkScalarBarActor to show distribution histogram.
142 myDistributionActor->ReleaseGraphicsResources(win);
146 /*--------------------------------------------------------------------------*/
147 SMESH_ScalarBarActor::~SMESH_ScalarBarActor()
149 if (this->LabelFormat)
151 delete [] this->LabelFormat;
152 this->LabelFormat = NULL;
155 this->TitleMapper->Delete();
156 this->TitleActor->Delete();
158 if (this->TextMappers != NULL )
160 for (int i=0; i < this->NumberOfLabelsBuilt; i++)
162 this->TextMappers[i]->Delete();
163 this->TextActors[i]->Delete();
165 delete [] this->TextMappers;
166 delete [] this->TextActors;
169 this->ScalarBar->Delete();
170 this->ScalarBarMapper->Delete();
171 this->ScalarBarActor->Delete();
175 delete [] this->Title;
179 this->SetLookupTable(NULL);
180 this->SetLabelTextProperty(NULL);
181 this->SetTitleTextProperty(NULL);
184 // Customization of the vtkScalarBarActor to show distribution histogram:
185 myDistribution->Delete();
186 myDistributionMapper->Delete();
187 myDistributionActor->Delete();
191 //----------------------------------------------------------------------------
192 int SMESH_ScalarBarActor::RenderOverlay(vtkViewport *viewport)
194 int renderedSomething = 0;
197 // Everything is built, just have to render
198 if (this->Title != NULL)
200 renderedSomething += this->TitleActor->RenderOverlay(viewport);
202 if ( !myTitleOnlyVisibility ) {
203 this->ScalarBarActor->RenderOverlay(viewport);
204 this->myDistributionActor->RenderOverlay(viewport);
205 if ( this->TextActors == NULL )
207 vtkWarningMacro(<<"Need a mapper to render a scalar bar");
208 return renderedSomething;
211 for ( i=0; i<this->NumberOfLabels; i++ )
213 renderedSomething += this->TextActors[i]->RenderOverlay(viewport);
216 renderedSomething = (renderedSomething > 0)?(1):(0);
218 return renderedSomething;
222 //----------------------------------------------------------------------------
223 int SMESH_ScalarBarActor::RenderOpaqueGeometry(vtkViewport *viewport)
225 int renderedSomething = 0;
229 if (!this->LookupTable)
231 vtkWarningMacro(<<"Need a mapper to render a scalar bar");
235 if (!this->TitleTextProperty)
237 vtkErrorMacro(<<"Need title text property to render a scalar bar");
241 if (!this->LabelTextProperty)
243 vtkErrorMacro(<<"Need label text property to render a scalar bar");
247 // Check to see whether we have to rebuild everything
248 int positionsHaveChanged = 0;
249 if (viewport->GetMTime() > this->BuildTime ||
250 (viewport->GetVTKWindow() &&
251 viewport->GetVTKWindow()->GetMTime() > this->BuildTime))
253 // if the viewport has changed we may - or may not need
254 // to rebuild, it depends on if the projected coords change
256 barOrigin = this->PositionCoordinate->GetComputedViewportValue(viewport);
258 this->Position2Coordinate->GetComputedViewportValue(viewport)[0] -
261 this->Position2Coordinate->GetComputedViewportValue(viewport)[1] -
263 if (this->LastSize[0] != size[0] ||
264 this->LastSize[1] != size[1] ||
265 this->LastOrigin[0] != barOrigin[0] ||
266 this->LastOrigin[1] != barOrigin[1])
268 positionsHaveChanged = 1;
272 // Check to see whether we have to rebuild everything
273 if ( positionsHaveChanged ||
274 this->GetMTime() > this->BuildTime ||
275 this->LookupTable->GetMTime() > this->BuildTime ||
276 this->LabelTextProperty->GetMTime() > this->BuildTime ||
277 this->TitleTextProperty->GetMTime() > this->BuildTime)
279 vtkDebugMacro(<<"Rebuilding subobjects");
281 // Delete previously constructed objects
283 if ( this->TextMappers != NULL )
285 for ( i = 0; i < this->NumberOfLabelsBuilt; i++ )
287 this->TextMappers[i]->Delete();
288 this->TextActors[i]->Delete();
290 delete [] this->TextMappers;
291 delete [] this->TextActors;
294 // Build scalar bar object; determine its type
296 // is this a vtkLookupTable or a subclass of vtkLookupTable
297 // with its scale set to log
298 // NOTE: it's possible we could to without the 'lut' variable
299 // later in the code, but if the vtkLookupTableSafeDownCast operation
300 // fails for some reason, this code will break in new ways. So, the 'LUT'
301 // variable is used for this operation only
302 vtkLookupTable *LUT = vtkLookupTable::SafeDownCast( this->LookupTable );
306 if ( LUT->GetScale() == VTK_SCALE_LOG10 )
312 // we hard code how many steps to display
313 vtkScalarsToColors *lut = this->LookupTable;
314 int numColors = this->MaximumNumberOfColors;
315 double *range = lut->GetRange();
317 int numPts = 2*(numColors + 1);
318 vtkPoints *pts = vtkPoints::New();
319 pts->SetNumberOfPoints(numPts);
320 vtkCellArray *polys = vtkCellArray::New();
321 polys->Allocate(polys->EstimateSize(numColors,4));
322 vtkUnsignedCharArray *colors = vtkUnsignedCharArray::New();
323 colors->SetNumberOfComponents(3);
324 colors->SetNumberOfTuples(numColors);
328 // Customization of the vtkScalarBarActor to show distribution histogram.
329 bool distrVisibility = (numColors == (int)this->myNbValues.size());
330 vtkPoints *distrPts = 0;
331 vtkCellArray *distrPolys = 0;
332 vtkUnsignedCharArray *distColors = 0;
333 int numDistrPts = 0, numPositiveVal=0, maxValue=0;
335 vtkDebugMacro(<<" Distribution invisible, because numColors == this->myNbValues.size()");
337 if ( distrVisibility && GetDistributionVisibility() )
339 for ( i = 0 ; i < (int)myNbValues.size(); i++ ) {
340 if ( myNbValues[i] ) {
342 maxValue = std::max(maxValue,myNbValues[i]);
345 numDistrPts = 4*(numPositiveVal);
346 distrPts = vtkPoints::New();
347 distrPolys = vtkCellArray::New();
348 distrPts->SetNumberOfPoints(numDistrPts);
349 distrPolys->Allocate(distrPolys->EstimateSize(numPositiveVal,4));
350 this->myDistribution->Initialize();
351 this->myDistribution->SetPoints(distrPts);
352 this->myDistribution->SetPolys(distrPolys);
354 distrPolys->Delete();
355 if ( myDistributionColoringType == SMESH_MULTICOLOR_TYPE )
357 distColors = vtkUnsignedCharArray::New();
358 distColors->SetNumberOfComponents(3);
359 distColors->SetNumberOfTuples(numPositiveVal);
360 this->myDistribution->GetCellData()->SetScalars(distColors);
361 distColors->Delete();
363 else if( myDistributionColoringType == SMESH_MONOCOLOR_TYPE )
365 this->myDistribution->GetCellData()->SetScalars(NULL);
370 myDistribution->Reset();
374 this->ScalarBarActor->SetProperty(this->GetProperty());
375 this->ScalarBar->Initialize();
376 this->ScalarBar->SetPoints(pts);
377 this->ScalarBar->SetPolys(polys);
378 this->ScalarBar->GetCellData()->SetScalars(colors);
379 pts->Delete(); polys->Delete(); colors->Delete();
381 // get the viewport size in display coordinates
382 int *barOrigin, barWidth, barHeight, distrHeight;
383 barOrigin = this->PositionCoordinate->GetComputedViewportValue(viewport);
385 this->Position2Coordinate->GetComputedViewportValue(viewport)[0] -
388 this->Position2Coordinate->GetComputedViewportValue(viewport)[1] -
390 this->LastOrigin[0] = barOrigin[0];
391 this->LastOrigin[1] = barOrigin[1];
392 this->LastSize[0] = size[0];
393 this->LastSize[1] = size[1];
395 // Update all the composing objects
396 this->TitleActor->SetProperty(this->GetProperty());
397 this->TitleMapper->SetInput(this->Title);
398 if (this->TitleTextProperty->GetMTime() > this->BuildTime)
400 // Shallow copy here so that the size of the title prop is not affected
401 // by the automatic adjustment of its text mapper's size (i.e. its
402 // mapper's text property is identical except for the font size
403 // which will be modified later). This allows text actors to
404 // share the same text property, and in that case specifically allows
405 // the title and label text prop to be the same.
406 this->TitleMapper->GetTextProperty()->ShallowCopy(this->TitleTextProperty);
407 this->TitleMapper->GetTextProperty()->SetJustificationToCentered();
410 // find the best size for the title font
412 this->SizeTitle(titleSize, size, viewport);
414 // find the best size for the ticks
416 this->AllocateAndSizeLabels(labelSize, size, viewport,range);
417 this->NumberOfLabelsBuilt = this->NumberOfLabels;
420 double x[3]; x[2] = 0.0;
421 double delta, itemH, shrink;
422 if ( this->Orientation == VTK_ORIENT_VERTICAL ) {
424 // Customization of the vtkScalarBarActor to show distribution histogram.
425 double delimeter=0.0;
426 if(GetDistributionVisibility() && distrVisibility) {
427 delimeter=0.01*size[0]; //1 % from horizontal size of the full presentation size.
428 barWidth = size[0] - 4 - labelSize[0];
429 distrHeight = barWidth/2;
431 barWidth = size[0] - 4 - labelSize[0];
435 barHeight = (int)(0.86*size[1]);
436 delta=(double)barHeight/numColors;
438 for ( i=0; i<numPts/2; i++ ) {
439 x[0] = distrHeight+delimeter/2.0;
441 pts->SetPoint(2*i,x);
443 pts->SetPoint(2*i+1,x);
446 if ( GetDistributionVisibility() && distrVisibility ) {
447 // Distribution points
448 shrink = delta*SHRINK_COEF;
449 vtkIdType distPtsId=0;
450 vtkIdType distPtsIds[4];
451 for ( i = 0; i < numColors; i++ ) {
452 if ( myNbValues[i] ) {
453 itemH = distrHeight*((double)myNbValues[i]/maxValue);
455 if(distrHeight == itemH)
456 itemH = itemH - delimeter/2;
458 x[1] = i*delta+shrink;
460 // first point of polygon (quadrangle)
462 distPtsIds[0] = distPtsId;
463 distrPts->SetPoint(distPtsId++,x);
465 // second point of polygon (quadrangle)
467 distPtsIds[1] = distPtsId;
468 distrPts->SetPoint(distPtsId++,x);
470 x[1] = i*delta+delta-shrink;
472 // third point of polygon (quadrangle)
474 distPtsIds[3] = distPtsId;
475 distrPts->SetPoint(distPtsId++,x);
477 // fourth point of polygon (quadrangle)
479 distPtsIds[2] = distPtsId;
480 distrPts->SetPoint(distPtsId++,x);
483 distrPolys->InsertNextCell(4,distPtsIds);
493 // Customization of the vtkScalarBarActor to show distribution histogram.
494 double coef1, delimeter=0.0;
495 if ( GetDistributionVisibility() && distrVisibility ) {
497 distrHeight = (int)((coef1/2)*size[1]);
498 //delimeter between distribution diagram and scalar bar
499 delimeter=0.02*size[1];
503 barHeight = (int)(coef1*size[1]);
507 barHeight = (int)(coef1*size[1]);
509 delta=(double)barWidth/numColors;
510 for ( i = 0; i < numPts/2; i++ ) {
513 pts->SetPoint(2*i,x);
514 x[1] = distrHeight + delimeter;
515 pts->SetPoint(2*i+1,x);
518 if ( GetDistributionVisibility() && distrVisibility ) {
519 // Distribution points
520 shrink = delta*SHRINK_COEF;
521 vtkIdType distPtsId=0;
522 vtkIdType distPtsIds[4];
523 for ( i = 0; i < numColors; i++ ) {
525 itemH = distrHeight*((double)myNbValues[i]/maxValue);
527 // first point of polygon (quadrangle)
528 x[0] = i*delta+shrink;
530 distPtsIds[0] = distPtsId;
531 distrPts->SetPoint(distPtsId++,x);
533 // second point of polygon (quadrangle)
534 x[0] = i*delta+shrink;
536 distPtsIds[3] = distPtsId;
537 distrPts->SetPoint(distPtsId++,x);
539 // third point of polygon (quadrangle)
540 x[0] = i*delta+delta-shrink;
542 distPtsIds[1] = distPtsId;
543 distrPts->SetPoint(distPtsId++,x);
545 // fourth point of polygon (quadrangle)
546 x[0] = i*delta+delta-shrink;
548 distPtsIds[2] = distPtsId;
549 distrPts->SetPoint(distPtsId++,x);
551 // Add polygon into poly data
552 distrPolys->InsertNextCell(4,distPtsIds);
559 //polygons & cell colors
561 const unsigned char *rgba;
562 vtkIdType ptIds[4], dcCount=0;
563 for ( i = 0; i < numColors; i++ )
566 ptIds[1] = ptIds[0] + 1;
567 ptIds[2] = ptIds[1] + 2;
568 ptIds[3] = ptIds[0] + 2;
569 polys->InsertNextCell(4,ptIds);
573 double rgbval = log10(range[0]) +
574 i*(log10(range[1])-log10(range[0]))/(numColors -1);
575 rgba = lut->MapValue(pow(10.0,rgbval));
579 rgba = lut->MapValue(range[0] + (range[1] - range[0])*
580 ((double)i /(numColors-1.0)));
583 rgb = colors->GetPointer(3*i); //write into array directly
589 // Customization of the vtkScalarBarActor to show distribution histogram.
590 if ( myDistributionColoringType == SMESH_MULTICOLOR_TYPE &&
591 GetDistributionVisibility() &&
595 rgb = distColors->GetPointer(3*dcCount); //write into array directly
603 // Now position everything properly
606 if ( this->Orientation == VTK_ORIENT_VERTICAL )
611 this->TitleActor->SetPosition(size[0]/2, 0.9*size[1]);
613 for ( i = 0; i < this->NumberOfLabels; i++ )
615 if ( this->NumberOfLabels > 1 )
617 val = (double)i/(this->NumberOfLabels-1) *barHeight;
623 this->TextMappers[i]->GetSize(viewport,sizeTextData);
624 this->TextMappers[i]->GetTextProperty()->SetJustificationToLeft();
625 this->TextActors[i]->SetPosition(barWidth+3,
626 val - sizeTextData[1]/2);
631 this->TitleActor->SetPosition(size[0]/2,
632 barHeight + labelSize[1] + 0.1*size[1]);
633 for ( i = 0; i < this->NumberOfLabels; i++ )
635 this->TextMappers[i]->GetTextProperty()->SetJustificationToCentered();
636 if (this->NumberOfLabels > 1)
638 val = (double)i/(this->NumberOfLabels-1) * barWidth;
644 this->TextActors[i]->SetPosition(val, barHeight + 0.05*size[1]);
648 this->BuildTime.Modified();
651 // Everything is built, just have to render
652 if ( this->Title != NULL )
654 renderedSomething += this->TitleActor->RenderOpaqueGeometry(viewport);
656 this->ScalarBarActor->RenderOpaqueGeometry(viewport);
657 this->myDistributionActor->RenderOpaqueGeometry(viewport);
658 for ( i = 0; i < this->NumberOfLabels; i++ )
660 renderedSomething += this->TextActors[i]->RenderOpaqueGeometry(viewport);
663 renderedSomething = (renderedSomething > 0)?(1):(0);
665 return renderedSomething;
668 //----------------------------------------------------------------------------
669 void SMESH_ScalarBarActor::PrintSelf(ostream& os, vtkIndent indent)
671 this->Superclass::PrintSelf(os,indent);
673 if ( this->LookupTable )
675 os << indent << "Lookup Table:\n";
676 this->LookupTable->PrintSelf(os,indent.GetNextIndent());
680 os << indent << "Lookup Table: (none)\n";
683 if (this->TitleTextProperty)
685 os << indent << "Title Text Property:\n";
686 this->TitleTextProperty->PrintSelf(os,indent.GetNextIndent());
690 os << indent << "Title Text Property: (none)\n";
693 if (this->LabelTextProperty)
695 os << indent << "Label Text Property:\n";
696 this->LabelTextProperty->PrintSelf(os,indent.GetNextIndent());
700 os << indent << "Label Text Property: (none)\n";
703 os << indent << "Title: " << (this->Title ? this->Title : "(none)") << "\n";
704 os << indent << "Maximum Number Of Colors: "
705 << this->MaximumNumberOfColors << "\n";
706 os << indent << "Number Of Labels: " << this->NumberOfLabels << "\n";
707 os << indent << "Number Of Labels Built: " << this->NumberOfLabelsBuilt << "\n";
709 os << indent << "Orientation: ";
710 if ( this->Orientation == VTK_ORIENT_HORIZONTAL )
712 os << "Horizontal\n";
719 os << indent << "Label Format: " << this->LabelFormat << "\n";
722 //----------------------------------------------------------------------------
723 void SMESH_ScalarBarActor::ShallowCopy(vtkProp *prop)
725 SMESH_ScalarBarActor *a = SMESH_ScalarBarActor::SafeDownCast(prop);
728 this->SetPosition2(a->GetPosition2());
729 this->SetLookupTable(a->GetLookupTable());
730 this->SetMaximumNumberOfColors(a->GetMaximumNumberOfColors());
731 this->SetOrientation(a->GetOrientation());
732 this->SetLabelTextProperty(a->GetLabelTextProperty());
733 this->SetTitleTextProperty(a->GetTitleTextProperty());
734 this->SetLabelFormat(a->GetLabelFormat());
735 this->SetTitle(a->GetTitle());
736 this->GetPositionCoordinate()->SetCoordinateSystem
737 (a->GetPositionCoordinate()->GetCoordinateSystem());
738 this->GetPositionCoordinate()->SetValue
739 (a->GetPositionCoordinate()->GetValue());
740 this->GetPosition2Coordinate()->SetCoordinateSystem
741 (a->GetPosition2Coordinate()->GetCoordinateSystem());
742 this->GetPosition2Coordinate()->SetValue
743 (a->GetPosition2Coordinate()->GetValue());
747 this->vtkActor2D::ShallowCopy(prop);
750 //----------------------------------------------------------------------------
751 void SMESH_ScalarBarActor::AllocateAndSizeLabels(int *labelSize,
753 vtkViewport *viewport,
756 labelSize[0] = labelSize[1] = 0;
758 this->TextMappers = new vtkTextMapper * [this->NumberOfLabels];
759 this->TextActors = new vtkActor2D * [this->NumberOfLabels];
766 // TODO: this should be optimized, maybe by keeping a list of
767 // allocated mappers, in order to avoid creation/destruction of
768 // their underlying text properties (i.e. each time a mapper is
769 // created, text properties are created and shallow-assigned a font size
770 // which value might be "far" from the target font size).
772 // is this a vtkLookupTable or a subclass of vtkLookupTable
773 // with its scale set to log
774 vtkLookupTable *LUT = vtkLookupTable::SafeDownCast( this->LookupTable );
778 if ( LUT->GetScale() == VTK_SCALE_LOG10 )
784 for ( i = 0; i < this->NumberOfLabels; i++ )
786 this->TextMappers[i] = vtkTextMapper::New();
791 if ( this->NumberOfLabels > 1 )
793 lval = log10(range[0]) + (double)i/(this->NumberOfLabels-1) *
794 (log10(range[1])-log10(range[0]));
798 lval = log10(range[0]) + 0.5*(log10(range[1])-log10(range[0]));
800 val = pow(10.0,lval);
804 if ( this->NumberOfLabels > 1 )
807 (double)i/(this->NumberOfLabels-1) * (range[1]-range[0]);
811 val = range[0] + 0.5*(range[1]-range[0]);
815 sprintf(string, this->LabelFormat, val);
816 this->TextMappers[i]->SetInput(string);
818 // Shallow copy here so that the size of the label prop is not affected
819 // by the automatic adjustment of its text mapper's size (i.e. its
820 // mapper's text property is identical except for the font size
821 // which will be modified later). This allows text actors to
822 // share the same text property, and in that case specifically allows
823 // the title and label text prop to be the same.
824 this->TextMappers[i]->GetTextProperty()->ShallowCopy(this->LabelTextProperty);
826 this->TextActors[i] = vtkActor2D::New();
827 this->TextActors[i]->SetMapper(this->TextMappers[i]);
828 this->TextActors[i]->SetProperty(this->GetProperty());
829 this->TextActors[i]->GetPositionCoordinate()->
830 SetReferenceCoordinate(this->PositionCoordinate);
833 if ( this->NumberOfLabels )
835 int targetWidth, targetHeight;
837 // Customization of the vtkScalarBarActor to show distribution histogram.
838 bool distrVisibility = ( this->MaximumNumberOfColors == (int) this->myNbValues.size() );
840 if ( GetDistributionVisibility() && distrVisibility )
841 if ( this->Orientation == VTK_ORIENT_VERTICAL )
846 if (this->Orientation == VTK_ORIENT_VERTICAL )
852 if ( this->Orientation == VTK_ORIENT_VERTICAL )
854 targetWidth = (int)(coef*size[0]);
855 targetHeight = (int)(0.86*size[1]/this->NumberOfLabels);
859 targetWidth = (int)(size[0]*0.8/this->NumberOfLabels);
860 targetHeight = (int)(coef*size[1]);
864 vtkTextMapper::SetMultipleConstrainedFontSize( viewport,
868 this->NumberOfLabels,
873 //----------------------------------------------------------------------------
874 void SMESH_ScalarBarActor::SizeTitle(int *titleSize,
876 vtkViewport *viewport)
878 titleSize[0] = titleSize[1] = 0;
880 if ( this->Title == NULL || !strlen(this->Title) )
885 int targetWidth, targetHeight;
887 targetWidth = size[0];
889 // Customization of the vtkScalarBarActor to show distribution histogram.
890 bool distrVisibility = ( this->MaximumNumberOfColors == (int) this->myNbValues.size() );
892 if ( GetDistributionVisibility() && distrVisibility )
897 if ( this->Orientation == VTK_ORIENT_VERTICAL )
899 targetHeight = (int)(0.1*size[1]);
903 targetHeight = (int)(coef*size[1]);
906 this->TitleMapper->SetConstrainedFontSize(viewport, targetWidth, targetHeight);
908 this->TitleMapper->GetSize(viewport, titleSize);
912 /*--------------------------------------------------------------------------*/
913 void SMESH_ScalarBarActor::SetDistributionVisibility( int flag )
915 myDistributionActor->SetVisibility( flag );
920 /*--------------------------------------------------------------------------*/
921 int SMESH_ScalarBarActor::GetDistributionVisibility()
923 return myDistributionActor->GetVisibility();
927 void SMESH_ScalarBarActor::SetDistribution( const std::vector<int>& theNbValues )
929 myNbValues = theNbValues;
933 void SMESH_ScalarBarActor::SetDistributionColor( double rgb[3] )
935 myDistributionActor->GetProperty()->SetColor(rgb);
939 void SMESH_ScalarBarActor::GetDistributionColor( double rgb[3] )
941 myDistributionActor->GetProperty()->GetColor(rgb);
944 void SMESH_ScalarBarActor::SetTitleOnlyVisibility( bool theTitleOnlyVisibility )
946 myTitleOnlyVisibility = theTitleOnlyVisibility;
949 bool SMESH_ScalarBarActor::GetTitleOnlyVisibility()
951 return myTitleOnlyVisibility;