private void RenderVTU()
        {
            // reader
            vtkXMLUnstructuredGridReader reader = vtkXMLUnstructuredGridReader.New();

            reader.SetFileName(m_FileName);
            reader.Update(); // here we read the file actually

            // mapper
            vtkDataSetMapper gridMapper = vtkDataSetMapper.New();

            gridMapper.SetInputConnection(reader.GetOutputPort());

            // actor
            vtkActor gridActor = vtkActor.New();

            gridActor.SetMapper(gridMapper);

            // add our actor to the renderer
            imgPropList.Add(gridActor);
            m_Renderer.AddActor(gridActor);

            // reposition the camera, so that actor can be fully seen
            m_Renderer.ResetCamera();

            //Rerender the screen
            m_RenderWindow.Render();
            m_Renderer.Render();
        }
        private void renderWindowControl1_Load(object sender, EventArgs e)
        {
            try {
                string filePath = @"C:\VTK\vtkdata-5.8.0\Data\quadraticTetra01.vtu";

                // reader
                vtkXMLUnstructuredGridReader reader = vtkXMLUnstructuredGridReader.New();
                if (reader.CanReadFile(filePath) == 0)
                {
                    MessageBox.Show("Cannot read file \"" + filePath + "\"", "Error", MessageBoxButtons.OK);
                    return;
                }
                reader.SetFileName(filePath);
                reader.Update(); // here we read the file actually

                // mapper
                vtkDataSetMapper gridMapper = vtkDataSetMapper.New();
                gridMapper.SetInputConnection(reader.GetOutputPort());

                // actor
                vtkActor gridActor = vtkActor.New();
                gridActor.SetMapper(gridMapper);

                // 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.2, 0.3, 0.4);

                // add our actor to the renderer
                renderer.AddActor(gridActor);

                // reposition the camera, so that actor can be fully seen
                renderer.ResetCamera();
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK);
            }
        }
예제 #3
0
        private void WriteVTUFile()
        {
            // 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();
            string     filePath = System.IO.Path.Combine(root, @"Data\tetra_test.vtu");

            vtkPoints points = vtkPoints.New();

            points.InsertNextPoint(0, 0, 0);
            points.InsertNextPoint(1, 0, 0);
            points.InsertNextPoint(1, 1, 0);
            points.InsertNextPoint(0, 1, 1);

            vtkTetra tetra = vtkTetra.New();

            tetra.GetPointIds().SetId(0, 0);
            tetra.GetPointIds().SetId(1, 1);
            tetra.GetPointIds().SetId(2, 2);
            tetra.GetPointIds().SetId(3, 3);

            vtkCellArray cellArray = vtkCellArray.New();

            cellArray.InsertNextCell(tetra);

            vtkUnstructuredGrid unstructuredGrid = vtkUnstructuredGrid.New();

            unstructuredGrid.SetPoints(points);
            const int VTK_TETRA = 10;

            unstructuredGrid.SetCells(VTK_TETRA, cellArray);

            // Write file
            vtkXMLUnstructuredGridWriter writer = vtkXMLUnstructuredGridWriter.New();

            writer.SetFileName(filePath);
            writer.SetInput(unstructuredGrid);
            writer.Write();

            // Read and display file for verification that it was written correctly
            vtkXMLUnstructuredGridReader reader = vtkXMLUnstructuredGridReader.New();

            if (reader.CanReadFile(filePath) == 0)
            {
                MessageBox.Show("Cannot read file \"" + filePath + "\"", "Error", MessageBoxButtons.OK);
                return;
            }
            reader.SetFileName(filePath);
            reader.Update();

            vtkDataSetMapper mapper = vtkDataSetMapper.New();

            mapper.SetInputConnection(reader.GetOutputPort());

            // actor
            vtkActor actor = vtkActor.New();

            actor.SetMapper(mapper);

            // 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.2, 0.3, 0.4);
            // add our actor to the renderer
            renderer.AddActor(actor);
        }