The HausdorffDistance component computes the symmetrical Hausdorff distance between two point clouds by calculating one-sided distances from each cloud to the other.
sheet
# HausdorffDistance
**Overview**
The `HausdorffDistance` component is an analysis tool that computes the Hausdorff distance between two point clouds. It does not directly influence simulation physics but serves as a metric for comparing and analyzing point cloud data.
**Mathematical Model**
The Hausdorff distance measures how far apart two sets of points are from each other. The symmetrical Hausdorff distance is defined as follows:
$$
D_H(P_1, P_2) = \max\left(\sup_{p_1 \in P_1} \inf_{p_2 \in P_2} d(p_1, p_2), \sup_{p_2 \in P_2} \inf_{p_1 \in P_1} d(p_2, p_1)\right)
$$
where $d$ is the Euclidean distance between two points. Specifically:
- **Distance from Point Cloud 1 to Point Cloud 2 ($D_{12}$)**: For each point $p_1 \in P_1$, find the closest point $p_2 \in P_2$. The maximum of these minimum distances is defined as $D_{12}$.
$$
D_{12} = \max_{p_1 \in P_1} \left(\min_{p_2 \in P_2} d(p_1, p_2)\right)
$$
- **Distance from Point Cloud 2 to Point Cloud 1 ($D_{21}$)**: Similarly, for each point $p_2 \in P_2$, find the closest point $p_1 \in P_1$. The maximum of these minimum distances is defined as $D_{21}$.
$$
D_{21} = \max_{p_2 \in P_2} \left(\min_{p_1 \in P_1} d(p_2, p_1)\right)
$$
- **Symmetrical Hausdorff Distance ($D_H$)**: The maximum of $D_{12}$ and $D_{21}$ is the symmetrical Hausdorff distance.
$$
D_H = \max(D_{12}, D_{21})
$$
**Parameters and Data**
- **`points1 (VecCoord)`**: Points belonging to the first point cloud. Type: `VecCoord`, Default: None.
- **`points2 (VecCoord)`**: Points belonging to the second point cloud. Type: `VecCoord`, Default: None.
- **`d12 (Real)`**: Distance from point cloud 1 to 2. Type: `Real`, Default: None.
- **`d21 (Real)`**: Distance from point cloud 2 to 1. Type: `Real`, Default: None.
- **`max (Real)`**: Symmetrical Hausdorff distance. Type: `Real`, Default: None.
- **`update (bool)`**: Recompute every time step. Type: `bool`, Default: False.
component_description
{
"description": "The HausdorffDistance component computes the Hausdorff distance between two point clouds in a SOFA simulation. The Hausdorff distance is a measure used to determine the maximum distance of a set of points in one cloud to the closest point in another cloud.",
"input_data_fields": [
{
"description": "Points belonging to the first point cloud.",
"name": "points1",
"type": "Data\u003cVecCoord\u003e"
},
{
"description": "Points belonging to the second point cloud.",
"name": "points2",
"type": "Data\u003cVecCoord\u003e"
}
],
"methods": [
{
"description": "Initializes the component by computing distances between point clouds.",
"name": "init()"
},
{
"description": "Reinitializes the component, currently does nothing.",
"name": "reinit()"
},
{
"description": "Updates the distances if the \u0027update\u0027 flag is set to true.",
"name": "doUpdate()"
},
{
"description": "Computes the minimum distance from a point to a point cloud.",
"name": "distance(Coord p, VecCoord S)"
},
{
"description": "Calculates and sets the non-symmetrical and symmetrical Hausdorff distances between two point clouds.",
"name": "computeDistances()"
}
],
"name": "HausdorffDistance",
"namespace": "sofa::component::engine::analyze",
"output_data_fields": [
{
"description": "Distance from point cloud 1 to point cloud 2.",
"name": "d12",
"type": "Data\u003cReal\u003e"
},
{
"description": "Distance from point cloud 2 to point cloud 1.",
"name": "d21",
"type": "Data\u003cReal\u003e"
},
{
"description": "Symmetrical Hausdorff distance between the two point clouds.",
"name": "max",
"type": "Data\u003cReal\u003e"
}
],
"parameters": [
{
"default_value": "false",
"description": "Flag to indicate whether to recompute distances at every time step.",
"name": "update",
"type": "Data\u003cbool\u003e"
}
],
"usage": [
"This component is typically used in scenarios where one needs to measure the dissimilarity between two sets of points, often for comparison or alignment purposes.",
"The component can be templated with different data types such as Vec1Types, Vec2Types, Vec3Types, Rigid2Types, and Rigid3Types."
]
}
maths
<maths_md_description>
The HausdorffDistance component computes the distance between two point clouds, $P_1$ and $P_2$. The Hausdorff distance is a measure of how far apart these two sets are from each other. It is defined as follows:
$$
D_H(P_1, P_2) = \max\left(\sup_{p_1 \in P_1} \inf_{p_2 \in P_2} d(p_1, p_2), \sup_{p_2 \in P_2} \inf_{p_1 \in P_1} d(p_2, p_1)\right)
$$
where $d$ is the Euclidean distance between two points.
In this implementation, the component computes both one-sided distances and their maximum to get the symmetrical Hausdorff distance. Specifically:
- **Distance from Point Cloud 1 to Point Cloud 2 ($D_{12}$)**: For each point $p_1$ in $P_1$, find the closest point $p_2$ in $P_2$. The maximum of these minimum distances is defined as $D_{12}$.
$$
D_{12} = \max_{p_1 \in P_1} \left(\min_{p_2 \in P_2} d(p_1, p_2)\right)
$$
- **Distance from Point Cloud 2 to Point Cloud 1 ($D_{21}$)**: Similarly, for each point $p_2$ in $P_2$, find the closest point $p_1$ in $P_1$. The maximum of these minimum distances is defined as $D_{21}$.
$$
D_{21} = \max_{p_2 \in P_2} \left(\min_{p_1 \in P_1} d(p_2, p_1)\right)
$$
- **Symmetrical Hausdorff Distance ($D_H$)**: The maximum of $D_{12}$ and $D_{21}$ is the symmetrical Hausdorff distance.
$$
D_H = \max(D_{12}, D_{21})
$$
The component provides three outputs:
- **$D_{12}$**: The maximum minimum distance from points in $P_1$ to their closest neighbors in $P_2$.
- **$D_{21}$**: The maximum minimum distance from points in $P_2$ to their closest neighbors in $P_1$.
- **$D_H$**: The symmetrical Hausdorff distance, which is the larger of $D_{12}$ and $D_{21}$.
The component can be templated over different types (e.g., `Vec3Types`), allowing it to work with different data types representing points in 1D, 2D, or 3D space. The computation is performed at initialization (`init`) and can optionally update every time step if the `d_update` flag is set to true.
This component does not directly contribute to the physics simulation but serves as a tool for analyzing and comparing point clouds in the context of simulations.
{
"name": "HausdorffDistance",
"main": {
"name": "HausdorffDistance",
"namespace": "sofa::component::engine::analyze",
"module": "Sofa.Component.Engine.Analyze",
"include": "sofa/component/engine/analyze/HausdorffDistance.h",
"doc": "Compute the Hausdorff distance of two point clouds.\n\nThis class compute the Hausdorff distance of two point clouds\n\\todo: mean and mean square error",
"inherits": [
"DataEngine"
],
"templates": [
"sofa::defaulttype::Rigid2Types",
"sofa::defaulttype::Rigid3Types",
"sofa::defaulttype::Vec1Types"
],
"data_fields": [
{
"name": "d_points_1",
"type": "VecCoord",
"xmlname": "points1",
"help": "Points belonging to the first point cloud"
},
{
"name": "d_points_2",
"type": "VecCoord",
"xmlname": "points2",
"help": "Points belonging to the second point cloud"
},
{
"name": "d_d12",
"type": "Real",
"xmlname": "d12",
"help": "Distance from point cloud 1 to 2"
},
{
"name": "d_d21",
"type": "Real",
"xmlname": "d21",
"help": "Distance from point cloud 2 to 1"
},
{
"name": "d_max",
"type": "Real",
"xmlname": "max",
"help": "Symmetrical Hausdorff distance"
},
{
"name": "d_update",
"type": "bool",
"xmlname": "update",
"help": "Recompute every time step"
}
],
"links": [],
"methods": [
{
"name": "handleEvent",
"return_type": "void",
"params": [
{
"name": "event",
"type": "core::objectmodel::Event *"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "onBeginAnimationStep",
"return_type": "void",
"params": [
{
"name": "",
"type": "const double"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "init",
"return_type": "void",
"params": [],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "reinit",
"return_type": "void",
"params": [],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "doUpdate",
"return_type": "void",
"params": [],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "computeDistances",
"return_type": "void",
"params": [],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "distance",
"return_type": "Real",
"params": [
{
"name": "p",
"type": "Coord"
},
{
"name": "S",
"type": "VecCoord"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
}
]
},
"desc": {
"component_description": {
"name": "HausdorffDistance",
"namespace": "sofa::component::engine::analyze",
"description": "The HausdorffDistance component computes the Hausdorff distance between two point clouds in a SOFA simulation. The Hausdorff distance is a measure used to determine the maximum distance of a set of points in one cloud to the closest point in another cloud.",
"input_data_fields": [
{
"name": "points1",
"type": "Data<VecCoord>",
"description": "Points belonging to the first point cloud."
},
{
"name": "points2",
"type": "Data<VecCoord>",
"description": "Points belonging to the second point cloud."
}
],
"output_data_fields": [
{
"name": "d12",
"type": "Data<Real>",
"description": "Distance from point cloud 1 to point cloud 2."
},
{
"name": "d21",
"type": "Data<Real>",
"description": "Distance from point cloud 2 to point cloud 1."
},
{
"name": "max",
"type": "Data<Real>",
"description": "Symmetrical Hausdorff distance between the two point clouds."
}
],
"parameters": [
{
"name": "update",
"type": "Data<bool>",
"default_value": "false",
"description": "Flag to indicate whether to recompute distances at every time step."
}
],
"methods": [
{
"name": "init()",
"description": "Initializes the component by computing distances between point clouds."
},
{
"name": "reinit()",
"description": "Reinitializes the component, currently does nothing."
},
{
"name": "doUpdate()",
"description": "Updates the distances if the 'update' flag is set to true."
},
{
"name": "distance(Coord p, VecCoord S)",
"description": "Computes the minimum distance from a point to a point cloud."
},
{
"name": "computeDistances()",
"description": "Calculates and sets the non-symmetrical and symmetrical Hausdorff distances between two point clouds."
}
],
"usage": [
"This component is typically used in scenarios where one needs to measure the dissimilarity between two sets of points, often for comparison or alignment purposes.",
"The component can be templated with different data types such as Vec1Types, Vec2Types, Vec3Types, Rigid2Types, and Rigid3Types."
]
}
},
"maths": {
"maths": "<maths_md_description>\n\nThe HausdorffDistance component computes the distance between two point clouds, $P_1$ and $P_2$. The Hausdorff distance is a measure of how far apart these two sets are from each other. It is defined as follows:\n\n$$\nD_H(P_1, P_2) = \\max\\left(\\sup_{p_1 \\in P_1} \\inf_{p_2 \\in P_2} d(p_1, p_2), \\sup_{p_2 \\in P_2} \\inf_{p_1 \\in P_1} d(p_2, p_1)\\right)\n$$\n\nwhere $d$ is the Euclidean distance between two points.\n\nIn this implementation, the component computes both one-sided distances and their maximum to get the symmetrical Hausdorff distance. Specifically:\n\n- **Distance from Point Cloud 1 to Point Cloud 2 ($D_{12}$)**: For each point $p_1$ in $P_1$, find the closest point $p_2$ in $P_2$. The maximum of these minimum distances is defined as $D_{12}$.\n\n$$\nD_{12} = \\max_{p_1 \\in P_1} \\left(\\min_{p_2 \\in P_2} d(p_1, p_2)\\right)\n$$\n\n- **Distance from Point Cloud 2 to Point Cloud 1 ($D_{21}$)**: Similarly, for each point $p_2$ in $P_2$, find the closest point $p_1$ in $P_1$. The maximum of these minimum distances is defined as $D_{21}$.\n\n$$\nD_{21} = \\max_{p_2 \\in P_2} \\left(\\min_{p_1 \\in P_1} d(p_2, p_1)\\right)\n$$\n\n- **Symmetrical Hausdorff Distance ($D_H$)**: The maximum of $D_{12}$ and $D_{21}$ is the symmetrical Hausdorff distance.\n\n$$\nD_H = \\max(D_{12}, D_{21})\n$$\n\nThe component provides three outputs:\n- **$D_{12}$**: The maximum minimum distance from points in $P_1$ to their closest neighbors in $P_2$.\n- **$D_{21}$**: The maximum minimum distance from points in $P_2$ to their closest neighbors in $P_1$.\n- **$D_H$**: The symmetrical Hausdorff distance, which is the larger of $D_{12}$ and $D_{21}$.\n\nThe component can be templated over different types (e.g., `Vec3Types`), allowing it to work with different data types representing points in 1D, 2D, or 3D space. The computation is performed at initialization (`init`) and can optionally update every time step if the `d_update` flag is set to true.\n\nThis component does not directly contribute to the physics simulation but serves as a tool for analyzing and comparing point clouds in the context of simulations."
},
"summary": {
"abstract": "The HausdorffDistance component computes the symmetrical Hausdorff distance between two point clouds by calculating one-sided distances from each cloud to the other.",
"sheet": "# HausdorffDistance\n\n**Overview**\n\nThe `HausdorffDistance` component is an analysis tool that computes the Hausdorff distance between two point clouds. It does not directly influence simulation physics but serves as a metric for comparing and analyzing point cloud data.\n\n**Mathematical Model**\n\nThe Hausdorff distance measures how far apart two sets of points are from each other. The symmetrical Hausdorff distance is defined as follows:\n\n$$\nD_H(P_1, P_2) = \\max\\left(\\sup_{p_1 \\in P_1} \\inf_{p_2 \\in P_2} d(p_1, p_2), \\sup_{p_2 \\in P_2} \\inf_{p_1 \\in P_1} d(p_2, p_1)\\right)\n$$\n\nwhere $d$ is the Euclidean distance between two points. Specifically:\n\n- **Distance from Point Cloud 1 to Point Cloud 2 ($D_{12}$)**: For each point $p_1 \\in P_1$, find the closest point $p_2 \\in P_2$. The maximum of these minimum distances is defined as $D_{12}$.\n\n$$\nD_{12} = \\max_{p_1 \\in P_1} \\left(\\min_{p_2 \\in P_2} d(p_1, p_2)\\right)\n$$\n\n- **Distance from Point Cloud 2 to Point Cloud 1 ($D_{21}$)**: Similarly, for each point $p_2 \\in P_2$, find the closest point $p_1 \\in P_1$. The maximum of these minimum distances is defined as $D_{21}$.\n\n$$\nD_{21} = \\max_{p_2 \\in P_2} \\left(\\min_{p_1 \\in P_1} d(p_2, p_1)\\right)\n$$\n\n- **Symmetrical Hausdorff Distance ($D_H$)**: The maximum of $D_{12}$ and $D_{21}$ is the symmetrical Hausdorff distance.\n\n$$\nD_H = \\max(D_{12}, D_{21})\n$$\n\n**Parameters and Data**\n\n- **`points1 (VecCoord)`**: Points belonging to the first point cloud. Type: `VecCoord`, Default: None.\n- **`points2 (VecCoord)`**: Points belonging to the second point cloud. Type: `VecCoord`, Default: None.\n- **`d12 (Real)`**: Distance from point cloud 1 to 2. Type: `Real`, Default: None.\n- **`d21 (Real)`**: Distance from point cloud 2 to 1. Type: `Real`, Default: None.\n- **`max (Real)`**: Symmetrical Hausdorff distance. Type: `Real`, Default: None.\n- **`update (bool)`**: Recompute every time step. Type: `bool`, Default: False."
}
}