874 {
875 options opts;
876
877 if (!parse_arguments(argc, argv, opts)) {
878 std::cout << R"(
879 ____ ____ __ __ _______ _______ ____ _ ____ _____
880 | _ \ / ___| \/ | | ____\ \/ /_ _| _ \ / \ / ___|_ _|
881 | | | | | | |\/| | | _| \ / | | | |_) | / _ \| | | |
882 | |_| | |___| | | | | |___ / \ | | | _ < / ___ \ |___ | |
883 |____/ \____|_| |_| |_____/_/\_\ |_| |_| \_\/_/ \_\____| |_|
884
885 DICOM Pixel Data Extraction Utility
886)" << "\n";
887 print_usage(argv[0]);
888 return 1;
889 }
890
891
892 if (!std::filesystem::exists(opts.input_path)) {
893 std::cerr << "Error: Input path does not exist: " << opts.input_path.string()
894 << "\n";
895 return 2;
896 }
897
898
899 if (!opts.quiet) {
900 std::cout << R"(
901 ____ ____ __ __ _______ _______ ____ _ ____ _____
902 | _ \ / ___| \/ | | ____\ \/ /_ _| _ \ / \ / ___|_ _|
903 | | | | | | |\/| | | _| \ / | | | |_) | / _ \| | | |
904 | |_| | |___| | | | | |___ / \ | | | _ < / ___ \ |___ | |
905 |____/ \____|_| |_| |_____/_/\_\ |_| |_| \_\/_/ \_\____| |_|
906
907 DICOM Pixel Data Extraction Utility
908)" << "\n";
909 }
910
911 extraction_stats stats;
912 auto start_time = std::chrono::steady_clock::now();
913
914 if (std::filesystem::is_directory(opts.input_path)) {
915
916 if (!opts.info_only) {
917 if (!std::filesystem::exists(opts.output_path)) {
918 std::filesystem::create_directories(opts.output_path);
919 }
920 }
921
922 if (!opts.quiet) {
923 std::cout << "Processing directory: " << opts.input_path.string() << "\n";
924 if (opts.recursive) {
925 std::cout << "Mode: Recursive\n\n";
926 }
927 }
928
929 process_directory(opts.input_path, opts.output_path, opts, stats);
930 } else {
931
932 ++stats.total_files;
933
934 if (extract_file(opts.input_path, opts.output_path, opts)) {
935 ++stats.success_count;
936 if (!opts.quiet && !opts.info_only) {
937 std::cout << "Extraction completed successfully.\n";
938 std::cout << " Output: " << opts.output_path.string() << "\n";
939 }
940 } else {