findBoundaries-methods: Find Boundaries Between Regions on a Surface

findBoundariesR Documentation

Find Boundaries Between Regions on a Surface

Description

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.

Usage

findBoundaries(x, method = "midpoint", ...)

## S4 method for signature 'NeuroSurface'
findBoundaries(x, method = "midpoint", ...)

Arguments

x

A NeuroSurface object containing geometry and region IDs as data values.

method

A character string specifying the boundary detection method. Options are "faces", "midpoint", "centroid", "edge_vertices", and "edge_faces".

...

Additional arguments passed to the underlying function.

Details

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.

Value

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.

See Also

find_roi_boundaries

Examples


# 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
    )
  }
}



bbuchsbaum/neurosurf documentation built on June 10, 2025, 8:22 p.m.