private void DrawTexturePlane() { //load in the texture map vtkBMPReader bmpReader = vtkBMPReader.New(); bmpReader.SetFileName(@"..\..\Data\masonry.bmp"); vtkTexture atext = vtkTexture.New(); atext.SetInputConnection(bmpReader.GetOutputPort()); atext.InterpolateOn(); //create a plane source and actor vtkPlaneSource plane = vtkPlaneSource.New(); plane.SetPoint1(0, 0, 0); vtkPolyDataMapper planeMapper = vtkPolyDataMapper.New(); planeMapper.SetInputConnection(plane.GetOutputPort()); vtkActor planeActor = vtkActor.New(); planeActor.SetMapper(planeMapper); planeActor.SetTexture(atext); vtkRenderer renderer = vtkRenderer.New(); vtkRenderWindow renWin = myRenderWindowControl.RenderWindow; renWin.AddRenderer(renderer); renderer.AddActor(planeActor); }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVcombStreamers2(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); // 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(); ps = new vtkPlaneSource(); ps.SetXResolution((int)4); ps.SetYResolution((int)4); ps.SetOrigin((double)2,(double)-2,(double)26); ps.SetPoint1((double)2,(double)2,(double)26); ps.SetPoint2((double)2,(double)-2,(double)32); psMapper = vtkPolyDataMapper.New(); psMapper.SetInputConnection((vtkAlgorithmOutput)ps.GetOutputPort()); psActor = new vtkActor(); psActor.SetMapper((vtkMapper)psMapper); psActor.GetProperty().SetRepresentationToWireframe(); streamer = new vtkDashedStreamLine(); streamer.SetInputConnection((vtkAlgorithmOutput)pl3d.GetOutputPort()); streamer.SetSource((vtkDataSet)ps.GetOutput()); streamer.SetMaximumPropagationTime((double)100); streamer.SetIntegrationStepLength((double).2); streamer.SetStepLength((double).001); streamer.SetNumberOfThreads((int)1); streamer.SetIntegrationDirectionToForward(); streamMapper = vtkPolyDataMapper.New(); streamMapper.SetInputConnection((vtkAlgorithmOutput)streamer.GetOutputPort()); streamMapper.SetScalarRange( (double)((vtkDataSet)pl3d.GetOutput()).GetScalarRange()[0], (double)((vtkDataSet)pl3d.GetOutput()).GetScalarRange()[1]); streamline = new vtkActor(); streamline.SetMapper((vtkMapper)streamMapper); outline = new vtkStructuredGridOutlineFilter(); outline.SetInputConnection((vtkAlgorithmOutput)pl3d.GetOutputPort()); outlineMapper = vtkPolyDataMapper.New(); outlineMapper.SetInputConnection((vtkAlgorithmOutput)outline.GetOutputPort()); outlineActor = new vtkActor(); outlineActor.SetMapper((vtkMapper)outlineMapper); // Add the actors to the renderer, set the background and size[] //[] ren1.AddActor((vtkProp)psActor); ren1.AddActor((vtkProp)outlineActor); ren1.AddActor((vtkProp)streamline); ren1.SetBackground((double)1,(double)1,(double)1); renWin.SetSize((int)300,(int)300); ren1.SetBackground((double)0.1,(double)0.2,(double)0.4); cam1 = ren1.GetActiveCamera(); cam1.SetClippingRange((double)3.95297,(double)50); cam1.SetFocalPoint((double)9.71821,(double)0.458166,(double)29.3999); cam1.SetPosition((double)2.7439,(double)-37.3196,(double)38.7167); cam1.SetViewUp((double)-0.16123,(double)0.264271,(double)0.950876); // render the image[] //[] renWin.Render(); // prevent the tk window from showing up then start the event loop[] //deleteAllVTKObjects(); }
private void CreatePlane(cPoint3D Axis1, cPoint3D Axis2, cPoint3D Origin, Color Colour) { Position = new cPoint3D(Origin.X, Origin.Y, Origin.Z); this.Colour = Colour; Plane = vtkPlaneSource.New(); Plane.SetPoint1(Axis1.X, Axis1.Y, Axis1.Z); Plane.SetPoint2(Axis2.X, Axis2.Y, Axis2.Z); Plane.SetOrigin(0, 0, 0); Plane.SetXResolution(1); Plane.SetYResolution(1); vtk_PolyDataMapper = vtkPolyDataMapper.New(); vtk_PolyDataMapper.SetInputConnection(Plane.GetOutputPort()); CreateVTK3DObject(0); }
//切片模式_绘制 private void DrawMode_Slice() { int[] xyz = m_ImageData.GetDimensions(); double[] sp = m_ImageData.GetSpacing(); double[] pos = new double[] { m_XPos, m_YPos, m_ZPos }; #region -------------------XOY切片(垂直Z轴)------------------- m_ImageResliceXOY = vtkImageReslice.New(); m_ImageResliceXOY.SetInput(m_ImageData); m_ImageResliceXOY.SetResliceAxesDirectionCosines( 1, 0, 0, 0, 1, 0, 0, 0, 1 ); m_ImageResliceXOY.InterpolateOn(); m_ImageResliceXOY.SetInterpolationModeToNearestNeighbor(); m_ImageResliceXOY.SetResliceAxesOrigin(pos[0], pos[1], pos[2]); m_ImageResliceXOY.SetOutputDimensionality(2); m_ImageResliceXOY.Update(); m_TextureXOY = vtkTexture.New(); m_TextureXOY.InterpolateOff(); m_TextureXOY.SetInput(m_ImageResliceXOY.GetOutput()); m_TextureXOY.SetLookupTable(m_LookupTable); m_TextureXOY.MapColorScalarsThroughLookupTableOn(); //---------------------set plane position---------- m_PlaneSourceXOY = vtkPlaneSource.New(); m_PlaneSourceXOY.SetXResolution(xyz[0]); m_PlaneSourceXOY.SetYResolution(xyz[1]); m_PlaneSourceXOY.SetOrigin(0, 0, 0); m_PlaneSourceXOY.SetPoint1((xyz[0] - 1) * sp[0], 0, 0); m_PlaneSourceXOY.SetPoint2(0, (xyz[1] - 1) * sp[1], 0); m_PlaneSourceXOY.Push(pos[2]); //---------------------pipeline-------------------- m_PlaneMapperXOY = vtkPolyDataMapper.New(); m_PlaneMapperXOY.SetInput(m_PlaneSourceXOY.GetOutput()); m_ActorXOY = vtkActor.New(); m_ActorXOY.SetMapper(m_PlaneMapperXOY); m_ActorXOY.SetTexture(m_TextureXOY); #endregion #region -------------------XOZ切片(垂直Y轴)------------------- m_ImageResliceXOZ = vtkImageReslice.New(); m_ImageResliceXOZ.SetInput(m_ImageData); m_ImageResliceXOZ.SetResliceAxesDirectionCosines( 1, 0, 0, 0, 0, -1, 0, 1, 0 ); m_ImageResliceXOZ.InterpolateOn(); m_ImageResliceXOZ.SetInterpolationModeToNearestNeighbor(); m_ImageResliceXOZ.SetResliceAxesOrigin(pos[0], pos[1], pos[2]); m_ImageResliceXOZ.SetOutputDimensionality(2); m_ImageResliceXOZ.Update(); m_TextureXOZ = vtkTexture.New(); m_TextureXOZ.SetInput(m_ImageResliceXOZ.GetOutput()); m_TextureXOZ.SetLookupTable(m_LookupTable); m_TextureXOZ.MapColorScalarsThroughLookupTableOn(); //---------------------set plane position-------------------- m_PlaneSourceXOZ = vtkPlaneSource.New(); m_PlaneSourceXOZ.SetXResolution(xyz[0]); m_PlaneSourceXOZ.SetYResolution(xyz[2]); m_PlaneSourceXOZ.SetOrigin(0, 0, (xyz[2] - 1) * sp[2]); m_PlaneSourceXOZ.SetPoint1((xyz[0] - 1) * sp[0], 0, (xyz[2] - 1) * sp[2]); m_PlaneSourceXOZ.SetPoint2(0, 0, 0); m_PlaneSourceXOZ.Push(pos[1]); //---------------------pipeline------------------------------ m_PlaneMapperXOZ = vtkPolyDataMapper.New(); m_PlaneMapperXOZ.SetInput(m_PlaneSourceXOZ.GetOutput()); m_ActorXOZ = vtkActor.New(); m_ActorXOZ.SetMapper(m_PlaneMapperXOZ); m_ActorXOZ.SetTexture(m_TextureXOZ); #endregion #region -------------------YOZ切片(垂直X轴)------------------- m_ImageResliceYOZ = vtkImageReslice.New(); m_ImageResliceYOZ.SetInput(m_ImageData); m_ImageResliceYOZ.SetResliceAxesDirectionCosines( 0, 0, -1, 0, 1, 0, 1, 0, 0 ); m_ImageResliceYOZ.InterpolateOn(); m_ImageResliceYOZ.SetInterpolationModeToNearestNeighbor(); m_ImageResliceYOZ.SetResliceAxesOrigin(pos[0], pos[1], pos[2]); m_ImageResliceYOZ.SetOutputDimensionality(2); m_ImageResliceYOZ.Update(); m_TextureYOZ = vtkTexture.New(); m_TextureYOZ.SetInput(m_ImageResliceYOZ.GetOutput()); m_TextureYOZ.SetLookupTable(m_LookupTable); m_TextureYOZ.MapColorScalarsThroughLookupTableOn(); //---------------------set plane position-------------------- m_PlaneSourceYOZ = vtkPlaneSource.New(); m_PlaneSourceYOZ.SetXResolution(xyz[2]); m_PlaneSourceYOZ.SetYResolution(xyz[1]); m_PlaneSourceYOZ.SetOrigin(0, 0, (xyz[2] - 1) * sp[2]); m_PlaneSourceYOZ.SetPoint1(0, 0, 0); m_PlaneSourceYOZ.SetPoint2(0, (xyz[1] - 1) * sp[1], (xyz[2] - 1) * sp[2]); m_PlaneSourceYOZ.Push(pos[0]); //---------------------pipeline------------------------------ m_PlaneMapperYOZ = vtkPolyDataMapper.New(); m_PlaneMapperYOZ.SetInput(m_PlaneSourceYOZ.GetOutput()); m_ActorYOZ = vtkActor.New(); m_ActorYOZ.SetMapper(m_PlaneMapperYOZ); m_ActorYOZ.SetTexture(m_TextureYOZ); #endregion m_Renderer.AddActor(m_ActorXOY); m_Renderer.AddActor(m_ActorXOZ); m_Renderer.AddActor(m_ActorYOZ); }
/// <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> /// 绘制立方体的五个面 /// 根据index确定需要绘制哪个面 /// </summary> /// <param name="index"></param> /// <param name="renderer"></param> public void PlotSurface(int index, vtkRenderer renderer) { vtkPlaneSource pSrc = vtkPlaneSource.New(); vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); vtkActor actor = vtkActor.New(); switch (index) { case 0: pSrc.SetCenter(sideLen + 0.5 + offset[0], sideLen + 0.5 + offset[1], 0 + offset[2]); pSrc.SetNormal(0, 0, 1); pSrc.SetPoint1(sideLen + offset[0], 0 + offset[1], 0 + offset[2]); pSrc.SetPoint2(0 + offset[0], sideLen + offset[1], 0 + offset[2]); mapper.SetInput(pSrc.GetOutput()); actor.SetMapper(mapper); renderer.AddActor(actor); break; case 1: pSrc.SetCenter(0 + offset[0], sideLen + 0.5 + offset[1], sideLen - 0.5 + offset[2]); pSrc.SetNormal(1, 0, 0); pSrc.SetPoint1(0 + offset[0], 0 + offset[1], sideLen + offset[2]); pSrc.SetPoint2(0 + offset[0], sideLen + offset[1], 0 + offset[2]); mapper.SetInput(pSrc.GetOutput()); actor.SetMapper(mapper); renderer.AddActor(actor); break; case 2: pSrc.SetCenter(sideLen + offset[0], sideLen + 0.5 + offset[1], sideLen - 0.5 + offset[2]); pSrc.SetNormal(1, 0, 0); pSrc.SetPoint1(sideLen + offset[0], 0 + offset[1], sideLen + offset[2]); pSrc.SetPoint2(sideLen + offset[0], sideLen + offset[1], 0 + offset[2]); mapper.SetInput(pSrc.GetOutput()); actor.SetMapper(mapper); renderer.AddActor(actor); break; case 3: pSrc.SetCenter(sideLen + 0.5 + offset[0], 0 + offset[1], sideLen - 0.5 + offset[2]); pSrc.SetNormal(0, 1, 0); pSrc.SetPoint1(sideLen + offset[0], 0 + offset[1], 0 + offset[2]); pSrc.SetPoint2(0 + offset[0], 0 + offset[1], sideLen + offset[2]); mapper.SetInput(pSrc.GetOutput()); actor.SetMapper(mapper); renderer.AddActor(actor); break; case 4: pSrc.SetCenter(sideLen + 0.5 + offset[0], sideLen + offset[1], sideLen - 0.5 + offset[2]); pSrc.SetNormal(0, 1, 0); pSrc.SetPoint1(sideLen + offset[0], sideLen + offset[1], 0 + offset[2]); pSrc.SetPoint2(0 + offset[0], sideLen + offset[1], sideLen + offset[2]); mapper.SetInput(pSrc.GetOutput()); actor.SetMapper(mapper); renderer.AddActor(actor); break; case 5: break; default: break; } }
/// <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> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVTestSplineFilter(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); // 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(); ps = new vtkPlaneSource(); ps.SetXResolution((int)4); ps.SetYResolution((int)4); ps.SetOrigin((double)2, (double)-2, (double)26); ps.SetPoint1((double)2, (double)2, (double)26); ps.SetPoint2((double)2, (double)-2, (double)32); psMapper = vtkPolyDataMapper.New(); psMapper.SetInputConnection((vtkAlgorithmOutput)ps.GetOutputPort()); psActor = new vtkActor(); psActor.SetMapper((vtkMapper)psMapper); psActor.GetProperty().SetRepresentationToWireframe(); rk4 = new vtkRungeKutta4(); streamer = new vtkStreamLine(); streamer.SetInputData((vtkDataSet)pl3d.GetOutput().GetBlock(0)); streamer.SetSourceConnection(ps.GetOutputPort()); streamer.SetMaximumPropagationTime((double)100); streamer.SetIntegrationStepLength((double).2); streamer.SetStepLength((double).001); streamer.SetNumberOfThreads((int)1); streamer.SetIntegrationDirectionToForward(); streamer.VorticityOn(); streamer.SetIntegrator((vtkInitialValueProblemSolver)rk4); sf = new vtkSplineFilter(); sf.SetInputConnection((vtkAlgorithmOutput)streamer.GetOutputPort()); sf.SetSubdivideToLength(); sf.SetLength((double)0.15); rf = new vtkRibbonFilter(); rf.SetInputConnection((vtkAlgorithmOutput)sf.GetOutputPort()); rf.SetWidth((double)0.1); rf.SetWidthFactor((double)5); streamMapper = vtkPolyDataMapper.New(); streamMapper.SetInputConnection((vtkAlgorithmOutput)rf.GetOutputPort()); streamMapper.SetScalarRange((double)((vtkDataSet)pl3d.GetOutput().GetBlock(0)).GetScalarRange()[0], (double)((vtkDataSet)pl3d.GetOutput().GetBlock(0)).GetScalarRange()[1]); streamline = new vtkActor(); streamline.SetMapper((vtkMapper)streamMapper); 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); // Add the actors to the renderer, set the background and size[] //[] ren1.AddActor((vtkProp)psActor); ren1.AddActor((vtkProp)outlineActor); ren1.AddActor((vtkProp)streamline); ren1.SetBackground((double)1, (double)1, (double)1); renWin.SetSize((int)300, (int)300); ren1.SetBackground((double)0.1, (double)0.2, (double)0.4); cam1 = ren1.GetActiveCamera(); cam1.SetClippingRange((double)3.95297, (double)50); cam1.SetFocalPoint((double)9.71821, (double)0.458166, (double)29.3999); cam1.SetPosition((double)2.7439, (double)-37.3196, (double)38.7167); cam1.SetViewUp((double)-0.16123, (double)0.264271, (double)0.950876); // render the image[] //[] renWin.Render(); // prevent the tk window from showing up then start the event loop[] // for testing[] threshold = 15; //deleteAllVTKObjects(); }