How do you get an impoly class object from its handle?

조회 수: 10 (최근 30일)
Andrew Diamond
Andrew Diamond 2012년 6월 5일
댓글: Image Analyst 2015년 5월 31일
I created impoly objects with impoly. Their tag is impoly. At some later point I want to get all the properties of all the created impolys. I can use findall on a Tag of impoly but that apparently just returns the handles as opposed to the class objects. I know this because when I try calling the impoly methods (e.g. getColor) on a returned handle it barfs because the handle, which is a double, isn't an impoly class object. Calling impoly on the class does not cast it.
I could store the objects when they are created to work on them later but they user might delete them etc. In any even it seems silly to do that.
=
specifics: On my gui a botton links to a callback which calls impoly. impoly returns an impoly object that the impoly members can operate. Eg h=impoly(axeshandle) setColor(h,'red');
When the user clicks my "Save" button, another callback is called and in that I use a H=findall(axeshandle, 'Tag', 'impoly') to find and return all the polygons. However, H is all double type graphics handles and so a call like GetColor(H(1)) will fail with the error :
Conversion to double from cell is not possible.

답변 (2개)

Andrew Diamond
Andrew Diamond 2012년 6월 5일
Apparently the function aptgetapi gives access to the methods.
Given h, a returned simple handle (by findobj or findall)
api=iptgetapi(h)
PtsList = api.getPosition();
yields a nx2 list of polygon points. I'm sure the other methods work accordingly.
I simply can't believe what it took to find this out. Searching support didn't seem to yield anything. You'd think I was the first person to do it or it was plainly obvious. I find either hard to believe.
It's like original sin.
  댓글 수: 3
Slim
Slim 2015년 5월 31일
Works great ! Thanks a lot !
Image Analyst
Image Analyst 2015년 5월 31일
"I simply can't believe what it took to find this out." - probably because hardly anyone ever does that, and if they did, they'd just save the poly objects in a cell array if they knew they'd need them later.

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2012년 6월 5일
imh = handle(h);
imh.setColor('red');
  댓글 수: 1
Andrew Diamond
Andrew Diamond 2012년 6월 5일
This doesn't seem to work as the handle(h) returns an object of class hggroup vs impoly.( and impoly, not hggroup, has the setColor etc methods)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Type Identification에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by