Exemple #1
0
        /// <summary>
        /// Détruit proprement les objets
        /// </summary>
        public void destroy()
        {
            _renderer.RemoveActor(_volumeActor);

            if (_stlReader != null)
            {
                _stlReader.Dispose();
            }

            if (_volumeMapper != null)
            {
                _volumeMapper.Dispose();
            }

            if (_volumeActor != null)
            {
                _renderer.RemoveActor(_volumeActor);
                _volumeActor.Dispose();
            }

            if (_edgeMapper != null)
            {
                _edgeMapper.Dispose();
            }

            if (_edgeActor != null)
            {
                _renderer.RemoveActor(_edgeActor);
                _edgeActor.Dispose();
            }

            Render();
        }
Exemple #2
0
        private void RenderImage()
        {
            //Get rid of any props already there
            if (imgProp != null)
            {
                m_Renderer.RemoveActor(imgProp);
                imgProp.Dispose();
                imgProp = null;
            }

            Kitware.VTK.vtkImageReader2 rdr =
                Kitware.VTK.vtkImageReader2Factory.CreateImageReader2(m_FileName);
            rdr.SetFileName(m_FileName);
            rdr.Update();
            imgProp = vtkImageActor.New();
            ((vtkImageActor)imgProp).SetInput(rdr.GetOutput());
            rdr.Dispose();

            m_Renderer.AddActor(imgProp);
            //Reset the camera to show the image
            //Equivilant of pressing 'r'
            m_Renderer.ResetCamera();
            //Rerender the screen
            //NOTE: sometimes you have to drag the mouse
            //a little before the image shows up
            renderWindowControl1.RenderWindow.Render();
            m_Renderer.Render();
        }
        // Remove last actor
        private void removeLastToolStripMenuItem_Click(object sender, EventArgs e)
        {
            vtkProp3D lastVtkProp3D = imgPropList[imgPropList.Count - 1];

            imgPropList.Remove(lastVtkProp3D);

            m_Renderer.RemoveActor(lastVtkProp3D);
            //Rerender the screen
            m_RenderWindow.Render();
            m_Renderer.Render();
        }
Exemple #4
0
 public void RemoveActor(FEMActor actor)
 {
     if (!m_actorDict.ContainsKey(actor))
     {
         return;
     }
     m_actorDict.Remove(actor);
     m_render.RemoveActor(actor);
     SetViewPort(eCameraPos.YTop); //设置视角
     m_renderWinCtrl.Invalidate(); //重绘
 }
Exemple #5
0
        public void RemoveMe()
        {
            if (_rendererPackage != null)
            {
                _rendererPackage.RemoveActor(_lineActor);
            }
            if (_renderer != null)
            {
                _renderer.RemoveActor(_lineActor);
            }

            _lineActor.Dispose();
            line.Dispose();
        }
        public void RemoveMe()
        {
            if (centerLineActor != null)
            {
                renderer.RemoveActor(centerLineActor);
                centerLineActor.Dispose();
                centerLineActor = null;
            }

            _cleanFilter.Dispose();
            _profileTubes.Dispose();
            _profileData.Dispose();
            _lines.Dispose();
            _points.Dispose();
            this._mapper.Dispose();
        }
Exemple #7
0
        public void SetTopMost()
        {
            vtkRenderer _aRender = _rendererPackage.Renderer;

            if (_aRender.GetLayer() > 0)
            {
                return;
            }

            if (_aRender.GetRenderWindow().GetRenderers().GetNumberOfItems() == 1)
            {
                vtkRenderer ren1 = vtkRenderer.New(); // 2d actor
                ren1.SetLayer(1);                     // top layer
                ren1.InteractiveOff();

                _aRender.SetLayer(0);
                _aRender.GetRenderWindow().SetNumberOfLayers(2);
                _aRender.GetRenderWindow().AddRenderer(ren1);

                //ren1.SetActiveCamera(_aRender.GetActiveCamera());

                //new SpherePackage(ren1, new double[] { 0, 0, 0 }, 600).SetOpacity(0.01f);

                _aRender.SetActiveCamera(ren1.GetActiveCamera());

                _aRender.RemoveActor(Actor);
                ren1.AddActor(Actor);

                _aRender.InteractiveOn();
            }
            else
            {
                for (int i = 0; i < _aRender.GetRenderWindow().GetRenderers().GetNumberOfItems(); ++i)
                {
                    int layer = vtkRenderer.SafeDownCast(_aRender.GetRenderWindow().GetRenderers().GetItemAsObject(i)).GetLayer();

                    if (layer == 1)
                    {
                        vtkRenderer.SafeDownCast(_aRender.GetRenderWindow().GetRenderers().GetItemAsObject(i)).AddActor(Actor);
                    }
                    else
                    {
                        vtkRenderer.SafeDownCast(_aRender.GetRenderWindow().GetRenderers().GetItemAsObject(i)).RemoveActor(Actor);
                    }
                }
            }
        }
