Esempio n. 1
0
        private void m_renderWinCtrl_Load(object sender, EventArgs e)
        {
            m_renWindow = m_renderWinCtrl.RenderWindow;
            m_render    = m_renWindow.GetRenderers().GetFirstRenderer();
            m_iren      = m_renWindow.GetInteractor();

            InitRenderWindow();
        }
Esempio n. 2
0
        public MyInteractorStyle(RenderWindowControl ctrl)
        {
            m_RWCtrl   = ctrl;
            m_rendWin  = ctrl.RenderWindow;
            m_renderer = m_rendWin.GetRenderers().GetFirstRenderer();
            m_iren     = m_rendWin.GetInteractor();

            m_iren.LeftButtonReleaseEvt += new vtkObjectEventHandler(m_interactor_LeftButtonReleaseEvt);

            m_iren.LeftButtonPressEvt += new vtkObjectEventHandler(m_iren_RightButtonPressEvt);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            vtkSTLReader reader = vtkSTLReader.New();
            string       path   = @"d:\Staz\projekt2\Projekt2\Projekt2\fibula.stl";

            reader.SetFileName(path);
            vtkPolyDataMapper Mapper = vtkPolyDataMapper.New();

            Mapper.SetInputConnection(reader.GetOutputPort());
            vtkActor Actor = vtkActor.New();

            Actor.SetMapper(Mapper);
            renderer.AddActor(Actor);
            reader.SetFileName(path);
            vtkPolyDataMapper Mapperinscription = vtkPolyDataMapper.New();

            Mapperinscription.SetInputConnection(reader.GetOutputPort());

            renderer.ResetCamera();
            renderWindow.GetInteractor().Render();
        }
Esempio n. 4
0
        private void CreateAxes()
        {
            //  -------------------- Axes of Coordinate system --------------------------------------------
            Axes = new vtkAxesActor();
            Axes.GetXAxisShaftProperty().SetLineWidth((float)3.0);
            Axes.GetYAxisShaftProperty().SetLineWidth((float)3.0);
            Axes.GetZAxisShaftProperty().SetLineWidth((float)3.0);
            Axes.GetXAxisShaftProperty().SetRepresentationToSurface();
            Axes.GetYAxisShaftProperty().SetRepresentationToSurface();
            Axes.GetZAxisShaftProperty().SetRepresentationToSurface();

            Axes.GetXAxisCaptionActor2D().GetCaptionTextProperty().SetFontSize(25);
            Axes.GetXAxisCaptionActor2D().GetCaptionTextProperty().SetBold(0);
            Axes.GetXAxisCaptionActor2D().GetCaptionTextProperty().ItalicOff();
            Axes.GetXAxisCaptionActor2D().GetCaptionTextProperty().ShadowOff();
            Axes.GetXAxisCaptionActor2D().GetTextActor().SetTextScaleModeToNone();

            Axes.GetYAxisCaptionActor2D().GetCaptionTextProperty().SetFontSize(25);
            Axes.GetYAxisCaptionActor2D().GetCaptionTextProperty().SetBold(0);
            Axes.GetYAxisCaptionActor2D().GetCaptionTextProperty().ItalicOff();
            Axes.GetYAxisCaptionActor2D().GetCaptionTextProperty().ShadowOff();
            Axes.GetYAxisCaptionActor2D().GetTextActor().SetTextScaleModeToNone();

            Axes.GetZAxisCaptionActor2D().GetCaptionTextProperty().SetFontSize(25);
            Axes.GetZAxisCaptionActor2D().GetCaptionTextProperty().SetBold(0);
            Axes.GetZAxisCaptionActor2D().GetCaptionTextProperty().ItalicOff();
            Axes.GetZAxisCaptionActor2D().GetCaptionTextProperty().ShadowOff();
            Axes.GetZAxisCaptionActor2D().GetTextActor().SetTextScaleModeToNone();

            Widget = new vtkOrientationMarkerWidget();
            Widget.SetOrientationMarker(Axes);
            Widget.SetInteractor(renderWindow.GetInteractor());
            Widget.SetViewport(0.7, 0.7, 1.2, 1.2);
            Widget.SetEnabled(1);
            Widget.InteractiveOff();
        }
        /// <summary>
        /// Renders this VtkRenderWindowControl.
        /// </summary>
        ///
        /// <seealso cref="M:ActivizWPF.Framework.Native.HwndWrapper.Render()"/>
        protected override void Render()
        {
            try
            {
                if (_renderWindow != null)
                {
                    this.SyncRenderWindowSize();

                    if (_renderWindow.GetInteractor() != _renderWindowInteractor)
                    {
                        AttachInteractor();
                        _renderWindow.Render();
                    }

                    _renderWindow.Render();
                }
            }
            catch (Exception e)
            {
                log.ErrorException("Render()", e);
            }
        }
