Point-marker tool
DigitalMicrograph Script
Example tool to add transparent circle markers with label at clicked-on positions.
Preview
/////////////////////////////////////////////////////////////////////////////
// Tool to add transparent circle markers with label at clicked positions. //
/////////////////////////////////////////////////////////////////////////////
number kRasterDisplayType = 1
class CSimplePointLabeler
{
CSimplePointLabeler( object self ) { Result( "\n PointTool activated"); }
~CSimplePointLabeler( object self ) { Result( "\n PointTool stopped"); }
number listenID
number pointNr, radius
number colTrans, colR, colG, colB, colDim
object InitOnFront( object self, number startNr, number pRadius )
{
pointNr = startNr; radius = pRadius;
colTrans = 0.9; colR = 1; colG = 1; colB = 0; colDim = 0.7;
image front
if ( !GetFrontImage( front ) ) return self
imageDisplay disp = front.ImageGetImageDisplay( 0 )
if ( kRasterDisplayType != disp.ImageDisplayGetDisplayType() ) return self
string messageMap = "unassociated_click:OnClick"
listenID = ImageDisplayAddEventListener( disp, self, messageMap )
string message = "Click on the image to add numbered markers."
message += "\nStop the tool by clicking with the SHIFT key pressed."
OKDialog( message )
return self
}
void OnClick( object self, number f, ImageDisplay disp, number px, number py )
{
if ( ShiftDown() )
{
ImageDisplayRemoveEventListener( disp, listenID )
return
}
ROI marker = NewROI()
marker.ROISetCircle( px, py, radius )
marker.ROISetMoveable( 0 )
marker.ROISetVolatile( 0 )
marker.ROISetDrawFilled( 1 )
marker.ROISetFillProperties( colTrans, colR, colG, colB )
marker.ROISetColor( colR*colDim, colG*colDim, colB*colDim )
marker.ROISetLabel( "#" + pointNr )
disp.ImageDisplayAddROI( marker )
pointNr++
}
}
{
object labelTool = Alloc(CSimplePointLabeler).InitOnFront( 1, 10 )
}