diff --git a/callbacks/_imageProcessing.py b/callbacks/_imageProcessing.py index a4e55d5..6269ff5 100644 --- a/callbacks/_imageProcessing.py +++ b/callbacks/_imageProcessing.py @@ -233,7 +233,6 @@ def resetCrop(self, sender = None, app_data = None): if self.blocks[Blocks.importImage.value]['output'] is None: dpg.configure_item('noImage', show=True) - dpg.set_value('cropCheckbox', False) self.blocks[Blocks.crop.value]['status'] = False return diff --git a/callbacks/_mesh.py b/callbacks/_mesh.py index 90d5ffe..e2b74ee 100644 --- a/callbacks/_mesh.py +++ b/callbacks/_mesh.py @@ -63,7 +63,31 @@ def getMesh(x, y, xmin, ymin, dx, dy): if point[0] != prevpoint[0] or point[1] != prevpoint[1]: xResult.append(point[0]) yResult.append(point[1]) - + + xAux = xResult + yAux = yResult + xResult = [xAux[0]] + yResult = [yAux[0]] + for i in range(1, len(xAux)): + while True: + offsetX = 0 + offsetY = 0 + if xAux[i] - xResult[-1] > dx: + offsetX = dx + elif xResult[-1] - xAux[i] > dx: + offsetX = - dx + if yAux[i] - yResult[-1] > dy: + offsetY = dy + elif yResult[-1] - yAux[i] > dy: + offsetY = - dy + if offsetX != 0 or offsetY != 0: + xResult.append(xResult[-1] + offsetX) + yResult.append(yResult[-1] + offsetY) + else: + break + xResult.append(xAux[i]) + yResult.append(yAux[i]) + aux = max(xResult) if aux != xmax: xmax = aux diff --git a/callbacks/_meshGeneration.py b/callbacks/_meshGeneration.py index 487f9e1..e5a02be 100644 --- a/callbacks/_meshGeneration.py +++ b/callbacks/_meshGeneration.py @@ -82,15 +82,18 @@ def importContour(self, sender = None, app_data = None): dpg.set_value("original_ny", 'ny: ' + str(int(ny))) dpg.set_value("nx", 'nx: ' + str(int(nx))) dpg.set_value("ny", 'ny: ' + str(int(ny))) - dpg.configure_item("dx", default_value = dx, min_value = dx) - dpg.configure_item("dy", default_value = dy, min_value = dy) + dpg.configure_item("dx", default_value = dx) + dpg.configure_item("dy", default_value = dy) dpg.configure_item("xi", default_value = xmin) dpg.configure_item("yi", default_value = ymin) dpg.configure_item("xi_zoom", default_value = xmin, min_value = xmin) dpg.configure_item("yi_zoom", default_value = ymin, min_value = ymin) dpg.configure_item("xf_zoom", default_value = xmin + dx, min_value = xmin + dx, max_value = xmax) dpg.configure_item("yf_zoom", default_value = ymin + dy, min_value = ymin + dy, max_value = ymax) - dpg.configure_item("exportMesh", enabled=True) + dpg.configure_item("exportMesh", show=True) + dpg.configure_item("exportMeshText", show=True) + dpg.configure_item("exportMeshTooltip", show=True) + dpg.add_separator(parent="meshGeneration") self.currentX = self.currentX[4:] self.currentY = self.currentY[4:] @@ -248,7 +251,7 @@ def updateMesh(self, sender=None, app_data=None): aux = dpg.get_value("original_area") originalArea = float(aux[15:]) dif = abs(originalArea - area) - dpg.set_value("difference", "Difference: " + str(dif) + " ({:.2f}%)".format(100*dif/originalArea)) + dpg.set_value("difference", "Difference: " + str(dif) + " ({:.2f}%)".format(abs(100*dif/originalArea))) dpg.set_value("contour_nodes_number", "Contour Nodes Number: " + str(len(self.currentX))) dpg.delete_item("meshPlot") diff --git a/callbacks/_sparseMesh.py b/callbacks/_sparseMesh.py index 4e10a13..f3cde2e 100644 --- a/callbacks/_sparseMesh.py +++ b/callbacks/_sparseMesh.py @@ -80,10 +80,10 @@ def updateRanges(self, dxAux, dyAux, xmin, ymin): r["xi"] = xmin r["yi"] = ymin else: - nx = originaldx//r["dx"] - r["dx"] = dxAux/nx - ny = originaldy//r["dy"] - r["dy"] = dyAux/ny + auxX = originaldx//r["dx"] + r["dx"] = dxAux/auxX + auxY = originaldy//r["dy"] + r["dy"] = dyAux/auxY if xmin > r["xi"]: r["xi"] = xmin elif xmin < r["xi"]: @@ -98,16 +98,19 @@ def updateRanges(self, dxAux, dyAux, xmin, ymin): xmax = r["xf"] ymax = r["yf"] - nx = round((xmax - xminAux)/r["dx"]) + 1 - ny = round((ymax - yminAux)/r["dy"]) + 1 if (xmax - xminAux)/r["dx"] != (xmax - xminAux)//r["dx"]: - r["xf"] = xminAux + nx * r["dx"] - nx += 1 + nx = (xmax - xminAux)//self.ranges[0]["dx"] + if i == 0: + nx += 1 + r["xf"] = xminAux + nx * self.ranges[0]["dx"] if (ymax - yminAux)/r["dy"] != (ymax - yminAux)//r["dy"]: - r["yf"] = yminAux + ny * r["dy"] - ny += 1 - r["nx"] = nx - r["ny"] = ny + ny = (ymax - yminAux)//self.ranges[0]["dy"] + if i == 0: + ny += 1 + r["yf"] = yminAux + ny * self.ranges[0]["dy"] + + r["nx"] = round((r["xf"] - xminAux)/r["dx"]) + 1 + r["ny"] = round((r["yf"] - yminAux)/r["dy"]) + 1 self.ranges[i] = r @@ -143,7 +146,11 @@ def setIntervals(self): self.dy.sort() - + def getIndex(item, itens): + for i in range(len(itens)): + if item == itens[i]: + return i + return None """ Retorna o valor de x da coordenada do nó da malha onde o ponto informado está @@ -229,6 +236,35 @@ def get_adaptative_mesh(self, x, y): if point[0] != prevpoint[0] or point[1] != prevpoint[1]: xResult.append(point[0]) yResult.append(point[1]) + + xAux = xResult + yAux = yResult + xResult = [xAux[0]] + yResult = [yAux[0]] + xIndex = SparseMesh.getIndex(xResult[0], self.dx) + yIndex = SparseMesh.getIndex(yResult[0], self.dy) + for i in range(1, len(xAux)): + while True: + dxAux = xResult[-1] + dyAux = yResult[-1] + if xAux[i] - xResult[-1] > 0: + xIndex += 1 + dxAux = self.dx[xIndex] + elif xResult[-1] - xAux[i] > 0: + xIndex -= 1 + dxAux = self.dx[xIndex] + if yAux[i] - yResult[-1] > 0: + yIndex += 1 + dyAux = self.dy[yIndex] + elif yResult[-1] - yAux[i] > 0: + yIndex -= 1 + dyAux = self.dy[yIndex] + if dxAux != xResult[-1] or dyAux != yResult[-1]: + xResult.append(dxAux) + yResult.append(dyAux) + else: + break + return xResult, yResult """ @@ -237,21 +273,32 @@ def get_adaptative_mesh(self, x, y): def getNode(self, xpoint, ypoint): - auxX = xpoint - auxY = ypoint - flag = 0 + + flag = False for r in self.ranges[::-1]: if r["xi"] <= xpoint <= r["xf"] and r["yi"] <= ypoint <= r["yf"]: auxX = (xpoint - r["xi"]) // r["dx"] * r["dx"] + r["xi"] auxY = (ypoint - r["yi"]) // r["dy"] * r["dy"] + r["yi"] - flag = 1 + flag = True break if flag: return[auxX, auxY] - print([auxX, auxY]) + print("A figura é maior que os limites da malha") quit(1) + def getNodeSize(self, xpoint, ypoint): + dxAux = self.ranges[0]["dx"] + dyAux = self.ranges[0]["dy"] + + for r in self.ranges[:0:-1]: + if r["xi"] <= xpoint < r["xf"] and r["yi"] <= ypoint < r["yf"]: + dxAux = r["dx"] + dyAux = r["dy"] + break + + return dxAux, dyAux + """ Percore x e y, obtendo os nós da malha irregular para cada ponto com a função getNode, e removendo nós irrelevantes. @@ -307,6 +354,32 @@ def get_sparse_mesh(self, x, y): if point[0] != prevpoint[0] or point[1] != prevpoint[1]: xResult.append(point[0]) yResult.append(point[1]) + + xAux = xResult + yAux = yResult + xResult = [xAux[0]] + yResult = [yAux[0]] + for i in range(1, len(xAux)): + dxAux, dyAux = self.getNodeSize(xResult[-1], yResult[-1]) + while True: + offsetX = 0 + offsetY = 0 + if xAux[i] - xResult[-1] > dxAux: + offsetX = dxAux + elif xResult[-1] - xAux[i] > dxAux: + offsetX = - dxAux + if yAux[i] - yResult[-1] > dyAux: + offsetY = dyAux + elif yResult[-1] - yAux[i] > dyAux: + offsetY = - dyAux + if offsetX != 0 or offsetY != 0: + xResult.append(xResult[-1] + offsetX) + yResult.append(yResult[-1] + offsetY) + else: + break + xResult.append(xAux[i]) + yResult.append(yAux[i]) + return xResult, yResult diff --git a/interface/_meshTab.py b/interface/_meshTab.py index a2d118b..ab1a76c 100644 --- a/interface/_meshTab.py +++ b/interface/_meshTab.py @@ -52,10 +52,10 @@ def showMeshGeneration(callbacks): dpg.add_text('Node Size') with dpg.group(horizontal=True): dpg.add_text('dx:') - dpg.add_input_float(tag='dx', default_value=1, min_value=1, min_clamped=True) + dpg.add_input_float(tag='dx', default_value=1, min_value=0.000001, min_clamped=True) with dpg.group(horizontal=True): dpg.add_text('dy:') - dpg.add_input_float(tag='dy', default_value=1, min_value=1, min_clamped=True) + dpg.add_input_float(tag='dy', default_value=1, min_value=0.000001, min_clamped=True) dpg.add_text('Original Mesh Start:') dpg.add_text('x: --', tag='original_xi') @@ -78,10 +78,9 @@ def showMeshGeneration(callbacks): dpg.add_text("Click to remove all zoom regions.") dpg.add_separator() - - dpg.add_text("Save Mesh") - dpg.add_button(tag='exportMesh', enabled=False, label='Export Mesh', callback=lambda: dpg.configure_item("exportMeshFile", show=True)) - with dpg.tooltip("exportMesh"): + dpg.add_text("Save Mesh", tag="exportMeshText", show=False) + dpg.add_button(tag='exportMesh', show=False, label='Export Mesh', callback=lambda: dpg.configure_item("exportMeshFile", show=True)) + with dpg.tooltip("exportMesh", tag="exportMeshTooltip", show=False): dpg.add_text("Click to save mesh data in text files.") with dpg.window(label='Add Mesh Zoom Region', modal=True, show=False, tag="sparsePopup", min_size=[400,420]):