|
Hello,
I would like to improve the time efficiency of my code (see below):
//========================================
//There is a structure "s" consisted of delaunay triangulations of different geometrical objects.
s = struct('tess', {});
<<...>>
//E.g.
s(1).tess = DelaunayTri(v(:,1),v(:,2),v(:,3));
// This function veryfies the intersection of all faces of tetrahedrons with the curve
function answer = f1(...);
tessqty = length(s(:));
P1 = []; P2 = []; P3 = [];
for i = 1 : tessqty
tess = s(i).tess;
faces = [tess(:,[1 2 3]); tess(:,[2 3 4]); ...
tess(:,[1 3 4]); tess(:,[1 2 4])];
P1 = [P1; s(i).tess.X(faces(:,1),1) s(i).tess.X(faces(:,1),2) s(i).tess.X(faces(:,1),3)];
P2 = [P2; s(i).tess.X(faces(:,2),1) s(i).tess.X(faces(:,2),2) s(i).tess.X(faces(:,2),3)];
P3 = [P3; s(i).tess.X(faces(:,3),1) s(i).tess.X(faces(:,3),2) s(i).tess.X(faces(:,3),3)];
end
walk = ones(leng,1);
for j = 1 : leng
for i = 1 : length(P1(:,1))
[flag,u,v,a] = rayTriangleIntersection(origin(j,:),direct(j,:),P1(i,:),P2(i,:),P3(i,:));
if flag == 1
intersection = origin(j,:) + a*direct(j,:);
if pointSegment(intersection,origin(j,:),dest(j,:))
walk(j) = 0;
break,
end
end;
end;
end;
answer = walk;
end;
//========================================
This function "f1" is executed inside the FOR LOOP (with 100 iterations). Totally, it takes a very long time (>30 minutes) to run the code. I was thinking about the vectorization of the code, but it doesn't work for the structure "s".
I would appreciate any help. Perhaps, someone could share the experience. Thanks a lot.
|