Commit 00530ec4 authored by Andrew Heather's avatar Andrew Heather
Browse files

ENH: runTimePostProcessing - added option to draw axes

Examle usage:

    // Optional axes dictionary
    // Note: axes not vivible by default for backwards compatility
    axes
    {
        visible         yes;
        colour          (0 0 0);
        fontColour      (0.7 0.7 0.7);
        fontSize        30;
        lengthFactor    0.2;
    }
parent f8a8c546
......@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2015-2019 OpenCFD Ltd.
Copyright (C) 2015-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -30,14 +30,19 @@ License
#include "Constant.H"
// VTK includes
#include "vtkAxesActor.h"
#include "vtkCamera.h"
#include "vtkCaptionActor2D.h"
#include "vtkCubeSource.h"
#include "vtkLightKit.h"
#include "vtkPolyDataMapper.h"
#include "vtkPNGWriter.h"
#include "vtkProperty.h"
#include "vtkRenderer.h"
#include "vtkRendererCollection.h"
#include "vtkRenderWindow.h"
#include "vtkTextActor.h"
#include "vtkTextProperty.h"
#include "vtkWindowToImageFilter.h"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
......@@ -127,6 +132,24 @@ void Foam::functionObjects::runTimePostPro::scene::readColours
}
void Foam::functionObjects::runTimePostPro::scene::readAxes
(
const dictionary& dict
)
{
// Off for backwards compatibility
axes_.visible = dict.getOrDefault<bool>("visible", false);
if (axes_.visible)
{
axes_.colour = dict.getOrDefault<vector>("colour", vector::max);
axes_.fontColour = dict.getOrDefault<vector>("fontColour", vector::max);
axes_.fontSize = dict.getOrDefault<scalar>("fontSize", 20);
axes_.lengthFactor = dict.getOrDefault<scalar>("lengthFactor", 0.1);
}
}
void Foam::functionObjects::runTimePostPro::scene::setActorVisibility
(
vtkRenderer* renderer,
......@@ -217,6 +240,56 @@ void Foam::functionObjects::runTimePostPro::scene::initialise
clipBoxActor_->VisibilityOff();
renderer->AddActor(clipBoxActor_);
}
// Add the axes
if (axes_.visible)
{
axes_.actor = vtkSmartPointer<vtkAxesActor>::New();
renderer->AddActor(axes_.actor);
axes_.actor->SetTotalLength
(
axes_.lengthFactor,
axes_.lengthFactor,
axes_.lengthFactor
);
auto axisLabel = vtkSmartPointer<vtkTextProperty>::New();
axisLabel->SetFontFamilyToArial();
axisLabel->ShadowOff();
if (axes_.fontColour != vector::max)
{
const vector& c = axes_.fontColour;
axisLabel->SetColor(c[0], c[1], c[2]);
}
// SetFontSize only works if using SetTextScaleModeToNone - see below
axisLabel->SetFontSize(axes_.fontSize);
auto* axisX = axes_.actor->GetXAxisCaptionActor2D();
auto* axisY = axes_.actor->GetYAxisCaptionActor2D();
auto* axisZ = axes_.actor->GetZAxisCaptionActor2D();
axisX->SetCaptionTextProperty(axisLabel);
axisY->SetCaptionTextProperty(axisLabel);
axisZ->SetCaptionTextProperty(axisLabel);
// Note: SetTextScaleModeToNone
axisX->GetTextActor()->SetTextScaleModeToNone();
axisY->GetTextActor()->SetTextScaleModeToNone();
axisZ->GetTextActor()->SetTextScaleModeToNone();
if (axes_.colour != vector::max)
{
const vector& c = axes_.colour;
axes_.actor->GetXAxisShaftProperty()->SetColor(c[0], c[1], c[2]);
axes_.actor->GetYAxisShaftProperty()->SetColor(c[0], c[1], c[2]);
axes_.actor->GetZAxisShaftProperty()->SetColor(c[0], c[1], c[2]);
axes_.actor->GetXAxisTipProperty()->SetColor(c[0], c[1], c[2]);
axes_.actor->GetYAxisTipProperty()->SetColor(c[0], c[1], c[2]);
axes_.actor->GetZAxisTipProperty()->SetColor(c[0], c[1], c[2]);
}
}
}
......@@ -300,6 +373,7 @@ Foam::functionObjects::runTimePostPro::scene::scene
cameraZoom_(nullptr),
clipBox_(boundBox::invertedBox),
clipBoxActor_(),
axes_(),
parallelProjection_(true),
nFrameTotal_(1),
startPosition_(0),
......@@ -344,6 +418,7 @@ void Foam::functionObjects::runTimePostPro::scene::read
{
readCamera(dict.subDict("camera"));
readColours(dict.subDict("colours"));
readAxes(dict.subOrEmptyDict("axes"));
}
......
......@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2015-2019 OpenCFD Ltd.
Copyright (C) 2015-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -31,6 +31,17 @@ Description
Usage
\verbatim
// Optional axes dictionary
axes
{
visible yes;
colour (0 0 0);
fontColour (0.7 0.5 0.3);
fontSize 30;
lengthFactor 0.2;
}
camera
{
// Total number of frames to generate
......@@ -80,6 +91,7 @@ SourceFiles
class vtkActor;
class vtkRenderer;
class vtkRenderWindow;
class vtkAxesActor;
namespace Foam
{
......@@ -111,6 +123,9 @@ class scene
//- Read colour properties
void readColours(const dictionary& dict);
//- Read axes properties
void readAxes(const dictionary& dict);
//- Set visibility of all actors on/off
void setActorVisibility
(
......@@ -127,12 +142,25 @@ class scene
protected:
// Helper struct to manage axes properties
struct axesProperties
{
bool visible;
vector colour;
vector fontColour;
scalar fontSize;
scalar lengthFactor;
//- Axes actor
vtkSmartPointer<vtkAxesActor> actor;
};
// Protected Data
//- Colours
HashPtrTable<Function1<vector>> colours_;
// Camera settings
//- Position
......@@ -161,6 +189,9 @@ protected:
//- Clipping box actor
vtkSmartPointer<vtkActor> clipBoxActor_;
//- Axes properties;
axesProperties axes_;
//- Parallel projection flag
bool parallelProjection_;
......
  • Hi @andy, the feedback received from usage is good, however we would need functionality to relocate the axis to something in visible area (instead of default origin) according to camera orientation. Can you please add this feature?

Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment