private void vtkPolyDataConnectivityFilter_LargestRegion() { // Small sphere vtkSphereSource sphereSource1 = vtkSphereSource.New(); sphereSource1.Update(); // Large sphere vtkSphereSource sphereSource2 = vtkSphereSource.New(); sphereSource2.SetRadius(10); sphereSource2.SetCenter(25, 0, 0); sphereSource2.SetThetaResolution(10); sphereSource2.SetPhiResolution(10); sphereSource2.Update(); vtkAppendPolyData appendFilter = vtkAppendPolyData.New(); appendFilter.AddInputConnection(sphereSource1.GetOutputPort()); appendFilter.AddInputConnection(sphereSource2.GetOutputPort()); appendFilter.Update(); vtkPolyDataConnectivityFilter connectivityFilter = vtkPolyDataConnectivityFilter.New(); connectivityFilter.SetInputConnection(appendFilter.GetOutputPort()); connectivityFilter.SetExtractionModeToLargestRegion(); connectivityFilter.Update(); // Create a mapper and actor for original data vtkPolyDataMapper originalMapper = vtkPolyDataMapper.New(); originalMapper.SetInputConnection(appendFilter.GetOutputPort()); originalMapper.Update(); vtkActor originalActor = vtkActor.New(); originalActor.SetMapper(originalMapper); // Create a mapper and actor for extracted data vtkPolyDataMapper extractedMapper = vtkPolyDataMapper.New(); extractedMapper.SetInputConnection(connectivityFilter.GetOutputPort()); extractedMapper.Update(); vtkActor extractedActor = vtkActor.New(); extractedActor.GetProperty().SetColor(1, 0, 0); extractedActor.SetMapper(extractedMapper); // get a reference to the renderwindow of our renderWindowControl1 vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow; // renderer vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer(); // set background color renderer.SetBackground(0.2, 0.3, 0.4); // add our actor to the renderer renderer.AddActor(originalActor); renderer.AddActor(extractedActor); }
private void ColorDisconnectedRegions() { // Create some spheres vtkSphereSource sphereSource1 = vtkSphereSource.New(); sphereSource1.Update(); vtkSphereSource sphereSource2 = vtkSphereSource.New(); sphereSource2.SetCenter(5, 0, 0); sphereSource2.Update(); vtkSphereSource sphereSource3 = vtkSphereSource.New(); sphereSource3.SetCenter(10, 0, 0); sphereSource3.Update(); vtkAppendPolyData appendFilter = vtkAppendPolyData.New(); appendFilter.AddInputConnection(sphereSource1.GetOutputPort()); appendFilter.AddInputConnection(sphereSource2.GetOutputPort()); appendFilter.AddInputConnection(sphereSource3.GetOutputPort()); vtkPolyDataConnectivityFilter connectivityFilter = vtkPolyDataConnectivityFilter.New(); connectivityFilter.SetInputConnection(appendFilter.GetOutputPort()); connectivityFilter.SetExtractionModeToAllRegions(); connectivityFilter.ColorRegionsOn(); connectivityFilter.Update(); // Visualize vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); mapper.SetInputConnection(connectivityFilter.GetOutputPort()); double[] range = connectivityFilter.GetOutput().GetPointData().GetArray("RegionId").GetRange(); mapper.SetScalarRange(range[0], range[1]); vtkActor actor = vtkActor.New(); actor.SetMapper(mapper); // get a reference to the renderwindow of our renderWindowControl1 vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow; // renderer vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer(); // set background color renderer.SetBackground(0.0, 0.0, 0.0); // add our actor to the renderer renderer.AddActor(actor); }
private void ExtractLargestIsoSurface(string filePath, double threshold, bool extractLargest) { // Load data vtkStructuredPointsReader reader = vtkStructuredPointsReader.New(); reader.SetFileName(filePath); // Create a 3D model using marching cubes vtkMarchingCubes mc = vtkMarchingCubes.New(); mc.SetInputConnection(reader.GetOutputPort()); mc.ComputeNormalsOn(); mc.ComputeGradientsOn(); mc.SetValue(0, threshold); // second value acts as threshold // To remain largest region vtkPolyDataConnectivityFilter confilter = vtkPolyDataConnectivityFilter.New(); confilter.SetInputConnection(mc.GetOutputPort()); confilter.SetExtractionModeToLargestRegion(); // Create a mapper vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); if (extractLargest) { mapper.SetInputConnection(confilter.GetOutputPort()); } else { mapper.SetInputConnection(mc.GetOutputPort()); } mapper.ScalarVisibilityOff(); // utilize actor's property I set // Visualize vtkActor actor = vtkActor.New(); actor.GetProperty().SetColor(1, 1, 1); actor.SetMapper(mapper); // get a reference to the renderwindow of our renderWindowControl1 vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow; // renderer vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer(); // add our actor to the renderer renderer.AddActor(actor); }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVpolyConn(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); // read 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(); // planes to connect[] plane1 = new vtkStructuredGridGeometryFilter(); plane1.SetInputData((vtkDataSet)pl3d.GetOutput().GetBlock(0)); plane1.SetExtent((int)20,(int)20,(int)0,(int)100,(int)0,(int)100); conn = new vtkPolyDataConnectivityFilter(); conn.SetInputConnection((vtkAlgorithmOutput)plane1.GetOutputPort()); conn.ScalarConnectivityOn(); conn.SetScalarRange((double)0.19,(double)0.25); plane1Map = vtkPolyDataMapper.New(); plane1Map.SetInputConnection((vtkAlgorithmOutput)conn.GetOutputPort()); plane1Map.SetScalarRange((double)((vtkDataSet)pl3d.GetOutput().GetBlock(0)).GetScalarRange()[0], (double)((vtkDataSet)pl3d.GetOutput().GetBlock(0)).GetScalarRange()[1]); plane1Actor = new vtkActor(); plane1Actor.SetMapper((vtkMapper)plane1Map); plane1Actor.GetProperty().SetOpacity((double)0.999); // 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); outlineProp = outlineActor.GetProperty(); outlineProp.SetColor((double)0,(double)0,(double)0); // Add the actors to the renderer, set the background and size[] //[] ren1.AddActor((vtkProp)outlineActor); ren1.AddActor((vtkProp)plane1Actor); ren1.SetBackground((double)1,(double)1,(double)1); renWin.SetSize((int)300,(int)300); cam1 = new vtkCamera(); cam1.SetClippingRange((double)14.29,(double)63.53); cam1.SetFocalPoint((double)8.58522,(double)1.58266,(double)30.6486); cam1.SetPosition((double)37.6808,(double)-20.1298,(double)35.4016); cam1.SetViewAngle((double)30); cam1.SetViewUp((double)-0.0566235,(double)0.140504,(double)0.98846); ren1.SetActiveCamera((vtkCamera)cam1); iren.Initialize(); // render the image[] //[] // prevent the tk window from showing up then start the event loop[] //deleteAllVTKObjects(); }
///<summary> A Set Method for Static Variables </summary> public static void Setconn(vtkPolyDataConnectivityFilter toSet) { conn = toSet; }
///<summary> A Set Method for Static Variables </summary> public static void Setconn(vtkPolyDataConnectivityFilter toSet) { conn = toSet; }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVpolyConn(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); // read 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(); // planes to connect[] plane1 = new vtkStructuredGridGeometryFilter(); plane1.SetInputData((vtkDataSet)pl3d.GetOutput().GetBlock(0)); plane1.SetExtent((int)20, (int)20, (int)0, (int)100, (int)0, (int)100); conn = new vtkPolyDataConnectivityFilter(); conn.SetInputConnection((vtkAlgorithmOutput)plane1.GetOutputPort()); conn.ScalarConnectivityOn(); conn.SetScalarRange((double)0.19, (double)0.25); plane1Map = vtkPolyDataMapper.New(); plane1Map.SetInputConnection((vtkAlgorithmOutput)conn.GetOutputPort()); plane1Map.SetScalarRange((double)((vtkDataSet)pl3d.GetOutput().GetBlock(0)).GetScalarRange()[0], (double)((vtkDataSet)pl3d.GetOutput().GetBlock(0)).GetScalarRange()[1]); plane1Actor = new vtkActor(); plane1Actor.SetMapper((vtkMapper)plane1Map); plane1Actor.GetProperty().SetOpacity((double)0.999); // 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); outlineProp = outlineActor.GetProperty(); outlineProp.SetColor((double)0, (double)0, (double)0); // Add the actors to the renderer, set the background and size[] //[] ren1.AddActor((vtkProp)outlineActor); ren1.AddActor((vtkProp)plane1Actor); ren1.SetBackground((double)1, (double)1, (double)1); renWin.SetSize((int)300, (int)300); cam1 = new vtkCamera(); cam1.SetClippingRange((double)14.29, (double)63.53); cam1.SetFocalPoint((double)8.58522, (double)1.58266, (double)30.6486); cam1.SetPosition((double)37.6808, (double)-20.1298, (double)35.4016); cam1.SetViewAngle((double)30); cam1.SetViewUp((double)-0.0566235, (double)0.140504, (double)0.98846); ren1.SetActiveCamera((vtkCamera)cam1); iren.Initialize(); // render the image[] //[] // prevent the tk window from showing up then start the event loop[] //deleteAllVTKObjects(); }