Commit 6eb102f5fb68c062f24cc52df6014b81c5efe67d

Authored by Pavel Govyadinov
1 parent 9f9f1788

Fixed issue cause by splitting up the code and hid the DEBUG messages behind a variable

GraphCanvas.py
... ... @@ -21,6 +21,8 @@ import network_dep as nwt
21 21 from graph_shaders import vert, frag, vs, fs
22 22 from subgraph_shaders import vert_s, frag_s, vs_s, fs_s
23 23  
  24 +DEBUG = False
  25 +
24 26 #The graph canvas class that
25 27 class GraphCanvas(scene.SceneCanvas):
26 28  
... ... @@ -229,12 +231,13 @@ class GraphCanvas(scene.SceneCanvas):
229 231 len_array = np.zeros(location.shape[0])
230 232 offset_array = np.zeros(location.shape, dtype=np.float32)
231 233 cam_array[:][0:3] = camera_pos
232   - offset = [(bbu[0]-bbl[0])/2, (bbu[1]-bbl[1])/2, (bbu[2]-bbl[2])/2]
  234 + offset = [(self.bbu[0]-self.bbl[0])/2, (self.bbu[1]-self.bbl[1])/2, (self.bbu[2]-self.bbl[2])/2]
233 235 location = location - offset
234 236 location = location - camera_pos
235 237 for i in range(location.shape[0]):
236 238 len_array[i] = np.sqrt(np.power(location[i][0],2) + np.power(location[i][1],2) + np.power(location[i][2],2))
237 239  
  240 +
238 241 G.vertex_properties['dist_from_camera'] = G.new_vertex_property('float', vals=len_array)
239 242 self.data['a_size'] = nwt.Network.map_vertices_to_range(G, [1*self.pixel_scale, 60*self.pixel_scale], 'dist_from_camera').get_array()
240 243  
... ... @@ -266,7 +269,7 @@ class GraphCanvas(scene.SceneCanvas):
266 269 len_array = np.zeros(location.shape[0])
267 270 #offset_array = np.zeros(location.shape, dtype=np.float32)
268 271 cam_array[:][0:3] = camera_pos
269   - offset = [(bbu[0]-bbl[0])/2, (bbu[1]-bbl[1])/2, (bbu[2]-bbl[2])/2]
  272 + offset = [(self.bbu[0]-self.bbl[0])/2, (self.bbu[1]-self.bbl[1])/2, (self.bbu[2]-self.bbl[2])/2]
270 273 location = location - offset
271 274 location = location - camera_pos
272 275 for i in range(location.shape[0]):
... ... @@ -350,7 +353,7 @@ class GraphCanvas(scene.SceneCanvas):
350 353 self.data['a_selection'] = G.vertex_properties["selection"].get_array()
351 354 #self.data['a_graph_size'] = [bbu-bbl]
352 355  
353   - self.program['u_graph_size'] = [bbu-bbl]
  356 + self.program['u_graph_size'] = [self.bbu-self.bbl]
354 357  
355 358 self.vbo = gloo.VertexBuffer(self.data)
356 359 self.gen_line_vbo(G)
... ... @@ -363,7 +366,8 @@ class GraphCanvas(scene.SceneCanvas):
363 366 if(self.subgraphs):
364 367 #self.program_e_s.bind(self.vbo_s)
365 368 self.program_s.bind(self.vbo_s)
366   - print(self.view)
  369 + if DEBUG:
  370 + print(self.view)
