Esempio n. 1
0
def main():
    # Command Line Arguments
    parser = argparse.ArgumentParser()
    parser.add_argument("-i", "--input", const=str, nargs="?")
    args = parser.parse_args()

    log.info("Loading Data")

    globaldata = core.getKeyVal("globaldata")

    if globaldata == None:

        file1 = open(args.input or "preprocessorfile.txt", "r")
        data = file1.read()
        globaldata = ["start"]
        splitdata = data.split("\n")
        splitdata = splitdata[:-1]

        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)

    else:
        globaldata.insert(0, "start")

    globaldata = core.addLeftRightPoints(globaldata)
    globaldata = core.cleanNeighbours(globaldata)
    wallpoints = core.getWallPointArray(globaldata)
    wallcount = str(wallpoints)
    wallcount = wallcount.count(",") - wallcount.count("[]") + 1
    wallpointsData = core.generateWallPolygons(wallpoints)

    log.info("Running Non Aero Checks")
    globaldata = core.checkAeroGlobal2(globaldata, wallpointsData, wallcount)

    log.info("Generating Polyfile data")
    core.generateOutput(globaldata, wallpoints, wallpointsData)

    log.info("Synchronizing Neighbours")
    globaldata = core.neighbourSynchronize(globaldata)

    globaldata.pop(0)

    core.setKeyVal("globaldata", globaldata)

    log.info("Writing file to disk")

    with open("preprocessorfile_cleaned.txt", "w") as text_file:
        for item1 in globaldata:
            text_file.writelines(["%s " % item for item in item1])
            text_file.writelines("\n")
    log.info("Done")
Esempio n. 2
0
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")
Esempio n. 3
0
def main():
    # Command Line Arguments
    parser = argparse.ArgumentParser()
    parser.add_argument("-i", "--input", 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]

    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)
    wallpointsData = core.generateWallPolygons(wallpoints)
    print(len(wallpointsData))
    x, y = wallpointsData[0].exterior.xy
    fig, axs = plt.subplots()
    axs.fill(x, y, alpha=0.5, fc='r', ec='none')
    plt.show()  #if not interactive.

    log.info("Running Non Aero Checks")

    for idx in trange(1, len(globaldata)):
        nbhs = core.getNeighbours(idx, globaldata)
        for itm in nbhs:
            cord = core.getPointXY(itm, globaldata)
            if core.isNonAeroDynamic(idx, cord, globaldata, wallpointsData):
                log.warning("Point %s has a non aero point with index %s", idx,
                            itm)

    log.info("Done")
