projectCoordinates: Project 3D Coordinates onto a Surface and Smooth the Values

View source: R/neighborhood.R

projectCoordinatesR Documentation

Project 3D Coordinates onto a Surface and Smooth the Values

Description

This function projects a set of 3D coordinates onto a given surface and creates a NeuroSurface object with the smoothed values. The projection is performed by finding the closest points on the surface, and then a kernel density smoother is applied locally to produce the final values.

Usage

projectCoordinates(surfgeom, points, sigma = 5, ...)

Arguments

surfgeom

A SurfaceGeometry object representing the surface onto which the coordinates will be projected.

points

A numeric matrix with three columns (x, y, z) representing the 3D coordinates to be projected onto the surface.

sigma

A numeric value specifying the smoothing radius for the kernel density smoother. Default is 5.

...

Additional arguments passed to the smoothing function.

Details

The function first projects each 3D coordinate onto the closest point on the surface defined by surfgeom. The values at these projected points are then smoothed using a kernel density smoother, where the sigma parameter controls the extent of the smoothing. The result is a NeuroSurface object containing the smoothed values, suitable for further analysis or visualization.

Value

A NeuroSurface object with the smoothed values mapped onto the surface.

Examples

# Load a sample surface from the package
surf_file <- system.file("extdata", "std.8.lh.inflated.asc", package = "neurosurf")
surfgeom <- readAsc(surf_file)

# Get the surface coordinates
surf_coords <- coords(surfgeom)

# Create some sample 3D coordinates to project
# We'll use a subset of the surface vertices with small random offsets
set.seed(123)
sample_indices <- sample(1:nrow(surf_coords), 50)
sample_coords <- surf_coords[sample_indices, ] + matrix(rnorm(150, 0, 0.5), ncol = 3)

# Project these coordinates onto the surface
projected_surface <- projectCoordinates(surfgeom, sample_coords, sigma = 3)

# Check the result
max(series(projected_surface))  # Maximum density value
sum(series(projected_surface) > 0)  # Number of vertices with non-zero values


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