1 // Copyright (C) 2007-2008 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 // VISU OBJECT : interactive object for VISU entities implementation
23 // File: VISU_PipeLine.hxx
24 // Author: Alexey PETROV
27 #include "VISU_ScalarBarActor.hxx"
29 #include <vtkPolyDataMapper2D.h>
30 #include <vtkCellArray.h>
31 #include <vtkCellData.h>
32 #include <vtkObjectFactory.h>
33 #include <vtkPolyData.h>
34 #include <vtkPolyDataMapper2D.h>
35 #include <vtkScalarsToColors.h>
36 #include <vtkTextMapper.h>
37 #include <vtkTextProperty.h>
38 #include <vtkViewport.h>
39 #include <vtkWindow.h>
40 #include <vtkLogLookupTable.h>
41 #include <vtkProperty2D.h> // RKV
42 #include <vtkAxisActor2D.h> // RKV
46 vtkCxxRevisionMacro(VISU_ScalarBarActor, "$Revision$");
48 vtkCxxSetObjectMacro(VISU_ScalarBarActor,LookupTable,VISU_LookupTable);
49 vtkCxxSetObjectMacro(VISU_ScalarBarActor,LabelTextProperty,vtkTextProperty);
50 vtkCxxSetObjectMacro(VISU_ScalarBarActor,TitleTextProperty,vtkTextProperty);
52 //------------------------------------------------------------------------------
53 VISU_ScalarBarActor* VISU_ScalarBarActor::New(){
54 vtkObject* ret = vtkObjectFactory::CreateInstance("VISU_ScalarBarActor");
56 return (VISU_ScalarBarActor*)ret;
57 return new VISU_ScalarBarActor;
60 VISU_ScalarBarActor::VISU_ScalarBarActor()
62 this->LookupTable = NULL;
63 this->Position2Coordinate->SetValue(0.17, 0.8);
65 this->PositionCoordinate->SetCoordinateSystemToNormalizedViewport();
66 this->PositionCoordinate->SetValue(0.82,0.1);
68 this->MaximumNumberOfColors = 64;
69 this->NumberOfLabels = 5;
70 this->NumberOfLabelsBuilt = 0;
71 this->Orientation = VTK_ORIENT_VERTICAL;
74 this->LabelTextProperty = vtkTextProperty::New();
75 this->LabelTextProperty->SetFontSize(12);
76 this->LabelTextProperty->SetBold(1);
77 this->LabelTextProperty->SetItalic(1);
78 this->LabelTextProperty->SetShadow(1);
79 this->LabelTextProperty->SetFontFamilyToArial();
81 this->TitleTextProperty = vtkTextProperty::New();
82 this->TitleTextProperty->ShallowCopy(this->LabelTextProperty);
84 this->LabelFormat = new char[8];
85 sprintf(this->LabelFormat,"%s","%-#6.3g");
87 this->TitleMapper = vtkTextMapper::New();
88 this->TitleActor = vtkActor2D::New();
89 this->TitleActor->SetMapper(this->TitleMapper);
90 this->TitleActor->GetPositionCoordinate()->
91 SetReferenceCoordinate(this->PositionCoordinate);
93 this->TextMappers = NULL;
94 this->TextActors = NULL;
96 this->ScalarBar = vtkPolyData::New();
97 this->ScalarBarMapper = vtkPolyDataMapper2D::New();
98 this->ScalarBarMapper->SetInput(this->ScalarBar);
99 this->ScalarBarActor = vtkActor2D::New();
100 this->ScalarBarActor->SetMapper(this->ScalarBarMapper);
101 this->ScalarBarActor->GetPositionCoordinate()->
102 SetReferenceCoordinate(this->PositionCoordinate);
103 this->LastOrigin[0] = 0;
104 this->LastOrigin[1] = 0;
105 this->LastSize[0] = 0;
106 this->LastSize[1] = 0;
108 this->TitleRatioSize = 0;
109 this->LabelRatioWidth = 0;
110 this->BarRatioWidth = 0;
111 this->BarRatioHeight = 0;
114 this->Distribution = vtkDoubleArray::New();
115 this->DistributionObj = vtkDataObject::New();
116 this->DistributionActor = VISU_XYPlotActor::New();
117 this->DistributionActor->SetTitle("");
118 this->DistributionActor->SetXTitle("");
119 this->DistributionActor->SetYTitle("");
120 this->DistributionActor->GetXAxisActor2D()->LabelVisibilityOff();
121 this->DistributionActor->GetXAxisActor2D()->TitleVisibilityOff();
122 this->DistributionActor->GetXAxisActor2D()->TickVisibilityOff();
123 // this->DistributionActor->GetXAxisActor2D()->SetFontFactor(0.);
124 this->DistributionActor->SetNumberOfYLabels(1);
125 // this->DistributionActor->SetNumberOfXLabels(2);
126 this->DistributionActor->GetXAxisActor2D()->AdjustLabelsOff();
127 this->DistributionActor->GetYAxisActor2D()->AdjustLabelsOff();
128 this->DistributionActor->LegendOff();
129 this->DistributionActor->SetLabelFormat("%4.3f");
130 this->DistributionActor->SetXValuesToIndex();
131 // this->DistributionActor->GetPositionCoordinate()->SetValue(0.0, 0.67, 0);
132 // this->DistributionActor->GetPosition2Coordinate()->SetValue(1.0, 0.33, 0); // #relative to Position
133 this->DistributionActor->GetPositionCoordinate()->
134 SetReferenceCoordinate(this->PositionCoordinate);
135 this->DistributionVisibilityOff(); // Don't show the distribution curve by default
140 void VISU_ScalarBarActor::ReleaseGraphicsResources(vtkWindow *win)
142 this->TitleActor->ReleaseGraphicsResources(win);
143 if (this->TextMappers != NULL )
145 for (int i=0; i < this->NumberOfLabelsBuilt; i++)
147 this->TextActors[i]->ReleaseGraphicsResources(win);
150 this->ScalarBarActor->ReleaseGraphicsResources(win);
151 this->DistributionActor->ReleaseGraphicsResources(win); // RKV
154 VISU_ScalarBarActor::~VISU_ScalarBarActor()
156 if (this->LabelFormat)
158 delete [] this->LabelFormat;
159 this->LabelFormat = NULL;
162 this->TitleMapper->Delete();
163 this->TitleActor->Delete();
165 if (this->TextMappers != NULL )
167 for (int i=0; i < this->NumberOfLabelsBuilt; i++)
169 this->TextMappers[i]->Delete();
170 this->TextActors[i]->Delete();
172 delete [] this->TextMappers;
173 delete [] this->TextActors;
177 this->DistributionActor->Delete();
178 this->DistributionObj->Delete();
179 this->SetDistribution(NULL);
182 this->ScalarBar->Delete();
183 this->ScalarBarMapper->Delete();
184 this->ScalarBarActor->Delete();
188 delete [] this->Title;
192 this->SetLookupTable(NULL);
193 this->SetLabelTextProperty(NULL);
194 this->SetTitleTextProperty(NULL);
197 int VISU_ScalarBarActor::RenderOverlay(vtkViewport *viewport)
199 int renderedSomething = 0;
202 // Everything is built, just have to render
203 if (this->Title != NULL)
205 renderedSomething += this->TitleActor->RenderOverlay(viewport);
207 this->ScalarBarActor->RenderOverlay(viewport);
209 if (this->DistributionVisibility)
210 this->DistributionActor->RenderOverlay(viewport);
212 if( this->TextActors == NULL)
214 vtkWarningMacro(<<"Need a mapper to render a scalar bar");
215 return renderedSomething;
218 for (i=0; i<this->NumberOfLabels; i++)
220 renderedSomething += this->TextActors[i]->RenderOverlay(viewport);
223 renderedSomething = (renderedSomething > 0)?(1):(0);
225 return renderedSomething;
228 int VISU_ScalarBarActor::RenderOpaqueGeometry(vtkViewport *viewport)
230 int renderedSomething = 0;
234 if (!this->LookupTable)
236 vtkWarningMacro(<<"Need a mapper to render a scalar bar");
240 if (!this->TitleTextProperty)
242 vtkErrorMacro(<<"Need title text property to render a scalar bar");
246 if (!this->LabelTextProperty)
248 vtkErrorMacro(<<"Need label text property to render a scalar bar");
252 // Check to see whether we have to rebuild everything
253 int positionsHaveChanged = 0;
254 if (viewport->GetMTime() > this->BuildTime ||
255 (viewport->GetVTKWindow() &&
256 viewport->GetVTKWindow()->GetMTime() > this->BuildTime))
258 // if the viewport has changed we may - or may not need
259 // to rebuild, it depends on if the projected coords chage
261 barOrigin = this->PositionCoordinate->GetComputedViewportValue(viewport);
263 this->Position2Coordinate->GetComputedViewportValue(viewport)[0] -
266 this->Position2Coordinate->GetComputedViewportValue(viewport)[1] -
268 if (this->LastSize[0] != size[0] ||
269 this->LastSize[1] != size[1] ||
270 this->LastOrigin[0] != barOrigin[0] ||
271 this->LastOrigin[1] != barOrigin[1])
273 positionsHaveChanged = 1;
277 // Check to see whether we have to rebuild everything
279 if (positionsHaveChanged ||
280 this->GetMTime() > this->BuildTime ||
281 this->LookupTable->GetMTime() > this->BuildTime ||
282 this->LabelTextProperty->GetMTime() > this->BuildTime ||
283 this->TitleTextProperty->GetMTime() > this->BuildTime ||
284 this->Distribution->GetMTime() > this->BuildTime)
286 /* RKV if (positionsHaveChanged ||
287 this->GetMTime() > this->BuildTime ||
288 this->LookupTable->GetMTime() > this->BuildTime ||
289 this->LabelTextProperty->GetMTime() > this->BuildTime ||
290 this->TitleTextProperty->GetMTime() > this->BuildTime)*/
293 // Delete previously constructed objects
295 if (this->TextMappers != NULL )
297 for (i=0; i < this->NumberOfLabelsBuilt; i++)
299 this->TextMappers[i]->Delete();
300 this->TextActors[i]->Delete();
302 delete [] this->TextMappers;
303 delete [] this->TextActors;
306 // Build scalar bar object; determine its type
308 VISU_LookupTable *lut = this->LookupTable; //SALOME specific
309 int isLogTable = lut->GetScale() == VTK_SCALE_LOG10;
311 // we hard code how many steps to display
312 int numColors = this->MaximumNumberOfColors;
313 vtkFloatingPointType *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);
325 // If the distribution is changed then recalculate the total
326 if (this->Distribution->GetMTime() > this->BuildTime) {
327 int aNbVals = this->Distribution->GetNumberOfTuples();
329 this->Distribution->GetRange(range);
330 this->DistributionActor->SetYRange(0, range[1]);
332 for(vtkIdType aValId = 0; aValId < aNbVals; aValId++){
333 total += this->Distribution->GetValue(aValId);
335 this->DistributionActor->SetYRange(0, total);
339 this->DistributionActor->SetProperty(this->GetProperty());
340 this->DistributionActor->GetProperty()->SetColor(1, 1, 1);
341 this->DistributionActor->GetProperty()->SetLineWidth(2);
342 this->DistributionActor->GetProperty()->SetDisplayLocationToForeground();
343 vtkTextProperty* tprop;
344 tprop = this->DistributionActor->GetTitleTextProperty();
345 tprop->SetColor(this->DistributionActor->GetProperty()->GetColor());
346 // this->DistributionActor->SetAxisTitleTextProperty(tprop);
347 // this->DistributionActor->SetAxisLabelTextProperty(tprop);
350 this->ScalarBarActor->SetProperty(this->GetProperty());
351 this->ScalarBar->Initialize();
352 this->ScalarBar->SetPoints(pts);
353 this->ScalarBar->SetPolys(polys);
354 this->ScalarBar->GetCellData()->SetScalars(colors);
355 pts->Delete(); polys->Delete(); colors->Delete();
357 // get the viewport size in display coordinates
358 int *barOrigin, barWidth, barHeight;
359 barOrigin = this->PositionCoordinate->GetComputedViewportValue(viewport);
361 this->Position2Coordinate->GetComputedViewportValue(viewport)[0] -
364 this->Position2Coordinate->GetComputedViewportValue(viewport)[1] -
366 this->LastOrigin[0] = barOrigin[0];
367 this->LastOrigin[1] = barOrigin[1];
368 this->LastSize[0] = size[0];
369 this->LastSize[1] = size[1];
371 // Update all the composing objects
372 this->TitleActor->SetProperty(this->GetProperty());
373 this->TitleMapper->SetInput(this->Title);
374 if (this->TitleTextProperty->GetMTime() > this->BuildTime)
376 // Shallow copy here so that the size of the title prop is not affected
377 // by the automatic adjustment of its text mapper's size (i.e. its
378 // mapper's text property is identical except for the font size
379 // which will be modified later). This allows text actors to
380 // share the same text property, and in that case specifically allows
381 // the title and label text prop to be the same.
382 this->TitleMapper->GetTextProperty()->ShallowCopy(this->TitleTextProperty);
383 this->TitleMapper->GetTextProperty()->SetJustificationToCentered();
386 // find the best size for the title font
388 this->SizeTitle(titleSize, size, viewport);
390 // find the best size for the ticks
392 this->AllocateAndSizeLabels(labelSize, size, viewport, range);
393 this->NumberOfLabelsBuilt = this->NumberOfLabels;
395 this->SizeBar(barWidth, barHeight, size, viewport, range);
398 vtkFloatingPointType x[3]; x[2] = 0.0;
399 vtkFloatingPointType delta, val;
400 if ( this->Orientation == VTK_ORIENT_VERTICAL )
402 delta=(vtkFloatingPointType)barHeight/numColors;
403 for (i=0; i<numPts/2; i++)
407 pts->SetPoint(2*i,x);
409 pts->SetPoint(2*i+1,x);
414 delta=(vtkFloatingPointType)barWidth/numColors;
415 for (i=0; i<numPts/2; i++)
419 pts->SetPoint(2*i,x);
421 pts->SetPoint(2*i+1,x);
425 //polygons & cell colors
426 unsigned char *rgba, *rgb;
428 for (i=0; i<numColors; i++)
431 ptIds[1] = ptIds[0] + 1;
432 ptIds[2] = ptIds[1] + 2;
433 ptIds[3] = ptIds[0] + 2;
434 polys->InsertNextCell(4,ptIds);
436 if ( isLogTable ){ //SALOME specific
437 vtkFloatingPointType rgbval = log10(range[0]) +
438 i*(log10(range[1])-log10(range[0]))/(numColors -1);
439 rgba = lut->MapValue(rgbval);
441 rgba = lut->MapValue(range[0] + (range[1] - range[0])*
442 ((vtkFloatingPointType)i /(numColors-1.0)));
445 rgb = colors->GetPointer(3*i); //write into array directly
451 // Now position everything properly
453 if (this->Orientation == VTK_ORIENT_VERTICAL)
458 this->TitleActor->SetPosition(size[0]/2, 0.9*size[1]);
460 for (i=0; i < this->NumberOfLabels; i++)
462 val = (vtkFloatingPointType)i/(this->NumberOfLabels-1) *barHeight;
463 this->TextMappers[i]->GetSize(viewport,sizeTextData);
464 this->TextMappers[i]->GetTextProperty()->SetJustificationToLeft();
465 this->TextActors[i]->SetPosition(barWidth+3,
466 val - sizeTextData[1]/2);
472 this->TitleActor->SetPosition(size[0]/2,
473 barHeight + labelSize[1] + 0.1*size[1]);
474 for (i=0; i < this->NumberOfLabels; i++)
476 this->TextMappers[i]->GetTextProperty()->SetJustificationToCentered();
477 val = (vtkFloatingPointType)i/(this->NumberOfLabels-1) * barWidth;
478 this->TextActors[i]->SetPosition(val, barHeight + 0.05*size[1]);
483 // Compute the position of the distribution curve
484 this->PlaceDistribution(viewport, barWidth, barHeight); // RKV
486 this->BuildTime.Modified();
489 // Everything is built, just have to render
490 if (this->Title != NULL)
492 renderedSomething += this->TitleActor->RenderOpaqueGeometry(viewport);
494 this->ScalarBarActor->RenderOpaqueGeometry(viewport);
496 if (this->DistributionVisibility)
497 this->DistributionActor->RenderOpaqueGeometry(viewport);
499 for (i=0; i<this->NumberOfLabels; i++)
501 renderedSomething += this->TextActors[i]->RenderOpaqueGeometry(viewport);
504 renderedSomething = (renderedSomething > 0)?(1):(0);
506 return renderedSomething;
509 void VISU_ScalarBarActor::PrintSelf(ostream& os, vtkIndent indent)
511 this->Superclass::PrintSelf(os,indent);
513 if ( this->LookupTable )
515 os << indent << "Lookup Table:\n";
516 this->LookupTable->PrintSelf(os,indent.GetNextIndent());
520 os << indent << "Lookup Table: (none)\n";
523 if (this->TitleTextProperty)
525 os << indent << "Title Text Property:\n";
526 this->TitleTextProperty->PrintSelf(os,indent.GetNextIndent());
530 os << indent << "Title Text Property: (none)\n";
533 if (this->LabelTextProperty)
535 os << indent << "Label Text Property:\n";
536 this->LabelTextProperty->PrintSelf(os,indent.GetNextIndent());
540 os << indent << "Label Text Property: (none)\n";
543 os << indent << "Title: " << (this->Title ? this->Title : "(none)") << "\n";
544 os << indent << "Maximum Number Of Colors: "
545 << this->MaximumNumberOfColors << "\n";
546 os << indent << "Number Of Labels: " << this->NumberOfLabels << "\n";
547 os << indent << "Number Of Labels Built: " << this->NumberOfLabelsBuilt << "\n";
549 os << indent << "Orientation: ";
550 if ( this->Orientation == VTK_ORIENT_HORIZONTAL )
552 os << "Horizontal\n";
559 os << indent << "Label Format: " << this->LabelFormat << "\n";
562 void VISU_ScalarBarActor::ShallowCopy(vtkProp *prop)
564 VISU_ScalarBarActor *a = VISU_ScalarBarActor::SafeDownCast(prop);
567 this->SetPosition2(a->GetPosition2());
568 this->SetLookupTable(a->GetLookupTable());
569 this->SetMaximumNumberOfColors(a->GetMaximumNumberOfColors());
570 this->SetOrientation(a->GetOrientation());
571 this->SetLabelTextProperty(a->GetLabelTextProperty());
572 this->SetTitleTextProperty(a->GetTitleTextProperty());
573 this->SetLabelFormat(a->GetLabelFormat());
574 this->SetTitle(a->GetTitle());
575 this->GetPositionCoordinate()->SetCoordinateSystem(
576 a->GetPositionCoordinate()->GetCoordinateSystem());
577 this->GetPositionCoordinate()->SetValue(
578 a->GetPositionCoordinate()->GetValue());
579 this->GetPosition2Coordinate()->SetCoordinateSystem(
580 a->GetPosition2Coordinate()->GetCoordinateSystem());
581 this->GetPosition2Coordinate()->SetValue(
582 a->GetPosition2Coordinate()->GetValue());
586 this->vtkActor2D::ShallowCopy(prop);
589 void VISU_ScalarBarActor::AllocateAndSizeLabels(int *labelSize, int *size,
590 vtkViewport *viewport,
591 vtkFloatingPointType *range)
593 labelSize[0] = labelSize[1] = 0;
595 this->TextMappers = new vtkTextMapper * [this->NumberOfLabels];
596 this->TextActors = new vtkActor2D * [this->NumberOfLabels];
600 vtkFloatingPointType val;
603 // TODO: this should be optimized, maybe by keeping a list of
604 // allocated mappers, in order to avoid creation/destruction of
605 // their underlying text properties (i.e. each time a mapper is
606 // created, text properties are created and shallow-assigned a font size
607 // which value might be "far" from the target font size).
609 VISU_LookupTable *lut = this->LookupTable; //SALOME specific
610 int isLogTable = lut->GetScale() == VTK_SCALE_LOG10;
612 for (i=0; i < this->NumberOfLabels; i++)
614 this->TextMappers[i] = vtkTextMapper::New();
616 if(isLogTable && 0 < i && i < this->NumberOfLabels - 1){ // SALOME specific
617 vtkFloatingPointType lval = log10(range[0]) + (vtkFloatingPointType)i/(this->NumberOfLabels-1) *
618 (log10(range[1])-log10(range[0]));
619 val = pow((double)10,(double)lval);
621 val = range[0] + (vtkFloatingPointType)i/(this->NumberOfLabels-1) * (range[1]-range[0]);
623 sprintf(string, this->LabelFormat, val);
624 this->TextMappers[i]->SetInput(string);
626 // Shallow copy here so that the size of the label prop is not affected
627 // by the automatic adjustment of its text mapper's size (i.e. its
628 // mapper's text property is identical except for the font size
629 // which will be modified later). This allows text actors to
630 // share the same text property, and in that case specifically allows
631 // the title and label text prop to be the same.
632 this->TextMappers[i]->GetTextProperty()->ShallowCopy(
633 this->LabelTextProperty);
635 this->TextActors[i] = vtkActor2D::New();
636 this->TextActors[i]->SetMapper(this->TextMappers[i]);
637 this->TextActors[i]->SetProperty(this->GetProperty());
638 this->TextActors[i]->GetPositionCoordinate()->
639 SetReferenceCoordinate(this->PositionCoordinate);
642 if (this->NumberOfLabels)
644 int targetWidth, targetHeight;
646 if(LabelRatioWidth == 0)
647 if ( this->Orientation == VTK_ORIENT_VERTICAL )
648 targetWidth = (int)(0.6*size[0]);
650 targetWidth = (int)(size[0]*0.8/this->NumberOfLabels);
652 targetWidth = (int)(0.01*LabelRatioWidth*size[0]);
654 if ( this->Orientation == VTK_ORIENT_VERTICAL )
655 targetHeight = (int)(0.86*size[1]/this->NumberOfLabels);
657 targetHeight = (int)(0.25*size[1]);
659 vtkTextMapper::SetMultipleConstrainedFontSize(viewport,
663 this->NumberOfLabels,
668 void VISU_ScalarBarActor::SizeTitle(int *titleSize, int *size,
669 vtkViewport *viewport)
671 titleSize[0] = titleSize[1] = 0;
673 if (this->Title == NULL || !strlen(this->Title))
678 int targetWidth, targetHeight;
680 if(TitleRatioSize == 0)
681 targetWidth = size[0];
683 targetWidth = (int)(0.01*TitleRatioSize*size[0]);
685 if ( this->Orientation == VTK_ORIENT_VERTICAL )
686 targetHeight = (int)(0.1*size[1]);
688 targetHeight = (int)(0.25*size[1]);
690 this->TitleMapper->SetConstrainedFontSize(
691 viewport, targetWidth, targetHeight);
693 this->TitleMapper->GetSize(viewport, titleSize);
697 void VISU_ScalarBarActor::SetDistributionVisibility(int v)
699 this->DistributionVisibility = v;
701 this->DistributionActor->VisibilityOn();
703 this->DistributionActor->VisibilityOff();
707 void VISU_ScalarBarActor::SetDistribution(vtkDoubleArray *distr)
709 this->Distribution = distr;
710 if (distr == NULL) return;
712 this->DistributionObj->Initialize();
713 this->DistributionObj->GetFieldData()->AddArray(this->Distribution);
714 this->DistributionActor->AddDataObjectInput(this->DistributionObj);
715 // Set ranges of axes for the distribution curve
716 this->DistributionActor->SetXRange(0, this->Distribution->GetNumberOfTuples()-1);
718 this->Distribution->GetRange(range);
719 int aNbVals = this->Distribution->GetNumberOfTuples();
721 if (this->GetDebug()) {
722 for(vtkIdType aValId = 0; aValId < aNbVals; aValId++){
723 // if (this->GetDebug()) {
724 if (this->Distribution->GetValue(aValId) > 0)
725 vtkDebugMacro(<< "D(" << aValId << ") = " << this->Distribution->GetValue(aValId));
727 // total += this->Distribution->GetValue(aValId);
730 // this->DistributionActor->SetYRange(0, total);
731 this->DistributionActor->SetYRange(0, range[1]);
732 vtkDebugMacro(<< "max X = " << this->Distribution->GetNumberOfTuples());
733 vtkDebugMacro(<< "Y = (" << range[0] << ", " << range[1] << ")");
734 // vtkDebugMacro(<< "total = " << total);
737 void VISU_ScalarBarActor::DebugOn() {
738 this->DistributionActor->DebugOn();
739 Superclass::DebugOn();
742 void VISU_ScalarBarActor::DebugOff() {
743 this->DistributionActor->DebugOff();
744 Superclass::DebugOff();
748 void VISU_ScalarBarActor::SetRatios(int titleRatioSize, int labelRatioWidth,
749 int barRatioWidth, int barRatioHeight)
751 TitleRatioSize=titleRatioSize;
752 if(TitleRatioSize>100)
754 else if(TitleRatioSize<0)
757 LabelRatioWidth=labelRatioWidth;
758 if(LabelRatioWidth>100)
760 else if(LabelRatioWidth<0)
763 BarRatioWidth=barRatioWidth;
764 if(BarRatioWidth>100)
766 else if(BarRatioWidth<0)
769 BarRatioHeight=barRatioHeight;
770 if(BarRatioHeight>100)
772 else if(BarRatioHeight<0)
776 void VISU_ScalarBarActor::GetRatios(int& titleRatioSize, int& labelRatioWidth,
777 int& barRatioWidth, int& barRatioHeight)
779 titleRatioSize=TitleRatioSize;
780 labelRatioWidth=LabelRatioWidth;
781 barRatioWidth=BarRatioWidth;
782 barRatioHeight=BarRatioHeight;
785 void VISU_ScalarBarActor::SizeBar(int& barSizeWidth, int& barSizeHeight, int *size,
786 vtkViewport *viewport, vtkFloatingPointType *range)
788 if(BarRatioWidth == 0)
789 if ( this->Orientation == VTK_ORIENT_VERTICAL )
792 this->AllocateAndSizeLabels(labelSize, size, viewport,range);
793 barSizeWidth = size[0] - 4 - labelSize[0];
795 barSizeWidth = size[0];
797 barSizeWidth = (int)(0.01*BarRatioWidth*size[0]);
799 if(BarRatioHeight == 0)
800 if ( this->Orientation == VTK_ORIENT_VERTICAL )
801 barSizeHeight = (int)(0.86*size[1]);
803 barSizeHeight = (int)(0.4*size[1]);
805 barSizeHeight = (int)(0.01*BarRatioHeight*size[1]);
808 //------------------------------------------------------------------------------
809 /** Place the distribution plot actor in the viewport according to the
810 * scalar bar location and orientation */
811 void VISU_ScalarBarActor::PlaceDistribution(vtkViewport *viewport, const int barWidth, const int barHeight) {
812 vtkDebugMacro(<< "barOrigin[0]=" << this->LastOrigin[0] << "; barOrigin[1]=" << this->LastOrigin[1]);
813 // Detect the side of the viewport where the curve should be placed by the bar origin.
814 double u = (double)(this->LastOrigin[0]), v = (double)(this->LastOrigin[1]), z=0;
815 viewport->ViewportToNormalizedViewport(u, v);
817 if ( this->Orientation == VTK_ORIENT_VERTICAL ) {
818 // Position the distribution curve vertically
820 // X - UP, Y - TO THE LEFT
821 this->DistributionActor->SetPlotLocation(VISU_XYPLOT_RIGHT);
822 // Curve to be placed on the left side of the bar
823 vtkDebugMacro(<< "Curve to be placed on the left side of the bar");
824 // relative to the bar origin
827 viewport->ViewportToNormalizedViewport(u, v);
828 vtkDebugMacro(<< "u=" << u << "; v=" << v);
829 this->DistributionActor->GetPositionCoordinate()->SetValue(u, v, 0);
830 // relative to Position
833 viewport->ViewportToNormalizedViewport(u, v);
834 vtkDebugMacro("u2=" << u << "; v2=" << v);
835 this->DistributionActor->GetPosition2Coordinate()->SetValue(u, v, 0);
837 // X - UP, Y - TO THE RIGHT
838 this->DistributionActor->SetPlotLocation(VISU_XYPLOT_LEFT);
839 // Curve to be placed on the right side of the bar
840 vtkDebugMacro(<< "Curve to be placed on the right side of the bar");
841 // relative to the bar origin
844 viewport->ViewportToNormalizedViewport(u, v);
845 vtkDebugMacro(<< "u=" << u << "; v=" << v);
846 this->DistributionActor->GetPositionCoordinate()->SetValue(u, v, 0);
847 // relative to Position
850 viewport->ViewportToNormalizedViewport(u, v);
851 vtkDebugMacro("u2=" << u << "; v2=" << v);
852 this->DistributionActor->GetPosition2Coordinate()->SetValue(u, v, 0);
855 // Position the distribution curve horizontally
857 // X - TO THE LEFT, Y - DOWN
858 this->DistributionActor->SetPlotLocation(VISU_XYPLOT_TOP);
859 // Curve to be placed below the bar
860 vtkDebugMacro(<< "Curve to be placed below the bar");
861 // relative to the bar origin
864 viewport->ViewportToNormalizedViewport(u, v);
865 vtkDebugMacro(<< "u=" << u << "; v=" << v);
866 this->DistributionActor->GetPositionCoordinate()->SetValue(u, v, 0);
867 // relative to Position
870 viewport->ViewportToNormalizedViewport(u, v);
871 vtkDebugMacro("u2=" << u << "; v2=" << v);
872 this->DistributionActor->GetPosition2Coordinate()->SetValue(u, v, 0);
874 // X - TO THE RIGHT, Y - UP
875 this->DistributionActor->SetPlotLocation(VISU_XYPLOT_BOTTOM);
876 // Curve to be placed on the top of the bar
877 vtkDebugMacro(<< "Curve to be placed on the top of the bar");
878 // relative to the bar origin
881 viewport->ViewportToNormalizedViewport(u, v);
882 vtkDebugMacro(<< "u=" << u << "; v=" << v);
883 this->DistributionActor->GetPositionCoordinate()->SetValue(u, v, 0);
884 // relative to Position
887 viewport->ViewportToNormalizedViewport(u, v);
888 vtkDebugMacro("u2=" << u << "; v2=" << v);
889 this->DistributionActor->GetPosition2Coordinate()->SetValue(u, v, 0);