Ejemplo n.º 1
0
        /// <summary>
        /// Set up the dialog
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void renderWindowControl1_Load(object sender, EventArgs e)
        {
            //Setup the variables and the background
            vtkRenderer ren1 = renderWindowControl1.RenderWindow.GetRenderers().GetFirstRenderer();

            mapper.SetInputConnection(puzzle.GetOutputPort());
            mapper2.SetInputConnection(arrows.GetOutputPort());
            actor.SetMapper(mapper);
            actor2.SetMapper(mapper2);
            ren1.AddActor(actor);
            ren1.AddActor(actor2);
            ren1.SetBackground(0.1, 0.2, 0.4);

            //Set up the camera
            ren1.ResetCamera();
            vtkCamera cam = ren1.GetActiveCamera();

            cam.Elevation(-40);
            renderWindowControl1.RenderWindow.Render();

            //Change the style to a trackball style
            //Equivalent of pressing 't'
            vtkRenderWindowInteractor iren   = renderWindowControl1.RenderWindow.GetInteractor();
            vtkInteractorStyleSwitch  istyle = vtkInteractorStyleSwitch.New();

            iren.SetInteractorStyle(istyle);
            (istyle).SetCurrentStyleToTrackballCamera();

            //Add events to the iren instead of Observers
            iren.MouseMoveEvt += new vtkObject.vtkObjectEventHandler(MotionCallback);
            iren.CharEvt      += new vtkObject.vtkObjectEventHandler(CharCallback);
        }
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVTestExtrudePiece(String [] argv)
    {
        //Prefix Content is: ""

          disk = new vtkDiskSource();
          disk.SetRadialResolution((int)2);
          disk.SetCircumferentialResolution((int)9);
          clean = new vtkCleanPolyData();
          clean.SetInputConnection((vtkAlgorithmOutput)disk.GetOutputPort());
          clean.SetTolerance((double)0.01);
          piece = new vtkExtractPolyDataPiece();
          piece.SetInputConnection((vtkAlgorithmOutput)clean.GetOutputPort());
          extrude = new vtkPLinearExtrusionFilter();
          extrude.SetInputConnection((vtkAlgorithmOutput)piece.GetOutputPort());
          extrude.PieceInvariantOn();
          // Create the RenderWindow, Renderer and both Actors[]
          //[]
          ren1 = vtkRenderer.New();
          renWin = vtkRenderWindow.New();
          renWin.AddRenderer((vtkRenderer)ren1);
          iren = new vtkRenderWindowInteractor();
          iren.SetRenderWindow((vtkRenderWindow)renWin);
          mapper = vtkPolyDataMapper.New();
          mapper.SetInputConnection((vtkAlgorithmOutput)extrude.GetOutputPort());
          mapper.SetNumberOfPieces((int)2);
          mapper.SetPiece((int)1);
          bf = new vtkProperty();
          bf.SetColor((double)1,(double)0,(double)0);
          actor = new vtkActor();
          actor.SetMapper((vtkMapper)mapper);
          actor.GetProperty().SetColor((double)1,(double)1,(double)0.8);
          actor.SetBackfaceProperty((vtkProperty)bf);
          // Add the actors to the renderer, set the background and size[]
          //[]
          ren1.AddActor((vtkProp)actor);
          ren1.SetBackground((double)0.1,(double)0.2,(double)0.4);
          renWin.SetSize((int)300,(int)300);
          // render the image[]
          //[]
          cam1 = ren1.GetActiveCamera();
          cam1.Azimuth((double)20);
          cam1.Elevation((double)40);
          ren1.ResetCamera();
          cam1.Zoom((double)1.2);
          iren.Initialize();
          // prevent the tk window from showing up then start the event loop[]

        //deleteAllVTKObjects();
    }
