示例#1
0
def applyDecorators_CGM1(smc, model,acqStatic,optional_mp,markerDiameter):

    # native but thighRotation altered in mp
    if smc["left"] == enums.CgmStaticMarkerConfig.Native and optional_mp["LeftThighRotation"] !=0:
        logging.warning("CASE FOUND ===> Left Side = NATIVE CGM1 + manual Thigh  ")
        modelDecorator.Cgm1ManualOffsets(model).compute(acqStatic,"left",optional_mp["LeftThighRotation"],
            markerDiameter, optional_mp["LeftTibialTorsion"], optional_mp["LeftShankRotation"])

    if smc["right"] == enums.CgmStaticMarkerConfig.Native and optional_mp["RightThighRotation"] !=0:
        logging.warning("CASE FOUND ===> Right Side = NATIVE CGM1 + manual Thigh  ")
        modelDecorator.Cgm1ManualOffsets(model).compute(acqStatic,"right",optional_mp["RightThighRotation"],
            markerDiameter,optional_mp["RightTibialTorsion"],optional_mp["RightShankRotation"])

    # KAD
    if smc["left"] == enums.CgmStaticMarkerConfig.KAD:
        logging.warning("CASE FOUND ===> Left Side = KAD")
        modelDecorator.Kad(model,acqStatic).compute(markerDiameter=markerDiameter, side="left")

    if smc["right"] == enums.CgmStaticMarkerConfig.KAD:
        logging.warning("CASE FOUND ===> Right Side = KAD")
        modelDecorator.Kad(model,acqStatic).compute(markerDiameter=markerDiameter, side="right")

    # KADmed
    if smc["left"] == enums.CgmStaticMarkerConfig.KADmed:
        logging.warning("CASE FOUND ===> Left Side = KAD+med")
        modelDecorator.Kad(model,acqStatic).compute(markerDiameter=markerDiameter, side="left")
        modelDecorator.AnkleCalibrationDecorator(model).midMaleolus(acqStatic, markerDiameter=markerDiameter, side="left")

    if smc["right"] == enums.CgmStaticMarkerConfig.KADmed:
        logging.warning("CASE FOUND ===> Right Side = KAD+med")
        modelDecorator.Kad(model,acqStatic).compute(markerDiameter=markerDiameter, side="right")
        modelDecorator.AnkleCalibrationDecorator(model).midMaleolus(acqStatic, markerDiameter=markerDiameter, side="right")
示例#2
0
def applyBasicDecorators(dcm, model,acqStatic,optional_mp,markerDiameter,cgm1only=False):

    # native but thighRotation altered in mp
    if dcm["Left Knee"] == enums.JointCalibrationMethod.Basic and  dcm["Left Ankle"] == enums.JointCalibrationMethod.Basic and optional_mp["LeftThighRotation"] !=0:
        logging.warning("CASE FOUND ===> Left Side = NATIVE CGM1 + manual Thigh  ")
        modelDecorator.Cgm1ManualOffsets(model).compute(acqStatic,"left",optional_mp["LeftThighRotation"],
            markerDiameter, optional_mp["LeftTibialTorsion"], optional_mp["LeftShankRotation"])

    if dcm["Right Knee"] == enums.JointCalibrationMethod.Basic and  dcm["Right Ankle"] == enums.JointCalibrationMethod.Basic and optional_mp["RightThighRotation"] !=0:
        logging.warning("CASE FOUND ===> Right Side = NATIVE CGM1 + manual Thigh  ")
        modelDecorator.Cgm1ManualOffsets(model).compute(acqStatic,"right",optional_mp["RightThighRotation"],
            markerDiameter,optional_mp["RightTibialTorsion"],optional_mp["RightShankRotation"])

    # KAD - and Kadmed
    if dcm["Left Knee"] == enums.JointCalibrationMethod.KAD:
        logging.warning("CASE FOUND ===> Left Side = KAD")
        modelDecorator.Kad(model,acqStatic).compute(markerDiameter=markerDiameter, side="left")
        if  dcm["Left Ankle"] == enums.JointCalibrationMethod.Medial:
            modelDecorator.AnkleCalibrationDecorator(model).midMaleolus(acqStatic, markerDiameter=markerDiameter, side="left")

    if dcm["Right Knee"] == enums.JointCalibrationMethod.KAD:
        logging.warning("CASE FOUND ===> Right Side = KAD")
        modelDecorator.Kad(model,acqStatic).compute(markerDiameter=markerDiameter, side="right")
        if  dcm["Right Ankle"] == enums.JointCalibrationMethod.Medial:
            modelDecorator.AnkleCalibrationDecorator(model).midMaleolus(acqStatic, markerDiameter=markerDiameter, side="right")

    if not cgm1only:

        #Kad-like (KneeMed)
        if dcm["Left Knee"] == enums.JointCalibrationMethod.Medial and dcm["Left Ankle"] == enums.JointCalibrationMethod.Basic:
            modelDecorator.KneeCalibrationDecorator(model).midCondyles_KAD(acqStatic, markerDiameter=markerDiameter, side="left")
        if dcm["Right Knee"] == enums.JointCalibrationMethod.Medial and dcm["Right Ankle"] == enums.JointCalibrationMethod.Basic:
            modelDecorator.KneeCalibrationDecorator(model).midCondyles_KAD(acqStatic, markerDiameter=markerDiameter, side="right")

        #knee and ankle Med
        if dcm["Left Knee"] == enums.JointCalibrationMethod.Medial and dcm["Left Ankle"] == enums.JointCalibrationMethod.Medial:
            modelDecorator.KneeCalibrationDecorator(model).midCondyles(acqStatic, markerDiameter=markerDiameter, side="left")
            modelDecorator.AnkleCalibrationDecorator(model).midMaleolus(acqStatic, markerDiameter=markerDiameter, side="left")

        if dcm["Right Knee"] == enums.JointCalibrationMethod.Medial and dcm["Right Ankle"] == enums.JointCalibrationMethod.Medial:
            modelDecorator.KneeCalibrationDecorator(model).midCondyles(acqStatic, markerDiameter=markerDiameter, side="right")
            modelDecorator.AnkleCalibrationDecorator(model).midMaleolus(acqStatic, markerDiameter=markerDiameter, side="right")
