/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVStreamPolyData(String [] argv) { //Prefix Content is: "" NUMBER_OF_PIECES = 5; // Generate implicit model of a sphere[] //[] // Create renderer stuff[] //[] ren1 = vtkRenderer.New(); renWin = vtkRenderWindow.New(); renWin.AddRenderer((vtkRenderer)ren1); iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); // create pipeline that handles ghost cells[] sphere = new vtkSphereSource(); sphere.SetRadius((double)3); sphere.SetPhiResolution((int)100); sphere.SetThetaResolution((int)150); // sphere AddObserver StartEvent {tk_messageBox -message "Executing with piece [[sphere GetOutput] GetUpdatePiece]"}[] // Just playing with an alternative that is not currently used.[] //method moved // Just playing with an alternative that is not currently used.[] deci = new vtkDecimatePro(); deci.SetInputConnection((vtkAlgorithmOutput)sphere.GetOutputPort()); // this did not remove seams as I thought it would[] deci.BoundaryVertexDeletionOff(); //deci PreserveTopologyOn[] // Since quadric Clustering does not handle borders properly yet,[] // the pieces will have dramatic "eams"[] q = new vtkQuadricClustering(); q.SetInputConnection((vtkAlgorithmOutput)sphere.GetOutputPort()); q.SetNumberOfXDivisions((int)5); q.SetNumberOfYDivisions((int)5); q.SetNumberOfZDivisions((int)10); q.UseInputPointsOn(); streamer = new vtkPolyDataStreamer(); //streamer SetInputConnection [deci GetOutputPort][] streamer.SetInputConnection((vtkAlgorithmOutput)q.GetOutputPort()); //streamer SetInputConnection [pdn GetOutputPort][] streamer.SetNumberOfStreamDivisions((int)NUMBER_OF_PIECES); mapper = vtkPolyDataMapper.New(); mapper.SetInputConnection((vtkAlgorithmOutput)streamer.GetOutputPort()); mapper.ScalarVisibilityOff(); mapper.SetPiece((int)0); mapper.SetNumberOfPieces((int)2); mapper.ImmediateModeRenderingOn(); actor = new vtkActor(); actor.SetMapper((vtkMapper)mapper); actor.GetProperty().SetColor((double)0.8300, 0.2400, 0.1000); // Add the actors to the renderer, set the background and size[] //[] ren1.GetActiveCamera().SetPosition((double)5, (double)5, (double)10); ren1.GetActiveCamera().SetFocalPoint((double)0, (double)0, (double)0); ren1.AddActor((vtkProp)actor); ren1.SetBackground((double)1, (double)1, (double)1); renWin.SetSize((int)300, (int)300); iren.Initialize(); // render the image[] //[] // 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 AVStreamPolyData(String [] argv) { //Prefix Content is: "" NUMBER_OF_PIECES = 5; // Generate implicit model of a sphere[] //[] // Create renderer stuff[] //[] ren1 = vtkRenderer.New(); renWin = vtkRenderWindow.New(); renWin.AddRenderer((vtkRenderer)ren1); iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); // create pipeline that handles ghost cells[] sphere = new vtkSphereSource(); sphere.SetRadius((double)3); sphere.SetPhiResolution((int)100); sphere.SetThetaResolution((int)150); // sphere AddObserver StartEvent {tk_messageBox -message "Executing with piece [[sphere GetOutput] GetUpdatePiece]"}[] // Just playing with an alternative that is not currently used.[] //method moved // Just playing with an alternative that is not currently used.[] deci = new vtkDecimatePro(); deci.SetInputConnection((vtkAlgorithmOutput)sphere.GetOutputPort()); // this did not remove seams as I thought it would[] deci.BoundaryVertexDeletionOff(); //deci PreserveTopologyOn[] // Since quadric Clustering does not handle borders properly yet,[] // the pieces will have dramatic "eams"[] q = new vtkQuadricClustering(); q.SetInputConnection((vtkAlgorithmOutput)sphere.GetOutputPort()); q.SetNumberOfXDivisions((int)5); q.SetNumberOfYDivisions((int)5); q.SetNumberOfZDivisions((int)10); q.UseInputPointsOn(); streamer = new vtkPolyDataStreamer(); //streamer SetInputConnection [deci GetOutputPort][] streamer.SetInputConnection((vtkAlgorithmOutput)q.GetOutputPort()); //streamer SetInputConnection [pdn GetOutputPort][] streamer.SetNumberOfStreamDivisions((int)NUMBER_OF_PIECES); mapper = vtkPolyDataMapper.New(); mapper.SetInputConnection((vtkAlgorithmOutput)streamer.GetOutputPort()); mapper.ScalarVisibilityOff(); mapper.SetPiece((int)0); mapper.SetNumberOfPieces((int)2); mapper.ImmediateModeRenderingOn(); actor = new vtkActor(); actor.SetMapper((vtkMapper)mapper); actor.GetProperty().SetColor((double) 0.8300, 0.2400, 0.1000 ); // Add the actors to the renderer, set the background and size[] //[] ren1.GetActiveCamera().SetPosition((double)5,(double)5,(double)10); ren1.GetActiveCamera().SetFocalPoint((double)0,(double)0,(double)0); ren1.AddActor((vtkProp)actor); ren1.SetBackground((double)1,(double)1,(double)1); renWin.SetSize((int)300,(int)300); iren.Initialize(); // render the image[] //[] // prevent the tk window from showing up then start the event loop[] //deleteAllVTKObjects(); }
private void Decimation() { vtkSphereSource sphereSource = vtkSphereSource.New(); sphereSource.Update(); vtkPolyData input = vtkPolyData.New(); input.ShallowCopy(sphereSource.GetOutput()); Debug.WriteLine("Before decimation" + Environment.NewLine + "------------"); Debug.WriteLine("There are " + input.GetNumberOfPoints() + " points."); Debug.WriteLine("There are " + input.GetNumberOfPolys() + " polygons."); vtkDecimatePro decimate = vtkDecimatePro.New(); #if VTK_MAJOR_VERSION_5 decimate.SetInputConnection(input.GetProducerPort()); #else decimate.SetInputData(input); #endif //decimate.SetTargetReduction(.99); //99% reduction (if there was 100 triangles, now there will be 1) decimate.SetTargetReduction(.10); //10% reduction (if there was 100 triangles, now there will be 90) decimate.Update(); vtkPolyData decimated = vtkPolyData.New(); decimated.ShallowCopy(decimate.GetOutput()); Debug.WriteLine("After decimation" + Environment.NewLine + "------------"); Debug.WriteLine("There are " + decimated.GetNumberOfPoints() + " points."); Debug.WriteLine("There are " + decimated.GetNumberOfPolys() + " polygons."); vtkPolyDataMapper inputMapper = vtkPolyDataMapper.New(); #if VTK_MAJOR_VERSION_5 inputMapper.SetInputConnection(input.GetProducerPort()); #else inputMapper.SetInputData(input); #endif vtkActor inputActor = vtkActor.New(); inputActor.SetMapper(inputMapper); vtkPolyDataMapper decimatedMapper = vtkPolyDataMapper.New(); #if VTK_MAJOR_VERSION_5 decimatedMapper.SetInputConnection(decimated.GetProducerPort()); #else decimatedMapper.SetInputData(decimated); #endif vtkActor decimatedActor = vtkActor.New(); decimatedActor.SetMapper(decimatedMapper); vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow; this.Size = new System.Drawing.Size(612, 352); // Define viewport ranges // (xmin, ymin, xmax, ymax) double[] leftViewport = new double[] { 0.0, 0.0, 0.5, 1.0 }; double[] rightViewport = new double[] { 0.5, 0.0, 1.0, 1.0 }; // Setup both renderers vtkRenderer leftRenderer = vtkRenderer.New(); renderWindow.AddRenderer(leftRenderer); leftRenderer.SetViewport(leftViewport[0], leftViewport[1], leftViewport[2], leftViewport[3]); leftRenderer.SetBackground(.6, .5, .4); vtkRenderer rightRenderer = vtkRenderer.New(); renderWindow.AddRenderer(rightRenderer); rightRenderer.SetViewport(rightViewport[0], rightViewport[1], rightViewport[2], rightViewport[3]); rightRenderer.SetBackground(.4, .5, .6); // Add the sphere to the left and the cube to the right leftRenderer.AddActor(inputActor); rightRenderer.AddActor(decimatedActor); leftRenderer.ResetCamera(); rightRenderer.ResetCamera(); renderWindow.Render(); }