IMcRegionsGetFeaturePointsEx Method |
![]() |
Namespace: MediaCy.IQL.Features
Function GetFeaturePointsEx ( Optional FeatureIndex As Integer = 0, <OptionalAttribute> <OutAttribute> ByRef PointsResults As Object, Optional ResultType As mcOutlineType = mcOutlineType.mcotNoGaps, <OptionalAttribute> OperationValue As Object, Optional Flags As mcGetFeaturePointsExFlags = mcGetFeaturePointsExFlags.gfpxDefault ) As Integer
'This is GetFeaturePointsExSamples.bas Option Explicit '**** Utility Sub's and Function's **** 'Run this to clear all standard McFeatures Sub ResetTheStandardMcFeatures() If ActiveImage Is Nothing Then Exit Sub With ActiveImage .PointFeatures.Reset 'clear any existing standard features .LineFeatures.Reset .RegionFeatures.Reset End With 'ActiveImage End Sub 'ResetTheStandardMcFeatures Sub LetUserCreateSomeFeature(theMcFeatures As McFeatures, graphObjType As String) If theMcFeatures Is Nothing Then Exit Sub ResetTheStandardMcFeatures 'clear any existing standard features theMcFeatures.AutoDisplay = True theMcFeatures.AutoDisplayOverlay.SelectTool , graphObjType, mcgtStandardAutoDisplay End Sub 'LetUserCreateRegionFeature 'Run this to let the user create a polygon RegionFeatures feature Sub LetUserCreateRegionFeature() If ActiveImage Is Nothing Then Exit Sub LetUserCreateSomeFeature ActiveImage.RegionFeatures, "McGraphObjPoly" End Sub 'LetUserCreateRegionFeature Function CheckForNoRegionFeature() As Boolean CheckForNoRegionFeature = True 'assume no feature If ActiveImage Is Nothing Then Exit Function If ActiveImage.RegionFeatures.Count = 0 Then MsgBox "You need to create a closed region." LetUserCreateRegionFeature Exit Function End If 'no features 'ELSE we have at least one feature CheckForNoRegionFeature = False 'we have a feature End Function 'CheckForNoRegionFeature 'Run this to let the user create an open polyline LineFeatures feature Sub LetUserCreatePolyLineFeature() If ActiveImage Is Nothing Then Exit Sub LetUserCreateSomeFeature ActiveImage.LineFeatures, "McGraphObjPoly" End Sub 'LetUserCreatePolyLineFeature Function CheckForNoLineFeature() As Boolean CheckForNoLineFeature = True 'assume no feature If ActiveImage Is Nothing Then Exit Function If ActiveImage.LineFeatures.Count = 0 Then MsgBox "You need to create a polyline." LetUserCreatePolyLineFeature Exit Function End If 'no features 'ELSE we have at least one feature CheckForNoLineFeature = False 'we have a feature End Function 'CheckForNoLineFeature 'Run this to let the user create a set of PointFeatures feature Sub LetUserCreatePointFeatures() If ActiveImage Is Nothing Then Exit Sub LetUserCreateSomeFeature ActiveImage.PointFeatures, "McGraphObjPoint" End Sub 'LetUserCreatePointFeatures Function CheckForNoPoints(Optional nNeeded As Long = 2) As Boolean CheckForNoPoints = True 'assume no feature If ActiveImage Is Nothing Then Exit Function If ActiveImage.PointFeatures.Count < nNeeded Then MsgBox "You need to create a at least " & nNeeded & " points." LetUserCreatePointFeatures Exit Function End If 'no features 'ELSE we have at least 3 points CheckForNoPoints = False 'we have a feature End Function 'CheckForNoPoints 'The following routine executes GetFeaturePointsEx on the zero'th feature (or all 'features for a McPoints) and displays the results overlying the orignal display. Sub DoGetFeaturePointsEx(theMcFeatures As McFeatures, ResultType As mcOutlineType, _ Optional OpValue As Variant, Optional Flags As mcGetFeaturePointsExFlags = gfpxDefault) Dim lNpts As Long, ptsResult As Variant ptsResult = Empty lNpts = theMcFeatures.GetFeaturePointsEx(0, ptsResult, ResultType, OpValue, Flags) 'We display the result as a McPoints, McRegions or as a McLines, depending on the source and Flags Dim bResultIsClosed As Boolean, mcfeaturesResults As McFeatures bResultIsClosed = ((theMcFeatures.Type(-1) And mcftEmptyRegions) <> 0) Or _ ((Flags And gfpxClosedBoundary) <> 0) Or (ResultType = mcotConvex) 'For the interpolation tests show results as points Dim lResultFeature As Long lResultFeature = 0 'for McLines or McRegions If ResultType = mcotSetNumbers Or ResultType = mcotSetSpacing Then Set mcfeaturesResults = CreateOperator("McPoints", theMcFeatures) lResultFeature = -1 'result is all features of this McPoints 'Else we create either a McRegions or McLines as a child of theMcFeatures ElseIf bResultIsClosed Then 'result points are a closed polygon? Set mcfeaturesResults = CreateOperator("McRegions", theMcFeatures) Else 'result points are an open polyline Set mcfeaturesResults = CreateOperator("McLines", theMcFeatures) End If 'fi result points an open polyline mcfeaturesResults.AutoDisplay = True mcfeaturesResults.SetFeaturePoints lResultFeature, ptsResult mcfeaturesResults.DisplayedObjects.SetColors &HFFFF& 'make the overlay yellow If lResultFeature = -1 Then MsgBox "The interpolated points show in yellow." & vbCrLf & "They will disappear when you press OK." Else MsgBox "The transformed line shows in yellow." & vbCrLf & "It will disappear when you press OK." End If End Sub 'DoGetFeaturePointsEx '***** Here are the test Sub's ****** 'Convex hull Sub DoConvexHull() If CheckForNoRegionFeature Then Exit Sub DoGetFeaturePointsEx ActiveImage.RegionFeatures, mcotConvex, 0, gfpxConstantArea End Sub 'DoConvexHull Sub DoConvexHullOnPoints() If CheckForNoPoints(3) Then Exit Sub DoGetFeaturePointsEx ActiveImage.PointFeatures, mcotConvex, 0, gfpxConstantArea End Sub 'DoConvexHullOnPoints 'Filtering Sub DoSmoothBoundary() If CheckForNoRegionFeature Then Exit Sub 'smooth over 10 pixels DoGetFeaturePointsEx ActiveImage.RegionFeatures, mcotFilter, 10, gfpxConstantArea End Sub 'DoSmoothBoundary Sub DoSmoothPolyline() If CheckForNoLineFeature Then Exit Sub 'smooth the polyline over 12 pixels DoGetFeaturePointsEx ActiveImage.LineFeatures, mcotFilter, 12 End Sub 'DoSmoothPolyline 'Interpolation Sub DoSetNumbersOfVertices() If CheckForNoRegionFeature Then Exit Sub 'Break boundary into 5 vertices DoGetFeaturePointsEx ActiveImage.RegionFeatures, mcotSetNumbers, 5 End Sub 'DoSetNumbersOfVertices Sub DoSetSpacingOfLineVertices() If CheckForNoLineFeature Then Exit Sub 'Break polyline into vertices 20 units apart DoGetFeaturePointsEx ActiveImage.LineFeatures, mcotSetSpacing, 20 End Sub 'DoSetSpacingOfLineVertices 'Fill gaps Sub DoBoundaryFillGaps() If CheckForNoRegionFeature Then Exit Sub 'convert boundary into 1-pixel steps DoGetFeaturePointsEx ActiveImage.RegionFeatures, mcotNoGaps End Sub 'DoBoundaryFillGaps 'Getting LONGPOINT results and 4-connected mcotNoGaps results on a McLines Sub NoGapsLineWithAndWithout8Connect() With ActiveImage.LineFeatures .Reset ActiveImage.RegionFeatures.Reset ActiveImage.PointFeatures.Reset .SetFeaturePoints 0, Array(1, 1, 10, 10) 'line at 45 degrees .OptionFlags(mcofConnect8) = mcofConnect8 'make sure it's 8-connected 'First, show the original vertices on a zoomed display ActiveWindow.View.Magnification = 16# ' magnify the display Dim varPtsOriginal As Variant .GetFeaturePoints 0, varPtsOriginal ActiveImage.PointFeatures.SetFeaturePoints -1, varPtsOriginal MsgBox "The display shows the two original vertices of the 45 degree line segment" 'Do the no-gaps Get the number of result points first Dim nPts As Long nPts = .GetFeaturePointsEx(0, , mcotNoGaps) ReDim ptsNoGaps(nPts - 1) As LONGPOINT .GetFeaturePointsEx 0, ptsNoGaps, mcotNoGaps 'show the result ActiveImage.PointFeatures.SetFeaturePoints -1, ptsNoGaps MsgBox "The display shows the 8-connected no-gap vertices of the 45 degree line segment" 'repeat no-gaps with the McLines 4-connected .OptionFlags(mcofConnect8) = mcofNoFlags 'make it 4-connected nPts = .GetFeaturePointsEx(0, , mcotNoGaps) ReDim ptsNoGaps(nPts - 1) As LONGPOINT .GetFeaturePointsEx 0, ptsNoGaps, mcotNoGaps 'now show the result ActiveImage.PointFeatures.SetFeaturePoints -1, ptsNoGaps MsgBox "The display shows the 4-connected no-gap vertices of the 45 degree line segment" 'restore the default 8-connected state, .OptionFlags(mcofConnect8) = mcofConnect8 'which is 8-connected End With 'ActiveImage.LineFeatures End Sub 'NoGapsLineWithAndWithout8Connect
'Get convex hull of RegionFeatures feature zero 'get the convex hull of feature 0 as an array of SINGLEPOINT Dim varConvexHull As Variant varConvexHull = Empty Dim lNumPoints As long lNumPoints = ThisApplication.ActiveImage.RegionFeatures.GetFeaturePoints(0, varConvexHull, mcotConvex, , gfpxConstantArea) 'Or get the convex hull of feature 0 as an array of LONGPOINT ' get number of points lNumPoints = ThisApplication.ActiveImage.RegionFeatures.GetFeaturePointsEx( 0, , mcotConvex, , gfpxConstantArea) ' get the points result as integral points ReDim ptsConvex( lNumPoints-1) As LONGPOINT ThisApplication.ActiveImage.RegionFeatures.GetFeaturePoints(0, ptsConvex, mcotConvex, , gfpxConstantArea)