now i making pI’m creating a program that overlays two objects and prints one object with color mapping based on the coordinate values.

The overlay output was successful, but I could not find a way to do color mapping.

I output two objects using vtkVolume. However, the problem is that I can not extract the value corresponding to the coordinates of the object to be color-mapped in vtkVolume. How do I do color mapping to a volume? Thank you very much for your answers.

```
import vtk
import nrrd
import numpy as np
from vtk.util import numpy_support as VN
renWin = vtk.vtkRenderWindow()
renderer = vtk.vtkRenderer()
renWin.AddRenderer(renderer)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
lstVolume = []
reader = vtk.vtkNrrdReader()
reader.SetFileName('sample_nrrd.nrrd')
reader.Update()
vol = ImageDataToVolume(reader.GetOutput())
lstVolume.append(vol)
renderer.AddVolume(vol)
reader1 = vtk.vtkNrrdReader()
reader1.SetFileName('Segmentation-label_2.nrrd')
reader1.Update()
scalar = GetScalarData(reader1)
print(scalar)
vol1 = ImageDataToVolume(reader1.GetOutput())
lstVolume.append(vol1)
renderer.AddVolume(vol1)
iren.Initialize()
renWin.Render()
iren.Start()
def ImageDataToVolume(imagedata):
mapper = vtk.vtkSmartVolumeMapper()
mapper.SetInputData(imagedata)
vol = vtk.vtkVolume()
vol.SetMapper(mapper)
ApplyAutoVolumeProperty(imagedata, mapper, vol)
return vol
def GetScalarData(ptData):
vtkDataArray = ptData.GetScalars()
if vtkDataArray == None:
return np.array([])
sData = VN.vtk_to_numpy(vtkDataArray)
return sData
def ApplyAutoVolumeProperty(pData, pMapper, pVolume):
scalar = GetScalarData(pData.GetPointData())
min_value = -1000
max_value = 3095
fCenter = (max_value - min_value) / 2.0
fWidth = max_value - min_value
fLow = fCenter - fWidth / 2.0
fHigh = fCenter + fWidth / 2.0
fTerm = fHigh - fLow;
print("min, max : " + str(min_value) + ", " + str(max_value))
pMapper.SetBlendModeToComposite()
volProperty = vtk.vtkVolumeProperty()
volProperty.ShadeOn()
volProperty.SetInterpolationTypeToLinear()
volProperty.SetDiffuse(0.7)
volProperty.SetAmbient(0.2)
volProperty.SetSpecular(0.3)
volProperty.SetSpecularPower(30.0)
otf = vtk.vtkPiecewiseFunction()
otf.AddPoint(fLow, 0.0) # start
otf.AddPoint(fHigh, 1.0) # end
volProperty.SetScalarOpacity(0, otf)
ctf = vtk.vtkColorTransferFunction()
ctf.AddRGBPoint(fLow + fTerm * 0 * 0.2, 0.0, 0.0, 0.0)
ctf.AddRGBPoint(fLow + fTerm * 1 * 0.2, 0.7, 0.4, 0.1)
ctf.AddRGBPoint(fLow + fTerm * 2 * 0.2, 0.6, 0.5, 0.3)
ctf.AddRGBPoint(fHigh, 1.0, 1.0, 1.0)
volProperty.SetColor(0, ctf)
pVolume.SetProperty(volProperty)
pass
if __name__ == '__main__':
main()
```