%CNNSEARCH Find the first nearest neighbor.
% [INDICES] = CNNSEARCH(CLOUD,QUERY,SEARCHMETHOD,...) finds the first
% nearest neighbor of each point of QUERY in CLOUD, where both input
% arguments are three dimensional point clouds. Indices of matches are
% stored in INDICES. If there is no match, the corresponding entry in
% INDICES is 0.
%
% SEARCHMETHOD can be one of the following:
% 1. 'brute' Brute force search.
% 2. 'hash' Search by hashing. A 3D grid is used for indexing.
% Grid size can be specified by SEARCHDEPTH.
% 3. 'octree' An octree is made use of for searching. In order to
% avoid costly construction of unnecessary leaves, one
% can limit the depth SEARCHDEPTH, and force the creation
% of leaves when the number of points fall below a
% predefined value LEAFSIZELIMITER.
% 4. 'kdtree' A kdtree is made use of for searching. In order to
% avoid costly construction of unnecessary leaves, one
% can limit the depth SEARCHDEPTH and LEAFSIZELIMITER as
% in (3).
%
% [...] = CNNSEARCH(...,SEARCHMETHOD,RADIUS,SEARCHDEPTH,LEAFSIZELIMITER)
% Default values for the optional parameters RADIUS, SEARCHDEPTH and
% LEAFSIZELIMITER are Inf, 1 and 1000, respectively.
%
% Note that this function works only with single-precision arrays and
% uses Euclidean distance metric for comparisons.
%
% Examples:
%
% A = single(rand(70*1000,3));
% B = single(0.7 + rand(10*1000,3));
% radius = 0.22;
% bdx = cnnsearch(A,B,'brute',radius);
% hdx = cnnsearch(A,B,'hash', radius,100);
% odx = cnnsearch(A,B,'octree',radius,10,1000);
% kdx = cnnsearch(A,B,'kdtree',radius,10);
%
% hold on
% i = bdx(bdx>0);
% plot3(A(:,1),A(:,2),A(:,3),'g.');
% plot3(B(:,1),B(:,2),B(:,3),'y.');
% plot3(A(i,1),A(i,2),A(i,3),'ro');
% axis equal
%
% See also KNNSEARCH
%
% Copyright 2010 This file and its content belong to Ulas Yilmaz.
% You are welcome to use it for non-commercial purposes, such as
% student projects, research and personal interest. However,
% you are not allowed to use it for commercial purposes, without
% an explicit written and signed license agreement with the owner.
% Contact info at http://www.cv.tu-berlin.de
% Berlin University of Technology Germany
% Last Modification: 10.08.2010
%
% function [indices] = cnnsearch(cloud,query,searchmethod,varargin)
% end