예제 #1
0
        private void Frustum()
        {
            // Create a frustum.
            // in this example we need the renderer first to retrieve the active camera
            // in order to get camera's frustum planes
            vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;
            vtkRenderer     renderer     = renderWindow.GetRenderers().GetFirstRenderer();
            vtkCamera       camera       = renderer.GetActiveCamera();

            double[] aspect      = renderer.GetAspect();
            double   aspectRatio = aspect[0] / aspect[1];

            // allocate memory for 24 unmanaged doubles
            int    size = Marshal.SizeOf(typeof(double)) * 24;
            IntPtr ptr  = Marshal.AllocHGlobal(size);

            camera.GetFrustumPlanes(aspectRatio, ptr);
            // in case we would need this values directly we could copy
            // the unmanaged double array to a managed array like so:

            // double[] planesArray = new double[24];
            // Marshal.Copy(ptr, planesArray, 0, 24);

            // but fortunately we can forward the IntPtr directly to the function
            // SetFrustumPlanes()
            vtkPlanes planes = vtkPlanes.New();

            planes.SetFrustumPlanes(ptr);
            // free unmanaged memory
            Marshal.FreeHGlobal(ptr);

            vtkFrustumSource frustumSource = vtkFrustumSource.New();

            frustumSource.SetPlanes(planes);
            frustumSource.Update();

            vtkPolyData frustum = frustumSource.GetOutput();
            // Visualize
            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();

            mapper.SetInput(frustum);
            vtkActor actor = vtkActor.New();

            actor.SetMapper(mapper);

            renderer.SetBackground(.2, .1, .3); // Background color dark purple
            renderer.AddActor(actor);
            renderer.ResetCamera();
        }
예제 #2
0
        private void Planes()
        {
            // in this example we need the renderer first to retrieve the active camera
            // in order to get camera's frustum planes and renderer's aspectratio
            vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;
            vtkRenderer     renderer     = vtkRenderer.New();

            renderer = renderWindow.GetRenderers().GetFirstRenderer();
            vtkCamera camera = renderer.GetActiveCamera();

            double[] aspect      = renderer.GetAspect();
            double   aspectRatio = aspect[0] / aspect[1];

            vtkPlanes planes = vtkPlanes.New();
            // one way
            {
                // allocate memory for 24 unmanaged doubles
                int    size = Marshal.SizeOf(typeof(double)) * 24;
                IntPtr ptr  = Marshal.AllocHGlobal(size);
                camera.GetFrustumPlanes(aspectRatio, ptr);
                // in case we would need this values diectly we could copy
                // the unmanaged double array to a managed array like so:

                // double[] planesArray = new double[24];
                // Marshal.Copy(ptr, planesArray, 0, 24);

                // but fortunately we can forward the IntPtr directly to the function
                // SetFrustumPlanes()
                planes.SetFrustumPlanes(ptr);
                // free unmanaged memory
                Marshal.FreeHGlobal(ptr);
            }
            // another way
            {
                vtkSphereSource sphereSource = vtkSphereSource.New();
                sphereSource.Update();
                double[] bounds = new double[6];
                bounds = sphereSource.GetOutput().GetBounds();
                planes.SetBounds(bounds[0], bounds[1], bounds[2], bounds[3], bounds[4], bounds[5]);
            }
            // nothing to visualize
        }