retuve.hip_us.metrics.c_ratio

Metric: Centering Ratio

 1# Copyright 2024 Adam McArthur
 2#
 3# Licensed under the Apache License, Version 2.0 (the "License");
 4# you may not use this file except in compliance with the License.
 5# You may obtain a copy of the License at
 6#
 7#     http://www.apache.org/licenses/LICENSE-2.0
 8#
 9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15"""
16Metric: Centering Ratio
17"""
18
19from typing import Tuple
20
21import numpy as np
22import open3d as o3d
23
24from retuve.hip_us.classes.general import HipDatasUS
25from retuve.hip_us.typing import CoordinatesArray3D, FemoralHeadSphere
26from retuve.keyphrases.config import Config
27
28
29def get_centering_ratio(
30    illium_mesh: o3d.geometry.TriangleMesh,
31    femoral_head_sphere: FemoralHeadSphere,
32    hip_datas: HipDatasUS = None,
33    config: Config = None,
34) -> Tuple[
35    float, Tuple[CoordinatesArray3D, CoordinatesArray3D, CoordinatesArray3D]
36]:
37    """
38    Get the centering ratio for the femoral head.
39
40    :param illium_mesh: o3d.geometry.TriangleMesh: The Illium mesh.
41    :param femoral_head_sphere: FemoralHeadSphere: The femoral head sphere.
42    :param hip_datas: HipDatasUS: The HipDatasUS object.
43    :param config: Config: The Config object.
44
45    :return: The centering ratio and the 3 points used to calculate it.
46    """
47    verticies = np.array(illium_mesh.vertices)
48
49    # Get min and maz verticies in the z axis
50    min_z = np.min(verticies[:, 2])
51    max_z = np.max(verticies[:, 2])
52
53    fem_center = [
54        np.mean(femoral_head_sphere[0]),
55        np.mean(femoral_head_sphere[1]),
56        np.mean(femoral_head_sphere[2]),
57    ]
58
59    min_z_vert = [
60        fem_center[0],
61        fem_center[1],
62        min_z,
63    ]
64
65    max_z_vert = [
66        fem_center[0],
67        fem_center[1],
68        max_z,
69    ]
70
71    # # Get the ratio
72    ratio = abs(fem_center[2] - max_z) / abs(max_z - min_z)
73
74    ratio = round(ratio, 2)
75
76    return round(ratio, 2), (fem_center, max_z_vert, min_z_vert)
def get_centering_ratio( illium_mesh: open3d.cpu.pybind.geometry.TriangleMesh, femoral_head_sphere: Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray], hip_datas: retuve.hip_us.classes.general.HipDatasUS = None, config: retuve.keyphrases.config.Config = None) -> Tuple[float, Tuple[numpy.ndarray[Any, numpy.dtype[numpy.float64]], numpy.ndarray[Any, numpy.dtype[numpy.float64]], numpy.ndarray[Any, numpy.dtype[numpy.float64]]]]:
30def get_centering_ratio(
31    illium_mesh: o3d.geometry.TriangleMesh,
32    femoral_head_sphere: FemoralHeadSphere,
33    hip_datas: HipDatasUS = None,
34    config: Config = None,
35) -> Tuple[
36    float, Tuple[CoordinatesArray3D, CoordinatesArray3D, CoordinatesArray3D]
37]:
38    """
39    Get the centering ratio for the femoral head.
40
41    :param illium_mesh: o3d.geometry.TriangleMesh: The Illium mesh.
42    :param femoral_head_sphere: FemoralHeadSphere: The femoral head sphere.
43    :param hip_datas: HipDatasUS: The HipDatasUS object.
44    :param config: Config: The Config object.
45
46    :return: The centering ratio and the 3 points used to calculate it.
47    """
48    verticies = np.array(illium_mesh.vertices)
49
50    # Get min and maz verticies in the z axis
51    min_z = np.min(verticies[:, 2])
52    max_z = np.max(verticies[:, 2])
53
54    fem_center = [
55        np.mean(femoral_head_sphere[0]),
56        np.mean(femoral_head_sphere[1]),
57        np.mean(femoral_head_sphere[2]),
58    ]
59
60    min_z_vert = [
61        fem_center[0],
62        fem_center[1],
63        min_z,
64    ]
65
66    max_z_vert = [
67        fem_center[0],
68        fem_center[1],
69        max_z,
70    ]
71
72    # # Get the ratio
73    ratio = abs(fem_center[2] - max_z) / abs(max_z - min_z)
74
75    ratio = round(ratio, 2)
76
77    return round(ratio, 2), (fem_center, max_z_vert, min_z_vert)

Get the centering ratio for the femoral head.

Parameters
  • illium_mesh: o3d.geometry.TriangleMesh: The Illium mesh.
  • femoral_head_sphere: FemoralHeadSphere: The femoral head sphere.
  • hip_datas: HipDatasUS: The HipDatasUS object.
  • config: Config: The Config object.
Returns

The centering ratio and the 3 points used to calculate it.