Esempio n. 1
2
        static void Main(string[] args)
        {
            // This example demonstrates the use of vtk3DSImporter.
            // vtk3DSImporter is used to load 3D Studio files.  Unlike writers,
            // importers can load scenes (data as well as lights, cameras, actors
            // etc.). Importers will either generate an instance of vtkRenderWindow
            // and/or vtkRenderer or will use the ones you specify.
            string VTK_DATA_ROOT = vtk.vtkDotNetUtil.vtkGetDataRoot();

            // Create the importer and read a file
            vtk.vtk3DSImporter importer = new vtk.vtk3DSImporter();
            importer.ComputeNormalsOn();
            importer.SetFileName(VTK_DATA_ROOT + "/Data/iflamigm.3ds");
            importer.Read();

            // Here we let the importer create a renderer and a render window for
            // us. We could have also create and assigned those ourselves like so:
            // renWin = vtk.vtkRenderWindow();
            // importer.SetRenderWindow(renWin);

            // Assign an interactor.
            // We have to ask the importer for it's render window.
            vtk.vtkRenderWindow renWin = importer.GetRenderWindow();
            vtk.vtkRenderWindowInteractor iren = new vtk.vtkRenderWindowInteractor();
            iren.SetRenderWindow(renWin);

            // Set the render window's size
            renWin.SetSize(300, 300);

            // Set some properties on the renderer.
            // We have to ask the importer for it's renderer.
            vtk.vtkRenderer ren = importer.GetRenderer();
            ren.SetBackground(0.1, 0.2, 0.4);

            // Position the camera:
            // change view up to +z
            vtk.vtkCamera camera = ren.GetActiveCamera();
            camera.SetPosition(0, 1, 0);
            camera.SetFocalPoint(0, 0, 0);
            camera.SetViewUp(0, 0, 1);
            // let the renderer compute good position and focal point
            ren.ResetCamera();
            camera.Dolly(1.4);
            ren.ResetCameraClippingRange();

            iren.Initialize();
            renWin.Render();
            iren.Start();

            vtk.vtkWin32OpenGLRenderWindow win32win =
                vtk.vtkWin32OpenGLRenderWindow.SafeDownCast(renWin);
            if (null != win32win) win32win.Clean();
        }
