def cgm24(cls): """ """ MAIN_PATH = pyCGM2.TEST_DATA_PATH + "operations\\markerDecomposition\\CGM24decomposeTracking\\" # staticFilename = "PN01OP01S01STAT.c3d" acqStatic = btkTools.smartReader(str(MAIN_PATH + staticFilename)) model=cgm2.CGM2_4LowerLimbs() model.setVersion("CGM2.4e") model.configure() markerDiameter=14 mp={ 'Bodymass' : 83.0, 'LeftLegLength' : 874.0, 'RightLegLength' : 876.0 , 'LeftKneeWidth' : 106.0, 'RightKneeWidth' : 103.0, 'LeftAnkleWidth' : 74.0, 'RightAnkleWidth' : 72.0, 'LeftSoleDelta' : 0, 'RightSoleDelta' : 0, } model.addAnthropoInputParameters(mp) # CALIBRATION scp=modelFilters.StaticCalibrationProcedure(model) modelFilters.ModelCalibrationFilter(scp,acqStatic,model, leftFlatFoot = 1, rightFlatFoot = 1, markerDiameter=markerDiameter, ).compute() modelDecorator.KneeCalibrationDecorator(model).midCondyles(acqStatic, markerDiameter=markerDiameter, side="left") modelDecorator.AnkleCalibrationDecorator(model).midMaleolus(acqStatic, markerDiameter=markerDiameter, side="left") modelDecorator.KneeCalibrationDecorator(model).midCondyles(acqStatic, markerDiameter=markerDiameter, side="right") modelDecorator.AnkleCalibrationDecorator(model).midMaleolus(acqStatic, markerDiameter=markerDiameter, side="right") modelDecorator.HipJointCenterDecorator(model).hara(side = "Both") scp=modelFilters.StaticCalibrationProcedure(model) modelFilters.ModelCalibrationFilter(scp,acqStatic,model, leftFlatFoot = 1, rightFlatFoot = 1, markerDiameter=markerDiameter, ).compute() # --- Test 1 Motion Axe X ------- gaitFilename="PN01OP01S01SS01.c3d" acqGait = btkTools.smartReader(str(MAIN_PATH + gaitFilename)) modMotion=modelFilters.ModelMotionFilter(scp,acqGait,model,pyCGM2Enums.motionMethod.Sodervisk ) modMotion.compute() mtf = modelFilters.TrackingMarkerDecompositionFilter(model,acqGait) mtf.decompose() btkTools.smartWriter(acqGait, "cgm24-decompose.c3d")
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")
def noIK_6dof(cls): MAIN_PATH = pyCGM2.TEST_DATA_PATH + "CGM2\\cgm2.4\\fullBody\\" staticFilename = "PN01OP01S01STAT.c3d" gaitFilename = "PN01OP01S01STAT.c3d" markerDiameter = 14 mp = { 'Bodymass': 83.0, 'LeftLegLength': 874.0, 'RightLegLength': 876.0, 'LeftKneeWidth': 106.0, 'RightKneeWidth': 103.0, 'LeftAnkleWidth': 74.0, 'RightAnkleWidth': 72.0, 'LeftSoleDelta': 0, 'RightSoleDelta': 0, } # --- Calibration --- acqStatic = btkTools.smartReader(str(MAIN_PATH + staticFilename)) translators = files.getTranslators(MAIN_PATH, "CGM2_4.translators") acqStatic = btkTools.applyTranslators(acqStatic, translators) model = cgm2.CGM2_4() model.configure() model.addAnthropoInputParameters(mp) # ---- Calibration ---- scp = modelFilters.StaticCalibrationProcedure(model) modelFilters.ModelCalibrationFilter(scp, acqStatic, model).compute() print "----" print model.getSegment("Left Shank").getReferential( "TF").relativeMatrixAnatomic print "----" # # cgm decorator modelDecorator.HipJointCenterDecorator(model).hara() modelDecorator.KneeCalibrationDecorator(model).midCondyles( acqStatic, markerDiameter=markerDiameter, side="both") modelDecorator.AnkleCalibrationDecorator(model).midMaleolus( acqStatic, markerDiameter=markerDiameter, side="both") # # # final modelFilters.ModelCalibrationFilter( scp, acqStatic, model, markerDiameter=markerDiameter).compute() # ------ Fitting ------- acqGait = btkTools.smartReader(str(MAIN_PATH + gaitFilename)) acqGait = btkTools.applyTranslators(acqGait, translators) # Motion FILTER modMotion = modelFilters.ModelMotionFilter( scp, acqGait, model, enums.motionMethod.Sodervisk) modMotion.compute() btkTools.smartWriter(acqGait, "cgm24_noIK6dof_staticMotion.c3d")
def noIK_6dof_Garches(cls): MAIN_PATH = pyCGM2.TEST_DATA_PATH + "Datasets Tests\\didier\\08_02_18_Vincent Pere\\" staticFilename = "08_02_18_Vincent_Pere_Statique_000_MOKKA.c3d" gaitFilename = "08_02_18_Vincent_Pere_Statique_000_MOKKA.c3d" markerDiameter = 14 mp = { 'Bodymass': 70.0, 'LeftLegLength': 890.0, 'RightLegLength': 890.0, 'LeftKneeWidth': 150.0, 'RightKneeWidth': 150.0, 'LeftAnkleWidth': 88.0, 'RightAnkleWidth': 99.0, 'LeftSoleDelta': 0, 'RightSoleDelta': 0, } # --- Calibration --- acqStatic = btkTools.smartReader(str(MAIN_PATH + staticFilename)) model = cgm2.CGM2_4() model.configure() model.addAnthropoInputParameters(mp) # ---- Calibration ---- scp = modelFilters.StaticCalibrationProcedure(model) modelFilters.ModelCalibrationFilter(scp, acqStatic, model).compute() print "----" print model.getSegment("Left Shank").getReferential( "TF").relativeMatrixAnatomic print "----" # # cgm decorator modelDecorator.HipJointCenterDecorator(model).hara() modelDecorator.KneeCalibrationDecorator(model).midCondyles( acqStatic, markerDiameter=markerDiameter, side="both") modelDecorator.AnkleCalibrationDecorator(model).midMaleolus( acqStatic, markerDiameter=markerDiameter, side="both") # # # final modelFilters.ModelCalibrationFilter( scp, acqStatic, model, markerDiameter=markerDiameter).compute() # ------ Fitting ------- acqGait = btkTools.smartReader(str(MAIN_PATH + gaitFilename)) # Motion FILTER modMotion = modelFilters.ModelMotionFilter( scp, acqGait, model, enums.motionMethod.Sodervisk) modMotion.compute() btkTools.smartWriter(acqGait, "cgm24_noIK6dof_staticMotion_Garches.c3d")
def calibration_FlatFoot(cls): MAIN_PATH = pyCGM2.TEST_DATA_PATH + "CGM2\\cgm2.4\\medial\\" staticFilename = "static.c3d" markerDiameter = 14 mp = { 'Bodymass': 69.0, 'LeftLegLength': 930.0, 'RightLegLength': 930.0, 'LeftKneeWidth': 94.0, 'RightKneeWidth': 64.0, 'LeftAnkleWidth': 67.0, 'RightAnkleWidth': 62.0, 'LeftSoleDelta': 0, 'RightSoleDelta': 0, "LeftToeOffset": 0, "RightToeOffset": 0, } # --- Calibration --- acqStatic = btkTools.smartReader(str(MAIN_PATH + staticFilename)) model = cgm2.CGM2_4() model.configure() model.addAnthropoInputParameters(mp) # ---- Calibration ---- scp = modelFilters.StaticCalibrationProcedure(model) modelFilters.ModelCalibrationFilter(scp, acqStatic, model).compute() # cgm decorator modelDecorator.HipJointCenterDecorator(model).hara() modelDecorator.KneeCalibrationDecorator(model).midCondyles( acqStatic, markerDiameter=markerDiameter, side="both") modelDecorator.AnkleCalibrationDecorator(model).midMaleolus( acqStatic, markerDiameter=markerDiameter, side="both") # final modelFilters.ModelCalibrationFilter(scp, acqStatic, model, markerDiameter=markerDiameter, leftFlatFoot=True, rightFlatFoot=True).compute() # display CS csp = modelFilters.ModelCoordinateSystemProcedure(model) csf = modelFilters.CoordinateSystemDisplayFilter(csp, model, acqStatic) csf.setStatic(True) csf.display() btkTools.smartWriter(acqStatic, "cgm2.4_FlatFoot.c3d")
def calibration_GarchesFlatFoot(cls): MAIN_PATH = pyCGM2.TEST_DATA_PATH + "Datasets Tests\\didier\\08_02_18_Vincent Pere\\" staticFilename = "08_02_18_Vincent_Pere_Statique_000_MOKKA.c3d" markerDiameter = 14 mp = { 'Bodymass': 70.0, 'LeftLegLength': 890.0, 'RightLegLength': 890.0, 'LeftKneeWidth': 150.0, 'RightKneeWidth': 150.0, 'LeftAnkleWidth': 88.0, 'RightAnkleWidth': 99.0, 'LeftSoleDelta': 0, 'RightSoleDelta': 0, "LeftToeOffset": 0, "RightToeOffset": 0, } # --- Calibration --- acqStatic = btkTools.smartReader(str(MAIN_PATH + staticFilename)) model = cgm2.CGM2_4() model.configure() model.addAnthropoInputParameters(mp) # ---- Calibration ---- scp = modelFilters.StaticCalibrationProcedure(model) modelFilters.ModelCalibrationFilter(scp, acqStatic, model).compute() # cgm decorator modelDecorator.HipJointCenterDecorator(model).hara() modelDecorator.KneeCalibrationDecorator(model).midCondyles( acqStatic, markerDiameter=markerDiameter, side="both") modelDecorator.AnkleCalibrationDecorator(model).midMaleolus( acqStatic, markerDiameter=markerDiameter, side="both") # final modelFilters.ModelCalibrationFilter(scp, acqStatic, model, markerDiameter=markerDiameter, leftFlatFoot=True, rightFlatFoot=True).compute() # display CS csp = modelFilters.ModelCoordinateSystemProcedure(model) csf = modelFilters.CoordinateSystemDisplayFilter(csp, model, acqStatic) csf.setStatic(True) csf.display() btkTools.smartWriter(acqStatic, "cgm2.4_GarchesFlatFoot.c3d")
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")
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")
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()
def advancedCGM1_kad_midMaleolus_markerDiameter(cls): MAIN_PATH = pyCGM2.TEST_DATA_PATH + "CGM1\\CGM1-TESTS\\KAD-Med-markerDiameter\\" staticFilename = "MRI-US-01, 2008-08-08, 3DGA 02.c3d" acqStatic = btkTools.smartReader(str(MAIN_PATH + staticFilename)) model=cgm.CGM1 model.configure() markerDiameter=25.0 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,markerDiameter=markerDiameter, leftFlatFoot = False, rightFlatFoot = False).compute() # cgm decorator modelDecorator.Kad(model,acqStatic).compute(markerDiameter=markerDiameter, side="both") modelDecorator.AnkleCalibrationDecorator(model).midMaleolus(acqStatic,markerDiameter=markerDiameter, side="both") modelFilters.ModelCalibrationFilter(scp,acqStatic,model, markerDiameter=markerDiameter).compute() # TESTS ------------------------------------------------ offsetTesting(acqStatic,model,display = True, unitTesting=True) 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 ,"mid") np.testing.assert_equal(model.getSegment("Right Shank").getReferential("TF").static.getNode_byLabel("RAJC").m_desc ,"mid") np.testing.assert_equal(model.getSegment("Left Foot").getReferential("TF").static.getNode_byLabel("LAJC").m_desc ,"mid") np.testing.assert_equal(model.getSegment("Right Foot").getReferential("TF").static.getNode_byLabel("RAJC").m_desc ,"mid") 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_midMaleolus_markerDiameter.c3d")
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")
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)
def full_IK(cls): MAIN_PATH = pyCGM2.TEST_DATA_PATH + "CGM2\\cgm2.3\\fullBody\\" staticFilename = "PN01OP01S01STAT.c3d" gaitFilename = "PN01OP01S01SS01.c3d" markerDiameter = 14 mp = { 'Bodymass': 83.0, 'LeftLegLength': 874.0, 'RightLegLength': 876.0, 'LeftKneeWidth': 106.0, 'RightKneeWidth': 103.0, 'LeftAnkleWidth': 74.0, 'RightAnkleWidth': 72.0, 'LeftSoleDelta': 0, 'RightSoleDelta': 0, } # --- Calibration --- acqStatic = btkTools.smartReader(str(MAIN_PATH + staticFilename)) translators = files.getTranslators(MAIN_PATH, "CGM2_3.translators") acqStatic = btkTools.applyTranslators(acqStatic, translators) model = cgm2.CGM2_3LowerLimbs() model.configure() model.addAnthropoInputParameters(mp) # ---- Calibration ---- scp = modelFilters.StaticCalibrationProcedure(model) modelFilters.ModelCalibrationFilter(scp, acqStatic, model).compute() # cgm decorator modelDecorator.HipJointCenterDecorator(model).hara() modelDecorator.KneeCalibrationDecorator(model).midCondyles( acqStatic, markerDiameter=markerDiameter, side="both") modelDecorator.AnkleCalibrationDecorator(model).midMaleolus( acqStatic, markerDiameter=markerDiameter, side="both") # final modelFilters.ModelCalibrationFilter( scp, acqStatic, model, markerDiameter=markerDiameter).compute() # ------ Fitting ------- acqGait = btkTools.smartReader(str(MAIN_PATH + gaitFilename)) acqGait = btkTools.applyTranslators(acqGait, translators) # Motion FILTER modMotion = modelFilters.ModelMotionFilter( scp, acqGait, model, enums.motionMethod.Sodervisk) modMotion.compute() # ------- OPENSIM IK -------------------------------------- # --- osim builder --- cgmCalibrationprocedure = opensimFilters.CgmOpensimCalibrationProcedures( model) markersetFile = pyCGM2.OPENSIM_PREBUILD_MODEL_PATH + "models\\settings\\cgm2_3\\cgm2_3-markerset.xml" osimfile = pyCGM2.OPENSIM_PREBUILD_MODEL_PATH + "models\\osim\\lowerLimb_ballsJoints.osim" oscf = opensimFilters.opensimCalibrationFilter( osimfile, model, cgmCalibrationprocedure, MAIN_PATH) oscf.addMarkerSet(markersetFile) scalingOsim = oscf.build(exportOsim=False) # --- fitting --- #procedure cgmFittingProcedure = opensimFilters.CgmOpensimFittingProcedure(model) iksetupFile = pyCGM2.OPENSIM_PREBUILD_MODEL_PATH + "models\\settings\\cgm2_3\\cgm2_3-ikSetUp_template.xml" osrf = opensimFilters.opensimFittingFilter(iksetupFile, scalingOsim, cgmFittingProcedure, MAIN_PATH) acqIK = osrf.run(acqGait, str(MAIN_PATH + gaitFilename), exportSetUp=False) # -------- NEW MOTION FILTER ON IK MARKERS ------------------ modMotion_ik = modelFilters.ModelMotionFilter( scp, acqIK, model, enums.motionMethod.Sodervisk, useForMotionTest=True) modMotion_ik.compute() finalJcs = modelFilters.ModelJCSFilter(model, acqIK) finalJcs.setFilterBool(False) finalJcs.compute(description="ik", pointLabelSuffix="2_ik") # btkTools.smartWriter(acqIK, "cgm23_fullIK_Motion.c3d")
def CGM23_2DOF_test(cls): MAIN_PATH = pyCGM2.TEST_DATA_PATH + "CGM2\\cgm2.3\\Knee Calibration\\" staticFilename = "Static.c3d" leftKneeFilename = "Left Knee.c3d" rightKneeFilename = "Right Knee.c3d" gaitFilename = "gait trial 01.c3d" 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, } acqStatic = btkTools.smartReader(str(MAIN_PATH + staticFilename)) model = cgm2.CGM2_3() model.configure() model.addAnthropoInputParameters(mp) # --- INITIAL CALIBRATION --- scp = modelFilters.StaticCalibrationProcedure(model) modelFilters.ModelCalibrationFilter(scp, acqStatic, model).compute() # cgm decorator modelDecorator.HipJointCenterDecorator(model).hara() modelDecorator.KneeCalibrationDecorator(model).midCondyles( acqStatic, markerDiameter=markerDiameter, side="both") modelDecorator.AnkleCalibrationDecorator(model).midMaleolus( acqStatic, markerDiameter=markerDiameter, side="both") # final modelFilters.ModelCalibrationFilter( scp, acqStatic, model, seLeftHJCnode="LHJC_Hara", useRightHJCnode="RHJC_Hara", useLeftKJCnode="LKJC_mid", useLeftAJCnode="LAJC_mid", useRightKJCnode="RKJC_mid", useRightAJCnode="RAJC_mid", markerDiameter=markerDiameter).compute() # ------ LEFT KNEE CALIBRATION ------- acqLeftKnee = btkTools.smartReader(str(MAIN_PATH + leftKneeFilename)) # Motion of only left modMotionLeftKnee = modelFilters.ModelMotionFilter( scp, acqLeftKnee, model, enums.motionMethod.Sodervisk) modMotionLeftKnee.segmentalCompute(["Left Thigh", "Left Shank"]) # decorator modelDecorator.KneeCalibrationDecorator(model).calibrate2dof( "Left", indexFirstFrame=489, indexLastFrame=1451) # ----add Point into the c3d---- btkTools.smartWriter(acqLeftKnee, "Left Knee-2dof.c3d") # ------ RIGHT KNEE CALIBRATION ------- acqRightKnee = btkTools.smartReader(str(MAIN_PATH + rightKneeFilename)) # Motion of only left modMotionRightKnee = modelFilters.ModelMotionFilter( scp, acqRightKnee, model, enums.motionMethod.Sodervisk) modMotionRightKnee.segmentalCompute(["Right Thigh", "Right Shank"]) # decorator modelDecorator.KneeCalibrationDecorator(model).calibrate2dof( "Right", indexFirstFrame=25, indexLastFrame=1060) # ----add Point into the c3d---- btkTools.smartWriter(acqRightKnee, "Right Knee-2dof.c3d") #--- FINAL CALIBRATION --- modelFilters.ModelCalibrationFilter( scp, acqStatic, model, useLeftHJCnode="LHJC_Hara", useRightHJCnode="RHJC_Hara", useLeftKJCnode="KJC_Sara", useLeftAJCnode="LAJC_mid", useRightKJCnode="KJC_Sara", useRightAJCnode="RAJC_mid", markerDiameter=markerDiameter).compute() # save static c3d with update KJC btkTools.smartWriter(acqStatic, "Static-2DOF.c3d")
pointLabel1="RSMH", pointLabel2="RHEE", pointLabel3="RVMH", pointLabelOrigin="RHEE") #---Initial Calibration Filter--- smf0 = modelFilters.ModelCalibrationFilter(gcp, acqStatic, bioMechModel) smf0.setBoolOption("technicalReferentialOnly") smf0.compute() # ---- decorator ---- modelDecorator.HipJointCenterDecorator(bioMechModel).greatTrochanterOffset( acqStatic) modelDecorator.KneeCalibrationDecorator(bioMechModel).midCondyles( acqStatic) modelDecorator.AnkleCalibrationDecorator(bioMechModel).midMaleolus( acqStatic) gcp.setAnatomicalDefinition("Pelvis", sequence="YZX", nodeLabel1="RASI", nodeLabel2="LASI", nodeLabel3="SACR", nodeLabelOrigin="midASIS") gcp.setAnatomicalDefinition("Left Thigh", sequence="ZXiY", nodeLabel1="LKJC_mid", nodeLabel2="LHJC_gt", nodeLabel3="LKNE", nodeLabelOrigin="LHJC_gt") gcp.setAnatomicalDefinition("Right Thigh", sequence="ZXY",
def test_lowLevel(self): DATA_PATH = pyCGM2.TEST_DATA_PATH + "GaitModels\CGM2.3\\Hannibal-medial\\" staticFilename = "static.c3d" gaitFilename= "gait1.c3d" markerDiameter=14 required_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, 'LeftShoulderOffset' : 0, 'RightShoulderOffset' : 0, 'LeftElbowWidth' : 0, 'LeftWristWidth' : 0, 'LeftHandThickness' : 0, 'RightElbowWidth' : 0, 'RightWristWidth' : 0, 'RightHandThickness' : 0 } optional_mp = { 'LeftTibialTorsion' : 0, 'LeftThighRotation' : 0, 'LeftShankRotation' : 0, 'RightTibialTorsion' : 0, 'RightThighRotation' : 0, 'RightShankRotation' : 0 } # --- Calibration --- # ---check marker set used---- acqStatic = btkTools.smartReader(DATA_PATH + staticFilename) dcm = cgm.CGM.detectCalibrationMethods(acqStatic) model=cgm2.CGM2_3() model.configure(detectedCalibrationMethods=dcm) model.addAnthropoInputParameters(required_mp,optional=optional_mp) # ---- Calibration ---- scp=modelFilters.StaticCalibrationProcedure(model) modelFilters.ModelCalibrationFilter(scp,acqStatic,model).compute() # cgm decorator modelDecorator.HipJointCenterDecorator(model).hara() modelDecorator.KneeCalibrationDecorator(model).midCondyles(acqStatic, markerDiameter=markerDiameter, side="both") modelDecorator.AnkleCalibrationDecorator(model).midMaleolus(acqStatic, markerDiameter=markerDiameter, side="both") # final modelFilters.ModelCalibrationFilter(scp,acqStatic,model, markerDiameter=markerDiameter).compute() # ------ Fitting ------- acqGait = btkTools.smartReader(DATA_PATH + gaitFilename) # Motion FILTER modMotion=modelFilters.ModelMotionFilter(scp,acqGait,model,enums.motionMethod.Sodervisk) modMotion.compute() # ------- OPENSIM IK -------------------------------------- # --- osim builder --- cgmCalibrationprocedure = opensimFilters.CgmOpensimCalibrationProcedures(model) markersetFile = pyCGM2.OPENSIM_PREBUILD_MODEL_PATH + "models\\settings\\cgm2_3\\cgm2_3-markerset.xml" osimfile = pyCGM2.OPENSIM_PREBUILD_MODEL_PATH + "models\\osim\\lowerLimb_ballsJoints.osim" oscf = opensimFilters.opensimCalibrationFilter(osimfile, model, cgmCalibrationprocedure, DATA_PATH) oscf.addMarkerSet(markersetFile) scalingOsim = oscf.build(exportOsim=False) # --- fitting --- #procedure cgmFittingProcedure = opensimFilters.CgmOpensimFittingProcedure(model) iksetupFile = pyCGM2.OPENSIM_PREBUILD_MODEL_PATH + "models\\settings\\cgm2_3\\cgm2_3-ikSetUp_template.xml" osrf = opensimFilters.opensimFittingFilter(iksetupFile, scalingOsim, cgmFittingProcedure, DATA_PATH, acqGait ) acqIK = osrf.run(str(DATA_PATH + gaitFilename ),exportSetUp=False) # -------- NEW MOTION FILTER ON IK MARKERS ------------------ modMotion_ik=modelFilters.ModelMotionFilter(scp,acqIK,model,enums.motionMethod.Sodervisk, useForMotionTest=True) modMotion_ik.compute() finalJcs =modelFilters.ModelJCSFilter(model,acqIK) finalJcs.compute(description="ik", pointLabelSuffix = "2_ik")# btkTools.smartWriter(acqIK,"cgm23_fullIK_Motion.c3d")
def kinematicFitting_oneFile_cgmProcedure(cls): DATA_PATH = pyCGM2.TEST_DATA_PATH + "CGM2\\LowerLimb\\subject10_S1A1_julieDataSet_noModelOutputs\\" config = dict() config["static"] = "StaticR010S1A1.c3d" config["dynamicTrial"] = [ "R010S1A1Gait001.c3d", "R010S1A1Gait003.c3d", "R010S1A1Gait004.c3d", "R010S1A1Gait005.c3d", "R010S1A1Gait007.c3d", "R010S1A1Gait010.c3d" ] configMP = { "Bodymass": 64.0, "LeftLegLength": 865.0, "RightLegLength": 855.0, "LeftKneeWidth": 100.0, "RightKneeWidth": 101.0, "LeftAnkleWidth": 69.0, "RightAnkleWidth": 69.0 } requiredMarkers = [ "LASI", "RASI", "LPSI", "RPSI", "RTHIAP", "RTHIAD", "RTHI", "RKNE", "RSHN", "RTIAP", "RTIB", "RANK", "RHEE", "RTOE", "RCUN", "RD1M", "RD5M" ] acqStatic = btkTools.smartReader(DATA_PATH + config["static"]) # model model = cgm2Julie.CGM2ModelInf() model.configure() markerDiameter = 14 mp = { 'Bodymass': configMP["Bodymass"], 'LeftLegLength': configMP["LeftLegLength"], 'RightLegLength': configMP["RightLegLength"], 'LeftKneeWidth': configMP["LeftKneeWidth"], 'RightKneeWidth': configMP["RightKneeWidth"], 'LeftAnkleWidth': configMP["LeftAnkleWidth"], 'RightAnkleWidth': configMP["RightAnkleWidth"], } #offset 2ndToe Joint toe = acqStatic.GetPoint("RTOE").GetValues()[:, :].mean(axis=0) mp["rightToeOffset"] = (toe[2] - markerDiameter / 2.0) / 2.0 model.addAnthropoInputParameters(mp) # -----------CGM STATIC CALIBRATION-------------------- # --- Initial calibration scp = modelFilters.StaticCalibrationProcedure(model) modelFilters.ModelCalibrationFilter( scp, acqStatic, model, rightFlatHindFoot=True).compute() # Initial calibration # --- decorator modelDecorator.KneeCalibrationDecorator(model).midCondyles( acqStatic, leftMedialKneeLabel="LKNM", rightMedialKneeLabel="RKNM") modelDecorator.AnkleCalibrationDecorator(model).midMaleolus( acqStatic, leftMedialAnkleLabel="LMMA", rightMedialAnkleLabel="RMMA") # --- Updated calibration modelFilters.ModelCalibrationFilter(scp, acqStatic, model, useLeftKJCnode="LKJC_mid", useRightKJCnode="RKJC_mid", useLeftAJCnode="LAJC_mid", useRightAJCnode="RAJC_mid", rightFlatHindFoot=True).compute() # ---- optional -update static c3d #btkTools.smartWriter(acqStatic, "StaticCalibrated.c3d") # -----------CGM MOTION 6dof-------------------- # --- reader and checking acqGait = btkTools.smartReader(DATA_PATH + config["dynamicTrial"][0]) btkTools.checkMarkers(acqGait, requiredMarkers) btkTools.isGap(acqGait, requiredMarkers) btkTools.checkFirstAndLastFrame(acqGait, "LASI") logging.info("dyn Acquisition ---> OK ") # --- filters modMotion = modelFilters.ModelMotionFilter( scp, acqGait, model, pyCGM2Enums.motionMethod.Determinist) modMotion.compute() modelFilters.ModelJCSFilter(model, acqGait).compute(description="vectoriel", pointLabelSuffix="2_6dof") # --- writer #btkTools.smartWriter(acqGait, "motionCalibrated.c3d") # ------- OPENSIM IK -------------------------------------- cgmprocedure = opensimFilters.CgmOpensimCalibrationProcedures(model) markersetFile = pyCGM2.OPENSIM_PREBUILD_MODEL_PATH + "models\\draft-opensimPreProcessing\\cgm2-markerset.xml" osimfile = pyCGM2.OPENSIM_PREBUILD_MODEL_PATH + "models\\draft-opensimPreProcessing\\cgm2-model.osim" oscf = opensimFilters.opensimCalibrationFilter(osimfile, model, cgmprocedure) oscf.addMarkerSet(markersetFile) fittingOsim = oscf.build() filename = config["dynamicTrial"][0] cgmFittingProcedure = opensimFilters.CgmOpensimFittingProcedure(model) cgmFittingProcedure.updateMarkerWeight("LASI", 100) iksetupFile = pyCGM2.OPENSIM_PREBUILD_MODEL_PATH + "models\\draft-opensimPreProcessing\\ikSetUp_template.xml" osrf = opensimFilters.opensimFittingFilter(iksetupFile, fittingOsim, cgmFittingProcedure, DATA_PATH) acqIK = osrf.run(acqGait, str(DATA_PATH + filename)) # -------- NEW MOTION FILTER ON IK MARKERS ------------------ modMotion_ik = modelFilters.ModelMotionFilter( scp, acqIK, model, pyCGM2Enums.motionMethod.Sodervisk) modMotion_ik.compute() finalJcs = modelFilters.ModelJCSFilter(model, acqIK) finalJcs.setFilterBool(False) finalJcs.compute(description="ik", pointLabelSuffix="2_ik") # # recup du mot file motFilename = str(DATA_PATH + config["dynamicTrial"][0][:-4] + ".mot") comparisonOpensimVsCGM(motFilename, acqIK, "2_ik")
def CGM2_4_SARA_test(cls): MAIN_PATH = pyCGM2.TEST_DATA_PATH + "CGM2\\cgm2.4\\Knee Calibration\\" staticFilename = "static.c3d" funcFilename = "functional.c3d" gaitFilename = "gait trial 01.c3d" markerDiameter = 14 mp = { 'Bodymass': 69.0, 'LeftLegLength': 930.0, 'RightLegLength': 930.0, 'LeftKneeWidth': 94.0, 'RightKneeWidth': 64.0, 'LeftAnkleWidth': 67.0, 'RightAnkleWidth': 62.0, 'LeftSoleDelta': 0, 'RightSoleDelta': 0, "LeftToeOffset": 0, "RightToeOffset": 0, } acqStatic = btkTools.smartReader(str(MAIN_PATH + staticFilename)) model = cgm2.CGM2_4LowerLimbs() model.configure() model.addAnthropoInputParameters(mp) # --- INITIAL CALIBRATION --- scp = modelFilters.StaticCalibrationProcedure(model) modelFilters.ModelCalibrationFilter(scp, acqStatic, model).compute() # cgm decorator modelDecorator.HipJointCenterDecorator(model).hara() modelDecorator.KneeCalibrationDecorator(model).midCondyles( acqStatic, markerDiameter=markerDiameter, side="both", cgm1Behaviour=True) modelDecorator.AnkleCalibrationDecorator(model).midMaleolus( acqStatic, markerDiameter=markerDiameter, side="both") # final modelFilters.ModelCalibrationFilter( scp, acqStatic, model, seLeftHJCnode="LHJC_Hara", useRightHJCnode="RHJC_Hara", useLeftKJCnode="LKJC_mid", useLeftAJCnode="LAJC_mid", useRightKJCnode="RKJC_mid", useRightAJCnode="RAJC_mid", markerDiameter=markerDiameter).compute() # ------ LEFT KNEE CALIBRATION ------- acqFunc = btkTools.smartReader(str(MAIN_PATH + funcFilename)) # Motion of only left modMotionLeftKnee = modelFilters.ModelMotionFilter( scp, acqFunc, model, pyCGM2Enums.motionMethod.Sodervisk) modMotionLeftKnee.segmentalCompute(["Left Thigh", "Left Shank"]) # decorator modelDecorator.KneeCalibrationDecorator(model).sara( "Left", indexFirstFrame=831, indexLastFrame=1280) # ----add Point into the c3d---- Or_inThigh = model.getSegment("Left Thigh").getReferential( "TF").getNodeTrajectory("KneeFlexionOri") axis_inThigh = model.getSegment("Left Thigh").getReferential( "TF").getNodeTrajectory("KneeFlexionAxis") btkTools.smartAppendPoint(acqFunc, "Left" + "_KneeFlexionOri", Or_inThigh) btkTools.smartAppendPoint(acqFunc, "Left" + "_KneeFlexionAxis", axis_inThigh) # ------ RIGHT KNEE CALIBRATION ------- # Motion of only left modMotionRightKnee = modelFilters.ModelMotionFilter( scp, acqFunc, model, pyCGM2Enums.motionMethod.Sodervisk) modMotionRightKnee.segmentalCompute(["Right Thigh", "Right Shank"]) # decorator modelDecorator.KneeCalibrationDecorator(model).sara("Right", indexFirstFrame=61, indexLastFrame=551) # ----add Point into the c3d---- Or_inThigh = model.getSegment("Right Thigh").getReferential( "TF").getNodeTrajectory("KneeFlexionOri") axis_inThigh = model.getSegment("Right Thigh").getReferential( "TF").getNodeTrajectory("KneeFlexionAxis") btkTools.smartAppendPoint(acqFunc, "Right" + "_KneeFlexionOri", Or_inThigh) btkTools.smartAppendPoint(acqFunc, "Right" + "_KneeFlexionAxis", axis_inThigh) btkTools.smartWriter(acqFunc, "acqFunc-Sara.c3d") #--- FINAL CALIBRATION --- modelFilters.ModelCalibrationFilter( scp, acqStatic, model, useLeftHJCnode="LHJC_Hara", useRightHJCnode="RHJC_Hara", useLeftKJCnode="KJC_Sara", useLeftAJCnode="LAJC_mid", useRightKJCnode="KJC_Sara", useRightAJCnode="RAJC_mid", markerDiameter=markerDiameter, RotateLeftThighFlag=True, RotateRightThighFlag=True).compute() # save static c3d with update KJC btkTools.smartWriter(acqStatic, "Static-SARA.c3d") # ------ Fitting ------- acqGait = btkTools.smartReader(str(MAIN_PATH + gaitFilename)) # Motion FILTER 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", "RASI", "RPSI", "LPSI"]) modelFilters.ModelAbsoluteAnglesFilter( model, acqGait, segmentLabels=["Left HindFoot", "Right HindFoot", "Pelvis"], angleLabels=["LFootProgress", "RFootProgress", "Pelvis"], eulerSequences=["TOR", "TOR", "ROT"], globalFrameOrientation=globalFrame, forwardProgression=forwardProgression).compute( pointLabelSuffix="cgm1_6dof") # ------- OPENSIM IK -------------------------------------- # --- osim builder --- cgmCalibrationprocedure = opensimFilters.CgmOpensimCalibrationProcedures( model) markersetFile = pyCGM2.OPENSIM_PREBUILD_MODEL_PATH + "models\\settings\\cgm2_4\\cgm2_4-markerset.xml" osimfile = pyCGM2.OPENSIM_PREBUILD_MODEL_PATH + "models\\osim\\lowerLimb_ballsJoints.osim" oscf = opensimFilters.opensimCalibrationFilter( osimfile, model, cgmCalibrationprocedure) oscf.addMarkerSet(markersetFile) scalingOsim = oscf.build(exportOsim=False) # --- fitting --- #procedure cgmFittingProcedure = opensimFilters.CgmOpensimFittingProcedure(model) iksetupFile = pyCGM2.OPENSIM_PREBUILD_MODEL_PATH + "models\\settings\\cgm2_4\\cgm2_4-ikSetUp_template.xml" osrf = opensimFilters.opensimFittingFilter(iksetupFile, scalingOsim, cgmFittingProcedure, MAIN_PATH) acqIK = osrf.run(acqGait, str(MAIN_PATH + gaitFilename), exportSetUp=False) # -------- NEW MOTION FILTER ON IK MARKERS ------------------ modMotion_ik = modelFilters.ModelMotionFilter( scp, acqIK, model, pyCGM2Enums.motionMethod.Sodervisk, useForMotionTest=True) modMotion_ik.compute() finalJcs = modelFilters.ModelJCSFilter(model, acqIK) finalJcs.setFilterBool(False) finalJcs.compute(description="ik", pointLabelSuffix="2_ik") # btkTools.smartWriter(acqIK, "gait trial 01 - Fitting.c3d")
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")
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")
def full_IK(cls): MAIN_PATH = pyCGM2.TEST_DATA_PATH + "CGM2\\cgm2.4\\medial\\" staticFilename = "static.c3d" gaitFilename = "gait Trial 01.c3d" markerDiameter = 14 mp = { 'Bodymass': 69.0, 'LeftLegLength': 930.0, 'RightLegLength': 930.0, 'LeftKneeWidth': 94.0, 'RightKneeWidth': 64.0, 'LeftAnkleWidth': 67.0, 'RightAnkleWidth': 62.0, 'LeftSoleDelta': 0, 'RightSoleDelta': 0, "LeftToeOffset": 0, "RightToeOffset": 0, } # --- Calibration --- acqStatic = btkTools.smartReader(str(MAIN_PATH + staticFilename)) model = cgm2.CGM2_4LowerLimbs() model.configure() model.addAnthropoInputParameters(mp) # ---- Calibration ---- scp = modelFilters.StaticCalibrationProcedure(model) modelFilters.ModelCalibrationFilter(scp, acqStatic, model).compute() # cgm decorator modelDecorator.HipJointCenterDecorator(model).hara() modelDecorator.KneeCalibrationDecorator(model).midCondyles( acqStatic, markerDiameter=markerDiameter, side="both") modelDecorator.AnkleCalibrationDecorator(model).midMaleolus( acqStatic, markerDiameter=markerDiameter, side="both") # final modelFilters.ModelCalibrationFilter( scp, acqStatic, model, markerDiameter=markerDiameter).compute() # ------ Fitting ------- acqGait = btkTools.smartReader(str(MAIN_PATH + gaitFilename)) # Motion FILTER modMotion = modelFilters.ModelMotionFilter( scp, acqGait, model, pyCGM2Enums.motionMethod.Sodervisk) modMotion.compute() # relative angles modelFilters.ModelJCSFilter(model, acqGait).compute( description="vectoriel", pointLabelSuffix="cgm1_6dof") # absolute angles longitudinalAxis, forwardProgression, globalFrame = btkTools.findProgressionAxisFromPelvicMarkers( acqGait, ["LASI", "RASI", "RPSI", "LPSI"]) modelFilters.ModelAbsoluteAnglesFilter( model, acqGait, segmentLabels=["Left Foot", "Right Foot", "Pelvis"], angleLabels=["LFootProgress", "RFootProgress", "Pelvis"], eulerSequences=["TOR", "TOR", "ROT"], globalFrameOrientation=globalFrame, forwardProgression=forwardProgression).compute( pointLabelSuffix="cgm1_6dof") # ---Marker decomp filter---- mtf = modelFilters.TrackingMarkerDecompositionFilter(model, acqGait) mtf.decompose() # ------- OPENSIM IK -------------------------------------- # --- osim builder --- cgmCalibrationprocedure = opensimFilters.CgmOpensimCalibrationProcedures( model) markersetFile = pyCGM2.OPENSIM_PREBUILD_MODEL_PATH + "models\\settings\\cgm2_4\\cgm2_4-markerset - expert.xml" osimfile = pyCGM2.OPENSIM_PREBUILD_MODEL_PATH + "models\\osim\\lowerLimb_ballsJoints.osim" oscf = opensimFilters.opensimCalibrationFilter( osimfile, model, cgmCalibrationprocedure, MAIN_PATH) oscf.addMarkerSet(markersetFile) scalingOsim = oscf.build(exportOsim=False) # --- fitting --- #procedure cgmFittingProcedure = opensimFilters.CgmOpensimFittingProcedure( model, expertMode=True) iksetupFile = pyCGM2.OPENSIM_PREBUILD_MODEL_PATH + "models\\settings\\cgm2_4\\cgm2_4-expert-ikSetUp_template.xml" osrf = opensimFilters.opensimFittingFilter(iksetupFile, scalingOsim, cgmFittingProcedure, MAIN_PATH) acqIK = osrf.run(acqGait, str(MAIN_PATH + gaitFilename), exportSetUp=False) # -------- NEW MOTION FILTER ON IK MARKERS ------------------ modMotion_ik = modelFilters.ModelMotionFilter( scp, acqIK, model, pyCGM2Enums.motionMethod.Sodervisk, useForMotionTest=True) modMotion_ik.compute() finalJcs = modelFilters.ModelJCSFilter(model, acqIK) finalJcs.setFilterBool(False) finalJcs.compute(description="ik", pointLabelSuffix="2_ik") # btkTools.smartWriter(acqIK, "cgm24e_fullIK.c3d")
def CGM2_4_SARA_test(cls): MAIN_PATH = pyCGM2.TEST_DATA_PATH + "CGM2\\cgm2.4\\Knee Calibration\\" staticFilename = "static.c3d" funcFilename = "functional.c3d" gaitFilename = "gait trial 01.c3d" markerDiameter = 14 mp = { 'Bodymass': 69.0, 'LeftLegLength': 930.0, 'RightLegLength': 930.0, 'LeftKneeWidth': 94.0, 'RightKneeWidth': 64.0, 'LeftAnkleWidth': 67.0, 'RightAnkleWidth': 62.0, 'LeftSoleDelta': 0, 'RightSoleDelta': 0, "LeftToeOffset": 0, "RightToeOffset": 0, } acqStatic = btkTools.smartReader(str(MAIN_PATH + staticFilename)) model = cgm2.CGM2_4() model.configure() model.addAnthropoInputParameters(mp) # --- INITIAL CALIBRATION --- scp = modelFilters.StaticCalibrationProcedure(model) modelFilters.ModelCalibrationFilter(scp, acqStatic, model).compute() # cgm decorator modelDecorator.HipJointCenterDecorator(model).hara() modelDecorator.KneeCalibrationDecorator(model).midCondyles( acqStatic, markerDiameter=markerDiameter, side="both") modelDecorator.AnkleCalibrationDecorator(model).midMaleolus( acqStatic, markerDiameter=markerDiameter, side="both") # final modelFilters.ModelCalibrationFilter( scp, acqStatic, model, seLeftHJCnode="LHJC_Hara", useRightHJCnode="RHJC_Hara", useLeftKJCnode="LKJC_mid", useLeftAJCnode="LAJC_mid", useRightKJCnode="RKJC_mid", useRightAJCnode="RAJC_mid", markerDiameter=markerDiameter).compute() # ------ LEFT KNEE CALIBRATION ------- acqFunc = btkTools.smartReader(str(MAIN_PATH + funcFilename)) # Motion of only left modMotionLeftKnee = modelFilters.ModelMotionFilter( scp, acqFunc, model, enums.motionMethod.Sodervisk) modMotionLeftKnee.segmentalCompute(["Left Thigh", "Left Shank"]) # decorator modelDecorator.KneeCalibrationDecorator(model).sara( "Left", indexFirstFrame=831, indexLastFrame=1280) # ----add Point into the c3d---- Or_inThigh = model.getSegment("Left Thigh").getReferential( "TF").getNodeTrajectory("KneeFlexionOri") axis_inThigh = model.getSegment("Left Thigh").getReferential( "TF").getNodeTrajectory("KneeFlexionAxis") btkTools.smartAppendPoint(acqFunc, "Left" + "_KneeFlexionOri", Or_inThigh) btkTools.smartAppendPoint(acqFunc, "Left" + "_KneeFlexionAxis", axis_inThigh) # ------ RIGHT KNEE CALIBRATION ------- # Motion of only left modMotionRightKnee = modelFilters.ModelMotionFilter( scp, acqFunc, model, enums.motionMethod.Sodervisk) modMotionRightKnee.segmentalCompute(["Right Thigh", "Right Shank"]) # decorator modelDecorator.KneeCalibrationDecorator(model).sara("Right", indexFirstFrame=61, indexLastFrame=551) # ----add Point into the c3d---- Or_inThigh = model.getSegment("Right Thigh").getReferential( "TF").getNodeTrajectory("KneeFlexionOri") axis_inThigh = model.getSegment("Right Thigh").getReferential( "TF").getNodeTrajectory("KneeFlexionAxis") btkTools.smartAppendPoint(acqFunc, "Right" + "_KneeFlexionOri", Or_inThigh) btkTools.smartAppendPoint(acqFunc, "Right" + "_KneeFlexionAxis", axis_inThigh) btkTools.smartWriter(acqFunc, "acqFunc-Sara.c3d") #--- FINAL CALIBRATION --- modelFilters.ModelCalibrationFilter( scp, acqStatic, model, useLeftHJCnode="LHJC_Hara", useRightHJCnode="RHJC_Hara", useLeftKJCnode="KJC_Sara", useLeftAJCnode="LAJC_mid", useRightKJCnode="KJC_Sara", useRightAJCnode="RAJC_mid", markerDiameter=markerDiameter).compute() # save static c3d with update KJC btkTools.smartWriter(acqStatic, "Static-SARA.c3d") # print functional Offsets print model.mp_computed["LeftKneeFuncCalibrationOffset"] print model.mp_computed["RightKneeFuncCalibrationOffset"]
def calibrate(self, aquiStatic, dictRef, dictAnatomic, options=None): # add markers valSACR = (aquiStatic.GetPoint("LPSI").GetValues() + aquiStatic.GetPoint("RPSI").GetValues()) / 2.0 btkTools.smartAppendPoint(aquiStatic, "SACR", valSACR, desc="") valMidAsis = (aquiStatic.GetPoint("LASI").GetValues() + aquiStatic.GetPoint("RASI").GetValues()) / 2.0 btkTools.smartAppendPoint(aquiStatic, "midASIS", valMidAsis, desc="") valLMET = (aquiStatic.GetPoint("LFMH").GetValues() + aquiStatic.GetPoint("LVMH").GetValues()) / 2.0 btkTools.smartAppendPoint(aquiStatic, "LMET", valLMET, desc="") valRMET = (aquiStatic.GetPoint("RFMH").GetValues() + aquiStatic.GetPoint("RVMH").GetValues()) / 2.0 btkTools.smartAppendPoint(aquiStatic, "RMET", valRMET, desc="") ff = aquiStatic.GetFirstFrame() lf = aquiStatic.GetLastFrame() frameInit = ff - ff frameEnd = lf - ff + 1 # calibrate technical self._calibrateTechnicalSegment(aquiStatic, "Pelvis", dictRef, frameInit, frameEnd, options=options) self._calibrateTechnicalSegment(aquiStatic, "Left Thigh", dictRef, frameInit, frameEnd, options=options) self._calibrateTechnicalSegment(aquiStatic, "Right Thigh", dictRef, frameInit, frameEnd, options=options) self._calibrateTechnicalSegment(aquiStatic, "Left Shank", dictRef, frameInit, frameEnd, options=options) self._calibrateTechnicalSegment(aquiStatic, "Right Shank", dictRef, frameInit, frameEnd, options=options) self._calibrateTechnicalSegment(aquiStatic, "Left Foot", dictRef, frameInit, frameEnd, options=options) self._calibrateTechnicalSegment(aquiStatic, "Right Foot", dictRef, frameInit, frameEnd, options=options) # # ---- decorator ---- modelDecorator.HipJointCenterDecorator(self).greatTrochanterOffset( aquiStatic) modelDecorator.KneeCalibrationDecorator(self).midCondyles(aquiStatic) modelDecorator.AnkleCalibrationDecorator(self).midMaleolus(aquiStatic) # calibrate anatomic self._calibrateAnatomicalSegment(aquiStatic, "Pelvis", dictAnatomic, frameInit, frameEnd, options=options) self._calibrateAnatomicalSegment(aquiStatic, "Left Thigh", dictAnatomic, frameInit, frameEnd, options=options) self._calibrateAnatomicalSegment(aquiStatic, "Right Thigh", dictAnatomic, frameInit, frameEnd, options=options) self._calibrateAnatomicalSegment(aquiStatic, "Left Shank", dictAnatomic, frameInit, frameEnd, options=options) self._calibrateAnatomicalSegment(aquiStatic, "Right Shank", dictAnatomic, frameInit, frameEnd, options=options) self._calibrateAnatomicalSegment(aquiStatic, "Left Foot", dictAnatomic, frameInit, frameEnd, options=options) self._calibrateAnatomicalSegment(aquiStatic, "Right Foot", dictAnatomic, frameInit, frameEnd, options=options)
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)
acqStatic = btkTools.smartReader(str(MAIN_PATH + staticFilename)) model = cgm2.CGM2_2LowerLimbs() model.configure() model.addAnthropoInputParameters(mp) # ------ calibration ------- scp = modelFilters.StaticCalibrationProcedure(model) modelFilters.ModelCalibrationFilter(scp, acqStatic, model).compute() # cgm decorator modelDecorator.HipJointCenterDecorator(model).hara() modelDecorator.KneeCalibrationDecorator(model).midCondyles( acqStatic, markerDiameter=markerDiameter, side="both") modelDecorator.AnkleCalibrationDecorator(model).midMaleolus( acqStatic, markerDiameter=markerDiameter, side="both") # final modelFilters.ModelCalibrationFilter( scp, acqStatic, model, markerDiameter=markerDiameter).compute() # ------ Fitting ------- acqGait = btkTools.smartReader(str(MAIN_PATH + gaitFilename)) # Motion FILTER modMotion = modelFilters.ModelMotionFilter( scp, acqGait, model, pyCGM2Enums.motionMethod.Determinist) modMotion.compute() # relative angles modelFilters.ModelJCSFilter(model,