# HG changeset patch
# User iuc
# Date 1471978679 14400
# Node ID aceda40ef31193d662b1d7bbdf913e2da2c11808
Uploaded
diff -r 000000000000 -r aceda40ef311 icqsol_color_surface_field.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/icqsol_color_surface_field.py Tue Aug 23 14:57:59 2016 -0400
@@ -0,0 +1,47 @@
+#!/usr/bin/env python
+import argparse
+import shutil
+
+import icqsol_utils
+
+# Parse Command Line.
+parser = argparse.ArgumentParser()
+parser.add_argument('--input', dest='input', help='Shape dataset selected from history')
+parser.add_argument('--input_file_format_and_type', dest='input_file_format_and_type', help='Input file format and type')
+parser.add_argument('--input_dataset_type', dest='input_dataset_type', help='Input dataset_type')
+parser.add_argument('--field_name', dest='field_name', help='Field name')
+parser.add_argument('--field_component_index', dest='field_component_index', type=int, help='Index of field component')
+parser.add_argument('--color_map', dest='color_map', help='Color map')
+parser.add_argument('--output', dest='output', help='Output dataset')
+parser.add_argument('--output_vtk_type', dest='output_vtk_type', help='Output VTK type')
+
+args = parser.parse_args()
+
+tmp_dir = icqsol_utils.get_temp_dir()
+input_format, input_file_type = icqsol_utils.get_format_and_type(args.input_file_format_and_type)
+
+# Instantiate a ShapeManager for loading the input.
+shape_mgr = icqsol_utils.get_shape_manager(icqsol_utils.VTK, args.input_dataset_type)
+
+# Get the vtkPolyData from the input dataset.
+vtk_poly_data = shape_mgr.loadAsVtkPolyData(args.input)
+# Add color to the data.
+colored_vtk_poly_data = shape_mgr.colorSurfaceField(vtk_poly_data=vtk_poly_data,
+ color_map=args.color_map,
+ field_name=args.field_name,
+ field_component=args.field_component_index)
+
+# Write min/max field values.
+minVal, maxVal = shape_mgr.getFieldRange(vtk_poly_data, args.field_name, args.field_component_index)
+print 'component {2} min/max values of field {3}: {0}/{1}'.format(minVal, maxVal, args.field_component_index, args.field_name)
+
+# Define the output file format and type.
+output_format, output_file_type = icqsol_utils.get_format_and_type(args.output_vtk_type)
+tmp_output_path = icqsol_utils.get_temporary_file_path(tmp_dir, output_format)
+
+# Make sure the ShapeManager's writer is VTK POLYDATA.
+shape_mgr.setWriter(file_format=icqsol_utils.VTK, vtk_dataset_type=icqsol_utils.POLYDATA)
+
+# Save the output.
+shape_mgr.saveVtkPolyData(vtk_poly_data=colored_vtk_poly_data, file_name=tmp_output_path, file_type=output_file_type)
+shutil.move(tmp_output_path, args.output)
diff -r 000000000000 -r aceda40ef311 icqsol_color_surface_field.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/icqsol_color_surface_field.xml Tue Aug 23 14:57:59 2016 -0400
@@ -0,0 +1,70 @@
+
+
+ field
+
+ icqsol_macros.xml
+
+
+
+
+
+
+
+
+ value is not None and len(value.metadata.field_names) > 0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+**What it does**
+
+Colors a shape's selected surface field using a selected color map. This tool will restrict selected
+input shapes to only those that have at least one surface field.
+
+* **Shape** - Shape containing a surface field to be colored.
+* **Field name for coloring** - Name of the surface field to be colored.
+* **Color map** - Color map to be used when coloring the surface field.
+
+
+
+
+
diff -r 000000000000 -r aceda40ef311 icqsol_macros.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/icqsol_macros.xml Tue Aug 23 14:57:59 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 aceda40ef311 icqsol_tool_form_utils.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/icqsol_tool_form_utils.py Tue Aug 23 14:57:59 2016 -0400
@@ -0,0 +1,21 @@
+
+def get_field_components_options(dataset, **kwd):
+ field_name = kwd.get('field_name', None)
+ options = []
+ if dataset.metadata is None:
+ return options
+ if not hasattr(dataset.metadata, 'field_names'):
+ return options
+ if dataset.metadata.field_names is None:
+ return options
+ if field_name is None:
+ # The expression validator that helps populate the select list of input
+ # datsets in the icqsol_color_surface_field tool does not filter out
+ # datasets with no field field_names, so we need this check.
+ if len(dataset.metadata.field_names) == 0:
+ return options
+ field_name = dataset.metadata.field_names[0]
+ field_components = dataset.metadata.field_components.get(field_name, [])
+ for i, field_component in enumerate(field_components):
+ options.append((field_component, field_component, i == 0))
+ return options
diff -r 000000000000 -r aceda40ef311 icqsol_utils.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/icqsol_utils.py Tue Aug 23 14:57:59 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 aceda40ef311 test-data/box_with_surface_field.vtkascii
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/box_with_surface_field.vtkascii Tue Aug 23 14:57:59 2016 -0400
@@ -0,0 +1,44 @@
+# vtk DataFile Version 4.0
+vtk output
+ASCII
+DATASET POLYDATA
+POINTS 24 float
+0 0 0 0 0 1 0 1 1
+0 1 0 1 0 0 1 1 0
+1 1 1 1 0 1 0 0 0
+0 0 0 0 0 1 0 0 1
+0 1 1 0 1 1 0 1 0
+0 1 0 1 0 0 1 0 0
+1 1 0 1 1 0 1 1 1
+1 1 1 1 0 1 1 0 1
+
+POLYGONS 12 48
+3 3 0 1
+3 1 2 3
+3 7 4 5
+3 5 6 7
+3 10 8 16
+3 16 22 10
+3 18 14 12
+3 12 20 18
+3 17 9 15
+3 15 19 17
+3 13 11 23
+3 23 21 13
+
+CELL_DATA 12
+FIELD FieldData 1
+surface_field 1 12 double
+0.0136441 0.218305 0.97075 1.17541 0.0136441 0.218305 0.0136441 0.218305 0.106345
+0.42538 1.21152 1.53055
+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 aceda40ef311 test-data/box_with_surface_field_colored.vtkascii
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/box_with_surface_field_colored.vtkascii Tue Aug 23 14:57:59 2016 -0400
@@ -0,0 +1,47 @@
+# vtk DataFile Version 4.0
+vtk output
+ASCII
+DATASET POLYDATA
+POINTS 24 float
+0 0 0 0 0 1 0 1 1
+0 1 0 1 0 0 1 1 0
+1 1 1 1 0 1 0 0 0
+0 0 0 0 0 1 0 0 1
+0 1 1 0 1 1 0 1 0
+0 1 0 1 0 0 1 0 0
+1 1 0 1 1 0 1 1 1
+1 1 1 1 0 1 1 0 1
+
+POLYGONS 12 48
+3 3 0 1
+3 1 2 3
+3 7 4 5
+3 5 6 7
+3 10 8 16
+3 16 22 10
+3 18 14 12
+3 12 20 18
+3 17 9 15
+3 15 19 17
+3 13 11 23
+3 23 21 13
+
+CELL_DATA 12
+COLOR_SCALARS Colors 3
+0 0 1 0.0431373 0.168627 0.956863 0.698039 0.839216 0.301961
+0.870588 0.45098 0.129412 0 0 1
+0.0431373 0.168627 0.956863 0 0 1
+0.0431373 0.168627 0.956863 0.00784314 0.0352941 0.992157
+0.172549 0.568627 0.827451 0.894118 0.376471 0.105882
+1 0 0
+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
+