Esempio n. 2
0
        public void VolumeRender(vtk.vtkImageData VoxelDatat)
        {
            VoxelData = VoxelDatat;
            renWin.AddRenderer(ren1);
            iren.SetRenderWindow(renWin);

            double[] inputRange = VoxelData.GetScalarRange();

            vtk.vtkPiecewiseFunction opacityTransferFunction = new vtk.vtkPiecewiseFunction();
            opacityTransferFunction.AddPoint(inputRange[0], 0);
            opacityTransferFunction.AddPoint(inputRange[1], 1);

            vtk.vtkColorTransferFunction colorTransferFunction = new vtk.vtkColorTransferFunction();
            colorTransferFunction.AddRGBPoint(inputRange[0], 1.0, 1.0, 1.0);
            colorTransferFunction.AddRGBPoint(inputRange[1], 1.0, 1.0, 1.0);

            volumeProperty.SetColor(colorTransferFunction);
            volumeProperty.SetScalarOpacity(opacityTransferFunction);
            volumeProperty.ShadeOff();
            volumeProperty.SetInterpolationTypeToLinear();

            volume.SetProperty(volumeProperty);

            setRAY();
            ren1.AddVolume(volume);
            ren1.ResetCamera();
            renWin.Render();
            addBusyObservers();
            iren.Initialize(); iren.Enable();
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            string VTK_DATA_ROOT = vtk.vtkDotNetUtil.vtkGetDataRoot();

            // Create the reader and read a data file.  Connect the mapper and
            // actor.
            vtk.vtkSTLReader sr = new vtk.vtkSTLReader();
            sr.SetFileName(VTK_DATA_ROOT + "/Data/42400-IDGH.stl");

            vtk.vtkPolyDataMapper stlMapper = new vtk.vtkPolyDataMapper();
            stlMapper.SetInputConnection(sr.GetOutputPort());

            vtk.vtkLODActor stlActor = new vtk.vtkLODActor();
            stlActor.SetMapper(stlMapper);

            // Create the Renderer, RenderWindow, and RenderWindowInteractor
            vtk.vtkRenderer ren = new vtk.vtkRenderer();
            vtk.vtkRenderWindow renWin = new vtk.vtkRenderWindow();
            renWin.AddRenderer(ren);
            vtk.vtkRenderWindowInteractor iren = new vtk.vtkRenderWindowInteractor();
            iren.SetRenderWindow(renWin);

            // Add the actors to the render; set the background and size
            ren.AddActor(stlActor);
            ren.SetBackground(0.1, 0.2, 0.4);
            renWin.SetSize(500, 500);

            // Zoom in closer
            ren.ResetCamera();
            vtk.vtkCamera cam1 = ren.GetActiveCamera();
            cam1.Zoom(1.4);

            iren.Initialize();
            renWin.Render();
            iren.Start();

            vtk.vtkWin32OpenGLRenderWindow win32win =
                vtk.vtkWin32OpenGLRenderWindow.SafeDownCast(renWin);
            if (null != win32win) win32win.Clean();
        }
        public void ShowVTKV3d()
        {
            renWin.AddRenderer(aRenderer);
            iren.SetRenderWindow(renWin);

            vtk.vtkSmoothPolyDataFilter smoother = new vtk.vtkSmoothPolyDataFilter();
            smoother.SetInputConnection(mc.GetOutputPort());
            smoother.SetRelaxationFactor(0.05);
            smoother.SetNumberOfIterations(30);

            vtk.vtkDecimatePro deci = new vtk.vtkDecimatePro();
            deci.SetInputConnection(smoother.GetOutputPort());
            deci.SetTargetReduction(0.9);
            deci.PreserveTopologyOn();
            deci.Update();

            int marchingNumberOfPoints = deci.GetOutput().GetNumberOfPoints();
            int marchingNumberOfPolys  = deci.GetOutput().GetNumberOfPolys();

            info += "marching number of points : " + marchingNumberOfPoints + "\r\n";
            info += "marching number of polys : " + marchingNumberOfPolys + "\r\n";

            vtk.vtkSmoothPolyDataFilter smoother2 = new vtk.vtkSmoothPolyDataFilter();
            smoother2.SetInputConnection(deci.GetOutputPort());
            smoother2.SetRelaxationFactor(0.05);
            smoother2.SetNumberOfIterations(30);

            mcmap.SetInputConnection(smoother2.GetOutputPort());
            mcmap.ScalarVisibilityOff();
            mcactor.SetMapper(mcmap);
            mcactor.GetProperty().SetColor(1, 1, 1);

            aRenderer.AddActor(mcactor);
            aRenderer.SetBackground(0.0f, 0.0f, 0.0f);
            aRenderer.ResetCamera();
            renWin.Render();
            addBusyObservers();
            iren.Initialize(); iren.Enable();
        }
