Beruflich Dokumente
Kultur Dokumente
' automationDomination.sky
' by: Arton Oey
' Tested on 32-bit Windows 7 Cortex 4.1.1.1408 completed and tested with Mandi Gibbons on 07/24/15
'
'
' Functions:
' " Trims the ends of a video via first or last force plate detection minus a set time/frame "
' " Cubic joins or linear join depending on the short gap value determined "
' " Unname all markers and autoID all markers to correct for possible flip-flops "
' " Template rectify and Template ID prior to the cubic, virtual, or linear join "
' Dont use on all .caps because 10 undos is the limit
'
' TELL ME ALL ISSUES if a marker does exist and the program DID NOT TAKE IT INTO ACCOUNT
Sub SkyMain
' ====== SYNTAXES ====== '
Dim finalFrame As Integer = 100
Dim intialFrame As Integer = 100
Dim iHi As Integer = swLoadedTracks_GetNumberOfFrames()
Dim nMarkers As Integer = swGetData_NumberOfMarkers()
Dim i As Integer 'cant declare i inside the while loop unlike for
Dim j As Integer ' Man I hate not being able to resuse variables
Dim k As Integer
Dim start As Integer
Dim finish As Integer
Dim forces4THPLATE(7) As Single ' resets an array with 7 values
Dim forces2NDPLATE(7) As Single ' resets an array with 7 values
Dim forces1STPLATE(7) As Single ' resets an array with 7 values
Dim iMarker As Integer = 0
' ====== AUTOID AND DELETING FROM MARKERSET ANY NON EXISTENT MARKERS ====== '
i = 250 ' approximately start of force plate
'MsgBox("If a prompt asks to delete a marker, it is deleting it from the markerset because it doesnt exist. This
program requires that you delete it.")
'Dim shoulderMarker As Integer = swModel_GetMarkerIndex("R.Shoulder") ' markers used in every template
'Dim hipMarker As Integer = swModel_GetMarkerIndex("L.Hip")
'Dim thighMarker As Integer = swModel_GetMarkerIndex("L.Thigh.Upper")
While 1 'frame start at 90 coz midpoint likely to have all markers
swLoadedTracks_SetFrameNumber(i)
swPost_AutoID()
If i = 250
i=i+1
Continue While
End If
If swCancelled() Then
Message("Cancelled.")
Exit Sub ' dont use return
Else If i = 253
Message("Using a different frame range.")
i = 350
Else
For a As Integer = 0 To nMarkers - 1 '@ frame number i where it was defined
resultNow = swContext_GetMarkerPosition(a,X,Y,Z)
swLoadedTracks_SetFrameNumber(i - 1)
resultBefore = swContext_GetMarkerPosition(a,X,Y,Z)
If (resultNow = 1 And resultBefore = 1) And a < nMarkers - 1
Continue For' 0 = no data for marker 1 = data exists for the given marker
Else If (resultNow = 1 And resultBefore = 0) Or (resultNow = 0 And resultBefore = 1)
Exit For 'discrepancies exist
Else If a = nMarkers - 1 And (resultNow = 1 And resultBefore = 1)
swLoadedTracks_SetFrameNumber(i)
Exit While
End If
Next
End If
i=i+1
End While
swmarkers_selectnone()
'
'
'
"l.shank.upper"
'
swmarker_setselected(jmarker, 1)
'
selected.
'
swmarker_setselected(jmarker + 2, 1)
'
swmarker_setselected(jmarker + 3, 1)
'
swpost_rectifysolidobject()
'
else
'
continue for
'
'
end if
next
End If
swLoadedTracks_SetFrameNumber(start)
For b As Integer = 0 To nMarkers - 1 ' markers in the template
iResult = swContext_GetMarkerPosition(b,X,Y,Z)
If iResult = 0 Then ' 0 = no data for marker 1 = data exists for the given marker
i = start ' the new start for creating a template
Exit For
Else If b = nMarkers - 1 And iResult = 1 And start - i >= fudgeFactor
Call swPost_CreateTemplate(3,i,start)' this is a hail mary coz u need prayer for it to work
swPost_RectifyLinkages()
swPost_TemplateRectify(0)
Exit While
Else If swCancelled() Then
Message("Cancelled")
Exit Sub
End If
Next
start = start + 1
End While
For k = 60 To iHi / 2 'iHi / 6 gets it closer to 100 to prevent noise data used
swGetData_SetFrameNumber(k) 'Call some swGetData functions to get data for this frame
swGetData_ForcePlateForces(3, forces4THPLATE) ' 0 is first force plate therefore 3 is the 4th force plate
swGetData_ForcePlateForces(1, forces2NDPLATE) ' 0 is first force plate therefore 3 is the 4th force plate
swGetData_ForcePlateForces(0, forces1STPLATE) ' 0 is first force plate therefore 3 is the 4th force plate
If forces4THPLATE(2) <> 0 'Force in z-drection
intialFrame = 4
Exit For
Else If forces2NDPLATE(2) <> 0
intialFrame = 2
Exit For
Else If forces1STPLATE(2) <> 0
intialFrame = 1
Exit For
End If
Next
res1 = InputBox("Type in a frame value that you want to subtract before " + CStr(k) + " on PLATE " +
CStr(intialFrame), "automationDomination.sky")
If res1 = ""
res1 = k / 2
End If
'AutoFrameID from end to find the final change in voltage of F4Z (Z being highest voltage change)
For j = (5 / 6) * iHi To iHi / 2 Step -1
'swLoadedTracks_SetFrameNumber(j)
swGetData_SetFrameNumber(j) 'Call some swGetData functions to get data for this frame
swGetData_ForcePlateForces(3, forces4THPLATE) ' 0 is first force plate therefore 3 is the 4th force plate
swGetData_ForcePlateForces(1, forces2NDPLATE) ' 0 is first force plate therefore 3 is the 4th force plate
swGetData_ForcePlateForces(0, forces1STPLATE) ' 0 is first force plate therefore 3 is the 4th force plate
If forces4THPLATE(2) <> 0 'Force in z-drection
finalFrame = 4
Exit For
Else If forces2NDPLATE(2) <> 0
finalFrame = 2
Exit For
' ====== REGULAR RECTIFY WITH UNDO (IF RECTIFY MAKES IT WORSE) ====== '
' Regular rectify works by finding the misssing marker data from all the other markers identified
' If two missing markers are located within the same frame, then rectify will sometimes (idk why) work most
time wont
' regular rectify will sometime identify one marker at the cost of 2 good data being deleted
For iFrame As Integer = k - res1 - 1 To j + res2 + 1
Marker = 0
While Marker <> nMarkers - 1
swLoadedTracks_SetFrameNumber(iFrame - 1)
swContext_GetMarkerPosition(Marker, X, Y, Z) 'multiple markers in the same frame
If (X = 0 And Y = 0 And Z = 0)
Continue For
Else If (Marker = nMarkers - 1) And (X <> 0 And Y <> 0 And Z <> 0)
Exit While
Else If (Marker = nMarkers - 1) And (X = 0 And Y = 0 And Z = 0)
Continue For
End If
Marker = Marker + 1
End While
iMarker = 0
While iMarker <> nMarkers - 1
swLoadedTracks_SetFrameNumber(iFrame)
'swGetData_SetFrameNumber(iFrame)
swContext_GetMarkerPosition(iMarker,X,Y,Z) 'multiple markers in the same frame
If (X = 0 And Y = 0 And Z = 0) 'means that the gap is still there even after rectify
For jFrame As Integer = iFrame To iHi - 1
swLoadedTracks_SetFrameNumber(jFrame)
swContext_GetMarkerPosition(iMarker, X, Y, Z) 'multiple markers in the same
frame
If (X = 0 And Y = 0 And Z = 0)
'growing gap
Else
Call swPost_SetRange(k - res1 - 1,jFrame + 1) 'THIS IS REALLY
IMPORTANT BECAUSE MORE RANGE IS GOOD
swPost_SmartRectify() 'needs a selected frame range and a good frame
that uses all markers
Exit For
End If
Next
End If
If swCancelled() Then
Exit Sub
End If
iMarker = iMarker + 1
End While
Next
' NOW 100% CERTAIN THAT MISSING GAPS ARE DUE TO MISSING MARKERS
' ====== VIRTUAL JOIN THEN CUBIC JOIN GAPS OF 10 FRAMES ====== '
'' MY RANT ''
' I was under the impression that one would generally use virtual join on any length of frame gap
' HOWEVER I have now recently found out that if you use VM I on 2 missing markers on the same
' missing frame gap OR use it for more than say 10 frames, you will generate a -X^2 sorta graph
' whereby the virtually generated marker itself will orbit around.
' This is generally not true for clinical data but is true for research data
' THIS IS BASICALLY A MISSING MARKER FINDER AND HOW LONG OF A FRAME GAP (REALLY BRILLIANT PEICE OF
CODE DOWN BELOW)
Dim frameGap As Integer = 0
'Dim missingMarkerLength As Integer = 0
shortGap = InputBox("Type in a frame value that you would consider as equal to or less than a short gap. This
value with be virtual join, cubic or linear depending on the gap length.", "automationDomination.sky")
If shortGap = "" Then
shortGap = 6
MsgBox("You entered nothing and will default to " + CStr(shortGap) + " frames")
End If
If (X = 0 And Y = 0 And Z = 0) 'means that the gap is still there even after rectify
For jFrame As Integer = iFrame To iHi - 1
swLoadedTracks_SetFrameNumber(jFrame)
swContext_GetMarkerPosition(teet, X, Y, Z) 'multiple markers in the same frame
If (X = 0 And Y = 0 And Z = 0)
'continues to count the gap and does nothing
Else
If (jFrame - iFrame <= shortGap) 'missing MarkerLength = jFrameiFrame
If (jFrame - iFrame <= 3) ' blip (generally tails occur so don't do
cubic else tails make spike)
Call swPost_SetRange(iFrame,jFrame)
swMarkers_SelectAll()
swPost_JoinAll(0) ' 1 = cubic join and 0 = linear join
Else
End If
Else 'long gaps
'swPost_JoinVirtual(iMarker, 1) ' 0 is VMI and 1 is VMII
If swCancelled() Then
Exit Sub
End If
Next
Next
Call swPost_SetRange(0,iHi-1)
swMarkers_SelectAll()
swPost_JoinVirtual_Multiple()
' AFTER THE ABOVE IS COMPLETED, IT IS WITH 100% CERTAINTY THAT ALL GAPS (ASIDE THE END POINTS) ARE
FILLED
' ERGO, ANY CUT MADE WILL NOT BE ON A FRAME WITHOUT AN ANCHOR POINT AND CUBIC/Linear will not
work
MsgBox("THIS PROGRAM CAN NOT BE RUNNED ON THE SAME WALK TWICE IN A ROW. MUST REVERT TO
ORIGINAL FILE BY CHANGING .CAPS AND THEN COMING BACK TO THIS ONE.")
End Sub