Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code at the end of the year #7

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 122 additions & 1 deletion HandGenerator/HandGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self, parent=None):

self.connectorNode = None
self.generated = False

slicer.mymod = self
def setup(self):
ScriptedLoadableModuleWidget.setup(self)

Expand All @@ -53,8 +53,14 @@ def setup(self):
self.generateButton.text = "Generate Hands"
self.parametersFormLayout.addWidget(self.generateButton)

self.generateModelButton = qt.QPushButton()
self.generateModelButton.setDefault(False)
self.generateModelButton.text = "Generate Hand Models"
self.parametersFormLayout.addWidget(self.generateModelButton)

self.connectButton.connect('clicked(bool)', self.onConnectButtonClicked)
self.generateButton.connect('clicked(bool)', self.generateCylinders)
self.generateModelButton.connect('clicked(bool)', self.generateModels)
self.layout.addStretch(1)

def onConnectButtonClicked(self):
Expand Down Expand Up @@ -115,3 +121,118 @@ def generateCylinders(self):
slicer.mrmlScene.RemoveNode(nodes[i])
self.generated = False
self.generateCylinders()


def generateModels(self):
self.resourcePath = os.path.dirname(os.path.abspath(__file__))
if self.generated == False:
self.nodes = slicer.util.getNodesByClass('vtkMRMLLinearTransformNode')
self.n = len(self.nodes)
l = slicer.modules.createmodels.logic()

mat = vtk.vtkMatrix4x4()
mat_axis_conv = vtk.vtkMatrix4x4()
mat_table_to_mounted = vtk.vtkMatrix4x4()
# Old transforms
mat.SetElement(0,0,-1)
mat.SetElement(2,2,-1)

# Transform Matrix for HTC VIVE
#mat.SetElement(0,0,-0.99)
#mat.SetElement(0,1,-0.02)
#mat.SetElement(0,2,0.08)
#mat.SetElement(0,3,-2.75)
#mat.SetElement(1,0,-0.06)
#mat.SetElement(1,1,-.23)
#mat.SetElement(1,2,-0.97)
#mat.SetElement(1,3,29.11)
#mat.SetElement(2,0,0.04)
#mat.SetElement(2,1,-0.98)
#mat.SetElement(2,2,0.23)
#mat.SetElement(2,3,-133.75)

# Transform Matrix for HTC VIVE PRO
mat.SetElement(0,0,-0.99)
mat.SetElement(0,1,-0.02)
mat.SetElement(0,2,0.08)
mat.SetElement(0,3,7.25)
mat.SetElement(1,0,-0.06)
mat.SetElement(1,1,-0.23)
mat.SetElement(1,2,-0.97)
mat.SetElement(1,3,-100.89)
mat.SetElement(2,0,0.04)
mat.SetElement(2,1,-0.98)
mat.SetElement(2,2,0.23)
mat.SetElement(2,3,-111.75)

# Transforms from https://developer.leapmotion.com/documentation/v4/vrar.html
# Must attach to HMD transforms (ie, make HMD transform the parent of this matrix
# Setting the axis_conversion
#mat_axis_conv.SetElement(2,2,-1) #Identity with position 2,2 (starting from 0) set to -1

# Setting the table_to_mounted matrix
#mat_table_to_mounted.SetElement(0,0,-1)
#mat_table_to_mounted.SetElement(1,1,0)
#mat_table_to_mounted.SetElement(1,2,-1)
#mat_table_to_mounted.SetElement(2,1,-1)
#mat_table_to_mounted.SetElement(2,2,0)
#mat_table_to_mounted.SetElement(2,3,-80)

#Multiply4x4(mat_axis_conv, mat_table_to_mounted, mat)
#vtk.vtkMatrix4x4.Multiply4x4(mat_axis_conv,mat_table_to_mounted, mat)

self.Xflip = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLLinearTransformNode')
self.Xflip.SetName('LHG_TrackerToHMD')
self.Xflip.SetAndObserveMatrixTransformToParent(mat)
#self.Xflip.SetAndObserveTransformNodeID(self.Xflip.GetID()) Set this to observe the VR.HMD transform
#self.HMDAlign = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLLinearTransformNode')
#self.HMDAlign.SetName("LHG_RASToHMD")
self.generated = True

print(self.resourcePath)


for i in range (0, self.n):
if 'Left' in self.nodes[i].GetName() or 'Right' in self.nodes[i].GetName():
if 'Dis' in self.nodes[i].GetName() or 'Int' in self.nodes[i].GetName() or 'Prox' in self.nodes[i].GetName() or 'Meta' in self.nodes[i].GetName() or 'Palm' in self.nodes[i].GetName():