示例#3
0
    def advancedCGM11_KneeMedKad_TrueEquinus(cls):
        """


        """
        MAIN_PATH = pyCGM2.TEST_DATA_PATH + "CGM1\\CGM1-TESTS\\kad-med-TrueEquinus\\"
        staticFilename = "static.c3d"

        acqStatic = btkTools.smartReader(str(MAIN_PATH + staticFilename))

        model = cgm.CGM1
        model.configure()
        markerDiameter = 14
        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
        }

        model.addAnthropoInputParameters(mp, optional=optional_mp)

        # -----------CGM STATIC CALIBRATION--------------------
        scp = modelFilters.StaticCalibrationProcedure(model)
        modelFilters.ModelCalibrationFilter(scp, acqStatic, model).compute()

        # cgm decorator

        modelDecorator.Kad(model, acqStatic).compute()
        modelDecorator.AnkleCalibrationDecorator(model).midMaleolus(
            acqStatic, side="both")

        modelFilters.ModelCalibrationFilter(scp, acqStatic, model).compute()

        btkTools.smartWriter(acqStatic, "Kad-med-TrueEquinus.c3d")
示例#4
0
    def advancedCGM1_kadMed_manualTibialTorsion(cls):
        """
        - constraints on both tibial Torsion But application of a KAD-med calibration
        => tibial Torsion has to be udpated

        """
        MAIN_PATH = pyCGM2.TEST_DATA_PATH + "CGM1\\CGM1-TESTS\\KAD-Med\\"
        staticFilename = "MRI-US-01, 2008-08-08, 3DGA 02.c3d"

        acqStatic = btkTools.smartReader(str(MAIN_PATH +  staticFilename))

        model=cgm.CGM1LowerLimbs()
        model.configure()
        markerDiameter=14
        mp={
        'Bodymass'   : 71.0,
        'LeftLegLength' : 860.0,
        'RightLegLength' : 865.0 ,
        'LeftKneeWidth' : 102.0,
        'RightKneeWidth' : 103.4,
        'LeftAnkleWidth' : 75.3,
        'RightAnkleWidth' : 72.9,
        'LeftSoleDelta' : 0,
        'RightSoleDelta' : 0,
        }

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

        model.addAnthropoInputParameters(mp,optional=optional_mp)

        # -----------CGM STATIC CALIBRATION--------------------
        scp=modelFilters.StaticCalibrationProcedure(model)
        modelFilters.ModelCalibrationFilter(scp,acqStatic,model).compute()

        # cgm decorator
        modelDecorator.Kad(model,acqStatic).compute()
        modelDecorator.AnkleCalibrationDecorator(model).midMaleolus(acqStatic, side="both")

        modelFilters.ModelCalibrationFilter(scp,acqStatic,model).compute()


        np.testing.assert_equal(model.m_useRightTibialTorsion,True )
        np.testing.assert_equal(model.m_useLeftTibialTorsion,True )
        np.testing.assert_equal(model.mp["LeftTibialTorsion"],0 ) # cancel by the decorator
        np.testing.assert_equal(model.mp["RightTibialTorsion"],0)


        ltt_vicon = np.rad2deg(acqStatic.GetMetaData().FindChild("PROCESSING").value().FindChild("LTibialTorsion").value().GetInfo().ToDouble()[0])
        rtt_vicon =np.rad2deg(acqStatic.GetMetaData().FindChild("PROCESSING").value().FindChild("RTibialTorsion").value().GetInfo().ToDouble()[0])

        np.testing.assert_almost_equal(-1.0*model.mp_computed["LeftTibialTorsionOffset"],ltt_vicon, decimal = 3)
        np.testing.assert_almost_equal(model.mp_computed["RightTibialTorsionOffset"],rtt_vicon, decimal = 3)
