static void Main() { string VTK_DATA_ROOT = "C:/Program Files/VTKData"; // Create a vtkBYUReader and read in a data set. vtkBYUReader fohe = new vtkBYUReader(); fohe.SetGeometryFileName(VTK_DATA_ROOT + "/Data/teapot.g"); // Create a vtkPolyDataNormals filter to calculate the normals of the // data set. vtkPolyDataNormals normals = new vtkPolyDataNormals(); normals.SetInputConnection(fohe.GetOutputPort()); // Set up the associated mapper and actor. vtkPolyDataMapper foheMapper = new vtkPolyDataMapper(); foheMapper.SetInputConnection(normals.GetOutputPort()); vtkLODActor foheActor = new vtkLODActor(); foheActor.SetMapper(foheMapper); // Create a vtkOutlineFilter to draw the bounding box of the data set. // Also create the associated mapper and actor. vtkOutlineFilter outline = new vtkOutlineFilter(); outline.SetInputConnection(normals.GetOutputPort()); vtkPolyDataMapper mapOutline = new vtkPolyDataMapper(); mapOutline.SetInputConnection(outline.GetOutputPort()); vtkActor outlineActor = new vtkActor(); outlineActor.SetMapper(mapOutline); outlineActor.GetProperty().SetColor(0, 0, 0); // Create a vtkCamera, and set the camera parameters. vtkCamera camera = new vtkCamera(); camera.SetClippingRange(1.60187, 20.0842); camera.SetFocalPoint(0.21406, 1.5, 0); camera.SetPosition(8.3761, 4.94858, 4.12505); camera.SetViewUp(0.180325, 0.549245, -0.815974); // Create a vtkLight, and set the light parameters. vtkLight light = new vtkLight(); light.SetFocalPoint(0.21406, 1.5, 0); light.SetPosition(8.3761, 4.94858, 4.12505); // Create the Renderers. Assign them the appropriate viewport // coordinates, active camera, and light. vtkRenderer ren = new vtkRenderer(); ren.SetViewport(0, 0, 0.5, 1.0); ren.SetActiveCamera(camera); ren.AddLight(light); vtkRenderer ren2 = new vtkRenderer(); ren2.SetViewport(0.5, 0, 1.0, 1.0); ren2.SetActiveCamera(camera); ren2.AddLight(light); // Create the RenderWindow and RenderWindowInteractor. vtkRenderWindow renWin = new vtkRenderWindow(); renWin.AddRenderer(ren); renWin.AddRenderer(ren2); renWin.SetWindowName("VTK - Cube Axes"); renWin.SetSize(600, 300); vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow(renWin); // Add the actors to the renderer, and set the background. ren.AddViewProp(foheActor); ren.AddViewProp(outlineActor); ren2.AddViewProp(foheActor); ren2.AddViewProp(outlineActor); ren.SetBackground(0.1, 0.2, 0.4); ren2.SetBackground(0.1, 0.2, 0.4); // Create a text property for both cube axes vtkTextProperty tprop = new vtkTextProperty(); tprop.SetColor(1, 1, 1); tprop.ShadowOn(); // Create a vtkCubeAxesActor2D. Use the outer edges of the bounding box to // draw the axes. Add the actor to the renderer. vtkCubeAxesActor2D axes = new vtkCubeAxesActor2D(); axes.SetInput(normals.GetOutput()); axes.SetCamera(ren.GetActiveCamera()); axes.SetLabelFormat("%6.4g"); axes.SetFlyModeToOuterEdges(); axes.SetFontFactor(0.8); axes.SetAxisTitleTextProperty(tprop); axes.SetAxisLabelTextProperty(tprop); ren.AddViewProp(axes); // Create a vtkCubeAxesActor2D. Use the closest vertex to the camera to // determine where to draw the axes. Add the actor to the renderer. vtkCubeAxesActor2D axes2 = new vtkCubeAxesActor2D(); axes2.SetViewProp(foheActor); axes2.SetCamera(ren2.GetActiveCamera()); axes2.SetLabelFormat("%6.4g"); axes2.SetFlyModeToClosestTriad(); axes2.SetFontFactor(0.8); axes2.ScalingOff(); axes2.SetAxisTitleTextProperty(tprop); axes2.SetAxisLabelTextProperty(tprop); ren2.AddViewProp(axes2); renWin.AddObserver((uint) EventIds.AbortCheckEvent, CheckAbort); iren.Initialize(); renWin.Render(); iren.Start(); vtkWin32OpenGLRenderWindow win32win = vtkWin32OpenGLRenderWindow.SafeDownCast(renWin); if (null != win32win) win32win.Clean(); }
public static int Main(string[] args) { string filename = args[0]; vtkGDCMImageReader reader = vtkGDCMImageReader.New(); vtkStringArray array = vtkStringArray.New(); array.InsertNextValue(filename); reader.SetFileNames(array); reader.Update(); //System.Console.Write(reader.GetOutput()); vtkRenderWindowInteractor iren = vtkRenderWindowInteractor.New(); vtkImageViewer2 viewer = vtkImageViewer2.New(); viewer.SetInput(reader.GetOutput()); viewer.SetupInteractor(iren); viewer.SetSize(600, 600); viewer.Render(); iren.Initialize(); iren.Start(); return(0); }
// Draw xyz axis private void xyzToolStripMenuItem_Click(object sender, EventArgs e) { if (null == axesWidget) { vtkAxesActor axes = new vtkAxesActor(); axesWidget = new vtkOrientationMarkerWidget(); axesWidget.SetOutlineColor(0.9300, 0.5700, 0.1300); axesWidget.SetOrientationMarker(axes); axesWidget.SetInteractor(Interactor); axesWidget.SetViewport(0.0, 0.0, 0.2, 0.2); axesWidget.SetEnabled(1); axesWidget.InteractiveOn(); // Begin mouse interaction Interactor.Start(); } else if (axesWidget.GetEnabled() != 0) { axesWidget.EnabledOff(); } else { axesWidget.EnabledOn(); } m_Renderer.ResetCamera(); m_RenderWindow.Render(); }
static private void init() { vtkSTLReader rdr = vtkSTLReader.New(); rdr.SetFileName("BODY-EXTRUDEUR-WADE.stl"); // Créer une géométrie sphérique /*vtkSphereSource sphere = vtkSphereSource.New(); * sphere.SetRadius(1.0); * sphere.SetThetaResolution(18); * sphere.SetPhiResolution(18);*/ // Transforme la géométrie en primitives graphiques (OpenGL dans notre cas) vtkPolyDataMapper map = vtkPolyDataMapper.New(); map.SetInput(rdr.GetOutput()); // L'acteur représente l'entitée géométrique. // Il permet de définir sa position, son orientation, sa couleur, etc. vtkActor aSphere = new vtkActor(); aSphere.SetMapper(map); aSphere.GetProperty().SetColor(0.8, 0.8, 0.8); // color blue // Nous créons un renderer qui va faire le rendu de notre entitée. vtkRenderer ren1 = vtkRenderer.New(); ren1.AddActor(aSphere); ren1.SetBackground(1, 1, 1); // background color white // Nous créons une fenêtre de rendu vtkRenderWindow renWin = vtkRenderWindow.New(); renWin.AddRenderer(ren1); renWin.SetSize(300, 300); // Nous créons un interactor qui permet de bouger la caméra. vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow(renWin); // Nous lançons le rendu et l'interaction renWin.Render(); iren.Start(); ////// CLEANUP /////// rdr.Dispose(); map.Dispose(); aSphere.Dispose(); ren1.Dispose(); renWin.Dispose(); iren.Dispose(); }
/// <summary> /// Crée les objets de base : renderer, axes, interactor. /// </summary> private void initBaseObjects() { // Nous créons un renderer qui va faire le rendu de notre entitée. _renderer = vtkRenderer.New(); _stlLoader = new STLLoader(this._renderer); _stlLoader.VolumeColor = Properties.Settings.Default.VolumeColor; _stlLoader.EdgeColor = Properties.Settings.Default.EdgeColor; _stlLoader.ShowVolume = Properties.Settings.Default.ShowVolume; _stlLoader.ShowEdges = Properties.Settings.Default.ShowEdges; this.aretesToolStripMenuItem.Checked = (bool)loadSetting("ShowEdges"); this.volumeToolStripMenuItem.Checked = (bool)loadSetting("ShowVolume"); _renderer.SetBackground(1, 1, 1); // background color white vtkRenderCtl.RenderWindow.AddRenderer(_renderer); // Nous créons un interactor qui permet de bouger la caméra. _interactor = vtkRenderWindowInteractor.New(); _interactor.SetRenderWindow(vtkRenderCtl.RenderWindow); //axes vtkAxes axes = vtkAxes.New(); axes.SetScaleFactor(10); addActor(axes.GetOutput()); /* * //outil de mesure * vtkDistanceWidget wdgDistance = vtkDistanceWidget.New(); * wdgDistance.SetInteractor(_interactor); * wdgDistance.CreateDefaultRepresentation(); * ((vtkDistanceRepresentation)wdgDistance.GetRepresentation()).SetLabelFormat("%-#6.3g mm"); * wdgDistance.On(); */ Camera.SetPosition(0, 0, -300); vtkRenderCtl.RenderWindow.Render(); _interactor.RenderEvt += _interactor_RenderEvt; vtkInteractorStyleSwitch style = vtkInteractorStyleSwitch.New(); style.SetCurrentStyleToTrackballCamera(); _interactor.SetInteractorStyle(style); _interactor.Start(); }
// Static void method with same signature as "Main" is always // file base name: // /// <summary> /// VTK test Main method /// </summary> public static void vtkConeSourceTest(string[] args) { bool interactive = false; foreach (string s in args) { // -I means "interactive" test -- do not automatically quit: // if (s == "-I") { interactive = true; } } vtkConeSource source = new vtkConeSource(); vtkMapper mapper = vtkPolyDataMapper.New(); mapper.SetInputConnection(source.GetOutputPort()); vtkActor actor = new vtkActor(); actor.SetMapper(mapper); vtkRenderer ren1 = vtkRenderer.New(); ren1.AddActor(actor); ren1.SetBackground(0.1, 0.2, 0.4); vtkRenderWindow renWin = vtkRenderWindow.New(); renWin.AddRenderer(ren1); renWin.SetSize(400, 300); vtkRenderWindowInteractor iren = vtkRenderWindowInteractor.New(); iren.SetRenderWindow(renWin); iren.Initialize(); Kitware.mummy.Runtime.Methods.Print(false); Kitware.mummy.Runtime.Methods.PrintWrappedObjectsTable(); if (interactive) { iren.Start(); } ren1.SetRenderWindow(null); iren.SetRenderWindow(null); renWin.Dispose(); }
///<summary>Entry Point</summary> static void Main(string[] args) { // Create a simple sphere. A pipeline is created. sphere = vtkSphereSource.New(); sphere.SetThetaResolution(8); sphere.SetPhiResolution(16); shrink = vtkShrinkPolyData.New(); shrink.SetInputConnection(sphere.GetOutputPort()); shrink.SetShrinkFactor(0.9); mapper = vtkPolyDataMapper.New(); mapper.SetInputConnection(shrink.GetOutputPort()); // The actor links the data pipeline to the rendering subsystem actor = vtkActor.New(); actor.SetMapper(mapper); actor.GetProperty().SetColor(1, 0, 0); // Create components of the rendering subsystem // ren1 = vtkRenderer.New(); renWin = vtkRenderWindow.New(); renWin.AddRenderer(ren1); iren = vtkRenderWindowInteractor.New(); iren.SetRenderWindow(renWin); // Add the actors to the renderer, set the window size // ren1.AddViewProp(actor); renWin.SetSize(250, 250); renWin.Render(); camera = ren1.GetActiveCamera(); camera.Zoom(1.5); // render the image and start the event loop // renWin.Render(); iren.Initialize(); iren.Start(); deleteAllVTKObjects(); }
public static int Main(string[] args) { vtkTesting testHelper = vtkTesting.New(); for (int cc = 0; cc < args.Length; cc++) { //testHelper.AddArguments(argc,const_cast<const char **>(argv)); //System.Console.Write( "args: " + args[cc] + "\n" ); testHelper.AddArgument(args[cc]); } if (testHelper.IsFlagSpecified("-D") != 0) { string VTK_DATA_ROOT = vtkGDCMTesting.GetVTKDataRoot(); if (VTK_DATA_ROOT != null) { //System.Console.Write( "VTK_DATA_ROOT: " + VTK_DATA_ROOT + "\n" ); testHelper.SetDataRoot(VTK_DATA_ROOT); testHelper.AddArgument("-D"); testHelper.AddArgument(VTK_DATA_ROOT); } } string dataRoot = testHelper.GetDataRoot(); string filename = dataRoot; filename += "/Data/mr.001"; vtkDirectory dir = vtkDirectory.New(); if (dir.FileIsDirectory(dataRoot) == 0) { filename = vtkGDCMTesting.GetGDCMDataRoot() + "/test.acr"; } //System.Console.Write( "dataRoot: " + dataRoot + "\n" ); System.Console.Write("filename being used is: " + filename + "\n"); vtkGDCMImageReader reader = vtkGDCMImageReader.New(); vtkStringArray array = vtkStringArray.New(); array.InsertNextValue(filename); reader.SetFileNames(array); reader.Update(); System.Console.Write(reader.GetOutput()); vtkRenderWindowInteractor iren = vtkRenderWindowInteractor.New(); vtkRenderer ren1 = vtkRenderer.New(); vtkRenderWindow renWin = vtkRenderWindow.New(); renWin.AddRenderer(ren1); vtkImageActor actor = vtkImageActor.New(); vtkImageMapToWindowLevelColors coronalColors = vtkImageMapToWindowLevelColors.New(); coronalColors.SetInput(reader.GetOutput()); actor.SetInput(coronalColors.GetOutput()); ren1.AddActor(actor); iren.SetRenderWindow(renWin); iren.Initialize(); renWin.Render(); int retVal = testHelper.IsInteractiveModeSpecified(); if (retVal != 0) { iren.Start(); } return(0); }
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(); }
/// <summary> /// Entry Point /// </summary> /// <param name="argv"></param> public static void Main(String[] argv) { // This example demonstrates how to use 2D Delaunay triangulation. // We create a fancy image of a 2D Delaunay triangulation. Points are // randomly generated. // first we load in the standard vtk packages into tcl // Generate some random points math = vtkMath.New(); points = vtkPoints.New(); for(int i = 0; i < 50; i++) { points.InsertPoint(i, vtkMath.Random(0, 1), vtkMath.Random(0, 1), 0.0); } // Create a polydata with the points we just created. profile = vtkPolyData.New(); profile.SetPoints(points); // Perform a 2D Delaunay triangulation on them. del = vtkDelaunay2D.New(); del.SetInput(profile); del.SetTolerance(0.001); mapMesh = vtkPolyDataMapper.New(); mapMesh.SetInputConnection(del.GetOutputPort()); meshActor = vtkActor.New(); meshActor.SetMapper(mapMesh); meshActor.GetProperty().SetColor(.1, .2, .4); // We will now create a nice looking mesh by wrapping the edges in tubes, // and putting fat spheres at the points. extract = vtkExtractEdges.New(); extract.SetInputConnection(del.GetOutputPort()); tubes = vtkTubeFilter.New(); tubes.SetInputConnection(extract.GetOutputPort()); tubes.SetRadius(0.01); tubes.SetNumberOfSides(6); mapEdges = vtkPolyDataMapper.New(); mapEdges.SetInputConnection(tubes.GetOutputPort()); edgeActor = vtkActor.New(); edgeActor.SetMapper(mapEdges); edgeActor.GetProperty().SetColor(0.2000, 0.6300, 0.7900); edgeActor.GetProperty().SetSpecularColor(1, 1, 1); edgeActor.GetProperty().SetSpecular(0.3); edgeActor.GetProperty().SetSpecularPower(20); edgeActor.GetProperty().SetAmbient(0.2); edgeActor.GetProperty().SetDiffuse(0.8); ball = vtkSphereSource.New(); ball.SetRadius(0.025); ball.SetThetaResolution(12); ball.SetPhiResolution(12); balls = vtkGlyph3D.New(); balls.SetInputConnection(del.GetOutputPort()); balls.SetSourceConnection(ball.GetOutputPort()); mapBalls = vtkPolyDataMapper.New(); mapBalls.SetInputConnection(balls.GetOutputPort()); ballActor = vtkActor.New(); ballActor.SetMapper(mapBalls); ballActor.GetProperty().SetColor(1.0000, 0.4118, 0.7059); ballActor.GetProperty().SetSpecularColor(1, 1, 1); ballActor.GetProperty().SetSpecular(0.3); ballActor.GetProperty().SetSpecularPower(20); ballActor.GetProperty().SetAmbient(0.2); ballActor.GetProperty().SetDiffuse(0.8); // Create graphics objects // Create the rendering window, renderer, and interactive renderer ren1 = vtkRenderer.New(); renWin = vtkRenderWindow.New(); renWin.AddRenderer(ren1); iren = vtkRenderWindowInteractor.New(); iren.SetRenderWindow(renWin); // Add the actors to the renderer, set the background and size ren1.AddActor(ballActor); ren1.AddActor(edgeActor); ren1.SetBackground(1, 1, 1); renWin.SetSize(150, 150); // render the image ren1.ResetCamera(); ren1.GetActiveCamera().Zoom(1.5); iren.Initialize(); iren.Start(); // Clean Up deleteAllVTKObjects(); }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void Main(String[] argv) { try { bool fail_on_image_diff = false; //Prefix Content is: "" int argc = 0; if (argv != null) { argc = argv.Length; } // setup some common things for testing[] vtkMath.RandomSeed(6); // create the testing class to do the work[] rtTester = new vtkTesting(); for (int i = 1; i < argc; i++) { rtTester.AddArgument(argv[i]); if (argv[i] == "--fail-on-image-diff") { fail_on_image_diff = true; } } // string auto_path = ""; // VTK_DATA_ROOT = rtTester.GetDataRoot(); // load in the script[] if (0 == argv.Length) { test = GetTestNameInteractively(); } else { test = argv[0]; } //The class that we are about to execute the test in System.Type t = System.Type.GetType(test + "Class"); if (null == t) { throw new System.ArgumentException(System.String.Format( "error: could not create a Type object for '{0}'...\n\n{1}\n{2}\n{3}\n{4}\n\n{5}\n\n", test + "Class", "Typo?", "Did you follow the C# test driver naming convention?", "Did you add the test to the CMakeLists.txt file?", "Did you reconfigure/rebuild after adding the test?", "Test 'method' name should equal 'file name without extension'... Test 'public class' name should be the same but with 'Class' appended..." )); } // set the default threshold, the Tcl script may change this[] threshold = -1; executeMethod(t, "Setthreshold", new object[] { threshold }); executeMethod(t, "SetVTK_DATA_ROOT", new object[] { VTK_DATA_ROOT }); //run the test executeMethod(t, test, new object[] { argv }); tempRenderWindowInteractor = (vtkRenderWindowInteractor)executeMethod(t, "Getiren", new object[] { }); tempRenderWindow = (vtkRenderWindow)executeMethod(t, "GetrenWin", new object[] { }); tempViewer = (vtkObject)executeMethod(t, "Getviewer", new object[] { }); tempw2i = (vtkWindowToImageFilter)executeMethod(t, "Getw2i", new object[] { }); //update the threshold from what the test made it threshold = (int)executeMethod(t, "Getthreshold", new object[] { }); if (tempRenderWindowInteractor != null) { tempRenderWindow.Render(); } // run the event loop quickly to map any tkwidget windows[] // current directory[] rtResult = 0; if (fail_on_image_diff && rtTester.IsValidImageSpecified() != 0) { // look for a renderWindow ImageWindow or ImageViewer[] // first check for some common names[] if (tempRenderWindow != null) { rtTester.SetRenderWindow(tempRenderWindow); if ((threshold) == -1) { threshold = 10; } } else { if ((threshold) == -1) { threshold = 5; } if (tempViewer != null) { if (tempViewer.IsA("vtkImageViewer") != 0) { tempRenderWindow = ((vtkImageViewer)tempViewer).GetRenderWindow(); } else if (tempViewer.IsA("vtkImageViewer2") != 0) { tempRenderWindow = ((vtkImageViewer2)tempViewer).GetRenderWindow(); } else { throw new System.Exception(""); } rtTester.SetRenderWindow(tempRenderWindow); if (tempViewer.IsA("vtkImageViewer") != 0) { ((vtkImageViewer)tempViewer).Render(); } else if (tempViewer.IsA("vtkImageViewer2") != 0) { ((vtkImageViewer2)tempViewer).Render(); } } else { tempRenderWindow = (vtkRenderWindow)executeMethod(t, "GetimgWin", new object[] { }); if (tempRenderWindow != null) { rtTester.SetRenderWindow(tempRenderWindow); tempRenderWindow.Render(); } } } if (tempRenderWindow == null) { throw new System.Exception("tempRenderWindow cannot be null for IsValidImageSpecified case..."); } rtResult = rtTester.RegressionTest(threshold); } if (rtTester.IsInteractiveModeSpecified() != 0) { if (tempRenderWindowInteractor != null) { tempRenderWindowInteractor.Start(); } } // Force other objects that may have holds on the render window // to let go: // rtTester.SetRenderWindow(null); if (null != tempw2i) { tempw2i.SetInput(null); } executeMethod(t, "deleteAllVTKObjects", new object[] { }); deleteAllVTKObjects(); // Force a garbage collection prior to exiting the test // so that any memory leaks reported are likely to be // *actual* leaks of some sort rather than false reports: // System.GC.Collect(); System.GC.WaitForPendingFinalizers(); // Fail the tests that have image diffs if fail_on_image_diff is on: // if (fail_on_image_diff && 0 == rtResult) { throw new System.Exception("error: image RegressionTest failed"); } // Test finished without throwing any exceptions... // Therefore, it passed. Exit with a zero ExitCode. // System.Environment.ExitCode = 0; } catch (System.Exception exc) { // Catch anything, spit it out to the console so it can be captured // by ctest. Exit with a non-zero ExitCode. // System.Console.Error.WriteLine("================================================================================"); System.Console.Error.WriteLine(""); System.Console.Error.WriteLine("TclToCsScript C# test driver caught System.Exception:"); System.Console.Error.WriteLine(""); System.Console.Error.WriteLine("{0}", exc.ToString()); System.Console.Error.WriteLine(""); System.Console.Error.WriteLine("================================================================================"); System.Console.Error.WriteLine(""); System.Environment.ExitCode = 2345; } }
//vtkRenderWindow RenderWindow; private void GenerateGraph() { // get a reference to the renderwindow of our renderWindowControl1 vtkRenderWindow RenderWindow = renderWindowControl1.RenderWindow; //renWin = vtkRenderWindow.New(); RenderWindow.LineSmoothingOn(); RenderWindow.PointSmoothingOn(); // RenderWindow.SetWindowName("3D World"); // RenderWindow.BordersOn(); RenderWindow.DoubleBufferOn(); //RenderWindow.SetSize(WinPos[0], WinPos[1]); //this.ren1 = vtkRenderer.New(); // this.Input.renWin = RenderWindow; this.Input.AssociatedVTKRenderer = RenderWindow.GetRenderers().GetFirstRenderer(); //Input.AssociatedVTKRenderer = this.Input.AssociatedVTKRenderer; Input.AssociatedrenderWindow = renderWindowControl1; foreach (var item in this.Input.ListObject) { item.AddMeToTheWorld(this.Input.AssociatedVTKRenderer); } foreach (var item in this.Input.ListVolume) { item.AddMeToTheWorld(this.Input.AssociatedVTKRenderer); } foreach (var item in this.Input.ListLights) { item.AddMeToTheWorld(this.Input.AssociatedVTKRenderer); } RenderWindow.AddRenderer(this.Input.AssociatedVTKRenderer); iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow(RenderWindow); // iren.SetInteractorStyle(vtkInteractorStyleJoystickCamera.New()); iren.SetInteractorStyle(vtkInteractorStyleTrackballCamera.New()); // iren.SetInteractorStyle(vtkInteractorStyleTrackballActor.New()); iren.Start(); // iren.SetInteractorStyle(vtkInteractorStyleTerrain.New()); // iren.LeftButtonPressEvt += new vtkObject.vtkObjectEventHandler(RenderWindow_LeftButtonPressEvt); iren.KeyPressEvt += new vtkObject.vtkObjectEventHandler(RenderWindow_KeyPressEvt); iren.RightButtonPressEvt += new vtkObject.vtkObjectEventHandler(RenderWindow_RightButtonPressEvt); this.Input.AssociatedVTKRenderer.SetBackground(this.Input.BackGroundColor.R / 255.0, this.Input.BackGroundColor.G / 255.0, this.Input.BackGroundColor.B / 255.0); this.Input.AssociatedVTKRenderer.SetActiveCamera(this.Input.Vtk_CameraView); // Setup offscreen rendering //vtkGraphicsFactory graphics_factory = vtkGraphicsFactory.New(); // graphics_factory.SetOffScreenOnlyMode( 1); // graphics_factory.SetUseMesaClasses( 1 ); // vtkImagingFactory imaging_factory = vtkImagingFactory.New(); // imaging_factory.SetUseMesaClasses( 1 ); // A renderer and render window // vtkRenderer renderer = vtkRenderer.New(); //vtkRenderWindow renderWindow = // vtkRenderWindow.New(); // RenderWindow.SetOffScreenRendering(1); //renderWindow.AddRenderer(renderer); RenderWindow.Render(); //vtkWindowToImageFilter windowToImageFilter = // vtkWindowToImageFilter.New(); //windowToImageFilter.SetInput(RenderWindow); //windowToImageFilter.Update(); //vtkPNGWriter writer = // vtkPNGWriter.New(); //writer.SetFileName("screenshot1.png"); //writer.SetInputConnection(windowToImageFilter.GetOutputPort()); //writer.Write(); //Renderer.ResetCamera(); // Input.Render(); }
/// <summary> /// A console application that creates a /// vtkRenderWindow without a Windows Form /// </summary> /// <param name="argv"></param> public static void Main(String[] argv) { // Demonstrate how to use the vtkBoxWidget 3D widget, // This script uses a 3D box widget to define a "clipping box" to clip some // simple geometry (a mace). Make sure that you hit the "W" key to activate the widget. // Create a mace out of filters. sphere = vtkSphereSource.New(); cone = vtkConeSource.New(); glyph = vtkGlyph3D.New(); glyph.SetInputConnection(sphere.GetOutputPort()); glyph.SetSource(cone.GetOutput()); glyph.SetVectorModeToUseNormal(); glyph.SetScaleModeToScaleByVector(); glyph.SetScaleFactor(0.25); // The sphere and spikes are appended into a single polydata. This just makes things // simpler to manage. apd = vtkAppendPolyData.New(); apd.AddInput(glyph.GetOutput()); apd.AddInput(sphere.GetOutput()); maceMapper = vtkPolyDataMapper.New(); maceMapper.SetInputConnection(apd.GetOutputPort()); maceActor = vtkLODActor.New(); maceActor.SetMapper(maceMapper); maceActor.VisibilityOn(); // This portion of the code clips the mace with the vtkPlanes implicit function. // The clipped region is colored green. planes = vtkPlanes.New(); clipper = vtkClipPolyData.New(); clipper.SetInputConnection(apd.GetOutputPort()); clipper.SetClipFunction(planes); clipper.InsideOutOn(); selectMapper = vtkPolyDataMapper.New(); selectMapper.SetInputConnection(clipper.GetOutputPort()); selectActor = vtkLODActor.New(); selectActor.SetMapper(selectMapper); selectActor.GetProperty().SetColor(0, 1, 0); selectActor.VisibilityOff(); selectActor.SetScale(1.01, 1.01, 1.01); // Create the RenderWindow, Renderer and both Actors ren1 = vtkRenderer.New(); renWin = vtkRenderWindow.New(); renWin.AddRenderer(ren1); iren = vtkRenderWindowInteractor.New(); iren.SetRenderWindow(renWin); // The SetInteractor method is how 3D widgets are associated with the render // window interactor. Internally, SetInteractor sets up a bunch of callbacks // using the Command/Observer mechanism (AddObserver()). boxWidget = vtkBoxWidget.New(); boxWidget.SetInteractor(iren); boxWidget.SetPlaceFactor(1.25); ren1.AddActor(maceActor); ren1.AddActor(selectActor); // Add the actors to the renderer, set the background and size ren1.SetBackground(0.1, 0.2, 0.4); renWin.SetSize(300, 300); // Place the interactor initially. The input to a 3D widget is used to // initially position and scale the widget. The EndInteractionEvent is // observed which invokes the SelectPolygons callback. boxWidget.SetInput(glyph.GetOutput()); boxWidget.PlaceWidget(); boxWidget.EndInteractionEvt += new vtkObject.vtkObjectEventHandler(SelectPolygons); // render the image iren.Initialize(); iren.Start(); //Clean up deleteAllVTKObjects(); }
/// <summary> /// Entry Point /// </summary> /// <param name="argv"></param> public static void Main(String[] argv) { // This example demonstrates how to use the vtkLineWidget to seed // and manipulate streamlines. Two line widgets are created. One is // invoked by pressing 'W', the other by pressing 'L'. Both can exist // together. // Start by loading some data. pl3d = vtkMultiBlockPLOT3DReader.New(); pl3d.SetXYZFileName("../../../combxyz.bin"); pl3d.SetQFileName("../../../combq.bin"); pl3d.SetScalarFunctionNumber(100); pl3d.SetVectorFunctionNumber(202); pl3d.Update(); // The line widget is used seed the streamlines. lineWidget = vtkLineWidget.New(); seeds = vtkPolyData.New(); lineWidget.SetInput(pl3d.GetOutput()); lineWidget.SetAlignToYAxis(); lineWidget.PlaceWidget(); lineWidget.GetPolyData(seeds); lineWidget.ClampToBoundsOn(); rk4 = vtkRungeKutta4.New(); streamer = vtkStreamLine.New(); streamer.SetInputData((vtkDataSet)pl3d.GetOutput().GetBlock(0)); streamer.SetSource(seeds); streamer.SetMaximumPropagationTime(100); streamer.SetIntegrationStepLength(.2); streamer.SetStepLength(.001); streamer.SetNumberOfThreads(1); streamer.SetIntegrationDirectionToForward(); streamer.VorticityOn(); streamer.SetIntegrator(rk4); rf = vtkRibbonFilter.New(); rf.SetInputConnection(streamer.GetOutputPort()); rf.SetWidth(0.1); rf.SetWidthFactor(5); streamMapper = vtkPolyDataMapper.New(); streamMapper.SetInputConnection(rf.GetOutputPort()); streamMapper.SetScalarRange(pl3d.GetOutput().GetScalarRange()[0], pl3d.GetOutput().GetScalarRange()[1]); streamline = vtkActor.New(); streamline.SetMapper(streamMapper); streamline.VisibilityOff(); // The second line widget is used seed more streamlines. lineWidget2 = vtkLineWidget.New(); seeds2 = vtkPolyData.New(); lineWidget2.SetInput(pl3d.GetOutput()); lineWidget2.PlaceWidget(); lineWidget2.GetPolyData(seeds2); lineWidget2.SetKeyPressActivationValue((sbyte)108); streamer2 = vtkStreamLine.New(); streamer2.SetInputDaat((vtkDataSet)pl3d.GetOutput().GetBlock(0)); streamer2.SetSource(seeds2); streamer2.SetMaximumPropagationTime(100); streamer2.SetIntegrationStepLength(.2); streamer2.SetStepLength(.001); streamer2.SetNumberOfThreads(1); streamer2.SetIntegrationDirectionToForward(); streamer2.VorticityOn(); streamer2.SetIntegrator(rk4); rf2 = vtkRibbonFilter.New(); rf2.SetInputConnection(streamer2.GetOutputPort()); rf2.SetWidth(0.1); rf2.SetWidthFactor(5); streamMapper2 = vtkPolyDataMapper.New(); streamMapper2.SetInputConnection(rf2.GetOutputPort()); streamMapper2.SetScalarRange(pl3d.GetOutput().GetScalarRange()[0], pl3d.GetOutput().GetScalarRange()[1]); streamline2 = vtkActor.New(); streamline2.SetMapper(streamMapper2); streamline2.VisibilityOff(); outline = vtkStructuredGridOutlineFilter.New(); outline.SetInputData((vtkDataSet)pl3d.GetOutput().GetBlock(0)); outlineMapper = vtkPolyDataMapper.New(); outlineMapper.SetInputConnection(outline.GetOutputPort()); outlineActor = vtkActor.New(); outlineActor.SetMapper(outlineMapper); // Create the RenderWindow, Renderer and both Actors ren1 = vtkRenderer.New(); renWin = vtkRenderWindow.New(); renWin.AddRenderer(ren1); iren = vtkRenderWindowInteractor.New(); iren.SetRenderWindow(renWin); // Associate the line widget with the interactor lineWidget.SetInteractor(iren); lineWidget.StartInteractionEvt += new vtkObject.vtkObjectEventHandler(BeginInteraction); lineWidget.InteractionEvt += new vtkObject.vtkObjectEventHandler(GenerateStreamlines); lineWidget2.SetInteractor(iren); lineWidget2.StartInteractionEvt += new vtkObject.vtkObjectEventHandler(BeginInteraction2); lineWidget2.EndInteractionEvt += new vtkObject.vtkObjectEventHandler(GenerateStreamlines2); // Add the actors to the renderer, set the background and size ren1.AddActor(outlineActor); ren1.AddActor(streamline); ren1.AddActor(streamline2); ren1.SetBackground(1, 1, 1); renWin.SetSize(300, 300); ren1.SetBackground(0.1, 0.2, 0.4); cam1 = ren1.GetActiveCamera(); cam1.SetClippingRange(3.95297, 50); cam1.SetFocalPoint(9.71821, 0.458166, 29.3999); cam1.SetPosition(2.7439, -37.3196, 38.7167); cam1.SetViewUp(-0.16123, 0.264271, 0.950876); // render the image renWin.Render(); lineWidget2.On(); iren.Initialize(); iren.Start(); //Clean Up deleteAllVTKObjects(); }
/// <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> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void Main(String[] argv) { try { bool fail_on_image_diff = false; //Prefix Content is: "" int argc = 0; if (argv != null) { argc = argv.Length; } // setup some common things for testing[] vtkMath.RandomSeed(6); // create the testing class to do the work[] rtTester = new vtkTesting(); for (int i = 1; i < argc; i++) { rtTester.AddArgument(argv[i]); if (argv[i] == "--fail-on-image-diff") { fail_on_image_diff = true; } } // string auto_path = ""; // VTK_DATA_ROOT = rtTester.GetDataRoot(); // load in the script[] if (0 == argv.Length) { test = GetTestNameInteractively(); } else { test = argv[0]; } //The class that we are about to execute the test in System.Type t = System.Type.GetType(test + "Class"); if (null == t) { throw new System.ArgumentException(System.String.Format( "error: could not create a Type object for '{0}'...\n\n{1}\n{2}\n{3}\n{4}\n\n{5}\n\n", test + "Class", "Typo?", "Did you follow the C# test driver naming convention?", "Did you add the test to the CMakeLists.txt file?", "Did you reconfigure/rebuild after adding the test?", "Test 'method' name should equal 'file name without extension'... Test 'public class' name should be the same but with 'Class' appended..." )); } // set the default threshold, the Tcl script may change this[] threshold = -1; executeMethod(t, "Setthreshold", new object[] { threshold }); executeMethod(t, "SetVTK_DATA_ROOT", new object[] { VTK_DATA_ROOT }); //run the test executeMethod(t, test, new object[] { argv }); tempRenderWindowInteractor = (vtkRenderWindowInteractor)executeMethod(t, "Getiren", new object[] { }); tempRenderWindow = (vtkRenderWindow)executeMethod(t, "GetrenWin", new object[] { }); tempViewer = (vtkObject)executeMethod(t, "Getviewer", new object[] { }); tempw2i = (vtkWindowToImageFilter)executeMethod(t, "Getw2i", new object[] { }); //update the threshold from what the test made it threshold = (int)executeMethod(t, "Getthreshold", new object[] { }); if (tempRenderWindowInteractor != null) { tempRenderWindow.Render(); } // run the event loop quickly to map any tkwidget windows[] // current directory[] rtResult = 0; if (fail_on_image_diff && rtTester.IsValidImageSpecified() != 0) { // look for a renderWindow ImageWindow or ImageViewer[] // first check for some common names[] if (tempRenderWindow != null) { rtTester.SetRenderWindow(tempRenderWindow); if ((threshold) == -1) { threshold = 10; } } else { if ((threshold) == -1) { threshold = 5; } if (tempViewer != null) { if (tempViewer.IsA("vtkImageViewer") != 0) { tempRenderWindow = ((vtkImageViewer)tempViewer).GetRenderWindow(); } else if (tempViewer.IsA("vtkImageViewer2") != 0) { tempRenderWindow = ((vtkImageViewer2)tempViewer).GetRenderWindow(); } else { throw new System.Exception(""); } rtTester.SetRenderWindow(tempRenderWindow); if (tempViewer.IsA("vtkImageViewer") != 0) { ((vtkImageViewer)tempViewer).Render(); } else if (tempViewer.IsA("vtkImageViewer2") != 0) { ((vtkImageViewer2)tempViewer).Render(); } } else { tempRenderWindow = (vtkRenderWindow)executeMethod(t, "GetimgWin", new object[] { }); if (tempRenderWindow != null) { rtTester.SetRenderWindow(tempRenderWindow); tempRenderWindow.Render(); } } } if (tempRenderWindow == null) { throw new System.Exception("tempRenderWindow cannot be null for IsValidImageSpecified case..."); } rtResult = rtTester.RegressionTest(threshold); } if (rtTester.IsInteractiveModeSpecified() != 0) { if (tempRenderWindowInteractor != null) { tempRenderWindowInteractor.Start(); } } // Force other objects that may have holds on the render window // to let go: // rtTester.SetRenderWindow(null); if (null != tempw2i) { tempw2i.SetInput(null); } executeMethod(t, "deleteAllVTKObjects", new object[] { }); deleteAllVTKObjects(); // Force a garbage collection prior to exiting the test // so that any memory leaks reported are likely to be // *actual* leaks of some sort rather than false reports: // System.GC.Collect(); System.GC.WaitForPendingFinalizers(); // Fail the tests that have image diffs if fail_on_image_diff is on: // if (fail_on_image_diff && 0 == rtResult) { throw new System.Exception("error: image RegressionTest failed"); } // Test finished without throwing any exceptions... // Therefore, it passed. Exit with a zero ExitCode. // System.Environment.ExitCode = 0; } catch (System.Exception exc) { // Catch anything, spit it out to the console so it can be captured // by ctest. Exit with a non-zero ExitCode. // System.Console.Error.WriteLine("================================================================================"); System.Console.Error.WriteLine(""); System.Console.Error.WriteLine("TclToCsScript C# test driver caught System.Exception:"); System.Console.Error.WriteLine(""); System.Console.Error.WriteLine("{0}", exc.ToString()); System.Console.Error.WriteLine(""); System.Console.Error.WriteLine("================================================================================"); System.Console.Error.WriteLine(""); System.Environment.ExitCode = 2345; } }
int build3DViewFull() { Kitware.VTK.RenderWindowControl rw = new Kitware.VTK.RenderWindowControl(); vtkRenderWindow _renwin = rw.RenderWindow; vtkRenderer _render = _renwin.GetRenderers().GetFirstRenderer(); _renwin.AddRenderer(_render); vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow(_renwin); // 新建文件读取对象,常见的有vtkBMPReader、vtkDICOMImageReader、vtkJPEGReader等 vtkJPEGReader jpegReader = new vtkJPEGReader(); // 不同的reader需要设置的参数是不同的 因此本例仅适合jpegreader jpegReader.SetFilePrefix("C:/Users/DawnWind/Desktop/000/"); // 要打开的路径 jpegReader.SetFilePattern("%s%d.jpg"); // 图片文件名格式,此处为 0.jpg 1.jpg ... jpegReader.SetDataByteOrderToLittleEndian(); jpegReader.SetDataSpacing(1, 1, 1.4); // 设置图片中像素比,我理解得不清楚,具体请百度之 jpegReader.SetFileNameSliceSpacing(1); jpegReader.SetDataExtent(0, 209, 0, 209, 0, 29); // 这里因为在000文件夹里面有0.jpg ~ 29.jpg,所以设置为 0,29 // 每张图片的长宽为210 * 210 因此设置为0,209 jpegReader.Update(); // update这里要注意一下,对于VTK在默认情况下是在最后操作时候才一次性刷新 // 也就是说如果没有自动刷新的话,在一些中间过程中是无法获得到数据的,因为没update进去 vtkContourFilter skinExtractor = new vtkContourFilter(); skinExtractor.SetInputConnection(jpegReader.GetOutputPort()); skinExtractor.SetValue(200, 100); //值越大,保留的部分越少。 //重新计算法向量 vtkPolyDataNormals skinNormals = new vtkPolyDataNormals(); skinNormals.SetInputConnection(skinExtractor.GetOutputPort()); skinNormals.SetFeatureAngle(60.0); //Specify the angle that defines a sharp edge. //If the difference in angle across neighboring polygons is greater than this value, //the shared edge is considered "sharp". //create triangle strips and/or poly-lines 为了更快的显示速度 vtkStripper skinStripper = new vtkStripper(); skinStripper.SetInputConnection(skinNormals.GetOutputPort()); vtkPolyDataMapper skinMapper = new vtkPainterPolyDataMapper(); skinMapper.SetInputConnection(skinStripper.GetOutputPort()); skinMapper.ScalarVisibilityOff(); //这样不会带颜色 vtkActor skin = new vtkActor(); skin.SetMapper(skinMapper); // An outline provides context around the data. // 一个围绕在物体的立体框,可以先忽略 /* * vtkOutlineFilter> outlineData = * vtkOutlineFilter>::New(); * outlineData.SetInputConnection(dicomReader.GetOutputPort()); * * vtkPolyDataMapper> mapOutline = * vtkPolyDataMapper>::New(); * mapOutline.SetInputConnection(outlineData.GetOutputPort()); * * vtkActor> outline = * vtkActor>::New(); * outline.SetMapper(mapOutline); * outline.GetProperty().SetColor(0,0,0); * * aRenderer.AddActor(outline); */ // It is convenient to create an initial view of the data. The FocalPoint // and Position form a vector direction. Later on (ResetCamera() method) // this vector is used to position the camera to look at the data in // this direction. vtkCamera aCamera = new vtkCamera(); aCamera.SetViewUp(0, 0, -1); aCamera.SetPosition(0, 1, 0); aCamera.SetFocalPoint(0, 0, 0); aCamera.ComputeViewPlaneNormal(); aCamera.Azimuth(30.0); aCamera.Elevation(30.0); // Actors are added to the renderer. An initial camera view is created. // The Dolly() method moves the camera towards the FocalPoint, // thereby enlarging the image. _render.AddActor(skin); _render.SetActiveCamera(aCamera); _render.ResetCamera(); aCamera.Dolly(1.5); // Set a background color for the renderer and set the size of the // render window (expressed in pixels). _render.SetBackground(.2, .3, .4); _renwin.SetSize(640, 480); // Note that when camera movement occurs (as it does in the Dolly() // method), the clipping planes often need adjusting. Clipping planes // consist of two planes: near and far along the view direction. The // near plane clips out objects in front of the plane; the far plane // clips out objects behind the plane. This way only what is drawn // between the planes is actually rendered. _render.ResetCameraClippingRange(); // Initialize the event loop and then start it. iren.Initialize(); iren.Start(); return(0); }
/// <summary> /// An example that does not use a Windows Form /// </summary> /// <param name="argv"></param> public static void Main(String[] argv) { // This example demonstrates the use of vtkCubeAxesActor2D to indicate the // position in space that the camera is currently viewing. // The vtkCubeAxesActor2D draws axes on the bounding box of the data set and // labels the axes with x-y-z coordinates. // // First we include the VTK Tcl packages which will make available // all of the vtk commands to Tcl // // Create a vtkBYUReader and read in a data set. // fohe = vtkBYUReader.New(); fohe.SetGeometryFileName("../../../teapot.g"); // Create a vtkPolyDataNormals filter to calculate the normals of the data set. normals = vtkPolyDataNormals.New(); normals.SetInputConnection(fohe.GetOutputPort()); // Set up the associated mapper and actor. foheMapper = vtkPolyDataMapper.New(); foheMapper.SetInputConnection(normals.GetOutputPort()); foheActor = vtkLODActor.New(); foheActor.SetMapper(foheMapper); // Create a vtkOutlineFilter to draw the bounding box of the data set. Also // create the associated mapper and actor. outline = vtkOutlineFilter.New(); outline.SetInputConnection(normals.GetOutputPort()); mapOutline = vtkPolyDataMapper.New(); mapOutline.SetInputConnection(outline.GetOutputPort()); outlineActor = vtkActor.New(); outlineActor.SetMapper(mapOutline); outlineActor.GetProperty().SetColor(0, 0, 0); // Create a vtkCamera, and set the camera parameters. camera = vtkCamera.New(); camera.SetClippingRange(1.60187, 20.0842); camera.SetFocalPoint(0.21406, 1.5, 0); camera.SetPosition(8.3761, 4.94858, 4.12505); camera.SetViewUp(0.180325, 0.549245, -0.815974); // Create a vtkLight, and set the light parameters. light = vtkLight.New(); light.SetFocalPoint(0.21406, 1.5, 0); light.SetPosition(8.3761, 4.94858, 4.12505); // Create the Renderers. Assign them the appropriate viewport coordinates, // active camera, and light. ren1 = vtkRenderer.New(); ren1.SetViewport(0, 0, 0.5, 1.0); ren1.SetActiveCamera(camera); ren1.AddLight(light); ren2 = vtkRenderer.New(); ren2.SetViewport(0.5, 0, 1.0, 1.0); ren2.SetActiveCamera(camera); ren2.AddLight(light); // Create the RenderWindow and RenderWindowInteractor. renWin = vtkRenderWindow.New(); renWin.AddRenderer(ren1); renWin.AddRenderer(ren2); renWin.SetWindowName("VTK - Cube Axes"); renWin.SetSize(600, 300); iren = vtkRenderWindowInteractor.New(); iren.SetRenderWindow(renWin); // Add the actors to the renderer, and set the background. ren1.AddViewProp(foheActor); ren1.AddViewProp(outlineActor); ren2.AddViewProp(foheActor); ren2.AddViewProp(outlineActor); ren1.SetBackground(0.1, 0.2, 0.4); ren2.SetBackground(0.1, 0.2, 0.4); // Create a text property for both cube axes tprop = vtkTextProperty.New(); tprop.SetColor(1, 1, 1); tprop.ShadowOn(); // Create a vtkCubeAxesActor2D. Use the outer edges of the bounding box to // draw the axes. Add the actor to the renderer. axes = vtkCubeAxesActor2D.New(); axes.SetInput(normals.GetOutput()); axes.SetCamera(ren1.GetActiveCamera()); axes.SetLabelFormat("%6.4g"); axes.SetFlyModeToOuterEdges(); axes.SetFontFactor(0.8); axes.SetAxisTitleTextProperty(tprop); axes.SetAxisLabelTextProperty(tprop); ren1.AddViewProp(axes); // Create a vtkCubeAxesActor2D. Use the closest vertex to the camera to // determine where to draw the axes. Add the actor to the renderer. axes2 = vtkCubeAxesActor2D.New(); axes2.SetViewProp(foheActor); axes2.SetCamera(ren2.GetActiveCamera()); axes2.SetLabelFormat("%6.4g"); axes2.SetFlyModeToClosestTriad(); axes2.SetFontFactor(0.8); axes2.ScalingOff(); axes2.SetAxisTitleTextProperty(tprop); axes2.SetAxisLabelTextProperty(tprop); ren2.AddViewProp(axes2); // Render renWin.Render(); // Set the user method (bound to key 'u') iren.Initialize(); iren.Start(); // Set up a check for aborting rendering. renWin.AbortCheckEvt += new vtkObject.vtkObjectEventHandler(TkCheckAbort); //Clean Up deleteAllVTKObjects(); }
static void Main(string[] args) { // create a sphere source, mapper, and actor vtkSphereSource sphere = new vtkSphereSource(); vtkPolyDataMapper sphereMapper = new vtkPolyDataMapper(); sphereMapper.SetInputConnection(sphere.GetOutputPort()); vtkPolyDataMapper.GlobalImmediateModeRenderingOn(); vtkLODActor sphereActor = new vtkLODActor(); sphereActor.SetMapper(sphereMapper); // create the spikes by glyphing the sphere with a cone. Create the // mapper and actor for the glyphs. vtkConeSource cone = new vtkConeSource(); vtkGlyph3D glyph = new vtkGlyph3D(); glyph.SetInputConnection(sphere.GetOutputPort()); glyph.SetSource(cone.GetOutput()); glyph.SetVectorModeToUseNormal(); glyph.SetScaleModeToScaleByVector(); glyph.SetScaleFactor(0.25); vtkPolyDataMapper spikeMapper = new vtkPolyDataMapper(); spikeMapper.SetInputConnection(glyph.GetOutputPort()); vtkLODActor spikeActor = new vtkLODActor(); spikeActor.SetMapper(spikeMapper); // Create a text mapper and actor to display the results of picking. vtkTextMapper textMapper = new vtkTextMapper(); vtkTextProperty tprop = textMapper.GetTextProperty(); tprop.SetFontFamilyToArial(); tprop.SetFontSize(10); tprop.BoldOn(); tprop.ShadowOn(); tprop.SetColor(1, 0, 0); vtkActor2D textActor = new vtkActor2D(); textActor.VisibilityOff(); textActor.SetMapper(textMapper); // Create a cell picker. vtkCellPicker picker = new vtkCellPicker(); PickData pd = new PickData(); pd.textActor = textActor; pd.textMapper = textMapper; vtkDotNetCallback cb = new vtkDotNetCallback(pd.annotatePickCallback); // Now at the end of the pick event call the above function. picker.AddObserver((uint) EventIds.EndPickEvent, cb); // Create the Renderer, RenderWindow, etc. and set the Picker. vtkRenderer ren = new vtkRenderer(); vtkRenderWindow renWin = new vtkRenderWindow(); renWin.AddRenderer(ren); vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow(renWin); iren.SetPicker(picker); // Add the actors to the renderer, set the background and size ren.AddActor2D(textActor); ren.AddActor(sphereActor); ren.AddActor(spikeActor); ren.SetBackground(1, 1, 1); renWin.SetSize(300, 300); // Get the camera and zoom in closer to the image. ren.ResetCamera(); vtkCamera cam1 = ren.GetActiveCamera(); cam1.Zoom(1.4); iren.Initialize(); // Initially pick the cell at this location. picker.Pick(85, 126, 0, ren); renWin.Render(); iren.Start(); vtkWin32OpenGLRenderWindow win32win = vtkWin32OpenGLRenderWindow.SafeDownCast(renWin); if (null != win32win) win32win.Clean(); }
static void PrintImage(string Ipath) { vtkDICOMImageReader reader = vtkDICOMImageReader.New(); reader.SetDirectoryName(Ipath); reader.Update(); X = reader.GetWidth(); Y = reader.GetHeight(); Z = reader.GetPixelSpacing(); Console.WriteLine(X * Z[0]); Console.WriteLine(Y * Z[1]); Console.WriteLine(Z[2]); // Visualize _ImageViewer = vtkImageViewer2.New(); _ImageViewer.SetInputConnection(reader.GetOutputPort()); // Get range of slices (min is the first index, max is the last index) _ImageViewer.GetSliceRange(ref _MinSlice, ref _MaxSlice); Console.WriteLine(_MinSlice); Console.WriteLine(_MaxSlice); _SliceStatusMapper = vtkTextMapper.New(); _SliceStatusMapper.SetInputConnection(reader.GetOutputPort()); vtkActor2D sliceStatusActor = vtkActor2D.New(); sliceStatusActor.SetMapper(_SliceStatusMapper); vtkRenderWindow renderWindow = vtkRenderWindow.New(); //Display in full screen renderWindow.SetFullScreen(1); vtkInteractorStyleImage interactorStyle = vtkInteractorStyleImage.New(); renderWindow.GetRenderers().InitTraversal(); vtkRenderer ren; while ((ren = renderWindow.GetRenderers().GetNextItem()) != null) { renderWindow.AddRenderer(ren); } _ImageViewer.SetRenderWindow(renderWindow); _ImageViewer.GetRenderer().AddActor2D(sliceStatusActor); _ImageViewer.SetSlice(_Slice); _ColorLevel = 500; _ImageViewer.SetColorLevel(_BlackLevel); _ImageViewer.Render(); Down(_period, 62); Backward(_period, 1); _ImageViewer.SetColorLevel(_ColorLevel); _ImageViewer.Render(); System.Threading.Thread.Sleep(_layertime); // delay iren = vtkRenderWindowInteractor.New(); iren.SetRenderWindow(renderWindow); renderWindow.Render(); //Start Timer InitTimer(); iren.Start(); if (reader != null) { reader.Dispose(); } if (_ImageViewer != null) { _ImageViewer.Dispose(); } if (_SliceStatusMapper != null) { _SliceStatusMapper.Dispose(); } if (sliceStatusActor != null) { sliceStatusActor.Dispose(); } if (renderWindow != null) { renderWindow.Dispose(); } if (interactorStyle != null) { interactorStyle.Dispose(); } if (ren != null) { ren.Dispose(); } if (iren != null) { iren.Dispose(); } }