From 488b411e71828cab7c593eea254a5536c387555f Mon Sep 17 00:00:00 2001 From: Andrew Maclean <andrew.amaclean@gmail.com> Date: Mon, 30 Dec 2024 09:08:58 +1100 Subject: [PATCH] Sphere->SphereSource, adding images and orientation markers --- src/Cxx.md | 7 +++-- src/Cxx/Annotation/CMakeLists.txt | 1 + src/Cxx/Annotation/PolarAxesActor.cxx | 13 +++++++++ src/Cxx/GeometricObjects/GoldenBallSource.cxx | 13 +++++++++ .../{Sphere.cxx => SphereSource.cxx} | 16 ++++++++++- .../{Sphere.md => SphereSource.md} | 0 src/PythonicAPI.md | 2 ++ src/PythonicAPI/Annotation/PolarAxesActor.py | 9 ++++++ .../GeometricObjects/GoldenBallSource.py | 28 +++++++++++++------ .../{Sphere.md => SphereSource.md} | 0 .../{Sphere.py => SphereSource.py} | 22 +++++++++++---- .../Cxx/Annotation/TestPolarAxesActor.png | 4 +-- .../GeometricObjects/TestGoldenBallSource.png | 3 ++ .../Cxx/GeometricObjects/TestSphere.png | 3 -- .../Cxx/GeometricObjects/TestSphereSource.png | 3 ++ .../Annotation/TestPolarAxesActor.png | 4 +-- .../GeometricObjects/TestGoldenBallSource.png | 3 ++ .../GeometricObjects/TestSphereSource.png | 3 ++ 18 files changed, 110 insertions(+), 24 deletions(-) rename src/Cxx/GeometricObjects/{Sphere.cxx => SphereSource.cxx} (77%) rename src/Cxx/GeometricObjects/{Sphere.md => SphereSource.md} (100%) rename src/PythonicAPI/GeometricObjects/{Sphere.md => SphereSource.md} (100%) rename src/PythonicAPI/GeometricObjects/{Sphere.py => SphereSource.py} (50%) create mode 100644 src/Testing/Baseline/Cxx/GeometricObjects/TestGoldenBallSource.png delete mode 100644 src/Testing/Baseline/Cxx/GeometricObjects/TestSphere.png create mode 100644 src/Testing/Baseline/Cxx/GeometricObjects/TestSphereSource.png create mode 100644 src/Testing/Baseline/PythonicAPI/GeometricObjects/TestGoldenBallSource.png create mode 100644 src/Testing/Baseline/PythonicAPI/GeometricObjects/TestSphereSource.png diff --git a/src/Cxx.md b/src/Cxx.md index 20416e67bee..3f2a61f795e 100644 --- a/src/Cxx.md +++ b/src/Cxx.md @@ -218,19 +218,20 @@ If you are new to VTK then these [tutorials](#tutorial) will help to get you sta | -------------- | ------------- | ------- | [Arrow](/Cxx/GeometricObjects/Arrow) | [Cone](/Cxx/GeometricObjects/Cone) | Display a cone -[ConeDemo](/Cxx/GeometricObjects/ConeDemo) | Disolay four different resolution cones. +[ConeDemo](/Cxx/GeometricObjects/ConeDemo) | Display four different resolution cones. [Cylinder](/Cxx/GeometricObjects/Cylinder) | [Disk](/Cxx/GeometricObjects/Disk) | A circle with a hole in it. [EarthSource](/Cxx/GeometricObjects/EarthSource) | Create the Earth. [Frustum](/Cxx/GeometricObjects/Frustum) | +[GoldenBallSource](/Cxx/GeometricObjects/GoldenBallSource) | Construct a solid, tetrahedralized ball. [Line](/Cxx/GeometricObjects/Line) | [OrientedArrow](/Cxx/GeometricObjects/OrientedArrow) | Orient an arrow along an arbitrary vector. [OrientedCylinder](/Cxx/GeometricObjects/OrientedCylinder) | Orient a cylinder along an arbitrary vector. -[Plane](/Cxx/GeometricObjects/Plane) | +[Plane](/Cxx/GeometricObjects/Plane) | Construct a plane. [PlatonicSolids](/Cxx/GeometricObjects/PlatonicSolids) | [PolyLine1](/Cxx/GeometricObjects/PolyLine1) | This example demonstrates how to create a polygon through several ordered points. [RegularPolygonSource](/Cxx/GeometricObjects/RegularPolygonSource) | -[Sphere](/Cxx/GeometricObjects/Sphere) | +[SphereSource](/Cxx/GeometricObjects/SphereSource) | Construct a sphere. [TessellatedBoxSource](/Cxx/GeometricObjects/TessellatedBoxSource) | Generate a box with tessellated sides. [TextActor](/Cxx/GeometricObjects/TextActor) | 2D "HUD-type" text diff --git a/src/Cxx/Annotation/CMakeLists.txt b/src/Cxx/Annotation/CMakeLists.txt index 16a44f00008..7546b9dea77 100644 --- a/src/Cxx/Annotation/CMakeLists.txt +++ b/src/Cxx/Annotation/CMakeLists.txt @@ -13,6 +13,7 @@ if(NOT VTK_BINARY_DIR) FiltersSources IOParallel InteractionStyle + InteractionWidgets RenderingAnnotation RenderingCore RenderingFreeType diff --git a/src/Cxx/Annotation/PolarAxesActor.cxx b/src/Cxx/Annotation/PolarAxesActor.cxx index 7352f0d209e..bff8f8d6c0d 100644 --- a/src/Cxx/Annotation/PolarAxesActor.cxx +++ b/src/Cxx/Annotation/PolarAxesActor.cxx @@ -1,5 +1,7 @@ #include <vtkActor.h> #include <vtkCamera.h> +#include <vtkCameraOrientationWidget.h> +#include <vtkInteractorStyleSwitch.h> #include <vtkNamedColors.h> #include <vtkNew.h> #include <vtkParametricEnneper.h> @@ -43,6 +45,12 @@ int main(int, char*[]) vtkNew<vtkRenderWindowInteractor> renderWindowInteractor; renderWindowInteractor->SetRenderWindow(renderWindow); + auto is = vtkInteractorStyleSwitch::SafeDownCast( + renderWindowInteractor->GetInteractorStyle()); + if (is) + { + is->SetCurrentStyleToTrackballCamera(); + } double* bounds; bounds = fnSrc->GetOutput()->GetBounds(); @@ -78,6 +86,11 @@ int main(int, char*[]) polarAxesActor->SetCamera(renderer->GetActiveCamera()); renderer->ResetCamera(); + vtkNew<vtkCameraOrientationWidget> cow; + cow->SetParentRenderer(renderer); + // Enable the widget. + cow->On(); + renderer->SetBackground(colors->GetColor3d("MidnightBlue").GetData()); // Render and interact. diff --git a/src/Cxx/GeometricObjects/GoldenBallSource.cxx b/src/Cxx/GeometricObjects/GoldenBallSource.cxx index 24a4e76952c..b5f6e308048 100644 --- a/src/Cxx/GeometricObjects/GoldenBallSource.cxx +++ b/src/Cxx/GeometricObjects/GoldenBallSource.cxx @@ -1,6 +1,8 @@ #include <vtkActor.h> +#include <vtkCameraOrientationWidget.h> #include <vtkDataSetMapper.h> #include <vtkGoldenBallSource.h> +#include <vtkInteractorStyleSwitch.h> #include <vtkNamedColors.h> #include <vtkNew.h> #include <vtkProperty.h> @@ -45,9 +47,20 @@ int main(int, char*[]) renderWindow->AddRenderer(renderer); vtkNew<vtkRenderWindowInteractor> renderWindowInteractor; renderWindowInteractor->SetRenderWindow(renderWindow); + auto is = vtkInteractorStyleSwitch::SafeDownCast( + renderWindowInteractor->GetInteractorStyle()); + if (is) + { + is->SetCurrentStyleToTrackballCamera(); + } renderer->AddActor(actor); + vtkNew<vtkCameraOrientationWidget> cow; + cow->SetParentRenderer(renderer); + // Enable the widget. + cow->On(); + renderWindow->Render(); renderWindowInteractor->Start(); diff --git a/src/Cxx/GeometricObjects/Sphere.cxx b/src/Cxx/GeometricObjects/SphereSource.cxx similarity index 77% rename from src/Cxx/GeometricObjects/Sphere.cxx rename to src/Cxx/GeometricObjects/SphereSource.cxx index 41df0587753..8af6cda05dd 100644 --- a/src/Cxx/GeometricObjects/Sphere.cxx +++ b/src/Cxx/GeometricObjects/SphereSource.cxx @@ -1,4 +1,6 @@ #include <vtkActor.h> +#include <vtkCameraOrientationWidget.h> +#include <vtkInteractorStyleSwitch.h> #include <vtkNamedColors.h> #include <vtkNew.h> #include <vtkPolyDataMapper.h> @@ -23,6 +25,7 @@ int main(int, char*[]) // Make the surface smooth. sphereSource->SetPhiResolution(50); sphereSource->SetThetaResolution(50); + sphereSource->LatLongTessellationOff(); vtkNew<vtkPolyDataMapper> mapper; mapper->SetInputConnection(sphereSource->GetOutputPort()); @@ -39,14 +42,25 @@ int main(int, char*[]) vtkNew<vtkRenderer> renderer; vtkNew<vtkRenderWindow> renderWindow; renderWindow->SetSize(600, 600); - renderWindow->SetWindowName("Sphere"); + renderWindow->SetWindowName("Sphere Source"); renderWindow->AddRenderer(renderer); vtkNew<vtkRenderWindowInteractor> renderWindowInteractor; renderWindowInteractor->SetRenderWindow(renderWindow); + auto is = vtkInteractorStyleSwitch::SafeDownCast( + renderWindowInteractor->GetInteractorStyle()); + if (is) + { + is->SetCurrentStyleToTrackballCamera(); + } renderer->AddActor(actor); renderer->SetBackground(colors->GetColor3d("ParaViewBkg").GetData()); + vtkNew<vtkCameraOrientationWidget> cow; + cow->SetParentRenderer(renderer); + // Enable the widget. + cow->On(); + renderWindow->Render(); renderWindowInteractor->Start(); diff --git a/src/Cxx/GeometricObjects/Sphere.md b/src/Cxx/GeometricObjects/SphereSource.md similarity index 100% rename from src/Cxx/GeometricObjects/Sphere.md rename to src/Cxx/GeometricObjects/SphereSource.md diff --git a/src/PythonicAPI.md b/src/PythonicAPI.md index 7d5f59e3dd5..0b046878aed 100644 --- a/src/PythonicAPI.md +++ b/src/PythonicAPI.md @@ -149,9 +149,11 @@ This Python script, [SelectExamples](../PythonicAPI/Utilities/SelectExamples), w | -------------- | ------------- | ------- | [EarthSource](/PythonicAPI/GeometricObjects/EarthSource) | Create the Earth. [Frustum](/PythonicAPI/GeometricObjects/Frustum) | +[GoldenBallSource](/PythonicAPI/GeometricObjects/GoldenBallSource) | Construct a solid, tetrahedralized ball. [OrientedArrow](/PythonicAPI/GeometricObjects/OrientedArrow) | Orient an arrow along an arbitrary vector. [OrientedCylinder](/PythonicAPI/GeometricObjects/OrientedCylinder) | Orient a cylinder along an arbitrary vector. [PlatonicSolids](/PythonicAPI/GeometricObjects/PlatonicSolids) | All five platonic solids are displayed. +[SphereSource](/PythonicAPI/GeometricObjects/SphereSource) | Construct a sphere. [TessellatedBoxSource](/PythonicAPI/GeometricObjects/TessellatedBoxSource) | Generate a box with tessellated sides. ### Non Linear diff --git a/src/PythonicAPI/Annotation/PolarAxesActor.py b/src/PythonicAPI/Annotation/PolarAxesActor.py index 2b8f6f9ea7a..7965c7872a0 100755 --- a/src/PythonicAPI/Annotation/PolarAxesActor.py +++ b/src/PythonicAPI/Annotation/PolarAxesActor.py @@ -9,6 +9,7 @@ import vtkmodules.vtkRenderingOpenGL2 from vtkmodules.vtkCommonColor import vtkNamedColors from vtkmodules.vtkCommonComputationalGeometry import vtkParametricEnneper from vtkmodules.vtkFiltersSources import vtkParametricFunctionSource +from vtkmodules.vtkInteractionWidgets import vtkCameraOrientationWidget from vtkmodules.vtkRenderingAnnotation import vtkPolarAxesActor from vtkmodules.vtkRenderingCore import ( vtkActor, @@ -39,6 +40,9 @@ def main(): render_window.AddRenderer(renderer) render_window_interactor = vtkRenderWindowInteractor() render_window_interactor.render_window = render_window + # Since we import vtkmodules.vtkInteractionStyle we can do this + # because vtkInteractorStyleSwitch is automatically imported: + render_window_interactor.interactor_style.SetCurrentStyleToTrackballCamera() bounds = fn_src.update().output.bounds radius = math.sqrt(abs(dot_product((bounds[0], bounds[2]), (bounds[1], bounds[3])))) @@ -66,6 +70,11 @@ def main(): polar_axes_actor.SetCamera(renderer.active_camera) renderer.ResetCamera() + cow = vtkCameraOrientationWidget(parent_renderer=renderer, + interactor=render_window_interactor) + # Enable the widget. + cow.On() + # Render and interact. render_window.Render() render_window_interactor.Start() diff --git a/src/PythonicAPI/GeometricObjects/GoldenBallSource.py b/src/PythonicAPI/GeometricObjects/GoldenBallSource.py index 0d80734eee0..f30b6ac0525 100755 --- a/src/PythonicAPI/GeometricObjects/GoldenBallSource.py +++ b/src/PythonicAPI/GeometricObjects/GoldenBallSource.py @@ -5,38 +5,50 @@ import vtkmodules.vtkInteractionStyle # noinspection PyUnresolvedReferences import vtkmodules.vtkRenderingOpenGL2 from vtkmodules.vtkCommonColor import vtkNamedColors -from vtkmodules.vtkFiltersSources import vtkSphereSource, vtkGoldenBallSource +from vtkmodules.vtkFiltersSources import vtkGoldenBallSource +from vtkmodules.vtkInteractionWidgets import vtkCameraOrientationWidget from vtkmodules.vtkRenderingCore import ( vtkActor, - vtkPolyDataMapper, vtkRenderWindow, vtkRenderWindowInteractor, - vtkRenderer, vtkMapper, vtkDataSetMapper, vtkProperty + vtkRenderer, vtkDataSetMapper, vtkProperty ) def main(): colors = vtkNamedColors() - colors.SetColor("ParaViewBkg", [82, 87, 110, 255]) + colors.SetColor("ParaViewBkg", 82, 87, 110, 255) # Create a golden ball. - golden_ball_source = vtkGoldenBallSource(center=(0.0, 0.0, 0.0), radius=5.0, resolution=200, generate_normals=True, include_center_point=True) + golden_ball_source = vtkGoldenBallSource(center=(0.0, 0.0, 0.0), + radius=5.0, resolution=200, + generate_normals=True, + include_center_point=True) mapper = vtkDataSetMapper() golden_ball_source >> mapper - actor_prop = vtkProperty(color = colors.GetColor3d('Gold'), edge_color = colors.GetColor3d('DarkSlateBlue'), edge_visibility = True) + actor_prop = vtkProperty(color=colors.GetColor3d('Gold'), edge_color=colors.GetColor3d('DarkSlateBlue'), + edge_visibility=True) actor = vtkActor(property=actor_prop, mapper=mapper) - renderer = vtkRenderer(background = colors.GetColor3d('ParaViewBkg')) - render_window = vtkRenderWindow(size=(600,600),window_name='Golden Ball Source') + renderer = vtkRenderer(background=colors.GetColor3d('ParaViewBkg')) + render_window = vtkRenderWindow(size=(600, 600), window_name='Golden Ball Source') render_window.AddRenderer(renderer) render_window_interactor = vtkRenderWindowInteractor() render_window_interactor.SetRenderWindow(render_window) + # Since we import vtkmodules.vtkInteractionStyle we can do this + # because vtkInteractorStyleSwitch is automatically imported: + render_window_interactor.interactor_style.SetCurrentStyleToTrackballCamera() renderer.AddActor(actor) renderer.ResetCamera() + cow = vtkCameraOrientationWidget(parent_renderer=renderer, + interactor=render_window_interactor) + # Enable the widget. + cow.On() + render_window.Render() render_window_interactor.Start() diff --git a/src/PythonicAPI/GeometricObjects/Sphere.md b/src/PythonicAPI/GeometricObjects/SphereSource.md similarity index 100% rename from src/PythonicAPI/GeometricObjects/Sphere.md rename to src/PythonicAPI/GeometricObjects/SphereSource.md diff --git a/src/PythonicAPI/GeometricObjects/Sphere.py b/src/PythonicAPI/GeometricObjects/SphereSource.py similarity index 50% rename from src/PythonicAPI/GeometricObjects/Sphere.py rename to src/PythonicAPI/GeometricObjects/SphereSource.py index e8afc525129..01681a46d3f 100755 --- a/src/PythonicAPI/GeometricObjects/Sphere.py +++ b/src/PythonicAPI/GeometricObjects/SphereSource.py @@ -6,6 +6,7 @@ import vtkmodules.vtkInteractionStyle import vtkmodules.vtkRenderingOpenGL2 from vtkmodules.vtkCommonColor import vtkNamedColors from vtkmodules.vtkFiltersSources import vtkSphereSource +from vtkmodules.vtkInteractionWidgets import vtkCameraOrientationWidget from vtkmodules.vtkRenderingCore import ( vtkActor, vtkPolyDataMapper, @@ -17,25 +18,36 @@ from vtkmodules.vtkRenderingCore import ( def main(): colors = vtkNamedColors() - colors.SetColor("ParaViewBkg", [82, 87, 110, 255]) + colors.SetColor("ParaViewBkg", 82, 87, 110, 255) # Create a sphere. - sphere_source = vtkSphereSource(center=(0.0, 0.0, 0.0), radius=5.0, phi_resolution=50, theta_resolution=50) + sphere_source = vtkSphereSource(center=(0.0, 0.0, 0.0), radius=5.0, + phi_resolution=50, theta_resolution=50, + lat_long_tessellation=False) mapper = vtkPolyDataMapper() sphere_source >> mapper - actor_prop = vtkProperty(color = colors.GetColor3d('Peru'), edge_color = colors.GetColor3d('DarkSlateBlue'), edge_visibility = True) + actor_prop = vtkProperty(color=colors.GetColor3d('Peru'), edge_color=colors.GetColor3d('DarkSlateBlue'), + edge_visibility=True) actor = vtkActor(property=actor_prop, mapper=mapper) - renderer = vtkRenderer(background = colors.GetColor3d('ParaViewBkg')) - render_window = vtkRenderWindow(size=(600,600),window_name='Sphere') + renderer = vtkRenderer(background=colors.GetColor3d('ParaViewBkg')) + render_window = vtkRenderWindow(size=(600, 600), window_name='Sphere Source') render_window.AddRenderer(renderer) render_window_interactor = vtkRenderWindowInteractor() render_window_interactor.SetRenderWindow(render_window) + # Since we import vtkmodules.vtkInteractionStyle we can do this + # because vtkInteractorStyleSwitch is automatically imported: + render_window_interactor.interactor_style.SetCurrentStyleToTrackballCamera() renderer.AddActor(actor) + cow = vtkCameraOrientationWidget(parent_renderer=renderer, + interactor=render_window_interactor) + # Enable the widget. + cow.On() + render_window.Render() render_window_interactor.Start() diff --git a/src/Testing/Baseline/Cxx/Annotation/TestPolarAxesActor.png b/src/Testing/Baseline/Cxx/Annotation/TestPolarAxesActor.png index 7b595fffc4f..b0826e6a02c 100644 --- a/src/Testing/Baseline/Cxx/Annotation/TestPolarAxesActor.png +++ b/src/Testing/Baseline/Cxx/Annotation/TestPolarAxesActor.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:cdf09292a4b523c2ac8af7cc200f88c30b4b9114153e149b6e4378c9836f3716 -size 72184 +oid sha256:ca43404809ab78bb7e9f6b19300231c052ab39dcaa6a951b416dd35a538a3de4 +size 74520 diff --git a/src/Testing/Baseline/Cxx/GeometricObjects/TestGoldenBallSource.png b/src/Testing/Baseline/Cxx/GeometricObjects/TestGoldenBallSource.png new file mode 100644 index 00000000000..845ed75d25c --- /dev/null +++ b/src/Testing/Baseline/Cxx/GeometricObjects/TestGoldenBallSource.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:51a174c1c774a6c993a02d7c21995dbc1f5dbb65b468b264e933af724f3ebe2b +size 115759 diff --git a/src/Testing/Baseline/Cxx/GeometricObjects/TestSphere.png b/src/Testing/Baseline/Cxx/GeometricObjects/TestSphere.png deleted file mode 100644 index 48037d829e5..00000000000 --- a/src/Testing/Baseline/Cxx/GeometricObjects/TestSphere.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:0c98cd9e7e14e0b4fb23acf83712c6bf1a018081eada3ee94244ae0ec1d9e44d -size 18855 diff --git a/src/Testing/Baseline/Cxx/GeometricObjects/TestSphereSource.png b/src/Testing/Baseline/Cxx/GeometricObjects/TestSphereSource.png new file mode 100644 index 00000000000..646e9087cb0 --- /dev/null +++ b/src/Testing/Baseline/Cxx/GeometricObjects/TestSphereSource.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4e4e1c764056abbf05e1d966c13ababe1f66c35d8c16d3db5306a045d165a05b +size 209379 diff --git a/src/Testing/Baseline/PythonicAPI/Annotation/TestPolarAxesActor.png b/src/Testing/Baseline/PythonicAPI/Annotation/TestPolarAxesActor.png index 7b595fffc4f..b0826e6a02c 100644 --- a/src/Testing/Baseline/PythonicAPI/Annotation/TestPolarAxesActor.png +++ b/src/Testing/Baseline/PythonicAPI/Annotation/TestPolarAxesActor.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:cdf09292a4b523c2ac8af7cc200f88c30b4b9114153e149b6e4378c9836f3716 -size 72184 +oid sha256:ca43404809ab78bb7e9f6b19300231c052ab39dcaa6a951b416dd35a538a3de4 +size 74520 diff --git a/src/Testing/Baseline/PythonicAPI/GeometricObjects/TestGoldenBallSource.png b/src/Testing/Baseline/PythonicAPI/GeometricObjects/TestGoldenBallSource.png new file mode 100644 index 00000000000..845ed75d25c --- /dev/null +++ b/src/Testing/Baseline/PythonicAPI/GeometricObjects/TestGoldenBallSource.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:51a174c1c774a6c993a02d7c21995dbc1f5dbb65b468b264e933af724f3ebe2b +size 115759 diff --git a/src/Testing/Baseline/PythonicAPI/GeometricObjects/TestSphereSource.png b/src/Testing/Baseline/PythonicAPI/GeometricObjects/TestSphereSource.png new file mode 100644 index 00000000000..646e9087cb0 --- /dev/null +++ b/src/Testing/Baseline/PythonicAPI/GeometricObjects/TestSphereSource.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4e4e1c764056abbf05e1d966c13ababe1f66c35d8c16d3db5306a045d165a05b +size 209379 -- GitLab