[vtkusers] mapping a 3D polydata model to a sphere

Meehan, Bernard MEEHANBT at nv.doe.gov
Wed Sep 9 10:27:08 EDT 2015


If you don¹t mind only the points being moved, you could try something
like this:

#!/usr/bin/env python
# This example creates a simple stereographic projection of a portion of a
# sphere. I have taken a lot of the code from the "ExpCos.py" demo program
on
# the GitHub site:
# 
https://github.com/Kitware/VTK/blob/master/Examples/Modelling/Python/expCos
.py

import sys, vtk
from math import *

#--------------------------------------------------------------------------
----#
#                set up a plane in the center of the view area
    #
#--------------------------------------------------------------------------
----#
plane = vtk.vtkPlaneSource()
plane.SetXResolution(20)
plane.SetYResolution(20)
plane.SetCenter(0., -0.5, 0.)

transform = vtk.vtkTransform()
transform.Scale(pi, pi, 1)

scale_transform = vtk.vtkTransformPolyDataFilter()
scale_transform.SetInputConnection(plane.GetOutputPort())
scale_transform.SetTransform(transform)
scale_transform.Update()

# Perform the stereographic projection directly on the points in the plane
# above. This assumes that the x coordinate is the azimuthal angle, and is
in
# the range (-pi, pi), and that the y coordinate is the altitude angle, in
the
# range (-pi/2, pi/2).
input_pd  = scale_transform.GetOutputDataObject(0)
stereo_pd = vtk.vtkPolyData()
stereo_pd.CopyStructure(input_pd)

new_points = vtk.vtkPoints()
for i in range(input_pd.GetNumberOfPoints()):
  location   = input_pd.GetPoint(i)
  phi, theta = location[:2]

  x = sin(phi)*sin(theta)/(1 - cos(phi)*sin(theta))
  y = cos(theta)/(1 - cos(phi)*sin(theta))
  new_points.InsertPoint(i, x, y, 0.)

stereo_pd.SetPoints(new_points)

stereo_edges = vtk.vtkExtractEdges()
stereo_edges.SetInputData(stereo_pd)

stereo_edge_mapper = vtk.vtkPolyDataMapper()
stereo_edge_mapper.SetInputConnection(stereo_edges.GetOutputPort())

stereo_map_mapper = vtk.vtkPolyDataMapper()
stereo_map_mapper.SetInputData(stereo_pd)

stereo_map_actor = vtk.vtkActor()
stereo_map_actor.SetMapper(stereo_map_mapper)
stereo_map_actor.GetProperty().SetColor(0.9020, 0.6627, 1.0000)
stereo_map_actor.GetProperty().SetOpacity(0.4)

stereo_edge_actor = vtk.vtkActor()
stereo_edge_actor.SetMapper(stereo_edge_mapper)
stereo_edge_actor.GetProperty().SetColor(0.1882, 0.1294, 1.0000)

#--------------------------------------------------------------------------
----#
#                               rendering stuff
    #
#--------------------------------------------------------------------------
----#
ren = vtk.vtkRenderer()
ren.AddActor(stereo_map_actor)
ren.AddActor(stereo_edge_actor)

renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
renWin.SetSize(500, 500)

iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)

ren.ResetCamera()
iren.Initialize()
renWin.Render()
iren.Start()


On 9/9/15, 3:27 AM, "vtkusers on behalf of AIs" <vtkusers-bounces at vtk.org
on behalf of royalmatador at gmail.com> wrote:

>Hi Everyone,
>I have a 3D polydata model which I would like to map to a 3D sphere.
>Does anyone know how I can achieve this?
>Cheers
>AIs
>
>
>
>--
>View this message in context:
>http://vtk.1045678.n5.nabble.com/mapping-a-3D-polydata-model-to-a-sphere-t
>p5733784.html
>Sent from the VTK - Users mailing list archive at Nabble.com.
>_______________________________________________
>Powered by www.kitware.com
>
>Visit other Kitware open-source projects at
>http://www.kitware.com/opensource/opensource.html
>
>Please keep messages on-topic and check the VTK FAQ at:
>http://www.vtk.org/Wiki/VTK_FAQ
>
>Search the list archives at: http://markmail.org/search/?q=vtkusers
>
>Follow this link to subscribe/unsubscribe:
>http://public.kitware.com/mailman/listinfo/vtkusers



More information about the vtkusers mailing list