diffrp.utils.geometry#
- diffrp.utils.geometry.barycentric(a: Tensor, b: Tensor, c: Tensor, p: Tensor)#
Computes barycentric coordinates from a point
pand triangle verticesa,bandc.- Parameters:
of (Takes broadcastable inputs) –
- Returns:
Stacked
(u, v, w)tensor of shape (…, 3) s.t.p = ua + vb + wc.- Return type:
torch.Tensor
- diffrp.utils.geometry.compute_face_normals(verts: Tensor, faces: Tensor, normalize=False)#
Compute per-face normals from vertices and faces. Faces are assumed to be CCW winding.
- Parameters:
verts (torch.Tensor) – Tensor of shape (num_verts, 3) containing vertex coordinates.
faces (torch.Tensor) – Tensor of shape (num_faces, 3) containing triangle indices.
normalize (bool) – Whether the results should be normalized.
- Returns:
Tensor of shape (num_faces, 3) containing per-face normals.
- Return type:
torch.Tensor
- diffrp.utils.geometry.compute_vertex_normals(verts: Tensor, faces: Tensor)#
Compute per-vertex normals from vertices and faces. Faces are assumed to be CCW winding.
- Parameters:
verts (torch.Tensor) – Tensor of shape (num_verts, 3) containing vertex coordinates.
faces (torch.Tensor) – Tensor of shape (num_faces, 3) containing triangle indices.
- Returns:
Tensor of shape (num_verts, 3) containing normalized per-vertex normals.
- Return type:
torch.Tensor
- diffrp.utils.geometry.make_face_soup(verts, tris, face_normals)#
Make a face soup geometry from vertices, triangles and face normals.
- Parameters:
verts (torch.Tensor) – Tensor of shape (num_verts, 3) containing vertex coordinates.
faces (torch.Tensor) – Tensor of shape (num_faces, 3) containing triangle indices.
face_normals (torch.Tensor) – Tensor of shape (num_faces, 3) containing face normals.
- Returns:
Constructed geometry. There are 3 * num_faces vertices and num_faces triangles in the result.
- Return type:
tuple of (verts, tris, vertex_normals)
- diffrp.utils.geometry.point_in_tri2d(pt: Tensor, v1: Tensor, v2: Tensor, v3: Tensor) Tensor#
Decide whether points lie in 2D triangles. Tensors broadcast. Modified from
calibur.point_in_tri2d.- Parameters:
pt –
(..., 2)points to decide.v1 –
(..., 2)first vertex in triangles.v2 –
(..., 2)second vertex in triangles.v3 –
(..., 2)third vertex in triangles.
- Returns:
(..., 1)boolean result of points lie in triangles.
- diffrp.utils.geometry.sign2d(p1: Tensor, p2: Tensor, p3: Tensor) Tensor#
Modified from
calibur.sign2d.