From f922784983c1fdf4a628b36f85184ff73caf8e49 Mon Sep 17 00:00:00 2001 From: Steve Pieper Date: Thu, 18 Feb 2021 14:45:06 -0500 Subject: [PATCH] Set active arrays in vtk polydata Previously untrakofy output a vtkPolyData with arrays for each of the restored attributes, but it did not set any of them active. Some SlicerDMRI utilities require a default active tensor be defined (even though it's not semantically meaningful). This change sets the first scalar array and the first tensor array to be active in order to be compatible with the expectations of the FiberTractMeasurements tool in SlicerDMRI. Fixes #11 --- trako/gltfi2vtk.py | 8 +++++++- trako/util.py | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/trako/gltfi2vtk.py b/trako/gltfi2vtk.py index 810e53e..203a23c 100644 --- a/trako/gltfi2vtk.py +++ b/trako/gltfi2vtk.py @@ -87,6 +87,7 @@ def convert(input, output=None, verbose=True): points = vtk.vtkPoints() points.SetData(numpy_support.numpy_to_vtk(draco_points_reshaped)) polydata.SetPoints(points) + pointdata = polydata.GetPointData() # # scalars @@ -101,11 +102,16 @@ def convert(input, output=None, verbose=True): scalarname = k[1:] vtkArr = numpy_support.numpy_to_vtk(draco_points_reshaped) vtkArr.SetName(scalarname) - polydata.GetPointData().AddArray(vtkArr) + pointdata.AddArray(vtkArr) if verbose: print('Restored scalar', scalarname) + if draco_points_reshaped.shape[1] == 1 and pointdata.GetScalars() is None: + pointdata.SetScalars(vtkArr) + + if draco_points_reshaped.shape[1] == 9 and pointdata.GetTensors() is None: + pointdata.SetTensors(vtkArr) # # # now the indices / cell data diff --git a/trako/util.py b/trako/util.py index 576ea34..8341ed6 100644 --- a/trako/util.py +++ b/trako/util.py @@ -1,5 +1,5 @@ import numpy as np -import matplotlib.pyplot as plt +#import matplotlib.pyplot as plt import vtk from vtk.util import numpy_support