From 20d1164e5d8ed5ac2b7cd44132b9c765ecb63dfc Mon Sep 17 00:00:00 2001 From: Chen Date: Thu, 1 Sep 2016 16:57:29 -0400 Subject: [PATCH] add tensor support for vtk_addRectlinearGridData --- processing/post/vtk_addRectilinearGridData.py | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/processing/post/vtk_addRectilinearGridData.py b/processing/post/vtk_addRectilinearGridData.py index 63e0bf783..283a076c7 100755 --- a/processing/post/vtk_addRectilinearGridData.py +++ b/processing/post/vtk_addRectilinearGridData.py @@ -38,6 +38,10 @@ parser.add_option('-v', '--vector', dest = 'vector', action = 'extend', metavar = '', help = 'vector value label(s)') +parser.add_option('-t', '--tensor', + dest = 'tensor', + action = 'extend', metavar = '', + help = 'tensor (3x3) value label(s)') parser.add_option('-c', '--color', dest = 'color', action = 'extend', metavar = '', @@ -45,6 +49,7 @@ parser.add_option('-c', '--color', parser.set_defaults(scalar = [], vector = [], + tensor = [], color = [], inplace = False, render = False, @@ -92,9 +97,10 @@ for name in filenames: errors = [] VTKarray = {} active = defaultdict(list) - + for datatype,dimension,label in [['scalar',1,options.scalar], ['vector',3,options.vector], + ['tensor',9,options.tensor], ['color',3,options.color], ]: for i,dim in enumerate(table.label_dimension(label)): @@ -105,7 +111,7 @@ for name in filenames: remarks.append('adding {} "{}"...'.format(datatype,me)) active[datatype].append(me) - if datatype in ['scalar','vector']: VTKarray[me] = vtk.vtkDoubleArray() + if datatype in ['scalar','vector','tensor']: VTKarray[me] = vtk.vtkDoubleArray() elif datatype == 'color': VTKarray[me] = vtk.vtkUnsignedCharArray() VTKarray[me].SetNumberOfComponents(dimension) @@ -117,7 +123,7 @@ for name in filenames: table.close(dismiss = True) continue -# ------------------------------------------ process data --------------------------------------- +# ------------------------------------------ process data --------------------------------------- datacount = 0 @@ -129,11 +135,12 @@ for name in filenames: theData = [table.data[i] for i in table.label_indexrange(me)] # read strings if datatype == 'color': VTKarray[me].InsertNextTuple3(*map(lambda x: int(255.*float(x)),theData)) elif datatype == 'vector': VTKarray[me].InsertNextTuple3(*map(float,theData)) + elif datatype == 'tensor': VTKarray[me].InsertNextTuple9(*map(float,theData)) elif datatype == 'scalar': VTKarray[me].InsertNextValue(float(theData[0])) table.close() # close input ASCII table -# ------------------------------------------ add data --------------------------------------- +# ------------------------------------------ add data --------------------------------------- if datacount == Npoints: mode = 'point' elif datacount == Ncells: mode = 'cell' @@ -154,7 +161,7 @@ for name in filenames: rGrid.Modified() if vtk.VTK_MAJOR_VERSION <= 5: rGrid.Update() -# ------------------------------------------ output result --------------------------------------- +# ------------------------------------------ output result --------------------------------------- writer = vtk.vtkXMLRectilinearGridWriter() writer.SetDataModeToBinary() @@ -164,7 +171,7 @@ for name in filenames: else: writer.SetInputData(rGrid) writer.Write() -# ------------------------------------------ render result --------------------------------------- +# ------------------------------------------ render result --------------------------------------- if options.render: mapper = vtk.vtkDataSetMapper() @@ -188,7 +195,7 @@ if options.render: iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) - + iren.Initialize() renWin.Render() iren.Start()