Пример #1
0
        private void UpdateRendererOutline(ref vtk.vtkActor2D outlineRendererActor, ref vtk.vtkPolyData polyData, vtk.vtkRenderer renderer)
        {
            try
            {

                if (outlineRendererActor == null)
                {
                    outlineRendererActor = new vtk.vtkActor2D();

                    polyData = new vtk.vtkPolyData();
                    polyData.Allocate(5, 0);

                    vtk.vtkIdList idList = new vtk.vtkIdList();
                    idList.SetNumberOfIds(5);

                    vtk.vtkPoints points = new vtk.vtkPoints();
                    idList.InsertId(0, points.InsertNextPoint(1, 1, 0));
                    idList.InsertId(1, points.InsertNextPoint(2, 1, 0));
                    idList.InsertId(2, points.InsertNextPoint(2, 2, 0));
                    idList.InsertId(3, points.InsertNextPoint(1, 2, 0));
                    idList.InsertId(4, idList.GetId(0));

                    polyData.SetPoints(points);
                    polyData.InsertNextCell(4, idList);

                    vtk.vtkCoordinate coordinate = new vtk.vtkCoordinate();
                    coordinate.SetCoordinateSystemToDisplay();
                    vtk.vtkPolyDataMapper2D mapper = new vtk.vtkPolyDataMapper2D();
                    mapper.SetInput(polyData);
                    mapper.SetTransformCoordinate(coordinate);

                    outlineRendererActor.SetMapper(mapper);
                    outlineRendererActor.SetPosition(0, 0);
                    outlineRendererActor.SetPosition2(1, 1);

                    renderer.AddActor(outlineRendererActor);
                }

                double[] vp = renderer.GetViewport();
                renderer.NormalizedDisplayToDisplay(ref vp[0], ref vp[1]);
                renderer.NormalizedDisplayToDisplay(ref vp[2], ref vp[3]);

                polyData.GetPoints().SetPoint(0, vp[0], vp[1], 0);
                polyData.GetPoints().SetPoint(1, vp[2], vp[1], 0);
                polyData.GetPoints().SetPoint(2, vp[2], vp[3], 0);
                polyData.GetPoints().SetPoint(3, vp[0], vp[3], 0);

                // Change Outline color and width
                double[] normalOutlineColor = ApplicationOptions.Instance().RendererLayoutOptions.NormalOutlineColor;
                float normalOutlineWidth = ApplicationOptions.Instance().RendererLayoutOptions.NormalOutlineLineWidth;

                if (renderer == IApp.theApp.RendererManager.ActiveRenderer)
                {
                    normalOutlineColor = ApplicationOptions.Instance().RendererLayoutOptions.ActiveOutlineColor;
                    normalOutlineWidth = ApplicationOptions.Instance().RendererLayoutOptions.ActiveOutlineLineWidth;
                }

                outlineRendererActor.GetProperty().SetColor(normalOutlineColor);
                outlineRendererActor.GetProperty().SetLineWidth(normalOutlineWidth);
            }
            catch (Exception ex)
            {
                string errMsg = ex.Message + "\n" + ex.StackTrace;
                vtk.vtkOutputWindow.GetInstance().DisplayErrorText(errMsg);
            }
        }
