50 lines
1.3 KiB
Python
50 lines
1.3 KiB
Python
"""测量任务基类"""
|
|
from abc import ABC, abstractmethod
|
|
from typing import Dict, Any, Optional
|
|
from dataclasses import dataclass
|
|
import numpy as np
|
|
|
|
|
|
@dataclass
|
|
class MeasurementResult:
|
|
"""测量结果数据类"""
|
|
task_name: str
|
|
task_type: str
|
|
success: bool
|
|
data: Optional[Dict[str, Any]] = None
|
|
error_message: Optional[str] = None
|
|
|
|
|
|
class BaseMeasurement(ABC):
|
|
"""测量任务基类"""
|
|
|
|
def __init__(self, name: str, point_cloud: np.ndarray, config: Dict[str, Any], spatial_index=None):
|
|
"""
|
|
初始化测量任务
|
|
|
|
Args:
|
|
name: 任务名称
|
|
point_cloud: 完整点云数组 (N, 3)
|
|
config: 任务配置字典
|
|
spatial_index: 空间索引对象(可选)
|
|
"""
|
|
self.name = name
|
|
self.point_cloud = point_cloud
|
|
self.config = config
|
|
self.task_type = config.get('type', 'unknown')
|
|
self.spatial_index = spatial_index # 保存空间索引
|
|
|
|
@abstractmethod
|
|
def execute(self) -> MeasurementResult:
|
|
"""
|
|
执行测量任务
|
|
|
|
Returns:
|
|
MeasurementResult: 测量结果
|
|
"""
|
|
pass
|
|
|
|
def is_enabled(self) -> bool:
|
|
"""检查任务是否启用"""
|
|
return self.config.get('enabled', True)
|