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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
| function calcul_ellipsoide(h,e,val_k)
t_debut=tic;
mex=[];
[phi, theta]=meshgrid([0:0.9:pi], [0:0.9:2*pi]);
global chemin_final;
fid = fopen(chemin_final, 'rt');
t_start=tic;
while feof(fid) == 0
tline = fgetl(fid);
TargetVar = regexp(tline,' ','split');
if length(TargetVar)>2
[xc, reste] =strtok(tline, ' ');
[yc, reste] =strtok(reste, ' ');
[zc, reste] =strtok(reste, ' ');
[Rayon, reste] =strtok(reste, ' ');
h=h+1;
Pts(h,1:3)= [str2num(xc) str2num(yc) str2num(zc)] ;
Ray(h,1)=str2num(Rayon);
Vol(h,1)=((4/3)*pi)*(Ray(h)^3);
end
end
t_while = toc(t_start);
%---------------------------fin du bloc 1--------------------
k=val_k;
%---------------------------debut du bloc 2--------------------
t_debut2=tic;
[idx,C]=kmeans_kemgue(Pts,k,Vol,Ray,'distance','madist');
fig=figure('name','Modelix-visualisation ellipsoides','WindowStyle','modal');
axis equal;
t_kmeans=toc(t_debut2);
%---------------------------fin du bloc 2--------------------
%title(sprintf('Visualisation du sous ensemble'))
%---------------------------debut du bloc 3--------------------
t_debut3=tic;
%l = parallel.pool.Constant(mex);
% i=1;
%while i <k
parfor (i=1:k,8)
members = (i == idx);
disp(strcat('Cluster numero <',num2str(i),'>'));
sousEns=Pts(members,:);
if(isempty(sousEns)==1)
continue
end
sousRay=Ray(members);
disp('De Centroid');
disp(C(i,:));
Echan=[];
% l=size(sousEns,1);
% parfor (j = 1:l,8)
for j=1:size(sousEns,1)
xx=[];
yy=[];
zz=[];
xx=sousRay(j)*sin(phi).*cos(theta)+sousEns(j,1);
yy=sousRay(j)*sin(phi).*sin(theta)+sousEns(j,2);
zz=sousRay(j)*cos(phi)+sousEns(j,3);
% disp('OOOKKKKK')
n=size(xx(:),1);
Echan2=[];
Echan2(1:n,1)=xx(:);
Echan2(1:n,2)=yy(:);
Echan2(1:n,3)=zz(:);
Echan=[Echan2;Echan];
[xu,yu,zu] = sphere;
x = xu*sousRay(j) + sousEns(j,1);
y = yu*sousRay(j) + sousEns(j,2);
z = zu*sousRay(j) + sousEns(j,3);
c = ones(size(z))*1;
hold on;
surf(x,y,z,c);
end
% envConvex=[]
% Echan
hold on
% disp('Echantillons');
% disp(Echan);
% Calcul de l'enveloppe convexe du sous ensemble de boule
[envConvex,vol]=convhull(Echan,'simplify',true);
% Ajout de l'enveloppe convexe du sous ensemble sur le dessin
% trisurf(envConvex,Echan(:,1),Echan(:,2),Echan(:,3), 'Facecolor','cyan'); axis equal;
col1=Echan(:,1);
col2=Echan(:,2);
col3=Echan(:,3);
% trisurf(envConvex,col1,col2,col3, 'Facecolor','cyan');
% Ajout des points echantionné d'un sous ensemble sur la figure de
% visualisation.% hold on
plot3(Echan(:,1),Echan(:,2),Echan(:,3),'.');
% Trace de l'ellipsoide qui approxime l'envesloppe convexe.
plot3(col1(envConvex(:,1)),col2(envConvex(:,2)),col3(envConvex(:,3)),'.');
Ptsapp=[];
Ptsapp=[col1 col2 col3];
hold on;
nbptsvisual=15;
[A1 centro] = approximation(Ptsapp',0.01)
[~,D1,V1] = svd(A1);
rx = 1/sqrt(D1(1,1));
ry = 1/sqrt(D1(2,2));
rz = 1/sqrt(D1(3,3));
me = [centro(1) centro(2) centro(3) rx ry rz];
mex=[me;mex];
[u v] = meshgrid(linspace(0,2*pi,nbptsvisual),linspace(-pi/2,pi/2,nbptsvisual))
x1 = rx*cos(u').*cos(v');
y1 = ry*sin(u').*cos(v');
z1 = rz*sin(v');
for indx = 1:nbptsvisual
for indy = 1:nbptsvisual
poin = [x1(indx,indy) y1(indx,indy) z1(indx,indy)]';
Pt = V1 * poin;
x1(indx,indy) = Pt(1)+centro(1);
y1(indx,indy) = Pt(2)+centro(2);
z1(indx,indy) = Pt(3)+centro(3);
end
end
uicontrol(fig, 'style','pushbutton', 'string','sauvergader', 'units','normalized', 'fontsize',11, 'position',[.05 .05 .15 .07], 'FontWeight','bold', 'FontName','Times New Roman', 'callback',{@sauvegarder,mex});
mesh(x1,y1,z1,'facecolor','none');
% set(me,'facecolor','none');
% surf(x1,y1,z1);
% i=i+1;
end
t_for=toc(t_debut3);
%---------------------------fin du bloc 3--------------------
end |
Partager