SamplingMesh
Functions to sample point cloud from the mesh
farthest_point_sample
Select points using Farthest Point Sampling (FPS).
This function selects npoint indices from an input point cloud such that
each newly selected point is as far as possible (in Euclidean distance)
from the already selected set. Only the first three dimensions of
point are used as XYZ coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
point
|
ndarray
|
np.ndarray Point cloud array of shape (N, D). Only the first three columns are interpreted as XYZ coordinates, so D must be at least 3. |
required |
npoint
|
int
|
np.ndarray Number of points to sample. Must satisfy 1 <= npoint <= N. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Array of shape (npoint,) containing the indices of the sampled points (dtype int32). |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If |
Source code in src\utils.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | |
area_and_normal
Compute per-face normals and areas for a triangular mesh.
Given mesh vertices and triangular faces, this function computes the outward face normals (unit vectors) and the corresponding face areas. Faces with zero area (degenerate triangles) receive a zero normal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vertices
|
ndarray
|
np.ndarray Array of shape (N, 3) containing vertex coordinates (XYZ). |
required |
faces
|
ndarray
|
np.ndarray
Array of shape (M, 3) containing vertex indices for each
triangular face. Each row is a triplet of integer indices into |
required |
Returns:
| Type | Description |
|---|---|
tuple[ndarray, ndarray]
|
tuple[np.ndarray, np.ndarray]: - face_normals: Array of shape (M, 3) with unit normal vectors for each face. Degenerate faces have a zero vector. - face_areas: Array of shape (M,) with the area of each face. |
Source code in src\utils.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
sample_points_with_normal_features
Sample points on a mesh surface with associated face normals.
Points are sampled on the triangular mesh defined by vertices and
faces. Triangles are chosen with probability proportional to their
surface area, and points are sampled uniformly within each selected
triangle using random barycentric coordinates. The function returns
both the sampled 3D points and the corresponding per-point normals,
taken from the face normals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vertices
|
ndarray
|
Array of shape (V, 3) containing the mesh vertex coordinates (XYZ). |
required |
faces
|
ndarray
|
Array of shape (F, 3) containing vertex indices for each
triangular face. Each row is a triplet of integer indices into
|
required |
face_normals
|
ndarray
|
Array of shape (F, 3) with the normal vector for each face, typically unit-length. |
required |
face_areas
|
ndarray
|
Array of shape (F,) with the area of each face. |
required |
n_points
|
int
|
Number of points to sample on the mesh surface. |
required |
Returns:
| Type | Description |
|---|---|
tuple[ndarray, ndarray]
|
tuple[np.ndarray, np.ndarray]: - sampled_points: Array of shape (n_points, 3) with the sampled XYZ coordinates on the mesh surface. - sampled_normals: Array of shape (n_points, 3) with the corresponding normal vectors (one per sampled point), copied from the selected face normals. |
Source code in src\utils.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |
process_file
Source code in src\create_pc.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | |
Extract PC from Mesh