I used plot3. when I try to rotate the 3D image, it is too slow to rotate for each time.

hFig = figure('name','3D Plotting_Solve_Pyramid','numbertitle','off'); hold on;
set(gcf,'Renderer','OpenGL'); % might improve performance
hAxes = gca;
for row = 1:hightl
for col = 1:4:widthl
objcolor = double(I2(row,col,:))./255.0;
if objectpoint(row,col,3) >= -2.0 %&& (sum(objcolor)>0.3)
plot3(hAxes, objectpoint(row,col,1), objectpoint(row,col,2), objectpoint(row,col,3), '.', 'MarkerEdgeColor',objcolor);
end
end
end
%Set up the view.
xlabel(' X axis');
ylabel(' Y axis');
zlabel(' Z axis');
grid on;
cameratoolbar show;
axis vis3d;
axis equal;

Answers (1)

I'm guessing that widthl and hightl are fairly large. This means that you're creating a large number of objects which are each drawing a single point. That's not a very efficient way to do it. You'll be much better off batching them up into a single object. A modern GPU is optimized for drawing large batches of geometry, not for drawing large numbers of tiny batches.
I discussed that in quite a bit of detail in this blog post and this blog post.
It looks like it'd actually be quite simple in this case. It's probably something like:
x = objectpoint(:,:,1);
y = objectpoint(:,:,2);
z = objectpoint(:,:,3);
r = double(x) / 255;
g = double(y) / 255;
b = double(z) / 255;
mask = (z(:)>=-2) & (r(:)+g(:)+b(:) > .3);
scatter3(hAxes,x(mask),y(mask),z(mask),[],[r(mask), g(mask), b(mask)],'.')
On my system, with a Quadro K600 on R2015a, that runs at over 10 million markers per second. You could probably do better with a bit of tweaking, but that's about 120 frames per second for this image:

5 Comments

I used your code to run my data but nothing show up in the figure.
There is an error.
" Error using scatter3 (line 45) Wrong number of input arguments. "
I'm not sure. Here's the entire piece of code I ran to get that picture:
close all
clear all
objectpoint = imread('ngc6543a.jpg');
hAxes=gca
x = objectpoint(:,:,1);
y = objectpoint(:,:,2);
z = objectpoint(:,:,3);
r = double(x) / 255;
g = double(y) / 255;
b = double(z) / 255;
mask = (z(:)>=-2) & (r(:)+g(:)+b(:) > .3);
scatter3(hAxes,x(mask),y(mask),z(mask),[], ...
[r(mask), g(mask), b(mask)],'.')
There was a typo. I had x,y,z in the color field instead of r,g,b. I don't think that would have resulted in the error you have though.
I corrected my code. Now I can ran my code to get the correct figure.
Thanks
From scatter3(hAxes,x(mask),y(mask),z(mask),[], ... [r(mask), g(mask), b(mask)],'.')
What does [] mean in this command?
"If S is empty, then the default size of 36 points squared is used."

Sign in to comment.

Categories

Find more on Graphics Performance in Help Center and File Exchange

Asked:

on 20 Aug 2015

Commented:

on 22 Aug 2015

Community Treasure Hunt

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

Start Hunting!