Esempio n. 1
0
def get_calibration_arguments_and_model_manager(model_type, data_path,
                                                session_xml, point_suffix):
    settings = get_settings(model_type)
    translators = settings["Translators"]
    required_mp, optional_mp = qtmTools.SubjectMp(session_xml)

    static_session_xml_soup = utils.find_static(session_xml)
    calibration_filename = qtmTools.getFilename(static_session_xml_soup)

    leftFlatFoot = toBool(static_session_xml_soup.Left_foot_flat)
    rightFlatFoot = toBool(static_session_xml_soup.Right_foot_flat)
    headFlat = toBool(static_session_xml_soup.Head_flat)
    markerDiameter = float(
        static_session_xml_soup.Marker_diameter.text) * 1000.0

    dynamic_measurements = qtmTools.findDynamic(session_xml)
    user_settings = {
        "Calibration": {
            "Left flat foot": leftFlatFoot,
            "Right flat foot": rightFlatFoot,
            "Head flat": headFlat,
            "StaticTrial": calibration_filename
        },
        "Global": {
            "Marker diameter": markerDiameter,
            "Point suffix": point_suffix
        },
        "MP": {
            "Required": required_mp,
            "Optional": optional_mp
        },
        "Fitting": {
            "Trials": dynamic_measurements
        }
    }
    if model_type == "CGM1":
        model_manager = ModelManager.CGM1ConfigManager(
            user_settings,
            localInternalSettings=settings,
            localTranslators={"Translators": translators})
        model_manager.contruct()
        calibration_arguments = (
            data_path + "\\",
            model_manager.staticTrial,
            model_manager.translators,
            model_manager.requiredMp,
            model_manager.optionalMp,
            model_manager.leftFlatFoot,
            model_manager.rightFlatFoot,
            model_manager.headFlat,
            model_manager.markerDiameter,
            model_manager.pointSuffix,
        )
    elif model_type == "CGM2_3":
        model_manager = ModelManager.CGM2_3ConfigManager(
            user_settings,
            localInternalSettings=settings,
            localTranslators={"Translators": translators})
        model_manager.contruct()
        finalSettings = model_manager.getFinalSettings()
        calibration_arguments = (
            data_path + "\\",
            model_manager.staticTrial,
            model_manager.translators,
            finalSettings,
            model_manager.requiredMp,
            model_manager.optionalMp,
            model_manager.enableIK,
            model_manager.leftFlatFoot,
            model_manager.rightFlatFoot,
            model_manager.headFlat,
            model_manager.markerDiameter,
            model_manager.hjcMethod,
            model_manager.pointSuffix,
        )
    else:
        raise Exception(
            "Processing for model_type={} is not implemented".format(
                model_type))
    return calibration_arguments, model_manager
Esempio n. 2
0
def getCGMmanager(CGMversion,
                  userSettings,
                  internalSettings=None,
                  translators=None,
                  localIkWeight=None,
                  vsk=None):

    # --- Manager ----
    if model == "CGM1.0":
        manager = ModelManager.CGM1ConfigManager(
            userSettings,
            localInternalSettings=internalSettings,
            localTranslators=translators,
            localIkWeight=localIkWeight,
            vsk=vsk)

    elif model == "CGM1.1":
        manager = ModelManager.CGM1_1ConfigManager(
            userSettings,
            localInternalSettings=internalSettings,
            localTranslators=translators,
            localIkWeight=localIkWeight,
            vsk=vsk)

    elif model == "CGM2.1":
        manager = ModelManager.CGM2_1ConfigManager(
            userSettings,
            localInternalSettings=internalSettings,
            localTranslators=translators,
            localIkWeight=localIkWeight,
            vsk=vsk)

    elif model == "CGM2.2":
        manager = ModelManager.CGM2_2ConfigManager(
            userSettings,
            localInternalSettings=internalSettings,
            localTranslators=translators,
            localIkWeight=localIkWeight,
            vsk=vsk)

    elif model == "CGM2.3":
        manager = ModelManager.CGM2_3ConfigManager(
            userSettings,
            localInternalSettings=internalSettings,
            localTranslators=translators,
            localIkWeight=localIkWeight,
            vsk=vsk)

    elif model == "CGM2.4":
        manager = ModelManager.CGM2_4ConfigManager(
            userSettings,
            localInternalSettings=internalSettings,
            localTranslators=translators,
            localIkWeight=localIkWeight,
            vsk=vsk)

    elif model == "CGM2.5":
        manager = ModelManager.CGM2_5ConfigManager(
            userSettings,
            localInternalSettings=internalSettings,
            localTranslators=translators,
            localIkWeight=localIkWeight,
            vsk=vsk)
    else:
        raise Exception(
            "[pyCGM2] : Model version not known (choice CGM1.0 to CGM2.5 )")

    manager.contruct()

    return manager
