def get_valid_nodes(triangles: Triangulation) -> np.ndarray: """Get nodes in the mesh wish are valid (not masked). :param triangles: The triangulated mesh :return: List of node ids outside of mask """ return np.unique(triangles.get_masked_triangles()).reshape(-1,)
def reload(self, imageName): #Let's create a canvas self.w.pack() self.w.delete("all") #Let's create an image image = Image.open(imageName) pixels = image.load() width, height = image.size #Just a testing data structure. Don't use this. all_pixels = [] #Use this one when doing calculations. points = [] xarray = [] yarray = [] color = ["red", "orange", "yellow", "green", "blue", "violet"] #loop(self, points, pixels, all_pixels, width, height) for x in range(width): for y in range(height): cpixel = pixels[x, y] foo = random.randint(1, 7) if (round(sum(cpixel)) / float(len(cpixel)) > 127) & (x%foo == 0) & (y%foo == 0): all_pixels.append(255) points.append(Point(x*2, y*2)) xarray.append(x*2) yarray.append(1000 - y*2) #self.w.create_oval(x*2, y*2, x*2+1, y*2+1, fill="black") else: all_pixels.append(0) triangulation = Triangulation(xarray, yarray) triangles = triangulation.get_masked_triangles() polygons = [] for triangle in triangles: self.w.create_polygon([xarray[triangle[0]], 1000 - yarray[triangle[0]]], [xarray[triangle[1]], 1000 - yarray[triangle[1]]], [xarray[triangle[2]], 1000 - yarray[triangle[2]]], fill=random.choice(color))
def reload(self, imageName, seed, scale): try: #Let's create a canvas #voronoiCircles = [] self.w.pack() self.w.delete("all") #Let's create an image image = Image.open(imageName) colors = [] pixels = image.load() width, height = image.size #print(width) #Just a testing data structure. Don't use this. all_pixels = [] #Use this one when doing calculations. points = [] xarray = [] yarray = [] color = ["red", "orange", "yellow", "green", "blue", "violet"] #loop(self, points, pixels, all_pixels, width, height) for x in range(width): for y in range(height): cpixel = pixels[x, y] #colors.append(cpixel) #print(cpixel) foo = random.randint(1, seed) #if (round(sum(cpixel)) / float(len(cpixel)) > 127) & (x%foo == 0) & (y%foo == 0): if ( x%foo == 0) and (y%foo == 0): all_pixels.append(255) points.append(Point(x*scale, y*scale)) xarray.append(x*scale) yarray.append(y*scale) colors.append(cpixel) #self.w.create_oval(x*2, y*2, x*2+1, y*2+1, fill="black") #else: # all_pixels.append(0) #print(all_pixels) triangulation = Triangulation(xarray, yarray) triangles = triangulation.get_masked_triangles() #triangles = triangulation.triangles() #print(triangles) for triangle in triangles: x1 = xarray[triangle[0]] y1 = yarray[triangle[0]] x2 = xarray[triangle[1]] y2 = yarray[triangle[1]] x3 = xarray[triangle[2]] y3 = yarray[triangle[2]] #print(circumcircle(circle)) #red= colors[triangle[0]][0] try: red=colors[triangle[0]][0] green= colors[triangle[0]][1] blue= colors[triangle[0]][2] mycolor = '#%02x%02x%02x' % (red, green, blue) except IndexError: if colors[triangle[0]][1] > 100: mycolor='black' else: mycolor='white' self.w.create_polygon([x1, y1], [x2, y2], [x3, y3], fill=mycolor) center = circumcenter([x1, y1], [x2, y2], [x3, y3]) bisector1 = [[(x1+x2)/2], [(y1+y2)/2]] bisector2 = [[(x2+x3)/2], [(y2+y3)/2]] bisector3 = [[(x3+x1)/2], [(y3+y1)/2]] self.w.create_line(center[0], center[1], bisector1[0], bisector1[1]) self.w.create_line(center[0], center[1], bisector2[0], bisector2[1]) self.w.create_line(center[0], center[1], bisector3[0], bisector3[1]) #self.w.create_oval(center[0]-1, center[1]-1, center[0]+1, center[1]+1, fill="black") #create_circle(self.w, center[0], center[1], center[2]) #voronoiCircles.append(center) except (AttributeError, IOError, FileNotFoundError): pass """
def triangulate(x, y): tri = Triangulation(x, y) return tri.get_masked_triangles()
if bn <= 0.1: #num[-1][-1]=num[-1][-1]+1 num[-1] = num[-1] + 1 k = k + 1 j = j + 1 i = i + 1 #print(num) s = np.linspace(0, 2 * np.pi, 37) for ang in s: #l = Line2D([np.cos(ang), 1.02*np.cos(ang)], [np.sin(ang), 1.02*np.sin(ang)]) #ax.add_line(l) if 0 == np.cos(ang) or 0 == np.sin(ang): continue x0.append(np.cos(ang)) y0.append(np.sin(ang)) num.append(0) while k < len(x): bn = np.sqrt((0.1 * i - x[k])**2 + (0.1 * j - y[k])**2) if bn <= 0.1: #num[-1][-1]=num[-1][-1]+1 num[-1] = num[-1] + 1 tri = Triangulation(x0, y0) atri = tri.get_masked_triangles() #绘图 levels = np.arange(0., 110., 5) #plt.triplot(tri) a = sub.tricontourf(tri, num, levels=levels) fig.colorbar(a, shrink=0.7) show()