/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVTestPolygonWriters(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[] //[] input = new vtkPolyDataReader(); input.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/brainImageSmooth.vtk"); //[] // generate vectors[] clean = new vtkCleanPolyData(); clean.SetInputConnection((vtkAlgorithmOutput)input.GetOutputPort()); smooth = new vtkWindowedSincPolyDataFilter(); smooth.SetInputConnection((vtkAlgorithmOutput)clean.GetOutputPort()); smooth.GenerateErrorVectorsOn(); smooth.GenerateErrorScalarsOn(); smooth.Update(); mapper = vtkPolyDataMapper.New(); mapper.SetInputConnection((vtkAlgorithmOutput)smooth.GetOutputPort()); mapper.SetScalarRange((double)((vtkDataSet)smooth.GetOutput()).GetScalarRange()[0], (double)((vtkDataSet)smooth.GetOutput()).GetScalarRange()[1]); brain = new vtkActor(); brain.SetMapper((vtkMapper)mapper); // Add the actors to the renderer, set the background and size[] //[] ren1.AddActor((vtkProp)brain); renWin.SetSize((int)320,(int)240); ren1.GetActiveCamera().SetPosition((double)149.653,(double)-65.3464,(double)96.0401); ren1.GetActiveCamera().SetFocalPoint((double)146.003,(double)22.3839,(double)0.260541); ren1.GetActiveCamera().SetViewAngle((double)30); ren1.GetActiveCamera().SetViewUp((double)-0.255578,(double)-0.717754,(double)-0.647695); ren1.GetActiveCamera().SetClippingRange((double)79.2526,(double)194.052); iren.Initialize(); renWin.Render(); // render the image[] //[] // prevent the tk window from showing up then start the event loop[] //[] // 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"); //[] //[] // test the writers[] dsw = new vtkDataSetWriter(); dsw.SetInputConnection((vtkAlgorithmOutput)smooth.GetOutputPort()); dsw.SetFileName((string)"brain.dsw"); dsw.Write(); File.Delete("brain.dsw"); pdw = new vtkPolyDataWriter(); pdw.SetInputConnection((vtkAlgorithmOutput)smooth.GetOutputPort()); pdw.SetFileName((string)"brain.pdw"); pdw.Write(); File.Delete("brain.pdw"); iv = new vtkIVWriter(); iv.SetInputConnection((vtkAlgorithmOutput)smooth.GetOutputPort()); iv.SetFileName((string)"brain.iv"); iv.Write(); File.Delete("brain.iv"); //[] // the next writers only handle triangles[] triangles = new vtkTriangleFilter(); triangles.SetInputConnection((vtkAlgorithmOutput)smooth.GetOutputPort()); iv2 = new vtkIVWriter(); iv2.SetInputConnection((vtkAlgorithmOutput)triangles.GetOutputPort()); iv2.SetFileName((string)"brain2.iv"); iv2.Write(); File.Delete("brain2.iv"); edges = new vtkExtractEdges(); edges.SetInputConnection((vtkAlgorithmOutput)triangles.GetOutputPort()); iv3 = new vtkIVWriter(); iv3.SetInputConnection((vtkAlgorithmOutput)edges.GetOutputPort()); iv3.SetFileName((string)"brain3.iv"); iv3.Write(); File.Delete("brain3.iv"); byu = new vtkBYUWriter(); byu.SetGeometryFileName((string)"brain.g"); byu.SetScalarFileName((string)"brain.s"); byu.SetDisplacementFileName((string)"brain.d"); byu.SetInputConnection((vtkAlgorithmOutput)triangles.GetOutputPort()); byu.Write(); File.Delete("brain.g"); File.Delete("brain.s"); File.Delete("brain.d"); mcubes = new vtkMCubesWriter(); mcubes.SetInputConnection((vtkAlgorithmOutput)triangles.GetOutputPort()); mcubes.SetFileName((string)"brain.tri"); mcubes.SetLimitsFileName((string)"brain.lim"); mcubes.Write(); File.Delete("brain.lim"); File.Delete("brain.tri"); stl = new vtkSTLWriter(); stl.SetInputConnection((vtkAlgorithmOutput)triangles.GetOutputPort()); stl.SetFileName((string)"brain.stl"); stl.Write(); File.Delete("brain.stl"); stlBinary = new vtkSTLWriter(); stlBinary.SetInputConnection((vtkAlgorithmOutput)triangles.GetOutputPort()); stlBinary.SetFileName((string)"brainBinary.stl"); stlBinary.SetFileType((int)2); stlBinary.Write(); File.Delete("brainBinary.stl"); } //deleteAllVTKObjects(); }
///<summary> A Set Method for Static Variables </summary> public static void Setbyu(vtkBYUWriter toSet) { byu = toSet; }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVTestPolygonWriters(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[] //[] input = new vtkPolyDataReader(); input.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/brainImageSmooth.vtk"); //[] // generate vectors[] clean = new vtkCleanPolyData(); clean.SetInputConnection((vtkAlgorithmOutput)input.GetOutputPort()); smooth = new vtkWindowedSincPolyDataFilter(); smooth.SetInputConnection((vtkAlgorithmOutput)clean.GetOutputPort()); smooth.GenerateErrorVectorsOn(); smooth.GenerateErrorScalarsOn(); smooth.Update(); mapper = vtkPolyDataMapper.New(); mapper.SetInputConnection((vtkAlgorithmOutput)smooth.GetOutputPort()); mapper.SetScalarRange((double)((vtkDataSet)smooth.GetOutput()).GetScalarRange()[0], (double)((vtkDataSet)smooth.GetOutput()).GetScalarRange()[1]); brain = new vtkActor(); brain.SetMapper((vtkMapper)mapper); // Add the actors to the renderer, set the background and size[] //[] ren1.AddActor((vtkProp)brain); renWin.SetSize((int)320, (int)240); ren1.GetActiveCamera().SetPosition((double)149.653, (double)-65.3464, (double)96.0401); ren1.GetActiveCamera().SetFocalPoint((double)146.003, (double)22.3839, (double)0.260541); ren1.GetActiveCamera().SetViewAngle((double)30); ren1.GetActiveCamera().SetViewUp((double)-0.255578, (double)-0.717754, (double)-0.647695); ren1.GetActiveCamera().SetClippingRange((double)79.2526, (double)194.052); iren.Initialize(); renWin.Render(); // render the image[] //[] // prevent the tk window from showing up then start the event loop[] //[] // 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"); //[] //[] // test the writers[] dsw = new vtkDataSetWriter(); dsw.SetInputConnection((vtkAlgorithmOutput)smooth.GetOutputPort()); dsw.SetFileName((string)"brain.dsw"); dsw.Write(); File.Delete("brain.dsw"); pdw = new vtkPolyDataWriter(); pdw.SetInputConnection((vtkAlgorithmOutput)smooth.GetOutputPort()); pdw.SetFileName((string)"brain.pdw"); pdw.Write(); File.Delete("brain.pdw"); iv = new vtkIVWriter(); iv.SetInputConnection((vtkAlgorithmOutput)smooth.GetOutputPort()); iv.SetFileName((string)"brain.iv"); iv.Write(); File.Delete("brain.iv"); //[] // the next writers only handle triangles[] triangles = new vtkTriangleFilter(); triangles.SetInputConnection((vtkAlgorithmOutput)smooth.GetOutputPort()); iv2 = new vtkIVWriter(); iv2.SetInputConnection((vtkAlgorithmOutput)triangles.GetOutputPort()); iv2.SetFileName((string)"brain2.iv"); iv2.Write(); File.Delete("brain2.iv"); edges = new vtkExtractEdges(); edges.SetInputConnection((vtkAlgorithmOutput)triangles.GetOutputPort()); iv3 = new vtkIVWriter(); iv3.SetInputConnection((vtkAlgorithmOutput)edges.GetOutputPort()); iv3.SetFileName((string)"brain3.iv"); iv3.Write(); File.Delete("brain3.iv"); byu = new vtkBYUWriter(); byu.SetGeometryFileName((string)"brain.g"); byu.SetScalarFileName((string)"brain.s"); byu.SetDisplacementFileName((string)"brain.d"); byu.SetInputConnection((vtkAlgorithmOutput)triangles.GetOutputPort()); byu.Write(); File.Delete("brain.g"); File.Delete("brain.s"); File.Delete("brain.d"); mcubes = new vtkMCubesWriter(); mcubes.SetInputConnection((vtkAlgorithmOutput)triangles.GetOutputPort()); mcubes.SetFileName((string)"brain.tri"); mcubes.SetLimitsFileName((string)"brain.lim"); mcubes.Write(); File.Delete("brain.lim"); File.Delete("brain.tri"); stl = new vtkSTLWriter(); stl.SetInputConnection((vtkAlgorithmOutput)triangles.GetOutputPort()); stl.SetFileName((string)"brain.stl"); stl.Write(); File.Delete("brain.stl"); stlBinary = new vtkSTLWriter(); stlBinary.SetInputConnection((vtkAlgorithmOutput)triangles.GetOutputPort()); stlBinary.SetFileName((string)"brainBinary.stl"); stlBinary.SetFileType((int)2); stlBinary.Write(); File.Delete("brainBinary.stl"); } //deleteAllVTKObjects(); }