print('Resources\\' + self.nodes[i].GetName() + ".stl")
self.tempModel = slicer.util.loadModel(os.path.join(self.resourcePath, 'Resources\\' + self.nodes[i].GetName() + ".stl"))
if self.tempModel is not False:
self.nodes[i].SetAndObserveTransformNodeID(self.Xflip.GetID())
self.tempModel.SetAndObserveTransformNodeID(self.nodes[i].GetID())
self.tempModel.SetName('LHG_Seg' + self.nodes[i].GetName())

else:
self.nodes = slicer.util.getNodesByClass('vtkMRMLLinearTransformNode')
self.n = len(self.nodes)
self.models = slicer.util.getNodesByClass('vtkMRMLModelNode')
if self.Xflip is None:
mat = vtk.vtkMatrix4x4()
# Old transforms
mat.SetElement(0,0,-1)
mat.SetElement(2,2,-1)

# New transforms
mat.SetElement(0,0,-1)
mat.SetElement(1,1,0.17)
mat.SetElement(1,2,-0.99)
mat.SetElement(1,3,-70)
mat.SetElement(2,1,-0.99)
mat.SetElement(2,2,-0.17)
mat.SetElement(2,3,-80)
self.Xflip = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLLinearTransformNode')
self.Xflip.SetName('LHG_TrackerToHMD')
self.Xflip.SetAndObserveMatrixTransformToParent(mat)
for j in range(0, len(self.models)):
if 'LHG_' in self.models[j].GetName():
slicer.mrmlScene.RemoveNode(self.models[j])
for i in range (0, self.n):
if 'Left' in self.nodes[i].GetName() or 'Right' in self.nodes[i].GetName():
if 'Dis' in self.nodes[i].GetName() or 'Int' in self.nodes[i].GetName() or 'Prox' in self.nodes[i].GetName() or 'Meta' in self.nodes[i].GetName():
print('Resources\\' + self.nodes[i].GetName() + ".stl")
self.tempModel = slicer.util.loadModel(os.path.join(self.resourcePath, 'Resources\\' + self.nodes[i].GetName() + ".stl"))
self.nodes[i].SetAndObserveTransformNodeID(self.Xflip.GetID())
self.tempModel.SetAndObserveTransformNodeID(self.nodes[i].GetID())
self.tempModel.SetName('LHG_Seg' + self.nodes[i].GetName())
33 changes: 19 additions & 14 deletions HandGenerator/PlusDeviceSet_Server_LeapMotionTracker Both.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
AcquisitionRate="1000"
Id="TrackerDevice"
Type="LeapMotion"
LeapHMDPolicy="FALSE"
LeapHMDPolicy="TRUE"
ToolReferenceFrame="Tracker" >
<DataSources>
<DataSource Type="Video" Id="LeftCamera"/>
Expand All @@ -26,13 +26,14 @@
<DataSource Type="Tool" Id="LeftRingIntermediate"/>
<DataSource Type="Tool" Id="LeftPinkyIntermediate"/>

<DataSource Type="Tool" Id="LeftThumbProximal"/>
<!--<DataSource Type="Tool" Id="LeftThumbProximal"/>-->
<DataSource Type="Tool" Id="LeftIndexProximal"/>
<DataSource Type="Tool" Id="LeftMiddleProximal"/>
<DataSource Type="Tool" Id="LeftRingProximal"/>
<DataSource Type="Tool" Id="LeftPinkyProximal"/>

<DataSource Type="Tool" Id="LeftPalm"/>
<!--<DataSource Type="Tool" Id="LeftPalm"/>-->
<DataSource Type="Tool" Id="LeftMiddleMetacarpal"/>

<DataSource Type="Tool" Id="RightThumbDistal"/>
<DataSource Type="Tool" Id="RightIndexDistal"/>
Expand All @@ -46,13 +47,14 @@
<DataSource Type="Tool" Id="RightRingIntermediate"/>
<DataSource Type="Tool" Id="RightPinkyIntermediate"/>

<DataSource Type="Tool" Id="RightThumbProximal"/>
<!--<DataSource Type="Tool" Id="RightThumbProximal"/>-->
<DataSource Type="Tool" Id="RightIndexProximal"/>
<DataSource Type="Tool" Id="RightMiddleProximal"/>
<DataSource Type="Tool" Id="RightRingProximal"/>
<DataSource Type="Tool" Id="RightPinkyProximal"/>

<DataSource Type="Tool" Id="RightPalm"/>
<!--<DataSource Type="Tool" Id="RightPalm"/>-->
<DataSource Type="Tool" Id="RightMiddleMetacarpal"/>