367 371 self.update()
368 372  
369 373 """
... ... @@ -720,7 +724,8 @@ class GraphCanvas(scene.SceneCanvas):
720 724 if(self.subgraphs):
721 725 #self.program_e_s.bind(self.vbo_s)
722 726 self.program_s.bind(self.vbo_s)
723   - print(self.view)
  727 + if DEBUG:
  728 + print(self.view)
724 729 self.update()
725 730  
726 731  
... ... @@ -797,11 +802,13 @@ class GraphCanvas(scene.SceneCanvas):
797 802 for j in range(len(arc_length_vertex)):
798 803 if j != 0:
799 804 arc_length_vertex[j] += arc_length_vertex[j-1]
800   - print("arc_length before ", arc_length_vertex, " and sum to ", sum(arc_length_vertex))
  805 + if DEBUG:
  806 + print("arc_length before ", arc_length_vertex, " and sum to ", sum(arc_length_vertex))
801 807 arc_length_vertex = np.asarray(arc_length_vertex, dtype = np.float32)
802 808 arc_length_vertex = (np.pi - -np.pi)/(max(arc_length_vertex) - min(arc_length_vertex)) \
803 809 * (arc_length_vertex- min(arc_length_vertex)) + (-np.pi)
804   - print(arc_length_vertex)
  810 + if DEBUG:
  811 + print(arc_length_vertex)
805 812 #print(arc_length)
806 813  
807 814  
... ... @@ -821,7 +828,8 @@ class GraphCanvas(scene.SceneCanvas):
821 828  
822 829 temp.append(np.sum(g.vertex_properties['degree'].get_array()))
823 830 G.clear_filters()
824   - print(self.clusters['a_outer_arc_length'])
  831 + if DEBUG:
  832 + print(self.clusters['a_outer_arc_length'])
825 833 maximum = max(temp)
826 834 minimum = min(temp)
827 835 if len(temp) > 1:
... ... @@ -873,7 +881,8 @@ class GraphCanvas(scene.SceneCanvas):
873 881 self.program.bind(self.vbo)
874 882 if(self.subgraphs):
875 883 self.program_s.bind(self.vbo_s)
876   - print(self.view)
  884 + if DEBUG:
  885 + print(self.view)
877 886 self.update()
878 887  
879 888 """
... ... @@ -881,7 +890,8 @@ class GraphCanvas(scene.SceneCanvas):
881 890 spectral clustering on the graph passed if the subgraph is set to true.
882 891 """
883 892 def set_data(self, G, bbl, bbu, subgraph=True):
884   - print("Setting data")
  893 + if DEBUG:
  894 + print("Setting data")
885 895 self.G = G
886 896 self.bbl = bbl
887 897 self.bbu = bbu
... ... @@ -942,7 +952,8 @@ class GraphCanvas(scene.SceneCanvas):
942 952 if(self.subgraphs):
943 953 #self.program_e_s.bind(self.vbo_s)
944 954 self.program_s.bind(self.vbo_s)
945   - print(self.view)
  955 + if DEBUG:
  956 + print(self.view)
946 957 self.update()
947 958  
948 959 """
... ... @@ -1057,7 +1068,7 @@ class GraphCanvas(scene.SceneCanvas):
1057 1068 if(self.view[0][0] > 0.0010):
1058 1069 c_id = self.get_clicked_id(event)
1059 1070 if(c_id != None):
1060   - self.original_point = G.vertex_properties["pos"][G.vertex(c_id)]
  1071 + self.original_point = self.G.vertex_properties["pos"][self.G.vertex(c_id)]
1061 1072 self.location = event.pos
1062 1073 self.moving = True
1063 1074 self.down = True
... ... @@ -1067,7 +1078,8 @@ class GraphCanvas(scene.SceneCanvas):
1067 1078 #print("Clicked on:", event.pos)
1068 1079 else:
1069 1080 c_id = self.get_clicked_id(event, True)
1070   - print(c_id)
  1081 + if DEBUG:
  1082 + print(c_id)
1071 1083 if(c_id != None):
1072 1084 self.original_point = self.cluster_pos[c_id]
1073 1085 self.location = event.pos
... ... @@ -1090,10 +1102,10 @@ class GraphCanvas(scene.SceneCanvas):
1090 1102 self.update()
1091 1103  
1092 1104 def add_to_path(self, source, target):
1093   - vl, el = nwt.gt.graph_tool.topology.shortest_path(G, G.vertex(source), G.vertex(target), weights=G.edge_properties["av_radius"])
  1105 + vl, el = nwt.gt.graph_tool.topology.shortest_path(self.G, self.G.vertex(source), self.G.vertex(target), weights=self.G.edge_properties["av_radius"])
1094 1106 for v in vl:
1095 1107 if(int(v) not in self.path):
1096   - G.vertex_properties["selection"][v] = 2.0
  1108 + self.G.vertex_properties["selection"][v] = 2.0
1097 1109 self.data['a_selection'][int(v)] = 2.0
1098 1110 if(int(v) not in self.full_path):
1099 1111 self.full_path.append(int(v))
... ... @@ -1105,7 +1117,7 @@ class GraphCanvas(scene.SceneCanvas):
1105 1117 #check whether this is the first node to be selected
1106 1118 if(self.pathing == False):
1107 1119 #if it is, select that node and turn the pathing variable on.
1108   - G.vertex_properties["selection"][G.vertex(c_id)] = 1.0
  1120 + self.G.vertex_properties["selection"][self.G.vertex(c_id)] = 1.0
1109 1121 self.pathing = True
1110 1122 if(c_id not in self.path):
1111 1123 self.path.append(c_id)
... ... @@ -1113,14 +1125,14 @@ class GraphCanvas(scene.SceneCanvas):
1113 1125 update_vbo(self)
1114 1126 print("I turned on the first node")
1115 1127 else:
1116   - if(G.vertex_properties["selection"][G.vertex(c_id)] == 1.0):
1117   - G.vertex_properties["selection"][G.vertex(c_id)] = 0.0
  1128 + if(self.G.vertex_properties["selection"][self.G.vertex(c_id)] == 1.0):
  1129 + self.G.vertex_properties["selection"][self.G.vertex(c_id)] = 0.0
