MCPcopy Create free account
hub / github.com/Kitware/VTK / BuildLabels

Method BuildLabels

Rendering/Annotation/vtkAxisActor2D.cxx:760–912  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

758
759//------------------------------------------------------------------------------
760void vtkAxisActor2D::BuildLabels(vtkViewport* viewport)
761{
762 // Update the labels text. Do it only if the range has been adjusted,
763 // i.e. if we think that new labels must be created.
764 // WARNING: if LabelFormat has changed, they should be recreated too
765 // but at this point the check on LabelFormat is "included" in
766 // UpdateAdjustedRange(), which is the function that update
767 // AdjustedRangeBuildTime or not.
768 vtkMTimeType labeltime = this->AdjustedRangeBuildTime;
769 int nbOfLabels = static_cast<int>(this->TickValues.size());
770 if (this->NumberOfLabelsBuilt != nbOfLabels)
771 {
772 vtkErrorMacro("Inconsistent number of labels. Got " << nbOfLabels << " values but expects "
773 << this->NumberOfLabelsBuilt);
774 }
775
776 if (nbOfLabels < 1)
777 {
778 return;
779 }
780
781 if (this->AdjustedRangeBuildTime > this->BuildTime)
782 {
783 for (int i = 0; i < nbOfLabels; i++)
784 {
785 double val = this->TickValues[i];
786 if (this->GetNotation() == vtkNumberToString::Mixed)
787 {
788 // Use default legend notation : don't use vtkNumberToString
789 // for the default setting in order to ensure retrocompatibility
790 std::string labelFormat = this->LabelFormat ? vtk::to_std_format(this->LabelFormat) : "";
791 char string[512];
792 VTK_FORMAT_IF_ERROR_BREAK(
793 auto result = vtk::format_to_n(string, sizeof(string), labelFormat, val);
794 *result.out = '\0');
795 this->LabelMappers[i]->SetInput(string);
796 }
797 else
798 {
799 vtkNumberToString converter;
800 converter.SetNotation(this->GetNotation());
801 converter.SetPrecision(this->GetPrecision());
802 std::string formattedString = converter.Convert(val);
803 this->LabelMappers[i]->SetInput(formattedString.c_str());
804 }
805 }
806
807 // Check if the label text has changed
808 labeltime = std::max(this->LabelMappers[this->NumberOfLabelsBuilt - 1]->GetMTime(), labeltime);
809 }
810
811 // Copy prop and text prop eventually
812 for (int i = 0; i < this->NumberOfLabelsBuilt; i++)
813 {
814 if (this->LabelTextProperty->GetMTime() > this->BuildTime ||
815 this->AdjustedRangeBuildTime > this->BuildTime)
816 {
817 // Shallow copy here so that the size of the label prop is not

Callers 1

BuildAxisMethod · 0.95

Calls 15

GetAxisAngleMethod · 0.95
to_std_formatFunction · 0.85
SetFontSizeMethod · 0.80
format_to_nFunction · 0.50
maxFunction · 0.50
sqrtFunction · 0.50
sizeMethod · 0.45
GetNotationMethod · 0.45
SetInputMethod · 0.45
SetNotationMethod · 0.45

Tested by

no test coverage detected