Skip to content
Snippets Groups Projects
Commit f16bf69e authored by Andrew Maclean's avatar Andrew Maclean
Browse files

Adding PolarAxesActor.cxx

parent 4a20d038
No related branches found
No related tags found
1 merge request!395Adding some new vtk 9.4 examples
......@@ -944,6 +944,7 @@ This section includes ?vtkUnstructuredGrid?.
| -------------- | ------------- | ------- |
[LegendScaleActor](/Cxx/Annotation/LegendScaleActor) | Display the scale of a scene.
[MultiLineText](/Cxx/Annotation/MultiLineText) | Display multiline text.
[PolarAxesActor](/Cxx/Annotation/PolarAxesActor) | Draw polar axes in a specified plane for a given pole.
[TextOrigin](/Cxx/Annotation/TextOrigin) | The 3D text always faces the active camera.
[XYPlot](/Cxx/Annotation/XYPlot) | Display line probes.
......
#include <vtkActor.h>
#include <vtkCamera.h>
#include <vtkNamedColors.h>
#include <vtkNew.h>
#include <vtkParametricEnneper.h>
#include <vtkParametricFunctionSource.h>
#include <vtkPolarAxesActor.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkProperty2D.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <cmath>
#include <numeric>
#include <vector>
int main(int, char*[])
{
vtkNew<vtkNamedColors> colors;
// The source will be a parametric function.
vtkNew<vtkParametricEnneper> src;
vtkNew<vtkParametricFunctionSource> fnSrc;
fnSrc->SetParametricFunction(src);
fnSrc->Update();
// Create a mapper and actor.
vtkNew<vtkPolyDataMapper> mapper;
mapper->SetInputConnection(fnSrc->GetOutputPort());
vtkNew<vtkActor> actor;
actor->SetMapper(mapper);
actor->GetProperty()->SetColor(
colors->GetColor3d("CornflowerBlue").GetData());
// Create a renderer, render window, and interactor.
vtkNew<vtkRenderer> renderer;
vtkNew<vtkRenderWindow> renderWindow;
renderWindow->AddRenderer(renderer);
renderWindow->SetWindowName("PolarAxesActor");
renderWindow->SetSize(600, 600);
vtkNew<vtkRenderWindowInteractor> renderWindowInteractor;
renderWindowInteractor->SetRenderWindow(renderWindow);
double* bounds;
bounds = fnSrc->GetOutput()->GetBounds();
std::vector<double> p1{bounds[0], bounds[2]};
std::vector<double> p2{bounds[1], bounds[3]};
auto radius =
std::inner_product(std::cbegin(p1), std::cend(p1), std::begin(p2), 0.0);
radius = std::sqrt(std::abs(radius));
std::vector<double> pole{0.0, 0.0, bounds[5]};
vtkNew<vtkPolarAxesActor> polarAxesActor;
polarAxesActor->SetPole(pole.data());
polarAxesActor->SetMaximumRadius(radius);
polarAxesActor->SetRequestedNumberOfPolarAxes(5);
polarAxesActor->SetMinimumAngle(-45.0);
polarAxesActor->SetMaximumAngle(135.0);
auto axesProp = polarAxesActor->GetPolarAxisProperty();
axesProp->SetColor(colors->GetColor3d("Red").GetData());
auto arcsProp = polarAxesActor->GetPolarArcsProperty();
arcsProp->SetColor(colors->GetColor3d("Yellow").GetData());
arcsProp->SetLineWidth(1.0);
polarAxesActor->SetSecondaryRadialAxesProperty(axesProp);
polarAxesActor->SetLastRadialAxisProperty(axesProp);
polarAxesActor->SetSecondaryPolarArcsProperty(arcsProp);
// Add the actor to the scene.
renderer->AddActor(actor);
renderer->AddActor(polarAxesActor);
renderer->GetActiveCamera()->ParallelProjectionOn();
polarAxesActor->SetCamera(renderer->GetActiveCamera());
renderer->ResetCamera();
renderer->SetBackground(colors->GetColor3d("MidnightBlue").GetData());
// Render and interact.
renderWindow->Render();
renderWindowInteractor->Start();
return EXIT_SUCCESS;
}
......@@ -34,25 +34,25 @@ def main():
actor.property.color = colors.GetColor3d('CornflowerBlue')
# Create a renderer, render window, and interactor.
renderer = vtkRenderer(background=colors.GetColor3d('DarkSlateGray'))
renderer = vtkRenderer(background=colors.GetColor3d('MidnightBlue'))
render_window = vtkRenderWindow(size=(600, 600), window_name='PolarAxesActor')
render_window.AddRenderer(renderer)
render_window_interactor = vtkRenderWindowInteractor()
render_window_interactor.render_window = render_window
bounds = fn_src.update().output.bounds
radius = math.sqrt((bounds[1] - bounds[0]) ** 2 + (bounds[3] - bounds[2]) ** 2) / 2.0
radius = math.sqrt(abs(dot_product((bounds[0], bounds[2]), (bounds[1], bounds[3]))))
pole = (0.0, 0.0, bounds[5])
polar_axes_actor = vtkPolarAxesActor(pole=pole, maximum_radius=radius,
requested_number_of_polar_axes=5,
minimum_angle=-45.0, maximum_angle=135)
minimum_angle=-45.0, maximum_angle=135.0)
axes_prop = polar_axes_actor.polar_axis_property
axes_prop.color = colors.GetColor3d('Red')
arcs_prop = polar_axes_actor.polar_arcs_property
arcs_prop.color = colors.GetColor3d('Yellow')
arcs_prop.line_width = 1
arcs_prop.line_width = 1.0
polar_axes_actor.secondary_radial_axes_property = axes_prop
polar_axes_actor.last_radial_axis_property = axes_prop
......@@ -63,14 +63,20 @@ def main():
renderer.AddActor(polar_axes_actor)
renderer.active_camera.parallel_projection = True
polar_axes_actor.SetCamera(renderer.active_camera)
renderer.ResetCamera()
# Render and interact.
render_window_interactor.Initialize()
polar_axes_actor.SetCamera(renderer.active_camera)
render_window.Render()
render_window_interactor.Start()
def dot_product(v1, v2):
total = 0.0
for x, y in zip(v1, v2):
total += x * y
return total
if __name__ == '__main__':
main()
src/Testing/Baseline/Cxx/Annotation/TestPolarAxesActor.png

130 B

src/Testing/Baseline/PythonicAPI/Annotation/TestPolarAxesActor.png

130 B

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