Esempio n. 5
0
        void Run()
        {
            // Create a selection window.  We will display the point and cell ids
            // that lie within this window.
            int xmin = 200;
            xLength = 100;
            xmax = xmin + xLength;
            int ymin = 200;
            yLength = 100;
            ymax = ymin + yLength;

            pts = new vtk.vtkPoints();
            pts.InsertPoint(0, xmin, ymin, 0);
            pts.InsertPoint(1, xmax, ymin, 0);
            pts.InsertPoint(2, xmax, ymax, 0);
            pts.InsertPoint(3, xmin, ymax, 0);
            vtk.vtkCellArray rect = new vtk.vtkCellArray();
            rect.InsertNextCell(5);
            rect.InsertCellPoint(0);
            rect.InsertCellPoint(1);
            rect.InsertCellPoint(2);
            rect.InsertCellPoint(3);
            rect.InsertCellPoint(0);
            vtk.vtkPolyData selectRect = new vtk.vtkPolyData();
            selectRect.SetPoints(pts);
            selectRect.SetLines(rect);
            vtk.vtkPolyDataMapper2D rectMapper = new vtk.vtkPolyDataMapper2D();
            rectMapper.SetInput(selectRect);
            vtk.vtkActor2D rectActor = new vtk.vtkActor2D();
            rectActor.SetMapper(rectMapper);

            // Create a sphere and its associated mapper and actor.
            vtk.vtkSphereSource sphere = new vtk.vtkSphereSource();
            vtk.vtkPolyDataMapper sphereMapper = new vtk.vtkPolyDataMapper();
            sphereMapper.SetInputConnection(sphere.GetOutputPort());
            vtk.vtkPolyDataMapper.GlobalImmediateModeRenderingOn();
            vtk.vtkActor sphereActor = new vtk.vtkActor();
            sphereActor.SetMapper(sphereMapper);

            // Generate data arrays containing point and cell ids
            vtk.vtkIdFilter ids = new vtk.vtkIdFilter();
            ids.SetInputConnection(sphere.GetOutputPort());
            ids.PointIdsOn();
            ids.CellIdsOn();
            ids.FieldDataOn();

            // Create the renderer here because vtkSelectVisiblePoints needs it.
            vtk.vtkRenderer ren = new vtk.vtkRenderer();

            // Create labels for points
            visPts = new vtk.vtkSelectVisiblePoints();
            visPts.SetInputConnection(ids.GetOutputPort());
            visPts.SetRenderer(ren);
            visPts.SelectionWindowOn();
            visPts.SetSelection(xmin, xmin + xLength, ymin, ymin + yLength);

            // Create the mapper to display the point ids.  Specify the format to
            // use for the labels.  Also create the associated actor.
            vtk.vtkLabeledDataMapper ldm = new vtk.vtkLabeledDataMapper();
            ldm.SetInputConnection(visPts.GetOutputPort());
            ldm.SetLabelFormat("%g");
            ldm.SetLabelModeToLabelFieldData();
            vtk.vtkActor2D pointLabels = new vtk.vtkActor2D();
            pointLabels.SetMapper(ldm);

            // Create labels for cells
            vtk.vtkCellCenters cc = new vtk.vtkCellCenters();
            cc.SetInputConnection(ids.GetOutputPort());
            visCells = new vtk.vtkSelectVisiblePoints();
            visCells.SetInputConnection(cc.GetOutputPort());
            visCells.SetRenderer(ren);
            visCells.SelectionWindowOn();
            visCells.SetSelection(xmin, xmin + xLength, ymin, ymin + yLength);

            // Create the mapper to display the cell ids.  Specify the format to
            // use for the labels.  Also create the associated actor.
            vtk.vtkLabeledDataMapper cellMapper = new vtk.vtkLabeledDataMapper();
            cellMapper.SetInputConnection(visCells.GetOutputPort());
            cellMapper.SetLabelFormat("%g");
            cellMapper.SetLabelModeToLabelFieldData();
            cellMapper.GetLabelTextProperty().SetColor(0, 1, 0);
            vtk.vtkActor2D cellLabels = new vtk.vtkActor2D();
            cellLabels.SetMapper(cellMapper);

            // Create the RenderWindow and RenderWindowInteractor
            renWin = new vtk.vtkRenderWindow();
            renWin.AddRenderer(ren);
            vtk.vtkRenderWindowInteractor iren = new vtk.vtkRenderWindowInteractor();
            iren.SetRenderWindow(renWin);

            // Add the actors to the renderer; set the background and size;
            // render
            ren.AddActor(sphereActor);
            ren.AddActor2D(rectActor);
            ren.AddActor2D(pointLabels);
            ren.AddActor2D(cellLabels);

            ren.SetBackground(1, 1, 1);
            renWin.SetSize(500, 500);

            // Initialize the interactor.
            iren.Initialize();
            renWin.Render();

            // Move the selection window across the data set.
            MoveWindow();

            // Put the selection window in the center of the render window.
            // This works because the xmin = ymin = 200, xLength = yLength = 100, and
            // the render window size is 500 x 500.
            PlaceWindow(xmin, ymin);

            // Now start normal interaction.
            iren.Start();
            vtk.vtkWin32OpenGLRenderWindow win32win =
                vtk.vtkWin32OpenGLRenderWindow.SafeDownCast(renWin);
            if (null != win32win) win32win.Clean();
        }