</DataSources>
<OutputChannels>
Expand All @@ -72,12 +74,13 @@
<DataSource Id="LeftRingIntermediate"/>
<DataSource Id="LeftPinkyIntermediate"/>

<DataSource Id="LeftThumbProximal"/>
<!--<DataSource Id="LeftThumbProximal"/>-->
<DataSource Id="LeftIndexProximal"/>
<DataSource Id="LeftMiddleProximal"/>
<DataSource Id="LeftRingProximal"/>
<DataSource Id="LeftPinkyProximal"/>
<DataSource Id="LeftPalm"/>
<!--<DataSource Id="LeftPalm"/>-->
<DataSource Id="LeftMiddleMetacarpal"/>

<DataSource Id="RightThumbDistal"/>
<DataSource Id="RightIndexDistal"/>
Expand All @@ -91,12 +94,13 @@
<DataSource Id="RightRingIntermediate"/>
<DataSource Id="RightPinkyIntermediate"/>

<DataSource Id="RightThumbProximal"/>
<!--<DataSource Id="RightThumbProximal"/>-->
<DataSource Id="RightIndexProximal"/>
<DataSource Id="RightMiddleProximal"/>
<DataSource Id="RightRingProximal"/>
<DataSource Id="RightPinkyProximal"/>
<DataSource Id="RightPalm"/>
<!--<DataSource Id="RightPalm"/>-->
<DataSource Id="RightMiddleMetacarpal"/>
</OutputChannel>
</OutputChannels>
</Device>
Expand Down Expand Up @@ -160,12 +164,13 @@
<Transform Name="LeftRingIntermediateToTracker"/>
<Transform Name="LeftPinkyIntermediateToTracker"/>

<Transform Name="LeftThumbProximalToTracker"/>
<!--<Transform Name="LeftThumbProximalToTracker"/>-->
<Transform Name="LeftIndexProximalToTracker"/>
<Transform Name="LeftMiddleProximalToTracker"/>
<Transform Name="LeftRingProximalToTracker"/>
<Transform Name="LeftPinkyProximalToTracker"/>
<Transform Name="LeftPalmToTracker"/>
<!--<Transform Name="LeftPalmToTracker"/>-->
<Transform Name="LeftMiddleMetacarpalToTracker"/>

<Transform Name="RightThumbDistalToTracker"/>
<Transform Name="RightIndexDistalToTracker"/>
Expand All @@ -179,13 +184,13 @@
<Transform Name="RightRingIntermediateToTracker"/>
<Transform Name="RightPinkyIntermediateToTracker"/>

<Transform Name="RightThumbProximalToTracker"/>
<!--<Transform Name="RightThumbProximalToTracker"/>-->
<Transform Name="RightIndexProximalToTracker"/>
<Transform Name="RightMiddleProximalToTracker"/>
<Transform Name="RightRingProximalToTracker"/>
<Transform Name="RightPinkyProximalToTracker"/>
<Transform Name="RightPalmToTracker"/>

<!--<Transform Name="RightPalmToTracker"/>-->
<Transform Name="RightMiddleMetacarpalToTracker"/>
</TransformNames>
</DefaultClientInfo>
</PlusOpenIGTLinkServer>
Expand Down
21 changes: 11 additions & 10 deletions HandGenerator/PlusDeviceSet_Server_LeapMotionTracker Left.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
AcquisitionRate="1000"
Id="TrackerDevice"
Type="LeapMotion"
LeapHMDPolicy="FALSE"
LeapHMDPolicy="TRUE"
ToolReferenceFrame="Tracker" >
<DataSources>
<DataSource Type="Video" Id="LeftCamera"/>
Expand All @@ -26,14 +26,14 @@
<DataSource Type="Tool" Id="LeftRingIntermediate"/>
<DataSource Type="Tool" Id="LeftPinkyIntermediate"/>

<DataSource Type="Tool" Id="LeftThumbProximal"/>
<!--<DataSource Type="Tool" Id="LeftThumbProximal"/>-->
<DataSource Type="Tool" Id="LeftIndexProximal"/>
<DataSource Type="Tool" Id="LeftMiddleProximal"/>
<DataSource Type="Tool" Id="LeftRingProximal"/>
<DataSource Type="Tool" Id="LeftPinkyProximal"/>

<DataSource Type="Tool" Id="LeftPalm"/>

<!--<DataSource Type="Tool" Id="LeftPalm"/>-->
<DataSource Type="Tool" Id="LeftMiddleMetacarpal"/>
<!--
<DataSource Type="Tool" Id="RightThumbDistal"/>
<DataSource Type="Tool" Id="RightIndexDistal"/>
Expand Down Expand Up @@ -74,13 +74,14 @@
<DataSource Id="LeftRingIntermediate"/>
<DataSource Id="LeftPinkyIntermediate"/>