1118 1130 self.path.remove(c_id)
1119 1131 self.data['a_selection'][c_id] = 0.0
1120 1132 update_vbo(self)
1121 1133 print("I turned off a node")
1122   - elif(G.vertex_properties["selection"][G.vertex(c_id)] == 0.0):
1123   - G.vertex_properties["selection"][G.vertex(c_id)] = 1.0
  1134 + elif(self.G.vertex_properties["selection"][self.G.vertex(c_id)] == 0.0):
  1135 + self.G.vertex_properties["selection"][self.G.vertex(c_id)] = 1.0
1124 1136 if(c_id not in self.path):
1125 1137 self.path.append(c_id)
1126 1138 self.data['a_selection'][c_id] = 1.0
... ... @@ -1131,7 +1143,7 @@ class GraphCanvas(scene.SceneCanvas):
1131 1143 add_to_path(self, self.path[i], self.path[i+1])
1132 1144 update_vbo(self)
1133 1145 #THIS IS WHERE I LEFT IT OFF.
1134   - if(np.sum(G.vertex_properties["selection"].get_array()) == 0):
  1146 + if(np.sum(self.G.vertex_properties["selection"].get_array()) == 0):
1135 1147 self.pathing = False
1136 1148  
1137 1149  
... ... @@ -1236,7 +1248,7 @@ class GraphCanvas(scene.SceneCanvas):
1236 1248 #Project into GLSpace and get before and after move coordinates
1237 1249 coord = self.transforms.get_transform('canvas', 'render').map(self.location)[:2]
1238 1250 coord2 = self.transforms.get_transform('canvas', 'render').map(event.pos)[:2]
1239   - cur_pos = G.vertex_properties["pos"][G.vertex(self.c_id[0])]
  1251 + cur_pos = self.G.vertex_properties["pos"][self.G.vertex(self.c_id[0])]
1240 1252 #print(cur_pos, " Before")
1241 1253  
1242 1254 #Adjust the position of the node based on the current view matrix.
... ... @@ -1245,13 +1257,13 @@ class GraphCanvas(scene.SceneCanvas):
1245 1257  
1246 1258 #print(cur_pos, " After")
1247 1259 #Upload the changed data.
1248   - G.vertex_properties["pos"][G.vertex(self.c_id[0])] = cur_pos
  1260 + self.G.vertex_properties["pos"][self.G.vertex(self.c_id[0])] = cur_pos
1249 1261 self.data['a_position'][self.c_id[0]] = cur_pos
1250 1262  
1251 1263 #update the edge data by finding all edges connected to the vertex
1252 1264 v = self.G.vertex(self.c_id[0])
1253 1265 for e in v.all_edges():
1254   - d = np.subtract(G.vertex_properties["pos"][e.source()], G.vertex_properties["pos"][e.target()])
  1266 + d = np.subtract(self.G.vertex_properties["pos"][e.source()], self.G.vertex_properties["pos"][e.target()])
1255 1267 d_norm = d[0:2]
1256 1268 d_norm = d_norm / np.sqrt(np.power(d_norm[0],2) + np.power(d_norm[1],2))
1257 1269 norm = np.zeros((2,), dtype=np.float32)
... ... @@ -1319,7 +1331,7 @@ class GraphCanvas(scene.SceneCanvas):
1319 1331 cur_pos[0] = cur_pos[0] - (coord[0]-coord2[0])/self.view[0][0]
1320 1332 cur_pos[1] = cur_pos[1] - (coord[1]-coord2[1])/self.view[0][0]
1321 1333  
1322   - self.update_cluster_position(G, cur_pos, offset, self.c_id[0])
  1334 + self.update_cluster_position(self.G, cur_pos, offset, self.c_id[0])
1323 1335 #self.original_point = cur_pos
1324 1336 self.vbo = gloo.VertexBuffer(self.data)
1325 1337 self.vbo_line = gloo.VertexBuffer(self.line_data)
... ...
GraphWidget.py
... ... @@ -10,6 +10,7 @@ from GraphCanvas import GraphCanvas
10 10 from pyqtgraph.Qt import QtCore, QtGui, QtWidgets
11 11 import network_dep as nwt
12 12  
  13 +DEBUG = False
