Here is a working solution that I developed with much help from this list and 
especially David DeMarle (and probably you, Utkarsh), along with a sample data 
file.


On Mar 30, 2016, at 8:07 AM, Utkarsh Ayachit 
<[email protected]<mailto:[email protected]>> wrote:

Rich,

Attached is a sample script that you can run using pvpython or pvbatch or 
vtkpython executables.

Utkarsh

On Tue, Mar 29, 2016 at 1:35 PM, Cook, Rich 
<[email protected]<mailto:[email protected]>> wrote:
I'm still trying to solve my ellipsoid puzzle.
From looking around online, I've found a promising avenue.  Create a 
vtk.vtkParametricEllipsoid, rotate it, and then write to VTK for my user.
My question is, can someone help me finish this script?  I am hoping for an 
experienced user it's trivial.  My objective is to hand the user a python 
script to convert her data to VTK.

from ? import ?  # WHAT GOES HERE?  Do I need to run this from paraview?
for ellipsoid in ellipsoids:
ellipsoid = vtk.vtkParametricEllipsoid()
ellipsoid.SetXRadius(50)
ellipsoid.SetYRadius(10)
ellipsoid.SetZRadius(10)
transform = vtk.vtkTransform()
transform.RotateWXYZ(45,0,1,0)
transform.Translate(100,200,50)
# The magic:   connect the transform to the ellipsoid and add it to the scene.
# HOW???

# write all objects in the scene to a VTK file  Again, HOW?

--
✐Richard Cook
✇ Lawrence Livermore National Laboratory
Bldg-453 Rm-4024, Mail Stop L-557
7000 East Avenue,  Livermore, CA, 94550, USA
☎ (office) (925) 423-9605<tel:%28925%29%20423-9605>
☎ (fax) (925) 423-6961<tel:%28925%29%20423-6961>
---
Information Management & Graphics Grp., Services & Development Div., Integrated 
Computing & Communications Dept.
(opinions expressed herein are mine and not those of LLNL)




_______________________________________________
Powered by 
www.kitware.com<http://secure-web.cisco.com/1ortPqUlji2GoZo2RSdhxP3AI6cEdi2ap0jKeswJ_7lkEVI-VzqTwdyQIGJ4cIypf_zrvHAAIGO0mD7AC7HyZ9fsrMJy4c63CxPHOpEw6NaSFGX5GveTxzspw7XnM9a7Y43ul4yEgW8_z9ji6ZcNQDQgIoyK8uNuc5pNchFIopm71zC9W_3GomNOUdBvhdhdR4SOC0M4JsPBhHl6YuLNdN_XFbnPvyesyyW0EhasAQls8WCQkhlJWcKHcBZWukup2CqPz7YozeGbVqHl6VYdMBF5U954vvQYsA6UFaGsYBFvh1jOnHKvPHWT5pmY48z-vPlCePVClzNTHHnvCF9OjusCSkUIYjcUffJgBwcW29CqKTQ2_ONwKiX_hPV7qmsve/http%3A%2F%2Fwww.kitware.com>

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html<http://secure-web.cisco.com/1Vf0smVBSzXh-Ov2c-OCGjA7unhsO9_P0K0VfzpHJEitUtESoKsZ5PqzlsXQVB35nQsIw1UdrVYHmvP_u7E6pUmKqxECnWev1d8bMD9OBUhJNYPQ3TM36cKK53Nd9Cg5XAEqW4BOkGhTo6MbfBSFVOJy1OwV5dJxZzDNWmk80trhh2sBbWVzRxvEHxlQ8I2YQS10GTVeu0uWH4Qg-4Hdnp4UWlQN0QBQky_XolZSuFoXXFWi27ZubBiaqUo1PGnsCom_jscjwWVumrc2k5f0u0PASok6V0DRR0kgI6t9AIqexJvVGBoXMPVGJWRHgGsEfyssviKqabcTpCpKlVLIDBJMxJEZS_zcmckkRTh7VNcZQpA2lbzVhCx5A9pvaW1gT/http%3A%2F%2Fwww.kitware.com%2Fopensource%2Fopensource.html>

Please keep messages on-topic and check the ParaView Wiki at: 
http://paraview.org/Wiki/ParaView<http://secure-web.cisco.com/1gMvNKYfoBcd6FEGyz3Z5vPGQ-j2UJlU1dp01XHmK9Bo_qUuUWHSccCewsEcvob_RwMSA_176IsqaoIbwKtJdFh3AMwdhOqu7w0HJen9J4FSrsBQHhG297XuiJc7d7CSwTRXzeIgulN1IbISPO-zCjiHtrTWMpaV9sbjfaiOk1wYzFdhoT_b2g9JF0QmLQsUt4A1iMOe-wiiIc5kfhOerxC_5n_erFT5nFCGJm5FYogUXxRKfUNyo-AYTdOHaqYiAiHQiMoIEtLE2MbLzw8-wKhEk-c4EevJPbcDQ6wjm95uk9nEIS4zGZJkci906RZzJAEv1z-DkNRl3ei1fHBomav7M4b4NHiBpE7XXb0YSdt40QpElyRu7mfhSDfg1AKMW/http%3A%2F%2Fparaview.org%2FWiki%2FParaView>

