Contents Menu Expand Light mode Dark mode Auto light/dark mode
ACloudViewer 3.9.4 documentation
ACloudViewer 3.9.4 documentation

Getting Started

  • Introduction
  • Installation
  • Quick Start
  • Building from Source
  • Build documentation
  • CloudViewer-ML

Tutorial

  • Tutorial
  • Core
    • Tensor
    • Hash map
  • Geometry
    • Point cloud
    • Mesh
    • RGBD images
    • KDTree
    • Half Edge Mesh
    • File IO
    • Point cloud outlier removal
    • Voxelization
    • Octree
    • Surface reconstruction
    • Transformation
    • Mesh deformation
    • Intrinsic shape signatures (ISS)
    • Ray Casting
    • Distance Queries
    • UV Maps
    • Python Interface
    • Working with NumPy
  • Geometry (Tensor)
    • PointCloud
  • Dataset
  • Visualization
    • Visualization
    • Customized visualization
    • Interactive visualization
    • Non-blocking visualization
    • Headless rendering
    • CPU (Software) Rendering
    • Web visualizer and Jupyter
    • CloudViewer for TensorBoard
    • Simple geometry sequences
    • Rich 3D models with PBR materials
    • 3DML models training and inference
    • Custom properties and semantic segmentation
    • 3D object detection
    • Troubleshooting
  • Pipelines
    • ICP registration
    • Robust kernels
    • Colored point cloud registration
    • Global registration
    • Multiway registration
    • RGBD integration
    • RGBD Odometry
    • Color Map Optimization
  • Pipelines (Tensor)
    • ICP registration
    • Robust Kernel
  • Reconstruction system
    • System overview
    • Make fragments
    • Register fragments
    • Refine registration
    • Integrate scene
    • Capture your own dataset
  • Reconstruction system (Tensor)
    • Voxel Block Grid
    • TSDF Integration
    • Customized Integration
    • Ray Casting in a Voxel Block Grid
    • Dense RGB-D SLAM
  • Sensor
    • Azure Kinect with CloudViewer
    • RealSense with CloudViewer
  • Advanced Topics
  • Reference