Esempio n. 6
0
        public void rendersiteplanes(vtk.vtkImageData VoxelData)
        {
            //vtk.vtkWin32RenderWindowInteractor

            renwX.AddRenderer(renX);
            renwY.AddRenderer(renY);
            renwZ.AddRenderer(renZ);

            irenX.SetRenderWindow(renwX);
            irenY.SetRenderWindow(renwY);
            irenZ.SetRenderWindow(renwZ);


            vtk.vtkOutlineFilter outline = new vtk.vtkOutlineFilter();
            outline.SetInput(VoxelData);

            vtk.vtkPolyDataMapper outlineMapper = new vtk.vtkPolyDataMapper();
            outlineMapper.SetInputConnection(outline.GetOutputPort());

            vtk.vtkActor outlineActor = new vtk.vtkActor();
            outlineActor.SetMapper(outlineMapper);

            vtk.vtkCellPicker picker = new vtk.vtkCellPicker();
            picker.SetTolerance(0.005);


            planeWidgetX.SetInteractor(irenX);
            planeWidgetX.DisplayTextOff();
            planeWidgetX.SetInput(VoxelData);
            planeWidgetX.SetPlaneOrientationToXAxes();
            planeWidgetX.SetSliceIndex(slizex);
            planeWidgetX.SetPicker(picker);
            planeWidgetX.On();
            planeWidgetX.InteractionOff();

            if (firstTime)
            {
                double[]           wl   = new double[2];
                vtk.vtkLookupTable lktb = new vtk.vtkLookupTable();
                lktb      = planeWidgetX.GetLookupTable();
                wl        = lktb.GetTableRange();
                rangeXMin = wl[0];
                rangeXMax = wl[1];

                planeWidgetX.GetWindowLevel(wl);
                windowX = wl[0];
                levelX  = wl[1];
            }


            planeWidgetY.SetInteractor(irenY);
            planeWidgetY.DisplayTextOff();
            planeWidgetY.SetInput(VoxelData);
            planeWidgetY.SetPlaneOrientationToYAxes();
            planeWidgetY.SetSliceIndex(slizey);
            planeWidgetY.SetPicker(picker);
            planeWidgetY.On();
            planeWidgetY.InteractionOff();

            if (firstTime)
            {
                double[]           wl   = new double[2];
                vtk.vtkLookupTable lktb = new vtk.vtkLookupTable();
                lktb      = planeWidgetY.GetLookupTable();
                wl        = lktb.GetTableRange();
                rangeYMin = wl[0];
                rangeYMax = wl[1];

                planeWidgetY.GetWindowLevel(wl);
                windowY = wl[0];
                levelY  = wl[1];
            }


            planeWidgetZ.SetInteractor(irenZ);
            planeWidgetZ.DisplayTextOff();
            planeWidgetZ.SetInput(VoxelData);
            planeWidgetZ.SetPlaneOrientationToZAxes();
            planeWidgetZ.SetSliceIndex(slizez);
            planeWidgetZ.SetPicker(picker);
            planeWidgetZ.On();
            planeWidgetZ.InteractionOff();

            if (firstTime)
            {
                double[]           wl   = new double[2];
                vtk.vtkLookupTable lktb = new vtk.vtkLookupTable();
                lktb      = planeWidgetZ.GetLookupTable();
                wl        = lktb.GetTableRange();
                rangeZMin = wl[0];
                rangeZMax = wl[1];

                planeWidgetZ.GetWindowLevel(wl);
                windowZ = wl[0];
                levelZ  = wl[1];
            }

            firstTime = false;
            enabled   = true;

            if (firstime == 1)
            {
                renX.GetActiveCamera().Roll(90);
                renX.GetActiveCamera().Azimuth(90);

                renY.GetActiveCamera().Elevation(-90);
                renX.GetActiveCamera().ParallelProjectionOff();
                renY.GetActiveCamera().ParallelProjectionOff();
                renZ.GetActiveCamera().ParallelProjectionOff();
            }

            renX.ResetCamera();
            renY.ResetCamera();
            renZ.ResetCamera();

            renX.GetActiveCamera().ParallelProjectionOn();
            renY.GetActiveCamera().ParallelProjectionOn();
            renZ.GetActiveCamera().ParallelProjectionOn();

            renX.GetActiveCamera().Azimuth(-90);
            renX.GetActiveCamera().Roll(-90);

            renY.GetActiveCamera().Elevation(90);

            firstime = 1;
            int[]    dimensions = VoxelData.GetDimensions();
            double[] spacing    = VoxelData.GetSpacing();
            double   xmax       = (double)dimensions[0] * spacing[0] * 0.5;
            double   ymax       = (double)dimensions[1] * spacing[1] * 0.5;
            double   zmax       = (double)dimensions[2] * spacing[2] * 0.5;

            double smax = xmax;

            if (ymax > smax)
            {
                smax = ymax;
            }
            if (zmax > smax)
            {
                smax = zmax;
            }

            renX.GetActiveCamera().SetParallelScale(smax);
            renY.GetActiveCamera().SetParallelScale(smax);
            renZ.GetActiveCamera().SetParallelScale(smax);

            renX.GetActiveCamera().SetClippingRange(0.1, 1000);
            renY.GetActiveCamera().SetClippingRange(0.1, 1000);
            renZ.GetActiveCamera().SetClippingRange(0.1, 1000);

            irenX.Initialize();
            irenY.Initialize();
            irenZ.Initialize();

            irenX.Disable();
            irenY.Disable();
            irenZ.Disable();

            renwX.Render();
            renwY.Render();
            renwZ.Render();
        }