Search the list archives at: http://markmail.org/search/?q=ParaView

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/paraview<http://secure-web.cisco.com/1LfjDkIeiov9cRryNT-1cO9sV9YOVRAPyvyeOkwttqzJq8VnN0NqVRH5Cl-88y8-Xk8Mb3rRgasWM1LSDF2MNlm6f-JpVLVJGHaQNMV_sqAJbcNWgkHa1Wz0jUYYb73Yu2T9tjxAZHHUK3Qh0VYHvZzTauvcF1Isc_-gZQwQTH0HHGtxx2Ve0-Ui54y5MGfHk50XjfvlGBosbfJZd_l8qP67L6VvvBFgdN1lNRolJmAC3czRNjkE8c4bDsW-Fdj0Y8DQAEgLfRjnWQi1vRfdYLCA1PNseW3VcgtnrIlA5BQqiQJna30ugnwOxJ-nthlwuA8rMk2_JmjiYB7NAd38RxeNAPDwpG-H0CnAI80mTvIrQoSxU35TvB6LqB7VBcsyF/http%3A%2F%2Fpublic.kitware.com%2Fmailman%2Flistinfo%2Fparaview>


<sample.py>

--
✐Richard Cook
✇ Lawrence Livermore National Laboratory
Bldg-453 Rm-4024, Mail Stop L-557
7000 East Avenue,  Livermore, CA, 94550, USA
☎ (office) (925) 423-9605
☎ (fax) (925) 423-6961
---
Information Management & Graphics Grp., Services & Development Div., Integrated 
Computing & Communications Dept.
(opinions expressed herein are mine and not those of LLNL)



#!/Programs/Scientific-Visualization/Paraview/ParaView-5.0.0.app/Contents/bin/pvpython
# or #!/usr/bin/env vtkpython
# or #!/usr/bin/env pvpython
# e.g. /Programs/Scientific-Visualization/Paraview/ParaView-5.0.0.app/Contents/bin/pvpython
from math import cos, sin, acos, pi
import numpy as np
from numpy import linalg as LA
import vtk, sys, argparse

parser = argparse.ArgumentParser(description='Create a VTK file from an inclusions file')
parser.add_argument('infile', default="inclusions.dat", help="name of inclusion file")
parser.add_argument('--outfile', '-o', default="ellipsoids.vtk", required=False, help="name of output VTK file")
args = parser.parse_args()

appended = vtk.vtkAppendPolyData()
appended.UserManagedInputsOn()

lines = []
for line in open(args.infile, "r").readlines():
   line = line.strip()
   if line[0] == '#':
      continue
   lines.append(line)

appended.SetNumberOfInputs(len(lines))

idx = 0
for line in lines:
   vals = map(float, line.split())
   ellipsoid = vtk.vtkParametricEllipsoid()
   [x,y,z] = [vals[1], vals[2], vals[3]]
   [Sx,Sy,Sz] = [vals[4], vals[5], vals[6]]
   theta = pi*vals[7]/180.0
   phi =  pi*vals[8]/180.0
   # convert [theta,phi] to cartesian vector V:
   V = [cos(theta)*sin(phi), sin(theta)*sin(phi), cos(phi)]
   # print "From theta,phi = (%f,%f) we get V is %s"%(vals[7],vals[8],str(V))
   X = [1,0,0]
   crossvec = np.cross(V,X)
   [rx,ry,rz] = crossvec
   if LA.norm(crossvec) == 0:
      rot = 0
   else:
      rot = acos(np.dot(V,X)/LA.norm(V))
   rot = 180*rot/pi
   # print "V = (%f,%f,%f) and rot = %f"%(rx,ry,rz,rot)
   ellipsoid.SetXRadius(Sx)
   ellipsoid.SetYRadius(Sy)
   ellipsoid.SetZRadius(Sz)
   parametricFunctionSource = vtk.vtkParametricFunctionSource()
   parametricFunctionSource.SetParametricFunction(ellipsoid);
   transform = vtk.vtkTransform()
   transformFilter = vtk.vtkTransformFilter()
   transformFilter.SetTransform(transform)
   transformFilter.SetInputConnection(parametricFunctionSource.GetOutputPort())
   transform.Identity()
   transform.Translate(x,y,z)
   if rot != 0:
      transform.RotateWXYZ(rot,rx,ry,rz)
   transformFilter.Update()
   appended.SetInputDataByNumber(idx, transformFilter.GetOutput())
   idx = idx + 1

writer = vtk.vtkDataSetWriter()
writer.SetFileName(args.outfile)
writer.SetInputConnection(appended.GetOutputPort())
writer.Write()

print "Wrote file", args.outfile

sys.exit(0)


Attachment: test_inclusionsV2.dat
Description: test_inclusionsV2.dat

_______________________________________________
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 ParaView Wiki at: 
http://paraview.org/Wiki/ParaView

Search the list archives at: http://markmail.org/search/?q=ParaView

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/paraview

Reply via email to