View source: R/BoneDensityFunctions.R
plot_cross_section_bone | R Documentation |
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.
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
)
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. |
Generates an 'rgl' plot
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.