Sie sind auf Seite 1von 12

'

' 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

Dim Marker As Integer = 0


Dim fudgeFactor As Integer = 0

' ====== UNNAMING ALL MARKERS ====== '


swMarkers_SelectAll()
swPost_MakeUnnamed()
swPost_CleanUnnamed()

' Rectify unnamed

' ====== 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

'delete markername from markerset


swPopups_SetQuietMode(1)
For a As Integer = 0 To nMarkers - 1 '@ frame number i where it was defined
resultNow = swContext_GetMarkerPosition(a,X,Y,Z)
If resultNow = 0
swModel_DeleteMarker(a)
End If
Next
swPopups_SetQuietMode(0)
' ====== RIGID BODY RECTIFY ====== '
' RIGID BODY BELOW GENERALLY UNNEEDED
'

swmarkers_selectnone()

'

for jmarker as integer = 0 to nmarkers - 1

'
'
"l.shank.upper"

dim name as string = swgetdata_markername(jmarker)


if name = "r.thigh.upper" or name = "l.thigh.upper" or name = "l.shank.upper" or name =

'

swmarker_setselected(jmarker, 1)

'
selected.

swmarker_setselected(jmarker + 1, 1) ' 0 makes the marker unselected, 1 makes it

'

swmarker_setselected(jmarker + 2, 1)

'

swmarker_setselected(jmarker + 3, 1)

'

swpost_rectifysolidobject()

'

else

'

continue for

'
'

end if
next

' ====== TEMPLATE RECTIFY ====== '


'' MY RANT ''
' dont use rectify on all frames because flip flops will occur
' using rectify after template rectify will make it into rectify (hence flip flops)
' rectify then template rectify still does rectify and not the template rectify
' AutoID all the frame gaps still has gaps eventhough markers exist
' Creating a Template and then Template ID is in my opinion is the best option
Call swPost_SetRange(0,iHi-1)
swMarkers_SelectNone()
swPost_Template_UseAllMarkers(1)
swPost_RectifyLinkages()'Template Rectify from the current frame to setRanged/highlighted frame
swPost_TemplateRectify(0)
' Sometimes this isn't even needed to find entire marker set
fudgeFactor = (iHi - 1) / 4 ' more the better BUT too much might not get a template
If fudgeFactor > 200
fudgeFactor = 200 ' coz its a really noisy data and guaranteed gaps will occur after 200
End If
start = i + 1
While start < iHi - 1
If start = (iHi - 1) - fudgeFactor
Exit While

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

' ====== TRIMMING ====== '


'F1X F1Y F1Z M1X M1Y M1Z F2X F3X M4Z M2Z
' 0 1 2 3 4 5 6 12 19 11 swGetData_AnalogVoltage
'res = MsgBox("Default programmed trim ?", vbYesNo + vbDefaultButton1, "automationDomination.sky")
'If res = vbNo Then
'GoTo Line1
'Exit Sub
'End If

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

Else If forces1STPLATE(1) <> 0


finalFrame = 1
Exit For
End If
Next
res2 = InputBox("Type in a frame value that you want to add after the final strike point of " + CStr(j) + " on PLATE
" + CStr(finalFrame), "automationDomination.sky")
If res2 = "" Then
If finalFrame = 4 Or finalFrame = 2
res2 = ((iHi - 1) - j) / 3
Else If finalFrame = 1
res2 = ((iHi - 1) - j) / 2
End If
End If

' ====== 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

For a As Integer = iFrame To jFrame


For b As Integer = 0 To nMarkers - 1
swLoadedTracks_SetFrameNumber(a)
swContext_GetMarkerPosition(b,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
swPost_Undo()
'VIRTUAL JOIN/CUBIC/LINEAR
Exit While
End If
Next
Next

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

For iFrame As Integer = 0 To iHi - 1


For teet As Integer = 0 To nMarkers - 1
swLoadedTracks_SetFrameNumber(iFrame)
'swGetData_SetFrameNumber(iFrame)
swContext_GetMarkerPosition(teet,X,Y,Z) 'multiple markers in the same frame

' Debugging Tool


'Message(CStr(iFrame) + " @ " + swGetData_MarkerName(iMarker))
'Message(CStr(X))
'Message(CStr(Y))
'Message(CStr(Z))

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

' not blip


Call swPost_SetRange(iFrame,jFrame)
swMarkers_SelectAll()
swPost_JoinAll(1) ' 1 = cubic join and 0 = linear join

End If
Else 'long gaps
'swPost_JoinVirtual(iMarker, 1) ' 0 is VMI and 1 is VMII

'swModel_GetVMarkerName THIS IS REALLY GOOD FUNCTION


FOR VM 2 DEFINITION
End If
Exit For
End If
Next
End If

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

' ====== TRIM ====== '


Call swPost_SetRange(j + res2 + 1,iHi - 1)
swMarkers_SelectAll()
swPost_MakeUnnamed()
swPost_CleanUnnamed()

' Rectify unnamed

Call swPost_SetRange(0,k - res1 - 1)


swMarkers_SelectAll()
swPost_MakeUnnamed()
swPost_CleanUnnamed()

' Rectify unnamed

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

Das könnte Ihnen auch gefallen