diff --git a/src/PythonicAPI.md b/src/PythonicAPI.md index 49cce79889b644cf5039438020ec34b130bd63bd..d89a9a8c3b14ec2cd11bbddeaed4d4739d36385d 100644 --- a/src/PythonicAPI.md +++ b/src/PythonicAPI.md @@ -492,6 +492,7 @@ See [this tutorial](http://www.vtk.org/Wiki/VTK/Tutorials/3DDataTypes) for a bri [DataSetSurface](/PythonicAPI/VisualizationAlgorithms/DataSetSurface) | Cutting a hexahedron with a plane. The red line on the surface shows the cut. [DepthSortPolyData](/PythonicAPI/Visualization/DepthSortPolyData) | Poly Data Depth Sorting. [DisplacementPlot](/PythonicAPI/VisualizationAlgorithms/DisplacementPlot) | Show modal lines for a vibrating beam. +[DistanceToCamera](/PythonicAPI/Visualization/DistanceToCamera) | [FastSplatter](/PythonicAPI/Visualization/FastSplatter) | Convolve a splat image with every point in an input image. [FlyingHeadSlice](/PythonicAPI/VisualizationAlgorithms/FlyingHeadSlice) | Flying edges used to generate contour lines. [FroggieSurface](/PythonicAPI/Visualization/FroggieSurface) | Construct surfaces from a segmented frog dataset. Up to fifteen different surfaces may be extracted. You can turn on and off surfaces and control the camera position. @@ -596,6 +597,7 @@ See [this tutorial](http://www.vtk.org/Wiki/VTK/Tutorials/3DDataTypes) for a bri [CheckerboardWidget](/PythonicAPI/Widgets/CheckerboardWidget) | Compare two images using a checkerboard. [CompassWidget](/PythonicAPI/Widgets/CompassWidget) | Draws an interactive compass. [ContourWidget](/PythonicAPI/Widgets/ContourWidget) | Draw a contour (line) which can be deformed by the user. +[DistanceWidget](/PythonicAPI/Widgets/DistanceWidget) | [ImplicitConeWidget](/PythonicAPI/Widgets/ImplicitConeWidget) | An interactive implicit cone widget. [ImplicitPlaneWidget2](/PythonicAPI/Widgets/ImplicitPlaneWidget2) | Clip polydata with an implicit plane. [PolygonalSurfacePointPlacer](/PythonicAPI/PolyData/PolygonalSurfacePointPlacer) | Used in conjunction with vtkContourWidget to draw curves on a surface. diff --git a/src/PythonicAPI/Visualization/DistanceToCamera.md b/src/PythonicAPI/Visualization/DistanceToCamera.md new file mode 100644 index 0000000000000000000000000000000000000000..7422470d6a801b46bdbce134e28b2164bf7b7108 --- /dev/null +++ b/src/PythonicAPI/Visualization/DistanceToCamera.md @@ -0,0 +1,3 @@ +### Description + +This example produces two arrows whose scale stays fixed with respect to the distance from the camera (i.e. as you zoom in and out). Standard spheres are drawn for comparison. diff --git a/src/PythonicAPI/Visualization/DistanceToCamera.py b/src/PythonicAPI/Visualization/DistanceToCamera.py new file mode 100644 index 0000000000000000000000000000000000000000..fa6a878dbe8b641ceff5372c18e24eab1dd82993 --- /dev/null +++ b/src/PythonicAPI/Visualization/DistanceToCamera.py @@ -0,0 +1,96 @@ +#!/usr/bin/env python3 + +# noinspection PyUnresolvedReferences +import vtkmodules.vtkInteractionStyle +# noinspection PyUnresolvedReferences +import vtkmodules.vtkRenderingOpenGL2 +from vtkmodules.vtkCommonColor import vtkNamedColors +from vtkmodules.vtkCommonDataModel import vtkDataObject +from vtkmodules.vtkFiltersCore import vtkGlyph3D +from vtkmodules.vtkFiltersSources import vtkSphereSource, vtkPointSource, vtkArrowSource +from vtkmodules.vtkInteractionStyle import vtkInteractorStyleTrackballCamera +from vtkmodules.vtkRenderingCore import ( + vtkActor, + vtkPolyDataMapper, + vtkRenderer, + vtkRenderWindow, + vtkRenderWindowInteractor, vtkDistanceToCamera +) + + +def main(): + colors = vtkNamedColors() + + # --------------------------------------------------------------------------- + # Draw some arrows that maintain a fixed size during zooming. + + # Create a set of points. + fixed_point_source = vtkPointSource(number_of_points=2) + + # Calculate the distance to the camera of each point. + distance_to_camera = vtkDistanceToCamera(screen_size=100.0) + fixed_point_source >> distance_to_camera + + # Glyph each point with an arrow. + arrow = vtkArrowSource() + fixed_glyph = vtkGlyph3D(input_connection=distance_to_camera.output_port, source_connection=arrow.output_port) + + # Scale each point. + fixed_glyph.SetScaleModeToScaleByScalar() + fixed_glyph.SetInputArrayToProcess(0, 0, 0, vtkDataObject.FIELD_ASSOCIATION_POINTS, 'DistanceToCamera') + + # Create a mapper. + fixed_mapper = vtkPolyDataMapper(scalar_visibility=False) + fixed_glyph >> fixed_mapper + + # Create an actor. + fixed_actor = vtkActor(mapper=fixed_mapper) + fixed_actor.property.color = colors.GetColor3d('Cyan') + + # --------------------------------------------------------------------------- + # Draw some spheres that get bigger when zooming in. + # Create a set of points. + point_source = vtkPointSource(number_of_points=4) + + # Glyph each point with a sphere. + sphere = vtkSphereSource() + glyph = vtkGlyph3D(input_connection=point_source.output_port, source_connection=sphere.output_port) + glyph.SetScaleFactor(0.1) + + # Create a mapper. + mapper = vtkPolyDataMapper(scalar_visibility=False) + glyph >> mapper + + # Create an actor. + actor = vtkActor(mapper=mapper) + actor.property.color = colors.GetColor3d('Yellow') + + # --------------------------------------------------------------------------- + + # A renderer and render window. + renderer = vtkRenderer(background=colors.GetColor3d('SlateGray')) + render_window = vtkRenderWindow(window_name='DistanceToCamera') + render_window.AddRenderer(renderer) + + # Give DistanceToCamera a pointer to the renderer. + distance_to_camera.renderer = renderer + + # Add the actors to the scene. + renderer.AddActor(fixed_actor) + renderer.AddActor(actor) + + # An interactor. + render_window_interactor = vtkRenderWindowInteractor() + style = vtkInteractorStyleTrackballCamera() + render_window_interactor.interactor_style = style + render_window_interactor.render_window = render_window + + # Render an image (lights and cameras are created automatically). + render_window.Render() + + # Begin mouse interaction. + render_window_interactor.Start() + + +if __name__ == '__main__': + main() diff --git a/src/PythonicAPI/Widgets/DistanceWidget.md b/src/PythonicAPI/Widgets/DistanceWidget.md new file mode 100644 index 0000000000000000000000000000000000000000..087020dae748764b17c0375c01026e9ef23893c0 --- /dev/null +++ b/src/PythonicAPI/Widgets/DistanceWidget.md @@ -0,0 +1,5 @@ +### Description + +* Contributed by Arnaud Gelas + +Click two points to see the distance between them. diff --git a/src/PythonicAPI/Widgets/DistanceWidget.py b/src/PythonicAPI/Widgets/DistanceWidget.py new file mode 100644 index 0000000000000000000000000000000000000000..b7ca38e4ac68658234ae47d5c1a2a9638c10bfbe --- /dev/null +++ b/src/PythonicAPI/Widgets/DistanceWidget.py @@ -0,0 +1,43 @@ +#!/usr/bin/python3 + +# noinspection PyUnresolvedReferences +import vtkmodules.vtkInteractionStyle +# noinspection PyUnresolvedReferences +import vtkmodules.vtkRenderingOpenGL2 +from vtkmodules.vtkCommonColor import vtkNamedColors +from vtkmodules.vtkInteractionWidgets import vtkDistanceWidget +from vtkmodules.vtkRenderingCore import ( + vtkRenderWindow, + vtkRenderWindowInteractor, + vtkRenderer +) + + +def main(): + colors = vtkNamedColors() + + # A renderer and render window. + renderer = vtkRenderer(background=colors.GetColor3d('Navy')) + render_window = vtkRenderWindow(window_name='DistanceWidget') + render_window.AddRenderer(renderer) + # An interactor. + render_window_interactor = vtkRenderWindowInteractor() + render_window_interactor.render_window = render_window + + distance_widget = vtkDistanceWidget(interactor=render_window_interactor) + distance_widget.CreateDefaultRepresentation() + distance_widget.representation.label_format = '%-#6.3g mm' + + # Render an image (lights and cameras are created automatically). + render_window.Render() + + render_window_interactor.Initialize() + render_window.Render() + distance_widget.On() + + # Begin mouse interaction. + render_window_interactor.Start() + + +if __name__ == '__main__': + main() diff --git a/src/Testing/Baseline/PythonicAPI/Visualization/TestDistanceToCamera.png b/src/Testing/Baseline/PythonicAPI/Visualization/TestDistanceToCamera.png new file mode 100644 index 0000000000000000000000000000000000000000..2b011898450af1b469341978437fa5e6fd49da97 --- /dev/null +++ b/src/Testing/Baseline/PythonicAPI/Visualization/TestDistanceToCamera.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ee33edeff2cc89a5194e20dc96be4f7ed8113eae1d46c5033ed20d049521656c +size 6455 diff --git a/src/Testing/Baseline/PythonicAPI/Widgets/TestDistanceWidget.png b/src/Testing/Baseline/PythonicAPI/Widgets/TestDistanceWidget.png new file mode 100644 index 0000000000000000000000000000000000000000..12f36176bb821f312d0aa58119c8e438fa851083 --- /dev/null +++ b/src/Testing/Baseline/PythonicAPI/Widgets/TestDistanceWidget.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a6f0a7b9a86bde0de32dc03a81469ea5aa7f8fab27016ad32caf44f7381fdbe8 +size 912