Ejemplo n.º 3
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVTestSpherePuzzle(String [] argv)
    {
        //Prefix Content is: ""

          // prevent the tk window from showing up then start the event loop[]
          renWin = vtkRenderWindow.New();
          // create a rendering window and renderer[]
          ren1 = vtkRenderer.New();
          renWin.AddRenderer((vtkRenderer)ren1);
          renWin.SetSize((int)400,(int)400);
          puzzle = new vtkSpherePuzzle();
          mapper = vtkPolyDataMapper.New();
          mapper.SetInputConnection((vtkAlgorithmOutput)puzzle.GetOutputPort());
          actor = new vtkActor();
          actor.SetMapper((vtkMapper)mapper);
          arrows = new vtkSpherePuzzleArrows();
          mapper2 = vtkPolyDataMapper.New();
          mapper2.SetInputConnection((vtkAlgorithmOutput)arrows.GetOutputPort());
          actor2 = new vtkActor();
          actor2.SetMapper((vtkMapper)mapper2);
          // Add the actors to the renderer, set the background and size[]
          //[]
          ren1.AddActor((vtkProp)actor);
          ren1.AddActor((vtkProp)actor2);
          ren1.SetBackground((double)0.1,(double)0.2,(double)0.4);
          LastVal = -1;
          //method moved
          //method moved
          renWin.Render();
          cam = ren1.GetActiveCamera();
          cam.Elevation((double)-40);
          puzzle.MoveHorizontal((int)0,(int)100,(int)0);
          puzzle.MoveHorizontal((int)1,(int)100,(int)1);
          puzzle.MoveHorizontal((int)2,(int)100,(int)0);
          puzzle.MoveVertical((int)2,(int)100,(int)0);
          puzzle.MoveVertical((int)1,(int)100,(int)0);
          renWin.Render();

        //deleteAllVTKObjects();
    }
Ejemplo n.º 4
0
        int build3DViewFull()
        {
            Kitware.VTK.RenderWindowControl rw = new Kitware.VTK.RenderWindowControl();

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

            _renwin.AddRenderer(_render);

            vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor();

            iren.SetRenderWindow(_renwin);

            // 新建文件读取对象,常见的有vtkBMPReader、vtkDICOMImageReader、vtkJPEGReader等
            vtkJPEGReader jpegReader = new vtkJPEGReader();

            // 不同的reader需要设置的参数是不同的 因此本例仅适合jpegreader
            jpegReader.SetFilePrefix("C:/Users/DawnWind/Desktop/000/"); // 要打开的路径
            jpegReader.SetFilePattern("%s%d.jpg");                      // 图片文件名格式,此处为 0.jpg 1.jpg ...
            jpegReader.SetDataByteOrderToLittleEndian();
            jpegReader.SetDataSpacing(1, 1, 1.4);                       // 设置图片中像素比,我理解得不清楚,具体请百度之
            jpegReader.SetFileNameSliceSpacing(1);

            jpegReader.SetDataExtent(0, 209, 0, 209, 0, 29);
            // 这里因为在000文件夹里面有0.jpg ~ 29.jpg,所以设置为 0,29
            // 每张图片的长宽为210 * 210 因此设置为0,209

            jpegReader.Update();
            // update这里要注意一下,对于VTK在默认情况下是在最后操作时候才一次性刷新
            // 也就是说如果没有自动刷新的话,在一些中间过程中是无法获得到数据的,因为没update进去

            vtkContourFilter skinExtractor = new vtkContourFilter();

            skinExtractor.SetInputConnection(jpegReader.GetOutputPort());
            skinExtractor.SetValue(200, 100);    //值越大,保留的部分越少。

            //重新计算法向量
            vtkPolyDataNormals skinNormals = new vtkPolyDataNormals();

            skinNormals.SetInputConnection(skinExtractor.GetOutputPort());
            skinNormals.SetFeatureAngle(60.0);
            //Specify the angle that defines a sharp edge.
            //If the difference in angle across neighboring polygons is greater than this value,
            //the shared edge is considered "sharp".


            //create triangle strips and/or poly-lines 为了更快的显示速度
            vtkStripper skinStripper = new vtkStripper();

            skinStripper.SetInputConnection(skinNormals.GetOutputPort());

            vtkPolyDataMapper skinMapper = new vtkPainterPolyDataMapper();

            skinMapper.SetInputConnection(skinStripper.GetOutputPort());
            skinMapper.ScalarVisibilityOff();    //这样不会带颜色



            vtkActor skin = new vtkActor();

            skin.SetMapper(skinMapper);

            // An outline provides context around the data.
            // 一个围绕在物体的立体框,可以先忽略

            /*
             * vtkOutlineFilter> outlineData =
             *  vtkOutlineFilter>::New();
             * outlineData.SetInputConnection(dicomReader.GetOutputPort());
             *
             * vtkPolyDataMapper> mapOutline =
             *  vtkPolyDataMapper>::New();
             * mapOutline.SetInputConnection(outlineData.GetOutputPort());
             *
             * vtkActor> outline =
             *  vtkActor>::New();
             * outline.SetMapper(mapOutline);
             * outline.GetProperty().SetColor(0,0,0);
             *
             * aRenderer.AddActor(outline);
             */
            // It is convenient to create an initial view of the data. The FocalPoint
            // and Position form a vector direction. Later on (ResetCamera() method)
            // this vector is used to position the camera to look at the data in
            // this direction.
            vtkCamera aCamera = new vtkCamera();

            aCamera.SetViewUp(0, 0, -1);
            aCamera.SetPosition(0, 1, 0);
            aCamera.SetFocalPoint(0, 0, 0);
            aCamera.ComputeViewPlaneNormal();
            aCamera.Azimuth(30.0);
            aCamera.Elevation(30.0);

            // Actors are added to the renderer. An initial camera view is created.
            // The Dolly() method moves the camera towards the FocalPoint,
            // thereby enlarging the image.
            _render.AddActor(skin);
            _render.SetActiveCamera(aCamera);
            _render.ResetCamera();
            aCamera.Dolly(1.5);

            // Set a background color for the renderer and set the size of the
            // render window (expressed in pixels).
            _render.SetBackground(.2, .3, .4);
            _renwin.SetSize(640, 480);

            // Note that when camera movement occurs (as it does in the Dolly()
            // method), the clipping planes often need adjusting. Clipping planes
            // consist of two planes: near and far along the view direction. The
            // near plane clips out objects in front of the plane; the far plane
            // clips out objects behind the plane. This way only what is drawn
            // between the planes is actually rendered.
            _render.ResetCameraClippingRange();

            // Initialize the event loop and then start it.
            iren.Initialize();
            iren.Start();
            return(0);
        }
