/// <summary> /// Gets a 2D slice from the 3D data. /// </summary> /// <param name="volume">Full 3D data.</param> /// <param name="sliceN">Number of slice to be selected.</param> /// <param name="axis">Axis on which selection will be made.</param> /// <returns></returns> public static vtkImageData volumeSlicer(vtkImageData volume, int[] sliceN, int axis) { //Initialize VOI extractor and permuter. //Permuter will correct the orientation of the output image vtkExtractVOI slicer = vtkExtractVOI.New(); vtkImagePermute permuter = vtkImagePermute.New(); //Connect data to slicer slicer.SetInput(volume); slicer.Update(); //Get data dimensions int[] dims = slicer.GetOutput().GetExtent(); //Get slice //Coronal plane if (axis == 0) { //Set VOI slicer.SetVOI(sliceN[0] - 1, sliceN[0], dims[2], dims[3], dims[4], dims[5]); slicer.Update(); //Permute image (not necessary here) permuter.SetInputConnection(slicer.GetOutputPort()); permuter.SetFilteredAxes(1, 2, 0); permuter.Update(); } //Transverse plane YZ if (axis == 1) { //Set VOI slicer.SetVOI(dims[0], dims[1], sliceN[1] - 1, sliceN[1], dims[4], dims[5]); slicer.Update(); //Permute image permuter.SetInputConnection(slicer.GetOutputPort()); permuter.SetFilteredAxes(0, 2, 1); permuter.Update(); } //Transverse plane, XZ if (axis == 2) { //Set VOI slicer.SetVOI(dims[0], dims[1], dims[2], dims[3], sliceN[2] - 1, sliceN[2]); slicer.Update(); //Permute image permuter.SetInputConnection(slicer.GetOutputPort()); permuter.SetFilteredAxes(0, 1, 2); permuter.Update(); } //slicer.Update(); //Return copy of the slice return(permuter.GetOutput()); }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVTestExtractVOI(String [] argv) { //Prefix Content is: "" // to mark the origin[] sphere = new vtkSphereSource(); sphere.SetRadius((double)2.0); sphereMapper = vtkPolyDataMapper.New(); sphereMapper.SetInputConnection((vtkAlgorithmOutput)sphere.GetOutputPort()); sphereMapper.ImmediateModeRenderingOn(); sphereActor = new vtkActor(); sphereActor.SetMapper((vtkMapper)sphereMapper); rt = new vtkRTAnalyticSource(); rt.SetWholeExtent((int)-50,(int)50,(int)-50,(int)50,(int)0,(int)0); voi = new vtkExtractVOI(); voi.SetInputConnection((vtkAlgorithmOutput)rt.GetOutputPort()); voi.SetVOI((int)-11,(int)39,(int)5,(int)45,(int)0,(int)0); voi.SetSampleRate((int)5,(int)5,(int)1); // Get rid ambiguous triagulation issues.[] surf = new vtkDataSetSurfaceFilter(); surf.SetInputConnection((vtkAlgorithmOutput)voi.GetOutputPort()); tris = new vtkTriangleFilter(); tris.SetInputConnection((vtkAlgorithmOutput)surf.GetOutputPort()); mapper = vtkPolyDataMapper.New(); mapper.SetInputConnection((vtkAlgorithmOutput)tris.GetOutputPort()); mapper.ImmediateModeRenderingOn(); mapper.SetScalarRange((double)130,(double)280); actor = new vtkActor(); actor.SetMapper((vtkMapper)mapper); ren = vtkRenderer.New(); ren.AddActor((vtkProp)actor); ren.AddActor((vtkProp)sphereActor); ren.ResetCamera(); camera = ren.GetActiveCamera(); //$camera SetPosition 68.1939 -23.4323 12.6465[] //$camera SetViewUp 0.46563 0.882375 0.0678508 [] //$camera SetFocalPoint 3.65707 11.4552 1.83509 [] //$camera SetClippingRange 59.2626 101.825 [] renWin = vtkRenderWindow.New(); renWin.AddRenderer((vtkRenderer)ren); iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); iren.Initialize(); //deleteAllVTKObjects(); }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVTestExtractVOI(String [] argv) { //Prefix Content is: "" // to mark the origin[] sphere = new vtkSphereSource(); sphere.SetRadius((double)2.0); sphereMapper = vtkPolyDataMapper.New(); sphereMapper.SetInputConnection((vtkAlgorithmOutput)sphere.GetOutputPort()); sphereMapper.ImmediateModeRenderingOn(); sphereActor = new vtkActor(); sphereActor.SetMapper((vtkMapper)sphereMapper); rt = new vtkRTAnalyticSource(); rt.SetWholeExtent((int)-50, (int)50, (int)-50, (int)50, (int)0, (int)0); voi = new vtkExtractVOI(); voi.SetInputConnection((vtkAlgorithmOutput)rt.GetOutputPort()); voi.SetVOI((int)-11, (int)39, (int)5, (int)45, (int)0, (int)0); voi.SetSampleRate((int)5, (int)5, (int)1); // Get rid ambiguous triagulation issues.[] surf = new vtkDataSetSurfaceFilter(); surf.SetInputConnection((vtkAlgorithmOutput)voi.GetOutputPort()); tris = new vtkTriangleFilter(); tris.SetInputConnection((vtkAlgorithmOutput)surf.GetOutputPort()); mapper = vtkPolyDataMapper.New(); mapper.SetInputConnection((vtkAlgorithmOutput)tris.GetOutputPort()); mapper.ImmediateModeRenderingOn(); mapper.SetScalarRange((double)130, (double)280); actor = new vtkActor(); actor.SetMapper((vtkMapper)mapper); ren = vtkRenderer.New(); ren.AddActor((vtkProp)actor); ren.AddActor((vtkProp)sphereActor); ren.ResetCamera(); camera = ren.GetActiveCamera(); //$camera SetPosition 68.1939 -23.4323 12.6465[] //$camera SetViewUp 0.46563 0.882375 0.0678508 [] //$camera SetFocalPoint 3.65707 11.4552 1.83509 [] //$camera SetClippingRange 59.2626 101.825 [] renWin = vtkRenderWindow.New(); renWin.AddRenderer((vtkRenderer)ren); iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); iren.Initialize(); //deleteAllVTKObjects(); }
public cVolumeRendering3D(cSingleChannelImage SingleChannelImage, cPoint3D Pos, byte[][] NewLUT, c3DNewWorld AssociatedWorld) { if (SingleChannelImage.Data == null) return; baseInit(AssociatedWorld); this.SetName("Volume 3D [" + SingleChannelImage.Name + "]"); this.LUT = NewLUT; vtk_volume = vtkVolume.New(); vtkImageData imageData = vtkImageData.New(); vtkUnsignedShortArray UshortArray = vtkUnsignedShortArray.New(); voi = vtkExtractVOI.New(); ColorTransferFunction = vtkColorTransferFunction.New(); for (int i = 0; i < SingleChannelImage.Width * SingleChannelImage.Height * SingleChannelImage.Depth; i++) { UshortArray.InsertTuple1(i, (ushort)SingleChannelImage.Data[i]); // data are converted to UShort } imageData = vtkImageData.New(); imageData.SetDimensions(SingleChannelImage.Width, SingleChannelImage.Height, SingleChannelImage.Depth); imageData.SetOrigin(0, 0, 0); if ((SingleChannelImage.Resolution.X == 0) || (SingleChannelImage.Resolution.Y == 0) || (SingleChannelImage.Resolution.Z == 0)) imageData.SetSpacing(1.0, 1.0, 1.0); else imageData.SetSpacing(SingleChannelImage.Resolution.X, SingleChannelImage.Resolution.Y, SingleChannelImage.Resolution.Z); imageData.GetPointData().SetScalars(UshortArray); voi = vtkExtractVOI.New(); voi.SetInput(imageData); voi.SetVOI(0, SingleChannelImage.Width - 1, 0, SingleChannelImage.Height - 1, 0, SingleChannelImage.Depth - 1); voi.SetSampleRate(1, 1, 1); opacityTransferFunction = vtkPiecewiseFunction.New(); range = imageData.GetScalarRange(); opacityTransferFunction.AddPoint(range[0], 0.0); opacityTransferFunction.AddPoint(range[1], 0.3); //opacityTransferFunction.AddPoint(2000, 0.1); //opacityTransferFunction.AddPoint(range[0] + (range[1]-range[0])/2.0, 0.0); //opacityTransferFunction.AddPoint(range[1], 0.7); if (LUT == null) { //cLUT MyLut = new cLUT(); //LUT = MyLut.LUT_JET; ColorTransferFunction.AddRGBPoint(0, 0 , 0, 0); ColorTransferFunction.AddRGBPoint(1, 1, 1, 1); } //double LUTSize = LUT[0].Length; //for (int i = 0; i < (int)LUTSize; i++) //{ // colorTransferFunction.AddRGBPoint(i, LUT[0][i] / LUTSize, LUT[1][i] / LUTSize, LUT[2][i] / LUTSize); //} ColorTransferFunction.Build(); volumeProperty = vtkVolumeProperty.New(); volumeProperty.SetColor(ColorTransferFunction); volumeProperty.SetScalarOpacity(opacityTransferFunction); volumeProperty.SetInterpolationTypeToNearest(); volumeProperty.ShadeOff(); vtkVolumeTextureMapper3D volumeTextureMapper = vtkVolumeTextureMapper3D.New(); volumeTextureMapper.SetInputConnection(voi.GetOutputPort()); //vtkVolumeRayCastCompositeFunction compositeFunction = vtkVolumeRayCastCompositeFunction.New(); //vtkVolumeRayCastMapper volumeMapper = vtkVolumeRayCastMapper.New(); //volumeMapper.SetVolumeRayCastFunction(compositeFunction); //volumeMapper.SetInputConnection(voi.GetOutputPort()); vtk_volume = vtkVolume.New(); vtk_volume.SetMapper(volumeTextureMapper); vtk_volume.SetProperty(volumeProperty); vtk_volume.PickableOn(); vtk_volume.SetPosition(Pos.X, Pos.Y, Pos.Z); }
public cVolumeRendering3D(vtkImageData imageData, cPoint3D Pos) { baseInit(null); vtk_volume = vtkVolume.New(); // vtkFloatArray floatArray = vtkFloatArray.New(); //vtkCharArray charArray = vtkCharArray.New(); // vtkUnsignedShortArray UshortArray = vtkUnsignedShortArray.New(); vtkExtractVOI voi = vtkExtractVOI.New(); // vtkPiecewiseFunction opacityTransferFunction = vtkPiecewiseFunction.New(); vtkColorTransferFunction colorTransferFunction = vtkColorTransferFunction.New(); vtkVolumeProperty volumeProperty = vtkVolumeProperty.New(); // imageData.GetPointData().SetScalars(UshortArray); voi = vtkExtractVOI.New(); voi.SetInput(imageData); voi.SetVOI(0, imageData.GetDimensions()[0] - 1, 0, imageData.GetDimensions()[1] - 1, 0, imageData.GetDimensions()[2] - 1); voi.SetSampleRate(1, 1, 1); opacityTransferFunction = vtkPiecewiseFunction.New(); range = imageData.GetScalarRange(); opacityTransferFunction.AddPoint(100, 0.0); opacityTransferFunction.AddPoint(1000, 1); //opacityTransferFunction.AddPoint(range[0] + (range[1]-range[0])/2.0, 0.0); //opacityTransferFunction.AddPoint(range[1], 0.7); ////Scale the image between 0 and 1 using a lookup table //vtkLookupTable table = vtkLookupTable.New(); //table.SetValueRange(0,1); //table.SetSaturationRange(0,0); //table.SetRange(range[0], range[1]); //shoul here not be the minimum/maximum possible of "data"? //table.SetRampToLinear(); //table.Build(); //vtkImageMapToColors color = vtkImageMapToColors.New(); //color.SetLookupTable(table); //color.SetInputConnection(imageData.GetProducerPort()); vtkColorTransferFunction ColorTransferFunction = vtkColorTransferFunction.New(); ColorTransferFunction.AddRGBPoint(20.0, 0.0, 0.0, 1.0); ColorTransferFunction.AddRGBPoint(255.0, 1.0, 0.0, 0.0); //ColorTransferFunction.AddRGBPoint(1000.0, 0.8, 0.5, 0.0); //opacityTransferFunction.ClampingOff(); volumeProperty = vtkVolumeProperty.New(); volumeProperty.SetColor(colorTransferFunction); volumeProperty.SetScalarOpacity(opacityTransferFunction); volumeProperty.SetInterpolationTypeToLinear(); volumeProperty.ShadeOn(); volumeProperty.SetAmbient(0.6); volumeProperty.SetDiffuse(0.6); volumeProperty.SetSpecular(0.1); //volumeProperty.SetAmbient(0.1); //volumeProperty.SetDiffuse(0.9); //volumeProperty.SetSpecular(0.2); //volumeProperty.SetSpecularPower(10.0); //volumeProperty[band].SetScalarOpacityUnitDistance(0.8919); vtkVolumeTextureMapper3D volumeTextureMapper = vtkVolumeTextureMapper3D.New(); ////volumeTextureMapper.SetInputConnection(color.GetOutputPort()); volumeTextureMapper.SetInputConnection(voi.GetOutputPort()); //vtkVolumeRayCastCompositeFunction compositeFunction = vtkVolumeRayCastCompositeFunction.New(); //vtkVolumeRayCastMapper volumeMapper = vtkVolumeRayCastMapper.New(); //volumeMapper.SetVolumeRayCastFunction(compositeFunction); //volumeMapper.SetInputConnection(voi.GetOutputPort()); vtk_volume = vtkVolume.New(); vtk_volume.SetMapper(volumeTextureMapper); vtk_volume.SetProperty(volumeProperty); vtk_volume.PickableOff(); vtk_volume.SetPosition(Pos.X, Pos.Y, Pos.Z); }