Skip to content

Addition of --axesGrid option #2100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions application/F3DOptionsTools.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ static inline const std::array<CLIGroup, 8> CLIOptions = {{
{ "grid-unit", "", "Size of grid unit square, automatically computed by default", "<value>", "" },
{ "grid-subdivisions", "", "Number of grid subdivisions", "<value>", "" },
{ "grid-color", "", "Color of main grid lines", "<color>", "" },
{ "axes-grid", "", "Enable grid axis", "<bool>", "1" },
{ "edges", "e", "Show cell edges", "<bool>", "1" },
{ "armature", "", "Enable armature visualization", "<bool>", "1" },
{ "camera-index", "", "Select the camera to use", "<index>", "" },
Expand Down
1 change: 1 addition & 0 deletions application/F3DOptionsTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ static inline const std::map<std::string_view, std::string_view> LibOptionsNames
{ "grid-unit", "render.grid.unit" },
{ "grid-subdivisions", "render.grid.subdivisions" },
{ "grid-color", "render.grid.color" },
{ "axes-grid", "render.axes_grid.enable" },
{ "edges", "render.show_edges" },
{ "armature", "render.armature.enable" },
{ "camera-index", "scene.camera.index" },
Expand Down
1 change: 1 addition & 0 deletions application/testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ f3d_test(NAME TestGridAbsolute DATA f3d.vtp ARGS -g --up=-Y --camera-direction=-
f3d_test(NAME TestGridClipping DATA offset-flat-box.glb ARGS -g --grid-absolute --camera-position=70,120,350)
f3d_test(NAME TestGridColor DATA suzanne.ply ARGS -g --grid-color=1,1,1)
f3d_test(NAME TestAxis DATA suzanne.ply ARGS -x)
f3d_test(NAME TestAxesGridEnable DATA suzanne.ply ARGS --axes-grid)
f3d_test(NAME TestBackfaceVisible DATA backface.vtp ARGS --backface-type=visible)
f3d_test(NAME TestBackfaceHidden DATA backface.vtp ARGS --backface-type=hidden)
f3d_test(NAME TestPointCloud DATA pointsCloud.vtp ARGS -o --point-sprites-size=20)
Expand Down
6 changes: 6 additions & 0 deletions library/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@
"default_value": "0.0, 0.0, 0.0"
}
},
"axes_grid": {
"enable": {
"type": "bool",
"default_value": "false"
}
},
"raytracing": {
"enable": {
"type": "bool",
Expand Down
2 changes: 2 additions & 0 deletions library/src/window_impl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,8 @@ void window_impl::UpdateDynamicOptions()
renderer->ShowGrid(opt.render.grid.enable);
renderer->SetGridColor(opt.render.grid.color);

renderer->ShowAxesGrid(opt.render.axes_grid.enable);

if (!opt.scene.camera.index.has_value())
{
renderer->SetUseOrthographicProjection(opt.scene.camera.orthographic);
Expand Down
3 changes: 3 additions & 0 deletions testing/baselines/TestAxesGridEnable.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
88 changes: 88 additions & 0 deletions vtkext/private/module/vtkF3DRenderer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <vtkCellData.h>
#include <vtkColorTransferFunction.h>
#include <vtkCornerAnnotation.h>
#include <vtkCubeAxesActor.h>
#include <vtkCullerCollection.h>
#include <vtkFloatArray.h>
#include <vtkImageData.h>
Expand Down Expand Up @@ -264,6 +265,7 @@ void vtkF3DRenderer::Initialize()

this->AddViewProp(this->ScalarBarActor);
this->AddActor(this->GridActor);
this->AddActor(this->CubeAxesActor);
this->AddActor(this->SkyboxActor);
this->AddActor(this->UIActor);

Expand Down Expand Up @@ -709,6 +711,87 @@ void vtkF3DRenderer::ConfigureGridUsingCurrentActors()
this->ResetCameraClippingRange();
}

//----------------------------------------------------------------------------
void vtkF3DRenderer::ShowAxesGrid(bool show)
{
if (this->AxesGridVisible != show)
{
this->AxesGridVisible = show;
this->RenderPassesConfigured = false;
this->CubeAxesConfigured = false;
this->CheatSheetConfigured = false;
}
}

//----------------------------------------------------------------------------
void vtkF3DRenderer::ConfigureCubeAxisUsingCurrentActors()
{
bool show = this->AxesGridVisible;
if (show)
{
double* up = this->GetEnvironmentUp();
double* right = this->GetEnvironmentRight();
double front[3];
vtkMath::Cross(right, up, front);

vtkNew<vtkMatrix4x4> upMatrix;
const double m[16] = {
right[0], right[1], right[2], 0, //
up[0], up[1], up[2], 0, //
front[0], front[1], front[2], 0, //
0, 0, 0, 1, //
};
upMatrix->DeepCopy(m);
vtkNew<vtkMatrix4x4> upMatrixInv;
upMatrixInv->DeepCopy(upMatrix);
upMatrixInv->Transpose();

double orientation[3];
vtkTransform::GetOrientation(orientation, upMatrixInv);
const vtkBoundingBox bbox = this->ComputeVisiblePropOrientedBounds(upMatrix);

if (!bbox.IsValid())
{
show = false;
}
else
{
this->CubeAxesActor->SetOrientation(orientation);
this->CubeAxesActor->SetVisibility(true);

double center[4] = { 0, 0, 0, 1 };
bbox.GetCenter(center);

this->CubeAxesActor->SetPosition(center);

double a, b, c, x, y, z;
bbox.GetBounds(a, b, c, x, y, z);
double bounds[6] = { a, b, c, x, y, z };
this->CubeAxesActor->SetBounds(bounds);

this->CubeAxesActor->XAxisLabelVisibilityOn();
this->CubeAxesActor->YAxisLabelVisibilityOn();
this->CubeAxesActor->ZAxisLabelVisibilityOn();
this->CubeAxesActor->SetCamera(GetActiveCamera());

this->CubeAxesActor->SetFlyModeToStaticEdges();
this->CubeAxesActor->SetXAxisMinorTickVisibility(false);
this->CubeAxesActor->SetYAxisMinorTickVisibility(false);
this->CubeAxesActor->SetZAxisMinorTickVisibility(false);

this->CubeAxesActor->GetLabelTextProperty(0)->SetColor(right);
this->CubeAxesActor->GetTitleTextProperty(0)->SetColor(right);
this->CubeAxesActor->GetLabelTextProperty(1)->SetColor(up);
this->CubeAxesActor->GetTitleTextProperty(1)->SetColor(up);
this->CubeAxesActor->GetLabelTextProperty(2)->SetColor(front);
this->CubeAxesActor->GetTitleTextProperty(2)->SetColor(front);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this color code seems incorrect

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind explaining which part is incorrect?

I matched the axes colours against the grid (shortcut g)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You use the right/up/front vector as colors, resulting in pure red and green in the grid, im not sure this is intended ?

Copy link
Author

@ArchiePayne ArchiePayne Mar 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just took the idea from line 699-700 within vtkF3DRenderer.cxx, where the grid colour is set.

gridMapper->SetAxis1Color(::abs(right[0]), ::abs(right[1]), ::abs(right[2]), 1);

gridMapper->SetAxis2Color(::abs(front[0]), ::abs(front[1]), ::abs(front[2]), 1);

Do you have any suggestions for colours? Perhaps if there are any colours defined anywhere I could take them.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha right, ill take a look


this->CubeAxesConfigured = true;
}
}
this->CubeAxesActor->SetVisibility(show);
}

//----------------------------------------------------------------------------
vtkBoundingBox vtkF3DRenderer::ComputeVisiblePropOrientedBounds(const vtkMatrix4x4* matrix)
{
Expand Down Expand Up @@ -1708,6 +1791,11 @@ void vtkF3DRenderer::UpdateActors()
{
this->ConfigureGridUsingCurrentActors();
}

if (!this->CubeAxesConfigured)
{
this->ConfigureCubeAxisUsingCurrentActors();
}
}

//----------------------------------------------------------------------------
Expand Down
10 changes: 10 additions & 0 deletions vtkext/private/module/vtkF3DRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace fs = std::filesystem;

class vtkColorTransferFunction;
class vtkCornerAnnotation;
class vtkCubeAxesActor;
class vtkImageReader2;
class vtkOrientationMarkerWidget;
class vtkScalarBarActor;
Expand Down Expand Up @@ -53,6 +54,7 @@ class vtkF3DRenderer : public vtkOpenGLRenderer
*/
void ShowAxis(bool show);
void ShowGrid(bool show);
void ShowAxesGrid(bool show);
void ShowEdge(const std::optional<bool>& show);
void ShowTimer(bool show);
void ShowMetaData(bool show);
Expand Down Expand Up @@ -451,6 +453,11 @@ class vtkF3DRenderer : public vtkOpenGLRenderer
*/
void ConfigureGridUsingCurrentActors();

/**
* Configure the cube Axis actor
*/
void ConfigureCubeAxisUsingCurrentActors();

/**
* Configure the different render passes
*/
Expand Down Expand Up @@ -496,6 +503,7 @@ class vtkF3DRenderer : public vtkOpenGLRenderer
vtkSmartPointer<vtkOrientationMarkerWidget> AxisWidget;

vtkNew<vtkActor> GridActor;
vtkNew<vtkCubeAxesActor> CubeAxesActor;
vtkNew<vtkSkybox> SkyboxActor;
vtkNew<vtkF3DUIActor> UIActor;

Expand All @@ -504,6 +512,7 @@ class vtkF3DRenderer : public vtkOpenGLRenderer
bool CheatSheetConfigured = false;
bool ActorsPropertiesConfigured = false;
bool GridConfigured = false;
bool CubeAxesConfigured = false;
bool RenderPassesConfigured = false;
bool LightIntensitiesConfigured = false;
bool TextActorsConfigured = false;
Expand All @@ -519,6 +528,7 @@ class vtkF3DRenderer : public vtkOpenGLRenderer
bool GridVisible = false;
bool GridAbsolute = false;
bool AxisVisible = false;
bool AxesGridVisible = false;
std::optional<bool> EdgeVisible;
bool TimerVisible = false;
bool FilenameVisible = false;
Expand Down
Loading