Welcome to toha_nearest_neighbor’s documentation!
Installation
Install with pip
:
$ pip3 install toha_nearest_neighbor
Api Reference
- toha_nearest_neighbor.brute_force_location(line_points: np.ndarray, point_cloud: np.ndarray, parallel=False) Tuple[np.ndarray, np.ndarray]
For every point in
point_cloud
, find it’s nearest neighbor inline_points
using a brute-force algorithm. Returns a tuple of the closestline_points
locations and their associated distances.- Parameters:
line_points (np.ndarray) – a 2D numpy array with each point being described by a row, and columns of coordinates of that point. Array should be in the shape
(NUM_LINE_POINTS, POINT DIMENSION)
point_cloud (np.ndarray) – a 2D numpy array with each point being described by a row, and columns of coordinates of that point. Array should be in the shape
(NUM_POINT_CLOUD_POINTS, POINT DIMENSION)
parallel (bool) – enable parallel processing for the dataset. If you have more than 2,000 line points and 2,000 point cloud points this may be useful.
this function returns a
(NUM_POINT_CLOUD_POINTS, POINT DIMENSION)
shaped array of the points where eachi
th row of the returned array is a row ofline_points
that is closest to thei
th row ofpoint_cloud
Example:
import toha_nearest_neighbor import numpy as np line_points = np.array( [ [0.0, 0.0], [1.0, 1.0], [2.0, 2.0], ] ) point_cloud = np.array( [ [0.1, -0.1], #closest to the 0-th index of line_points rows [2.2, 3.0], # closest to the 2-nd index of line_points rows ] ) closest_line_points, distances = toha_nearest_neighbor.brute_force(line_points, point_cloud) # [[0. 0.] # [2. 2.]] print(closest_line_points) # [0.02 1.04] print(distances)
- toha_nearest_neighbor.brute_force_index(line_points: np.ndarray, point_cloud: np.ndarray, parallel=False) Tuple[np.ndarray, np.ndarray]
For every point in
point_cloud
, find it’s nearest neighbor inline_points
using a brute-force algorithm. Returns a tuple of indicies of the closestline_points
rows and their associated distances.- Parameters:
line_points (np.ndarray) – a 2D numpy array with each point being described by a row, and columns of coordinates of that point. Array should be in the shape
(NUM_LINE_POINTS, POINT DIMENSION)
point_cloud (np.ndarray) – a 2D numpy array with each point being described by a row, and columns of coordinates of that point. Array should be in the shape
(NUM_POINT_CLOUD_POINTS, POINT DIMENSION)
parallel (bool) – enable parallel processing for the dataset. If you have more than 2,000 line points and 2,000 point cloud points this may be useful.
Example:
import toha_nearest_neighbor import numpy as np line_points = np.array( [ [0.0, 0.0], [1.0, 1.0], [2.0, 2.0], ] ) point_cloud = np.array( [ [0.1, -0.1], #closest to the 0-th index of line_points rows [2.2, 3.0], # closest to the 2-nd index of line_points rows ] ) indicies, distances = toha_nearest_neighbor.brute_force_index(line_points, point_cloud) # [0 2] print(indicies) # [0.02 1.04] print(distances)
- toha_nearest_neighbor.kd_tree_location(line_points: np.ndarray, point_cloud: np.ndarray, parallel=False) Tuple[np.ndarray, np.ndarray]
For every point in
point_cloud
, find it’s nearest neighbor inline_points
using a brute-force algorithm. Returns a tuple of the closestline_points
locations and their associated distances.- Parameters:
line_points (np.ndarray) – a 2D numpy array with each point being described by a row, and columns of coordinates of that point. Array should be in the shape
(NUM_LINE_POINTS, POINT DIMENSION)
point_cloud (np.ndarray) – a 2D numpy array with each point being described by a row, and columns of coordinates of that point. Array should be in the shape
(NUM_POINT_CLOUD_POINTS, POINT DIMENSION)
parallel (bool) – enable parallel processing for the dataset. If you have more than 2,000 line points and 2,000 point cloud points this may be useful.
this function returns a
(NUM_POINT_CLOUD_POINTS, POINT DIMENSION)
shaped array of the points where eachi
th row of the returned array is a row ofline_points
that is closest to thei
th row ofpoint_cloud
Example:
import toha_nearest_neighbor import numpy as np line_points = np.array( [ [0.0, 0.0], [1.0, 1.0], [2.0, 2.0], ] ) point_cloud = np.array( [ [0.1, -0.1], #closest to the 0-th index of line_points rows [2.2, 3.0], # closest to the 2-nd index of line_points rows ] ) (closest_line_points, distances) = toha_nearest_neighbor.kd_tree_location(line_points, point_cloud, parallel = True) # [[0. 0.] # [2. 2.]] print(closest_line_points) # [0.02 1.04] print(distances)
- toha_nearest_neighbor.kd_tree_index(line_points: np.ndarray, point_cloud: np.ndarray, parallel=False) Tuple[np.ndarray, np.ndarray]
For every point in
point_cloud
, find it’s nearest neighbor inline_points
using a kd-tree algorithm. Returns a tuple of indicies of the closestline_points
rows and their associated distances.- Parameters:
line_points (np.ndarray) – a 2D numpy array with each point being described by a row, and columns of coordinates of that point. Array should be in the shape
(NUM_LINE_POINTS, POINT DIMENSION)
point_cloud (np.ndarray) – a 2D numpy array with each point being described by a row, and columns of coordinates of that point. Array should be in the shape
(NUM_POINT_CLOUD_POINTS, POINT DIMENSION)
parallel (bool) – enable parallel processing for the dataset. If you have more than 2,000 line points and 2,000 point cloud points this may be useful.
this function returns a
(NUM_POINT_CLOUD_POINTS, POINT DIMENSION)
shaped array of the points where eachi
th row of the returned array is a row ofline_points
that is closest to thei
th row ofpoint_cloud
Example:
import toha_nearest_neighbor import numpy as np line_points = np.array( [ [0.0, 0.0], [1.0, 1.0], [2.0, 2.0], ] ) point_cloud = np.array( [ [0.1, -0.1], #closest to the 0-th index of line_points rows [2.2, 3.0], # closest to the 2-nd index of line_points rows ] ) indicies, distances = toha_nearest_neighbor.kd_tree_index(line_points, point_cloud, parallel = True) # [0 2] print(indicies) # [0.02 1.04] print(distances)