<DataSource Id="LeftThumbProximal"/>
<!--<DataSource Id="LeftThumbProximal"/>-->
<DataSource Id="LeftIndexProximal"/>
<DataSource Id="LeftMiddleProximal"/>
<DataSource Id="LeftRingProximal"/>
<DataSource Id="LeftPinkyProximal"/>
<DataSource Id="LeftPalm"/>

<!--<DataSource Id="LeftPalm"/>-->
<DataSource Id="LeftMiddleMetacarpal"/>

<!--
<DataSource Id="RightThumbDistal"/>
<DataSource Id="RightIndexDistal"/>
Expand Down Expand Up @@ -164,13 +165,13 @@
<Transform Name="LeftRingIntermediateToTracker"/>
<Transform Name="LeftPinkyIntermediateToTracker"/>

<Transform Name="LeftThumbProximalToTracker"/>
<!--<Transform Name="LeftThumbProximalToTracker"/>-->
<Transform Name="LeftIndexProximalToTracker"/>
<Transform Name="LeftMiddleProximalToTracker"/>
<Transform Name="LeftRingProximalToTracker"/>
<Transform Name="LeftPinkyProximalToTracker"/>
<Transform Name="LeftPalmToTracker"/>

<!--<Transform Name="LeftPalmToTracker"/>-->
<Transform Name="LeftMiddleMetacarpalToTracker"/>
<!--
<Transform Name="RightThumbDistalToTracker"/>
<Transform Name="RightIndexDistalToTracker"/>
Expand Down
18 changes: 10 additions & 8 deletions HandGenerator/PlusDeviceSet_Server_LeapMotionTracker Right.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
AcquisitionRate="1000"
Id="TrackerDevice"
Type="LeapMotion"
LeapHMDPolicy="FALSE"
LeapHMDPolicy="TRUE"
ToolReferenceFrame="Tracker" >
<DataSources>
<DataSource Type="Video" Id="LeftCamera"/>
Expand Down Expand Up @@ -48,13 +48,14 @@
<DataSource Type="Tool" Id="RightRingIntermediate"/>
<DataSource Type="Tool" Id="RightPinkyIntermediate"/>

<DataSource Type="Tool" Id="RightThumbProximal"/>
<!--<DataSource Type="Tool" Id="RightThumbProximal"/>-->
<DataSource Type="Tool" Id="RightIndexProximal"/>
<DataSource Type="Tool" Id="RightMiddleProximal"/>
<DataSource Type="Tool" Id="RightRingProximal"/>
<DataSource Type="Tool" Id="RightPinkyProximal"/>

<DataSource Type="Tool" Id="RightPalm"/>
<!--<DataSource Type="Tool" Id="RightPalm"/>-->
<DataSource Type="Tool" Id="RightMiddleMetacarpal"/>

</DataSources>
<OutputChannels>
Expand Down Expand Up @@ -95,12 +96,13 @@
<DataSource Id="RightRingIntermediate"/>
<DataSource Id="RightPinkyIntermediate"/>

<DataSource Id="RightThumbProximal"/>
<!--<DataSource Id="RightThumbProximal"/>-->
<DataSource Id="RightIndexProximal"/>
<DataSource Id="RightMiddleProximal"/>
<DataSource Id="RightRingProximal"/>
<DataSource Id="RightPinkyProximal"/>
<DataSource Id="RightPalm"/>
<!--<DataSource Id="RightPalm"/>-->
<DataSource Id="RightMiddleMetacarpal"/>
</OutputChannel>
</OutputChannels>
</Device>
Expand Down Expand Up @@ -185,13 +187,13 @@
<Transform Name="RightRingIntermediateToTracker"/>
<Transform Name="RightPinkyIntermediateToTracker"/>

<Transform Name="RightThumbProximalToTracker"/>
<!--<Transform Name="RightThumbProximalToTracker"/>-->
<Transform Name="RightIndexProximalToTracker"/>
<Transform Name="RightMiddleProximalToTracker"/>
<Transform Name="RightRingProximalToTracker"/>
<Transform Name="RightPinkyProximalToTracker"/>
<Transform Name="RightPalmToTracker"/>

<!--<Transform Name="RightPalmToTracker"/>-->
<Transform Name="RightMiddleMetacarpalToTracker"/>
</TransformNames>
</DefaultClientInfo>
</PlusOpenIGTLinkServer>
Expand Down
Loading