Esempio n. 7
0
        public void render3Dplanes(vtk.vtkImageData VoxelData)
        {
            renWin.AddRenderer(ren2);

            iren.SetRenderWindow(renWin);

            vtk.vtkOutlineFilter outline = new vtk.vtkOutlineFilter();
            outline.SetInput(VoxelData);

            vtk.vtkPolyDataMapper outlineMapper = new vtk.vtkPolyDataMapper();
            outlineMapper.SetInputConnection(outline.GetOutputPort());

            vtk.vtkActor outlineActor = new vtk.vtkActor();
            outlineActor.SetMapper(outlineMapper);

            vtk.vtkCellPicker picker = new vtk.vtkCellPicker();
            picker.SetTolerance(0.005);

            vtk.vtkColorTransferFunction colorTransferFunction = new vtk.vtkColorTransferFunction();

            double[] inputRange = VoxelData.GetScalarRange();
            colorTransferFunction.AddRGBPoint(inputRange[0], 0.0, 0.0, 0.0);
            colorTransferFunction.AddRGBPoint(inputRange[1], 1.0, 1.0, 1.0);

            sColorsX.SetLookupTable(colorTransferFunction);
            sColorsY.SetLookupTable(colorTransferFunction);
            sColorsZ.SetLookupTable(colorTransferFunction);

            planeWidgetX.SetColorMap(sColorsX);
            planeWidgetX.SetInteractor(iren);
            planeWidgetX.DisplayTextOff();
            planeWidgetX.SetInput(VoxelData);
            planeWidgetX.SetPlaneOrientationToXAxes();
            planeWidgetX.SetSliceIndex(slizex);
            planeWidgetX.SetPicker(picker);
            planeWidgetX.On();
            planeWidgetX.InteractionOff();

            planeWidgetY.SetColorMap(sColorsY);
            planeWidgetY.SetInteractor(iren);
            planeWidgetY.DisplayTextOff();
            planeWidgetY.SetInput(VoxelData);
            planeWidgetY.SetPlaneOrientationToYAxes();
            planeWidgetY.SetSliceIndex(slizey);
            planeWidgetY.SetPicker(picker);
            planeWidgetY.On();
            planeWidgetY.InteractionOff();


            planeWidgetZ.SetColorMap(sColorsZ);
            planeWidgetZ.SetInteractor(iren);
            planeWidgetZ.DisplayTextOff();
            planeWidgetZ.SetInput(VoxelData);
            planeWidgetZ.SetPlaneOrientationToZAxes();
            planeWidgetZ.SetSliceIndex(slizez);
            planeWidgetZ.SetPicker(picker);
            planeWidgetZ.On();
            planeWidgetZ.InteractionOff();
            ren2.ResetCamera();
            renWin.Render();
            iren.Initialize(); iren.Enable();
        }
