Our users need to trace around a region on an image using impoly (closed = 0). In some cases they would like to start at a point that aligns with a separate feature in another part of the image. So they asked for a movable, vertical "guide line" to help with the alignment.
Code:
hFig = figure;hImg = imshow(imgFileName);lineColor = [0 1 0.89];lineWidth = 2;ax=gca;szImg = size(hImg.CData);imgCenter = 0.5*szImg(1:2);%%
origButtonMotionCB = get(hFig, 'WindowButtonMotionFcn'); hLine = xline(ax, imgCenter(1), '--', 'Color', lineColor, 'LineWidth', lineWidth);set(hLine, 'ButtonDownFcn', @(obj, eventdata)fcnStartDragLine(gcbo, eventdata, hFig)); set(hFig, 'WindowButtonUpFcn', {@fcnStopDragLine, hFig, origButtonMotionCB}); function fcnStartDragLine(hObject, eventdata, hFig)hLine = hObject;set(hFig, 'WindowButtonMotionFcn', {@fcnDragLine, hFig, hLine});end function fcnDragLine(hObject, eventdata, hFig, hLine)ax = findobj(hFig, 'Type', 'axes');pt = get(ax, 'CurrentPoint');ptX = pt(1, 1);set(hLine, 'Value', ptX);end function fcnStopDragLine(hObject, eventdata, hFig, origButtonMotionCB)set(hFig, 'WindowButtonMotionFcn', origButtonMotionCB);end
Problem: After drawing the guide line, I launch impoly, however the animated line that extends from the previous vertex to the mouse pointer no longer appears. Everything else works per spec( i.e., I can still add new vertices, etc).
If I launch impoly before adding the guide line, then the animated line appears during the polygon creation.
If I delete the guide line from the axis.Children, impoly still has no animated line.
What am I missing?
Thank you in advance for any help you can offer.
Best Answer