//镂空模式_初始化颜色 private void InitializeColor_HollowOut(ExGrid Grid) { m_LookupTable = vtkLookupTable.New(); m_LookupTable.SetTableRange(Grid.Min, Grid.Max); //蓝色->红色 m_LookupTable.SetHueRange(0.666667, 0); m_LookupTable.SetNumberOfColors(100); m_LookupTable.Build(); //设定标量值的颜色 m_ColorTransferFunction = vtkColorTransferFunction.New(); for (int i = 0; i < 100; i += 10) { var color = m_LookupTable.GetTableValue(i); double Range = Grid.Max - Grid.Min; m_ColorTransferFunction.AddRGBPoint(Grid.Min + i * Range / 100.0, color[0], color[1], color[2]); } m_ColorTransferFunction.Build(); //线性插值透明度 m_PiecewiseFunction = vtkPiecewiseFunction.New(); // [,) InitRanges(); foreach (var range in m_IntersectRanges) { double Min = range.Min; double Max = range.Max; ////由于VTK的特性,对Max进行修正 //如果透明 if (range.Transparent) { m_PiecewiseFunction.AddSegment(Min, Transparency_Yes, Max, Transparency_Yes); } //不透明 else { Min = Min + EPSILON; Max = Max - EPSILON; m_PiecewiseFunction.AddSegment(Min, Transparency_Not, Max, Transparency_Not); } } }
/// <summary> /// Set up the new PlaneWidget. /// </summary> /// <param name="planeWidget">Plane to set up.</param> private void SetupPlane(PlaneWidget planeWidget) { planeWidget.DisplayTextOff(); planeWidget.SetInput(_dicomLoader.GetOutput()); planeWidget.SetPlaneOrientationToXAxes(); planeWidget.SetSliceIndex(250); planeWidget.SetInteractor(_renderWindowInteractor); planeWidget.SetLeftButtonAction(99); planeWidget.SetRightButtonAction(0); planeWidget.SetMarginSizeX(0); planeWidget.SetMarginSizeY(0); planeWidget.GetMarginProperty().SetColor(1, 0, 0); planeWidget.GetSelectedPlaneProperty().SetOpacity(0); planeWidget.GetCursorProperty().SetOpacity(0); planeWidget.GetPlaneProperty().SetOpacity(0); vtkColorTransferFunction colors = vtkColorTransferFunction.New(); if (planeWidget.Axis == Axis.X) { planeWidget.SetPlaneOrientationToXAxes(); colors.AddRGBPoint(0, 1, 0, 0); //red } else if (planeWidget.Axis == Axis.Y) { planeWidget.SetPlaneOrientationToYAxes(); colors.AddRGBPoint(0, 0, 1, 0); } else if (planeWidget.Axis == Axis.Z) { planeWidget.SetPlaneOrientationToZAxes(); colors.AddRGBPoint(0, 0, 0, 1); } colors.SetAlpha(0.4); colors.SetColorSpaceToRGB(); colors.Build(); planeWidget.GetColorMap().SetLookupTable(colors); }
//普通模式_初始化颜色 private void InitializeColor_Normal(ExGrid Grid) { m_LookupTable = vtkLookupTable.New(); m_LookupTable.SetTableRange(Grid.Min, Grid.Max); //蓝色->红色 m_LookupTable.SetHueRange(0.667, 0); m_LookupTable.SetNumberOfColors(100); m_LookupTable.Build(); //设定标量值的颜色 m_ColorTransferFunction = vtkColorTransferFunction.New(); for (int i = 0; i < 100; i += 10) { var color = m_LookupTable.GetTableValue(i); double Range = Grid.Max - Grid.Min; m_ColorTransferFunction.AddRGBPoint(Grid.Min + i * Range / 100.0, color[0], color[1], color[2]); } m_ColorTransferFunction.Build(); //线性插值透明度 m_PiecewiseFunction = vtkPiecewiseFunction.New(); m_PiecewiseFunction.AddPoint(Grid.Min, 1); m_PiecewiseFunction.AddPoint(Grid.Max, 1); }
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); }