Пример #2
0
        void Run()
        {
            // Create a selection window.  We will display the point and cell ids
            // that lie within this window.
            int xmin = 200;
            xLength = 100;
            xmax = xmin + xLength;
            int ymin = 200;
            yLength = 100;
            ymax = ymin + yLength;

            pts = new vtk.vtkPoints();
            pts.InsertPoint(0, xmin, ymin, 0);
            pts.InsertPoint(1, xmax, ymin, 0);
            pts.InsertPoint(2, xmax, ymax, 0);
            pts.InsertPoint(3, xmin, ymax, 0);
            vtk.vtkCellArray rect = new vtk.vtkCellArray();
            rect.InsertNextCell(5);
            rect.InsertCellPoint(0);
            rect.InsertCellPoint(1);
            rect.InsertCellPoint(2);
            rect.InsertCellPoint(3);
            rect.InsertCellPoint(0);
            vtk.vtkPolyData selectRect = new vtk.vtkPolyData();
            selectRect.SetPoints(pts);
            selectRect.SetLines(rect);
            vtk.vtkPolyDataMapper2D rectMapper = new vtk.vtkPolyDataMapper2D();
            rectMapper.SetInput(selectRect);
            vtk.vtkActor2D rectActor = new vtk.vtkActor2D();
            rectActor.SetMapper(rectMapper);

            // Create a sphere and its associated mapper and actor.
            vtk.vtkSphereSource sphere = new vtk.vtkSphereSource();
            vtk.vtkPolyDataMapper sphereMapper = new vtk.vtkPolyDataMapper();
            sphereMapper.SetInputConnection(sphere.GetOutputPort());
            vtk.vtkPolyDataMapper.GlobalImmediateModeRenderingOn();
            vtk.vtkActor sphereActor = new vtk.vtkActor();
            sphereActor.SetMapper(sphereMapper);

            // Generate data arrays containing point and cell ids
            vtk.vtkIdFilter ids = new vtk.vtkIdFilter();
            ids.SetInputConnection(sphere.GetOutputPort());
            ids.PointIdsOn();
            ids.CellIdsOn();
            ids.FieldDataOn();

            // Create the renderer here because vtkSelectVisiblePoints needs it.
            vtk.vtkRenderer ren = new vtk.vtkRenderer();

            // Create labels for points
            visPts = new vtk.vtkSelectVisiblePoints();
            visPts.SetInputConnection(ids.GetOutputPort());
            visPts.SetRenderer(ren);
            visPts.SelectionWindowOn();
            visPts.SetSelection(xmin, xmin + xLength, ymin, ymin + yLength);

            // Create the mapper to display the point ids.  Specify the format to
            // use for the labels.  Also create the associated actor.
            vtk.vtkLabeledDataMapper ldm = new vtk.vtkLabeledDataMapper();
            ldm.SetInputConnection(visPts.GetOutputPort());
            ldm.SetLabelFormat("%g");
            ldm.SetLabelModeToLabelFieldData();
            vtk.vtkActor2D pointLabels = new vtk.vtkActor2D();
            pointLabels.SetMapper(ldm);

            // Create labels for cells
            vtk.vtkCellCenters cc = new vtk.vtkCellCenters();
            cc.SetInputConnection(ids.GetOutputPort());
            visCells = new vtk.vtkSelectVisiblePoints();
            visCells.SetInputConnection(cc.GetOutputPort());
            visCells.SetRenderer(ren);
            visCells.SelectionWindowOn();
            visCells.SetSelection(xmin, xmin + xLength, ymin, ymin + yLength);

            // Create the mapper to display the cell ids.  Specify the format to
            // use for the labels.  Also create the associated actor.
            vtk.vtkLabeledDataMapper cellMapper = new vtk.vtkLabeledDataMapper();
            cellMapper.SetInputConnection(visCells.GetOutputPort());
            cellMapper.SetLabelFormat("%g");
            cellMapper.SetLabelModeToLabelFieldData();
            cellMapper.GetLabelTextProperty().SetColor(0, 1, 0);
            vtk.vtkActor2D cellLabels = new vtk.vtkActor2D();
            cellLabels.SetMapper(cellMapper);

            // Create the RenderWindow and RenderWindowInteractor
            renWin = new vtk.vtkRenderWindow();
            renWin.AddRenderer(ren);
            vtk.vtkRenderWindowInteractor iren = new vtk.vtkRenderWindowInteractor();
            iren.SetRenderWindow(renWin);

            // Add the actors to the renderer; set the background and size;
            // render
            ren.AddActor(sphereActor);
            ren.AddActor2D(rectActor);
            ren.AddActor2D(pointLabels);
            ren.AddActor2D(cellLabels);

            ren.SetBackground(1, 1, 1);
            renWin.SetSize(500, 500);

            // Initialize the interactor.
            iren.Initialize();
            renWin.Render();

            // Move the selection window across the data set.
            MoveWindow();

            // Put the selection window in the center of the render window.
            // This works because the xmin = ymin = 200, xLength = yLength = 100, and
            // the render window size is 500 x 500.
            PlaceWindow(xmin, ymin);

            // Now start normal interaction.
            iren.Start();
            vtk.vtkWin32OpenGLRenderWindow win32win =
                vtk.vtkWin32OpenGLRenderWindow.SafeDownCast(renWin);
            if (null != win32win) win32win.Clean();
        }
