Skip to content

Commit eb32679

Browse files
committed
Update to lesson4 scaling
1 parent 32c9724 commit eb32679

2 files changed

Lines changed: 56 additions & 68 deletions

File tree

Scaling/_static/lesson4/image1.png

0 Bytes
Loading

Scaling/lesson4.md

Lines changed: 56 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
This lesson explains how we can use our own custom scaling function,
44
which we designed in Lesson 3 and combine it with the overall human body scaling laws.
55

6-
:::{seealso}
6+
```{seealso}
77
The section on scaling in the AMMR documentation.
8-
:::
8+
```
99

1010
## Preparing for subject-specific scaling
1111

@@ -22,21 +22,15 @@ from a CT-scan of one of his left femur. To increase the accuracy of our model,
2222
let us improve it using a subject-specific scaling for the femur.
2323

2424
First of all, let us prepare a model matching the standard size man to
25-
be the basis for further subject-specific improvements. Therefore we use the model from the
26-
first section **ScalingStandard,** StandingModelScalingDisplay from the
27-
AnyBody Managed Model Repository (AMMR). This is well suited to show how
25+
be the basis for further subject-specific improvements. Therefore we use the [StandingModelScalingDisplay](ammr:sphx_glr_auto_examples_other_plot_standingmodelscalingdisplay.py) from the AnyBody Managed Model Repository (AMMR), with the `_SCALING_STANDARD_`, option. This is well suited to show how
2826
to use subject-specific geometry in a model.
2927

3028
## Including custom scaling for a single segment
3129

3230
Let us configure this example to use ScalingStandard. We need to define
3331
`BM_SCALING` as `_SCALING_STANDARD_` and out-comment all other parts of
3432
the scaling configuration block. With this setting, the model is now scaled to
35-
the generic size. We can now include individual scaling functions for each segment,
36-
which will be done in a special file *CustomScaling.any*, where all the
37-
modifications related to individual segment morphing are recommended to be done.
38-
This file is already present in the example and you can include it as shown
39-
below:
33+
the generic size.
4034

4135
```AnyScriptDoc
4236
/*------------- SCALING CONFIGURATION SECTION --------------------*/
@@ -47,32 +41,29 @@ below:
4741
// #define BM_SCALING _SCALING_UNIFORM_
4842
// #define BM_SCALING _SCALING_LENGTHMASS_
4943
// #define BM_SCALING _SCALING_LENGTHMASS_FAT_
44+
```
5045

5146

52-
// Scaling laws using external measures
53-
// #define BM_SCALING _SCALING_UNIFORM_EXTMEASUREMENTS_
54-
// #define BM_SCALING _SCALING_LENGTHMASS_EXTMEASUREMENTS_
55-
// #define BM_SCALING _SCALING_LENGTHMASS_FAT_EXTMEASUREMENTS_
47+
We can now include individual scaling functions for each segment,
48+
which will be done in a special file {file}`CustomScaling.any`, where all the
49+
modifications related to individual segment should be be done.
50+
This file is already present in the example and you can include it as shown
51+
below:
5652

57-
// Anthropometric data file (unchanged files can be found in AAUHuman\Scaling\AnyFamily)
58-
// #path BM_SCALING_ANTHRO_FILE "Model\AnyFamily\AnyMan.any"
59-
// #path BM_SCALING_ANTHRO_FILE "Model\AnyFamily\AnyManUniform.any"
60-
// #path BM_SCALING_ANTHRO_FILE "Model\AnyFamily\AnyManExternal.any"
61-
// #path BM_SCALING_ANTHRO_FILE
62-
"Model\AnyFamily\AnyManExtPercentile.any"
63-
// #path BM_SCALING_ANTHRO_FILE
64-
"Model\AnyFamily\AnyWomanExtPercentile.any"
53+
```AnyScriptDoc
6554
//--------------- END OF SCALING CONFIGURATION -------------------
6655
6756
§#include "Model\CustomScaling.any"§
6857
6958
#include "<ANYBODY_PATH_BODY>/HumanModel.any"
7059
```
7160

72-
In case you want to personalize your own model - just copy CustomScaling.any
61+
:::{tip}
62+
In case you want to personalize your own model - just copy {file}`CustomScaling.any`
7363
file into the Model folder and follow the instructions from this tutorial.
64+
:::
7465

