Personalize model based on CT data

Hi Lee,

I have to stress that when constructing a transformation using the vertices of STL surfaces (AnyFunTransform3DSTL), the surfaces have to be topologically equivalent, i.e. the surfaces have the same number of triangles and each neighbour and vertices represent the same features on both surfaces.

So if you do not have this your best bet will be to continue with the AnyFunTransform3DRBF function.

Looking at your code with the RBFDef, it looks fine. You can try using the settings I pasted below and see if there is an improvement. Or also try to select more points to see if that makes a difference.

AnyFunTransform3DRBF RBFTransform = {
  PreTransforms = {&.AffineTransform};
  RBFDef = {
    Type = RBF_Triharmonic;
    Param = 0.2;   

    [..rest of code..] 
 };

You should also bring in your target bone and draw it in another color to see how well the morphing is going. Make a little chunk of code (note: you might have to adjust file names/locations and ScaleXYZ accordingly) like this within the HumanModel.any file:

Main.Studies.HumanModel.BodyModel.Left.Leg.Seg.Thigh = {
  AnyFunTransform3D &CustomMarkerScaling = Main.Studies.HumanModel.SubjectSpecificScaling.Left.Thigh.RegistrationTransform; 

   AnyRefNode SS_STLNode  = {
     AnySurfSTL FemurSTL = {
      FileName = "target\Femur_target_L.stl";
      ScaleXYZ = {1, 1, 1}/1000;
      AnyFunTransform3D &scale = ..CustomMarkerScaling;        
        AnyDrawSurf stldraw = {
          FileName = .FileName;
          ScaleXYZ = {1, 1, 1}/1000;
          AnyFunTransform3D &scale = .scale;
          RGB = {0,1,0};
          Opacity = .....BonesOpacity.Thigh;
        };            
      };
    };
  };

Hello,

Thank you for your help!

I’ll try to select more points to see what will happen?

As you mentioned above about the AnyFunTransform3DSTL, I am wondering how can I do to acquire the topologically equivalent surfaces? Are there some tutorials or software or something else I can reference?

Thank you again!

Best Regards,
Lee

I am sorry for the late reply. There are some tools to do it. I believe Mimics by Materialise may have a morphing tool. Another option could be to generate bones using a template mesh from statistical shape models.

Kind regards,
Pavel

Hello,

After custom scaling the femur and tibia based on CT imsges, I found the anatomical reference frame and the kneejoint reference frame are not even perpendicular to each other (X,Y,Z). Should I define the new reference frame?

Thank you!
Lee

Hi Lee,

Why should they be aligned? The knee joint serves one purpose, the anatomical frame another.

Regards,
Pavel

Hello,

What I really means is the Y axis is not perpendicular to the XZ plane. Is that normal ?

That does not make sense. Each Y axis is perpendicular to the corresponding XZ plane.

Hello,

I recreated the system based on the aRel and SRel. Maybe I was wrong.

When I try to import the femoral component which I adjust in mimics like this.


The blue bone is the femur exported in local fame from AnyBody and the green one is the adjusted implant which shares the same coordinate system with the femur.

After I import the implant in the way below:

It didn’t perform as I expected. Is there something wrong with the code?

Thank you!
Lee

Hi Lee,

The bone in Mimics does not correspond the one in AnyBody. You either exported scaled surface, or exported in global, or using a bone from a different dataset, i.e. bone from TLEM2.1, when the Mimics one is TLEM1.1. If you have everything consistent - you should get right match.

Regards,
Pavel

Hello,

The blue one is the femur exported from AnyBody after custom scaling and I import it into the mimics 3-matic software to adjust the implant to match it.

I believe I used the right dataset and exported in the local frame. You mean I shouldn’t export scaled surface?

Regards,
Lee

Hello,

After scaling, I noticed that the local frame axial orientation is different. was that a problem I should concern about?

Regards,
Lee

Hi Lee, I asked my colleague to share some code that will help you do it the right way. Regards, Pavel

Hi Lee,

Going back a few comments:

image

, can you tell me what AnyFunTransform3D &Scale = …Scale; points to?

This AnyFunTransform3D should point to: Main.Studies.HumanModel.SubjectSpecificScaling.Left.Thigh.RegistrationTransform;

Which should be defined as the following in your SubjectSpecificScaling.any file:

  AnyFunTransform3DLin2 RegistrationTransform = {
    Points0 = .AffineTransform.Points1;
    Points1 = ....BodyModel.Left.Leg.Seg.Thigh.Scale(.AffineTransform.Points0unscaled);
    Mode = VTK_LANDMARK_RIGIDBODY;
  };

  AnyFunTransform3DLin2 AffineTransform = {
    AnyFileVar SourceSTL = FilePathCompleteOf(...Source.Right.FilenameThigh) + ".stl";
    AnyFileVar TargetSTL = FilePathCompleteOf(...Target.Left.FilenameThigh) + ".stl";
    AnyMatrix Points0unscaled = STL_Vertices(SourceSTL, iarr(0, floor(NumPoints0/NumPoints), 
    NumPoints0 - 1), 1)*0.001;
    Points0 = .TSeg2ScaleFrame(Points0unscaled);
    Points1 = STL_Vertices(TargetSTL, iarr(0, floor(NumPoints1/NumPoints), NumPoints1 - 1), 
    1)*0.001;
    AnyInt NumPoints0 = STL_Size(SourceSTL, 1)[0];
    AnyInt NumPoints1 = STL_Size(TargetSTL, 1)[0];
    AnyVar NumPoints = 5000;
    Mode = VTK_LANDMARK_AFFINE;
  };

  AnyFunTransform3D &TSeg2ScaleFrame = ...BodyModel.Left.Leg.Seg.Thigh.Scale.T0;

Is that correct?

-Christine

Thank you very much!

Hi Christine,

Thank you for your help!

That might be the real problem, as you mentioned above, the scaling was indeed used wrongly. I forgot to reverse the frames. I’ll keep you posted.

Thank you again!

Regards,
Lee

Hi,

Problem solved. I just commend the AnyFunTransform3D line and everything is ok.

Another Problem: After morphing, the knee joint placement seems a little bit weird.

image

According to the article of marra, the next step should be the analytical joint fitting.
image

Could you give me some examples of how to adjust it?

Thank you!

Regards,
Lee

Hi Lee,

Good to hear things worked out. There are many different options for surface fitting tools, it depends what you have available and what is easiest for you (3-matic, matlab, python). You can fit surfaces directly in AnyBody by importing your surface selection as an STL and using the GetVertices() function in AnyDrawSurf. In the example below I fit a cylinder to the tibiofemoral contact area of the medial condyle of the femur:

AnyDrawSurf Medial_Condyle = {
  FileName = ANYBODY_PATH_MODELUTILS +"\MovingAxisKnee\STLs\Medial_Condyle.stl";
  ScaleXYZ = {1.0, 1.0, 1.0};
  RGB = {0,0,1};
  AnyFunTransform3D &Scale =.SubjectSpecificScaling.RegTransform;
  Face=-1;
  AnyInt NumPoints = STL_Size(FileName, 1)[0];
 AnyFloat points = GetVertices(iarr(0, 1, NumPoints-1));
};

AnyRefNode Medial_Condyle_center = {
  sRel = cylinder_fit.sRel; 
  ARel = cylinder_fit.ARel;
  AnySurfCylinderFit cylinder_fit = {
    Length = 0.000001;
    FixedDirection = Off;
    Points = DesignVar(.Medial._points);
    AnyDrawParamSurf ViewFit={
      Visible = On;
      RGB={0,1,1};
      Opacity=0.2;
      };
   };
};

You can do a similar procedure to fit the lateral condyle, and then connect the center nodes to define a the tibiofemoral hinge joint axis. Please note this is only one way of defining the knee joint, there are many options in the literature. With respect to the hip joint you can fit a sphere to the femoral head (using AnySurfEllipsoidFit with spherical switch ‘on’. Finally, please see this source for how the ankle joint was fit:

[1] Parra WCH, Chatterjee HJ, Soligo C. Calculating the axes of rotation for the subtalar and talocrural joints using 3D bone reconstructions. J Biomech 2012;45:1103–7. doi:10.1016/j.jbiomech.2012.01.011.

Best Regards,
Christine

Hi,

Thank you so much for your help! :smile:
I’ll try to do it.

Thanks again!

Regards,
Lee