plot_cross_section_bone: Plot Cross-Sectional Bone Visualization in 3D

View source: R/BoneDensityFunctions.R

plot_cross_section_boneR Documentation

Plot Cross-Sectional Bone Visualization in 3D

Description

Visualizes a 3D cross-section of a bone using surface mesh and internal density (fill) points. Clips the surface mesh at a given axis and value, and overlays a 2D projection of internal density.

Usage

plot_cross_section_bone(
  surface_mesh,
  surface_colors = NULL,
  fill_coords,
  fill_colors,
  slice_axis,
  slice_val,
  slice_thickness = 1,
  IncludeSurface = FALSE,
  title = "Bone Cross-Section",
  userMat = NULL,
  legend = TRUE,
  legend_color_sel = NULL,
  legend_maxi = NULL,
  legend_mini = NULL
)

Arguments

surface_mesh

A 'mesh3d' object representing the outer surface of the bone.

surface_colors

Optional. A vector of colors for each vertex of the surface mesh. If NULL, uses mesh's own material colors.

fill_coords

A numeric matrix of internal fill point coordinates.

fill_colors

A vector of colors corresponding to fill points.

slice_axis

Character. ''x'‘, '’y'‘, or '’z''. Axis along which to slice.

slice_val

Numeric (0 to 1). Relative slice location along selected axis.

slice_thickness

Numeric. Width of the slice (default = 1).

IncludeSurface

Logical. Whether to include the clipped surface mesh.

title

Character. Title for the plot.

userMat

Optional. A 4x4 matrix controlling view orientation.

legend

Logical. Optional color bar.

legend_color_sel

Optional character with color gradient

legend_maxi

Numeric. Maximum bone density.

legend_mini

Numeric. Minimum bone density.

Value

Generates an 'rgl' plot

Examples


  # Download CT scan
  url <- "https://github.com/Telfer/BoneDensityMapping/releases/download/v1.0.1/test_CT_hip.nii.gz"
  scan_filepath <- tempfile(fileext = ".nii.gz")
  download.file(url, scan_filepath, mode = "wb")
  nifti <- import_scan(scan_filepath)
  url2 <- "https://github.com/Telfer/BoneDensityMapping/releases/download/v1.0.2/test_CT_femur.stl"
  bone_filepath <- tempfile(fileext = ".stl")
  download.file(url2, bone_filepath, mode = "wb")
  surface_mesh <- import_mesh(bone_filepath)
  landmark_path <- system.file("extdata", "test_femur.mrk.json",
                               package = "BoneDensityMapping")
  landmarks <- import_lmks(landmark_path)
  mapped_coords <- surface_points_template(surface_mesh, landmarks,
                                           no_surface_sliders = 100)
  mat_peak <- voxel_point_intersect(mapped_coords, nifti)
  colored_mesh <- color_mesh(surface_mesh, mapped_coords, mat_peak)
  internal_fill <- fill_bone_points(surface_mesh, 3)
  internal_density <- voxel_point_intersect(internal_fill, nifti,
                                            ct_eqn = "linear",
                                            ct_params = c(68.4, 1.106))
  internal_colors <- color_mapping(internal_density)
  plot_cross_section_bone(colored_mesh, surface_colors = NULL,
                          internal_fill, internal_colors, slice_axis = 'x',
                          slice_val = 0.5)


BoneDensityMapping documentation built on Aug. 8, 2025, 6:46 p.m.