Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
041a85a
Added setting for excessive force adjust
MiikaVuorio Jul 26, 2024
1cecbd6
fix python 3.8 incompatibility
MiikaVuorio Jul 26, 2024
888a13e
Fixed second python 38 incompatibility
MiikaVuorio Jul 26, 2024
bee05ac
removed debugging print statement
MiikaVuorio Jul 26, 2024
e1c6665
added force compensation control in nav preferences
MiikaVuorio Aug 13, 2024
d7bf69a
Added menu items for force shift
MiikaVuorio Aug 14, 2024
34ebfa5
improved force compensation gui
MiikaVuorio Aug 15, 2024
857983f
added force compensation text
MiikaVuorio Aug 22, 2024
9dfeef3
added missing return to createForceCompText function
MiikaVuorio Aug 22, 2024
864682c
Trying different text position for force compensation text
MiikaVuorio Aug 22, 2024
7d80839
text position change test
MiikaVuorio Aug 22, 2024
03fb4de
robot to neuronavigation force compensation amount
MiikaVuorio Aug 22, 2024
15ff1cc
Changed the force compensate to be displayed from an internal variable
MiikaVuorio Aug 22, 2024
cca7bc6
added info of compensation to invesalisu
MiikaVuorio Aug 26, 2024
4d2b393
changed force compensate text into arrow
MiikaVuorio Aug 26, 2024
7575030
testing force compensate distance
MiikaVuorio Aug 26, 2024
5176a16
testing up / down arrow in viewer_volume
MiikaVuorio Aug 26, 2024
d780623
Testing creation of up arrow as a vtku.vtkTextActor if it would actua…
MiikaVuorio Aug 26, 2024
6e0fb8f
didn't work reverting to without force compensate text, just try to c…
MiikaVuorio Aug 26, 2024
82bb8ed
added an arrow that appears with the distance text, hopefully
MiikaVuorio Aug 27, 2024
a2d9cec
testing different createArrow params
MiikaVuorio Aug 27, 2024
83c09cc
removed arrow stuff. Hopefully no errors in invesalius now
MiikaVuorio Aug 28, 2024
57b8570
restored distance thingy
MiikaVuorio Aug 28, 2024
eb2d54c
commented out arrow creation funtion
MiikaVuorio Aug 29, 2024
c0d1738
Created force compensate arrow
MiikaVuorio Aug 29, 2024
4e03233
added print statements to understand when createTargetGuide runs
MiikaVuorio Aug 29, 2024
ec60266
added creation of force_compensate_arrow_up to onupdatecoilpose
MiikaVuorio Aug 29, 2024
680c1af
clearer print statements and copied more exactly one of the existing …
MiikaVuorio Aug 29, 2024
0f37769
Testing different arrow values
MiikaVuorio Aug 29, 2024
03edf08
trying a different number for arrow
MiikaVuorio Aug 29, 2024
a37bd27
how about zero zero, will the arrow disappear?
MiikaVuorio Aug 29, 2024
3ffe029
back to 50 and trying rotate 270
MiikaVuorio Aug 29, 2024
a073459
back to 50 and trying rotate 270
MiikaVuorio Aug 29, 2024
cab6a7a
Ok, let's see what this'll give
MiikaVuorio Aug 29, 2024
6c6215f
slightly different numbers
MiikaVuorio Aug 29, 2024
e0b4d1d
commented out some pointless prints
MiikaVuorio Aug 29, 2024
1317a3f
all the colours
MiikaVuorio Aug 29, 2024
ca50dc9
Merge branch 'master' into pr/891
rmatsuda Feb 11, 2025
5fcfe36
RUFF
rmatsuda Feb 11, 2025
8b39ea9
Merge branch 'master' into Force-and-torque-implementations
rmatsuda Feb 17, 2025
cbc50a0
Merge branch 'master' into Force-and-torque-implementations
rmatsuda Mar 7, 2025
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
9 changes: 9 additions & 0 deletions invesalius/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,15 @@
CONSOLE_LOGGING_LEVEL = 9
LOGGING_LEVEL_TYPES = ["NOTSET", "DEBUG", "INFO", "WARN", "ERROR", "CRITICAL"]

# ------------ Navigation options key ------------
EXCESSIVE_FORCE_ADJUST = 10
EXCESSIVE_FORCE_MIN = 11
EXCESSIVE_FORCE_MAX = 12
FORCE_SENSOR_CENTERING = 13

# Default value for excessive force adjust
FORCE_ADJUST_DISTANCE = 4