Пример #3
0
        // Function: Calculate en render Histogram in window
        public void renderHistogram(vtk.vtkImageData VoxelData)
        {
            // Get size of histogram window
            int[] size = renHist.GetSize();
            width = size[0]; height = size[1];


            //Setup parameters histogram Accumulate Filter
            numBins    = width / 2;
            inputRange = VoxelData.GetScalarRange();
            double origin  = inputRange[0];
            double spacing = 1.0 * (inputRange[1] - origin) / numBins;

            // Setup Accumulate filter
            vtk.vtkImageAccumulate accumulate = new vtk.vtkImageAccumulate();
            accumulate.SetInput(VoxelData); //Get input voxeldata
            accumulate.SetComponentExtent(0, numBins - 1, 0, 0, 0, 0);
            accumulate.SetComponentOrigin(origin, 0.0, 0.0);
            accumulate.SetComponentSpacing(spacing, 1.0, 1.0);

            // Make Data object from Accumulated object
            data = accumulate.GetOutput();
            data.Update();

            // Initialize first and last point of the transferfunction.
            npoints    = 2;
            pointsx[0] = 0; pointsy[0] = 0;
            pointsx[1] = width - 1; pointsy[1] = height - 1;
            pointsc[0] = 1; pointsc[1] = 1;

            // Draw the histogram in a canvas and add the transferfunction to it
            drawhisto();
            drawcurve();

            // Create a color table
            vtk.vtkColorTransferFunction colorTransferFunction = new vtk.vtkColorTransferFunction();
            for (int i = 0; i < 14; i++)
            {
                colorTransferFunction.AddRGBPoint(i, colortable[i, 0], colortable[i, 1], colortable[i, 2]);
            }



            // Use the color table to color the histogram window objects
            vtk.vtkImageMapToColors sColors = new vtk.vtkImageMapToColors();
            sColors.SetInputConnection(canvas.GetOutputPort());
            sColors.SetLookupTable(colorTransferFunction);

            // Convert the histogram image to a histogram imagemap
            vtk.vtkImageMapper histmap = new vtk.vtkImageMapper();
            histmap.SetInputConnection(sColors.GetOutputPort());
            histmap.RenderToRectangleOn();
            histmap.SetColorWindow(256);
            histmap.SetColorLevel(127);

            // Create the actor needed to draw the histogram image
            vtk.vtkActor2D imageactor = new vtk.vtkActor2D();
            imageactor.SetMapper(histmap);
            imageactor.SetPosition(0, 0); // Fit the histogram to the window
            imageactor.SetPosition2(1, 1);

            // Add the Histogram Image Render to the window object
            ren1.AddActor(imageactor);
            ren1.SetViewport(0, 0, 1, 1); // Fit the histogram to the window
            renHist.AddRenderer(ren1);

            // Add a Window (mouse) interactor to the window
            iren.SetRenderWindow(renHist);

            // Add mouse events to the window
            iren.RemoveObserver((uint)vtk.EventIds.LeftButtonPressEvent);
            iren.AddObserver((uint)vtk.EventIds.LeftButtonPressEvent, new vtk.vtkDotNetCallback(LeftButtonPress));

            iren.RemoveObserver((uint)vtk.EventIds.LeftButtonReleaseEvent);
            iren.AddObserver((uint)vtk.EventIds.LeftButtonReleaseEvent, new vtk.vtkDotNetCallback(LeftButtonRelease));

            iren.RemoveObserver((uint)vtk.EventIds.MouseMoveEvent);
            iren.AddObserver((uint)vtk.EventIds.MouseMoveEvent, new vtk.vtkDotNetCallback(MouseMove));

            iren.RemoveObserver((uint)vtk.EventIds.RightButtonPressEvent);
            iren.AddObserver((uint)vtk.EventIds.RightButtonPressEvent, new vtk.vtkDotNetCallback(RightButtonPress));

            iren.RemoveObserver((uint)vtk.EventIds.MiddleButtonPressEvent);
            iren.AddObserver((uint)vtk.EventIds.MiddleButtonPressEvent, new vtk.vtkDotNetCallback(MiddleButtonPress));

            // Set the (display) update rate of the histogram
            iren.SetStillUpdateRate(5);
            iren.SetDesiredUpdateRate(5);

            // Initialize interactor and render histogram
            iren.Initialize();
            renHist.Render();

            // Debug output
            info = "Histogram is created \r\n";
        }