colmap 0.1.2

A comprehensive Rust library for COLMAP-style computer vision and 3D reconstruction
Documentation
//! 核心数据结构和类型定义
//!
//! 这个模块包含了 COLMAP 库的所有基础数据结构和类型定义,为整个库提供统一的数据表示。
//! 所有其他模块都依赖于这里定义的核心类型。
//!
//! # 主要组件
//!
//! - **相机模型**:支持针孔、鱼眼等多种相机模型和畸变参数
//! - **图像数据**:图像元数据、特征点、描述符等信息
//! - **特征表示**:2D 特征点、描述符、匹配关系
//! - **3D 几何**:3D 点、轨迹、观测关系
//! - **相机姿态**:位置、方向、变换矩阵
//! - **重建结果**:完整的 3D 重建数据结构
//! - **错误处理**:统一的错误类型和结果类型
//!
//! # 使用示例
//!
//! ## 创建相机模型
//!
//! ```rust,ignore
//! use colmap::core::*;
//!
//! // 创建针孔相机模型
//! let intrinsics = CameraIntrinsics::pinhole(800.0, 800.0, 320.0, 240.0);
//! let camera = Camera::new(1, intrinsics, (640, 480), "Camera1".to_string());
//!
//! // 创建带畸变的相机模型
//! let intrinsics_with_distortion = CameraIntrinsics::pinhole_with_distortion(
//!     800.0, 800.0, 320.0, 240.0,
//!     vec![-0.1, 0.05, 0.001, -0.002]
//! );
//! ```
//!
//! ## 处理特征点
//!
//! ```rust,ignore
//! use colmap::core::*;
//! use nalgebra::Point2;
//!
//! // 创建特征点
//! let point = Point2::new(100.0, 200.0);
//! let descriptor = vec![1, 2, 3, 4, 5, 6, 7, 8];
//! let feature = Feature::simple(point, descriptor);
//!
//! // 创建特征匹配
//! let match_pair = FeatureMatch::new(0, 1, 0.8);
//! ```
//!
//! ## 3D 点和轨迹
//!
//! ```rust,ignore
//! use colmap::core::*;
//! use nalgebra::Point3;
//!
//! // 创建 3D 点
//! let point_3d = Point3D::new(
//!     1,
//!     Point3::new(1.0, 2.0, 3.0),
//!     [255, 128, 64] // RGB 颜色
//! );
//!
//! // 添加观测
//! let observation = Observation::new(1, 0); // 图像 ID 1,特征点索引 0
//! // point_3d.add_observation(observation);
//! ```
//!
//! ## 相机姿态
//!
//! ```rust,ignore
//! use colmap::core::*;
//! use nalgebra::{Point3, UnitQuaternion, Vector3};
//!
//! // 创建相机姿态
//! let position = Point3::new(0.0, 0.0, 0.0);
//! let rotation = UnitQuaternion::identity();
//! let pose = CameraPose::new(position, rotation);
//!
//! // 计算投影矩阵
//! let projection_matrix = pose.projection_matrix(&camera.intrinsics);
//! ```

pub mod camera;
pub mod image;
pub mod feature;
pub mod point3d;
pub mod pose;
pub mod reconstruction;

// 重新导出主要类型
pub use camera::*;
pub use image::*;
pub use feature::*;
pub use point3d::*;
pub use pose::*;
pub use reconstruction::*;

/// 库的通用错误类型
#[derive(Debug, thiserror::Error)]
pub enum ColmapError {
    #[error("IO error: {0}")]
    Io(#[from] std::io::Error),
    
    #[error("Image processing error: {0}")]
    ImageProcessing(String),
    
    #[error("Feature extraction failed: {0}")]
    FeatureExtraction(String),
    
    #[error("Feature matching failed: {0}")]
    FeatureMatching(String),
    
    #[error("SfM reconstruction failed: {0}")]
    SfmReconstruction(String),
    
    #[error("MVS reconstruction failed: {0}")]
    MvsReconstruction(String),
    
    #[error("Mathematical computation error: {0}")]
    Math(String),
    
    #[error("Configuration error: {0}")]
    Config(String),
    
    #[error("Invalid parameter: {0}")]
    InvalidParameter(String),
    
    #[error("Camera calibration error: {0}")]
    CameraCalibration(String),
    
    #[error("Triangulation failed: {0}")]
    Triangulation(String),
    
    #[error("Bundle adjustment failed: {0}")]
    BundleAdjustment(String),
    
    #[error("Database error: {0}")]
    Database(String),
    
    #[error("Serialization error: {0}")]
    Serialization(String),
    
    #[error("GPU error: {0}")]
    Gpu(String),
    
    #[error("Out of memory: {0}")]
    OutOfMemory(String),
    
    #[error("Not implemented: {0}")]
    NotImplemented(String),
}

/// 库的通用结果类型
pub type Result<T> = std::result::Result<T, ColmapError>;

/// 常用的数学类型别名
pub type Vector2 = nalgebra::Vector2<f64>;
pub type Vector3 = nalgebra::Vector3<f64>;
pub type Point2 = nalgebra::Point2<f64>;
pub type Point3 = nalgebra::Point3<f64>;
pub type Matrix3 = nalgebra::Matrix3<f64>;
pub type Matrix4 = nalgebra::Matrix4<f64>;
pub type Quaternion = nalgebra::UnitQuaternion<f64>;
pub type Isometry3 = nalgebra::Isometry3<f64>;