[vtkusers] vtkImageMapToColors doesn't work on vtkImageViewer2
Liu_tj
tjlp at netease.com
Fri Apr 1 10:31:02 EDT 2016
Hi, VTK guys,
I use vtkImageViewer2 to display DICOM series. Now I want to display special color for some grayscale threshold. But it doesn't work. Any steps do I miss? Below is my C# code. Segament_Threshold is a defined class including two members: Min_Threshold and Max_Threshold.
private void GrayToColors( Segament_Threshold threshold)
{
m_scalarrange = new double[2];
m_scalarrange = m_imageViewer.GetInput().GetScalarRange();
vtkLookupTable lookupTable = vtkLookupTable.New();
double validmin = System.Math.Max(m_scalarrange[0], threshold.Min_Threshold);
double validmax = System.Math.Min(m_scalarrange[1], threshold.Max_Threshold);
int number = (int)(m_scalarrange[1] - m_scalarrange[0] + 1);
lookupTable.SetRange(m_scalarrange[0], m_scalarrange[1]);
lookupTable.SetNumberOfTableValues(number);
lookupTable.Build();
for (int i = (int)(m_scalarrange[0]); i < (int)(validmin); i++)
{
lookupTable.SetTableValue(i - (int)m_scalarrange[0], 0.0, 0.0, 0.0, 0.0);
}
for (int i = (int)(validmin); i <= (int)(validmax); i++)
{
lookupTable.SetTableValue(i - (int)m_scalarrange[0], 0x66 / 0xff, 1.0, 1.0, 1.0);
}
for (int i = (int)(threshold.Max_Threshold) + 1; i < (int)(m_scalarrange[1]); i++)
{
lookupTable.SetTableValue(i - (int)m_scalarrange[0], 0.0, 0.0, 0.0, 0.0);
}
vtkImageMapToColors colormapper = vtkImageMapToColors.New();
colormapper.SetInputData(m_imageViewer.GetInput());
colormapper.SetOutputFormatToRGB();
colormapper.PassAlphaToOutputOn();
colormapper.SetLookupTable(lookupTable);
colormapper.Update();
if (m_colormapActor == null)
{
m_colormapActor = vtkImageActor.New();
m_colormapActor.GetMapper().SetInputConnection(colormapper.GetOutputPort());
m_renderer.AddActor(m_colormapActor);
}
m_renderer.ResetCamera();
m_renderer.Modified();
m_imageViewer.SetRenderer(m_renderer);
m_imageViewer.Render();
}
Thanks
Liu Peng
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160401/a54186bf/attachment.html>
More information about the vtkusers
mailing list