diff --git a/main.py b/main.py index 3b1e6b1..8d92a9d 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,4 @@ +import argparse import math from typing import List, Tuple @@ -190,7 +191,9 @@ # Function to visualize thumb data with a slider -def visualize_thumb_data(data: List[ThumbFrameData], POINT_NAMES: List[str] = []): +def visualize_thumb_data( + data: List[ThumbFrameData], POINT_NAMES: List[str] = [], data_file: str = "" +): if not data: return @@ -240,7 +243,8 @@ x2, y2, z2 = p2 mid_x = 0.5 * (x1 + x2) + LABEL_OFFSET_XY * (x1 - x2) mid_y = 0.5 * (y1 + y2) + LABEL_OFFSET_XY * (y1 - y2) - mid_z = 0.5 * (z1 + z2) + LABEL_OFFSET_Z_FACTOR * (z_max - z_min) + mid_z = 0.5 * (z1 + z2) + LABEL_OFFSET_XY * (z1 - z2) + # mid_z = 0.5 * (z1 + z2) + LABEL_OFFSET_Z_FACTOR * (z_max - z_min) midp = [mid_x, mid_y, mid_z] return [[x1, x2], [y1, y2], [z1, z2]], midp @@ -270,9 +274,11 @@ arrow_labels.append(lbl) # Angle display - angle_text1 = fig.text(0.02, 0.95, "", fontsize=12, weight="bold") + if data_file: + fig.suptitle(f"Loaded file: {data_file}", fontsize=14) + angle_text1 = fig.text(0.02, 0.93, "", fontsize=12, weight="bold") angle_text1.set_text(compute_and_format_angle(points, 0, 1)) - angle_text2 = fig.text(0.02, 0.92, "", fontsize=12, weight="bold") + angle_text2 = fig.text(0.02, 0.90, "", fontsize=12, weight="bold") angle_text2.set_text(compute_and_format_angle(points, 4, 1)) ax.set_xlabel("X") @@ -312,13 +318,15 @@ # Update texts for i, p in enumerate(points): - texts[i].set_position((p[0], p[1], p[2])) + texts[i].set_position((p[0], p[1])) + texts[i].set_3d_properties(p[2], zdir=None) # Update all configured arrows for i_pair, (idx1, idx2, color, name) in enumerate(VECTORS): arrow_pts, mid_pts = vector_coordinates(points[idx1], points[idx2]) arrows[i_pair]._verts3d = arrow_pts - arrow_labels[i_pair].set_position(mid_pts) + arrow_labels[i_pair].set_position((mid_pts[0], mid_pts[1])) + arrow_labels[i_pair].set_3d_properties(mid_pts[2], zdir=None) # Update angle text angle_text1.set_text(compute_and_format_angle(points, 0, 1)) @@ -389,13 +397,38 @@ # Main function to test loading and visualization def main(): + parser = argparse.ArgumentParser(description="Thumb analysis visualizer") + parser.add_argument( + "csv_file", + nargs="?", + default="IwasakiThumbRightKapandji03.csv", + help="Input CSV file path", + ) + args = parser.parse_args() + # Test the load_thumb_data function - data_file = "IwasakiThumbRightKapandji03.csv" - names, data = load_thumb_data(data_file) + data_file = args.csv_file + try: + names, data = load_thumb_data(data_file) + except FileNotFoundError: + print(f"Error: CSV file not found: {data_file}") + return + except pd.errors.EmptyDataError: + print(f"Error: CSV file is empty: {data_file}") + return + except pd.errors.ParserError as e: + print(f"Error: Failed to parse CSV file: {data_file}") + print(f"Details: {e}") + return + except Exception as e: + print(f"Error: Failed to load CSV file: {data_file}") + print(f"Details: {e}") + return + print(f"Loaded {len(data)} frames") if data: # Visualize the data - visualize_thumb_data(data, names) + visualize_thumb_data(data, names, data_file) if __name__ == "__main__":