Click or drag to resize

IMcRegions2GetOrderedPosition Method

Identifies the relative postion of features.

Namespace:  MediaCy.IQL.Features
Assembly:  MediaCy.IQL.Features (in MediaCy.IQL.Features.dll) Version: 10.0.6912.0
Syntax
VB
Function GetOrderedPosition ( 
	Optional Ordering As mcPositionOrdering = mcPositionOrdering.mcpoByBoundsMidPoint,
	<OptionalAttribute> Selector As Object
) As Object

Parameters

Ordering (Optional)
Type: MediaCy.IQL.FeaturesmcPositionOrdering
What feature bounds should be used to determine the postion order: the left,top (mcpoByLeftTopBound) or the center (mcpoByBoundsMidPoint) of the bounding rectangle. If not given, mcpoByBoundsMidPoint is the default.
Selector (Optional)
Type: SystemObject
An empty variant, a single negative value, a single index value, or an array of zero or more index values (negative index values are legal but will be ignored). If the Selector argument is a non-negative scalar value, then ordered position of the indicated feature from the collection is returned as a scalar Long value. If the Selector argument is missing, or any negative scalar value, then the ordered position of all features are returned as an array of Long values. The number of elements in the array will be equal to the Count property. This array may be subsequently used as a Selector argument for the GetFeatures method to extract features into an ordered McFeatures. If Selector is an array, then zero or positive values are treated as indices into the features collection, negative values are legal but ignored. In this case, the ordered position will be returned as an array of Long values equal to the length of the number of non-negative elements in the Selector array. Index values greater or equal to the Count property are illegal. If the argument is a McFeatures (i.e., McPoints, McLines or McRegions) or a McBitMask, then features that intersersect the selector's bit mask are selected as if an array of index values were supplied. If the OptionFlags mcofFullCoverageIntersectionTest bit is set, then the test is more stringent and a feature must be fully covered by the selector's bit mask in order to be included in the selection.

Return Value

Type: Object
Either a single feature index value or an array of feature index values, giving the ordered position of the selected features.

Implements

IMcRegionsGetOrderedPosition(mcPositionOrdering, Object)
Remarks
This method returns an index or selector (an array of such indices) giving the ordered position on all (the default) or selected features based on the feature bounding rectangle (see GetFeatureBoundingBox). The ordering is always from top to bottom, and then left to right. It may be based on either the Left, Top point of the bounding rectangle, or on the mid-point of the bounding rectangle (this is the default ordering). Many other feature orderings may be of interest to you. For example, you might wish to sort McRegions features by size or by McLines by the position of the end of each line feature. These orderings can usually be accomplished easily by passing a measurement value (or a value computed from measurements) to the McOMGlobal.McSort method, which will return a sorted selector. The Samples illustrate several of these orderings.
Examples
VB
'These samples illustrate various sortings of features based on
'feature properties

'Note: the BoneBig.jpg example image is a good one for these examples
Private Function uLoadExampleImage(Optional strImage As String = "BoneBig.jpg") As Boolean
    If MsgBox("Open example image?", vbYesNo) = vbYes Then
        Images.Open Path + "Images\" + strImage
        ActiveImage.Aoi.SetBox -1, 10, 10, 160, 160
        ActiveWindow.View.Magnification = 3#
    End If 'user wants to open an example image
    'Else leave the ActiveImage alone
    If ActiveImage Is Nothing Then
        MsgBox "There is no ActiveImage, so the example cannot run."
    Else
        Output.Show "Output"
        Output.Clear
        ActiveImage.RegionFeatures.Reset
        ActiveImage.LineFeatures.Reset
    End If
    uLoadExampleImage = ActiveImage Is Nothing
End Function 'uLoadExampleImage

'Show the ordering of region centroids from top-to-bottom, left-to-right
Public Sub OrderByPosition()
    If uLoadExampleImage Then Exit Sub
    With ActiveImage.RegionFeatures
        .Threshold.Execute 'get some regions
        Dim selOrdering() As Long
        selOrdering = .GetOrderedPosition(mcpoByBoundsMidPoint)
        Output.PrintMessage "Region mid-point ordering for " & .Count & " regions:" & vbCrLf & _
            McToText(selOrdering)
    End With 'ActiveImage.RegionFeatures
End Sub 'OrderByPosition

'Show the ordering of regions by area.  The smallest 1/2 of the areas are removed.
Public Sub OrderByAreaAndRemoveSmallerOnes()
    If uLoadExampleImage Then Exit Sub
    With ActiveImage.RegionFeatures
        .Threshold.Execute 'get some regions
        Dim selOrdering() As Long
        selOrdering = McSort(.mRgnArea)
        Output.PrintMessage "Region area-size ordering for " & .Count & " regions:" & vbCrLf & _
                McToText(selOrdering)
            'Now remove the smallest 1/2 of areas
        If .Count < 2 Then Exit Sub
        .RemoveFeature McOpSelect(selOrdering, McOpFillIn(0, .Count / 2))
    End With 'ActiveImage.RegionFeatures
End Sub 'OrderByAreaAndRemoveSmallerOnes

'Show the ordering of lines by the postion of their end-points.  Ordering of the
'end points is from top-to-bottom, left-to-right
Public Sub OrderByLineEndPoints()
    If uLoadExampleImage Then Exit Sub
    With ActiveImage.LineFeatures
        .SetFromMaskMethod = mcsfmmLinesLongestStraight
        .Threshold.Execute 'get lines across blobs
            'Since Points are x and y, we need to create a number that is
            'ordered by y and then x
        If .Count = 0 Then Exit Sub
        Dim dYthenX() As Double
        dYthenX = McOpAdd(McOpMul(McOpCast(.mLnEndY, "REAL"), 30000#), .mLnEndX)
        Dim selOrdering() As Long
        selOrdering = McSort(dYthenX)
            'Show the ordering on the image, fill SourceData with feature order
        Dim nL As Long
        For nL = 0 To .Count - 1
            .SourceData(selOrdering(nL)) = nL + 1
        Next nL
            'and show that as a label
        .DisplayedObjects.SetLabelText "%d", mcsltDisplaySourceData + mcsltLabelLineend  ' + mcgsLabelCenter

        Output.PrintMessage "Line ordering by EndPt for " & .Count & " lines:" & vbCrLf & _
            McToText(selOrdering)
    End With 'ActiveImage.LineFeatures
End Sub 'OrderByAreaAndRemoveSmallerOnes
See Also