bugGNU Octave - Bugs: bug #65422, Octave patch does not plot patch...

 
 

bug #65422: Octave patch does not plot patch if points create a straight line

Submitter:  Liang Tang <lt1234>
Submitted:  Wed 06 Mar 2024 04:14:04 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Confirmed Assigned to:  None
Originator Name:  lt1234 Open/Closed:  * Open
Release:  * stable Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Wed 20 Mar 2024 01:05:58 PM UTC, comment #6: 

The observation was that, for cases 3 and 4, there was very little difference in time.  But, there was significant time save for case 1, compared to 2.  I can move this discussion away.  Thanks. 

Visually, I have not seen the performance from tic/toc numbers you showed.  (I did similar also but not shown in the example.)  patch was displayed once the command was issued.  line ran for some time dependent on n.  I don't know if tic/toc represents the time for graphic handling.

I have to run on software rendering whenever patch is present.  In the other patch bug report, I had indicated that crash or  plot window freeze can be an issue. Os is win10.   I also had difficulties in consistently reproducing these issues.  

When the number of patches is in the 50k-150k range, even with a single facecolor for all patches, 8.4.0 with hardware rendering crashed.  But crash is not what this report is for.  I just provide for your info only.  


Liang Tang <lt1234>
Wed 20 Mar 2024 12:37:25 PM UTC, comment #5: 

IIUC, you are comparing the time that it takes to create a single patch object to the time it takes to create 1001 line objects.
Obviously, creating 1001 line objects will take longer.

If you compare the time for creating 1 patch object to the time for creating 1 line object, the line object is faster here.
E.g., after having run your example:

>> tic, h_tri=patch('Vertices',     vert(:,2:end),'Faces', faces,'FaceColor',[1 0 0],'EdgeColor', [1 0 0],'FaceAlpha', 0.2, 'LineWidth', 1 ); toc
Elapsed time is 0.0061202 seconds.
>> tic, l=line(xd(:),yd(:),zd(:), 'color', 'r'); toc
Elapsed time is 0.00542593 seconds.


Anyway, this discussion is off-topic to this report. Please, ask questions about how to use Octave on the discourse forum:
https://octave.discourse.group/

Markus Mützel <mmuetzel>
Group administrator
Wed 20 Mar 2024 10:41:00 AM UTC, comment #4: 

I tried to find a workaround.  But it did not work.  Line is significantly slower than patch.  Thanks. 

This example shows the elapsed time to draw similar number of line segments using patch and line are very different. Patch is faster.  The performance of using all lines in a single line command does not show much improvement over drawing the many lines one-by-one. 

% line
n=5000; n=1000; % adjust as needed
tt=reshape(linspace(0, 2*pi, n), [],1); rr=100;
x=rr*sin(tt); y=rr*cos(tt); z=sin(tt);
x_ave=mean(x);y_ave=mean(y); z_ave=mean(z);

x=[x;x_ave]; y=[y;y_ave]; z=[z;z_ave];

figure('name', '1 All-in-one.  Really fast'); axs=axes; hold on; %plot3(x,y,z); hold on;
faces=[ (n+1)*ones(n-1,1) reshape([1:1:n-1],[],1)  reshape([2:1:n],[],1)];
vert =[[1:size(x,1)]'  x y z];
h_tri=patch('Vertices',     vert(:,2:end),'Faces', faces,'FaceColor',[1 0 0],'EdgeColor', [1 0 0],'FaceAlpha', 0.2, 'LineWidth', 1 ); whos h_tri % single handle

figure('name', '2 One-by-one.  Really slow, expected.'); axs=axes;  hold on; % plot3(x,y,z);
vert =[[1:size(x,1)]'  x y z];
for ii=1:n-1,
    faces=[ (n+1) ii  ii+1];
    h_tri=patch('Vertices',     vert(:,2:end),'Faces', faces,'FaceColor',[1 0 0],'EdgeColor', [1 0 0],'FaceAlpha', 0.2, 'LineWidth', 1 ); % mutiple handles
end; whos h_tri

% number of line segments is about 50% of patch.

figure('name', '3 all lines in one is slow, surprisingly.'); plot3(x,y,z); hold on;
xd=[repmat(x_ave, 1, size(x,1)); reshape(x,1,[])];yd=[repmat(y_ave, 1, size(x,1)); reshape(y,1,[])];zd=[repmat(z_ave, 1, size(x,1)); reshape(z,1,[])];
l=line(xd,yd,zd, 'color', 'r'); whos l  % multiple handles

figure('name', '4 separated lines is also slow, as expected.'); axs=axes; plot3(x,y,z); hold on;
for ii=1:n, ll(ii)=line( [x_ave;x(ii)], [y_ave; y(ii)], [z_ave; z(ii)], 'color', 'r'); end; whos ll  % multiple handles



Liang Tang <lt1234>
Wed 20 Mar 2024 12:45:43 AM UTC, comment #3: 

I think this may be an OpenGL issue with co-linear patch points.  The patch object is created correctly in Octave and has the right face, vertex, color properties.

Rik <rik5>
Group administrator
Wed 06 Mar 2024 04:50:33 PM UTC, comment #2: 

confirming that for both examples in comment #0 and comment #1, Matlab 2023b produces a straight line plot while octave 9.0.91 produces an empty axis.  the patch function does return a handle to a patch object with all the pieces you'd expect to be there, it just doesn't render. updating release to stable.

Nicholas Jankowski <nrjank>
Group Member
Wed 06 Mar 2024 04:42:10 PM UTC, comment #1: 

Just an update.  The "two points" in the title and comment #1 is not correct. 

As long as the patch describes a straight line, Octave patch does not plot or warn/error.

pts=[0 0 0;1 1 1; 2 2 2]; tri=[1 2 3]
figure; patch('Vertices', pts,'Faces', tri, 'EdgeColor', 'k');

Liang Tang <lt1234>
Wed 06 Mar 2024 04:14:04 PM UTC, original submission:  

Hi,

Octave patch does not plot line defined by two points.  Octave does not draw the patch and does not return an error.  The plot is silently empty. Thanks.

Replacing a single patch with a for-loop with many individual line commands is very slow, as you would expect.

% example

pts=[0 0 0;1 1 1]; tri=[1 2]
figure; patch('Vertices', pts,'Faces', tri, 'EdgeColor', 'k');

Liang Tang <lt1234>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by mmuetzel (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by nrjank (Posted a comment)
  • -email is unavailable- added by lt1234 (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2024-03-08 nrjank Operating SystemMicrosoft Windows Any
    2024-03-06 nrjank SummaryOctave patch does not plot patch defined by two points Octave patch does not plot patch if points create a straight line
    2024-03-06 nrjank StatusNone Confirmed
        Release8.2.0 stable

    Back to the top

    Powered by Savane 3.13-461b.
    Corresponding source code