public override void UpatePoints()
        {
            // Get Point List
            if (Parent == null) return;
            IList<CTwoPoints> pointsList = Parent.PointsList;

            // Update points
            if (m_points == null)
            {
                m_points = new vtk.vtkPoints();

                // Create Points
                m_points.Reset();
                foreach (CTwoPoints pair in pointsList)
                {
                    m_points.InsertNextPoint(pair.First.Point);
                    m_points.InsertNextPoint(pair.Second.Point);
                }

                vtk.vtkCellArray lines = new vtk.vtkCellArray();
                for (int i = 0; i < pointsList.Count; ++i)
                {
                    // Create Linee
                    vtk.vtkLine line = new vtk.vtkLine();
                    line.GetPointIds().SetId(0, i * 2);
                    line.GetPointIds().SetId(1, i * 2 + 1);

                    lines.InsertNextCell(line);
                }

                vtk.vtkPolyData polyData = new vtk.vtkPolyData();
                polyData.SetPoints(m_points);
                polyData.SetLines(lines);

                vtk.vtkPolyDataMapper dataMapper = new vtk.vtkPolyDataMapper();
                dataMapper.SetInput(polyData);

                Actor.SetMapper(dataMapper);
            }
            else if (m_points.GetNumberOfPoints() != pointsList.Count * 2)
            {
                return;
            }
            else
            {
                m_points.Reset();
                foreach (CTwoPoints pair in pointsList)
                {
                    m_points.InsertNextPoint(pair.First.Point);
                    m_points.InsertNextPoint(pair.Second.Point);
                }
                m_points.Modified();
            }
        }
Ejemplo n.º 2
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);
            }
        }