Question

  • I have a 3-D geometrical shape which I have to convert into a point cloud.
  • The resultant point cloud can be considered equivalent to a point cloud output from a Laser Scan of the object.
  • No mesh generation is neeeded
  • The points generated may be evenly spaced, or maybe just randomly spaced - doesn't matter
  • The 3-D shape can be provided in the form of a 3-D mathematical formula
  • This has to be done using MATLAB
Was it helpful?

Solution

It's difficult to answer without an example but it sounds like you just want to perform a montecarlo simulation?

Lets say your shape is defined by the function f and that you have X, Y limits stored in two element vector e.g. xlim = [-10 10] i.e. all possible x values of this shape lie between x = -10 and x = 10 then I would suggest that you make f return some sort of error code if there is no value for a specific x-y pair. I'm going to assume that will be NaN. So f(x,y) is a function you are writing that either returns a z if it can or NaN if it can't

n= 10000;
counter  = 1;
shape = nan(n, 3)
while counter < n
   x = rand*diff(xlim) + mean(xlmin);
   y = rand*diff(ylim) + mean(ylim);
   z = f(x,y)
   if ~isnan(z)
      shape(counter, :) = [x, y, z];
      counter = counter + 1    
   end
end

So the above code will generate 10000 (non unique, but that's easily adapted for) points randomly sample across your shape.

Now after typing this I realise that perhaps your shape is actually not all that big and maybe you can uniformly sample it rather than randomly:

for x = xlim(1):xstep:xlim(2)
   for y = ylim(1):ystep:ylim(2)
       shape(counter, :) = [x, y, f(x,y)];
   end
end 

or if you write f to be vectorized (preferable)

shape = [(xlim(1):xstep:xlim(2))', (ylim(1):ystep:ylim(2))', f(xlim(1):xstep:xlim(2), ylim(1):ystep:ylim(2));

and then either way

shape(isnan(shape(:, 3), :) = []; %remove the points that fell outside the shape

OTHER TIPS

Here is the code to create a Cloud image with a Depth image from a PrimeSense Camera.

The input/Ouput of this function :

-inputs
 depth         -depth map
 topleft       -topleft coordinates of the segmented image in the whole image

-outputs
 pclouds       -3d point clouds

MatLab code :

depth = double(depth);
% Size of camera image
center = [320 240];
[imh, imw] = size(depth);
constant = 570.3;

% convert depth image to 3d point clouds
pclouds = zeros(imh,imw,3);
xgrid = ones(imh,1)*(1:imw) + (topleft(1)-1) - center(1);
ygrid = (1:imh)'*ones(1,imw) + (topleft(2)-1) - center(2);
pclouds(:,:,1) = xgrid.*depth/constant;
pclouds(:,:,2) = ygrid.*depth/constant;
pclouds(:,:,3) = depth;
distance = sqrt(sum(pclouds.^2,3));

Edit : This source is from this current article http://www.cs.washington.edu/rgbd-dataset/software.html

You can find some other Cloud function in MatLab and C++ that can be interest you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top