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); }
public static vtkPolyData Create(List <List <double[]> > xyzList, double radius) { vtkAppendPolyData append = new vtkAppendPolyData(); foreach (List <double[]> list in xyzList) { append.AddInput(Create(list, radius)); } append.Update(); return(append.GetOutput()); }
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); }
static public vtkProp3D genActor(List <GaussianCluster> data) { vtkProperty pro = new vtkProperty(); // 默认颜色 pro.SetColor(config.cone_color[0], config.cone_color[1], config.cone_color[2]); pro.SetOpacity(0.4); vtkAppendPolyData polydata = vtkAppendPolyData.New(); for (int i = 1; i < data.Count; i++) { var cluster = data[i]; System.Windows.Forms.MessageBox.Show("cluster.start_radius:" + cluster.start_radius.ToString() + "cluster.distance:" + cluster.distance.ToString() + "cluster.is_foucs:" + cluster.is_foucs.ToString() + "cluster.foucs_radius:" + cluster.foucs_radius.ToString()); vtkTransform transform = vtkTransform.New(); transform.Translate(cluster.coordinate.pos.x, cluster.coordinate.pos.y, cluster.coordinate.pos.z); transform.RotateWXYZ(cluster.coordinate.rotate_theta, cluster.coordinate.rotate_axis.x, cluster.coordinate.rotate_axis.y, cluster.coordinate.rotate_axis.z); vtkTransformPolyDataFilter transFilter = vtkTransformPolyDataFilter.New(); transFilter.SetInputConnection(combiFrustumCone(cluster.start_radius, 1, cluster.angle, true, 0.01)); transFilter.SetTransform(transform); transFilter.Update(); polydata.AddInputConnection(transFilter.GetOutputPort()); } vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); mapper.SetInputConnection(polydata.GetOutputPort()); mapper.ScalarVisibilityOff(); // The actor links the data pipeline to the rendering subsystem vtkActor actor = vtkActor.New(); actor.SetProperty(pro); actor.SetMapper(mapper); return(actor); }
static public vtkAlgorithmOutput combiFrustumCone(double start_radius, double distance, double angle, bool is_foucs, double foucs_radius) { double tanArc = Math.Tan(Math.PI * angle / 180); double origin_dis = start_radius / tanArc; if (is_foucs) // 缩小 { double origin_foucs_dis = foucs_radius / tanArc; double fouce_dis = origin_dis - origin_foucs_dis; if (distance > fouce_dis) //缩小到焦点后放大 { vtkAppendPolyData polydata = vtkAppendPolyData.New(); polydata.AddInputConnection(genFrustumCone(origin_dis, start_radius, fouce_dis, false)); vtkTransform transform = vtkTransform.New(); transform.Translate(0, 0, fouce_dis); vtkTransformPolyDataFilter transFilter = vtkTransformPolyDataFilter.New(); origin_dis = origin_foucs_dis + distance - fouce_dis; transFilter.SetInputConnection(genFrustumCone(origin_dis, origin_dis * tanArc, distance - fouce_dis, true)); transFilter.SetTransform(transform); //use vtkTransform (or maybe vtkLinearTransform) transFilter.Update(); polydata.AddInputConnection(transFilter.GetOutputPort()); polydata.Update(); return(polydata.GetOutputPort()); } else { return(genFrustumCone(origin_dis, start_radius, distance, false)); } } else // 放大 { double total_dis = origin_dis + distance; double end_radius = total_dis * tanArc; return(genFrustumCone(total_dis, end_radius, distance, true)); } }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVMatrixToTransform(String [] argv) { //Prefix Content is: "" // This example demonstrates how to use a matrix in place of a transfrom[] // via vtkMatrixToLinearTransform and vtkMatrixToHomogeneousTransform.[] // create a rendering window[] renWin = vtkRenderWindow.New(); renWin.SetSize((int)600,(int)300); // set up first set of polydata[] p1 = new vtkPlaneSource(); p1.SetOrigin((double)0.5,(double)0.508,(double)-0.5); p1.SetPoint1((double)-0.5,(double)0.508,(double)-0.5); p1.SetPoint2((double)0.5,(double)0.508,(double)0.5); p1.SetXResolution((int)5); p1.SetYResolution((int)5); p2 = new vtkPlaneSource(); p2.SetOrigin((double)-0.508,(double)0.5,(double)-0.5); p2.SetPoint1((double)-0.508,(double)-0.5,(double)-0.5); p2.SetPoint2((double)-0.508,(double)0.5,(double)0.5); p2.SetXResolution((int)5); p2.SetYResolution((int)5); p3 = new vtkPlaneSource(); p3.SetOrigin((double)-0.5,(double)-0.508,(double)-0.5); p3.SetPoint1((double)0.5,(double)-0.508,(double)-0.5); p3.SetPoint2((double)-0.5,(double)-0.508,(double)0.5); p3.SetXResolution((int)5); p3.SetYResolution((int)5); p4 = new vtkPlaneSource(); p4.SetOrigin((double)0.508,(double)-0.5,(double)-0.5); p4.SetPoint1((double)0.508,(double)0.5,(double)-0.5); p4.SetPoint2((double)0.508,(double)-0.5,(double)0.5); p4.SetXResolution((int)5); p4.SetYResolution((int)5); p5 = new vtkPlaneSource(); p5.SetOrigin((double)0.5,(double)0.5,(double)-0.508); p5.SetPoint1((double)0.5,(double)-0.5,(double)-0.508); p5.SetPoint2((double)-0.5,(double)0.5,(double)-0.508); p5.SetXResolution((int)5); p5.SetYResolution((int)5); p6 = new vtkPlaneSource(); p6.SetOrigin((double)0.5,(double)0.5,(double)0.508); p6.SetPoint1((double)-0.5,(double)0.5,(double)0.508); p6.SetPoint2((double)0.5,(double)-0.5,(double)0.508); p6.SetXResolution((int)5); p6.SetYResolution((int)5); // append together[] ap = new vtkAppendPolyData(); ap.AddInputConnection(p1.GetOutputPort()); ap.AddInputConnection(p2.GetOutputPort()); ap.AddInputConnection(p3.GetOutputPort()); ap.AddInputConnection(p4.GetOutputPort()); ap.AddInputConnection(p5.GetOutputPort()); ap.AddInputConnection(p6.GetOutputPort()); //--------------------------[] // linear transform matrix[] t1 = new vtkMatrixToLinearTransform(); m1 = new vtkMatrix4x4(); t1.SetInput((vtkMatrix4x4)m1); m1.SetElement((int)0,(int)0,(double)1.127631); m1.SetElement((int)0,(int)1,(double)0.205212); m1.SetElement((int)0,(int)2,(double)-0.355438); m1.SetElement((int)1,(int)0,(double)0.000000); m1.SetElement((int)1,(int)1,(double)0.692820); m1.SetElement((int)1,(int)2,(double)0.400000); m1.SetElement((int)2,(int)0,(double)0.200000); m1.SetElement((int)2,(int)1,(double)-0.469846); m1.SetElement((int)2,(int)2,(double)0.813798); f11 = new vtkTransformPolyDataFilter(); f11.SetInputConnection((vtkAlgorithmOutput)ap.GetOutputPort()); f11.SetTransform((vtkAbstractTransform)t1); m11 = new vtkDataSetMapper(); m11.SetInputConnection((vtkAlgorithmOutput)f11.GetOutputPort()); a11 = new vtkActor(); a11.SetMapper((vtkMapper)m11); a11.GetProperty().SetColor((double)1,(double)0,(double)0); a11.GetProperty().SetRepresentationToWireframe(); ren11 = vtkRenderer.New(); ren11.SetViewport((double)0.0,(double)0.5,(double)0.25,(double)1.0); ren11.ResetCamera((double)-0.5,(double)0.5,(double)-0.5,(double)0.5,(double)-1,(double)1); ren11.AddActor((vtkProp)a11); renWin.AddRenderer((vtkRenderer)ren11); // inverse identity transform[] f12 = new vtkTransformPolyDataFilter(); f12.SetInputConnection((vtkAlgorithmOutput)ap.GetOutputPort()); f12.SetTransform((vtkAbstractTransform)t1.GetInverse()); m12 = new vtkDataSetMapper(); m12.SetInputConnection((vtkAlgorithmOutput)f12.GetOutputPort()); a12 = new vtkActor(); a12.SetMapper((vtkMapper)m12); a12.GetProperty().SetColor((double)0.9,(double)0.9,(double)0); a12.GetProperty().SetRepresentationToWireframe(); ren12 = vtkRenderer.New(); ren12.SetViewport((double)0.0,(double)0.0,(double)0.25,(double)0.5); ren12.ResetCamera((double)-0.5,(double)0.5,(double)-0.5,(double)0.5,(double)-1,(double)1); ren12.AddActor((vtkProp)a12); renWin.AddRenderer((vtkRenderer)ren12); //--------------------------[] // perspective transform matrix[] m2 = new vtkMatrix4x4(); m2.SetElement((int)3,(int)0,(double)-0.11); m2.SetElement((int)3,(int)1,(double)0.3); m2.SetElement((int)3,(int)2,(double)0.2); t2 = new vtkMatrixToHomogeneousTransform(); t2.SetInput((vtkMatrix4x4)m2); f21 = new vtkTransformPolyDataFilter(); f21.SetInputConnection((vtkAlgorithmOutput)ap.GetOutputPort()); f21.SetTransform((vtkAbstractTransform)t2); m21 = new vtkDataSetMapper(); m21.SetInputConnection((vtkAlgorithmOutput)f21.GetOutputPort()); a21 = new vtkActor(); a21.SetMapper((vtkMapper)m21); a21.GetProperty().SetColor((double)1,(double)0,(double)0); a21.GetProperty().SetRepresentationToWireframe(); ren21 = vtkRenderer.New(); ren21.SetViewport((double)0.25,(double)0.5,(double)0.50,(double)1.0); ren21.ResetCamera((double)-0.5,(double)0.5,(double)-0.5,(double)0.5,(double)-1,(double)1); ren21.AddActor((vtkProp)a21); renWin.AddRenderer((vtkRenderer)ren21); // inverse linear transform[] f22 = new vtkTransformPolyDataFilter(); f22.SetInputConnection((vtkAlgorithmOutput)ap.GetOutputPort()); f22.SetTransform((vtkAbstractTransform)t2.GetInverse()); m22 = new vtkDataSetMapper(); m22.SetInputConnection((vtkAlgorithmOutput)f22.GetOutputPort()); a22 = new vtkActor(); a22.SetMapper((vtkMapper)m22); a22.GetProperty().SetColor((double)0.9,(double)0.9,(double)0); a22.GetProperty().SetRepresentationToWireframe(); ren22 = vtkRenderer.New(); ren22.SetViewport((double)0.25,(double)0.0,(double)0.50,(double)0.5); ren22.ResetCamera((double)-0.5,(double)0.5,(double)-0.5,(double)0.5,(double)-1,(double)1); ren22.AddActor((vtkProp)a22); renWin.AddRenderer((vtkRenderer)ren22); //--------------------------[] // linear concatenation - should end up with identity here[] t3 = new vtkTransform(); t3.Concatenate((vtkLinearTransform)t1); t3.Concatenate((vtkLinearTransform)t1.GetInverse()); f31 = new vtkTransformPolyDataFilter(); f31.SetInputConnection((vtkAlgorithmOutput)ap.GetOutputPort()); f31.SetTransform((vtkAbstractTransform)t3); m31 = new vtkDataSetMapper(); m31.SetInputConnection((vtkAlgorithmOutput)f31.GetOutputPort()); a31 = new vtkActor(); a31.SetMapper((vtkMapper)m31); a31.GetProperty().SetColor((double)1,(double)0,(double)0); a31.GetProperty().SetRepresentationToWireframe(); ren31 = vtkRenderer.New(); ren31.SetViewport((double)0.50,(double)0.5,(double)0.75,(double)1.0); ren31.ResetCamera((double)-0.5,(double)0.5,(double)-0.5,(double)0.5,(double)-1,(double)1); ren31.AddActor((vtkProp)a31); renWin.AddRenderer((vtkRenderer)ren31); // inverse linear transform[] f32 = new vtkTransformPolyDataFilter(); f32.SetInputConnection((vtkAlgorithmOutput)ap.GetOutputPort()); f32.SetTransform((vtkAbstractTransform)t3.GetInverse()); m32 = new vtkDataSetMapper(); m32.SetInputConnection((vtkAlgorithmOutput)f32.GetOutputPort()); a32 = new vtkActor(); a32.SetMapper((vtkMapper)m32); a32.GetProperty().SetColor((double)0.9,(double)0.9,(double)0); a32.GetProperty().SetRepresentationToWireframe(); ren32 = vtkRenderer.New(); ren32.SetViewport((double)0.5,(double)0.0,(double)0.75,(double)0.5); ren32.ResetCamera((double)-0.5,(double)0.5,(double)-0.5,(double)0.5,(double)-1,(double)1); ren32.AddActor((vtkProp)a32); renWin.AddRenderer((vtkRenderer)ren32); //--------------------------[] // perspective transform concatenation[] t4 = new vtkPerspectiveTransform(); t4.Concatenate((vtkHomogeneousTransform)t1); t4.Concatenate((vtkHomogeneousTransform)t2); t4.Concatenate((vtkHomogeneousTransform)t3); f41 = new vtkTransformPolyDataFilter(); f41.SetInputConnection((vtkAlgorithmOutput)ap.GetOutputPort()); f41.SetTransform((vtkAbstractTransform)t4); m41 = new vtkDataSetMapper(); m41.SetInputConnection((vtkAlgorithmOutput)f41.GetOutputPort()); a41 = new vtkActor(); a41.SetMapper((vtkMapper)m41); a41.GetProperty().SetColor((double)1,(double)0,(double)0); a41.GetProperty().SetRepresentationToWireframe(); ren41 = vtkRenderer.New(); ren41.SetViewport((double)0.75,(double)0.5,(double)1.0,(double)1.0); ren41.ResetCamera((double)-0.5,(double)0.5,(double)-0.5,(double)0.5,(double)-1,(double)1); ren41.AddActor((vtkProp)a41); renWin.AddRenderer((vtkRenderer)ren41); // inverse of transform concatenation[] f42 = new vtkTransformPolyDataFilter(); f42.SetInputConnection((vtkAlgorithmOutput)ap.GetOutputPort()); f42.SetTransform((vtkAbstractTransform)t4.GetInverse()); m42 = new vtkDataSetMapper(); m42.SetInputConnection((vtkAlgorithmOutput)f42.GetOutputPort()); a42 = new vtkActor(); a42.SetMapper((vtkMapper)m42); a42.GetProperty().SetColor((double)0.9,(double)0.9,(double)0); a42.GetProperty().SetRepresentationToWireframe(); ren42 = vtkRenderer.New(); ren42.SetViewport((double)0.75,(double)0.0,(double)1.0,(double)0.5); ren42.ResetCamera((double)-0.5,(double)0.5,(double)-0.5,(double)0.5,(double)-1,(double)1); ren42.AddActor((vtkProp)a42); renWin.AddRenderer((vtkRenderer)ren42); renWin.Render(); //deleteAllVTKObjects(); }
///<summary> A Set Method for Static Variables </summary> public static void Setap(vtkAppendPolyData toSet) { ap = toSet; }
///<summary> A Set Method for Static Variables </summary> public static void SetappendF(vtkAppendPolyData toSet) { appendF = toSet; }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVprobeComb(String [] argv) { //Prefix Content is: "" // create planes[] // Create the RenderWindow, Renderer and both Actors[] //[] ren1 = vtkRenderer.New(); renWin = vtkRenderWindow.New(); renWin.SetMultiSamples(0); renWin.AddRenderer((vtkRenderer)ren1); iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); // create pipeline[] //[] 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(); plane = new vtkPlaneSource(); plane.SetResolution((int)50, (int)50); transP1 = new vtkTransform(); transP1.Translate((double)3.7, (double)0.0, (double)28.37); transP1.Scale((double)5, (double)5, (double)5); transP1.RotateY((double)90); tpd1 = new vtkTransformPolyDataFilter(); tpd1.SetInputConnection((vtkAlgorithmOutput)plane.GetOutputPort()); tpd1.SetTransform((vtkAbstractTransform)transP1); outTpd1 = new vtkOutlineFilter(); outTpd1.SetInputConnection((vtkAlgorithmOutput)tpd1.GetOutputPort()); mapTpd1 = vtkPolyDataMapper.New(); mapTpd1.SetInputConnection((vtkAlgorithmOutput)outTpd1.GetOutputPort()); tpd1Actor = new vtkActor(); tpd1Actor.SetMapper((vtkMapper)mapTpd1); tpd1Actor.GetProperty().SetColor((double)0, (double)0, (double)0); transP2 = new vtkTransform(); transP2.Translate((double)9.2, (double)0.0, (double)31.20); transP2.Scale((double)5, (double)5, (double)5); transP2.RotateY((double)90); tpd2 = new vtkTransformPolyDataFilter(); tpd2.SetInputConnection((vtkAlgorithmOutput)plane.GetOutputPort()); tpd2.SetTransform((vtkAbstractTransform)transP2); outTpd2 = new vtkOutlineFilter(); outTpd2.SetInputConnection((vtkAlgorithmOutput)tpd2.GetOutputPort()); mapTpd2 = vtkPolyDataMapper.New(); mapTpd2.SetInputConnection((vtkAlgorithmOutput)outTpd2.GetOutputPort()); tpd2Actor = new vtkActor(); tpd2Actor.SetMapper((vtkMapper)mapTpd2); tpd2Actor.GetProperty().SetColor((double)0, (double)0, (double)0); transP3 = new vtkTransform(); transP3.Translate((double)13.27, (double)0.0, (double)33.30); transP3.Scale((double)5, (double)5, (double)5); transP3.RotateY((double)90); tpd3 = new vtkTransformPolyDataFilter(); tpd3.SetInputConnection((vtkAlgorithmOutput)plane.GetOutputPort()); tpd3.SetTransform((vtkAbstractTransform)transP3); outTpd3 = new vtkOutlineFilter(); outTpd3.SetInputConnection((vtkAlgorithmOutput)tpd3.GetOutputPort()); mapTpd3 = vtkPolyDataMapper.New(); mapTpd3.SetInputConnection((vtkAlgorithmOutput)outTpd3.GetOutputPort()); tpd3Actor = new vtkActor(); tpd3Actor.SetMapper((vtkMapper)mapTpd3); tpd3Actor.GetProperty().SetColor((double)0, (double)0, (double)0); appendF = new vtkAppendPolyData(); appendF.AddInputConnection(tpd1.GetOutputPort()); appendF.AddInputConnection(tpd2.GetOutputPort()); appendF.AddInputConnection(tpd3.GetOutputPort()); probe = new vtkProbeFilter(); probe.SetInputConnection((vtkAlgorithmOutput)appendF.GetOutputPort()); probe.SetSourceData((vtkDataSet)pl3d.GetOutput().GetBlock(0)); contour = new vtkContourFilter(); contour.SetInputConnection((vtkAlgorithmOutput)probe.GetOutputPort()); contour.GenerateValues((int)50, (double)((vtkDataSet)pl3d.GetOutput().GetBlock(0)).GetScalarRange()[0], (double)((vtkDataSet)pl3d.GetOutput().GetBlock(0)).GetScalarRange()[1]); contourMapper = vtkPolyDataMapper.New(); contourMapper.SetInputConnection((vtkAlgorithmOutput)contour.GetOutputPort()); contourMapper.SetScalarRange((double)((vtkDataSet)pl3d.GetOutput().GetBlock(0)).GetScalarRange()[0], (double)((vtkDataSet)pl3d.GetOutput().GetBlock(0)).GetScalarRange()[1]); planeActor = new vtkActor(); planeActor.SetMapper((vtkMapper)contourMapper); 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); outlineActor.GetProperty().SetColor((double)0, (double)0, (double)0); ren1.AddActor((vtkProp)outlineActor); ren1.AddActor((vtkProp)planeActor); ren1.AddActor((vtkProp)tpd1Actor); ren1.AddActor((vtkProp)tpd2Actor); ren1.AddActor((vtkProp)tpd3Actor); ren1.SetBackground((double)1, (double)1, (double)1); renWin.SetSize((int)400, (int)400); cam1 = ren1.GetActiveCamera(); cam1.SetClippingRange((double)3.95297, (double)50); cam1.SetFocalPoint((double)8.88908, (double)0.595038, (double)29.3342); cam1.SetPosition((double)-12.3332, (double)31.7479, (double)41.2387); cam1.SetViewUp((double)0.060772, (double)-0.319905, (double)0.945498); iren.Initialize(); // prevent the tk window from showing up then start the event loop[] //deleteAllVTKObjects(); }
/// <summary> /// A console application that creates a /// vtkRenderWindow without a Windows Form /// </summary> /// <param name="argv"></param> public static void Main(String[] argv) { // Demonstrate how to use the vtkBoxWidget 3D widget, // This script uses a 3D box widget to define a "clipping box" to clip some // simple geometry (a mace). Make sure that you hit the "W" key to activate the widget. // Create a mace out of filters. sphere = vtkSphereSource.New(); cone = vtkConeSource.New(); glyph = vtkGlyph3D.New(); glyph.SetInputConnection(sphere.GetOutputPort()); glyph.SetSource(cone.GetOutput()); glyph.SetVectorModeToUseNormal(); glyph.SetScaleModeToScaleByVector(); glyph.SetScaleFactor(0.25); // The sphere and spikes are appended into a single polydata. This just makes things // simpler to manage. apd = vtkAppendPolyData.New(); apd.AddInput(glyph.GetOutput()); apd.AddInput(sphere.GetOutput()); maceMapper = vtkPolyDataMapper.New(); maceMapper.SetInputConnection(apd.GetOutputPort()); maceActor = vtkLODActor.New(); maceActor.SetMapper(maceMapper); maceActor.VisibilityOn(); // This portion of the code clips the mace with the vtkPlanes implicit function. // The clipped region is colored green. planes = vtkPlanes.New(); clipper = vtkClipPolyData.New(); clipper.SetInputConnection(apd.GetOutputPort()); clipper.SetClipFunction(planes); clipper.InsideOutOn(); selectMapper = vtkPolyDataMapper.New(); selectMapper.SetInputConnection(clipper.GetOutputPort()); selectActor = vtkLODActor.New(); selectActor.SetMapper(selectMapper); selectActor.GetProperty().SetColor(0, 1, 0); selectActor.VisibilityOff(); selectActor.SetScale(1.01, 1.01, 1.01); // Create the RenderWindow, Renderer and both Actors ren1 = vtkRenderer.New(); renWin = vtkRenderWindow.New(); renWin.AddRenderer(ren1); iren = vtkRenderWindowInteractor.New(); iren.SetRenderWindow(renWin); // The SetInteractor method is how 3D widgets are associated with the render // window interactor. Internally, SetInteractor sets up a bunch of callbacks // using the Command/Observer mechanism (AddObserver()). boxWidget = vtkBoxWidget.New(); boxWidget.SetInteractor(iren); boxWidget.SetPlaceFactor(1.25); ren1.AddActor(maceActor); ren1.AddActor(selectActor); // Add the actors to the renderer, set the background and size ren1.SetBackground(0.1, 0.2, 0.4); renWin.SetSize(300, 300); // Place the interactor initially. The input to a 3D widget is used to // initially position and scale the widget. The EndInteractionEvent is // observed which invokes the SelectPolygons callback. boxWidget.SetInput(glyph.GetOutput()); boxWidget.PlaceWidget(); boxWidget.EndInteractionEvt += new vtkObject.vtkObjectEventHandler(SelectPolygons); // render the image iren.Initialize(); iren.Start(); //Clean up deleteAllVTKObjects(); }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVMatrixToTransform(String [] argv) { //Prefix Content is: "" // This example demonstrates how to use a matrix in place of a transfrom[] // via vtkMatrixToLinearTransform and vtkMatrixToHomogeneousTransform.[] // create a rendering window[] renWin = vtkRenderWindow.New(); renWin.SetSize((int)600, (int)300); // set up first set of polydata[] p1 = new vtkPlaneSource(); p1.SetOrigin((double)0.5, (double)0.508, (double)-0.5); p1.SetPoint1((double)-0.5, (double)0.508, (double)-0.5); p1.SetPoint2((double)0.5, (double)0.508, (double)0.5); p1.SetXResolution((int)5); p1.SetYResolution((int)5); p2 = new vtkPlaneSource(); p2.SetOrigin((double)-0.508, (double)0.5, (double)-0.5); p2.SetPoint1((double)-0.508, (double)-0.5, (double)-0.5); p2.SetPoint2((double)-0.508, (double)0.5, (double)0.5); p2.SetXResolution((int)5); p2.SetYResolution((int)5); p3 = new vtkPlaneSource(); p3.SetOrigin((double)-0.5, (double)-0.508, (double)-0.5); p3.SetPoint1((double)0.5, (double)-0.508, (double)-0.5); p3.SetPoint2((double)-0.5, (double)-0.508, (double)0.5); p3.SetXResolution((int)5); p3.SetYResolution((int)5); p4 = new vtkPlaneSource(); p4.SetOrigin((double)0.508, (double)-0.5, (double)-0.5); p4.SetPoint1((double)0.508, (double)0.5, (double)-0.5); p4.SetPoint2((double)0.508, (double)-0.5, (double)0.5); p4.SetXResolution((int)5); p4.SetYResolution((int)5); p5 = new vtkPlaneSource(); p5.SetOrigin((double)0.5, (double)0.5, (double)-0.508); p5.SetPoint1((double)0.5, (double)-0.5, (double)-0.508); p5.SetPoint2((double)-0.5, (double)0.5, (double)-0.508); p5.SetXResolution((int)5); p5.SetYResolution((int)5); p6 = new vtkPlaneSource(); p6.SetOrigin((double)0.5, (double)0.5, (double)0.508); p6.SetPoint1((double)-0.5, (double)0.5, (double)0.508); p6.SetPoint2((double)0.5, (double)-0.5, (double)0.508); p6.SetXResolution((int)5); p6.SetYResolution((int)5); // append together[] ap = new vtkAppendPolyData(); ap.AddInputConnection(p1.GetOutputPort()); ap.AddInputConnection(p2.GetOutputPort()); ap.AddInputConnection(p3.GetOutputPort()); ap.AddInputConnection(p4.GetOutputPort()); ap.AddInputConnection(p5.GetOutputPort()); ap.AddInputConnection(p6.GetOutputPort()); //--------------------------[] // linear transform matrix[] t1 = new vtkMatrixToLinearTransform(); m1 = new vtkMatrix4x4(); t1.SetInput((vtkMatrix4x4)m1); m1.SetElement((int)0, (int)0, (double)1.127631); m1.SetElement((int)0, (int)1, (double)0.205212); m1.SetElement((int)0, (int)2, (double)-0.355438); m1.SetElement((int)1, (int)0, (double)0.000000); m1.SetElement((int)1, (int)1, (double)0.692820); m1.SetElement((int)1, (int)2, (double)0.400000); m1.SetElement((int)2, (int)0, (double)0.200000); m1.SetElement((int)2, (int)1, (double)-0.469846); m1.SetElement((int)2, (int)2, (double)0.813798); f11 = new vtkTransformPolyDataFilter(); f11.SetInputConnection((vtkAlgorithmOutput)ap.GetOutputPort()); f11.SetTransform((vtkAbstractTransform)t1); m11 = new vtkDataSetMapper(); m11.SetInputConnection((vtkAlgorithmOutput)f11.GetOutputPort()); a11 = new vtkActor(); a11.SetMapper((vtkMapper)m11); a11.GetProperty().SetColor((double)1, (double)0, (double)0); a11.GetProperty().SetRepresentationToWireframe(); ren11 = vtkRenderer.New(); ren11.SetViewport((double)0.0, (double)0.5, (double)0.25, (double)1.0); ren11.ResetCamera((double)-0.5, (double)0.5, (double)-0.5, (double)0.5, (double)-1, (double)1); ren11.AddActor((vtkProp)a11); renWin.AddRenderer((vtkRenderer)ren11); // inverse identity transform[] f12 = new vtkTransformPolyDataFilter(); f12.SetInputConnection((vtkAlgorithmOutput)ap.GetOutputPort()); f12.SetTransform((vtkAbstractTransform)t1.GetInverse()); m12 = new vtkDataSetMapper(); m12.SetInputConnection((vtkAlgorithmOutput)f12.GetOutputPort()); a12 = new vtkActor(); a12.SetMapper((vtkMapper)m12); a12.GetProperty().SetColor((double)0.9, (double)0.9, (double)0); a12.GetProperty().SetRepresentationToWireframe(); ren12 = vtkRenderer.New(); ren12.SetViewport((double)0.0, (double)0.0, (double)0.25, (double)0.5); ren12.ResetCamera((double)-0.5, (double)0.5, (double)-0.5, (double)0.5, (double)-1, (double)1); ren12.AddActor((vtkProp)a12); renWin.AddRenderer((vtkRenderer)ren12); //--------------------------[] // perspective transform matrix[] m2 = new vtkMatrix4x4(); m2.SetElement((int)3, (int)0, (double)-0.11); m2.SetElement((int)3, (int)1, (double)0.3); m2.SetElement((int)3, (int)2, (double)0.2); t2 = new vtkMatrixToHomogeneousTransform(); t2.SetInput((vtkMatrix4x4)m2); f21 = new vtkTransformPolyDataFilter(); f21.SetInputConnection((vtkAlgorithmOutput)ap.GetOutputPort()); f21.SetTransform((vtkAbstractTransform)t2); m21 = new vtkDataSetMapper(); m21.SetInputConnection((vtkAlgorithmOutput)f21.GetOutputPort()); a21 = new vtkActor(); a21.SetMapper((vtkMapper)m21); a21.GetProperty().SetColor((double)1, (double)0, (double)0); a21.GetProperty().SetRepresentationToWireframe(); ren21 = vtkRenderer.New(); ren21.SetViewport((double)0.25, (double)0.5, (double)0.50, (double)1.0); ren21.ResetCamera((double)-0.5, (double)0.5, (double)-0.5, (double)0.5, (double)-1, (double)1); ren21.AddActor((vtkProp)a21); renWin.AddRenderer((vtkRenderer)ren21); // inverse linear transform[] f22 = new vtkTransformPolyDataFilter(); f22.SetInputConnection((vtkAlgorithmOutput)ap.GetOutputPort()); f22.SetTransform((vtkAbstractTransform)t2.GetInverse()); m22 = new vtkDataSetMapper(); m22.SetInputConnection((vtkAlgorithmOutput)f22.GetOutputPort()); a22 = new vtkActor(); a22.SetMapper((vtkMapper)m22); a22.GetProperty().SetColor((double)0.9, (double)0.9, (double)0); a22.GetProperty().SetRepresentationToWireframe(); ren22 = vtkRenderer.New(); ren22.SetViewport((double)0.25, (double)0.0, (double)0.50, (double)0.5); ren22.ResetCamera((double)-0.5, (double)0.5, (double)-0.5, (double)0.5, (double)-1, (double)1); ren22.AddActor((vtkProp)a22); renWin.AddRenderer((vtkRenderer)ren22); //--------------------------[] // linear concatenation - should end up with identity here[] t3 = new vtkTransform(); t3.Concatenate((vtkLinearTransform)t1); t3.Concatenate((vtkLinearTransform)t1.GetInverse()); f31 = new vtkTransformPolyDataFilter(); f31.SetInputConnection((vtkAlgorithmOutput)ap.GetOutputPort()); f31.SetTransform((vtkAbstractTransform)t3); m31 = new vtkDataSetMapper(); m31.SetInputConnection((vtkAlgorithmOutput)f31.GetOutputPort()); a31 = new vtkActor(); a31.SetMapper((vtkMapper)m31); a31.GetProperty().SetColor((double)1, (double)0, (double)0); a31.GetProperty().SetRepresentationToWireframe(); ren31 = vtkRenderer.New(); ren31.SetViewport((double)0.50, (double)0.5, (double)0.75, (double)1.0); ren31.ResetCamera((double)-0.5, (double)0.5, (double)-0.5, (double)0.5, (double)-1, (double)1); ren31.AddActor((vtkProp)a31); renWin.AddRenderer((vtkRenderer)ren31); // inverse linear transform[] f32 = new vtkTransformPolyDataFilter(); f32.SetInputConnection((vtkAlgorithmOutput)ap.GetOutputPort()); f32.SetTransform((vtkAbstractTransform)t3.GetInverse()); m32 = new vtkDataSetMapper(); m32.SetInputConnection((vtkAlgorithmOutput)f32.GetOutputPort()); a32 = new vtkActor(); a32.SetMapper((vtkMapper)m32); a32.GetProperty().SetColor((double)0.9, (double)0.9, (double)0); a32.GetProperty().SetRepresentationToWireframe(); ren32 = vtkRenderer.New(); ren32.SetViewport((double)0.5, (double)0.0, (double)0.75, (double)0.5); ren32.ResetCamera((double)-0.5, (double)0.5, (double)-0.5, (double)0.5, (double)-1, (double)1); ren32.AddActor((vtkProp)a32); renWin.AddRenderer((vtkRenderer)ren32); //--------------------------[] // perspective transform concatenation[] t4 = new vtkPerspectiveTransform(); t4.Concatenate((vtkHomogeneousTransform)t1); t4.Concatenate((vtkHomogeneousTransform)t2); t4.Concatenate((vtkHomogeneousTransform)t3); f41 = new vtkTransformPolyDataFilter(); f41.SetInputConnection((vtkAlgorithmOutput)ap.GetOutputPort()); f41.SetTransform((vtkAbstractTransform)t4); m41 = new vtkDataSetMapper(); m41.SetInputConnection((vtkAlgorithmOutput)f41.GetOutputPort()); a41 = new vtkActor(); a41.SetMapper((vtkMapper)m41); a41.GetProperty().SetColor((double)1, (double)0, (double)0); a41.GetProperty().SetRepresentationToWireframe(); ren41 = vtkRenderer.New(); ren41.SetViewport((double)0.75, (double)0.5, (double)1.0, (double)1.0); ren41.ResetCamera((double)-0.5, (double)0.5, (double)-0.5, (double)0.5, (double)-1, (double)1); ren41.AddActor((vtkProp)a41); renWin.AddRenderer((vtkRenderer)ren41); // inverse of transform concatenation[] f42 = new vtkTransformPolyDataFilter(); f42.SetInputConnection((vtkAlgorithmOutput)ap.GetOutputPort()); f42.SetTransform((vtkAbstractTransform)t4.GetInverse()); m42 = new vtkDataSetMapper(); m42.SetInputConnection((vtkAlgorithmOutput)f42.GetOutputPort()); a42 = new vtkActor(); a42.SetMapper((vtkMapper)m42); a42.GetProperty().SetColor((double)0.9, (double)0.9, (double)0); a42.GetProperty().SetRepresentationToWireframe(); ren42 = vtkRenderer.New(); ren42.SetViewport((double)0.75, (double)0.0, (double)1.0, (double)0.5); ren42.ResetCamera((double)-0.5, (double)0.5, (double)-0.5, (double)0.5, (double)-1, (double)1); ren42.AddActor((vtkProp)a42); renWin.AddRenderer((vtkRenderer)ren42); renWin.Render(); //deleteAllVTKObjects(); }
public static void ShowPolydata(string airwayPath, string lesionPath) { vtkAppendPolyData appendPolydata = new vtkAppendPolyData(); if (File.Exists(airwayPath)) { vtkXMLPolyDataReader reader = new vtkXMLPolyDataReader(); reader.SetFileName(airwayPath); reader.Update(); appendPolydata.AddInput(reader.GetOutput()); reader.Dispose(); } else { MessageBox.Show("airwayPath : " + airwayPath + "文件不存在!"); } if (File.Exists(lesionPath)) { vtkXMLPolyDataReader reader = new vtkXMLPolyDataReader(); reader.SetFileName(lesionPath); reader.Update(); appendPolydata.AddInput(reader.GetOutput()); reader.Dispose(); } else { MessageBox.Show("lesionPath : " + lesionPath + "文件不存在!"); } vtkRenderWindow renWin = vtkRenderWindow.New(); renWin.SetSize(600, 600); vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor(); renWin.SetInteractor(iren); vtkInteractorStyleTrackballCamera interactorStyle = new vtkInteractorStyleTrackballCamera(); iren.SetInteractorStyle(interactorStyle); vtkRenderer renderer = vtkRenderer.New(); renderer.GradientBackgroundOn(); renderer.SetBackground(0, 0, 0); renderer.SetBackground2(0, 0, 1); renWin.AddRenderer(renderer); vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); mapper.ScalarVisibilityOff(); mapper.SetInput(appendPolydata.GetOutput()); vtkActor actor = new vtkActor(); actor.SetMapper(mapper); renderer.AddActor(actor); renderer.Render(); renderer.ResetCamera(); renWin.Render(); //Thread thread = new Thread(new ThreadStart( // delegate // { // iren.Start(); // })); //thread.Start(); }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVprobeComb(String [] argv) { //Prefix Content is: "" // create planes[] // Create the RenderWindow, Renderer and both Actors[] //[] ren1 = vtkRenderer.New(); renWin = vtkRenderWindow.New(); renWin.AddRenderer((vtkRenderer)ren1); iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); // create pipeline[] //[] pl3d = new vtkPLOT3DReader(); 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(); plane = new vtkPlaneSource(); plane.SetResolution((int)50,(int)50); transP1 = new vtkTransform(); transP1.Translate((double)3.7,(double)0.0,(double)28.37); transP1.Scale((double)5,(double)5,(double)5); transP1.RotateY((double)90); tpd1 = new vtkTransformPolyDataFilter(); tpd1.SetInputConnection((vtkAlgorithmOutput)plane.GetOutputPort()); tpd1.SetTransform((vtkAbstractTransform)transP1); outTpd1 = new vtkOutlineFilter(); outTpd1.SetInputConnection((vtkAlgorithmOutput)tpd1.GetOutputPort()); mapTpd1 = vtkPolyDataMapper.New(); mapTpd1.SetInputConnection((vtkAlgorithmOutput)outTpd1.GetOutputPort()); tpd1Actor = new vtkActor(); tpd1Actor.SetMapper((vtkMapper)mapTpd1); tpd1Actor.GetProperty().SetColor((double)0,(double)0,(double)0); transP2 = new vtkTransform(); transP2.Translate((double)9.2,(double)0.0,(double)31.20); transP2.Scale((double)5,(double)5,(double)5); transP2.RotateY((double)90); tpd2 = new vtkTransformPolyDataFilter(); tpd2.SetInputConnection((vtkAlgorithmOutput)plane.GetOutputPort()); tpd2.SetTransform((vtkAbstractTransform)transP2); outTpd2 = new vtkOutlineFilter(); outTpd2.SetInputConnection((vtkAlgorithmOutput)tpd2.GetOutputPort()); mapTpd2 = vtkPolyDataMapper.New(); mapTpd2.SetInputConnection((vtkAlgorithmOutput)outTpd2.GetOutputPort()); tpd2Actor = new vtkActor(); tpd2Actor.SetMapper((vtkMapper)mapTpd2); tpd2Actor.GetProperty().SetColor((double)0,(double)0,(double)0); transP3 = new vtkTransform(); transP3.Translate((double)13.27,(double)0.0,(double)33.30); transP3.Scale((double)5,(double)5,(double)5); transP3.RotateY((double)90); tpd3 = new vtkTransformPolyDataFilter(); tpd3.SetInputConnection((vtkAlgorithmOutput)plane.GetOutputPort()); tpd3.SetTransform((vtkAbstractTransform)transP3); outTpd3 = new vtkOutlineFilter(); outTpd3.SetInputConnection((vtkAlgorithmOutput)tpd3.GetOutputPort()); mapTpd3 = vtkPolyDataMapper.New(); mapTpd3.SetInputConnection((vtkAlgorithmOutput)outTpd3.GetOutputPort()); tpd3Actor = new vtkActor(); tpd3Actor.SetMapper((vtkMapper)mapTpd3); tpd3Actor.GetProperty().SetColor((double)0,(double)0,(double)0); appendF = new vtkAppendPolyData(); appendF.AddInput((vtkPolyData)tpd1.GetOutput()); appendF.AddInput((vtkPolyData)tpd2.GetOutput()); appendF.AddInput((vtkPolyData)tpd3.GetOutput()); probe = new vtkProbeFilter(); probe.SetInputConnection((vtkAlgorithmOutput)appendF.GetOutputPort()); probe.SetSource((vtkDataObject)pl3d.GetOutput()); contour = new vtkContourFilter(); contour.SetInputConnection((vtkAlgorithmOutput)probe.GetOutputPort()); contour.GenerateValues((int)50,(double)((vtkDataSet)pl3d.GetOutput()).GetScalarRange()[0], (double)((vtkDataSet)pl3d.GetOutput()).GetScalarRange()[1]); contourMapper = vtkPolyDataMapper.New(); contourMapper.SetInputConnection((vtkAlgorithmOutput)contour.GetOutputPort()); contourMapper.SetScalarRange((double)((vtkDataSet)pl3d.GetOutput()).GetScalarRange()[0], (double)((vtkDataSet)pl3d.GetOutput()).GetScalarRange()[1]); planeActor = new vtkActor(); planeActor.SetMapper((vtkMapper)contourMapper); outline = new vtkStructuredGridOutlineFilter(); outline.SetInputConnection((vtkAlgorithmOutput)pl3d.GetOutputPort()); outlineMapper = vtkPolyDataMapper.New(); outlineMapper.SetInputConnection((vtkAlgorithmOutput)outline.GetOutputPort()); outlineActor = new vtkActor(); outlineActor.SetMapper((vtkMapper)outlineMapper); outlineActor.GetProperty().SetColor((double)0,(double)0,(double)0); ren1.AddActor((vtkProp)outlineActor); ren1.AddActor((vtkProp)planeActor); ren1.AddActor((vtkProp)tpd1Actor); ren1.AddActor((vtkProp)tpd2Actor); ren1.AddActor((vtkProp)tpd3Actor); ren1.SetBackground((double)1,(double)1,(double)1); renWin.SetSize((int)400,(int)400); cam1 = ren1.GetActiveCamera(); cam1.SetClippingRange((double)3.95297,(double)50); cam1.SetFocalPoint((double)8.88908,(double)0.595038,(double)29.3342); cam1.SetPosition((double)-12.3332,(double)31.7479,(double)41.2387); cam1.SetViewUp((double)0.060772,(double)-0.319905,(double)0.945498); iren.Initialize(); // prevent the tk window from showing up then start the event loop[] //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); }
public void CreateViewport(Grid Window) { WindowsFormsHost VTK_Window = new WindowsFormsHost(); // Create Windows Forms Host for VTK Window RenWinControl = new RenderWindowControl(); // Initialize VTK Renderer Window Control // Clear input Window and add new host Window.Children.Clear(); Window.Children.Add(VTK_Window); VTK_Window.Child = RenWinControl; // Create Render Window renderWindow = RenWinControl.RenderWindow; // Initialize Interactor Inter = vtkRenderWindowInteractor.New(); Inter.LeftButtonPressEvt += new vtkObject.vtkObjectEventHandler(SelectPointClick); Inter.RightButtonPressEvt += new vtkObject.vtkObjectEventHandler(UnselectPointClick); renderWindow.SetInteractor(Inter); Inter.Initialize(); InterStyleTrack = vtkInteractorStyleTrackballCamera.New(); //Inter.SetInteractorStyle(InterStyleTrack); InterStylePick = vtkInteractorStyleRubberBandPick.New(); Inter.SetInteractorStyle(InterStylePick); // Initialize View Viewport = renderWindow.GetRenderers().GetFirstRenderer(); Viewport.RemoveAllViewProps(); CreateViewportBorder(Viewport, new double[3] { 128.0, 128.0, 128.0 }); // Set default background color Viewport.GradientBackgroundOn(); Viewport.SetBackground(163.0 / 255.0, 163.0 / 255.0, 163.0 / 255.0); Viewport.SetBackground2(45.0 / 255.0, 85.0 / 255.0, 125.0 / 255.0); // Other properties Viewport.GetActiveCamera().ParallelProjectionOn(); // Initialize Selection objects AppendFaces = vtkAppendPolyData.New(); Faces = vtkPolyData.New(); SelectionMode = false; SelectionSize = 0.1; SelectionPoints = vtkPoints.New(); SelectionActor = vtkActor.New(); SelectionPolyData = vtkPolyData.New(); SelectionPolyData.SetPoints(SelectionPoints); SelectionSphere = vtkSphereSource.New(); SelectionSphere.SetPhiResolution(12); SelectionSphere.SetThetaResolution(12); SelectionSphere.SetRadius(SelectionSize); SelectionGlyph = vtkGlyph3D.New(); SelectionGlyph.SetInput(SelectionPolyData); SelectionGlyph.SetSourceConnection(SelectionSphere.GetOutputPort()); SelectionMapper = vtkPolyDataMapper.New(); SelectionMapper.SetInputConnection(SelectionGlyph.GetOutputPort()); SelectionActor.SetMapper(SelectionMapper); SelectionActor.GetProperty().SetColor(1, 1, 1); SelectionActor.VisibilityOn(); Viewport.AddActor(SelectionActor); // Create new Properties and Objects CreateColorMap(); CreateScalarBar(); CreateAxes(); CreateSlider(); CreateClipPlane(); }