1 | function [v, f] = getHalfDino(CHATTY) |
---|
2 | %% [verts, faces] = getHalfDino(CHATTY) |
---|
3 | %% If CHATTY (default FALSE) then do display |
---|
4 | FALSE = 0==1; |
---|
5 | TRUE = ~FALSE; |
---|
6 | |
---|
7 | if nargin == 0 |
---|
8 | CHATTY = 0; |
---|
9 | end |
---|
10 | |
---|
11 | |
---|
12 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
13 | %%% Read and display Dino data set |
---|
14 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
15 | dinoData; |
---|
16 | |
---|
17 | if CHATTY |
---|
18 | lines = showWire(verts,faces,1); |
---|
19 | title('Full Dino Data Set'); |
---|
20 | fprintf(2,'Rotate this figure.\n'); |
---|
21 | fprintf(2,'Press any key to continue...'); |
---|
22 | pause; fprintf(2,'ok\n'); |
---|
23 | end |
---|
24 | |
---|
25 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
26 | %%% Extract one side of Dino in principal coordinates |
---|
27 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
28 | %% Find Dino's principal axes |
---|
29 | mn = sum(verts,1)/size(verts,1); |
---|
30 | [U S V] = svd(verts-repmat(mn, size(verts,1), 1), 0); S = diag(S); |
---|
31 | |
---|
32 | %% Expect third axis to be the lateral direction. |
---|
33 | %% Remove vertices with z < 0 |
---|
34 | id = U(:,2) < -0.001; |
---|
35 | |
---|
36 | %% Compute vertices in principal axes. |
---|
37 | v = U(~id, :)*diag(S); |
---|
38 | |
---|
39 | %% Relabel the remaining vertices |
---|
40 | relabel = zeros(size(verts,1),1); |
---|
41 | relabel(~id) = 1:sum(~id); |
---|
42 | |
---|
43 | %% Write the faces in terms of the relabelled vertices |
---|
44 | f={}; j=0; |
---|
45 | for k = 1:length(faces) |
---|
46 | if ~any(id(faces{k})) |
---|
47 | j = j+1; |
---|
48 | f{j} = relabel(faces{k})'; |
---|
49 | end |
---|
50 | end |
---|
51 | |
---|
52 | if CHATTY |
---|
53 | l = showWire(v,f,1); |
---|
54 | title('One Sided Dino Data Set'); |
---|
55 | fprintf(2,'Rotate this figure.\n'); |
---|
56 | fprintf(2,'Press any key to continue...'); |
---|
57 | pause; fprintf(2,'ok\n'); |
---|
58 | |
---|
59 | %%%%% Show Dino as a surface plot |
---|
60 | figure(3); clf; |
---|
61 | for k = 1:length(f) |
---|
62 | vf = v(f{k},:); |
---|
63 | patch(vf(:,1), vf(:,2), vf(:,3), vf(:,2)); |
---|
64 | end |
---|
65 | set(gca,'YDir', 'reverse'); |
---|
66 | axis vis3d; axis square; axis equal; |
---|
67 | title('One Sided Dino Data Set'); |
---|
68 | fprintf(2,'Rotate this figure.\n'); |
---|
69 | fprintf(2,'Press any key to continue...'); |
---|
70 | pause; |
---|
71 | fprintf(2,'ok\n'); |
---|
72 | |
---|
73 | end |
---|
74 | return; |
---|