# Correlaction extracted from pyDicom
DICOM_ENCODING_TO_PYTHON = {
"None": "iso8859",
Expand Down
99 changes: 98 additions & 1 deletion invesalius/data/viewer_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@ def __init__(self, parent):

self.distance_text = None
self.robot_warnings_text = None
self.force_compensate_arrow_up = None
# self.force_compensate_text = None
self.force_compensate_distance = 0

# self.obj_axes = None
self.mark_actor = None
Expand Down Expand Up @@ -507,6 +510,10 @@ def __bind_events(self):
Publisher.subscribe(
self.OnUpdateRobotStatus, "Robot to Neuronavigation: Update robot status"
)
Publisher.subscribe(
self.UpdateForceCompensation,
"Robot to Neuronavigation: Update force compensation displacement",
)
Publisher.subscribe(self.GetCoilPosition, "Calculate position and rotation")
Publisher.subscribe(
self.CreateCortexProjectionOnScalp, "Send efield target position on brain"
Expand Down Expand Up @@ -919,6 +926,8 @@ def CreateTargetGuide(self):
obj_pitch.RotateY(90)
obj_pitch.RotateZ(180)

force_compensate_arrow_up = self.actor_factory.CreateArrow([0, 0, 0], [0, 0, 50])

arrow_roll_z1 = self.actor_factory.CreateArrow([-50, -35, 12], [-50, -35, 50])
arrow_roll_z1.GetProperty().SetColor(1, 1, 0)
arrow_roll_z1.RotateX(-60)
Expand Down Expand Up @@ -957,13 +966,17 @@ def CreateTargetGuide(self):
arrow_pitch_x1,
arrow_pitch_x2,
)
print("FORCE_COMP_ARROW_UP_IN_CREATE_TARGET_GUIDE")
self.force_compensate_arrow_up = force_compensate_arrow_up

for ind in self.guide_coil_actors:
self.target_guide_renderer.AddActor(ind)

for ind in self.guide_arrow_actors:
self.target_guide_renderer.AddActor(ind)

self.target_guide_renderer.AddActor(force_compensate_arrow_up)

def EnableTargetMode(self):
# Store the current camera settings so that they can be restored when the target mode is disabled.
self.stored_camera_settings = self.GetCameraSettings()
Expand All @@ -985,10 +998,16 @@ def EnableTargetMode(self):
if self.distance_text is not None:
self.ren.RemoveActor(self.distance_text.actor)

# if self.force_compensate_arrow_up is not None:
# self.ren.RemoveActor(self.force_compensate_arrow_up)

# Create new actor for 'distance' text
distance_text = self.CreateDistanceText()
self.ren.AddActor(distance_text.actor)

# force_compensate_arrow_up = self.CreateCompensateArrowUp()
# self.ren.AddActor(force_compensate_arrow_up)

# Store the object for 'distance' text so it can be modified when distance changes.
self.distance_text = distance_text

Expand All @@ -1003,6 +1022,16 @@ def EnableTargetMode(self):
# Store the object for 'distance' text so it can be modified when distance changes.
self.robot_warnings_text = robot_warnings_text

##########################################

# force_compensate_text = self.CreateForceCompensateText()
# self.ren.AddActor(force_compensate_text.actor)

# # Store the object for 'compensate' text so it can be modified when distance changes.
# self.force_compensate_text = force_compensate_text

##########################################

self.CreateTargetGuide()

self.ren.ResetCamera()
Expand Down Expand Up @@ -1042,6 +1071,11 @@ def DisableTargetMode(self):
if self.robot_warnings_text is not None:
self.ren.RemoveActor(self.robot_warnings_text.actor)

##########################################
# if self.force_compensate_arrow_up is not None:
# self.ren.RemomveActor(self.force_compensate_arrow_up)
##########################################

self.camera_show_object = None
if self.actor_peel:
if self.object_orientation_torus_actor:
Expand All @@ -1064,18 +1098,37 @@ def SetTargetMode(self, enabled=False):
else:
self.DisableTargetMode()

def UpdateForceCompensation(self, displacement):
self.force_compensate_distance = displacement
# formatted_force_compensate = "Force Compensate: {: >5.1f} mm".format(displacement)
# if self.force_compensate_text is not None:
# self.force_compensate_text.SetValue(formatted_force_compensate)

def OnUpdateCoilPose(self, m_img, coord):
# vtk_colors = vtkNamedColors()
if self.target_coord and self.target_mode:
distance_to_target = distance.euclidean(
coord[0:3], (self.target_coord[0], -self.target_coord[1], self.target_coord[2])
)

formatted_distance = f"Distance: {distance_to_target: >5.1f} mm"
if self.force_compensate_distance < 0:
formatted_distance = f"Distance: {distance_to_target: >5.1f} mm UP \u2191"
# self.force_compensate_arrow_up.SetOrientation()
elif self.force_compensate_distance > 0:
formatted_distance = f"Distance: {distance_to_target: >5.1f} mm DOWN ↓\u2193"
else:
formatted_distance = f"Distance: {distance_to_target: >5.1f} mm"

# formatted_force_compensate = "Force Compensate: {: >5.1f} mm".format(self.force_compensate_distance)

if self.distance_text is not None:
self.distance_text.SetValue(formatted_distance)

##########################################
# if self.force_compensate_text is not None:
# self.force_compensate_text.SetValue(formatted_force_compensate)
##########################################

self.ren.ResetCamera()
self.SetCameraTarget()
if distance_to_target > 100:
Expand Down Expand Up @@ -1124,6 +1177,22 @@ def OnUpdateCoilPose(self, m_img, coord):
for actor in self.guide_arrow_actors:
self.target_guide_renderer.RemoveActor(actor)

########
if self.force_compensate_arrow_up is not None:
self.target_guide_renderer.RemoveActor(self.force_compensate_arrow_up)

# print("creating force_compensate_arrow_up")
# force_compensate_arrow_up = self.actor_factory.CreateArrow([0, 0, 0], [0, 0, 50])
force_compensate_arrow_up = self.actor_factory.CreateArrow([0, 0, 0], [0, -50, 0])
force_compensate_arrow_up.SetPosition(0, -575, 0)
force_compensate_arrow_up.RotateY(90)
force_compensate_arrow_up.RotateZ(180)
force_compensate_arrow_up.GetProperty().SetColor(1, 1, 1)

# print("Adding the actor force_compensate_arrow_up")
self.target_guide_renderer.AddActor(force_compensate_arrow_up)
########

if (
self.angle_threshold * const.ARROW_SCALE
> coordrx_arrow
Expand Down Expand Up @@ -1290,6 +1359,34 @@ def CreateDistanceText(self):

return distance_text

# def CreateCompensateArrowUp(self):
# # arrow_source = vtkArrowSource()

# force_compensate_arrow_up = self.actor_factory.CreateArrow([0, 0, 0], [10, 10, 10])
# force_compensate_arrow_up.GetProperty().SetColor(1, 1, 0)
# force_compensate_arrow_up.RotateX(-60)
# force_compensate_arrow_up.RotateZ(180)
# return force_compensate_arrow_up

# def CreateForceCompensateText(self):
# up_arrow_actor = vtku.vtkTextActor()
# up_arrow_actor.SetInput("TESTTEST") # Unicode for up arrow
# up_arrow_actor.GetTextProperty().SetFontSize(24)
# up_arrow_actor.GetTextProperty().SetColor(1.0, 1.0, 1.0)
# up_arrow_actor.SetPosition(100, 100) #### Might wanna change

# return up_arrow_actor

# def CreateForceCompensateText(self):
# force_compensate_text = vtku.Text()

# force_compensate_text.SetSize(20)
# force_compensate_text.SetPosition((0.03, 0.09)) # to do dynamic positioning I'd have to run setPosition in some part of code that runs continuosly
# force_compensate_text.SetVerticalJustificationToBottom()
# force_compensate_text.BoldOn()

# return force_compensate_text

def CenterOfMass(self):
barycenter = [0.0, 0.0, 0.0]
proj = prj.Project()
Expand Down
7 changes: 7 additions & 0 deletions invesalius/gui/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,9 @@ def ShowPreferences(self, page=0):
logging_level = values[const.LOGGING_LEVEL]
append_log_file = values[const.APPEND_LOG_FILE]
logging_file = values[const.LOGFILE]
excessive_force_adjust = values[const.EXCESSIVE_FORCE_ADJUST]
excessive_force_distance = values[const.EXCESSIVE_FORCE_MIN]
force_centering_on = values[const.FORCE_SENSOR_CENTERING]

session.SetConfig("rendering", rendering)
session.SetConfig("surface_interpolation", surface_interpolation)
Expand All @@ -786,13 +789,17 @@ def ShowPreferences(self, page=0):
session.SetConfig("logging_level", logging_level)
session.SetConfig("append_log_file", append_log_file)
session.SetConfig("logging_file", logging_file)
session.SetConfig("excessive_force_adjust", excessive_force_adjust)
session.SetConfig("excessive_force_distance", excessive_force_distance)
session.SetConfig("force_centering_on", force_centering_on)

Publisher.sendMessage("Remove Volume")
Publisher.sendMessage("Reset Raycasting")
Publisher.sendMessage("Update Slice Interpolation")
Publisher.sendMessage("Update Slice Interpolation MenuBar")
Publisher.sendMessage("Update Navigation Mode MenuBar")
Publisher.sendMessage("Update Surface Interpolation")
Publisher.sendMessage("Update excessive force adjustment")

def ShowAbout(self):
"""
Expand Down
Loading
Loading