From 483a15532069f85d111b9896adab90d0ad034c81 Mon Sep 17 00:00:00 2001 From: Sebastien Jourdain Date: Mon, 6 Feb 2017 10:55:00 -0700 Subject: [PATCH] Fix python code to copy web application --- flake8.cfg | 2 +- tomviz/python/tomviz/web.py | 118 ++++++++++++++++-------------------- 2 files changed, 54 insertions(+), 66 deletions(-) diff --git a/flake8.cfg b/flake8.cfg index 83870651d..9e5c0f7a7 100644 --- a/flake8.cfg +++ b/flake8.cfg @@ -4,7 +4,7 @@ max-line-length: 80 max-complexity: 14 format: pylint #quotes: ' -exclude: thirdparty/* +exclude: thirdparty/*,web/* # Ignore certain errors. # # Whitespace errors diff --git a/tomviz/python/tomviz/web.py b/tomviz/python/tomviz/web.py index 635719bc7..c4ce0cead 100644 --- a/tomviz/python/tomviz/web.py +++ b/tomviz/python/tomviz/web.py @@ -1,43 +1,50 @@ -import os, shutil +import os +import shutil + from paraview import simple -from paraview.web.dataset_builder import * +from paraview.web.dataset_builder import ImageDataSetBuilder +from paraview.web.dataset_builder import CompositeDataSetBuilder -# ----------------------------------------------------------------------------- -# Main function -# ----------------------------------------------------------------------------- def web_export(destinationPath, exportType, deltaPhi, deltaTheta): dest = '%s/data' % destinationPath - camera = {'type': 'spherical', 'phi': range(0, 360, deltaPhi), 'theta': range(-deltaTheta, deltaTheta + 1, deltaTheta)} + camera = { + 'type': 'spherical', + 'phi': range(0, 360, deltaPhi), + 'theta': range(-deltaTheta, deltaTheta + 1, deltaTheta) + } + + # Copy application + copy_viewer(destinationPath) # Choose export mode: - if exportType == 0: + if exportType == 0: export_images(dest, camera) if exportType == 1: export_layers(dest, camera) - copy_viewer(destinationPath) - # ----------------------------------------------------------------------------- -# Helpers +# Helpers # ----------------------------------------------------------------------------- + def get_proxy(id): - remoteObj = simple.servermanager.ActiveConnection.Session.GetRemoteObject(int(id)) + session = simple.servermanager.ActiveConnection.Session + remoteObj = session.GetRemoteObject(int(id)) return simple.servermanager._getPyProxy(remoteObj) + def copy_viewer(destinationPath): - # FIXME !!! - # searchPath = os.path.realpath(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../..')) - # print 'search from', searchPath - # for root, dirs, files in os.walk(searchPath): - # print root - # if 'index.html' in files: - # print 'copy', root, 'to', destinationPath - # shutil.copytree(os.join(root, 'tomviz'), os.join(destinationPath, 'tomviz')) - # return - pass + searchPath = os.getcwd() + for root, dirs, files in os.walk(searchPath): + if 'index.html' in files: + shutil.copytree(os.path.join(root, 'tomviz'), + os.path.join(destinationPath, 'tomviz')) + shutil.copy(os.path.join(root, 'index.html'), + destinationPath) + return + def add_scene_item(scene, name, proxy, view): hasNormal = False @@ -45,14 +52,14 @@ def add_scene_item(scene, name, proxy, view): colors = {} representation = {} rep = simple.GetRepresentation(proxy, view) - + # Skip volume if rep.Visibility == 0 or rep.Representation == 'Volume': return for prop in ['Representation']: representation[prop] = rep.GetProperty(prop).GetData() - + pdInfo = proxy.GetPointDataInformation() numberOfPointArrays = pdInfo.GetNumberOfArrays() for idx in xrange(numberOfPointArrays): @@ -63,36 +70,46 @@ def add_scene_item(scene, name, proxy, view): if array.Name not in ['vtkValidPointMask', 'Normals']: hasColor = True if rangeValues[0] == rangeValues[1]: - colors[array.Name] = { 'constant': rangeValues[0] } + colors[array.Name] = {'constant': rangeValues[0]} else: - colors[array.Name] = { 'location': 'POINT_DATA', 'range': [i for i in rangeValues] } - + colors[array.Name] = { + 'location': 'POINT_DATA', + 'range': [i for i in rangeValues] + } + # Get information about cell data arrays cdInfo = proxy.GetCellDataInformation() numberOfCellArrays = cdInfo.GetNumberOfArrays() for idx in xrange(numberOfCellArrays): array = cdInfo.GetArray(idx) hasColor = True - colors[array.Name] = { 'location': 'CELL_DATA', 'range': array.GetRange(-1) } + colors[array.Name] = { + 'location': 'CELL_DATA', + 'range': array.GetRange(-1) + } # Make sure Normals are available if lighting by normals source = proxy - if 'normal' in scene['light'] and rep.Representation != 'Outline': + if not hasColor or rep.Representation == 'Outline': + colors = {'solid': {'constant': 0}} + elif 'normal' in scene['light'] and not hasNormal: rep.Visibility = 0 surface = simple.ExtractSurface(Input=proxy) surfaceWithNormals = simple.GenerateSurfaceNormals(Input=surface) source = surfaceWithNormals - if not hasColor or rep.Representation == 'Outline': - colors = { 'solid': { 'constant': 0 } } - - scene['scene'].append({ 'name': name, 'source': source, 'colors': colors, 'representation': representation }) - + scene['scene'].append({ + 'name': name, + 'source': source, + 'colors': colors, + 'representation': representation + }) # ----------------------------------------------------------------------------- # Image based exporter # ----------------------------------------------------------------------------- + def export_images(destinationPath, camera): view = simple.GetRenderView() idb = ImageDataSetBuilder(destinationPath, 'image/jpg', camera) @@ -104,6 +121,7 @@ def export_images(destinationPath, camera): # Composite exporter # ----------------------------------------------------------------------------- + def export_layers(destinationPath, camera): view = simple.GetRenderView() fp = tuple(view.CameraFocalPoint) @@ -122,40 +140,10 @@ def export_layers(destinationPath, camera): for key, value in simple.GetSources().iteritems(): add_scene_item(sceneDescription, key[0], value, view) - # rep = simple.GetRepresentation(value, view) - # if rep.Visibility == 0: - # print "skip", key - # continue - - # print 'process', key - - # if 'Outline' in key[0]: # Outline - # sceneDescription['scene'].append({ - # 'name': 'Outline', - # 'source': value, - # 'colors': { - # 'solid': { 'constant': 0 } - # } - # }) - # elif 'PassThrough' in key[0]: # Slice - # sceneDescription['scene'].append(extract_scene_item('Othogonal Slice', value)) - # pass - # elif 'FlyingEdges' in key[0]: # Contour - # sceneDescription['scene'].append(extract_scene_item('Contour', value)) - # pass - # elif 'TrivialProducer' in key[0]: # volume - # # sceneDescription['scene'].append(extract_scene_item('Volume', value)) - # pass - # elif 'ResampleWithDataset' in key[0]: # ? - # sceneDescription['scene'].append(extract_scene_item('Resample', value)) - # pass - # elif 'Threshold' in key[0]: # Threshold - # sceneDescription['scene'].append(extract_scene_item('Threshold', value)) - # pass - # Generate export - dsb = CompositeDataSetBuilder(destinationPath, sceneDescription, camera, {}, {}, view) + dsb = CompositeDataSetBuilder( + destinationPath, sceneDescription, camera, {}, {}, view) dsb.start() dsb.writeData() dsb.stop(compress=False)