Python API

  • cloudViewer.camera
    • PinholeCameraIntrinsic
    • PinholeCameraIntrinsicParameters
    • PinholeCameraParameters
    • PinholeCameraTrajectory
  • cloudViewer.core
    • Blob
    • DLDeviceType
    • Device
    • Dtype
    • DynamicSizeVector
    • HashBackendType
    • HashMap
    • HashSet
    • Scalar
    • SizeVector
    • Tensor
    • TensorList
    • addmm
    • append
    • concatenate
    • det
    • inv
    • lstsq
    • lu
    • lu_ipiv
    • matmul
    • maximum
    • minimum
    • solve
    • svd
    • tril
    • triu
    • triul
    • cuda
      • device_count
      • is_available
      • release_cache
      • synchronize
    • kernel
      • test_linalg_integration
    • nns
      • NearestNeighborSearch
  • cloudViewer.data
    • ArmadilloMesh
    • AvocadoModel
    • BalusterVase
    • BedroomRGBDImages
    • BunnyMesh
    • CrateModel
    • DamagedHelmetModel
    • DataDescriptor
    • Dataset
    • DemoColoredICPPointClouds
    • DemoCropPointCloud
    • DemoCustomVisualization
    • DemoDopplerICPSequence
    • DemoFeatureMatchingPointClouds
    • DemoICPPointClouds
    • DemoPoseGraphOptimization
    • DownloadDataset
    • EaglePointCloud
    • FacetsModel
    • FlightHelmetModel
    • JackJackL515Bag
    • JuneauImage
    • KnotMesh
    • LivingRoomPointClouds
    • LoungeRGBDImages
    • MetalTexture
    • MonkeyModel
    • OfficePointClouds
    • PCDPointCloud
    • PLYPointCloud
    • PaintedPlasterTexture
    • PolylinesModel
    • RedwoodIndoorLivingRoom1
    • RedwoodIndoorLivingRoom2
    • RedwoodIndoorOffice1
    • RedwoodIndoorOffice2
    • SampleFountainRGBDImages
    • SampleL515Bag
    • SampleNYURGBDImage
    • SampleRedwoodRGBDImages
    • SampleSUNRGBDImage
    • SampleTUMRGBDImage
    • SwordModel
    • TerrazzoTexture
    • TilesTexture
    • WoodFloorTexture
    • WoodTexture
    • get_custom_downloads_prefix
    • set_custom_downloads_prefix
  • cloudViewer.geometry
    • BoundingBox
    • DeformAsRigidAsPossibleEnergy
    • FilterScope
    • GenericCloud
    • GenericIndexedCloud
    • GenericIndexedCloudPersist
    • GenericIndexedMesh
    • GenericMesh
    • GenericTriangle
    • HalfEdge
    • HalfEdgeTriangleMesh
    • Image
    • ImageFilterType
    • KDTreeFlann
    • KDTreeSearchParam
    • KDTreeSearchParamHybrid
    • KDTreeSearchParamKNN
    • KDTreeSearchParamRadius
    • LineSet
    • MeshScalarFieldProcessType
    • Octree
    • OctreeColorLeafNode
    • OctreeInternalNode
    • OctreeInternalPointNode
    • OctreeLeafNode
    • OctreeNode
    • OctreeNodeInfo
    • OctreePointColorLeafNode
    • OrientedBoundingBox
    • Polyline
    • RGBDImage
    • RansacParams
    • RansacResult
    • ReferenceCloud
    • SimplificationContraction
    • TetraMesh
    • TriangulationType
    • VerticesIndexes
    • Voxel
    • VoxelGrid
    • ccBBox
    • ccBox
    • ccCircle
    • ccCone
    • ccCoordinateSystem
    • ccCylinder
    • ccDisc
    • ccDish
    • ccDrawableObject
    • ccExtru
    • ccFacet
    • ccGenericMesh
    • ccGenericPointCloud
    • ccGenericPrimitive
    • ccHObject
    • ccMesh
    • ccObject
    • ccPlanarEntityInterface
    • ccPlane
    • ccPointCloud
    • ccPolyline
    • ccQuadric
    • ccSphere
    • ccTorus
    • ecvMeshBase
    • ecvOrientedBBox
    • To2DLabel
    • To2DViewportLabel
    • To2DViewportObject
    • ToBBox
    • ToBox
    • ToCameraSensor
    • ToCone
    • ToCoordinateSystem
    • ToCylinder
    • ToDish
    • ToExtru
    • ToFacet
    • ToGBLSensor
    • ToImage
    • ToImage2
    • ToKdTree
    • ToLineSet
    • ToMesh
    • ToOctree2
    • ToOctreeProxy
    • ToOrientedBBox
    • ToPlane
    • ToPointCloud
    • ToPolyline
    • ToQuadric
    • ToRGBDImage
    • ToSensor
    • ToSphere
    • ToSubMesh
    • ToTorus
    • ToTransBuffer
    • ToVoxelGrid
    • get_rotation_matrix_from_axis_angle
    • get_rotation_matrix_from_euler_angle
    • get_rotation_matrix_from_quaternion
    • get_rotation_matrix_from_xyz
    • get_rotation_matrix_from_xzy
    • get_rotation_matrix_from_yxz
    • get_rotation_matrix_from_yzx
    • get_rotation_matrix_from_zxy
    • get_rotation_matrix_from_zyx
    • keypoint
      • compute_iss_keypoints
  • cloudViewer.io
    • FileGeometry
    • read_entity
    • read_feature
    • read_file_geometry_type
    • read_image
    • read_line_set
    • read_octree
    • read_pinhole_camera_intrinsic
    • read_pinhole_camera_parameters
    • read_pinhole_camera_trajectory
    • read_point_cloud
    • read_point_cloud_from_bytes
    • read_pose_graph
    • read_triangle_mesh
    • read_triangle_model
    • read_voxel_grid
    • write_entity
    • write_feature
    • write_image
    • write_line_set
    • write_octree
    • write_pinhole_camera_intrinsic
    • write_pinhole_camera_parameters
    • write_pinhole_camera_trajectory
    • write_point_cloud
    • write_point_cloud_to_bytes
    • write_pose_graph
    • write_triangle_mesh
    • write_voxel_grid
    • rpc
      • BufferConnection
      • Connection
      • destroy_zmq_context
      • data_buffer_to_meta_geometry
      • set_active_camera
      • set_legacy_camera
      • set_mesh_data
      • set_point_cloud
      • set_time
      • set_triangle_mesh
  • cloudViewer.t
    • geometry
      • AxisAlignedBoundingBox
      • DrawableGeometry
      • Geometry
      • Image
      • InterpType
      • LineSet
      • MethodOBBCreate
      • Metric
      • MetricParameters
      • OrientedBoundingBox
      • PointCloud
      • RGBDImage
      • RaycastingScene
      • TensorMap
      • TriangleMesh
      • VectorMetric
      • VoxelBlockGrid
    • io
      • DepthNoiseSimulator
      • RGBDSensor
      • RGBDVideoMetadata
      • RGBDVideoReader
      • SensorType
      • read_image
      • read_npz
      • read_numpy
      • read_point_cloud
      • read_triangle_mesh
      • write_image
      • write_npz
      • write_numpy
      • write_point_cloud
      • write_triangle_mesh
    • pipelines
      • odometry
        • Method
        • OdometryConvergenceCriteria
        • OdometryLossParams
        • OdometryResult
        • compute_odometry_information_matrix
        • compute_odometry_result_hybrid
        • compute_odometry_result_intensity
        • compute_odometry_result_point_to_plane
        • rgbd_odometry_multi_scale
      • registration
        • ICPConvergenceCriteria
        • RegistrationResult
        • TransformationEstimation
        • TransformationEstimationForColoredICP
        • TransformationEstimationForDopplerICP
        • TransformationEstimationPointToPlane
        • TransformationEstimationPointToPoint
        • compute_fpfh_feature
        • correspondences_from_features
        • evaluate_registration
        • get_information_matrix
        • icp
        • multi_scale_icp
        • robust_kernel
          • RobustKernel
          • RobustKernelMethod
      • slac
        • control_grid
        • slac_debug_option
        • slac_optimizer_params
        • run_rigid_optimizer_for_fragments
        • run_slac_optimizer_for_fragments
        • save_correspondences_for_pointclouds
      • slam
        • Frame
        • Model
  • cloudViewer.ml
    • contrib
      • iou_3d_cpu
      • iou_bev_cpu
      • knn_search
      • radius_search
      • subsample
      • subsample_batch
    • torch
      • classes
        • RaggedTensor
      • dataloaders
        • ConcatBatcher
        • DefaultBatcher
        • TorchDataloader
        • get_sampler
      • datasets
        • Argoverse
        • Custom3D
        • Electricity3D
        • InferenceDummySplit
        • KITTI
        • Lyft
        • NuScenes
        • ParisLille3D
        • S3DIS
        • Scannet
        • SemSegRandomSampler
        • SemSegSpatiallyRegularSampler
        • Semantic3D
        • SemanticKITTI
        • ShapeNet
        • SunRGBD
        • Toronto3D
        • Waymo
        • utils
          • BEVBox3D
          • DataProcessing
          • ObjdetAugmentation
          • create_3D_rotations
          • get_min_bbox
          • trans_augment
          • trans_crop_pc
          • trans_normalize
      • layers
        • ContinuousConv
        • FixedRadiusSearch
        • KNNSearch
        • RadiusSearch
        • SparseConv
        • SparseConvTranspose
        • VoxelPooling
      • models
        • KPFCNN
        • PVCNN
        • PointPillars
        • PointRCNN
        • PointTransformer
        • RandLANet
        • SparseConvUnet
      • modules
        • losses
          • CrossEntropyLoss
          • FocalLoss
          • SemSegLoss
          • SmoothL1Loss
          • filter_valid_label
        • metrics
          • SemSegMetric
      • ops
        • build_spatial_hash_table
        • continuous_conv
        • continuous_conv_transpose
        • fixed_radius_search
        • invert_neighbors_list
        • knn_search
        • nms
        • radius_search
        • ragged_to_dense
        • reduce_subarrays_sum
        • sparse_conv
        • sparse_conv_transpose
        • voxel_pooling
        • voxelize
      • pipelines
        • ObjectDetection
        • SemanticSegmentation
      • vis
        • BoundingBox3D
        • Colormap
        • DataModel
        • DatasetModel
        • LabelLUT
        • Model
        • Visualizer
        • deque
        • rgb_to_yiq
  • cloudViewer.pipelines
    • color_map
      • NonRigidOptimizerOption
      • RigidOptimizerOption
      • run_non_rigid_optimizer
      • run_rigid_optimizer
    • integration
      • ScalableTSDFVolume
      • TSDFVolume
      • TSDFVolumeColorType
      • UniformTSDFVolume
    • odometry
      • OdometryOption
      • RGBDOdometryJacobian
      • RGBDOdometryJacobianFromColorTerm
      • RGBDOdometryJacobianFromHybridTerm
      • compute_rgbd_odometry
    • registration
      • CauchyLoss
      • CorrespondenceChecker
      • CorrespondenceCheckerBasedOnDistance
      • CorrespondenceCheckerBasedOnEdgeLength
      • CorrespondenceCheckerBasedOnNormal
      • FastGlobalRegistrationOption
      • Feature
      • GMLoss
      • GlobalOptimizationConvergenceCriteria
      • GlobalOptimizationGaussNewton
      • GlobalOptimizationLevenbergMarquardt
      • GlobalOptimizationMethod
      • GlobalOptimizationOption
      • HuberLoss
      • ICPConvergenceCriteria
      • L1Loss
      • L2Loss
      • PoseGraph
      • PoseGraphEdge
      • PoseGraphEdgeVector
      • PoseGraphNode
      • PoseGraphNodeVector
      • RANSACConvergenceCriteria
      • RegistrationResult
      • RobustKernel
      • TransformationEstimation
      • TransformationEstimationForColoredICP
      • TransformationEstimationForGeneralizedICP
      • TransformationEstimationPointToPlane
      • TransformationEstimationPointToPoint
      • TukeyLoss
      • compute_fpfh_feature
      • correspondences_from_features
      • evaluate_registration
      • get_information_matrix_from_point_clouds
      • global_optimization
      • registration_colored_icp
      • registration_fgr_based_on_correspondence
      • registration_fgr_based_on_feature_matching
      • registration_generalized_icp
      • registration_icp
      • registration_ransac_based_on_correspondence
      • registration_ransac_based_on_feature_matching
  • cloudViewer.utility
    • DoubleVector
    • IntVector
    • Matrix
    • Matrix3dVector
    • Matrix4dVector
    • Range
    • ScalarField
    • Vector2dVector
    • Vector2iVector
    • Vector3dVector
    • Vector3iVector
    • Vector4iVector
    • VerbosityContextManager
    • VerbosityLevel
    • ccScalarField
    • get_verbosity_level
    • reset_print_function
    • set_verbosity_level
  • cloudViewer.visualization
    • ItemsView
    • KeysView
    • Material
    • MeshColorOption
    • MeshShadeOption
    • O3DVisualizer
    • PickedPoint
    • PointColorOption
    • RenderOption
    • ScalarProperties
    • SelectedIndex
    • SelectionPolygonVolume
    • TextureMaps
    • ValuesView
    • VectorProperties
    • ViewControl
    • Visualizer
    • VisualizerWithEditing
    • VisualizerWithKeyCallback
    • VisualizerWithVertexSelection
    • draw_geometries
    • draw_geometries_with_animation_callback
    • draw_geometries_with_custom_animation
    • draw_geometries_with_editing
    • draw_geometries_with_key_callbacks
    • draw_geometries_with_vertex_selection
    • read_selection_polygon_volume
    • ExternalVisualizer
    • draw
    • draw_plotly
    • draw_plotly_server
    • get_plotly_fig
    • to_mitsuba
    • app
      • run_viewer
    • gui
      • Application
      • Window
      • WindowBase
      • Dialog
      • SceneWidget
      • Widget
      • Horiz
      • Vert
      • CollapsableVert
      • ScrollableVert
      • StackedWidget
      • LayoutContext
      • Margins
      • Button
      • Checkbox
      • Combobox
      • ColorEdit
      • NumberEdit
      • RadioButton
      • Slider
      • TextEdit
      • ToggleSwitch
      • VectorEdit
      • Label
      • Label3D
      • ImageWidget
      • ListView
      • ProgressBar
      • TabControl
      • TreeView
      • CheckableTextTreeCell
      • ColormapTreeCell
      • LUTTreeCell
      • FileDialog
      • Menu
      • Theme
      • Color
      • FontDescription
      • FontStyle
      • KeyEvent
      • KeyModifier
      • KeyName
      • Layout1D
      • MouseButton
      • MouseEvent
      • Size
      • Rect
      • UIImage
      • VGrid
      • WidgetProxy
      • WidgetStack
    • rendering
      • Camera
      • CloudViewerScene
      • ColorGrading
      • Gradient
      • MaterialRecord
      • OffscreenRenderer
      • Renderer
      • Scene
      • TextureHandle
      • TriangleMeshModel
      • View
    • webrtc_server
      • call_http_api
      • disable_http_handshake
      • enable_webrtc
      • register_data_channel_message_callback
    • tensorboard_plugin.summary
      • BoundingBox3D
      • PluginDirectory
      • Summary
      • SummaryWriter
      • TensorProto
      • TensorShapeProto
      • add_3d
      • makedirs
      • masked_crc32c
      • partial