Esempio n. 4
0
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)

    file1 = open(args.input or "preprocessorfile.txt", "r")
    data = file1.read()
    globaldata = ["start"]
    splitdata = data.split("\n")
    splitdata = splitdata[:-1]

    log.info("Processed Pre-Processor File")
    log.info("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)
    wallpointsData = core.generateWallPolygons(wallpoints)

    log.info("Finding average distance")

    log.info("Done")
def main():
    # Command Line Arguments
    parser = argparse.ArgumentParser()
    parser.add_argument("-i", "--input", const=str, nargs="?")
    parser.add_argument("-a", "--algorithm", nargs="+")
    args = parser.parse_args()

    log.info("Loading Data")
    log.debug("Arguments")
    log.debug(args)
    configData = core.getConfig()

    globaldata = core.getKeyVal("globaldata")
    hashtable = {}

    if globaldata == None:

        file1 = open(args.input or "preprocessorfile.txt", "r")
        data = file1.read()
        globaldata = ["start"]
        splitdata = data.split("\n")
        splitdata = splitdata[:-1]

        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
            hashtable["{},{}".format(entry[1], entry[2])] = int(entry[0])
            globaldata.append(entry)

    else:
        globaldata.insert(0,"start")
        hashtable = core.generateHashtable(globaldata)

    # globaldata = core.cleanNeighbours(globaldata)

    wallpts = core.getWallPointArray(globaldata)

    algo1,algo2,algo3 = True,True,True

    if len(args.algorithm) == 3:
        algo = list(map(core.ConvertStringToBool,args.algorithm))
        algo1 = algo[0]
        algo2 = algo[1]
        algo3 = algo[2]

    log.info("Generating Wall Polygons for Aerochecks")
    wallpts = core.generateWallPolygons(wallpts)
    log.info("Detected " + str(len(wallpts)) + " geometry(s).")
    log.info("Wall Polygon Generation Complete")
    log.info("Deleting Unneeded Wall Points (Except Left and Right Points)")

    globaldata = core.cleanWallPoints(globaldata)
    badPoints = []

    with np.errstate(divide='ignore', invalid='ignore'):
        if algo1 == True:
            log.info("Triangulating")
            interiorpts = []
            interiorpts.extend(range(1, len(globaldata)))
            interiorpts = core.convertPointToShapelyPoint(core.convertIndexToPoints(interiorpts,globaldata))
            interiorpts = MultiPoint(interiorpts)
            interiortriangles = triangulate(interiorpts)
            log.info("Generated " + str(len(interiortriangles)) + " triangle(s).")
            polydata = balance.getPolygon(interiortriangles)
            log.info("Running Connectivity Check")
            globaldata,badPoints = core.connectivityCheck(globaldata, badPoints, configData, quick=True)
            log.info("Connectivity Check Done")
            log.info("Running Triangulation Balancing using Nischay's Triangle Neighbours")
            globaldata = balance.triangleBalance(globaldata, polydata, wallpts, configData, badPoints)
            log.info("Triangle Balancing Done")
        if algo2 == True:
            log.info("Running Connectivity Check")
            globaldata,badPoints = core.connectivityCheck(globaldata, badPoints, configData, quick=True)
            log.info("Connectivity Recheck Done")
            log.info("Running Triangulation Balancing using Kumar's Neighbours (Left and Right Mode)")
            globaldata = balance.triangleBalance2(globaldata, wallpts, configData, badPoints, hashtable)
        if algo3 == True:
            log.info("Running Connectivity Check")
            globaldata,badPoints = core.connectivityCheck(globaldata, badPoints, configData, quick=True)
            log.info("Running Triangulation Balancing using Kumar's Neighbours (General)")
            globaldata = balance.triangleBalance3(globaldata, wallpts, configData, badPoints, hashtable)
        log.info("Running Connectivity Recheck")
        globaldata,badPoints = core.connectivityCheck(globaldata, badPoints, configData, quick=True)
    log.warning("Total Number of Points unable to be fixed: {}".format(len(badPoints)))
    # log.info("Writing Deletion Points")
    # problempts = findDeletionPoints(globaldata)
    
    # globaldata = core.cleanNeighbours(globaldata)

    # core.writeConditionValuesForWall(globaldata, configData)

    globaldata.pop(0)

    core.setKeyVal("globaldata",globaldata)

    # with open("removal_points.txt", "w") as text_file:
    #     for item1 in problempts:
    #         text_file.writelines(["%s " % item1])
    #         text_file.writelines("\n")

    log.info("Writing Preprocessor File")

    with open("preprocessorfile_triangulate.txt", "w") as text_file:
        for item1 in globaldata:
            text_file.writelines(["%s " % item for item in item1])
            text_file.writelines("\n")
    log.info("Done")
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()

    hashtable = {}
    hashtableIndices = {}

    if globaldata == None:

        file1 = open(args.input or "preprocessorfile_pointremoval.txt", "r")
        data = file1.read()
        globaldata = ["start"]
        splitdata = data.split("\n")
        splitdata = splitdata[:-1]

        log.info("Processed Pre-Processor File")
        log.info("Converting to readable format")

        for idx, itm in enumerate(tqdm(splitdata)):
            itm = itm.split(" ")
            itm.pop(-1)
            entry = itm
            hashtable["{},{}".format(entry[1], entry[2])] = int(entry[0])
            hashtableIndices[int(entry[0])] = (float(entry[1]), float(entry[2]))
            globaldata.append(entry)

    else:
        globaldata.insert(0,"start")
        hashtable, hashtableIndices = core.generateHashtableAndIndices(globaldata)

    # globaldata = core.cleanNeighbours(globaldata)

    wallpoints = core.getWallPointArray(globaldata)
    boundingBox = core.getBoundingBoxes(wallpoints, configData, offset=True)
    boundingBox = core.convertToShapelyTuple(boundingBox)
    wallpoints = core.convertToShapely(wallpoints)

    configData = core.getConfig()

    THRESHOLD = int(configData["rechecker"]["conditionValueThreshold"])
    MAX_POINTS = -configData["rechecker"]["maxPoints"]

    log.info("Finding Pseudo Points")
    badList = core.getPseudoPointsParallel(hashtable, configData, boundingBox)
    badList = core.convertPointsToIndex(badList, globaldata, hashtable)

    log.info("Checking Points")
    badList = core.checkConditionNumberBad(globaldata, THRESHOLD, configData, badList, hashtableIndices)
    log.info("Problematic Points to be fixed: {}".format(len(badList)))

    # for idx, itm in enumerate(globaldata):
    #     if idx > 0 and getFlag(idx, globaldata) == 0:
    #         checkConditionNumberWall(idx, globaldata, 30)

    log.info("Fixing Points")
    with np.errstate(divide='ignore', invalid='ignore'):
        for idx in badList:
            globaldata = core.fixXPosMain(idx, globaldata, THRESHOLD, wallpoints, MAX_POINTS, configData, hashtable)
        for idx in badList:
            globaldata = core.fixXNegMain(idx, globaldata, THRESHOLD, wallpoints, MAX_POINTS, configData, hashtable)
        for idx in badList:
            globaldata = core.fixYPosMain(idx, globaldata, THRESHOLD, wallpoints, MAX_POINTS, configData, hashtable)
        for idx in badList:
            globaldata = core.fixYNegMain(idx, globaldata, THRESHOLD, wallpoints, MAX_POINTS, configData, hashtable)

    log.info("Rechecking Points after fixing")
    with np.errstate(divide='ignore', invalid='ignore'):
        badList = core.checkConditionNumberSelectively(globaldata, THRESHOLD, badList, configData)

    if len(badList) == 0:
        log.info("All problematic points have been fixed")
    else:
        log.warning("Total Number of Points unable to be fixed: {}".format(len(badList)))

    # print("Set Flag")

    # for idx,itm in enumerate(globaldata):
    #     if(idx > 0 and getFlag(idx,globaldata) == 1):
    #         globaldata = setFlags(idx,globaldata,60)

    # globaldata = core.cleanNeighbours(globaldata)

    globaldata.pop(0)

    core.setKeyVal("globaldata",globaldata)

    with open("preprocessorfile_rechecker.txt", "w") as text_file:
        for item1 in globaldata:
            text_file.writelines(["%s " % item for item in item1])
            text_file.writelines("\n")

    log.info("Data Converted")
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 main():
    # Command Line Arguments
    parser = argparse.ArgumentParser()
    parser.add_argument("-i", "--input", const=str, nargs="?")
    parser.add_argument("-b", "--bspline", nargs="+")
    parser.add_argument("-n", "--normal", nargs="?")
    parser.add_argument("-p", "--forcemidpointspline", nargs="?")
    parser.add_argument("-q", "--checkquadrant", nargs="?")
    parser.add_argument("-c", "--cache", nargs="?")
    parser.add_argument("-s", "--pseudocheck", nargs="?")
    parser.add_argument("-d", "--dry-run", nargs="?")
    parser.add_argument("-f", "--force-non-leaf", nargs="?")
    args = parser.parse_args()
    np.seterr(divide='ignore')

    configData = core.getConfig()

    dryRun = False
    if args.dry_run:
        dryRun = core.ConvertStringToBool(args.dry_run)

    normalApproach = False
    if args.normal:
        normalApproach = core.ConvertStringToBool(args.normal)

    cache = True
    if args.cache:
        cache = core.ConvertStringToBool(args.cache)

    forcemidpointspline = False
    if args.forcemidpointspline:
        forcemidpointspline = core.ConvertStringToBool(
            args.forcemidpointspline)

    quadrantcheck = True
    if args.checkquadrant:
        quadrantcheck = core.ConvertStringToBool(args.checkquadrant)

    pseudocheck = False
    if args.pseudocheck:
        pseudocheck = core.ConvertStringToBool(args.pseudocheck)

    overrideNL = False
    if args.force_non_leaf:
        overrideNL = core.ConvertStringToBool(args.force_non_leaf)

    log.info("Loading Data")
    log.debug("Arguments")
    log.debug(args)
    if quadrantcheck == False:
        log.warn("Warning: Quadrant Check is disabled")

    if normalApproach == True:
        log.info(
            "Info: Normal Bsplining is occuring with point control {}".format(
                configData['bspline']['pointControl']))
    else:
        log.info("Info: Mid Point BSplining is occuring with point control {}".
                 format(configData['bspline']['pointControl']))

    if forcemidpointspline == True:
        log.warn(
            "Warning: Mid Point BSpline has been forced. Point Control set to 3"
        )
        if normalApproach:
            log.warn("Warning: Normal BSpline has been disabled")
        normalApproach = False

    if dryRun:
        log.info(
            "Info: Dry Run has been enabled. No point will actually be saved.")

    if pseudocheck:
        log.info("Info: Pseudo Points are being checked and fixed.")
        log.info("Pseudo Distance is set to {}".format(
            configData['bspline']['pseudoDist']))

    if configData["bspline"]["polygon"] == True:
        log.info(
            "Info: Polygon Mode has been enabled. Bspline will be disabled.")

    if overrideNL:
        log.warn(
            "Warning: Non Leaf Points are forced to bspline. Point cannot be removed."
        )

    if cache:
        globaldata = core.getKeyVal("globaldata")
    else:
        globaldata = None

    hashtable = {}

    if globaldata == None:

        file1 = open(args.input or "preprocessorfile_bspline.txt", "r")

        data = file1.read()
        globaldata = ["start"]
        splitdata = data.split("\n")
        splitdata = splitdata[:-1]

        log.info("Processed Pre-Processor File")
        log.info("Converting to readable format")

        for idx, itm in enumerate(tqdm(splitdata)):
            itm = itm.split(" ")
            itm.pop(-1)
            entry = itm
            hashtable["{},{}".format(entry[1], entry[2])] = int(entry[0])
            globaldata.append(entry)

    else:
        globaldata.insert(0, "start")
        hashtable = core.generateHashtable(globaldata)

    if not forcemidpointspline:
        POINT_CONTROL = int(configData["bspline"]["pointControl"])
    else:
        POINT_CONTROL = 3

    # globaldata = core.cleanNeighbours(globaldata)
    wallPts = core.getWallPointArray(globaldata)
    boundingBox = core.getBoundingBoxes(wallPts, configData, offset=True)
    boundingBox = core.convertToShapelyTuple(boundingBox)

    additionPts = []
    bsplineArray = []
    for itm in wallPts:
        bsplineData = np.array(core.undelimitXY(itm))
        bsplineArray.append(bsplineData)
    try:
        writingDict = dict(core.load_obj("wall"))
    except IOError:
        writingDict = {}
    log.info("Caching Wall Geometries")
    shapelyWallData = core.convertToShapely(wallPts)
    log.info("Searching for bad points")
    # badList = None
    badList = core.getPseudoPointsParallel(hashtable, configData, boundingBox)
    badList = core.convertPointsToIndex(badList, globaldata, hashtable)
    problempts, perpendicularpts, badpts = core.checkPoints(
        globaldata,
        args.bspline,
        normalApproach,
        configData,
        pseudocheck,
        shapelyWallData,
        badList,
        overrideNL=overrideNL)
    log.info("Bsplining {} points".format(len(problempts)))
    log.info("Starting BSpline")
    for idx, itm in enumerate(tqdm(problempts)):
        data = core.feederData(itm, wallPts)
        switch = False
        if configData["bspline"]["polygon"] == False:
            if configData["global"]["wallPointOrientation"] == "ccw":
                if data[0] == 1 and data[1] == 0:
                    newpts = core.generateBSplineBetween(
                        bsplineArray[data[2]], data[1], data[0], POINT_CONTROL)
                    switch = True
                else:
                    newpts = core.generateBSplineBetween(
                        bsplineArray[data[2]], data[0], data[1], POINT_CONTROL)
            else:
                switch = True
                if data[1] == 0 and data[0] == 1:
                    newpts = core.generateBSplineBetween(
                        bsplineArray[data[2]], data[1], data[0], POINT_CONTROL)
                    switch = True
                elif data[1] == 0 and data[0] != 1:
                    newpts = core.generateBSplineBetween(
                        bsplineArray[data[2]], data[0], data[1], POINT_CONTROL)
                    switch = False
                elif data[0] == 0 and data[1] != 1:
                    newpts = core.generateBSplineBetween(
                        bsplineArray[data[2]], data[1], data[0], POINT_CONTROL)
                    switch = True
                else:
                    newpts = core.generateBSplineBetween(
                        bsplineArray[data[2]], data[0], data[1], POINT_CONTROL)
                    switch = False
            if quadrantcheck:
                newpts = core.getPointsOnlyInQuadrant(newpts, badpts[idx],
                                                      globaldata)
                if len(newpts) == 0:
                    if not pseudocheck:
                        log.error(
                            "Error: Quadrant Check failed. No point exist.")
                        log.error("Problem point is {}".format(badpts[idx]))
                        continue
                    else:
                        log.warn(
                            "Warn: Quadrant Check failed. No point exists. Ignored since Pseudo Check is enabled."
                        )
                        continue
            newpts = core.findNearestPoint(perpendicularpts[idx], newpts)
            print(newpts)
            if newpts == False:
                log.error(
                    "Error: Increase your Bspline Point Control Attribute")
                exit()
        else:
            newpts = list(perpendicularpts[idx])
            if configData["global"]["wallPointOrientation"] == "ccw":
                if data[0] == 1 and data[1] == 0:
                    switch = True
                else:
                    switch = False
            else:
                switch = True
                if data[1] == 0 and data[0] == 1:
                    switch = True
                elif data[1] == 0 and data[0] != 1:
                    switch = False
                elif data[0] == 0 and data[1] != 1:
                    switch = True
                else:
                    switch = False
            if quadrantcheck:
                newpts = core.getPointsOnlyInQuadrant([newpts], badpts[idx],
                                                      globaldata)
                if len(newpts) == 0:
                    if not pseudocheck:
                        log.error(
                            "Error: Quadrant Check failed. No point exist.")
                        log.error("Problem point is {}".format(badpts[idx]))
                        continue
                    else:
                        log.warn(
                            "Warn: Quadrant Check failed. No point exists. Ignored since Pseudo Check is enabled."
                        )
                        continue
                newpts = list(newpts[0])
            print(newpts)
        if switch:
            wallPtLocation = data[4]
        else:
            wallPtLocation = data[3]
        try:
            datum = list(writingDict[wallPtLocation])
            datum.append(newpts)
            writingDict[wallPtLocation] = datum
        except KeyError:
            writingDict[wallPtLocation] = [newpts]
        additionPts.append(newpts)
    if not dryRun:
        with open("adapted.txt", "a+") as text_file:
            text_file.writelines("1000 1000\n2000 2000\n")
            for item1 in additionPts:
                text_file.write("%s %s \n" % (item1[0], item1[1]))
            text_file.writelines("1000 1000\n")
        core.save_obj(writingDict, "wall")
Esempio n. 9
0
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()