13 14  
14 15 """
15 16 Initializes the entire QTlayout and sets the mouse press events.
... ... @@ -68,21 +69,24 @@ class GraphWidget(QtGui.QWidget):
68 69 #EXP_adv = menu.addAction('Export VTK Advanced')
69 70 NL = menu.addAction('New Layout')
70 71 action = menu.exec_(event.native.globalPos())
71   - print(action)
  72 + if DEBUG:
  73 + print(action)
72 74 for i in range(len(vertex_actions)):
73 75 if action == vertex_actions[i]:
74 76 if vertex_props[i] == "clusters":
75 77 self.canvas.color_vertices(self.canvas.G, vertex_props[i], dtype=True)
76 78 else:
77 79 self.canvas.color_vertices(self.canvas.G, vertex_props[i])
78   - print(vertex_props[i])
  80 +
  81 + if DEBUG:
  82 + print(vertex_props[i])
79 83 if action == NS:
80 84 if self.use_3D == False:
81 85 self.use_3D = True
82 86 else:
83 87 self.use_3D = False
84 88 self.canvas.size_vertices(self.canvas.G, 'degree' )
85   - self.canvas.color_vertices(self.canvas.G)
  89 + self.canvas.color_vertices(self.canvas.G, 'degree')
86 90 #if action == NC:
87 91 # self.canvas.color_vertices(self.canvas.G, not self.color)
88 92 # self.color = not self.color
... ... @@ -94,7 +98,8 @@ class GraphWidget(QtGui.QWidget):
94 98 # nwt.Network.write_vtk(self.canvas.G, "./nwt_points_wise_binned.vtk", camera=self.camera, binning = True)
95 99 # nwt.Network.write_vtk(self.canvas.G, "./nwt_points_wise_non_binned.vtk", camera=self.camera, binning = False)
96 100 if action == tmp:
97   - print("Stuff")
  101 + if DEBUG:
  102 + print("Stuff")
98 103 #self.cb = QtWidgets.QComboBox()
99 104 #vertex_props = self.canvas.G.vertex_properties.keys()
100 105 #for i in range(len(vertex_props)):
... ... @@ -171,7 +176,8 @@ class GraphWidget(QtGui.QWidget):
171 176 self.camera = [x,y,z]
172 177 self.canvas.vertexSizeFromDistance(self.canvas.G, [x,y,z])
173 178 self.canvas.vertexAlphaFromDistance(self.canvas.G, [x,y,z])
174   - #print("got signal", x, y, z)
  179 + if DEBUG:
  180 + print("got signal", x, y, z)
175 181  
176 182 """
177 183 Initialization method that connects the slot to the function that handles
... ...
GuiVisPy_tube.py
... ... @@ -25,6 +25,9 @@ from GraphWidget import GraphWidget
25 25 from TubeWidget import TubeWidget
26 26  
27 27  
  28 +DEBUG = False
  29 +
  30 +
28 31 #set the backend. for different versions of PyQt
29 32 app.use_app(backend_name='PyQt5')
30 33  
... ... @@ -93,7 +96,9 @@ G, bbl, bbu = load_nwt("/home/pavel/Documents/Python/GraphGuiQt/network_4.nwt")
93 96 #ret = nwt.Network.get_affinity_matrix(G, "length")
94 97 node_image = QtGui.QImage("/home/pavel/Documents/Python/GraphGuiQt/node_tex.jpg")
95 98 node_tex = QtGui.QBitmap.fromImage(node_image)
96   -print(node_tex.depth())
  99 +
  100 +if DEBUG:
  101 + print(node_tex.depth())
97 102 center = (bbu-bbl)/2.0
98 103 #fibers.opts['distance'] = 5
99 104 # item = NodeItem(G)
... ...
TubeCanvas.py
... ... @@ -23,6 +23,12 @@ import network_dep as nwt
23 23  
24 24 from tube_shaders import FRAG_SHADER, VERT_SHADER
25 25  
  26 +from mpl_toolkits.mplot3d import Axes3D
  27 +import matplotlib
  28 +import matplotlib.pyplot as plt
  29 +
  30 +DEBUG = False
  31 +
26 32 class TubeDraw(scene.SceneCanvas):
27 33 #sigUpdate = QtCore.pyqtSignal(float, float, float)
28 34  
... ... @@ -105,7 +111,8 @@ class TubeDraw(scene.SceneCanvas):
105 111 for j in range(3):
106 112 self.bb[i,j] = bb[i][j]
107 113 self.program['u_bb'] = self.bb
108   - print('bb is ', self.bb)
  114 + if DEBUG:
  115 + print('bb is ', self.bb)
109 116 # for i in range(len(self.translate)):
110 117 # self.camera[i] += self.translate[i]
111 118  
... ... @@ -127,7 +134,8 @@ class TubeDraw(scene.SceneCanvas):
127 134 def on_resize(self, event):
128 135 width, height = event.physical_size
129 136 gloo.set_viewport(0, 0, width, height)
130   - print(self.physical_size)
  137 + if DEBUG:
  138 + print(self.physical_size)
