UNPKG

js-subpcd

Version:

🌟 High-performance JavaScript/TypeScript QuadTree point cloud filtering and processing library. Published on npm as js-subpcd with PCL.js compatible API for spatial filtering, subsampling, and nearest neighbor search.

249 lines (248 loc) • 6.63 kB
/** * JavaScript QuadTree Point Cloud Filtering Package * PCL.js compatible API for point cloud processing with QuadTree spatial indexing */ import { QuadTree } from 'js-quadtree'; export interface Point3DData { x: number; y: number; z: number; data?: any; } export interface CoordinateArrays { x: number[]; y: number[]; z: number[]; } export interface Bounds { minX: number; minY: number; maxX: number; maxY: number; } export interface LayerInfo { layer: number; gridSize: number; totalCells: number; cellSize: number; spacingX: number; spacingY: number; depth: number; } export interface InitOptions { url?: string; [key: string]: any; } /** * Point class representing XYZ coordinates, compatible with PCL.js PointXYZ */ export declare class PointXYZ { x: number; y: number; z: number; constructor(x?: number, y?: number, z?: number); /** * Create a copy of this point */ clone(): PointXYZ; /** * Calculate distance to another point */ distanceTo(other: PointXYZ): number; } /** * Legacy Point3D class for backward compatibility */ export declare class Point3D extends PointXYZ { data?: any; constructor(x: number, y: number, z: number, data?: any); } /** * Point Cloud data structure, compatible with PCL.js patterns */ export declare class PointCloud { points: PointXYZ[]; pointType: typeof PointXYZ; width: number; height: number; isOrganized: boolean; constructor(pointType?: typeof PointXYZ); /** * Get the number of points in the cloud */ size(): number; /** * Check if the point cloud is empty */ empty(): boolean; /** * Add a point to the cloud */ addPoint(point: PointXYZ): void; /** * Get point at index */ at(index: number): PointXYZ; /** * Clear all points */ clear(): void; } /** * Data loader for point cloud files, following PCL.js async patterns */ export declare class DataLoader { cloud: PointCloud; bounds: number[] | null; constructor(); /** * Load point cloud data from file (async, PCL.js style) */ loadPCDData(input: string | ArrayBuffer): Promise<PointCloud>; /** * Load points from a text file (legacy method) */ loadFromFile(filename: string): PointXYZ[]; /** * Parse point cloud data from string */ _parsePointCloudData(data: string): PointCloud; /** * Calculate bounding box from loaded points */ private _calculateBounds; /** * Get coordinate arrays (legacy compatibility) */ getCoordinateArrays(): CoordinateArrays; /** * Get bounding box */ getBounds(): number[] | null; /** * Get points array (legacy compatibility) */ get points(): PointXYZ[]; /** * Set points array (legacy compatibility) */ set points(points: PointXYZ[]); } /** * QuadTree Manager using js-quadtree library */ export declare class QuadTreeManager { quadtree: QuadTree | null; points: Point3D[]; bounds: number[] | null; coordinateArrays: CoordinateArrays | null; sparseThreshold: number; constructor(); /** * Build quadtree from Point3D objects */ buildTree(points: Point3D[], bounds: number[], maxElements?: number, maxDepth?: number): void; /** * Build quadtree from coordinate arrays */ buildTreeFromArrays(xCoords: number[], yCoords: number[], zCoords: number[], bounds: number[], maxElements?: number, maxDepth?: number): void; /** * Query points within a rectangular region */ queryRegion(minX: number, minY: number, maxX: number, maxY: number): Point3D[]; /** * Query point indices within a rectangular region (optimized) */ queryRegionIndices(minX: number, minY: number, maxX: number, maxY: number): number[]; /** * Find nearest neighbors to a point */ findNearestNeighbors(x: number, y: number, count?: number, maxDistance?: number | null): Point3D[]; /** * Get statistics about the quadtree */ getStatistics(): { totalPoints: number; }; /** * Check if quadtree is built */ isBuilt(): boolean; /** * Clear the quadtree */ clear(): void; } /** * QuadTree Filter for point cloud filtering operations */ export declare class QuadTreeFilter { minCellSize: number; dataLoader: DataLoader; quadtreeManager: QuadTreeManager; layerSchedule: LayerInfo[] | null; points: PointXYZ[]; bounds: number[] | null; private _cachedPointsHash; private _cachedBounds; private _cachedLayerSchedule; private _treeBuilt; constructor(minCellSize: number); /** * Load points from file */ loadFromFile(filename: string): void; /** * Filter points by grid spacing */ filterPointsByGridSpacing(xCoords: number[], yCoords: number[], zCoords: number[], minLateralSpacing: number): Point3D[]; /** * Calculate hash for coordinate arrays */ private _calculatePointsHash; /** * Calculate layer schedule for power-of-2 grids */ calculateLayerSchedule(bounds: number[], minCellSize: number): LayerInfo[]; /** * Filter points by grid spacing (internal method) */ private _filterByGridSpacing; /** * Filter points by quadtree depth */ filterByDepth(targetDepth: number): Point3D[]; } export interface PCLObject { PointXYZ: typeof PointXYZ; PointCloud: typeof PointCloud; DataLoader: typeof DataLoader; QuadTreeManager: typeof QuadTreeManager; QuadTreeFilter: typeof QuadTreeFilter; loadPCDData: (data: ArrayBuffer) => Promise<PointCloud>; savePCDDataASCII: (cloud: PointCloud) => ArrayBuffer; } /** * PCL.js compatible initialization function */ export declare function init(options?: InitOptions): Promise<PCLObject>; /** * Load PCD data (global function, PCL.js style) */ export declare function loadPCDData(data: ArrayBuffer, pointType?: typeof PointXYZ): PointCloud; /** * Save point cloud as PCD ASCII data */ export declare function savePCDDataASCII(cloud: PointCloud): ArrayBuffer; declare const _default: { PointXYZ: typeof PointXYZ; PointCloud: typeof PointCloud; Point3D: typeof Point3D; DataLoader: typeof DataLoader; QuadTreeManager: typeof QuadTreeManager; QuadTreeFilter: typeof QuadTreeFilter; init: typeof init; loadPCDData: typeof loadPCDData; savePCDDataASCII: typeof savePCDDataASCII; }; export default _default;