Commit ec9c3641 authored by Dave DeMarle's avatar Dave DeMarle
Browse files

fixes for paraview 5.0.0.rc2 testing

Isolated file IO (well at least O), and thus PIL, into the new raster_wrangler module.
Added to that a path to use VTK if PIL is not available so that generators on HPC machines don't need to compile PIL.
Also, prevent a runtime warning from paraview_introspect, save out version metadata, and let caller not provide the "info.json" filename.
parent 746d04ab
......@@ -37,18 +37,9 @@ import os.path
import re
import itertools
import weakref
import PIL.Image
import PIL.ImImagePlugin
import numpy as np
import copy
try:
import OexrHelper as exr
exrEnabled = True
print "Imported OpenEXR, will default to *.exr in z-buffer images."
except ImportError:
exrEnabled = False
import raster_wrangler
class Document(object):
"""
......@@ -519,8 +510,11 @@ class FileStore(Store):
def __init__(self, dbfilename=None):
super(FileStore, self).__init__()
self.__filename_pattern = None
self.__dbfilename = dbfilename if dbfilename \
tmpfname = dbfilename if dbfilename \
else os.path.join(os.getcwd(), "info.json")
if not tmpfname.endswith("info.json"):
tmpfname = os.path.join(tmpfname, "info.json")
self.__dbfilename = tmpfname
self.cached_searches = {}
self.cached_files = {}
......@@ -608,7 +602,7 @@ class FileStore(Store):
#determine file type for this document
doctype = self.determine_type(desc)
if doctype == "Z":
if exrEnabled:
if raster_wrangler.exrEnabled:
ext = ".exr"
else:
ext = ".im"
......@@ -627,24 +621,10 @@ class FileStore(Store):
if not document.data == None:
doctype = self.determine_type(document.descriptor)
if doctype == 'RGB' or doctype == 'VALUE':
imageslice = document.data
pimg = PIL.Image.fromarray(imageslice)
pimg.save(fname)
elif doctype == 'LUMINANCE':
imageslice = document.data
pimg = PIL.Image.fromarray(imageslice)
pimg.save(fname)
if doctype == 'RGB' or doctype == 'VALUE' or doctype == 'LUMINANCE':
raster_wrangler.rgbwriter(document.data, fname)
elif doctype == 'Z':
imageslice = document.data
if exrEnabled:
exr.save_depth(imageslice, fname)
else:
pimg = PIL.Image.fromarray(imageslice)
#TODO: avoid letting ImImagePlugin.py insert the Name: filename in line two
# why? because ImImagePlugin.py has a 100 character limit when it reads back
pimg.save(fname)
pimg.save(fname) #beside PIL.im, is there a standard for depth images?
raster_wrangler.zwriter(document.data, fname)
else:
with open(fname, mode='w') as file:
file.write(document.data)
......@@ -659,7 +639,7 @@ class FileStore(Store):
im = PIL.Image.open(doc_file)
data = np.array(im, np.uint8).reshape(im.size[1], im.size[0], 3)
elif doctype == 'Z':
if exrEnabled:
if raster_wrangler.exrEnabled:
data = exr.load_depth(doc_file)
else:
try:
......
......@@ -63,13 +63,13 @@ class ImageExplorer(explorers.Explorer):
if self.UsingGL2:
def rgb2grey(rgb, height, width):
as_grey = np.dot(rgb[...,:3], [0.0, 1.0, 0.0]) #pass through Diffuse lum term
res = np.flipud(as_grey.reshape(height,width).astype('uint8'))
res = as_grey.reshape(height,width).astype('uint8')
return res
self.rgb2grey = rgb2grey
else:
def rgb2grey(rgb, height, width):
as_grey = np.dot(rgb[...,:3], [0.299, 0.587, 0.144])
res = np.flipud(as_grey.reshape(height,width).astype('uint8'))
res = as_grey.reshape(height,width).astype('uint8')
return res
self.rgb2grey = rgb2grey
......@@ -83,7 +83,7 @@ class ImageExplorer(explorers.Explorer):
rw = self.view.GetRenderWindow()
width,height = rw.GetSize()
try:
imageslice = np.flipud(idata.reshape(height,width))
imageslice = idata.reshape(height,width)
except ValueError:
imageslice = None
#import Image
......@@ -121,7 +121,7 @@ class ImageExplorer(explorers.Explorer):
height = ext[3] - ext[2] + 1
imagescalars = image.GetPointData().GetScalars()
idata = numpy_support.vtk_to_numpy(imagescalars)
imageslice = np.flipud(idata.reshape(height,width,3))
imageslice = idata.reshape(height,width,3)
image.UnRegister(None)
#import Image
#img = Image.fromarray(imageslice)
......
......@@ -266,8 +266,12 @@ def make_cinema_store(levels, ocsfname, forcetime=False, _userDefinedValues={}):
tvalues = tprop['values']
#start with clean slate, other than time
cs = cinema_store.FileStore(ocsfname)
except IOError:
except IOError, KeyError:
pass
cs.add_metadata({'type':'composite-image-stack'})
cs.add_metadata({'store_type':'FS'})
cs.add_metadata({'version':'0.0'})
lcnt = 0
objhomes = {}
objnames = {}
......@@ -403,7 +407,8 @@ def explore(cs, proxies, iSave=True, currentTime=None):
rep = paraview.simple.GetRepresentation(sp, view_proxy)
#hide all annotations
rep.SetScalarBarVisibility(view_proxy, False)
if rep.LookupTable:
rep.SetScalarBarVisibility(view_proxy, False)
tc1 = pv_explorers.SourceProxyInLayer("ON", rep)
lt = explorers.Layer(y, [tc1])
tracks.append(lt)
......
#==============================================================================
# Copyright (c) 2015, Kitware Inc., Los Alamos National Laboratory
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this
# list of conditions and the following disclaimer in the documentation and/or other
# materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may
# be used to endorse or promote products derived from this software without specific
# prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#==============================================================================
"""
Module that uses one of the available back end libraries to write out image
files for cinema's file store class.
"""
import numpy
exrEnabled = False
try:
import OexrHelper as exr
exrEnabled = True
print "Imported OpenEXR, will default to *.exr in z-buffer images."
except ImportError:
pass
pilEnabled = False
try:
import PIL.Image
import PIL.ImImagePlugin
pilEnabled = True
except ImportError:
pass
vtkEnabled = False
try:
import sys
if "paraview" in sys.modules:
import paraview.vtk
import paraview.vtk.vtkIOImage
from paraview.vtk.vtkIOImage import (vtkPNGWriter,
vtkBMPWriter,
vtkPNMWriter,
vtkTIFFWriter,
vtkJPEGWriter)
from paraview.vtk.vtkCommonDataModel import vtkImageData
from paraview import numpy_support as n2v
else:
import vtk
from vtk import (vtkPNGWriter,
vtkBMPWriter,
vtkPNMWriter,
vtkTIFFWriter,
vtkJPEGWriter,
vtkImageData)
from vtk.util import numpy_support as n2v
vtkEnabled = True
except ImportError:
pass
def _make_writer(filename):
"Internal function."
extension = None
parts = filename.split('.')
if len(parts) > 1:
extension = parts[-1]
else:
raise RuntimeError, "Filename has no extension, please specify a write"
if extension == 'png':
return vtkPNGWriter()
elif extension == 'bmp':
return vtkBMPWriter()
elif extension == 'ppm':
return vtkPNMWriter()
elif extension == 'tif' or extension == 'tiff':
return vtkTIFFWriter()
elif extension == 'jpg' or extension == 'jpeg':
return vtkJPEGWriter()
else:
raise RuntimeError, "Cannot infer filetype from extension:", extension
def rgbwriter(imageslice, fname):
if pilEnabled:
imageslice = numpy.flipud(imageslice)
pimg = PIL.Image.fromarray(imageslice)
pimg.save(fname)
return
if vtkEnabled:
height = imageslice.shape[1]
width = imageslice.shape[0]
contig = imageslice.reshape(height*width,3)
vtkarray = n2v.numpy_to_vtk(contig)
id = vtkImageData()
id.SetExtent(0, height-1, 0, width-1, 0, 0)
id.GetPointData().SetScalars(vtkarray)
writer = _make_writer(fname)
writer.SetInputData(id)
writer.SetFileName(fname)
writer.Write()
return
print "Warning: need PIL or VTK to write to " + fname
def zwriter(imageslice, fname):
if exrEnabled:
imageslice = numpy.flipud(imageslice)
exr.save_depth(imageslice, fname)
return
if pilEnabled:
imageslice = numpy.flipud(imageslice)
pimg = PIL.Image.fromarray(imageslice)
#TODO:
# don't let ImImagePlugin.py insert the Name: filename in line two
# why? because ImImagePlugin.py reader has a 100 character limit
pimg.save(fname)
return
if vtkEnabled:
height = imageslice.shape[1]
width = imageslice.shape[0]
file = open(fname, mode='w')
file.write("Image type: L 32F image\r\n")
file.write("Name: A cinema depth image\r\n")
file.write("Image size (x*y): "+str(height) + "*" + str(width) + "\r\n")
file.write("File size (no of images): 1\r\n")
file.write(chr(26))
imageslice.tofile(file)
file.close()
return
print "Warning: need OpenEXR or PIL or VTK to write to " + fname
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment