Пример #1
0
    def KadMed_TrueEquinus(cls):
        DATA_PATH = pyCGM2.TEST_DATA_PATH + "CGM1\\CGM1-TESTS\\kad-med-TrueEquinus\\"
        staticFilename = "static.c3d"


        markerDiameter=14
        required_mp={
        'Bodymass'   : 36.9,
        'LeftLegLength' : 665.0,
        'RightLegLength' : 655.0 ,
        'LeftKneeWidth' : 102.7,
        'RightKneeWidth' : 100.2,
        'LeftAnkleWidth' : 64.5,
        'RightAnkleWidth' : 63.0,
        'LeftSoleDelta' : 0,
        'RightSoleDelta' : 0,
        }

        optional_mp={
        'InterAsisDistance'   : 0,
        'LeftAsisTrocanterDistance' : 0,
        'LeftThighRotation' : 0,
        'LeftShankRotation' : 0 ,
        'LeftTibialTorsion' : 0,
        'RightAsisTrocanterDistance' : 0,
        'RightThighRotation' : 0,
        'RightShankRotation' : 0,
        'RightTibialTorsion' : 0
        }


        #import ipdb; ipdb.set_trace()
        settings = files.openJson(pyCGM2.PYCGM2_APPDATA_PATH,"CGM1_1-pyCGM2.settings")
        translators = settings["Translators"]

        pointSuffix = "cgm1_6dof"

        model,acqStatic = cgm1_1.calibrate(DATA_PATH,staticFilename,translators,
                                   required_mp,optional_mp,
                                   False,False,markerDiameter,
                                   pointSuffix)


        btkTools.smartWriter(acqStatic,"CGM11-KadMed-TrueEquinus-static.c3d")


        #motion
        gaitFilename="gait trial 01.c3d"
        mfpa  = None
        momentProjection=enums.MomentProjection.Distal

        acqGait = cgm1_1.fitting(model,DATA_PATH, gaitFilename,
                 translators,
                 markerDiameter,
                 pointSuffix,
                 mfpa,
                 momentProjection)


        mcsp = modelFilters.ModelCoordinateSystemProcedure(model)
        mcsf = modelFilters.CoordinateSystemDisplayFilter(mcsp,model,acqGait)
        mcsf.setStatic(False)
        mcsf.display()

        btkTools.smartWriter(acqGait, "CGM11-KadMed-TrueEquinus-gait.c3d")


        # testings
        offsetTesting(acqStatic,model,display = True, unitTesting=False)

        testJointCentres(acqGait)
