Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I intercept ROI movement when the user drags an ROI handle?

Solved!
Go to solution

Hello,I am using VDM2009 with C#. I need to do some ROI manipulation and need to intercept the mouse movements but don't know which events to use.As an example, assume I have created an OvalContour ROI and that it is a circle (width = height).I need to do 2 things:1) When the user drags one of the 4 handles, I need to check which handle is being dragged so that I can programmatically drag an adjacent handle so that the circle remains a circle and does not become an oval.

 

2) When the user clicks/drags the center of the circle, I need to prevent the ROI from updating so that the circle does not move. (It would be even better if there was a way to disable movement of the circle and only allow scaling.)I don't know which events to use to accomplish this behavior and am not sure how to retrieve the ROI handles to know which one is being dragged. Any/all help would be much appreciated.Thanks,Neville

Message 1 of 7
(4,217 Views)

Hey nb1forxp,

 

As far as what event to use, you could use a click event or a mouse down event. Then, as far as setting the ROI to be circular, you could use the ROILeft, ROITop, ROIWidth, ROIHeight properties to pragmatically read and set the ROI size and location to fit your needs. Check out the help documents for more information on these properties and events and how to use them.

Message Edited by BCho on 08-24-2009 02:20 PM
Hope this helps.
-Ben

WaterlooLabs
0 Kudos
Message 2 of 7
(4,193 Views)

Hello Ben,

 

Thanks for your help.  It looks like I picked a bad example because your solution works for a circle, but not another case I have.  Another case is a three-point PolyLineContour where the center point should always remain at the center of the screen.  The user should be able to move and drag the other 2 points to create an arbitrary angle.  I need to make sure the center point of the PolyLineContour ROI doesn't move, but the ROIlocation and ROIsize parameters won't help me since the location and size will change based on the location of the endpoints.  How do I know which of the ROI handles is being dragged?

 

Also, I looked in the help but couldn't figure out how to Get/Set the ROIlocation and ROIsize properties.  Can you please give the quick syntax?  E.g., imageViewer1.Roi[0]...

 

Thanks,

Neville 

0 Kudos
Message 3 of 7
(4,189 Views)

Hi Neville,

 

You use a mouse down event and check to see if the location of the mouse is the same as the center point of the PolyLineContour.

 

As far as I can tell, there isn't a ROIlocation or ROIsize function. There is, however, a ROIprofile function that returns the line profile (i.e. the coordinates of the points).

0 Kudos
Message 4 of 7
(4,163 Views)

Hello Olivia,

 

Thanks for your help.  What you said makes sense.  I'll give that a shot.

 

When I said ROIlocation, I meant ROILeft, ROIRight, ROITop, ROIBottom.  When I said ROISize, I meant ROIWidth and ROIHeight.  I don't know how to Get/Set those items.  In other words, how do I get the value of ROILeft?  How do I set the value of ROIWidth (maybe it's not settable)?

Thanks for the info about the ROIprofile function.  That looks useful.  I also found the ROI bounding box object as part of the RoiProfileReport, which looks useful too.

 

Thanks,
Neville 

0 Kudos
Message 5 of 7
(4,160 Views)

Hey Neville,

 

As an alternative, you could use the CWIMAQRegions.GetBoundingRectangle to get the bounds of your ROI and then use the CWIMAQRegions.AddRegion to redraw your ROI after you have have calculated your new corrected ROI bounds. With this Regions method, there is also a _RegionsChanged event that you could use. This would allow you to only process your event when the user tries to change the ROI.

 

Have you seen the NI Vision for Visual Basic Reference Help? Some of the parameters will be a little different then what you are working with because you are using C#. But, because you are using a .NET language the functions will be the same for the most part. You can find this document at C:\Program Files\National Instruments\Vision\Documentation\cwimaq.chm. Once in the document you can search for all sorts of functionality and the corresponding syntax.

Hope this helps.
-Ben

WaterlooLabs
0 Kudos
Message 6 of 7
(4,137 Views)
Solution
Accepted by topic author nb1forxp

Hello Ben,


Thanks again for your help.  I looked up the definitions for ROILeft, etc, in the VB Reference Help as you suggested.  While many objects are similar in name/parameter, it seems that those objects (ROILeft, etc) are ones that aren't easy to find how to use in the C# version.  But thanks for pointing me to the VB Ref Help file.  I wish there was one for C#...I can't figure out how to search effectively in the C# help file that's pre-integrated into Visual Studio.

 

Thanks for your suggestion about the ROI.  That makes sense and I'll keep it in mind.


In the meantime, I found a solution to my problem.  I'm using the C# function public bool PreFilterMessage(ref Message objMessage) to prefilter the mousedown and mousemove messages.  Once I find one, I check to see if the cursor is over a part of the ROI that I care about.  If I want to do something special, I do it at that point.  If I want to prevent the normal NI ROI behavior on mousedown and mousemove, I trash the message.

 

It's a total pain, but it looks like the NI functions aren't set up to do this sort of thing in an elegant way.  Thanks again for all your help!

Neville 

0 Kudos
Message 7 of 7
(4,124 Views)