示例#5
0
    def kadMedCGM1_proximal(cls, plotFlag=False):

        MAIN_PATH = pyCGM2.TEST_DATA_PATH + "CGM1\\PIG advanced\\KAD-tibialTorsion\\"
        staticFilename = "MRI-US-01, 2008-08-08, 3DGA 02.c3d"

        acqStatic = btkTools.smartReader(str(MAIN_PATH + staticFilename))

        model = cgm.CGM1
        model.configure()

        markerDiameter = 14
        mp = {
            'Bodymass': 71.0,
            'LeftLegLength': 860.0,
            'RightLegLength': 865.0,
            'LeftKneeWidth': 102.0,
            'RightKneeWidth': 103.4,
            'LeftAnkleWidth': 75.3,
            'RightAnkleWidth': 72.9,
            'LeftSoleDelta': 0,
            'RightSoleDelta': 0,
        }
        model.addAnthropoInputParameters(mp)

        scp = modelFilters.StaticCalibrationProcedure(model)
        modelFilters.ModelCalibrationFilter(scp, acqStatic, model).compute()

        # cgm decorator
        modelDecorator.Kad(model, acqStatic).compute()
        modelDecorator.AnkleCalibrationDecorator(model).midMaleolus(
            acqStatic, side="both")

        modelFilters.ModelCalibrationFilter(scp, acqStatic, model).compute()

        # ------ Test 1 Motion Axe X -------
        gaitFilename = "MRI-US-01, 2008-08-08, 3DGA 14.Proximal.c3d"
        acqGait = btkTools.smartReader(str(MAIN_PATH + gaitFilename))

        # Motion FILTER
        # optimisation segmentaire et calibration fonctionnel
        modMotion = modelFilters.ModelMotionFilter(
            scp,
            acqGait,
            model,
            pyCGM2Enums.motionMethod.Determinist,
            viconCGM1compatible=False)
        modMotion.compute()

        # Joint kinematics
        modelFilters.ModelJCSFilter(model, acqGait).compute(
            description="vectoriel", pointLabelSuffix="cgm1_6dof")

        # BSP model
        bspModel = bodySegmentParameters.Bsp(model)
        bspModel.compute()

        # force plate -- construction du wrench attribue au pied
        forceplates.appendForcePlateCornerAsMarker(acqGait)
        mappedForcePlate = forceplates.matchingFootSideOnForceplate(acqGait)
        modelFilters.ForcePlateAssemblyFilter(
            model,
            acqGait,
            "RL",
            leftSegmentLabel="Left Foot",
            rightSegmentLabel="Right Foot").compute()

        idp = modelFilters.CGMLowerlimbInverseDynamicProcedure()
        modelFilters.InverseDynamicFilter(
            model,
            acqGait,
            procedure=idp,
            projection=pyCGM2Enums.MomentProjection.Proximal,
            viconCGM1compatible=True).compute(pointLabelSuffix="cgm1_6dof")

        modelFilters.JointPowerFilter(
            model, acqGait).compute(pointLabelSuffix="cgm1_6dof")

        # writer
        btkTools.smartWriter(acqGait, "testInvDyn_kadMed.c3d")

        if plotFlag:
            plotMoment(acqGait, "LAnkleMoment", "LAnkleMoment_cgm1_6dof",
                       "kadMedCGM1_proximal-LAnkleMoment")
            plotMoment(acqGait, "RAnkleMoment", "RAnkleMoment_cgm1_6dof",
                       "kadMedCGM1_proximal-RAnkleMoment")
            plt.show()
示例#6
0
    def advancedCGM1_kad_manualTibialTorsion(cls):

        MAIN_PATH = pyCGM2.TEST_DATA_PATH + "CGM1\\CGM1-TESTS\\KAD-manualTibialTorsion\\"
        staticFilename = "MRI-US-01, 2008-08-08, 3DGA 02.c3d"

        acqStatic = btkTools.smartReader(str(MAIN_PATH +  staticFilename))

        model=cgm.CGM1
        model.configure()

        markerDiameter=14
        mp={
        'Bodymass'   : 71.0,
        'LeftLegLength' : 860.0,
        'RightLegLength' : 865.0 ,
        'LeftKneeWidth' : 102.0,
        'RightKneeWidth' : 103.4,
        'LeftAnkleWidth' : 75.3,
        'RightAnkleWidth' : 72.9,
        'LeftSoleDelta' : 0,
        'RightSoleDelta' : 0,
        }

        optional_mp={
        'LeftTibialTorsion' : -30.0,
        'RightTibialTorsion' : -30.0
        }
        model.addAnthropoInputParameters(mp,optional=optional_mp)

        # -----------CGM STATIC CALIBRATION--------------------
        scp=modelFilters.StaticCalibrationProcedure(model)
        modelFilters.ModelCalibrationFilter(scp,acqStatic,model).compute()

        # cgm decorator
        modelDecorator.Kad(model,acqStatic).compute()

        modelFilters.ModelCalibrationFilter(scp,acqStatic,model,
                                            viconCGM1compatible=True).compute()

        # TESTS ------------------------------------------------
        # offset testing
        offsetTesting(acqStatic,model,display =True, unitTesting=True)


        # node description
        np.testing.assert_equal(model.getSegment("Left Thigh").getReferential("TF").static.getNode_byLabel("LKJC").m_desc ,"KAD")
        np.testing.assert_equal(model.getSegment("Right Thigh").getReferential("TF").static.getNode_byLabel("RKJC").m_desc ,"KAD")

        np.testing.assert_equal(model.getSegment("Left Shank").getReferential("TF").static.getNode_byLabel("LKJC").m_desc ,"KAD")
        np.testing.assert_equal(model.getSegment("Right Shank").getReferential("TF").static.getNode_byLabel("RKJC").m_desc ,"KAD")


        np.testing.assert_equal(model.getSegment("Left Shank").getReferential("TF").static.getNode_byLabel("LAJC").m_desc ,"KAD-manualTT")
        np.testing.assert_equal(model.getSegment("Right Shank").getReferential("TF").static.getNode_byLabel("RAJC").m_desc ,"KAD-manualTT")

        np.testing.assert_equal(model.getSegment("Left Foot").getReferential("TF").static.getNode_byLabel("LAJC").m_desc ,"KAD-manualTT")
        np.testing.assert_equal(model.getSegment("Right Foot").getReferential("TF").static.getNode_byLabel("RAJC").m_desc ,"KAD-manualTT")

        np.testing.assert_equal(model.m_useRightTibialTorsion,True )
        np.testing.assert_equal(model.m_useLeftTibialTorsion,True )

        # joint centres
        np.testing.assert_almost_equal(acqStatic.GetPoint("LFEP").GetValues().mean(axis=0),acqStatic.GetPoint("LHJC").GetValues().mean(axis=0),decimal = 3)
        np.testing.assert_almost_equal(acqStatic.GetPoint("RFEP").GetValues().mean(axis=0),acqStatic.GetPoint("RHJC").GetValues().mean(axis=0),decimal = 3)


        np.testing.assert_almost_equal(acqStatic.GetPoint("LFEO").GetValues().mean(axis=0),acqStatic.GetPoint("LKJC").GetValues().mean(axis=0),decimal = 3)
        np.testing.assert_almost_equal(acqStatic.GetPoint("RFEO").GetValues().mean(axis=0),acqStatic.GetPoint("RKJC").GetValues().mean(axis=0),decimal = 3)

        np.testing.assert_almost_equal(acqStatic.GetPoint("LTIO").GetValues().mean(axis=0),acqStatic.GetPoint("LAJC").GetValues().mean(axis=0),decimal = 3)
        np.testing.assert_almost_equal(acqStatic.GetPoint("RTIO").GetValues().mean(axis=0),acqStatic.GetPoint("RAJC").GetValues().mean(axis=0),decimal = 3)



        btkTools.smartWriter(acqStatic, "outStatic_advancedCGM1_kad_manualTibial.c3d")
