Skip to content

Commit

Permalink
Issue #100 got some colour stuff in
Browse files Browse the repository at this point in the history
  • Loading branch information
thompson318 committed Jul 7, 2022
1 parent 8be3526 commit 3ff9665
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 37 deletions.
1 change: 1 addition & 0 deletions sksurgerybard/visualisation/bard_visualisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import numpy as np
from sksurgeryvtk.models.vtk_sphere_model import VTKSphereModel
from sksurgerybard.visualisation.colours import get_yellow, get_green

def configure_model_and_ref(configuration, transform_manager):
"""
Expand Down
110 changes: 73 additions & 37 deletions sksurgerybard/visualisation/colours.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,78 @@
# Grayscale Design palette: https://grayscale.design/app?lums=100.00,88.89,77.78,66.67,55.56,44.44,33.33,22.22,11.11,0.00&palettes=%23ffff00,%2300ff00&filters=0%7C0,0%7C0&names=Yellow,Greeen&labels=,

#lets create dictionaries we can use of pre set colours
{
"grayscale": {
"50": "rgb(255, 255, 255)",
"100": "rgb(242, 242, 242)",
"200": "rgb(228, 228, 228)",
"300": "rgb(213, 213, 213)",
"400": "rgb(197, 197, 197)",
"500": "rgb(178, 178, 178)",
"600": "rgb(156, 156, 156)",
"700": "rgb(130, 130, 130)",
"800": "rgb(94, 94, 94)",
"900": "rgb(0, 0, 0)"
},
"Yellow": {
"50": "rgb(255, 255, 255)",
"100": "rgb(250, 250, 0)",
"200": "rgb(236, 236, 0)",
"300": "rgb(220, 220, 0)",
"400": "rgb(203, 203, 0)",
"500": "rgb(184, 184, 0)",
"600": "rgb(162, 162, 0)",
"700": "rgb(134, 134, 0)",
"800": "rgb(97, 97, 0)",
"900": "rgb(0, 0, 0)"
},
"Greeen": {
"50": "rgb(255, 255, 255)",
"100": "rgb(205, 255, 205)",
"200": "rgb(129, 255, 129)",
"300": "rgb(0, 247, 0)",
"400": "rgb(0, 228, 0)",
"500": "rgb(0, 207, 0)",
"600": "rgb(0, 182, 0)",
"700": "rgb(0, 151, 0)",
"800": "rgb(0, 110, 0)",
"900": "rgb(0, 0, 0)"
}
grayscale = {
"50": [255, 255, 255],
"100": [242, 242, 242],
"200": [228, 228, 228],
"300": [213, 213, 213],
"400": [197, 197, 197],
"500": [178, 178, 178],
"600": [156, 156, 156],
"700": [130, 130, 130],
"800": [94, 94, 94],
"900": [0, 0, 0]
}

yellow = {
"50": [255, 255, 255],
"100": [250, 250, 0],
"200": [236, 236, 0],
"300": [220, 220, 0],
"400": [203, 203, 0],
"500": [184, 184, 0],
"600": [162, 162, 0],
"700": [134, 134, 0],
"800": [97, 97, 0],
"900": [0, 0, 0]
}

green = {
"50": [255, 255, 255],
"100": [205, 255, 205],
"200": [129, 255, 129],
"300": [0, 247, 0],
"400": [0, 228, 0],
"500": [0, 207, 0],
"600": [0, 182, 0],
"700": [0, 151, 0],
"800": [0, 110, 0],
"900": [0, 0, 0]
}

def y_pos_to_luminance(y_pos):
"""
y_pos is a float between 0 and 1 representing the position of the
mouse on the screen. High y_pos corresponds to high luminance (50)
low y_pos to low luminance (900)
"""
luminances = ["50", "100", "200", "300", "400", "500", "600",
"700", "800", "900"]
index = 0
threshold = 0.9
while index < len(luminances):
if y_pos > threshold:
return luminances[index]
index += 1
threshold -= 0.1

return luminances[index-1]


def integer_colour_to_float(colour):
"""
converts an integer colour to a float colour
"""
out=[]
for value in colour:
out.append((value)/256.0)

return out



def get_green(y_pos):
return green.get(y_pos_to_luminance(y_pos))

def get_yellow(y_pos):
return integer_colour_to_float(yellow.get(y_pos_to_luminance(y_pos)))
38 changes: 38 additions & 0 deletions tests/visualisation/test_colours.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-
"""Tests for BARD pointer module"""
import pytest
import vtk
import numpy as np
from sksurgerycore.transforms.transform_manager import TransformManager
import sksurgerybard.visualisation.colours as cls

#pylint:disable=no-member

def test_y_pos_to_luminance():
"""Checks that the y_pos to luminance look up works"""

assert cls.y_pos_to_luminance(1.0) == "50"
assert cls.y_pos_to_luminance(0.91) == "50"
assert cls.y_pos_to_luminance(0.90) == "100"
assert cls.y_pos_to_luminance(0.80) == "200"
assert cls.y_pos_to_luminance(0.70) == "300"
assert cls.y_pos_to_luminance(0.60) == "400"
assert cls.y_pos_to_luminance(0.50) == "500"
assert cls.y_pos_to_luminance(0.40) == "600"
assert cls.y_pos_to_luminance(0.30) == "700"
assert cls.y_pos_to_luminance(0.20) == "800"
assert cls.y_pos_to_luminance(0.10) == "900"
assert cls.y_pos_to_luminance(0.00) == "900"


def test_integer_colour_to_float():
"""Tests that integer to float colour works"""
assert cls.integer_colour_to_float([255,128,0]) == [1.0, 0.5, 0.0]

def test_get_yellow():
"""Checks that get yellow returns the right value"""
assert cls.get_yellow(1.0) == [1.0, 1.0, 1.0]

def test_get_green():
"""Checks that get green returns the right value"""
assert cls.get_green(1.0) == [1.0, 1.0, 1.0]

0 comments on commit 3ff9665

Please sign in to comment.