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(); }
private void CreateSurfaceRendering() { _contourFilter = new vtkContourFilter(); _contourFilter.SetInput(_volumeGraphic.GetImageData()); _contourFilter.SetValue(0, _volumeGraphic.GetRescaledLevel()); vtkPolyDataNormals normals = new vtkPolyDataNormals(); normals.SetInputConnection(_contourFilter.GetOutputPort()); normals.SetFeatureAngle(60.0); vtkStripper stripper = new vtkStripper(); stripper.SetInputConnection(normals.GetOutputPort()); vtkPolyDataMapper mapper = new vtkPolyDataMapper(); mapper.SetInputConnection(stripper.GetOutputPort()); mapper.ScalarVisibilityOff(); _vtkActor = new vtkActor(); _vtkActor.SetMapper(mapper); _vtkActor.GetProperty().SetSpecular(.3); _vtkActor.GetProperty().SetSpecularPower(20); ApplySetting("Opacity"); ApplySetting("Level"); }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVTestUnstructuredPieces(String [] argv) { //Prefix Content is: "" math = new vtkMath(); vtkMath.RandomSeed((int)22); pf = new vtkParallelFactory(); vtkParallelFactory.RegisterFactory((vtkObjectFactory)pf); pl3d = new vtkMultiBlockPLOT3DReader(); pl3d.SetXYZFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/combxyz.bin"); pl3d.SetQFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/combq.bin"); pl3d.SetScalarFunctionNumber((int)100); dst = new vtkDataSetTriangleFilter(); dst.SetInputData((vtkDataSet)pl3d.GetOutput().GetBlock(0)); extract = new vtkExtractUnstructuredGridPiece(); extract.SetInputConnection((vtkAlgorithmOutput)dst.GetOutputPort()); cf = new vtkContourFilter(); cf.SetInputConnection((vtkAlgorithmOutput)extract.GetOutputPort()); cf.SetValue((int)0, (double)0.24); pdn = new vtkPolyDataNormals(); pdn.SetInputConnection((vtkAlgorithmOutput)cf.GetOutputPort()); ps = new vtkPieceScalars(); ps.SetInputConnection((vtkAlgorithmOutput)pdn.GetOutputPort()); mapper = vtkPolyDataMapper.New(); mapper.SetInputConnection((vtkAlgorithmOutput)ps.GetOutputPort()); mapper.SetNumberOfPieces((int)3); actor = new vtkActor(); actor.SetMapper((vtkMapper)mapper); ren = vtkRenderer.New(); ren.AddActor((vtkProp)actor); ren.ResetCamera(); camera = ren.GetActiveCamera(); //$camera SetPosition 68.1939 -23.4323 12.6465[] //$camera SetViewUp 0.46563 0.882375 0.0678508 [] //$camera SetFocalPoint 3.65707 11.4552 1.83509 [] //$camera SetClippingRange 59.2626 101.825 [] renWin = vtkRenderWindow.New(); renWin.AddRenderer((vtkRenderer)ren); iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); iren.Initialize(); //deleteAllVTKObjects(); }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVTestUnstructuredPieces(String [] argv) { //Prefix Content is: "" math = new vtkMath(); vtkMath.RandomSeed((int)22); pf = new vtkParallelFactory(); vtkParallelFactory.RegisterFactory((vtkObjectFactory)pf); pl3d = new vtkMultiBlockPLOT3DReader(); pl3d.SetXYZFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/combxyz.bin"); pl3d.SetQFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/combq.bin"); pl3d.SetScalarFunctionNumber((int)100); dst = new vtkDataSetTriangleFilter(); dst.SetInputData((vtkDataSet)pl3d.GetOutput().GetBlock(0)); extract = new vtkExtractUnstructuredGridPiece(); extract.SetInputConnection((vtkAlgorithmOutput)dst.GetOutputPort()); cf = new vtkContourFilter(); cf.SetInputConnection((vtkAlgorithmOutput)extract.GetOutputPort()); cf.SetValue((int)0,(double)0.24); pdn = new vtkPolyDataNormals(); pdn.SetInputConnection((vtkAlgorithmOutput)cf.GetOutputPort()); ps = new vtkPieceScalars(); ps.SetInputConnection((vtkAlgorithmOutput)pdn.GetOutputPort()); mapper = vtkPolyDataMapper.New(); mapper.SetInputConnection((vtkAlgorithmOutput)ps.GetOutputPort()); mapper.SetNumberOfPieces((int)3); actor = new vtkActor(); actor.SetMapper((vtkMapper)mapper); ren = vtkRenderer.New(); ren.AddActor((vtkProp)actor); ren.ResetCamera(); camera = ren.GetActiveCamera(); //$camera SetPosition 68.1939 -23.4323 12.6465[] //$camera SetViewUp 0.46563 0.882375 0.0678508 [] //$camera SetFocalPoint 3.65707 11.4552 1.83509 [] //$camera SetClippingRange 59.2626 101.825 [] renWin = vtkRenderWindow.New(); renWin.AddRenderer((vtkRenderer)ren); iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); iren.Initialize(); //deleteAllVTKObjects(); }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVTenEllip(String [] argv) { //Prefix Content is: "" // create tensor ellipsoids[] // Create the RenderWindow, Renderer and interactive renderer[] //[] ren1 = vtkRenderer.New(); renWin = vtkRenderWindow.New(); renWin.SetMultiSamples(0); renWin.AddRenderer((vtkRenderer)ren1); iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); //[] // Create tensor ellipsoids[] //[] // generate tensors[] ptLoad = new vtkPointLoad(); ptLoad.SetLoadValue((double)100.0); ptLoad.SetSampleDimensions((int)6,(int)6,(int)6); ptLoad.ComputeEffectiveStressOn(); ptLoad.SetModelBounds((double)-10,(double)10,(double)-10,(double)10,(double)-10,(double)10); // extract plane of data[] plane = new vtkImageDataGeometryFilter(); plane.SetInputConnection((vtkAlgorithmOutput)ptLoad.GetOutputPort()); plane.SetExtent((int)2,(int)2,(int)0,(int)99,(int)0,(int)99); // Generate ellipsoids[] sphere = new vtkSphereSource(); sphere.SetThetaResolution((int)8); sphere.SetPhiResolution((int)8); ellipsoids = new vtkTensorGlyph(); ellipsoids.SetInputConnection((vtkAlgorithmOutput)ptLoad.GetOutputPort()); ellipsoids.SetSourceConnection((vtkAlgorithmOutput)sphere.GetOutputPort()); ellipsoids.SetScaleFactor((double)10); ellipsoids.ClampScalingOn(); ellipNormals = new vtkPolyDataNormals(); ellipNormals.SetInputConnection((vtkAlgorithmOutput)ellipsoids.GetOutputPort()); // Map contour[] lut = new vtkLogLookupTable(); lut.SetHueRange((double).6667,(double)0.0); ellipMapper = vtkPolyDataMapper.New(); ellipMapper.SetInputConnection((vtkAlgorithmOutput)ellipNormals.GetOutputPort()); ellipMapper.SetLookupTable((vtkScalarsToColors)lut); plane.Update(); //force update for scalar range[] ellipMapper.SetScalarRange((double)((vtkDataSet)plane.GetOutput()).GetScalarRange()[0],(double)((vtkDataSet)plane.GetOutput()).GetScalarRange()[1]); ellipActor = new vtkActor(); ellipActor.SetMapper((vtkMapper)ellipMapper); //[] // Create outline around data[] //[] outline = new vtkOutlineFilter(); outline.SetInputConnection((vtkAlgorithmOutput)ptLoad.GetOutputPort()); outlineMapper = vtkPolyDataMapper.New(); outlineMapper.SetInputConnection((vtkAlgorithmOutput)outline.GetOutputPort()); outlineActor = new vtkActor(); outlineActor.SetMapper((vtkMapper)outlineMapper); outlineActor.GetProperty().SetColor((double)0,(double)0,(double)0); //[] // Create cone indicating application of load[] //[] coneSrc = new vtkConeSource(); coneSrc.SetRadius((double).5); coneSrc.SetHeight((double)2); coneMap = vtkPolyDataMapper.New(); coneMap.SetInputConnection((vtkAlgorithmOutput)coneSrc.GetOutputPort()); coneActor = new vtkActor(); coneActor.SetMapper((vtkMapper)coneMap); coneActor.SetPosition((double)0,(double)0,(double)11); coneActor.RotateY((double)90); coneActor.GetProperty().SetColor((double)1,(double)0,(double)0); camera = new vtkCamera(); camera.SetFocalPoint((double)0.113766,(double)-1.13665,(double)-1.01919); camera.SetPosition((double)-29.4886,(double)-63.1488,(double)26.5807); camera.SetViewAngle((double)24.4617); camera.SetViewUp((double)0.17138,(double)0.331163,(double)0.927879); camera.SetClippingRange((double)1,(double)100); ren1.AddActor((vtkProp)ellipActor); ren1.AddActor((vtkProp)outlineActor); ren1.AddActor((vtkProp)coneActor); ren1.SetBackground((double)1.0,(double)1.0,(double)1.0); ren1.SetActiveCamera((vtkCamera)camera); renWin.SetSize((int)400,(int)400); renWin.Render(); // prevent the tk window from showing up then start the event loop[] //deleteAllVTKObjects(); }
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> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVEnSightRectGridASCII(String [] argv) { //Prefix Content is: "" VTK_VARY_RADIUS_BY_VECTOR = 2; // create pipeline[] //[] reader = new vtkGenericEnSightReader(); // Make sure all algorithms use the composite data pipeline[] cdp = new vtkCompositeDataPipeline(); vtkGenericEnSightReader.SetDefaultExecutivePrototype((vtkExecutive)cdp); reader.SetCaseFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/EnSight/RectGrid_ascii.case"); reader.Update(); toRectilinearGrid = new vtkCastToConcrete(); // toRectilinearGrid SetInputConnection [reader GetOutputPort] [] toRectilinearGrid.SetInput((vtkDataObject)reader.GetOutput().GetBlock((uint)0)); plane = new vtkRectilinearGridGeometryFilter(); plane.SetInput((vtkDataObject)toRectilinearGrid.GetRectilinearGridOutput()); plane.SetExtent((int)0,(int)100,(int)0,(int)100,(int)15,(int)15); tri = new vtkTriangleFilter(); tri.SetInputConnection((vtkAlgorithmOutput)plane.GetOutputPort()); warper = new vtkWarpVector(); warper.SetInputConnection((vtkAlgorithmOutput)tri.GetOutputPort()); warper.SetScaleFactor((double)0.05); planeMapper = new vtkDataSetMapper(); planeMapper.SetInputConnection((vtkAlgorithmOutput)warper.GetOutputPort()); planeMapper.SetScalarRange((double)0.197813,(double)0.710419); planeActor = new vtkActor(); planeActor.SetMapper((vtkMapper)planeMapper); cutPlane = new vtkPlane(); // eval cutPlane SetOrigin [[reader GetOutput] GetCenter][] cutPlane.SetOrigin((double)((vtkDataSet)reader.GetOutput().GetBlock((uint)0)).GetCenter()[0], (double)((vtkDataSet)reader.GetOutput().GetBlock((uint)0)).GetCenter()[1], (double)((vtkDataSet)reader.GetOutput().GetBlock((uint)0)).GetCenter()[2]); cutPlane.SetNormal((double)1,(double)0,(double)0); planeCut = new vtkCutter(); planeCut.SetInput((vtkDataObject)toRectilinearGrid.GetRectilinearGridOutput()); planeCut.SetCutFunction((vtkImplicitFunction)cutPlane); cutMapper = new vtkDataSetMapper(); cutMapper.SetInputConnection((vtkAlgorithmOutput)planeCut.GetOutputPort()); cutMapper.SetScalarRange((double)((vtkDataSet)((vtkMultiBlockDataSet)reader.GetOutput()).GetBlock((uint)0)).GetPointData().GetScalars().GetRange()[0], (double)((vtkDataSet)((vtkMultiBlockDataSet)reader.GetOutput()).GetBlock((uint)0)).GetPointData().GetScalars().GetRange()[1]); cutActor = new vtkActor(); cutActor.SetMapper((vtkMapper)cutMapper); iso = new vtkContourFilter(); iso.SetInput((vtkDataObject)toRectilinearGrid.GetRectilinearGridOutput()); iso.SetValue((int)0,(double)0.7); normals = new vtkPolyDataNormals(); normals.SetInputConnection((vtkAlgorithmOutput)iso.GetOutputPort()); normals.SetFeatureAngle((double)45); isoMapper = vtkPolyDataMapper.New(); isoMapper.SetInputConnection((vtkAlgorithmOutput)normals.GetOutputPort()); isoMapper.ScalarVisibilityOff(); isoActor = new vtkActor(); isoActor.SetMapper((vtkMapper)isoMapper); isoActor.GetProperty().SetColor((double) 1.0000, 0.8941, 0.7686 ); isoActor.GetProperty().SetRepresentationToWireframe(); streamer = new vtkStreamLine(); // streamer SetInputConnection [reader GetOutputPort][] streamer.SetInput((vtkDataObject)reader.GetOutput().GetBlock((uint)0)); streamer.SetStartPosition((double)-1.2,(double)-0.1,(double)1.3); streamer.SetMaximumPropagationTime((double)500); streamer.SetStepLength((double)0.05); streamer.SetIntegrationStepLength((double)0.05); streamer.SetIntegrationDirectionToIntegrateBothDirections(); streamTube = new vtkTubeFilter(); streamTube.SetInputConnection((vtkAlgorithmOutput)streamer.GetOutputPort()); streamTube.SetRadius((double)0.025); streamTube.SetNumberOfSides((int)6); streamTube.SetVaryRadius((int)VTK_VARY_RADIUS_BY_VECTOR); mapStreamTube = vtkPolyDataMapper.New(); mapStreamTube.SetInputConnection((vtkAlgorithmOutput)streamTube.GetOutputPort()); mapStreamTube.SetScalarRange((double)((vtkDataSet)reader.GetOutput().GetBlock((uint)0)).GetPointData().GetScalars().GetRange()[0], (double)((vtkDataSet)reader.GetOutput().GetBlock((uint)0)).GetPointData().GetScalars().GetRange()[1]); // [[[[reader GetOutput] GetPointData] GetScalars] GetRange][] streamTubeActor = new vtkActor(); streamTubeActor.SetMapper((vtkMapper)mapStreamTube); streamTubeActor.GetProperty().BackfaceCullingOn(); outline = new vtkOutlineFilter(); outline.SetInput((vtkDataObject)toRectilinearGrid.GetRectilinearGridOutput()); outlineMapper = vtkPolyDataMapper.New(); outlineMapper.SetInputConnection((vtkAlgorithmOutput)outline.GetOutputPort()); outlineActor = new vtkActor(); outlineActor.SetMapper((vtkMapper)outlineMapper); outlineActor.GetProperty().SetColor((double) 0.0000, 0.0000, 0.0000 ); // Graphics stuff[] // Create the RenderWindow, Renderer and both Actors[] //[] ren1 = vtkRenderer.New(); renWin = vtkRenderWindow.New(); renWin.AddRenderer((vtkRenderer)ren1); iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); // Add the actors to the renderer, set the background and size[] //[] ren1.AddActor((vtkProp)outlineActor); ren1.AddActor((vtkProp)planeActor); ren1.AddActor((vtkProp)cutActor); ren1.AddActor((vtkProp)isoActor); ren1.AddActor((vtkProp)streamTubeActor); ren1.SetBackground((double)1,(double)1,(double)1); renWin.SetSize((int)400,(int)400); cam1 = ren1.GetActiveCamera(); cam1.SetClippingRange((double)3.76213,(double)10.712); cam1.SetFocalPoint((double)-0.0842503,(double)-0.136905,(double)0.610234); cam1.SetPosition((double)2.53813,(double)2.2678,(double)-5.22172); cam1.SetViewUp((double)-0.241047,(double)0.930635,(double)0.275343); iren.Initialize(); // render the image[] //[] // prevent the tk window from showing up then start the event loop[] vtkGenericEnSightReader.SetDefaultExecutivePrototype(null); //deleteAllVTKObjects(); }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVTestPolyDataPieces(String [] argv) { //Prefix Content is: "" math = new vtkMath(); vtkMath.RandomSeed((int)22); pf = new vtkParallelFactory(); vtkParallelFactory.RegisterFactory((vtkObjectFactory)pf); sphere = new vtkSphereSource(); sphere.SetPhiResolution((int)32); sphere.SetThetaResolution((int)32); extract = new vtkExtractPolyDataPiece(); extract.SetInputConnection((vtkAlgorithmOutput)sphere.GetOutputPort()); normals = new vtkPolyDataNormals(); normals.SetInputConnection((vtkAlgorithmOutput)extract.GetOutputPort()); ps = new vtkPieceScalars(); ps.SetInputConnection((vtkAlgorithmOutput)normals.GetOutputPort()); mapper = vtkPolyDataMapper.New(); mapper.SetInputConnection((vtkAlgorithmOutput)ps.GetOutputPort()); mapper.SetNumberOfPieces((int)2); actor = new vtkActor(); actor.SetMapper((vtkMapper)mapper); sphere2 = new vtkSphereSource(); sphere2.SetPhiResolution((int)32); sphere2.SetThetaResolution((int)32); extract2 = new vtkExtractPolyDataPiece(); extract2.SetInputConnection((vtkAlgorithmOutput)sphere2.GetOutputPort()); mapper2 = vtkPolyDataMapper.New(); mapper2.SetInputConnection((vtkAlgorithmOutput)extract2.GetOutputPort()); mapper2.SetNumberOfPieces((int)2); mapper2.SetPiece((int)1); mapper2.SetScalarRange((double)0, (double)4); mapper2.SetScalarModeToUseCellFieldData(); mapper2.SetColorModeToMapScalars(); mapper2.ColorByArrayComponent((string)"vtkGhostLevels", (int)0); mapper2.SetGhostLevel((int)4); // check the pipeline size[] extract2.UpdateInformation(); psize = new vtkPipelineSize(); if ((psize.GetEstimatedSize((vtkAlgorithm)extract2, (int)0, (int)0)) > 100) { //puts skipedputs ['stderr', '"ERROR: Pipeline Size increased"'] } if ((psize.GetNumberOfSubPieces((uint)10, (vtkPolyDataMapper)mapper2)) != 2) { //puts skipedputs ['stderr', '"ERROR: Number of sub pieces changed"'] } actor2 = new vtkActor(); actor2.SetMapper((vtkMapper)mapper2); actor2.SetPosition((double)1.5, (double)0, (double)0); sphere3 = new vtkSphereSource(); sphere3.SetPhiResolution((int)32); sphere3.SetThetaResolution((int)32); extract3 = new vtkExtractPolyDataPiece(); extract3.SetInputConnection((vtkAlgorithmOutput)sphere3.GetOutputPort()); ps3 = new vtkPieceScalars(); ps3.SetInputConnection((vtkAlgorithmOutput)extract3.GetOutputPort()); mapper3 = vtkPolyDataMapper.New(); mapper3.SetInputConnection((vtkAlgorithmOutput)ps3.GetOutputPort()); mapper3.SetNumberOfSubPieces((int)8); mapper3.SetScalarRange((double)0, (double)8); actor3 = new vtkActor(); actor3.SetMapper((vtkMapper)mapper3); actor3.SetPosition((double)0, (double)-1.5, (double)0); sphere4 = new vtkSphereSource(); sphere4.SetPhiResolution((int)32); sphere4.SetThetaResolution((int)32); extract4 = new vtkExtractPolyDataPiece(); extract4.SetInputConnection((vtkAlgorithmOutput)sphere4.GetOutputPort()); ps4 = new vtkPieceScalars(); ps4.RandomModeOn(); ps4.SetScalarModeToCellData(); ps4.SetInputConnection((vtkAlgorithmOutput)extract4.GetOutputPort()); mapper4 = vtkPolyDataMapper.New(); mapper4.SetInputConnection((vtkAlgorithmOutput)ps4.GetOutputPort()); mapper4.SetNumberOfSubPieces((int)8); mapper4.SetScalarRange((double)0, (double)8); actor4 = new vtkActor(); actor4.SetMapper((vtkMapper)mapper4); actor4.SetPosition((double)1.5, (double)-1.5, (double)0); ren = vtkRenderer.New(); ren.AddActor((vtkProp)actor); ren.AddActor((vtkProp)actor2); ren.AddActor((vtkProp)actor3); ren.AddActor((vtkProp)actor4); renWin = vtkRenderWindow.New(); renWin.AddRenderer((vtkRenderer)ren); iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); iren.Initialize(); //deleteAllVTKObjects(); }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVTenEllip(String [] argv) { //Prefix Content is: "" // create tensor ellipsoids[] // Create the RenderWindow, Renderer and interactive renderer[] //[] ren1 = vtkRenderer.New(); renWin = vtkRenderWindow.New(); renWin.SetMultiSamples(0); renWin.AddRenderer((vtkRenderer)ren1); iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); //[] // Create tensor ellipsoids[] //[] // generate tensors[] ptLoad = new vtkPointLoad(); ptLoad.SetLoadValue((double)100.0); ptLoad.SetSampleDimensions((int)6, (int)6, (int)6); ptLoad.ComputeEffectiveStressOn(); ptLoad.SetModelBounds((double)-10, (double)10, (double)-10, (double)10, (double)-10, (double)10); // extract plane of data[] plane = new vtkImageDataGeometryFilter(); plane.SetInputConnection((vtkAlgorithmOutput)ptLoad.GetOutputPort()); plane.SetExtent((int)2, (int)2, (int)0, (int)99, (int)0, (int)99); // Generate ellipsoids[] sphere = new vtkSphereSource(); sphere.SetThetaResolution((int)8); sphere.SetPhiResolution((int)8); ellipsoids = new vtkTensorGlyph(); ellipsoids.SetInputConnection((vtkAlgorithmOutput)ptLoad.GetOutputPort()); ellipsoids.SetSourceConnection((vtkAlgorithmOutput)sphere.GetOutputPort()); ellipsoids.SetScaleFactor((double)10); ellipsoids.ClampScalingOn(); ellipNormals = new vtkPolyDataNormals(); ellipNormals.SetInputConnection((vtkAlgorithmOutput)ellipsoids.GetOutputPort()); // Map contour[] lut = new vtkLogLookupTable(); lut.SetHueRange((double).6667, (double)0.0); ellipMapper = vtkPolyDataMapper.New(); ellipMapper.SetInputConnection((vtkAlgorithmOutput)ellipNormals.GetOutputPort()); ellipMapper.SetLookupTable((vtkScalarsToColors)lut); plane.Update(); //force update for scalar range[] ellipMapper.SetScalarRange((double)((vtkDataSet)plane.GetOutput()).GetScalarRange()[0], (double)((vtkDataSet)plane.GetOutput()).GetScalarRange()[1]); ellipActor = new vtkActor(); ellipActor.SetMapper((vtkMapper)ellipMapper); //[] // Create outline around data[] //[] outline = new vtkOutlineFilter(); outline.SetInputConnection((vtkAlgorithmOutput)ptLoad.GetOutputPort()); outlineMapper = vtkPolyDataMapper.New(); outlineMapper.SetInputConnection((vtkAlgorithmOutput)outline.GetOutputPort()); outlineActor = new vtkActor(); outlineActor.SetMapper((vtkMapper)outlineMapper); outlineActor.GetProperty().SetColor((double)0, (double)0, (double)0); //[] // Create cone indicating application of load[] //[] coneSrc = new vtkConeSource(); coneSrc.SetRadius((double).5); coneSrc.SetHeight((double)2); coneMap = vtkPolyDataMapper.New(); coneMap.SetInputConnection((vtkAlgorithmOutput)coneSrc.GetOutputPort()); coneActor = new vtkActor(); coneActor.SetMapper((vtkMapper)coneMap); coneActor.SetPosition((double)0, (double)0, (double)11); coneActor.RotateY((double)90); coneActor.GetProperty().SetColor((double)1, (double)0, (double)0); camera = new vtkCamera(); camera.SetFocalPoint((double)0.113766, (double)-1.13665, (double)-1.01919); camera.SetPosition((double)-29.4886, (double)-63.1488, (double)26.5807); camera.SetViewAngle((double)24.4617); camera.SetViewUp((double)0.17138, (double)0.331163, (double)0.927879); camera.SetClippingRange((double)1, (double)100); ren1.AddActor((vtkProp)ellipActor); ren1.AddActor((vtkProp)outlineActor); ren1.AddActor((vtkProp)coneActor); ren1.SetBackground((double)1.0, (double)1.0, (double)1.0); ren1.SetActiveCamera((vtkCamera)camera); renWin.SetSize((int)400, (int)400); renWin.Render(); // prevent the tk window from showing up then start the event loop[] //deleteAllVTKObjects(); }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVfieldToUGrid(String [] argv) { //Prefix Content is: "" // Read a field representing unstructured grid and display it (similar to blow.tcl)[] // create a reader and write out field daya[] reader = new vtkUnstructuredGridReader(); reader.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/blow.vtk"); reader.SetScalarsName((string)"thickness9"); reader.SetVectorsName((string)"displacement9"); ds2do = new vtkDataSetToDataObjectFilter(); ds2do.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort()); // we must be able to write here[] try { channel = new StreamWriter("UGridField.vtk"); tryCatchError = "NOERROR"; } catch (Exception) { tryCatchError = "ERROR"; } if (tryCatchError.Equals("NOERROR")) { channel.Close(); write = new vtkDataObjectWriter(); write.SetInputConnection((vtkAlgorithmOutput)ds2do.GetOutputPort()); write.SetFileName((string)"UGridField.vtk"); write.Write(); // Read the field and convert to unstructured grid.[] dor = new vtkDataObjectReader(); dor.SetFileName((string)"UGridField.vtk"); do2ds = new vtkDataObjectToDataSetFilter(); do2ds.SetInputConnection((vtkAlgorithmOutput)dor.GetOutputPort()); do2ds.SetDataSetTypeToUnstructuredGrid(); do2ds.SetPointComponent((int)0, (string)"Points", (int)0); do2ds.SetPointComponent((int)1, (string)"Points", (int)1); do2ds.SetPointComponent((int)2, (string)"Points", (int)2); do2ds.SetCellTypeComponent((string)"CellTypes", (int)0); do2ds.SetCellConnectivityComponent((string)"Cells", (int)0); do2ds.Update(); fd2ad = new vtkFieldDataToAttributeDataFilter(); fd2ad.SetInputData((vtkDataObject)do2ds.GetUnstructuredGridOutput()); fd2ad.SetInputFieldToDataObjectField(); fd2ad.SetOutputAttributeDataToPointData(); fd2ad.SetVectorComponent((int)0, (string)"displacement9", (int)0); fd2ad.SetVectorComponent((int)1, (string)"displacement9", (int)1); fd2ad.SetVectorComponent((int)2, (string)"displacement9", (int)2); fd2ad.SetScalarComponent((int)0, (string)"thickness9", (int)0); fd2ad.Update(); // Now start visualizing[] warp = new vtkWarpVector(); warp.SetInputData((vtkDataObject)fd2ad.GetUnstructuredGridOutput()); // extract mold from mesh using connectivity[] connect = new vtkConnectivityFilter(); connect.SetInputConnection((vtkAlgorithmOutput)warp.GetOutputPort()); connect.SetExtractionModeToSpecifiedRegions(); connect.AddSpecifiedRegion((int)0); connect.AddSpecifiedRegion((int)1); moldMapper = new vtkDataSetMapper(); moldMapper.SetInputConnection((vtkAlgorithmOutput)connect.GetOutputPort()); moldMapper.ScalarVisibilityOff(); moldActor = new vtkActor(); moldActor.SetMapper((vtkMapper)moldMapper); moldActor.GetProperty().SetColor((double).2, (double).2, (double).2); moldActor.GetProperty().SetRepresentationToWireframe(); // extract parison from mesh using connectivity[] connect2 = new vtkConnectivityFilter(); connect2.SetInputConnection((vtkAlgorithmOutput)warp.GetOutputPort()); connect2.SetExtractionModeToSpecifiedRegions(); connect2.AddSpecifiedRegion((int)2); parison = new vtkGeometryFilter(); parison.SetInputConnection((vtkAlgorithmOutput)connect2.GetOutputPort()); normals2 = new vtkPolyDataNormals(); normals2.SetInputConnection((vtkAlgorithmOutput)parison.GetOutputPort()); normals2.SetFeatureAngle((double)60); lut = new vtkLookupTable(); lut.SetHueRange((double)0.0, (double)0.66667); parisonMapper = vtkPolyDataMapper.New(); parisonMapper.SetInputConnection((vtkAlgorithmOutput)normals2.GetOutputPort()); parisonMapper.SetLookupTable((vtkScalarsToColors)lut); parisonMapper.SetScalarRange((double)0.12, (double)1.0); parisonActor = new vtkActor(); parisonActor.SetMapper((vtkMapper)parisonMapper); cf = new vtkContourFilter(); cf.SetInputConnection((vtkAlgorithmOutput)connect2.GetOutputPort()); cf.SetValue((int)0, (double).5); contourMapper = vtkPolyDataMapper.New(); contourMapper.SetInputConnection((vtkAlgorithmOutput)cf.GetOutputPort()); contours = new vtkActor(); contours.SetMapper((vtkMapper)contourMapper); // Create graphics stuff[] ren1 = vtkRenderer.New(); renWin = vtkRenderWindow.New(); renWin.AddRenderer((vtkRenderer)ren1); iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); // Add the actors to the renderer, set the background and size[] ren1.AddActor((vtkProp)moldActor); ren1.AddActor((vtkProp)parisonActor); ren1.AddActor((vtkProp)contours); ren1.ResetCamera(); ren1.GetActiveCamera().Azimuth((double)60); ren1.GetActiveCamera().Roll((double)-90); ren1.GetActiveCamera().Dolly((double)2); ren1.ResetCameraClippingRange(); ren1.SetBackground((double)1, (double)1, (double)1); renWin.SetSize((int)375, (int)200); iren.Initialize(); } // prevent the tk window from showing up then start the event loop[] //deleteAllVTKObjects(); }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVfieldToRGrid(String [] argv) { //Prefix Content is: "" //# Generate a rectilinear grid from a field.[] //#[] // get the interactor ui[] // Create a reader and write out the field[] reader = new vtkDataSetReader(); reader.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/RectGrid2.vtk"); ds2do = new vtkDataSetToDataObjectFilter(); ds2do.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort()); try { channel = new StreamWriter("RGridField.vtk"); tryCatchError = "NOERROR"; } catch(Exception) {tryCatchError = "ERROR";} if(tryCatchError.Equals("NOERROR")) { channel.Close(); writer = new vtkDataObjectWriter(); writer.SetInputConnection((vtkAlgorithmOutput)ds2do.GetOutputPort()); writer.SetFileName((string)"RGridField.vtk"); writer.Write(); // Read the field[] //[] dor = new vtkDataObjectReader(); dor.SetFileName((string)"RGridField.vtk"); do2ds = new vtkDataObjectToDataSetFilter(); do2ds.SetInputConnection((vtkAlgorithmOutput)dor.GetOutputPort()); do2ds.SetDataSetTypeToRectilinearGrid(); do2ds.SetDimensionsComponent((string)"Dimensions",(int)0); do2ds.SetPointComponent((int)0,(string)"XCoordinates",(int)0); do2ds.SetPointComponent((int)1,(string)"YCoordinates",(int)0); do2ds.SetPointComponent((int)2,(string)"ZCoordinates",(int)0); fd2ad = new vtkFieldDataToAttributeDataFilter(); fd2ad.SetInput((vtkDataObject)do2ds.GetRectilinearGridOutput()); fd2ad.SetInputFieldToDataObjectField(); fd2ad.SetOutputAttributeDataToPointData(); fd2ad.SetVectorComponent((int)0,(string)"vectors",(int)0); fd2ad.SetVectorComponent((int)1,(string)"vectors",(int)1); fd2ad.SetVectorComponent((int)2,(string)"vectors",(int)2); fd2ad.SetScalarComponent((int)0,(string)"scalars",(int)0); fd2ad.Update(); // create pipeline[] //[] plane = new vtkRectilinearGridGeometryFilter(); plane.SetInput((vtkDataObject)fd2ad.GetRectilinearGridOutput()); plane.SetExtent((int)0,(int)100,(int)0,(int)100,(int)15,(int)15); warper = new vtkWarpVector(); warper.SetInputConnection((vtkAlgorithmOutput)plane.GetOutputPort()); warper.SetScaleFactor((double)0.05); planeMapper = new vtkDataSetMapper(); planeMapper.SetInputConnection((vtkAlgorithmOutput)warper.GetOutputPort()); planeMapper.SetScalarRange((double)0.197813,(double)0.710419); planeActor = new vtkActor(); planeActor.SetMapper((vtkMapper)planeMapper); cutPlane = new vtkPlane(); cutPlane.SetOrigin(fd2ad.GetOutput().GetCenter()[0],fd2ad.GetOutput().GetCenter()[1],fd2ad.GetOutput().GetCenter()[2]); cutPlane.SetNormal((double)1,(double)0,(double)0); planeCut = new vtkCutter(); planeCut.SetInput((vtkDataObject)fd2ad.GetRectilinearGridOutput()); planeCut.SetCutFunction((vtkImplicitFunction)cutPlane); cutMapper = new vtkDataSetMapper(); cutMapper.SetInputConnection((vtkAlgorithmOutput)planeCut.GetOutputPort()); cutMapper.SetScalarRange( (double)((vtkDataSet)fd2ad.GetOutput()).GetPointData().GetScalars().GetRange()[0], (double)((vtkDataSet)fd2ad.GetOutput()).GetPointData().GetScalars().GetRange()[1]); cutActor = new vtkActor(); cutActor.SetMapper((vtkMapper)cutMapper); iso = new vtkContourFilter(); iso.SetInput((vtkDataObject)fd2ad.GetRectilinearGridOutput()); iso.SetValue((int)0,(double)0.7); normals = new vtkPolyDataNormals(); normals.SetInputConnection((vtkAlgorithmOutput)iso.GetOutputPort()); normals.SetFeatureAngle((double)45); isoMapper = vtkPolyDataMapper.New(); isoMapper.SetInputConnection((vtkAlgorithmOutput)normals.GetOutputPort()); isoMapper.ScalarVisibilityOff(); isoActor = new vtkActor(); isoActor.SetMapper((vtkMapper)isoMapper); isoActor.GetProperty().SetColor((double) 1.0000, 0.8941, 0.7686 ); isoActor.GetProperty().SetRepresentationToWireframe(); streamer = new vtkStreamLine(); streamer.SetInputConnection((vtkAlgorithmOutput)fd2ad.GetOutputPort()); streamer.SetStartPosition((double)-1.2,(double)-0.1,(double)1.3); streamer.SetMaximumPropagationTime((double)500); streamer.SetStepLength((double)0.05); streamer.SetIntegrationStepLength((double)0.05); streamer.SetIntegrationDirectionToIntegrateBothDirections(); streamTube = new vtkTubeFilter(); streamTube.SetInputConnection((vtkAlgorithmOutput)streamer.GetOutputPort()); streamTube.SetRadius((double)0.025); streamTube.SetNumberOfSides((int)6); streamTube.SetVaryRadiusToVaryRadiusByVector(); mapStreamTube = vtkPolyDataMapper.New(); mapStreamTube.SetInputConnection((vtkAlgorithmOutput)streamTube.GetOutputPort()); mapStreamTube.SetScalarRange( (double)((vtkDataSet)fd2ad.GetOutput()).GetPointData().GetScalars().GetRange()[0], (double)((vtkDataSet)fd2ad.GetOutput()).GetPointData().GetScalars().GetRange()[1]); streamTubeActor = new vtkActor(); streamTubeActor.SetMapper((vtkMapper)mapStreamTube); streamTubeActor.GetProperty().BackfaceCullingOn(); outline = new vtkOutlineFilter(); outline.SetInput((vtkDataObject)fd2ad.GetRectilinearGridOutput()); outlineMapper = vtkPolyDataMapper.New(); outlineMapper.SetInputConnection((vtkAlgorithmOutput)outline.GetOutputPort()); outlineActor = new vtkActor(); outlineActor.SetMapper((vtkMapper)outlineMapper); outlineActor.GetProperty().SetColor((double) 0.0000, 0.0000, 0.0000 ); // Graphics stuff[] // Create the RenderWindow, Renderer and both Actors[] //[] ren1 = vtkRenderer.New(); renWin = vtkRenderWindow.New(); renWin.AddRenderer((vtkRenderer)ren1); iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); // Add the actors to the renderer, set the background and size[] //[] ren1.AddActor((vtkProp)outlineActor); ren1.AddActor((vtkProp)planeActor); ren1.AddActor((vtkProp)cutActor); ren1.AddActor((vtkProp)isoActor); ren1.AddActor((vtkProp)streamTubeActor); ren1.SetBackground((double)1,(double)1,(double)1); renWin.SetSize((int)300,(int)300); ren1.GetActiveCamera().SetPosition((double)0.0390893,(double)0.184813,(double)-3.94026); ren1.GetActiveCamera().SetFocalPoint((double)-0.00578326,(double)0,(double)0.701967); ren1.GetActiveCamera().SetViewAngle((double)30); ren1.GetActiveCamera().SetViewUp((double)0.00850257,(double)0.999169,(double)0.0398605); ren1.GetActiveCamera().SetClippingRange((double)3.08127,(double)6.62716); iren.Initialize(); // render the image[] //[] File.Delete("RGridField.vtk"); } // prevent the tk window from showing up then start the event loop[] //deleteAllVTKObjects(); }
/// <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(); }
/// <summary> /// Changes the actors to whatever the /// animal currently loaded is /// </summary> public void updateAnimal() { //----Go through the pipeline for the animal body //Convert the polydata to triangles (in the default files they are rectangles) triangleAnimal.SetInputConnection(animalData); if (this.checkBox1.Checked) { //smooth the polydata cleanAnimal.SetInputConnection(triangleAnimal.GetOutputPort()); smoothAnimal.SetInputConnection(cleanAnimal.GetOutputPort()); normalsAnimal.SetInputConnection(smoothAnimal.GetOutputPort()); //connect the smoothed data to a mapper animalMapper.SetInputConnection(normalsAnimal.GetOutputPort()); //decimate the smoothed polydata decimateAnimal.SetInputConnection(normalsAnimal.GetOutputPort()); } else { //connect the triangle polydata to a mapper before decimation animalMapper.SetInputConnection(triangleAnimal.GetOutputPort()); //decimate the triangled data decimateAnimal.SetInputConnection(triangleAnimal.GetOutputPort()); } double targetreduc = 0.5; if (double.TryParse(toolStripTextBox1.Text, out targetreduc)) { decimateAnimal.SetTargetReduction(targetreduc); } decimateAnimal.SetPreserveTopology(0); //connect the decimated polydata a mapper deciAnimalMapper.SetInputConnection(decimateAnimal.GetOutputPort()); //----Go through the pipeline for the first eye //Convert the polydata to triangles (in the default files they are rectangles) triangles.SetInputConnection(eyeData1); if (this.checkBox1.Checked) { //smooth the polydata clean.SetInputConnection(triangles.GetOutputPort()); smooth.SetInputConnection(clean.GetOutputPort()); normals.SetInputConnection(smooth.GetOutputPort()); //connect the smoothed data to a mapper sphereTexture.SetInputConnection(normals.GetOutputPort()); //decimate the smoothed polydata eyeMapper1.SetInputConnection(sphereTexture.GetOutputPort()); } else { sphereTexture.SetInputConnection(triangles.GetOutputPort()); //connect the triangle polydata to a mapper before decimation eyeMapper1.SetInputConnection(sphereTexture.GetOutputPort()); } decimate.SetInputConnection(sphereTexture.GetOutputPort()); if (double.TryParse(toolStripTextBox1.Text, out targetreduc)) { decimate.SetTargetReduction(targetreduc); } decimate.SetPreserveTopology(0); //connect the decimated polydata a mapper deciEyeMapper1.SetInputConnection(decimate.GetOutputPort()); //----Go through the pipeline for the second eye //Convert the polydata to triangles (in the default files they are rectangles) triangles.SetInputConnection(eyeData1); if (this.checkBox1.Checked) { //smooth the polydata clean.SetInputConnection(triangles.GetOutputPort()); smooth.SetInputConnection(clean.GetOutputPort()); normals.SetInputConnection(smooth.GetOutputPort()); //connect the smoothed data to a mapper sphereTexture.SetInputConnection(normals.GetOutputPort()); //decimate the smoothed polydata eyeMapper2.SetInputConnection(sphereTexture.GetOutputPort()); } else { sphereTexture.SetInputConnection(triangles.GetOutputPort()); //connect the triangle polydata to a mapper before decimation eyeMapper2.SetInputConnection(sphereTexture.GetOutputPort()); } decimate.SetInputConnection(sphereTexture.GetOutputPort()); if (double.TryParse(toolStripTextBox1.Text, out targetreduc)) { decimate.SetTargetReduction(targetreduc); } decimate.SetPreserveTopology(0); //connect the decimated polydata a mapper deciEyeMapper2.SetInputConnection(decimate.GetOutputPort()); //----Set the textures and position of the decimated model deciAnimalActor.SetMapper(deciAnimalMapper); if (this.checkBox2.Checked) { deciAnimalActor.SetTexture(deciAnimalColorTexture); } else { deciAnimalActor.SetTexture(null); } deciEyeActor1.SetMapper(deciEyeMapper1); if (this.checkBox2.Checked) { deciEyeActor1.SetTexture(eyeColorTexture1); deciEyeActor1.SetTexture(deciEyeColorTexture1); } else { deciEyeActor1.SetTexture(null); } deciEyeActor1.SetPosition(eyeX, eyeY, eyeZ); deciEyeActor2.SetMapper(deciEyeMapper2); if (this.checkBox2.Checked) { deciEyeActor2.SetTexture(eyeColorTexture2); deciEyeActor2.SetTexture(deciEyeColorTexture2); } else { deciEyeActor2.SetTexture(null); } deciEyeActor2.SetPosition(-eyeX, eyeY, eyeZ); //----Set the text to the decimated poly count //Update the mappers to get the number of polygons deciAnimalMapper.Update(); deciEyeMapper1.Update(); deciEyeMapper2.Update(); textAfter.SetInput(((((vtkPolyData)deciAnimalMapper.GetInput()).GetNumberOfPolys() + ((vtkPolyData)deciEyeMapper1.GetInput()).GetNumberOfPolys() + ((vtkPolyData)deciEyeMapper2.GetInput()).GetNumberOfPolys())).ToString() + " Polygons"); textAfter.SetDisplayPosition(10, 10); //----Set the textures and position of the decimated model animalActor.SetMapper(animalMapper); if (this.checkBox2.Checked) { animalActor.SetTexture(animalColorTexture); } else { animalActor.SetTexture(null); } eyeActor1.SetMapper(eyeMapper1); if (this.checkBox2.Checked) { eyeActor1.SetTexture(eyeColorTexture1); } else { eyeActor1.SetTexture(null); } eyeActor1.SetPosition(eyeX, eyeY, eyeZ); eyeActor2.SetMapper(eyeMapper2); if (this.checkBox2.Checked) { eyeActor2.SetTexture(eyeColorTexture2); } else { eyeActor2.SetTexture(null); } eyeActor2.SetPosition(-eyeX, eyeY, eyeZ); //Update the pipeline to get the number of polygons animalMapper.Update(); eyeMapper1.Update(); eyeMapper2.Update(); //----Set the text to the full poly count textBefore.SetInput((((vtkPolyData)animalMapper.GetInput()).GetNumberOfPolys() + ((vtkPolyData)eyeMapper1.GetInput()).GetNumberOfPolys() + ((vtkPolyData)eyeMapper2.GetInput()).GetNumberOfPolys()).ToString() + " Polygons"); textBefore.SetDisplayPosition(10, 10); }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVrectGrid(String [] argv) { //Prefix Content is: "" VTK_VARY_RADIUS_BY_VECTOR = 2; // create pipeline[] //[] reader = new vtkDataSetReader(); reader.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/RectGrid2.vtk"); reader.Update(); toRectilinearGrid = new vtkCastToConcrete(); toRectilinearGrid.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort()); toRectilinearGrid.Update(); plane = new vtkRectilinearGridGeometryFilter(); plane.SetInputData((vtkDataObject)toRectilinearGrid.GetRectilinearGridOutput()); plane.SetExtent((int)0, (int)100, (int)0, (int)100, (int)15, (int)15); warper = new vtkWarpVector(); warper.SetInputConnection((vtkAlgorithmOutput)plane.GetOutputPort()); warper.SetScaleFactor((double)0.05); planeMapper = new vtkDataSetMapper(); planeMapper.SetInputConnection((vtkAlgorithmOutput)warper.GetOutputPort()); planeMapper.SetScalarRange((double)0.197813, (double)0.710419); planeActor = new vtkActor(); planeActor.SetMapper((vtkMapper)planeMapper); cutPlane = new vtkPlane(); cutPlane.SetOrigin(reader.GetOutput().GetCenter()[0], reader.GetOutput().GetCenter()[1], reader.GetOutput().GetCenter()[2]); cutPlane.SetNormal((double)1, (double)0, (double)0); planeCut = new vtkCutter(); planeCut.SetInputData((vtkDataObject)toRectilinearGrid.GetRectilinearGridOutput()); planeCut.SetCutFunction((vtkImplicitFunction)cutPlane); cutMapper = new vtkDataSetMapper(); cutMapper.SetInputConnection((vtkAlgorithmOutput)planeCut.GetOutputPort()); cutMapper.SetScalarRange((double)((vtkDataSet)reader.GetOutput()).GetPointData().GetScalars().GetRange()[0], (double)((vtkDataSet)reader.GetOutput()).GetPointData().GetScalars().GetRange()[1]); cutActor = new vtkActor(); cutActor.SetMapper((vtkMapper)cutMapper); iso = new vtkContourFilter(); iso.SetInputData((vtkDataObject)toRectilinearGrid.GetRectilinearGridOutput()); iso.SetValue((int)0, (double)0.7); normals = new vtkPolyDataNormals(); normals.SetInputConnection((vtkAlgorithmOutput)iso.GetOutputPort()); normals.SetFeatureAngle((double)45); isoMapper = vtkPolyDataMapper.New(); isoMapper.SetInputConnection((vtkAlgorithmOutput)normals.GetOutputPort()); isoMapper.ScalarVisibilityOff(); isoActor = new vtkActor(); isoActor.SetMapper((vtkMapper)isoMapper); isoActor.GetProperty().SetColor((double)1.0000, 0.8941, 0.7686); isoActor.GetProperty().SetRepresentationToWireframe(); streamer = new vtkStreamLine(); streamer.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort()); streamer.SetStartPosition((double)-1.2, (double)-0.1, (double)1.3); streamer.SetMaximumPropagationTime((double)500); streamer.SetStepLength((double)0.05); streamer.SetIntegrationStepLength((double)0.05); streamer.SetIntegrationDirectionToIntegrateBothDirections(); streamTube = new vtkTubeFilter(); streamTube.SetInputConnection((vtkAlgorithmOutput)streamer.GetOutputPort()); streamTube.SetRadius((double)0.025); streamTube.SetNumberOfSides((int)6); streamTube.SetVaryRadius((int)VTK_VARY_RADIUS_BY_VECTOR); mapStreamTube = vtkPolyDataMapper.New(); mapStreamTube.SetInputConnection((vtkAlgorithmOutput)streamTube.GetOutputPort()); mapStreamTube.SetScalarRange((double)((vtkDataSet)reader.GetOutput()).GetPointData().GetScalars().GetRange()[0], (double)((vtkDataSet)reader.GetOutput()).GetPointData().GetScalars().GetRange()[1]); streamTubeActor = new vtkActor(); streamTubeActor.SetMapper((vtkMapper)mapStreamTube); streamTubeActor.GetProperty().BackfaceCullingOn(); outline = new vtkOutlineFilter(); outline.SetInputData((vtkDataObject)toRectilinearGrid.GetRectilinearGridOutput()); outlineMapper = vtkPolyDataMapper.New(); outlineMapper.SetInputConnection((vtkAlgorithmOutput)outline.GetOutputPort()); outlineActor = new vtkActor(); outlineActor.SetMapper((vtkMapper)outlineMapper); outlineActor.GetProperty().SetColor((double)0.0000, 0.0000, 0.0000); // Graphics stuff[] // Create the RenderWindow, Renderer and both Actors[] //[] ren1 = vtkRenderer.New(); renWin = vtkRenderWindow.New(); renWin.SetMultiSamples(0); renWin.AddRenderer((vtkRenderer)ren1); iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); // Add the actors to the renderer, set the background and size[] //[] ren1.AddActor((vtkProp)outlineActor); ren1.AddActor((vtkProp)planeActor); ren1.AddActor((vtkProp)cutActor); ren1.AddActor((vtkProp)isoActor); ren1.AddActor((vtkProp)streamTubeActor); ren1.SetBackground((double)1, (double)1, (double)1); renWin.SetSize((int)400, (int)400); cam1 = ren1.GetActiveCamera(); cam1.SetClippingRange((double)3.76213, (double)10.712); cam1.SetFocalPoint((double)-0.0842503, (double)-0.136905, (double)0.610234); cam1.SetPosition((double)2.53813, (double)2.2678, (double)-5.22172); cam1.SetViewUp((double)-0.241047, (double)0.930635, (double)0.275343); iren.Initialize(); // render the image[] //[] // prevent the tk window from showing up then start the event loop[] //deleteAllVTKObjects(); }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVfieldToRGrid(String [] argv) { //Prefix Content is: "" //# Generate a rectilinear grid from a field.[] //#[] // get the interactor ui[] // Create a reader and write out the field[] reader = new vtkDataSetReader(); reader.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/RectGrid2.vtk"); ds2do = new vtkDataSetToDataObjectFilter(); ds2do.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort()); try { channel = new StreamWriter("RGridField.vtk"); tryCatchError = "NOERROR"; } catch (Exception) { tryCatchError = "ERROR"; } if (tryCatchError.Equals("NOERROR")) { channel.Close(); writer = new vtkDataObjectWriter(); writer.SetInputConnection((vtkAlgorithmOutput)ds2do.GetOutputPort()); writer.SetFileName((string)"RGridField.vtk"); writer.Write(); // Read the field[] //[] dor = new vtkDataObjectReader(); dor.SetFileName((string)"RGridField.vtk"); do2ds = new vtkDataObjectToDataSetFilter(); do2ds.SetInputConnection((vtkAlgorithmOutput)dor.GetOutputPort()); do2ds.SetDataSetTypeToRectilinearGrid(); do2ds.SetDimensionsComponent((string)"Dimensions", (int)0); do2ds.SetPointComponent((int)0, (string)"XCoordinates", (int)0); do2ds.SetPointComponent((int)1, (string)"YCoordinates", (int)0); do2ds.SetPointComponent((int)2, (string)"ZCoordinates", (int)0); do2ds.Update(); fd2ad = new vtkFieldDataToAttributeDataFilter(); fd2ad.SetInputData((vtkDataObject)do2ds.GetRectilinearGridOutput()); fd2ad.SetInputFieldToDataObjectField(); fd2ad.SetOutputAttributeDataToPointData(); fd2ad.SetVectorComponent((int)0, (string)"vectors", (int)0); fd2ad.SetVectorComponent((int)1, (string)"vectors", (int)1); fd2ad.SetVectorComponent((int)2, (string)"vectors", (int)2); fd2ad.SetScalarComponent((int)0, (string)"scalars", (int)0); fd2ad.Update(); // create pipeline[] //[] plane = new vtkRectilinearGridGeometryFilter(); plane.SetInputData((vtkDataObject)fd2ad.GetRectilinearGridOutput()); plane.SetExtent((int)0, (int)100, (int)0, (int)100, (int)15, (int)15); warper = new vtkWarpVector(); warper.SetInputConnection((vtkAlgorithmOutput)plane.GetOutputPort()); warper.SetScaleFactor((double)0.05); planeMapper = new vtkDataSetMapper(); planeMapper.SetInputConnection((vtkAlgorithmOutput)warper.GetOutputPort()); planeMapper.SetScalarRange((double)0.197813, (double)0.710419); planeActor = new vtkActor(); planeActor.SetMapper((vtkMapper)planeMapper); cutPlane = new vtkPlane(); cutPlane.SetOrigin(fd2ad.GetOutput().GetCenter()[0], fd2ad.GetOutput().GetCenter()[1], fd2ad.GetOutput().GetCenter()[2]); cutPlane.SetNormal((double)1, (double)0, (double)0); planeCut = new vtkCutter(); planeCut.SetInputData((vtkDataObject)fd2ad.GetRectilinearGridOutput()); planeCut.SetCutFunction((vtkImplicitFunction)cutPlane); cutMapper = new vtkDataSetMapper(); cutMapper.SetInputConnection((vtkAlgorithmOutput)planeCut.GetOutputPort()); cutMapper.SetScalarRange( (double)((vtkDataSet)fd2ad.GetOutput()).GetPointData().GetScalars().GetRange()[0], (double)((vtkDataSet)fd2ad.GetOutput()).GetPointData().GetScalars().GetRange()[1]); cutActor = new vtkActor(); cutActor.SetMapper((vtkMapper)cutMapper); iso = new vtkContourFilter(); iso.SetInputData((vtkDataObject)fd2ad.GetRectilinearGridOutput()); iso.SetValue((int)0, (double)0.7); normals = new vtkPolyDataNormals(); normals.SetInputConnection((vtkAlgorithmOutput)iso.GetOutputPort()); normals.SetFeatureAngle((double)45); isoMapper = vtkPolyDataMapper.New(); isoMapper.SetInputConnection((vtkAlgorithmOutput)normals.GetOutputPort()); isoMapper.ScalarVisibilityOff(); isoActor = new vtkActor(); isoActor.SetMapper((vtkMapper)isoMapper); isoActor.GetProperty().SetColor((double)1.0000, 0.8941, 0.7686); isoActor.GetProperty().SetRepresentationToWireframe(); streamer = new vtkStreamLine(); streamer.SetInputConnection((vtkAlgorithmOutput)fd2ad.GetOutputPort()); streamer.SetStartPosition((double)-1.2, (double)-0.1, (double)1.3); streamer.SetMaximumPropagationTime((double)500); streamer.SetStepLength((double)0.05); streamer.SetIntegrationStepLength((double)0.05); streamer.SetIntegrationDirectionToIntegrateBothDirections(); streamTube = new vtkTubeFilter(); streamTube.SetInputConnection((vtkAlgorithmOutput)streamer.GetOutputPort()); streamTube.SetRadius((double)0.025); streamTube.SetNumberOfSides((int)6); streamTube.SetVaryRadiusToVaryRadiusByVector(); mapStreamTube = vtkPolyDataMapper.New(); mapStreamTube.SetInputConnection((vtkAlgorithmOutput)streamTube.GetOutputPort()); mapStreamTube.SetScalarRange( (double)((vtkDataSet)fd2ad.GetOutput()).GetPointData().GetScalars().GetRange()[0], (double)((vtkDataSet)fd2ad.GetOutput()).GetPointData().GetScalars().GetRange()[1]); streamTubeActor = new vtkActor(); streamTubeActor.SetMapper((vtkMapper)mapStreamTube); streamTubeActor.GetProperty().BackfaceCullingOn(); outline = new vtkOutlineFilter(); outline.SetInputData((vtkDataObject)fd2ad.GetRectilinearGridOutput()); outlineMapper = vtkPolyDataMapper.New(); outlineMapper.SetInputConnection((vtkAlgorithmOutput)outline.GetOutputPort()); outlineActor = new vtkActor(); outlineActor.SetMapper((vtkMapper)outlineMapper); outlineActor.GetProperty().SetColor((double)0.0000, 0.0000, 0.0000); // Graphics stuff[] // Create the RenderWindow, Renderer and both Actors[] //[] ren1 = vtkRenderer.New(); renWin = vtkRenderWindow.New(); renWin.SetMultiSamples(0); renWin.AddRenderer((vtkRenderer)ren1); iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); // Add the actors to the renderer, set the background and size[] //[] ren1.AddActor((vtkProp)outlineActor); ren1.AddActor((vtkProp)planeActor); ren1.AddActor((vtkProp)cutActor); ren1.AddActor((vtkProp)isoActor); ren1.AddActor((vtkProp)streamTubeActor); ren1.SetBackground((double)1, (double)1, (double)1); renWin.SetSize((int)300, (int)300); ren1.GetActiveCamera().SetPosition((double)0.0390893, (double)0.184813, (double)-3.94026); ren1.GetActiveCamera().SetFocalPoint((double)-0.00578326, (double)0, (double)0.701967); ren1.GetActiveCamera().SetViewAngle((double)30); ren1.GetActiveCamera().SetViewUp((double)0.00850257, (double)0.999169, (double)0.0398605); ren1.GetActiveCamera().SetClippingRange((double)3.08127, (double)6.62716); iren.Initialize(); // render the image[] //[] File.Delete("RGridField.vtk"); } // prevent the tk window from showing up then start the event loop[] //deleteAllVTKObjects(); }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVfieldToUGrid(String [] argv) { //Prefix Content is: "" // Read a field representing unstructured grid and display it (similar to blow.tcl)[] // create a reader and write out field daya[] reader = new vtkUnstructuredGridReader(); reader.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/blow.vtk"); reader.SetScalarsName((string)"thickness9"); reader.SetVectorsName((string)"displacement9"); ds2do = new vtkDataSetToDataObjectFilter(); ds2do.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort()); // we must be able to write here[] try { channel = new StreamWriter("UGridField.vtk"); tryCatchError = "NOERROR"; } catch(Exception) {tryCatchError = "ERROR";} if (tryCatchError.Equals("NOERROR")) { channel.Close(); write = new vtkDataObjectWriter(); write.SetInputConnection((vtkAlgorithmOutput)ds2do.GetOutputPort()); write.SetFileName((string)"UGridField.vtk"); write.Write(); // Read the field and convert to unstructured grid.[] dor = new vtkDataObjectReader(); dor.SetFileName((string)"UGridField.vtk"); do2ds = new vtkDataObjectToDataSetFilter(); do2ds.SetInputConnection((vtkAlgorithmOutput)dor.GetOutputPort()); do2ds.SetDataSetTypeToUnstructuredGrid(); do2ds.SetPointComponent((int)0,(string)"Points",(int)0); do2ds.SetPointComponent((int)1,(string)"Points",(int)1); do2ds.SetPointComponent((int)2,(string)"Points",(int)2); do2ds.SetCellTypeComponent((string)"CellTypes",(int)0); do2ds.SetCellConnectivityComponent((string)"Cells",(int)0); fd2ad = new vtkFieldDataToAttributeDataFilter(); fd2ad.SetInput((vtkDataObject)do2ds.GetUnstructuredGridOutput()); fd2ad.SetInputFieldToDataObjectField(); fd2ad.SetOutputAttributeDataToPointData(); fd2ad.SetVectorComponent((int)0,(string)"displacement9",(int)0); fd2ad.SetVectorComponent((int)1,(string)"displacement9",(int)1); fd2ad.SetVectorComponent((int)2,(string)"displacement9",(int)2); fd2ad.SetScalarComponent((int)0,(string)"thickness9",(int)0); // Now start visualizing[] warp = new vtkWarpVector(); warp.SetInput((vtkDataObject)fd2ad.GetUnstructuredGridOutput()); // extract mold from mesh using connectivity[] connect = new vtkConnectivityFilter(); connect.SetInputConnection((vtkAlgorithmOutput)warp.GetOutputPort()); connect.SetExtractionModeToSpecifiedRegions(); connect.AddSpecifiedRegion((int)0); connect.AddSpecifiedRegion((int)1); moldMapper = new vtkDataSetMapper(); moldMapper.SetInputConnection((vtkAlgorithmOutput)connect.GetOutputPort()); moldMapper.ScalarVisibilityOff(); moldActor = new vtkActor(); moldActor.SetMapper((vtkMapper)moldMapper); moldActor.GetProperty().SetColor((double).2,(double).2,(double).2); moldActor.GetProperty().SetRepresentationToWireframe(); // extract parison from mesh using connectivity[] connect2 = new vtkConnectivityFilter(); connect2.SetInputConnection((vtkAlgorithmOutput)warp.GetOutputPort()); connect2.SetExtractionModeToSpecifiedRegions(); connect2.AddSpecifiedRegion((int)2); parison = new vtkGeometryFilter(); parison.SetInputConnection((vtkAlgorithmOutput)connect2.GetOutputPort()); normals2 = new vtkPolyDataNormals(); normals2.SetInputConnection((vtkAlgorithmOutput)parison.GetOutputPort()); normals2.SetFeatureAngle((double)60); lut = new vtkLookupTable(); lut.SetHueRange((double)0.0,(double)0.66667); parisonMapper = vtkPolyDataMapper.New(); parisonMapper.SetInputConnection((vtkAlgorithmOutput)normals2.GetOutputPort()); parisonMapper.SetLookupTable((vtkScalarsToColors)lut); parisonMapper.SetScalarRange((double)0.12,(double)1.0); parisonActor = new vtkActor(); parisonActor.SetMapper((vtkMapper)parisonMapper); cf = new vtkContourFilter(); cf.SetInputConnection((vtkAlgorithmOutput)connect2.GetOutputPort()); cf.SetValue((int)0,(double).5); contourMapper = vtkPolyDataMapper.New(); contourMapper.SetInputConnection((vtkAlgorithmOutput)cf.GetOutputPort()); contours = new vtkActor(); contours.SetMapper((vtkMapper)contourMapper); // Create graphics stuff[] ren1 = vtkRenderer.New(); renWin = vtkRenderWindow.New(); renWin.AddRenderer((vtkRenderer)ren1); iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); // Add the actors to the renderer, set the background and size[] ren1.AddActor((vtkProp)moldActor); ren1.AddActor((vtkProp)parisonActor); ren1.AddActor((vtkProp)contours); ren1.ResetCamera(); ren1.GetActiveCamera().Azimuth((double)60); ren1.GetActiveCamera().Roll((double)-90); ren1.GetActiveCamera().Dolly((double)2); ren1.ResetCameraClippingRange(); ren1.SetBackground((double)1,(double)1,(double)1); renWin.SetSize((int)375,(int)200); iren.Initialize(); } // prevent the tk window from showing up then start the event loop[] //deleteAllVTKObjects(); }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVTestPolyDataPieces(String [] argv) { //Prefix Content is: "" math = new vtkMath(); vtkMath.RandomSeed((int)22); pf = new vtkParallelFactory(); vtkParallelFactory.RegisterFactory((vtkObjectFactory)pf); sphere = new vtkSphereSource(); sphere.SetPhiResolution((int)32); sphere.SetThetaResolution((int)32); extract = new vtkExtractPolyDataPiece(); extract.SetInputConnection((vtkAlgorithmOutput)sphere.GetOutputPort()); normals = new vtkPolyDataNormals(); normals.SetInputConnection((vtkAlgorithmOutput)extract.GetOutputPort()); ps = new vtkPieceScalars(); ps.SetInputConnection((vtkAlgorithmOutput)normals.GetOutputPort()); mapper = vtkPolyDataMapper.New(); mapper.SetInputConnection((vtkAlgorithmOutput)ps.GetOutputPort()); mapper.SetNumberOfPieces((int)2); actor = new vtkActor(); actor.SetMapper((vtkMapper)mapper); sphere2 = new vtkSphereSource(); sphere2.SetPhiResolution((int)32); sphere2.SetThetaResolution((int)32); extract2 = new vtkExtractPolyDataPiece(); extract2.SetInputConnection((vtkAlgorithmOutput)sphere2.GetOutputPort()); mapper2 = vtkPolyDataMapper.New(); mapper2.SetInputConnection((vtkAlgorithmOutput)extract2.GetOutputPort()); mapper2.SetNumberOfPieces((int)2); mapper2.SetPiece((int)1); mapper2.SetScalarRange((double)0,(double)4); mapper2.SetScalarModeToUseCellFieldData(); mapper2.SetColorModeToMapScalars(); mapper2.ColorByArrayComponent((string)"vtkGhostLevels",(int)0); mapper2.SetGhostLevel((int)4); // check the pipeline size[] extract2.UpdateInformation(); psize = new vtkPipelineSize(); if ((psize.GetEstimatedSize((vtkAlgorithm)extract2,(int)0,(int)0)) > 100) { //puts skipedputs ['stderr', '"ERROR: Pipeline Size increased"'] } if ((psize.GetNumberOfSubPieces((uint)10,(vtkPolyDataMapper)mapper2)) != 2) { //puts skipedputs ['stderr', '"ERROR: Number of sub pieces changed"'] } actor2 = new vtkActor(); actor2.SetMapper((vtkMapper)mapper2); actor2.SetPosition((double)1.5,(double)0,(double)0); sphere3 = new vtkSphereSource(); sphere3.SetPhiResolution((int)32); sphere3.SetThetaResolution((int)32); extract3 = new vtkExtractPolyDataPiece(); extract3.SetInputConnection((vtkAlgorithmOutput)sphere3.GetOutputPort()); ps3 = new vtkPieceScalars(); ps3.SetInputConnection((vtkAlgorithmOutput)extract3.GetOutputPort()); mapper3 = vtkPolyDataMapper.New(); mapper3.SetInputConnection((vtkAlgorithmOutput)ps3.GetOutputPort()); mapper3.SetNumberOfSubPieces((int)8); mapper3.SetScalarRange((double)0,(double)8); actor3 = new vtkActor(); actor3.SetMapper((vtkMapper)mapper3); actor3.SetPosition((double)0,(double)-1.5,(double)0); sphere4 = new vtkSphereSource(); sphere4.SetPhiResolution((int)32); sphere4.SetThetaResolution((int)32); extract4 = new vtkExtractPolyDataPiece(); extract4.SetInputConnection((vtkAlgorithmOutput)sphere4.GetOutputPort()); ps4 = new vtkPieceScalars(); ps4.RandomModeOn(); ps4.SetScalarModeToCellData(); ps4.SetInputConnection((vtkAlgorithmOutput)extract4.GetOutputPort()); mapper4 = vtkPolyDataMapper.New(); mapper4.SetInputConnection((vtkAlgorithmOutput)ps4.GetOutputPort()); mapper4.SetNumberOfSubPieces((int)8); mapper4.SetScalarRange((double)0,(double)8); actor4 = new vtkActor(); actor4.SetMapper((vtkMapper)mapper4); actor4.SetPosition((double)1.5,(double)-1.5,(double)0); ren = vtkRenderer.New(); ren.AddActor((vtkProp)actor); ren.AddActor((vtkProp)actor2); ren.AddActor((vtkProp)actor3); ren.AddActor((vtkProp)actor4); renWin = vtkRenderWindow.New(); renWin.AddRenderer((vtkRenderer)ren); iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); iren.Initialize(); //deleteAllVTKObjects(); }