From 3b97717aea606697ecb40d57ce90b6c1e507de37 Mon Sep 17 00:00:00 2001
From: Yoann Guilhem <yoann.guilhem@esrf.fr>
Date: Sun, 2 Dec 2012 19:16:46 +0000
Subject: [PATCH] Cleaned and optimized some utility functions (maths, imaging
 and cryst)

git-svn-id: https://svn.code.sf.net/p/dct/code/trunk@937 4c865b51-4357-4376-afb4-474e03ccb993
---
 zUtil_Cryst/gtCrystVector2SST.m   | 10 ++++++----
 zUtil_Imaging/hsl2rgb.m           |  5 ++---
 zUtil_Imaging/rgb2hsl.m           |  3 +--
 zUtil_Maths/gtMathsEuler2Rod.m    |  6 ------
 zUtil_Maths/gtMathsRod2Euler.m    |  3 ---
 zUtil_Maths/gtMathsRod2RotMat.m   |  1 +
 zUtil_Maths/gtMathsRotMat2Euler.m |  2 +-
 zUtil_Maths/gtMathsRotMat2Rod.m   |  3 ---
 8 files changed, 11 insertions(+), 22 deletions(-)

diff --git a/zUtil_Cryst/gtCrystVector2SST.m b/zUtil_Cryst/gtCrystVector2SST.m
index d77554bc..98834229 100644
--- a/zUtil_Cryst/gtCrystVector2SST.m
+++ b/zUtil_Cryst/gtCrystVector2SST.m
@@ -83,21 +83,23 @@ function [rgb, Vsst, Vsst_p] = gtCrystVector2SST(Vc, crystal_system, symm, satur
     ok_too = (ok > 1);
 
     if any(ok_no)
-        warning('Problem when moving to SST triangle, no indices found for vectors:');
+        warning('gtCrystVector2SST:no_indices_found', ...
+            'Problem when moving to SST triangle, no indices found for vectors:');
         disp('  indices:');
         disp(find(ok_no)');
         disp('  vectors:');
-        disp(Vc(find(ok_no), :));
+        disp(Vc(ok_no, :));
         iSST(1, :, ok_no) = 1;
         anglesR(1, :, ok_no) = 0;
         anglesB(1, :, ok_no) = 0;
     end
     if any(ok_too)
-        warning('Might be a problem when moving to SST triangle, too many indices found!');
+        warning('gtCrystVector2SST:too_many_indices_found', ...
+            'Might be a problem when moving to SST triangle, too many indices found!');
         disp('  indices:');
         disp(find(ok_too)');
         disp('  vectors:');
-        disp(Vc(find(ok_too), :));
+        disp(Vc(ok_too, :));
         i_too = find(iSST(:, :, ok_too));
         iSST(i_too(2:end), :, ok_too) = 0;
     end
diff --git a/zUtil_Imaging/hsl2rgb.m b/zUtil_Imaging/hsl2rgb.m
index 6498501b..7a8b73e6 100644
--- a/zUtil_Imaging/hsl2rgb.m
+++ b/zUtil_Imaging/hsl2rgb.m
@@ -17,7 +17,6 @@ function rgb = hsl2rgb(hsl, progress)
 %     Note:
 %       See also rgb2hsl, rgb2hsv, hsv2rgb
 %
-%
 %     Version 002 16-10-2012 by YGuilhem
 %       Add an option to display progress report
 %
@@ -25,7 +24,6 @@ function rgb = hsl2rgb(hsl, progress)
 
 if max(max(hsl))>1 || min(min(hsl))<0,
     error('HSL values have to be between 0 and 1');
-    return;
 end;
 
 todo = size(hsl, 1);
@@ -48,6 +46,7 @@ for i=1:size(hsl,1),
         temp2=hsl(i,3)+hsl(i,2)-hsl(i,3)*hsl(i,2);
     end;
     temp1=2*hsl(i,3)-temp2;
+    temp3=zeros(size(temp1));
     temp3(1)=hsl(i,1)+1/3;
     temp3(2)=hsl(i,1);
     temp3(3)=hsl(i,1)-1/3;
@@ -70,7 +69,7 @@ for i=1:size(hsl,1),
     
     % Give a progress report for long lists
     if progress && mod(i, 1000)==0
-        disp(sprintf('% 5.1f %%',  100*i/todo));
+        fprintf('% 5.1f %%',  100*i/todo);
     end
 end
 
diff --git a/zUtil_Imaging/rgb2hsl.m b/zUtil_Imaging/rgb2hsl.m
index 79878f69..a9f982f7 100644
--- a/zUtil_Imaging/rgb2hsl.m
+++ b/zUtil_Imaging/rgb2hsl.m
@@ -25,7 +25,6 @@ function hsl = rgb2hsl(rgb, progress)
 
 if max(max(rgb))>1 || min(min(rgb))<0,
     error('RGB values have to be between 0 and 1');
-    return;
 end;
 
 todo = size(rgb, 1);
@@ -67,7 +66,7 @@ for i=1:size(rgb,1),
 
     % Give a progress report for long lists
     if progress && mod(i, 1000)==0
-        disp(sprintf('% 5.1f %%',  100*i/todo));
+        fprintf('% 5.1f %%',  100*i/todo);
     end
 end
 
diff --git a/zUtil_Maths/gtMathsEuler2Rod.m b/zUtil_Maths/gtMathsEuler2Rod.m
index 12674d46..959b38d4 100644
--- a/zUtil_Maths/gtMathsEuler2Rod.m
+++ b/zUtil_Maths/gtMathsEuler2Rod.m
@@ -22,12 +22,6 @@ if size(euler, 2) ~= 3
         'Given matrix size is not Mx3!');
 end
 
-% Get number of r vectors
-M = size(euler, 1);
-
-% Set epsilon to avoid singular values
-epsilon = 1.e-9;
-
 % Create Euler angles vectors
 phi1 = euler(:, 1);
 phi  = euler(:, 2);
diff --git a/zUtil_Maths/gtMathsRod2Euler.m b/zUtil_Maths/gtMathsRod2Euler.m
index 19f2a6ff..2a820dbd 100644
--- a/zUtil_Maths/gtMathsRod2Euler.m
+++ b/zUtil_Maths/gtMathsRod2Euler.m
@@ -23,9 +23,6 @@ if size(r, 2) ~= 3
         'Given matrix size is not Mx3!');
 end
 
-% Get number of r vectors
-M = size(r, 1);
-
 % Set epsilon to avoid singular values
 epsilon = 1.e-9;
 
diff --git a/zUtil_Maths/gtMathsRod2RotMat.m b/zUtil_Maths/gtMathsRod2RotMat.m
index a1ba4ce6..0f02b2e2 100644
--- a/zUtil_Maths/gtMathsRod2RotMat.m
+++ b/zUtil_Maths/gtMathsRod2RotMat.m
@@ -56,6 +56,7 @@ w = [ n0 ,  n3 , -n2 ; ...
       n2 , -n1 ,  n0 ];
 
 % Squared w matrix
+w2 = zeros(size(w));
 for ig=1:M
     w2(:, :, ig) = w(:, :, ig)^2;
 end
diff --git a/zUtil_Maths/gtMathsRotMat2Euler.m b/zUtil_Maths/gtMathsRotMat2Euler.m
index c859c95e..251046af 100644
--- a/zUtil_Maths/gtMathsRotMat2Euler.m
+++ b/zUtil_Maths/gtMathsRotMat2Euler.m
@@ -19,7 +19,7 @@ function euler = gtMathsRotMat2Euler(g)
 %     Version 001 15-06-2012 by YGuilhem
 
 % Check size of g matrix
-if size(g{1}) ~= [3 3]
+if any(size(g{1}) ~= 3)
     gtError('RotMat:wrong_matrix_size', 'Given matrices size is not 3x3!');
 end
 
diff --git a/zUtil_Maths/gtMathsRotMat2Rod.m b/zUtil_Maths/gtMathsRotMat2Rod.m
index 3a98ab80..7dc3d6d5 100644
--- a/zUtil_Maths/gtMathsRotMat2Rod.m
+++ b/zUtil_Maths/gtMathsRotMat2Rod.m
@@ -27,9 +27,6 @@ else
     gtError('RotMat:wrong_matrix_size', 'Given matrices size is not 3x3!');
 end
 
-% Get number of rotation matrices and allocate Euler angles vectors
-M = length(g);
-
 % Set epsilon to avoid singular values
 epsilon = 1.e-9;
 
-- 
GitLab