How does getPosition work in impoly?
Afficher commentaires plus anciens
Hello,
i've been using impoly for drawing polygon in a blank figure, and then use the pos=getPosition(h) function to get the position of the drawn polygon. but the problem is, when i changed the corner of the drawn polygon, the "h=getPosition" function won't retrieve (update) the new position, is there a way to update the position while we change the corner?.
also, suppose that i draw a few polygon in a figure using only "h=impoly" then i want to delete one of the previous polygons (by choosing one of the drawn polygons to be deleted). i have used the "delete(h)" command but only the previous body that can be deleted.
thanks in advance :)
2 commentaires
Mallory
le 16 Jan 2012
Matt Tearle
le 16 Jan 2012
Glad to help. You could upvote Alex's answer (I have, because it was a good explanation of the code I posted.)
Réponse acceptée
Plus de réponses (2)
Alex Taylor
le 13 Jan 2012
Regarding "updating the polygon position". I'm still not fully understanding the question, but Matt has already provided good answers. I'd like to try to add a bit.
1) The getPosition method of impoly will always return the current XY positions of the vertices of the polygon. If you adjust the polygon position via an interactive gesture, or via the setPosition method, calling getPosition will always provide updated information. So, I don't know what you mean when you say "the "h=getPosition" function won't retrieve (update) the new position". Each time you want to know the current vertex positions, you can call getPosition and you will get the updated vertex positions.
2) If what you want is a function to fire whenever the position of the polygon is adjusted, then you should use the addNewPositionCallback method described by Matt. To provide a slightly more simple example:
h = impoly();
fun = @(p) disp(p);
addNewPositionCallback(h,fun);
Will add a new position callback function to the impoly object h which will cause the function defined in the anonymous function "fun" to fire each time the position of the polygon changes. The function argument requires that you pass in a function handle, which can either be an anonymous function or can be a handle to any function on the path. In this case, the anonymous function fun takes one input argument "p", which is the array of new XY vertex positions. The function uses the DISP function to display these vertex positions.
- Alex.
Image Analyst
le 16 Jan 2012
0 votes
You might consider using roipolyold(). It doesn't let you reposition the location of vertices that have already been placed, but you avoid having to right click and "copy mask" or whatever it says. It finishes simply by you right clicking the last point.
Catégories
En savoir plus sur Scripts dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!