# HG changeset patch
# User greg
# Date 1449677275 18000
# Node ID 4afbbfafc3c2898574d5b2e97fd5d99ed0ed2ec2
Uploaded
diff -r 000000000000 -r 4afbbfafc3c2 icqsol_add_texture.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/icqsol_add_texture.py Wed Dec 09 11:07:55 2015 -0500
@@ -0,0 +1,50 @@
+#!/usr/bin/env python
+import argparse
+import shutil
+
+import icqsol_utils
+from icqsol.shapes.icqShapeManager import ShapeManager
+
+# 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('--input_texture', dest='input_texture', help='Image dataset selected from history')
+parser.add_argument('--input_texture_file_format', dest='input_texture_file_format', help='Input texture file format')
+parser.add_argument('--max_edge_length', dest='max_edge_length', type=float, default=float('inf'), help='Maximum edge length')
+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()
+
+input_format, input_file_type = icqsol_utils.get_format_and_type(args.input_file_format_and_type)
+tmp_dir = icqsol_utils.get_temp_dir()
+
+# Instantiate a ShapeManager for loading the input.
+if input_format == icqsol_utils.VTK:
+ shape_mgr = ShapeManager(file_format=input_format, vtk_dataset_type=args.input_dataset_type)
+else:
+ shape_mgr = ShapeManager(file_format=input_format)
+
+# Get the vtk polydata from the input dataset.
+vtk_poly_data = shape_mgr.loadAsVtkPolyData(args.input)
+# The ShapeManager.addTextureToVtkPolyData function expects
+# a specific file extension at the end of the file path.
+tmp_texture_file_path = icqsol_utils.get_input_file_path(tmp_dir, args.input_texture, args.input_texture_file_format)
+
+# Apply the texture to the shape's surface.
+vtk_poly_data = shape_mgr.addTextureToVtkPolyData(vtk_poly_data,
+ texture_file=tmp_texture_file_path,
+ max_edge_length=args.max_edge_length)
+
+# Define the output file format and type (the output_format can only be 'vtk').
+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.
+shape_mgr.setWriter(file_format=icqsol_utils.VTK, vtk_dataset_type=icqsol_utils.POLYDATA)
+
+# Save the output.
+shape_mgr.saveVtkPolyData(vtk_poly_data=vtk_poly_data, file_name=tmp_output_path, file_type=output_file_type)
+shutil.move(tmp_output_path, args.output)
diff -r 000000000000 -r 4afbbfafc3c2 icqsol_add_texture.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/icqsol_add_texture.xml Wed Dec 09 11:07:55 2015 -0500
@@ -0,0 +1,64 @@
+
+
+ to a shape surface
+
+ icqsol_macros.xml
+
+
+
+ 0:
+ --max_edge_length $max_edge_length
+ #end if
+ --output "$output"
+ --output_vtk_type $output_vtk_type
+]]>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+**What it does**
+
+Adds a texture by applying an image to the surface of a shape. The shape is projected onto a bounding box
+and the color is selected by flattening the box to fit the image. Refinement can be applied for a smoother
+result.
+
+* **Shape** - Shape for applying a surface texture.
+* **Maximum edge length** - The shape's edges are smoothed by adding points to its edges that are longer than the defined maximum length.
+* **Texture image** - Image to be applied to the shape's surface to create the texture.
+
+
+
+
diff -r 000000000000 -r 4afbbfafc3c2 icqsol_macros.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/icqsol_macros.xml Wed Dec 09 11:07:55 2015 -0500
@@ -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 4afbbfafc3c2 icqsol_utils.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/icqsol_utils.py Wed Dec 09 11:07:55 2015 -0500
@@ -0,0 +1,74 @@
+import os
+import sys
+import tempfile
+
+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_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 4afbbfafc3c2 test-data/sandstone.jpg
Binary file test-data/sandstone.jpg has changed
diff -r 000000000000 -r 4afbbfafc3c2 test-data/shaft.vtkascii
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/shaft.vtkascii Wed Dec 09 11:07:55 2015 -0500
@@ -0,0 +1,103 @@
+# vtk DataFile Version 3.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 -6.12323e-18 1 -0.1 -6.12323e-18
+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 -1.22465e-17 0.1 1 -1.22465e-17 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 1.83697e-17
+1 0.1 1.83697e-17 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 -6.12323e-18 1 -0.1 -6.12323e-18 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 -1.22465e-17 0.1
+1 -1.22465e-17 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 1.83697e-17 1 0.1 1.83697e-17
+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
+
diff -r 000000000000 -r 4afbbfafc3c2 tool_dependencies.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tool_dependencies.xml Wed Dec 09 11:07:55 2015 -0500
@@ -0,0 +1,6 @@
+
+
+
+
+
+