Ejemplo n.º 5
0
        private void renderWindowControl1_Load(object sender, EventArgs e)
        {
            // Create components of the rendering subsystem
            //
            vtkRenderer     ren1   = renderWindowControl1.RenderWindow.GetRenderers().GetFirstRenderer();
            vtkRenderWindow renWin = renderWindowControl1.RenderWindow;

            renWin.SetSize((int)paras.Height, (int)paras.Width);

            // Add the actors to the renderer, set the window size
            //
            vtkPoints      points  = vtkPoints.New();
            vtkCellArray   polys   = vtkCellArray.New();
            vtkFloatArray  scalars = vtkFloatArray.New();
            vtkLookupTable Luk     = vtkLookupTable.New();

            if (paras.Using3DTower == 1)
            {
                vtkActor   actor1  = new vtkActor();
                vtkActor2D actor2D = new vtkActor2D();
                if (paras.StageID != -1)
                {
                    if (paras.UsingEdges == 1)
                    {
                        MessageBox.Show("单元显示无法使用");
                    }
                    else
                    {
                        BasicVTKBuilder(ref actor1, ref points, ref polys, ref scalars, ref Luk, ref actor2D);
                        ren1.AddActor(actor1);
                        ren1.AddActor2D(actor2D);

                        vtkActor2D textActor = new vtkActor2D();
                        VTKInfoBuilder(ref textActor);
                        ren1.AddActor2D(textActor);
                    }
                }
                else
                {
                    if (paras.UsingEdges == 1)
                    {
                        ExtractEdgesVTKBuilderWithoutRunning(ref actor1, ref points, ref polys, ref scalars, ref Luk);
                    }
                    else
                    {
                        BasicVTKBuilderWithoutRunning(ref actor1, ref points, ref polys, ref scalars, ref Luk);
                    }
                    ren1.AddActor(actor1);
                }
            }

            if (paras.UsingVirtualHeater == 1)
            {
                //MessageBox.Show("!");
                vtkActor2D actor2 = VirtualHeaterVTKBuilder();
                ren1.AddActor(actor2);
            }


            renWin.Render();
            vtkCamera camera = ren1.GetActiveCamera();

            //camera.ParallelProjectionOn();
            //camera.Elevation(20);
            int[] camera_pos = new int[3];

            if (paras.globalEnv == 1)
            {
                camera_pos[1] = -70;
            }
            else
            {
                camera_pos[1] = -80;
            }

            if (paras.RotateAngle == 0)
            {
                camera_pos[1] = -camera_pos[1];
                camera_pos[0] = camera_pos[2] = 0;
                camera.SetRoll(-2);
            }
            else if (paras.RotateAngle == 180)
            {
                camera_pos[0] = camera_pos[2] = 0;
                camera.SetRoll(180);
            }
            else if (paras.RotateAngle == 90)
            {
                double r = (double)Math.Abs(camera_pos[1]);
                camera_pos[0] = (int)(-r * 0.707);
                camera_pos[1] = (int)(-r * 0.707);
                camera_pos[2] = 0;
                camera.SetRoll(225);
            }
            else if (paras.RotateAngle == 270)
            {
                double r = (double)Math.Abs(camera_pos[1]);
                camera_pos[0] = (int)(r * 0.707);
                camera_pos[1] = (int)(-r * 0.707);
                camera_pos[2] = 0;
                camera.SetRoll(135);
            }

            camera.SetPosition((double)camera_pos[0], (double)camera_pos[1], (double)camera_pos[2]);
            //camera.Yaw(10);
            camera.Elevation(1);
            camera.ParallelProjectionOn();
            camera.Zoom(0.9);
            StoredViewCamera = new List <vtkCamera>();
            for (int i = 0; i < 3; i++)
            {
                vtkCamera ViewCamera = new vtkCamera();


                if (i == 0)
                {
                    ViewCamera.SetPosition(camera.GetPosition()[0],
                                           camera.GetPosition()[1],
                                           camera.GetPosition()[2]);
                    ViewCamera.SetRoll(camera.GetRoll());
                }
                else if (i == 1)
                {
                    ViewCamera.SetPosition(80, 0, 0);
                    ViewCamera.SetRoll(180);
                }
                else if (i == 2)
                {
                    ViewCamera.SetPosition(0, 0, -80);
                    ViewCamera.SetRoll(camera.GetRoll());
                }
                ViewCamera.SetFocalPoint(camera.GetFocalPoint()[0],
                                         camera.GetFocalPoint()[1],
                                         camera.GetFocalPoint()[2]);
                ViewCamera.SetViewUp(camera.GetViewUp()[0],
                                     camera.GetViewUp()[1],
                                     camera.GetViewUp()[2]);
                StoredViewCamera.Add(ViewCamera);
            }

            //camera.Zoom(1.5);
        }
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVTestPDataSetReaderGrid(String [] argv)
    {
        //Prefix Content is: ""

        // Create the RenderWindow, Renderer and both Actors[]
        //[]
        ren1 = vtkRenderer.New();
        renWin = vtkRenderWindow.New();
        renWin.AddRenderer((vtkRenderer)ren1);
        iren = new vtkRenderWindowInteractor();
        iren.SetRenderWindow((vtkRenderWindow)renWin);
        //[]
        // If the current directory is writable, then test the witers[]
        //[]
        try
          {
          channel = new StreamWriter("test.tmp");
          tryCatchError = "NOERROR";
          }
        catch(Exception)
          {
          tryCatchError = "ERROR";
          }
        if(tryCatchError.Equals("NOERROR"))
          {
          channel.Close();
          File.Delete("test.tmp");
          // ====== Structured Grid ======[]
          // First save out a grid in parallel form.[]
          reader = new vtkMultiBlockPLOT3DReader();
          reader.SetXYZFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/combxyz.bin");
          reader.SetQFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/combq.bin");
          writer = new vtkPDataSetWriter();
          writer.SetFileName((string)"comb.pvtk");
          writer.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort());
          writer.SetNumberOfPieces((int)4);
          writer.Write();
          pReader = new vtkPDataSetReader();
          pReader.SetFileName((string)"comb.pvtk");
          surface = new vtkDataSetSurfaceFilter();
          surface.SetInputConnection((vtkAlgorithmOutput)pReader.GetOutputPort());
          mapper = vtkPolyDataMapper.New();
          mapper.SetInputConnection((vtkAlgorithmOutput)surface.GetOutputPort());
          mapper.SetNumberOfPieces((int)2);
          mapper.SetPiece((int)0);
          mapper.SetGhostLevel((int)1);
          mapper.Update();
          File.Delete("comb.pvtk");
          File.Delete("comb.0.vtk");
          File.Delete("comb.1.vtk");
          File.Delete("comb.2.vtk");
          File.Delete("comb.3.vtk");
          actor = new vtkActor();
          actor.SetMapper((vtkMapper)mapper);
          actor.SetPosition((double)-5,(double)0,(double)-29);
          // Add the actors to the renderer, set the background and size[]
          //[]
          ren1.AddActor((vtkProp)actor);
          // ====== ImageData ======[]
          // First save out a grid in parallel form.[]
          fractal = new vtkImageMandelbrotSource();
          fractal.SetWholeExtent((int)0,(int)9,(int)0,(int)9,(int)0,(int)9);
          fractal.SetSampleCX((double)0.1,(double)0.1,(double)0.1,(double)0.1);
          fractal.SetMaximumNumberOfIterations((ushort)10);
          writer2 = new vtkPDataSetWriter();
          writer.SetFileName((string)"fractal.pvtk");
          writer.SetInputConnection((vtkAlgorithmOutput)fractal.GetOutputPort());
          writer.SetNumberOfPieces((int)4);
          writer.Write();
          pReader2 = new vtkPDataSetReader();
          pReader2.SetFileName((string)"fractal.pvtk");
          iso = new vtkContourFilter();
          iso.SetInputConnection((vtkAlgorithmOutput)pReader2.GetOutputPort());
          iso.SetValue((int)0,(double)4);
          mapper2 = vtkPolyDataMapper.New();
          mapper2.SetInputConnection((vtkAlgorithmOutput)iso.GetOutputPort());
          mapper2.SetNumberOfPieces((int)3);
          mapper2.SetPiece((int)0);
          mapper2.SetGhostLevel((int)0);
          mapper2.Update();
          File.Delete("fractal.pvtk");
          File.Delete("fractal.0.vtk");
          File.Delete("fractal.1.vtk");
          File.Delete("fractal.2.vtk");
          File.Delete("fractal.3.vtk");
          actor2 = new vtkActor();
          actor2.SetMapper((vtkMapper)mapper2);
          actor2.SetScale((double)5,(double)5,(double)5);
          actor2.SetPosition((double)6,(double)6,(double)6);
          // Add the actors to the renderer, set the background and size[]
          //[]
          ren1.AddActor((vtkProp)actor2);
          // ====== PolyData ======[]
          // First save out a grid in parallel form.[]
          sphere = new vtkSphereSource();
          sphere.SetRadius((double)2);
          writer3 = new vtkPDataSetWriter();
          writer3.SetFileName((string)"sphere.pvtk");
          writer3.SetInputConnection((vtkAlgorithmOutput)sphere.GetOutputPort());
          writer3.SetNumberOfPieces((int)4);
          writer3.Write();
          pReader3 = new vtkPDataSetReader();
          pReader3.SetFileName((string)"sphere.pvtk");
          mapper3 = vtkPolyDataMapper.New();
          mapper3.SetInputConnection((vtkAlgorithmOutput)pReader3.GetOutputPort());
          mapper3.SetNumberOfPieces((int)2);
          mapper3.SetPiece((int)0);
          mapper3.SetGhostLevel((int)1);
          mapper3.Update();
          File.Delete("sphere.pvtk");
          File.Delete("sphere.0.vtk");
          File.Delete("sphere.1.vtk");
          File.Delete("sphere.2.vtk");
          File.Delete("sphere.3.vtk");
          actor3 = new vtkActor();
          actor3.SetMapper((vtkMapper)mapper3);
          actor3.SetPosition((double)6,(double)6,(double)6);
          // Add the actors to the renderer, set the background and size[]
          //[]
          ren1.AddActor((vtkProp)actor3);
          }

        ren1.SetBackground((double)0.1,(double)0.2,(double)0.4);
        renWin.SetSize((int)300,(int)300);
        // render the image[]
        //[]
        cam1 = ren1.GetActiveCamera();
        cam1.Azimuth((double)20);
        cam1.Elevation((double)40);
        ren1.ResetCamera();
        cam1.Zoom((double)1.2);
        iren.Initialize();
        // prevent the tk window from showing up then start the event loop[]

        //deleteAllVTKObjects();
    }