/// <summary> /// 进行可视化 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void VisiualizeSlicesWnd_Load(object sender, EventArgs e) { vtkRenderer renderer = rwcShowSlices.RenderWindow.GetRenderers().GetFirstRenderer(); renderer.SetBackground(1, 1, 1); //CuteTools.ShowImageSeries(fnFormat, height, width, startIndex, endIndex, renderer); //return; vtkBMPReader reader = vtkBMPReader.New(); reader.SetFilePattern(fnFormat); reader.SetDataExtent(0, height - 1, 0, width - 1, startIndex, endIndex); reader.SetDataScalarTypeToUnsignedChar(); reader.Update(); vol = vtkVolume.New(); vtkFixedPointVolumeRayCastMapper texMapper = vtkFixedPointVolumeRayCastMapper.New(); texMapper.SetInput(reader.GetOutput()); vol.SetMapper(texMapper); colorTransferFunction = vtkColorTransferFunction.New(); colorTransferFunction.AddRGBPoint(0, tbR1.Value * 1.0 / 255, tbG1.Value * 1.0 / 255, tbB1.Value * 1.0 / 255); colorTransferFunction.AddRGBPoint(1, tbR2.Value * 1.0 / 255, tbG2.Value * 1.0 / 255, tbB2.Value * 1.0 / 255); colorTransferFunction.ClampingOn(); vpro = vtkVolumeProperty.New(); vtkPiecewiseFunction compositeOpacity = vtkPiecewiseFunction.New(); compositeOpacity.AddPoint(0, 0); //compositeOpacity.AddPoint(120.0, 0.5); compositeOpacity.AddPoint(255.0, 1); compositeOpacity.ClampingOn(); vpro.SetScalarOpacity(compositeOpacity); vpro.SetColor(colorTransferFunction); //vpro.SetInterpolationTypeToLinear(); vpro.SetInterpolationTypeToNearest(); //vpro.ShadeOn(); vol.SetProperty(vpro); //画轴距图 vol.SetOrientation(45, 45, 0); //rwcShowSlices.RenderWindow.GetRenderers().GetFirstRenderer().AddVolume( vol ); rwcShowSlices.Refresh(); }
/// <summary> /// /// <summary> /// 用体绘制的方法绘制一系列的图像 /// </summary> /// <param name="format">图像文件的字符串格式</param> /// <param name="height">一幅图像的高度</param> /// <param name="width">高度</param> /// <param name="startIndex">起始index</param> /// <param name="endIndex">末尾index</param> /// <param name="r">renderer,如果非空,则将其体绘制结果添加到这里面来</param> /// example: /// CuteTools.ShowImageSeries(@"initial/%03d.bmp",64, 64, 0, 62); public static void ShowImageSeries(string format, int height, int width, int startIndex, int endIndex, vtkRenderer r = null) { if (format == null || format.Count() <= 4 || (!format.Substring(format.Count() - 3, 3).Equals("bmp"))) { Console.WriteLine("image filename is not correct!!"); return; } vtkBMPReader reader = vtkBMPReader.New(); reader.SetFilePattern(format); reader.SetDataExtent(0, height - 1, 0, width - 1, startIndex, endIndex); reader.SetDataScalarTypeToUnsignedChar(); reader.Update(); vtkVolume vol = vtkVolume.New(); vtkFixedPointVolumeRayCastMapper texMapper = vtkFixedPointVolumeRayCastMapper.New(); texMapper.SetInput(reader.GetOutput()); vol.SetMapper(texMapper); vtkColorTransferFunction colorTransferFunction = vtkColorTransferFunction.New(); colorTransferFunction.AddRGBPoint(0.0, 0.0, 255.0, 0.0); //colorTransferFunction.AddRGBPoint(120.0, 0.0, 0.0, 1.0); //colorTransferFunction.AddRGBPoint(160.0, 1.0, 0.0, 0.0); //colorTransferFunction.AddRGBPoint(200.0, 0.0, 1.0, 0.0); colorTransferFunction.AddRGBPoint(255, 0, 0, 1.0); colorTransferFunction.ClampingOn(); vtkVolumeProperty vpro = vtkVolumeProperty.New(); vtkPiecewiseFunction compositeOpacity = vtkPiecewiseFunction.New(); compositeOpacity.AddPoint(80, 1); compositeOpacity.AddPoint(120, 0.2); compositeOpacity.AddPoint(255, 0); compositeOpacity.ClampingOn(); vpro.SetScalarOpacity(compositeOpacity); //vpro.SetColor( colorTransferFunction ); vpro.SetInterpolationTypeToLinear(); //vpro.ShadeOn(); vol.SetProperty(vpro); //画轴距图 vol.SetOrientation(45, 45, 0); if (r != null) { r.AddVolume(vol); } else { vtkRenderer render = vtkRenderer.New(); render.AddVolume(vol); render.SetBackground(1, 1, 1); vtkRenderWindow wnd = vtkRenderWindow.New(); wnd.AddRenderer(render); vtkRenderWindowInteractor inter = vtkRenderWindowInteractor.New(); inter.SetRenderWindow(wnd); inter.Initialize(); inter.Start(); } }