Freigeben über


SelfIntersections Property

SelfIntersections Property

Returns the self-intersections of the stroke.

Declaration

[C++]

[propget] HRESULT get_SelfIntersections (
    [out, retval] VARIANT* SelfIntersections
);

[Microsoft® Visual Basic® 6.0]

Public Property Get SelfIntersections() As Variant

Property Value

VARIANT An array of floating point index values that represents the self-intersections of a IInkStrokeDisp object.

This property is read only.

For more information about the VARIANT structure, see Using the Automation Library.

Return Value

HRESULT value Description
S_OK Success.
E_POINTER The parameter pointer was NULL or invalid.
E_OUTOFMEMORY Cannot allocate memory for the points.
E_INK_EXCEPTION An exception occurred inside the method.

Remarks

A self-intersection is the point of a stroke where the stroke crosses over itself.

A floating point index is a float value that represents a location somewhere between two points in the stroke. As examples, if 0.0 is the first point in the stroke and 1.0 is the second point in the stroke, 0.5 is halfway between the first and second points. Similarly, a floating point index value of 37.25 represents a location that is 25 percent along the line between points 37 and 38 of the stroke.

Note: A floating point index is returned for each intersection and line segment combination. If a stroke has one intersection, this property returns two self intersections, one for each line segment that is part of the intersection.

Example

[Visual Basic 6.0]

This Visual Basic 6.0 example demonstrates displaying several kinds of information that is recorded with each IInkStrokeDisp object. The calling program uses menu items to toggle the display of each strokes points, Bezier points, Bezier cusps, and self-intersections. The InkRenderer object's InkSpaceToPixelFromPoints method is used to convert the points for display. The LocatePoint helper function is used to interpolate the locations of the self-intersections.

Option Explicit
Option Base 0
Dim WithEvents theInkCollector As InkCollector

Private Sub Form_Load()
    Me.ScaleMode = vbPixels
    Set theInkCollector = New InkCollector
    theInkCollector.hWnd = Me.hWnd
    theInkCollector.Enabled = True
End Sub

Private Sub Form_Paint()
    Dim i As Integer
    Dim theStrokes As InkStrokes
    Set theStrokes = theInkCollector.Ink.Strokes
    Dim theStroke As IInkStrokeDisp
    For Each theStroke In theStrokes
        Dim ptBezierPoints() As Long
        ptBezierPoints = theStroke.BezierPoints
        Dim ptStrokePoints() As Long
        ptStrokePoints = theStroke.GetPoints()
        theInkCollector.Renderer.InkSpaceToPixelFromPoints Me.hDC, ptBezierPoints
        theInkCollector.Renderer.InkSpaceToPixelFromPoints Me.hDC, ptStrokePoints
        If MenuDemoCusps.Checked Then
            Dim theCusps() As Long
            theCusps = theStroke.BezierCusps
            For i = 0 To UBound(theCusps)
                'Draw a little rectangle around each Bezier cusp.
                Dim cuspX As Long
                Dim cuspY As Long
                cuspX = ptBezierPoints(theCusps(i) * 2)
                cuspY = ptBezierPoints(theCusps(i) * 2 + 1)
                Line (cuspX - 2, cuspY - 2)-Step(5, 5), vbRed, B
            Next
        End If
        If MenuDemoPoints.Checked Then
            For i = 0 To UBound(ptBezierPoints) Step 2
                'Draw a little diagonal line up from each Bezier point.
                Line (ptBezierPoints(i), ptBezierPoints(i + 1)) _
                    -Step(4, -4), vbBlue
            Next
        End If
        If MenuDemoAllPoints.Checked Then
            For i = 0 To UBound(ptStrokePoints) Step 2
                'Draw a little diagonal line down from each point.
                Line (ptStrokePoints(i), ptStrokePoints(i + 1)) _
                    -Step(-4, 5), vbMagenta
            Next
        End If
        If MenuDemoSelfIntersections.Checked Then
            Dim theSelfIntersectionLocationsArray() As Single
            theSelfIntersectionLocationsArray = theStroke.SelfIntersections
            Dim theSelfIntersectionLocation As Variant
            For Each theSelfIntersectionLocation In theSelfIntersectionLocationsArray
                Dim pt() As Long
                pt = LocatePoint(theStroke, theSelfIntersectionLocation)
                theInkCollector.Renderer.InkSpaceToPixel Me.hDC, pt(0), pt(1)
                'Draw a little circle around each intersection.
                Circle (pt(0), pt(1)), 7, vbRed
            Next
        End If
    Next
End Sub

Private Sub MenuDemoAllPoints_Click()
    MenuDemoAllPoints.Checked = Not MenuDemoAllPoints.Checked
End Sub

Private Sub MenuDemoCusps_Click()
    MenuDemoCusps.Checked = Not MenuDemoCusps.Checked
End Sub

Private Sub MenuDemoPoints_Click()
    MenuDemoPoints.Checked = Not MenuDemoPoints.Checked
End Sub

Private Sub MenuDemoSelfIntersections_Click()
    MenuDemoSelfIntersections.Checked = _
        Not MenuDemoSelfIntersections.Checked
End Sub

Private Sub MenuFileExit_Click()
    Unload Me
End Sub

'This function returns the approximate point along
'a stroke represented by a Single, as a Point.
Private Function LocatePoint( _
ByVal theStroke As IInkStrokeDisp, _
ByVal theFIndex As Single) As Long()
    Dim theResult(1) As Long
    'Get the two nearest points to the point of interest.
    Dim ptStrokePoints() As Long
    ptStrokePoints = theStroke.GetPoints(Int(theFIndex), 2)
    If UBound(ptStrokePoints) < 2 Then
        'This must be an end point.
        theResult(0) = ptStrokePoints(0)
        theResult(1) = ptStrokePoints(1)
    Else
        'Get fractional part to interpolate the distance
        'between the points.
        Dim theFraction As Single
        theFraction = theFIndex - Int(theFIndex)
        Dim deltaX As Integer
        deltaX = _
            CInt((ptStrokePoints(2) - ptStrokePoints(0)) * theFraction)
        Dim deltaY As Integer
        deltaY = _
            CInt((ptStrokePoints(3) - ptStrokePoints(1)) * theFraction)
        'Return the interpolated point.
        theResult(0) = ptStrokePoints(0) + deltaX
        theResult(1) = ptStrokePoints(1) + deltaY
    End If
    LocatePoint = theResult
End Function

Private Sub theInkCollector_Stroke( _
ByVal Cursor As MSINKAUTLib.IInkCursor, _
ByVal Stroke As MSINKAUTLib.IInkStrokeDisp, _
Cancel As Boolean)
    Refresh
End Sub

Applies To