示例#7
0
    def advancedCGM11_KadMed_TrueEquinus(cls):
        """


        """
        MAIN_PATH = pyCGM2.TEST_DATA_PATH + "CGM1\\CGM1-TESTS\\kad-med-TrueEquinus\\"
        staticFilename = "static.c3d"

        acqStatic = btkTools.smartReader(str(MAIN_PATH +  staticFilename))

        model=cgm.CGM1LowerLimbs()
        model.configure()
        markerDiameter=14
        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
        }

        model.addAnthropoInputParameters(mp,optional=optional_mp)

        # -----------CGM STATIC CALIBRATION--------------------
        scp=modelFilters.StaticCalibrationProcedure(model)
        modelFilters.ModelCalibrationFilter(scp,acqStatic,model).compute()

        # cgm decorator

        modelDecorator.Kad(model,acqStatic).compute()
        modelDecorator.AnkleCalibrationDecorator(model).midMaleolus(acqStatic, side="both")

        modelFilters.ModelCalibrationFilter(scp,acqStatic,model).compute()

        # tibial torsion
        ltt_vicon = np.rad2deg(acqStatic.GetMetaData().FindChild("PROCESSING").value().FindChild("LTibialTorsion").value().GetInfo().ToDouble()[0])
        rtt_vicon =np.rad2deg(acqStatic.GetMetaData().FindChild("PROCESSING").value().FindChild("RTibialTorsion").value().GetInfo().ToDouble()[0])


        logging.info(" LTibialTorsion : Vicon (%.6f)  Vs pyCGM2 (%.6f)" %(ltt_vicon,model.mp_computed["LeftTibialTorsionOffset"]))
        logging.info(" RTibialTorsion : Vicon (%.6f)  Vs pyCGM2 (%.6f)" %(rtt_vicon,model.mp_computed["RightTibialTorsionOffset"]))

         # thigh and shank Offsets
        lto = model.getViconThighOffset("Left")
        lso = model.getViconShankOffset("Left")
        rto = model.getViconThighOffset("Right")
        rso = model.getViconShankOffset("Right")

        lto_vicon = np.rad2deg(acqStatic.GetMetaData().FindChild("PROCESSING").value().FindChild("LThighRotation").value().GetInfo().ToDouble()[0])
        lso_vicon = np.rad2deg(acqStatic.GetMetaData().FindChild("PROCESSING").value().FindChild("LShankRotation").value().GetInfo().ToDouble()[0])

        rto_vicon = np.rad2deg(acqStatic.GetMetaData().FindChild("PROCESSING").value().FindChild("RThighRotation").value().GetInfo().ToDouble()[0])
        rso_vicon = np.rad2deg(acqStatic.GetMetaData().FindChild("PROCESSING").value().FindChild("RShankRotation").value().GetInfo().ToDouble()[0])

        logging.info(" LThighRotation : Vicon (%.6f)  Vs pyCGM2 (%.6f)" %(lto_vicon,lto))
        logging.info(" LShankRotation : Vicon (%.6f)  Vs pyCGM2 (%.6f)" %(lso_vicon,lso))
        logging.info(" RThighRotation : Vicon (%.6f)  Vs pyCGM2 (%.6f)" %(rto_vicon,rto))
        logging.info(" RShankRotation : Vicon (%.6f)  Vs pyCGM2 (%.6f)" %(rso_vicon,rso))

        btkTools.smartWriter(acqStatic,"Kad-med-TrueEquinus.c3d")


        gaitFilename="gait trial 01.c3d"
        acqGait = btkTools.smartReader(str(MAIN_PATH +  gaitFilename))


        # Motion FILTER
        # optimisation segmentaire et calibration fonctionnel
        modMotion=modelFilters.ModelMotionFilter(scp,acqGait,model,pyCGM2Enums.motionMethod.Determinist)
        modMotion.compute()

        # relative angles
        modelFilters.ModelJCSFilter(model,acqGait).compute(description="vectoriel", pointLabelSuffix="cgm1_6dof")


        # absolute angles
        longitudinalAxis,forwardProgression,globalFrame = btkTools.findProgressionAxisFromPelvicMarkers(acqGait,["LASI","LPSI","RASI","RPSI"])
        modelFilters.ModelAbsoluteAnglesFilter(model,acqGait,
                                      segmentLabels=["Left Foot","Right Foot","Pelvis"],
                                      angleLabels=["LFootProgress", "RFootProgress","Pelvis"],
                                      eulerSequences=["TOR","TOR", "TOR"],
                                      globalFrameOrientation = globalFrame,
                                      forwardProgression = forwardProgression).compute(pointLabelSuffix="cgm1_6dof")

        btkTools.smartWriter(acqGait, "Kad-med-TrueEquinus-angles.c3d")