75-
If we open this file by a double click, we can see that a common place
66+
If we open this file (by a double click it), we can see that a common place
7667
to make modifications has already been prepared. Further, we can find
7768
an access point to the geometrical scaling law folder, which will be
7869
used to specify individual scaling laws.
@@ -90,13 +81,17 @@ transforms from the previous lesson. We also need to download the
9081
{download}`source <Downloads/SourceFemur.stl>` (native to AMMR) and
9182
{download}`target <Downloads/TargetFemur.stl>` (courtesy of Prof.
9283
Sebastian Dendorfer, OTH Regensburg, Germany) femur surface
93-
geometries, and copy them to the *Model* folder of the
94-
StandingModelScalingDisplay example. Now, we need to make several
84+
geometries.
85+
86+
Next copy these three files into the {file}`Model` subfolder in the
87+
*StandingModelScalingDisplay* example.
88+
89+
Now, we need to make several
9590
small adjustments to the scaling law for smooth incorporation into the
9691
model structure.
9792

98-
Starting from the AMMR v1.6.2, individual segment scaling function is
99-
implemented in the anatomical reference frame. We will call this frame
93+
In the **A**nyBody **M**anaged **M**odel **R**epository (AMMR) scaling functions are
94+
implemented in the anatomical reference frames. We will call this frame
10095
a scaling reference frame, since there might be several definitions of
10196
anatomical reference frames. In general, the segmental frame can be
10297
different from the scaling reference frame. The human body model
@@ -112,43 +107,37 @@ In our scaling law (MyScalingFunction.any) the source entities are
112107

113108
- MyScalingFunction.AffineTransform.Points0,
114109
- MyScalingFunction.RBFTransform.Points0,
115-
- MyScalingFunction.STLTransform.Input.SourceSrf.
110+
- MyScalingFunction.STLTransform.Input.SourceSurf.
116111

117-
In the AMMR version 1.6.2 such transformations will be segment dependent and
118-
will only be needed for right and left shank and femur as well as for
112+
In the **AMMR** such transformations will be segment dependent. It is only be needed for right and left shank and femur as well as for
119113
the pelvis. For all other segments this transform can be defined as an
120114
identity transformation or does not have to be applied to the source
121-
entities. The following transforms can be referenced as TSeg2ScaleFrame,
122-
the name that will be used further:
115+
entities. The following transforms can be referenced as `TSeg2ScaleFrame` (**T**ransform **Seg**mental **2** to **Scale**ling **Frame**). That name that will be used further:
123116

124-
- HumanModel.BodyModel.Left\[*Right*\].Seg.Thigh\[*Shank*\].Scale.T0
125-
- HumanModel.BodyModel.Trunk.SegmentsLumbar.PelvisSeg.Scale_Trunk_Pelvis.ScaleAfterInterfaceMorphingDef.Scale.T0.
117+
- `HumanModel.BodyModel.[Left/Right].Seg.[Thigh/Shank].Scale.T0`
118+
- `HumanModel.BodyModel.Trunk.SegmentsLumbar.PelvisSeg.Scale_Trunk_Pelvis.ScaleAfterInterfaceMorphingDef.Scale.T0`
126119

127-
Starting from the AMMR v1.6.3 (corresponds to the AMS v 6.0.3) this
128-
transform, TSeg2ScaleFrame, is already defined and can be found in the
129-
subfolder of HumanModel.Scaling.GeometricalScaling, which corresponds to
120+
In the model repository this transform, `TSeg2ScaleFrame`, is already defined and can be found in the
121+
subfolder of `HumanModel.Scaling.GeometricalScaling`, which corresponds to
130122
the morphed segment and has a similar name. This transform can be easily
131123
accessed as demonstrated below and no extra actions are needed.
132124

