Esempio n. 1
0
        public void readVTKDicom(string dirname)
        {
            vtk.vtkDICOMImageReader DICOMreader = new vtk.vtkDICOMImageReader();
            DICOMreader.SetDirectoryName(dirname);
            DICOMreader.SetDataOrigin(0, 0, 0);
            DICOMreader.Update();

            vtk.vtkImageChangeInformation imageChangeInformation = new vtk.vtkImageChangeInformation();
            imageChangeInformation.SetInput(DICOMreader.GetOutput());
            imageChangeInformation.CenterImageOn(); // Centered the image here....
            imageChangeInformation.Update();

            VoxelData = imageChangeInformation.GetOutput();

            spacing = VoxelData.GetSpacing();
            int numberofpixels = VoxelData.GetNumberOfPoints();

            dimensions      = VoxelData.GetDimensions();
            metaScalarRange = VoxelData.GetScalarRange();
            double[] origin = VoxelData.GetOrigin();

            info  = "\r\n VTK Dicom dir read, parameters: \r\n";
            info += "Volume dimensions : " + dimensions[0] + " " + dimensions[1] + " " + dimensions[2] + "\r\n";
            info += "Volume scales : " + spacing[0] + " " + spacing[1] + " " + spacing[2] + "\r\n";
            info += "Scalar range : " + metaScalarRange[0] + " " + metaScalarRange[1] + "\r\n";
            info += "Volume origin: " + origin[0] + " " + origin[1] + " " + origin[2] + "\r\n";
            info += "Number of Pixels : " + numberofpixels + "\r\n";
            GC.Collect();
        }
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
        public void deleterender()
        {
            EmptyVTK eVolume = new EmptyVTK();

            VoxelData = eVolume.GetEmptyVolume(); VoxelData.Update();
            vtk.vtkFixedPointVolumeRayCastMapper volumeMapper = new vtk.vtkFixedPointVolumeRayCastMapper();
            volumeMapper.SetInput(VoxelData); volumeMapper.Update();
            volume.SetMapper(volumeMapper); volume.Update();

            iren.Disable();
        }
Esempio n. 4
0
        public void deleterender()
        {
            EmptyVTK eVolume = new EmptyVTK();

            vtk.vtkImageData VoxelData = eVolume.GetEmptyVolume();
            planeWidgetX.SetInput(VoxelData);
            planeWidgetY.SetInput(VoxelData);
            planeWidgetZ.SetInput(VoxelData);
            planeWidgetX.Off();
            planeWidgetY.Off();
            planeWidgetZ.Off();
            renWin.Render();
        }
        public void MC_VTK(vtk.vtkImageData VoxelDatat)
        {
            VoxelData = VoxelDatat;
            mc.SetInput(VoxelData);
            mc.SetValue(0, isovalue);
            mc.ComputeGradientsOff();
            mc.ComputeScalarsOff();
            mc.ComputeNormalsOff();
            mc.ComputeNormalsOn();
            mc.Update();
            int marchingNumberOfPoints = mc.GetOutput().GetNumberOfPoints();
            int marchingNumberOfPolys  = mc.GetOutput().GetNumberOfPolys();

            info += "marching number of points : " + marchingNumberOfPoints + "\r\n";
            info += "marching number of polys : " + marchingNumberOfPolys + "\r\n";
        }
Esempio n. 6
0
        public vtk.vtkImageData GetEmptyVolume()
        {
            // Create a pointer to a small array
            int[]  managedArray = { 1, 1, 1, 1, 1, 1, 1, 1 };
            IntPtr pnt          = Marshal.AllocHGlobal(Marshal.SizeOf(managedArray[0]) * managedArray.Length);

            Marshal.Copy(managedArray, 0, pnt, managedArray.Length);

            vtk.vtkImageData emptyVolume = new vtk.vtkImageData();
            // Use the small array as data of the empty Volume
            vtk.vtkImageImport importer = new vtk.vtkImageImport();
            importer.SetWholeExtent(0, 1, 0, 1, 0, 1);
            importer.SetDataExtentToWholeExtent();
            importer.SetDataScalarTypeToUnsignedShort();
            importer.SetImportVoidPointer(pnt);
            emptyVolume = importer.GetOutput();
            return(emptyVolume);
        }
Esempio n. 7
0
        public void ReadVTKV3D(string filename)
        {
            readv3dinfo V3Dfileinfo = new readv3dinfo();

            V3Dfileinfo.getv3dinfo(filename);

            vtk.vtkImageReader V3Dreader = new vtk.vtkImageReader();
            //V3Dreader.RemoveAllInputs();
            // all the slices are in one file
            V3Dreader.SetFileDimensionality(3);

            // image is greyscale
            V3Dreader.SetNumberOfScalarComponents(1);

            // 2 bytes per voxel
            V3Dreader.SetDataScalarTypeToUnsignedShort();

            // volume dimension sizes
            int maxx = V3Dfileinfo.v3dsizes[0] - 1;
            int maxy = V3Dfileinfo.v3dsizes[1] - 1;
            int maxz = V3Dfileinfo.v3dsizes[2] - 1;

            V3Dreader.SetDataExtent(0, maxx, 0, maxy, 0, maxz);

            //voxel spacing
            spacing = V3Dfileinfo.v3dscales;
            V3Dreader.SetDataSpacing(spacing);

            // set to zero unless you know
            double[] origing = new double[3] {
                0, 0, 0
            };
            V3Dreader.SetDataOrigin(origing);

            V3Dreader.SetHeaderSize((uint)V3Dfileinfo.v3doffset);

            // set filename
            V3Dreader.SetFileName(V3Dfileinfo.v3dfilename);

            V3Dreader.Update();

            vtk.vtkImageChangeInformation imageChangeInformation = new vtk.vtkImageChangeInformation();
            imageChangeInformation.SetInput(V3Dreader.GetOutput());
            imageChangeInformation.CenterImageOn(); // Centered the image here....
            imageChangeInformation.Update();

            VoxelData = imageChangeInformation.GetOutput();

            spacing = VoxelData.GetSpacing();
            int numberofpixels = VoxelData.GetNumberOfPoints();

            dimensions      = VoxelData.GetDimensions();
            metaScalarRange = VoxelData.GetScalarRange();
            double[] origin = VoxelData.GetOrigin();

            info  = "\r\n VTK file read, parameters: \r\n";
            info += "Volume dimensions : " + dimensions[0] + " " + dimensions[1] + " " + dimensions[2] + "\r\n";
            info += "Volume scales : " + spacing[0] + " " + spacing[1] + " " + spacing[2] + "\r\n";
            info += "Volume origin: " + origin[0] + " " + origin[1] + " " + origin[2] + "\r\n";
            info += "Scalar range : " + metaScalarRange[0] + " " + metaScalarRange[1] + "\r\n";
            info += "Number of Pixels : " + numberofpixels + "\r\n";
            GC.Collect();
        }
Esempio n. 8
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. 9
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. 10
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";
        }