Skip to content

Commit

Permalink
meshes3d: rename meshComplement.m to reverseMeshFaceOrientation.m
Browse files Browse the repository at this point in the history
  • Loading branch information
dlegland committed Jul 15, 2024
1 parent b321d4e commit 9e7ab8e
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
function varargout = meshComplement(varargin)
%MESHCOMPLEMENT Reverse the normal of each face in the mesh.
%
% Note: deprecated, use reverseMeshFaceOrientation instead.
%
% [V2, F2] = meshComplement(V, F)
%
% Example
Expand All @@ -22,6 +24,10 @@
% Created: 2020-01-22, using Matlab 9.7.0.1247435 (R2019b) Update 2
% Copyright 2020-2024 INRAE - BIA Research Unit - BIBS Platform (Nantes)

warning('matgeom:meshes3d:deprecated', ...
'meshComplement is deprecated, use reverseMeshFaceOrientation instead');


% extract mesh data
mesh = parseMeshData(varargin{:});
faces = mesh.faces;
Expand Down
44 changes: 44 additions & 0 deletions matGeom/meshes3d/reverseMeshFaceOrientation.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
function varargout = reverseMeshFaceOrientation(varargin)
%REVERSEMESHFACEORIENTATION Reverse the normal of each face in the mesh.
%
% [V2, F2] = reverseMeshFaceOrientation(V, F)
% Computes new face vertex indices such that the volume enclosed by the
% mesh becomes the opposite of that of the original mesh. The vertex
% position of the two meshes are the same.
%
% Example
% [v, f] = createOctahedron;
% meshVolume(v, f)
% ans =
% 1.3333
% [v2, f2] = reverseMeshFaceOrientation(v, f);
% meshVolume(v2, f2)
% ans =
% -1.3333
%
% See also
% meshes3d, meshVolume
%

% ------
% Author: David Legland
% e-mail: david.legland@inrae.fr
% INRAE - BIA Research Unit - BIBS Platform (Nantes)
% Created: 2024-07-15, using Matlab 24.1.0.2628055 (R2024a) Update 4
% Copyright 2024 INRAE.

% extract mesh data
mesh = parseMeshData(varargin{:});
faces = mesh.faces;

% iterate over faces to invert order of vertex indices
if isnumeric(faces)
faces = faces(:, [1 end:-1:2]);
else
for i = 1:size(faces, 1)
faces{i} = faces{i}([1 end:-1:2]);
end
end

% create new mesh data
varargout = formatMeshOutput(nargout, mesh.vertices, faces);

0 comments on commit 9e7ab8e

Please sign in to comment.