/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVTestExtrudePiece(String [] argv) { //Prefix Content is: "" disk = new vtkDiskSource(); disk.SetRadialResolution((int)2); disk.SetCircumferentialResolution((int)9); clean = new vtkCleanPolyData(); clean.SetInputConnection((vtkAlgorithmOutput)disk.GetOutputPort()); clean.SetTolerance((double)0.01); piece = new vtkExtractPolyDataPiece(); piece.SetInputConnection((vtkAlgorithmOutput)clean.GetOutputPort()); extrude = new vtkPLinearExtrusionFilter(); extrude.SetInputConnection((vtkAlgorithmOutput)piece.GetOutputPort()); extrude.PieceInvariantOn(); // Create the RenderWindow, Renderer and both Actors[] //[] ren1 = vtkRenderer.New(); renWin = vtkRenderWindow.New(); renWin.AddRenderer((vtkRenderer)ren1); iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); mapper = vtkPolyDataMapper.New(); mapper.SetInputConnection((vtkAlgorithmOutput)extrude.GetOutputPort()); mapper.SetNumberOfPieces((int)2); mapper.SetPiece((int)1); bf = new vtkProperty(); bf.SetColor((double)1,(double)0,(double)0); actor = new vtkActor(); actor.SetMapper((vtkMapper)mapper); actor.GetProperty().SetColor((double)1,(double)1,(double)0.8); actor.SetBackfaceProperty((vtkProperty)bf); // Add the actors to the renderer, set the background and size[] //[] ren1.AddActor((vtkProp)actor); 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> /// Changes the actors to whatever the /// animal currently loaded is /// </summary> public void updateAnimal() { //----Go through the pipeline for the animal body //Convert the polydata to triangles (in the default files they are rectangles) triangleAnimal.SetInputConnection(animalData); if (this.checkBox1.Checked) { //smooth the polydata cleanAnimal.SetInputConnection(triangleAnimal.GetOutputPort()); smoothAnimal.SetInputConnection(cleanAnimal.GetOutputPort()); normalsAnimal.SetInputConnection(smoothAnimal.GetOutputPort()); //connect the smoothed data to a mapper animalMapper.SetInputConnection(normalsAnimal.GetOutputPort()); //decimate the smoothed polydata decimateAnimal.SetInputConnection(normalsAnimal.GetOutputPort()); } else { //connect the triangle polydata to a mapper before decimation animalMapper.SetInputConnection(triangleAnimal.GetOutputPort()); //decimate the triangled data decimateAnimal.SetInputConnection(triangleAnimal.GetOutputPort()); } double targetreduc = 0.5; if (double.TryParse(toolStripTextBox1.Text, out targetreduc)) { decimateAnimal.SetTargetReduction(targetreduc); } decimateAnimal.SetPreserveTopology(0); //connect the decimated polydata a mapper deciAnimalMapper.SetInputConnection(decimateAnimal.GetOutputPort()); //----Go through the pipeline for the first eye //Convert the polydata to triangles (in the default files they are rectangles) triangles.SetInputConnection(eyeData1); if (this.checkBox1.Checked) { //smooth the polydata clean.SetInputConnection(triangles.GetOutputPort()); smooth.SetInputConnection(clean.GetOutputPort()); normals.SetInputConnection(smooth.GetOutputPort()); //connect the smoothed data to a mapper sphereTexture.SetInputConnection(normals.GetOutputPort()); //decimate the smoothed polydata eyeMapper1.SetInputConnection(sphereTexture.GetOutputPort()); } else { sphereTexture.SetInputConnection(triangles.GetOutputPort()); //connect the triangle polydata to a mapper before decimation eyeMapper1.SetInputConnection(sphereTexture.GetOutputPort()); } decimate.SetInputConnection(sphereTexture.GetOutputPort()); if (double.TryParse(toolStripTextBox1.Text, out targetreduc)) { decimate.SetTargetReduction(targetreduc); } decimate.SetPreserveTopology(0); //connect the decimated polydata a mapper deciEyeMapper1.SetInputConnection(decimate.GetOutputPort()); //----Go through the pipeline for the second eye //Convert the polydata to triangles (in the default files they are rectangles) triangles.SetInputConnection(eyeData1); if (this.checkBox1.Checked) { //smooth the polydata clean.SetInputConnection(triangles.GetOutputPort()); smooth.SetInputConnection(clean.GetOutputPort()); normals.SetInputConnection(smooth.GetOutputPort()); //connect the smoothed data to a mapper sphereTexture.SetInputConnection(normals.GetOutputPort()); //decimate the smoothed polydata eyeMapper2.SetInputConnection(sphereTexture.GetOutputPort()); } else { sphereTexture.SetInputConnection(triangles.GetOutputPort()); //connect the triangle polydata to a mapper before decimation eyeMapper2.SetInputConnection(sphereTexture.GetOutputPort()); } decimate.SetInputConnection(sphereTexture.GetOutputPort()); if (double.TryParse(toolStripTextBox1.Text, out targetreduc)) { decimate.SetTargetReduction(targetreduc); } decimate.SetPreserveTopology(0); //connect the decimated polydata a mapper deciEyeMapper2.SetInputConnection(decimate.GetOutputPort()); //----Set the textures and position of the decimated model deciAnimalActor.SetMapper(deciAnimalMapper); if (this.checkBox2.Checked) { deciAnimalActor.SetTexture(deciAnimalColorTexture); } else { deciAnimalActor.SetTexture(null); } deciEyeActor1.SetMapper(deciEyeMapper1); if (this.checkBox2.Checked) { deciEyeActor1.SetTexture(eyeColorTexture1); deciEyeActor1.SetTexture(deciEyeColorTexture1); } else { deciEyeActor1.SetTexture(null); } deciEyeActor1.SetPosition(eyeX, eyeY, eyeZ); deciEyeActor2.SetMapper(deciEyeMapper2); if (this.checkBox2.Checked) { deciEyeActor2.SetTexture(eyeColorTexture2); deciEyeActor2.SetTexture(deciEyeColorTexture2); } else { deciEyeActor2.SetTexture(null); } deciEyeActor2.SetPosition(-eyeX, eyeY, eyeZ); //----Set the text to the decimated poly count //Update the mappers to get the number of polygons deciAnimalMapper.Update(); deciEyeMapper1.Update(); deciEyeMapper2.Update(); textAfter.SetInput(((((vtkPolyData)deciAnimalMapper.GetInput()).GetNumberOfPolys() + ((vtkPolyData)deciEyeMapper1.GetInput()).GetNumberOfPolys() + ((vtkPolyData)deciEyeMapper2.GetInput()).GetNumberOfPolys())).ToString() + " Polygons"); textAfter.SetDisplayPosition(10, 10); //----Set the textures and position of the decimated model animalActor.SetMapper(animalMapper); if (this.checkBox2.Checked) { animalActor.SetTexture(animalColorTexture); } else { animalActor.SetTexture(null); } eyeActor1.SetMapper(eyeMapper1); if (this.checkBox2.Checked) { eyeActor1.SetTexture(eyeColorTexture1); } else { eyeActor1.SetTexture(null); } eyeActor1.SetPosition(eyeX, eyeY, eyeZ); eyeActor2.SetMapper(eyeMapper2); if (this.checkBox2.Checked) { eyeActor2.SetTexture(eyeColorTexture2); } else { eyeActor2.SetTexture(null); } eyeActor2.SetPosition(-eyeX, eyeY, eyeZ); //Update the pipeline to get the number of polygons animalMapper.Update(); eyeMapper1.Update(); eyeMapper2.Update(); //----Set the text to the full poly count textBefore.SetInput((((vtkPolyData)animalMapper.GetInput()).GetNumberOfPolys() + ((vtkPolyData)eyeMapper1.GetInput()).GetNumberOfPolys() + ((vtkPolyData)eyeMapper2.GetInput()).GetNumberOfPolys()).ToString() + " Polygons"); textBefore.SetDisplayPosition(10, 10); }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void 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> /// 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(); }
private void FilledContours(string filePath, int numberOfContours) { // Read the file vtkXMLPolyDataReader reader = vtkXMLPolyDataReader.New(); reader.SetFileName(filePath); reader.Update(); // Update so that we can get the scalar range double[] scalarRange = reader.GetOutput().GetPointData().GetScalars().GetRange(); vtkAppendPolyData appendFilledContours = vtkAppendPolyData.New(); double delta = (scalarRange[1] - scalarRange[0]) / (numberOfContours - 1); // Keep the clippers alive List <vtkClipPolyData> clippersLo = new List <vtkClipPolyData>(); List <vtkClipPolyData> clippersHi = new List <vtkClipPolyData>(); for (int i = 0; i < numberOfContours; i++) { double valueLo = scalarRange[0] + i * delta; double valueHi = scalarRange[0] + (i + 1) * delta; clippersLo.Add(vtkClipPolyData.New()); clippersLo[i].SetValue(valueLo); if (i == 0) { clippersLo[i].SetInputConnection(reader.GetOutputPort()); } else { clippersLo[i].SetInputConnection(clippersHi[i - 1].GetOutputPort(1)); } clippersLo[i].InsideOutOff(); clippersLo[i].Update(); clippersHi.Add(vtkClipPolyData.New()); clippersHi[i].SetValue(valueHi); clippersHi[i].SetInputConnection(clippersLo[i].GetOutputPort()); clippersHi[i].GenerateClippedOutputOn(); clippersHi[i].InsideOutOn(); clippersHi[i].Update(); if (clippersHi[i].GetOutput().GetNumberOfCells() == 0) { continue; } vtkFloatArray cd = vtkFloatArray.New(); cd.SetNumberOfComponents(1); cd.SetNumberOfTuples(clippersHi[i].GetOutput().GetNumberOfCells()); cd.FillComponent(0, valueLo); clippersHi[i].GetOutput().GetCellData().SetScalars(cd); appendFilledContours.AddInputConnection(clippersHi[i].GetOutputPort()); } vtkCleanPolyData filledContours = vtkCleanPolyData.New(); filledContours.SetInputConnection(appendFilledContours.GetOutputPort()); vtkLookupTable lut = vtkLookupTable.New(); lut.SetNumberOfTableValues(numberOfContours + 1); lut.Build(); vtkPolyDataMapper contourMapper = vtkPolyDataMapper.New(); contourMapper.SetInputConnection(filledContours.GetOutputPort()); contourMapper.SetScalarRange(scalarRange[0], scalarRange[1]); contourMapper.SetScalarModeToUseCellData(); contourMapper.SetLookupTable(lut); vtkActor contourActor = vtkActor.New(); contourActor.SetMapper(contourMapper); contourActor.GetProperty().SetInterpolationToFlat(); vtkContourFilter contours = vtkContourFilter.New(); contours.SetInputConnection(filledContours.GetOutputPort()); contours.GenerateValues(numberOfContours, scalarRange[0], scalarRange[1]); vtkPolyDataMapper contourLineMapperer = vtkPolyDataMapper.New(); contourLineMapperer.SetInputConnection(contours.GetOutputPort()); contourLineMapperer.SetScalarRange(scalarRange[0], scalarRange[1]); contourLineMapperer.ScalarVisibilityOff(); vtkActor contourLineActor = vtkActor.New(); contourLineActor.SetMapper(contourLineMapperer); contourLineActor.GetProperty().SetLineWidth(2); // get a reference to the renderwindow of our renderWindowControl1 vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow; // renderer vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer(); // set background color renderer.SetBackground(.2, .3, .4); // add our actor to the renderer renderer.AddActor(contourActor); renderer.AddActor(contourLineActor); }