Skip to content
Snippets Groups Projects
Commit fdab76cf authored by Nicolas Vuaille's avatar Nicolas Vuaille
Browse files

vktLegendScaleActor expose more Axis parameters

* utility methods
parent e8193228
No related branches found
No related tags found
No related merge requests found
......@@ -13,6 +13,7 @@
=========================================================================*/
// This tests the terrain annotation capabilities in VTK.
#include "vtkAxisActor2D.h"
#include "vtkCamera.h"
#include "vtkInteractorStyleTrackballCamera.h"
#include "vtkLegendScaleActor.h"
......@@ -23,39 +24,55 @@
#include "vtkRenderer.h"
#include "vtkSphereSource.h"
#include "vtkTestUtilities.h"
#include "vtkTextProperty.h"
//------------------------------------------------------------------------------
int TestLegendScaleActor(int argc, char* argv[])
{
// Create the RenderWindow, Renderer and both Actors
//
vtkRenderer* ren1 = vtkRenderer::New();
vtkRenderWindow* renWin = vtkRenderWindow::New();
vtkNew<vtkRenderer> ren1;
vtkNew<vtkRenderWindow> renWin;
renWin->SetMultiSamples(0);
renWin->AddRenderer(ren1);
ren1->GetActiveCamera()->ParallelProjectionOn();
vtkInteractorStyleTrackballCamera* style = vtkInteractorStyleTrackballCamera::New();
vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New();
vtkNew<vtkInteractorStyleTrackballCamera> style;
vtkNew<vtkRenderWindowInteractor> iren;
iren->SetRenderWindow(renWin);
iren->SetInteractorStyle(style);
// Create a test pipeline
//
vtkSphereSource* ss = vtkSphereSource::New();
vtkPolyDataMapper* mapper = vtkPolyDataMapper::New();
vtkNew<vtkSphereSource> ss;
vtkNew<vtkPolyDataMapper> mapper;
mapper->SetInputConnection(ss->GetOutputPort());
vtkActor* sph = vtkActor::New();
vtkNew<vtkActor> sph;
sph->SetMapper(mapper);
// Create the actor
vtkLegendScaleActor* actor = vtkLegendScaleActor::New();
actor->TopAxisVisibilityOn();
vtkNew<vtkLegendScaleActor> legendActor;
legendActor->TopAxisVisibilityOn();
legendActor->SetLabelModeToXYCoordinates();
legendActor->AllAxesOff();
legendActor->LeftAxisVisibilityOn();
legendActor->TopAxisVisibilityOn();
legendActor->SetLeftBorderOffset(70);
legendActor->SetTopBorderOffset(50);
legendActor->GetTopAxis()->SetNumberOfLabels(3);
legendActor->SetCornerOffsetFactor(1);
vtkNew<vtkTextProperty> textProp;
textProp->SetColor(1, 0.5, 0);
textProp->SetFontSize(18);
textProp->BoldOn();
legendActor->SetUseFontSizeFromProperty(true);
legendActor->SetAxesTextProperty(textProp);
// Add the actors to the renderer, set the background and size
ren1->AddActor(sph);
ren1->AddViewProp(actor);
ren1->AddViewProp(legendActor);
ren1->SetBackground(0.1, 0.2, 0.4);
renWin->SetSize(300, 300);
......@@ -70,14 +87,5 @@ int TestLegendScaleActor(int argc, char* argv[])
iren->Start();
}
ss->Delete();
mapper->Delete();
sph->Delete();
actor->Delete();
style->Delete();
iren->Delete();
renWin->Delete();
ren1->Delete();
return !retVal;
}
b996ef7706b6aaa05403059e7e381552cde10086c7f6f937b0f79070445b4f59b0df6dbf9161e7dc0c14e976cd6f44ac83b01f7e0037ae864f4b543c7e244f69
2824415ba24e1d451774e2faa1248235c57b96a5cfbc07432fbffd3db338a18759386fcd7792b43f70113bce9c8840d9f1783861d86e6ae456f2c8cedc76e2ca
......@@ -150,6 +150,40 @@ vtkLegendScaleActor::~vtkLegendScaleActor()
}
}
//------------------------------------------------------------------------------
void vtkLegendScaleActor::SetAdjustLabels(bool adjust)
{
this->RightAxis->SetAdjustLabels(adjust);
this->TopAxis->SetAdjustLabels(adjust);
this->LeftAxis->SetAdjustLabels(adjust);
this->BottomAxis->SetAdjustLabels(adjust);
}
//------------------------------------------------------------------------------
void vtkLegendScaleActor::SetUseFontSizeFromProperty(bool fromProp)
{
this->RightAxis->SetUseFontSizeFromProperty(fromProp);
this->TopAxis->SetUseFontSizeFromProperty(fromProp);
this->LeftAxis->SetUseFontSizeFromProperty(fromProp);
this->BottomAxis->SetUseFontSizeFromProperty(fromProp);
}
//------------------------------------------------------------------------------
void vtkLegendScaleActor::SetAxesTextProperty(vtkTextProperty* prop)
{
this->RightAxis->SetLabelTextProperty(prop);
this->TopAxis->SetLabelTextProperty(prop);
this->LeftAxis->SetLabelTextProperty(prop);
this->BottomAxis->SetLabelTextProperty(prop);
this->RightAxis->SetTitleTextProperty(prop);
this->TopAxis->SetTitleTextProperty(prop);
this->LeftAxis->SetTitleTextProperty(prop);
this->BottomAxis->SetTitleTextProperty(prop);
this->Modified();
}
//------------------------------------------------------------------------------
void vtkLegendScaleActor::GetActors2D(vtkPropCollection* pc)
{
......
......@@ -190,6 +190,20 @@ public:
vtkGetObjectMacro(LegendLabelProperty, vtkTextProperty);
///@}
/**
* Configuration forwarded to each axis.
*/
///@{
/// Set the axes text properties.
void SetAxesTextProperty(vtkTextProperty* property);
/// Set the axes to get font size from text property.
void SetUseFontSizeFromProperty(bool sizeFromProp);
/// Set the axes to adjust labels position to a "nice" one.
void SetAdjustLabels(bool ajust);
///@}
///@{
/**
* These are methods to retrieve the vtkAxisActors used to represent
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment