1111
1212% ------
1313% Author: David Legland
14- % e-mail: david.legland@inra .fr
14+ % e-mail: david.legland@inrae .fr
1515% Created: 2011-11-21, using Matlab 7.9.0.529 (R2009b)
1616% Copyright 2011 INRA - Cepia Software Platform.
1717
1818%% Properties
1919properties
2020 ButtonPressed = false ;
2121
22- % the current drawing 'color ', initialized to white
23- Color = 255 ;
22+ % % The current drawing 'value ', initialized to white
23+ % Value = 255;
2424
2525 PreviousPoint ;
2626end
@@ -56,11 +56,7 @@ function onMouseMoved(obj, hObject, eventdata) %#ok<INUSD>
5656 function processCurrentPosition(obj )
5757 doc = obj .Viewer .Doc ;
5858 img = doc .Image ;
59-
60- if ~isGrayscaleImage(img )
61- return ;
62- end
63-
59+
6460 point = get(obj .Viewer .Handles .ImageAxis , ' CurrentPoint' );
6561 coord = round(pointToIndex(obj , point(1 , 1 : 2 )));
6662
@@ -69,13 +65,21 @@ function processCurrentPosition(obj)
6965 if any(coord < 1 ) || any(coord > dim([1 2 ]))
7066 return ;
7167 end
68+
69+ % indices of Z, C and T dimensions
70+ iz = 1 ;
71+ if isa(obj .Viewer , ' imagem.gui.Image3DSliceViewer' )
72+ iz = obj .Viewer .SliceIndex ;
73+ end
74+ ic = 1 : channelNumber(img );
75+ it = 1 ; % not managed for the moment
7276
7377 if ~isempty(obj .PreviousPoint )
7478 % mouse moved from a previous position
75- drawBrushLine(obj , coord , obj .PreviousPoint );
79+ drawBrushLine(obj , coord , obj .PreviousPoint , iz , ic , it );
7680 else
7781 % respond to mouse button pressed, mouse hasn't moved yet
78- drawBrush(obj , coord );
82+ drawBrush(obj , coord , iz , ic , it );
7983 end
8084
8185 obj.PreviousPoint = coord ;
@@ -96,16 +100,16 @@ function processCurrentPosition(obj)
96100 index = (point - origin ) ./ spacing + 1 ;
97101 end
98102
99- function drawBrushLine(obj , coord1 , coord2 )
103+ function drawBrushLine(obj , coord1 , coord2 , iz , ic , it )
100104 [x , y ] = imagem .tools .Brush .intline(coord1(1 ), coord1(2 ), coord2(1 ), coord2(2 ));
101105
102106 % iterate on current line
103107 for i = 1 : length(x )
104- drawBrush(obj , [x(i ) y(i )]);
108+ drawBrush(obj , [x(i ) y(i )], iz , ic , it );
105109 end
106110 end
107111
108- function drawBrush(obj , coord )
112+ function drawBrush(obj , coord , iz , ic , it )
109113 doc = obj .Viewer .Doc ;
110114
111115 % brush size in each direction
@@ -119,25 +123,26 @@ function drawBrush(obj, coord)
119123 y1 = max(coord(2 )-bs1 , 1 );
120124 x2 = min(coord(1 )+bs2 , dim(1 ));
121125 y2 = min(coord(2 )+bs2 , dim(2 ));
122-
126+
123127 % iterate on brush pixels
124- for i = x1 : x2
125- for j = y1 : y2
126- doc .Image( i , j ) = obj .Color ;
128+ for ix = x1 : x2
129+ for iy = y1 : y2
130+ doc .Image .Data( ix , iy , iz , ic , it ) = obj .Viewer . Gui . App . BrushValue ;
127131 end
128132 end
129133 end
130134end % methods
131135
132136methods (Static , Access = private )
133137 function [x , y ] = intline(x1 , y1 , x2 , y2 )
134- % INTLINE Integer-coordinate line drawing algorithm.
135- % [X, Y] = INTLINE(X1, X2, Y1, Y2) computes an
138+ % Integer-coordinate line drawing algorithm.
139+ %
140+ % [X, Y] = intline(X1, X2, Y1, Y2) computes an
136141 % approximation to the line segment joining (X1, Y1) and
137142 % (X2, Y2) with integer coordinates. X1, X2, Y1, and Y2
138- % should be integers. INTLINE is reversible; that is,
139- % INTLINE (X1, X2, Y1, Y2) produces the same results as
140- % FLIPUD(INTLINE (X2, X1, Y2, Y1)).
143+ % should be integers. intline is reversible; that is,
144+ % intline (X1, X2, Y1, Y2) produces the same results as
145+ % FLIPUD(intline (X2, X1, Y2, Y1)).
141146 %
142147 % Function adapted from the 'strel' function of matlab.
143148 %
@@ -190,7 +195,7 @@ function drawBrush(obj, coord)
190195methods
191196 function b = isActivable(obj )
192197 doc = obj .Viewer .Doc ;
193- b = ~isempty(doc ) && ~isempty(doc .Image ) && isScalarImage( doc . Image ) ;
198+ b = ~isempty(doc ) && ~isempty(doc .Image );
194199 end
195200end
196201
0 commit comments