[vtkusers] How to show the cross hairs for vtkResliceImageViewer

Liu_tj tjlp at netease.com
Mon Mar 21 10:20:31 EDT 2016


Hi, VTK guys,

I use vtkResliceImageViewer to display DICOM series. But the 2 cross hairs are not displayed. How to show it? The reslice mode to axis-aligned. The GreyToColors() function adds LookupTable for the image viewer.

My code below:

       private void Display2(vtkRenderWindow aRenderWindow, vtkImageData aData)
        {
            if (aData == null)
                return;

            m_imageViewer = vtkResliceImageViewer.New();
           
            vtkRenderWindowInteractor interactor = aRenderWindow.GetInteractor();

            m_renderer = aRenderWindow.GetRenderers().GetFirstRenderer();
            m_renderer.SetBackground(0.0, 0.0, 0.0);

            m_imageViewer.SetRenderWindow(aRenderWindow);

            m_imageViewer.SetupInteractor(interactor);
            m_imageViewer.SetRenderer(m_renderer);
            //aRenderWindow.GetRenderers().InitTraversal();

            m_imageViewer.SetInputData(aData);
            m_imageViewer.SliceScrollOnMouseWheelOn();
            m_imageViewer.SetResliceModeToAxisAligned();
            //m_imageViewer.SetResliceModeToOblique();
            vtkResliceCursorLineRepresentation rep = vtkResliceCursorLineRepresentation.SafeDownCast(m_imageViewer.GetResliceCursorWidget().GetRepresentation());
            rep.GetResliceCursorActor().GetCursorAlgorithm().SetReslicePlaneNormal((int)m_sliceDirection);
            switch (m_sliceDirection)
            {
                case Direction.AXIAL:
                    m_imageViewer.SetSliceOrientationToXY();
                    break;
                case Direction.CORONAL:
                    m_imageViewer.SetSliceOrientationToYZ();
                    break;
                case Direction.SAGITTAL:
                    m_imageViewer.SetSliceOrientationToXZ();
                    break;
                default:
                    break;
            }
            m_imageViewer.SetThickMode(1);
            m_imageViewer.GetSliceRange(ref m_minSliceNumber, ref m_maxSliceNumber);
            m_currentSlice = m_minSliceNumber + (m_maxSliceNumber - m_minSliceNumber) / 2;
            m_imageViewer.SetSlice(m_currentSlice);

            m_scalarrange = new double[2];
            m_scalarrange = m_imageViewer.GetInput().GetScalarRange();

            if (!m_initialized)
            {
                m_threshold = new Segament_Threshold();
                m_threshold.Min_Threshold = 0;
                m_threshold.Max_Threshold = m_scalarrange[1];
            }
            GrayToColors(m_threshold);
            m_initialized = true;
        }

        private void GrayToColors( Segament_Threshold threshold)
        {
            vtkLookupTable colormap = 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);
            colormap.SetRange(m_scalarrange[0], m_scalarrange[1]);
            colormap.SetNumberOfTableValues(number);
            colormap.Build();

            //for (int i = (int)(scalarrange[0]); i < (int)(threshhold[0]); i++)
            //{
            //    colormap.SetTableValue(i - (int)scalarrange[0], 0.0, 0.0, 0.0, 0.0);
            //}
            for (int i = (int)(validmin); i <= (int)(validmax); i++)
            {
                colormap.SetTableValue(i - (int)m_scalarrange[0], RenderingColor.RENDERING_RED, RenderingColor.RENDERING_GREEN, RenderingColor.RENDERING_BLUE, 1.0);
            }
            for (int i = (int)(threshold.Max_Threshold) + 1; i < (int)(m_scalarrange[1]); i++)
            {
                colormap.SetTableValue(i - (int)m_scalarrange[0], 0.0, 0.0, 0.0, 0.0);
            }

            //vtkImageMapToColors colormapper = vtkImageMapToColors.New();
            //colormapper.SetInputConnection(data);
            vtkImageMapToWindowLevelColors colormapper = m_imageViewer.GetWindowLevel();
            colormapper.SetOutputFormatToRGB();
            colormapper.SetLookupTable(colormap);
            colormapper.Update();

            if (!m_initialized)
                m_colormapActor = vtkImageActor.New();
            m_colormapActor.SetInputData(colormapper.GetOutput());
            if (!m_initialized)
                m_renderer.AddActor(m_colormapActor);           
            m_renderer.ResetCamera();
            m_renderer.Modified();
            m_imageViewer.Render();
        }

Thanks
Liu Peng

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160321/a37e97e6/attachment.html>


More information about the vtkusers mailing list