示例#8
0
    def kad_midMaleolus(cls):
        """

        """

        MAIN_PATH = pyCGM2.TEST_DATA_PATH + "CGM1\\CGM1-TESTS\\KAD-Med\\"
        staticFilename = "MRI-US-01, 2008-08-08, 3DGA 02.c3d"

        acqStatic = btkTools.smartReader(str(MAIN_PATH +  staticFilename))

        model=cgm.CGM1LowerLimbs()
        model.configure()

        mp={
        'Bodymass'   : 71.0,
        'LeftLegLength' : 860.0,
        'RightLegLength' : 865.0 ,
        'LeftKneeWidth' : 102.0,
        'RightKneeWidth' : 103.4,
        'LeftAnkleWidth' : 75.3,
        'RightAnkleWidth' : 72.9,
        'LeftSoleDelta' : 0,
        'RightSoleDelta' : 0,
        }
        model.addAnthropoInputParameters(mp)

        scp=modelFilters.StaticCalibrationProcedure(model)
        modelFilters.ModelCalibrationFilter(scp,acqStatic,model).compute()

        # cgm decorator
        modelDecorator.Kad(model,acqStatic).compute()
        modelDecorator.AnkleCalibrationDecorator(model).midMaleolus(acqStatic, side="both")

        modelFilters.ModelCalibrationFilter(scp,acqStatic,model).compute()

        # tibial torsion
        ltt_vicon = np.rad2deg(acqStatic.GetMetaData().FindChild("PROCESSING").value().FindChild("LTibialTorsion").value().GetInfo().ToDouble()[0])
        rtt_vicon =np.rad2deg(acqStatic.GetMetaData().FindChild("PROCESSING").value().FindChild("RTibialTorsion").value().GetInfo().ToDouble()[0])


        logging.info(" LTibialTorsion : Vicon (%.6f)  Vs pyCGM2 (%.6f)" %(ltt_vicon,model.mp_computed["LeftTibialTorsionOffset"]))
        logging.info(" RTibialTorsion : Vicon (%.6f)  Vs pyCGM2 (%.6f)" %(rtt_vicon,model.mp_computed["RightTibialTorsionOffset"]))

        # foot offsets
        spf_l,sro_l = model.getViconFootOffset("Left")
        spf_r,sro_r = model.getViconFootOffset("Right")
        vicon_spf_l  = np.rad2deg(acqStatic.GetMetaData().FindChild("PROCESSING").value().FindChild("LStaticPlantFlex").value().GetInfo().ToDouble()[0])
        vicon_spf_r  = np.rad2deg(acqStatic.GetMetaData().FindChild("PROCESSING").value().FindChild("RStaticPlantFlex").value().GetInfo().ToDouble()[0])
        vicon_sro_l  = np.rad2deg(acqStatic.GetMetaData().FindChild("PROCESSING").value().FindChild("LStaticRotOff").value().GetInfo().ToDouble()[0])
        vicon_sro_r  = np.rad2deg(acqStatic.GetMetaData().FindChild("PROCESSING").value().FindChild("RStaticRotOff").value().GetInfo().ToDouble()[0])


        logging.info(" LStaticPlantFlex : Vicon (%.6f)  Vs bodyBuilderFoot (%.6f)" %(spf_l,vicon_spf_l))
        logging.info(" RStaticPlantFlex : Vicon (%.6f)  Vs bodyBuilderFoot (%.6f)" %(spf_r,vicon_spf_r))
        logging.info(" LStaticRotOff : Vicon (%.6f)  Vs bodyBuilderFoot (%.6f)" %(sro_l,vicon_sro_l))
        logging.info(" RStaticRotOff : Vicon (%.6f)  Vs bodyBuilderFoot (%.6f)" %(sro_r,vicon_sro_r))

         # thigh and shank Offsets
        lto = model.getViconThighOffset("Left")
        lso = model.getViconShankOffset("Left")
        rto = model.getViconThighOffset("Right")
        rso = model.getViconShankOffset("Right")

        lto_vicon = np.rad2deg(acqStatic.GetMetaData().FindChild("PROCESSING").value().FindChild("LThighRotation").value().GetInfo().ToDouble()[0])
        lso_vicon = np.rad2deg(acqStatic.GetMetaData().FindChild("PROCESSING").value().FindChild("LShankRotation").value().GetInfo().ToDouble()[0])

        rto_vicon = np.rad2deg(acqStatic.GetMetaData().FindChild("PROCESSING").value().FindChild("RThighRotation").value().GetInfo().ToDouble()[0])
        rso_vicon = np.rad2deg(acqStatic.GetMetaData().FindChild("PROCESSING").value().FindChild("RShankRotation").value().GetInfo().ToDouble()[0])



        logging.info(" LThighRotation : Vicon (%.6f)  Vs pyCGM2 (%.6f)" %(lto_vicon,lto))
        logging.info(" LShankRotation : Vicon (%.6f)  Vs pyCGM2 (%.6f)" %(lso_vicon,lso))
        logging.info(" RThighRotation : Vicon (%.6f)  Vs pyCGM2 (%.6f)" %(rto_vicon,rto))
        logging.info(" RShankRotation : Vicon (%.6f)  Vs pyCGM2 (%.6f)" %(rso_vicon,rso))


        # ------ Test 1 Motion Axe X -------
        gaitFilename="MRI-US-01, 2008-08-08, 3DGA 14.c3d"
        acqGait = btkTools.smartReader(str(MAIN_PATH +  gaitFilename))


        # Motion FILTER
        # optimisation segmentaire et calibration fonctionnel
        modMotion=modelFilters.ModelMotionFilter(scp,acqGait,model,pyCGM2Enums.motionMethod.Determinist)
        modMotion.compute()

        # relative angles
        modelFilters.ModelJCSFilter(model,acqGait).compute(description="vectoriel", pointLabelSuffix="cgm1_6dof")


        # absolute angles
        longitudinalAxis,forwardProgression,globalFrame = btkTools.findProgressionAxisFromPelvicMarkers(acqGait,["LASI","LPSI","RASI","RPSI"])
        modelFilters.ModelAbsoluteAnglesFilter(model,acqGait,
                                      segmentLabels=["Left Foot","Right Foot","Pelvis"],
                                      angleLabels=["LFootProgress", "RFootProgress","Pelvis"],
                                      eulerSequences=["TOR","TOR", "TOR"],
                                      globalFrameOrientation = globalFrame,
                                      forwardProgression = forwardProgression).compute(pointLabelSuffix="cgm1_6dof")

        btkTools.smartWriter(acqGait, "advancedCGM1_kad_midMaleolus-14.c3d")

        # tests on joint angles
        np.testing.assert_almost_equal( acqGait.GetPoint("RHipAngles").GetValues(),
                                        acqGait.GetPoint("RHipAngles_cgm1_6dof").GetValues(), decimal =3)

        np.testing.assert_almost_equal( acqGait.GetPoint("LHipAngles").GetValues(),
                                        acqGait.GetPoint("LHipAngles_cgm1_6dof").GetValues(), decimal =3)

        np.testing.assert_almost_equal( acqGait.GetPoint("RKneeAngles").GetValues(),
                                        acqGait.GetPoint("RKneeAngles_cgm1_6dof").GetValues(), decimal =2)

        np.testing.assert_almost_equal( acqGait.GetPoint("LKneeAngles").GetValues(),
                                        acqGait.GetPoint("LKneeAngles_cgm1_6dof").GetValues(), decimal =2)


        np.testing.assert_almost_equal( acqGait.GetPoint("RPelvisAngles").GetValues(),
                                        acqGait.GetPoint("RPelvisAngles_cgm1_6dof").GetValues(), decimal =3)
        np.testing.assert_almost_equal( acqGait.GetPoint("LPelvisAngles").GetValues(),
                                        acqGait.GetPoint("LPelvisAngles_cgm1_6dof").GetValues(), decimal =3)