Esempio n. 6
0
        private void DrawSelectedLineCircular()
        {
            DateTime monday = this.startDate.AddDays(-(int)this.startDate.DayOfWeek + (int)DayOfWeek.Monday);

            List <vtkActor> actors = new List <vtkActor>();


            if (!string.IsNullOrEmpty(this.circularChartSelectedLine))
            {
                actors.AddRange(this.DrawSectors(monday, 5, this.lines[this.circularChartSelectedLine]));
            }

            vtkRenderWindow renderWindow = this.RenderWindowCircularChart.RenderWindow;

            vtkInteractorStyleImage interactorStyle = new vtkInteractorStyleImage();

            renderWindow.GetInteractor().SetInteractorStyle(interactorStyle);

            vtkRenderer renderer = renderer = renderWindow.GetRenderers().GetFirstRenderer();

            renderer.SetBackground(0.6f, 0.6f, 0.6f);

            renderer.Clear();
            this.RenderWindowCircularChart.Invalidate();


            actors.AddRange(this.DrawClockLines());


            foreach (vtkActor actor in actors)
            {
                renderer.AddActor(actor);
            }



            this.RenderWindowCircularChart.Update();
        }
Esempio n. 7
0
        /// <summary>
        /// 读取stl文件,并在窗口进行显示,并设置全局变量originalMesh
        /// </summary>
        private void ReadSTL()
        {
            //Path to vtk data must be set as an environment variable
            //VTK_DATA_ROOT=""
            vtkSTLReader reader = vtkSTLReader.New();
            reader.SetFileName(FileFullName);
            reader.Update();
            mapper = vtkPolyDataMapper.New();
            mapper.SetInputConnection(reader.GetOutputPort());

            actor = vtkActor.New();
            actor.SetMapper(mapper);
            //get a reference to the renderwindow of our renderWindowControll
            renderWindow = renderWindowControl1.RenderWindow;
            //renderer
            renderer = renderWindow.GetRenderers().GetFirstRenderer();
            //移除之前所有prop
            renderer.RemoveAllViewProps();
            //set background color
            renderer.SetBackground(0.2, 0.3, 0.4);
            //add our actor to the renderer
            renderer.AddActor(actor);
            originalMesh = vtkPolyData.New();
            originalMesh.DeepCopy(reader.GetOutput());
            tb_numOfPoint.Text = originalMesh.GetNumberOfPoints().ToString();

            //creat a cell picker
            picker = vtkCellPicker.New();
            vtkRenderWindowInteractor iren = renderWindow.GetInteractor();
            iren.SetPicker(picker);

            renderer.ResetCamera();
            renderWindow.Render();
        }
Esempio n. 8
0
 //Set default
 public void set_default()
 {
     renWin.GetInteractor().SetInteractorStyle(default_style);
 }
Esempio n. 9
0
        private void PolygonalSurfaceContourLineInterpolator()
        {
            vtkPolyData     polyData;
            vtkSphereSource sphereSource = vtkSphereSource.New();

            sphereSource.SetThetaResolution(40);
            sphereSource.SetPhiResolution(20);
            sphereSource.Update();

            polyData = sphereSource.GetOutput();
            // The Dijkstra interpolator will not accept cells that aren't triangles
            vtkTriangleFilter triangleFilter = vtkTriangleFilter.New();

#if VTK_MAJOR_VERSION_5
            triangleFilter.SetInput(polyData);
#else
            triangleFilter.SetInputData(polyData);
#endif
            triangleFilter.Update();

            vtkPolyData pd = triangleFilter.GetOutput();

            //Create a mapper and actor
            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();
            mapper.SetInputConnection(triangleFilter.GetOutputPort());

            vtkActor actor = vtkActor.New();
            actor.SetMapper(mapper);
            actor.GetProperty().SetInterpolationToFlat();

            // get a reference to the renderwindow of our renderWindowControl1
            vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;
            // renderer
            vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer();
            // set background color
            renderer.SetBackground(0.3, 0.4, 0.5);
            // add our actor to the renderer
            renderer.AddActor(actor);

            // Here comes the contour widget stuff.....
            vtkContourWidget contourWidget = vtkContourWidget.New();
            contourWidget.SetInteractor(renderWindow.GetInteractor());
            vtkOrientedGlyphContourRepresentation rep =
                vtkOrientedGlyphContourRepresentation.SafeDownCast(
                    contourWidget.GetRepresentation());
            rep.GetLinesProperty().SetColor(1, 0.2, 0);
            rep.GetLinesProperty().SetLineWidth(3.0f);

            vtkPolygonalSurfacePointPlacer pointPlacer =
                vtkPolygonalSurfacePointPlacer.New();
            pointPlacer.AddProp(actor);
            pointPlacer.GetPolys().AddItem(pd);
            rep.SetPointPlacer(pointPlacer);

            vtkPolygonalSurfaceContourLineInterpolator interpolator =
                vtkPolygonalSurfaceContourLineInterpolator.New();
            interpolator.GetPolys().AddItem(pd);
            rep.SetLineInterpolator(interpolator);

            renderWindow.Render();
            contourWidget.EnabledOn();
        }
