127 lines
3.6 KiB
Python
127 lines
3.6 KiB
Python
"""列车点云测量系统 - 主程序入口"""
|
|
import sys
|
|
import argparse
|
|
from pathlib import Path
|
|
|
|
# 添加src目录到Python路径
|
|
sys.path.insert(0, str(Path(__file__).parent / "src"))
|
|
|
|
from task_manager import TaskManager
|
|
|
|
|
|
def parse_args():
|
|
"""解析命令行参数"""
|
|
parser = argparse.ArgumentParser(
|
|
description="列车点云测量系统",
|
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
epilog="""
|
|
示例:
|
|
python main.py # 使用默认配置文件
|
|
python main.py -c config/custom.yaml # 指定配置文件
|
|
python main.py -p data/train.ply # 指定点云文件(覆盖配置)
|
|
python main.py -o results/output # 指定输出目录
|
|
python main.py -c config/custom.yaml -p data/train.ply -o results/
|
|
"""
|
|
)
|
|
|
|
parser.add_argument(
|
|
'-c', '--config',
|
|
type=str,
|
|
default='config/measurements.yaml',
|
|
help='配置文件路径 (默认: config/measurements.yaml)'
|
|
)
|
|
|
|
parser.add_argument(
|
|
'-p', '--pointcloud',
|
|
type=str,
|
|
default=None,
|
|
help='点云文件路径 (覆盖配置文件中的路径)'
|
|
)
|
|
|
|
parser.add_argument(
|
|
'-o', '--output',
|
|
type=str,
|
|
default=None,
|
|
help='结果输出目录 (覆盖配置文件中的路径,默认: results/)'
|
|
)
|
|
|
|
return parser.parse_args()
|
|
|
|
|
|
def main():
|
|
"""主函数"""
|
|
print("=" * 60)
|
|
print("列车点云测量系统")
|
|
print("=" * 60)
|
|
|
|
# 解析命令行参数
|
|
args = parse_args()
|
|
|
|
# 配置文件路径(支持相对路径和绝对路径)
|
|
config_file = Path(args.config)
|
|
if not config_file.is_absolute():
|
|
config_file = Path(__file__).parent / config_file
|
|
|
|
if not config_file.exists():
|
|
print(f"错误: 配置文件不存在: {config_file}")
|
|
return 1
|
|
|
|
print(f"\n加载配置文件: {config_file}")
|
|
|
|
# 创建任务管理器
|
|
manager = TaskManager()
|
|
|
|
# 加载配置
|
|
if not manager.load_config(str(config_file)):
|
|
print("错误: 配置文件加载失败")
|
|
return 1
|
|
|
|
# 命令行参数覆盖配置
|
|
if args.pointcloud:
|
|
pointcloud_path = Path(args.pointcloud)
|
|
if not pointcloud_path.is_absolute():
|
|
pointcloud_path = Path(__file__).parent / pointcloud_path
|
|
manager.override_pointcloud_path(str(pointcloud_path))
|
|
print(f"使用命令行指定的点云文件: {pointcloud_path}")
|
|
|
|
if args.output:
|
|
output_dir = Path(args.output)
|
|
if not output_dir.is_absolute():
|
|
output_dir = Path(__file__).parent / output_dir
|
|
manager.override_output_dir(str(output_dir))
|
|
print(f"使用命令行指定的输出目录: {output_dir}")
|
|
|
|
# 执行所有测量任务
|
|
print("\n开始执行测量任务...")
|
|
print("-" * 60)
|
|
|
|
results = manager.run_all_tasks()
|
|
|
|
# 输出结果摘要
|
|
print("\n" + "=" * 60)
|
|
print("测量结果摘要")
|
|
print("=" * 60)
|
|
|
|
success_count = sum(1 for r in results if r['status'] == 'success')
|
|
failed_count = len(results) - success_count
|
|
|
|
print(f"\n总任务数: {len(results)}")
|
|
print(f"成功: {success_count}")
|
|
print(f"失败: {failed_count}")
|
|
|
|
if failed_count > 0:
|
|
print("\n失败的任务:")
|
|
for result in results:
|
|
if result['status'] == 'failed':
|
|
print(f" - {result['name']}: {result.get('error', '未知错误')}")
|
|
|
|
print("\n" + "=" * 60)
|
|
print("测量完成!")
|
|
print("=" * 60)
|
|
|
|
return 0 if failed_count == 0 else 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|