#        # tests on angles influence by Vicon error
#        np.testing.assert_almost_equal( acqGait.GetPoint("RAnkleAngles").GetValues(),
#                                        acqGait.GetPoint("RAnkleAngles_cgm1_6dof").GetValues(), decimal =3)
#        np.testing.assert_almost_equal( acqGait.GetPoint("LAnkleAngles").GetValues(),
#                                        acqGait.GetPoint("LAnkleAngles_cgm1_6dof").GetValues(), decimal =3)
#
#        np.testing.assert_almost_equal( acqGait.GetPoint("LFootProgressAngles").GetValues(),
#                                        acqGait.GetPoint("LFootProgressAngles_cgm1_6dof").GetValues(), decimal =3)
#        np.testing.assert_almost_equal( acqGait.GetPoint("RFootProgressAngles").GetValues(),
#                                        acqGait.GetPoint("RFootProgressAngles_cgm1_6dof").GetValues(), decimal =3)


        # ------ Test 2 Motion Axe -X -------
        gaitFilename="MRI-US-01, 2008-08-08, 3DGA 12.c3d"
        acqGait = btkTools.smartReader(str(MAIN_PATH +  gaitFilename))


        # Motion FILTER
        # optimisation segmentaire et calibration fonctionnel
        modMotion=modelFilters.ModelMotionFilter(scp,acqGait,model,pyCGM2Enums.motionMethod.Determinist)
        modMotion.compute()

        # relative angles
        modelFilters.ModelJCSFilter(model,acqGait).compute(description="vectoriel", pointLabelSuffix="cgm1_6dof")

        # absolute angles
        longitudinalAxis,forwardProgression,globalFrame = btkTools.findProgressionAxisFromPelvicMarkers(acqGait,["LASI","LPSI","RASI","RPSI"])
        modelFilters.ModelAbsoluteAnglesFilter(model,acqGait,
                                      segmentLabels=["Left Foot","Right Foot","Pelvis"],
                                      angleLabels=["LFootProgress", "RFootProgress","Pelvis"],
                                      globalFrameOrientation = globalFrame,
                                      eulerSequences=["TOR","TOR", "TOR"],
                                      forwardProgression = forwardProgression).compute(pointLabelSuffix="cgm1_6dof")

       #btkTools.smartWriter(acqGait, "test.c3d")

        # tests on joint angles
        np.testing.assert_almost_equal( acqGait.GetPoint("RHipAngles").GetValues(),
                                        acqGait.GetPoint("RHipAngles_cgm1_6dof").GetValues(), decimal =3)

        np.testing.assert_almost_equal( acqGait.GetPoint("LHipAngles").GetValues(),
                                        acqGait.GetPoint("LHipAngles_cgm1_6dof").GetValues(), decimal =3)

        np.testing.assert_almost_equal( acqGait.GetPoint("RKneeAngles").GetValues(),
                                        acqGait.GetPoint("RKneeAngles_cgm1_6dof").GetValues(), decimal =2)

        np.testing.assert_almost_equal( acqGait.GetPoint("LKneeAngles").GetValues(),
                                        acqGait.GetPoint("LKneeAngles_cgm1_6dof").GetValues(), decimal =2)


        np.testing.assert_almost_equal( acqGait.GetPoint("RPelvisAngles").GetValues(),
                                        acqGait.GetPoint("RPelvisAngles_cgm1_6dof").GetValues(), decimal =3)
        np.testing.assert_almost_equal( acqGait.GetPoint("LPelvisAngles").GetValues(),
                                        acqGait.GetPoint("LPelvisAngles_cgm1_6dof").GetValues(), decimal =3)
