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 AVtextureThreshold(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/bluntfinxyz.bin"); pl3d.SetQFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/bluntfinq.bin"); pl3d.SetScalarFunctionNumber((int)100); pl3d.SetVectorFunctionNumber((int)202); pl3d.Update(); // wall[] //[] wall = new vtkStructuredGridGeometryFilter(); wall.SetInputData(pl3d.GetOutput().GetBlock(0)); wall.SetExtent((int)0,(int)100,(int)0,(int)0,(int)0,(int)100); wallMap = vtkPolyDataMapper.New(); wallMap.SetInputConnection((vtkAlgorithmOutput)wall.GetOutputPort()); wallMap.ScalarVisibilityOff(); wallActor = new vtkActor(); wallActor.SetMapper((vtkMapper)wallMap); wallActor.GetProperty().SetColor((double)0.8,(double)0.8,(double)0.8); // fin[] // [] fin = new vtkStructuredGridGeometryFilter(); fin.SetInputData(pl3d.GetOutput().GetBlock(0)); fin.SetExtent((int)0,(int)100,(int)0,(int)100,(int)0,(int)0); finMap = vtkPolyDataMapper.New(); finMap.SetInputConnection((vtkAlgorithmOutput)fin.GetOutputPort()); finMap.ScalarVisibilityOff(); finActor = new vtkActor(); finActor.SetMapper((vtkMapper)finMap); finActor.GetProperty().SetColor((double)0.8,(double)0.8,(double)0.8); // planes to threshold[] tmap = new vtkStructuredPointsReader(); tmap.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/texThres2.vtk"); texture = new vtkTexture(); texture.SetInputConnection((vtkAlgorithmOutput)tmap.GetOutputPort()); texture.InterpolateOff(); texture.RepeatOff(); plane1 = new vtkStructuredGridGeometryFilter(); plane1.SetInputData(pl3d.GetOutput().GetBlock(0)); plane1.SetExtent((int)10,(int)10,(int)0,(int)100,(int)0,(int)100); thresh1 = new vtkThresholdTextureCoords(); thresh1.SetInputConnection((vtkAlgorithmOutput)plane1.GetOutputPort()); thresh1.ThresholdByUpper((double)1.5); plane1Map = new vtkDataSetMapper(); plane1Map.SetInputConnection((vtkAlgorithmOutput)thresh1.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.SetTexture((vtkTexture)texture); plane1Actor.GetProperty().SetOpacity((double)0.999); plane2 = new vtkStructuredGridGeometryFilter(); plane2.SetInputData(pl3d.GetOutput().GetBlock(0)); plane2.SetExtent((int)30,(int)30,(int)0,(int)100,(int)0,(int)100); thresh2 = new vtkThresholdTextureCoords(); thresh2.SetInputConnection((vtkAlgorithmOutput)plane2.GetOutputPort()); thresh2.ThresholdByLower((double)1.5); plane2Map = new vtkDataSetMapper(); plane2Map.SetInputConnection((vtkAlgorithmOutput)thresh2.GetOutputPort()); plane2Map.SetScalarRange((double)((vtkDataSet)pl3d.GetOutput().GetBlock(0)).GetScalarRange()[0], (double)((vtkDataSet)pl3d.GetOutput().GetBlock(0)).GetScalarRange()[1]); plane2Actor = new vtkActor(); plane2Actor.SetMapper((vtkMapper)plane2Map); plane2Actor.SetTexture((vtkTexture)texture); plane2Actor.GetProperty().SetOpacity((double)0.999); plane3 = new vtkStructuredGridGeometryFilter(); plane3.SetInputData(pl3d.GetOutput().GetBlock(0)); plane3.SetExtent((int)35,(int)35,(int)0,(int)100,(int)0,(int)100); thresh3 = new vtkThresholdTextureCoords(); thresh3.SetInputConnection((vtkAlgorithmOutput)plane3.GetOutputPort()); thresh3.ThresholdBetween((double)1.5,(double)1.8); plane3Map = new vtkDataSetMapper(); plane3Map.SetInputConnection((vtkAlgorithmOutput)thresh3.GetOutputPort()); plane3Map.SetScalarRange((double)((vtkDataSet)pl3d.GetOutput().GetBlock(0)).GetScalarRange()[0], (double)((vtkDataSet)pl3d.GetOutput().GetBlock(0)).GetScalarRange()[1]); plane3Actor = new vtkActor(); plane3Actor.SetMapper((vtkMapper)plane3Map); plane3Actor.SetTexture((vtkTexture)texture); plane3Actor.GetProperty().SetOpacity((double)0.999); // outline[] outline = new vtkStructuredGridOutlineFilter(); outline.SetInputData(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)wallActor); ren1.AddActor((vtkProp)finActor); ren1.AddActor((vtkProp)plane1Actor); ren1.AddActor((vtkProp)plane2Actor); ren1.AddActor((vtkProp)plane3Actor); ren1.SetBackground((double)1,(double)1,(double)1); renWin.SetSize((int)256,(int)256); cam1 = new vtkCamera(); cam1.SetClippingRange((double)1.51176,(double)75.5879); cam1.SetFocalPoint((double)2.33749,(double)2.96739,(double)3.61023); cam1.SetPosition((double)10.8787,(double)5.27346,(double)15.8687); cam1.SetViewAngle((double)30); cam1.SetViewUp((double)-0.0610856,(double)0.987798,(double)-0.143262); ren1.SetActiveCamera((vtkCamera)cam1); 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 AVtextureThreshold(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/bluntfinxyz.bin"); pl3d.SetQFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/bluntfinq.bin"); pl3d.SetScalarFunctionNumber((int)100); pl3d.SetVectorFunctionNumber((int)202); pl3d.Update(); // wall[] //[] wall = new vtkStructuredGridGeometryFilter(); wall.SetInputData(pl3d.GetOutput().GetBlock(0)); wall.SetExtent((int)0, (int)100, (int)0, (int)0, (int)0, (int)100); wallMap = vtkPolyDataMapper.New(); wallMap.SetInputConnection((vtkAlgorithmOutput)wall.GetOutputPort()); wallMap.ScalarVisibilityOff(); wallActor = new vtkActor(); wallActor.SetMapper((vtkMapper)wallMap); wallActor.GetProperty().SetColor((double)0.8, (double)0.8, (double)0.8); // fin[] // [] fin = new vtkStructuredGridGeometryFilter(); fin.SetInputData(pl3d.GetOutput().GetBlock(0)); fin.SetExtent((int)0, (int)100, (int)0, (int)100, (int)0, (int)0); finMap = vtkPolyDataMapper.New(); finMap.SetInputConnection((vtkAlgorithmOutput)fin.GetOutputPort()); finMap.ScalarVisibilityOff(); finActor = new vtkActor(); finActor.SetMapper((vtkMapper)finMap); finActor.GetProperty().SetColor((double)0.8, (double)0.8, (double)0.8); // planes to threshold[] tmap = new vtkStructuredPointsReader(); tmap.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/texThres2.vtk"); texture = new vtkTexture(); texture.SetInputConnection((vtkAlgorithmOutput)tmap.GetOutputPort()); texture.InterpolateOff(); texture.RepeatOff(); plane1 = new vtkStructuredGridGeometryFilter(); plane1.SetInputData(pl3d.GetOutput().GetBlock(0)); plane1.SetExtent((int)10, (int)10, (int)0, (int)100, (int)0, (int)100); thresh1 = new vtkThresholdTextureCoords(); thresh1.SetInputConnection((vtkAlgorithmOutput)plane1.GetOutputPort()); thresh1.ThresholdByUpper((double)1.5); plane1Map = new vtkDataSetMapper(); plane1Map.SetInputConnection((vtkAlgorithmOutput)thresh1.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.SetTexture((vtkTexture)texture); plane1Actor.GetProperty().SetOpacity((double)0.999); plane2 = new vtkStructuredGridGeometryFilter(); plane2.SetInputData(pl3d.GetOutput().GetBlock(0)); plane2.SetExtent((int)30, (int)30, (int)0, (int)100, (int)0, (int)100); thresh2 = new vtkThresholdTextureCoords(); thresh2.SetInputConnection((vtkAlgorithmOutput)plane2.GetOutputPort()); thresh2.ThresholdByLower((double)1.5); plane2Map = new vtkDataSetMapper(); plane2Map.SetInputConnection((vtkAlgorithmOutput)thresh2.GetOutputPort()); plane2Map.SetScalarRange((double)((vtkDataSet)pl3d.GetOutput().GetBlock(0)).GetScalarRange()[0], (double)((vtkDataSet)pl3d.GetOutput().GetBlock(0)).GetScalarRange()[1]); plane2Actor = new vtkActor(); plane2Actor.SetMapper((vtkMapper)plane2Map); plane2Actor.SetTexture((vtkTexture)texture); plane2Actor.GetProperty().SetOpacity((double)0.999); plane3 = new vtkStructuredGridGeometryFilter(); plane3.SetInputData(pl3d.GetOutput().GetBlock(0)); plane3.SetExtent((int)35, (int)35, (int)0, (int)100, (int)0, (int)100); thresh3 = new vtkThresholdTextureCoords(); thresh3.SetInputConnection((vtkAlgorithmOutput)plane3.GetOutputPort()); thresh3.ThresholdBetween((double)1.5, (double)1.8); plane3Map = new vtkDataSetMapper(); plane3Map.SetInputConnection((vtkAlgorithmOutput)thresh3.GetOutputPort()); plane3Map.SetScalarRange((double)((vtkDataSet)pl3d.GetOutput().GetBlock(0)).GetScalarRange()[0], (double)((vtkDataSet)pl3d.GetOutput().GetBlock(0)).GetScalarRange()[1]); plane3Actor = new vtkActor(); plane3Actor.SetMapper((vtkMapper)plane3Map); plane3Actor.SetTexture((vtkTexture)texture); plane3Actor.GetProperty().SetOpacity((double)0.999); // outline[] outline = new vtkStructuredGridOutlineFilter(); outline.SetInputData(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)wallActor); ren1.AddActor((vtkProp)finActor); ren1.AddActor((vtkProp)plane1Actor); ren1.AddActor((vtkProp)plane2Actor); ren1.AddActor((vtkProp)plane3Actor); ren1.SetBackground((double)1, (double)1, (double)1); renWin.SetSize((int)256, (int)256); cam1 = new vtkCamera(); cam1.SetClippingRange((double)1.51176, (double)75.5879); cam1.SetFocalPoint((double)2.33749, (double)2.96739, (double)3.61023); cam1.SetPosition((double)10.8787, (double)5.27346, (double)15.8687); cam1.SetViewAngle((double)30); cam1.SetViewUp((double)-0.0610856, (double)0.987798, (double)-0.143262); ren1.SetActiveCamera((vtkCamera)cam1); iren.Initialize(); // render the image[] //[] // prevent the tk window from showing up then start the event loop[] //deleteAllVTKObjects(); }