//wizualizacja 3d ----------------------------------------------------------------- public Visualization3D(RenderWindowControl window, DicomLoader dicomLoader, Chart chart) { _chart = chart; _window = window; _dicomLoader = dicomLoader; PresetReader = new XmlPresetReader(); // Create a mapper and actor _mapper = vtkSmartVolumeMapper.New(); _mapper.SetInput(_dicomLoader.GetOutput()); _volume = vtkVolume.New(); SetOpacityFunction(); SetGradientOpacity(); _volume.SetMapper(_mapper); renderer = vtkRenderer.New(); renderer.AddVolume(_volume); _window.RenderWindow.GetRenderers().RemoveAllItems(); _window.RenderWindow.AddRenderer(renderer); _window.RenderWindow.GetRenderers().GetFirstRenderer().AddVolume(_volume); // An interactor _renderWindowInteractor = vtkRenderWindowInteractor.New(); _renderWindowInteractor.SetRenderWindow(_window.RenderWindow); //Camera style vtkInteractorStyleTrackballCamera style = vtkInteractorStyleTrackballCamera.New(); style.AutoAdjustCameraClippingRangeOff(); _renderWindowInteractor.SetInteractorStyle(style); //Create and setup planes PlaneWidgetX = new PlaneWidget(Axis.X); SetupPlane(PlaneWidgetX); PlaneWidgetY = new PlaneWidget(Axis.Y); SetupPlane(PlaneWidgetY); PlaneWidgetZ = new PlaneWidget(Axis.Z); SetupPlane(PlaneWidgetZ); // Render _window.RenderWindow.Render(); //ClipingModule _clipingModule = new ClipingModule(GetObjectSize()); }
public static void ShowPolydata(string airwayPath) { if (!File.Exists(airwayPath)) { MessageBox.Show("文件不存在!"); return; } vtkRenderWindow renWin = vtkRenderWindow.New(); renWin.SetSize(600, 600); vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor(); renWin.SetInteractor(iren); vtkInteractorStyleTrackballCamera interactorStyle = new vtkInteractorStyleTrackballCamera(); iren.SetInteractorStyle(interactorStyle); vtkRenderer renderer = vtkRenderer.New(); renderer.GradientBackgroundOn(); renderer.SetBackground(0, 0, 0); renderer.SetBackground2(0, 0, 1); renWin.AddRenderer(renderer); vtkXMLPolyDataReader reader = new vtkXMLPolyDataReader(); reader.SetFileName(airwayPath); reader.Update(); vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); mapper.ScalarVisibilityOff(); mapper.SetInput(reader.GetOutput()); reader.Dispose(); vtkActor actor = new vtkActor(); actor.SetMapper(mapper); renderer.AddActor(actor); renWin.Render(); }
private void SetRenderWindow(vtkWin32OpenGLRenderWindow win) { _vtkWin32OpenGLRW = vtkWin32OpenGLRenderWindow.SafeDownCast(win); if (_vtkWin32OpenGLRW != null) { vtkGenericRenderWindowInteractor iren = new vtkGenericRenderWindowInteractor(); iren.SetRenderWindow(_vtkWin32OpenGLRW); vtkInteractorStyleTrackballCamera style = new vtkInteractorStyleTrackballCamera(); iren.SetInteractorStyle(style); style.Dispose(); // The control must wait to initialize the interactor until it has // been given a parent window. Until then, initializing the interactor // will always fail. // release our hold on interactor iren.Dispose(); } }
static void Main(string[] args) { // // Next we create an instance of vtkConeSource and set some of its // properties. The instance of vtkConeSource "cone" is part of a visualization // pipeline (it is a source process object); it produces data (output type is // vtkPolyData) which other filters may process. // vtkConeSource cone = new vtkConeSource(); cone.SetHeight( 3.0f ); cone.SetRadius( 1.0f ); cone.SetResolution( 10 ); // // In this example we terminate the pipeline with a mapper process object. // (Intermediate filters such as vtkShrinkPolyData could be inserted in // between the source and the mapper.) We create an instance of // vtkPolyDataMapper to map the polygonal data into graphics primitives. We // connect the output of the cone souece to the input of this mapper. // vtkPolyDataMapper coneMapper = new vtkPolyDataMapper(); coneMapper.SetInput( cone.GetOutput() ); // // Create an actor to represent the cone. The actor orchestrates rendering of // the mapper's graphics primitives. An actor also refers to properties via a // vtkProperty instance, and includes an internal transformation matrix. We // set this actor's mapper to be coneMapper which we created above. // vtkActor coneActor = new vtkActor(); coneActor.SetMapper( coneMapper ); // // Create the Renderer and assign actors to it. A renderer is like a // viewport. It is part or all of a window on the screen and it is // responsible for drawing the actors it has. We also set the background // color here // vtkRenderer ren1 = new vtkRenderer(); ren1.AddActor( coneActor ); ren1.SetBackground( 0.1f, 0.2f, 0.4f ); // // Finally we create the render window which will show up on the screen // We put our renderer into the render window using AddRenderer. We also // set the size to be 300 pixels by 300 // vtkRenderWindow renWin = new vtkRenderWindow(); renWin.AddRenderer( ren1 ); renWin.SetSize( 300, 300 ); vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow(renWin); vtkInteractorStyleTrackballCamera style = new vtkInteractorStyleTrackballCamera(); iren.SetInteractorStyle(style); vtkBoxWidget boxWidget = new vtkBoxWidget(); boxWidget.SetInteractor(iren); boxWidget.SetPlaceFactor(1.25f); boxWidget.SetProp3D(coneActor); boxWidget.PlaceWidget(); boxWidget.AddObserver((uint) EventIds.InteractionEvent, new vtkDotNetCallback(myCallback)); boxWidget.On(); iren.Initialize(); iren.Start(); vtkWin32OpenGLRenderWindow win32win = vtkWin32OpenGLRenderWindow.SafeDownCast(renWin); if ( null != win32win ) win32win.Clean(); }
private void SetRenderWindow(vtkWin32OpenGLRenderWindow win) { _vtkWin32OpenGLRW = vtkWin32OpenGLRenderWindow.SafeDownCast(win); if(_vtkWin32OpenGLRW != null) { vtkGenericRenderWindowInteractor iren = new vtkGenericRenderWindowInteractor(); iren.SetRenderWindow(_vtkWin32OpenGLRW); vtkInteractorStyleTrackballCamera style = new vtkInteractorStyleTrackballCamera(); iren.SetInteractorStyle(style); style.Dispose(); // The control must wait to initialize the interactor until it has // been given a parent window. Until then, initializing the interactor // will always fail. // release our hold on interactor iren.Dispose(); } }
public static void ShowPolydata(string airwayPath, string lesionPath) { vtkAppendPolyData appendPolydata = new vtkAppendPolyData(); if (File.Exists(airwayPath)) { vtkXMLPolyDataReader reader = new vtkXMLPolyDataReader(); reader.SetFileName(airwayPath); reader.Update(); appendPolydata.AddInput(reader.GetOutput()); reader.Dispose(); } else { MessageBox.Show("airwayPath : " + airwayPath + "文件不存在!"); } if (File.Exists(lesionPath)) { vtkXMLPolyDataReader reader = new vtkXMLPolyDataReader(); reader.SetFileName(lesionPath); reader.Update(); appendPolydata.AddInput(reader.GetOutput()); reader.Dispose(); } else { MessageBox.Show("lesionPath : " + lesionPath + "文件不存在!"); } vtkRenderWindow renWin = vtkRenderWindow.New(); renWin.SetSize(600, 600); vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor(); renWin.SetInteractor(iren); vtkInteractorStyleTrackballCamera interactorStyle = new vtkInteractorStyleTrackballCamera(); iren.SetInteractorStyle(interactorStyle); vtkRenderer renderer = vtkRenderer.New(); renderer.GradientBackgroundOn(); renderer.SetBackground(0, 0, 0); renderer.SetBackground2(0, 0, 1); renWin.AddRenderer(renderer); vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); mapper.ScalarVisibilityOff(); mapper.SetInput(appendPolydata.GetOutput()); vtkActor actor = new vtkActor(); actor.SetMapper(mapper); renderer.AddActor(actor); renderer.Render(); renderer.ResetCamera(); renWin.Render(); //Thread thread = new Thread(new ThreadStart( // delegate // { // iren.Start(); // })); //thread.Start(); }
public void CreateViewport(Grid Window) { WindowsFormsHost VTK_Window = new WindowsFormsHost(); // Create Windows Forms Host for VTK Window RenWinControl = new RenderWindowControl(); // Initialize VTK Renderer Window Control // Clear input Window and add new host Window.Children.Clear(); Window.Children.Add(VTK_Window); VTK_Window.Child = RenWinControl; // Create Render Window renderWindow = RenWinControl.RenderWindow; // Initialize Interactor Inter = vtkRenderWindowInteractor.New(); Inter.LeftButtonPressEvt += new vtkObject.vtkObjectEventHandler(SelectPointClick); Inter.RightButtonPressEvt += new vtkObject.vtkObjectEventHandler(UnselectPointClick); renderWindow.SetInteractor(Inter); Inter.Initialize(); InterStyleTrack = vtkInteractorStyleTrackballCamera.New(); //Inter.SetInteractorStyle(InterStyleTrack); InterStylePick = vtkInteractorStyleRubberBandPick.New(); Inter.SetInteractorStyle(InterStylePick); // Initialize View Viewport = renderWindow.GetRenderers().GetFirstRenderer(); Viewport.RemoveAllViewProps(); CreateViewportBorder(Viewport, new double[3] { 128.0, 128.0, 128.0 }); // Set default background color Viewport.GradientBackgroundOn(); Viewport.SetBackground(163.0 / 255.0, 163.0 / 255.0, 163.0 / 255.0); Viewport.SetBackground2(45.0 / 255.0, 85.0 / 255.0, 125.0 / 255.0); // Other properties Viewport.GetActiveCamera().ParallelProjectionOn(); // Initialize Selection objects AppendFaces = vtkAppendPolyData.New(); Faces = vtkPolyData.New(); SelectionMode = false; SelectionSize = 0.1; SelectionPoints = vtkPoints.New(); SelectionActor = vtkActor.New(); SelectionPolyData = vtkPolyData.New(); SelectionPolyData.SetPoints(SelectionPoints); SelectionSphere = vtkSphereSource.New(); SelectionSphere.SetPhiResolution(12); SelectionSphere.SetThetaResolution(12); SelectionSphere.SetRadius(SelectionSize); SelectionGlyph = vtkGlyph3D.New(); SelectionGlyph.SetInput(SelectionPolyData); SelectionGlyph.SetSourceConnection(SelectionSphere.GetOutputPort()); SelectionMapper = vtkPolyDataMapper.New(); SelectionMapper.SetInputConnection(SelectionGlyph.GetOutputPort()); SelectionActor.SetMapper(SelectionMapper); SelectionActor.GetProperty().SetColor(1, 1, 1); SelectionActor.VisibilityOn(); Viewport.AddActor(SelectionActor); // Create new Properties and Objects CreateColorMap(); CreateScalarBar(); CreateAxes(); CreateSlider(); CreateClipPlane(); }
private void renderWindowControl1_Load(object sender, EventArgs e) { vtkRenderWindow renWin = renderWindowControl1.RenderWindow; _render = renderWindowControl1.RenderWindow.GetRenderers().GetFirstRenderer(); //_render.SetBackground(1, 1, 1); _render.SetBackground(1.0, 1.0, 1.0); // 设置页面底部颜色值 _render.SetBackground2(0.529, 0.8078, 0.92157); // 设置页面顶部颜色值 _render.SetGradientBackground(true); // 开启渐变色背景设置 double axesScale = 1; // 初始化vtk窗口 vtkAxesActor axes = vtkAxesActor.New(); axes.GetXAxisCaptionActor2D().GetCaptionTextProperty().SetColor(1, 0, 0); //修改X字体颜色为红色 axes.GetYAxisCaptionActor2D().GetCaptionTextProperty().SetColor(0, 2, 0); //修改Y字体颜色为绿色 axes.GetZAxisCaptionActor2D().GetCaptionTextProperty().SetColor(0, 0, 3); //修改Z字体颜色为蓝色 axes.SetConeRadius(0.3); axes.SetConeResolution(20); //axes->SetTotalLength(10, 10, 10); //修改坐标尺寸 vtkAxesActor axes1 = vtkAxesActor.New(); axes1.GetXAxisCaptionActor2D().GetCaptionTextProperty().SetColor(1, 0, 0); //修改X字体颜色为红色 axes1.GetYAxisCaptionActor2D().GetCaptionTextProperty().SetColor(0, 2, 0); //修改Y字体颜色为绿色 axes1.GetZAxisCaptionActor2D().GetCaptionTextProperty().SetColor(0, 0, 3); //修改Z字体颜色为蓝色 axes1.SetConeRadius(0.03); axes1.AxisLabelsOff(); axes1.GetXAxisCaptionActor2D().GetCaptionTextProperty().SetFontSize(1); //axes1.SetConeRadius(0.3); axes1.SetConeResolution(20); _render.AddActor(axes1); vtkRenderWindowInteractor interactor = vtkRenderWindowInteractor.New(); interactor.SetRenderWindow(renWin); vtkInteractorStyleTrackballCamera style = vtkInteractorStyleTrackballCamera.New(); interactor.SetInteractorStyle(style); renWin.SetInteractor(interactor); interactor.Initialize(); vtkCamera aCamera = vtkCamera.New(); aCamera.SetViewUp(0, 0, 1); //设视角位置 aCamera.SetPosition(0, -3 * axesScale, 0); //设观察对象位 aCamera.SetFocalPoint(0, 0, 0); //设焦点 aCamera.ComputeViewPlaneNormal(); //自动 _render.SetActiveCamera(aCamera); _render.ResetCamera(); renWin.Render(); widget1 = vtkOrientationMarkerWidget.New(); widget1.SetOutlineColor(0.9300, 0.5700, 0.1300); widget1.SetOrientationMarker(axes); widget1.SetInteractor(interactor); widget1.SetViewport(0.0, 0.0, 0.25, 0.25); widget1.SetEnabled(1); widget1.InteractiveOff(); //_render.AddViewProp(FrustumCone.genActor(new CompontData())); }