Do something to waves in marquee

This code permits the user to select a subset of waves in a graph by drawing a marquee around them, then choosing a command from the marquee menu that is executed on that subset of waves. The example here highlights the selected waves, but lots of other possibilities exist, such as deleting the waves, averaging them, hiding them, ....






#pragma rtGlobals=1     // Use modern global access method.
#include <Execute Cmd On List>  

Menu "GraphMarquee"
    "Do something to Waves in Marquee"
    "Do something else to Waves in Marquee"
End

Function pointInBox(px,py,bl,bt,br,bb)  // determine if point is in box
    variable px,py,bl,bt,br,bb
   
    return((px>bl && br>px) && (py>bb && bt>py))
End

Function waveThroughBox(w,bl,bt,br,bb)  // determine if wave w goes through box
    wave w
    variable bl,bt,br,bb
   
    variable pt,px
    for(pt=0;numpnts(w)>pt;pt+=1)
        px=DimOffset(w,0)+DimDelta(w,0)*pt
        if(pointInBox(px,w[pt],bl,bt,br,bb))
            return 1
        endif
    endfor
    return 0
End

Function/S WavesinBox(bl,bt,br,bb)  // get list of waves passing through box
    variable bl,bt,br,bb

    string retlst,aWv,wvl=WaveList("*",";","WIN:")
    retlst=""
    variable i
    for(i=0;ItemsinList(wvl)>i;i+=1)
        aWv=StringFromList(i,wvl)
        wave wv=$aWv
        if(waveThroughBox(wv,bl,bt,br,bb))
            retlst+=aWv+";"
        endif
    endfor
    return retlst
End

Function DoSomethingToWavesInMarquee()  // here, just highlighting traces

    GetMarquee/K left,bottom
    string waves2highlight=WavesinBox(V_left,V_top,V_right,V_bottom)
    ExecuteCmdOnList("ModifyGraph lsize(%s)=3",waves2highlight)
End

Function DoSomethingElseToWavesInMarquee()  // here, just reversing highlighting of traces

    GetMarquee/K left,bottom
    string waves2highlight=WavesinBox(V_left,V_top,V_right,V_bottom)
    ExecuteCmdOnList("ModifyGraph lsize(%s)=1",waves2highlight)
End



Function TestMarqueeWaves() // just puts some waves into a graph onto which one can draw a marquee and highlight some of the waves

    variable nwaves=10
    variable i
    string awv
    Display/W=(200,200,600,600)
    for(i=0;nwaves>i;i+=1)
        awv="w"+Num2Str(i)
        Make/O/N=100 $awv=gnoise(1)
        Smooth 11,$awv
        AppendtoGraph $awv
        ModifyGraph rgb($awv)=(65535*i/nwaves,65535*(1-i/nwaves),332767)
    endfor
    ModifyGraph mode=0
End

Forum

Support

Gallery

Igor Pro 8

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More