Esempio n. 3
0
def main(args):
    DATA_PATH = os.getcwd() + "\\"

    # User Settings
    if os.path.isfile(DATA_PATH + args.userFile):
        userSettings = files.openFile(DATA_PATH, args.userFile)
    else:
        raise Exception("user setting file not found")

    # internal (expert) Settings
    if args.expertFile:
        if os.path.isfile(DATA_PATH + args.expertFile):
            internalSettings = files.openFile(DATA_PATH, args.expertFile)
        else:
            raise Exception("expert setting file not found")
    else:
        internalSettings = None

    # translators
    if os.path.isfile(DATA_PATH + "CGM2_3.translators"):
        translators = files.openFile(DATA_PATH, "CGM2_3.translators")
    else:
        translators = None

    # localIkWeight
    if os.path.isfile(DATA_PATH + "CGM2_3.ikw"):
        localIkWeight = files.openFile(DATA_PATH, "CGM2_3.ikw")
    else:
        localIkWeight = None

    if args.vskFile:
        vsk = vskTools.Vsk(str(DATA_PATH + args.vskFile))
    else:
        vsk = None

    # --- Manager ----
    manager = ModelManager.CGM2_3ConfigManager(
        userSettings,
        localInternalSettings=internalSettings,
        localTranslators=translators,
        localIkWeight=localIkWeight,
        vsk=vsk)
    manager.contruct()
    finalSettings = manager.getFinalSettings()
    files.prettyDictPrint(finalSettings)

    logging.info("=============Calibration=============")
    model, finalAcqStatic = cgm2_3.calibrate(DATA_PATH,
                                             manager.staticTrial,
                                             manager.translators,
                                             finalSettings,
                                             manager.requiredMp,
                                             manager.optionalMp,
                                             manager.enableIK,
                                             manager.leftFlatFoot,
                                             manager.rightFlatFoot,
                                             manager.headFlat,
                                             manager.markerDiameter,
                                             manager.hjcMethod,
                                             manager.pointSuffix,
                                             displayCoordinateSystem=True)

    btkTools.smartWriter(
        finalAcqStatic,
        str(DATA_PATH + finalSettings["Calibration"]["StaticTrial"][:-4] +
            "-pyCGM2modelled.c3d"))
    logging.info("Static Calibration -----> Done")

    manager.updateMp(model)
    #files.prettyDictPrint(manager.finalSettings)

    logging.info("=============Fitting=============")
    for trial in manager.dynamicTrials:
        mfpa = None if trial["Mfpa"] == "Auto" else trial["Mfpa"]
        reconstructFilenameLabelled = trial["File"]

        acqGait = cgm2_3.fitting(model,
                                 DATA_PATH,
                                 reconstructFilenameLabelled,
                                 manager.translators,
                                 finalSettings,
                                 manager.enableIK,
                                 manager.markerDiameter,
                                 manager.pointSuffix,
                                 mfpa,
                                 manager.momentProjection,
                                 displayCoordinateSystem=True)

        btkTools.smartWriter(
            acqGait,
            str(DATA_PATH + reconstructFilenameLabelled[:-4] +
                "-pyCGM2modelled.c3d"))
        logging.info("---->dynamic trial (%s) processed" %
                     (reconstructFilenameLabelled))

    logging.info("=============Writing of final Settings=============")
    i = 0
    while os.path.exists("CGM2.3 [%s].completeSettings" % i):
        i += 1
    filename = "CGM2.3 [" + str(i) + "].completeSettings"
    files.saveJson(DATA_PATH, filename, finalSettings)
    logging.info("---->complete settings (%s) exported" % (filename))

    raw_input("Press return to exit..")
Esempio n. 4
0
def getCGMmanager(CGMversion,
                  userSettings,
                  internalSettings=None,
                  translators=None,
                  localIkWeight=None,
                  vsk=None):
    """
    return CGM settings

    :param CGMversion [str]:  CGM version name
    :param userSettings [dict]:  content of the userSettings yaml file


    **optional**
    :param internalSettings [dict]: content of the internalSettings yaml file
    :param translators [dict]: content of the translators file
    :param localIkWeight [dict]: content of the localIkweight file
    :param vsk [file]: vsk file

    **Return**
    :param [dict]:  eventual CGM settings

    """

    # --- Manager ----
    if model == "CGM1.0":
        manager = ModelManager.CGM1ConfigManager(
            userSettings,
            localInternalSettings=internalSettings,
            localTranslators=translators,
            localIkWeight=localIkWeight,
            vsk=vsk)

    elif model == "CGM1.1":
        manager = ModelManager.CGM1_1ConfigManager(
            userSettings,
            localInternalSettings=internalSettings,
            localTranslators=translators,
            localIkWeight=localIkWeight,
            vsk=vsk)

    elif model == "CGM2.1":
        manager = ModelManager.CGM2_1ConfigManager(
            userSettings,
            localInternalSettings=internalSettings,
            localTranslators=translators,
            localIkWeight=localIkWeight,
            vsk=vsk)

    elif model == "CGM2.2":
        manager = ModelManager.CGM2_2ConfigManager(
            userSettings,
            localInternalSettings=internalSettings,
            localTranslators=translators,
            localIkWeight=localIkWeight,
            vsk=vsk)

    elif model == "CGM2.3":
        manager = ModelManager.CGM2_3ConfigManager(
            userSettings,
            localInternalSettings=internalSettings,
            localTranslators=translators,
            localIkWeight=localIkWeight,
            vsk=vsk)

    elif model == "CGM2.4":
        manager = ModelManager.CGM2_4ConfigManager(
            userSettings,
            localInternalSettings=internalSettings,
            localTranslators=translators,
            localIkWeight=localIkWeight,
            vsk=vsk)

    elif model == "CGM2.5":
        manager = ModelManager.CGM2_5ConfigManager(
            userSettings,
            localInternalSettings=internalSettings,
            localTranslators=translators,
            localIkWeight=localIkWeight,
            vsk=vsk)
    else:
        raise Exception(
            "[pyCGM2] : Model version not known (choice CGM1.0 to CGM2.5 )")

    manager.contruct()

    return manager