Skip to content
Snippets Groups Projects
Commit 0f3d2548 authored by MarieBofferding's avatar MarieBofferding
Browse files

//WIP added computing of electrode direction and baseline

also tried to implement computing distance between contact points and baseline, doesn't work correctly yet
parent f99cf539
No related branches found
No related tags found
2 merge requests!3Regular merge of develop,!2Seeg algorithm
......@@ -51,7 +51,7 @@ componentIdxsHeads = idxs(areas >= MINVOXELNUMBER_HEAD & areas <= MAXVOXELNUMBER
%% PCA to get biggest eigenvalue from latent and principle direction from coeff matrix
% TODO:
A = [];
newPositionsContactCandidates = zeros(3,length(contactCandidate));
% this should be the same as length of componentIdxs?
numCandidates = length(contactCandidate)+length(headCandidate);
......@@ -69,19 +69,97 @@ for i = 1:(length(headCandidate))
disp(['centroid at ' num2str(i) ' is: ' num2str(centroidPositionHead)]);
shiftcoord = global2localcoord([0;0;0], 'rr', centroidPositionHead');
% shiftcoord = global2localcoord([0;0;0], 'rr', centroidPositionHead');
% get the centroids of the contactCandidates and shift them by the
% vector of the centroid of the current head candidate
for j = 1:(length(contactCandidate))
centroidPositionContact = ccProps(componentIdxsContacts(j)).Centroid;
newContactPosition = coeff * centroidPositionContact' + centroidPositionHead';
disp(['new Contact Position at ' num2str(j) ' is: ' num2str(newContactPosition')]);
newPositionsContactCandidates(:,j) = newContactPosition;
end
% compute the centroid of all contact points together to later get the
% direction in which we define our estimated electrode
centroidOfAllContacts = mean(newPositionsContactCandidates, 2);
% new origin is centroid point of head and new (local) coordinate
% system is coeff from the pca
% compute vector between the two points
vectorBetweenHeadCentroidCentroidOfAll = centroidOfAllContacts - centroidPositionHead';
% compute both "end points" on the bolt head, were the x-axis of our
% new coordinate system is going through
% then we can use them to determine, to which end the mean is nearer
% and therefore we now on which side of the bolt head the contact
% candidates lie
endOneOfBoltHead = coeff(:,1) * latent(1,:) + centroidPositionHead';
endTwoOfBoltHead = coeff(:,1) * latent(1,:) * (-1.0) + centroidPositionHead';
% compute the lengths of the vectors between both endpoints and the
% centroid point of the contact candidates
distMeanToEndOne = norm(centroidOfAllContacts - endOneOfBoltHead);
distMeanToEndTwo = norm(centroidOfAllContacts - endTwoOfBoltHead);
% we set the origin of our future line to the end which is furthest
% away from the centroid point and go with it in the direction of the
% other endpoint, because now we know, there are all the contact
% candidates
if(distMeanToEndOne < distMeanToEndTwo)
originOfLine = endTwoOfBoltHead;
secondPointOnLine = endOneOfBoltHead;
else
originOfLine = endOneOfBoltHead;
secondPointOnLine = endTwoOfBoltHead;
end
% can this be 3-dimensional
% baseline = polyfit(originOfLine, secondPointOnLine, 1);
% vector pointing from origin point of line to second one
originToSecondPoint = secondPointOnLine - originOfLine;
lengthBetweenPoints = norm(originToSecondPoint);
% get unit vector along the line
originToSecondPoint = originToSecondPoint / lengthBetweenPoints;
% compute y = a * x + b to get the line, where a is 0 < a <
% lengthBetweenPoints
%baseline = originOfLine + (lengthBetweenPoints/2) * originToSecondPoint;
% description of our baseline going out from one end of the bolt
% through the other end into the head space with the contact candidates
baseline = @(t)(originOfLine + originToSecondPoint * t);
% iterate through all contact candidates to find all of them, that have
% a smaller distance to the baseline than some defined threshold
% TODO: sort out possible problems with voxels/mm between line and
% point
for k = 1:(length(contactCandidate))
contactPoint = newPositionsContactCandidates(:,k);
xValueOfContactPoint = contactPoint(1,:);
% wanted to compute distance between point and corresponding point
% on the baseline, but there may be conflicts with position of
% point and baseline measurement in mm
dist = norm(componentIdxsContacts(k) - baseline(k));
if(dist < threshold)
%add point to matrix
end
end
figure
plotv(baseline);
figure
scatterMatrix3(newPositionsContactCandidates);
hold on
scatterMatrix3(centroidOfAllContacts');
hold off
%
% de=det(coeff);
%
% newcoeff = [coeff(:,2), -coeff(:,3), coeff(:,1)];
......@@ -109,31 +187,31 @@ end
% end
x=coeff(:,1);
y=coeff(:,2);
z=coeff(:,3);
inter = intersect(intersect(x,y),z);
plot(x);
plot(y);
plot(z);
t=det(coeff);
plot3(x,y,z);
%coeff(:,1)
M = [0,0,1;0,0,-1;0,1,0];
a = M(:,1);
b = M(:,2);
c = M(:,3);
vec_inter = intersect(intersect(a,b), c);
figure;
plotv(M, '-');
%
% x=coeff(:,1);
% y=coeff(:,2);
% z=coeff(:,3);
%
% inter = intersect(intersect(x,y),z);
%
% plot(x);
% plot(y);
% plot(z);
%
% t=det(coeff);
%
% plot3(x,y,z);
%
% %coeff(:,1)
%
%
% M = [0,0,1;0,0,-1;0,1,0];
%
% a = M(:,1);
% b = M(:,2);
% c = M(:,3);
%
% vec_inter = intersect(intersect(a,b), c);
%
% figure;
% plotv(M, '-');
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment