[770c98]: / Docs / body / _static / TLEM22_TLEM21_comparison.any

Download this file

427 lines (373 with data), 19.0 kB

#path ANYBODY_PATH_OUTPUT "."
#include "../../../libdef.any"

#define BM_ARM_LEFT OFF
#define BM_ARM_RIGHT OFF
#define BM_TRUNK_MUSCLES OFF
#define BM_LEG_MODEL _LEG_MODEL_TLEM2_

#define BM_SCALING _SCALING_NONE_
#define SHOW_AMMR24_FOOT 1
#define SHOW_AMMR25_FOOT 0
#define BM_LEG_MUSCLES_BOTH OFF
#define BM_LEG_LEFT OFF


#include "<ANYBODY_PATH_MODELUTILS>/Video/VideoLookAtCamera.any"




Main = {
  
  AnyFloat AMMR24Color = {0.6,0.6,0.6};
  
  Main.HumanModel.BodyModel.Right.Leg.Seg = {
    AnySeg Shank2 = {
      Mass = 0;
      Jii = {0,0,0};
      r0=.Thigh.KneeJoint.sRel*.Thigh.Axes0'+.Thigh.r0-OldKneeJoint.sRel*Axes0';
      Axes0 = 
          .Thigh.Axes0*
          .Thigh.KneeJoint.ARel*
          .Thigh.KneeJoint.RotNode.ARel*
          RotMat((-pi/180)*...JointPos.KneeFlexion,z)*
          OldKneeJoint.RotNode.ARel'*
          OldKneeJoint.ARel';

      AnyVar Sign = .Shank.Sign;      
      AnyFunTransform3D &Scale =.Shank.Scale;      
      AnyDrawSurf DrwSurfTibia =
      {
        FileName ??= ..STL.FilenameShank;
        ScaleXYZ ??= {1.0, 1.0, ...Sign*1.0};
        RGB ??= Main.AMMR24Color;
        AnyFunTransform3D &Scale =.Scale;
        Opacity ??= ...BonesOpacity.Shank;
        Face=-1;
      };
      AnyDrawSurf DrwSurfFibula = {
        FileName ??= ..STL.FilenameFibula;
        ScaleXYZ ??= {1.0, 1.0, ...Sign*1.0};
        RGB ??= Main.AMMR24Color;
        AnyFunTransform3D &Scale =.Scale; 
        Opacity ??= ...BonesOpacity.Shank;
        Face=-1;
      };  
      AnyMat33 TF = {{1,0,0},{0,1,0},{0,0,Sign}};
      AnyFolder StdPar = {
        AnyVec3 MedialMalleolus = {0.017065441344676, 0.004967186589899, -0.027608399085015}*.TF';
        AnyVec3 LateralMalleolus = {-0.017065441344676,  -0.004967186589900,   0.027608399085015}*.TF';
        AnyFloat KneeJointAxis = .Sign*{0.02081402, 0.1209213,0.9924439}*.TF'/ vnorm({0.02081402, 0.1209213,0.9924439});
        AnyVec3 KneeJoint = ..Shank.StdPar.KneeJoint;
        AnyVec3 LateralFemuralCondyleInNeutralConf = ..Shank.StdPar.LateralFemuralCondyleInNeutralConf;
        AnyVec3 MedialFemuralCondyleInNeutralConf = ..Shank.StdPar.MedialFemuralCondyleInNeutralConf;
        AnyVec3 Insertion_patella_tendon = ..Shank.StdPar.Insertion_patella_tendon;
        AnyVec3 LateralTibialEpicondyle = ..Shank.StdPar.LateralTibialEpicondyle;
        AnyVec3 MedialTibialEpicondyle = ..Shank.StdPar.MedialTibialEpicondyle;        
      };
      
      AnyFloat pUnscaled = {StdPar.LateralMalleolus, StdPar.MedialMalleolus, StdPar.LateralTibialEpicondyle, StdPar.MedialTibialEpicondyle};
      AnyFunTransform3D& GeomScale = ..GeoScaling.Shank.ScaleFunction;
      #define MACRO_CONSTRUCT_ANATOMICAL_FRAME_s(p, SIGN) 0.5*(p[2]+p[3])
      #define MACRO_CONSTRUCT_ANATOMICAL_FRAME_A(p, SIGN) RotMat(0.5*(p[2]+p[3]), 0.5*(p[0]+p[1]), p[2]) *RotMat(0.5*pi,y)*RotMat(-0.5*pi,x)*RotMat(0.5*(SIGN-1)*pi,y)
      
//      #include "..\Scaling\SegScaleFunWrtAnatomicalFrame.any"
      
      AnyRefNode AnatomicalFrame =
      {
        AnyFloat pScaled = .Scale(.pUnscaled);
        sRel = MACRO_CONSTRUCT_ANATOMICAL_FRAME_s(pScaled, .Sign);
        ARel = MACRO_CONSTRUCT_ANATOMICAL_FRAME_A(pScaled, .Sign);
        AnyVec3 sRelUnscaled = MACRO_CONSTRUCT_ANATOMICAL_FRAME_s(.pUnscaled, .Sign); ///< Generic unscaled position of shank ScalingNode
        AnyMat33 ARelUnscaled = MACRO_CONSTRUCT_ANATOMICAL_FRAME_A(.pUnscaled, .Sign);///< Generic unscaled rotation of shank ScalingNode
      };
      #undef MACRO_CONSTRUCT_ANATOMICAL_FRAME_s
      #undef MACRO_CONSTRUCT_ANATOMICAL_FRAME_A

//      AnyRefNode &AnatomicalFrame = .Shank.AnatomicalFrame;
      AnyRefNode Insertion_patella_tendon = { sRel =.Scale(.StdPar.Insertion_patella_tendon);};
      
      AnyKinPLine PatellaTendon = {
        // These are the nodes that the measure refers to. The connection is regarded
        // as being stiff. 
        AnyRefNode &Origin_patella_tendon = ..Patella.Origin_patella_tendon;
        AnyRefNode &Insertion_patella_tendon = .Insertion_patella_tendon;
        
        
        //AnyRefNode &Insertion_patella_tendon = ...Seg.Shank.Insertion_patella_tendon;
        
        AnyDrawPLine Patella_tendon = 
        {
          Thickness = 0.001;
          RGB = Main.AMMR24Color;
          Opacity = ....BonesOpacity.Patella;
        };
      };
      
      
      AnyRefNode OldAnkleJoint = {
        AnyVar TibialTorsionOffset = DesignVar(0);
//        AnyVec3 sRelUnscaled =  .StdPar.AnkleJoint;
        
        AnyVec3 OldAnkleJoint = {0.01337003, -0.01126083, 0.0007477404};
        AnyVec3 OldAnkleJointAxis = normalize({0.362799, 0.1304906, -0.9226858});
        
        AnyMat33 ARelUnscaled =   RotMat({0, 0, 0.0}, .Sign*(AnkleLateralControlPoint-AnkleMedialControlPoint ), .AnatomicalFrame.ARelUnscaled'[1])*RotMat(pi/2,y);
        // Control point for the Ankle joint. Found by projecting the malleolus bony landmarks onto the
        // ankle axis from the cadaver data set. Thus, scaling the control points will also scale the ankle joint axis
        AnyVec3 AnkleLateralControlPoint =  OldAnkleJoint + (.StdPar.LateralMalleolus - OldAnkleJoint)*OldAnkleJointAxis'*OldAnkleJointAxis;
        // Control point for the Ankle joint. Found by projecting the malleolus bony landmarks onto the
        // ankle axis from the cadaver data set. Thus, scaling the control points will also scale the ankle joint axis
        AnyVec3 AnkleMedialControlPoint = OldAnkleJoint + (.StdPar.MedialMalleolus - OldAnkleJoint)*OldAnkleJointAxis'*OldAnkleJointAxis;
        sRel = .Scale(OldAnkleJoint);
        // Ankle Joint orientation is calculated based on the direction between the two control points.
        ARel = RotMat({0,0,0.0}, .Sign*(.Scale(AnkleLateralControlPoint) - .Scale(AnkleMedialControlPoint) ),  .AnatomicalFrame.ARel'[1])*RotMat(pi/2,y)*RotMat(TibialTorsionOffset,y);
      }; 
      
      AnyRefNode OldKneeJoint = {
        AnyVec3 sRelUnscaled = .StdPar.KneeJoint;
        AnyMat33 ARelUnscaled =  RotMat({0,0,0.0},
                                .Sign*(LateralControlPoint - MedialControlPoint),
                                -1*.AnatomicalFrame.ARelUnscaled'[1])*RotMat(pi,z)*RotMat(-pi/2,y);
        /// Control point for the knee joint. Found by projecting the EpicondylusFemoris bony landmarks onto the
        /// knee axis from the cadaver data set. Thus, scaling the control points will also scale the Knee joint axis
        AnyVec3 LateralControlPoint = .StdPar.KneeJoint + (.StdPar.LateralFemuralCondyleInNeutralConf - .StdPar.KneeJoint)*.StdPar.KneeJointAxis'*.StdPar.KneeJointAxis;
        /// Control point for the knee joint. Found by projecting the EpicondylusFemoris bony landmarks onto the
        /// knee axis from the cadaver data set. Thus, scaling the control points will also scale the Knee joint axis
        AnyVec3 MedialControlPoint = .StdPar.KneeJoint + (.StdPar.MedialFemuralCondyleInNeutralConf - .StdPar.KneeJoint)*.StdPar.KneeJointAxis'*.StdPar.KneeJointAxis;      
        
        sRel = .Scale(.StdPar.KneeJoint);
        /// Knee Joint orientation is calculated based on the direction between the two control points.
        ARel = RotMat({0,0,0.0}, .Sign*(.Scale(LateralControlPoint)-.Scale(MedialControlPoint)), -1*.AnatomicalFrame.ARel'[1])*RotMat(pi,z)*RotMat(-pi/2,y);
        
        AnyRefNode RotNode={
          ARel={{....Sign*1,0,0},{0,....Sign*1,0},{0,0,1}};
        };  
        AnyDrawLine line = {
          p0 = 0.05*{0,0,1};
          p1 = -0.05*{0,0,1};
          Line.RGB = Main.AMMR24Color;
          GlobalCoord = Off;
        };        
      };
    };
  };
  Main.HumanModel.BodyModel.Right.Leg = {
    Jnt = {
      
      AnyRevoluteJoint Knee2 = {
        AnyRefFrame &thigh = .Knee.ThighNode;
        AnyRefFrame &shank = ..Seg.Shank2.OldKneeJoint;
        Axis = z;
      };
      AnyKinEqSimpleDriver Knee2Drv = {
        AnyKinMeasure &KneeJoint2 = .Knee2;
        DriverPos = {Main.HumanModel.Mannequin.Posture.Right.KneeFlexion*pi/180};
        DriverVel = {Main.HumanModel.Mannequin.PostureVel.Right.KneeFlexion*pi/180};
      };
    };
  };
  
  Main.HumanModel.BodyModel.Right.Leg.Seg.Shank = {
  AnyRefNode OldAnkleJoint = {
     AnyVar TibialTorsionOffset = DesignVar(0);
       AnyVec3 sRelUnscaled =  .StdPar.AnkleJoint;
       
       AnyVec3 OldAnkleJoint = {0.01337003, -0.01126083, 0.0007477404};
       AnyVec3 OldAnkleJointAxis = normalize({0.362799, 0.1304906, -0.9226858});
       
       AnyMat33 ARelUnscaled =   RotMat({0, 0, 0.0}, .Sign*(AnkleLateralControlPoint-AnkleMedialControlPoint ), .AnatomicalFrame.ARelUnscaled'[1])*RotMat(pi/2,y);
       // Control point for the Ankle joint. Found by projecting the malleolus bony landmarks onto the
       // ankle axis from the cadaver data set. Thus, scaling the control points will also scale the ankle joint axis
       AnyVec3 AnkleLateralControlPoint =  OldAnkleJoint + (.StdPar.LateralMalleolus - OldAnkleJoint)*OldAnkleJointAxis'*OldAnkleJointAxis;
       // Control point for the Ankle joint. Found by projecting the malleolus bony landmarks onto the
       // ankle axis from the cadaver data set. Thus, scaling the control points will also scale the ankle joint axis
       AnyVec3 AnkleMedialControlPoint = OldAnkleJoint + (.StdPar.MedialMalleolus - OldAnkleJoint)*OldAnkleJointAxis'*OldAnkleJointAxis;
       sRel = .Scale(OldAnkleJoint);
       // Ankle Joint orientation is calculated based on the direction between the two control points.
       ARel = RotMat({0,0,0.0}, .Sign*(.Scale(AnkleLateralControlPoint) - .Scale(AnkleMedialControlPoint) ),  .AnatomicalFrame.ARel'[1])*RotMat(pi/2,y)*RotMat(TibialTorsionOffset,y);
     };    
  };

  Main.HumanModel.BodyModel.Right.Leg.Seg.Shank.OldAnkleJoint = {
    AnyDrawLine line = {
      p0 = 0.05*{0,0,1};
      p1 = -0.05*{0,0,1};
      Line.RGB = Main.AMMR24Color;
      GlobalCoord = Off;
    };
  };
  Main.HumanModel.BodyModel.Right.Leg.Seg.Foot.Talus.AnkleJoint = {
    AnyDrawLine line = {
      p0 = 0.05*{0,0,1};
      p1 = -0.05*{0,0,1};
      GlobalCoord = Off;
    };
  };
  Main.HumanModel.BodyModel.Right.Leg.Seg.Shank.KneeJoint = {
    AnyDrawLine line = {
      p0 = 0.05*{0,0,1};
      p1 = -0.05*{0,0,1};
      GlobalCoord = Off;
    };
  };

  Main.HumanModel.BodyModel.Right.Leg.Seg.Shank2 = {
    
    
    #if SHOW_AMMR25_FOOT == 1
    AnyRefNode AMMR25Foot = {
      // LinRotZYXPos is the output of linear and rotational (RotAxesAngles) measures between the shank and foot with Ref = 0 for lin measure.
      // AMMR 25 foot uses the values from AMMR shipped with AMS 7.5.0.10984. This includes the update of talus segmental frame to be coincident 
      // with the foot segmental frame and redefinition of foot/talus anatomical frame using bony landmarks. See AMMR master PR #800 and #810 on
      // github for details.
      AnyFloat LinRotZYXPos = {0.0073004129631475583, -0.030270340545254942, 0.0068700894472033197, 0.044073349632333815, -0.013175969238109486, -0.031498255158394939};
      sRel = take(LinRotZYXPos, {0,1,2});
      ARel = RotMat(LinRotZYXPos[3],z)*RotMat(LinRotZYXPos[4],y)*RotMat(LinRotZYXPos[5],x);
      AnyDrawSurf FootSurf = {
        //        FileName = Main.HumanModel.BodyModel.Right.Leg.Seg.Foot.DrwSurf.FileName;
        FileName = "Surfs25/foot";
        RGB = {1,0,0};
      };
      AnyDrawSurf TalusSurf = {
        FileName = "Surfs25/talus";
        RGB = {1,0,0};
      };
    };
    #endif
    
    #if SHOW_AMMR24_FOOT == 1
    AnyRefNode AMMR24Foot = {
      // LinRotZYXPos is the output of linear and rotational (RotAxesAngles) measures between the shank and foot with Ref = 0 for lin measure.
      // AMMR 24 foot uses the values from AMMR 2.4.4. 
      AnyFloat LinRotZYXPos =  {0.0066484131164842976, -0.030121205310853393, 0.006633998007163501, 0.0078587544343148297, -0.0084462997063536882, -0.017192110582242365};
      sRel = take(LinRotZYXPos, {0,1,2});
      ARel = RotMat(LinRotZYXPos[3],z)*RotMat(LinRotZYXPos[4],y)*RotMat(LinRotZYXPos[5],x);
      AnyDrawSurf FootSurf = {
        FileName = "Surfs24/foot";
        RGB = Main.AMMR24Color;
      };
      AnyRefNode AMMR24TalusNodeInFoot = {
        // LinRotZYXPos is the output of linear and rotational (RotAxesAngles) measures between the foot and talus with Ref = 0 for lin measure.
        // AMMR 2.4.4 has separate segmental frames for talus and foot. Therefore, the need for two nodes.
        AnyFloat LinRotZYXPos = {0.0064517313882190806, 0.024429377011198451, -0.0055430553948084332, 0.0018108189479568528, 0.0070842459268321001, 0.013447326605168291}; //
        //{0.012958866336459846, -0.0057403859490013399, 0.00072649518666837104, 0.0095474755358000256, -0.0013319584159514619, -0.0037594545457295004}; AMMR 24 Talus in Shank
        sRel = take(LinRotZYXPos, {0,1,2});
        ARel = RotMat(LinRotZYXPos[3],z)*RotMat(LinRotZYXPos[4],y)*RotMat(LinRotZYXPos[5],x);
        AnyDrawSurf TalusSurf = {
          FileName = "Surfs24/talus";
          RGB = Main.AMMR24Color;
        };
      };
    };
    #endif
    
  };
  
  
  VideoLookAtCamera SnapShot1(UP_DIRECTION=y, _AUTO_OPEN_PREVIEW_=0) =
  {
    VideoName = "TLEM22_TLEM21_closeup";
    Analysis = {
      AnyOperation &ref = Main.study.InitialConditions;
    };
    Camera.Perspective = On;
    CameraDistance = 1.04;
    VideoInputScale = 5;
    VideoResolution = {600,600};
//    CameraLookAtPoint = Main.HumanModel.BodyModel.Trunk.SegmentsLumbar.PelvisSeg.r+{0,-0.96,0};
    CameraLookAtPoint = Main.HumanModel.BodyModel.Right.Leg.Seg.Foot.r + {0,0.15,0};
    CameraFieldOfView = DesignVar(0.45);
    CameraDirection  = {1,0.2,0.50};
    BackgroundColor = DesignVar({1,1,1});
    Preview.FileName = VideoName + ".jpg";
  };   

  VideoLookAtCamera SnapShot_Top(UP_DIRECTION=y, _AUTO_OPEN_PREVIEW_=0) =
  {
    VideoName = "TLEM22_TLEM21_TopView";
    Analysis = {
      AnyOperation &ref = Main.study.InitialConditions;
    };
    Camera.Perspective = On;
    CameraDistance = 1.04;
    VideoInputScale = 5;
    VideoResolution = {600,600};
//    CameraLookAtPoint = Main.HumanModel.BodyModel.Trunk.SegmentsLumbar.PelvisSeg.r+{0,-0.96,0};
    CameraLookAtPoint = Main.HumanModel.BodyModel.Right.Leg.Seg.Foot.r + {0.05,0.0,0};
    CameraFieldOfView = DesignVar(0.65);
    CameraDirection  = {0.0001,0.65,0.0};
    BackgroundColor = DesignVar({1,1,1});
    Preview.FileName = VideoName + ".jpg";
//    viewCamera = On;
  };  
  
  VideoLookAtCamera SnapShot_Front(UP_DIRECTION=y, _AUTO_OPEN_PREVIEW_=0) =
  {
    VideoName = "TLEM22_TLEM21_FrontView";
    Analysis = {
      AnyOperation &ref = Main.study.InitialConditions;
    };
    Camera.Perspective = On;
    CameraDistance = 1.04;
    VideoInputScale = 5;
    VideoResolution = {600,600};
//    CameraLookAtPoint = Main.HumanModel.BodyModel.Trunk.SegmentsLumbar.PelvisSeg.r+{0,-0.96,0};
    CameraLookAtPoint = Main.HumanModel.BodyModel.Right.Leg.Seg.Foot.r + {0.0,0.15,0};
    CameraFieldOfView = DesignVar(0.65);
    CameraDirection  = {1,0.0,0.0};
    BackgroundColor = DesignVar({1,1,1});
    Preview.FileName = VideoName + ".jpg";
//    viewCamera = On;
  }; 
  
  VideoLookAtCamera SnapShot_Side(UP_DIRECTION=y, _AUTO_OPEN_PREVIEW_=0) =
  {
    VideoName = "TLEM22_TLEM21_SideView";
    Analysis = {
      AnyOperation &ref = Main.study.InitialConditions;
    };
    Camera.Perspective = On;
    CameraDistance = 1.04;
    VideoInputScale = 5;
    VideoResolution = {600,600};
//    CameraLookAtPoint = Main.HumanModel.BodyModel.Trunk.SegmentsLumbar.PelvisSeg.r+{0,-0.96,0};
    CameraLookAtPoint = Main.HumanModel.BodyModel.Right.Leg.Seg.Foot.r + {0.0,0.15,0};
    CameraFieldOfView = DesignVar(0.65);
    CameraDirection  = {0,0.0,1.0};
    BackgroundColor = DesignVar({1,1,1});
    Preview.FileName = VideoName + ".jpg";
//    viewCamera = On;
  }; 
  
  VideoLookAtCamera SnapShot_Foot_Front(UP_DIRECTION=y, _AUTO_OPEN_PREVIEW_=0) =
  {
    VideoName = "TLEM22_TLEM21_Foot_FrontView";
    Analysis = {
      AnyOperation &ref = Main.study.InitialConditions;
    };
    Camera.Perspective = On;
    CameraDistance = 1.04;
    VideoInputScale = 5;
    VideoResolution = {600,600};
//    CameraLookAtPoint = Main.HumanModel.BodyModel.Trunk.SegmentsLumbar.PelvisSeg.r+{0,-0.96,0};
    CameraLookAtPoint = Main.HumanModel.BodyModel.Right.Leg.Seg.Foot.r + {0.0,0.0,0};
    CameraFieldOfView = DesignVar(0.25);
    CameraDirection  = {1,0.0,0.0};
    BackgroundColor = DesignVar({1,1,1});
    Preview.FileName = VideoName + ".jpg";
//    viewCamera = On;
  }; 
  
  VideoLookAtCamera SnapShot_Foot_Side(UP_DIRECTION=y, _AUTO_OPEN_PREVIEW_=0) =
  {
    VideoName = "TLEM22_TLEM21_Foot_SideView";
    Analysis = {
      AnyOperation &ref = Main.study.InitialConditions;
    };
    Camera.Perspective = On;
    CameraDistance = 1.04;
    VideoInputScale = 5;
    VideoResolution = {600,600};
//    CameraLookAtPoint = Main.HumanModel.BodyModel.Trunk.SegmentsLumbar.PelvisSeg.r+{0,-0.96,0};
    CameraLookAtPoint = Main.HumanModel.BodyModel.Right.Leg.Seg.Foot.r + {0.08,0.0,0};
    CameraFieldOfView = DesignVar(0.25);
    CameraDirection  = {0,0.0,1.0};
    BackgroundColor = DesignVar({1,1,1});
    Preview.FileName = VideoName + ".jpg";
//    viewCamera = On;
  }; 
  
  
  
  VideoLookAtCamera RotatingVideo(UP_DIRECTION=y , _AUTO_PLAY_VIDEOS=OFF, VIDEO_ENCODER="libx264") =
  {
    VideoName = "TLEM22_TLEM21_rotating_model";
    
    Analysis = {
      AnyOperation &ref = Main.study.Kinematics;
    };
    VideoInputScale = 5;
    VideoResolution = {650,650};
    VideoInputFrameRate = 30; 
    VideoOutputFrameRate = 30;
//    CameraLookAtPoint = Main.HumanModel.BodyModel.Trunk.SegmentsLumbar.PelvisSeg.r+{0, -0.90, 0};
    CameraLookAtPoint = Main.HumanModel.BodyModel.Right.Leg.Seg.Foot.r + {0,0.18,0};
    CameraFieldOfView = DesignVar(0.55);
    CameraDirection  = {cos(2*pi*Main.study.t),0,sin(2*pi*Main.study.t) };
    BackgroundColor = DesignVar({1,1,1});
    Counter = Main.study.iStep;
  }; 
   
  
  #include "<ANYBODY_PATH_BODY>\HumanModel.any"
    
  HumanModel.Mannequin.Posture.Right = {
    ElbowPronation = -70;
    WristAbduction = 15;
  };
 
  AnyBodyStudy study = 
  {
    AnyFolder& CameraRef1 = Main.RotatingVideo;
    AnyFolder& Model = Main.HumanModel.BodyModelWithDefaultDrivers;
    Gravity = {0, -9.81, 0};
    nStep = 150;
  };
  
  
  AnyOperationSequence RunApplication = 
  {
     AnyOperation& initpos = Main.study.InitialConditions;
     AnyOperation& SnapShot1 = Main.SnapShot1.Preview;
     AnyOperation& RotatingVideo = Main.RotatingVideo.Create_Video;
  };
  
};