131 139  
132 140 #overloaded function called during the self.update() call to update the current
133 141 #frame using the GLSL frag/vert shaders
... ... @@ -294,32 +302,32 @@ class TubeDraw(scene.SceneCanvas):
294 302 #Add the caps for each of the endpoints.
295 303  
296 304  
297   -
298   - if(i == 2):
299   - fig = plt.figure()
300   - ax = fig.add_subplot(111, projection='3d')
301   - #ax.scatter(circle_pts[:,:,0], circle_pts[:,:,1], circle_pts[:,:,2])
302   - ax.plot(pts[:,0], pts[:,1], pts[:,2])
303   - for j in range(pts.shape[0]):
304   - ax.plot(circle_pts[j,:,0], circle_pts[j,:,1], circle_pts[j,:,2])
305   - for j in range(triangles.shape[0]):
306   - tri = np.zeros((3,4))
307   - tri[:,0] = self.cylinder_data['a_position'][triangles[j][0]]
308   - tri[:,1] = self.cylinder_data['a_position'][triangles[j][1]]
309   - tri[:,2] = self.cylinder_data['a_position'][triangles[j][2]]
310   - tri[:,3] = self.cylinder_data['a_position'][triangles[j][0]]
311   - ax.plot(tri[0,:], tri[1,:], tri[2,:], c='b')
312   - for j in range(triangles.shape[0]):
313   - tri = np.zeros((3,3))
314   - tri[:,0] = self.cylinder_data['a_position'][triangles[j][0]]
315   - tri[:,1] = self.cylinder_data['a_position'][triangles[j][1]]
316   - tri[:,2] = self.cylinder_data['a_position'][triangles[j][2]]
317   - norm = np.zeros((3,3))
318   - norm[:,0] = self.cylinder_data['a_normal'][triangles[j][0]]
319   - norm[:,1] = self.cylinder_data['a_normal'][triangles[j][1]]
320   - norm[:,2] = self.cylinder_data['a_normal'][triangles[j][2]]
321   - ax.quiver(tri[0,:], tri[1,:], tri[2,:], norm[0,:], norm[1,:], norm[2,:], colors = 'r')
322   - plt.show()
  305 + if DEBUG:
  306 + if(i == 2):
  307 + fig = plt.figure()
  308 + ax = fig.add_subplot(111, projection='3d')
  309 + #ax.scatter(circle_pts[:,:,0], circle_pts[:,:,1], circle_pts[:,:,2])
  310 + ax.plot(pts[:,0], pts[:,1], pts[:,2])
  311 + for j in range(pts.shape[0]):
  312 + ax.plot(circle_pts[j,:,0], circle_pts[j,:,1], circle_pts[j,:,2])
  313 + for j in range(triangles.shape[0]):
  314 + tri = np.zeros((3,4))
  315 + tri[:,0] = self.cylinder_data['a_position'][triangles[j][0]]
  316 + tri[:,1] = self.cylinder_data['a_position'][triangles[j][1]]
  317 + tri[:,2] = self.cylinder_data['a_position'][triangles[j][2]]
  318 + tri[:,3] = self.cylinder_data['a_position'][triangles[j][0]]
  319 + ax.plot(tri[0,:], tri[1,:], tri[2,:], c='b')
  320 + for j in range(triangles.shape[0]):
  321 + tri = np.zeros((3,3))
  322 + tri[:,0] = self.cylinder_data['a_position'][triangles[j][0]]
  323 + tri[:,1] = self.cylinder_data['a_position'][triangles[j][1]]
  324 + tri[:,2] = self.cylinder_data['a_position'][triangles[j][2]]
  325 + norm = np.zeros((3,3))
  326 + norm[:,0] = self.cylinder_data['a_normal'][triangles[j][0]]
  327 + norm[:,1] = self.cylinder_data['a_normal'][triangles[j][1]]
  328 + norm[:,2] = self.cylinder_data['a_normal'][triangles[j][2]]
  329 + ax.quiver(tri[0,:], tri[1,:], tri[2,:], norm[0,:], norm[1,:], norm[2,:], colors = 'r')
  330 + plt.show()
323 331 i+=1
324 332 #create the data.
325 333  
... ... @@ -387,7 +395,8 @@ class TubeDraw(scene.SceneCanvas):
387 395  
388 396 theta = (coord[0]-coord2[0])*360.0/2.0/np.pi
389 397 phi = (coord[1]-coord2[1])*360.0/2.0/np.pi
390   - print(theta*360.0/2.0/np.pi, -phi*360.0/2.0/np.pi)
  398 + if DEBUG:
  399 + print(theta*360.0/2.0/np.pi, -phi*360.0/2.0/np.pi)
