private void RenderVTI() { // reader // Read all the data from the file vtkXMLImageDataReader reader = vtkXMLImageDataReader.New(); if (reader.CanReadFile(m_FileName) == 0) { MessageBox.Show("Cannot read file \"" + m_FileName + "\"", "Error", MessageBoxButtons.OK); return; } vtkVolume vol = vtkVolume.New(); vtkColorTransferFunction ctf = vtkColorTransferFunction.New(); vtkPiecewiseFunction spwf = vtkPiecewiseFunction.New(); vtkPiecewiseFunction gpwf = vtkPiecewiseFunction.New(); reader.SetFileName(m_FileName); reader.Update(); // here we read the file actually // mapper vtkFixedPointVolumeRayCastMapper mapper = vtkFixedPointVolumeRayCastMapper.New(); mapper.SetInputConnection(reader.GetOutputPort()); // actor vtkActor actor = vtkActor.New(); //actor.SetMapper(mapper); actor.GetProperty().SetRepresentationToWireframe(); // add our actor to the renderer //Set the color curve for the volume ctf.AddHSVPoint(0, .67, .07, 1); ctf.AddHSVPoint(94, .67, .07, 1); ctf.AddHSVPoint(139, 0, 0, 0); ctf.AddHSVPoint(160, .28, .047, 1); ctf.AddHSVPoint(254, .38, .013, 1); //Set the opacity curve for the volume spwf.AddPoint(84, 0); spwf.AddPoint(151, .1); spwf.AddPoint(255, 1); //Set the gradient curve for the volume gpwf.AddPoint(0, .2); gpwf.AddPoint(10, .2); gpwf.AddPoint(25, 1); vol.GetProperty().SetColor(ctf); vol.GetProperty().SetScalarOpacity(spwf); vol.GetProperty().SetGradientOpacity(gpwf); vol.SetMapper(mapper); //Go through the Graphics Pipeline m_Renderer.AddVolume(vol); m_Renderer.ResetCamera(); //renderer.AddActor(actor); RenderSlicer(); }
/// <summary> /// Reads new preset, updating color and opacity function from it. /// </summary> /// <param name="presetName">Name of choosen preset.</param> public void ChangeColorAndOpacityFunction(PresetInformation PresetInfo) { vtkColorTransferFunction ctf = vtkColorTransferFunction.New(); vtkPiecewiseFunction spwf = vtkPiecewiseFunction.New(); if (PresetInfo != null) { foreach (var pair in PresetInfo.Series[0].OpacityFunction) { spwf.AddPoint(pair.Key, pair.Value); } foreach (var pair in PresetInfo.Series[0].ColorFuction) { ctf.AddRGBSegment(pair.Key, pair.Value[0].R, pair.Value[0].G, pair.Value[0].B, pair.Key, pair.Value[1].R, pair.Value[1].G, pair.Value[1].B); } ctf.SetScaleToLinear(); _volume.GetProperty().SetColor(ctf); _volume.GetProperty().SetScalarOpacity(spwf); _currentSerieNumber = 0; Update3DVisualization(); } }
/// <summary> /// Reads new preset, updating color and opacity function from it. /// </summary> /// <param name="presetName">Name of choosen preset.</param> public void ChangeColorAndOpacityFunction(string presetName) { vtkColorTransferFunction ctf = vtkColorTransferFunction.New(); vtkPiecewiseFunction spwf = vtkPiecewiseFunction.New(); PresetInfo = PresetReader.ReadXmlFile(presetName); _chart.Series["OpacityFunction"].Points.Clear(); _chart.Series["OpacityFunctionSpline"].Points.Clear(); foreach (var pair in PresetInfo.Series[0].OpacityFunction) { spwf.AddPoint(pair.Key, pair.Value); _chart.Series["OpacityFunction"].Points.AddXY(pair.Key, pair.Value); _chart.Series["OpacityFunctionSpline"].Points.AddXY(pair.Key, pair.Value); } foreach (var pair in PresetInfo.Series[0].ColorFuction) { ctf.AddRGBSegment(pair.Key, pair.Value[0].R, pair.Value[0].G, pair.Value[0].B, pair.Key, pair.Value[1].R, pair.Value[1].G, pair.Value[1].B); //Color colorRight = Color.FromArgb((int)pair.Value[1].R, (int)pair.Value[1].G, (int)pair.Value[1].B); //Color colorLeft = Color.FromArgb((int)pair.Value[0].R, (int)pair.Value[0].G, (int)pair.Value[0].B); } ctf.SetScaleToLinear(); _volume.GetProperty().SetColor(ctf); _volume.GetProperty().SetScalarOpacity(spwf); _currentSerieNumber = 0; }
private void setOpacityFunction() { spwf = vtkPiecewiseFunction.New(); //Set the opacity curve for the volume spwf.AddPoint(this.windowLevel - (this.windowWidth / 2), 0); spwf.AddPoint(this.windowLevel, 1); spwf.AddPoint(this.windowLevel + (this.windowWidth / 2), 0); vol.GetProperty().SetScalarOpacity(spwf); }
/// <summary> /// Set the gradient function for the volume. /// </summary> private void SetGradientOpacity() { vtkPiecewiseFunction gpwf = vtkPiecewiseFunction.New(); //Set the gradient curve for the volume gpwf.AddPoint(0, .2); gpwf.AddPoint(10, .2); gpwf.AddPoint(25, 1); _volume.GetProperty().SetGradientOpacity(gpwf); }
public void updateChartSpline(List <DataPoint> splinePoints) { vtkPiecewiseFunction spwf = vtkPiecewiseFunction.New(); chart1.Series["OpacityFunctionSpline"].Points.Clear(); foreach (DataPoint point in splinePoints) { spwf.AddPoint(point.XValue, point.YValues[0]); chart1.Series["OpacityFunctionSpline"].Points.AddXY(point.XValue, point.YValues[0]); } }
/// <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(); }
public void changeOpacityFunction(String presetName) { spwf = vtkPiecewiseFunction.New(); Dictionary <float, float> values = presetMapper.changeOpacityFunction(presetName); foreach (var pair in values) { spwf.AddPoint(pair.Key, pair.Value); } vol.GetProperty().SetScalarOpacity(spwf); }
//切片模式_初始化颜色 private void InitializeColor_Slice(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_PiecewiseFunction = vtkPiecewiseFunction.New(); m_PiecewiseFunction.AddPoint(Grid.Min, 1); m_PiecewiseFunction.AddPoint(Grid.Max, 1); }
/// <summary> /// Updates opacity function, when new points are added. /// </summary> /// <param name="splinePoints">List of new points</param> public void ChangeSplineFunction(List <DataPoint> splinePoints) { vtkPiecewiseFunction spwf = vtkPiecewiseFunction.New(); foreach (DataPoint point in splinePoints) { spwf.AddPoint(point.XValue, point.YValues[0]); } _volume.GetProperty().SetScalarOpacity(spwf); _window.Validate(); _window.Update(); _window.RenderWindow.Render(); }
//updatatuje okno wziualizacji 3d public void update3DVisualization(float windowLevel, float windowWidth) { this.windowLevel = windowLevel; this.windowWidth = windowWidth; spwf = vtkPiecewiseFunction.New(); spwf.AddPoint(this.windowLevel - (this.windowWidth / 2), 0); spwf.AddPoint(this.windowLevel, 1); spwf.AddPoint(this.windowLevel + (this.windowWidth / 2), 0); vol.GetProperty().SetScalarOpacity(spwf); window.Validate(); window.Update(); window.RenderWindow.Render(); }
/// <summary> /// Changes the opacity function to another serie from preset. /// </summary> /// <param name="numberOfSerie">Number of serie to update.</param> public void ChangeToSerie(PresetInformation PresetInfo, int numberOfSerie) { vtkPiecewiseFunction spwf = vtkPiecewiseFunction.New(); foreach (var pair in PresetInfo.Series[numberOfSerie].OpacityFunction) { spwf.AddPoint(pair.Key, pair.Value); } _volume.GetProperty().SetScalarOpacity(spwf); _window.Validate(); _window.Update(); _window.RenderWindow.Render(); _currentSerieNumber = numberOfSerie; }
private vtkProp CreateVolumeRendering() { _opacityTransferFunction = new vtkPiecewiseFunction(); _opacityTransferFunction.ClampingOff(); _colorTransferFunction = new vtkColorTransferFunction(); _colorTransferFunction.SetColorSpaceToRGB(); _colorTransferFunction.ClampingOff(); SetOpacityTransferFunction(); SetColorTransferFunction(); vtkVolumeProperty volumeProperty = new vtkVolumeProperty(); volumeProperty.ShadeOn(); volumeProperty.SetInterpolationTypeToLinear(); volumeProperty.SetColor(_colorTransferFunction); volumeProperty.SetScalarOpacity(_opacityTransferFunction); volumeProperty.SetDiffuse(0.7); volumeProperty.SetAmbient(0.1); volumeProperty.SetSpecular(.3); volumeProperty.SetSpecularPower(20); //vtkOpenGLVolumeTextureMapper2D volumeMapper = new vtkOpenGLVolumeTextureMapper2D(); //vtkOpenGLVolumeTextureMapper3D volumeMapper = new vtkOpenGLVolumeTextureMapper3D(); //volumeMapper.SetPreferredMethodToNVidia(); //volumeMapper.SetSampleDistance(1.0f); //int supported = volumeMapper.IsRenderSupported(volumeProperty); vtkFixedPointVolumeRayCastMapper volumeMapper = new vtkFixedPointVolumeRayCastMapper(); //vtkVolumeRayCastMapper volumeMapper = new vtkVolumeRayCastMapper(); volumeMapper.SetInput(_volumeLayer.GetImageData()); ////vtkVolumeRayCastCompositeFunction rayCastFunction = new vtkVolumeRayCastCompositeFunction(); ////volumeMapper.SetVolumeRayCastFunction(rayCastFunction); //vtkVolumeRayCastIsosurfaceFunction rayCastFunction = new vtkVolumeRayCastIsosurfaceFunction(); //volumeMapper.SetVolumeRayCastFunction(rayCastFunction); _vtkVolume = new vtkVolume(); _vtkVolume.SetMapper(volumeMapper); _vtkVolume.SetProperty(volumeProperty); return(_vtkVolume); }
/// <summary> /// Display the render window with the 3D Volume in it /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void renderWindowControl2_Load(object sender, EventArgs e) { //Create all the objects for the pipeline vtkRenderer renderer = renderWindowControl2.RenderWindow.GetRenderers().GetFirstRenderer(); vtkXMLImageDataReader reader = vtkXMLImageDataReader.New(); vtkFixedPointVolumeRayCastMapper texMapper = vtkFixedPointVolumeRayCastMapper.New(); vtkVolume vol = vtkVolume.New(); vtkColorTransferFunction ctf = vtkColorTransferFunction.New(); vtkPiecewiseFunction spwf = vtkPiecewiseFunction.New(); vtkPiecewiseFunction gpwf = vtkPiecewiseFunction.New(); //Read in the file reader.SetFileName(fileName); reader.Update(); //Go through the visulizatin pipeline texMapper.SetInputConnection(reader.GetOutputPort()); //Set the color curve for the volume ctf.AddHSVPoint(0, .67, .07, 1); ctf.AddHSVPoint(94, .67, .07, 1); ctf.AddHSVPoint(139, 0, 0, 0); ctf.AddHSVPoint(160, .28, .047, 1); ctf.AddHSVPoint(254, .38, .013, 1); //Set the opacity curve for the volume spwf.AddPoint(84, 0); spwf.AddPoint(151, .1); spwf.AddPoint(255, 1); //Set the gradient curve for the volume gpwf.AddPoint(0, .2); gpwf.AddPoint(10, .2); gpwf.AddPoint(25, 1); vol.GetProperty().SetColor(ctf); vol.GetProperty().SetScalarOpacity(spwf); vol.GetProperty().SetGradientOpacity(gpwf); vol.SetMapper(texMapper); //Go through the Graphics Pipeline renderer.AddVolume(vol); }
//镂空模式_初始化颜色 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); } } }
private vtkProp CreateVolumeRendering() { _opacityTransferFunction = new vtkPiecewiseFunction(); _opacityTransferFunction.ClampingOff(); _colorTransferFunction = new vtkColorTransferFunction(); _colorTransferFunction.SetColorSpaceToRGB(); _colorTransferFunction.ClampingOff(); SetOpacityTransferFunction(); SetColorTransferFunction(); vtkVolumeProperty volumeProperty = new vtkVolumeProperty(); volumeProperty.ShadeOn(); volumeProperty.SetInterpolationTypeToLinear(); volumeProperty.SetColor(_colorTransferFunction); volumeProperty.SetScalarOpacity(_opacityTransferFunction); volumeProperty.SetDiffuse(0.7); volumeProperty.SetAmbient(0.1); volumeProperty.SetSpecular(.3); volumeProperty.SetSpecularPower(20); //vtkOpenGLVolumeTextureMapper2D volumeMapper = new vtkOpenGLVolumeTextureMapper2D(); //vtkOpenGLVolumeTextureMapper3D volumeMapper = new vtkOpenGLVolumeTextureMapper3D(); //volumeMapper.SetPreferredMethodToNVidia(); //volumeMapper.SetSampleDistance(1.0f); //int supported = volumeMapper.IsRenderSupported(volumeProperty); vtkFixedPointVolumeRayCastMapper volumeMapper = new vtkFixedPointVolumeRayCastMapper(); //vtkVolumeRayCastMapper volumeMapper = new vtkVolumeRayCastMapper(); volumeMapper.SetInput(_volumeLayer.GetImageData()); ////vtkVolumeRayCastCompositeFunction rayCastFunction = new vtkVolumeRayCastCompositeFunction(); ////volumeMapper.SetVolumeRayCastFunction(rayCastFunction); //vtkVolumeRayCastIsosurfaceFunction rayCastFunction = new vtkVolumeRayCastIsosurfaceFunction(); //volumeMapper.SetVolumeRayCastFunction(rayCastFunction); _vtkVolume = new vtkVolume(); _vtkVolume.SetMapper(volumeMapper); _vtkVolume.SetProperty(volumeProperty); return _vtkVolume; }
//普通模式_初始化颜色 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); }
/// <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(); } }
///<summary> A Set Method for Static Variables </summary> public static void Setgop(vtkPiecewiseFunction toSet) { gop = toSet; }
///<summary> A Set Method for Static Variables </summary> public static void Setgop(vtkPiecewiseFunction toSet) { gop = toSet; }
///<summary> A Set Method for Static Variables </summary> public static void Setsurface(vtkPiecewiseFunction toSet) { surface = toSet; }
///<summary> A Set Method for Static Variables </summary> public static void SetrampPoint2(vtkPiecewiseFunction toSet) { rampPoint2 = toSet; }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVcursor3D(String [] argv) { //Prefix Content is: "" // This little example shows how a cursor can be created in [] // image viewers, and renderers. The standard TkImageViewerWidget and[] // TkRenderWidget bindings are used. There is a new binding:[] // middle button in the image viewer sets the position of the cursor. [] // First we include the VTK Tcl packages which will make available [] // all of the vtk commands to Tcl[] // Global values[] CURSOR_X = 20; CURSOR_Y = 20; CURSOR_Z = 20; IMAGE_MAG_X = 4; IMAGE_MAG_Y = 4; IMAGE_MAG_Z = 1; // Pipeline stuff[] reader = new vtkSLCReader(); reader.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/neghip.slc"); // Cursor stuff[] magnify = new vtkImageMagnify(); magnify.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort()); magnify.SetMagnificationFactors((int)IMAGE_MAG_X,(int)IMAGE_MAG_Y,(int)IMAGE_MAG_Z); image_cursor = new vtkImageCursor3D(); image_cursor.SetInputConnection((vtkAlgorithmOutput)magnify.GetOutputPort()); image_cursor.SetCursorPosition((double)CURSOR_X*IMAGE_MAG_X,(double)CURSOR_Y*IMAGE_MAG_Y,(double)CURSOR_Z*IMAGE_MAG_Z); image_cursor.SetCursorValue((double)255); image_cursor.SetCursorRadius((int)50*IMAGE_MAG_X); axes = new vtkAxes(); axes.SymmetricOn(); axes.SetOrigin((double)CURSOR_X,(double)CURSOR_Y,(double)CURSOR_Z); axes.SetScaleFactor((double)50.0); axes_mapper = vtkPolyDataMapper.New(); axes_mapper.SetInputConnection((vtkAlgorithmOutput)axes.GetOutputPort()); axesActor = new vtkActor(); axesActor.SetMapper((vtkMapper)axes_mapper); axesActor.GetProperty().SetAmbient((double)0.5); // Image viewer stuff[] viewer = new vtkImageViewer(); viewer.SetInputConnection((vtkAlgorithmOutput)image_cursor.GetOutputPort()); viewer.SetZSlice((int)CURSOR_Z*IMAGE_MAG_Z); viewer.SetColorWindow((double)256); viewer.SetColorLevel((double)128); //method moved //method moved //method moved // Create transfer functions for opacity and color[] opacity_transfer_function = new vtkPiecewiseFunction(); opacity_transfer_function.AddPoint((double)20,(double)0.0); opacity_transfer_function.AddPoint((double)255,(double)0.2); color_transfer_function = new vtkColorTransferFunction(); color_transfer_function.AddRGBPoint((double)0,(double)0,(double)0,(double)0); color_transfer_function.AddRGBPoint((double)64,(double)1,(double)0,(double)0); color_transfer_function.AddRGBPoint((double)128,(double)0,(double)0,(double)1); color_transfer_function.AddRGBPoint((double)192,(double)0,(double)1,(double)0); color_transfer_function.AddRGBPoint((double)255,(double)0,(double).2,(double)0); // Create properties, mappers, volume actors, and ray cast function[] volume_property = new vtkVolumeProperty(); volume_property.SetColor((vtkColorTransferFunction)color_transfer_function); volume_property.SetScalarOpacity((vtkPiecewiseFunction)opacity_transfer_function); composite_function = new vtkVolumeRayCastCompositeFunction(); volume_mapper = new vtkVolumeRayCastMapper(); volume_mapper.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort()); volume_mapper.SetVolumeRayCastFunction((vtkVolumeRayCastFunction)composite_function); volume = new vtkVolume(); volume.SetMapper((vtkAbstractVolumeMapper)volume_mapper); volume.SetProperty((vtkVolumeProperty)volume_property); // Create outline[] outline = new vtkOutlineFilter(); outline.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort()); outline_mapper = vtkPolyDataMapper.New(); outline_mapper.SetInputConnection((vtkAlgorithmOutput)outline.GetOutputPort()); outlineActor = new vtkActor(); outlineActor.SetMapper((vtkMapper)outline_mapper); outlineActor.GetProperty().SetColor((double)1,(double)1,(double)1); // Create the renderer[] ren1 = vtkRenderer.New(); ren1.AddActor((vtkProp)axesActor); ren1.AddVolume((vtkProp)volume); ren1.SetBackground((double)0.1,(double)0.2,(double)0.4); renWin2 = vtkRenderWindow.New(); renWin2.AddRenderer((vtkRenderer)ren1); renWin2.SetSize((int)256,(int)256); // Create the GUI: two renderer widgets and a quit button[] //tk window skipped.. // Set the window manager (wm command) so that it registers a[] // command to handle the WM_DELETE_WINDOW protocal request. This[] // request is triggered when the widget is closed using the standard[] // window manager icons or buttons. In this case the exit callback[] // will be called and it will free up any objects we created then exit[] // the application.[] // Help label, frame and quit button[] //tk window skipped.. //tk window skipped.. //tk window skipped.. //deleteAllVTKObjects(); }
///<summary> A Set Method for Static Variables </summary> public static void Setramp1(vtkPiecewiseFunction toSet) { ramp1 = toSet; }
///<summary> A Set Method for Static Variables </summary> public static void SetrampPoint2(vtkPiecewiseFunction toSet) { rampPoint2 = toSet; }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVgaussian(String [] argv) { //Prefix Content is: "" ren1 = vtkRenderer.New(); renWin = vtkRenderWindow.New(); renWin.SetMultiSamples(0); renWin.AddRenderer((vtkRenderer)ren1); renWin.SetSize((int)300, (int)300); iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); camera = new vtkCamera(); camera.ParallelProjectionOn(); camera.SetViewUp((double)0, (double)1, (double)0); camera.SetFocalPoint((double)12, (double)10.5, (double)15); camera.SetPosition((double)-70, (double)15, (double)34); camera.ComputeViewPlaneNormal(); ren1.SetActiveCamera((vtkCamera)camera); // Create the reader for the data[] //vtkStructuredPointsReader reader[] reader = new vtkGaussianCubeReader(); reader.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/m4_TotalDensity.cube"); reader.SetHBScale((double)1.1); reader.SetBScale((double)10); reader.Update(); range = reader.GetGridOutput().GetPointData().GetScalars().GetRange(); min = (double)(lindex(range, 0)); max = (double)(lindex(range, 1)); readerSS = new vtkImageShiftScale(); readerSS.SetInputData((vtkDataObject)reader.GetGridOutput()); readerSS.SetShift((double)min * -1); readerSS.SetScale((double)255 / (max - min)); readerSS.SetOutputScalarTypeToUnsignedChar(); bounds = new vtkOutlineFilter(); bounds.SetInputData((vtkDataObject)reader.GetGridOutput()); boundsMapper = vtkPolyDataMapper.New(); boundsMapper.SetInputConnection((vtkAlgorithmOutput)bounds.GetOutputPort()); boundsActor = new vtkActor(); boundsActor.SetMapper((vtkMapper)boundsMapper); boundsActor.GetProperty().SetColor((double)0, (double)0, (double)0); contour = new vtkContourFilter(); contour.SetInputData((vtkDataObject)reader.GetGridOutput()); contour.GenerateValues((int)5, (double)0, (double).05); contourMapper = vtkPolyDataMapper.New(); contourMapper.SetInputConnection((vtkAlgorithmOutput)contour.GetOutputPort()); contourMapper.SetScalarRange((double)0, (double).1); ((vtkLookupTable)contourMapper.GetLookupTable()).SetHueRange(0.32, 0); contourActor = new vtkActor(); contourActor.SetMapper((vtkMapper)contourMapper); contourActor.GetProperty().SetOpacity((double).5); // Create transfer mapping scalar value to opacity[] opacityTransferFunction = new vtkPiecewiseFunction(); opacityTransferFunction.AddPoint((double)0, (double)0.01); opacityTransferFunction.AddPoint((double)255, (double)0.35); opacityTransferFunction.ClampingOn(); // Create transfer mapping scalar value to color[] colorTransferFunction = new vtkColorTransferFunction(); colorTransferFunction.AddHSVPoint((double)0.0, (double)0.66, (double)1.0, (double)1.0); colorTransferFunction.AddHSVPoint((double)50.0, (double)0.33, (double)1.0, (double)1.0); colorTransferFunction.AddHSVPoint((double)100.0, (double)0.00, (double)1.0, (double)1.0); // The property describes how the data will look[] volumeProperty = new vtkVolumeProperty(); volumeProperty.SetColor((vtkColorTransferFunction)colorTransferFunction); volumeProperty.SetScalarOpacity((vtkPiecewiseFunction)opacityTransferFunction); volumeProperty.SetInterpolationTypeToLinear(); // The mapper / ray cast function know how to render the data[] compositeFunction = new vtkVolumeRayCastCompositeFunction(); volumeMapper = new vtkVolumeRayCastMapper(); //vtkVolumeTextureMapper2D volumeMapper[] volumeMapper.SetVolumeRayCastFunction((vtkVolumeRayCastFunction)compositeFunction); volumeMapper.SetInputConnection((vtkAlgorithmOutput)readerSS.GetOutputPort()); // The volume holds the mapper and the property and[] // can be used to position/orient the volume[] volume = new vtkVolume(); volume.SetMapper((vtkAbstractVolumeMapper)volumeMapper); volume.SetProperty((vtkVolumeProperty)volumeProperty); ren1.AddVolume((vtkProp)volume); //ren1 AddActor contourActor[] ren1.AddActor((vtkProp)boundsActor); //#####################################################################[] Sphere = new vtkSphereSource(); Sphere.SetCenter((double)0, (double)0, (double)0); Sphere.SetRadius((double)1); Sphere.SetThetaResolution((int)16); Sphere.SetStartTheta((double)0); Sphere.SetEndTheta((double)360); Sphere.SetPhiResolution((int)16); Sphere.SetStartPhi((double)0); Sphere.SetEndPhi((double)180); Glyph = new vtkGlyph3D(); Glyph.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort()); Glyph.SetOrient((int)1); Glyph.SetColorMode((int)1); //Glyph ScalingOn[] Glyph.SetScaleMode((int)2); Glyph.SetScaleFactor((double).6); Glyph.SetSourceConnection(Sphere.GetOutputPort()); AtomsMapper = vtkPolyDataMapper.New(); AtomsMapper.SetInputConnection((vtkAlgorithmOutput)Glyph.GetOutputPort()); AtomsMapper.SetImmediateModeRendering((int)1); AtomsMapper.UseLookupTableScalarRangeOff(); AtomsMapper.SetScalarVisibility((int)1); AtomsMapper.SetScalarModeToDefault(); Atoms = new vtkActor(); Atoms.SetMapper((vtkMapper)AtomsMapper); Atoms.GetProperty().SetRepresentationToSurface(); Atoms.GetProperty().SetInterpolationToGouraud(); Atoms.GetProperty().SetAmbient((double)0.15); Atoms.GetProperty().SetDiffuse((double)0.85); Atoms.GetProperty().SetSpecular((double)0.1); Atoms.GetProperty().SetSpecularPower((double)100); Atoms.GetProperty().SetSpecularColor((double)1, (double)1, (double)1); Atoms.GetProperty().SetColor((double)1, (double)1, (double)1); Tube = new vtkTubeFilter(); Tube.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort()); Tube.SetNumberOfSides((int)16); Tube.SetCapping((int)0); Tube.SetRadius((double)0.2); Tube.SetVaryRadius((int)0); Tube.SetRadiusFactor((double)10); BondsMapper = vtkPolyDataMapper.New(); BondsMapper.SetInputConnection((vtkAlgorithmOutput)Tube.GetOutputPort()); BondsMapper.SetImmediateModeRendering((int)1); BondsMapper.UseLookupTableScalarRangeOff(); BondsMapper.SetScalarVisibility((int)1); BondsMapper.SetScalarModeToDefault(); Bonds = new vtkActor(); Bonds.SetMapper((vtkMapper)BondsMapper); Bonds.GetProperty().SetRepresentationToSurface(); Bonds.GetProperty().SetInterpolationToGouraud(); Bonds.GetProperty().SetAmbient((double)0.15); Bonds.GetProperty().SetDiffuse((double)0.85); Bonds.GetProperty().SetSpecular((double)0.1); Bonds.GetProperty().SetSpecularPower((double)100); Bonds.GetProperty().SetSpecularColor((double)1, (double)1, (double)1); Bonds.GetProperty().SetColor((double)1, (double)1, (double)1); ren1.AddActor((vtkProp)Bonds); ren1.AddActor((vtkProp)Atoms); //###################################################[] ren1.SetBackground((double)1, (double)1, (double)1); ren1.ResetCamera(); renWin.Render(); //method moved renWin.AbortCheckEvt += new Kitware.VTK.vtkObject.vtkObjectEventHandler(TkCheckAbort_Command.Execute); iren.Initialize(); //deleteAllVTKObjects(); }
///<summary> A Set Method for Static Variables </summary> public static void Setconstant1(vtkPiecewiseFunction toSet) { constant1 = toSet; }
///<summary> A Set Method for Static Variables </summary> public static void Setsurface(vtkPiecewiseFunction toSet) { surface = toSet; }
public void changeOpacityFunction(String presetName) { spwf = vtkPiecewiseFunction.New(); Dictionary<float, float> values = presetMapper.changeOpacityFunction(presetName); foreach (var pair in values) { spwf.AddPoint(pair.Key, pair.Value); } vol.GetProperty().SetScalarOpacity(spwf); }
//updatatuje okno wziualizacji 3d public void update3DVisualization(float windowLevel, float windowWidth) { this.windowLevel = windowLevel; this.windowWidth = windowWidth; spwf = vtkPiecewiseFunction.New(); spwf.AddPoint(this.windowLevel - (this.windowWidth / 2), 0); spwf.AddPoint(this.windowLevel, 1); spwf.AddPoint(this.windowLevel + (this.windowWidth / 2), 0); vol.GetProperty().SetScalarOpacity(spwf); window.Validate(); window.Update(); window.RenderWindow.Render(); }
///<summary> A Set Method for Static Variables </summary> public static void Setopacity_transfer_function(vtkPiecewiseFunction toSet) { opacity_transfer_function = toSet; }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVcursor3D(String [] argv) { //Prefix Content is: "" // This little example shows how a cursor can be created in [] // image viewers, and renderers. The standard TkImageViewerWidget and[] // TkRenderWidget bindings are used. There is a new binding:[] // middle button in the image viewer sets the position of the cursor. [] // First we include the VTK Tcl packages which will make available [] // all of the vtk commands to Tcl[] // Global values[] CURSOR_X = 20; CURSOR_Y = 20; CURSOR_Z = 20; IMAGE_MAG_X = 4; IMAGE_MAG_Y = 4; IMAGE_MAG_Z = 1; // Pipeline stuff[] reader = new vtkSLCReader(); reader.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/neghip.slc"); // Cursor stuff[] magnify = new vtkImageMagnify(); magnify.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort()); magnify.SetMagnificationFactors((int)IMAGE_MAG_X, (int)IMAGE_MAG_Y, (int)IMAGE_MAG_Z); image_cursor = new vtkImageCursor3D(); image_cursor.SetInputConnection((vtkAlgorithmOutput)magnify.GetOutputPort()); image_cursor.SetCursorPosition((double)CURSOR_X * IMAGE_MAG_X, (double)CURSOR_Y * IMAGE_MAG_Y, (double)CURSOR_Z * IMAGE_MAG_Z); image_cursor.SetCursorValue((double)255); image_cursor.SetCursorRadius((int)50 * IMAGE_MAG_X); axes = new vtkAxes(); axes.SymmetricOn(); axes.SetOrigin((double)CURSOR_X, (double)CURSOR_Y, (double)CURSOR_Z); axes.SetScaleFactor((double)50.0); axes_mapper = vtkPolyDataMapper.New(); axes_mapper.SetInputConnection((vtkAlgorithmOutput)axes.GetOutputPort()); axesActor = new vtkActor(); axesActor.SetMapper((vtkMapper)axes_mapper); axesActor.GetProperty().SetAmbient((double)0.5); // Image viewer stuff[] viewer = new vtkImageViewer(); viewer.SetInputConnection((vtkAlgorithmOutput)image_cursor.GetOutputPort()); viewer.SetZSlice((int)CURSOR_Z * IMAGE_MAG_Z); viewer.SetColorWindow((double)256); viewer.SetColorLevel((double)128); //method moved //method moved //method moved // Create transfer functions for opacity and color[] opacity_transfer_function = new vtkPiecewiseFunction(); opacity_transfer_function.AddPoint((double)20, (double)0.0); opacity_transfer_function.AddPoint((double)255, (double)0.2); color_transfer_function = new vtkColorTransferFunction(); color_transfer_function.AddRGBPoint((double)0, (double)0, (double)0, (double)0); color_transfer_function.AddRGBPoint((double)64, (double)1, (double)0, (double)0); color_transfer_function.AddRGBPoint((double)128, (double)0, (double)0, (double)1); color_transfer_function.AddRGBPoint((double)192, (double)0, (double)1, (double)0); color_transfer_function.AddRGBPoint((double)255, (double)0, (double).2, (double)0); // Create properties, mappers, volume actors, and ray cast function[] volume_property = new vtkVolumeProperty(); volume_property.SetColor((vtkColorTransferFunction)color_transfer_function); volume_property.SetScalarOpacity((vtkPiecewiseFunction)opacity_transfer_function); composite_function = new vtkVolumeRayCastCompositeFunction(); volume_mapper = new vtkVolumeRayCastMapper(); volume_mapper.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort()); volume_mapper.SetVolumeRayCastFunction((vtkVolumeRayCastFunction)composite_function); volume = new vtkVolume(); volume.SetMapper((vtkAbstractVolumeMapper)volume_mapper); volume.SetProperty((vtkVolumeProperty)volume_property); // Create outline[] outline = new vtkOutlineFilter(); outline.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort()); outline_mapper = vtkPolyDataMapper.New(); outline_mapper.SetInputConnection((vtkAlgorithmOutput)outline.GetOutputPort()); outlineActor = new vtkActor(); outlineActor.SetMapper((vtkMapper)outline_mapper); outlineActor.GetProperty().SetColor((double)1, (double)1, (double)1); // Create the renderer[] ren1 = vtkRenderer.New(); ren1.AddActor((vtkProp)axesActor); ren1.AddVolume((vtkProp)volume); ren1.SetBackground((double)0.1, (double)0.2, (double)0.4); renWin2 = vtkRenderWindow.New(); renWin2.AddRenderer((vtkRenderer)ren1); renWin2.SetSize((int)256, (int)256); // Create the GUI: two renderer widgets and a quit button[] //tk window skipped.. // Set the window manager (wm command) so that it registers a[] // command to handle the WM_DELETE_WINDOW protocal request. This[] // request is triggered when the widget is closed using the standard[] // window manager icons or buttons. In this case the exit callback[] // will be called and it will free up any objects we created then exit[] // the application.[] // Help label, frame and quit button[] //tk window skipped.. //tk window skipped.. //tk window skipped.. //deleteAllVTKObjects(); }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVTestFixedPointRayCasterNearest(String [] argv) { //Prefix Content is: "" // Create a gaussian[] gs = new vtkImageGaussianSource(); gs.SetWholeExtent((int)0, (int)30, (int)0, (int)30, (int)0, (int)30); gs.SetMaximum((double)255.0); gs.SetStandardDeviation((double)5); gs.SetCenter((double)15, (double)15, (double)15); // threshold to leave a gap that should show up for[] // gradient opacity[] t = new vtkImageThreshold(); t.SetInputConnection((vtkAlgorithmOutput)gs.GetOutputPort()); t.ReplaceInOn(); t.SetInValue((double)0); t.ThresholdBetween((double)150, (double)200); // Use a shift scale to convert to unsigned char[] ss = new vtkImageShiftScale(); ss.SetInputConnection((vtkAlgorithmOutput)t.GetOutputPort()); ss.SetOutputScalarTypeToUnsignedChar(); // grid will be used for two component dependent[] grid0 = new vtkImageGridSource(); grid0.SetDataScalarTypeToUnsignedChar(); grid0.SetGridSpacing((int)10, (int)10, (int)10); grid0.SetLineValue((double)200); grid0.SetFillValue((double)10); grid0.SetDataExtent((int)0, (int)30, (int)0, (int)30, (int)0, (int)30); // use dilation to thicken the grid[] d = new vtkImageContinuousDilate3D(); d.SetInputConnection((vtkAlgorithmOutput)grid0.GetOutputPort()); d.SetKernelSize((int)3, (int)3, (int)3); // Now make a two component dependent[] iac = new vtkImageAppendComponents(); iac.AddInputConnection(d.GetOutputPort()); iac.AddInputConnection(ss.GetOutputPort()); // Some more gaussians for the four component indepent case[] gs1 = new vtkImageGaussianSource(); gs1.SetWholeExtent((int)0, (int)30, (int)0, (int)30, (int)0, (int)30); gs1.SetMaximum((double)255.0); gs1.SetStandardDeviation((double)4); gs1.SetCenter((double)5, (double)5, (double)5); t1 = new vtkImageThreshold(); t1.SetInputConnection((vtkAlgorithmOutput)gs1.GetOutputPort()); t1.ReplaceInOn(); t1.SetInValue((double)0); t1.ThresholdBetween((double)150, (double)256); gs2 = new vtkImageGaussianSource(); gs2.SetWholeExtent((int)0, (int)30, (int)0, (int)30, (int)0, (int)30); gs2.SetMaximum((double)255.0); gs2.SetStandardDeviation((double)4); gs2.SetCenter((double)12, (double)12, (double)12); gs3 = new vtkImageGaussianSource(); gs3.SetWholeExtent((int)0, (int)30, (int)0, (int)30, (int)0, (int)30); gs3.SetMaximum((double)255.0); gs3.SetStandardDeviation((double)4); gs3.SetCenter((double)19, (double)19, (double)19); t3 = new vtkImageThreshold(); t3.SetInputConnection((vtkAlgorithmOutput)gs3.GetOutputPort()); t3.ReplaceInOn(); t3.SetInValue((double)0); t3.ThresholdBetween((double)150, (double)256); gs4 = new vtkImageGaussianSource(); gs4.SetWholeExtent((int)0, (int)30, (int)0, (int)30, (int)0, (int)30); gs4.SetMaximum((double)255.0); gs4.SetStandardDeviation((double)4); gs4.SetCenter((double)26, (double)26, (double)26); //tk window skipped.. iac1 = new vtkImageAppendComponents(); iac1.AddInputConnection(t1.GetOutputPort()); iac1.AddInputConnection(gs2.GetOutputPort()); iac2 = new vtkImageAppendComponents(); iac2.AddInputConnection(iac1.GetOutputPort()); iac2.AddInputConnection(t3.GetOutputPort()); iac3 = new vtkImageAppendComponents(); iac3.AddInputConnection(iac2.GetOutputPort()); iac3.AddInputConnection(gs4.GetOutputPort()); // create the four component dependend - [] // use lines in x, y, z for colors[] gridR = new vtkImageGridSource(); gridR.SetDataScalarTypeToUnsignedChar(); gridR.SetGridSpacing((int)10, (int)100, (int)100); gridR.SetLineValue((double)250); gridR.SetFillValue((double)100); gridR.SetDataExtent((int)0, (int)30, (int)0, (int)30, (int)0, (int)30); dR = new vtkImageContinuousDilate3D(); dR.SetInputConnection((vtkAlgorithmOutput)gridR.GetOutputPort()); dR.SetKernelSize((int)2, (int)2, (int)2); gridG = new vtkImageGridSource(); gridG.SetDataScalarTypeToUnsignedChar(); gridG.SetGridSpacing((int)100, (int)10, (int)100); gridG.SetLineValue((double)250); gridG.SetFillValue((double)100); gridG.SetDataExtent((int)0, (int)30, (int)0, (int)30, (int)0, (int)30); dG = new vtkImageContinuousDilate3D(); dG.SetInputConnection((vtkAlgorithmOutput)gridG.GetOutputPort()); dG.SetKernelSize((int)2, (int)2, (int)2); gridB = new vtkImageGridSource(); gridB.SetDataScalarTypeToUnsignedChar(); gridB.SetGridSpacing((int)100, (int)100, (int)10); gridB.SetLineValue((double)0); gridB.SetFillValue((double)250); gridB.SetDataExtent((int)0, (int)30, (int)0, (int)30, (int)0, (int)30); dB = new vtkImageContinuousDilate3D(); dB.SetInputConnection((vtkAlgorithmOutput)gridB.GetOutputPort()); dB.SetKernelSize((int)2, (int)2, (int)2); // need some appending[] iacRG = new vtkImageAppendComponents(); iacRG.AddInputConnection(dR.GetOutputPort()); iacRG.AddInputConnection(dG.GetOutputPort()); iacRGB = new vtkImageAppendComponents(); iacRGB.AddInputConnection(iacRG.GetOutputPort()); iacRGB.AddInputConnection(dB.GetOutputPort()); iacRGBA = new vtkImageAppendComponents(); iacRGBA.AddInputConnection(iacRGB.GetOutputPort()); iacRGBA.AddInputConnection(ss.GetOutputPort()); // We need a bunch of opacity functions[] // this one is a simple ramp to .2[] rampPoint2 = new vtkPiecewiseFunction(); rampPoint2.AddPoint((double)0, (double)0.0); rampPoint2.AddPoint((double)255, (double)0.2); // this one is a simple ramp to 1[] ramp1 = new vtkPiecewiseFunction(); ramp1.AddPoint((double)0, (double)0.0); ramp1.AddPoint((double)255, (double)1.0); // this one shows a sharp surface[] surface = new vtkPiecewiseFunction(); surface.AddPoint((double)0, (double)0.0); surface.AddPoint((double)10, (double)0.0); surface.AddPoint((double)50, (double)1.0); surface.AddPoint((double)255, (double)1.0); // this one is constant 1[] constant1 = new vtkPiecewiseFunction(); constant1.AddPoint((double)0, (double)1.0); constant1.AddPoint((double)255, (double)1.0); // this one is used for gradient opacity[] gop = new vtkPiecewiseFunction(); gop.AddPoint((double)0, (double)0.0); gop.AddPoint((double)20, (double)0.0); gop.AddPoint((double)60, (double)1.0); gop.AddPoint((double)255, (double)1.0); // We need a bunch of color functions[] // This one is a simple rainbow[] rainbow = new vtkColorTransferFunction(); rainbow.SetColorSpaceToHSV(); rainbow.HSVWrapOff(); rainbow.AddHSVPoint((double)0, (double)0.1, (double)1.0, (double)1.0); rainbow.AddHSVPoint((double)255, (double)0.9, (double)1.0, (double)1.0); // this is constant red[] red = new vtkColorTransferFunction(); red.AddRGBPoint((double)0, (double)1, (double)0, (double)0); red.AddRGBPoint((double)255, (double)1, (double)0, (double)0); // this is constant green[] green = new vtkColorTransferFunction(); green.AddRGBPoint((double)0, (double)0, (double)1, (double)0); green.AddRGBPoint((double)255, (double)0, (double)1, (double)0); // this is constant blue[] blue = new vtkColorTransferFunction(); blue.AddRGBPoint((double)0, (double)0, (double)0, (double)1); blue.AddRGBPoint((double)255, (double)0, (double)0, (double)1); // this is constant yellow[] yellow = new vtkColorTransferFunction(); yellow.AddRGBPoint((double)0, (double)1, (double)1, (double)0); yellow.AddRGBPoint((double)255, (double)1, (double)1, (double)0); ren1 = vtkRenderer.New(); renWin = vtkRenderWindow.New(); renWin.AddRenderer((vtkRenderer)ren1); renWin.SetSize((int)500, (int)500); iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); ren1.GetCullers().InitTraversal(); culler = (vtkFrustumCoverageCuller)ren1.GetCullers().GetNextItem(); culler.SetSortingStyleToBackToFront(); // We need 25 mapper / actor pairs which we will render[] // in a grid. Going down we will vary the input data[] // with the top row unsigned char, then float, then[] // two dependent components, then four dependent components[] // then four independent components. Going across we[] // will vary the rendering method with MIP, Composite,[] // Composite Shade, Composite GO, and Composite GO Shade.[] j = 0; while ((j) < 5) { i = 0; while ((i) < 5) { volumeProperty[i, j] = new vtkVolumeProperty(); volumeMapper[i, j] = new vtkFixedPointVolumeRayCastMapper(); volumeMapper[i, j].SetSampleDistance((float)0.25); volume[i, j] = new vtkVolume(); volume[i, j].SetMapper((vtkAbstractVolumeMapper)volumeMapper[i, j]); volume[i, j].SetProperty((vtkVolumeProperty)volumeProperty[i, j]); volume[i, j].AddPosition((double)i * 30, (double)j * 30, (double)0); ren1.AddVolume((vtkProp)volume[i, j]); i = i + 1; } j = j + 1; } i = 0; while ((i) < 5) { volumeMapper[0, i].SetInputConnection(t.GetOutputPort()); volumeMapper[1, i].SetInputConnection(ss.GetOutputPort()); volumeMapper[2, i].SetInputConnection(iac.GetOutputPort()); volumeMapper[3, i].SetInputConnection(iac3.GetOutputPort()); volumeMapper[4, i].SetInputConnection(iacRGBA.GetOutputPort()); volumeMapper[i, 0].SetBlendModeToMaximumIntensity(); volumeMapper[i, 1].SetBlendModeToComposite(); volumeMapper[i, 2].SetBlendModeToComposite(); volumeMapper[i, 3].SetBlendModeToComposite(); volumeMapper[i, 4].SetBlendModeToComposite(); volumeProperty[0, i].IndependentComponentsOn(); volumeProperty[1, i].IndependentComponentsOn(); volumeProperty[2, i].IndependentComponentsOff(); volumeProperty[3, i].IndependentComponentsOn(); volumeProperty[4, i].IndependentComponentsOff(); volumeProperty[0, i].SetColor(rainbow); volumeProperty[0, i].SetScalarOpacity(rampPoint2); volumeProperty[0, i].SetGradientOpacity(constant1); volumeProperty[1, i].SetColor(rainbow); volumeProperty[1, i].SetScalarOpacity(rampPoint2); volumeProperty[1, i].SetGradientOpacity(constant1); volumeProperty[2, i].SetColor(rainbow); volumeProperty[2, i].SetScalarOpacity(rampPoint2); volumeProperty[2, i].SetGradientOpacity(constant1); volumeProperty[3, i].SetColor(0, red); volumeProperty[3, i].SetColor(1, green); volumeProperty[3, i].SetColor(2, blue); volumeProperty[3, i].SetColor(3, yellow); volumeProperty[3, i].SetScalarOpacity(0, rampPoint2); volumeProperty[3, i].SetScalarOpacity(1, rampPoint2); volumeProperty[3, i].SetScalarOpacity(2, rampPoint2); volumeProperty[3, i].SetScalarOpacity(3, rampPoint2); volumeProperty[3, i].SetGradientOpacity(0, constant1); volumeProperty[3, i].SetGradientOpacity(1, constant1); volumeProperty[3, i].SetGradientOpacity(2, constant1); volumeProperty[3, i].SetGradientOpacity(3, constant1); volumeProperty[3, i].SetComponentWeight(0, 1); volumeProperty[3, i].SetComponentWeight(1, 1); volumeProperty[3, i].SetComponentWeight(2, 1); volumeProperty[3, i].SetComponentWeight(3, 1); volumeProperty[4, i].SetColor(rainbow); volumeProperty[4, i].SetScalarOpacity(rampPoint2); volumeProperty[4, i].SetGradientOpacity(constant1); volumeProperty[i, 2].ShadeOn(); volumeProperty[i, 4].ShadeOn((int)0); volumeProperty[i, 4].ShadeOn((int)1); volumeProperty[i, 4].ShadeOn((int)2); volumeProperty[i, 4].ShadeOn((int)3); i = i + 1; } volumeProperty[0, 0].SetScalarOpacity((vtkPiecewiseFunction)ramp1); volumeProperty[1, 0].SetScalarOpacity((vtkPiecewiseFunction)ramp1); volumeProperty[2, 0].SetScalarOpacity((vtkPiecewiseFunction)ramp1); volumeProperty[3, 0].SetScalarOpacity((int)0, (vtkPiecewiseFunction)surface); volumeProperty[3, 0].SetScalarOpacity((int)1, (vtkPiecewiseFunction)surface); volumeProperty[3, 0].SetScalarOpacity((int)2, (vtkPiecewiseFunction)surface); volumeProperty[3, 0].SetScalarOpacity((int)3, (vtkPiecewiseFunction)surface); volumeProperty[4, 0].SetScalarOpacity((vtkPiecewiseFunction)ramp1); volumeProperty[0, 2].SetScalarOpacity((vtkPiecewiseFunction)surface); volumeProperty[1, 2].SetScalarOpacity((vtkPiecewiseFunction)surface); volumeProperty[2, 2].SetScalarOpacity((vtkPiecewiseFunction)surface); volumeProperty[3, 2].SetScalarOpacity((int)0, (vtkPiecewiseFunction)surface); volumeProperty[3, 2].SetScalarOpacity((int)1, (vtkPiecewiseFunction)surface); volumeProperty[3, 2].SetScalarOpacity((int)2, (vtkPiecewiseFunction)surface); volumeProperty[3, 2].SetScalarOpacity((int)3, (vtkPiecewiseFunction)surface); volumeProperty[4, 2].SetScalarOpacity((vtkPiecewiseFunction)surface); volumeProperty[0, 4].SetScalarOpacity((vtkPiecewiseFunction)surface); volumeProperty[1, 4].SetScalarOpacity((vtkPiecewiseFunction)surface); volumeProperty[2, 4].SetScalarOpacity((vtkPiecewiseFunction)surface); volumeProperty[3, 4].SetScalarOpacity((int)0, (vtkPiecewiseFunction)surface); volumeProperty[3, 4].SetScalarOpacity((int)1, (vtkPiecewiseFunction)surface); volumeProperty[3, 4].SetScalarOpacity((int)2, (vtkPiecewiseFunction)surface); volumeProperty[3, 4].SetScalarOpacity((int)3, (vtkPiecewiseFunction)surface); volumeProperty[4, 4].SetScalarOpacity((vtkPiecewiseFunction)surface); volumeProperty[0, 3].SetGradientOpacity((vtkPiecewiseFunction)gop); volumeProperty[1, 3].SetGradientOpacity((vtkPiecewiseFunction)gop); volumeProperty[2, 3].SetGradientOpacity((vtkPiecewiseFunction)gop); volumeProperty[3, 3].SetGradientOpacity((int)0, (vtkPiecewiseFunction)gop); volumeProperty[3, 3].SetGradientOpacity((int)2, (vtkPiecewiseFunction)gop); volumeProperty[4, 3].SetGradientOpacity((vtkPiecewiseFunction)gop); volumeProperty[3, 3].SetScalarOpacity((int)0, (vtkPiecewiseFunction)ramp1); volumeProperty[3, 3].SetScalarOpacity((int)2, (vtkPiecewiseFunction)ramp1); volumeProperty[0, 4].SetGradientOpacity((vtkPiecewiseFunction)gop); volumeProperty[1, 4].SetGradientOpacity((vtkPiecewiseFunction)gop); volumeProperty[2, 4].SetGradientOpacity((vtkPiecewiseFunction)gop); volumeProperty[3, 4].SetGradientOpacity((int)0, (vtkPiecewiseFunction)gop); volumeProperty[3, 4].SetGradientOpacity((int)2, (vtkPiecewiseFunction)gop); volumeProperty[4, 4].SetGradientOpacity((vtkPiecewiseFunction)gop); renWin.Render(); ren1.GetActiveCamera().Dolly((double)1.3); ren1.GetActiveCamera().Azimuth((double)15); ren1.GetActiveCamera().Elevation((double)5); ren1.ResetCameraClippingRange(); iren.Initialize(); //deleteAllVTKObjects(); }
public void Coloring(int shft = 0) { //vtkFixedPointVolumeRayCastMapper texMapper = vtkFixedPointVolumeRayCastMapper.New(); vtkSmartVolumeMapper texMapper = vtkSmartVolumeMapper.New(); vol = vtkVolume.New(); vtkColorTransferFunction ctf = vtkColorTransferFunction.New(); vtkPiecewiseFunction spwf = vtkPiecewiseFunction.New(); vtkPiecewiseFunction gpwf = vtkPiecewiseFunction.New(); texMapper.SetInputConnection(reader3D.GetOutputPort()); //Set the color curve for the volume //ctf.AddHSVPoint(0, .67, .07, 1); //ctf.AddHSVPoint(94, .67, .07, 1); //ctf.AddHSVPoint(139, 0, 0, 0); //ctf.AddHSVPoint(160, .28, .047, 1); //ctf.AddHSVPoint(254, .38, .013, 1); ctf.AddRGBPoint(0.0, 0.0, 0.0, 0.0); ctf.AddRGBPoint(64.0, 1.0, 0.0, 0.0); ctf.AddRGBPoint(128.0, 0.0, 0.0, 1.0); ctf.AddRGBPoint(192.0, 0.0, 1.0, 0.0); ctf.AddRGBPoint(255.0, 0.0, 0.2, 0.0); //Set the opacity curve for the volume spwf.AddPoint(584 + shft, 0); spwf.AddPoint(651 + shft, .1); //spwf.AddPoint(255, 1); //spwf.AddPoint(4, 0); //spwf.AddPoint(51, .7); //spwf.AddPoint(155, 0.5); //spwf.AddPoint(255, 0.2); //spwf.AddPoint(1055, 0); //Set the gradient curve for the volume //gpwf.AddPoint(0, .2); gpwf.AddPoint(10, 1); gpwf.AddPoint(225, 0.5); gpwf.AddPoint(1235, 0.2); gpwf.AddPoint(3235, 0); vol.GetProperty().SetColor(ctf); vol.GetProperty().SetScalarOpacity(spwf); //vol.GetProperty().SetGradientOpacity(gpwf); vol.GetProperty().ShadeOn(); vol.GetProperty().SetInterpolationTypeToLinear(); vol.SetMapper(texMapper); //green background renderer3D.SetBackground(0.3, 0.6, 0.3); //Go through the Graphics Pipeline renderer3D.AddVolume(vol); renderWindow3D.Render(); }
///<summary> A Set Method for Static Variables </summary> public static void Setramp1(vtkPiecewiseFunction toSet) { ramp1 = toSet; }
private void setOpacityFunction() { spwf = vtkPiecewiseFunction.New(); //Set the opacity curve for the volume spwf.AddPoint(this.windowLevel - (this.windowWidth / 2), 0); spwf.AddPoint(this.windowLevel, 1); spwf.AddPoint(this.windowLevel + (this.windowWidth / 2), 0); vol.GetProperty().SetScalarOpacity(spwf); }
///<summary> A Set Method for Static Variables </summary> public static void Setconstant1(vtkPiecewiseFunction toSet) { constant1 = toSet; }
public cFeedBackMessage Run() { if (base.Start() == false) { base.FeedBackMessage.IsSucceed = false; return base.FeedBackMessage; } object _firstValue = base.ListProperties.FindByName("Max. Opacity"); double MaxOpacity = 0; if (_firstValue == null) { base.GenerateError("Max. Opacity not found !"); return base.FeedBackMessage; } try { cProperty TmpProp = (cProperty)_firstValue; MaxOpacity = (double)TmpProp.GetValue(); Input[1][1] = MaxOpacity; } catch (Exception) { base.GenerateError("Max. Opacity cast didn't work"); return base.FeedBackMessage; } object _ScdValue = base.ListProperties.FindByName("Min. Opacity"); double MinOpacity = 0; if (_ScdValue == null) { base.GenerateError("Min. Opacity not found !"); return base.FeedBackMessage; } try { cProperty TmpProp = (cProperty)_ScdValue; MinOpacity = (double)TmpProp.GetValue(); Input[0][1] = MaxOpacity; } catch (Exception) { base.GenerateError("Min. Opacity cast didn't work"); return base.FeedBackMessage; } ToReturn = vtkPiecewiseFunction.New(); for (int i = 0; i < this.Input[0].Count; i++) { ToReturn.AddPoint(this.Input[0][i], this.Input[1][i]); } // Here is the right way for accessing the parameters... // a little laborious, but that's the price to pay for a complete interface //object _firstValue = base.ListProperties.FindByName("First Paramater"); //double firstValue = 0; //if (_firstValue == null) //{ // base.GenerateError("First Paramater not found !"); // return base.FeedBackMessage; //} //try //{ // cProperty TmpProp = (cProperty)_firstValue; // firstValue = (double)TmpProp.GetValue(); //} //catch (Exception) //{ // base.GenerateError("First Paramater cast didn't work"); // return base.FeedBackMessage; //} //ToReturn = new cExtendedTable((int)firstValue, (int)firstValue, 0); base.End(); return FeedBackMessage; }
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); }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVTestFixedPointRayCasterNearest(String [] argv) { //Prefix Content is: "" // Create a gaussian[] gs = new vtkImageGaussianSource(); gs.SetWholeExtent((int)0,(int)30,(int)0,(int)30,(int)0,(int)30); gs.SetMaximum((double)255.0); gs.SetStandardDeviation((double)5); gs.SetCenter((double)15,(double)15,(double)15); // threshold to leave a gap that should show up for[] // gradient opacity[] t = new vtkImageThreshold(); t.SetInputConnection((vtkAlgorithmOutput)gs.GetOutputPort()); t.ReplaceInOn(); t.SetInValue((double)0); t.ThresholdBetween((double)150,(double)200); // Use a shift scale to convert to unsigned char[] ss = new vtkImageShiftScale(); ss.SetInputConnection((vtkAlgorithmOutput)t.GetOutputPort()); ss.SetOutputScalarTypeToUnsignedChar(); // grid will be used for two component dependent[] grid0 = new vtkImageGridSource(); grid0.SetDataScalarTypeToUnsignedChar(); grid0.SetGridSpacing((int)10,(int)10,(int)10); grid0.SetLineValue((double)200); grid0.SetFillValue((double)10); grid0.SetDataExtent((int)0,(int)30,(int)0,(int)30,(int)0,(int)30); // use dilation to thicken the grid[] d = new vtkImageContinuousDilate3D(); d.SetInputConnection((vtkAlgorithmOutput)grid0.GetOutputPort()); d.SetKernelSize((int)3,(int)3,(int)3); // Now make a two component dependent[] iac = new vtkImageAppendComponents(); iac.AddInput((vtkDataObject)d.GetOutput()); iac.AddInput((vtkDataObject)ss.GetOutput()); // Some more gaussians for the four component indepent case[] gs1 = new vtkImageGaussianSource(); gs1.SetWholeExtent((int)0,(int)30,(int)0,(int)30,(int)0,(int)30); gs1.SetMaximum((double)255.0); gs1.SetStandardDeviation((double)4); gs1.SetCenter((double)5,(double)5,(double)5); t1 = new vtkImageThreshold(); t1.SetInputConnection((vtkAlgorithmOutput)gs1.GetOutputPort()); t1.ReplaceInOn(); t1.SetInValue((double)0); t1.ThresholdBetween((double)150,(double)256); gs2 = new vtkImageGaussianSource(); gs2.SetWholeExtent((int)0,(int)30,(int)0,(int)30,(int)0,(int)30); gs2.SetMaximum((double)255.0); gs2.SetStandardDeviation((double)4); gs2.SetCenter((double)12,(double)12,(double)12); gs3 = new vtkImageGaussianSource(); gs3.SetWholeExtent((int)0,(int)30,(int)0,(int)30,(int)0,(int)30); gs3.SetMaximum((double)255.0); gs3.SetStandardDeviation((double)4); gs3.SetCenter((double)19,(double)19,(double)19); t3 = new vtkImageThreshold(); t3.SetInputConnection((vtkAlgorithmOutput)gs3.GetOutputPort()); t3.ReplaceInOn(); t3.SetInValue((double)0); t3.ThresholdBetween((double)150,(double)256); gs4 = new vtkImageGaussianSource(); gs4.SetWholeExtent((int)0,(int)30,(int)0,(int)30,(int)0,(int)30); gs4.SetMaximum((double)255.0); gs4.SetStandardDeviation((double)4); gs4.SetCenter((double)26,(double)26,(double)26); //tk window skipped.. iac1 = new vtkImageAppendComponents(); iac1.AddInput((vtkDataObject)t1.GetOutput()); iac1.AddInput((vtkDataObject)gs2.GetOutput()); iac2 = new vtkImageAppendComponents(); iac2.AddInput((vtkDataObject)iac1.GetOutput()); iac2.AddInput((vtkDataObject)t3.GetOutput()); iac3 = new vtkImageAppendComponents(); iac3.AddInput((vtkDataObject)iac2.GetOutput()); iac3.AddInput((vtkDataObject)gs4.GetOutput()); // create the four component dependend - [] // use lines in x, y, z for colors[] gridR = new vtkImageGridSource(); gridR.SetDataScalarTypeToUnsignedChar(); gridR.SetGridSpacing((int)10,(int)100,(int)100); gridR.SetLineValue((double)250); gridR.SetFillValue((double)100); gridR.SetDataExtent((int)0,(int)30,(int)0,(int)30,(int)0,(int)30); dR = new vtkImageContinuousDilate3D(); dR.SetInputConnection((vtkAlgorithmOutput)gridR.GetOutputPort()); dR.SetKernelSize((int)2,(int)2,(int)2); gridG = new vtkImageGridSource(); gridG.SetDataScalarTypeToUnsignedChar(); gridG.SetGridSpacing((int)100,(int)10,(int)100); gridG.SetLineValue((double)250); gridG.SetFillValue((double)100); gridG.SetDataExtent((int)0,(int)30,(int)0,(int)30,(int)0,(int)30); dG = new vtkImageContinuousDilate3D(); dG.SetInputConnection((vtkAlgorithmOutput)gridG.GetOutputPort()); dG.SetKernelSize((int)2,(int)2,(int)2); gridB = new vtkImageGridSource(); gridB.SetDataScalarTypeToUnsignedChar(); gridB.SetGridSpacing((int)100,(int)100,(int)10); gridB.SetLineValue((double)0); gridB.SetFillValue((double)250); gridB.SetDataExtent((int)0,(int)30,(int)0,(int)30,(int)0,(int)30); dB = new vtkImageContinuousDilate3D(); dB.SetInputConnection((vtkAlgorithmOutput)gridB.GetOutputPort()); dB.SetKernelSize((int)2,(int)2,(int)2); // need some appending[] iacRG = new vtkImageAppendComponents(); iacRG.AddInput((vtkDataObject)dR.GetOutput()); iacRG.AddInput((vtkDataObject)dG.GetOutput()); iacRGB = new vtkImageAppendComponents(); iacRGB.AddInput((vtkDataObject)iacRG.GetOutput()); iacRGB.AddInput((vtkDataObject)dB.GetOutput()); iacRGBA = new vtkImageAppendComponents(); iacRGBA.AddInput((vtkDataObject)iacRGB.GetOutput()); iacRGBA.AddInput((vtkDataObject)ss.GetOutput()); // We need a bunch of opacity functions[] // this one is a simple ramp to .2[] rampPoint2 = new vtkPiecewiseFunction(); rampPoint2.AddPoint((double)0,(double)0.0); rampPoint2.AddPoint((double)255,(double)0.2); // this one is a simple ramp to 1[] ramp1 = new vtkPiecewiseFunction(); ramp1.AddPoint((double)0,(double)0.0); ramp1.AddPoint((double)255,(double)1.0); // this one shows a sharp surface[] surface = new vtkPiecewiseFunction(); surface.AddPoint((double)0,(double)0.0); surface.AddPoint((double)10,(double)0.0); surface.AddPoint((double)50,(double)1.0); surface.AddPoint((double)255,(double)1.0); // this one is constant 1[] constant1 = new vtkPiecewiseFunction(); constant1.AddPoint((double)0,(double)1.0); constant1.AddPoint((double)255,(double)1.0); // this one is used for gradient opacity[] gop = new vtkPiecewiseFunction(); gop.AddPoint((double)0,(double)0.0); gop.AddPoint((double)20,(double)0.0); gop.AddPoint((double)60,(double)1.0); gop.AddPoint((double)255,(double)1.0); // We need a bunch of color functions[] // This one is a simple rainbow[] rainbow = new vtkColorTransferFunction(); rainbow.SetColorSpaceToHSV(); rainbow.HSVWrapOff(); rainbow.AddHSVPoint((double)0,(double)0.1,(double)1.0,(double)1.0); rainbow.AddHSVPoint((double)255,(double)0.9,(double)1.0,(double)1.0); // this is constant red[] red = new vtkColorTransferFunction(); red.AddRGBPoint((double)0,(double)1,(double)0,(double)0); red.AddRGBPoint((double)255,(double)1,(double)0,(double)0); // this is constant green[] green = new vtkColorTransferFunction(); green.AddRGBPoint((double)0,(double)0,(double)1,(double)0); green.AddRGBPoint((double)255,(double)0,(double)1,(double)0); // this is constant blue[] blue = new vtkColorTransferFunction(); blue.AddRGBPoint((double)0,(double)0,(double)0,(double)1); blue.AddRGBPoint((double)255,(double)0,(double)0,(double)1); // this is constant yellow[] yellow = new vtkColorTransferFunction(); yellow.AddRGBPoint((double)0,(double)1,(double)1,(double)0); yellow.AddRGBPoint((double)255,(double)1,(double)1,(double)0); ren1 = vtkRenderer.New(); renWin = vtkRenderWindow.New(); renWin.AddRenderer((vtkRenderer)ren1); renWin.SetSize((int)500,(int)500); iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); ren1.GetCullers().InitTraversal(); culler = (vtkFrustumCoverageCuller)ren1.GetCullers().GetNextItem(); culler.SetSortingStyleToBackToFront(); // We need 25 mapper / actor pairs which we will render[] // in a grid. Going down we will vary the input data[] // with the top row unsigned char, then float, then[] // two dependent components, then four dependent components[] // then four independent components. Going across we[] // will vary the rendering method with MIP, Composite,[] // Composite Shade, Composite GO, and Composite GO Shade.[] j = 0; while((j) < 5) { i = 0; while((i) < 5) { volumeProperty[i,j] = new vtkVolumeProperty(); volumeMapper[i,j] = new vtkFixedPointVolumeRayCastMapper(); volumeMapper[i,j].SetSampleDistance((float)0.25); volume[i,j] = new vtkVolume(); volume[i,j].SetMapper((vtkAbstractVolumeMapper)volumeMapper[i,j]); volume[i,j].SetProperty((vtkVolumeProperty)volumeProperty[i,j]); volume[i,j].AddPosition((double)i*30,(double)j*30,(double)0); ren1.AddVolume((vtkProp)volume[i,j]); i = i + 1; } j = j + 1; } i = 0; while((i) < 5) { volumeMapper[0,i].SetInputConnection(t.GetOutputPort()); volumeMapper[1,i].SetInputConnection(ss.GetOutputPort()); volumeMapper[2,i].SetInputConnection(iac.GetOutputPort()); volumeMapper[3,i].SetInputConnection(iac3.GetOutputPort()); volumeMapper[4,i].SetInputConnection(iacRGBA.GetOutputPort()); volumeMapper[i,0].SetBlendModeToMaximumIntensity(); volumeMapper[i,1].SetBlendModeToComposite(); volumeMapper[i,2].SetBlendModeToComposite(); volumeMapper[i,3].SetBlendModeToComposite(); volumeMapper[i,4].SetBlendModeToComposite(); volumeProperty[0,i].IndependentComponentsOn(); volumeProperty[1,i].IndependentComponentsOn(); volumeProperty[2,i].IndependentComponentsOff(); volumeProperty[3,i].IndependentComponentsOn(); volumeProperty[4,i].IndependentComponentsOff(); volumeProperty[0,i].SetColor(rainbow); volumeProperty[0,i].SetScalarOpacity(rampPoint2); volumeProperty[0,i].SetGradientOpacity(constant1); volumeProperty[1,i].SetColor(rainbow); volumeProperty[1,i].SetScalarOpacity(rampPoint2); volumeProperty[1,i].SetGradientOpacity(constant1); volumeProperty[2,i].SetColor(rainbow); volumeProperty[2,i].SetScalarOpacity(rampPoint2); volumeProperty[2,i].SetGradientOpacity(constant1); volumeProperty[3,i].SetColor(0, red); volumeProperty[3,i].SetColor(1, green); volumeProperty[3,i].SetColor(2, blue ); volumeProperty[3,i].SetColor(3, yellow); volumeProperty[3,i].SetScalarOpacity(0,rampPoint2); volumeProperty[3,i].SetScalarOpacity(1,rampPoint2); volumeProperty[3,i].SetScalarOpacity(2,rampPoint2); volumeProperty[3,i].SetScalarOpacity(3,rampPoint2); volumeProperty[3,i].SetGradientOpacity(0,constant1); volumeProperty[3,i].SetGradientOpacity(1,constant1); volumeProperty[3,i].SetGradientOpacity(2,constant1); volumeProperty[3,i].SetGradientOpacity(3,constant1); volumeProperty[3,i].SetComponentWeight(0,1); volumeProperty[3,i].SetComponentWeight(1,1); volumeProperty[3,i].SetComponentWeight(2,1); volumeProperty[3,i].SetComponentWeight(3,1); volumeProperty[4,i].SetColor(rainbow); volumeProperty[4,i].SetScalarOpacity(rampPoint2); volumeProperty[4,i].SetGradientOpacity(constant1); volumeProperty[i,2].ShadeOn(); volumeProperty[i,4].ShadeOn((int)0); volumeProperty[i,4].ShadeOn((int)1); volumeProperty[i,4].ShadeOn((int)2); volumeProperty[i,4].ShadeOn((int)3); i = i + 1; } volumeProperty[0,0].SetScalarOpacity((vtkPiecewiseFunction)ramp1); volumeProperty[1,0].SetScalarOpacity((vtkPiecewiseFunction)ramp1); volumeProperty[2,0].SetScalarOpacity((vtkPiecewiseFunction)ramp1); volumeProperty[3,0].SetScalarOpacity((int)0,(vtkPiecewiseFunction)surface); volumeProperty[3,0].SetScalarOpacity((int)1,(vtkPiecewiseFunction)surface); volumeProperty[3,0].SetScalarOpacity((int)2,(vtkPiecewiseFunction)surface); volumeProperty[3,0].SetScalarOpacity((int)3,(vtkPiecewiseFunction)surface); volumeProperty[4,0].SetScalarOpacity((vtkPiecewiseFunction)ramp1); volumeProperty[0,2].SetScalarOpacity((vtkPiecewiseFunction)surface); volumeProperty[1,2].SetScalarOpacity((vtkPiecewiseFunction)surface); volumeProperty[2,2].SetScalarOpacity((vtkPiecewiseFunction)surface); volumeProperty[3,2].SetScalarOpacity((int)0,(vtkPiecewiseFunction)surface); volumeProperty[3,2].SetScalarOpacity((int)1,(vtkPiecewiseFunction)surface); volumeProperty[3,2].SetScalarOpacity((int)2,(vtkPiecewiseFunction)surface); volumeProperty[3,2].SetScalarOpacity((int)3,(vtkPiecewiseFunction)surface); volumeProperty[4,2].SetScalarOpacity((vtkPiecewiseFunction)surface); volumeProperty[0,4].SetScalarOpacity((vtkPiecewiseFunction)surface); volumeProperty[1,4].SetScalarOpacity((vtkPiecewiseFunction)surface); volumeProperty[2,4].SetScalarOpacity((vtkPiecewiseFunction)surface); volumeProperty[3,4].SetScalarOpacity((int)0,(vtkPiecewiseFunction)surface); volumeProperty[3,4].SetScalarOpacity((int)1,(vtkPiecewiseFunction)surface); volumeProperty[3,4].SetScalarOpacity((int)2,(vtkPiecewiseFunction)surface); volumeProperty[3,4].SetScalarOpacity((int)3,(vtkPiecewiseFunction)surface); volumeProperty[4,4].SetScalarOpacity((vtkPiecewiseFunction)surface); volumeProperty[0,3].SetGradientOpacity((vtkPiecewiseFunction)gop); volumeProperty[1,3].SetGradientOpacity((vtkPiecewiseFunction)gop); volumeProperty[2,3].SetGradientOpacity((vtkPiecewiseFunction)gop); volumeProperty[3,3].SetGradientOpacity((int)0,(vtkPiecewiseFunction)gop); volumeProperty[3,3].SetGradientOpacity((int)2,(vtkPiecewiseFunction)gop); volumeProperty[4,3].SetGradientOpacity((vtkPiecewiseFunction)gop); volumeProperty[3,3].SetScalarOpacity((int)0,(vtkPiecewiseFunction)ramp1); volumeProperty[3,3].SetScalarOpacity((int)2,(vtkPiecewiseFunction)ramp1); volumeProperty[0,4].SetGradientOpacity((vtkPiecewiseFunction)gop); volumeProperty[1,4].SetGradientOpacity((vtkPiecewiseFunction)gop); volumeProperty[2,4].SetGradientOpacity((vtkPiecewiseFunction)gop); volumeProperty[3,4].SetGradientOpacity((int)0,(vtkPiecewiseFunction)gop); volumeProperty[3,4].SetGradientOpacity((int)2,(vtkPiecewiseFunction)gop); volumeProperty[4,4].SetGradientOpacity((vtkPiecewiseFunction)gop); renWin.Render(); ren1.GetActiveCamera().Dolly((double)1.3); ren1.GetActiveCamera().Azimuth((double)15); ren1.GetActiveCamera().Elevation((double)5); ren1.ResetCameraClippingRange(); iren.Initialize(); //deleteAllVTKObjects(); }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVgaussian(String [] argv) { //Prefix Content is: "" ren1 = vtkRenderer.New(); renWin = vtkRenderWindow.New(); renWin.AddRenderer((vtkRenderer)ren1); renWin.SetSize((int)300,(int)300); iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); camera = new vtkCamera(); camera.ParallelProjectionOn(); camera.SetViewUp((double)0,(double)1,(double)0); camera.SetFocalPoint((double)12,(double)10.5,(double)15); camera.SetPosition((double)-70,(double)15,(double)34); camera.ComputeViewPlaneNormal(); ren1.SetActiveCamera((vtkCamera)camera); // Create the reader for the data[] //vtkStructuredPointsReader reader[] reader = new vtkGaussianCubeReader(); reader.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/m4_TotalDensity.cube"); reader.SetHBScale((double)1.1); reader.SetBScale((double)10); reader.Update(); range = reader.GetGridOutput().GetPointData().GetScalars().GetRange(); min = (double)(lindex(range,0)); max = (double)(lindex(range,1)); readerSS = new vtkImageShiftScale(); readerSS.SetInput((vtkDataObject)reader.GetGridOutput()); readerSS.SetShift((double)min*-1); readerSS.SetScale((double)255/(max-min)); readerSS.SetOutputScalarTypeToUnsignedChar(); bounds = new vtkOutlineFilter(); bounds.SetInput((vtkDataObject)reader.GetGridOutput()); boundsMapper = vtkPolyDataMapper.New(); boundsMapper.SetInputConnection((vtkAlgorithmOutput)bounds.GetOutputPort()); boundsActor = new vtkActor(); boundsActor.SetMapper((vtkMapper)boundsMapper); boundsActor.GetProperty().SetColor((double)0,(double)0,(double)0); contour = new vtkContourFilter(); contour.SetInput((vtkDataObject)reader.GetGridOutput()); contour.GenerateValues((int)5,(double)0,(double).05); contourMapper = vtkPolyDataMapper.New(); contourMapper.SetInputConnection((vtkAlgorithmOutput)contour.GetOutputPort()); contourMapper.SetScalarRange((double)0,(double).1); ((vtkLookupTable)contourMapper.GetLookupTable()).SetHueRange(0.32,0); contourActor = new vtkActor(); contourActor.SetMapper((vtkMapper)contourMapper); contourActor.GetProperty().SetOpacity((double).5); // Create transfer mapping scalar value to opacity[] opacityTransferFunction = new vtkPiecewiseFunction(); opacityTransferFunction.AddPoint((double)0,(double)0.01); opacityTransferFunction.AddPoint((double)255,(double)0.35); opacityTransferFunction.ClampingOn(); // Create transfer mapping scalar value to color[] colorTransferFunction = new vtkColorTransferFunction(); colorTransferFunction.AddHSVPoint((double)0.0,(double)0.66,(double)1.0,(double)1.0); colorTransferFunction.AddHSVPoint((double)50.0,(double)0.33,(double)1.0,(double)1.0); colorTransferFunction.AddHSVPoint((double)100.0,(double)0.00,(double)1.0,(double)1.0); // The property describes how the data will look[] volumeProperty = new vtkVolumeProperty(); volumeProperty.SetColor((vtkColorTransferFunction)colorTransferFunction); volumeProperty.SetScalarOpacity((vtkPiecewiseFunction)opacityTransferFunction); volumeProperty.SetInterpolationTypeToLinear(); // The mapper / ray cast function know how to render the data[] compositeFunction = new vtkVolumeRayCastCompositeFunction(); volumeMapper = new vtkVolumeRayCastMapper(); //vtkVolumeTextureMapper2D volumeMapper[] volumeMapper.SetVolumeRayCastFunction((vtkVolumeRayCastFunction)compositeFunction); volumeMapper.SetInputConnection((vtkAlgorithmOutput)readerSS.GetOutputPort()); // The volume holds the mapper and the property and[] // can be used to position/orient the volume[] volume = new vtkVolume(); volume.SetMapper((vtkAbstractVolumeMapper)volumeMapper); volume.SetProperty((vtkVolumeProperty)volumeProperty); ren1.AddVolume((vtkProp)volume); //ren1 AddActor contourActor[] ren1.AddActor((vtkProp)boundsActor); //#####################################################################[] Sphere = new vtkSphereSource(); Sphere.SetCenter((double)0,(double)0,(double)0); Sphere.SetRadius((double)1); Sphere.SetThetaResolution((int)16); Sphere.SetStartTheta((double)0); Sphere.SetEndTheta((double)360); Sphere.SetPhiResolution((int)16); Sphere.SetStartPhi((double)0); Sphere.SetEndPhi((double)180); Glyph = new vtkGlyph3D(); Glyph.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort()); Glyph.SetOrient((int)1); Glyph.SetColorMode((int)1); //Glyph ScalingOn[] Glyph.SetScaleMode((int)2); Glyph.SetScaleFactor((double).6); Glyph.SetSource((vtkPolyData)Sphere.GetOutput()); AtomsMapper = vtkPolyDataMapper.New(); AtomsMapper.SetInputConnection((vtkAlgorithmOutput)Glyph.GetOutputPort()); AtomsMapper.SetImmediateModeRendering((int)1); AtomsMapper.UseLookupTableScalarRangeOff(); AtomsMapper.SetScalarVisibility((int)1); AtomsMapper.SetScalarModeToDefault(); Atoms = new vtkActor(); Atoms.SetMapper((vtkMapper)AtomsMapper); Atoms.GetProperty().SetRepresentationToSurface(); Atoms.GetProperty().SetInterpolationToGouraud(); Atoms.GetProperty().SetAmbient((double)0.15); Atoms.GetProperty().SetDiffuse((double)0.85); Atoms.GetProperty().SetSpecular((double)0.1); Atoms.GetProperty().SetSpecularPower((double)100); Atoms.GetProperty().SetSpecularColor((double)1,(double)1,(double)1); Atoms.GetProperty().SetColor((double)1,(double)1,(double)1); Tube = new vtkTubeFilter(); Tube.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort()); Tube.SetNumberOfSides((int)16); Tube.SetCapping((int)0); Tube.SetRadius((double)0.2); Tube.SetVaryRadius((int)0); Tube.SetRadiusFactor((double)10); BondsMapper = vtkPolyDataMapper.New(); BondsMapper.SetInputConnection((vtkAlgorithmOutput)Tube.GetOutputPort()); BondsMapper.SetImmediateModeRendering((int)1); BondsMapper.UseLookupTableScalarRangeOff(); BondsMapper.SetScalarVisibility((int)1); BondsMapper.SetScalarModeToDefault(); Bonds = new vtkActor(); Bonds.SetMapper((vtkMapper)BondsMapper); Bonds.GetProperty().SetRepresentationToSurface(); Bonds.GetProperty().SetInterpolationToGouraud(); Bonds.GetProperty().SetAmbient((double)0.15); Bonds.GetProperty().SetDiffuse((double)0.85); Bonds.GetProperty().SetSpecular((double)0.1); Bonds.GetProperty().SetSpecularPower((double)100); Bonds.GetProperty().SetSpecularColor((double)1,(double)1,(double)1); Bonds.GetProperty().SetColor((double)1,(double)1,(double)1); ren1.AddActor((vtkProp)Bonds); ren1.AddActor((vtkProp)Atoms); //###################################################[] ren1.SetBackground((double)1,(double)1,(double)1); ren1.ResetCamera(); renWin.Render(); //method moved renWin.AbortCheckEvt += new Kitware.VTK.vtkObject.vtkObjectEventHandler(TkCheckAbort_Command.Execute); iren.Initialize(); //deleteAllVTKObjects(); }
private void setGradientOpacity() { gpwf = vtkPiecewiseFunction.New(); //Set the gradient curve for the volume gpwf.AddPoint(0, .2); gpwf.AddPoint(10, .2); gpwf.AddPoint(25, 1); vol.GetProperty().SetGradientOpacity(gpwf); }
///<summary> A Set Method for Static Variables </summary> public static void Setopacity_transfer_function(vtkPiecewiseFunction toSet) { opacity_transfer_function = toSet; }
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); }