private void DisposeSecondRenderWindow()
        {
            if (this.SecondRenderer != null)
            {
                this.SecondRenderer.SetRenderWindow(null);
            }

            if (this.SecondRenderWindowInteractor != null)
            {
                this.SecondRenderWindowInteractor.Dispose();
                this.SecondRenderWindowInteractor = null;
            }

            if (this.SecondRenderWindow != null)
            {
                this.SecondRenderWindow.Dispose();
                this.SecondRenderWindow = null;
            }

            if (this.SecondRenderer != null)
            {
                this.SecondRenderer.Dispose();
                this.SecondRenderer = null;
            }
        }
예제 #2
0
        public void InitializeVTK(System.Windows.Forms.Integration.WindowsFormsHost wfh)
        {
            this.AddTestActors = false;
            this.Dock          = System.Windows.Forms.DockStyle.Fill;
            wfh.Child          = this;
            wfh.Visibility     = System.Windows.Visibility.Visible;
            vtkRendererCollection rs = this.RenderWindow.GetRenderers();

            Kitware.VTK.vtkRenderer r = rs.GetFirstRenderer();
            r.SetBackground(0.1, 0.3, 0.7);
            r.SetBackground2(0.7, 0.8, 1.0);
            r.SetGradientBackground(true);

            m_renderer = r;
        }
        private Kitware.VTK.vtkRenderWindow AddConeSourceToSecondRenderWindow()
        {
            this.SecondRenderer               = Kitware.VTK.vtkRenderer.New();
            this.SecondRenderWindow           = Kitware.VTK.vtkRenderWindow.New();
            this.SecondRenderWindowInteractor = Kitware.VTK.vtkRenderWindowInteractor.New();

            this.SecondRenderWindow.AddRenderer(this.SecondRenderer);
            this.SecondRenderWindow.SetSize(400, 300);
            this.SecondRenderWindow.SetInteractor(this.SecondRenderWindowInteractor);

            AddConeSourceToRenderWindow(this.SecondRenderWindow);

            this.SecondRenderWindow.Render();

            return(this.SecondRenderWindow);
        }