391 400 self.camera = self.camera - self.translate
392 401 q1 = Quaternion.create_from_axis_angle(angle=phi, ax=0.0, ay=1.0, az=0.0, degrees=True)
393 402 q2 = Quaternion.create_from_axis_angle(angle=theta, ax=1.0, ay=0.0, az=0.0, degrees=True)
... ... @@ -432,7 +441,8 @@ class TubeDraw(scene.SceneCanvas):
432 441 #self.camera[0] = self.camera[0] + self.center[0]
433 442 #self.camera[1] = self.camera[1] + self.center[1]
434 443 #self.camera[2] = self.camera[2] - self.center[2]
435   - print("current position ", self.camera, " and up vector ", self.up)
  444 + if DEBUG:
  445 + print("current position ", self.camera, " and up vector ", self.up)
436 446 self.program['u_eye'] = self.camera
437 447 self.program['u_up'] = self.up
438 448 self.program['u_LightPos'] = [self.camera[0], self.camera[1], self.camera[2]]
... ...
TubeWidget.py
... ... @@ -14,6 +14,8 @@ Created on Mon Aug 5 15:53:16 2019
14 14 from pyqtgraph.Qt import QtCore, QtGui, QtWidgets
15 15 from TubeCanvas import TubeDraw
16 16  
  17 +DEBUG = False
  18 +
17 19 class TubeWidget(QtGui.QWidget):
18 20 sigUpdate = QtCore.pyqtSignal(float, float, float)
19 21 #Initializes the QT wrapper class.
... ... @@ -60,6 +62,7 @@ class TubeWidget(QtGui.QWidget):
60 62 #self.view = self.canvas.view
61 63 self.camera = self.canvas.camera
62 64 #print("stuff", self.view[3, 0], self.view[3, 1], self.view[3, 2])
63   - print("stuff", self.camera[0], self.camera[1], self.camera[2])
  65 + if DEBUG:
  66 + print("stuff", self.camera[0], self.camera[1], self.camera[2])
64 67 self.sigUpdate.emit(self.camera[0], self.camera[1], self.camera[2])
65 68  
... ...
network_dep.py
... ... @@ -27,6 +27,8 @@ import copy
27 27 #import matplotlib.pyplot as plt
28 28 #from matplotlib import cm
29 29  
  30 +DEBUG = False
  31 +
30 32 '''
31 33 Definition of the Node class
32 34 Duplicate of the node class in network
... ... @@ -81,9 +83,9 @@ class Fiber:
81 83 for i in range(len(self.points)-1):
82 84 length = length + math.sqrt(pow(self.points[i][0]- self.points[i+1][0],2) + pow(self.points[i][1]- self.points[i+1][1],2) + pow(self.points[i][2]- self.points[i+1][2],2))
83 85 if(length == 0):
84   - print(self.points)
85   - print(len(self.points))
86   - print(self.v0, " ", self.v1)
  86 + print("NON-CRITICAL ERROR: edge with length 0 is detected: IDX = "\
  87 + , i, ", points = ", self.points, " len(points) = ", len(self.points)\
  88 + , " vertices = ", self.v0, " ", self.v1)
87 89 return length
88 90  
89 91 '''
... ... @@ -396,12 +398,12 @@ class AABB():
396 398  
397 399  
398 400 vertices = list(np.unique(np.array(vertices), axis=0))
399   - import matplotlib.pyplot as plt
400   - fig = plt.figure()
401   - ax = plt.axes(projection='3d')
402   - ax.scatter3D(np.array(vertices)[:, 0], np.array(vertices)[:, 1], np.array(vertices)[:, 2])
  401 + #import matplotlib.pyplot as plt
  402 + #fig = plt.figure()
  403 + #ax = plt.axes(projection='3d')
  404 + #ax.scatter3D(np.array(vertices)[:, 0], np.array(vertices)[:, 1], np.array(vertices)[:, 2])
403 405  
404   - print("THERE ARE THIS MANY ", len(vertices))
  406 + #print("THERE ARE THIS MANY ", len(vertices))
405 407 return vertices
406 408  
407 409 def getVolume(self):
... ... @@ -417,42 +419,49 @@ class AABB():
417 419 temp = copy.deepcopy(self.A)
418 420 temp[0] = temp[0] + size[0]
419 421 points.append(temp)
420   - print('1', temp)
  422 + if DEBUG:
  423 + print('1', temp)
421 424  
422 425 temp = copy.deepcopy(self.A)
423 426 temp[1] = temp[1] + size[1]
424 427 points.append(temp)
425   - print('1', temp)
  428 + if DEBUG:
  429 + print('1', temp)
