Title: | Estimate the Chest Volume with Markers Data |
---|---|
Description: | Provides tools to process and analyze chest expansion using 3D marker data from motion capture systems. Includes functions for data processing, marker position adjustment, volume calculation using convex hulls, and visualization in 2D and 3D. Barber et al. (1996) <doi:10.1145/235815.235821>. TAMIYA Hiroyuki et al. (2021) <doi:10.1038/s41598-021-01033-8>. |
Authors: | Wai-Hang Kwong [aut, cre] |
Maintainer: | Wai-Hang Kwong <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.0.0 |
Built: | 2024-12-24 06:55:33 UTC |
Source: | CRAN |
Adjusts the positions of markers by moving them towards the average center position within each timeframe by a specified distance. This accounts for marker protrusion from the skin surface.
adj_position(data, distance = 1)
adj_position(data, distance = 1)
data |
A data frame where each row represents a marker at a specific timeframe, with columns 'Timeframe', 'Marker', 'X', 'Y', 'Z'. |
distance |
Numeric value indicating the distance to adjust towards the center (default is 1 cm). |
The function calculates the average center position of all markers within each timeframe and moves each marker towards the center by the specified distance along the line connecting the marker to the center.
A data frame of the same dimensions as data
, containing the adjusted marker coordinates.
data("sample_data") processed_data <- process_marker_data(head(sample_data)) adjusted_data <- adj_position(processed_data, distance = 1) head(adjusted_data)
data("sample_data") processed_data <- process_marker_data(head(sample_data)) adjusted_data <- adj_position(processed_data, distance = 1) head(adjusted_data)
Calculates the volumes of specified segments over time using convex hulls.
calculate_volumes(data, segments)
calculate_volumes(data, segments)
data |
A data frame containing adjusted marker coordinates in centimeters, with columns 'Timeframe', 'Marker', 'X', 'Y', 'Z'. |
segments |
A list of character vectors, each containing marker names defining a segment. |
Coordinates should be in centimeters to ensure correct volume units (cm³).
A data frame with columns 'Timeframe', 'Segment', 'Volume'.
# Define segments (e.g., quadrants of the chest) segments <- list( UL = c("M01", "M02", "M03", "M04"), UR = c("M05", "M06", "M07", "M08") ) # Assume 'adjusted_data' is the data frame with adjusted marker positions in cm data('sample_data') processed_data <- process_marker_data(head(sample_data)) adjusted_data <- adj_position(processed_data) volumes_df <- calculate_volumes(adjusted_data, segments) head(volumes_df)
# Define segments (e.g., quadrants of the chest) segments <- list( UL = c("M01", "M02", "M03", "M04"), UR = c("M05", "M06", "M07", "M08") ) # Assume 'adjusted_data' is the data frame with adjusted marker positions in cm data('sample_data') processed_data <- process_marker_data(head(sample_data)) adjusted_data <- adj_position(processed_data) volumes_df <- calculate_volumes(adjusted_data, segments) head(volumes_df)
This function generates a ggplot to display the volume changes by segment over time. It creates a line plot with each segment's volume on the y-axis and the timeframe on the x-axis.
plot_2d_volume( volume_data, segment_names = "Segment", title = "Volume Change by Segment" )
plot_2d_volume( volume_data, segment_names = "Segment", title = "Volume Change by Segment" )
volume_data |
A data frame with volume measurements, one column per segment, and a "frame" column for time. |
segment_names |
Column that contain name of segment to plot |
title |
Optional plot title. |
A ggplot object showing volume changes by segment over time.
# Example usage with random volume data set.seed(123) volume_data <- data.frame( Timeframe = 1:100, Volume = runif(100, min = 100, max = 150), Segment = 'UL' ) plot_2d_volume(volume_data, segment_names = 'Segment')
# Example usage with random volume data set.seed(123) volume_data <- data.frame( Timeframe = 1:100, Volume = runif(100, min = 100, max = 150), Segment = 'UL' ) plot_2d_volume(volume_data, segment_names = 'Segment')
Generates a 3D plot of chest markers with the selected segment highlighted, including the convex hull mesh of the selected segment.
plot_chest_3d( data, segments, selected_segment, timeframe = NULL, point_size = 5, highlight_color = "red", marker_color = "blue" )
plot_chest_3d( data, segments, selected_segment, timeframe = NULL, point_size = 5, highlight_color = "red", marker_color = "blue" )
data |
A data frame containing adjusted marker coordinates, with columns 'Timeframe', 'Marker', 'X', 'Y', 'Z'. Coordinates should be in consistent units (e.g., centimeters). |
segments |
A named list where each element is a character vector of marker names defining a segment. |
selected_segment |
A character string specifying the name of the segment to highlight. |
timeframe |
A numeric value indicating the timeframe to plot. If NULL, the first timeframe is used. |
point_size |
Numeric value specifying the size of the markers in the plot (default is 5). |
highlight_color |
Color to use for the highlighted segment markers and mesh (default is 'red'). |
marker_color |
Color to use for the non-highlighted markers (default is 'blue'). |
The function plots all markers at the specified timeframe, highlighting the markers in the selected segment and overlaying the convex hull mesh of the selected segment. The plot is interactive, allowing for rotation and zooming.
A plotly
object representing the 3D plot.
# Example input data (replace with your actual data) data(sample_data) df<-process_marker_data(head(sample_data)) df_a <- adj_position(df) # Define segments segments <- list( UL = c("M01", "M02", "M03", "M04") ) # Plot the 'UL' segment at timeframe 1 plot <- plot_chest_3d(df_a, segments, selected_segment = "UL", timeframe = 1) # Display the plot plot
# Example input data (replace with your actual data) data(sample_data) df<-process_marker_data(head(sample_data)) df_a <- adj_position(df) # Define segments segments <- list( UL = c("M01", "M02", "M03", "M04") ) # Plot the 'UL' segment at timeframe 1 plot <- plot_chest_3d(df_a, segments, selected_segment = "UL", timeframe = 1) # Display the plot plot
Processes the input dataset by sorting marker columns based on marker names and reformats it into a long format with columns 'Timeframe', 'Marker', 'X', 'Y', 'Z'. Adds a Timeframe column corresponding to each row (time frame) in the original data.
process_marker_data(data, convert_to_cm = TRUE)
process_marker_data(data, convert_to_cm = TRUE)
data |
A data frame containing marker coordinate data for all time frames. Columns should be named in the format 'MXX X', 'MXX Y', 'MXX Z' where 'MXX' is the marker name. |
convert_to_cm |
Logical, if TRUE, divides X, Y, Z coordinates by 10 to convert to centimeters (from millimeters). |
The function reshapes the wide-format data into a long format suitable for analysis, adding a Timeframe column that corresponds to each time frame. Optionally converts units to centimeters.
A data frame with columns 'Timeframe', 'Marker', 'X', 'Y', 'Z', sorted by Timeframe and Marker.
data(sample_data) processed_data <- process_marker_data(head(sample_data), convert_to_cm = TRUE) head(processed_data)
data(sample_data) processed_data <- process_marker_data(head(sample_data), convert_to_cm = TRUE) head(processed_data)
Reads an Excel file defining the markers in each segment and creates a list suitable for use with
plot_chest_3d
and calculate_segment_volumes
functions.
read_segment_definitions(filepath)
read_segment_definitions(filepath)
filepath |
A string specifying the path to the Excel file containing segment definitions. |
The Excel file should have a specific format:
Each row represents a segment.
The first column contains the segment names.
Subsequent columns contain the marker names belonging to each segment.
Missing marker entries can be left blank or filled with NA
.
A named list where each element is a character vector of marker names defining a segment.
# 'segment_def.xlsx' is the Excel file with segment definitions path <- system.file("extdata", "segment_def.xlsx", package="ChestVolume") segments <- read_segment_definitions(path) head(segments)
# 'segment_def.xlsx' is the Excel file with segment definitions path <- system.file("extdata", "segment_def.xlsx", package="ChestVolume") segments <- read_segment_definitions(path) head(segments)
This dataset contains 3D marker coordinate data collected from motion capture systems for chest expansion analysis. It includes 2309 time frames and 30 markers. Each marker has three coordinates: X, Y, and Z, representing its position in 3D space.
sample_data
sample_data
A data frame with 2309 rows and 90 variables (30 markers, each with X, Y, Z coordinates):
X-coordinate of marker M01
Y-coordinate of marker M01
Z-coordinate of marker M01
X-coordinate of marker M02
Y-coordinate of marker M02
Z-coordinate of marker M02
X-coordinate of marker M03
Y-coordinate of marker M03
Z-coordinate of marker M03
X-coordinate of marker M04
Y-coordinate of marker M04
Z-coordinate of marker M04
X-coordinate of marker M05
Y-coordinate of marker M05
Z-coordinate of marker M05
X-coordinate of marker M06
Y-coordinate of marker M06
Z-coordinate of marker M06
X-coordinate of marker M07
Y-coordinate of marker M07
Z-coordinate of marker M07
X-coordinate of marker M08
Y-coordinate of marker M08
Z-coordinate of marker M08
X-coordinate of marker M09
Y-coordinate of marker M09
Z-coordinate of marker M09
X-coordinate of marker M10
Y-coordinate of marker M10
Z-coordinate of marker M10
X-coordinate of marker M11
Y-coordinate of marker M11
Z-coordinate of marker M11
X-coordinate of marker M12
Y-coordinate of marker M12
Z-coordinate of marker M12
X-coordinate of marker M13
Y-coordinate of marker M13
Z-coordinate of marker M13
X-coordinate of marker M14
Y-coordinate of marker M14
Z-coordinate of marker M14
X-coordinate of marker M15
Y-coordinate of marker M15
Z-coordinate of marker M15
X-coordinate of marker M16
Y-coordinate of marker M16
Z-coordinate of marker M16
X-coordinate of marker M17
Y-coordinate of marker M17
Z-coordinate of marker M17
X-coordinate of marker M18
Y-coordinate of marker M18
Z-coordinate of marker M18
X-coordinate of marker M19
Y-coordinate of marker M19
Z-coordinate of marker M19
X-coordinate of marker M20
Y-coordinate of marker M20
Z-coordinate of marker M20
X-coordinate of marker M21
Y-coordinate of marker M21
Z-coordinate of marker M21
X-coordinate of marker M22
Y-coordinate of marker M22
Z-coordinate of marker M22
X-coordinate of marker M23
Y-coordinate of marker M23
Z-coordinate of marker M23
X-coordinate of marker M24
Y-coordinate of marker M24
Z-coordinate of marker M24
X-coordinate of marker M25
Y-coordinate of marker M25
Z-coordinate of marker M25
X-coordinate of marker M26
Y-coordinate of marker M26
Z-coordinate of marker M26
X-coordinate of marker M27
Y-coordinate of marker M27
Z-coordinate of marker M27
X-coordinate of marker M28
Y-coordinate of marker M28
Z-coordinate of marker M28
X-coordinate of marker M29
Y-coordinate of marker M29
Z-coordinate of marker M29
X-coordinate of marker M30
Y-coordinate of marker M30
Z-coordinate of marker M30
This dataset can be used to analyze chest expansion and calculate the volume of chest segments using convex hull methods. The markers are placed around the chest, and the data tracks the chest wall motion over time.
Collected using motion capture technology (e.g., Vicon system) for chest expansion studies.
data(sample_data) head(sample_data)
data(sample_data) head(sample_data)
This dataset defines chest segmentations using 3D markers. It is a list containing five elements: the first element is a vector of marker names, and the remaining four elements define markers assigned to four chest segments: UL (Upper Left), UR (Upper Right), LL (Lower Left), and LR (Lower Right).
Segment_example
Segment_example
A list with 5 elements:
A character vector of marker names.
A character vector of marker names included in the upper left (UL) chest segment.
A character vector of marker names included in the upper right (UR) chest segment.
A character vector of marker names included in the lower left (LL) chest segment.
A character vector of marker names included in the lower right (LR) chest segment.
This dataset is used to demonstrate how markers can be grouped into segments based on their positions on the chest. The segmentation divides the chest into four quadrants: UL (Upper Left), UR (Upper Right), LL (Lower Left), and LR (Lower Right).
# Load the dataset data(Segment_example) # View the structure of the dataset str(Segment_example) # Extract the marker names marker_names <- Segment_example[[1]] # Extract markers for the upper left (UL) segment UL_markers <- Segment_example$UL
# Load the dataset data(Segment_example) # View the structure of the dataset str(Segment_example) # Extract the marker names marker_names <- Segment_example[[1]] # Extract markers for the upper left (UL) segment UL_markers <- Segment_example$UL