Layering SortMethod for 3D Plotting

9 views (last 30 days)
Hello,
I'm rendering 3D point clouds on to the screen, and attempting to overlay feature points in Matlab R2014b. I end up with the following:
h = showPointCloud(pc(:,:,[1:3]), pc(:,:,[4:6]));
hold on;
plot3(m(1,:),m(2,:),m(3,:),'o','MarkerSize',8,'Color',[0 0 0],'MarkerFaceColor',[1 1 0]); % display 3D plot
hold off;
h.SortMethod = 'depth'; % or alternatively 'childorder'
When I use 'depth' I see the point cloud well, but the yellow markers get embedded.
When I use 'childorder' the depth order for the point cloud becomes buggy (notice how the Mickey doll is partially behind the monitor).
Other attempts:
  • It doesn't look like axes can be parented;
  • uistack seems to apply to GUI controls;
  • and I'm not sure if projecting the yellow markers to 2D would handle live updating on scene rotation
Thoughts? Thanks in advance!

Accepted Answer

Mike Garrity
Mike Garrity on 29 May 2015
One option to consider is to place your feature points in a separate axes. The contents of different axes are drawn with childorder, even if the contents of each axes are drawn with depthsort.
It's a bit tricky though. Here's a really simplified version:
%%Make a "point cloud"
x = randn(1,1000);
y = randn(1,1000);
z = randn(1,1000);
scatter3(x,y,z,'.')
%%Create overlay
a1 = gca;
a2 = axes('Position',a1.Position, ...
'CameraPosition',a1.CameraPosition,'CameraTarget',a1.CameraTarget, ...
'XLim',a1.XLim,'YLim',a1.YLim,'ZLim',a1.ZLim);
scatter3(a2,x(12),y(12),z(12),120,'ro','filled')
a2.Visible = 'off';
a2.HandleVisibility = 'off';
linkprop([a1, a2], {'CameraPosition','CameraTarget','CameraUpVector', ...
'XLim','YLim','ZLim'})
So what's going on here? We're putting the axes a2 on top of a1, the axes that contains our point cloud. Then we're hiding all of the decorations of a2, so it looks like the children of a2 are just drawing in a1. The trick is that we need to keep two axes in synch. The simplest tool for that is the linkprop command, but it can be a little tricky to work with, and I probably missed some details there.
The other trick here is to set HandleVisibility to off on a2. The reason for that is to keep things like the rotate3d tool from seeing it. The HandleVisibility property lets you hide this axes from those types of tools.
  1 Comment
Erika Harrison
Erika Harrison on 29 May 2015
Thanks so much Mike! There was an issue on the second set of points having their aspect ratios change, but I edited your axes and linkprop to include 'Position', 'CameraViewAngle', 'DataAspectRatio', 'PlotBoxAspectRatio' and 'View' as follows:
a2 = axes('Position',a1.Position, 'CameraPosition',a1.CameraPosition, ...
'CameraTarget',a1.CameraTarget,'CameraViewAngle', a1.CameraViewAngle, ...
'PlotBoxAspectRatio', a1.PlotBoxAspectRatio, 'DataAspectRatio', a1.DataAspectRatio, ...
'View', a1.View, 'XLim',a1.XLim,'YLim',a1.YLim,'ZLim',a1.ZLim);
linkprop([a1, a2], {'Position','CameraPosition','CameraTarget', ...
'CameraViewAngle','CameraUpVector', 'PlotBoxAspectRatio', ...
'DataAspectRatio', 'View','XLim','YLim','ZLim'});
All the extra properties may be overkill, but it'll maintain consistency. Thanks again!
Erika :)

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!