426 430  
427 431 temp = copy.deepcopy(self.A)
428 432 temp[2] = temp[2] + size[2]
429 433 points.append(temp)
430   - print('1', temp)
  434 + if DEBUG:
  435 + print('1', temp)
431 436  
432 437 temp = copy.deepcopy(self.A)
433 438 temp[1] = temp[1] + size[1]
434 439 temp[0] = temp[0] + size[0]
435 440 points.append(temp)
436   - print('1', temp)
  441 + if DEBUG:
  442 + print('1', temp)
437 443  
438 444 temp = copy.deepcopy(self.A)
439 445 temp[2] = temp[2] + size[2]
440 446 temp[0] = temp[0] + size[0]
441 447 points.append(temp)
442   - print('1', temp)
  448 + if DEBUG:
  449 + print('1', temp)
443 450  
444 451 temp = copy.deepcopy(self.A)
445 452 temp[1] = temp[1] + size[1]
446 453 temp[2] = temp[2] + size[2]
447 454 points.append(temp)
448   - print('1', temp)
  455 + if DEBUG:
  456 + print('1', temp)
449 457  
450 458 temp = copy.deepcopy(self.A)
451 459 temp[0] = temp[0] + size[0]
452 460 temp[1] = temp[1] + size[1]
453 461 temp[2] = temp[2] + size[2]
454 462 points.append(temp)
455   - print('1', temp)
  463 + if DEBUG:
  464 + print('1', temp)
456 465  
457 466 return points
458 467  
... ... @@ -908,7 +917,8 @@ class Network:
908 917  
909 918 def simulate_fractures(self, G, remove=10):
910 919 num_removed = int(np.floor(G.num_edges()*remove/100))
911   - print("num of edges to begin with = ", G.num_edges())
  920 + if DEBUG:
  921 + print("num of edges to begin with = ", G.num_edges())
912 922 indices = np.random.randint(0, int(G.num_edges()), size = [num_removed,1])
913 923 #aabb = AABB(G, is_dual)
914 924 tf = np.full((G.num_edges(), 1), True, dtype=bool)
... ... @@ -921,9 +931,10 @@ class Network:
921 931 G1.clear_filters()
922 932 G1 = self.filterDisconnected(G1)
923 933 G1.vertex_properties["degree"] = G1.degree_property_map("total")
924   - print("num of edges left = ", G1.num_edges())
925   - print("I should have removed, ", num_removed)
926   - print("Instead I removed, ", G.num_edges() - G1.num_edges())
  934 + if DEBUG:
  935 + print("num of edges left = ", G1.num_edges())
  936 + print("I should have removed, ", num_removed)
  937 + print("Instead I removed, ", G.num_edges() - G1.num_edges())
927 938  
928 939 return G1
929 940  
... ... @@ -992,7 +1003,8 @@ class Network:
992 1003  
993 1004 G.edge_properties["mst"] = gt.graph_tool.topology.min_spanning_tree(G, weights=G.edge_properties["length"])
994 1005 G.graph_properties["mst_ratio"] = np.double(np.sum(G.edge_properties["mst"].get_array()))/np.double(G.num_edges())
995   - print(np.double(np.sum(G.edge_properties["mst"].get_array()))/np.double(G.num_edges()))
  1006 + if DEBUG:
  1007 + print(np.double(np.sum(G.edge_properties["mst"].get_array()))/np.double(G.num_edges()))
996 1008 G.vertex_properties["degree"] = G.degree_property_map("total")
997 1009 G.vertex_properties["degree_volume"] = G.degree_property_map("total", weight=G.edge_properties["volume"])
998 1010 G.vertex_properties["degree_tortuosity"] = G.degree_property_map("total", G.edge_properties["tortuosity"])
... ... @@ -1065,9 +1077,11 @@ class Network:
1065 1077 G1 = self.filterBorder(G, is_dual=dual);
1066 1078 if(erode == True):
1067 1079 while(np.any(G1.degree_property_map("total").get_array() == True)):
1068   - print(G1.num_vertices())
  1080 + if DEBUG:
  1081 + print(G1.num_vertices())
1069 1082 G1 = self.filterBorder(G1, is_dual=dual)
1070   - print(G1.num_vertices())
  1083 + if DEBUG:
  1084 + print(G1.num_vertices())
1071 1085 G1 = self.recalculate_metrics(G1, is_dual=dual, )
1072 1086 else:
1073 1087 G1 = self.recalculate_metrics(G1, is_dual=dual)
... ... @@ -1331,7 +1345,7 @@ class Network:
1331 1345 r_edge[G.edge(v0,v1)] = r
1332 1346 av_edge[G.edge(v0,v1)] = self.F[i].av_radius()
1333 1347 else:
1334   - print("WTF")
  1348 + print("NON-CRITICAL ERROR: edge with length 0 detected--SKIPPED")
