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

Reworking ParametricObjects.

Former-commit-id: 91e58aca
parent 090d6a53
No related branches found
No related tags found
No related merge requests found
......@@ -3,12 +3,13 @@
#include <vtkParametricFunctionSource.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkSmartPointer.h>
// Select one of the following:
// Uncomment one of the following includes that correspond
// to the object that you have selected below:
// #include <vtkParametricBoy.h>
// #include <vtkParametricConicSpiral.h>
// #include <vtkParametricCrossCap.h>
......@@ -30,9 +31,8 @@ int main(int, char* [])
vtkSmartPointer<vtkNamedColors> namedColors =
vtkSmartPointer<vtkNamedColors>::New();
// Select one of the following (matching the selection above)
vtkSmartPointer<vtkParametricTorus> parametricObject =
vtkSmartPointer<vtkParametricTorus>::New();
// Uncomment one of the following and
// ensure the matching include (above) is umcommented).
// vtkSmartPointer<vtkParametricBoy> parametricObject =
// vtkSmartPointer<vtkParametricBoy>::New();
// vtkSmartPointer<vtkParametricConicSpiral> parametricObject =
......@@ -61,8 +61,8 @@ int main(int, char* [])
// vtkSmartPointer<vtkParametricSuperEllipsoid>::New();
// vtkSmartPointer<vtkParametricSuperToroid> parametricObject =
// vtkSmartPointer<vtkParametricSuperToroid>::New();
// vtkSmartPointer<vtkParametricTorus> parametricObject =
// vtkSmartPointer<vtkParametricTorus>::New();
vtkSmartPointer<vtkParametricTorus> parametricObject =
vtkSmartPointer<vtkParametricTorus>::New();
vtkSmartPointer<vtkParametricFunctionSource> parametricFunctionSource =
vtkSmartPointer<vtkParametricFunctionSource>::New();
......@@ -82,6 +82,7 @@ int main(int, char* [])
vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->SetWindowName("Parametric Objects");
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> interactor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
......
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import vtk
class ParametricObjects(object):
def ParametricObjects(self):
colors = vtk.vtkNamedColors()
# Select one of the following functions.
# parametricObject = vtk.vtkParametricBoy()
# parametricObject = vtk.vtkParametricConicSpiral()
# parametricObject = vtk.vtkParametricCrossCap()
# parametricObject = vtk.vtkParametricDini()
# parametricObject = vtk.vtkParametricEllipsoid()
# parametricObject = vtk.vtkParametricEnneper()
# parametricObject = vtk.vtkParametricFigure8Klein()
# parametricObject = vtk.vtkParametricKlein()
# parametricObject = vtk.vtkParametricMobius()
# parametricObject = vtk.vtkParametricRandomHills()
# parametricObject = vtk.vtkParametricRoman()
# parametricObject = vtk.vtkParametricSpline()
# parametricObject = vtk.vtkParametricSuperEllipsoid()
# parametricObject = vtk.vtkParametricSuperToroid()
parametricObject = vtk.vtkParametricTorus()
parametricSource = vtk.vtkParametricFunctionSource()
parametricSource.SetParametricFunction(parametricObject)
# mapper
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(parametricSource.GetOutputPort())
# actor
actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.GetProperty().SetDiffuseColor(colors.GetColor3d("Burlywood"))
# ------------------------------------------------------------
# Create the RenderWindow, Renderer and Interactor
# ------------------------------------------------------------
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
iren = vtk.vtkRenderWindowInteractor()
renWin.AddRenderer(ren)
iren.SetRenderWindow(renWin)
# add actors
ren.AddViewProp(actor)
ren.SetBackground(colors.GetColor3d("Beige"))
# enable user interface interactor
iren.Initialize()
renWin.Render()
iren.Start()
if __name__ == "__main__":
po = ParametricObjects()
po.ParametricObjects()
def main():
namedColors = vtk.vtkNamedColors()
# Uncomment one of the following.
# parametricObject = vtk.vtkParametricBoy()
# parametricObject = vtk.vtkParametricConicSpiral()
# parametricObject = vtk.vtkParametricCrossCap()
# parametricObject = vtk.vtkParametricDini()
# parametricObject = vtk.vtkParametricEllipsoid()
# parametricObject = vtk.vtkParametricEnneper()
# parametricObject = vtk.vtkParametricFigure8Klein()
# parametricObject = vtk.vtkParametricKlein()
# parametricObject = vtk.vtkParametricMobius()
# parametricObject = vtk.vtkParametricRandomHills()
# parametricObject = vtk.vtkParametricRoman()
# parametricObject = vtk.vtkParametricSpline()
# parametricObject = vtk.vtkParametricSuperEllipsoid()
# parametricObject = vtk.vtkParametricSuperToroid()
parametricObject = vtk.vtkParametricTorus()
parametricFunctionSource = vtk.vtkParametricFunctionSource()
parametricFunctionSource.SetParametricFunction(parametricObject)
parametricFunctionSource.Update()
# Visualize
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(parametricFunctionSource.GetOutputPort())
# Create an actor for the contours
actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.GetProperty().SetDiffuseColor(
namedColors.GetColor3d("Burlywood"))
renderer = vtk.vtkRenderer()
renderWindow = vtk.vtkRenderWindow()
renderWindow.SetWindowName("Parametric Objects")
renderWindow.AddRenderer(renderer)
interactor = vtk.vtkRenderWindowInteractor()
interactor.SetRenderWindow(renderWindow)
renderer.AddActor(actor)
renderer.SetBackground(namedColors.GetColor3d("Beige"))
renderWindow.Render()
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