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

Method BuildLabels

Rendering/Annotation/vtkCubeAxesActor.cxx:1848–2038  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

1846
1847//------------------------------------------------------------------------------
1848void vtkCubeAxesActor::BuildLabels(vtkAxisActor* axes[NUMBER_OF_ALIGNED_AXIS])
1849{
1850 char label[64];
1851 int labelCount = 0;
1852 double deltaMajor = axes[0]->GetDeltaMajor(axes[0]->GetAxisType());
1853 double val = axes[0]->GetMajorRangeStart();
1854 double p2[3], p1[3];
1855 axes[0]->GetPoint1Coordinate()->GetValue(p1);
1856 axes[0]->GetPoint2Coordinate()->GetValue(p2);
1857 double* range = axes[0]->GetRange();
1858 double axis[3] = { p2[0] - p1[0], p2[1] - p1[1], p2[2] - p1[2] };
1859 double axisLength = vtkMath::Norm(axis);
1860 double extents = range[1] - range[0];
1861 double tol =
1862 extents * 1e-6; // Calculate a relative tolerance based on the extent to compare to 0.
1863 bool mustAdjustValue = false;
1864 int lastPow = 0;
1865 int axisIndex = 0;
1866 vtkStringArray* customizedLabels = nullptr;
1867
1868 vtkStringArray* labels = vtkStringArray::New();
1869 std::string format("{:s}");
1870 switch (axes[0]->GetAxisType())
1871 {
1872 case vtkAxisActor::VTK_AXIS_TYPE_X:
1873 axisIndex = 0;
1874 format = this->XLabelFormat;
1875 mustAdjustValue = this->MustAdjustXValue;
1876 lastPow = this->LastXPow;
1877 break;
1878 case vtkAxisActor::VTK_AXIS_TYPE_Y:
1879 axisIndex = 1;
1880 format = this->YLabelFormat;
1881 mustAdjustValue = this->MustAdjustYValue;
1882 lastPow = this->LastYPow;
1883 break;
1884 case vtkAxisActor::VTK_AXIS_TYPE_Z:
1885 axisIndex = 2;
1886 format = this->ZLabelFormat;
1887 mustAdjustValue = this->MustAdjustZValue;
1888 lastPow = this->LastZPow;
1889 break;
1890 }
1891 format = vtk::to_std_format(format);
1892 customizedLabels = this->AxisLabels[axisIndex];
1893 // figure out how many labels we need:
1894 if (extents == 0)
1895 {
1896 labelCount = 0;
1897 }
1898 else
1899 {
1900 double rangeScale = axisLength / extents;
1901 double labelCountAsDouble = (axisLength - (val - range[0]) * rangeScale) / deltaMajor;
1902 labelCount = vtkMath::Floor(labelCountAsDouble + 2 * FLT_EPSILON) + 1;
1903 }
1904
1905 labels->SetNumberOfValues(labelCount);

Callers 2

ComputeTickSizeMethod · 0.95
BuildAxesMethod · 0.95

Calls 15

to_std_formatFunction · 0.85
GetDeltaMajorMethod · 0.80
DeleteMethod · 0.65
NormFunction · 0.50
NewFunction · 0.50
powFunction · 0.50
ifFunction · 0.50
GetValueMethod · 0.45
GetPoint1CoordinateMethod · 0.45
GetPoint2CoordinateMethod · 0.45
GetRangeMethod · 0.45
SetNumberOfValuesMethod · 0.45

Tested by

no test coverage detected