Exemple #8
0
        /* if we know which renderable to enable or disable, then only change the associated actors */
        private void UpdateRenderPipeLine(ARenderable aRenderable, bool p)
        {
            vtkRenderer renderer = _renderControl.RenderWindow.GetRenderers().GetFirstRenderer();

            if (p == false) // remove all actors of renderable
            {
                foreach (vtkActor a in aRenderable.Actors)
                {
                    renderer.RemoveActor(a);
                }
            }
            else //add new actors
            {
                foreach (vtkActor a in aRenderable.Actors)
                {
                    renderer.AddActor(a);
                }
            }
            // render the new scene. Note that renderer.Render() does _NOT_ update the scene, you need to render the interactor.
            _renderControl.RenderWindow.GetInteractor().Render();
        }
Exemple #9
0
        public void ImportVTK()
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                // Get the name of the file you want to open from the dialog
                string      fileName = openFileDialog1.FileName;
                vtkRenderer ren      = (vtkRenderer)this.myRenderWindowControl.RenderWindow.GetRenderers().GetItemAsObject(0);

                //Get rid of any props already there
                if (imgProp != null)
                {
                    ren.RemoveActor(imgProp);
                    imgProp.Dispose();
                    imgProp = null;
                }

                //Look at known file types to see if they are readable
                if (fileName.Contains(".png") ||
                    fileName.Contains(".jpg") ||
                    fileName.Contains(".jpeg") ||
                    fileName.Contains(".tif") ||
                    fileName.Contains(".slc") ||
                    fileName.Contains(".dicom") ||
                    fileName.Contains(".minc") ||
                    fileName.Contains(".bmp") ||
                    fileName.Contains(".pmn"))
                {
                    vtkImageReader2 rdr = vtkImageReader2Factory.CreateImageReader2(fileName);
                    rdr.SetFileName(fileName);
                    rdr.Update();
                    imgProp = vtkImageActor.New();

                    ((vtkImageActor)imgProp).SetInput(rdr.GetOutput());
                    rdr.Dispose();
                }

                //.vtk files need a DataSetReader instead of a ImageReader2
                //some .vtk files need a different kind of reader, but this
                //will read most and serve our purposes
                else if (fileName.Contains(".vtk") || fileName.Contains(".VTK"))
                {
                    vtkDataSetReader dataReader = vtkDataSetReader.New();
                    dataReader.SetFileName(fileName);
                    dataReader.Update();

                    vtkDataSetMapper dataMapper = vtkDataSetMapper.New();
                    dataMapper.SetInput(dataReader.GetOutput());

                    imgProp = vtkActor.New();
                    ((vtkActor)imgProp).SetMapper(dataMapper);

                    dataMapper.Dispose();
                    dataMapper = null;

                    dataReader.Dispose();
                    dataReader = null;
                }
                else
                {
                    return;
                }

                ren.RemoveAllViewProps();
                ren.AddActor(imgProp);
                ren.ResetCamera();
                ren.SetBackground(0.0, 0.46, 0.5);

                //Rerender the screen
                //NOTE: sometimes you have to drag the mouse
                //a little before the image shows up
                ren.Render();
                myRenderWindowControl.RenderWindow.Render();
                myRenderWindowControl.Refresh();
            }
        }
