dm script - Arrow annotation coordinates become incorrect when added to a annotation group - Stack Overflow

I'm experiencing an issue with arrow annotations in my ImageDisplay component. When I create arrow

I'm experiencing an issue with arrow annotations in my ImageDisplay component. When I create arrow annotations sequentially, the arrow coordinates are correct. However, if I first create an annotation group and then add arrow annotations to this group, the arrow coordinates become incorrect. It appears that the marker group's coordinate system might not match the coordinate system used by ImageDisplay.

What I've Tried:

  1. Generating arrow markers one by one works as expected.
Image img := RealImage("RImg",4,256,256)
img.ShowImage()
ImageDisplay img_disp = img.ImageGetImageDisplay(0)
ImageDocument img_doc = img.ImageGetOrCreateImageDocument()

Number radius = 50
Number cx = 128
Number cy = 128
Number flag = 1
for (Number count = 0 ; count < 4 ; count++)
{
    Number phi = count * 2 * Pi()/ 4
    Number px = round(cx+radius*Cos(phi))
    Number py = round(cy+radius*Sin(phi))
    Component arrow = NewArrowAnnotation(cy, cx, py, px)
    img_disp.ComponentAddChildAtEnd(arrow)
}
  1. Creating a marker group first and then adding arrow markers leads to mixed-up coordinates.
Image img := RealImage("RImg",4,256,256)
img.ShowImage()
ImageDisplay img_disp = img.ImageGetImageDisplay(0)
ImageDocument img_doc = img.ImageGetOrCreateImageDocument()
Component arrows = NewGroupAnnotation()

Number radius = 50
Number cx = 128
Number cy = 128
for (Number count = 0 ; count < 4 ; count++)
{
    Number phi = count * 2 * Pi()/ 4
    Number px = round(cx+radius*Cos(phi))
    Number py = round(cy+radius*Sin(phi))
    Result(py + ", " + px + "\n")
    Component arrow = NewArrowAnnotation(cy, cx, py, px)
    arrows.ComponentAddChildAtEnd(arrow)
}

img_disp.ComponentAddChildAtEnd(arrows)

Questions:

  1. What could cause the coordinate discrepancy between the marker group and the ImageDisplay?
  2. How can I ensure that the marker group uses the same coordinate system as ImageDisplay when adding arrow markers?

I'm experiencing an issue with arrow annotations in my ImageDisplay component. When I create arrow annotations sequentially, the arrow coordinates are correct. However, if I first create an annotation group and then add arrow annotations to this group, the arrow coordinates become incorrect. It appears that the marker group's coordinate system might not match the coordinate system used by ImageDisplay.

What I've Tried:

  1. Generating arrow markers one by one works as expected.
Image img := RealImage("RImg",4,256,256)
img.ShowImage()
ImageDisplay img_disp = img.ImageGetImageDisplay(0)
ImageDocument img_doc = img.ImageGetOrCreateImageDocument()

Number radius = 50
Number cx = 128
Number cy = 128
Number flag = 1
for (Number count = 0 ; count < 4 ; count++)
{
    Number phi = count * 2 * Pi()/ 4
    Number px = round(cx+radius*Cos(phi))
    Number py = round(cy+radius*Sin(phi))
    Component arrow = NewArrowAnnotation(cy, cx, py, px)
    img_disp.ComponentAddChildAtEnd(arrow)
}
  1. Creating a marker group first and then adding arrow markers leads to mixed-up coordinates.
Image img := RealImage("RImg",4,256,256)
img.ShowImage()
ImageDisplay img_disp = img.ImageGetImageDisplay(0)
ImageDocument img_doc = img.ImageGetOrCreateImageDocument()
Component arrows = NewGroupAnnotation()

Number radius = 50
Number cx = 128
Number cy = 128
for (Number count = 0 ; count < 4 ; count++)
{
    Number phi = count * 2 * Pi()/ 4
    Number px = round(cx+radius*Cos(phi))
    Number py = round(cy+radius*Sin(phi))
    Result(py + ", " + px + "\n")
    Component arrow = NewArrowAnnotation(cy, cx, py, px)
    arrows.ComponentAddChildAtEnd(arrow)
}

img_disp.ComponentAddChildAtEnd(arrows)

Questions:

  1. What could cause the coordinate discrepancy between the marker group and the ImageDisplay?
  2. How can I ensure that the marker group uses the same coordinate system as ImageDisplay when adding arrow markers?
Share Improve this question asked Mar 4 at 13:58 ChenZXChenZX 3372 silver badges11 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

The details of how coordinate systems are inherited by child Components of various types are very unclear to me and I have not found any place in the DM documentation that fully spells this out. Perhaps someone else can point us to a clearer explanation.

However, it does seem to be clear that group annotations do not have a well-defined coordinate system of their own and thus adding new (previously unplaced) annotations to a group often does not yield the desired result. The better approach seems to be to first place new annotations on the desired ImageDisplay and then add such placed annotations to a group in order to achieved the desired association of daughter Components, as follows:

Number imgW = 256
Number imgH = 256
Image img := RealImage("RImg",4,imgW,imgH)
img.ShowImage()
ImageDisplay img_disp = img.ImageGetImageDisplay(0)
ImageDocument img_doc = img.ImageGetOrCreateImageDocument()
Component arrows = NewGroupAnnotation()
img_disp.ComponentAddChildAtEnd(arrows)

Number radius = 50
Number cx = imgW/2
Number cy = imgH/2
for (Number count = 0 ; count < 4 ; count++)
{
    Number phi = count * 2 * Pi()/ 4
    Number px = round(cx+radius*Cos(phi))
    Number py = round(cy+radius*Sin(phi))
    Component arrow = NewArrowAnnotation(cy, cx, py, px)
    img_disp.ComponentAddChildAtEnd(arrow)
    arrows.ComponentAddChildAtEnd(arrow)
}

TagGroup properties = NewTagGroup()
arrows.ComponentExternalizeProperties(properties)
properties.TagGroupOpenBrowserWindow(0)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745039754a4607739.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信