findBoundaries | R Documentation |
This generic function identifies boundaries between different regions or parcellations on a surface. The implementation depends on the class of the input object.
Method to find boundaries between regions on a NeuroSurface object.
findBoundaries(x, method = "midpoint", ...)
## S4 method for signature 'NeuroSurface'
findBoundaries(x, method = "midpoint", ...)
x |
A NeuroSurface object containing geometry and region IDs as data values. |
method |
A character string specifying the boundary detection method.
Options are |
... |
Additional arguments passed to the underlying function. |
This function provides a high-level interface for finding boundaries between different regions on a surface mesh. It typically returns coordinates and metadata describing the boundaries between regions.
This method extracts the necessary components from the NeuroSurface object
(vertices, faces, and data values treated as region IDs) and passes them to
the lower-level find_roi_boundaries
function. It performs validation to
ensure the input data is suitable for boundary detection.
An object containing boundary information. The specific structure depends on the method implementation.
A list containing boundaries between regions as described in find_roi_boundaries
.
find_roi_boundaries
# Create a simple cube mesh with region IDs
# Define vertices (corners of a cube)
vertices <- matrix(c(
0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0,
0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1
), ncol = 3, byrow = TRUE)
# Define faces (12 triangular faces making a cube)
faces <- matrix(c(
1, 2, 3, 1, 3, 4, 5, 6, 7, 5, 7, 8,
1, 2, 6, 1, 6, 5, 3, 4, 8, 3, 8, 7,
1, 4, 8, 1, 8, 5, 2, 3, 7, 2, 7, 6
), ncol = 3, byrow = TRUE)
# Create a graph representation
edges <- rbind(
cbind(faces[, 1], faces[, 2]),
cbind(faces[, 2], faces[, 3]),
cbind(faces[, 3], faces[, 1])
)
g <- igraph::graph_from_edgelist(edges, directed = FALSE)
g <- igraph::simplify(g)
# Create SurfaceGeometry
mesh <- rgl::tmesh3d(
vertices = t(vertices),
indices = t(faces),
homogeneous = FALSE
)
geom <- new("SurfaceGeometry", mesh = mesh, graph = g, hemi = "left")
# Create a NeuroSurface with region IDs as data
# Regions: bottom half (1) and top half (2)
region_ids <- c(1, 1, 1, 1, 2, 2, 2, 2)
surface <- new("NeuroSurface",
geometry = geom,
indices = 1:8,
data = region_ids)
# Find boundaries between regions
boundaries <- findBoundaries(surface, method = "midpoint")
# Visualize if rgl is available
if (requireNamespace("rgl", quietly = TRUE)) {
rgl::open3d()
rgl::shade3d(mesh, col = region_ids)
# Plot the boundaries
for (i in seq_along(boundaries$boundary)) {
boundary_coords <- boundaries$boundary[[i]]
rgl::lines3d(
boundary_coords[,1],
boundary_coords[,2],
boundary_coords[,3],
col = "black",
lwd = 3
)
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.