MCPcopy Create free account
hub / github.com/Meshcapade/difflocks / load_strand

Function load_strand

utils/strand_util.py:10–67  ·  view source on GitHub ↗
(file, return_strands=False,interp=False,num_interp=100)

Source from the content-addressed store, hash-verified

8from utils.general_util import get_window
9
10def load_strand(file, return_strands=False,interp=False,num_interp=100):
11 with open(file, mode='rb')as f:
12 num_strand = f.read(4)
13
14 (num_strand,) = struct.unpack('I', num_strand)
15 point_count = f.read(4)
16
17 (point_count,) = struct.unpack('I', point_count)
18
19 # print("num_strand:",num_strand)
20 segments = f.read(2 * num_strand)
21 segments = struct.unpack('H' * num_strand, segments)
22 segments = list(segments)
23
24 num_points = sum(segments)
25
26 points = f.read(4 * num_points * 3)
27 points = struct.unpack('f' * num_points * 3, points)
28
29
30 f.close()
31 points = list(points)
32
33 points = np.array(points)
34 points = np.reshape(points, (-1, 3))
35 new_p = []
36 if return_strands:
37 beg = 0
38 strands = []
39 oris = []
40 for seg in segments:
41 end = beg + seg
42 strand = points[beg:end]
43 if interp:
44 try:
45 if strand.shape[0]>3:
46 new_points = B_spline_interpolate(strand,num_interp)
47 strand = np.stack(new_points,1)
48 new_p.append(strand)
49 else:
50 beg+=seg
51 continue
52 # new_p.append(strand)
53 except:
54 beg+=seg
55 continue
56
57
58 strands.append(strand)
59 dir = np.concatenate([strand[1:] - strand[:-1], strand[-1:] - strand[-2:-1]], 0)
60 dir = dir/np.linalg.norm(dir,2,-1,keepdims=True)
61 oris.append(dir)
62 beg += seg
63 if interp:
64 points = np.concatenate(new_p,0)
65 return segments, points, strands, oris
66 else:
67 return segments, points

Callers

nothing calls this directly

Calls 1

B_spline_interpolateFunction · 0.85

Tested by

no test coverage detected