From 4a6f2e25ffa9c59fa99e7badfe548a1cb25b6839 Mon Sep 17 00:00:00 2001 From: Nicola Vigano <nicola.vigano@esrf.fr> Date: Tue, 26 Jun 2012 10:03:27 +0000 Subject: [PATCH] GtPhase: added method to get neighbors of a grain. Signed-off-by: Nicola Vigano <nicola.vigano@esrf.fr> git-svn-id: https://svn.code.sf.net/p/dct/code/trunk@569 4c865b51-4357-4376-afb4-474e03ccb993 --- zUtil_DataStructures/GtPhase.m | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/zUtil_DataStructures/GtPhase.m b/zUtil_DataStructures/GtPhase.m index f42b2b83..2cbb4f53 100644 --- a/zUtil_DataStructures/GtPhase.m +++ b/zUtil_DataStructures/GtPhase.m @@ -436,6 +436,22 @@ classdef GtPhase < handle & obj.bboxExtremes(:,6) >= point(3) ... ); end + + function IDs = getNeighbours(obj, grainID) + numGrains = length(obj.grains); + replOnes = ones(numGrains, 1); + + halfLengths = obj.boundingBox(:, 4:6) / 2; + grainHalfLengths = halfLengths(grainID, :); + + maxDistances = halfLengths + grainHalfLengths(replOnes, :); + + centersInPixels = obj.boundingBox(:, 1:3) + halfLengths; + grainCenter = centersInPixels(grainID, :); + relativeCenters = abs(centersInPixels - grainCenter(replOnes, :)); + + IDs = setdiff(find(all(relativeCenters < maxDistances, 2)), grainID); + end function idspot = buildIdSpot(obj, grainid) difspotID = obj.summary{grainid}.difspotID'; % row vector -- GitLab