Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vertex indices #69

Closed
nowakf opened this issue Feb 11, 2022 · 3 comments
Closed

vertex indices #69

nowakf opened this issue Feb 11, 2022 · 3 comments

Comments

@nowakf
Copy link

nowakf commented Feb 11, 2022

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?

@kristoiv
Copy link

kristoiv commented May 1, 2022

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();

@oeed
Copy link

oeed commented Mar 18, 2024

This appears to have been fixed with #79, see e7ec1c7

@Stoeoef
Copy link
Owner

Stoeoef commented Apr 26, 2024

Agreed, this should be solved my making index public. Closing!

@Stoeoef Stoeoef closed this as completed Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants