stla / RCDT

R package for 2D constrained Delaunay triangulation
Other
5 stars 1 forks source link

properties of the triangulation #1

Closed mdsumner closed 2 years ago

mdsumner commented 2 years ago

Do you have plans to expose the area/angle/steiner points control? I'm not familiar enough with the code here, so just to point to the properties in {RTriangle} triangulation() that allow specifying maximum area and angle and other properties of the triangulation. Is that of interest for you?

BTW, this is SO EXCELLENT!

Thank you so much, I've been trying to get this going with CGAL but failed - previously I've used {RTriangle} in my {anglr} package.

If of interest here's a spatial example, using {silicate} to break down a polygon layer to edges. That SC0 function also works on line objects, and sp package types as well.

sc <- silicate::SC0(sf::read_sf(system.file("gpkg/nc.gpkg", package = "sf", mustWork = TRUE))[1, ])

library(RCDT)
d <- delaunay(as.matrix(sc$vertex[c("x_", "y_")]), 
              as.matrix(do.call(rbind, sc$object$topology_)[c(".vx0", ".vx1")]))

plotDelaunay(d)

image

stla commented 2 years ago

Hello,

Thank you. The features you request are in the TODO list of the author of the CDT library: https://github.com/artem-ogre/CDT/issues/7

mdsumner commented 2 years ago

ah, I see - thank you

keep an eye on thomasp35/euclid - that might eventually provide easy access to CGAL triangulations - but also see that it deps on {cgal4h}

I'll be interested to see how you are using this, and learning from how these libs get exposed in an R package ;)

mdsumner commented 2 years ago

hey and fwiw, you can convert a matrix or raster to a triangle mesh with {anglr} as.mesh3d, it was on CRAN but I haven't been able to get it updated

there's still {quadmesh} which does the same but for an old rgl format, it's much easier to code than I originally did - happy to show an example, just making a note here given your issue on the CDT repo

stla commented 2 years ago

One can convert to a rgl mesh as follows:

......
del <- delaunay(vertices, edges)

#
mesh <- tmesh3d(
  vertices = t(cbind(vertices, 0)),
  indices = t(del[["triangles"]])
)
wire3d(mesh)
mdsumner commented 2 years ago

I'm aware, I was talking about your volcano example - you can do it directly without a triangulation function for an elevation matrix 🙏

stla commented 2 years ago

Ah ok, I misunderstood.

You might also be interested in my package RCGAL. It allows to do constrained 2D tessellations as well. Unfortunately, I can't submit it to CRAN because of a bug that R CMD CHECK doesn't digest.

mdsumner commented 2 years ago

oh cool, I had seen that but it dropped off the radar - I had played with hypertidy/laridae, and more recently hypertidy/delone but your efforts clearly much more than mine in that arena :)

I'm keeping an eye on dickoa/cgal4h and especially how it's used for thomasp/euclid ;)

(I've been trying to stir up interest in R spatial for years on this, but no one seems to understand the need - though it pops up in GEOS contexts and in rayshader etc where they use earclipping or Delaunay-modified ear clipping ...)

interested in any efforts! especially if we can consolidate things

mdsumner commented 2 years ago

all my stuff with Triangle is in hypertidy/anglr (but it needs an update for the recent new features for rgl::mesh3d ... and I just haven't gotten to it), but basically you can convert matrix/raster/polygons to meshes with that (some of it relies on hypertidy/silicate for decomposing to edges DEL0() ... or paths in the case of earclipping TRI0()) :)