From 8dcabc19cbbd41df4cdbb94c027b515dd40a0845 Mon Sep 17 00:00:00 2001 From: Nicola Vigano <nicola.vigano@esrf.fr> Date: Wed, 4 Feb 2015 16:57:33 +0100 Subject: [PATCH] GtSample/GtPhase: added infrastructure for holding the information about extended grains and clusters of grains Signed-off-by: Nicola Vigano <nicola.vigano@esrf.fr> --- zUtil_DataStructures/GtGrain.m | 7 --- zUtil_DataStructures/GtPhase.m | 106 ++++++++++++++++++++++++-------- zUtil_DataStructures/GtSample.m | 22 +++++-- 3 files changed, 97 insertions(+), 38 deletions(-) delete mode 100644 zUtil_DataStructures/GtGrain.m diff --git a/zUtil_DataStructures/GtGrain.m b/zUtil_DataStructures/GtGrain.m deleted file mode 100644 index a241a34a..00000000 --- a/zUtil_DataStructures/GtGrain.m +++ /dev/null @@ -1,7 +0,0 @@ -classdef GtGrain < handle % XXX - To be removed after 31/12/2014 - properties - mergedIDs = []; - threshold = 0; - selectedDiffspots = []; - end -end diff --git a/zUtil_DataStructures/GtPhase.m b/zUtil_DataStructures/GtPhase.m index 031e59cc..929e84c3 100644 --- a/zUtil_DataStructures/GtPhase.m +++ b/zUtil_DataStructures/GtPhase.m @@ -3,20 +3,25 @@ classdef GtPhase < handle % grains are organized in a performance oriented structure and get/set methods % are provided, to aid the consistent use of the class. properties - grains = {}; % XXX - To be removed after 31/12/2014 - selectedGrains = []; % Booleans that enable/disable grains - completeness = []; % Index of completeness of a grain [0, 1] - center = []; % Center of mass of the grain - R_vector = []; % Orientation (in Rodrigues space) of the grain - boundingBox = []; % Bounding Box: [x y z lx ly lz] ? - active = true; % Boolean that enables/disables the phase - phaseName = ''; % Recognisable name for the phase - volumeFile = ''; % Path of the mat file which contains the data. - % The syntax is: 'filename:field' where field is - % the field in the mat file which actually contains - % the volume. - bboxExtremes = []; + selectedGrains = true(0, 1); % Booleans that enable/disable grains + completeness = zeros(0, 1); % Index of completeness of a grain [0, 1] + center = zeros(0, 3); % Center of mass of the grain + R_vector = zeros(0, 3); % Orientation (in Rodrigues space) of the grain + boundingBox = zeros(0, 6); % Bounding Box: [x y z lx ly lz] ? + active = true; % Boolean that enables/disables the phase + phaseName = ''; % Recognisable name for the phase + volumeFile = ''; % Path of the mat file which contains the data. + % The syntax is: 'filename:field' where field is + % the field in the mat file which actually contains + % the volume. + bboxExtremes = zeros(0, 6); orderedPositions = {}; + + use_extended = false(0, 1); + extended_params = GtPhase.makeExtendedField(cell(0, 1), cell(0, 1)); + + clusters = GtPhase.makeCluster( ... + cell(0, 1), cell(0, 1), cell(0, 1), cell(0, 1), cell(0, 1)); end properties (Access = public, Hidden = true) @@ -53,6 +58,12 @@ classdef GtPhase < handle obj.boundingBox = zeros(number, 6); obj.bboxExtremes = zeros(number, 6); obj.orderedPositions = {}; + + obj.use_extended = false(number, 1); + temp_init_cell = cell(number, 1); + obj.extended_params = GtPhase.makeExtendedField(temp_init_cell, temp_init_cell); + obj.clusters = GtPhase.makeCluster( ... + cell(0, 1), cell(0, 1), cell(0, 1), cell(0, 1), cell(0, 1)); end function pushGrain(obj) @@ -67,6 +78,10 @@ classdef GtPhase < handle obj.boundingBox = [obj.boundingBox; 0 0 0 0 0 0]; obj.bboxExtremes = [obj.bboxExtremes; 0 0 0 0 0 0]; obj.orderedPositions = {}; + + obj.use_extended = [obj.use_extended; false]; + obj.extended_params = [obj.extended_params; ... + GtPhase.makeExtendedField([], [])]; end function copy = getCopy(obj) @@ -84,6 +99,10 @@ classdef GtPhase < handle copy.bboxExtremes = obj.bboxExtremes; copy.orderedPositions = obj.orderedPositions; + + copy.use_extended = obj.use_extended; + copy.extended_params = obj.extended_params; + copy.clusters = obj.clusters; end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -119,7 +138,11 @@ classdef GtPhase < handle function setMergeIDs(obj, grainid, ids) obj.grains{grainid}.mergeIDs = ids; end - + + function setUseExtended(obj, grainid, use_ext) + obj.use_extended(grainid, 1) = use_ext; + end + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Getter Functions @@ -165,6 +188,14 @@ classdef GtPhase < handle shift = obj.boundingBox(grainid, 1:3); end + function use_ext = getUseExtended(obj, grainid) + use_ext = obj.use_extended(grainid, 1); + end + + function aclusters = getActiveClusters(obj) + aclusters = obj.clusters([obj.clusters(:).active]); + end + % grains fields function ids = getMergeIDs(obj, grainid) ids = obj.grains{grainid}.mergeIDs; @@ -175,7 +206,7 @@ classdef GtPhase < handle end function grainIDs = getGrainsWithCompletenessLessThan(obj, value) - % GTPHASE/GETGRAINSWITHCOMPLETENESSLESSTHAN Gets grains with + % GTPHASE/GETGRAINSWITHCOMPLETENESSLESSTHAN Gets grains with % (0 < completeness <= value) grainIDs = find(obj.completeness <= value & obj.completeness > 0); end @@ -184,16 +215,16 @@ classdef GtPhase < handle % GTPHASE/GETDESELECTEDGRAINS Gets deselected grains deselected = find(obj.selectedGrains == false); end - + function selected = getSelectedGrains(obj) % GTPHASE/GETSELECTEDGRAINS Gets selected grains selected = find(obj.selectedGrains == true); end - + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Analysis Functions - + function buildBBSearchList(obj) % buildBBSearchList(obj) for ii = 1:size(obj.bboxExtremes, 2) @@ -203,7 +234,7 @@ classdef GtPhase < handle function matchList = simpleSearchBBtouched(obj, point) % matchList = simpleSearchBBtouched(obj, point) - + matchList = find( obj.bboxExtremes(:,1) <= point(1) ... & obj.bboxExtremes(:,2) <= point(2) ... & obj.bboxExtremes(:,3) <= point(3) ... @@ -216,7 +247,7 @@ classdef GtPhase < handle function IDs = getNeighbours(obj, grainID, oversize) % IDs = getNeighbours(obj, grainID, oversize) - + if (~exist('oversize', 'var')) oversize = 1; end @@ -234,11 +265,10 @@ classdef GtPhase < handle IDs = setdiff(find(all(relativeCenters < (maxDistances * oversize), 2)), grainID); end - - + function merge = checkOverlapConflict(obj, id1, id2, pixelsize) % function merge = checkOverlapConflict(obj, id1, id2, pixelsize) - + merge_value1 = false; merge_value2 = false; @@ -254,7 +284,7 @@ classdef GtPhase < handle if (dist < thr_dist) merge_value1 = true; end - + % R_vector r1 = obj.R_vector(id1, :); r2 = obj.R_vector(id2, :); @@ -265,7 +295,7 @@ classdef GtPhase < handle if (angle < thr_angle) merge_value2 = true; end - + merge.grainID_1 = id1; merge.grainID_2 = id2; merge.center_1 = c1; @@ -281,4 +311,30 @@ classdef GtPhase < handle merge.tobemerged = merge_value1 & merge_value2; end end + + methods (Access = public, Static) + function extended_grain = makeExtendedField(bb_r_space, bb_o_space) + extended_grain = struct( ... + 'bb_r_space', bb_r_space, 'bb_o_space', bb_o_space); + end + + function cluster = makeCluster(included_ids, ref_r_vec, bb_r_space, bb_o_space, active) + if (~exist('active', 'var') || isempty(active)) + active = false; + end + cluster = struct( ... + 'included_ids', included_ids, 'ref_r_vec', ref_r_vec, ... + 'bb_r_space', bb_r_space, 'bb_o_space', bb_o_space, ... + 'active', active); + end + + function obj = loadobj(obj) + % Function to keep some sort of backwards compatibility + if (numel(obj.use_extended) == 0) + obj.use_extended = false(obj.grains_number, 1); + temp_init_cell = cell(obj.grains_number, 1); + obj.extended_params = GtPhase.makeExtendedField(temp_init_cell, temp_init_cell); + end + end + end end diff --git a/zUtil_DataStructures/GtSample.m b/zUtil_DataStructures/GtSample.m index 477ea624..9711b518 100644 --- a/zUtil_DataStructures/GtSample.m +++ b/zUtil_DataStructures/GtSample.m @@ -5,7 +5,7 @@ classdef GtSample < handle volumeFile = ''; dilVolFile = ''; absVolFile = ''; - + fileTable = ''; version; @@ -37,6 +37,12 @@ classdef GtSample < handle obj.version = GtSample.getCurrentVersion(); end + function delete(obj) + for ii = 1:numel(obj.phases) + delete(obj.phases{ii}); + end + end + function copy = getCopy(obj) num_phases = numel(obj.phases); copy = GtSample(num_phases, obj.volumeFile, ... @@ -70,6 +76,9 @@ classdef GtSample < handle obj.mergePhaseField(other, phaseNum, 'boundingBox', 0); % Merge bboxExtremes obj.mergePhaseField(other, phaseNum, 'bboxExtremes', 0); + + % Merge bboxExtremes + obj.mergePhaseField(other, phaseNum, 'use_extended', 0); end end @@ -84,7 +93,7 @@ classdef GtSample < handle if (~exist('fieldName', 'var')) fieldName = 'sample'; end - + lock = GtLockDB(fileTable, fileName); lock.acquire(); @@ -124,7 +133,7 @@ classdef GtSample < handle fileName = fullfile('4_grains', 'sample.mat'); end - sample = obj; + sample = obj; %#ok<NASGU> save(fileName, 'sample', '-v7.3'); end @@ -133,8 +142,9 @@ classdef GtSample < handle % instances to find the grains which have a lower completeness than the % value - grainIDs = {}; - for phaseID = 1:numel(obj.phases) + num_phases = numel(obj.phases); + grainIDs = cell(num_phases, 1); + for phaseID = 1:num_phases grainIDs{phaseID} = ... obj.phases{phaseID}.getGrainsWithCompletenessLessThan(value); end @@ -199,7 +209,7 @@ classdef GtSample < handle lock.release(); end - + function sample = loadFromFile(fileName, fieldName) % GTSAMPLE/LOADFROMFILE Not synchronized loading from a file -- GitLab