Skip to content

Commit d2896be

Browse files
committed
merge metch toolbox with iso2mesh
1 parent b9fbbf7 commit d2896be

13 files changed

+2443
-1
lines changed

affinemap.m

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
function [A,b]=affinemap(pfrom,pto)
2+
% [A,b]=affinemap(pfrom,pto)
3+
%
4+
% calculate an affine transform (A matrix and b vector) to map n
5+
% vertices from one space to the other using least square solutions
6+
%
7+
% author: Qianqian Fang <q.fang at neu.edu>
8+
% date: 12/12/2008
9+
%
10+
% parameters:
11+
% pfrom: nx3 matrix, each row is a 3d point in original space
12+
% pto: nx3 matrix, each row is a 3d point in the mapped space
13+
%
14+
% outputs:
15+
% A: 3x3 matrix, the calculated affine A matrix
16+
% b: 3x1 vector, the calculated affine b vector
17+
%
18+
% the solution will satisfy the following equation: A*pfrom'+b=pto
19+
%
20+
% Please find more information at http://iso2mesh.sf.net/cgi-bin/index.cgi?metch
21+
%
22+
% this function is part of "metch" toobox, see COPYING for license
23+
24+
bsubmat=eye(3);
25+
ptnum=size(pfrom,1);
26+
if(size(pto,1)~=ptnum)
27+
error('two inputs should have the same size');
28+
end
29+
amat=zeros(ptnum*3,9);
30+
for i=1:ptnum
31+
amat(i*3-2:i*3,:)=kron(bsubmat,pfrom(i,:));
32+
end
33+
amat=[amat,repmat(bsubmat,ptnum,1)];
34+
35+
bvec=pto';
36+
bvec=bvec(:);
37+
38+
x=amat\bvec;
39+
A=reshape(x(1:9),3,3)';
40+
b=x(end-2:end);

dist2surf.m

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
function [d2surf,cn]=dist2surf(node,nv,p,cn)
2+
% [d2surf,cn]=dist2surf(node,nv,p)
3+
%
4+
% calculate the distances from a point cloud to a surface, and return
5+
% the indices of the closest surface node
6+
%
7+
% author: Qianqian Fang <q.fang at neu.edu>
8+
% date: 12/12/2008
9+
%
10+
% parameters:
11+
% node: node coordinate of the surface mesh (nn x 3)
12+
% nv: nodal norms (vector) calculated from nodesurfnorm.m
13+
% with dimensions of (size(node,1),3), this can be
14+
% calcuated from nodesurfnorm.m
15+
% pt: points to be calculated, 3 columns for x,y and z respectively
16+
%
17+
% outputs:
18+
% d2surf: a vector of length of p, the distances from p(i) to the surface
19+
% cn: a integer vector with the length of p, the indices of the closest surface node
20+
%
21+
% Please find more information at http://iso2mesh.sf.net/cgi-bin/index.cgi?metch
22+
%
23+
% this function is part of "metch" toobox, see COPYING for license
24+
25+
26+
if(nargin<4)
27+
nn=size(node,1);
28+
pnum=size(p,1);
29+
mindist=zeros(pnum,1);
30+
cn=zeros(pnum,1);
31+
for i=1:pnum
32+
d0=node-repmat(p(i,:),nn,1);
33+
d0=sum(d0.*d0,2);
34+
[mindist(i),cn(i)]=min(d0);
35+
end
36+
end
37+
d2surf=abs(sum(nv(cn,:).*(p-node(cn,:)),2));

finddisconnsurf.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
% subroutine to extract disconnected surfaces from a
66
% cluster of surfaces
77
%
8-
% author: Qianqian Fang ([email protected].edu)
8+
% author: Qianqian Fang (q.fang at neu.edu)
99
% Date: 2008/03/06
1010
%
1111
% input:

linextriangle.m

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
function [isinside,pt,coord]=linextriangle(p0,p1,plane)
2+
% [isinside,pt,coord]=linextriangle(p0,p1,plane)
3+
%
4+
% calculate the intersection of a 3d line (passing two points)
5+
% with a plane (determined by 3 points)
6+
%
7+
% author: Qianqian Fang <q.fang at neu.edu>
8+
% date: 12/12/2008
9+
%
10+
% parameters:
11+
% p0: a 3d point in form of (x,y,z)
12+
% p1: another 3d point in form of (x,y,z), p0 and p1 determins the line
13+
% plane: a 3x3 matrix, each row is a 3d point in form of (x,y,z)
14+
% this is used to define a plane
15+
% outputs:
16+
% isinside: a boolean variable, 1 for the intersection is within the
17+
% 3d triangle determined by the 3 points in plane; 0 is outside
18+
% pt: the coordinates of the intersection pint
19+
% coord: 1x3 vector, if isinside=1, coord will record the barycentric
20+
% coordinate for the intersection point within the triangle;
21+
% otherwise it will be all zeros.
22+
%
23+
% for degenerated lines or triangles, this will stop
24+
%
25+
% Please find more information at http://iso2mesh.sf.net/cgi-bin/index.cgi?metch
26+
%
27+
% this function is part of "metch" toobox, see COPYING for license
28+
29+
[a,b,c,d]=getplanefrom3pt(plane);
30+
31+
if(a*a+b*b+c*c==0.0)
32+
error('degenerated plane');
33+
end
34+
35+
dl_n=sum([a b c].*(p1-p0));
36+
37+
if(dl_n==0.0)
38+
error('degenerated line');
39+
end
40+
41+
% solve for the intersection point
42+
t=-(a*p0(1)+b*p0(2)+c*p0(3)+d)/dl_n;
43+
pt=p0+(p1-p0)*t;
44+
45+
46+
dist=sum(abs(diff(plane)));
47+
[md,imax]=sort(dist);
48+
if(md(2)==0.0)
49+
error('degenerated triangle');
50+
end
51+
goodidx=imax(2:end);
52+
53+
ptproj=pt(goodidx);
54+
mat0=[plane(:,goodidx)',ptproj';1 1 1 1];
55+
56+
isinside=0;
57+
coord=[0 0 0];
58+
59+
det1=det(mat0(:,[4 2 3],:));
60+
det2=det(mat0(:,[1 4 3],:));
61+
if(det1*det2<0)
62+
return;
63+
end
64+
det3=det(mat0(:,[1 2 4],:));
65+
if(det2*det3<0)
66+
return;
67+
end
68+
if(det1*det3<0)
69+
return;
70+
end
71+
isinside=1;
72+
det0=det(mat0(:,1:3));
73+
74+
coord=[det1 det2 det3]/det0;

metchgui.fig

7.13 KB
Binary file not shown.

0 commit comments

Comments
 (0)