133125
Let us subject the source entities of the scaling law to the rigid body
134-
transformation, TSeg2ScaleFrame. We will need to make the following 3
135-
changes. Please note how we look up out of the *MyScalingFunction* folder
136-
using double and quadruple dots:
126+
transformation, `TSeg2ScaleFrame`. We will need to make the following 3
127+
changes. Please note how we look up out of the `MyScalingFunction` folder
128+
using `..` and `...` prefixes to the variables.:
129+
130+
```{code-block} AnyScriptDoc
137131
138-
```AnyScriptDoc
139132
AnyFunTransform3DLin2 AffineTransform =
140133
{
141134
Points0 = §..TSeg2ScaleFrame(§
142135
{{0.0138187,0.00136731,0.0273618}, // fovea capitis
143-
...
136+
-->8--
144137
{0.0368766,-0.393677,0.0266919}}§)§; // medial posterior condyle
145138
Points1 =
146139
{{0.289913,0.420538,0.0138931}, // fovea capitis
147-
...
148-
{0.261891,0.47585,-0.372696}}; // medial posterior condyle
149-
Mode = VTK_LANDMARK_AFFINE;
150-
};
151-
...
140+
-->8--
152141
AnyFunTransform3DRBF RBFTransform =
153142
{
154143
PreTransforms = {&.AffineTransform};
@@ -159,10 +148,10 @@ using double and quadruple dots:
159148
};
160149
Points0 = §..TSeg2ScaleFrame(§{
161150
{ 0.0138, 0.0014, 0.0274},
162-
...
151+
-->8--
163152
{ 0.0010, 0.0013, 0.0069}
164153
}§)§;
165-
...
154+
-->8--
166155
AnyFunTransform3DSTL STLTransform =
167156
{
168157
PreTransforms = {&.RBFTransform};
@@ -176,15 +165,15 @@ using double and quadruple dots:
176165
```
177166

178167
As you will see from the following changes the modification simply links
179-
the transformations to the folder containing our MyScalingFunction.any file.
168+
the transformations to the folder containing our `MyScalingFunction.any` file.
180169
In our case, this folder is
181-
HumanModel.Scaling.GeometricalScaling.Left.Thigh, which corresponds to
170+
`HumanModel.Scaling.GeometricalScaling.Left.Thigh`, which corresponds to
182171
the name of the segment, we are trying to morph, and contains our
183-
TSeg2ScaleFrame rigid body transform.
172+
`TSeg2ScaleFrame` rigid body transform.
184173

185174
So finally let us add this scaling function to the model. Please
186175
insert the following lines as shown below into the file
187-
CustomScaling.any:
176+
{file}`CustomScaling.any`:
188177

189178
```AnyScriptDoc
190179
HumanModel.Scaling.GeometricalScaling = {
@@ -196,29 +185,28 @@ Left.Thigh = {
196185
};
197186
```
198187

199-
In this modification, we added a pre-processor command (#define) that
200-
notifies the model assembling block that the anthropometric scaling
201-
for the left thigh segment is not being used. To process other body
188+
In this modification, we added a pre-processor command (`#define`) that
189+
notifies the model assembling block that the default anthropometric scaling
190+
for the left thigh segment should be excluded. To process other body
202191
parts you will need to add a similar definition, but utilize actual
203192
bone segment, e.g. `#define CUSTOM_SCALING_<Side>_<SegmentName>` for
204193
different sides or `CUSTOM_SCALING_<SegmentName>` for parts of the
205194
body that do not have sides. You can find a list of segments by
206195
browsing the scaling law in the Model tab:
207196

208-
```{image} _static/lesson4/image1.png
209-
:width: 50%
210-
```
197+
<img src="_static/lesson4/image1.png" alt="Scaling options in model tree">
198+
211199

212200
The other change was to assign the new custom scaling function to be
213201
used in the segment of the left thigh instead of the excluded one. If
214-
we now comment in DrawExternalMeasures.any and look in the Model View,
202+
we look in the Model View,
215203
we can see that the left femur is now shorter and a little thinner
216204
than with the standard scaling. So we have now successfully introduced
217205
our custom scaling law into the model.
218206

219-
```{image} _static/lesson4/image2.png
220-
:width: 60%
221-
```
207+
208+
<img src="_static/lesson4/image2.png" alt="Scaling options in model tree" width="60%">
209+
222210

223211
If we worked with a bone that does not have a controlateral pair, e.g.
224212
vertebrae, skull, etc., or just wanted to personalize a single side, we would
@@ -248,20 +236,20 @@ AnyFolder MyScalingFunction§_Mirrored§ = {
248236
{0,1,0},
249237
{0,0,-1}
250238
};§
251-
...
239+
-->8--
252240
AnyFunTransform3DLin2 AffineTransform =
253241
{
254242
Points0 = ..TSeg2ScaleFrame({...} §* .AMirroring§);
255243
Points1 = {...} §* .AMirroring§;
256244
Mode = VTK_LANDMARK_AFFINE;
257245
};
258-
...
246+
-->8--
259247
AnyFunTransform3DRBF RBFTransform =
260248
{
261-
...
249+
-->8--
262250
Points0 = ..TSeg2ScaleFrame({...} §* .AMirroring§);
263251
Points1 = {...} §* .AMirroring§;
264-
...
252+
-->8--
265253
};
266254
}; // MyScalingFunction§_Mirrored§
267255
```

0 commit comments

Comments
 (0)