spade
spade copied to clipboard
vertex indices
You sometimes represent a mesh with an array of vertices, and an array of triangle indices. I would construct such an array with something like:
let verts = triangulation.vertices().map(|pt| pt.data).collect();
let tris = triangulation.inner_faces().map(|f| f.vertices()).flat_map(|v| v.index());
Except, in spade 2.0, the index method is private. Is there another way?
Not sure if this is helpful, but just in case:
I had a similar requirement. I wanted to take 3d-planar polygons and triangulate them. To do that I did a 3d-to-2d projection (throwing away the least useful dimension in the 3d coordinates and passing the other two into spades 2d-triangulation). As an output I required a datatype like: Vec<[usize; 3]>, where each list item is a triple of indexes into the original vertices list representing each triangles' vertices that the delaunay creates. Then since my 2d projection vertices list of coordinates has the same order as my 3d-list of vertices I now have my polygon traingulated into triangles in 3d space.
I acheived this by using the support for a custom number type:
// Setup
pub struct IndexedNumType {
value: f64,
vertex_idx: Option<usize>,
}
// TODO: lots of boilerplate to fit the trait requirements, mostly just translating number operations to the f64-value inside the struct
let mut cdt_operation = ConstrainedDelaunayTriangulation::<Point2<indexed_num_type::IndexedNumType>>::new();
// Add points looking like
let p1 = Point2::new(
indexed_num_type::IndexedNumType::new(vertices[v0_idx][0], Some(v0_idx)),
indexed_num_type::IndexedNumType::new(vertices[v0_idx][1], Some(v0_idx)),
);
// When fetching results (we only care about indexes so only check x, y would be the same index value):
let mut triangle_indexes: Vec<[usize; 3]> = cdt_operation
.inner_faces()
.map(|it| {
it.positions()
.map(|position| position.x.vertex_idx().unwrap())
})
.collect();
This appears to have been fixed with #79, see https://github.com/Stoeoef/spade/commit/e7ec1c7d350aa57c43786a22e6a13a43b148f50f