Skip to content

Commit

Permalink
Feature: add invert button to ColorScale
Browse files Browse the repository at this point in the history
  • Loading branch information
Korbinian Eckstein committed Jul 25, 2024
1 parent ce5aa9b commit 77ffbfa
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions niivue/src/components/ScalingBox.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { computed } from '@preact/signals'
import { computed, useSignal } from '@preact/signals'
import { html } from 'htm/preact'
import { useRef, useEffect } from 'preact/hooks'
import { ExtendedNiivue } from '../events'
Expand All @@ -13,6 +13,7 @@ export const ScalingBox = (props: any) => {
if (visible && !visible.value) return html``

const selectedOverlay = computed(() => getOverlay(nvArraySelected.value[0]))
const invertState = useSignal(selectedOverlay.value.colormapInvert)

const setScaling = (val: ScalingOpts) => {
nvArraySelected.value.forEach((nv: ExtendedNiivue) => {
Expand Down Expand Up @@ -43,6 +44,13 @@ export const ScalingBox = (props: any) => {
})
}

const changeInverted = () => {
invertState.value = !selectedOverlay.value.colormapInvert
nvArraySelected.value.forEach((nv: ExtendedNiivue) => {
handleOverlayInvert(nv, selectedOverlayNumber.value, invertState.value!)
})
}

return html`
<div class="absolute left-8 top-8 bg-gray-500 rounded-md z-50 space-y-1 space-x-1 p-1">
<${Scaling} setScaling=${setScaling} init=${selectedOverlay.value} />
Expand All @@ -63,10 +71,13 @@ export const ScalingBox = (props: any) => {
step="0.1"
/>
<button
class="bg-gray-600 border-2 border-gray-600 rounded-md w-16 opacity-50 cursor-not-allowed"
onclick=${() => console.log('Not implemented yet')}
class="border-2 border-gray-600 rounded-md w-16 ${invertState.value
? 'bg-white text-gray-600'
: 'bg-gray-600'}"
onclick=${changeInverted}
value=${invertState}
>
Hide
Invert
</button>
<br />
<button
Expand Down Expand Up @@ -130,6 +141,18 @@ function isVolumeOverlay(nv: ExtendedNiivue) {
return nv.volumes.length > 0
}

function handleOverlayInvert(nv: ExtendedNiivue, layerNumber: number, invert: boolean) {
if (isVolumeOverlay(nv)) {
const overlay = nv.volumes[layerNumber]
if (overlay) {
overlay.colormapInvert = invert
}
} else {
nv.setMeshLayerProperty(nv.meshes[0].id as any, layerNumber, 'colormapInvert', invert ? 1 : 0)
}
nv.updateGLVolume()
}

function handleOverlayScaling(nv: ExtendedNiivue, layerNumber: number, scaling: ScalingOpts) {
if (isVolumeOverlay(nv)) {
const overlay = nv.volumes[layerNumber]
Expand Down

0 comments on commit 77ffbfa

Please sign in to comment.