diff --git a/GraphCanvas.py b/GraphCanvas.py index cb60c20..9cf11af 100644 --- a/GraphCanvas.py +++ b/GraphCanvas.py @@ -21,6 +21,8 @@ import network_dep as nwt from graph_shaders import vert, frag, vs, fs from subgraph_shaders import vert_s, frag_s, vs_s, fs_s +DEBUG = False + #The graph canvas class that class GraphCanvas(scene.SceneCanvas): @@ -229,12 +231,13 @@ class GraphCanvas(scene.SceneCanvas): len_array = np.zeros(location.shape[0]) offset_array = np.zeros(location.shape, dtype=np.float32) cam_array[:][0:3] = camera_pos - offset = [(bbu[0]-bbl[0])/2, (bbu[1]-bbl[1])/2, (bbu[2]-bbl[2])/2] + offset = [(self.bbu[0]-self.bbl[0])/2, (self.bbu[1]-self.bbl[1])/2, (self.bbu[2]-self.bbl[2])/2] location = location - offset location = location - camera_pos for i in range(location.shape[0]): len_array[i] = np.sqrt(np.power(location[i][0],2) + np.power(location[i][1],2) + np.power(location[i][2],2)) + G.vertex_properties['dist_from_camera'] = G.new_vertex_property('float', vals=len_array) self.data['a_size'] = nwt.Network.map_vertices_to_range(G, [1*self.pixel_scale, 60*self.pixel_scale], 'dist_from_camera').get_array() @@ -266,7 +269,7 @@ class GraphCanvas(scene.SceneCanvas): len_array = np.zeros(location.shape[0]) #offset_array = np.zeros(location.shape, dtype=np.float32) cam_array[:][0:3] = camera_pos - offset = [(bbu[0]-bbl[0])/2, (bbu[1]-bbl[1])/2, (bbu[2]-bbl[2])/2] + offset = [(self.bbu[0]-self.bbl[0])/2, (self.bbu[1]-self.bbl[1])/2, (self.bbu[2]-self.bbl[2])/2] location = location - offset location = location - camera_pos for i in range(location.shape[0]): @@ -350,7 +353,7 @@ class GraphCanvas(scene.SceneCanvas): self.data['a_selection'] = G.vertex_properties["selection"].get_array() #self.data['a_graph_size'] = [bbu-bbl] - self.program['u_graph_size'] = [bbu-bbl] + self.program['u_graph_size'] = [self.bbu-self.bbl] self.vbo = gloo.VertexBuffer(self.data) self.gen_line_vbo(G) @@ -363,7 +366,8 @@ class GraphCanvas(scene.SceneCanvas): if(self.subgraphs): #self.program_e_s.bind(self.vbo_s) self.program_s.bind(self.vbo_s) - print(self.view) + if DEBUG: + print(self.view) self.update() """ @@ -720,7 +724,8 @@ class GraphCanvas(scene.SceneCanvas): if(self.subgraphs): #self.program_e_s.bind(self.vbo_s) self.program_s.bind(self.vbo_s) - print(self.view) + if DEBUG: + print(self.view) self.update() @@ -797,11 +802,13 @@ class GraphCanvas(scene.SceneCanvas): for j in range(len(arc_length_vertex)): if j != 0: arc_length_vertex[j] += arc_length_vertex[j-1] - print("arc_length before ", arc_length_vertex, " and sum to ", sum(arc_length_vertex)) + if DEBUG: + print("arc_length before ", arc_length_vertex, " and sum to ", sum(arc_length_vertex)) arc_length_vertex = np.asarray(arc_length_vertex, dtype = np.float32) arc_length_vertex = (np.pi - -np.pi)/(max(arc_length_vertex) - min(arc_length_vertex)) \ * (arc_length_vertex- min(arc_length_vertex)) + (-np.pi) - print(arc_length_vertex) + if DEBUG: + print(arc_length_vertex) #print(arc_length) @@ -821,7 +828,8 @@ class GraphCanvas(scene.SceneCanvas): temp.append(np.sum(g.vertex_properties['degree'].get_array())) G.clear_filters() - print(self.clusters['a_outer_arc_length']) + if DEBUG: + print(self.clusters['a_outer_arc_length']) maximum = max(temp) minimum = min(temp) if len(temp) > 1: @@ -873,7 +881,8 @@ class GraphCanvas(scene.SceneCanvas): self.program.bind(self.vbo) if(self.subgraphs): self.program_s.bind(self.vbo_s) - print(self.view) + if DEBUG: + print(self.view) self.update() """ @@ -881,7 +890,8 @@ class GraphCanvas(scene.SceneCanvas): spectral clustering on the graph passed if the subgraph is set to true. """ def set_data(self, G, bbl, bbu, subgraph=True): - print("Setting data") + if DEBUG: + print("Setting data") self.G = G self.bbl = bbl self.bbu = bbu @@ -942,7 +952,8 @@ class GraphCanvas(scene.SceneCanvas): if(self.subgraphs): #self.program_e_s.bind(self.vbo_s) self.program_s.bind(self.vbo_s) - print(self.view) + if DEBUG: + print(self.view) self.update() """ @@ -1057,7 +1068,7 @@ class GraphCanvas(scene.SceneCanvas): if(self.view[0][0] > 0.0010): c_id = self.get_clicked_id(event) if(c_id != None): - self.original_point = G.vertex_properties["pos"][G.vertex(c_id)] + self.original_point = self.G.vertex_properties["pos"][self.G.vertex(c_id)] self.location = event.pos self.moving = True self.down = True @@ -1067,7 +1078,8 @@ class GraphCanvas(scene.SceneCanvas): #print("Clicked on:", event.pos) else: c_id = self.get_clicked_id(event, True) - print(c_id) + if DEBUG: + print(c_id) if(c_id != None): self.original_point = self.cluster_pos[c_id] self.location = event.pos @@ -1090,10 +1102,10 @@ class GraphCanvas(scene.SceneCanvas): self.update() def add_to_path(self, source, target): - vl, el = nwt.gt.graph_tool.topology.shortest_path(G, G.vertex(source), G.vertex(target), weights=G.edge_properties["av_radius"]) + 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"]) for v in vl: if(int(v) not in self.path): - G.vertex_properties["selection"][v] = 2.0 + self.G.vertex_properties["selection"][v] = 2.0 self.data['a_selection'][int(v)] = 2.0 if(int(v) not in self.full_path): self.full_path.append(int(v)) @@ -1105,7 +1117,7 @@ class GraphCanvas(scene.SceneCanvas): #check whether this is the first node to be selected if(self.pathing == False): #if it is, select that node and turn the pathing variable on. - G.vertex_properties["selection"][G.vertex(c_id)] = 1.0 + self.G.vertex_properties["selection"][self.G.vertex(c_id)] = 1.0 self.pathing = True if(c_id not in self.path): self.path.append(c_id) @@ -1113,14 +1125,14 @@ class GraphCanvas(scene.SceneCanvas): update_vbo(self) print("I turned on the first node") else: - if(G.vertex_properties["selection"][G.vertex(c_id)] == 1.0): - G.vertex_properties["selection"][G.vertex(c_id)] = 0.0 + if(self.G.vertex_properties["selection"][self.G.vertex(c_id)] == 1.0): + self.G.vertex_properties["selection"][self.G.vertex(c_id)] = 0.0 self.path.remove(c_id) self.data['a_selection'][c_id] = 0.0 update_vbo(self) print("I turned off a node") - elif(G.vertex_properties["selection"][G.vertex(c_id)] == 0.0): - G.vertex_properties["selection"][G.vertex(c_id)] = 1.0 + elif(self.G.vertex_properties["selection"][self.G.vertex(c_id)] == 0.0): + self.G.vertex_properties["selection"][self.G.vertex(c_id)] = 1.0 if(c_id not in self.path): self.path.append(c_id) self.data['a_selection'][c_id] = 1.0 @@ -1131,7 +1143,7 @@ class GraphCanvas(scene.SceneCanvas): add_to_path(self, self.path[i], self.path[i+1]) update_vbo(self) #THIS IS WHERE I LEFT IT OFF. - if(np.sum(G.vertex_properties["selection"].get_array()) == 0): + if(np.sum(self.G.vertex_properties["selection"].get_array()) == 0): self.pathing = False @@ -1236,7 +1248,7 @@ class GraphCanvas(scene.SceneCanvas): #Project into GLSpace and get before and after move coordinates coord = self.transforms.get_transform('canvas', 'render').map(self.location)[:2] coord2 = self.transforms.get_transform('canvas', 'render').map(event.pos)[:2] - cur_pos = G.vertex_properties["pos"][G.vertex(self.c_id[0])] + cur_pos = self.G.vertex_properties["pos"][self.G.vertex(self.c_id[0])] #print(cur_pos, " Before") #Adjust the position of the node based on the current view matrix. @@ -1245,13 +1257,13 @@ class GraphCanvas(scene.SceneCanvas): #print(cur_pos, " After") #Upload the changed data. - G.vertex_properties["pos"][G.vertex(self.c_id[0])] = cur_pos + self.G.vertex_properties["pos"][self.G.vertex(self.c_id[0])] = cur_pos self.data['a_position'][self.c_id[0]] = cur_pos #update the edge data by finding all edges connected to the vertex v = self.G.vertex(self.c_id[0]) for e in v.all_edges(): - d = np.subtract(G.vertex_properties["pos"][e.source()], G.vertex_properties["pos"][e.target()]) + d = np.subtract(self.G.vertex_properties["pos"][e.source()], self.G.vertex_properties["pos"][e.target()]) d_norm = d[0:2] d_norm = d_norm / np.sqrt(np.power(d_norm[0],2) + np.power(d_norm[1],2)) norm = np.zeros((2,), dtype=np.float32) @@ -1319,7 +1331,7 @@ class GraphCanvas(scene.SceneCanvas): cur_pos[0] = cur_pos[0] - (coord[0]-coord2[0])/self.view[0][0] cur_pos[1] = cur_pos[1] - (coord[1]-coord2[1])/self.view[0][0] - self.update_cluster_position(G, cur_pos, offset, self.c_id[0]) + self.update_cluster_position(self.G, cur_pos, offset, self.c_id[0]) #self.original_point = cur_pos self.vbo = gloo.VertexBuffer(self.data) self.vbo_line = gloo.VertexBuffer(self.line_data) diff --git a/GraphWidget.py b/GraphWidget.py index 36ceed3..2368e01 100644 --- a/GraphWidget.py +++ b/GraphWidget.py @@ -10,6 +10,7 @@ from GraphCanvas import GraphCanvas from pyqtgraph.Qt import QtCore, QtGui, QtWidgets import network_dep as nwt +DEBUG = False """ Initializes the entire QTlayout and sets the mouse press events. @@ -68,21 +69,24 @@ class GraphWidget(QtGui.QWidget): #EXP_adv = menu.addAction('Export VTK Advanced') NL = menu.addAction('New Layout') action = menu.exec_(event.native.globalPos()) - print(action) + if DEBUG: + print(action) for i in range(len(vertex_actions)): if action == vertex_actions[i]: if vertex_props[i] == "clusters": self.canvas.color_vertices(self.canvas.G, vertex_props[i], dtype=True) else: self.canvas.color_vertices(self.canvas.G, vertex_props[i]) - print(vertex_props[i]) + + if DEBUG: + print(vertex_props[i]) if action == NS: if self.use_3D == False: self.use_3D = True else: self.use_3D = False self.canvas.size_vertices(self.canvas.G, 'degree' ) - self.canvas.color_vertices(self.canvas.G) + self.canvas.color_vertices(self.canvas.G, 'degree') #if action == NC: # self.canvas.color_vertices(self.canvas.G, not self.color) # self.color = not self.color @@ -94,7 +98,8 @@ class GraphWidget(QtGui.QWidget): # nwt.Network.write_vtk(self.canvas.G, "./nwt_points_wise_binned.vtk", camera=self.camera, binning = True) # nwt.Network.write_vtk(self.canvas.G, "./nwt_points_wise_non_binned.vtk", camera=self.camera, binning = False) if action == tmp: - print("Stuff") + if DEBUG: + print("Stuff") #self.cb = QtWidgets.QComboBox() #vertex_props = self.canvas.G.vertex_properties.keys() #for i in range(len(vertex_props)): @@ -171,7 +176,8 @@ class GraphWidget(QtGui.QWidget): self.camera = [x,y,z] self.canvas.vertexSizeFromDistance(self.canvas.G, [x,y,z]) self.canvas.vertexAlphaFromDistance(self.canvas.G, [x,y,z]) - #print("got signal", x, y, z) + if DEBUG: + print("got signal", x, y, z) """ Initialization method that connects the slot to the function that handles diff --git a/GuiVisPy_tube.py b/GuiVisPy_tube.py index 96271d7..36538b7 100644 --- a/GuiVisPy_tube.py +++ b/GuiVisPy_tube.py @@ -25,6 +25,9 @@ from GraphWidget import GraphWidget from TubeWidget import TubeWidget +DEBUG = False + + #set the backend. for different versions of PyQt app.use_app(backend_name='PyQt5') @@ -93,7 +96,9 @@ G, bbl, bbu = load_nwt("/home/pavel/Documents/Python/GraphGuiQt/network_4.nwt") #ret = nwt.Network.get_affinity_matrix(G, "length") node_image = QtGui.QImage("/home/pavel/Documents/Python/GraphGuiQt/node_tex.jpg") node_tex = QtGui.QBitmap.fromImage(node_image) -print(node_tex.depth()) + +if DEBUG: + print(node_tex.depth()) center = (bbu-bbl)/2.0 #fibers.opts['distance'] = 5 # item = NodeItem(G) diff --git a/TubeCanvas.py b/TubeCanvas.py index 96c476c..2f17f64 100644 --- a/TubeCanvas.py +++ b/TubeCanvas.py @@ -23,6 +23,12 @@ import network_dep as nwt from tube_shaders import FRAG_SHADER, VERT_SHADER +from mpl_toolkits.mplot3d import Axes3D +import matplotlib +import matplotlib.pyplot as plt + +DEBUG = False + class TubeDraw(scene.SceneCanvas): #sigUpdate = QtCore.pyqtSignal(float, float, float) @@ -105,7 +111,8 @@ class TubeDraw(scene.SceneCanvas): for j in range(3): self.bb[i,j] = bb[i][j] self.program['u_bb'] = self.bb - print('bb is ', self.bb) + if DEBUG: + print('bb is ', self.bb) # for i in range(len(self.translate)): # self.camera[i] += self.translate[i] @@ -127,7 +134,8 @@ class TubeDraw(scene.SceneCanvas): def on_resize(self, event): width, height = event.physical_size gloo.set_viewport(0, 0, width, height) - print(self.physical_size) + if DEBUG: + print(self.physical_size) #overloaded function called during the self.update() call to update the current #frame using the GLSL frag/vert shaders @@ -294,32 +302,32 @@ class TubeDraw(scene.SceneCanvas): #Add the caps for each of the endpoints. - - if(i == 2): - fig = plt.figure() - ax = fig.add_subplot(111, projection='3d') - #ax.scatter(circle_pts[:,:,0], circle_pts[:,:,1], circle_pts[:,:,2]) - ax.plot(pts[:,0], pts[:,1], pts[:,2]) - for j in range(pts.shape[0]): - ax.plot(circle_pts[j,:,0], circle_pts[j,:,1], circle_pts[j,:,2]) - for j in range(triangles.shape[0]): - tri = np.zeros((3,4)) - tri[:,0] = self.cylinder_data['a_position'][triangles[j][0]] - tri[:,1] = self.cylinder_data['a_position'][triangles[j][1]] - tri[:,2] = self.cylinder_data['a_position'][triangles[j][2]] - tri[:,3] = self.cylinder_data['a_position'][triangles[j][0]] - ax.plot(tri[0,:], tri[1,:], tri[2,:], c='b') - for j in range(triangles.shape[0]): - tri = np.zeros((3,3)) - tri[:,0] = self.cylinder_data['a_position'][triangles[j][0]] - tri[:,1] = self.cylinder_data['a_position'][triangles[j][1]] - tri[:,2] = self.cylinder_data['a_position'][triangles[j][2]] - norm = np.zeros((3,3)) - norm[:,0] = self.cylinder_data['a_normal'][triangles[j][0]] - norm[:,1] = self.cylinder_data['a_normal'][triangles[j][1]] - norm[:,2] = self.cylinder_data['a_normal'][triangles[j][2]] - ax.quiver(tri[0,:], tri[1,:], tri[2,:], norm[0,:], norm[1,:], norm[2,:], colors = 'r') - plt.show() + if DEBUG: + if(i == 2): + fig = plt.figure() + ax = fig.add_subplot(111, projection='3d') + #ax.scatter(circle_pts[:,:,0], circle_pts[:,:,1], circle_pts[:,:,2]) + ax.plot(pts[:,0], pts[:,1], pts[:,2]) + for j in range(pts.shape[0]): + ax.plot(circle_pts[j,:,0], circle_pts[j,:,1], circle_pts[j,:,2]) + for j in range(triangles.shape[0]): + tri = np.zeros((3,4)) + tri[:,0] = self.cylinder_data['a_position'][triangles[j][0]] + tri[:,1] = self.cylinder_data['a_position'][triangles[j][1]] + tri[:,2] = self.cylinder_data['a_position'][triangles[j][2]] + tri[:,3] = self.cylinder_data['a_position'][triangles[j][0]] + ax.plot(tri[0,:], tri[1,:], tri[2,:], c='b') + for j in range(triangles.shape[0]): + tri = np.zeros((3,3)) + tri[:,0] = self.cylinder_data['a_position'][triangles[j][0]] + tri[:,1] = self.cylinder_data['a_position'][triangles[j][1]] + tri[:,2] = self.cylinder_data['a_position'][triangles[j][2]] + norm = np.zeros((3,3)) + norm[:,0] = self.cylinder_data['a_normal'][triangles[j][0]] + norm[:,1] = self.cylinder_data['a_normal'][triangles[j][1]] + norm[:,2] = self.cylinder_data['a_normal'][triangles[j][2]] + ax.quiver(tri[0,:], tri[1,:], tri[2,:], norm[0,:], norm[1,:], norm[2,:], colors = 'r') + plt.show() i+=1 #create the data. @@ -387,7 +395,8 @@ class TubeDraw(scene.SceneCanvas): theta = (coord[0]-coord2[0])*360.0/2.0/np.pi phi = (coord[1]-coord2[1])*360.0/2.0/np.pi - print(theta*360.0/2.0/np.pi, -phi*360.0/2.0/np.pi) + if DEBUG: + print(theta*360.0/2.0/np.pi, -phi*360.0/2.0/np.pi) self.camera = self.camera - self.translate q1 = Quaternion.create_from_axis_angle(angle=phi, ax=0.0, ay=1.0, az=0.0, degrees=True) 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): #self.camera[0] = self.camera[0] + self.center[0] #self.camera[1] = self.camera[1] + self.center[1] #self.camera[2] = self.camera[2] - self.center[2] - print("current position ", self.camera, " and up vector ", self.up) + if DEBUG: + print("current position ", self.camera, " and up vector ", self.up) self.program['u_eye'] = self.camera self.program['u_up'] = self.up self.program['u_LightPos'] = [self.camera[0], self.camera[1], self.camera[2]] diff --git a/TubeWidget.py b/TubeWidget.py index 2747819..01a1c38 100644 --- a/TubeWidget.py +++ b/TubeWidget.py @@ -14,6 +14,8 @@ Created on Mon Aug 5 15:53:16 2019 from pyqtgraph.Qt import QtCore, QtGui, QtWidgets from TubeCanvas import TubeDraw +DEBUG = False + class TubeWidget(QtGui.QWidget): sigUpdate = QtCore.pyqtSignal(float, float, float) #Initializes the QT wrapper class. @@ -60,6 +62,7 @@ class TubeWidget(QtGui.QWidget): #self.view = self.canvas.view self.camera = self.canvas.camera #print("stuff", self.view[3, 0], self.view[3, 1], self.view[3, 2]) - print("stuff", self.camera[0], self.camera[1], self.camera[2]) + if DEBUG: + print("stuff", self.camera[0], self.camera[1], self.camera[2]) self.sigUpdate.emit(self.camera[0], self.camera[1], self.camera[2]) diff --git a/network_dep.py b/network_dep.py index 4e43b88..b6d22e3 100755 --- a/network_dep.py +++ b/network_dep.py @@ -27,6 +27,8 @@ import copy #import matplotlib.pyplot as plt #from matplotlib import cm +DEBUG = False + ''' Definition of the Node class Duplicate of the node class in network @@ -81,9 +83,9 @@ class Fiber: for i in range(len(self.points)-1): 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)) if(length == 0): - print(self.points) - print(len(self.points)) - print(self.v0, " ", self.v1) + print("NON-CRITICAL ERROR: edge with length 0 is detected: IDX = "\ + , i, ", points = ", self.points, " len(points) = ", len(self.points)\ + , " vertices = ", self.v0, " ", self.v1) return length ''' @@ -396,12 +398,12 @@ class AABB(): vertices = list(np.unique(np.array(vertices), axis=0)) - import matplotlib.pyplot as plt - fig = plt.figure() - ax = plt.axes(projection='3d') - ax.scatter3D(np.array(vertices)[:, 0], np.array(vertices)[:, 1], np.array(vertices)[:, 2]) + #import matplotlib.pyplot as plt + #fig = plt.figure() + #ax = plt.axes(projection='3d') + #ax.scatter3D(np.array(vertices)[:, 0], np.array(vertices)[:, 1], np.array(vertices)[:, 2]) - print("THERE ARE THIS MANY ", len(vertices)) + #print("THERE ARE THIS MANY ", len(vertices)) return vertices def getVolume(self): @@ -417,42 +419,49 @@ class AABB(): temp = copy.deepcopy(self.A) temp[0] = temp[0] + size[0] points.append(temp) - print('1', temp) + if DEBUG: + print('1', temp) temp = copy.deepcopy(self.A) temp[1] = temp[1] + size[1] points.append(temp) - print('1', temp) + if DEBUG: + print('1', temp) temp = copy.deepcopy(self.A) temp[2] = temp[2] + size[2] points.append(temp) - print('1', temp) + if DEBUG: + print('1', temp) temp = copy.deepcopy(self.A) temp[1] = temp[1] + size[1] temp[0] = temp[0] + size[0] points.append(temp) - print('1', temp) + if DEBUG: + print('1', temp) temp = copy.deepcopy(self.A) temp[2] = temp[2] + size[2] temp[0] = temp[0] + size[0] points.append(temp) - print('1', temp) + if DEBUG: + print('1', temp) temp = copy.deepcopy(self.A) temp[1] = temp[1] + size[1] temp[2] = temp[2] + size[2] points.append(temp) - print('1', temp) + if DEBUG: + print('1', temp) temp = copy.deepcopy(self.A) temp[0] = temp[0] + size[0] temp[1] = temp[1] + size[1] temp[2] = temp[2] + size[2] points.append(temp) - print('1', temp) + if DEBUG: + print('1', temp) return points @@ -908,7 +917,8 @@ class Network: def simulate_fractures(self, G, remove=10): num_removed = int(np.floor(G.num_edges()*remove/100)) - print("num of edges to begin with = ", G.num_edges()) + if DEBUG: + print("num of edges to begin with = ", G.num_edges()) indices = np.random.randint(0, int(G.num_edges()), size = [num_removed,1]) #aabb = AABB(G, is_dual) tf = np.full((G.num_edges(), 1), True, dtype=bool) @@ -921,9 +931,10 @@ class Network: G1.clear_filters() G1 = self.filterDisconnected(G1) G1.vertex_properties["degree"] = G1.degree_property_map("total") - print("num of edges left = ", G1.num_edges()) - print("I should have removed, ", num_removed) - print("Instead I removed, ", G.num_edges() - G1.num_edges()) + if DEBUG: + print("num of edges left = ", G1.num_edges()) + print("I should have removed, ", num_removed) + print("Instead I removed, ", G.num_edges() - G1.num_edges()) return G1 @@ -992,7 +1003,8 @@ class Network: G.edge_properties["mst"] = gt.graph_tool.topology.min_spanning_tree(G, weights=G.edge_properties["length"]) G.graph_properties["mst_ratio"] = np.double(np.sum(G.edge_properties["mst"].get_array()))/np.double(G.num_edges()) - print(np.double(np.sum(G.edge_properties["mst"].get_array()))/np.double(G.num_edges())) + if DEBUG: + print(np.double(np.sum(G.edge_properties["mst"].get_array()))/np.double(G.num_edges())) G.vertex_properties["degree"] = G.degree_property_map("total") G.vertex_properties["degree_volume"] = G.degree_property_map("total", weight=G.edge_properties["volume"]) G.vertex_properties["degree_tortuosity"] = G.degree_property_map("total", G.edge_properties["tortuosity"]) @@ -1065,9 +1077,11 @@ class Network: G1 = self.filterBorder(G, is_dual=dual); if(erode == True): while(np.any(G1.degree_property_map("total").get_array() == True)): - print(G1.num_vertices()) + if DEBUG: + print(G1.num_vertices()) G1 = self.filterBorder(G1, is_dual=dual) - print(G1.num_vertices()) + if DEBUG: + print(G1.num_vertices()) G1 = self.recalculate_metrics(G1, is_dual=dual, ) else: G1 = self.recalculate_metrics(G1, is_dual=dual) @@ -1331,7 +1345,7 @@ class Network: r_edge[G.edge(v0,v1)] = r av_edge[G.edge(v0,v1)] = self.F[i].av_radius() else: - print("WTF") + print("NON-CRITICAL ERROR: edge with length 0 detected--SKIPPED") #generate centrality map @@ -1574,7 +1588,8 @@ class Network: #This is when the property map is integers #int32_t when integer value_type = propertymap.value_type() - print(value_type) + if DEBUG: + print(value_type) if(value_type == "int32_t"): array = propertymap.get_array() colors = cm.get_cmap(colormap, len(np.unique(array))) @@ -1589,7 +1604,8 @@ class Network: colors = cm.ScalarMappable(norm=norm, cmap=colormap) if key_type =='v': for v in G.vertices(): - print(colors.to_rgba(propertymap[v])) + if DEBUG: + print(colors.to_rgba(propertymap[v])) G.vertex_properties["RGBA"][v] = colors.to_rgba(propertymap[v]) return G.vertex_properties["RGBA"] elif(value_type == 'vector' or value_type == 'vector'): @@ -1628,6 +1644,7 @@ class Network: if d < dist: idx = M dist = d + #if DEBUG: print(idx, " vertex[",p[0][idx], p[1][idx], p[2][idx], "], point [", x[i], y[j], z[k], "]") clusters = G.new_vertex_property("int", vals=np.full((G.num_vertices(), 1), -1, dtype=int)) #eclusters = G.new_edge_property("int", vals=np.full((G.num_edges(), 1), -1, dtype=int)) @@ -1741,10 +1758,12 @@ class Network: eclusters = G1.new_edge_property("int", vals = np.full((G1.num_edges(), 1), 3, dtype=int)) G1.vertex_properties["cycle"] = clusters G1.edge_properties["cycle"] = eclusters - print("Number of vertices in Path is:", len(Vl)) + if DEBUG: + print("Number of vertices in Path is:", len(Vl)) for v in Vl: G1.vertex_properties["cycle"][G1.vertex(v)] = 10 - print(str(v)) + if DEBUG: + print(str(v)) #Create the arrays to be histogrammed later regarding every loop length_total = 0 volume_total = 0 @@ -1815,10 +1834,10 @@ class Network: n_components = G1.num_vertices() eigenvalues, eigenvectors = eigsh(L, k=n_components, which = "LM", sigma=1.0, maxiter = 5000) - plt.figure() - plt.scatter(np.arange(len(eigenvalues)), eigenvalues) - plt.grid() - plt.show() + #plt.figure() + #plt.scatter(np.arange(len(eigenvalues)), eigenvalues) + #plt.grid() + #plt.show() count = sum(eigenvalues > 1.01) return count @@ -1915,8 +1934,9 @@ class Network: if binning: index = np.digitize(G.edge_properties["RGBA"][e][3], bins, right=True) if (index >= len(bins) or index < 0): - print(G.edge_properties["RGBA"][e][3]) - print(index) + if DEBUG: + print(G.edge_properties["RGBA"][e][3]) + print(index) f.write("%.15f\n" % bins[index]) else: f.write("%.15f\n" % G.edge_properties["RGBA"][e][3]) @@ -2036,7 +2056,7 @@ class Network: #generate a KD-Tree out of the network point array tree = sp.spatial.cKDTree(P) - plt.scatter(P[:, 0], P[:, 1]) + #plt.scatter(P[:, 0], P[:, 1]) #specify the resolution of the ouput grid R = (200, 200, 200) -- libgit2 0.21.4