17 #include "vtkCellArray.h"
18 #include "vtkCellData.h"
19 #include "vtkContextScene.h"
20 #include "vtkDiscretizableColorTransferFunction.h"
21 #include "vtkDoubleArray.h"
22 #include "vtkFloatArray.h"
23 #include "vtkImageData.h"
26 #include "vtkObjectFactory.h"
27 #include "vtkPointData.h"
28 #include "vtkPoints.h"
29 #include "vtkPolyData.h"
30 #include "vtkPolyDataMapper2D.h"
31 #include "vtkProperty2D.h"
32 #include "vtkRenderWindow.h"
33 #include "vtkRenderer.h"
34 #include "vtkScalarBarActorInternal.h"
35 #include "vtkScalarsToColors.h"
36 #include "vtkSmartPointer.h"
37 #include "vtkStringArray.h"
38 #include "vtkTextActor.h"
39 #include "vtkTextProperty.h"
40 #include "vtkTexture.h"
41 #include "vtkUnsignedCharArray.h"
42 #include "vtkWindow.h"
44 #if defined(_WIN32) && !defined(__CYGWIN__)
45 #define SNPRINTF _snprintf
47 #define SNPRINTF snprintf
50 #define COLOR_TEXTURE_MAP_SIZE 256
52 #define MY_ABS(x) ((x) < 0 ? -(x) : (x))
65 this->SetRangeLabelFormat(
"%4.3e");
68 this->AnnotationTextScaling = 1;
69 this->SetVerticalTitleSeparation(4);
79 this->
TickMarksActor->GetPositionCoordinate()->SetReferenceCoordinate(
80 this->PositionCoordinate);
94 if (this->ComponentTitle) {
95 delete[] this->ComponentTitle;
96 this->ComponentTitle =
NULL;
105 this->Superclass::PrintSelf(os, indent);
112 os << indent <<
"RangeLabelFormat: "
114 os << indent <<
"ScalarBarTexture: ";
120 os << indent <<
"TickMarks: ";
122 this->
TickMarks->PrintSelf(os <<
"\n", indent.GetNextIndent());
126 os << indent <<
"TickMarksMapper: ";
132 os << indent <<
"TickMarksActor: ";
134 this->
TickMarksActor->PrintSelf(os <<
"\n", indent.GetNextIndent());
150 for (
unsigned int i = 0; i < this->P->TextActors.size(); i++) {
151 this->P->TextActors[i]->ReleaseGraphicsResources(window);
156 this->Superclass::ReleaseGraphicsResources(window);
162 if (vtkRenderer* renderer = vtkRenderer::SafeDownCast(viewport)) {
166 return this->Superclass::RenderOpaqueGeometry(viewport);
171 int renderedSomething = this->Superclass::RenderOverlay(viewport);
172 if (this->LookupTable && this->LookupTable->GetIndexedLookup()) {
173 return renderedSomething;
177 renderedSomething += this->
TickMarksActor->RenderOverlay(viewport);
180 return renderedSomething;
188 vtkViewport* viewport) {
191 vtkNew<vtkTextActor> textActor;
192 textActor->GetProperty()->DeepCopy(this->GetProperty());
193 textActor->GetPositionCoordinate()->SetReferenceCoordinate(
194 this->PositionCoordinate);
198 textActor->GetTextProperty()->ShallowCopy(this->LabelTextProperty);
199 if (this->P->Viewport) {
200 textActor->SetTextScaleModeToViewport();
201 textActor->ComputeScaledFont(this->P->Viewport);
207 #if defined(_MSC_VER) && (_MSC_VER < 1900)
208 unsigned int oldWin32ExponentFormat =
209 _set_output_format(_TWO_DIGIT_EXPONENT);
216 int smallestFoundWidth = VTK_INT_MAX;
217 bool foundValid =
false;
219 for (
int i = 1 + minDigits; i < 6; i++) {
228 std::string strToFilter = string2;
229 std::string ePlus =
"e+0";
230 std::string eMinus =
"e-0";
232 while ((pos = strToFilter.find(ePlus)) != std::string::npos ||
233 (pos = strToFilter.find(eMinus)) != std::string::npos) {
234 strToFilter.erase(pos + 2, 1);
236 strcpy(string2, strToFilter.c_str());
237 textActor->SetInput(string2);
239 textActor->SetConstrainedFontSize(viewport, VTK_INT_MAX,
242 textActor->GetSize(viewport, tsize);
243 if (tsize[0] < targetWidth) {
246 strcpy(
string, string2);
248 }
else if ((tsize[0] < smallestFoundWidth) && !foundValid) {
250 strcpy(
string, string2);
251 smallestFoundWidth = tsize[0];
256 SNPRINTF(
string, 1023, this->LabelFormat, value);
260 textActor->SetInput(
string);
262 #if defined(_MSC_VER) && (_MSC_VER < 1900)
263 _set_output_format(oldWin32ExponentFormat);
268 int fontSize = textActor->SetConstrainedFontSize(viewport, VTK_INT_MAX,
270 int maxFontSize = this->LabelTextProperty->GetFontSize();
271 if (fontSize > maxFontSize) {
272 textActor->GetTextProperty()->SetFontSize(maxFontSize);
277 textActor->GetSize(viewport, tsize);
278 if (tsize[0] > targetWidth) {
279 fontSize = textActor->SetConstrainedFontSize(viewport, targetWidth,
283 this->P->TextActors.push_back(textActor.GetPointer());
284 return static_cast<int>(this->P->TextActors.size()) - 1;
290 this->Superclass::PrepareTitleText();
293 if (this->P->Viewport) {
294 this->TitleActor->ComputeScaledFont(this->P->Viewport);
295 this->TitleActor->SetTextScaleModeToViewport();
302 if (aspectRatio <= 0.) {
307 this->P->ScalarBarBox.Size[0] =
308 static_cast<int>(
ceil(this->P->Frame.Size[1] / aspectRatio));
311 this->
LabelSpace = this->P->ScalarBarBox.Size[0] / 2 + 1;
313 this->P->ScalarBarBox.Posn = this->P->Frame.Posn;
316 vtkDiscretizableColorTransferFunction* lut =
317 vtkDiscretizableColorTransferFunction::SafeDownCast(
320 this->SetUseOpacity(lut->IsOpaque() ? 0 : 1);
326 if ((this->Title ==
NULL || !strlen(this->Title)) &&
327 (this->ComponentTitle ==
NULL || !strlen(this->ComponentTitle))) {
328 this->P->TitleBox.Size[0] = this->P->TitleBox.Size[1] = 0;
333 this->TitleActor->GetTextProperty()->ShallowCopy(this->TitleTextProperty);
334 this->TitleActor->GetTextProperty()->SetJustification(
336 this->TitleActor->GetTextProperty()->SetVerticalJustification(
337 this->Orientation == VTK_ORIENT_VERTICAL
339 : (this->TextPosition == vtkScalarBarActor::PrecedeScalarBar
345 this->TitleActor->GetSize(this->P->Viewport, titleSize);
350 if (this->Orientation == VTK_ORIENT_VERTICAL &&
351 (1.5 * titleSize[1] + 3 * this->TextPad >
352 0.75 * this->P->Frame.Size[1])) {
354 this->TitleActor->SetConstrainedFontSize(
355 this->P->Viewport, VTK_INT_MAX,
356 0.5 * this->P->Frame.Size[1] - 3 * this->TextPad);
357 this->TitleActor->GetSize(this->P->Viewport, titleSize);
359 this->P->TitleBox.Size[this->P->TL[0]] = titleSize[0];
360 this->P->TitleBox.Size[this->P->TL[1]] =
361 1.5 * (titleSize[1] + this->TextPad);
364 switch (this->TitleActor->GetTextProperty()->GetJustification()) {
366 this->P->TitleBox.Posn[0] = this->P->Frame.Posn[0] + this->TextPad;
369 this->P->TitleBox.Posn[0] = this->P->Frame.Posn[0] +
370 this->P->Frame.Size[this->P->TL[0]] -
371 this->TextPad - titleSize[0];
373 case VTK_TEXT_CENTERED:
375 this->P->TitleBox.Posn[0] =
376 this->P->Frame.Posn[0] +
377 (this->P->Frame.Size[this->P->TL[0]] - titleSize[0]) / 2;
380 if (this->Orientation ==
381 VTK_ORIENT_VERTICAL) {
382 this->P->TitleBox.Posn[1] =
383 this->P->Frame.Posn[1] + this->P->Frame.Size[this->P->TL[1]] -
384 this->P->TitleBox.Size[this->P->TL[1]] / 1.5;
385 this->P->ScalarBarBox.Size[this->P->TL[1]] -= 2 * this->TextPad;
393 if (this->TextPosition == vtkScalarBarActor::PrecedeScalarBar) {
394 this->P->TitleBox.Posn[1] = this->P->Frame.Posn[1];
396 this->P->ScalarBarBox.Posn[1] +=
397 this->P->TitleBox.Size[0] + this->TextPad;
398 this->P->NanBox.Posn[1] +=
399 this->TextPad + this->P->TitleBox.Size[0];
401 this->P->TitleBox.Posn[1] = this->P->Frame.Posn[1] +
402 this->P->ScalarBarBox.Size[0] +
410 this->Superclass::ComputeScalarBarLength();
415 if (this->LookupTable->GetIndexedLookup()) {
417 this->NumberOfLabelsBuilt = 0;
422 vtkNew<vtkTextActor> dummyActor;
423 dummyActor->GetTextProperty()->ShallowCopy(this->LabelTextProperty);
424 dummyActor->SetInput(
426 if (this->P->Viewport) {
427 dummyActor->SetTextScaleModeToViewport();
428 dummyActor->ComputeScaledFont(this->P->Viewport);
432 dummyActor->GetSize(this->P->Viewport, tsize);
434 int targetHeight =
static_cast<int>(
ceil(tsize[1]));
436 if (this->Orientation == VTK_ORIENT_VERTICAL) {
437 this->P->TickBox.Size[0] = std::max(
438 0, this->P->Frame.Size[0] - this->P->ScalarBarBox.Size[0]);
439 this->P->TickBox.Size[1] = this->P->ScalarBarBox.Size[1];
440 this->P->TickBox.Posn = this->P->ScalarBarBox.Posn;
441 if (this->TextPosition == vtkScalarBarActor::PrecedeScalarBar) {
442 this->P->ScalarBarBox.Posn[0] += this->P->TickBox.Size[0];
443 this->P->NanBox.Posn[0] += this->P->TickBox.Size[0];
445 this->P->TickBox.Posn[0] += this->P->ScalarBarBox.Size[0];
454 this->P->TickBox.Size[0] = this->
LabelSpace + 2 + targetHeight;
455 this->P->TickBox.Size[1] = this->P->ScalarBarBox.Size[1];
456 if (this->TextPosition ==
459 this->P->TickBox.Posn = this->P->ScalarBarBox.Posn;
460 this->P->ScalarBarBox.Posn[1] += this->P->TickBox.Size[0];
461 this->P->NanBox.Posn[1] += this->P->TickBox.Size[0];
463 this->P->TickBox.Posn[0] = this->P->ScalarBarBox.Posn[0];
464 this->P->TickBox.Posn[1] = this->P->TitleBox.Posn[1];
465 this->P->TitleBox.Posn[1] += this->P->TickBox.Size[0];
472 if (this->P->Labels.empty()) {
473 this->P->AnnotationBoxes->Initialize();
475 this->Superclass::ConfigureAnnotations();
483 double texturePolyDataBounds[6];
484 this->TexturePolyData->GetBounds(texturePolyDataBounds);
486 double scalarBarMinX = texturePolyDataBounds[0];
487 double scalarBarMaxX = texturePolyDataBounds[1];
489 switch (this->TitleActor->GetTextProperty()->GetJustification()) {
491 if (this->Orientation == VTK_ORIENT_VERTICAL) {
493 x -= this->P->TitleBox.Size[this->P->TL[0]];
499 if (this->Orientation == VTK_ORIENT_VERTICAL) {
501 x += this->P->TitleBox.Size[this->P->TL[0]];
506 case VTK_TEXT_CENTERED:
507 x = 0.5 * (scalarBarMinX + scalarBarMaxX);
512 <<
"Invalid text justification ("
513 << this->TitleActor->GetTextProperty()->GetJustification()
514 <<
" for scalar bar title.");
519 this->TitleActor->GetTextProperty()->GetVerticalJustification() ==
521 ? this->P->TitleBox.Posn[1]
522 : this->P->TitleBox.Posn[1] +
523 this->P->TitleBox.Size[this->P->TL[1]];
525 this->TitleActor->SetPosition(
x,
y);
530 bool isLogTable = (this->LookupTable->UsingLogScale() != 0);
531 double* range = this->LookupTable->GetRange();
533 if (this->LookupTable->GetIndexedLookup()) {
539 vtkAxis::Location loc;
540 vtkVector2f p1(this->P->TickBox.Posn.Cast<
float>().GetData());
542 if (this->Orientation == VTK_ORIENT_HORIZONTAL) {
543 p2[0] +=
static_cast<float>(this->P->TickBox.Size[1]);
544 loc = vtkAxis::BOTTOM;
546 p2[1] +=
static_cast<float>(this->P->TickBox.Size[1]);
562 std::vector<double> ticks;
563 ticks.reserve(tickArray->GetNumberOfTuples());
564 for (vtkIdType i = 0; i < tickArray->GetNumberOfTuples(); ++i) {
567 if (labelArray->GetValue(i).empty()) {
571 ticks.push_back(isLogTable ? std::pow(10.0, tickArray->GetValue(i))
572 : tickArray->GetValue(i));
579 double delta = range[1] - range[0];
582 double dmag = log10(delta);
583 double emag =
floor(dmag) - 1;
584 double mag = pow(10.0, emag);
585 if (1.1 * mag > delta) {
588 int leastDig =
floor(log10(fabs(mag)));
591 double absMax = std::max(std::fabs(range[0]), std::fabs(range[1]));
592 int leadDig =
floor(log10(absMax));
594 minDigits = leadDig - leastDig;
598 std::vector<int> tickToLabelId(ticks.size(), -1);
600 this->P->TextActors.reserve(ticks.size());
602 vtkNew<vtkCellArray> tickCells;
603 tickCells->Allocate(tickCells->EstimateSize(ticks.size() * 10, 2));
605 vtkNew<vtkPoints> tickPoints;
606 tickPoints->Allocate(ticks.size() * 20);
608 double targetWidth = this->P->TickBox.Size[this->P->TL[0]];
609 double targetHeight = this->P->TickBox.Size[this->P->TL[1]];
610 if (this->Orientation == VTK_ORIENT_HORIZONTAL) {
611 targetWidth = (targetWidth - (ticks.size() - 1) * this->TextPad) /
615 targetHeight = (targetHeight - (ticks.size() - 1) * this->TextPad) /
620 vtkNew<vtkTextActor> dummyActor;
621 dummyActor->GetTextProperty()->ShallowCopy(this->LabelTextProperty);
622 dummyActor->SetInput(
"()");
624 if (this->P->Viewport) {
625 dummyActor->SetTextScaleModeToViewport();
626 dummyActor->ComputeScaledFont(this->P->Viewport);
630 dummyActor->GetSize(this->P->Viewport, tsize);
632 if (tsize[1] < targetHeight) {
633 targetHeight = tsize[1];
637 bool precede = this->TextPosition == vtkScalarBarActor::PrecedeScalarBar;
638 int minimumFontSize = VTK_INT_MAX;
639 for (
int i = 0; i < static_cast<int>(ticks.size()); i++) {
640 double val = ticks[i];
644 if (!((val - 1
e-6 *
MY_ABS(val + range[0]) > range[0]) &&
645 (val + 1
e-6 *
MY_ABS(val + range[1]) < range[1]))) {
649 int labelIdx = this->
CreateLabel(val, minDigits, targetWidth,
650 targetHeight, this->P->Viewport);
651 tickToLabelId[i] = labelIdx;
652 vtkTextActor* textActor = this->P->TextActors[labelIdx];
654 int labelFontSize = textActor->GetTextProperty()->GetFontSize();
655 if (labelFontSize < minimumFontSize) {
656 minimumFontSize = labelFontSize;
661 for (
size_t i = 0; i < ticks.size(); i++) {
662 int labelIdx = tickToLabelId[i];
663 if (labelIdx == -1) {
667 vtkTextActor* textActor = this->P->TextActors[labelIdx];
671 textActor->GetTextProperty()->SetFontSize(minimumFontSize);
673 double val = ticks[i];
677 normVal = ((log10(val) - log10(range[0])) /
678 (log10(range[1]) - log10(range[0])));
680 normVal = (val - range[0]) / (range[1] - range[0]);
683 if (this->Orientation == VTK_ORIENT_VERTICAL) {
684 double x = precede ? this->P->TickBox.Posn[0] +
685 this->P->TickBox.Size[0]
686 : this->P->TickBox.Posn[0];
687 double y = normVal * this->P->TickBox.Size[1] +
688 this->P->TickBox.Posn[1];
690 textActor->GetSize(this->P->Viewport, textSize);
691 y -= textSize[1] / 2;
692 textActor->GetTextProperty()->SetJustification(
693 precede ? VTK_TEXT_RIGHT : VTK_TEXT_LEFT);
694 textActor->SetPosition(
698 double x = this->P->TickBox.Posn[0] +
699 normVal * this->P->TickBox.Size[1];
700 double y = precede ? this->P->TickBox.Posn[1] +
701 this->P->TickBox.Size[0]
702 : this->P->TickBox.Posn[1];
703 textActor->GetTextProperty()->SetJustificationToCentered();
704 textActor->GetTextProperty()->SetVerticalJustification(
705 precede ? VTK_TEXT_TOP : VTK_TEXT_BOTTOM);
706 textActor->SetPosition(
712 int numTicks =
static_cast<int>(ticks.size());
716 double fractionOfRange;
719 tickDelta = log10(ticks[numTicks - 1]) - log10(ticks[0]);
720 fractionOfRange = (tickDelta) / (log10(range[1]) - log10(range[0]));
723 tickDelta = ticks[numTicks - 1] - ticks[0];
724 fractionOfRange = (tickDelta) / (range[1] - range[0]);
727 double pixelsAvailable = fractionOfRange * this->P->TickBox.Size[1];
728 int maxNumMinorTicks = vtkMath::Floor(pixelsAvailable / 5);
731 const int minorRatios[] = {10, 5, 2, 1};
732 const int numMinorRatios =
733 static_cast<int>(
sizeof(minorRatios) /
sizeof(
int));
735 for (
int r = 0; r < numMinorRatios; r++) {
736 minorRatio = minorRatios[r];
737 int numMinorTicks = (numTicks - 1) * minorRatio;
738 if (numMinorTicks <= maxNumMinorTicks)
break;
742 double fakeMin, fakeMax;
744 fakeMin = 2 * ticks[0] - ticks[1];
745 fakeMax = 2 * ticks[numTicks - 1] - ticks[numTicks - 2];
747 fakeMin = pow(10.0, 2 * log10(ticks[0]) - log10(ticks[1]));
748 fakeMax = pow(10.0, 2 * log10(ticks[numTicks - 1]) -
749 log10(ticks[numTicks - 2]));
751 ticks.insert(ticks.begin(), fakeMin);
752 ticks.insert(ticks.end(), fakeMax);
753 numTicks =
static_cast<int>(ticks.size());
756 double minorTickRange[2];
757 minorTickRange[0] = ticks[i];
758 minorTickRange[1] = ticks[i + 1];
759 for (
int j = 0; j < minorRatio; j++) {
760 double val = (((minorTickRange[1] - minorTickRange[0]) * j) /
765 normVal = ((log10(val) - log10(range[0])) /
766 (log10(range[1]) - log10(range[0])));
768 normVal = (val - range[0]) / (range[1] - range[0]);
772 if ((normVal < 0.0) || (normVal > 1.0))
continue;
774 if (this->Orientation == VTK_ORIENT_VERTICAL) {
775 double x = precede ? this->P->TickBox.Posn[0] +
776 this->P->TickBox.Size[0]
777 : this->P->TickBox.Posn[0];
778 double y = normVal * this->P->TickBox.Size[1] +
779 this->P->TickBox.Posn[1];
781 ids[0] = tickPoints->InsertNextPoint(
783 ids[1] = tickPoints->InsertNextPoint(
785 tickCells->InsertNextCell(2, ids);
788 double x = this->P->TickBox.Posn[0] +
789 normVal * this->P->TickBox.Size[1];
790 double y = precede ? this->P->TickBox.Posn[1] +
791 this->P->TickBox.Size[0]
792 : this->P->TickBox.Posn[1];
794 ids[0] = tickPoints->InsertNextPoint(
796 ids[1] = tickPoints->InsertNextPoint(
798 tickCells->InsertNextCell(2, ids);
804 this->
TickMarks->SetLines(tickCells.GetPointer());
805 this->
TickMarks->SetPoints(tickPoints.GetPointer());
810 this->LabelTextProperty->GetColor(
color);
812 if (
color[2] > 0.5) {
822 int previousAutomaticLabelFormat = this->GetAutomaticLabelFormat();
823 this->SetAutomaticLabelFormat(0);
825 std::string previousLabelFormat(this->GetLabelFormat());
828 this->
CreateLabel(range[0], minDigits, targetWidth, targetHeight,
830 this->
CreateLabel(range[1], minDigits, targetWidth, targetHeight,
835 this->SetLabelFormat(previousLabelFormat.c_str());
839 for (
size_t i = this->P->TextActors.size() - 2;
840 i < this->P->TextActors.size(); ++i) {
841 vtkTextActor* textActor = this->P->TextActors[i];
844 textActor->GetTextProperty()->SetFontSize(minimumFontSize);
846 double val = range[i - (this->P->TextActors.size() - 2)];
850 normVal = ((log10(val) - log10(range[0])) /
851 (log10(range[1]) - log10(range[0])));
853 normVal = (val - range[0]) / (range[1] - range[0]);
856 if (this->Orientation == VTK_ORIENT_VERTICAL) {
857 double x = precede ? this->P->TickBox.Posn[0] +
858 this->P->TickBox.Size[0]
859 : this->P->TickBox.Posn[0];
860 double y = normVal * this->P->TickBox.Size[1] +
861 this->P->TickBox.Posn[1];
863 textActor->GetSize(this->P->Viewport, textSize);
864 y -= textSize[1] / 2;
865 textActor->GetTextProperty()->SetJustification(
866 precede ? VTK_TEXT_RIGHT : VTK_TEXT_LEFT);
867 textActor->SetPosition(
872 double x = this->P->TickBox.Posn[0] +
873 normVal * this->P->TickBox.Size[1];
874 double y = precede ? this->P->TickBox.Posn[1] +
875 this->P->TickBox.Size[0]
876 : this->P->TickBox.Posn[1];
877 textActor->GetTextProperty()->SetJustificationToCentered();
878 textActor->GetTextProperty()->SetVerticalJustification(
879 precede ? VTK_TEXT_TOP : VTK_TEXT_BOTTOM);
880 textActor->SetPosition(
x, precede ?
y - this->
LabelSpace
886 textActor->GetBoundingBox(this->P->Viewport, bbox);
887 double* pos = textActor->GetPosition();
893 for (
size_t j = 0; j < tickToLabelId.size(); ++j) {
894 int labelIdx = tickToLabelId[j];
895 if (labelIdx == -1) {
899 vtkTextActor* labelActor = this->P->TextActors[labelIdx];
903 labelActor->GetBoundingBox(this->P->Viewport, labelbbox);
904 labelpos = labelActor->GetPosition();
905 labelbbox[0] += labelpos[0];
906 labelbbox[1] += labelpos[0];
907 labelbbox[2] += labelpos[1];
908 labelbbox[3] += labelpos[1];
912 !((labelbbox[0] < bbox[0] && labelbbox[1] < bbox[0]) ||
913 (labelbbox[0] > bbox[1] && labelbbox[1] > bbox[1]));
915 !((labelbbox[2] < bbox[2] && labelbbox[3] < bbox[2]) ||
916 (labelbbox[2] > bbox[3] && labelbbox[3] > bbox[3]));
917 if (xoverlap && yoverlap) {
918 labelActor->SetVisibility(0);
925 for (
size_t i = 1; ticks.size() > 0 && i < ticks.size() - 1; i++) {
926 int labelIdx = tickToLabelId[i - 1];
927 if (labelIdx == -1) {
931 vtkTextActor* textActor = this->P->TextActors[labelIdx];
932 if (textActor->GetVisibility() == 0) {
936 double val = ticks[i];
940 normVal = ((log10(val) - log10(range[0])) /
941 (log10(range[1]) - log10(range[0])));
943 normVal = (val - range[0]) / (range[1] - range[0]);
946 if (this->Orientation == VTK_ORIENT_VERTICAL) {
947 double x = precede ? this->P->TickBox.Posn[0] +
948 this->P->TickBox.Size[0]
949 : this->P->TickBox.Posn[0];
950 double y = normVal * this->P->TickBox.Size[1] +
951 this->P->TickBox.Posn[1];
953 ids[0] = tickPoints->InsertNextPoint(
x - this->
LabelSpace + 2, y,
955 ids[1] = tickPoints->InsertNextPoint(
x + this->
LabelSpace - 2, y,
957 tickCells->InsertNextCell(2, ids);
960 double x = this->P->TickBox.Posn[0] +
961 normVal * this->P->TickBox.Size[1];
962 double y = precede ? this->P->TickBox.Posn[1] +
963 this->P->TickBox.Size[0]
964 : this->P->TickBox.Posn[1];
966 ids[0] = tickPoints->InsertNextPoint(
x,
y - this->
LabelSpace + 2,
968 ids[1] = tickPoints->InsertNextPoint(
x,
y + this->
LabelSpace - 2,
970 tickCells->InsertNextCell(2, ids);
977 static void AddLabelIfUnoccluded(
double x,
978 const vtkColor3ub&
color,
979 const std::string& label,
980 vtkScalarBarActorInternal* scalarBar) {
983 bool okLo =
true, okHi =
true;
984 if (!scalarBar->Labels.empty()) {
985 double delta = scalarBar->ScalarBarBox.Size[1] / 100.;
986 std::map<double, vtkStdString>::iterator clo =
987 scalarBar->Labels.lower_bound(
x);
989 if (clo == scalarBar->Labels
991 okLo = (
x - scalarBar->Labels.rbegin()->first) > delta;
993 okHi = (clo->first -
x) > delta;
994 if (clo != scalarBar->Labels.begin()) {
996 okLo = (
x - clo->first) > delta;
1001 scalarBar->Labels[
x] = label;
1002 scalarBar->LabelColors[
x] =
color;
1009 vtkScalarsToColors* lut = this->LookupTable;
1010 if (lut && !lut->GetIndexedLookup()) {
1011 const double* range = lut->GetRange();
1012 double dr = range[1] - range[0];
1013 double minX = this->P->ScalarBarBox.Posn[this->P->TL[1]];
1014 double maxX = this->P->ScalarBarBox.Size[1] + minX;
1023 vtkDiscretizableColorTransferFunction* transferFunc =
1024 vtkDiscretizableColorTransferFunction::SafeDownCast(
1026 vtkIdType nbValues = lut->GetNumberOfAvailableColors();
1027 if (transferFunc && transferFunc->GetDiscretize() &&
1028 this->AutomaticAnnotations && nbValues) {
1029 double step = dr / nbValues;
1030 double stepPos = (maxX - minX) / nbValues;
1031 for (vtkIdType i = 0; i <= nbValues; i++) {
1032 double value = range[0] + step * i;
1033 double pos = minX + stepPos * i;
1044 double lVal = log10(value);
1046 int least = (lVal > 0 ? +1 : -1) *
static_cast<int>(
floor(fabs(lVal)));
1048 int most =
static_cast<int>(
ceil(log10(fabs(value))));
1050 int dig = (most == VTK_INT_MIN) ? 3 : (most - least);
1052 char label[64],
fmt[64];
1057 this->LookupTable->GetColor(value, fltCol.GetData());
1058 for (
int j = 0; j < 3; ++j) {
1060 static_cast<unsigned char>(fltCol.GetData()[j] * 255.);
1062 AddLabelIfUnoccluded(pos, col, label, this->P);
1067 vtkNew<vtkFloatArray> tmp;
1069 double* range = this->LookupTable->GetRange();
1070 int isLogTable = this->LookupTable->UsingLogScale();
1075 double lval = log10(range[0]) +
1076 normVal * (log10(range[1]) - log10(range[0]));
1077 val = pow(10.0, lval);
1079 val = (range[1] - range[0]) * normVal + range[0];
1081 tmp->SetValue(i, val);
1083 vtkNew<vtkImageData> colorMapImage;
1085 colorMapImage->AllocateScalars(VTK_UNSIGNED_CHAR, 4);
1086 vtkDataArray*
colors = this->LookupTable->MapScalars(
1087 tmp.GetPointer(), VTK_COLOR_MODE_MAP_SCALARS, 0);
1088 colorMapImage->GetPointData()->SetScalars(
colors);
filament::Texture::InternalFormat format
void PrintSelf(ostream &os, vtkIndent indent) override
vtkNew< vtkContextScene > TickLayoutHelperScene
void LayoutTicks() override
int RenderOpaqueGeometry(vtkViewport *viewport) override
virtual void AddValueLabelIfUnoccluded(double value, double pos, double diff)
vtkTexture * ScalarBarTexture
void ConfigureAnnotations() override
int RenderOverlay(vtkViewport *viewport) override
virtual int CreateLabel(double value, int minDigits, int targetWidth, int targetHeight, vtkViewport *viewport)
void ConfigureTicks() override
void PrepareTitleText() override
vtkScalarBarActorCustom()
void ConfigureTitle() override
vtkActor2D * TickMarksActor
void EditAnnotations() override
void ComputeScalarBarLength() override
virtual void BuildScalarBarTexture()
void ReleaseGraphicsResources(vtkWindow *) override
vtkNew< vtkAxis > TickLayoutHelper
~vtkScalarBarActorCustom() override
vtkPolyDataMapper2D * TickMarksMapper
void LayoutTitle() override
void ComputeScalarBarThickness() override
QTextStream & endl(QTextStream &stream)
MiniVec< float, N > floor(const MiniVec< float, N > &a)
MiniVec< float, N > ceil(const MiniVec< float, N > &a)
#define COLOR_TEXTURE_MAP_SIZE
vtkStandardNewMacro(vtkScalarBarActorCustom)