1335 1349  
1336 1350  
1337 1351 #generate centrality map
... ... @@ -1574,7 +1588,8 @@ class Network:
1574 1588 #This is when the property map is integers
1575 1589 #int32_t when integer
1576 1590 value_type = propertymap.value_type()
1577   - print(value_type)
  1591 + if DEBUG:
  1592 + print(value_type)
1578 1593 if(value_type == "int32_t"):
1579 1594 array = propertymap.get_array()
1580 1595 colors = cm.get_cmap(colormap, len(np.unique(array)))
... ... @@ -1589,7 +1604,8 @@ class Network:
1589 1604 colors = cm.ScalarMappable(norm=norm, cmap=colormap)
1590 1605 if key_type =='v':
1591 1606 for v in G.vertices():
1592   - print(colors.to_rgba(propertymap[v]))
  1607 + if DEBUG:
  1608 + print(colors.to_rgba(propertymap[v]))
1593 1609 G.vertex_properties["RGBA"][v] = colors.to_rgba(propertymap[v])
1594 1610 return G.vertex_properties["RGBA"]
1595 1611 elif(value_type == 'vector<double>' or value_type == 'vector<float>'):
... ... @@ -1628,6 +1644,7 @@ class Network:
1628 1644 if d < dist:
1629 1645 idx = M
1630 1646 dist = d
  1647 + #if DEBUG:
1631 1648 print(idx, " vertex[",p[0][idx], p[1][idx], p[2][idx], "], point [", x[i], y[j], z[k], "]")
1632 1649 clusters = G.new_vertex_property("int", vals=np.full((G.num_vertices(), 1), -1, dtype=int))
1633 1650 #eclusters = G.new_edge_property("int", vals=np.full((G.num_edges(), 1), -1, dtype=int))
... ... @@ -1741,10 +1758,12 @@ class Network:
1741 1758 eclusters = G1.new_edge_property("int", vals = np.full((G1.num_edges(), 1), 3, dtype=int))
1742 1759 G1.vertex_properties["cycle"] = clusters
1743 1760 G1.edge_properties["cycle"] = eclusters
1744   - print("Number of vertices in Path is:", len(Vl))
  1761 + if DEBUG:
  1762 + print("Number of vertices in Path is:", len(Vl))
1745 1763 for v in Vl:
1746 1764 G1.vertex_properties["cycle"][G1.vertex(v)] = 10
1747   - print(str(v))
  1765 + if DEBUG:
  1766 + print(str(v))
1748 1767 #Create the arrays to be histogrammed later regarding every loop
1749 1768 length_total = 0
1750 1769 volume_total = 0
... ... @@ -1815,10 +1834,10 @@ class Network:
1815 1834 n_components = G1.num_vertices()
1816 1835 eigenvalues, eigenvectors = eigsh(L, k=n_components, which = "LM", sigma=1.0, maxiter = 5000)
1817 1836  
1818   - plt.figure()
1819   - plt.scatter(np.arange(len(eigenvalues)), eigenvalues)
1820   - plt.grid()
1821   - plt.show()
  1837 + #plt.figure()
  1838 + #plt.scatter(np.arange(len(eigenvalues)), eigenvalues)
  1839 + #plt.grid()
  1840 + #plt.show()
1822 1841  
1823 1842 count = sum(eigenvalues > 1.01)
1824 1843 return count
... ... @@ -1915,8 +1934,9 @@ class Network:
1915 1934 if binning:
1916 1935 index = np.digitize(G.edge_properties["RGBA"][e][3], bins, right=True)
1917 1936 if (index >= len(bins) or index < 0):
1918   - print(G.edge_properties["RGBA"][e][3])
1919   - print(index)
  1937 + if DEBUG:
  1938 + print(G.edge_properties["RGBA"][e][3])
  1939 + print(index)
1920 1940 f.write("%.15f\n" % bins[index])
1921 1941 else:
1922 1942 f.write("%.15f\n" % G.edge_properties["RGBA"][e][3])
... ... @@ -2036,7 +2056,7 @@ class Network:
2036 2056 #generate a KD-Tree out of the network point array
2037 2057 tree = sp.spatial.cKDTree(P)
2038 2058  
2039   - plt.scatter(P[:, 0], P[:, 1])
  2059 + #plt.scatter(P[:, 0], P[:, 1])
2040 2060  
2041 2061 #specify the resolution of the ouput grid
2042 2062 R = (200, 200, 200)
... ...