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

Adding GoldenBallSource

parent f16bf69e
No related branches found
No related tags found
1 merge request!395Adding some new vtk 9.4 examples
#include <vtkActor.h>
#include <vtkDataSetMapper.h>
#include <vtkGoldenBallSource.h>
#include <vtkNamedColors.h>
#include <vtkNew.h>
#include <vtkProperty.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <array>
int main(int, char*[])
{
vtkNew<vtkNamedColors> colors;
colors->SetColor("ParaViewBkg",
std::array<unsigned char, 4>{82, 87, 110, 255}.data());
// Create a golden ball source.
vtkNew<vtkGoldenBallSource> goldenBallSource;
goldenBallSource->SetCenter(0.0, 0.0, 0.0);
goldenBallSource->SetRadius(5.0);
goldenBallSource->SetResolution(200);
goldenBallSource->GenerateNormalsOn();
goldenBallSource->IncludeCenterPointOn();
vtkNew<vtkDataSetMapper> mapper;
mapper->SetInputConnection(goldenBallSource->GetOutputPort());
vtkNew<vtkProperty> actorProp;
actorProp->SetColor(colors->GetColor3d("Gold").GetData());
actorProp->SetEdgeColor(colors->GetColor3d("DarkSlateBlue").GetData());
actorProp->EdgeVisibilityOn();
vtkNew<vtkActor> actor;
actor->SetProperty(actorProp);
actor->SetMapper(mapper);
actor->GetProperty()->SetColor(colors->GetColor3d("Gold").GetData());
vtkNew<vtkRenderer> renderer;
renderer->SetBackground(colors->GetColor3d("ParaViewBkg").GetData());
vtkNew<vtkRenderWindow> renderWindow;
renderWindow->SetSize(600, 600);
renderWindow->SetWindowName("Golden Ball Source");
renderWindow->AddRenderer(renderer);
vtkNew<vtkRenderWindowInteractor> renderWindowInteractor;
renderWindowInteractor->SetRenderWindow(renderWindow);
renderer->AddActor(actor);
renderWindow->Render();
renderWindowInteractor->Start();
return EXIT_SUCCESS;
}
### Description
A vtkGoldenBallSource algorithm has been added to provide a method to construct a solid, tetrahedralized ball. It uses a Fibonacci spiral (generated using the “Golden Angle” of π(sqrt(5) - 1)) which is then projected out of the plane onto a sphere and Delaunay-tetrahedralized into a ball. It includes a “normal” vector field by default which is zero-length at the center of the ball.
Besides the spiral construction this algorithm is also distinct from the existing sphere source because it produces a solid rather than a bounding surface.
#include <vtkActor.h>
#include <vtkNamedColors.h>
#include <vtkPolyData.h>
#include <vtkNew.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkSmartPointer.h>
#include <vtkSphereSource.h>
#include <array>
int main(int, char*[])
{
vtkNew<vtkNamedColors> colors;
colors->SetColor("ParaViewBkg",
std::array<unsigned char, 4>{82, 87, 110, 255}.data());
// Create a sphere
vtkNew<vtkSphereSource> sphereSource;
sphereSource->SetCenter(0.0, 0.0, 0.0);
sphereSource->SetRadius(5.0);
// Make the surface smooth.
sphereSource->SetPhiResolution(100);
sphereSource->SetThetaResolution(100);
sphereSource->SetPhiResolution(50);
sphereSource->SetThetaResolution(50);
vtkNew<vtkPolyDataMapper> mapper;
mapper->SetInputConnection(sphereSource->GetOutputPort());
vtkNew<vtkProperty> actorProp;
actorProp->SetColor(colors->GetColor3d("Peru").GetData());
actorProp->SetEdgeColor(colors->GetColor3d("DarkSlateBlue").GetData());
actorProp->EdgeVisibilityOn();
vtkNew<vtkActor> actor;
actor->SetProperty(actorProp);
actor->SetMapper(mapper);
actor->GetProperty()->SetColor(colors->GetColor3d("Cornsilk").GetData());
vtkNew<vtkRenderer> renderer;
vtkNew<vtkRenderWindow> renderWindow;
renderWindow->SetSize(600, 600);
renderWindow->SetWindowName("Sphere");
renderWindow->AddRenderer(renderer);
vtkNew<vtkRenderWindowInteractor> renderWindowInteractor;
renderWindowInteractor->SetRenderWindow(renderWindow);
renderer->AddActor(actor);
renderer->SetBackground(colors->GetColor3d("DarkGreen").GetData());
renderer->SetBackground(colors->GetColor3d("ParaViewBkg").GetData());
renderWindow->Render();
renderWindowInteractor->Start();
......
### Description
A vtkGoldenBallSource algorithm has been added to provide a method to construct a solid, tetrahedralized ball. It uses a Fibonacci spiral (generated using the “Golden Angle” of π(sqrt(5) - 1)) which is then projected out of the plane onto a sphere and Delaunay-tetrahedralized into a ball. It includes a “normal” vector field by default which is zero-length at the center of the ball.
Besides the spiral construction this algorithm is also distinct from the existing sphere source because it produces a solid rather than a bounding surface.
#!/usr/bin/env python3
# noinspection PyUnresolvedReferences
import vtkmodules.vtkInteractionStyle
# noinspection PyUnresolvedReferences
import vtkmodules.vtkRenderingOpenGL2
from vtkmodules.vtkCommonColor import vtkNamedColors
from vtkmodules.vtkFiltersSources import vtkSphereSource, vtkGoldenBallSource
from vtkmodules.vtkRenderingCore import (
vtkActor,
vtkPolyDataMapper,
vtkRenderWindow,
vtkRenderWindowInteractor,
vtkRenderer, vtkMapper, vtkDataSetMapper, vtkProperty
)
def main():
colors = vtkNamedColors()
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)
mapper = vtkDataSetMapper()
golden_ball_source >> mapper
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')
render_window.AddRenderer(renderer)
render_window_interactor = vtkRenderWindowInteractor()
render_window_interactor.SetRenderWindow(render_window)
renderer.AddActor(actor)
renderer.ResetCamera()
render_window.Render()
render_window_interactor.Start()
if __name__ == '__main__':
main()
### Description
vtkSphereSource object creates a sphere (represented by polygons) of specified radius centered at the origin.
The resolution (polygonal discretization) in both the latitude (phi) and longitude (theta) directions can be specified.
It also is possible to create partial spheres by specifying maximum phi and theta angles. By default, the surface
tessellation of the sphere uses triangles; however you can set LatLongTessellation to produce a tessellation using
quadrilaterals.
#!/usr/bin/env python3
# noinspection PyUnresolvedReferences
import vtkmodules.vtkInteractionStyle
# noinspection PyUnresolvedReferences
import vtkmodules.vtkRenderingOpenGL2
from vtkmodules.vtkCommonColor import vtkNamedColors
from vtkmodules.vtkFiltersSources import vtkSphereSource
from vtkmodules.vtkRenderingCore import (
vtkActor,
vtkPolyDataMapper,
vtkRenderWindow,
vtkRenderWindowInteractor,
vtkRenderer, vtkProperty
)
def main():
colors = vtkNamedColors()
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)
mapper = vtkPolyDataMapper()
sphere_source >> mapper
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')
render_window.AddRenderer(renderer)
render_window_interactor = vtkRenderWindowInteractor()
render_window_interactor.SetRenderWindow(render_window)
renderer.AddActor(actor)
render_window.Render()
render_window_interactor.Start()
if __name__ == '__main__':
main()
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