Implementation of morphed TLEM 2 Femur

Hello together,

my colleague and I are currently working on a bone-morphing problem and @CDzialo asked us if we could share the issue here with the community. So there you go ;-).

We took the TLEM 2 femur from the AMMR and changed its anteversion, neck length, CCD angle and femoral length with a MatLab script without further changes of the mesh-topology. So the number of the vertices are the same, but their positions might have changed. Especially in the proximal part of the femur.

Our question is: how can we import the “new” vertex positions back into AnyBody?

Considering that we did not use the whole transformation process, like it is shown in tutorial 15, lesson 1.

Thanks in advance!

Best wishes

Lukas

Hi Lukas,

Unfortunately you will need to do the morphing to “import the new vertices back”. The good news are that you can select points on your STL files using the block of code below :

AnyInt NumPoints0 = STL_Size(SourceSTL, 1)[0];
AnyFileVar SourceSTL = FilePathCompleteOf(…Source.Right.FilenamePelvis) + “.stl”;
AnyMatrix Points0unscaled = STL_Vertices(SourceSTL, iarr(0, floor(NumPoints0/NumPoints), NumPoints0 - 1), 1);

You can then copy and paste all those transformations to get your morphing ready. But this will, of course, require the mesh topology to be consistent with the source bone. Meaning that those vertices that you moved - should represent same areas of the original bone.

If this is not the case - you can still use those vertices that match, but add a new logic to the modified regions.

Kind regards,
Pavel

Hello Pavel,

I just would like to say thanks for your reply :slight_smile: .
By now it seems that everything is going to work just fine with our model.

Best wishes

Lukas

2 Likes

Hello @pgalibarov ,

yesterday I tried to run a Parameter Identification with the “morphed femur” model.
Loading the model works fine. It looks like this:
Marker
Model%201

When I started the Parameter Identification, I got an error message that said, the kinematic analysis failed and there were lots of constraint violations.


Could it be that those “lost” markerpoints are the reason for this?
How do those Markerpoints behave and how can I make the simulation work?

This is the code how we implement the femur:



One last question:
Can I be sure that only the femur bones are now scaled differently and that other bones are not affected by their new morphology?

Big thanks in Advance and best wishes

Lukas

Hi Lukas,

Do your source and target STLs both have units in [m]?

Best Regards,
Christine

Hi Christine,

I think that they’re both in [m].

Can I check which units they have in AnyBody? Somewhere in the Modeltree?

I guess that the original bone in AnyBody is in [m]?

Best wishes

Lukas

Hi Lukas,

AnyBody is in [m].

I think the problem may be that you are not applying the ‘TSeg2ScaleFrame’ transformation to your Points0unscaled (both in the affinetransformation and the RBF).

AnyFunTransform3D &TSeg2ScaleFrame = Main.HumanModel.Scaling.GeometricalScaling.Right.Thigh.TSeg2ScaleFrame; 

