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.
240 lines (239 loc) • 6.4 kB
TypeScript
/**
* JavaScript QuadTree Point Cloud Filtering Package - Browser Version
* PCL.js compatible API for point cloud processing with QuadTree spatial indexing
* This version removes Node.js dependencies for browser compatibility
*/
export interface QuadTreeBoundary {
x: number;
y: number;
width: number;
height: number;
}
export interface QuadTreePoint {
x: number;
y: number;
data?: {
index: number;
z: number;
};
}
export interface TreeInfo {
type: 'wasm' | 'javascript';
instance: any;
pointCount: number;
}
interface WASMWrapper {
buildTree(points: Array<{
x: number;
y: number;
z: number;
}>, bounds: {
minX: number;
minY: number;
maxX: number;
maxY: number;
}): Promise<TreeInfo>;
filterByDepth(treeInfo: TreeInfo, targetDepth: number): Array<{
x: number;
y: number;
z: number;
}>;
}
declare global {
interface Window {
quadTreeWasmWrapper?: WASMWrapper;
PointXYZ: typeof PointXYZ;
PointCloud: typeof PointCloud;
Point3D: typeof Point3D;
DataLoader: typeof DataLoader;
QuadTreeManager: typeof QuadTreeManager;
QuadTreeFilter: typeof QuadTreeFilter;
}
}
/**
* Simple QuadTree implementation for browser use
*/
export declare class SimpleQuadTree {
boundary: QuadTreeBoundary;
capacity: number;
maxDepth: number;
depth: number;
points: QuadTreePoint[];
divided: boolean;
northeast: SimpleQuadTree | null;
northwest: SimpleQuadTree | null;
southeast: SimpleQuadTree | null;
southwest: SimpleQuadTree | null;
constructor(boundary: QuadTreeBoundary, capacity?: number, maxDepth?: number, depth?: number);
insert(point: QuadTreePoint): boolean;
contains(point: QuadTreePoint): boolean;
subdivide(): void;
query(range: QuadTreeBoundary, found?: QuadTreePoint[]): QuadTreePoint[];
intersects(range: QuadTreeBoundary): boolean;
inRange(point: QuadTreePoint, range: QuadTreeBoundary): boolean;
getAllPoints(found?: QuadTreePoint[]): QuadTreePoint[];
clear(): void;
}
/**
* 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);
}
/**
* 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;
/**
* Clear all points
*/
clear(): void;
}
/**
* Data loader for point cloud files, browser-compatible version
*/
export declare class DataLoader {
cloud: PointCloud;
bounds: number[] | null;
constructor();
/**
* Load point cloud data from text string
*/
loadFromText(data: 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(): {
x: number[];
y: number[];
z: number[];
};
/**
* 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 SimpleQuadTree with WebAssembly optimization
*/
export declare class QuadTreeManager {
quadtree: SimpleQuadTree | null;
points: Point3D[];
bounds: number[] | null;
coordinateArrays: {
x: number[];
y: number[];
z: number[];
} | null;
sparseThreshold: number;
treeInfo: TreeInfo | null;
wasmWrapper: WASMWrapper | null;
constructor();
/**
* Build quadtree from Point3D objects
*/
buildTree(points: Point3D[], bounds: number[], maxElements?: number, maxDepth?: number): void;
/**
* Build quadtree from coordinate arrays with automatic WASM/JS selection
*/
buildTreeFromArrays(xCoords: number[], yCoords: number[], zCoords: number[], bounds: number[], maxElements?: number, maxDepth?: number): Promise<void>;
/**
* Pure JavaScript tree building (fallback)
*/
private _buildTreeJS;
/**
* 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[];
/**
* Check if quadtree is built
*/
isBuilt(): boolean;
/**
* Clear the quadtree
*/
clear(): void;
}
interface LayerInfo {
layer: number;
gridSize: number;
totalCells: number;
cellSize: number;
spacingX: number;
spacingY: number;
depth: number;
}
/**
* 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 _treeBuilt;
constructor(minCellSize: number);
/**
* Calculate layer schedule for power-of-2 grids
*/
calculateLayerSchedule(bounds: number[], minCellSize: number): LayerInfo[];
/**
* Filter points by quadtree depth with WASM optimization and caching
*/
filterByDepth(targetDepth: number): Promise<Point3D[]>;
}
/**
* PCL.js compatible initialization function
*/
export declare function init(options?: any): Promise<any>;
export {};