Exemple #10
0
        protected override void OnMouseDoubleClick(MouseEventArgs e)
        {
            if (pick_trigger == false)
            {
                MessageBox.Show("请先选择靶点或穿刺点!");
                return;
            }
            if (pick_tag == true)
            {
                control_renderer.RemoveActor(this.spheres[this.sphere_num - 1]);
                this.point_num  -= 1;
                this.sphere_num -= 1;
            }
            if (this.sphere_num >= 6)
            {
                MessageBoxButtons messButton = MessageBoxButtons.OKCancel;
                DialogResult      dr         = MessageBox.Show("点数已满,是否清空?", "系统提示", messButton);
                if (dr == DialogResult.OK)
                {
                    for (int i = 0; i < this.sphere_num; i++)
                    {
                        control_renderer.RemoveActor(this.spheres[i]);
                        this.points = new double[20, 3];
                    }
                    this.point_num  = 0;
                    this.sphere_num = 0;
                }
                return;
            }
            //vtkRenderWindowInteractor inter_ren = this.GetInteractor();
            Console.WriteLine(this.point_num.ToString());
            double[] temp   = new double[2];
            double[] picked = new double[3];
            temp[0] = this.GetInteractor().GetEventPosition()[0];
            temp[1] = this.GetInteractor().GetEventPosition()[1];
            Console.WriteLine("picked position" + temp[0].ToString() + " , " + temp[1].ToString());
            this.GetInteractor().GetPicker().Pick(temp[0], temp[1], 0, this.GetInteractor().GetRenderWindow().GetRenderers().GetFirstRenderer());
            picked = this.GetInteractor().GetPicker().GetPickPosition();
            Console.WriteLine("picked point:" + picked[0].ToString() + " , " + picked[1].ToString() + " , " + picked[2].ToString());
            for (int i = 0; i < 3; i++)
            {
                this.points[point_num, i] = picked[i];
            }
            this.point_num++;
            base.OnMouseDoubleClick(e);

            //import a sphere object into scence
            vtkSphereSource sphere = new vtkSphereSource();

            sphere.SetCenter(picked[0], picked[1], picked[2]);
            sphere.SetRadius(3.0);

            vtkPolyDataMapper mapper = new vtkPolyDataMapper();

            mapper.SetInputConnection(sphere.GetOutputPort());

            vtkProperty property = new vtkProperty();

            property.SetColor(color[0], color[1], color[2]);
            property.SetOpacity(1);

            this.spheres[this.sphere_num] = new vtkActor();
            this.spheres[this.sphere_num].SetMapper(mapper);
            this.spheres[this.sphere_num].SetProperty(property);

            this.control_renderer.AddActor(this.spheres[this.sphere_num]);

            this.sphere_num++;
            this.pick_tag = true;
            //点数越界后弹窗确定是否清空
        }
Exemple #11
0
        /// <summary>
        /// Load an image with an open dialog
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                // Get the name of the file you want to open from the dialog
                string fileName = openFileDialog1.FileName;

                vtkRenderer ren = (vtkRenderer)this.renderWindowControl1.RenderWindow.GetRenderers().GetItemAsObject(0);

                //Get rid of any props already there
                if (imgProp != null)
                {
                    ren.RemoveActor(imgProp);
                    imgProp.Dispose();
                    imgProp = null;
                }

                //Look at known file types to see if they are readable
                if (fileName.Contains(".png") ||
                    fileName.Contains(".jpg") ||
                    fileName.Contains(".jpeg") ||
                    fileName.Contains(".tif") ||
                    fileName.Contains(".slc") ||
                    fileName.Contains(".dicom") ||
                    fileName.Contains(".minc") ||
                    fileName.Contains(".bmp") ||
                    fileName.Contains(".pmn"))
                {
                    Kitware.VTK.vtkImageReader2 rdr =
                        Kitware.VTK.vtkImageReader2Factory.CreateImageReader2(fileName);
                    rdr.SetFileName(fileName);
                    rdr.Update();
                    imgProp = vtkImageActor.New();
                    ((vtkImageActor)imgProp).SetInputConnection(rdr.GetOutputPort());
                    rdr.Dispose();
                }

                //.vtk files need a DataSetReader instead of a ImageReader2
                //some .vtk files need a different kind of reader, but this
                //will read most and serve our purposes
                else if (fileName.Contains(".vtk"))
                {
                    vtkDataSetReader dataReader = vtkDataSetReader.New();
                    vtkDataSetMapper dataMapper = vtkDataSetMapper.New();
                    imgProp = vtkActor.New();
                    dataReader.SetFileName(fileName);
                    dataReader.Update();
                    dataMapper.SetInputConnection(dataReader.GetOutputPort());
                    ((vtkActor)imgProp).SetMapper(dataMapper);
                    dataMapper.Dispose();
                    dataMapper = null;
                    dataReader.Dispose();
                    dataReader = null;
                }
                else
                {
                    return;
                }
                ren.AddActor(imgProp);
                //Reset the camera to show the image
                //Equivilant of pressing 'r'
                ren.ResetCamera();
                //Rerender the screen
                //NOTE: sometimes you have to drag the mouse
                //a little before the image shows up
                renderWindowControl1.RenderWindow.Render();
                ren.Render();
            }
        }