public void ApplySetting(string setting) { if (setting == "Visible") { if (_volumeGraphic.TissueSettings.Visible) { _vtkActor.VisibilityOn(); } else { _vtkActor.VisibilityOff(); } _vtkActor.ApplyProperties(); } else if (setting == "Opacity") { _vtkActor.GetProperty().SetOpacity((double)_volumeGraphic.TissueSettings.Opacity); _vtkActor.ApplyProperties(); } else if (setting == "Level") { _contourFilter.SetValue(0, _volumeGraphic.GetRescaledLevel()); double R = _volumeGraphic.TissueSettings.MinimumColor.R / 255.0f; double G = _volumeGraphic.TissueSettings.MinimumColor.G / 255.0f; double B = _volumeGraphic.TissueSettings.MinimumColor.B / 255.0f; _vtkActor.GetProperty().SetDiffuseColor(R, G, B); } }
void RenderSlicer() { //Create all the objects for the pipeline vtkXMLImageDataReader reader = vtkXMLImageDataReader.New(); vtkImageActor iactor = vtkImageActor.New(); vtkImageClip clip = vtkImageClip.New(); vtkContourFilter contour = vtkContourFilter.New(); vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); vtkActor actor = vtkActor.New(); vtkInteractorStyleImage style = vtkInteractorStyleImage.New(); vtkRenderer renderer = renderWindowControl2.RenderWindow.GetRenderers().GetFirstRenderer(); //Read the Image reader.SetFileName(m_FileName); //Go through the visulization pipeline iactor.SetInput(reader.GetOutput()); renderer.AddActor(iactor); reader.Update(); int[] extent = reader.GetOutput().GetWholeExtent(); iactor.SetDisplayExtent(extent[0], extent[1], extent[2], extent[3], (extent[4] + extent[5]) / 2, (extent[4] + extent[5]) / 2); clip.SetInputConnection(reader.GetOutputPort()); clip.SetOutputWholeExtent(extent[0], extent[1], extent[2], extent[3], (extent[4] + extent[5]) / 2, (extent[4] + extent[5]) / 2); contour.SetInputConnection(clip.GetOutputPort()); contour.SetValue(0, 100); mapper.SetInputConnection(contour.GetOutputPort()); mapper.SetScalarVisibility(1); //Go through the graphics pipeline actor.SetMapper(mapper); actor.GetProperty().SetColor(0, 1, 0); renderer.AddActor(actor); //Give a new style to the interactor //vtkRenderWindowInteractor iren = renderWindowControl2.RenderWindow.GetInteractor(); //iren.SetInteractorStyle(style); //Update global variables this.trackBar1.Maximum = extent[5]; this.trackBar1.Minimum = extent[4]; //this.Interactor = iren; this.m_SliceRenderWindow = renderWindowControl2.RenderWindow; this.m_SliceRenderer = renderer; this.m_SliceClip = clip; this.m_SliceImageActor = iactor; renderer.ResetCamera(); this.m_SliceRenderer.ResetCameraClippingRange(); this.m_SliceRenderWindow.Render(); }
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(); }
private void CreateSurfaceRendering() { _contourFilter = new vtk.vtkContourFilter(); _contourFilter.SetInput(_volumeGraphic.GetImageData()); _contourFilter.SetValue(0, _volumeGraphic.GetRescaledLevel()); vtkPolyDataNormals normals = new vtk.vtkPolyDataNormals(); normals.SetInputConnection(_contourFilter.GetOutputPort()); normals.SetFeatureAngle(60.0); vtkStripper stripper = new vtk.vtkStripper(); stripper.SetInputConnection(normals.GetOutputPort()); vtkPolyDataMapper mapper = new vtk.vtkPolyDataMapper(); mapper.SetInputConnection(stripper.GetOutputPort()); mapper.ScalarVisibilityOff(); _vtkActor = new vtk.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 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(); }
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 AVExtractTensors(String [] argv) { //Prefix Content is: "" // create tensor ellipsoids[] // Create the RenderWindow, Renderer and interactive renderer[] //[] ren1 = vtkRenderer.New(); renWin = vtkRenderWindow.New(); renWin.AddRenderer((vtkRenderer)ren1); iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); ptLoad = new vtkPointLoad(); ptLoad.SetLoadValue((double)100.0); ptLoad.SetSampleDimensions((int)30,(int)30,(int)30); ptLoad.ComputeEffectiveStressOn(); ptLoad.SetModelBounds((double)-10,(double)10,(double)-10,(double)10,(double)-10,(double)10); extractTensor = new vtkExtractTensorComponents(); extractTensor.SetInputConnection((vtkAlgorithmOutput)ptLoad.GetOutputPort()); extractTensor.ScalarIsEffectiveStress(); extractTensor.ScalarIsComponent(); extractTensor.ExtractScalarsOn(); extractTensor.ExtractVectorsOn(); extractTensor.ExtractNormalsOff(); extractTensor.ExtractTCoordsOn(); contour = new vtkContourFilter(); contour.SetInputConnection((vtkAlgorithmOutput)extractTensor.GetOutputPort()); contour.SetValue((int)0,(double)0); probe = new vtkProbeFilter(); probe.SetInputConnection((vtkAlgorithmOutput)contour.GetOutputPort()); probe.SetSource((vtkDataObject)ptLoad.GetOutput()); su = new vtkLoopSubdivisionFilter(); su.SetInputConnection((vtkAlgorithmOutput)probe.GetOutputPort()); su.SetNumberOfSubdivisions((int)1); s1Mapper = vtkPolyDataMapper.New(); s1Mapper.SetInputConnection((vtkAlgorithmOutput)probe.GetOutputPort()); // s1Mapper SetInputConnection [su GetOutputPort][] s1Actor = new vtkActor(); s1Actor.SetMapper((vtkMapper)s1Mapper); //[] // plane for context[] //[] g = new vtkImageDataGeometryFilter(); g.SetInputConnection((vtkAlgorithmOutput)ptLoad.GetOutputPort()); g.SetExtent((int)0,(int)100,(int)0,(int)100,(int)0,(int)0); g.Update(); //for scalar range[] gm = vtkPolyDataMapper.New(); gm.SetInputConnection((vtkAlgorithmOutput)g.GetOutputPort()); gm.SetScalarRange((double)((vtkDataSet)g.GetOutput()).GetScalarRange()[0],(double)((vtkDataSet)g.GetOutput()).GetScalarRange()[1]); ga = new vtkActor(); ga.SetMapper((vtkMapper)gm); s1Mapper.SetScalarRange((double)((vtkDataSet)g.GetOutput()).GetScalarRange()[0],(double)((vtkDataSet)g.GetOutput()).GetScalarRange()[1]); //[] // 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)s1Actor); ren1.AddActor((vtkProp)outlineActor); ren1.AddActor((vtkProp)coneActor); ren1.AddActor((vtkProp)ga); ren1.SetBackground((double)1.0,(double)1.0,(double)1.0); ren1.SetActiveCamera((vtkCamera)camera); renWin.SetSize((int)300,(int)300); 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> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVmultipleIso(String [] argv) { //Prefix Content is: "" // get the interactor ui[] //# 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); 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); pl3d.SetVectorFunctionNumber((int)202); pl3d.Update(); range = ((vtkDataSet)pl3d.GetOutput().GetBlock(0)).GetPointData().GetScalars().GetRange(); min = (double)(lindex(range, 0)); max = (double)(lindex(range, 1)); value = (min + max) / 2.0; cf = new vtkContourFilter(); cf.SetInputData((vtkDataSet)pl3d.GetOutput().GetBlock(0)); cf.SetValue((int)0, (double)value); cf.UseScalarTreeOn(); numberOfContours = 5; epsilon = (double)(max - min) / (double)(numberOfContours * 10); min = min + epsilon; max = max - epsilon; i = 1; while ((i) <= numberOfContours) { cf.SetValue((int)0, (double)min + ((i - 1) / (double)(numberOfContours - 1)) * (max - min)); cf.Update(); pd[i] = new vtkPolyData(); pd[i].CopyStructure((vtkDataSet)cf.GetOutput()); pd[i].GetPointData().DeepCopy((vtkFieldData)cf.GetOutput().GetPointData()); mapper[i] = vtkPolyDataMapper.New(); mapper[i].SetInputData((vtkPolyData)pd[i]); mapper[i].SetScalarRange((double)((vtkDataSet)pl3d.GetOutput().GetBlock(0)).GetPointData().GetScalars().GetRange()[0], (double)((vtkDataSet)pl3d.GetOutput().GetBlock(0)).GetPointData().GetScalars().GetRange()[1]); actor[i] = new vtkActor(); actor[i].AddPosition((double)0, (double)i * 12, (double)0); actor[i].SetMapper((vtkMapper)mapper[i]); ren1.AddActor((vtkProp)actor[i]); i = i + 1; } // Add the actors to the renderer, set the background and size[] //[] ren1.SetBackground((double).3, (double).3, (double).3); renWin.SetSize((int)450, (int)150); cam1 = ren1.GetActiveCamera(); ren1.GetActiveCamera().SetPosition((double)-36.3762, (double)32.3855, (double)51.3652); ren1.GetActiveCamera().SetFocalPoint((double)8.255, (double)33.3861, (double)29.7687); ren1.GetActiveCamera().SetViewAngle((double)30); ren1.GetActiveCamera().SetViewUp((double)0, (double)0, (double)1); ren1.ResetCameraClippingRange(); 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 AVTestGridSynchronizedTemplates3D(String [] argv) { //Prefix Content is: "" // cut data[] 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); pl3d.SetVectorFunctionNumber((int)202); pl3d.Update(); range = ((vtkDataSet)pl3d.GetOutput().GetBlock(0)).GetPointData().GetScalars().GetRange(); min = (double)(lindex(range,0)); max = (double)(lindex(range,1)); value = (min+max)/2.0; //vtkGridSynchronizedTemplates3D cf[] cf = new vtkContourFilter(); cf.SetInputData((vtkDataSet)pl3d.GetOutput().GetBlock(0)); cf.SetValue((int)0,(double)value); //cf ComputeNormalsOff[] cfMapper = vtkPolyDataMapper.New(); cfMapper.ImmediateModeRenderingOn(); cfMapper.SetInputConnection((vtkAlgorithmOutput)cf.GetOutputPort()); cfMapper.SetScalarRange((double)((vtkDataSet)pl3d.GetOutput().GetBlock(0)).GetPointData().GetScalars().GetRange()[0], (double)((vtkDataSet)pl3d.GetOutput().GetBlock(0)).GetPointData().GetScalars().GetRange()[1]); cfActor = new vtkActor(); cfActor.SetMapper((vtkMapper)cfMapper); //outline[] outline = new vtkStructuredGridOutlineFilter(); outline.SetInputData((vtkDataSet)pl3d.GetOutput().GetBlock(0)); outlineMapper = vtkPolyDataMapper.New(); outlineMapper.SetInputConnection((vtkAlgorithmOutput)outline.GetOutputPort()); outlineActor = new vtkActor(); outlineActor.SetMapper((vtkMapper)outlineMapper); outlineActor.GetProperty().SetColor((double)0,(double)0,(double)0); //# 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)cfActor); ren1.SetBackground((double)1,(double)1,(double)1); renWin.SetSize((int)400,(int)400); cam1 = ren1.GetActiveCamera(); cam1.SetClippingRange((double)3.95297,(double)50); cam1.SetFocalPoint((double)9.71821,(double)0.458166,(double)29.3999); cam1.SetPosition((double)2.7439,(double)-37.3196,(double)38.7167); cam1.SetViewUp((double)-0.16123,(double)0.264271,(double)0.950876); iren.Initialize(); // render the image[] //[] // loop over surfaces[] i = 0; while((i) < 17) { cf.SetValue((int)0,(double)min+(i/16.0)*(max-min)); renWin.Render(); i = i + 1; } cf.SetValue((int)0,(double)min+(0.2)*(max-min)); 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 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 AVExtractTensors(String [] argv) { //Prefix Content is: "" // create tensor ellipsoids[] // Create the RenderWindow, Renderer and interactive renderer[] //[] ren1 = vtkRenderer.New(); renWin = vtkRenderWindow.New(); renWin.AddRenderer((vtkRenderer)ren1); iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); ptLoad = new vtkPointLoad(); ptLoad.SetLoadValue((double)100.0); ptLoad.SetSampleDimensions((int)30, (int)30, (int)30); ptLoad.ComputeEffectiveStressOn(); ptLoad.SetModelBounds((double)-10, (double)10, (double)-10, (double)10, (double)-10, (double)10); extractTensor = new vtkExtractTensorComponents(); extractTensor.SetInputConnection((vtkAlgorithmOutput)ptLoad.GetOutputPort()); extractTensor.ScalarIsEffectiveStress(); extractTensor.ScalarIsComponent(); extractTensor.ExtractScalarsOn(); extractTensor.ExtractVectorsOn(); extractTensor.ExtractNormalsOff(); extractTensor.ExtractTCoordsOn(); contour = new vtkContourFilter(); contour.SetInputConnection((vtkAlgorithmOutput)extractTensor.GetOutputPort()); contour.SetValue((int)0, (double)0); probe = new vtkProbeFilter(); probe.SetInputConnection((vtkAlgorithmOutput)contour.GetOutputPort()); probe.SetSourceConnection(ptLoad.GetOutputPort()); su = new vtkLoopSubdivisionFilter(); su.SetInputConnection((vtkAlgorithmOutput)probe.GetOutputPort()); su.SetNumberOfSubdivisions((int)1); s1Mapper = vtkPolyDataMapper.New(); s1Mapper.SetInputConnection((vtkAlgorithmOutput)probe.GetOutputPort()); // s1Mapper SetInputConnection [su GetOutputPort][] s1Actor = new vtkActor(); s1Actor.SetMapper((vtkMapper)s1Mapper); //[] // plane for context[] //[] g = new vtkImageDataGeometryFilter(); g.SetInputConnection((vtkAlgorithmOutput)ptLoad.GetOutputPort()); g.SetExtent((int)0, (int)100, (int)0, (int)100, (int)0, (int)0); g.Update(); //for scalar range[] gm = vtkPolyDataMapper.New(); gm.SetInputConnection((vtkAlgorithmOutput)g.GetOutputPort()); gm.SetScalarRange((double)((vtkDataSet)g.GetOutput()).GetScalarRange()[0], (double)((vtkDataSet)g.GetOutput()).GetScalarRange()[1]); ga = new vtkActor(); ga.SetMapper((vtkMapper)gm); s1Mapper.SetScalarRange((double)((vtkDataSet)g.GetOutput()).GetScalarRange()[0], (double)((vtkDataSet)g.GetOutput()).GetScalarRange()[1]); //[] // 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)s1Actor); ren1.AddActor((vtkProp)outlineActor); ren1.AddActor((vtkProp)coneActor); ren1.AddActor((vtkProp)ga); ren1.SetBackground((double)1.0, (double)1.0, (double)1.0); ren1.SetActiveCamera((vtkCamera)camera); renWin.SetSize((int)300, (int)300); 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 AVTestPDataSetReaderGrid(String [] argv) { //Prefix Content is: "" // Create the RenderWindow, Renderer and both Actors[] //[] ren1 = vtkRenderer.New(); renWin = vtkRenderWindow.New(); renWin.AddRenderer((vtkRenderer)ren1); iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); //[] // If the current directory is writable, then test the witers[] //[] try { channel = new StreamWriter("test.tmp"); tryCatchError = "NOERROR"; } catch(Exception) { tryCatchError = "ERROR"; } if(tryCatchError.Equals("NOERROR")) { channel.Close(); File.Delete("test.tmp"); // ====== Structured Grid ======[] // First save out a grid in parallel form.[] reader = new vtkMultiBlockPLOT3DReader(); reader.SetXYZFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/combxyz.bin"); reader.SetQFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/combq.bin"); writer = new vtkPDataSetWriter(); writer.SetFileName((string)"comb.pvtk"); writer.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort()); writer.SetNumberOfPieces((int)4); writer.Write(); pReader = new vtkPDataSetReader(); pReader.SetFileName((string)"comb.pvtk"); surface = new vtkDataSetSurfaceFilter(); surface.SetInputConnection((vtkAlgorithmOutput)pReader.GetOutputPort()); mapper = vtkPolyDataMapper.New(); mapper.SetInputConnection((vtkAlgorithmOutput)surface.GetOutputPort()); mapper.SetNumberOfPieces((int)2); mapper.SetPiece((int)0); mapper.SetGhostLevel((int)1); mapper.Update(); File.Delete("comb.pvtk"); File.Delete("comb.0.vtk"); File.Delete("comb.1.vtk"); File.Delete("comb.2.vtk"); File.Delete("comb.3.vtk"); actor = new vtkActor(); actor.SetMapper((vtkMapper)mapper); actor.SetPosition((double)-5,(double)0,(double)-29); // Add the actors to the renderer, set the background and size[] //[] ren1.AddActor((vtkProp)actor); // ====== ImageData ======[] // First save out a grid in parallel form.[] fractal = new vtkImageMandelbrotSource(); fractal.SetWholeExtent((int)0,(int)9,(int)0,(int)9,(int)0,(int)9); fractal.SetSampleCX((double)0.1,(double)0.1,(double)0.1,(double)0.1); fractal.SetMaximumNumberOfIterations((ushort)10); writer2 = new vtkPDataSetWriter(); writer.SetFileName((string)"fractal.pvtk"); writer.SetInputConnection((vtkAlgorithmOutput)fractal.GetOutputPort()); writer.SetNumberOfPieces((int)4); writer.Write(); pReader2 = new vtkPDataSetReader(); pReader2.SetFileName((string)"fractal.pvtk"); iso = new vtkContourFilter(); iso.SetInputConnection((vtkAlgorithmOutput)pReader2.GetOutputPort()); iso.SetValue((int)0,(double)4); mapper2 = vtkPolyDataMapper.New(); mapper2.SetInputConnection((vtkAlgorithmOutput)iso.GetOutputPort()); mapper2.SetNumberOfPieces((int)3); mapper2.SetPiece((int)0); mapper2.SetGhostLevel((int)0); mapper2.Update(); File.Delete("fractal.pvtk"); File.Delete("fractal.0.vtk"); File.Delete("fractal.1.vtk"); File.Delete("fractal.2.vtk"); File.Delete("fractal.3.vtk"); actor2 = new vtkActor(); actor2.SetMapper((vtkMapper)mapper2); actor2.SetScale((double)5,(double)5,(double)5); actor2.SetPosition((double)6,(double)6,(double)6); // Add the actors to the renderer, set the background and size[] //[] ren1.AddActor((vtkProp)actor2); // ====== PolyData ======[] // First save out a grid in parallel form.[] sphere = new vtkSphereSource(); sphere.SetRadius((double)2); writer3 = new vtkPDataSetWriter(); writer3.SetFileName((string)"sphere.pvtk"); writer3.SetInputConnection((vtkAlgorithmOutput)sphere.GetOutputPort()); writer3.SetNumberOfPieces((int)4); writer3.Write(); pReader3 = new vtkPDataSetReader(); pReader3.SetFileName((string)"sphere.pvtk"); mapper3 = vtkPolyDataMapper.New(); mapper3.SetInputConnection((vtkAlgorithmOutput)pReader3.GetOutputPort()); mapper3.SetNumberOfPieces((int)2); mapper3.SetPiece((int)0); mapper3.SetGhostLevel((int)1); mapper3.Update(); File.Delete("sphere.pvtk"); File.Delete("sphere.0.vtk"); File.Delete("sphere.1.vtk"); File.Delete("sphere.2.vtk"); File.Delete("sphere.3.vtk"); actor3 = new vtkActor(); actor3.SetMapper((vtkMapper)mapper3); actor3.SetPosition((double)6,(double)6,(double)6); // Add the actors to the renderer, set the background and size[] //[] ren1.AddActor((vtkProp)actor3); } ren1.SetBackground((double)0.1,(double)0.2,(double)0.4); renWin.SetSize((int)300,(int)300); // render the image[] //[] cam1 = ren1.GetActiveCamera(); cam1.Azimuth((double)20); cam1.Elevation((double)40); ren1.ResetCamera(); cam1.Zoom((double)1.2); 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 AVTestPDataSetReaderGrid(String [] argv) { //Prefix Content is: "" // Create the RenderWindow, Renderer and both Actors[] //[] ren1 = vtkRenderer.New(); renWin = vtkRenderWindow.New(); renWin.AddRenderer((vtkRenderer)ren1); iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); //[] // If the current directory is writable, then test the witers[] //[] try { channel = new StreamWriter("test.tmp"); tryCatchError = "NOERROR"; } catch (Exception) { tryCatchError = "ERROR"; } if (tryCatchError.Equals("NOERROR")) { channel.Close(); File.Delete("test.tmp"); // ====== Structured Grid ======[] // First save out a grid in parallel form.[] reader = new vtkMultiBlockPLOT3DReader(); reader.SetXYZFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/combxyz.bin"); reader.SetQFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/combq.bin"); writer = new vtkPDataSetWriter(); writer.SetFileName((string)"comb.pvtk"); writer.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort()); writer.SetNumberOfPieces((int)4); writer.Write(); pReader = new vtkPDataSetReader(); pReader.SetFileName((string)"comb.pvtk"); surface = new vtkDataSetSurfaceFilter(); surface.SetInputConnection((vtkAlgorithmOutput)pReader.GetOutputPort()); mapper = vtkPolyDataMapper.New(); mapper.SetInputConnection((vtkAlgorithmOutput)surface.GetOutputPort()); mapper.SetNumberOfPieces((int)2); mapper.SetPiece((int)0); mapper.SetGhostLevel((int)1); mapper.Update(); File.Delete("comb.pvtk"); File.Delete("comb.0.vtk"); File.Delete("comb.1.vtk"); File.Delete("comb.2.vtk"); File.Delete("comb.3.vtk"); actor = new vtkActor(); actor.SetMapper((vtkMapper)mapper); actor.SetPosition((double)-5, (double)0, (double)-29); // Add the actors to the renderer, set the background and size[] //[] ren1.AddActor((vtkProp)actor); // ====== ImageData ======[] // First save out a grid in parallel form.[] fractal = new vtkImageMandelbrotSource(); fractal.SetWholeExtent((int)0, (int)9, (int)0, (int)9, (int)0, (int)9); fractal.SetSampleCX((double)0.1, (double)0.1, (double)0.1, (double)0.1); fractal.SetMaximumNumberOfIterations((ushort)10); writer2 = new vtkPDataSetWriter(); writer.SetFileName((string)"fractal.pvtk"); writer.SetInputConnection((vtkAlgorithmOutput)fractal.GetOutputPort()); writer.SetNumberOfPieces((int)4); writer.Write(); pReader2 = new vtkPDataSetReader(); pReader2.SetFileName((string)"fractal.pvtk"); iso = new vtkContourFilter(); iso.SetInputConnection((vtkAlgorithmOutput)pReader2.GetOutputPort()); iso.SetValue((int)0, (double)4); mapper2 = vtkPolyDataMapper.New(); mapper2.SetInputConnection((vtkAlgorithmOutput)iso.GetOutputPort()); mapper2.SetNumberOfPieces((int)3); mapper2.SetPiece((int)0); mapper2.SetGhostLevel((int)0); mapper2.Update(); File.Delete("fractal.pvtk"); File.Delete("fractal.0.vtk"); File.Delete("fractal.1.vtk"); File.Delete("fractal.2.vtk"); File.Delete("fractal.3.vtk"); actor2 = new vtkActor(); actor2.SetMapper((vtkMapper)mapper2); actor2.SetScale((double)5, (double)5, (double)5); actor2.SetPosition((double)6, (double)6, (double)6); // Add the actors to the renderer, set the background and size[] //[] ren1.AddActor((vtkProp)actor2); // ====== PolyData ======[] // First save out a grid in parallel form.[] sphere = new vtkSphereSource(); sphere.SetRadius((double)2); writer3 = new vtkPDataSetWriter(); writer3.SetFileName((string)"sphere.pvtk"); writer3.SetInputConnection((vtkAlgorithmOutput)sphere.GetOutputPort()); writer3.SetNumberOfPieces((int)4); writer3.Write(); pReader3 = new vtkPDataSetReader(); pReader3.SetFileName((string)"sphere.pvtk"); mapper3 = vtkPolyDataMapper.New(); mapper3.SetInputConnection((vtkAlgorithmOutput)pReader3.GetOutputPort()); mapper3.SetNumberOfPieces((int)2); mapper3.SetPiece((int)0); mapper3.SetGhostLevel((int)1); mapper3.Update(); File.Delete("sphere.pvtk"); File.Delete("sphere.0.vtk"); File.Delete("sphere.1.vtk"); File.Delete("sphere.2.vtk"); File.Delete("sphere.3.vtk"); actor3 = new vtkActor(); actor3.SetMapper((vtkMapper)mapper3); actor3.SetPosition((double)6, (double)6, (double)6); // Add the actors to the renderer, set the background and size[] //[] ren1.AddActor((vtkProp)actor3); } ren1.SetBackground((double)0.1, (double)0.2, (double)0.4); renWin.SetSize((int)300, (int)300); // render the image[] //[] cam1 = ren1.GetActiveCamera(); cam1.Azimuth((double)20); cam1.Elevation((double)40); ren1.ResetCamera(); cam1.Zoom((double)1.2); 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 AVTestGridSynchronizedTemplates3D(String [] argv) { //Prefix Content is: "" // cut data[] 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); pl3d.SetVectorFunctionNumber((int)202); pl3d.Update(); range = ((vtkDataSet)pl3d.GetOutput().GetBlock(0)).GetPointData().GetScalars().GetRange(); min = (double)(lindex(range, 0)); max = (double)(lindex(range, 1)); value = (min + max) / 2.0; //vtkGridSynchronizedTemplates3D cf[] cf = new vtkContourFilter(); cf.SetInputData((vtkDataSet)pl3d.GetOutput().GetBlock(0)); cf.SetValue((int)0, (double)value); //cf ComputeNormalsOff[] cfMapper = vtkPolyDataMapper.New(); cfMapper.ImmediateModeRenderingOn(); cfMapper.SetInputConnection((vtkAlgorithmOutput)cf.GetOutputPort()); cfMapper.SetScalarRange((double)((vtkDataSet)pl3d.GetOutput().GetBlock(0)).GetPointData().GetScalars().GetRange()[0], (double)((vtkDataSet)pl3d.GetOutput().GetBlock(0)).GetPointData().GetScalars().GetRange()[1]); cfActor = new vtkActor(); cfActor.SetMapper((vtkMapper)cfMapper); //outline[] outline = new vtkStructuredGridOutlineFilter(); outline.SetInputData((vtkDataSet)pl3d.GetOutput().GetBlock(0)); outlineMapper = vtkPolyDataMapper.New(); outlineMapper.SetInputConnection((vtkAlgorithmOutput)outline.GetOutputPort()); outlineActor = new vtkActor(); outlineActor.SetMapper((vtkMapper)outlineMapper); outlineActor.GetProperty().SetColor((double)0, (double)0, (double)0); //# 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)cfActor); ren1.SetBackground((double)1, (double)1, (double)1); renWin.SetSize((int)400, (int)400); cam1 = ren1.GetActiveCamera(); cam1.SetClippingRange((double)3.95297, (double)50); cam1.SetFocalPoint((double)9.71821, (double)0.458166, (double)29.3999); cam1.SetPosition((double)2.7439, (double)-37.3196, (double)38.7167); cam1.SetViewUp((double)-0.16123, (double)0.264271, (double)0.950876); iren.Initialize(); // render the image[] //[] // loop over surfaces[] i = 0; while ((i) < 17) { cf.SetValue((int)0, (double)min + (i / 16.0) * (max - min)); renWin.Render(); i = i + 1; } cf.SetValue((int)0, (double)min + (0.2) * (max - min)); 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 AVmultipleIso(String [] argv) { //Prefix Content is: "" // get the interactor ui[] //# 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); pl3d = new vtkPLOT3DReader(); pl3d.SetXYZFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/combxyz.bin"); pl3d.SetQFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/combq.bin"); pl3d.SetScalarFunctionNumber((int)100); pl3d.SetVectorFunctionNumber((int)202); pl3d.Update(); range = pl3d.GetOutput().GetPointData().GetScalars().GetRange(); min = (double)(lindex(range,0)); max = (double)(lindex(range,1)); value = (min+max)/2.0; cf = new vtkContourFilter(); cf.SetInputConnection((vtkAlgorithmOutput)pl3d.GetOutputPort()); cf.SetValue((int)0,(double)value); cf.UseScalarTreeOn(); numberOfContours = 5; epsilon = (double)(max-min)/(double)(numberOfContours*10); min = min+epsilon; max = max-epsilon; i = 1; while((i) <= numberOfContours) { cf.SetValue((int)0,(double)min+((i-1)/(double)(numberOfContours-1))*(max-min)); cf.Update(); pd[i] = new vtkPolyData(); pd[i].CopyStructure((vtkDataSet)cf.GetOutput()); pd[i].GetPointData().DeepCopy((vtkFieldData)cf.GetOutput().GetPointData()); mapper[i] = vtkPolyDataMapper.New(); mapper[i].SetInput((vtkPolyData)pd[i]); mapper[i].SetScalarRange((double)((vtkDataSet)pl3d.GetOutput()).GetPointData().GetScalars().GetRange()[0], (double)((vtkDataSet)pl3d.GetOutput()).GetPointData().GetScalars().GetRange()[1]); actor[i] = new vtkActor(); actor[i].AddPosition((double)0,(double)i*12,(double)0); actor[i].SetMapper((vtkMapper)mapper[i]); ren1.AddActor((vtkProp)actor[i]); i = i + 1; } // Add the actors to the renderer, set the background and size[] //[] ren1.SetBackground((double).3,(double).3,(double).3); renWin.SetSize((int)450,(int)150); cam1 = ren1.GetActiveCamera(); ren1.GetActiveCamera().SetPosition((double)-36.3762,(double)32.3855,(double)51.3652); ren1.GetActiveCamera().SetFocalPoint((double)8.255,(double)33.3861,(double)29.7687); ren1.GetActiveCamera().SetViewAngle((double)30); ren1.GetActiveCamera().SetViewUp((double)0,(double)0,(double)1); ren1.ResetCameraClippingRange(); iren.Initialize(); // render the image[] //[] // prevent the tk window from showing up then start the event loop[] //deleteAllVTKObjects(); }
/// <summary> /// Display the render window with the slice in it /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void renderWindowControl1_Load(object sender, EventArgs e) { //Get the name of the Unsigned Char volume that you want to load fileName = "../../../head.vti"; //Create all the objects for the pipeline vtkXMLImageDataReader reader = vtkXMLImageDataReader.New(); vtkImageActor iactor = vtkImageActor.New(); vtkImageClip clip = vtkImageClip.New(); vtkContourFilter contour = vtkContourFilter.New(); vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); vtkActor actor = vtkActor.New(); vtkInteractorStyleImage style = vtkInteractorStyleImage.New(); vtkRenderer renderer = renderWindowControl1.RenderWindow.GetRenderers().GetFirstRenderer(); //Read the Image reader.SetFileName(fileName); //Go through the visulization pipeline iactor.SetInputData(reader.GetOutput()); renderer.AddActor(iactor); reader.Update(); int[] extent = reader.GetOutput().GetExtent(); iactor.SetDisplayExtent(extent[0], extent[1], extent[2], extent[3], (extent[4] + extent[5]) / 2, (extent[4] + extent[5]) / 2); clip.SetInputConnection(reader.GetOutputPort()); clip.SetOutputWholeExtent(extent[0], extent[1], extent[2], extent[3], (extent[4] + extent[5]) / 2, (extent[4] + extent[5]) / 2); contour.SetInputConnection(clip.GetOutputPort()); contour.SetValue(0, 100); mapper.SetInputConnection(contour.GetOutputPort()); mapper.SetScalarVisibility(1); //Go through the graphics pipeline actor.SetMapper(mapper); actor.GetProperty().SetColor(0, 1, 0); renderer.AddActor(actor); //Give a new style to the interactor vtkRenderWindowInteractor iren = renderWindowControl1.RenderWindow.GetInteractor(); iren.SetInteractorStyle(style); //Add new events to the interactor style style.LeftButtonPressEvt += new vtkObject.vtkObjectEventHandler(iren_LeftButtonPressEvt); style.LeftButtonReleaseEvt += new vtkObject.vtkObjectEventHandler(iren_LeftButtonReleaseEvt); style.MouseMoveEvt += new vtkObject.vtkObjectEventHandler(iren_MouseMoveEvt); //Update global variables this.trackBar1.Maximum = extent[5]; this.trackBar1.Minimum = extent[4]; this.Interactor = iren; this.RenderWindow = renderWindowControl1.RenderWindow; this.Renderer = renderer; this.Clip = clip; this.ImageActor = iactor; }
/// <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(); }
//private void InitializeVTK() //{ // Kitware.VTK.RenderWindowControl vtkControl = new Kitware.VTK.RenderWindowControl(); // vtkControl.AddTestActors = false; // vtkControl.Location = new System.Drawing.Point(10, 10); // vtkControl.Name = "_renwin"; // vtkControl.Size = new System.Drawing.Size(100, 100); // vtkControl.TabIndex = 0; // vtkControl.TestText = null; // vtkControl.Dock = System.Windows.Forms.DockStyle.Fill; // vtkformhost.Child = vtkControl; // vtkformhost.Visibility = System.Windows.Visibility.Visible; // vtkSphereSource sphere = vtkSphereSource.New(); // sphere.SetThetaResolution(8); // sphere.SetPhiResolution(16); // vtkShrinkPolyData shrink = vtkShrinkPolyData.New(); // shrink.SetInputConnection(sphere.GetOutputPort()); // shrink.SetShrinkFactor(0.9); // vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); // mapper.SetInputConnection(shrink.GetOutputPort()); // // The actor links the data pipeline to the rendering subsystem // vtkActor actor = vtkActor.New(); // actor.SetMapper(mapper); // actor.GetProperty().SetColor(1, 0, 0); // // Create components of the rendering subsystem // // // Kitware.VTK.vtkRendererCollection rs = vtkControl.RenderWindow.GetRenderers(); // vtkRenderer ren1 = vtkControl.RenderWindow.GetRenderers().GetFirstRenderer(); // vtkRenderWindow renWin = vtkControl.RenderWindow; // // Add the actors to the renderer, set the window size // // // ren1.AddViewProp(actor); // renWin.SetSize(500, 500); // renWin.Render(); // vtkCamera camera = ren1.GetActiveCamera(); // camera.Zoom(1.5); //} private void InitializeVTK() { Kitware.VTK.RenderWindowControl rw = new Kitware.VTK.RenderWindowControl(); rw.AddTestActors = false; rw.Dock = System.Windows.Forms.DockStyle.Fill; vtkformhost.Child = rw; vtkformhost.Visibility = System.Windows.Visibility.Visible; Kitware.VTK.vtkRendererCollection rs = rw.RenderWindow.GetRenderers(); int rsc = rs.GetNumberOfItems(); Console.WriteLine(rsc + " renderers"); Kitware.VTK.vtkRenderer r = rs.GetFirstRenderer(); r.SetBackground(0.1, 0.3, 0.7); r.SetBackground2(0.7, 0.8, 1.0); r.SetGradientBackground(true); int i, j, k, kOffset, jOffset, offset; float s, sp, x, y, z; //创建结构化点数据集,(创建点和单元) vtkStructuredPoints vol = new vtkStructuredPoints(); vol.SetDimensions(26, 26, 26); //x,y,z三个坐标轴方向上各有26个点 vol.SetOrigin(-0.5, -0.5, -0.5); //设置数据集在坐标空间内的起点 sp = (float)(1.0 / 25.0); vol.SetSpacing(sp, sp, sp); //设置坐标轴上每个点的间距 //创建标量数据(作为结构化点数据集的属性数据) vtkFloatArray scalars = new vtkFloatArray(); scalars.SetNumberOfTuples(26 * 26 * 26);//设置标量个数,因为是点属性所以和点的个数相同 for (k = 0; k < 26; k++) { z = (float)(-0.5 + k * sp); kOffset = k * 26 * 26; for (j = 0; j < 26; j++) { y = (float)(-0.5 + j * sp); jOffset = j * 26; for (i = 0; i < 26; i++) { x = (float)(-0.5 + i * sp); s = (float)(x * x + y * y + z * z - (0.4 * 0.4)); //计算标量值,该方程为球体方程,位于球体上的点标量值为0 offset = i + jOffset + kOffset; //计算id scalars.InsertTuple1(offset, s); //插入标量值 } } } vol.GetPointData().SetScalars(scalars); //将标量值与点关联 //抽取标量值为0的点所形成的面 vtkContourFilter contour = new vtkContourFilter(); contour.SetInput(vol); contour.SetValue(0, 0); vtkPolyDataMapper volmapper = new vtkPainterPolyDataMapper(); volmapper.SetInput(contour.GetOutput()); vtkActor actor = new vtkActor(); actor.GetProperty().SetRepresentationToWireframe(); // actor.GetProperty().SetRepresentationToSurface(); // actor.GetProperty().SetRepresentationToPoints(); actor.GetProperty().SetColor(0, 0, 0); actor.SetMapper(volmapper); vtkRenderWindow _renwin = rw.RenderWindow; vtkRenderer _render = _renwin.GetRenderers().GetFirstRenderer(); _render.AddActor(actor); _renwin.Render(); _render.ResetCamera(); }