Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-09 10:47:17

0001 #!/bin/bash
0002 
0003 # Usage:
0004 #   ./cut_all_stl.sh INPUT_DIR OUTPUT_DIR reference.stl
0005 #
0006 # Example:
0007 #   ./cut_all_stl.sh ./meshes ./cut_meshes ./reference.stl
0008 
0009 set -u
0010 
0011 if [ "$#" -ne 3 ]; then
0012     echo "Usage: $0 INPUT_DIR OUTPUT_DIR REFERENCE_STL"
0013     exit 1
0014 fi
0015 
0016 INPUT_DIR="$1"
0017 OUTPUT_DIR="$2"
0018 REFERENCE_STL="$3"
0019 
0020 # Location of intersect_stl.py.
0021 # Change this if the Python script is somewhere else.
0022 INTERSECT_SCRIPT="./intersect_stl.py"
0023 
0024 # Check input directory
0025 if [ ! -d "$INPUT_DIR" ]; then
0026     echo "Error: input directory does not exist: $INPUT_DIR"
0027     exit 1
0028 fi
0029 
0030 # Check reference file
0031 if [ ! -f "$REFERENCE_STL" ]; then
0032     echo "Error: reference STL does not exist: $REFERENCE_STL"
0033     exit 1
0034 fi
0035 
0036 # Check intersection script
0037 if [ ! -f "$INTERSECT_SCRIPT" ]; then
0038     echo "Error: cannot find: $INTERSECT_SCRIPT"
0039     exit 1
0040 fi
0041 
0042 # Create output directory if necessary
0043 mkdir -p "$OUTPUT_DIR"
0044 
0045 count=0
0046 success=0
0047 failed=0
0048 
0049 # Process all .stl files
0050 for input_file in "$INPUT_DIR"/*.stl; do
0051 
0052     # If there are no matching files, stop
0053     [ -e "$input_file" ] || continue
0054 
0055     filename=$(basename "$input_file")
0056     basename="${filename%.*}"
0057 
0058     output_file="$OUTPUT_DIR/${basename}.stl"
0059 
0060     echo "------------------------------------------------------------"
0061     echo "Input:  $input_file"
0062     echo "Output: $output_file"
0063 
0064     count=$((count + 1))
0065 
0066     if python "$INTERSECT_SCRIPT" \
0067         "$input_file" \
0068         "$REFERENCE_STL" \
0069         "$output_file"
0070     then
0071         success=$((success + 1))
0072     else
0073         echo "WARNING: intersection failed or was empty for $filename"
0074         failed=$((failed + 1))
0075     fi
0076 
0077 done
0078 
0079 echo "------------------------------------------------------------"
0080 echo "Finished."
0081 echo "Files processed: $count"
0082 echo "Successful:      $success"
0083 echo "Failed/empty:    $failed"