Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(plot3): speed up + cube demo #1353

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- `plot`: speed optimization: `tic();plot(rand(300,300), rand(300,300));toc()`
- `plot`, `plot3` : speed optimization: `tic();plot(rand(300,300), rand(300,300));toc()`
- fmtlib 11.1.3

## 1.12.0 (2025-02-16)
Expand Down
62 changes: 62 additions & 0 deletions modules/graphics/examples/cube/demo_cube.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
%=============================================================================
% Copyright (c) 2016-present Allan CORNET (Nelson)
%=============================================================================
% This file is part of the Nelson.
%=============================================================================
% LICENCE_BLOCK_BEGIN
% SPDX-License-Identifier: LGPL-3.0-or-later
% LICENCE_BLOCK_END
%=============================================================================
% Define cube vertices
vertices = [
-1 -1 -1;
-1 -1 1;
-1 1 -1;
-1 1 1;
1 -1 -1;
1 -1 1;
1 1 -1;
1 1 1
];

% Define cube edges
edges = [
1 2; 1 3; 1 5;
2 4; 2 6;
3 4; 3 7;
4 8;
5 6; 5 7;
6 8;
7 8
];

% Generate random lines inside the cube
numLines = 1000; % Increased number of lines
randLines = -1 + 2 * rand(numLines, 6); % Random points in range [-1,1]
colors = rand(numLines, 3); % Generate random colors

% Create figure
f = figure('Visible', 'off');
axis equal;
axis off
grid on;
view(3);
hold on;

% Plot cube edges
for i = 1:size(edges, 1)
plot3(vertices(edges(i, :), 1), vertices(edges(i, :), 2), vertices(edges(i, :), 3), 'k', 'LineWidth', 1);
end

% Plot random lines inside the cube with multiple colors
plot3([randLines(:,1), randLines(:,4)]', ...
[randLines(:,2), randLines(:,5)]', ...
[randLines(:,3), randLines(:,6)]', 'LineWidth', 0.5);
f.Visible = 'on';

% Rotate the cube
for angle = 1:3600
if (isgraphics(f))
view(angle, 30);
end
end
4 changes: 3 additions & 1 deletion modules/graphics/functions/plot.m
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@
end
end
axes(saveca);
h.Visible='on';
if isempty(find(strcmp(propertiesList, 'Visible')))
h.Visible = 'on';
end
if (nargout > 0)
varargout{1} = h;
end
Expand Down
5 changes: 4 additions & 1 deletion modules/graphics/functions/plot3.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@
view(3);
end
axes(backupCurrentAxis);
if isempty(find(strcmp(propertiesList, 'Visible')))
h.Visible = 'on';
end
if (nargout > 0)
varargout{1} = h;
end
Expand Down Expand Up @@ -131,6 +134,6 @@
if (~any(strcmp(lineProperties, 'LineStyle')))
lineProperties = [lineProperties, {'LineStyle', lineStyle}];
end
hl = __line__('Parent', go, 'XData', x, 'YData', y, 'ZData', z, 'Color', color, lineProperties{:});
hl = __line__('Parent', go, 'XData', x, 'YData', y, 'ZData', z, 'Color', color, 'Visible', 'off', lineProperties{:});
end
%=============================================================================
1 change: 1 addition & 0 deletions modules/graphics/tests/test_examples.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
run([examples_directory, 'nefertiti-mask/nefertiti_mask.m']);
run([examples_directory, 'stanford-bunny/stanford_bunny.m']);
run([examples_directory, 'movie/demo_movie.m']);
run([examples_directory, 'cube/demo_cube.m']);
%=============================================================================
2 changes: 1 addition & 1 deletion modules/gui/src/cpp/MainGuiObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ DestroyMainGuiObject(void* term)
delete nlsTerm;
nlsTerm = nullptr;
}
NelSonQtApp->deleteLater();
delete NelSonQtApp;
NelSonQtApp = nullptr;
}
DestroyConsole();
Expand Down
Loading