"Philipp " <email@example.com> wrote in message <firstname.lastname@example.org>... > Hallo together... > I have some performance problems with my code; I've read of vectorizisation, jit or mex files - but I don't know exctly what to do and how to spped uop this thing. > I'm tring to find planes within a point cloud - therefore I calculated normals, sorted the points due to normal direction and then I want to region grow in this similar-direction point sets to get rid of outliners. And this last part of the algorithm is very slow: > > function [regionSet] = growOneRegion(index,range,points) > > %I build a kd-tree for the points > tree = kd_buildtree(points,0); > > %set a initial seed index > openPoints = ; > openPoints(1,1) = index; > > regionSet = ; > while(~isempty(openPoints)) > > element = openPoints(1,1); > openPoints(1,:) = ; > thePoint = points(element,:); > > %ssearch for neighbours > try > [index_vals,dist_vals,vector_vals] = kd_rangequery(tree,thePoint,range); > catch exception > index_vals = ; > end > > for j=1:size(index_vals,1) > > idx = index_vals(j,1); > [R,C] = find(openPoints==idx); > [R1,C1] = find(regionSet==idx); > > %add them to the queue > if(isempty(R) && isempty(R1)) > openPoints = [openPoints;idx]; > end > end > > regionSet = [regionSet;element]; > regionSet = unique(regionSet); > > sizer = size(regionSet,1); > sizeA = size(openPoints,1); > disp('region sets'); > disp(sizer); > > disp('open points'); > disp(sizeA); > end > > Hope anybody can help me... > Best regards
Just after a quick glance, I have a couple of comments.
Statements like: > openPoints = [openPoints;idx]; > regionSet = [regionSet;element]; that dynamically grow vectors (or matracies or arrays) are going to slow your code down considerably. Try pre-allocating them, if possible. Search this newsgroup, the Mathworks site, or the MATLAB FAQ at: <<http://matlab.wikia.com/wiki/FAQ>> for ways to do this.
Unless OpenPoints is a persistent variable, I'm not sure why it is necessary to follow: > openPoints = ; with > openPoints(1,1) = index;