示例#9
0
def applyBasicDecorators(dcm,
                         model,
                         acqStatic,
                         optional_mp,
                         markerDiameter,
                         cgm1only=False):
    if model.getBodyPart() != enums.BodyPart.UpperLimb:
        # native but thighRotation altered in mp
        if dcm["Left Knee"] == enums.JointCalibrationMethod.Basic and dcm[
                "Left Ankle"] == enums.JointCalibrationMethod.Basic and optional_mp[
                    "LeftThighRotation"] != 0:
            LOGGER.logger.debug(
                "CASE FOUND ===> Left Side = NATIVE CGM1 + manual Thigh  ")
            modelDecorator.Cgm1ManualOffsets(model).compute(
                acqStatic, "left", optional_mp["LeftThighRotation"],
                markerDiameter, optional_mp["LeftTibialTorsion"],
                optional_mp["LeftShankRotation"])

        if dcm["Right Knee"] == enums.JointCalibrationMethod.Basic and dcm[
                "Right Ankle"] == enums.JointCalibrationMethod.Basic and optional_mp[
                    "RightThighRotation"] != 0:
            LOGGER.logger.debug(
                "CASE FOUND ===> Right Side = NATIVE CGM1 + manual Thigh  ")
            modelDecorator.Cgm1ManualOffsets(model).compute(
                acqStatic, "right", optional_mp["RightThighRotation"],
                markerDiameter, optional_mp["RightTibialTorsion"],
                optional_mp["RightShankRotation"])

        # KAD - and Kadmed
        if dcm["Left Knee"] == enums.JointCalibrationMethod.KAD:
            LOGGER.logger.debug("CASE FOUND ===> Left Side = Knee-KAD")
            modelDecorator.Kad(model, acqStatic).compute(
                markerDiameter=markerDiameter, side="left")
            if dcm["Left Ankle"] == enums.JointCalibrationMethod.Medial:
                LOGGER.logger.debug("CASE FOUND ===> Left Side = Ankle-Med")
                modelDecorator.AnkleCalibrationDecorator(model).midMaleolus(
                    acqStatic, markerDiameter=markerDiameter, side="left")

        if dcm["Right Knee"] == enums.JointCalibrationMethod.KAD:
            LOGGER.logger.debug("CASE FOUND ===> Right Side = Knee-KAD")
            modelDecorator.Kad(model, acqStatic).compute(
                markerDiameter=markerDiameter, side="right")
            if dcm["Right Ankle"] == enums.JointCalibrationMethod.Medial:
                LOGGER.logger.debug("CASE FOUND ===> Right Side = Ankle-Med")
                modelDecorator.AnkleCalibrationDecorator(model).midMaleolus(
                    acqStatic, markerDiameter=markerDiameter, side="right")

    if not cgm1only:

        if model.getBodyPart() != enums.BodyPart.UpperLimb:
            #Kad-like (KneeMed)
            if dcm["Left Knee"] == enums.JointCalibrationMethod.Medial and dcm[
                    "Left Ankle"] == enums.JointCalibrationMethod.Basic:
                modelDecorator.KneeCalibrationDecorator(model).midCondyles_KAD(
                    acqStatic, markerDiameter=markerDiameter, side="left")
            if dcm["Right Knee"] == enums.JointCalibrationMethod.Medial and dcm[
                    "Right Ankle"] == enums.JointCalibrationMethod.Basic:
                modelDecorator.KneeCalibrationDecorator(model).midCondyles_KAD(
                    acqStatic, markerDiameter=markerDiameter, side="right")

            #knee and ankle Med
            if dcm["Left Knee"] == enums.JointCalibrationMethod.Medial and dcm[
                    "Left Ankle"] == enums.JointCalibrationMethod.Medial:
                LOGGER.logger.info(
                    "[pyCGM2] Left Knee : Medial - Left Ankle : Medial")
                modelDecorator.KneeCalibrationDecorator(model).midCondyles(
                    acqStatic, markerDiameter=markerDiameter, side="left")
                modelDecorator.AnkleCalibrationDecorator(model).midMaleolus(
                    acqStatic, markerDiameter=markerDiameter, side="left")

            if dcm["Right Knee"] == enums.JointCalibrationMethod.Medial and dcm[
                    "Right Ankle"] == enums.JointCalibrationMethod.Medial:
                LOGGER.logger.info(
                    "[pyCGM2] Right Knee : Medial - Right Ankle : Medial")
                modelDecorator.KneeCalibrationDecorator(model).midCondyles(
                    acqStatic, markerDiameter=markerDiameter, side="right")
                modelDecorator.AnkleCalibrationDecorator(model).midMaleolus(
                    acqStatic, markerDiameter=markerDiameter, side="right")