Python Examples

  • Camera
  • Core
  • Geometry
    • Geometry
    • Image
    • KD Tree
    • Octree
    • Point Cloud
    • Ray Casting
    • RGBD Image
    • Triangle Mesh
    • Voxel Grid
  • IO
  • Pipelines
  • Reconstruction
  • Utility
  • Visualization

C++ Examples

  • C++ Examples

C++ API

  • C++ documentation
    • Overview
    • Quick Start
    • Plugin System

Developer Guide

  • Contributing to ACloudViewer
  • Docker Development
  • CI/CD Pipeline

Resources

  • Changelog
  • Frequently Asked Questions
  • Getting Support
Back to top

cloudViewer.ml.torch.ops.knn_search#

cloudViewer.ml.torch.ops.knn_search(points, queries, k, points_row_splits, queries_row_splits, index_dtype=3, metric='L2', ignore_query_point=False, return_distances=False)[source]#

Computes the indices of k nearest neighbors.

This op computes the neighborhood for each query point and returns the indices of the neighbors. The output format is compatible with the radius_search and fixed_radius_search ops and supports returning less than k neighbors if there are less than k points or ignore_query_point is enabled and the queries and points arrays are the same point cloud. The following example shows the usual case where the outputs can be reshaped to a [num_queries, k] tensor:

import tensorflow as tf
import cloudViewer.ml.tf as ml3d

points = [
  [0.1,0.1,0.1],
  [0.5,0.5,0.5],
  [1.7,1.7,1.7],
  [1.8,1.8,1.8],
  [0.3,2.4,1.4]]

queries = [
    [1.0,1.0,1.0],
    [0.5,2.0,2.0],
    [0.5,2.1,2.2],
]

ans = ml3d.ops.knn_search(points, queries, k=2,
                    points_row_splits=[0,5],
                    queries_row_splits=[0,3],
                    return_distances=True)
# returns ans.neighbors_index      = [1, 2, 4, 2, 4, 2]
#         ans.neighbors_row_splits = [0, 2, 4, 6]
#         ans.neighbors_distance   = [0.75 , 1.47, 0.56, 1.62, 0.77, 1.85]
# Since there are more than k points and we do not ignore any points we can
# reshape the output to [num_queries, k] with
neighbors_index = tf.reshape(ans.neighbors_index, [3,2])
neighbors_distance = tf.reshape(ans.neighbors_distance, [3,2])


# or with pytorch
import torch
import cloudViewer.ml.torch as ml3d

points = torch.Tensor([
  [0.1,0.1,0.1],
  [0.5,0.5,0.5],
  [1.7,1.7,1.7],
  [1.8,1.8,1.8],
  [0.3,2.4,1.4]])

