Reading network data from a file
The data describing large networks can obviously not be written out manually, as in a previous post. Here we will take a look at getting network data from an obj file.
import urllib2
filepath = 'http://block.arch.ethz.ch/labs/samples/saddle.obj'
response = urllib2.urlopen(filepath)
data = iter(response.readlines())
xyz = [] # xyz coordinates
vertices = [] # unique xyz coordinates
points = [] # references to vertices
lines = [] # pairs of references to vertices
deg = None
for line in data:
parts = line.split()
if not parts:
continue
head = parts[0]
tail = parts[1:]
if 'deg' == head:
deg = int(tail[0])
elif 'end' == head:
deg = None
elif 'v' == head:
xyz.append(map(float, tail))
deg = None
elif 'p' == head:
points.append(int(tail[0]) - 1)
deg = None
elif 'curv' == head:
if deg != 1:
continue
if len(tail[2:]) != 2:
continue
lines.append((int(tail[2]) - 1, int(tail[3]) - 1))
deg = None
x2v = {}
tol = 0.001**2
for i, x in enumerate(iter(xyz)):
found = False
for j, v in enumerate(iter(vertices)):
if (x[0] - v[0])**2 < tol \
and (x[1] - v[1])**2 < tol \
and (x[2] - v[2])**2 < tol:
found = True
x2v[i] = j
break
if not found:
x2v[i] = len(vertices)
vertices.append(x)
edges = [(x2v[u], x2v[v]) for u, v in lines]
points[:] = [x2v[index] for index in points]
Dear, can you please send me the file from this lin http://block.arch.ethz.ch/labs/samples/saddle.obj.
The file does not exist any more and I would like to try the code for the purpose of learning the space structures module at the University of Surrey.
Thank you.
Hi.
The .obj file with is not available anymore.
http://block.arch.ethz.ch/labs/samples/saddle.obj
Can you send it to me?
I am currently a senior master student in Architectural Technology at the University of Tehran.
I am doing research on ” Interactive equilibrium modelling of structural elements in designing of ecotourism bridges ” as my thesis.
hi,
the sample file is indeed no longer available from that location.
instead you can find it here
https://raw.githubusercontent.com/compas-dev/compas/master/data/saddle.obj
for other sample files, see
https://github.com/compas-dev/compas/tree/master/data
best,
tom