Esempio n. 8
0
        // Function: Calculate en render Histogram in window
        public void renderHistogram(vtk.vtkImageData VoxelData)
        {
            // Get size of histogram window
            int[] size = renHist.GetSize();
            width = size[0]; height = size[1];


            //Setup parameters histogram Accumulate Filter
            numBins    = width / 2;
            inputRange = VoxelData.GetScalarRange();
            double origin  = inputRange[0];
            double spacing = 1.0 * (inputRange[1] - origin) / numBins;

            // Setup Accumulate filter
            vtk.vtkImageAccumulate accumulate = new vtk.vtkImageAccumulate();
            accumulate.SetInput(VoxelData); //Get input voxeldata
            accumulate.SetComponentExtent(0, numBins - 1, 0, 0, 0, 0);
            accumulate.SetComponentOrigin(origin, 0.0, 0.0);
            accumulate.SetComponentSpacing(spacing, 1.0, 1.0);

            // Make Data object from Accumulated object
            data = accumulate.GetOutput();
            data.Update();

            // Initialize first and last point of the transferfunction.
            npoints    = 2;
            pointsx[0] = 0; pointsy[0] = 0;
            pointsx[1] = width - 1; pointsy[1] = height - 1;
            pointsc[0] = 1; pointsc[1] = 1;

            // Draw the histogram in a canvas and add the transferfunction to it
            drawhisto();
            drawcurve();

            // Create a color table
            vtk.vtkColorTransferFunction colorTransferFunction = new vtk.vtkColorTransferFunction();
            for (int i = 0; i < 14; i++)
            {
                colorTransferFunction.AddRGBPoint(i, colortable[i, 0], colortable[i, 1], colortable[i, 2]);
            }



            // Use the color table to color the histogram window objects
            vtk.vtkImageMapToColors sColors = new vtk.vtkImageMapToColors();
            sColors.SetInputConnection(canvas.GetOutputPort());
            sColors.SetLookupTable(colorTransferFunction);

            // Convert the histogram image to a histogram imagemap
            vtk.vtkImageMapper histmap = new vtk.vtkImageMapper();
            histmap.SetInputConnection(sColors.GetOutputPort());
            histmap.RenderToRectangleOn();
            histmap.SetColorWindow(256);
            histmap.SetColorLevel(127);

            // Create the actor needed to draw the histogram image
            vtk.vtkActor2D imageactor = new vtk.vtkActor2D();
            imageactor.SetMapper(histmap);
            imageactor.SetPosition(0, 0); // Fit the histogram to the window
            imageactor.SetPosition2(1, 1);

            // Add the Histogram Image Render to the window object
            ren1.AddActor(imageactor);
            ren1.SetViewport(0, 0, 1, 1); // Fit the histogram to the window
            renHist.AddRenderer(ren1);

            // Add a Window (mouse) interactor to the window
            iren.SetRenderWindow(renHist);

            // Add mouse events to the window
            iren.RemoveObserver((uint)vtk.EventIds.LeftButtonPressEvent);
            iren.AddObserver((uint)vtk.EventIds.LeftButtonPressEvent, new vtk.vtkDotNetCallback(LeftButtonPress));

            iren.RemoveObserver((uint)vtk.EventIds.LeftButtonReleaseEvent);
            iren.AddObserver((uint)vtk.EventIds.LeftButtonReleaseEvent, new vtk.vtkDotNetCallback(LeftButtonRelease));

            iren.RemoveObserver((uint)vtk.EventIds.MouseMoveEvent);
            iren.AddObserver((uint)vtk.EventIds.MouseMoveEvent, new vtk.vtkDotNetCallback(MouseMove));

            iren.RemoveObserver((uint)vtk.EventIds.RightButtonPressEvent);
            iren.AddObserver((uint)vtk.EventIds.RightButtonPressEvent, new vtk.vtkDotNetCallback(RightButtonPress));

            iren.RemoveObserver((uint)vtk.EventIds.MiddleButtonPressEvent);
            iren.AddObserver((uint)vtk.EventIds.MiddleButtonPressEvent, new vtk.vtkDotNetCallback(MiddleButtonPress));

            // Set the (display) update rate of the histogram
            iren.SetStillUpdateRate(5);
            iren.SetDesiredUpdateRate(5);

            // Initialize interactor and render histogram
            iren.Initialize();
            renHist.Render();

            // Debug output
            info = "Histogram is created \r\n";
        }