queries = torch.Tensor([
    [1.0,1.0,1.0],
    [0.5,2.0,2.0],
    [0.5,2.1,2.2],
])

radii = torch.Tensor([1.0,1.0,1.0])

ans = ml3d.ops.knn_search(points, queries, k=2,
                          points_row_splits=torch.LongTensor([0,5]),
                          queries_row_splits=torch.LongTensor([0,3]),
                          return_distances=True)
# returns ans.neighbors_index      = [1, 2, 4, 2, 4, 2]
#         ans.neighbors_row_splits = [0, 2, 4, 6]
#         ans.neighbors_distance   = [0.75 , 1.47, 0.56, 1.62, 0.77, 1.85]
# Since there are more than k points and we do not ignore any points we can
# reshape the output to [num_queries, k] with
neighbors_index = ans.neighbors_index.reshape(3,2)
neighbors_distance = ans.neighbors_distance.reshape(3,2)

metric: Either L1 or L2. Default is L2

ignore_query_point: If true the points that coincide with the center of the

search window will be ignored. This excludes the query point if queries and

points are the same point cloud.

return_distances: If True the distances for each neighbor will be returned in

the output tensor neighbors_distances. If False a zero length Tensor will be returned for neighbors_distances.

points: The 3D positions of the input points.

queries: The 3D positions of the query points.

k: The number of nearest neighbors to search.

points_row_splits: 1D vector with the row splits information if points is

batched. This vector is [0, num_points] if there is only 1 batch item.

queries_row_splits: 1D vector with the row splits information if queries is

batched. This vector is [0, num_queries] if there is only 1 batch item.

neighbors_index: The compact list of indices of the neighbors. The

corresponding query point can be inferred from the neighbor_count_prefix_sum vector. Neighbors for the same point are sorted with respect to the distance.

Note that there is no guarantee that there will be exactly k neighbors in some cases. These cases are:

  • There are less than k points.

  • ignore_query_point is True and there are multiple points with the same position.

neighbors_row_splits: The exclusive prefix sum of the neighbor count for the

query points including the total neighbor count as the last element. The size of this array is the number of queries + 1.

neighbors_distance: Stores the distance to each neighbor if return_distances

is True. The distances are squared only if metric is L2. This is a zero length Tensor if return_distances is False.

Next
cloudViewer.ml.torch.ops.nms
Previous
cloudViewer.ml.torch.ops.invert_neighbors_list
Copyright © 2018 - 2026, ACloudViewer Team
Made with Sphinx and @pradyunsg's Furo
On this page
  • cloudViewer.ml.torch.ops.knn_search
    • knn_search()