示例#10
0
    def basicCGM1_KAD_tibialTorsion(cls):

        MAIN_PATH = pyCGM2.TEST_DATA_PATH + "CGM1\\CGM1-TESTS\\KAD-tibialTorsion-static_StaticVsDynamicAngles\\"

        staticFilename = "MRI-US-01, 2008-08-08, 3DGA 02.c3d"

        acqStatic = btkTools.smartReader(str(MAIN_PATH + staticFilename))

        model = cgm.CGM1LowerLimbs()
        model.configure()
        markerDiameter = 14
        mp = {
            'Bodymass': 71.0,
            'LeftLegLength': 860.0,
            'RightLegLength': 865.0,
            'LeftKneeWidth': 102.0,
            'RightKneeWidth': 103.4,
            'LeftAnkleWidth': 75.3,
            'RightAnkleWidth': 72.9,
            'LeftSoleDelta': 0,
            'RightSoleDelta': 0,
        }
        model.addAnthropoInputParameters(mp)

        # -----------CGM STATIC CALIBRATION--------------------
        scp = modelFilters.StaticCalibrationProcedure(model)
        modelFilters.ModelCalibrationFilter(scp,
                                            acqStatic,
                                            model,
                                            leftFlatFoot=False,
                                            rightFlatFoot=False).compute()

        # cgm decorator
        modelDecorator.Kad(model, acqStatic).compute()
        modelDecorator.AnkleCalibrationDecorator(model).midMaleolus(
            acqStatic, side="both")

        # final calibration
        modelFilters.ModelCalibrationFilter(scp,
                                            acqStatic,
                                            model,
                                            leftFlatFoot=False,
                                            rightFlatFoot=False).compute()

        spf_l, sro_l = model.getViconFootOffset("Left")
        spf_r, sro_r = model.getViconFootOffset("Right")

        # TESTS ------------------------------------------------

        np.testing.assert_equal(model.m_useRightTibialTorsion, True)
        np.testing.assert_equal(model.m_useLeftTibialTorsion, True)

        # joint centres
        np.testing.assert_almost_equal(
            acqStatic.GetPoint("LFEP").GetValues().mean(axis=0),
            acqStatic.GetPoint("LHJC").GetValues().mean(axis=0),
            decimal=3)
        np.testing.assert_almost_equal(
            acqStatic.GetPoint("RFEP").GetValues().mean(axis=0),
            acqStatic.GetPoint("RHJC").GetValues().mean(axis=0),
            decimal=3)

        np.testing.assert_almost_equal(
            acqStatic.GetPoint("LFEO").GetValues().mean(axis=0),
            acqStatic.GetPoint("LKJC").GetValues().mean(axis=0),
            decimal=3)
        np.testing.assert_almost_equal(
            acqStatic.GetPoint("RFEO").GetValues().mean(axis=0),
            acqStatic.GetPoint("RKJC").GetValues().mean(axis=0),
            decimal=3)

        np.testing.assert_almost_equal(
            acqStatic.GetPoint("LTIO").GetValues().mean(axis=0),
            acqStatic.GetPoint("LAJC").GetValues().mean(axis=0),
            decimal=3)
        np.testing.assert_almost_equal(
            acqStatic.GetPoint("RTIO").GetValues().mean(axis=0),
            acqStatic.GetPoint("RAJC").GetValues().mean(axis=0),
            decimal=3)

        # foot offsets
        vicon_spf_l = np.rad2deg(
            acqStatic.GetMetaData().FindChild("PROCESSING").value().FindChild(
                "LStaticPlantFlex").value().GetInfo().ToDouble()[0])
        vicon_spf_r = np.rad2deg(
            acqStatic.GetMetaData().FindChild("PROCESSING").value().FindChild(
                "RStaticPlantFlex").value().GetInfo().ToDouble()[0])
        vicon_sro_l = np.rad2deg(
            acqStatic.GetMetaData().FindChild("PROCESSING").value().FindChild(
                "LStaticRotOff").value().GetInfo().ToDouble()[0])
        vicon_sro_r = np.rad2deg(
            acqStatic.GetMetaData().FindChild("PROCESSING").value().FindChild(
                "RStaticRotOff").value().GetInfo().ToDouble()[0])

        logging.info(" LStaticPlantFlex : Vicon (%.6f)  Vs pyCGM2 (%.6f)" %
                     (spf_l, vicon_spf_l))
        logging.info(" RStaticPlantFlex : Vicon (%.6f)  Vs pyCGM2 (%.6f)" %
                     (spf_r, vicon_spf_r))
        logging.info(" LStaticRotOff : Vicon (%.6f)  Vs pyCGM2 (%.6f)" %
                     (sro_l, vicon_sro_l))
        logging.info(" RStaticRotOff : Vicon (%.6f)  Vs pyCGM2 (%.6f)" %
                     (sro_r, vicon_sro_r))

        np.testing.assert_almost_equal(spf_l, vicon_spf_l, decimal=3)
        np.testing.assert_almost_equal(spf_r, vicon_spf_r, decimal=3)
        np.testing.assert_almost_equal(sro_l, vicon_sro_l, decimal=3)
        np.testing.assert_almost_equal(sro_r, vicon_sro_r, decimal=3)

        # -------- CGM FITTING -------------------------------------------------

        # ---- on c3d processed vicon static-pig operation
        # Motion FILTER
        # optimisation segmentaire et calibration fonctionnel
        modMotion = modelFilters.ModelMotionFilter(
            scp,
            acqStatic,
            model,
            pyCGM2Enums.motionMethod.Determinist,
            markerDiameter=markerDiameter,
            pigStatic=True,
            useRightKJCmarker="RKJC_KAD",
            useRightAJCmarker="RAJC_KAD",
            useLeftKJCmarker="LKJC_KAD",
            useLeftAJCmarker="LAJC_MID",
            viconCGM1compatible=False)
        modMotion.compute()

        # relative angles
        modelFilters.ModelJCSFilter(model, acqStatic).compute(
            description="vectoriel", pointLabelSuffix="cgm1_6dof")

        btkTools.smartWriter(acqStatic,
                             "test_basicCGM1_KADmed-staticAngles.c3d")

        # ---- on c3d processed vicon dynamic-pig operation
        gaitFilename = "MRI-US-01, 2008-08-08, 3DGA 02 -dynamic.c3d"  #"staticComparisonPipelines.c3d"
        acqGait = btkTools.smartReader(str(MAIN_PATH + gaitFilename))

        # Motion FILTER
        # optimisation segmentaire et calibration fonctionnel

        # output and plot
        #btkTools.smartWriter(acqGait, "test_basicCGM1_KADmed-staticAngles.c3d")

        plotComparison(acqGait, acqStatic, "LHipAngles")
        plotComparison(acqGait, acqStatic, "LKneeAngles")
        plotComparison(acqGait, acqStatic, "LAnkleAngles")