예제 #1
0
        public void ReadImageIntoObject(RenderWindowControl renderWindowControl, nvmImageModel camera)
        {
            vtkRenderWindow renderWindow = renderWindowControl.RenderWindow;
            vtkRenderer     renderer     = renderWindow.GetRenderers().GetFirstRenderer();

            string        filePath = Path.Combine(tempDirectory, $"{camera.fileName}");
            vtkJPEGReader reader   = vtkJPEGReader.New();

            reader.SetFileName(filePath);
            reader.Update();

            // Treba poriesit ako nasmerovat obrazky bez pokazenia textury
            var vectoris = Vector3.Transform(new Vector3(0, 0, 1), camera.quaternion);

            vtkPlaneSource planeSource = vtkPlaneSource.New();
            vtkTexture     texture     = new vtkTexture();

            texture.SetInputConnection(reader.GetOutputPort());
            vtkTransform transform = new vtkTransform();

            transform.RotateX(180);
            texture.SetTransform(transform);

            vtkTextureMapToPlane plane = new vtkTextureMapToPlane();

            plane.SetInputConnection(planeSource.GetOutputPort());
            planeSource.SetCenter(camera.cameraCenter.X, camera.cameraCenter.Y, camera.cameraCenter.Z);

            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();

            mapper.SetInputConnection(plane.GetOutputPort());
            vtkActor actor = vtkActor.New();

            actor.SetMapper(mapper);
            actor.SetTexture(texture);

            renderer.SetBackground(0.2, 0.3, 0.4);
            renderer.AddActor(actor);
        }
예제 #2
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            vtkPoints points = vtkPoints.New();

            int GridSize = 10;

            for (int x = 0; x < GridSize; x++)
            {
                for (int y = 0; y < GridSize; y++)
                {
                    points.InsertNextPoint(x, y, (x + y) / (y + 1));
                }
            }

            // Add the grid points to a polydata object
            vtkPolyData polydata = vtkPolyData.New();

            polydata.SetPoints(points);

            // Triangulate the grid points
            vtkDelaunay2D delaunay = vtkDelaunay2D.New();

            delaunay.SetInput(polydata);
            delaunay.Update();

            vtkPlaneSource plane = vtkPlaneSource.New();

            //Read the image data from a file
            vtkJPEGReader reader = vtkJPEGReader.New();

            reader.SetFileName("C:\\Users\\georg\\Desktop\\texture.jpg");

            //Create texture object
            vtkTexture texture = vtkTexture.New();

            texture.SetInputConnection(reader.GetOutputPort());

            //Map texture coordinates
            vtkTextureMapToPlane map_to_plane = vtkTextureMapToPlane.New();

            map_to_plane.SetInputConnection(plane.GetOutputPort());
            map_to_plane.SetInputConnection(delaunay.GetOutputPort());

            //Create mapper and set the mapped texture as input
            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();

            mapper.SetInputConnection(map_to_plane.GetOutputPort());

            //Create actor and set the mapper and the texture
            vtkActor actor = vtkActor.New();

            actor.SetMapper(mapper);
            actor.SetTexture(texture);

            vtkRenderer renderer = vtkRenderer.New();

            renderer.AddActor(actor);


            RenderControl1.RenderWindow.AddRenderer(renderer);
        }