1 // Copyright (C) 2007-2016 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 <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;
119 // By default scalar map is shown
120 myTitleOnlyVisibility = false;
124 //----------------------------------------------------------------------------
125 // Release any graphics resources that are being consumed by this actor.
126 // The parameter window could be used to determine which graphic
127 // resources to release.
128 void SMESH_ScalarBarActor::ReleaseGraphicsResources(vtkWindow *win)
130 this->TitleActor->ReleaseGraphicsResources(win);
131 if (this->TextMappers != NULL )
133 for (int i=0; i < this->NumberOfLabelsBuilt; i++)
135 this->TextActors[i]->ReleaseGraphicsResources(win);
138 this->ScalarBarActor->ReleaseGraphicsResources(win);
140 // Customization of the vtkScalarBarActor to show distribution histogram.
141 myDistributionActor->ReleaseGraphicsResources(win);
145 /*--------------------------------------------------------------------------*/
146 SMESH_ScalarBarActor::~SMESH_ScalarBarActor() {
147 if (this->LabelFormat)
149 delete [] this->LabelFormat;
150 this->LabelFormat = NULL;
153 this->TitleMapper->Delete();
154 this->TitleActor->Delete();
156 if (this->TextMappers != NULL )
158 for (int i=0; i < this->NumberOfLabelsBuilt; i++)
160 this->TextMappers[i]->Delete();
161 this->TextActors[i]->Delete();
163 delete [] this->TextMappers;
164 delete [] this->TextActors;
167 this->ScalarBar->Delete();
168 this->ScalarBarMapper->Delete();
169 this->ScalarBarActor->Delete();
173 delete [] this->Title;
177 this->SetLookupTable(NULL);
178 this->SetLabelTextProperty(NULL);
179 this->SetTitleTextProperty(NULL);
182 // Customization of the vtkScalarBarActor to show distribution histogram:
183 myDistribution->Delete();
184 myDistributionMapper->Delete();
185 myDistributionActor->Delete();
189 //----------------------------------------------------------------------------
190 int SMESH_ScalarBarActor::RenderOverlay(vtkViewport *viewport)
192 int renderedSomething = 0;
195 // Everything is built, just have to render
196 if (this->Title != NULL)
198 renderedSomething += this->TitleActor->RenderOverlay(viewport);
200 if (!myTitleOnlyVisibility) {
201 this->ScalarBarActor->RenderOverlay(viewport);
202 this->myDistributionActor->RenderOverlay(viewport);
203 if( this->TextActors == NULL)
205 vtkWarningMacro(<<"Need a mapper to render a scalar bar");
206 return renderedSomething;
209 for (i=0; i<this->NumberOfLabels; i++)
211 renderedSomething += this->TextActors[i]->RenderOverlay(viewport);
214 renderedSomething = (renderedSomething > 0)?(1):(0);
216 return renderedSomething;
220 //----------------------------------------------------------------------------
221 int SMESH_ScalarBarActor::RenderOpaqueGeometry(vtkViewport *viewport)
223 int renderedSomething = 0;
227 if (!this->LookupTable)
229 vtkWarningMacro(<<"Need a mapper to render a scalar bar");
233 if (!this->TitleTextProperty)
235 vtkErrorMacro(<<"Need title text property to render a scalar bar");
239 if (!this->LabelTextProperty)
241 vtkErrorMacro(<<"Need label text property to render a scalar bar");
245 // Check to see whether we have to rebuild everything
246 int positionsHaveChanged = 0;
247 if (viewport->GetMTime() > this->BuildTime ||
248 (viewport->GetVTKWindow() &&
249 viewport->GetVTKWindow()->GetMTime() > this->BuildTime))
251 // if the viewport has changed we may - or may not need
252 // to rebuild, it depends on if the projected coords chage
254 barOrigin = this->PositionCoordinate->GetComputedViewportValue(viewport);
256 this->Position2Coordinate->GetComputedViewportValue(viewport)[0] -
259 this->Position2Coordinate->GetComputedViewportValue(viewport)[1] -
261 if (this->LastSize[0] != size[0] ||
262 this->LastSize[1] != size[1] ||
263 this->LastOrigin[0] != barOrigin[0] ||
264 this->LastOrigin[1] != barOrigin[1])
266 positionsHaveChanged = 1;
270 // Check to see whether we have to rebuild everything
271 if (positionsHaveChanged ||
272 this->GetMTime() > this->BuildTime ||
273 this->LookupTable->GetMTime() > this->BuildTime ||
274 this->LabelTextProperty->GetMTime() > this->BuildTime ||
275 this->TitleTextProperty->GetMTime() > this->BuildTime)
277 vtkDebugMacro(<<"Rebuilding subobjects");
279 // Delete previously constructed objects
281 if (this->TextMappers != NULL )
283 for (i=0; i < this->NumberOfLabelsBuilt; i++)
285 this->TextMappers[i]->Delete();
286 this->TextActors[i]->Delete();
288 delete [] this->TextMappers;
289 delete [] this->TextActors;
292 // Build scalar bar object; determine its type
294 // is this a vtkLookupTable or a subclass of vtkLookupTable
295 // with its scale set to log
296 // NOTE: it's possible we could to without the 'lut' variable
297 // later in the code, but if the vtkLookupTableSafeDownCast operation
298 // fails for some reason, this code will break in new ways. So, the 'LUT'
299 // variable is used for this operation only
300 vtkLookupTable *LUT = vtkLookupTable::SafeDownCast( this->LookupTable );
304 if ( LUT->GetScale() == VTK_SCALE_LOG10 )
310 // we hard code how many steps to display
311 vtkScalarsToColors *lut = this->LookupTable;
312 int numColors = this->MaximumNumberOfColors;
313 double *range = lut->GetRange();
315 int numPts = 2*(numColors + 1);
316 vtkPoints *pts = vtkPoints::New();
317 pts->SetNumberOfPoints(numPts);
318 vtkCellArray *polys = vtkCellArray::New();
319 polys->Allocate(polys->EstimateSize(numColors,4));
320 vtkUnsignedCharArray *colors = vtkUnsignedCharArray::New();
321 colors->SetNumberOfComponents(3);
322 colors->SetNumberOfTuples(numColors);
326 // Customization of the vtkScalarBarActor to show distribution histogram.
327 bool distrVisibility = (numColors == (int)this->myNbValues.size());
328 vtkPoints *distrPts = 0;
329 vtkCellArray *distrPolys = 0;
330 vtkUnsignedCharArray *distColors = 0;
331 int numDistrPts = 0, numPositiveVal=0, maxValue=0;
333 vtkDebugMacro(<<" Distribution invisible, because numColors == this->myNbValues.size()");
335 if ( distrVisibility && GetDistributionVisibility() ) {
336 for ( i = 0 ; i < (int)myNbValues.size(); i++ ) {
337 if ( myNbValues[i] ) {
339 maxValue = std::max(maxValue,myNbValues[i]);
342 numDistrPts = 4*(numPositiveVal);
343 distrPts = vtkPoints::New();
344 distrPolys = vtkCellArray::New();
345 distrPts->SetNumberOfPoints(numDistrPts);
346 distrPolys->Allocate(distrPolys->EstimateSize(numPositiveVal,4));
347 this->myDistribution->Initialize();
348 this->myDistribution->SetPoints(distrPts);
349 this->myDistribution->SetPolys(distrPolys);
351 distrPolys->Delete();
352 if ( myDistributionColoringType == SMESH_MULTICOLOR_TYPE ) {
353 distColors = vtkUnsignedCharArray::New();
354 distColors->SetNumberOfComponents(3);
355 distColors->SetNumberOfTuples(numPositiveVal);
356 this->myDistribution->GetCellData()->SetScalars(distColors);
357 distColors->Delete();
358 } else if( myDistributionColoringType == SMESH_MONOCOLOR_TYPE ){
359 this->myDistribution->GetCellData()->SetScalars(NULL);
362 myDistribution->Reset();
366 this->ScalarBarActor->SetProperty(this->GetProperty());
367 this->ScalarBar->Initialize();
368 this->ScalarBar->SetPoints(pts);
369 this->ScalarBar->SetPolys(polys);
370 this->ScalarBar->GetCellData()->SetScalars(colors);
371 pts->Delete(); polys->Delete(); colors->Delete();
373 // get the viewport size in display coordinates
374 int *barOrigin, barWidth, barHeight, distrHeight;
375 barOrigin = this->PositionCoordinate->GetComputedViewportValue(viewport);
377 this->Position2Coordinate->GetComputedViewportValue(viewport)[0] -
380 this->Position2Coordinate->GetComputedViewportValue(viewport)[1] -
382 this->LastOrigin[0] = barOrigin[0];
383 this->LastOrigin[1] = barOrigin[1];
384 this->LastSize[0] = size[0];
385 this->LastSize[1] = size[1];
387 // Update all the composing objects
388 this->TitleActor->SetProperty(this->GetProperty());
389 this->TitleMapper->SetInput(this->Title);
390 if (this->TitleTextProperty->GetMTime() > this->BuildTime)
392 // Shallow copy here so that the size of the title prop is not affected
393 // by the automatic adjustment of its text mapper's size (i.e. its
394 // mapper's text property is identical except for the font size
395 // which will be modified later). This allows text actors to
396 // share the same text property, and in that case specifically allows
397 // the title and label text prop to be the same.
398 this->TitleMapper->GetTextProperty()->ShallowCopy(this->TitleTextProperty);
399 this->TitleMapper->GetTextProperty()->SetJustificationToCentered();
402 // find the best size for the title font
404 this->SizeTitle(titleSize, size, viewport);
406 // find the best size for the ticks
408 this->AllocateAndSizeLabels(labelSize, size, viewport,range);
409 this->NumberOfLabelsBuilt = this->NumberOfLabels;
412 double x[3]; x[2] = 0.0;
413 double delta, itemH, shrink;
414 if ( this->Orientation == VTK_ORIENT_VERTICAL ) {
416 // Customization of the vtkScalarBarActor to show distribution histogram.
417 double delimeter=0.0;
418 if(GetDistributionVisibility() && distrVisibility) {
419 delimeter=0.01*size[0]; //1 % from horizontal size of the full presentation size.
420 barWidth = size[0] - 4 - labelSize[0];
421 distrHeight = barWidth/2;
423 barWidth = size[0] - 4 - labelSize[0];
427 barHeight = (int)(0.86*size[1]);
428 delta=(double)barHeight/numColors;
430 for ( i=0; i<numPts/2; i++ ) {
431 x[0] = distrHeight+delimeter/2.0;
433 pts->SetPoint(2*i,x);
435 pts->SetPoint(2*i+1,x);
438 if(GetDistributionVisibility() && distrVisibility) {
439 // Distribution points
440 shrink = delta*SHRINK_COEF;
441 vtkIdType distPtsId=0;
442 vtkIdType distPtsIds[4];
443 for(i=0; i<numColors; i++) {
445 itemH = distrHeight*((double)myNbValues[i]/maxValue);
447 if(distrHeight == itemH)
448 itemH = itemH - delimeter/2;
450 x[1] = i*delta+shrink;
452 // first point of polygon (quadrangle)
454 distPtsIds[0] = distPtsId;
455 distrPts->SetPoint(distPtsId++,x);
457 // second point of polygon (quadrangle)
459 distPtsIds[1] = distPtsId;
460 distrPts->SetPoint(distPtsId++,x);
462 x[1] = i*delta+delta-shrink;
464 // third point of polygon (quadrangle)
466 distPtsIds[3] = distPtsId;
467 distrPts->SetPoint(distPtsId++,x);
469 // fourth point of polygon (quadrangle)
471 distPtsIds[2] = distPtsId;
472 distrPts->SetPoint(distPtsId++,x);
475 distrPolys->InsertNextCell(4,distPtsIds);
485 // Customization of the vtkScalarBarActor to show distribution histogram.
486 double coef1, delimeter=0.0;
487 if(GetDistributionVisibility() && distrVisibility) {
489 distrHeight = (int)((coef1/2)*size[1]);
490 //delimeter between distribution diagram and scalar bar
491 delimeter=0.02*size[1];
495 barHeight = (int)(coef1*size[1]);
499 barHeight = (int)(coef1*size[1]);
501 delta=(double)barWidth/numColors;
502 for (i=0; i<numPts/2; i++) {
505 pts->SetPoint(2*i,x);
506 x[1] = distrHeight + delimeter;
507 pts->SetPoint(2*i+1,x);
510 if(GetDistributionVisibility() && distrVisibility) {
511 // Distribution points
512 shrink = delta*SHRINK_COEF;
513 vtkIdType distPtsId=0;
514 vtkIdType distPtsIds[4];
515 for(i=0; i<numColors; i++) {
517 itemH = distrHeight*((double)myNbValues[i]/maxValue);
519 // first point of polygon (quadrangle)
520 x[0] = i*delta+shrink;
522 distPtsIds[0] = distPtsId;
523 distrPts->SetPoint(distPtsId++,x);
525 // second point of polygon (quadrangle)
526 x[0] = i*delta+shrink;
528 distPtsIds[3] = distPtsId;
529 distrPts->SetPoint(distPtsId++,x);
531 // third point of polygon (quadrangle)
532 x[0] = i*delta+delta-shrink;
534 distPtsIds[1] = distPtsId;
535 distrPts->SetPoint(distPtsId++,x);
537 // fourth point of polygon (quadrangle)
538 x[0] = i*delta+delta-shrink;
540 distPtsIds[2] = distPtsId;
541 distrPts->SetPoint(distPtsId++,x);
543 // Add polygon into poly data
544 distrPolys->InsertNextCell(4,distPtsIds);
551 //polygons & cell colors
552 unsigned char *rgba, *rgb;
553 vtkIdType ptIds[4], dcCount=0;
554 for (i=0; i<numColors; i++)
557 ptIds[1] = ptIds[0] + 1;
558 ptIds[2] = ptIds[1] + 2;
559 ptIds[3] = ptIds[0] + 2;
560 polys->InsertNextCell(4,ptIds);
564 double rgbval = log10(range[0]) +
565 i*(log10(range[1])-log10(range[0]))/(numColors -1);
566 rgba = lut->MapValue(pow(10.0,rgbval));
570 rgba = lut->MapValue(range[0] + (range[1] - range[0])*
571 ((double)i /(numColors-1.0)));
574 rgb = colors->GetPointer(3*i); //write into array directly
580 // Customization of the vtkScalarBarActor to show distribution histogram.
581 if ( myDistributionColoringType == SMESH_MULTICOLOR_TYPE &&
582 GetDistributionVisibility() &&
586 rgb = distColors->GetPointer(3*dcCount); //write into array directly
594 // Now position everything properly
597 if (this->Orientation == VTK_ORIENT_VERTICAL)
602 this->TitleActor->SetPosition(size[0]/2, 0.9*size[1]);
604 for (i=0; i < this->NumberOfLabels; i++)
606 if (this->NumberOfLabels > 1)
608 val = (double)i/(this->NumberOfLabels-1) *barHeight;
614 this->TextMappers[i]->GetSize(viewport,sizeTextData);
615 this->TextMappers[i]->GetTextProperty()->SetJustificationToLeft();
616 this->TextActors[i]->SetPosition(barWidth+3,
617 val - sizeTextData[1]/2);
622 this->TitleActor->SetPosition(size[0]/2,
623 barHeight + labelSize[1] + 0.1*size[1]);
624 for (i=0; i < this->NumberOfLabels; i++)
626 this->TextMappers[i]->GetTextProperty()->SetJustificationToCentered();
627 if (this->NumberOfLabels > 1)
629 val = (double)i/(this->NumberOfLabels-1) * barWidth;
635 this->TextActors[i]->SetPosition(val, barHeight + 0.05*size[1]);
639 this->BuildTime.Modified();
642 // Everything is built, just have to render
643 if (this->Title != NULL)
645 renderedSomething += this->TitleActor->RenderOpaqueGeometry(viewport);
647 this->ScalarBarActor->RenderOpaqueGeometry(viewport);
648 this->myDistributionActor->RenderOpaqueGeometry(viewport);
649 for (i=0; i<this->NumberOfLabels; i++)
651 renderedSomething += this->TextActors[i]->RenderOpaqueGeometry(viewport);
654 renderedSomething = (renderedSomething > 0)?(1):(0);
656 return renderedSomething;
659 //----------------------------------------------------------------------------
660 void SMESH_ScalarBarActor::PrintSelf(ostream& os, vtkIndent indent)
662 this->Superclass::PrintSelf(os,indent);
664 if ( this->LookupTable )
666 os << indent << "Lookup Table:\n";
667 this->LookupTable->PrintSelf(os,indent.GetNextIndent());
671 os << indent << "Lookup Table: (none)\n";
674 if (this->TitleTextProperty)
676 os << indent << "Title Text Property:\n";
677 this->TitleTextProperty->PrintSelf(os,indent.GetNextIndent());
681 os << indent << "Title Text Property: (none)\n";
684 if (this->LabelTextProperty)
686 os << indent << "Label Text Property:\n";
687 this->LabelTextProperty->PrintSelf(os,indent.GetNextIndent());
691 os << indent << "Label Text Property: (none)\n";
694 os << indent << "Title: " << (this->Title ? this->Title : "(none)") << "\n";
695 os << indent << "Maximum Number Of Colors: "
696 << this->MaximumNumberOfColors << "\n";
697 os << indent << "Number Of Labels: " << this->NumberOfLabels << "\n";
698 os << indent << "Number Of Labels Built: " << this->NumberOfLabelsBuilt << "\n";
700 os << indent << "Orientation: ";
701 if ( this->Orientation == VTK_ORIENT_HORIZONTAL )
703 os << "Horizontal\n";
710 os << indent << "Label Format: " << this->LabelFormat << "\n";
713 //----------------------------------------------------------------------------
714 void SMESH_ScalarBarActor::ShallowCopy(vtkProp *prop)
716 SMESH_ScalarBarActor *a = SMESH_ScalarBarActor::SafeDownCast(prop);
719 this->SetPosition2(a->GetPosition2());
720 this->SetLookupTable(a->GetLookupTable());
721 this->SetMaximumNumberOfColors(a->GetMaximumNumberOfColors());
722 this->SetOrientation(a->GetOrientation());
723 this->SetLabelTextProperty(a->GetLabelTextProperty());
724 this->SetTitleTextProperty(a->GetTitleTextProperty());
725 this->SetLabelFormat(a->GetLabelFormat());
726 this->SetTitle(a->GetTitle());
727 this->GetPositionCoordinate()->SetCoordinateSystem(
728 a->GetPositionCoordinate()->GetCoordinateSystem());
729 this->GetPositionCoordinate()->SetValue(
730 a->GetPositionCoordinate()->GetValue());
731 this->GetPosition2Coordinate()->SetCoordinateSystem(
732 a->GetPosition2Coordinate()->GetCoordinateSystem());
733 this->GetPosition2Coordinate()->SetValue(
734 a->GetPosition2Coordinate()->GetValue());
738 this->vtkActor2D::ShallowCopy(prop);
741 //----------------------------------------------------------------------------
742 void SMESH_ScalarBarActor::AllocateAndSizeLabels(int *labelSize,
744 vtkViewport *viewport,
747 labelSize[0] = labelSize[1] = 0;
749 this->TextMappers = new vtkTextMapper * [this->NumberOfLabels];
750 this->TextActors = new vtkActor2D * [this->NumberOfLabels];
757 // TODO: this should be optimized, maybe by keeping a list of
758 // allocated mappers, in order to avoid creation/destruction of
759 // their underlying text properties (i.e. each time a mapper is
760 // created, text properties are created and shallow-assigned a font size
761 // which value might be "far" from the target font size).
763 // is this a vtkLookupTable or a subclass of vtkLookupTable
764 // with its scale set to log
765 vtkLookupTable *LUT = vtkLookupTable::SafeDownCast( this->LookupTable );
769 if ( LUT->GetScale() == VTK_SCALE_LOG10 )
775 for (i=0; i < this->NumberOfLabels; i++)
777 this->TextMappers[i] = vtkTextMapper::New();
782 if (this->NumberOfLabels > 1)
784 lval = log10(range[0]) + (double)i/(this->NumberOfLabels-1) *
785 (log10(range[1])-log10(range[0]));
789 lval = log10(range[0]) + 0.5*(log10(range[1])-log10(range[0]));
791 val = pow(10.0,lval);
795 if (this->NumberOfLabels > 1)
798 (double)i/(this->NumberOfLabels-1) * (range[1]-range[0]);
802 val = range[0] + 0.5*(range[1]-range[0]);
806 sprintf(string, this->LabelFormat, val);
807 this->TextMappers[i]->SetInput(string);
809 // Shallow copy here so that the size of the label prop is not affected
810 // by the automatic adjustment of its text mapper's size (i.e. its
811 // mapper's text property is identical except for the font size
812 // which will be modified later). This allows text actors to
813 // share the same text property, and in that case specifically allows
814 // the title and label text prop to be the same.
815 this->TextMappers[i]->GetTextProperty()->ShallowCopy(
816 this->LabelTextProperty);
818 this->TextActors[i] = vtkActor2D::New();
819 this->TextActors[i]->SetMapper(this->TextMappers[i]);
820 this->TextActors[i]->SetProperty(this->GetProperty());
821 this->TextActors[i]->GetPositionCoordinate()->
822 SetReferenceCoordinate(this->PositionCoordinate);
825 if (this->NumberOfLabels)
827 int targetWidth, targetHeight;
829 // Customization of the vtkScalarBarActor to show distribution histogram.
830 bool distrVisibility = ( this->MaximumNumberOfColors == (int) this->myNbValues.size() );
832 if( GetDistributionVisibility() && distrVisibility )
833 if(this->Orientation == VTK_ORIENT_VERTICAL)
838 if(this->Orientation == VTK_ORIENT_VERTICAL)
844 if ( this->Orientation == VTK_ORIENT_VERTICAL )
846 targetWidth = (int)(coef*size[0]);
847 targetHeight = (int)(0.86*size[1]/this->NumberOfLabels);
851 targetWidth = (int)(size[0]*0.8/this->NumberOfLabels);
852 targetHeight = (int)(coef*size[1]);
856 vtkTextMapper::SetMultipleConstrainedFontSize(viewport,
860 this->NumberOfLabels,
865 //----------------------------------------------------------------------------
866 void SMESH_ScalarBarActor::SizeTitle(int *titleSize,
868 vtkViewport *viewport)
870 titleSize[0] = titleSize[1] = 0;
872 if (this->Title == NULL || !strlen(this->Title))
877 int targetWidth, targetHeight;
879 targetWidth = size[0];
881 // Customization of the vtkScalarBarActor to show distribution histogram.
882 bool distrVisibility = ( this->MaximumNumberOfColors == (int) this->myNbValues.size() );
884 if ( GetDistributionVisibility() && distrVisibility )
889 if ( this->Orientation == VTK_ORIENT_VERTICAL )
891 targetHeight = (int)(0.1*size[1]);
895 targetHeight = (int)(coef*size[1]);
898 this->TitleMapper->SetConstrainedFontSize(viewport, targetWidth, targetHeight);
900 this->TitleMapper->GetSize(viewport, titleSize);
904 /*--------------------------------------------------------------------------*/
905 void SMESH_ScalarBarActor::SetDistributionVisibility(int flag) {
906 myDistributionActor->SetVisibility(flag);
911 /*--------------------------------------------------------------------------*/
912 int SMESH_ScalarBarActor::GetDistributionVisibility() {
913 return myDistributionActor->GetVisibility();
917 void SMESH_ScalarBarActor::SetDistribution(std::vector<int> theNbValues) {
918 myNbValues = theNbValues;
922 void SMESH_ScalarBarActor::SetDistributionColor (double rgb[3]) {
923 myDistributionActor->GetProperty()->SetColor(rgb);
927 void SMESH_ScalarBarActor::GetDistributionColor (double rgb[3]) {
928 myDistributionActor->GetProperty()->GetColor(rgb);
931 void SMESH_ScalarBarActor::SetTitleOnlyVisibility( bool theTitleOnlyVisibility) {
932 myTitleOnlyVisibility = theTitleOnlyVisibility;
935 bool SMESH_ScalarBarActor::GetTitleOnlyVisibility() {
936 return myTitleOnlyVisibility;