stack-3d/process_russ_format.py
2017-02-16 15:26:55 +00:00

44 lines
No EOL
1.4 KiB
Python

"""
Reader for the MATLAB vessel network format provided by Russel Bates (russell.bates@new.ox.ac.uk)
"""
from argparse import ArgumentParser
import scipy.io
import numpy as np
def compare(x, y):
return (x[0] == y[0]) and (x[1] == y[1]) and (x[2] == y[2])
def convert_to_vtk(mat):
"""
Convert the format to VTK
"""
nodes = []
edges = []
for idx, eachConnectedComponent in enumerate(mat["Vessels"][0]):
adjacency = eachConnectedComponent['Adj']
branches = eachConnectedComponent['Branch'][0][0][0]
if idx ==0:
for kdx, eachBranch in enumerate(branches):
if kdx <200:
for jdx, eachPoint in enumerate(eachBranch['Points'][0][0]):
nodes.append(np.array(eachPoint))
for idx, eachEntry in enumerate(nodes):
for jdx, eachOtherEntry in enumerate(nodes):
if idx!=jdx:
if compare(eachEntry, eachOtherEntry):
print eachEntry, eachOtherEntry, idx, jdx
break
#nodes.append(eachBranch['Points'][0][0][0])
#print eachBranch['Points'][0][0][0]
#adjacency_indices = adjacency[0][0].nonzero()
#print adjacency_indices[0]
mat = scipy.io.loadmat('/home/grogan/Vessels.mat', struct_as_record=True)
convert_to_vtk(mat)