Пример #2
0
    # check model is the CGM1
    logging.info("loaded model : %s" % (model.version))
    if model.version != "CGM1.1":
        raise Exception(
            "%s-pyCGM2.model file was not calibrated from the CGM1.1 calibration pipeline"
            % model.version)

        # --------------------------SESSION INFOS ------------------------------------

    #  translators management
    translators = files.getTranslators(DATA_PATH, "CGM1_1.translators")
    if not translators: translators = settings["Translators"]

    # --------------------------MODELLING PROCESSING -----------------------
    acqGait = cgm1_1.fitting(model, DATA_PATH, reconstructFilenameLabelled,
                             translators, markerDiameter, pointSuffix, mfpa,
                             momentProjection)

    # ----------------------SAVE-------------------------------------------
    # Todo: pyCGM2 model :  cpickle doesn t work. Incompatibility with Swig. ( see about BTK wrench)

    # new static file
    if args.fileSuffix is not None:
        btkTools.smartWriter(
            acqGait,
            str(DATA_PATH + reconstructFilenameLabelled[:-4] + "-modelled-" +
                args.fileSuffix + ".c3d"))
    else:
        btkTools.smartWriter(
            acqGait,
            str(DATA_PATH + reconstructFilenameLabelled[:-4] +
Пример #3
0
def modelling(manager,DATA_PATH,DATA_PATH_OUT,vskFile=None):
    modelVersion = manager.getModelVersion()
    logging.info("model version : %s" %(modelVersion))

    # --------------------------MODELLING ------------------------------------

    # manage global settings and translators
    if modelVersion == "CGM1.0":
        translatorFiles=  "CGM1.translators"
        globalPyCGM2settingFile = "CGM1-pyCGM2.settings"
    elif modelVersion == "CGM1.1":
        translatorFiles=  "CGM1_1.translators"
        globalPyCGM2settingFile = "CGM1_1-pyCGM2.settings"
    elif modelVersion == "CGM2.1":
        translatorFiles=  "CGM2_1.translators"
        globalPyCGM2settingFile = "CGM2_1-pyCGM2.settings"
    elif modelVersion == "CGM2.2":
        translatorFiles=  "CGM2_2.translators"
        globalPyCGM2settingFile = "CGM2_2-pyCGM2.settings"
    elif modelVersion == "CGM2.2e":
        translatorFiles=  "CGM2_2.translators"
        globalPyCGM2settingFile = "CGM2_2-Expert-pyCGM2.settings"
    elif modelVersion == "CGM2.3":
        translatorFiles=  "CGM2_3.translators"
        globalPyCGM2settingFile = "CGM2_3-pyCGM2.settings"
    elif modelVersion == "CGM2.3e":
        translatorFiles=  "CGM2_3.translators"
        globalPyCGM2settingFile = "CGM2_3-Expert-pyCGM2.settings"
    elif modelVersion == "CGM2.4":
        translatorFiles=  "CGM2_4.translators"
        globalPyCGM2settingFile = "CGM2_4-pyCGM2.settings"
    elif modelVersion == "CGM2.4e":
        translatorFiles=  "CGM2_4.translators"
        globalPyCGM2settingFile = "CGM2_4-Expert-pyCGM2.settings"

    else:
        raise Exception( "model version not known")

    settings = files.openJson(pyCGM2.PYCGM2_APPDATA_PATH,globalPyCGM2settingFile)
    translators = files.getTranslators(DATA_PATH,translatorFiles)
    if not translators: translators = settings["Translators"]

    # mp file
    if vskFile is None:
        logging.info("mp from pipeline file")
        required_mp,optional_mp = manager.getMP()
    else:
        logging.warning("mp from vsk file")
        vsk = vskTools.Vsk(str(DATA_PATH + vskFile))
        required_mp,optional_mp = vskTools.getFromVskSubjectMp(vsk, resetFlag=True)


    fileSuffix = manager.getFileSuffix()
    pointSuffix = manager.getPointSuffix()
    ik_flag = manager.isIkFitting()

    #------calibration--------
    leftFlatFoot = manager.getLeftFlatFoot()
    rightFlatFoot = manager.getRightFlatFoot()
    markerDiameter = manager.getMarkerDiameter()
    calibrateFilenameLabelled = manager.getStaticTial()

    if modelVersion == "CGM1.0":
        model,finalAcqStatic = cgm1.calibrate(DATA_PATH,calibrateFilenameLabelled,translators,required_mp,optional_mp,
               leftFlatFoot,rightFlatFoot,markerDiameter,
               pointSuffix)
    elif modelVersion == "CGM1.1":
        model,finalAcqStatic = cgm1_1.calibrate(DATA_PATH,calibrateFilenameLabelled,translators,required_mp,optional_mp,
               leftFlatFoot,rightFlatFoot,markerDiameter,
               pointSuffix)
    elif modelVersion == "CGM2.1":

        hjcMethods = manager.getHJC()
        hjcMethods["Left"] = "Hara" if hjcMethods["Left"] == [] else hjcMethods["Left"]
        hjcMethods["Right"] = "Hara" if hjcMethods["Right"] == [] else hjcMethods["Right"]
        model,finalAcqStatic = cgm2_1.calibrate(DATA_PATH,calibrateFilenameLabelled,translators,required_mp,optional_mp,
                      leftFlatFoot,rightFlatFoot,markerDiameter,hjcMethods,
                      pointSuffix)

    elif modelVersion == "CGM2.2":
        hjcMethods = manager.getHJC()
        hjcMethods["Left"] = "Hara" if hjcMethods["Left"] == [] else hjcMethods["Left"]
        hjcMethods["Right"] = "Hara" if hjcMethods["Right"] == [] else hjcMethods["Right"]
        model,finalAcqStatic = cgm2_2.calibrate(DATA_PATH,calibrateFilenameLabelled,translators,settings,
                          required_mp,optional_mp,
                          True,leftFlatFoot,rightFlatFoot,markerDiameter,hjcMethods,
                          pointSuffix)

    elif modelVersion == "CGM2.2e":
        hjcMethods =  manager.getHJC()
        hjcMethods["Left"] = "Hara" if hjcMethods["Left"] == [] else hjcMethods["Left"]
        hjcMethods["Right"] = "Hara" if hjcMethods["Right"] == [] else hjcMethods["Right"]
        model,finalAcqStatic = cgm2_2e.calibrate(DATA_PATH,calibrateFilenameLabelled,translators,settings,
                          required_mp,optional_mp,
                          True,leftFlatFoot,rightFlatFoot,markerDiameter,hjcMethods,
                          pointSuffix)

    elif modelVersion == "CGM2.3":
        hjcMethods = manager.getHJC()
        hjcMethods["Left"] = "Hara" if hjcMethods["Left"] == [] else hjcMethods["Left"]
        hjcMethods["Right"] = "Hara" if hjcMethods["Right"] == [] else hjcMethods["Right"]
        model,finalAcqStatic = cgm2_3.calibrate(DATA_PATH,calibrateFilenameLabelled,translators,settings,
                                  required_mp,optional_mp,
                                  ik_flag,leftFlatFoot,rightFlatFoot,markerDiameter,hjcMethods,
                                  pointSuffix)

    elif modelVersion == "CGM2.3e":
        hjcMethods = manager.getHJC()
        hjcMethods["Left"] = "Hara" if hjcMethods["Left"] == [] else hjcMethods["Left"]
        hjcMethods["Right"] = "Hara" if hjcMethods["Right"] == [] else hjcMethods["Right"]
        model,finalAcqStatic = cgm2_3e.calibrate(DATA_PATH,calibrateFilenameLabelled,translators,settings,
                                  required_mp,optional_mp,
                                  ik_flag,leftFlatFoot,rightFlatFoot,markerDiameter,hjcMethods,
                                  pointSuffix)

    elif modelVersion == "CGM2.4":
        hjcMethods = manager.getHJC()
        hjcMethods["Left"] = "Hara" if hjcMethods["Left"] == [] else hjcMethods["Left"]
        hjcMethods["Right"] = "Hara" if hjcMethods["Right"] == [] else hjcMethods["Right"]
        model,finalAcqStatic = cgm2_4.calibrate(DATA_PATH,calibrateFilenameLabelled,translators,settings,
                                  required_mp,optional_mp,
                                  ik_flag,leftFlatFoot,rightFlatFoot,markerDiameter,hjcMethods,
                                  pointSuffix)

    elif modelVersion == "CGM2.4e":
        hjcMethods = manager.getHJC()
        hjcMethods["Left"] = "Hara" if hjcMethods["Left"] == [] else hjcMethods["Left"]
        hjcMethods["Right"] = "Hara" if hjcMethods["Right"] == [] else hjcMethods["Right"]
        model,finalAcqStatic = cgm2_4e.calibrate(DATA_PATH,calibrateFilenameLabelled,translators,settings,
                                  required_mp,optional_mp,
                                  ik_flag,leftFlatFoot,rightFlatFoot,markerDiameter,hjcMethods,
                                  pointSuffix)

    btkTools.smartWriter(finalAcqStatic, str(DATA_PATH_OUT+"calibrated.c3d"))
    logging.info("Static Calibration -----> Done")

    # knee calibration
    leftEnable = manager.isKneeCalibrationEnable("Left")
    rightEnable = manager.isKneeCalibrationEnable("Right")

    if leftEnable:
        method, trial,begin,end,jointRange = manager.getKneeCalibration("Left")
        if method == "Calibration2Dof":
            model,acqFunc,side = kneeCalibration.calibration2Dof(model,
                DATA_PATH,trial,translators,
                "Left",begin,end,jointRange)

            logging.info("Left knee Calibration (Calibration2Dof) -----> Done")
        elif method == "SARA":
            model,acqFunc,side = kneeCalibration.sara(model,
                DATA_PATH,trial,translators,
                "Left",begin,end)
            logging.info("Left knee Calibration (SARA) -----> Done")
    if rightEnable:
        method, trial,begin,end,jointRange = manager.getKneeCalibration("Right")
        if method == "Calibration2Dof":
            model,acqFunc,side = kneeCalibration.calibration2Dof(model,
                DATA_PATH,trial,translators,
                "Right",begin,end,jointRange)
            logging.info("Right knee Calibration (Calibration2Dof) -----> Done")
        elif method == "SARA":
            model,acqFunc,side = kneeCalibration.sara(model,
                DATA_PATH,trial,translators,
                "Right",begin,end)
            logging.info("Right knee Calibration (SARA) -----> Done")

    # update mp
    manager.updateMp(model)
    # save settings
    if manager.m_pipelineFile is not None:
        manager.save(DATA_PATH,str( manager.m_pipelineFile+"-saved"))
        logging.info("pipeline file -----> Save")

    # Fitting
    trials = manager.getFittingTrials()
    momentProjection = manager.getMomentProjection()

    if modelVersion not in ["CGM1.0", "CGM1.1", "CGM2.1"]:
        ikwf = manager.getIkWeightFile()
        if ikwf is not None:
            ikWeight = files.openJson(DATA_PATH,ikwf)
            settings["Fitting"]["Weight"]=ikWeight["Weight"]


    for trial in trials:
        mfpa = None if trial["Mfpa"] == "Auto" else trial["Mfpa"]

        reconstructFilenameLabelled = trial["File"]


        if modelVersion == "CGM1.0":
            acqGait = cgm1.fitting(model,DATA_PATH, reconstructFilenameLabelled,
                translators,
                markerDiameter,
                pointSuffix,
                mfpa,momentProjection)
        elif modelVersion == "CGM1.1":
            acqGait = cgm1_1.fitting(model,DATA_PATH, reconstructFilenameLabelled,
                translators,
                markerDiameter,
                pointSuffix,
                mfpa,momentProjection)

        elif modelVersion == "CGM2.1":
            acqGait = cgm2_1.fitting(model,DATA_PATH, reconstructFilenameLabelled,
                translators,
                markerDiameter,
                pointSuffix,
                mfpa,momentProjection)

        elif modelVersion == "CGM2.2":
            acqGait = cgm2_2.fitting(model,DATA_PATH, reconstructFilenameLabelled,
                    translators,settings,
                    markerDiameter,
                    pointSuffix,
                    mfpa,
                    momentProjection)

        elif modelVersion == "CGM2.2e":
            acqGait = cgm2_2e.fitting(model,DATA_PATH, reconstructFilenameLabelled,
                    translators,settings,
                    markerDiameter,
                    pointSuffix,
                    mfpa,
                    momentProjection)

        elif modelVersion == "CGM2.3":
            acqGait = cgm2_3.fitting(model,DATA_PATH, reconstructFilenameLabelled,
                    translators,settings,
                    ik_flag,markerDiameter,
                    pointSuffix,
                    mfpa,
                    momentProjection)

        elif modelVersion == "CGM2.3e":
            acqGait = cgm2_3e.fitting(model,DATA_PATH, reconstructFilenameLabelled,
                    translators,settings,
                    ik_flag,markerDiameter,
                    pointSuffix,
                    mfpa,
                    momentProjection)

        elif modelVersion == "CGM2.4":
            acqGait = cgm2_4.fitting(model,DATA_PATH, reconstructFilenameLabelled,
                    translators,settings,
                    ik_flag,markerDiameter,
                    pointSuffix,
                    mfpa,
                    momentProjection)

        elif modelVersion == "CGM2.4e":
            acqGait = cgm2_4e.fitting(model,DATA_PATH, reconstructFilenameLabelled,
                    translators,settings,
                    ik_flag,markerDiameter,
                    pointSuffix,
                    mfpa,
                    momentProjection)

        logging.info("Fitting -----> Done")


        if fileSuffix is not None:
            c3dFilename = str(reconstructFilenameLabelled[:-4]+"-modelled-"+fileSuffix+".c3d")
        else:
            c3dFilename = str(reconstructFilenameLabelled[:-4]+"-modelled.c3d")

        btkTools.smartWriter(acqGait, str(DATA_PATH_OUT+c3dFilename))
        logging.info("c3d file (%s) generated" %(c3dFilename) )