def writeNormalsToText(globaldata, configData): with open("file.dat", "w+") as text_file: for idx,_ in enumerate(globaldata): if idx > 0: flag = core.getFlag(idx,globaldata) if(flag == 0 or flag == 2): x,y = core.getPoint(idx,globaldata) nx,ny = core.normalCalculation(idx,globaldata,True, configData) text_file.write("{} {} {} {}\n".format(x, y, nx, ny))
def createAdaptedFull(globaldata): for idx,_ in enumerate(globaldata): if idx > 0: flag = core.getFlag(idx,globaldata) if(flag == 0 or flag == 1): x,y = core.getPoint(idx,globaldata) with open("adapted.txt", "a") as text_file: text_file.writelines(str(x) + " " + str(y) + " \n") with open("adapted.txt", "a") as text_file: text_file.writelines("1000 1000\n")
def writeConditionValuesForWall(globaldata, configData): for idx,itm in enumerate(globaldata): if idx > 0: flag = core.getFlag(idx,globaldata) if(flag == 0): x,y = core.getPoint(idx,globaldata) xpos = core.conditionNumberOfXPos(idx,globaldata, configData) xneg = core.conditionNumberOfXNeg(idx,globaldata, configData) xposcount = len(core.getXPosPoints(idx,globaldata, configData)) xnegcount = len(core.getXNegPoints(idx,globaldata, configData)) if(xpos > 100 or xneg > 100 or xposcount < 3 or xnegcount < 3): with open("condition.dat", "a") as text_file: text_file.writelines(str(x) + " " + str(y) + " " + str(xposcount) + " " + str(xpos) + " " + str(xnegcount) + " " + str(xneg)) text_file.writelines("\n")
def writeNormalsAllCustom(globaldata, configData): with open("file.dat", "w+") as text_file: for idx,_ in enumerate(globaldata): if idx > 0: flag = core.getFlag(idx,globaldata) if flag == 0: x,y = core.getPoint(idx,globaldata) nx,ny = core.normalCalculation(idx,globaldata,True, configData) text_file.write("{} {} {} {}\n".format(x, y, nx, ny)) elif flag == 1: x,y = core.getPoint(idx,globaldata) nx, ny = core.getNormals(idx, globaldata, configData) if nx != 0 and ny != 1: text_file.write("{} {} {} {}\n".format(x, y, nx, ny))
def triangleBalance3(globaldata, wallpoints, configData, badPoints, hashtable=None): WALL_THRESHOLD = int( configData["triangulate"]["leftright"]["wallThreshold"]) AGGRESSIVE_MAX_NEIGHBOURS = -int( configData["triangulate"]["leftright"]["aggressiveMaxNeighbours"]) previousType = 0 for _, idx in enumerate(tqdm(badPoints)): if idx > 0: flag = int(core.getFlag(idx, globaldata)) xposf, xnegf, _, _ = core.getFlags(idx, globaldata) ## Wall Points if flag == 0: previousType = 0 if xposf == 1 or xposf == 2: nbhs = core.convertIndexToPoints( core.getNeighbours(idx, globaldata), globaldata) # if idx not in core.getWallEndPoints(globaldata): if True: nbhs = nbhs + core.getLeftandRightPoint( idx, globaldata) nbhs = list(set(nbhs)) globaldata = fixWallXPosGeneral(idx, globaldata, nbhs, AGGRESSIVE_MAX_NEIGHBOURS, WALL_THRESHOLD, True, wallpoints, configData, hashtable) if xnegf == 1 or xnegf == 2: nbhs = core.convertIndexToPoints( core.getNeighbours(idx, globaldata), globaldata) # if idx not in core.getWallEndPoints(globaldata): if True: nbhs = nbhs + core.getLeftandRightPoint( idx, globaldata) nbhs = list(set(nbhs)) globaldata = fixWallXNegGeneral(idx, globaldata, nbhs, AGGRESSIVE_MAX_NEIGHBOURS, WALL_THRESHOLD, True, wallpoints, configData, hashtable) elif previousType == 0: break return globaldata
def main(): # Command Line Arguments parser = argparse.ArgumentParser() parser.add_argument("-i", "--input", const=str, nargs="?") args = parser.parse_args() print("Loading Data") file1 = open(args.input or "preprocessorfile.txt", "r") data = file1.read() globaldata = ["start"] splitdata = data.split("\n") splitdata = splitdata[:-1] print("Processed Pre-Processor File") print("Converting to readable format") for idx, itm in enumerate(splitdata): printProgressBar(idx, len(splitdata) - 1, prefix="Progress:", suffix="Complete", length=50) itm = itm.split(" ") itm.pop(-1) entry = itm globaldata.append(entry) globaldata = core.cleanNeighbours(globaldata) stuff = [] for idx, _ in enumerate(globaldata): if idx > 0: flag = core.getFlag(idx, globaldata) if flag == 2: ptx, pty = core.getPoint(idx, globaldata) stuff.append([ptx, pty]) with open("outer.txt", "w") as text_file: for item1 in stuff: text_file.writelines(["%s " % item for item in item1]) text_file.writelines("\n")
def main(): # Command Line Arguments parser = argparse.ArgumentParser() parser.add_argument("-i", "--input", const=str, nargs="?") args = parser.parse_args() print("Loading Data") file1 = open(args.input or "preprocessorfile.txt", "r") data = file1.read() globaldata = ["start"] splitdata = data.split("\n") splitdata = splitdata[:-1] print("Processed Pre-Processor File") print("Converting to readable format") for idx, itm in enumerate(splitdata): printProgressBar(idx, len(splitdata) - 1, prefix="Progress:", suffix="Complete", length=50) itm = itm.split(" ") itm.pop(-1) entry = itm globaldata.append(entry) globaldata = core.cleanNeighbours(globaldata) wallpoints = core.getWallPointArray(globaldata) wallpointsIndex = core.getWallPointArrayIndex(globaldata) # result = core.findAverageWallDistance(globaldata,wallpointsIndex) # print(result) # temp.writeNormalsToText(globaldata) # temp.writeConditionValues(globaldata) temp.writeSrikanthStyle(globaldata) exit() wallpointsData = core.generateWallPolygons(wallpoints) while True: ptidx = input("Which point do you want to check? ") if ptidx == "exit": break ptidx = int(ptidx) print("Point Index:", ptidx) print("Point Co ordinate:", core.getPointXY(ptidx, globaldata)) flag = core.getFlag(ptidx, globaldata) flag = int(flag) if flag == 0: flagd = "Wall Point" elif flag == 1: flagd = "Interior Point" else: flagd = "Outer Point" print("Point Type:", flagd) nbhs = core.getNeighbours(ptidx, globaldata) print("Total Number of Neighbours:", len(nbhs)) print("Neighbour Array") print(nbhs) if (flag == 0): print(core.getConditionNumberLegacy(ptidx, globaldata)) xpos = core.getXPosPoints(ptidx, globaldata) xneg = core.getXNegPoints(ptidx, globaldata) print("xpos", len(xpos), "xneg", len(xneg)) else: print(core.getConditionNumberLegacy(ptidx, globaldata)) xpos = core.getDXPosPointsLegacy(ptidx, globaldata) xneg = core.getDXNegPointsLegacy(ptidx, globaldata) ypos = core.getDYPosPointsLegacy(ptidx, globaldata) yneg = core.getDYNegPointsLegacy(ptidx, globaldata) print("xpos", len(xpos), "xneg", len(xneg), "ypos", len(ypos), "yneg", len(yneg))
def triangleBalance(globaldata, polygonData, wallpoints, configData, badPoints): for _, idx in enumerate(tqdm(badPoints)): if idx > 0: flag = int(core.getFlag(idx, globaldata)) xposf, xnegf, yposf, ynegf = core.getFlags(idx, globaldata) WALL_OUTER_THRESHOLD = int( configData["triangulate"]["triangle"]["wallandOuterThreshold"]) INTERIOR_THRESHOLD = int( configData["triangulate"]["triangle"]["interiorThreshold"]) AGGRESSIVE_MAX_NEIGHBOURS = -int( configData["triangulate"]["triangle"] ["aggressiveMaxNeighbours"]) NORMAL_MAX_NEIGHBOURS = -int( configData["triangulate"]["triangle"]["normalMaxNeighbours"]) ## Interior Points if flag == 1: if xposf == 2: nbhs = getNeighboursFromTriangle(idx, globaldata, polygonData) globaldata = fixXpos(idx, globaldata, nbhs, NORMAL_MAX_NEIGHBOURS, INTERIOR_THRESHOLD, False, polygonData, wallpoints, configData) elif xposf == 1: nbhs = getNeighboursFromTriangle(idx, globaldata, polygonData) globaldata = fixXpos(idx, globaldata, nbhs, AGGRESSIVE_MAX_NEIGHBOURS, INTERIOR_THRESHOLD, True, polygonData, wallpoints, configData) if xnegf == 2: nbhs = getNeighboursFromTriangle(idx, globaldata, polygonData) globaldata = fixXneg(idx, globaldata, nbhs, NORMAL_MAX_NEIGHBOURS, INTERIOR_THRESHOLD, False, polygonData, wallpoints, configData) elif xnegf == 1: nbhs = getNeighboursFromTriangle(idx, globaldata, polygonData) globaldata = fixXneg(idx, globaldata, nbhs, AGGRESSIVE_MAX_NEIGHBOURS, INTERIOR_THRESHOLD, True, polygonData, wallpoints, configData) if yposf == 2: nbhs = getNeighboursFromTriangle(idx, globaldata, polygonData) globaldata = fixYpos(idx, globaldata, nbhs, NORMAL_MAX_NEIGHBOURS, INTERIOR_THRESHOLD, False, polygonData, wallpoints, configData) elif yposf == 1: nbhs = getNeighboursFromTriangle(idx, globaldata, polygonData) globaldata = fixYpos(idx, globaldata, nbhs, AGGRESSIVE_MAX_NEIGHBOURS, INTERIOR_THRESHOLD, True, polygonData, wallpoints, configData) if ynegf == 2: nbhs = getNeighboursFromTriangle(idx, globaldata, polygonData) globaldata = fixYneg(idx, globaldata, nbhs, NORMAL_MAX_NEIGHBOURS, INTERIOR_THRESHOLD, False, polygonData, wallpoints, configData) elif ynegf == 1: nbhs = getNeighboursFromTriangle(idx, globaldata, polygonData) globaldata = fixYneg(idx, globaldata, nbhs, AGGRESSIVE_MAX_NEIGHBOURS, INTERIOR_THRESHOLD, True, polygonData, wallpoints, configData) # Wall Points elif flag == 0: if xposf == 2: nbhs = getNeighboursFromTriangle(idx, globaldata, polygonData) globaldata = fixXpos(idx, globaldata, nbhs, -2, 30, True, polygonData, wallpoints, configData) elif xposf == 1: nbhs = getNeighboursFromTriangle(idx, globaldata, polygonData) globaldata = fixXpos(idx, globaldata, nbhs, -2, 30, True, polygonData, wallpoints, configData) if xnegf == 2: nbhs = getNeighboursFromTriangle(idx, globaldata, polygonData) globaldata = fixXneg(idx, globaldata, nbhs, -1, 30, False, polygonData, wallpoints, configData) elif xnegf == 1: nbhs = getNeighboursFromTriangle(idx, globaldata, polygonData) globaldata = fixXneg(idx, globaldata, nbhs, -2, 30, True, polygonData, wallpoints, configData) elif flag == 2: if xposf == 2: nbhs = getNeighboursFromTriangle(idx, globaldata, polygonData) globaldata = fixXpos(idx, globaldata, nbhs, NORMAL_MAX_NEIGHBOURS, WALL_OUTER_THRESHOLD, False, polygonData, wallpoints, configData) elif xposf == 1: nbhs = getNeighboursFromTriangle(idx, globaldata, polygonData) globaldata = fixXpos(idx, globaldata, nbhs, AGGRESSIVE_MAX_NEIGHBOURS, WALL_OUTER_THRESHOLD, True, polygonData, wallpoints, configData) if xnegf == 2: nbhs = getNeighboursFromTriangle(idx, globaldata, polygonData) globaldata = fixXneg(idx, globaldata, nbhs, NORMAL_MAX_NEIGHBOURS, WALL_OUTER_THRESHOLD, False, polygonData, wallpoints, configData) elif xnegf == 1: nbhs = getNeighboursFromTriangle(idx, globaldata, polygonData) globaldata = fixXneg(idx, globaldata, nbhs, AGGRESSIVE_MAX_NEIGHBOURS, WALL_OUTER_THRESHOLD, True, polygonData, wallpoints, configData) return globaldata
def main(): # Command Line Arguments parser = argparse.ArgumentParser() parser.add_argument("-i", "--input", const=str, nargs="?") args = parser.parse_args() log.info("Loading Data") log.debug("Arguments") log.debug(args) globaldata = core.getKeyVal("globaldata") configData = core.getConfig() globaldata.insert(0,"start") # print(len(globaldata)) globaldata = core.cleanNeighbours(globaldata) wallpoints = core.getWallPointArrayIndex(globaldata) wallpoints = core.flattenList(wallpoints) # wallpoints = core.convertToShapely(wallpoints) shiftFlag = int(configData["shift"]["shiftFlag"]) # Get interiorpts list interiorpts = core.getInteriorPointArrayIndex(globaldata) # print(interiorpts) # If the interior point has a wallpoint as neighbour log.info("Scanning Interior Points for Possible Shifting") for idx in tqdm(interiorpts): if core.containsWallPoints(globaldata, idx, wallpoints): # print(idx) toplx,toply,bottomrx,bottomry = core.getBoundingPointsOfQuadrant(idx, globaldata) nbhcords = core.getNeighbours(idx,globaldata) mainptx, mainpty = core.getPoint(idx,globaldata) bestwallpt = 0 mindist = 1000.0 # Get all neighbouring for itm in nbhcords: if core.getFlag(itm,globaldata) == 0: wallptx, wallpty = core.getPoint(itm, globaldata) if mindist > core.distance(mainptx, mainpty, wallptx, wallpty): mindist = core.distance(mainptx, mainpty, wallptx, wallpty) bestwallpt = itm # Safety Case if bestwallpt == 0: continue else: itm = bestwallpt # Calculate normal for that wall point nx, ny = core.normalCalculation(itm, globaldata, True, configData) slope = ny/nx wallptx, wallpty = core.getPoint(itm, globaldata) leftsidey = slope * (toplx - wallptx) + wallpty rightsidey = slope * (bottomrx - wallptx) + wallpty lowersidex = (bottomry - wallpty) / slope + wallptx uppersidex = (toply - wallpty) / slope + wallptx # Check if the quadrant and normal intersect if shiftFlag == 0: maxdist = 0.0 if leftsidey <= toply and leftsidey >= bottomry: # If yes, change x, y of interior point to lie on the normal if maxdist < core.distance(wallptx, wallpty, toplx, leftsidey): maxdist = core.distance(wallptx, wallpty, toplx, leftsidey) globaldata[idx][1] = toplx globaldata[idx][2] = leftsidey globaldata = core.setNormals(idx, globaldata, (nx, ny)) if rightsidey <= toply and rightsidey >= bottomry: if maxdist < core.distance(wallptx, wallpty, bottomrx, rightsidey): maxdist = core.distance(wallptx, wallpty, bottomrx, rightsidey) globaldata[idx][1] = bottomrx globaldata[idx][2] = rightsidey globaldata = core.setNormals(idx, globaldata, (nx, ny)) if uppersidex <= bottomrx and uppersidex >= toplx: if maxdist < core.distance(wallptx, wallpty, toplx, leftsidey): maxdist = core.distance(wallptx, wallpty, toplx, leftsidey) globaldata[idx][1] = uppersidex globaldata[idx][2] = toply globaldata = core.setNormals(idx, globaldata, (nx, ny)) if lowersidex <= bottomrx and lowersidex >= toplx: if maxdist < core.distance(wallptx, wallpty, lowersidex, bottomry): maxdist = core.distance(wallptx, wallpty, lowersidex, bottomry) globaldata[idx][1] = lowersidex globaldata[idx][2] = bottomry globaldata = core.setNormals(idx, globaldata, (nx, ny)) elif shiftFlag == 1: mindist = 1000.0 if leftsidey <= toply and leftsidey >= bottomry: # If yes, change x, y of interior point to lie on the normal if mindist > core.distance(wallptx, wallpty, toplx, leftsidey): mindist = core.distance(wallptx, wallpty, toplx, leftsidey) globaldata[idx][1] = toplx globaldata[idx][2] = leftsidey globaldata = core.setNormals(idx, globaldata, (nx, ny)) if rightsidey <= toply and rightsidey >= bottomry: if mindist > core.distance(wallptx, wallpty, bottomrx, rightsidey): mindist = core.distance(wallptx, wallpty, bottomrx, rightsidey) globaldata[idx][1] = bottomrx globaldata[idx][2] = rightsidey globaldata = core.setNormals(idx, globaldata, (nx, ny)) if uppersidex <= bottomrx and uppersidex >= toplx: if mindist > core.distance(wallptx, wallpty, toplx, leftsidey): mindist = core.distance(wallptx, wallpty, toplx, leftsidey) globaldata[idx][1] = uppersidex globaldata[idx][2] = toply globaldata = core.setNormals(idx, globaldata, (nx, ny)) if lowersidex <= bottomrx and lowersidex >= toplx: if mindist > core.distance(wallptx, wallpty, lowersidex, bottomry): mindist = core.distance(wallptx, wallpty, lowersidex, bottomry) globaldata[idx][1] = lowersidex globaldata[idx][2] = bottomry globaldata = core.setNormals(idx, globaldata, (nx, ny)) # print(idx) # break # else: # continue # print(nx, ny) globaldata.pop(0) core.setKeyVal("globaldata",globaldata) log.info("Writing file to disk") with open("preprocessorfile_shift.txt", "w") as text_file: for item1 in globaldata: text_file.writelines(["%s " % item for item in item1]) text_file.writelines("\n") log.info("Geometry Shifted Converted")
def generateReportConnectivity(globaldata): resultInterior = { "total": 0, "leastxpos": 0, "maxxpos": 0, "leastxneg": 0, "maxxneg": 0, "leastypos": 0, "maxypos": 0, "leastyneg": 0, "maxyneg": 0, "xposavg": 0, "xnegavg": 0, "yposavg": 0, "ynegavg": 0, "_init": False } resultOuter = { "total": 0, "leastxpos": 0, "maxxpos": 0, "leastxneg": 0, "maxxneg": 0, "xposavg": 0, "xnegavg": 0, "_init": False } resultWall = { "total": 0, "leastxpos": 0, "maxxpos": 0, "leastxneg": 0, "maxxneg": 0, "xposavg": 0, "xnegavg": 0, "_init": False } inxpos, inxneg, inypos, inyneg, ouxpos, ouxneg, waxpos, waxneg, interior, outer, wall = 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 for idx, _ in enumerate(globaldata): if (idx > 1): flag = core.getFlag(idx, globaldata) ## Interior Point if (flag == 1): nbhs = core.convertIndexToPoints( core.getNeighbours(idx, globaldata), globaldata) curcord = core.getPointXY(idx, globaldata) xpos, xneg, ypos, yneg, _ = core.deltaNeighbourCalculationLegacy( nbhs, curcord, False, False) interior = interior + 1 inxpos = inxpos + xpos inxneg = inxneg + xneg inypos = inypos + ypos inyneg = inyneg + yneg if (resultInterior["_init"] == True): if (xpos < resultInterior["leastxpos"]): resultInterior["leastxpos"] = xpos if (resultInterior["maxxpos"] < xpos): resultInterior["maxxpos"] = xpos if (xneg < resultInterior["leastxneg"]): resultInterior["leastxneg"] = xneg if (resultInterior["maxxneg"] < xneg): resultInterior["maxxneg"] = xneg if (ypos < resultInterior["leastypos"]): resultInterior["leastypos"] = ypos if (resultInterior["maxypos"] < ypos): resultInterior["maxypos"] = ypos if (yneg < resultInterior["leastyneg"]): resultInterior["leastyneg"] = yneg if (resultInterior["maxyneg"] < yneg): resultInterior["maxyneg"] = yneg else: resultInterior["_init"] = True resultInterior["leastxpos"] = xpos resultInterior["leastxneg"] = xneg resultInterior["leastypos"] = ypos resultInterior["leastyneg"] = yneg #Wall Points if (flag == 0): nbhs = core.convertIndexToPoints( core.getNeighbours(idx, globaldata), globaldata) curcord = core.getPointXY(idx, globaldata) xpos, xneg, _, _, _ = core.deltaNeighbourCalculationLegacy( nbhs, curcord, False, False) wall = wall + 1 waxpos = waxpos + xpos waxneg = waxneg + xneg if (resultWall["_init"] == True): if (xpos < resultWall["leastxpos"]): resultWall["leastxpos"] = xpos if (resultWall["maxxpos"] < xpos): resultWall["maxxpos"] = xpos if (xneg < resultWall["leastxneg"]): resultWall["leastxneg"] = xneg if (resultWall["maxxneg"] < xneg): resultWall["maxxneg"] = xneg else: resultWall["_init"] = True resultWall["leastxpos"] = xpos resultWall["leastxneg"] = xneg #Outer Points if (flag == 2): nbhs = core.convertIndexToPoints( core.getNeighbours(idx, globaldata), globaldata) curcord = core.getPointXY(idx, globaldata) xpos, xneg, _, _, _ = core.deltaNeighbourCalculationLegacy( nbhs, curcord, False, False) outer = outer + 1 ouxpos = ouxpos + xpos ouxneg = ouxneg + xneg if (resultOuter["_init"] == True): if (xpos < resultOuter["leastxpos"]): resultOuter["leastxpos"] = xpos if (resultOuter["maxxpos"] < xpos): resultOuter["maxxpos"] = xpos if (xneg < resultOuter["leastxneg"]): resultOuter["leastxneg"] = xneg if (resultOuter["maxxneg"] < xneg): resultOuter["maxxneg"] = xneg else: resultOuter["_init"] = True resultOuter["leastxpos"] = xpos resultOuter["leastxneg"] = xneg resultInterior["xposavg"] = float(round(inxpos / interior, 2)) resultInterior["xnegavg"] = float(round(inxneg / interior, 2)) resultInterior["yposavg"] = float(round(inypos / interior, 2)) resultInterior["ynegavg"] = float(round(inyneg / interior, 2)) resultInterior["total"] = interior resultOuter["xposavg"] = float(round(ouxpos / outer, 2)) resultOuter["xnegavg"] = float(round(ouxneg / outer, 2)) resultOuter["total"] = outer resultWall["xposavg"] = float(round(waxpos / wall, 2)) resultWall["xnegavg"] = float(round(waxneg / wall, 2)) resultWall["total"] = wall return resultWall, resultInterior, resultOuter
def generateReportConditionValue(globaldata, threshold): resultInterior = { "maxxpos": 0, "minxpos": 0, "maxxneg": 0, "minxneg": 0, "maxypos": 0, "minypos": 0, "maxyneg": 0, "minyneg": 0, "avgxpos": 0, "avgxneg": 0, "avgypos": 0, "avgyneg": 0, "nan": 0, "inf": 0, "_init": False } resultOuter = { "maxxpos": 0, "minxpos": 0, "maxxneg": 0, "minxneg": 0, "maxypos": 0, "minypos": 0, "maxyneg": 0, "minyneg": 0, "avgxpos": 0, "avgxneg": 0, "avgypos": 0, "avgyneg": 0, "nan": 0, "inf": 0, "_init": False } resultWall = { "maxxpos": 0, "minxpos": 0, "maxxneg": 0, "minxneg": 0, "maxypos": 0, "minypos": 0, "maxyneg": 0, "minyneg": 0, "avgxpos": 0, "avgxneg": 0, "avgypos": 0, "avgyneg": 0, "nan": 0, "inf": 0, "_init": False } totxpos = [0, 0, 0] totxneg = [0, 0, 0] totypos = [0, 0, 0] totyneg = [0, 0, 0] totinf = [0, 0, 0] totnan = [0, 0, 0] totpts = [0, 0, 0] for idx, _ in enumerate(globaldata): if (idx > 1): flag = core.getFlag(idx, globaldata) result = core.getConditionNumberLegacy(idx, globaldata) if (math.isnan(result["xpos"]) or math.isnan(result["xneg"]) or math.isnan(result["ypos"]) or math.isnan(result["yneg"])): totnan[flag] = totnan[flag] + 1 continue elif (result["xpos"] > threshold or result["xneg"] > threshold or result["ypos"] > threshold or result["yneg"] > threshold): totinf[flag] = totinf[flag] + 1 continue else: totxpos[flag] = totxpos[flag] + result["xpos"] totxneg[flag] = totxneg[flag] + result["xneg"] totypos[flag] = totypos[flag] + result["ypos"] totyneg[flag] = totyneg[flag] + result["yneg"] totpts[flag] = totpts[flag] + 1 # Interior if (flag == 1): if (resultInterior["_init"] == True): if (resultInterior["maxxpos"] < result["xpos"]): resultInterior["maxxpos"] = result["xpos"] if (result["xpos"] < resultInterior["minxpos"]): resultInterior["minxpos"] = result["xpos"] if (resultInterior["maxxneg"] < result["xneg"]): resultInterior["maxxneg"] = result["xneg"] if (result["xneg"] < resultInterior["minxneg"]): resultInterior["minxneg"] = result["xneg"] if (resultInterior["maxypos"] < result["ypos"]): resultInterior["maxypos"] = result["ypos"] if (result["ypos"] < resultInterior["minypos"]): resultInterior["minypos"] = result["ypos"] if (resultInterior["maxyneg"] < result["yneg"]): resultInterior["maxyneg"] = result["yneg"] if (result["yneg"] < resultInterior["minyneg"]): resultInterior["minyneg"] = result["yneg"] else: resultInterior["_init"] = True resultInterior["maxxpos"] = result["xpos"] resultInterior["minxpos"] = result["xpos"] resultInterior["maxxneg"] = result["xneg"] resultInterior["minxneg"] = result["xneg"] resultInterior["maxypos"] = result["ypos"] resultInterior["minypos"] = result["ypos"] resultInterior["maxyneg"] = result["yneg"] resultInterior["minyneg"] = result["yneg"] # Wall elif (flag == 0): if (resultWall["_init"] == True): if (resultWall["maxxpos"] < result["xpos"]): resultWall["maxxpos"] = result["xpos"] if (result["xpos"] < resultWall["minxpos"]): resultWall["minxpos"] = result["xpos"] if (resultWall["maxxneg"] < result["xneg"]): resultWall["maxxneg"] = result["xneg"] if (result["xneg"] < resultWall["minxneg"]): resultWall["minxneg"] = result["xneg"] if (resultWall["maxypos"] < result["ypos"]): resultWall["maxypos"] = result["ypos"] if (result["ypos"] < resultWall["minypos"]): resultWall["minypos"] = result["ypos"] if (resultWall["maxyneg"] < result["yneg"]): resultWall["maxyneg"] = result["yneg"] if (result["yneg"] < resultWall["minyneg"]): resultWall["minyneg"] = result["yneg"] else: resultWall["_init"] = True resultWall["maxxpos"] = result["xpos"] resultWall["minxpos"] = result["xpos"] resultWall["maxxneg"] = result["xneg"] resultWall["minxneg"] = result["xneg"] resultWall["maxypos"] = result["ypos"] resultWall["minypos"] = result["ypos"] resultWall["maxyneg"] = result["yneg"] resultWall["minyneg"] = result["yneg"] # Outer elif (flag == 2): if (resultOuter["_init"] == True): if (resultOuter["maxxpos"] < result["xpos"]): resultOuter["maxxpos"] = result["xpos"] if (result["xpos"] < resultOuter["minxpos"]): resultOuter["minxpos"] = result["xpos"] if (resultOuter["maxxneg"] < result["xneg"]): resultOuter["maxxneg"] = result["xneg"] if (result["xneg"] < resultOuter["minxneg"]): resultOuter["minxneg"] = result["xneg"] if (resultOuter["maxypos"] < result["ypos"]): resultOuter["maxypos"] = result["ypos"] if (result["ypos"] < resultOuter["minypos"]): resultOuter["minypos"] = result["ypos"] if (resultOuter["maxyneg"] < result["yneg"]): resultOuter["maxyneg"] = result["yneg"] if (result["yneg"] < resultOuter["minyneg"]): resultOuter["minyneg"] = result["yneg"] else: resultOuter["_init"] = True resultOuter["maxxpos"] = result["xpos"] resultOuter["minxpos"] = result["xpos"] resultOuter["maxxneg"] = result["xneg"] resultOuter["minxneg"] = result["xneg"] resultOuter["maxypos"] = result["ypos"] resultOuter["minypos"] = result["ypos"] resultOuter["maxyneg"] = result["yneg"] resultOuter["minyneg"] = result["yneg"] if (totpts[2] == 0): totpts[2] = 1 try: totxpos = [float(round(x / y, 2)) for x, y in zip(totxpos, totpts)] totxneg = [float(round(x / y, 2)) for x, y in zip(totxneg, totpts)] totypos = [float(round(x / y, 2)) for x, y in zip(totypos, totpts)] totyneg = [float(round(x / y, 2)) for x, y in zip(totyneg, totpts)] except ZeroDivisionError: pass resultInterior["avgxpos"] = totxpos[1] resultInterior["avgxneg"] = totxneg[1] resultInterior["avgypos"] = totypos[1] resultInterior["avgyneg"] = totyneg[1] resultInterior["nan"] = totnan[1] resultInterior["inf"] = totinf[1] resultOuter["avgxpos"] = totxpos[2] resultOuter["avgxneg"] = totxneg[2] resultOuter["avgypos"] = totypos[2] resultOuter["avgyneg"] = totyneg[2] resultOuter["nan"] = totnan[2] resultOuter["inf"] = totinf[2] resultWall["avgxpos"] = totxpos[0] resultWall["avgxneg"] = totxneg[0] resultWall["avgypos"] = totypos[0] resultWall["avgyneg"] = totyneg[0] resultWall["nan"] = totnan[0] resultWall["inf"] = totinf[0] return resultWall, resultInterior, resultOuter
def main(): # Command Line Arguments parser = argparse.ArgumentParser() parser.add_argument("-i", "--input", const=str, nargs="?") args = parser.parse_args() np.seterr(divide='ignore') print("Loading Data") loaded = False try: file1 = open(args.input, "r") data = file1.read() globaldata = ["start"] splitdata = data.split("\n") splitdata = splitdata[:-1] print("Processed Pre-Processor File") print("Converting to readable format") for _, itm in enumerate(tqdm(splitdata)): itm = itm.split(" ") itm.pop(-1) entry = itm globaldata.append(entry) globaldata = core.cleanNeighbours(globaldata) wallpoints = core.getWallPointArray(globaldata) wallpointsData = core.generateWallPolygons(wallpoints) wallpointsall = list( map(int, core.flattenList(core.getWallPointArrayIndex(globaldata)))) loaded = True except: loaded = False conf = core.getConfig() # interiorpts = [] # interiorpts.extend(range(1, len(globaldata))) # interiorpts = core.convertPointToShapelyPoint(core.convertIndexToPoints(interiorpts,globaldata)) # interiorpts = MultiPoint(interiorpts) # interiortriangles = triangulate(interiorpts) # polydata = balance.getPolygon(interiortriangles) # plot 'preprocessorfile.txt' using 2:3:(sprintf("%d", $1)) with labels notitle core.clearScreen() while True and loaded: print("Type 'exit! to quit (Does not save changes).") print("Type 'exit to quit (Saves changes).") print("Type 'wcc' to run Wall Connectivity Check on all Wall Points.") print( "Type 'wcc!' to run Wall Connectivity Check on all Wall Points and return nearest point." ) print( "Type 'wcc!!' to run Wall Connectivity Check on all Wall Points and generate a corresponding sensor file." ) print( "Type 'wcc!!!' to run Wall Connectivity Check on all Wall Points and try fixing sparsity. (Wall Mode)" ) print( "Type 'wcc!!!!' to run Wall Connectivity Check on all Wall Points and try fixing sparsity. (Interior Mode)" ) print( "Type 'wcc!!!!!' to run Wall Connectivity Check on all Wall Points and just print them." ) print( "Type 'wcc!!!!!!' to run Wall Connectivity Check on all Wall Points and just print a interior point which can be bsplined." ) print( "Type 'icc' to run Interior Connectivity Check on all Interior Points." ) print("Type 'cache' to push the file you read into cache.") print("Type 'integrity' to check wall.json integrity") print("Type 'integrity!' to check wall.json integrity and fix it") print("Type 'full' to perform one full refinement") print("Type 'fullno' to perform one full refinement (excluding outer)") print("Type 'customrefine' to perform custom refinement") print("Type 'customrefine!' to perform custom box refinement") print("Type 'old' to convert preprocessorfile to old format") print( "Type 'bad2' to print all points with 2 in it's split connectivity" ) print( "Type 'bad1' to print all points with 1 in it's split connectivity" ) print("Type 'split' to output the different type of points in a file") print("Type 'blank' to blank multiple non leaf points") print("Type 'config' to start Config Manager") print("Type 'plot' to start Plot Manager") print("Type 'config' to start Config Manager") print("Type 'hills' to start Hills and Valleys Manager") print("Type 'normals' to write normals to 'file.dat'") print( "Type 'normals!' to write normals (including custom) to 'file.dat'" ) print( "Type 'maxnbhs' to output the maximum number of neighbours in the file." ) ptidx = input("Which point do you want to fix? ").lower() if ptidx == "exit!": exit() if ptidx == "exit": break elif ptidx == "hills": core.hills_manager() elif ptidx == "wcc": core.clearScreen() globaldata, _ = core.connectivityCheck(globaldata, wallpointsall, conf) core.wallConnectivityCheck(globaldata) elif ptidx == "wcc!": core.clearScreen() globaldata, _ = core.connectivityCheck(globaldata, wallpointsall, conf) core.wallConnectivityCheckNearest(globaldata) elif ptidx == "wcc!!": core.clearScreen() globaldata, _ = core.connectivityCheck(globaldata, wallpointsall, conf) core.wallConnectivityCheckSensor(globaldata) elif ptidx == "wcc!!!": core.clearScreen() globaldata, _ = core.connectivityCheck(globaldata, wallpointsall, conf) core.sparseNullifier(globaldata, flagCheck=0) elif ptidx == "wcc!!!!": core.clearScreen() globaldata, _ = core.connectivityCheck(globaldata, wallpointsall, conf) core.sparseNullifier(globaldata, flagCheck=1) elif ptidx == "wcc!!!!!": core.clearScreen() globaldata, _ = core.connectivityCheck(globaldata, wallpointsall, conf) core.wallConnectivityCheck(globaldata, verbose=True) elif ptidx == "wcc!!!!!!": core.clearScreen() globaldata, _ = core.connectivityCheck(globaldata, wallpointsall, conf) core.wallSmoother(globaldata, conf) elif ptidx == "icc": core.clearScreen() core.interiorConnectivityCheck(globaldata, offset=len(wallpointsall)) elif ptidx == "cache": core.clearScreen() core.pushCache(globaldata) elif ptidx == "integrity": core.clearScreen() core.verifyIntegrity() elif ptidx == "integrity!": core.clearScreen() core.fixWallIntegrity() elif ptidx == "full": core.clearScreen() core.fullRefine(globaldata) elif ptidx == "fullno": core.clearScreen() core.fullRefineOuter(globaldata) elif ptidx == "customrefine": core.clearScreen() core.refineCustom(globaldata) elif ptidx == "customrefine!": core.clearScreen() core.refineCustomBox(globaldata) elif ptidx == "old": core.clearScreen() core.oldMode(globaldata) elif ptidx == "bad2": core.clearScreen() globaldata, _ = core.connectivityCheck(globaldata, None, conf) core.printBadness(2, globaldata) elif ptidx == "bad1": core.clearScreen() globaldata, _ = core.connectivityCheck(globaldata, None, conf) core.printBadness(1, globaldata) elif ptidx == "split": core.clearScreen() core.splitWrite(globaldata) elif ptidx == "config": core.clearScreen() core.configManager() elif ptidx == "blank": core.clearScreen() core.blankMultiple(globaldata, conf) elif ptidx == "plot": core.clearScreen() core.plotManager(globaldata, wallpoints) elif ptidx == "normals": temp.writeNormalsToText(globaldata, conf) core.clearScreen() elif ptidx == "normals!": temp.writeNormalsAllCustom(globaldata, conf) core.clearScreen() elif ptidx == "maxnbhs": core.clearScreen() core.maxNeighbours(globaldata) elif ptidx == "clear": core.clearScreen() isPointIndex = False try: ptidx = int(ptidx) isPointIndex = True except ValueError: isPointIndex = False pass if isPointIndex == True: core.clearScreen() print("Point Index:", ptidx) print("Point Co ordinate:", core.getPointXY(ptidx, globaldata)) flag = core.getFlag(ptidx, globaldata) flag = int(flag) if flag == 0: flagd = "Wall Point" elif flag == 1: flagd = "Interior Point" else: flagd = "Outer Point" print("Point Type:", flagd) nbhs = core.getNeighbours(ptidx, globaldata) print("Total Number of Neighbours:", len(nbhs)) print("Neighbour Array") print(nbhs) if (flag == 0): print(core.getConditionNumberNew(ptidx, globaldata, conf)) xpos = core.getXPosPoints(ptidx, globaldata, conf) xneg = core.getXNegPoints(ptidx, globaldata, conf) ypos = core.getYPosPoints(ptidx, globaldata, conf) yneg = core.getYNegPoints(ptidx, globaldata, conf) print("xpos", len(xpos), "xneg", len(xneg)) else: print(core.getConditionNumberNew(ptidx, globaldata, conf)) xpos = core.getXPosPoints(ptidx, globaldata, conf) xneg = core.getXNegPoints(ptidx, globaldata, conf) ypos = core.getYPosPoints(ptidx, globaldata, conf) yneg = core.getYNegPoints(ptidx, globaldata, conf) print("xpos", len(xpos), "xneg", len(xneg), "ypos", len(ypos), "yneg", len(yneg)) nx, ny = core.getNormals(ptidx, globaldata, conf) leaf = core.isLeafPoint(ptidx, globaldata) print("Leaf Point: {}".format(leaf)) print("nx = {} ny = {}".format(nx, ny)) print("Select Point Repair Option") print("(1) Exit") print("(2) Exit without saving any changes") print("(3) Go Back") print("(4) Find nearest distance to wall points") print("(5) Print Detailed Connectivity") print("(6) Adapt the point") print("(7) Blank the point") whatkind = int(input("What option do you want to select? ")) if whatkind == 1: core.clearScreen() break elif whatkind == 2: exit() elif whatkind == 3: core.clearScreen() elif whatkind == 4: core.clearScreen() px, py = core.getPoint(ptidx, globaldata) print("Nearest Distance: {}".format( min(core.wallDistance((px, py), wallpointsData)))) elif whatkind == 5: core.clearScreen() print("xpos connectivity: {}, no. of xpos: {}".format( core.convertPointsToIndex(xpos, globaldata), len(xpos))) print("xneg connectivity: {}, no. of xneg: {}".format( core.convertPointsToIndex(xneg, globaldata), len(xneg))) print("ypos connectivity: {}, no. of ypos: {}".format( core.convertPointsToIndex(ypos, globaldata), len(ypos))) print("yneg connectivity: {}, no. of yneg: {}".format( core.convertPointsToIndex(yneg, globaldata), len(yneg))) elif whatkind == 6: core.clearScreen() core.adaptPoint(ptidx, globaldata) elif whatkind == 7: core.clearScreen() core.blankPoint(ptidx, globaldata) else: core.clearScreen() break if loaded: globaldata.pop(0) with open("preprocessorfile_tools.txt", "w") as text_file: for item1 in globaldata: text_file.writelines(["%s " % item for item in item1]) text_file.writelines("\n") else: while True: print("Type 'integrity' to check wall.json integrity") print("Type 'integrity!' to check wall.json integrity and fix it") print("Type 'config' to start Config Manager") print("Type 'hills' to start Hills and Valleys Manager") print("Type 'exit' to exit") ptidx = input("Enter command: ").lower() if ptidx == "integrity": core.clearScreen() core.verifyIntegrity() elif ptidx == "integrity!": core.clearScreen() core.fixWallIntegrity() elif ptidx == "config": core.clearScreen() core.configManager() elif ptidx == "hills": core.clearScreen() core.hills_manager() elif ptidx == "exit": exit()