Esempio n. 10
0
        private void ReadDICOMSeries()
        {
            // Path to vtk data must be set as an environment variable
            // VTK_DATA_ROOT = "C:\VTK\vtkdata-5.8.0"
            vtkTesting test = vtkTesting.New();
            string     root = test.GetDataRoot();
            // Read all the DICOM files in the specified directory.
            // Caution: folder "DicomTestImages" don't exists by default in the standard vtk data folder
            // sample data are available at http://www.vtk.org/Wiki/images/1/12/VTK_Examples_StandardFormats_Input_DicomTestImages.zip

            //string folder = Path.Combine(root, @"Data\DicomTestImages");
            string folder = @"provaDicom/" + studyUID;

            Console.WriteLine(folder);
            vtkDICOMImageReader reader = vtkDICOMImageReader.New();

            reader.SetDirectoryName(folder);
            reader.Update();
            // Visualize
            _ImageViewer = vtkImageViewer2.New();
            _ImageViewer.SetInputConnection(reader.GetOutputPort());
            // get range of slices (min is the first index, max is the last index)
            _ImageViewer.GetSliceRange(ref _MinSlice, ref _MaxSlice);
            Debug.WriteLine("slices range from : " + _MinSlice.ToString() + " to " + _MaxSlice.ToString());

            // slice status message
            vtkTextProperty sliceTextProp = vtkTextProperty.New();

            sliceTextProp.SetFontFamilyToCourier();
            sliceTextProp.SetFontSize(20);
            sliceTextProp.SetVerticalJustificationToBottom();
            sliceTextProp.SetJustificationToLeft();

            _SliceStatusMapper = vtkTextMapper.New();
            _SliceStatusMapper.SetInput("Slice No " + (_Slice + 1).ToString() + "/" + (_MaxSlice + 1).ToString());
            _SliceStatusMapper.SetTextProperty(sliceTextProp);

            vtkActor2D sliceStatusActor = vtkActor2D.New();

            sliceStatusActor.SetMapper(_SliceStatusMapper);
            sliceStatusActor.SetPosition(15, 10);
            // usage hint message
            vtkTextProperty usageTextProp = vtkTextProperty.New();

            usageTextProp.SetFontFamilyToCourier();
            usageTextProp.SetFontSize(14);
            usageTextProp.SetVerticalJustificationToTop();
            usageTextProp.SetJustificationToLeft();

            vtkTextMapper usageTextMapper = vtkTextMapper.New();

            usageTextMapper.SetInput("Slice with mouse wheel\nor Up/Down-Key");
            usageTextMapper.SetTextProperty(usageTextProp);

            vtkActor2D usageTextActor = vtkActor2D.New();

            usageTextActor.SetMapper(usageTextMapper);
            usageTextActor.GetPositionCoordinate().SetCoordinateSystemToNormalizedDisplay();
            usageTextActor.GetPositionCoordinate().SetValue(0.05, 0.95);

            vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;

            vtkInteractorStyleImage interactorStyle = vtkInteractorStyleImage.New();

            // NOTA:non funziona la rotellina del mouse per cambiare slice <--------------------------------------
            // l'errore è causato dalla funzione DicomCFindRequest(della sorgente di FellowOak)
            //in QueryFellowOak.cs, in particolare dal costruttore
            // DicomCFindRequest(DicomQueryRetrieveLevel level)

            // interactorStyle.MouseWheelForwardEvt += new vtkObject.vtkObjectEventHandler(interactor_MouseWheelForwardEvt);
            //  interactorStyle.MouseWheelBackwardEvt += new vtkObject.vtkObjectEventHandler(interactor_MouseWheelBackwardEvt);

            renderWindow.GetInteractor().SetInteractorStyle(interactorStyle);
            renderWindow.GetRenderers().InitTraversal();
            vtkRenderer ren;

            while ((ren = renderWindow.GetRenderers().GetNextItem()) != null)
            {
                ren.SetBackground(0.0, 0.0, 0.0);
            }

            _ImageViewer.SetRenderWindow(renderWindow);
            _ImageViewer.GetRenderer().AddActor2D(sliceStatusActor);
            _ImageViewer.GetRenderer().AddActor2D(usageTextActor);
            _ImageViewer.SetSlice(_MinSlice);
            _ImageViewer.Render();
        }