Esempio n. 1
0
        private void ReadBMP()
        {
            // 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\masonry.bmp");
            //Read the image
            vtkBMPReader reader = vtkBMPReader.New();

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

            // Visualize
            vtkImageViewer2 imageViewer = vtkImageViewer2.New();

            imageViewer.SetInputConnection(reader.GetOutputPort());
            // 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);
            imageViewer.SetRenderer(renderer);
            renderer.ResetCamera();
        }
Esempio n. 2
0
        private void DrawTexturePlane()
        {
            //load in the texture map
            vtkBMPReader bmpReader = vtkBMPReader.New();

            bmpReader.SetFileName(@"..\..\Data\masonry.bmp");
            vtkTexture atext = vtkTexture.New();

            atext.SetInputConnection(bmpReader.GetOutputPort());
            atext.InterpolateOn();

            //create a plane source and actor
            vtkPlaneSource plane = vtkPlaneSource.New();

            plane.SetPoint1(0, 0, 0);
            vtkPolyDataMapper planeMapper = vtkPolyDataMapper.New();

            planeMapper.SetInputConnection(plane.GetOutputPort());
            vtkActor planeActor = vtkActor.New();

            planeActor.SetMapper(planeMapper);
            planeActor.SetTexture(atext);

            vtkRenderer     renderer = vtkRenderer.New();
            vtkRenderWindow renWin   = myRenderWindowControl.RenderWindow;

            renWin.AddRenderer(renderer);
            renderer.AddActor(planeActor);
        }
Esempio n. 3
0
        private void WriteBMP()
        {
            // 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\test_bmp.bmp");

            int[] extent = new int[] { 1, 10, 1, 10, 1, 10 };
            vtkImageCanvasSource2D imageSource = vtkImageCanvasSource2D.New();

            imageSource.SetScalarTypeToUnsignedChar();
            imageSource.SetExtent(0, 9, 0, 9, 0, 0);
            imageSource.SetNumberOfScalarComponents(3);
            imageSource.SetDrawColor(0, 0, 0, 0);
            imageSource.FillBox(0, 9, 0, 9);
            imageSource.SetDrawColor(255, 0, 0, 0);
            imageSource.FillBox(5, 7, 5, 7);
            imageSource.Update();

            vtkBMPWriter bmpWriter = vtkBMPWriter.New();

            bmpWriter.SetFileName(filePath);
            bmpWriter.SetInputConnection(imageSource.GetOutputPort());
            bmpWriter.Write();

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

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

            // Visualize
            vtkImageViewer2 imageViewer = vtkImageViewer2.New();

            imageViewer.SetInputConnection(reader.GetOutputPort());
            // 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);
            imageViewer.SetRenderer(renderer);
            renderer.ResetCamera();
        }