import vtkColorMaps from '@kitware/vtk.js/Rendering/Core/ColorTransferFunction/ColorMaps'
import vtkColorTransferFunction from '@kitware/vtk.js/Rendering/Core/ColorTransferFunction'
import vtkPiecewiseFunction from '@kitware/vtk.js/Common/DataModel/PiecewiseFunction'
import { utilities } from '@cornerstonejs/core'
const { getColormap } = utilities.colormap
function setPetColorMapTransferFunctionForVolumeActor(
  volumeInfo,
  isPT = false
) {
  const { volumeActor, preset } = volumeInfo
  const mapper = volumeActor.getMapper()
  mapper.setSampleDistance(1.0)

  const cfun = vtkColorTransferFunction.newInstance()
  // const presetToUse = preset || vtkColorMaps.getPresetByName('hsv')
  const presetToUse = preset || getColormap('siemens')

  cfun.applyColorMap(presetToUse)

  cfun.setMappingRange(0, 5)

  volumeActor.getProperty().setRGBTransferFunction(0, cfun)

  // Create scalar opacity function
  const ofun = vtkPiecewiseFunction.newInstance()
  if (isPT) {
    ofun.addPoint(0, 0.0)
    ofun.addPoint(0.1, 1.0)
  } else {
    ofun.addPoint(0, 0.0)
    ofun.addPoint(0.1, 0.9)
  }

  ofun.addPoint(5, 1.0)

  volumeActor.getProperty().setScalarOpacity(0, ofun)
}

export { setPetColorMapTransferFunctionForVolumeActor }
