How to get the angle of line annotation?

31 Views Asked by At

If I have one line annotation in the image display, how can I get the angle? If there are multiple lines, is that possible to know the creation sequence of each line?

1

There are 1 best solutions below

0
BmyGuest On BEST ANSWER

The order of components when iterating is from "topmost" to "bottommost". You just gets the line annotations' endpoints and perform the math.

ClearResults()
number kLIneAnno = 2
number kLineStart = 1
number kLineEnd = 2
imagedisplay disp = GetFrontImage().ImageGetImageDisplay(0)

number nComp = disp.ComponentCountChildren()
for( number i=0; i<nComp; i++ ){
    component comp = disp.ComponentGetChild(i)
    if ( comp.ComponentGetType()!= kLIneAnno ) continue
    Result("\n Line Annotation:")
    number sx,sy,ex,ey
    comp.ComponentGetControlPoint(kLinestart,sx,sy)
    comp.ComponentGetControlPoint(kLineend,ex,ey)
    Result("\n\t From: " + sx + " / " +sy)
    Result("\n\t To  : " + ex + " / " +ey)
    
    number angleRad = Atan2(-1*(ey-sy),(ex-sx)) // -1 because +Y is downwards in images
    Result("\n\t Angle:" + (180*angleRad/Pi())) 
}