I'm working with a set of planes and a set of 3D points.
I want to find the closest plane to each one of the points in my set.
Right now I compute the disance of one point to each of the planes in my plane set and decide wich one is the closest, then I repeat the same process for every point in my point set. This works fine, but the computational cost depends a lot of the number of planes I have, so if I add more planes (usually I work with more than 500 planes) the processing time increase a lot.
Is there a more effcient way to know the closest plane to a point without having to compute the distance to each of the planes?
I'm implementing this using C++ and VTK libraries
The planes are precomputed using information from a 3D tracker and the points are defined by the user.
This block of code computes the point coordinates (voxel) and calls DistanceToPlane to calculate the distance from the voxel to all the planes. After running this the vnl_vector distances should have the closest plane to each point in the poin cloud.
vnl_vector<double> distances;
for(int i=0; i<volumeSize[0]; i++){
std::cout<<"."<<std::flush;
for(int j=0; j<volumeSize[1]; j++){
for(int k=0; k<volumeSize[2]; k++){
double voxel[3];
voxel[0] = i*scale[0]*resolution + volumeOrigin[0];
voxel[1] = j*scale[1]*resolution + volumeOrigin[1];
voxel[2] = k*scale[1]*resolution + volumeOrigin[2];
double distance = maxDistance;
for(int plane=0; plane<volumeImageStack.size(); plane++){
double d = imagePlaneStack.at(plane)->DistanceToPlane(voxel);
if(d<distance)
distance = d;
}
distances.push_back(distance);
}
The DistanceToPlane() function computes the distance from a point to one plane, this function is called N time (N = number of planes) for each point.This function is implemented in the VTK library.
Thanks