-
Notifications
You must be signed in to change notification settings - Fork 326
/
compute_dual_graph.m
44 lines (38 loc) · 1.12 KB
/
compute_dual_graph.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
function [A,vertex1] = compute_dual_graph(face,vertex)
% compute_dual_graph - compute the dual graph of a given triangulation
%
% [A,vertex1] = compute_dual_graph(face,vertex);
%
% 'A' is the adjacency matrix of the abstract dual graph
% (recall that this graph link togeter adjacent faces
% in the triangulation).
%
% 'vertex' is optional, and if given, the position of the vertex
% of the dual graph (contained in 'vertex1') will
% the centroids of the face's vertex positions.
%
% Copyright (c) 2004 Gabriel PeyrŽ
if nargin<2
vertex = [];
end
[vertex,face] = check_face_vertex(vertex,face);
nface = size(face,2);
nvert = max(max(face));
fring = compute_face_ring(face);
% compute the center of the faces
if nargin>1
vertex1 = [ ...
sum(reshape(vertex(1,face),[3 nface]), 1)/3; ...
sum(reshape(vertex(2,face),[3 nface]), 1)/3; ...
sum(reshape(vertex(3,face),[3 nface]), 1)/3 ];
else
vertex1 = [];
end
A = zeros(nface,nface);
for i=1:nface
ring = fring{i};
for j=1:length(ring)
A(i,ring(j)) = 1;
A(ring(j),i) = 1;
end
end