AnyFunTransform3DLin2 AffineTransform = {
  Points0 = ..TSeg2ScaleFrame(
  {{0.0138187,0.00136731,0.0273618},   
...

AnyFunTransform3DRBF RBFTransform = {
  PreTransforms = {&.AffineTransform};
  RBFDef = {
    Type = RBF_ThinPlate;
    Param = 1;
  };
  Points0 = ..TSeg2ScaleFrame({
    { 0.0138, 0.0014, 0.0274},
...

Also within the STLTransform function, when you use AnySurfSTL for the source surf, this also should include:

  AnySurfSTL SourceSurf = {
    FileName = "SourceFemur.stl";
    ScaleXYZ = {1, 1, 1};
    AnyFunTransform3D &pre = ....TSeg2ScaleFrame;

In the first part of this tutorial it shows where to add this code in: https://anyscript.org/tutorials/Scaling/lesson4.html Hope this helps.

best regards,
Christine

Hello Christine,

thanks for your emediate replies =).
As you suggested, I changed the code in every necessary position, but now the model looks like this:

And I recieve the same Error during Parameter Identification.

Is it possible that if the initially defined scaling, which is for my subject specific simulations the SCALING_LENGTHMASSFAT (defined in the BodyModelConfig).
is not SCALING_STANDARD is a reason for the strange looking model?
Because the scaling in the Tutorial should be set to STANDARD.

Best wishes

Lukas

Hi Lukas,

Can you send me your model and the two STLs you are using? It might take less time to debug that way.

Best Regards,
Christine

Hi, Lukas,

As far as I’m concerned, SCALING_LENGTHMASSFAT is fine with the custom scaling.

I believe the reason is you used the AnyFunTransform3DSTL which requires the surfaces have to be topologically equivalent, i.e. the surfaces have the same number of triangles and each neighbor and vertices represent the same features on both surfaces.
Please try to use RBFTransform scalefunction like this:

AnyFunTransform3DIdentity ScaleFunction = {
PreTransforms = {&.RBFTransform, &.ReverseTransform}; // Using RBF Transform
};

Best Wishes,
Lee

1 Like

@Nickel_Lee, That’s correct you can use SCALING_LENGTHMASSFAT just fine, the tutorial has STANDARD just as an example.

Hi Lukus,

Looking at your code I found the following things going wrong:

  • Since the stls are both of right femurs, Mirroring will need to happen on the left leg, adjust CustomScalingFemur.any to account for this.

  • The STLs were both in mm so *0.001 needs to be applied to code using the STLs or points derived from STLs in order to bring back into [m] for use in AnyBody. For example:

    AnyMatrix Points0unscaled = 
    STL_Vertices(SourceSTL,iarr(0,floor(NumPoints0/NumPoints),NumPoints0 -1),1)*0.001;
    

and here…

  AnySurfSTL SourceSurf = {
    FileName = "TLEM_21.stl";
    ScaleXYZ = {1, 1, 1}*0.001;
    AnyFunTransform3D &pre = ....TSeg2ScaleFrame;
  };
  • ‘TSeg2ScaleFrame’ needs to be added to various locations according to: this post: Implementation of morphed TLEM 2 Femur )

  • You can change your STLTransform settings such that UseClosestPointMatchingOnOff=Off since you are lucky enough to have matching topology :blush:

Then you will get something like this (green is the actual target geometry so you can visualise how well AnyBody morphs to the subject-specific geometry)

Hope this helps.

Best Regards,
Christine

1 Like

Hello Christine,

thanks again for the help.

The Morphing is working and I got the first simulation results.

Best wishes

Lukas

1 Like

Hello Christine,

I have a few more questions for you that came up.

  1. During the scaling, is the Bergmann coordinate system, that is located in the hip joint centers, affected by any changes?
  2. Are all the muscles/ muscle attachment sites/ muscle wrappings also scaled/ fitted when the bone is morphed?
  3. We have the problem that the simulation is not working for one of our subjects. Do you have any suggestions?

Best wishes

Lukas

Hi Lukas,

1: When a segment is scaled all nodes on the segment is usually scaled.
You can always visualize the coordinate system in the node to see its position and orientation, using an AnyDrawRefFrame .

2: As a rule yes all nodes are scaled, wrapping surfaces are controlled by points and these points are part of the scaling so when the move the wrapping surface will change.

3: Please be more specific what is not working?

Best regards
Søren

Hi

I'm the supervisor of Lukas, who has finished his work now.

Regarding point 3:
The error of the RunAnalysis is:

#### Macro command : mcr(1:1)> classoperation Main.ModelSetup.Views.KinematicView"Set View"
1.0.1.0.0.2) ...Kinematic analysis completed.
1.0.1.0.0.3) ...Dependent variables are fully updated.
1.0.1.0) Kinematic analysis...
Progressing to solve kinematic optimality conditions and hard constraints.
Progressing to solve kinematic optimality conditions and hard constraints.
Progressing to solve kinematic optimality conditions and hard constraints.
Progressing to solve kinematic optimality conditions and hard constraints.
Failed to solve kinematic optimality conditions and hard constraints after 5 fallback attemps.
Constraint violations for study 'Main.Studies.MarkerTracking' : 
ERROR(OBJ.MCH.KIN3) :   D:/B..s/Hip/A..y/ammr/T..s/A..p/AnyMocapModel.any(41)  :   MarkerTracking.Kinematics  :  Kinematic analysis failed in time step 80 : Position analysis is not completed

To whom may I send the model for inspection?

Thanks in advance
Max

Misplaced shoulder markers in the marker protocol were the problem in this case.

Thanks to Søren for the help!

One more question:

If the custom femur scaling is used, I assume that the optimization of the right & left thigh should be set to OFF in the LabSpecificData.any. Right?

Thanks
Max

Hi Max,

Yes, that would be the normal way to do it.
It is also possible to have both if the custom scaling has been made a function of e.g. thigh length, but this a more special case.

Bets regards
Søren