예제 #4
0
        private void InitializeVTK()
        {
            Kitware.VTK.RenderWindowControl rw = new Kitware.VTK.RenderWindowControl();
            rw.AddTestActors = false;
            rw.Dock          = System.Windows.Forms.DockStyle.Fill;
            wfh.Child        = rw;
            wfh.Visibility   = System.Windows.Visibility.Visible;
            Kitware.VTK.vtkRendererCollection rs = rw.RenderWindow.GetRenderers();
            int rsc = rs.GetNumberOfItems();

            Console.WriteLine(rsc + " renderers");
            Kitware.VTK.vtkRenderer r = rs.GetFirstRenderer();
            r.SetBackground(0.1, 0.3, 0.7);
            r.SetBackground2(0.7, 0.8, 1.0);
            r.SetGradientBackground(true);

            Kitware.VTK.vtkAxesActor axa = new Kitware.VTK.vtkAxesActor();
            r.AddActor(axa);

            string vtkVersion = Kitware.VTK.vtkVersion.GetVTKVersion();

            vtkVersion = "VTK " + vtkVersion;
            Console.WriteLine(vtkVersion);

            this.label.Content = vtkVersion;

            axa.SetTotalLength(50.0, 50.0, 50.0);
            axa.SetConeRadius(0.1);
            //axa.SetAxisLabels(0);

            axa.GetXAxisCaptionActor2D().GetTextActor().SetTextScaleMode((int)Kitware.VTK.vtkTextActor.TEXT_SCALE_MODE_NONE_WrapperEnum.TEXT_SCALE_MODE_NONE);
            axa.GetXAxisCaptionActor2D().GetTextActor().GetTextProperty().SetFontSize(32);
            axa.GetYAxisCaptionActor2D().GetTextActor().SetTextScaleMode((int)Kitware.VTK.vtkTextActor.TEXT_SCALE_MODE_NONE_WrapperEnum.TEXT_SCALE_MODE_NONE);
            axa.GetYAxisCaptionActor2D().GetTextActor().GetTextProperty().SetFontSize(32);
            axa.GetZAxisCaptionActor2D().GetTextActor().SetTextScaleMode((int)Kitware.VTK.vtkTextActor.TEXT_SCALE_MODE_NONE_WrapperEnum.TEXT_SCALE_MODE_NONE);
            axa.GetZAxisCaptionActor2D().GetTextActor().GetTextProperty().SetFontSize(32);

            m_sa = this.CreateSphereActor(10.0);
            r.AddActor(m_sa);

            m_sa.SetPosition(25.0, 25.0, 25.0);
        }
        private void AddConeSourceToRenderWindow(Kitware.VTK.vtkRenderWindow renWin)
        {
            Kitware.VTK.vtkConeSource source = new Kitware.VTK.vtkConeSource();

            Kitware.VTK.vtkMapper mapper = new Kitware.VTK.vtkOpenGLPolyDataMapper();
            mapper.SetInputConnection(source.GetOutputPort());

            Kitware.VTK.vtkActor actor = new Kitware.VTK.vtkActor();
            actor.SetMapper(mapper);

            Kitware.VTK.vtkRenderer ren = null; //new Kitware.VTK.vtkOpenGLRenderer();
            ren = renWin.GetRenderers().GetFirstRenderer();
            ren.AddActor(actor);

            Kitware.VTK.vtkTextActor textActor = new Kitware.VTK.vtkTextActor();
            textActor.SetInput(Kitware.VTK.vtkVersion.GetVTKSourceVersion());
            ren.AddActor(textActor);

            //int n = renWin.GetRenderers().GetNumberOfItems();
            //System.Diagnostics.Debug.WriteLine(n);
            //System.Diagnostics.Debug.WriteLine(
            //  Kitware.mummy.Runtime.Methods.Print(false)
            //  );
        }
        private void DisposeSecondRenderWindow()
        {
            if (this.SecondRenderer != null)
              {
            this.SecondRenderer.SetRenderWindow(null);
              }

              if (this.SecondRenderWindowInteractor != null)
              {
            this.SecondRenderWindowInteractor.Dispose();
            this.SecondRenderWindowInteractor = null;
              }

              if (this.SecondRenderWindow != null)
              {
            this.SecondRenderWindow.Dispose();
            this.SecondRenderWindow = null;
              }

              if (this.SecondRenderer != null)
              {
            this.SecondRenderer.Dispose();
            this.SecondRenderer = null;
              }
        }
        private Kitware.VTK.vtkRenderWindow AddConeSourceToSecondRenderWindow()
        {
            this.SecondRenderer = Kitware.VTK.vtkRenderer.New();
              this.SecondRenderWindow = Kitware.VTK.vtkRenderWindow.New();
              this.SecondRenderWindowInteractor = Kitware.VTK.vtkRenderWindowInteractor.New();

              this.SecondRenderWindow.AddRenderer(this.SecondRenderer);
              this.SecondRenderWindow.SetSize(400, 300);
              this.SecondRenderWindow.SetInteractor(this.SecondRenderWindowInteractor);

              AddConeSourceToRenderWindow(this.SecondRenderWindow);

              this.SecondRenderWindow.Render();

              return this.SecondRenderWindow;
        }
        //private void InitializeVTK()
        //{
        //    Kitware.VTK.RenderWindowControl vtkControl = new Kitware.VTK.RenderWindowControl();
        //    vtkControl.AddTestActors = false;
        //    vtkControl.Location = new System.Drawing.Point(10, 10);
        //    vtkControl.Name = "_renwin";
        //    vtkControl.Size = new System.Drawing.Size(100, 100);
        //    vtkControl.TabIndex = 0;
        //    vtkControl.TestText = null;
        //    vtkControl.Dock = System.Windows.Forms.DockStyle.Fill;
        //    vtkformhost.Child = vtkControl;
        //    vtkformhost.Visibility = System.Windows.Visibility.Visible;

        //    vtkSphereSource sphere = vtkSphereSource.New();
        //    sphere.SetThetaResolution(8);
        //    sphere.SetPhiResolution(16);

        //    vtkShrinkPolyData shrink = vtkShrinkPolyData.New();
        //    shrink.SetInputConnection(sphere.GetOutputPort());
        //    shrink.SetShrinkFactor(0.9);

        //    vtkPolyDataMapper mapper = vtkPolyDataMapper.New();
        //    mapper.SetInputConnection(shrink.GetOutputPort());

        //    // The actor links the data pipeline to the rendering subsystem
        //    vtkActor actor = vtkActor.New();
        //    actor.SetMapper(mapper);
        //    actor.GetProperty().SetColor(1, 0, 0);

        //    // Create components of the rendering subsystem
        //    //
        //    Kitware.VTK.vtkRendererCollection rs = vtkControl.RenderWindow.GetRenderers();
        //    vtkRenderer ren1 = vtkControl.RenderWindow.GetRenderers().GetFirstRenderer();
        //    vtkRenderWindow renWin = vtkControl.RenderWindow;

        //    // Add the actors to the renderer, set the window size
        //    //
        //    ren1.AddViewProp(actor);
        //    renWin.SetSize(500, 500);
        //    renWin.Render();
        //    vtkCamera camera = ren1.GetActiveCamera();
        //    camera.Zoom(1.5);

        //}


        private void InitializeVTK()
        {
            Kitware.VTK.RenderWindowControl rw = new Kitware.VTK.RenderWindowControl();

            rw.AddTestActors       = false;
            rw.Dock                = System.Windows.Forms.DockStyle.Fill;
            vtkformhost.Child      = rw;
            vtkformhost.Visibility = System.Windows.Visibility.Visible;
            Kitware.VTK.vtkRendererCollection rs = rw.RenderWindow.GetRenderers();
            int rsc = rs.GetNumberOfItems();

            Console.WriteLine(rsc + " renderers");
            Kitware.VTK.vtkRenderer r = rs.GetFirstRenderer();
            r.SetBackground(0.1, 0.3, 0.7);
            r.SetBackground2(0.7, 0.8, 1.0);
            r.SetGradientBackground(true);

            int   i, j, k, kOffset, jOffset, offset;
            float s, sp, x, y, z;

            //创建结构化点数据集,(创建点和单元)
            vtkStructuredPoints vol = new vtkStructuredPoints();

            vol.SetDimensions(26, 26, 26);   //x,y,z三个坐标轴方向上各有26个点
            vol.SetOrigin(-0.5, -0.5, -0.5); //设置数据集在坐标空间内的起点
            sp = (float)(1.0 / 25.0);
            vol.SetSpacing(sp, sp, sp);      //设置坐标轴上每个点的间距

            //创建标量数据(作为结构化点数据集的属性数据)
            vtkFloatArray scalars = new vtkFloatArray();

            scalars.SetNumberOfTuples(26 * 26 * 26);//设置标量个数,因为是点属性所以和点的个数相同

            for (k = 0; k < 26; k++)
            {
                z       = (float)(-0.5 + k * sp);
                kOffset = k * 26 * 26;
                for (j = 0; j < 26; j++)
                {
                    y       = (float)(-0.5 + j * sp);
                    jOffset = j * 26;
                    for (i = 0; i < 26; i++)
                    {
                        x = (float)(-0.5 + i * sp);
                        s = (float)(x * x + y * y + z * z - (0.4 * 0.4));
                        //计算标量值,该方程为球体方程,位于球体上的点标量值为0
                        offset = i + jOffset + kOffset;  //计算id
                        scalars.InsertTuple1(offset, s); //插入标量值
                    }
                }
            }

            vol.GetPointData().SetScalars(scalars); //将标量值与点关联


            //抽取标量值为0的点所形成的面
            vtkContourFilter contour = new vtkContourFilter();

            contour.SetInput(vol);
            contour.SetValue(0, 0);

            vtkPolyDataMapper volmapper = new vtkPainterPolyDataMapper();

            volmapper.SetInput(contour.GetOutput());

            vtkActor actor = new vtkActor();

            actor.GetProperty().SetRepresentationToWireframe();
            // actor.GetProperty().SetRepresentationToSurface();
            // actor.GetProperty().SetRepresentationToPoints();
            actor.GetProperty().SetColor(0, 0, 0);
            actor.SetMapper(volmapper);

            vtkRenderWindow _renwin = rw.RenderWindow;
            vtkRenderer     _render = _renwin.GetRenderers().GetFirstRenderer();

            _render.AddActor(actor);

            _renwin.Render();

            _render.ResetCamera();
        }