1 // Copyright (C) 2007-2013 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.
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 <vtkObjectFactory.h>
32 #include <vtkPolyData.h>
33 #include <vtkPolyDataMapper2D.h>
34 #include <vtkScalarsToColors.h>
35 #include <vtkTextMapper.h>
36 #include <vtkTextProperty.h>
37 #include <vtkViewport.h>
38 #include <vtkWindow.h>
39 #include <vtkLookupTable.h>
40 #include <vtkProperty2D.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() {
55 this->LookupTable = NULL;
56 this->Position2Coordinate->SetValue(0.17, 0.8);
58 this->PositionCoordinate->SetCoordinateSystemToNormalizedViewport();
59 this->PositionCoordinate->SetValue(0.82,0.1);
61 this->MaximumNumberOfColors = 64;
62 this->NumberOfLabels = 5;
63 this->NumberOfLabelsBuilt = 0;
64 this->Orientation = VTK_ORIENT_VERTICAL;
67 this->LabelTextProperty = vtkTextProperty::New();
68 this->LabelTextProperty->SetFontSize(12);
69 this->LabelTextProperty->SetBold(1);
70 this->LabelTextProperty->SetItalic(1);
71 this->LabelTextProperty->SetShadow(1);
72 this->LabelTextProperty->SetFontFamilyToArial();
74 this->TitleTextProperty = vtkTextProperty::New();
75 this->TitleTextProperty->ShallowCopy(this->LabelTextProperty);
77 this->LabelFormat = new char[8];
78 sprintf(this->LabelFormat,"%s","%-#6.3g");
80 this->TitleMapper = vtkTextMapper::New();
81 this->TitleActor = vtkActor2D::New();
82 this->TitleActor->SetMapper(this->TitleMapper);
83 this->TitleActor->GetPositionCoordinate()->
84 SetReferenceCoordinate(this->PositionCoordinate);
86 this->TextMappers = NULL;
87 this->TextActors = NULL;
89 this->ScalarBar = vtkPolyData::New();
90 this->ScalarBarMapper = vtkPolyDataMapper2D::New();
91 this->ScalarBarMapper->SetInputData(this->ScalarBar);
92 this->ScalarBarActor = vtkActor2D::New();
93 this->ScalarBarActor->SetMapper(this->ScalarBarMapper);
94 this->ScalarBarActor->GetPositionCoordinate()->
95 SetReferenceCoordinate(this->PositionCoordinate);
96 this->LastOrigin[0] = 0;
97 this->LastOrigin[1] = 0;
98 this->LastSize[0] = 0;
99 this->LastSize[1] = 0;
103 // Customization of the vtkScalarBarActor to show distribution histogram.
104 myDistribution = vtkPolyData::New();
105 myDistributionMapper = vtkPolyDataMapper2D::New();
106 myDistributionMapper->SetInputData(this->myDistribution);
108 myDistributionActor = vtkActor2D::New();
109 myDistributionActor->SetMapper(this->myDistributionMapper);
110 myDistributionActor->GetPositionCoordinate()->
111 SetReferenceCoordinate(this->PositionCoordinate);
113 // By default distribution histogram is invisible
114 myDistributionActor->SetVisibility(0);
116 // By default monocolor
117 myDistributionColoringType = SMESH_MONOCOLOR_TYPE;
121 //----------------------------------------------------------------------------
122 // Release any graphics resources that are being consumed by this actor.
123 // The parameter window could be used to determine which graphic
124 // resources to release.
125 void SMESH_ScalarBarActor::ReleaseGraphicsResources(vtkWindow *win)
127 this->TitleActor->ReleaseGraphicsResources(win);
128 if (this->TextMappers != NULL )
130 for (int i=0; i < this->NumberOfLabelsBuilt; i++)
132 this->TextActors[i]->ReleaseGraphicsResources(win);
135 this->ScalarBarActor->ReleaseGraphicsResources(win);
137 // Customization of the vtkScalarBarActor to show distribution histogram.
138 myDistributionActor->ReleaseGraphicsResources(win);
142 /*--------------------------------------------------------------------------*/
143 SMESH_ScalarBarActor::~SMESH_ScalarBarActor() {
144 if (this->LabelFormat)
146 delete [] this->LabelFormat;
147 this->LabelFormat = NULL;
150 this->TitleMapper->Delete();
151 this->TitleActor->Delete();
153 if (this->TextMappers != NULL )
155 for (int i=0; i < this->NumberOfLabelsBuilt; i++)
157 this->TextMappers[i]->Delete();
158 this->TextActors[i]->Delete();
160 delete [] this->TextMappers;
161 delete [] this->TextActors;
164 this->ScalarBar->Delete();
165 this->ScalarBarMapper->Delete();
166 this->ScalarBarActor->Delete();
170 delete [] this->Title;
174 this->SetLookupTable(NULL);
175 this->SetLabelTextProperty(NULL);
176 this->SetTitleTextProperty(NULL);
179 // Customization of the vtkScalarBarActor to show distribution histogram:
180 myDistribution->Delete();
181 myDistributionMapper->Delete();
182 myDistributionActor->Delete();
186 //----------------------------------------------------------------------------
187 int SMESH_ScalarBarActor::RenderOverlay(vtkViewport *viewport)
189 int renderedSomething = 0;
192 // Everything is built, just have to render
193 if (this->Title != NULL)
195 renderedSomething += this->TitleActor->RenderOverlay(viewport);
197 this->ScalarBarActor->RenderOverlay(viewport);
198 this->myDistributionActor->RenderOverlay(viewport);
199 if( this->TextActors == NULL)
201 vtkWarningMacro(<<"Need a mapper to render a scalar bar");
202 return renderedSomething;
205 for (i=0; i<this->NumberOfLabels; i++)
207 renderedSomething += this->TextActors[i]->RenderOverlay(viewport);
210 renderedSomething = (renderedSomething > 0)?(1):(0);
212 return renderedSomething;
216 //----------------------------------------------------------------------------
217 int SMESH_ScalarBarActor::RenderOpaqueGeometry(vtkViewport *viewport)
219 int renderedSomething = 0;
223 if (!this->LookupTable)
225 vtkWarningMacro(<<"Need a mapper to render a scalar bar");
229 if (!this->TitleTextProperty)
231 vtkErrorMacro(<<"Need title text property to render a scalar bar");
235 if (!this->LabelTextProperty)
237 vtkErrorMacro(<<"Need label text property to render a scalar bar");
241 // Check to see whether we have to rebuild everything
242 int positionsHaveChanged = 0;
243 if (viewport->GetMTime() > this->BuildTime ||
244 (viewport->GetVTKWindow() &&
245 viewport->GetVTKWindow()->GetMTime() > this->BuildTime))
247 // if the viewport has changed we may - or may not need
248 // to rebuild, it depends on if the projected coords chage
250 barOrigin = this->PositionCoordinate->GetComputedViewportValue(viewport);
252 this->Position2Coordinate->GetComputedViewportValue(viewport)[0] -
255 this->Position2Coordinate->GetComputedViewportValue(viewport)[1] -
257 if (this->LastSize[0] != size[0] ||
258 this->LastSize[1] != size[1] ||
259 this->LastOrigin[0] != barOrigin[0] ||
260 this->LastOrigin[1] != barOrigin[1])
262 positionsHaveChanged = 1;
266 // Check to see whether we have to rebuild everything
267 if (positionsHaveChanged ||
268 this->GetMTime() > this->BuildTime ||
269 this->LookupTable->GetMTime() > this->BuildTime ||
270 this->LabelTextProperty->GetMTime() > this->BuildTime ||
271 this->TitleTextProperty->GetMTime() > this->BuildTime)
273 vtkDebugMacro(<<"Rebuilding subobjects");
275 // Delete previously constructed objects
277 if (this->TextMappers != NULL )
279 for (i=0; i < this->NumberOfLabelsBuilt; i++)
281 this->TextMappers[i]->Delete();
282 this->TextActors[i]->Delete();
284 delete [] this->TextMappers;
285 delete [] this->TextActors;
288 // Build scalar bar object; determine its type
290 // is this a vtkLookupTable or a subclass of vtkLookupTable
291 // with its scale set to log
292 // NOTE: it's possible we could to without the 'lut' variable
293 // later in the code, but if the vtkLookupTableSafeDownCast operation
294 // fails for some reason, this code will break in new ways. So, the 'LUT'
295 // variable is used for this operation only
296 vtkLookupTable *LUT = vtkLookupTable::SafeDownCast( this->LookupTable );
300 if ( LUT->GetScale() == VTK_SCALE_LOG10 )
306 // we hard code how many steps to display
307 vtkScalarsToColors *lut = this->LookupTable;
308 int numColors = this->MaximumNumberOfColors;
309 double *range = lut->GetRange();
311 int numPts = 2*(numColors + 1);
312 vtkPoints *pts = vtkPoints::New();
313 pts->SetNumberOfPoints(numPts);
314 vtkCellArray *polys = vtkCellArray::New();
315 polys->Allocate(polys->EstimateSize(numColors,4));
316 vtkUnsignedCharArray *colors = vtkUnsignedCharArray::New();
317 colors->SetNumberOfComponents(3);
318 colors->SetNumberOfTuples(numColors);
322 // Customization of the vtkScalarBarActor to show distribution histogram.
323 bool distrVisibility = (numColors == this->myNbValues.size());
325 vtkCellArray *distrPolys;
326 vtkUnsignedCharArray *distColors = 0;
327 int numDistrPts = 0, numPositiveVal=0, maxValue=0;
329 vtkDebugMacro(<<" Distribution invisible, because numColors == this->myNbValues.size()");
331 if (distrVisibility && GetDistributionVisibility()) {
332 for( i=0 ;i<myNbValues.size();i++ ) {
335 maxValue = std::max(maxValue,myNbValues[i]);
338 numDistrPts = 4*(numPositiveVal);
339 distrPts = vtkPoints::New();
340 distrPolys = vtkCellArray::New();
341 distrPts->SetNumberOfPoints(numDistrPts);
342 distrPolys->Allocate(distrPolys->EstimateSize(numPositiveVal,4));
343 this->myDistribution->Initialize();
344 this->myDistribution->SetPoints(distrPts);
345 this->myDistribution->SetPolys(distrPolys);
347 distrPolys->Delete();
348 if ( myDistributionColoringType == SMESH_MULTICOLOR_TYPE ) {
349 distColors = vtkUnsignedCharArray::New();
350 distColors->SetNumberOfComponents(3);
351 distColors->SetNumberOfTuples(numPositiveVal);
352 this->myDistribution->GetCellData()->SetScalars(distColors);
353 distColors->Delete();
354 } else if( myDistributionColoringType == SMESH_MONOCOLOR_TYPE ){
355 this->myDistribution->GetCellData()->SetScalars(NULL);
358 myDistribution->Reset();
362 this->ScalarBarActor->SetProperty(this->GetProperty());
363 this->ScalarBar->Initialize();
364 this->ScalarBar->SetPoints(pts);
365 this->ScalarBar->SetPolys(polys);
366 this->ScalarBar->GetCellData()->SetScalars(colors);
367 pts->Delete(); polys->Delete(); colors->Delete();
369 // get the viewport size in display coordinates
370 int *barOrigin, barWidth, barHeight, distrHeight;
371 barOrigin = this->PositionCoordinate->GetComputedViewportValue(viewport);
373 this->Position2Coordinate->GetComputedViewportValue(viewport)[0] -
376 this->Position2Coordinate->GetComputedViewportValue(viewport)[1] -
378 this->LastOrigin[0] = barOrigin[0];
379 this->LastOrigin[1] = barOrigin[1];
380 this->LastSize[0] = size[0];
381 this->LastSize[1] = size[1];
383 // Update all the composing objects
384 this->TitleActor->SetProperty(this->GetProperty());
385 this->TitleMapper->SetInput(this->Title);
386 if (this->TitleTextProperty->GetMTime() > this->BuildTime)
388 // Shallow copy here so that the size of the title prop is not affected
389 // by the automatic adjustment of its text mapper's size (i.e. its
390 // mapper's text property is identical except for the font size
391 // which will be modified later). This allows text actors to
392 // share the same text property, and in that case specifically allows
393 // the title and label text prop to be the same.
394 this->TitleMapper->GetTextProperty()->ShallowCopy(this->TitleTextProperty);
395 this->TitleMapper->GetTextProperty()->SetJustificationToCentered();
398 // find the best size for the title font
400 this->SizeTitle(titleSize, size, viewport);
402 // find the best size for the ticks
404 this->AllocateAndSizeLabels(labelSize, size, viewport,range);
405 this->NumberOfLabelsBuilt = this->NumberOfLabels;
408 double x[3]; x[2] = 0.0;
409 double delta, itemH, shrink;
410 if ( this->Orientation == VTK_ORIENT_VERTICAL ) {
412 // Customization of the vtkScalarBarActor to show distribution histogram.
413 double delimeter=0.0;
414 if(GetDistributionVisibility() && distrVisibility) {
415 delimeter=0.01*size[0]; //1 % from horizontal size of the full presentation size.
416 barWidth = size[0] - 4 - labelSize[0];
417 distrHeight = barWidth/2;
419 barWidth = size[0] - 4 - labelSize[0];
423 barHeight = (int)(0.86*size[1]);
424 delta=(double)barHeight/numColors;
426 for ( i=0; i<numPts/2; i++ ) {
427 x[0] = distrHeight+delimeter/2.0;
429 pts->SetPoint(2*i,x);
431 pts->SetPoint(2*i+1,x);
434 if(GetDistributionVisibility() && distrVisibility) {
435 // Distribution points
436 shrink = delta*SHRINK_COEF;
437 vtkIdType distPtsId=0;
438 vtkIdType distPtsIds[4];
439 for(i=0; i<numColors; i++) {
441 itemH = distrHeight*((double)myNbValues[i]/maxValue);
443 if(distrHeight == itemH)
444 itemH = itemH - delimeter/2;
446 x[1] = i*delta+shrink;
448 // first point of polygon (quadrangle)
450 distPtsIds[0] = distPtsId;
451 distrPts->SetPoint(distPtsId++,x);
453 // second point of polygon (quadrangle)
455 distPtsIds[1] = distPtsId;
456 distrPts->SetPoint(distPtsId++,x);
458 x[1] = i*delta+delta-shrink;
460 // third point of polygon (quadrangle)
462 distPtsIds[3] = distPtsId;
463 distrPts->SetPoint(distPtsId++,x);
465 // fourth point of polygon (quadrangle)
467 distPtsIds[2] = distPtsId;
468 distrPts->SetPoint(distPtsId++,x);
471 distrPolys->InsertNextCell(4,distPtsIds);
481 // Customization of the vtkScalarBarActor to show distribution histogram.
482 double coef1, delimeter=0.0;
483 if(GetDistributionVisibility() && distrVisibility) {
485 distrHeight = (int)((coef1/2)*size[1]);
486 //delimeter between distribution diagram and scalar bar
487 delimeter=0.02*size[1];
491 barHeight = (int)(coef1*size[1]);
495 barHeight = (int)(coef1*size[1]);
497 delta=(double)barWidth/numColors;
498 for (i=0; i<numPts/2; i++) {
501 pts->SetPoint(2*i,x);
502 x[1] = distrHeight + delimeter;
503 pts->SetPoint(2*i+1,x);
506 if(GetDistributionVisibility() && distrVisibility) {
507 // Distribution points
508 shrink = delta*SHRINK_COEF;
509 vtkIdType distPtsId=0;
510 vtkIdType distPtsIds[4];
511 for(i=0; i<numColors; i++) {
513 itemH = distrHeight*((double)myNbValues[i]/maxValue);
515 // first point of polygon (quadrangle)
516 x[0] = i*delta+shrink;
518 distPtsIds[0] = distPtsId;
519 distrPts->SetPoint(distPtsId++,x);
521 // second point of polygon (quadrangle)
522 x[0] = i*delta+shrink;
524 distPtsIds[3] = distPtsId;
525 distrPts->SetPoint(distPtsId++,x);
527 // third point of polygon (quadrangle)
528 x[0] = i*delta+delta-shrink;
530 distPtsIds[1] = distPtsId;
531 distrPts->SetPoint(distPtsId++,x);
533 // fourth point of polygon (quadrangle)
534 x[0] = i*delta+delta-shrink;
536 distPtsIds[2] = distPtsId;
537 distrPts->SetPoint(distPtsId++,x);
539 // Add polygon into poly data
540 distrPolys->InsertNextCell(4,distPtsIds);
547 //polygons & cell colors
548 unsigned char *rgba, *rgb;
549 vtkIdType ptIds[4], dcCount=0;
550 for (i=0; i<numColors; i++)
553 ptIds[1] = ptIds[0] + 1;
554 ptIds[2] = ptIds[1] + 2;
555 ptIds[3] = ptIds[0] + 2;
556 polys->InsertNextCell(4,ptIds);
560 double rgbval = log10(range[0]) +
561 i*(log10(range[1])-log10(range[0]))/(numColors -1);
562 rgba = lut->MapValue(pow(10.0,rgbval));
566 rgba = lut->MapValue(range[0] + (range[1] - range[0])*
567 ((double)i /(numColors-1.0)));
570 rgb = colors->GetPointer(3*i); //write into array directly
576 // Customization of the vtkScalarBarActor to show distribution histogram.
577 if(myNbValues[i] && myDistributionColoringType == SMESH_MULTICOLOR_TYPE && GetDistributionVisibility() && distrVisibility)
579 rgb = distColors->GetPointer(3*dcCount); //write into array directly
587 // Now position everything properly
590 if (this->Orientation == VTK_ORIENT_VERTICAL)
595 this->TitleActor->SetPosition(size[0]/2, 0.9*size[1]);
597 for (i=0; i < this->NumberOfLabels; i++)
599 if (this->NumberOfLabels > 1)
601 val = (double)i/(this->NumberOfLabels-1) *barHeight;
607 this->TextMappers[i]->GetSize(viewport,sizeTextData);
608 this->TextMappers[i]->GetTextProperty()->SetJustificationToLeft();
609 this->TextActors[i]->SetPosition(barWidth+3,
610 val - sizeTextData[1]/2);
615 this->TitleActor->SetPosition(size[0]/2,
616 barHeight + labelSize[1] + 0.1*size[1]);
617 for (i=0; i < this->NumberOfLabels; i++)
619 this->TextMappers[i]->GetTextProperty()->SetJustificationToCentered();
620 if (this->NumberOfLabels > 1)
622 val = (double)i/(this->NumberOfLabels-1) * barWidth;
628 this->TextActors[i]->SetPosition(val, barHeight + 0.05*size[1]);
632 this->BuildTime.Modified();
635 // Everything is built, just have to render
636 if (this->Title != NULL)
638 renderedSomething += this->TitleActor->RenderOpaqueGeometry(viewport);
640 this->ScalarBarActor->RenderOpaqueGeometry(viewport);
641 this->myDistributionActor->RenderOpaqueGeometry(viewport);
642 for (i=0; i<this->NumberOfLabels; i++)
644 renderedSomething += this->TextActors[i]->RenderOpaqueGeometry(viewport);
647 renderedSomething = (renderedSomething > 0)?(1):(0);
649 return renderedSomething;
652 //----------------------------------------------------------------------------
653 void SMESH_ScalarBarActor::PrintSelf(ostream& os, vtkIndent indent)
655 this->Superclass::PrintSelf(os,indent);
657 if ( this->LookupTable )
659 os << indent << "Lookup Table:\n";
660 this->LookupTable->PrintSelf(os,indent.GetNextIndent());
664 os << indent << "Lookup Table: (none)\n";
667 if (this->TitleTextProperty)
669 os << indent << "Title Text Property:\n";
670 this->TitleTextProperty->PrintSelf(os,indent.GetNextIndent());
674 os << indent << "Title Text Property: (none)\n";
677 if (this->LabelTextProperty)
679 os << indent << "Label Text Property:\n";
680 this->LabelTextProperty->PrintSelf(os,indent.GetNextIndent());
684 os << indent << "Label Text Property: (none)\n";
687 os << indent << "Title: " << (this->Title ? this->Title : "(none)") << "\n";
688 os << indent << "Maximum Number Of Colors: "
689 << this->MaximumNumberOfColors << "\n";
690 os << indent << "Number Of Labels: " << this->NumberOfLabels << "\n";
691 os << indent << "Number Of Labels Built: " << this->NumberOfLabelsBuilt << "\n";
693 os << indent << "Orientation: ";
694 if ( this->Orientation == VTK_ORIENT_HORIZONTAL )
696 os << "Horizontal\n";
703 os << indent << "Label Format: " << this->LabelFormat << "\n";
706 //----------------------------------------------------------------------------
707 void SMESH_ScalarBarActor::ShallowCopy(vtkProp *prop)
709 SMESH_ScalarBarActor *a = SMESH_ScalarBarActor::SafeDownCast(prop);
712 this->SetPosition2(a->GetPosition2());
713 this->SetLookupTable(a->GetLookupTable());
714 this->SetMaximumNumberOfColors(a->GetMaximumNumberOfColors());
715 this->SetOrientation(a->GetOrientation());
716 this->SetLabelTextProperty(a->GetLabelTextProperty());
717 this->SetTitleTextProperty(a->GetTitleTextProperty());
718 this->SetLabelFormat(a->GetLabelFormat());
719 this->SetTitle(a->GetTitle());
720 this->GetPositionCoordinate()->SetCoordinateSystem(
721 a->GetPositionCoordinate()->GetCoordinateSystem());
722 this->GetPositionCoordinate()->SetValue(
723 a->GetPositionCoordinate()->GetValue());
724 this->GetPosition2Coordinate()->SetCoordinateSystem(
725 a->GetPosition2Coordinate()->GetCoordinateSystem());
726 this->GetPosition2Coordinate()->SetValue(
727 a->GetPosition2Coordinate()->GetValue());
731 this->vtkActor2D::ShallowCopy(prop);
734 //----------------------------------------------------------------------------
735 void SMESH_ScalarBarActor::AllocateAndSizeLabels(int *labelSize,
737 vtkViewport *viewport,
740 labelSize[0] = labelSize[1] = 0;
742 this->TextMappers = new vtkTextMapper * [this->NumberOfLabels];
743 this->TextActors = new vtkActor2D * [this->NumberOfLabels];
750 // TODO: this should be optimized, maybe by keeping a list of
751 // allocated mappers, in order to avoid creation/destruction of
752 // their underlying text properties (i.e. each time a mapper is
753 // created, text properties are created and shallow-assigned a font size
754 // which value might be "far" from the target font size).
756 // is this a vtkLookupTable or a subclass of vtkLookupTable
757 // with its scale set to log
758 vtkLookupTable *LUT = vtkLookupTable::SafeDownCast( this->LookupTable );
762 if ( LUT->GetScale() == VTK_SCALE_LOG10 )
768 for (i=0; i < this->NumberOfLabels; i++)
770 this->TextMappers[i] = vtkTextMapper::New();
775 if (this->NumberOfLabels > 1)
777 lval = log10(range[0]) + (double)i/(this->NumberOfLabels-1) *
778 (log10(range[1])-log10(range[0]));
782 lval = log10(range[0]) + 0.5*(log10(range[1])-log10(range[0]));
784 val = pow(10.0,lval);
788 if (this->NumberOfLabels > 1)
791 (double)i/(this->NumberOfLabels-1) * (range[1]-range[0]);
795 val = range[0] + 0.5*(range[1]-range[0]);
799 sprintf(string, this->LabelFormat, val);
800 this->TextMappers[i]->SetInput(string);
802 // Shallow copy here so that the size of the label prop is not affected
803 // by the automatic adjustment of its text mapper's size (i.e. its
804 // mapper's text property is identical except for the font size
805 // which will be modified later). This allows text actors to
806 // share the same text property, and in that case specifically allows
807 // the title and label text prop to be the same.
808 this->TextMappers[i]->GetTextProperty()->ShallowCopy(
809 this->LabelTextProperty);
811 this->TextActors[i] = vtkActor2D::New();
812 this->TextActors[i]->SetMapper(this->TextMappers[i]);
813 this->TextActors[i]->SetProperty(this->GetProperty());
814 this->TextActors[i]->GetPositionCoordinate()->
815 SetReferenceCoordinate(this->PositionCoordinate);
818 if (this->NumberOfLabels)
820 int targetWidth, targetHeight;
822 // Customization of the vtkScalarBarActor to show distribution histogram.
823 bool distrVisibility = this->MaximumNumberOfColors == this->myNbValues.size();
825 if( GetDistributionVisibility() && distrVisibility )
826 if(this->Orientation == VTK_ORIENT_VERTICAL)
831 if(this->Orientation == VTK_ORIENT_VERTICAL)
837 if ( this->Orientation == VTK_ORIENT_VERTICAL )
839 targetWidth = (int)(coef*size[0]);
840 targetHeight = (int)(0.86*size[1]/this->NumberOfLabels);
844 targetWidth = (int)(size[0]*0.8/this->NumberOfLabels);
845 targetHeight = (int)(coef*size[1]);
849 vtkTextMapper::SetMultipleConstrainedFontSize(viewport,
853 this->NumberOfLabels,
858 //----------------------------------------------------------------------------
859 void SMESH_ScalarBarActor::SizeTitle(int *titleSize,
861 vtkViewport *viewport)
863 titleSize[0] = titleSize[1] = 0;
865 if (this->Title == NULL || !strlen(this->Title))
870 int targetWidth, targetHeight;
872 targetWidth = size[0];
874 // Customization of the vtkScalarBarActor to show distribution histogram.
875 bool distrVisibility = this->MaximumNumberOfColors == this->myNbValues.size();
877 if( GetDistributionVisibility() && distrVisibility )
882 if ( this->Orientation == VTK_ORIENT_VERTICAL )
884 targetHeight = (int)(0.1*size[1]);
888 targetHeight = (int)(coef*size[1]);
891 this->TitleMapper->SetConstrainedFontSize(
892 viewport, targetWidth, targetHeight);
894 this->TitleMapper->GetSize(viewport, titleSize);
898 /*--------------------------------------------------------------------------*/
899 void SMESH_ScalarBarActor::SetDistributionVisibility(int flag) {
900 myDistributionActor->SetVisibility(flag);
905 /*--------------------------------------------------------------------------*/
906 int SMESH_ScalarBarActor::GetDistributionVisibility() {
907 return myDistributionActor->GetVisibility();
911 void SMESH_ScalarBarActor::SetDistribution(std::vector<int> theNbValues) {
912 myNbValues = theNbValues;
916 void SMESH_ScalarBarActor::SetDistributionColor (double rgb[3]) {
917 myDistributionActor->GetProperty()->SetColor(rgb);
921 void SMESH_ScalarBarActor::GetDistributionColor (double rgb[3]) {
922 myDistributionActor->GetProperty()->GetColor(rgb);