A Window Hook Function to display the Z-dimension of an image using cursor position
remolorio
Hi
In principle, I would like to extract the X (='row') and Y (='col') position of the cursor in an image plot, and display example3Dwave[row][col][] in a seperate window. This should update as I move the cursor in the image plot.
I have spent all morning going through the help files and the forum, but unfortunately it seems to be beyond my understanding how to, for example, adapt the demos version to my needs.
would anyone be so kind and help me with this task?
Many thanks and best wishes
Remo
Forum
Support
Gallery
Igor Pro 9
Learn More
Igor XOP Toolkit
Learn More
Igor NIDAQ Tools MX
Learn More
Is the Info panel not sufficient for your needs? For the image's top "Graph" menu, select "Show Info" (ctrl+I in Windows). The cursor(s) give position and 'z' data.
December 18, 2019 at 03:16 am - Permalink
It is necessary that the graph which plots the Z dimension updates automatically as one hovers over the image with the cursor - similar to the line profile utility under the image tab.
December 18, 2019 at 04:34 am - Permalink
Here's what I would try:
Make a plot of the image (Graph1), and a second plot of the slice of wave w:
Display /N=Graph2 w[0][0][]
create a window hook function
STRUCT WMWinHookStruct &s
// use s.mouseLoc.h and s.mouseloc.v to access mouse coordinates
end
Use SetWindow to invoke the hook function for mousemoved events
DisplayHelpTopic("SetWindow")
DisplayHelpTopic("Named Window Hook Functions")
DisplayHelpTopic("WMWinHookStruct")
Figure out how to translate the mouse coordinates to get the current value of p and q to feed to the ReplaceWave operation.
Function MyWindowHook(s)
STRUCT WMWinHookStruct &s
// use s.mouseLoc.h and s.mouseloc.v to access mouse coordinates
// translate coordinates to var1=p and var2=q
ReplaceWave /W=Graph2 trace=w, w[var1][var2][]
end
I don't think there's any way to do it without writing at least a bit of code.
It might be easier to do it with a cursor hook, rather than figuring out mouse coordinates. So instead of hovering with the mouse you would have to drop a cursor on a pixel to update Graph2.
DisplayHelpTopic("Programming With Cursors")
December 18, 2019 at 06:45 am - Permalink
This isn't quite what you are looking for, but I wrote some code for doing something similar with 2D waves. The code generates an image plot of the 2D wave, a plot of the slice along the row of the cursor, and a plot of the slice along the column of the cursor. It uses a window hook to automatically update the row and column plots whenever the cursor (on any of the three graphs) is moved. It's been a while since I've looked at the code, but I think it could be used along with Tony's suggestions to do what you want.
December 18, 2019 at 08:41 am - Permalink
This is modified from an existing package and uses a mouse click on an image instead of a cursor (pretty much what Tony suggested). Maybe this is of use.
Set up image
MatrixOP/O SumImage = Sumbeams(cube)
NewImage/N=image SumImage
Hook funktion:
STRUCT WMWinHookStruct &s
// create references to required waves
wave SumImage
wave cube
// where is the mouse?
variable xpos = AxisValFromPixel("", "Bottom", s.mouseLoc.h)
variable ypos = AxisValFromPixel("", "Left", s.mouseLoc.v)
variable xx = round (xpos / DimDelta(SumImage, 0))
variable yy = round (ypos / DimDelta(SumImage, 0))
variable maxX = DimSize(cube, 0)
variable maxY = DimSize(cube, 1)
switch(s.eventCode)
case 3: // handle left mouse click
// prevent error when clicking outside of image
if (xx >= maxX || yy >= maxY || xx < 0 || yy < 0)
break
endif
MatrixOp/O CrsSpec = beam(cube, xx, yy)
wave CrsSpec
doWindow/F PointSpectrum
if (V_flag==0)
Display/K=1/N=PointSpectrum CrsSpec
endif
break
endswitch
return 1
End
then use hook:
SetWindow Image,hook(s)=Hook
Then click on the image to display the z-direction.
December 18, 2019 at 12:47 pm - Permalink
Thank you very much for all of your answers, I used ChrLies approach and it does what I want. Nevermind the "hovering", that was inaccurate language as it turns out...
December 19, 2019 at 06:50 am - Permalink