Hi,
I’m trying to set constant font size for vtkAxisActor2D
labels.
Acoordint to the documentation there is a method UseFontSizeFromPropertyOn()
wich should be used if we want to manually set font size via text property i.e.:
axis->GetLabelTextProperty()->SetFontSize(1);
axis->UseFontSizeFromPropertyOn();
But it seems that no matter what font size I choose the size of actually displayed numbers will be changed along with rendering window size changes.
Here is the code snippet (try to run and resze the window):
#include <vtkActor.h>
#include <vtkAxisActor.h>
#include <vtkAxisActor2D.h>
#include <vtkCamera.h>
#include <vtkNamedColors.h>
#include <vtkNew.h>
#include <vtkProperty.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkSmartPointer.h>
#include <vtkStringArray.h>
#include <vtkTextProperty.h>
int main(int argc, char *argv[]) {
// Create the axis actor
vtkNew<vtkAxisActor2D> axis;
axis->GetPoint1Coordinate()->SetCoordinateSystemToDisplay();
axis->GetPoint2Coordinate()->SetCoordinateSystemToDisplay();
axis->SetPoint1(500, 15.0);
axis->SetPoint2(100, 15.0);
axis->SetNumberOfLabels(11);
axis->SetNumberOfMinorTicks(5);
axis->GetLabelTextProperty()->SetFontSize(1);
// axis->SizeFontRelativeToAxisOn();
axis->UseFontSizeFromPropertyOn();
axis->SetTickVisibility(1);
axis->SetRange(-5, 5);
// Create the RenderWindow, Renderer and both Actors
vtkNew<vtkRenderer> renderer;
vtkNew<vtkRenderWindow> renderWindow;
renderWindow->AddRenderer(renderer);
renderWindow->SetWindowName("AxisActor");
vtkNew<vtkRenderWindowInteractor> interactor;
interactor->SetRenderWindow(renderWindow);
renderer->AddActor(axis);
renderWindow->SetSize(640, 480);
renderer->ResetCamera();
renderer->ResetCameraClippingRange();
// render the image
renderWindow->Render();
interactor->Initialize();
interactor->Start();
return 0;
}