# HG changeset patch
# User iuc
# Date 1471978822 14400
# Node ID fe94052daa00cd55ce42d99393c8df2fb76ebd11
Uploaded
diff -r 000000000000 -r fe94052daa00 icqsol_create_shape.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/icqsol_create_shape.py Tue Aug 23 15:00:22 2016 -0400
@@ -0,0 +1,85 @@
+#!/usr/bin/env python
+import argparse
+import shutil
+
+import icqsol_utils
+
+# Parse Command Line.
+parser = argparse.ArgumentParser()
+parser.add_argument('--create_process', dest='create_process', help='Shape creation process (create or clone)')
+parser.add_argument('--shape_input', dest='shape_input', default=None, help='Shape file if create_process is clone')
+parser.add_argument('--shape', dest='shape', default=None, help='Shape if create_process is create')
+parser.add_argument('--origin_x', dest='origin_x', type=float, default=None, help='X coordinate of origin')
+parser.add_argument('--origin_y', dest='origin_y', type=float, default=None, help='Y coordinate of origin')
+parser.add_argument('--origin_z', dest='origin_z', type=float, default=None, help='Z coordinate of origin')
+parser.add_argument('--length_x', dest='length_x', type=float, default=None, help='X coordinate of end')
+parser.add_argument('--length_y', dest='length_y', type=float, default=None, help='Y coordinate of end')
+parser.add_argument('--length_z', dest='length_z', type=float, default=None, help='Z coordinate of end')
+parser.add_argument('--angle', dest='angle', type=float, default=None, help='Angle')
+parser.add_argument('--radius', dest='radius', type=float, default=None, help='Radius')
+parser.add_argument('--n_theta', dest='n_theta', type=int, default=0, help='Number of slices')
+parser.add_argument('--n_phi', dest='n_phi', type=int, default=0, help='Number of stacks')
+parser.add_argument('--rotate', dest='rotate', help='Rotate cloned shape')
+parser.add_argument('--rotation_axis_x', dest='rotation_axis_x', type=float, default=None, help='X component of rotation axis')
+parser.add_argument('--rotation_axis_y', dest='rotation_axis_y', type=float, default=None, help='Y component of rotation axis')
+parser.add_argument('--rotation_axis_z', dest='rotation_axis_z', type=float, default=None, help='Z component of rotation axis')
+parser.add_argument('--rotation_degree', dest='rotation_degree', type=float, default=None, help='Degree of rotation around axis')
+parser.add_argument('--translate', dest='translate', help='Translate cloned shape')
+parser.add_argument('--output', dest='output', default=None, help='Output dataset')
+parser.add_argument('--output_vtk_type', dest='output_vtk_type', help='Output file format and type')
+
+args = parser.parse_args()
+
+if args.origin_x is not None and args.origin_y is not None and args.origin_z is not None:
+ origin = [args.origin_x, args.origin_y, args.origin_z]
+if args.length_x is not None and args.length_y is not None and args.length_z is not None:
+ lengths = [args.length_x, args.length_y, args.length_z]
+if args.rotation_axis_x is not None and args.rotation_axis_y is not None and args.rotation_axis_z is not None:
+ rotation_axis = [args.rotation_axis_x, args.rotation_axis_y, args.rotation_axis_z]
+
+# Define the output file format and type.
+format, file_type = icqsol_utils.get_format_and_type(args.output_vtk_type)
+tmp_dir = icqsol_utils.get_temp_dir()
+cloning = True if args.create_process == 'clone' else False
+
+# TODO: fix this to handle inputPLY files for cloning, but producing VTK POLYDATA.
+shape_mgr = icqsol_utils.get_shape_manager(format, icqsol_utils.POLYDATA)
+
+if cloning:
+ # We're cloning an existing shape selected from the history.
+ tmp_input_path = icqsol_utils.get_input_file_path(tmp_dir, args.shape_input, '.%s' % format)
+ shape_to_clone = shape_mgr.loadAsShape(tmp_input_path)
+ new_shape = shape_mgr.cloneShape(shape_to_clone)
+ if icqsol_utils.asbool(args.rotate):
+ shape_mgr.rotateShape(new_shape, axis=rotation_axis, angleDeg=args.rotation_degree)
+ if icqsol_utils.asbool(args.translate):
+ shape_mgr.translateShape(new_shape, disp=origin)
+else:
+ # Create the primitive shape.
+ if args.shape == 'box':
+ new_shape = shape_mgr.createShape('box',
+ origin=origin,
+ lengths=lengths)
+ elif args.shape == 'cone':
+ new_shape = shape_mgr.createShape('cone',
+ radius=args.radius,
+ origin=origin,
+ lengths=lengths,
+ n_theta=args.n_theta)
+ elif args.shape == 'cylinder':
+ new_shape = shape_mgr.createShape('cylinder',
+ radius=args.radius,
+ origin=origin,
+ lengths=lengths,
+ n_theta=args.n_theta)
+ elif args.shape == 'sphere':
+ new_shape = shape_mgr.createShape('sphere',
+ radius=args.radius,
+ origin=origin,
+ n_theta=args.n_theta,
+ n_phi=args.n_phi)
+
+# Save the output.
+tmp_output_path = icqsol_utils.get_temporary_file_path(tmp_dir, '.%s' % format)
+shape_mgr.saveShape(shape=new_shape, file_name=tmp_output_path, file_type=file_type)
+shutil.move(tmp_output_path, args.output)
diff -r 000000000000 -r fe94052daa00 icqsol_create_shape.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/icqsol_create_shape.xml Tue Aug 23 15:00:22 2016 -0400
@@ -0,0 +1,206 @@
+
+
+
+
+ icqsol_macros.xml
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ create_process_cond['create_process'] == "create"
+
+
+
+
+
+
+
+ create_process_cond['create_process'] == "clone"
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+**What it does**
+
+**Create a shape** - creates a selected primitive shape where shapes are Box, Cone, Cylinder and Sphere.
+
+* **Origin X,Y,Z** - Origin coordinate for all shapes.
+* **Lengths X,Y,Z** - Edge lengths for Box, Cone and Cylinder.
+* **Radius** - Radius length for Cone, Cylinder and Sphere.
+* **Number of slices** - Controls the tessellation along the longitude direction for all shapes.
+* **Number of stacks** - Controls the tessellation along the latitude direction for all shapes.
+* **Output format and file type** - Choose the output format **ply** or **vtk** and file type **ascii** or **binary**.
+
+-----
+
+**Clone a shape from your history** - creates a new copy of a shape selected from your history.
+
+* **Shape to clone** - Shape selected from your history for cloning.
+* **Rotate cloned shape?** - Enables rotation of the cloned shape around a defined axis.
+* **Rotation axis X,Y,Z** - The axis of rotation for the cloned shape.
+* **Degree of rotation** - The degree of rotation around the axis.
+* **Translate cloned shape?** - Enables resetting the origin of the cloned shape, moving the shape.
+* **New origin X,Y,Z** - Translated origin of cloned shape.
+
+
+
+
diff -r 000000000000 -r fe94052daa00 icqsol_macros.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/icqsol_macros.xml Tue Aug 23 15:00:22 2016 -0400
@@ -0,0 +1,116 @@
+
+
+ 1.0
+
+
+ icqsol
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ --origin_x $create_process_cond.shape_cond.origin_x
+ --origin_y $create_process_cond.shape_cond.origin_y
+ --origin_z $create_process_cond.shape_cond.origin_z
+
+
+
+
+
+
+
+ --length_x $create_process_cond.shape_cond.length_x
+ --length_y $create_process_cond.shape_cond.length_y
+ --length_z $create_process_cond.shape_cond.length_z
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ --radius $create_process_cond.shape_cond.radius
+
+
+
+
+
+
+
+ --n_theta $create_process_cond.shape_cond.n_theta
+
+
+
+
+
+
+
+ --n_phi $create_process_cond.shape_cond.n_phi
+
+
+
+
+
+
+
+
+
+ @unpublished{None,
+ author = {None},
+ title = {None},
+ year = {None},
+ eprint = {None},
+ url = {https://github.com/gregvonkuster/galaxy-csg}
+ }
+
+ @misc(Schroeder-Martin-Lorensen2006,
+ author = "Will Schroeder and
+ Ken Martin and
+ Bill Lorensen",
+ year = "2006",
+ title = "The Visualization Toolkit (4th ed.)",
+ publisher = "Kitware",
+ url = "https://en.wikipedia.org/wiki/Special:BookSources/978-1-930934-19-1")
+
+
+
+
diff -r 000000000000 -r fe94052daa00 icqsol_utils.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/icqsol_utils.py Tue Aug 23 15:00:22 2016 -0400
@@ -0,0 +1,86 @@
+import os
+import sys
+import tempfile
+
+from icqsol.shapes.icqShapeManager import ShapeManager
+from icqsol.bem.icqLaplaceSolver import LaplaceSolver
+
+PLY = 'ply'
+POLYDATA = 'POLYDATA'
+VTK = 'vtk'
+
+
+def asbool(val):
+ return str(val).lower() in ['yes', 'true']
+
+
+def get_format_and_type(galaxy_ext):
+ # Define the output file format and type.
+ format = None
+ datatype = None
+ if galaxy_ext in ['vtkascii', 'vtkbinary']:
+ format = VTK
+ elif galaxy_ext in ['plyascii', 'plybinary']:
+ format = PLY
+ if galaxy_ext in ['vtkascii', 'plyascii']:
+ datatype = 'ascii'
+ elif galaxy_ext in ['vtkbinary', 'plybinary']:
+ datatype = 'binary'
+ return format, datatype
+
+
+def get_input_file_path(tmp_dir, input_file, format):
+ """
+ iCqSol uses file extensions (e.g., .ply, .vtk) when reading and
+ writing files, so the Galaxy dataset naming convention of
+ setting all file extensions as .dat must be handled.
+ """
+ file_path = get_temporary_file_path(tmp_dir, format)
+ # Remove the file so we can create a symlink.
+ os.remove(file_path)
+ os.symlink(input_file, file_path)
+ return file_path
+
+
+def get_laplace_solver(shape_data, max_edge_length=float('inf')):
+ return LaplaceSolver(shape_data, max_edge_length=max_edge_length)
+
+
+def get_shape_manager(format=None, dataset_type=None):
+ # Instantiate a ShapeManager.
+ return ShapeManager(file_format=format, vtk_dataset_type=dataset_type)
+
+
+def get_temp_dir(prefix='tmp-vtk-', dir=None):
+ """
+ Return a temporary directory.
+ """
+ return tempfile.mkdtemp(prefix=prefix, dir=dir)
+
+
+def get_tempfilename(dir=None, suffix=None):
+ """
+ Return a temporary file name.
+ """
+ if suffix is None:
+ s = None
+ elif suffix.startswith('.'):
+ s = suffix
+ else:
+ s = '.%s' % suffix
+ fd, name = tempfile.mkstemp(suffix=s, dir=dir)
+ os.close(fd)
+ return name
+
+
+def get_temporary_file_path(tmp_dir, file_extension):
+ """
+ Return the path to a temporary file with a valid VTK format
+ file extension.
+ """
+ return get_tempfilename(tmp_dir, file_extension)
+
+
+def stop_err(msg):
+ sys.stderr.write("%s\n" % msg)
+ sys.exit()
diff -r 000000000000 -r fe94052daa00 test-data/head.vtkascii
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/head.vtkascii Tue Aug 23 15:00:22 2016 -0400
@@ -0,0 +1,65 @@
+# vtk DataFile Version 4.0
+vtk output
+ASCII
+DATASET POLYDATA
+POINTS 34 float
+-0.06 0 0 -0.06 0 -0.25 -0.06 -0.0956709 -0.23097
+0.08 0 0 -0.06 -0.176777 -0.176777 -0.06 -0.23097 -0.0956709
+-0.06 -0.25 0 -0.06 -0.23097 0.0956709 -0.06 -0.176777 0.176777
+-0.06 -0.0956709 0.23097 -0.06 0 0.25 -0.06 0.0956709 0.23097
+-0.06 0.176777 0.176777 -0.06 0.23097 0.0956709 -0.06 0.25 0
+-0.06 0.23097 -0.0956709 -0.06 0.176777 -0.176777 -0.06 0.0956709 -0.23097
+-0.06 0 -0.25 -0.06 -0.0956709 -0.23097 -0.06 -0.176777 -0.176777
+-0.06 -0.23097 -0.0956709 -0.06 -0.25 0 -0.06 -0.23097 0.0956709
+-0.06 -0.176777 0.176777 -0.06 -0.0956709 0.23097 -0.06 0 0.25
+-0.06 0.0956709 0.23097 -0.06 0.176777 0.176777 -0.06 0.23097 0.0956709
+-0.06 0.25 0 -0.06 0.23097 -0.0956709 -0.06 0.176777 -0.176777
+-0.06 0.0956709 -0.23097
+POLYGONS 32 128
+3 0 1 2
+3 18 3 19
+3 0 2 4
+3 19 3 20
+3 0 4 5
+3 20 3 21
+3 0 5 6
+3 21 3 22
+3 0 6 7
+3 22 3 23
+3 0 7 8
+3 23 3 24
+3 0 8 9
+3 24 3 25
+3 0 9 10
+3 25 3 26
+3 0 10 11
+3 26 3 27
+3 0 11 12
+3 27 3 28
+3 0 12 13
+3 28 3 29
+3 0 13 14
+3 29 3 30
+3 0 14 15
+3 30 3 31
+3 0 15 16
+3 31 3 32
+3 0 16 17
+3 32 3 33
+3 0 17 1
+3 33 3 18
+
+POINT_DATA 34
+NORMALS Normals float
+-1 0 0 -1 0 0 -1 0 0
+1 2.30575e-08 6.43464e-09 -1 0 0 -1 0 0
+-1 0 0 -1 0 0 -1 0 0
+-1 0 0 -1 0 0 -1 0 0
+-1 0 0 -1 0 0 -1 0 0
+-1 0 0 -1 0 0 -1 0 0
+0.872506 0 -0.488603 0.872506 -0.18698 -0.451411 0.872506 -0.345495 -0.345495
+0.872506 -0.451411 -0.18698 0.872506 -0.488603 0 0.872506 -0.451411 0.18698
+0.872506 -0.345495 0.345495 0.872506 -0.18698 0.451411 0.872506 0 0.488603
+0.872506 0.18698 0.451411 0.872506 0.345495 0.345495 0.872506 0.451411 0.18698
+0.872506 0.488603 0 0.872506 0.451411 -0.18698 0.872506 0.345495 -0.345495
+0.872506 0.18698 -0.451411
diff -r 000000000000 -r fe94052daa00 test-data/notch1.vtkascii
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/notch1.vtkascii Tue Aug 23 15:00:22 2016 -0400
@@ -0,0 +1,33 @@
+# vtk DataFile Version 4.0
+vtk output
+ASCII
+DATASET POLYDATA
+POINTS 24 float
+-0.06 -0.015 -0.15 -0.06 -0.015 0.15 -0.06 0.015 0.15
+-0.06 0.015 -0.15 -0.03 -0.015 -0.15 -0.03 0.015 -0.15
+-0.03 0.015 0.15 -0.03 -0.015 0.15 -0.06 -0.015 -0.15
+-0.06 -0.015 -0.15 -0.06 -0.015 0.15 -0.06 -0.015 0.15
+-0.06 0.015 0.15 -0.06 0.015 0.15 -0.06 0.015 -0.15
+-0.06 0.015 -0.15 -0.03 -0.015 -0.15 -0.03 -0.015 -0.15
+-0.03 0.015 -0.15 -0.03 0.015 -0.15 -0.03 0.015 0.15
+-0.03 0.015 0.15 -0.03 -0.015 0.15 -0.03 -0.015 0.15
+
+POLYGONS 6 30
+4 0 1 2 3
+4 4 5 6 7
+4 8 16 22 10
+4 14 12 20 18
+4 9 15 19 17
+4 11 23 21 13
+
+POINT_DATA 24
+NORMALS Normals float
+-1 0 0 -1 0 0 -1 0 0
+-1 0 0 1 0 0 1 0 0
+1 0 0 1 0 0 0 -1 0
+0 0 -1 0 -1 0 0 0 1
+0 1 0 0 0 1 0 1 0
+0 0 -1 0 -1 0 0 0 -1
+0 1 0 0 0 -1 0 1 0
+0 0 1 0 -1 0 0 0 1
+
diff -r 000000000000 -r fe94052daa00 test-data/notch2.vtkascii
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/notch2.vtkascii Tue Aug 23 15:00:22 2016 -0400
@@ -0,0 +1,33 @@
+# vtk DataFile Version 4.0
+vtk output
+ASCII
+DATASET POLYDATA
+POINTS 24 float
+-0.06 -0.15 0.015 -0.06 0.15 0.015 -0.06 0.15 -0.015
+-0.06 -0.15 -0.015 -0.03 -0.15 0.015 -0.03 -0.15 -0.015
+-0.03 0.15 -0.015 -0.03 0.15 0.015 -0.06 -0.15 0.015
+-0.06 -0.15 0.015 -0.06 0.15 0.015 -0.06 0.15 0.015
+-0.06 0.15 -0.015 -0.06 0.15 -0.015 -0.06 -0.15 -0.015
+-0.06 -0.15 -0.015 -0.03 -0.15 0.015 -0.03 -0.15 0.015
+-0.03 -0.15 -0.015 -0.03 -0.15 -0.015 -0.03 0.15 -0.015
+-0.03 0.15 -0.015 -0.03 0.15 0.015 -0.03 0.15 0.015
+
+POLYGONS 6 30
+4 0 1 2 3
+4 4 5 6 7
+4 8 16 22 10
+4 14 12 20 18
+4 9 15 19 17
+4 11 23 21 13
+
+POINT_DATA 24
+NORMALS Normals float
+-1 0 0 -1 0 0 -1 0 0
+-1 0 0 1 0 0 1 0 0
+1 0 0 1 0 0 0 0 1
+0 -1 0 0 0 1 0 1 0
+0 0 -1 0 1 0 0 0 -1
+0 -1 0 0 0 1 0 -1 0
+0 0 -1 0 -1 0 0 0 -1
+0 1 0 0 0 1 0 1 0
+
diff -r 000000000000 -r fe94052daa00 test-data/shaft.vtkascii
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/shaft.vtkascii Tue Aug 23 15:00:22 2016 -0400
@@ -0,0 +1,103 @@
+# vtk DataFile Version 4.0
+vtk output
+ASCII
+DATASET POLYDATA
+POINTS 66 float
+0 0 0 0 0 -0.1 0 -0.0382683 -0.092388
+1 0 -0.1 1 -0.0382683 -0.092388 1 0 0
+0 -0.0707107 -0.0707107 1 -0.0707107 -0.0707107 0 -0.092388 -0.0382683
+1 -0.092388 -0.0382683 0 -0.1 0 1 -0.1 0
+0 -0.092388 0.0382683 1 -0.092388 0.0382683 0 -0.0707107 0.0707107
+1 -0.0707107 0.0707107 0 -0.0382683 0.092388 1 -0.0382683 0.092388
+0 0 0.1 1 0 0.1 0 0.0382683 0.092388
+1 0.0382683 0.092388 0 0.0707107 0.0707107 1 0.0707107 0.0707107
+0 0.092388 0.0382683 1 0.092388 0.0382683 0 0.1 0
+1 0.1 0 0 0.092388 -0.0382683 1 0.092388 -0.0382683
+0 0.0707107 -0.0707107 1 0.0707107 -0.0707107 0 0.0382683 -0.092388
+1 0.0382683 -0.092388 0 0 -0.1 0 -0.0382683 -0.092388
+1 0 -0.1 1 -0.0382683 -0.092388 0 -0.0707107 -0.0707107
+1 -0.0707107 -0.0707107 0 -0.092388 -0.0382683 1 -0.092388 -0.0382683
+0 -0.1 0 1 -0.1 0 0 -0.092388 0.0382683
+1 -0.092388 0.0382683 0 -0.0707107 0.0707107 1 -0.0707107 0.0707107
+0 -0.0382683 0.092388 1 -0.0382683 0.092388 0 0 0.1
+1 0 0.1 0 0.0382683 0.092388 1 0.0382683 0.092388
+0 0.0707107 0.0707107 1 0.0707107 0.0707107 0 0.092388 0.0382683
+1 0.092388 0.0382683 0 0.1 0 1 0.1 0
+0 0.092388 -0.0382683 1 0.092388 -0.0382683 0 0.0707107 -0.0707107
+1 0.0707107 -0.0707107 0 0.0382683 -0.092388 1 0.0382683 -0.092388
+
+POLYGONS 48 208
+3 0 1 2
+4 35 34 3 4
+3 5 37 36
+3 0 2 6
+4 38 35 4 7
+3 5 39 37
+3 0 6 8
+4 40 38 7 9
+3 5 41 39
+3 0 8 10
+4 42 40 9 11
+3 5 43 41
+3 0 10 12
+4 44 42 11 13
+3 5 45 43
+3 0 12 14
+4 46 44 13 15
+3 5 47 45
+3 0 14 16
+4 48 46 15 17
+3 5 49 47
+3 0 16 18
+4 50 48 17 19
+3 5 51 49
+3 0 18 20
+4 52 50 19 21
+3 5 53 51
+3 0 20 22
+4 54 52 21 23
+3 5 55 53
+3 0 22 24
+4 56 54 23 25
+3 5 57 55
+3 0 24 26
+4 58 56 25 27
+3 5 59 57
+3 0 26 28
+4 60 58 27 29
+3 5 61 59
+3 0 28 30
+4 62 60 29 31
+3 5 63 61
+3 0 30 32
+4 64 62 31 33
+3 5 65 63
+3 0 32 1
+4 34 64 33 3
+3 5 36 65
+
+POINT_DATA 66
+NORMALS Normals float
+-1 0 0 -1 0 0 -1 0 0
+0 0 -1 0 -0.382683 -0.92388 1 0 0
+-1 0 0 0 -0.707107 -0.707107 -1 0 0
+0 -0.92388 -0.382683 -1 0 0 0 -1 0
+-1 0 0 0 -0.92388 0.382683 -1 0 0
+0 -0.707107 0.707107 -1 0 0 0 -0.382683 0.92388
+-1 0 0 0 0 1 -1 0 0
+0 0.382683 0.92388 -1 0 0 0 0.707107 0.707107
+-1 0 0 0 0.92388 0.382683 -1 0 0
+0 1 0 -1 0 0 0 0.92388 -0.382683
+-1 0 0 0 0.707107 -0.707107 -1 0 0
+0 0.382683 -0.92388 0 0 -1 0 -0.382683 -0.92388
+1 0 0 1 0 0 0 -0.707107 -0.707107
+1 0 0 0 -0.92388 -0.382683 1 0 0
+0 -1 0 1 0 0 0 -0.92388 0.382683
+1 0 0 0 -0.707107 0.707107 1 0 0
+0 -0.382683 0.92388 1 0 0 0 0 1
+1 0 0 0 0.382683 0.92388 1 0 0
+0 0.707107 0.707107 1 0 0 0 0.92388 0.382683
+1 0 0 0 1 0 1 0 0
+0 0.92388 -0.382683 1 0 0 0 0.707107 -0.707107
+1 0 0 0 0.382683 -0.92388 1 0 0
+