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 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 main(): # Command Line Arguments parser = argparse.ArgumentParser() parser.add_argument("-i", "--input", const=str, nargs="?") parser.add_argument("-a", "--headadapt", const=str, nargs="?") args = parser.parse_args() log.info("Loading Data") file1 = open(args.input or "preprocessorfile.txt", "r") data = file1.read() globaldata = ["start"] splitdata = data.split("\n") splitdata = splitdata[:-1] headAdpt = core.ConvertStringToBool(args.headadapt) log.info("Processed Pre-Processor File") log.info("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) if headAdpt: log.info("Find Points inside the Box (Head Adaptation)") result = core.findBoxAdaptPoints(globaldata,wallpoints) log.info("Writing file to disk") else: log.info("Find Points inside the Box (General Box Adaptation)") result = core.findGeneralBoxAdaptPoints(globaldata) log.info("Writing file to disk") with open("adapted.txt", "a") as text_file: for item1 in result: ptx,pty = core.getPoint(int(item1),globaldata) text_file.writelines(["%s %s" % (ptx, pty)]) text_file.writelines("\n") text_file.writelines("1000 1000\n") log.info("Done")
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 getNeighboursFromTriangle(index, globaldata, polygonData): cordx, cordy = core.getPoint(index, globaldata) return convertTupleToCord(polygonData[(float(cordx), float(cordy))])
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 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()