⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mp.pkg

📁 LastWave
💻 PKG
📖 第 1 页 / 共 2 页
字号:
#;; -*- Mode: Tcl -*-#..........................................................................#                                                                         #      L a s t W a v e    P a c k a g e 'mp' 2.0##      Author Emmanuel Bacry and Remi Gribonval#      #      File associated the mp package#                                                                    #..........................................................................# We need those packages for the Matching Pursuit# Test if the package STFT is already loaded, if not load itif ([package list 'stft'][0][1]==0) {    package load 'stft'}source MPDalgorithms## Let's create some book structures m,n# and the corresponding script for changing the objCur#if ([var exist m] == 0) {  foreach book "m n" {    # let's create the book    bk=[new &book]    bk.name=book    # Set it to the right variable    $book = bk    # and create the corresponding command    # It has to import the 'objCur' from the calling environement and the book from the global one    # and to set the first to the second one      setproc $book {} "{{{} {Changes the objCur variable to the book '$book'.}}}" \      %%`\      import args 1 $book      import args -1 objCur      objCur = null      objCur = $book      return    `  }  objCur=null  objCur=m  var delete book  var delete bk}## Dealing with the DISPLAY of BOOKs## The default position of book windowsdisp.book.rect={370 55 700 500}# Perform zoom on books with the mouse : there are two modesSetZoomBindings GraphBook {'rect' 'xrect'}## Perform cursor displaying on books : there are three modes# -no cursor at all# -a simple cross# -a rectangle aroung (all) the atom(s) of the "closest" molecule## # Regular cursor ## Print a caption with the time-frequency location of the mouse setproc _CursorTextGraphBook {}  {  book=[setg @object -graph]  # Get the time location (in real coordinates)  # and convert it into sample coordinates   index      = int((@x-book.x0)/book.dx+.5)  if (index < 0) {index=0}   if (index >= book.signalSize) {index=book.signalSize-1}   # Get the frequency location (in real coordinates)  # and convert it into sample coordinates   freq = int(@y*2*book.freqIdNyquist*book.dx+.5)  if (freq < 0) {freq=0}   if (freq > book.freqIdNyquist) {freq=book.freqIdNyquist}   return "$@objname : t=$@x [$index] f=$@y [$freq]" }setproc _DrawCursorNoneGraphBook {{&var cursor}} {  cursor.erase=null  return [_CursorTextGraphBook]}setproc _DrawCursorGraphBook {{&var cursor}}  {  # Draw the cross in inverted mode  _ViewDrawCrossHair cursor.view $@x $@y  # The very same command will erase the cursor  cursor.erase=%%`_ViewDrawCrossHair '$cursor.view' $@x $@y`  return [_CursorTextGraphBook]}## Cursor that circles the closest molecule#SetSuperposeBindings GraphBookbinding delete 'BookArrow'# Text relative to the circled molecule that must be be printed setproc _CursorClosestMolTextGraphBook {obj {&mol mol} {&int rank}}  {    # Check whether the molecule contains a harmonic structure or not    if (mol.dim != 1) {	harm="(h)"    } else {	harm=""    }    energy=mol.coeff2    s=mol[0].dt    t=mol[0].time    f=mol[0].freq    c=mol[0].chirp    sId=mol[0].windowSize    tId=mol[0].timeId    fId=mol[0].freqId    cId=mol[0].chirpId    return "$obj : #$rank $harm a=$energy s=$s [$sId] t=$t [$tId] f=$f [$fId] c=$c [$cId]"}# Draw as many 'rectangles' as needed around the atom(s) of a molecule setproc _DrawMolRect {obj {&mol mol} {&int rank}} {    # Prepares a list of options for drawing the 'rectangles'    list = ""    for {k=0} (k<mol.dim) {k=k+1} {	atom=mol[k]	if (atom is null) {continue}	freq       = atom.freq	time       = atom.time	chirp      = atom.chirp	dt         = atom.dt	df         = atom.df	# Deal with asymetric atoms	if (atom.windowShape == 'FoF' || atom.windowShape == 'exponential') {	    time = time+dt  	}	if (k>0) {list = list+" "}	list=list+"{$time $freq $dt $df $chirp}"    }    global bindings    bindings.GraphBook.BookArrow.rank=rank    command="_DrawNParallelograms '$@objname' "+"{$list}"    _SuperposeReplace $@objname 'molrect' "$command"}setproc _DrawCursorClosestMolGraphBook {{&var cursor}}  {  # Get the closest molecule and its rank  book=[setg @object -graph]  l=[setg @object -?closest $@x $@y]  # If there is none, do nothing  if (l==null) {    cursor.erase=null    return  }  # If there is one, check if it is visible   {n k}=l  mol   = book[n]  freq  = mol[0].freq  time  = mol[0].time  scale = mol[0].windowSize  # Get the time-freq rectangle that is displayed  {x0 x1 y0 y1} = [setg ${@objname}.^ -bound]  # Get the scale range that is displayed  {smin smax}   = [setg $@objname -s]  if (x0 > time || time > x1 || y0 > freq || freq > y1 || smin > scale || scale > smax) {    # No, it is not visible!    cursor.erase=null    return  }  # draw the appropriate rectangle(s) around its atom(s)  _DrawMolRect '$@objname' mol n  cursor.erase=%%`SuperposeDelete $@objname 'molrect'`  return [_CursorClosestMolTextGraphBook '$@objname' mol n]}SetCursorBindings GraphBook {%_DrawCursorNoneGraphBook %_DrawCursorGraphBook %_DrawCursorClosestMolGraphBook}# Draw a list of parallelogramssetproc _DrawParallelogram {obj {&listv i} {&word clip ``}} {    {t f dt df c}=i    options="-mode 'inverse' $clip"    eval %%`draw point  $obj t-dt f-c*dt-df $options`    eval %%`draw lineto $obj t-dt f-c*dt+df $options`    eval %%`draw lineto $obj t+dt f+c*dt+df $options`    eval %%`draw lineto $obj t+dt f+c*dt-df $options`    eval %%`draw lineto $obj t-dt f-c*dt-df $options` }setproc _DrawNParallelograms {obj {&word list} {&word clip ``}} {    lv = $list    foreach i lv {	_DrawParallelogram  '$obj' i $clip  }} # Draw a rectangle around the 'molecule' setproc _DrawMol {{&mol mol} {&int rank}} {    _DrawMolRect '$@objname' mol rank    setgu ${@objname}.^.^.box -string [_CursorClosestMolTextGraphBook '$@objname' mol rank]}# When we leave the graph we delete the global variablessetproc _LeaveMol {} {  SuperposeDelete @object 'molrect'   _DeleteEmptyGlobalArray bindings.GraphBook.BookArrow}# We start from a molecule book[rank] and return the rank of the next # (resp. previous) visible one. 'Next' (resp. previous) is meant in the# large/strict sense depending on the value of flagStrict. # For example the 'next' is :# -if flagStrict==0 : the smallest n>=rank such that book[n] is visible# -if flagStrict==1 : the smallest n> rank such that book[n] is visible## If no such visible molecule is visible we return -1setproc _GetMol {{&book book} {&int rank} {&string field} {&int flagStrict}} {    if (![msge ${@objname}.^ class 'View']) return    # Get the time-freq rectangle that is displayed    {x0 x1 y0 y1} = [setg ${@objname}.^ -bound]    # Get the scale range that is displayed    {smin smax}   = [setg $@objname -s]    # The direction in which we should look    if (field == "next") {	incr=1    } elseif (field == "prev")  {	incr=-1    } else {	errorf "Unknown &mol field %s"  field    }    # Now we loop to find the closest molecule that is displayed    for {n=rank+incr*flagStrict} (n>=0 && n<book.size) {n=n+incr} {	mol=book[n]	# Is the molecule visible ?	freq = mol[0].freq	time = mol[0].time	{timemin timemax} = mol[0].support	scale = mol[0].windowSize	if (x0 <= time && time <= x1 && y0 <= freq && freq <= y1 && smin <= scale && scale <= smax) {	    # Yes, it is visible!	    return n	}    }    return -1}setproc _DrawFirstMol {} {    book=[setg @object -graph]    rank=[_GetMol book 0 'next' 0]    if (rank<0) {return}    _DrawMol book[rank] rank}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -