#pragma TextEncoding = "UTF-8" #pragma rtGlobals=3 #pragma version=1.06 #pragma IgorVersion=7 #pragma moduleName=encircle #include // --------------------- Project Updater header ---------------------- // If you're using Igor Pro 7 or later and have Project Updater // installed, this package can check periodically for new releases. // http: www.igorexchange.com/project/Updater static constant kCHECK_FOR_UPDATES=1 // set to 1 to check for updates on init static function CheckForUpdates() if(kCHECK_FOR_UPDATES) #if (exists("Updater#UpdateCheck")==6) return Updater#UpdateCheck("fileloc:"+FunctionPath("")) #endif endif return 0 end // -------------------------------------------------------------------- // by tony.withers@uwo.ca // Description // draws a polgon around a cloud of data points on a plot. // How to use // Right click on a data point to invoke the trace menu and select // "Encircle points" to encicle all of the data in the wave. // Right click within marquee and select a wavename to encircle a subset // of data within that wave. // If you reshape the graph window you can repeat this procedure to // update the shape of the polygon. // Selecting "Remove Encircled Region" deletes the shaded region. // Polygons are drawn in the user back layer and can be edited with the // drawing tools. // Details // It makes most sense to apply this to x-y data. // Version history // 1.06 allows selection of a subset of points using the marquee, // but still limited to one encircled group of points per wave // 1.03 if Package Updater is installed, will check IgorExchange for new releases // 1.02 deal with offsets // 1.01 bug fix: remove gratuitous print statement // Wishlist // Allow user to select a region and encircle only the data that plot // within that region // could use GraphWaveDraw to select a group of points Menu "TracePopup" "Encircle points", /Q, encircle#DrawBoundingSpline() "Remove encircled region", /Q, encircle#RemoveBoundingSpline() end Menu "GraphMarquee", dynamic submenu "Encircle points" encircle#TracesInMarquee(), /Q, encircle#DrawBoundingSpline() end end static function DrawBoundingSpline() if (CheckForUpdates()) return 0 // this file has been updated; quit to allow user to reload endif // initialize (or reinitialize) the package data folder NewDataFolder /O root:Packages NewDataFolder /O root:Packages:Encircle // Create a data folder reference variable DFREF dfr = root:Packages:Encircle variable isMarquee=0 // figure out graph and trace names GetLastUserMenuInfo if (cmpstr(s_value, "Encircle points")) isMarquee=1 S_traceName=s_value endif string s_info=traceinfo(S_graphName, S_traceName, 0) if(numtype(NumberByKey("AXISZ",s_info))==0) doalert 1, "you've selected a contour trace. Continue?" if (v_flag==2) return 0 endif endif variable xOffset=GetNumFromModifyStr(s_info,"offset","{",0) variable yOffset=GetNumFromModifyStr(s_info,"offset","{",1) if(strlen(stringbykey("XWAVE",s_info))==0) duplicate /free tracenametowaveref(S_graphName, S_traceName), xdata xdata=x else wave xdata=XWaveRefFromTrace(S_graphName, S_traceName) endif wave ydata=tracenametowaveref(S_graphName, S_traceName) variable i if(isMarquee) make /free/n=0 xPoly, yPoly string StrXAxisName=stringbykey("XAXIS", TraceInfo("", S_traceName, 0 )) string StrYAxisName=stringbykey("YAXIS", TraceInfo("", S_traceName, 0 )) getmarquee /K $StrXAxisName, $StrYAxisName xPoly={v_left,v_left,v_right,v_right} yPoly={v_top, v_bottom, v_bottom, v_top} xPoly-=xOffset yPoly-=yOffset findPointsInPoly xdata, ydata, xPoly, yPoly wave W_inPoly=W_inPoly make /free/n=0 x_subset, y_subset for(i=0;i(vertices-1))] y_hull=W_YHull[p-(vertices)*(p>(vertices-1))] // find the centroid of the hull variable x0=0, y0=0, varA=0 variable factor for(i=0;i(np-1))] y_temp=ydata[p-(np-1)*(p>(np-1))] make /free /n=(segPoints) x_out, y_out make /free /n=4 x_in, y_in variable i for(i=1;i