IMcImageSetNextAccessPriority Method |
![]() |
Namespace: MediaCy.IQL.Engine
Sub SetNextAccessPriority ( Optional BasePriority As Double = 110, <OptionalAttribute> FramesSelector As Object, Optional DeltaEndPriority As Double = -5 )
'Create a multiframe image and set every other frame to white Private Function MakeBigSequence(nFrames As Long) As McImage Dim typeBS As McImageType Set typeBS = New McImageType typeBS.Initialize mcoFlatArray, mcpdtInteger, mciMonochrome, mcbpc8Bits, 1 ' typeBS.Initialize mcoDIBArray, mcpdtInteger, mciMonochrome, mcbpc8Bits, 1 'note: typeBS is the same as mciqtGray (i.e., 8-bit monochrome) Dim imgBS As McImage Set imgBS = Images.Add("BigSeq", 1024, 1024, nFrames, typeBS) ' Set imgBS = Images.Add("BigSeq", 1024, 1024, nFrames, typeBS, mcicfContiguous) Set typeBS = Nothing ' 'set even numbered frames to white imgBS.ActiveFrameRange = McOpMul(McOpFillIn(0&, nFrames / 2), 2) '0 to nFrames-2 step 2 imgBS.UseActiveFrameRange = True imgBS.Clear , 255 Set MakeBigSequence = imgBS 'NOTE: on exit the ActiveFrameRange is left set to even numbered frames End Function 'MakeBigSequence 'Set the AOI of frames in the active frame range to ascending gray levels Private Sub SetSequenceToAscendingGray(img As McImage) 'set ActiveFrameRange frames NextAccessPriorty from 110 down to 105 img.SetNextAccessPriority 110, img.ActiveFrameRange, -5 img.SetNextAccessPriority 'same as above using defaults 'Get the ActiveFrameRange as a McFrames collection Dim framesActiveRange As McFrames Set framesActiveRange = img.Frames(img.ActiveFrameRange) 'Show a progress meter Dim bs As McBusyState Set bs = SetBusyState bs.SetProgressInfo "Ascending gray", mcpacTopLevelCancelOnly, 0, framesActiveRange.Count 'loop frames, setting the AOI of each to an ascending gray value Dim dGryStep As Double, dGry As Double, lFrame As Long dGryStep = (img.RangeMax - img.RangeMin) / framesActiveRange.Count dGry = img.RangeMin img.BeginEndUpdateBlock True 'begin update block For lFrame = 0 To framesActiveRange.Count - 1 If bs.SetProgress(lFrame) Then Exit For 'allow user to cancel operation Dim raT As McRegionAccess Set raT = img.Aoi.AccessMaskedImageData(, , framesActiveRange(lFrame).FrameIndex) raT.SetToConstant dGry 'we are done with this frame, release raT 1st, so Set raT = Nothing 'it does not try to set NextAccessPriority 'we likely won't need this frame again soon, so set it to framesActiveRange(lFrame).NextAccessPriority = 100 'the default priority dGry = dGry + dGryStep 'for next loop Next 'lFrame img.BeginEndUpdateBlock False 'end update block End Sub 'SetSequenceToAscendingGray Sub RunATest() 'Note: NextAccessPriority is all about controlling swapping to disk, 'so we need to create an image that is big enough to cause swapping. 'Each frame created by MakeBigSequence is a Megabyte, so 1024 frames is 1 GB. 'With the memory management defaults, swapping starts when 80% of physical 'memory is used. In the test below, 128 frames are created, but the 'MemoryUsageLimit is set to 5 percent, so swapping occurs much more frequently 'than it would with the default of 80 percent. ' Dim nReplyToMsgBox As Integer nReplyToMsgBox = MsgBox("WARNING: This example is designed to test disk swapping and so takes a long time." + vbCrLf + _ "You can press Esc at any time to end it, but unless you want to test swapping don't run it." + vbCrLf + _ "Continue with the test?", vbDefaultButton2 + vbYesNo) If nReplyToMsgBox = vbNo Then Exit Sub 'ELSE go for it. RestoreMemoryManagerDefaults 'Set Memory swapping parameters to defaults Dim nFrames As Long ' nFrames = 1024 nFrames = 128 Dim imgMBS As McImage Set imgMBS = MakeBigSequence(nFrames) 'leaves ActiveFrameRange at even frames only 'Make memory swapping parameters tighter, so swapping will happen earlier Images.MemoryVirtualReserve = 50 'lots of reserve Images.MemoryUsageLimit = 5 'small percentage, so swap a lot 'Create an elliptical AOI imgMBS.Aoi.SetEllipse -1, 250, 250, 200, 150 'Set the AOI of the ActiveFrameRange frames to increasing Gray SetSequenceToAscendingGray imgMBS imgMBS.ActiveFrameRange = -1 'Set ActiveFrameRange to display all frames ActiveWindow.View.SequencePlayForward 'and play the sequence End Sub 'RunATest Sub RestoreMemoryManagerDefaults() Images.MemoryVirtualReserve = 10 Images.MemoryUsageLimit = 80 End Sub 'RestoreMemoryManagerDefaults