Ejemplo n.º 1
2
        static void Main()
        {
            string VTK_DATA_ROOT = "C:/Program Files/VTKData";

            // Create a vtkBYUReader and read in a data set.
            vtkBYUReader fohe = new vtkBYUReader();
            fohe.SetGeometryFileName(VTK_DATA_ROOT + "/Data/teapot.g");

            // Create a vtkPolyDataNormals filter to calculate the normals of the
            // data set.
            vtkPolyDataNormals normals = new vtkPolyDataNormals();
            normals.SetInputConnection(fohe.GetOutputPort());
            // Set up the associated mapper and actor.
            vtkPolyDataMapper foheMapper = new vtkPolyDataMapper();
            foheMapper.SetInputConnection(normals.GetOutputPort());
            vtkLODActor foheActor = new vtkLODActor();
            foheActor.SetMapper(foheMapper);

            // Create a vtkOutlineFilter to draw the bounding box of the data set.
            // Also create the associated mapper and actor.
            vtkOutlineFilter outline = new vtkOutlineFilter();
            outline.SetInputConnection(normals.GetOutputPort());
            vtkPolyDataMapper mapOutline = new vtkPolyDataMapper();
            mapOutline.SetInputConnection(outline.GetOutputPort());
            vtkActor outlineActor = new vtkActor();
            outlineActor.SetMapper(mapOutline);
            outlineActor.GetProperty().SetColor(0, 0, 0);

            // Create a vtkCamera, and set the camera parameters.
            vtkCamera camera = new vtkCamera();
            camera.SetClippingRange(1.60187, 20.0842);
            camera.SetFocalPoint(0.21406, 1.5, 0);
            camera.SetPosition(8.3761, 4.94858, 4.12505);
            camera.SetViewUp(0.180325, 0.549245, -0.815974);

            // Create a vtkLight, and set the light parameters.
            vtkLight light = new vtkLight();
            light.SetFocalPoint(0.21406, 1.5, 0);
            light.SetPosition(8.3761, 4.94858, 4.12505);

            // Create the Renderers.  Assign them the appropriate viewport
            // coordinates, active camera, and light.
            vtkRenderer ren = new vtkRenderer();
            ren.SetViewport(0, 0, 0.5, 1.0);
            ren.SetActiveCamera(camera);
            ren.AddLight(light);
            vtkRenderer ren2 = new vtkRenderer();
            ren2.SetViewport(0.5, 0, 1.0, 1.0);
            ren2.SetActiveCamera(camera);
            ren2.AddLight(light);

            // Create the RenderWindow and RenderWindowInteractor.
            vtkRenderWindow renWin = new vtkRenderWindow();
            renWin.AddRenderer(ren);
            renWin.AddRenderer(ren2);
            renWin.SetWindowName("VTK - Cube Axes");
            renWin.SetSize(600, 300);
            vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor();
            iren.SetRenderWindow(renWin);

            // Add the actors to the renderer, and set the background.
            ren.AddViewProp(foheActor);
            ren.AddViewProp(outlineActor);
            ren2.AddViewProp(foheActor);
            ren2.AddViewProp(outlineActor);

            ren.SetBackground(0.1, 0.2, 0.4);
            ren2.SetBackground(0.1, 0.2, 0.4);

            // Create a text property for both cube axes
            vtkTextProperty tprop = new vtkTextProperty();
            tprop.SetColor(1, 1, 1);
            tprop.ShadowOn();

            // Create a vtkCubeAxesActor2D.  Use the outer edges of the bounding box to
            // draw the axes.  Add the actor to the renderer.
            vtkCubeAxesActor2D axes = new vtkCubeAxesActor2D();
            axes.SetInput(normals.GetOutput());
            axes.SetCamera(ren.GetActiveCamera());
            axes.SetLabelFormat("%6.4g");
            axes.SetFlyModeToOuterEdges();
            axes.SetFontFactor(0.8);
            axes.SetAxisTitleTextProperty(tprop);
            axes.SetAxisLabelTextProperty(tprop);
            ren.AddViewProp(axes);

            // Create a vtkCubeAxesActor2D.  Use the closest vertex to the camera to
            // determine where to draw the axes.  Add the actor to the renderer.
            vtkCubeAxesActor2D axes2 = new vtkCubeAxesActor2D();
            axes2.SetViewProp(foheActor);
            axes2.SetCamera(ren2.GetActiveCamera());
            axes2.SetLabelFormat("%6.4g");
            axes2.SetFlyModeToClosestTriad();
            axes2.SetFontFactor(0.8);
            axes2.ScalingOff();
            axes2.SetAxisTitleTextProperty(tprop);
            axes2.SetAxisLabelTextProperty(tprop);
            ren2.AddViewProp(axes2);

            renWin.AddObserver((uint) EventIds.AbortCheckEvent, CheckAbort);

            iren.Initialize();
            renWin.Render();
            iren.Start();

            vtkWin32OpenGLRenderWindow win32win =
                vtkWin32OpenGLRenderWindow.SafeDownCast(renWin);
            if (null != win32win) win32win.Clean();
        }
Ejemplo n.º 2
0
        private void CreateSurfaceRendering()
        {
            _contourFilter = new vtkContourFilter();
            _contourFilter.SetInput(_volumeGraphic.GetImageData());
            _contourFilter.SetValue(0, _volumeGraphic.GetRescaledLevel());

            vtkPolyDataNormals normals = new vtkPolyDataNormals();

            normals.SetInputConnection(_contourFilter.GetOutputPort());
            normals.SetFeatureAngle(60.0);

            vtkStripper stripper = new vtkStripper();

            stripper.SetInputConnection(normals.GetOutputPort());

            vtkPolyDataMapper mapper = new vtkPolyDataMapper();

            mapper.SetInputConnection(stripper.GetOutputPort());
            mapper.ScalarVisibilityOff();

            _vtkActor = new vtkActor();
            _vtkActor.SetMapper(mapper);
            _vtkActor.GetProperty().SetSpecular(.3);
            _vtkActor.GetProperty().SetSpecularPower(20);
            ApplySetting("Opacity");
            ApplySetting("Level");
        }
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVTestUnstructuredPieces(String [] argv)
    {
        //Prefix Content is: ""

          math = new vtkMath();
          vtkMath.RandomSeed((int)22);
          pf = new vtkParallelFactory();
          vtkParallelFactory.RegisterFactory((vtkObjectFactory)pf);
          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);
          dst = new vtkDataSetTriangleFilter();
          dst.SetInputData((vtkDataSet)pl3d.GetOutput().GetBlock(0));
          extract = new vtkExtractUnstructuredGridPiece();
          extract.SetInputConnection((vtkAlgorithmOutput)dst.GetOutputPort());
          cf = new vtkContourFilter();
          cf.SetInputConnection((vtkAlgorithmOutput)extract.GetOutputPort());
          cf.SetValue((int)0,(double)0.24);
          pdn = new vtkPolyDataNormals();
          pdn.SetInputConnection((vtkAlgorithmOutput)cf.GetOutputPort());
          ps = new vtkPieceScalars();
          ps.SetInputConnection((vtkAlgorithmOutput)pdn.GetOutputPort());
          mapper = vtkPolyDataMapper.New();
          mapper.SetInputConnection((vtkAlgorithmOutput)ps.GetOutputPort());
          mapper.SetNumberOfPieces((int)3);
          actor = new vtkActor();
          actor.SetMapper((vtkMapper)mapper);
          ren = vtkRenderer.New();
          ren.AddActor((vtkProp)actor);
          ren.ResetCamera();
          camera = ren.GetActiveCamera();
          //$camera SetPosition 68.1939 -23.4323 12.6465[]
          //$camera SetViewUp 0.46563 0.882375 0.0678508  []
          //$camera SetFocalPoint 3.65707 11.4552 1.83509 []
          //$camera SetClippingRange 59.2626 101.825 []
          renWin = vtkRenderWindow.New();
          renWin.AddRenderer((vtkRenderer)ren);
          iren = new vtkRenderWindowInteractor();
          iren.SetRenderWindow((vtkRenderWindow)renWin);
          iren.Initialize();

        //deleteAllVTKObjects();
    }
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVTestUnstructuredPieces(String [] argv)
    {
        //Prefix Content is: ""

        math = new vtkMath();
        vtkMath.RandomSeed((int)22);
        pf = new vtkParallelFactory();
        vtkParallelFactory.RegisterFactory((vtkObjectFactory)pf);
        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);
        dst = new vtkDataSetTriangleFilter();
        dst.SetInputData((vtkDataSet)pl3d.GetOutput().GetBlock(0));
        extract = new vtkExtractUnstructuredGridPiece();
        extract.SetInputConnection((vtkAlgorithmOutput)dst.GetOutputPort());
        cf = new vtkContourFilter();
        cf.SetInputConnection((vtkAlgorithmOutput)extract.GetOutputPort());
        cf.SetValue((int)0, (double)0.24);
        pdn = new vtkPolyDataNormals();
        pdn.SetInputConnection((vtkAlgorithmOutput)cf.GetOutputPort());
        ps = new vtkPieceScalars();
        ps.SetInputConnection((vtkAlgorithmOutput)pdn.GetOutputPort());
        mapper = vtkPolyDataMapper.New();
        mapper.SetInputConnection((vtkAlgorithmOutput)ps.GetOutputPort());
        mapper.SetNumberOfPieces((int)3);
        actor = new vtkActor();
        actor.SetMapper((vtkMapper)mapper);
        ren = vtkRenderer.New();
        ren.AddActor((vtkProp)actor);
        ren.ResetCamera();
        camera = ren.GetActiveCamera();
        //$camera SetPosition 68.1939 -23.4323 12.6465[]
        //$camera SetViewUp 0.46563 0.882375 0.0678508  []
        //$camera SetFocalPoint 3.65707 11.4552 1.83509 []
        //$camera SetClippingRange 59.2626 101.825 []
        renWin = vtkRenderWindow.New();
        renWin.AddRenderer((vtkRenderer)ren);
        iren = new vtkRenderWindowInteractor();
        iren.SetRenderWindow((vtkRenderWindow)renWin);
        iren.Initialize();

//deleteAllVTKObjects();
    }
Ejemplo n.º 5
0
		private void CreateSurfaceRendering()
		{
			_contourFilter = new vtkContourFilter();
			_contourFilter.SetInput(_volumeGraphic.GetImageData());
			_contourFilter.SetValue(0, _volumeGraphic.GetRescaledLevel());

			vtkPolyDataNormals normals = new vtkPolyDataNormals();
			normals.SetInputConnection(_contourFilter.GetOutputPort());
			normals.SetFeatureAngle(60.0);

			vtkStripper stripper = new vtkStripper();
			stripper.SetInputConnection(normals.GetOutputPort());

			vtkPolyDataMapper mapper = new vtkPolyDataMapper();
			mapper.SetInputConnection(stripper.GetOutputPort());
			mapper.ScalarVisibilityOff();

			_vtkActor = new vtkActor();
			_vtkActor.SetMapper(mapper);
			_vtkActor.GetProperty().SetSpecular(.3);
			_vtkActor.GetProperty().SetSpecularPower(20);
			ApplySetting("Opacity");
			ApplySetting("Level");
		}
Ejemplo n.º 6
0
        /// <summary>
        /// 进行三维结构的转换
        /// </summary>
        /// <param name="degree"></param>
        /// <param name="polyData"></param>
        /// <param name="info"></param>
        /// <returns></returns>
        private static vtkPolyData Extrude3DSection(float degree, vtkPolyData polyData, ModelingBaseInfo info)
        {
            //进行拉伸以构造的三维实体
            vtkRotationalExtrusionFilter extrude = vtkRotationalExtrusionFilter.New();

            extrude.SetInput(polyData);
            extrude.SetResolution(80);
            extrude.SetAngle(degree);//旋转
            extrude.CappingOn();

            vtkPolyDataNormals normals = vtkPolyDataNormals.New();

            normals.SetInput(extrude.GetOutput());
            normals.SetFeatureAngle(100);
            //进行转换
            vtkTransform transform = vtkTransform.New();

            transform.RotateX(info.Angle);                                                            //逆时针为正,顺时针为负
            transform.Translate(info.BaseCoordinate.X, info.BaseCoordinate.Y, info.BaseCoordinate.Z); //先旋转后平移

            vtkTransformFilter transFilter = vtkTransformFilter.New();

            transFilter.SetTransform(transform);
            transFilter.SetInput(normals.GetOutput());

            //vtkTriangleFilter filter = vtkTriangleFilter.New();
            //filter.SetInput(transFilter.GetOutput());

            //return filter.GetPolyDataInput(0);

            vtkCleanPolyData clearPolydata = vtkCleanPolyData.New();//清除重合的点和片

            clearPolydata.SetInput(transFilter.GetOutput());
            return(clearPolydata.GetOutput());
            //return transFilter.GetPolyDataOutput();
        }
Ejemplo n.º 7
0
 ///<summary> A Set Method for Static Variables </summary>
 public static void Setnormals(vtkPolyDataNormals toSet)
 {
     normals = toSet;
 }
Ejemplo n.º 8
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVTestPolyDataPieces(String [] argv)
    {
        //Prefix Content is: ""

        math = new vtkMath();
        vtkMath.RandomSeed((int)22);
        pf = new vtkParallelFactory();
        vtkParallelFactory.RegisterFactory((vtkObjectFactory)pf);
        sphere = new vtkSphereSource();
        sphere.SetPhiResolution((int)32);
        sphere.SetThetaResolution((int)32);
        extract = new vtkExtractPolyDataPiece();
        extract.SetInputConnection((vtkAlgorithmOutput)sphere.GetOutputPort());
        normals = new vtkPolyDataNormals();
        normals.SetInputConnection((vtkAlgorithmOutput)extract.GetOutputPort());
        ps = new vtkPieceScalars();
        ps.SetInputConnection((vtkAlgorithmOutput)normals.GetOutputPort());
        mapper = vtkPolyDataMapper.New();
        mapper.SetInputConnection((vtkAlgorithmOutput)ps.GetOutputPort());
        mapper.SetNumberOfPieces((int)2);
        actor = new vtkActor();
        actor.SetMapper((vtkMapper)mapper);
        sphere2 = new vtkSphereSource();
        sphere2.SetPhiResolution((int)32);
        sphere2.SetThetaResolution((int)32);
        extract2 = new vtkExtractPolyDataPiece();
        extract2.SetInputConnection((vtkAlgorithmOutput)sphere2.GetOutputPort());
        mapper2 = vtkPolyDataMapper.New();
        mapper2.SetInputConnection((vtkAlgorithmOutput)extract2.GetOutputPort());
        mapper2.SetNumberOfPieces((int)2);
        mapper2.SetPiece((int)1);
        mapper2.SetScalarRange((double)0, (double)4);
        mapper2.SetScalarModeToUseCellFieldData();
        mapper2.SetColorModeToMapScalars();
        mapper2.ColorByArrayComponent((string)"vtkGhostLevels", (int)0);
        mapper2.SetGhostLevel((int)4);
        // check the pipeline size[]
        extract2.UpdateInformation();
        psize = new vtkPipelineSize();
        if ((psize.GetEstimatedSize((vtkAlgorithm)extract2, (int)0, (int)0)) > 100)
        {
            //puts skipedputs ['stderr', '"ERROR: Pipeline Size increased"']
        }


        if ((psize.GetNumberOfSubPieces((uint)10, (vtkPolyDataMapper)mapper2)) != 2)
        {
            //puts skipedputs ['stderr', '"ERROR: Number of sub pieces changed"']
        }


        actor2 = new vtkActor();
        actor2.SetMapper((vtkMapper)mapper2);
        actor2.SetPosition((double)1.5, (double)0, (double)0);
        sphere3 = new vtkSphereSource();
        sphere3.SetPhiResolution((int)32);
        sphere3.SetThetaResolution((int)32);
        extract3 = new vtkExtractPolyDataPiece();
        extract3.SetInputConnection((vtkAlgorithmOutput)sphere3.GetOutputPort());
        ps3 = new vtkPieceScalars();
        ps3.SetInputConnection((vtkAlgorithmOutput)extract3.GetOutputPort());
        mapper3 = vtkPolyDataMapper.New();
        mapper3.SetInputConnection((vtkAlgorithmOutput)ps3.GetOutputPort());
        mapper3.SetNumberOfSubPieces((int)8);
        mapper3.SetScalarRange((double)0, (double)8);
        actor3 = new vtkActor();
        actor3.SetMapper((vtkMapper)mapper3);
        actor3.SetPosition((double)0, (double)-1.5, (double)0);
        sphere4 = new vtkSphereSource();
        sphere4.SetPhiResolution((int)32);
        sphere4.SetThetaResolution((int)32);
        extract4 = new vtkExtractPolyDataPiece();
        extract4.SetInputConnection((vtkAlgorithmOutput)sphere4.GetOutputPort());
        ps4 = new vtkPieceScalars();
        ps4.RandomModeOn();
        ps4.SetScalarModeToCellData();
        ps4.SetInputConnection((vtkAlgorithmOutput)extract4.GetOutputPort());
        mapper4 = vtkPolyDataMapper.New();
        mapper4.SetInputConnection((vtkAlgorithmOutput)ps4.GetOutputPort());
        mapper4.SetNumberOfSubPieces((int)8);
        mapper4.SetScalarRange((double)0, (double)8);
        actor4 = new vtkActor();
        actor4.SetMapper((vtkMapper)mapper4);
        actor4.SetPosition((double)1.5, (double)-1.5, (double)0);
        ren = vtkRenderer.New();
        ren.AddActor((vtkProp)actor);
        ren.AddActor((vtkProp)actor2);
        ren.AddActor((vtkProp)actor3);
        ren.AddActor((vtkProp)actor4);
        renWin = vtkRenderWindow.New();
        renWin.AddRenderer((vtkRenderer)ren);
        iren = new vtkRenderWindowInteractor();
        iren.SetRenderWindow((vtkRenderWindow)renWin);
        iren.Initialize();

//deleteAllVTKObjects();
    }
Ejemplo n.º 9
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVfieldToUGrid(String [] argv)
    {
        //Prefix Content is: ""

          // Read a field representing unstructured grid and display it (similar to blow.tcl)[]
          // create a reader and write out field daya[]
          reader = new vtkUnstructuredGridReader();
          reader.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/blow.vtk");
          reader.SetScalarsName((string)"thickness9");
          reader.SetVectorsName((string)"displacement9");
          ds2do = new vtkDataSetToDataObjectFilter();
          ds2do.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort());
          // we must be able to write here[]
          try
          {
         channel = new StreamWriter("UGridField.vtk");
          tryCatchError = "NOERROR";
          }
          catch(Exception)
          {tryCatchError = "ERROR";}

          if (tryCatchError.Equals("NOERROR"))
          {
          channel.Close();
          write = new vtkDataObjectWriter();
          write.SetInputConnection((vtkAlgorithmOutput)ds2do.GetOutputPort());
          write.SetFileName((string)"UGridField.vtk");
          write.Write();
          // Read the field and convert to unstructured grid.[]
          dor = new vtkDataObjectReader();
          dor.SetFileName((string)"UGridField.vtk");
          do2ds = new vtkDataObjectToDataSetFilter();
          do2ds.SetInputConnection((vtkAlgorithmOutput)dor.GetOutputPort());
          do2ds.SetDataSetTypeToUnstructuredGrid();
          do2ds.SetPointComponent((int)0,(string)"Points",(int)0);
          do2ds.SetPointComponent((int)1,(string)"Points",(int)1);
          do2ds.SetPointComponent((int)2,(string)"Points",(int)2);
          do2ds.SetCellTypeComponent((string)"CellTypes",(int)0);
          do2ds.SetCellConnectivityComponent((string)"Cells",(int)0);
          fd2ad = new vtkFieldDataToAttributeDataFilter();
          fd2ad.SetInput((vtkDataObject)do2ds.GetUnstructuredGridOutput());
          fd2ad.SetInputFieldToDataObjectField();
          fd2ad.SetOutputAttributeDataToPointData();
          fd2ad.SetVectorComponent((int)0,(string)"displacement9",(int)0);
          fd2ad.SetVectorComponent((int)1,(string)"displacement9",(int)1);
          fd2ad.SetVectorComponent((int)2,(string)"displacement9",(int)2);
          fd2ad.SetScalarComponent((int)0,(string)"thickness9",(int)0);
          // Now start visualizing[]
          warp = new vtkWarpVector();
          warp.SetInput((vtkDataObject)fd2ad.GetUnstructuredGridOutput());
          // extract mold from mesh using connectivity[]
          connect = new vtkConnectivityFilter();
          connect.SetInputConnection((vtkAlgorithmOutput)warp.GetOutputPort());
          connect.SetExtractionModeToSpecifiedRegions();
          connect.AddSpecifiedRegion((int)0);
          connect.AddSpecifiedRegion((int)1);
          moldMapper = new vtkDataSetMapper();
          moldMapper.SetInputConnection((vtkAlgorithmOutput)connect.GetOutputPort());
          moldMapper.ScalarVisibilityOff();
          moldActor = new vtkActor();
          moldActor.SetMapper((vtkMapper)moldMapper);
          moldActor.GetProperty().SetColor((double).2,(double).2,(double).2);
          moldActor.GetProperty().SetRepresentationToWireframe();
          // extract parison from mesh using connectivity[]
          connect2 = new vtkConnectivityFilter();
          connect2.SetInputConnection((vtkAlgorithmOutput)warp.GetOutputPort());
          connect2.SetExtractionModeToSpecifiedRegions();
          connect2.AddSpecifiedRegion((int)2);
          parison = new vtkGeometryFilter();
          parison.SetInputConnection((vtkAlgorithmOutput)connect2.GetOutputPort());
          normals2 = new vtkPolyDataNormals();
          normals2.SetInputConnection((vtkAlgorithmOutput)parison.GetOutputPort());
          normals2.SetFeatureAngle((double)60);
          lut = new vtkLookupTable();
          lut.SetHueRange((double)0.0,(double)0.66667);
          parisonMapper = vtkPolyDataMapper.New();
          parisonMapper.SetInputConnection((vtkAlgorithmOutput)normals2.GetOutputPort());
          parisonMapper.SetLookupTable((vtkScalarsToColors)lut);
          parisonMapper.SetScalarRange((double)0.12,(double)1.0);
          parisonActor = new vtkActor();
          parisonActor.SetMapper((vtkMapper)parisonMapper);
          cf = new vtkContourFilter();
          cf.SetInputConnection((vtkAlgorithmOutput)connect2.GetOutputPort());
          cf.SetValue((int)0,(double).5);
          contourMapper = vtkPolyDataMapper.New();
          contourMapper.SetInputConnection((vtkAlgorithmOutput)cf.GetOutputPort());
          contours = new vtkActor();
          contours.SetMapper((vtkMapper)contourMapper);
          // Create graphics stuff[]
          ren1 = vtkRenderer.New();
          renWin = vtkRenderWindow.New();
          renWin.AddRenderer((vtkRenderer)ren1);
          iren = new vtkRenderWindowInteractor();
          iren.SetRenderWindow((vtkRenderWindow)renWin);
          // Add the actors to the renderer, set the background and size[]
          ren1.AddActor((vtkProp)moldActor);
          ren1.AddActor((vtkProp)parisonActor);
          ren1.AddActor((vtkProp)contours);
          ren1.ResetCamera();
          ren1.GetActiveCamera().Azimuth((double)60);
          ren1.GetActiveCamera().Roll((double)-90);
          ren1.GetActiveCamera().Dolly((double)2);
          ren1.ResetCameraClippingRange();
          ren1.SetBackground((double)1,(double)1,(double)1);
          renWin.SetSize((int)375,(int)200);
          iren.Initialize();
        }

          // prevent the tk window from showing up then start the event loop[]

        //deleteAllVTKObjects();
    }
Ejemplo n.º 10
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVTenEllip(String [] argv)
    {
        //Prefix Content is: ""

          // create tensor ellipsoids[]
          // Create the RenderWindow, Renderer and interactive renderer[]
          //[]
          ren1 = vtkRenderer.New();
          renWin = vtkRenderWindow.New();
          renWin.SetMultiSamples(0);
          renWin.AddRenderer((vtkRenderer)ren1);
          iren = new vtkRenderWindowInteractor();
          iren.SetRenderWindow((vtkRenderWindow)renWin);
          //[]
          // Create tensor ellipsoids[]
          //[]
          // generate tensors[]
          ptLoad = new vtkPointLoad();
          ptLoad.SetLoadValue((double)100.0);
          ptLoad.SetSampleDimensions((int)6,(int)6,(int)6);
          ptLoad.ComputeEffectiveStressOn();
          ptLoad.SetModelBounds((double)-10,(double)10,(double)-10,(double)10,(double)-10,(double)10);
          // extract plane of data[]
          plane = new vtkImageDataGeometryFilter();
          plane.SetInputConnection((vtkAlgorithmOutput)ptLoad.GetOutputPort());
          plane.SetExtent((int)2,(int)2,(int)0,(int)99,(int)0,(int)99);
          // Generate ellipsoids[]
          sphere = new vtkSphereSource();
          sphere.SetThetaResolution((int)8);
          sphere.SetPhiResolution((int)8);
          ellipsoids = new vtkTensorGlyph();
          ellipsoids.SetInputConnection((vtkAlgorithmOutput)ptLoad.GetOutputPort());
          ellipsoids.SetSourceConnection((vtkAlgorithmOutput)sphere.GetOutputPort());
          ellipsoids.SetScaleFactor((double)10);
          ellipsoids.ClampScalingOn();
          ellipNormals = new vtkPolyDataNormals();
          ellipNormals.SetInputConnection((vtkAlgorithmOutput)ellipsoids.GetOutputPort());
          // Map contour[]
          lut = new vtkLogLookupTable();
          lut.SetHueRange((double).6667,(double)0.0);
          ellipMapper = vtkPolyDataMapper.New();
          ellipMapper.SetInputConnection((vtkAlgorithmOutput)ellipNormals.GetOutputPort());
          ellipMapper.SetLookupTable((vtkScalarsToColors)lut);
          plane.Update();
          //force update for scalar range[]
          ellipMapper.SetScalarRange((double)((vtkDataSet)plane.GetOutput()).GetScalarRange()[0],(double)((vtkDataSet)plane.GetOutput()).GetScalarRange()[1]);
          ellipActor = new vtkActor();
          ellipActor.SetMapper((vtkMapper)ellipMapper);
          //[]
          // Create outline around data[]
          //[]
          outline = new vtkOutlineFilter();
          outline.SetInputConnection((vtkAlgorithmOutput)ptLoad.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);
          //[]
          // Create cone indicating application of load[]
          //[]
          coneSrc = new vtkConeSource();
          coneSrc.SetRadius((double).5);
          coneSrc.SetHeight((double)2);
          coneMap = vtkPolyDataMapper.New();
          coneMap.SetInputConnection((vtkAlgorithmOutput)coneSrc.GetOutputPort());
          coneActor = new vtkActor();
          coneActor.SetMapper((vtkMapper)coneMap);
          coneActor.SetPosition((double)0,(double)0,(double)11);
          coneActor.RotateY((double)90);
          coneActor.GetProperty().SetColor((double)1,(double)0,(double)0);
          camera = new vtkCamera();
          camera.SetFocalPoint((double)0.113766,(double)-1.13665,(double)-1.01919);
          camera.SetPosition((double)-29.4886,(double)-63.1488,(double)26.5807);
          camera.SetViewAngle((double)24.4617);
          camera.SetViewUp((double)0.17138,(double)0.331163,(double)0.927879);
          camera.SetClippingRange((double)1,(double)100);
          ren1.AddActor((vtkProp)ellipActor);
          ren1.AddActor((vtkProp)outlineActor);
          ren1.AddActor((vtkProp)coneActor);
          ren1.SetBackground((double)1.0,(double)1.0,(double)1.0);
          ren1.SetActiveCamera((vtkCamera)camera);
          renWin.SetSize((int)400,(int)400);
          renWin.Render();
          // prevent the tk window from showing up then start the event loop[]

        //deleteAllVTKObjects();
    }
Ejemplo n.º 11
0
    /// <summary>
    /// An example that does not use a Windows Form
    /// </summary>
    /// <param name="argv"></param>
    public static void Main(String[] argv)
    {
        // This example demonstrates the use of vtkCubeAxesActor2D to indicate the
        // position in space that the camera is currently viewing.
        // The vtkCubeAxesActor2D draws axes on the bounding box of the data set and
        // labels the axes with x-y-z coordinates.
        //
        // First we include the VTK Tcl packages which will make available
        // all of the vtk commands to Tcl
        //
        // Create a vtkBYUReader and read in a data set.
        //
        fohe = vtkBYUReader.New();
        fohe.SetGeometryFileName("../../../teapot.g");

        // Create a vtkPolyDataNormals filter to calculate the normals of the data set.
        normals = vtkPolyDataNormals.New();
        normals.SetInputConnection(fohe.GetOutputPort());

        // Set up the associated mapper and actor.
        foheMapper = vtkPolyDataMapper.New();
        foheMapper.SetInputConnection(normals.GetOutputPort());

        foheActor = vtkLODActor.New();
        foheActor.SetMapper(foheMapper);

        // Create a vtkOutlineFilter to draw the bounding box of the data set.  Also
        // create the associated mapper and actor.
        outline = vtkOutlineFilter.New();
        outline.SetInputConnection(normals.GetOutputPort());

        mapOutline = vtkPolyDataMapper.New();
        mapOutline.SetInputConnection(outline.GetOutputPort());

        outlineActor = vtkActor.New();
        outlineActor.SetMapper(mapOutline);
        outlineActor.GetProperty().SetColor(0, 0, 0);

        // Create a vtkCamera, and set the camera parameters.
        camera = vtkCamera.New();
        camera.SetClippingRange(1.60187, 20.0842);
        camera.SetFocalPoint(0.21406, 1.5, 0);
        camera.SetPosition(8.3761, 4.94858, 4.12505);
        camera.SetViewUp(0.180325, 0.549245, -0.815974);

        // Create a vtkLight, and set the light parameters.
        light = vtkLight.New();
        light.SetFocalPoint(0.21406, 1.5, 0);
        light.SetPosition(8.3761, 4.94858, 4.12505);

        // Create the Renderers.  Assign them the appropriate viewport coordinates,
        // active camera, and light.
        ren1 = vtkRenderer.New();
        ren1.SetViewport(0, 0, 0.5, 1.0);
        ren1.SetActiveCamera(camera);
        ren1.AddLight(light);

        ren2 = vtkRenderer.New();
        ren2.SetViewport(0.5, 0, 1.0, 1.0);
        ren2.SetActiveCamera(camera);
        ren2.AddLight(light);

        // Create the RenderWindow and RenderWindowInteractor.
        renWin = vtkRenderWindow.New();
        renWin.AddRenderer(ren1);
        renWin.AddRenderer(ren2);
        renWin.SetWindowName("VTK - Cube Axes");
        renWin.SetSize(600, 300);
        iren = vtkRenderWindowInteractor.New();
        iren.SetRenderWindow(renWin);

        // Add the actors to the renderer, and set the background.
        ren1.AddViewProp(foheActor);
        ren1.AddViewProp(outlineActor);
        ren2.AddViewProp(foheActor);
        ren2.AddViewProp(outlineActor);
        ren1.SetBackground(0.1, 0.2, 0.4);
        ren2.SetBackground(0.1, 0.2, 0.4);

        // Create a text property for both cube axes
        tprop = vtkTextProperty.New();
        tprop.SetColor(1, 1, 1);
        tprop.ShadowOn();

        // Create a vtkCubeAxesActor2D.  Use the outer edges of the bounding box to
        // draw the axes.  Add the actor to the renderer.
        axes = vtkCubeAxesActor2D.New();
        axes.SetInput(normals.GetOutput());
        axes.SetCamera(ren1.GetActiveCamera());
        axes.SetLabelFormat("%6.4g");
        axes.SetFlyModeToOuterEdges();
        axes.SetFontFactor(0.8);
        axes.SetAxisTitleTextProperty(tprop);
        axes.SetAxisLabelTextProperty(tprop);
        ren1.AddViewProp(axes);

        // Create a vtkCubeAxesActor2D.  Use the closest vertex to the camera to
        // determine where to draw the axes.  Add the actor to the renderer.
        axes2 = vtkCubeAxesActor2D.New();
        axes2.SetViewProp(foheActor);
        axes2.SetCamera(ren2.GetActiveCamera());
        axes2.SetLabelFormat("%6.4g");
        axes2.SetFlyModeToClosestTriad();
        axes2.SetFontFactor(0.8);
        axes2.ScalingOff();
        axes2.SetAxisTitleTextProperty(tprop);
        axes2.SetAxisLabelTextProperty(tprop);
        ren2.AddViewProp(axes2);

        // Render
        renWin.Render();

        // Set the user method (bound to key 'u')
        iren.Initialize();
        iren.Start();

        // Set up a check for aborting rendering.
        renWin.AbortCheckEvt += new vtkObject.vtkObjectEventHandler(TkCheckAbort);

        //Clean Up
        deleteAllVTKObjects();
    }
Ejemplo n.º 12
0
        private void UpdateVtk(VtkAlgorithm algorithm, tkDefaultContext context)
        {
            if (!IsInitialized())
                return;
            if (_input)
            {
                _algorithm.SetInputConnection(_input.Algorithm.GetOutputPort());
                _input.UpdateVtk(_input, null);
            }

            if (_triangleFilter == null || _algorithm == null || _vtkMesh == null ||
                _gameObject == null)
                return;
            _algorithm.Update();
            _output = (vtkDataSet)_algorithm.GetOutputDataObject(0);
            // Input connection has to be set here because _algorithm address changes somehow
            // because of FullInspector serialization
            if (OutputDataDataType != DataType.vtkPolyData)
            {
                if (_geometryFilter == null)
                    _geometryFilter = vtkGeometryFilter.New();
                //_geometryFilter.MergingOff();
                _geometryFilter.SetInputConnection(_algorithm.GetOutputPort());
                _triangleFilter.SetInputConnection(_geometryFilter.GetOutputPort());
            }
            else
                _triangleFilter.SetInputConnection(_algorithm.GetOutputPort());
            _triangleFilter.PassVertsOn();
            _triangleFilter.PassLinesOn();
            _triangleFilter.Update();
            _polyDataOutput = _triangleFilter.GetOutput();

            if (_polyDataOutput == null ||
                _polyDataOutput.GetNumberOfPoints() == 0 ||
                _polyDataOutput.GetNumberOfCells() == 0)
            {
                // Debug.Log("Polydata output empty!");
                return;
            }

            if (GenerateNormals && !VtkNormalsHelper.GetPointNormals(_polyDataOutput))
            {
                if (_normalsFilter == null)
                    _normalsFilter = vtkPolyDataNormals.New();
                _normalsFilter.SetInputConnection(_triangleFilter.GetOutputPort());
                _normalsFilter.ComputePointNormalsOn();
                _normalsFilter.ComputeCellNormalsOff();
                _normalsFilter.Update();
                _polyDataOutput = _normalsFilter.GetOutput();
            }

            _arrayNames = GetArrayNames(_polyDataOutput);
            _arrayLabels = _arrayNames.Select(t => new GUIContent(t)).ToArray();

            if(!GenerateMesh)
                return;

            _vtkMesh.Update(_polyDataOutput);
            UpdateMeshColors(_selectedArrayIndex);
            DestroyImmediate(_gameObject.GetComponent<MeshRenderer>());
            DestroyImmediate(_gameObject.GetComponent<MeshFilter>());
            if (_vtkMesh.Meshes.Count == 1)
            {
                _gameObject.AddComponent<MeshFilter>().sharedMesh = _vtkMesh.Meshes[0];
                var meshRenderer = _gameObject.AddComponent<MeshRenderer>();
                meshRenderer.material =
                    new Material(Shader.Find("Diffuse")) { color = Color.gray };
                for(var i = 0; i < _gameObject.transform.childCount; i++)
                    DestroyImmediate(_gameObject.transform.GetChild(i));
            }
            else
            {
                for (var i = 0; i < _vtkMesh.Meshes.Count; i++)
                {
                    var currentName = Name + "-" + i;
                    GameObject child;
                    var childTransform = _gameObject.transform.FindChild(currentName);
                    if (childTransform == null)
                    {
                        child = new GameObject(currentName);
                        child.transform.parent = _gameObject.transform;
                        child.transform.localPosition = new Vector3();
                        child.AddComponent<MeshFilter>();
                        var meshRenderer = child.AddComponent<MeshRenderer>();
                        meshRenderer.material =
                            new Material(Shader.Find("Diffuse")) {color = Color.gray};
                    }
                    else
                        child = childTransform.gameObject;
                    child.GetComponent<MeshFilter>().sharedMesh = _vtkMesh.Meshes[i];
                }
                while (_vtkMesh.Meshes.Count < _gameObject.transform.childCount)
                    DestroyImmediate(_gameObject.transform.GetChild(
                        _gameObject.transform.childCount - 1));
            }
            if(MaterialProperties == null)
                MaterialProperties = _gameObject.AddComponent<MaterialProperties>();
        }
Ejemplo n.º 13
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVrectGrid(String [] argv)
    {
        //Prefix Content is: ""

        VTK_VARY_RADIUS_BY_VECTOR = 2;
        // create pipeline[]
        //[]
        reader = new vtkDataSetReader();
        reader.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/RectGrid2.vtk");
        reader.Update();
        toRectilinearGrid = new vtkCastToConcrete();
        toRectilinearGrid.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort());
        toRectilinearGrid.Update();
        plane = new vtkRectilinearGridGeometryFilter();
        plane.SetInputData((vtkDataObject)toRectilinearGrid.GetRectilinearGridOutput());
        plane.SetExtent((int)0, (int)100, (int)0, (int)100, (int)15, (int)15);
        warper = new vtkWarpVector();
        warper.SetInputConnection((vtkAlgorithmOutput)plane.GetOutputPort());
        warper.SetScaleFactor((double)0.05);
        planeMapper = new vtkDataSetMapper();
        planeMapper.SetInputConnection((vtkAlgorithmOutput)warper.GetOutputPort());
        planeMapper.SetScalarRange((double)0.197813, (double)0.710419);
        planeActor = new vtkActor();
        planeActor.SetMapper((vtkMapper)planeMapper);
        cutPlane = new vtkPlane();
        cutPlane.SetOrigin(reader.GetOutput().GetCenter()[0], reader.GetOutput().GetCenter()[1], reader.GetOutput().GetCenter()[2]);
        cutPlane.SetNormal((double)1, (double)0, (double)0);
        planeCut = new vtkCutter();
        planeCut.SetInputData((vtkDataObject)toRectilinearGrid.GetRectilinearGridOutput());
        planeCut.SetCutFunction((vtkImplicitFunction)cutPlane);
        cutMapper = new vtkDataSetMapper();
        cutMapper.SetInputConnection((vtkAlgorithmOutput)planeCut.GetOutputPort());
        cutMapper.SetScalarRange((double)((vtkDataSet)reader.GetOutput()).GetPointData().GetScalars().GetRange()[0], (double)((vtkDataSet)reader.GetOutput()).GetPointData().GetScalars().GetRange()[1]);
        cutActor = new vtkActor();
        cutActor.SetMapper((vtkMapper)cutMapper);
        iso = new vtkContourFilter();
        iso.SetInputData((vtkDataObject)toRectilinearGrid.GetRectilinearGridOutput());
        iso.SetValue((int)0, (double)0.7);
        normals = new vtkPolyDataNormals();
        normals.SetInputConnection((vtkAlgorithmOutput)iso.GetOutputPort());
        normals.SetFeatureAngle((double)45);
        isoMapper = vtkPolyDataMapper.New();
        isoMapper.SetInputConnection((vtkAlgorithmOutput)normals.GetOutputPort());
        isoMapper.ScalarVisibilityOff();
        isoActor = new vtkActor();
        isoActor.SetMapper((vtkMapper)isoMapper);
        isoActor.GetProperty().SetColor((double)1.0000, 0.8941, 0.7686);
        isoActor.GetProperty().SetRepresentationToWireframe();
        streamer = new vtkStreamLine();
        streamer.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort());
        streamer.SetStartPosition((double)-1.2, (double)-0.1, (double)1.3);
        streamer.SetMaximumPropagationTime((double)500);
        streamer.SetStepLength((double)0.05);
        streamer.SetIntegrationStepLength((double)0.05);
        streamer.SetIntegrationDirectionToIntegrateBothDirections();
        streamTube = new vtkTubeFilter();
        streamTube.SetInputConnection((vtkAlgorithmOutput)streamer.GetOutputPort());
        streamTube.SetRadius((double)0.025);
        streamTube.SetNumberOfSides((int)6);
        streamTube.SetVaryRadius((int)VTK_VARY_RADIUS_BY_VECTOR);
        mapStreamTube = vtkPolyDataMapper.New();
        mapStreamTube.SetInputConnection((vtkAlgorithmOutput)streamTube.GetOutputPort());
        mapStreamTube.SetScalarRange((double)((vtkDataSet)reader.GetOutput()).GetPointData().GetScalars().GetRange()[0], (double)((vtkDataSet)reader.GetOutput()).GetPointData().GetScalars().GetRange()[1]);
        streamTubeActor = new vtkActor();
        streamTubeActor.SetMapper((vtkMapper)mapStreamTube);
        streamTubeActor.GetProperty().BackfaceCullingOn();
        outline = new vtkOutlineFilter();
        outline.SetInputData((vtkDataObject)toRectilinearGrid.GetRectilinearGridOutput());
        outlineMapper = vtkPolyDataMapper.New();
        outlineMapper.SetInputConnection((vtkAlgorithmOutput)outline.GetOutputPort());
        outlineActor = new vtkActor();
        outlineActor.SetMapper((vtkMapper)outlineMapper);
        outlineActor.GetProperty().SetColor((double)0.0000, 0.0000, 0.0000);
        // Graphics stuff[]
        // 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);
        // Add the actors to the renderer, set the background and size[]
        //[]
        ren1.AddActor((vtkProp)outlineActor);
        ren1.AddActor((vtkProp)planeActor);
        ren1.AddActor((vtkProp)cutActor);
        ren1.AddActor((vtkProp)isoActor);
        ren1.AddActor((vtkProp)streamTubeActor);
        ren1.SetBackground((double)1, (double)1, (double)1);
        renWin.SetSize((int)400, (int)400);
        cam1 = ren1.GetActiveCamera();
        cam1.SetClippingRange((double)3.76213, (double)10.712);
        cam1.SetFocalPoint((double)-0.0842503, (double)-0.136905, (double)0.610234);
        cam1.SetPosition((double)2.53813, (double)2.2678, (double)-5.22172);
        cam1.SetViewUp((double)-0.241047, (double)0.930635, (double)0.275343);
        iren.Initialize();
        // render the image[]
        //[]
        // prevent the tk window from showing up then start the event loop[]

//deleteAllVTKObjects();
    }
Ejemplo n.º 14
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVfieldToRGrid(String [] argv)
    {
        //Prefix Content is: ""

        //# Generate a rectilinear grid from a field.[]
        //#[]
        // get the interactor ui[]
        // Create a reader and write out the field[]
        reader = new vtkDataSetReader();
        reader.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/RectGrid2.vtk");
        ds2do = new vtkDataSetToDataObjectFilter();
        ds2do.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort());
        try
        {
            channel       = new StreamWriter("RGridField.vtk");
            tryCatchError = "NOERROR";
        }
        catch (Exception)
        { tryCatchError = "ERROR"; }

        if (tryCatchError.Equals("NOERROR"))
        {
            channel.Close();
            writer = new vtkDataObjectWriter();
            writer.SetInputConnection((vtkAlgorithmOutput)ds2do.GetOutputPort());
            writer.SetFileName((string)"RGridField.vtk");
            writer.Write();
            // Read the field[]
            //[]
            dor = new vtkDataObjectReader();
            dor.SetFileName((string)"RGridField.vtk");
            do2ds = new vtkDataObjectToDataSetFilter();
            do2ds.SetInputConnection((vtkAlgorithmOutput)dor.GetOutputPort());
            do2ds.SetDataSetTypeToRectilinearGrid();
            do2ds.SetDimensionsComponent((string)"Dimensions", (int)0);
            do2ds.SetPointComponent((int)0, (string)"XCoordinates", (int)0);
            do2ds.SetPointComponent((int)1, (string)"YCoordinates", (int)0);
            do2ds.SetPointComponent((int)2, (string)"ZCoordinates", (int)0);
            do2ds.Update();

            fd2ad = new vtkFieldDataToAttributeDataFilter();
            fd2ad.SetInputData((vtkDataObject)do2ds.GetRectilinearGridOutput());
            fd2ad.SetInputFieldToDataObjectField();
            fd2ad.SetOutputAttributeDataToPointData();
            fd2ad.SetVectorComponent((int)0, (string)"vectors", (int)0);
            fd2ad.SetVectorComponent((int)1, (string)"vectors", (int)1);
            fd2ad.SetVectorComponent((int)2, (string)"vectors", (int)2);
            fd2ad.SetScalarComponent((int)0, (string)"scalars", (int)0);
            fd2ad.Update();

            // create pipeline[]
            //[]
            plane = new vtkRectilinearGridGeometryFilter();
            plane.SetInputData((vtkDataObject)fd2ad.GetRectilinearGridOutput());
            plane.SetExtent((int)0, (int)100, (int)0, (int)100, (int)15, (int)15);
            warper = new vtkWarpVector();
            warper.SetInputConnection((vtkAlgorithmOutput)plane.GetOutputPort());
            warper.SetScaleFactor((double)0.05);
            planeMapper = new vtkDataSetMapper();
            planeMapper.SetInputConnection((vtkAlgorithmOutput)warper.GetOutputPort());
            planeMapper.SetScalarRange((double)0.197813, (double)0.710419);
            planeActor = new vtkActor();
            planeActor.SetMapper((vtkMapper)planeMapper);
            cutPlane = new vtkPlane();
            cutPlane.SetOrigin(fd2ad.GetOutput().GetCenter()[0], fd2ad.GetOutput().GetCenter()[1], fd2ad.GetOutput().GetCenter()[2]);
            cutPlane.SetNormal((double)1, (double)0, (double)0);
            planeCut = new vtkCutter();
            planeCut.SetInputData((vtkDataObject)fd2ad.GetRectilinearGridOutput());
            planeCut.SetCutFunction((vtkImplicitFunction)cutPlane);
            cutMapper = new vtkDataSetMapper();
            cutMapper.SetInputConnection((vtkAlgorithmOutput)planeCut.GetOutputPort());

            cutMapper.SetScalarRange(
                (double)((vtkDataSet)fd2ad.GetOutput()).GetPointData().GetScalars().GetRange()[0],
                (double)((vtkDataSet)fd2ad.GetOutput()).GetPointData().GetScalars().GetRange()[1]);
            cutActor = new vtkActor();
            cutActor.SetMapper((vtkMapper)cutMapper);
            iso = new vtkContourFilter();
            iso.SetInputData((vtkDataObject)fd2ad.GetRectilinearGridOutput());

            iso.SetValue((int)0, (double)0.7);
            normals = new vtkPolyDataNormals();
            normals.SetInputConnection((vtkAlgorithmOutput)iso.GetOutputPort());
            normals.SetFeatureAngle((double)45);

            isoMapper = vtkPolyDataMapper.New();
            isoMapper.SetInputConnection((vtkAlgorithmOutput)normals.GetOutputPort());
            isoMapper.ScalarVisibilityOff();
            isoActor = new vtkActor();
            isoActor.SetMapper((vtkMapper)isoMapper);
            isoActor.GetProperty().SetColor((double)1.0000, 0.8941, 0.7686);
            isoActor.GetProperty().SetRepresentationToWireframe();
            streamer = new vtkStreamLine();
            streamer.SetInputConnection((vtkAlgorithmOutput)fd2ad.GetOutputPort());
            streamer.SetStartPosition((double)-1.2, (double)-0.1, (double)1.3);
            streamer.SetMaximumPropagationTime((double)500);
            streamer.SetStepLength((double)0.05);
            streamer.SetIntegrationStepLength((double)0.05);
            streamer.SetIntegrationDirectionToIntegrateBothDirections();
            streamTube = new vtkTubeFilter();
            streamTube.SetInputConnection((vtkAlgorithmOutput)streamer.GetOutputPort());
            streamTube.SetRadius((double)0.025);
            streamTube.SetNumberOfSides((int)6);
            streamTube.SetVaryRadiusToVaryRadiusByVector();
            mapStreamTube = vtkPolyDataMapper.New();
            mapStreamTube.SetInputConnection((vtkAlgorithmOutput)streamTube.GetOutputPort());
            mapStreamTube.SetScalarRange(
                (double)((vtkDataSet)fd2ad.GetOutput()).GetPointData().GetScalars().GetRange()[0],
                (double)((vtkDataSet)fd2ad.GetOutput()).GetPointData().GetScalars().GetRange()[1]);
            streamTubeActor = new vtkActor();
            streamTubeActor.SetMapper((vtkMapper)mapStreamTube);
            streamTubeActor.GetProperty().BackfaceCullingOn();
            outline = new vtkOutlineFilter();
            outline.SetInputData((vtkDataObject)fd2ad.GetRectilinearGridOutput());
            outlineMapper = vtkPolyDataMapper.New();
            outlineMapper.SetInputConnection((vtkAlgorithmOutput)outline.GetOutputPort());
            outlineActor = new vtkActor();
            outlineActor.SetMapper((vtkMapper)outlineMapper);
            outlineActor.GetProperty().SetColor((double)0.0000, 0.0000, 0.0000);



            // Graphics stuff[]
            // 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);
            // Add the actors to the renderer, set the background and size[]
            //[]
            ren1.AddActor((vtkProp)outlineActor);
            ren1.AddActor((vtkProp)planeActor);
            ren1.AddActor((vtkProp)cutActor);
            ren1.AddActor((vtkProp)isoActor);
            ren1.AddActor((vtkProp)streamTubeActor);
            ren1.SetBackground((double)1, (double)1, (double)1);
            renWin.SetSize((int)300, (int)300);
            ren1.GetActiveCamera().SetPosition((double)0.0390893, (double)0.184813, (double)-3.94026);
            ren1.GetActiveCamera().SetFocalPoint((double)-0.00578326, (double)0, (double)0.701967);
            ren1.GetActiveCamera().SetViewAngle((double)30);
            ren1.GetActiveCamera().SetViewUp((double)0.00850257, (double)0.999169, (double)0.0398605);
            ren1.GetActiveCamera().SetClippingRange((double)3.08127, (double)6.62716);
            iren.Initialize();
            // render the image[]
            //[]

            File.Delete("RGridField.vtk");
        }


        // prevent the tk window from showing up then start the event loop[]

//deleteAllVTKObjects();
    }
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVEnSightRectGridASCII(String [] argv)
    {
        //Prefix Content is: ""

          VTK_VARY_RADIUS_BY_VECTOR = 2;
          // create pipeline[]
          //[]
          reader = new vtkGenericEnSightReader();
          // Make sure all algorithms use the composite data pipeline[]
          cdp = new vtkCompositeDataPipeline();
          vtkGenericEnSightReader.SetDefaultExecutivePrototype((vtkExecutive)cdp);
          reader.SetCaseFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/EnSight/RectGrid_ascii.case");
          reader.Update();
          toRectilinearGrid = new vtkCastToConcrete();
          //    toRectilinearGrid SetInputConnection [reader GetOutputPort] []
          toRectilinearGrid.SetInput((vtkDataObject)reader.GetOutput().GetBlock((uint)0));
          plane = new vtkRectilinearGridGeometryFilter();
          plane.SetInput((vtkDataObject)toRectilinearGrid.GetRectilinearGridOutput());
          plane.SetExtent((int)0,(int)100,(int)0,(int)100,(int)15,(int)15);
          tri = new vtkTriangleFilter();
          tri.SetInputConnection((vtkAlgorithmOutput)plane.GetOutputPort());
          warper = new vtkWarpVector();
          warper.SetInputConnection((vtkAlgorithmOutput)tri.GetOutputPort());
          warper.SetScaleFactor((double)0.05);
          planeMapper = new vtkDataSetMapper();
          planeMapper.SetInputConnection((vtkAlgorithmOutput)warper.GetOutputPort());
          planeMapper.SetScalarRange((double)0.197813,(double)0.710419);
          planeActor = new vtkActor();
          planeActor.SetMapper((vtkMapper)planeMapper);
          cutPlane = new vtkPlane();
          //    eval cutPlane SetOrigin [[reader GetOutput] GetCenter][]
          cutPlane.SetOrigin((double)((vtkDataSet)reader.GetOutput().GetBlock((uint)0)).GetCenter()[0], (double)((vtkDataSet)reader.GetOutput().GetBlock((uint)0)).GetCenter()[1], (double)((vtkDataSet)reader.GetOutput().GetBlock((uint)0)).GetCenter()[2]);
          cutPlane.SetNormal((double)1,(double)0,(double)0);
          planeCut = new vtkCutter();
          planeCut.SetInput((vtkDataObject)toRectilinearGrid.GetRectilinearGridOutput());
          planeCut.SetCutFunction((vtkImplicitFunction)cutPlane);
          cutMapper = new vtkDataSetMapper();
          cutMapper.SetInputConnection((vtkAlgorithmOutput)planeCut.GetOutputPort());
          cutMapper.SetScalarRange((double)((vtkDataSet)((vtkMultiBlockDataSet)reader.GetOutput()).GetBlock((uint)0)).GetPointData().GetScalars().GetRange()[0], (double)((vtkDataSet)((vtkMultiBlockDataSet)reader.GetOutput()).GetBlock((uint)0)).GetPointData().GetScalars().GetRange()[1]);
          cutActor = new vtkActor();
          cutActor.SetMapper((vtkMapper)cutMapper);
          iso = new vtkContourFilter();
          iso.SetInput((vtkDataObject)toRectilinearGrid.GetRectilinearGridOutput());
          iso.SetValue((int)0,(double)0.7);
          normals = new vtkPolyDataNormals();
          normals.SetInputConnection((vtkAlgorithmOutput)iso.GetOutputPort());
          normals.SetFeatureAngle((double)45);
          isoMapper = vtkPolyDataMapper.New();
          isoMapper.SetInputConnection((vtkAlgorithmOutput)normals.GetOutputPort());
          isoMapper.ScalarVisibilityOff();
          isoActor = new vtkActor();
          isoActor.SetMapper((vtkMapper)isoMapper);
          isoActor.GetProperty().SetColor((double) 1.0000, 0.8941, 0.7686 );
          isoActor.GetProperty().SetRepresentationToWireframe();
          streamer = new vtkStreamLine();
          //    streamer SetInputConnection [reader GetOutputPort][]
          streamer.SetInput((vtkDataObject)reader.GetOutput().GetBlock((uint)0));
          streamer.SetStartPosition((double)-1.2,(double)-0.1,(double)1.3);
          streamer.SetMaximumPropagationTime((double)500);
          streamer.SetStepLength((double)0.05);
          streamer.SetIntegrationStepLength((double)0.05);
          streamer.SetIntegrationDirectionToIntegrateBothDirections();
          streamTube = new vtkTubeFilter();
          streamTube.SetInputConnection((vtkAlgorithmOutput)streamer.GetOutputPort());
          streamTube.SetRadius((double)0.025);
          streamTube.SetNumberOfSides((int)6);
          streamTube.SetVaryRadius((int)VTK_VARY_RADIUS_BY_VECTOR);
          mapStreamTube = vtkPolyDataMapper.New();
          mapStreamTube.SetInputConnection((vtkAlgorithmOutput)streamTube.GetOutputPort());
          mapStreamTube.SetScalarRange((double)((vtkDataSet)reader.GetOutput().GetBlock((uint)0)).GetPointData().GetScalars().GetRange()[0], (double)((vtkDataSet)reader.GetOutput().GetBlock((uint)0)).GetPointData().GetScalars().GetRange()[1]);
          //       [[[[reader GetOutput] GetPointData] GetScalars] GetRange][]
          streamTubeActor = new vtkActor();
          streamTubeActor.SetMapper((vtkMapper)mapStreamTube);
          streamTubeActor.GetProperty().BackfaceCullingOn();
          outline = new vtkOutlineFilter();
          outline.SetInput((vtkDataObject)toRectilinearGrid.GetRectilinearGridOutput());
          outlineMapper = vtkPolyDataMapper.New();
          outlineMapper.SetInputConnection((vtkAlgorithmOutput)outline.GetOutputPort());
          outlineActor = new vtkActor();
          outlineActor.SetMapper((vtkMapper)outlineMapper);
          outlineActor.GetProperty().SetColor((double) 0.0000, 0.0000, 0.0000 );
          // Graphics stuff[]
          // Create the RenderWindow, Renderer and both Actors[]
          //[]
          ren1 = vtkRenderer.New();
          renWin = vtkRenderWindow.New();
          renWin.AddRenderer((vtkRenderer)ren1);
          iren = new vtkRenderWindowInteractor();
          iren.SetRenderWindow((vtkRenderWindow)renWin);
          // Add the actors to the renderer, set the background and size[]
          //[]
          ren1.AddActor((vtkProp)outlineActor);
          ren1.AddActor((vtkProp)planeActor);
          ren1.AddActor((vtkProp)cutActor);
          ren1.AddActor((vtkProp)isoActor);
          ren1.AddActor((vtkProp)streamTubeActor);
          ren1.SetBackground((double)1,(double)1,(double)1);
          renWin.SetSize((int)400,(int)400);
          cam1 = ren1.GetActiveCamera();
          cam1.SetClippingRange((double)3.76213,(double)10.712);
          cam1.SetFocalPoint((double)-0.0842503,(double)-0.136905,(double)0.610234);
          cam1.SetPosition((double)2.53813,(double)2.2678,(double)-5.22172);
          cam1.SetViewUp((double)-0.241047,(double)0.930635,(double)0.275343);
          iren.Initialize();
          // render the image[]
          //[]
          // prevent the tk window from showing up then start the event loop[]
          vtkGenericEnSightReader.SetDefaultExecutivePrototype(null);

        //deleteAllVTKObjects();
    }
Ejemplo n.º 16
0
        int build3DViewFull()
        {
            Kitware.VTK.RenderWindowControl rw = new Kitware.VTK.RenderWindowControl();

            vtkRenderWindow _renwin = rw.RenderWindow;
            vtkRenderer     _render = _renwin.GetRenderers().GetFirstRenderer();

            _renwin.AddRenderer(_render);

            vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor();

            iren.SetRenderWindow(_renwin);

            // 新建文件读取对象,常见的有vtkBMPReader、vtkDICOMImageReader、vtkJPEGReader等
            vtkJPEGReader jpegReader = new vtkJPEGReader();

            // 不同的reader需要设置的参数是不同的 因此本例仅适合jpegreader
            jpegReader.SetFilePrefix("C:/Users/DawnWind/Desktop/000/"); // 要打开的路径
            jpegReader.SetFilePattern("%s%d.jpg");                      // 图片文件名格式,此处为 0.jpg 1.jpg ...
            jpegReader.SetDataByteOrderToLittleEndian();
            jpegReader.SetDataSpacing(1, 1, 1.4);                       // 设置图片中像素比,我理解得不清楚,具体请百度之
            jpegReader.SetFileNameSliceSpacing(1);

            jpegReader.SetDataExtent(0, 209, 0, 209, 0, 29);
            // 这里因为在000文件夹里面有0.jpg ~ 29.jpg,所以设置为 0,29
            // 每张图片的长宽为210 * 210 因此设置为0,209

            jpegReader.Update();
            // update这里要注意一下,对于VTK在默认情况下是在最后操作时候才一次性刷新
            // 也就是说如果没有自动刷新的话,在一些中间过程中是无法获得到数据的,因为没update进去

            vtkContourFilter skinExtractor = new vtkContourFilter();

            skinExtractor.SetInputConnection(jpegReader.GetOutputPort());
            skinExtractor.SetValue(200, 100);    //值越大,保留的部分越少。

            //重新计算法向量
            vtkPolyDataNormals skinNormals = new vtkPolyDataNormals();

            skinNormals.SetInputConnection(skinExtractor.GetOutputPort());
            skinNormals.SetFeatureAngle(60.0);
            //Specify the angle that defines a sharp edge.
            //If the difference in angle across neighboring polygons is greater than this value,
            //the shared edge is considered "sharp".


            //create triangle strips and/or poly-lines 为了更快的显示速度
            vtkStripper skinStripper = new vtkStripper();

            skinStripper.SetInputConnection(skinNormals.GetOutputPort());

            vtkPolyDataMapper skinMapper = new vtkPainterPolyDataMapper();

            skinMapper.SetInputConnection(skinStripper.GetOutputPort());
            skinMapper.ScalarVisibilityOff();    //这样不会带颜色



            vtkActor skin = new vtkActor();

            skin.SetMapper(skinMapper);

            // An outline provides context around the data.
            // 一个围绕在物体的立体框,可以先忽略

            /*
             * vtkOutlineFilter> outlineData =
             *  vtkOutlineFilter>::New();
             * outlineData.SetInputConnection(dicomReader.GetOutputPort());
             *
             * vtkPolyDataMapper> mapOutline =
             *  vtkPolyDataMapper>::New();
             * mapOutline.SetInputConnection(outlineData.GetOutputPort());
             *
             * vtkActor> outline =
             *  vtkActor>::New();
             * outline.SetMapper(mapOutline);
             * outline.GetProperty().SetColor(0,0,0);
             *
             * aRenderer.AddActor(outline);
             */
            // It is convenient to create an initial view of the data. The FocalPoint
            // and Position form a vector direction. Later on (ResetCamera() method)
            // this vector is used to position the camera to look at the data in
            // this direction.
            vtkCamera aCamera = new vtkCamera();

            aCamera.SetViewUp(0, 0, -1);
            aCamera.SetPosition(0, 1, 0);
            aCamera.SetFocalPoint(0, 0, 0);
            aCamera.ComputeViewPlaneNormal();
            aCamera.Azimuth(30.0);
            aCamera.Elevation(30.0);

            // Actors are added to the renderer. An initial camera view is created.
            // The Dolly() method moves the camera towards the FocalPoint,
            // thereby enlarging the image.
            _render.AddActor(skin);
            _render.SetActiveCamera(aCamera);
            _render.ResetCamera();
            aCamera.Dolly(1.5);

            // Set a background color for the renderer and set the size of the
            // render window (expressed in pixels).
            _render.SetBackground(.2, .3, .4);
            _renwin.SetSize(640, 480);

            // Note that when camera movement occurs (as it does in the Dolly()
            // method), the clipping planes often need adjusting. Clipping planes
            // consist of two planes: near and far along the view direction. The
            // near plane clips out objects in front of the plane; the far plane
            // clips out objects behind the plane. This way only what is drawn
            // between the planes is actually rendered.
            _render.ResetCameraClippingRange();

            // Initialize the event loop and then start it.
            iren.Initialize();
            iren.Start();
            return(0);
        }
Ejemplo n.º 17
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVfieldToRGrid(String [] argv)
    {
        //Prefix Content is: ""

          //# Generate a rectilinear grid from a field.[]
          //#[]
          // get the interactor ui[]
          // Create a reader and write out the field[]
          reader = new vtkDataSetReader();
          reader.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/RectGrid2.vtk");
          ds2do = new vtkDataSetToDataObjectFilter();
          ds2do.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort());
          try
          {
         channel = new StreamWriter("RGridField.vtk");
          tryCatchError = "NOERROR";
          }
          catch(Exception)
          {tryCatchError = "ERROR";}

        if(tryCatchError.Equals("NOERROR"))
          {
          channel.Close();
          writer = new vtkDataObjectWriter();
          writer.SetInputConnection((vtkAlgorithmOutput)ds2do.GetOutputPort());
          writer.SetFileName((string)"RGridField.vtk");
          writer.Write();
          // Read the field[]
          //[]
          dor = new vtkDataObjectReader();
          dor.SetFileName((string)"RGridField.vtk");
          do2ds = new vtkDataObjectToDataSetFilter();
          do2ds.SetInputConnection((vtkAlgorithmOutput)dor.GetOutputPort());
          do2ds.SetDataSetTypeToRectilinearGrid();
          do2ds.SetDimensionsComponent((string)"Dimensions",(int)0);
          do2ds.SetPointComponent((int)0,(string)"XCoordinates",(int)0);
          do2ds.SetPointComponent((int)1,(string)"YCoordinates",(int)0);
          do2ds.SetPointComponent((int)2,(string)"ZCoordinates",(int)0);
          fd2ad = new vtkFieldDataToAttributeDataFilter();
          fd2ad.SetInput((vtkDataObject)do2ds.GetRectilinearGridOutput());
          fd2ad.SetInputFieldToDataObjectField();
          fd2ad.SetOutputAttributeDataToPointData();
          fd2ad.SetVectorComponent((int)0,(string)"vectors",(int)0);
          fd2ad.SetVectorComponent((int)1,(string)"vectors",(int)1);
          fd2ad.SetVectorComponent((int)2,(string)"vectors",(int)2);
          fd2ad.SetScalarComponent((int)0,(string)"scalars",(int)0);
          fd2ad.Update();
          // create pipeline[]
          //[]
          plane = new vtkRectilinearGridGeometryFilter();
          plane.SetInput((vtkDataObject)fd2ad.GetRectilinearGridOutput());
          plane.SetExtent((int)0,(int)100,(int)0,(int)100,(int)15,(int)15);
          warper = new vtkWarpVector();
          warper.SetInputConnection((vtkAlgorithmOutput)plane.GetOutputPort());
          warper.SetScaleFactor((double)0.05);
          planeMapper = new vtkDataSetMapper();
          planeMapper.SetInputConnection((vtkAlgorithmOutput)warper.GetOutputPort());
          planeMapper.SetScalarRange((double)0.197813,(double)0.710419);
          planeActor = new vtkActor();
          planeActor.SetMapper((vtkMapper)planeMapper);
          cutPlane = new vtkPlane();
          cutPlane.SetOrigin(fd2ad.GetOutput().GetCenter()[0],fd2ad.GetOutput().GetCenter()[1],fd2ad.GetOutput().GetCenter()[2]);
          cutPlane.SetNormal((double)1,(double)0,(double)0);
          planeCut = new vtkCutter();
          planeCut.SetInput((vtkDataObject)fd2ad.GetRectilinearGridOutput());
          planeCut.SetCutFunction((vtkImplicitFunction)cutPlane);
          cutMapper = new vtkDataSetMapper();
          cutMapper.SetInputConnection((vtkAlgorithmOutput)planeCut.GetOutputPort());
          cutMapper.SetScalarRange(
          (double)((vtkDataSet)fd2ad.GetOutput()).GetPointData().GetScalars().GetRange()[0],
          (double)((vtkDataSet)fd2ad.GetOutput()).GetPointData().GetScalars().GetRange()[1]);
          cutActor = new vtkActor();
          cutActor.SetMapper((vtkMapper)cutMapper);
          iso = new vtkContourFilter();
          iso.SetInput((vtkDataObject)fd2ad.GetRectilinearGridOutput());
          iso.SetValue((int)0,(double)0.7);
          normals = new vtkPolyDataNormals();
          normals.SetInputConnection((vtkAlgorithmOutput)iso.GetOutputPort());
          normals.SetFeatureAngle((double)45);
          isoMapper = vtkPolyDataMapper.New();
          isoMapper.SetInputConnection((vtkAlgorithmOutput)normals.GetOutputPort());
          isoMapper.ScalarVisibilityOff();
          isoActor = new vtkActor();
          isoActor.SetMapper((vtkMapper)isoMapper);
          isoActor.GetProperty().SetColor((double) 1.0000, 0.8941, 0.7686 );
          isoActor.GetProperty().SetRepresentationToWireframe();
          streamer = new vtkStreamLine();
          streamer.SetInputConnection((vtkAlgorithmOutput)fd2ad.GetOutputPort());
          streamer.SetStartPosition((double)-1.2,(double)-0.1,(double)1.3);
          streamer.SetMaximumPropagationTime((double)500);
          streamer.SetStepLength((double)0.05);
          streamer.SetIntegrationStepLength((double)0.05);
          streamer.SetIntegrationDirectionToIntegrateBothDirections();
          streamTube = new vtkTubeFilter();
          streamTube.SetInputConnection((vtkAlgorithmOutput)streamer.GetOutputPort());
          streamTube.SetRadius((double)0.025);
          streamTube.SetNumberOfSides((int)6);
          streamTube.SetVaryRadiusToVaryRadiusByVector();
          mapStreamTube = vtkPolyDataMapper.New();
          mapStreamTube.SetInputConnection((vtkAlgorithmOutput)streamTube.GetOutputPort());
          mapStreamTube.SetScalarRange(
          (double)((vtkDataSet)fd2ad.GetOutput()).GetPointData().GetScalars().GetRange()[0],
          (double)((vtkDataSet)fd2ad.GetOutput()).GetPointData().GetScalars().GetRange()[1]);
          streamTubeActor = new vtkActor();
          streamTubeActor.SetMapper((vtkMapper)mapStreamTube);
          streamTubeActor.GetProperty().BackfaceCullingOn();
          outline = new vtkOutlineFilter();
          outline.SetInput((vtkDataObject)fd2ad.GetRectilinearGridOutput());
          outlineMapper = vtkPolyDataMapper.New();
          outlineMapper.SetInputConnection((vtkAlgorithmOutput)outline.GetOutputPort());
          outlineActor = new vtkActor();
          outlineActor.SetMapper((vtkMapper)outlineMapper);
          outlineActor.GetProperty().SetColor((double) 0.0000, 0.0000, 0.0000 );
          // Graphics stuff[]
          // Create the RenderWindow, Renderer and both Actors[]
          //[]
          ren1 = vtkRenderer.New();
          renWin = vtkRenderWindow.New();
          renWin.AddRenderer((vtkRenderer)ren1);
          iren = new vtkRenderWindowInteractor();
          iren.SetRenderWindow((vtkRenderWindow)renWin);
          // Add the actors to the renderer, set the background and size[]
          //[]
          ren1.AddActor((vtkProp)outlineActor);
          ren1.AddActor((vtkProp)planeActor);
          ren1.AddActor((vtkProp)cutActor);
          ren1.AddActor((vtkProp)isoActor);
          ren1.AddActor((vtkProp)streamTubeActor);
          ren1.SetBackground((double)1,(double)1,(double)1);
          renWin.SetSize((int)300,(int)300);
          ren1.GetActiveCamera().SetPosition((double)0.0390893,(double)0.184813,(double)-3.94026);
          ren1.GetActiveCamera().SetFocalPoint((double)-0.00578326,(double)0,(double)0.701967);
          ren1.GetActiveCamera().SetViewAngle((double)30);
          ren1.GetActiveCamera().SetViewUp((double)0.00850257,(double)0.999169,(double)0.0398605);
          ren1.GetActiveCamera().SetClippingRange((double)3.08127,(double)6.62716);
          iren.Initialize();
          // render the image[]
          //[]

          File.Delete("RGridField.vtk");

        }

          // prevent the tk window from showing up then start the event loop[]

        //deleteAllVTKObjects();
    }
Ejemplo n.º 18
0
 ///<summary> A Set Method for Static Variables </summary>
 public static void SetellipNormals(vtkPolyDataNormals toSet)
 {
     ellipNormals = toSet;
 }
Ejemplo n.º 19
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVfieldToUGrid(String [] argv)
    {
        //Prefix Content is: ""

        // Read a field representing unstructured grid and display it (similar to blow.tcl)[]
        // create a reader and write out field daya[]
        reader = new vtkUnstructuredGridReader();
        reader.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/blow.vtk");
        reader.SetScalarsName((string)"thickness9");
        reader.SetVectorsName((string)"displacement9");
        ds2do = new vtkDataSetToDataObjectFilter();
        ds2do.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort());
        // we must be able to write here[]
        try
        {
            channel       = new StreamWriter("UGridField.vtk");
            tryCatchError = "NOERROR";
        }
        catch (Exception)
        { tryCatchError = "ERROR"; }

        if (tryCatchError.Equals("NOERROR"))
        {
            channel.Close();
            write = new vtkDataObjectWriter();
            write.SetInputConnection((vtkAlgorithmOutput)ds2do.GetOutputPort());
            write.SetFileName((string)"UGridField.vtk");
            write.Write();
            // Read the field and convert to unstructured grid.[]
            dor = new vtkDataObjectReader();
            dor.SetFileName((string)"UGridField.vtk");
            do2ds = new vtkDataObjectToDataSetFilter();
            do2ds.SetInputConnection((vtkAlgorithmOutput)dor.GetOutputPort());
            do2ds.SetDataSetTypeToUnstructuredGrid();
            do2ds.SetPointComponent((int)0, (string)"Points", (int)0);
            do2ds.SetPointComponent((int)1, (string)"Points", (int)1);
            do2ds.SetPointComponent((int)2, (string)"Points", (int)2);
            do2ds.SetCellTypeComponent((string)"CellTypes", (int)0);
            do2ds.SetCellConnectivityComponent((string)"Cells", (int)0);
            do2ds.Update();

            fd2ad = new vtkFieldDataToAttributeDataFilter();
            fd2ad.SetInputData((vtkDataObject)do2ds.GetUnstructuredGridOutput());
            fd2ad.SetInputFieldToDataObjectField();
            fd2ad.SetOutputAttributeDataToPointData();
            fd2ad.SetVectorComponent((int)0, (string)"displacement9", (int)0);
            fd2ad.SetVectorComponent((int)1, (string)"displacement9", (int)1);
            fd2ad.SetVectorComponent((int)2, (string)"displacement9", (int)2);
            fd2ad.SetScalarComponent((int)0, (string)"thickness9", (int)0);
            fd2ad.Update();

            // Now start visualizing[]
            warp = new vtkWarpVector();
            warp.SetInputData((vtkDataObject)fd2ad.GetUnstructuredGridOutput());
            // extract mold from mesh using connectivity[]
            connect = new vtkConnectivityFilter();
            connect.SetInputConnection((vtkAlgorithmOutput)warp.GetOutputPort());
            connect.SetExtractionModeToSpecifiedRegions();
            connect.AddSpecifiedRegion((int)0);
            connect.AddSpecifiedRegion((int)1);
            moldMapper = new vtkDataSetMapper();
            moldMapper.SetInputConnection((vtkAlgorithmOutput)connect.GetOutputPort());
            moldMapper.ScalarVisibilityOff();
            moldActor = new vtkActor();
            moldActor.SetMapper((vtkMapper)moldMapper);
            moldActor.GetProperty().SetColor((double).2, (double).2, (double).2);
            moldActor.GetProperty().SetRepresentationToWireframe();
            // extract parison from mesh using connectivity[]
            connect2 = new vtkConnectivityFilter();
            connect2.SetInputConnection((vtkAlgorithmOutput)warp.GetOutputPort());
            connect2.SetExtractionModeToSpecifiedRegions();
            connect2.AddSpecifiedRegion((int)2);
            parison = new vtkGeometryFilter();
            parison.SetInputConnection((vtkAlgorithmOutput)connect2.GetOutputPort());
            normals2 = new vtkPolyDataNormals();
            normals2.SetInputConnection((vtkAlgorithmOutput)parison.GetOutputPort());
            normals2.SetFeatureAngle((double)60);
            lut = new vtkLookupTable();
            lut.SetHueRange((double)0.0, (double)0.66667);
            parisonMapper = vtkPolyDataMapper.New();
            parisonMapper.SetInputConnection((vtkAlgorithmOutput)normals2.GetOutputPort());
            parisonMapper.SetLookupTable((vtkScalarsToColors)lut);
            parisonMapper.SetScalarRange((double)0.12, (double)1.0);
            parisonActor = new vtkActor();
            parisonActor.SetMapper((vtkMapper)parisonMapper);
            cf = new vtkContourFilter();
            cf.SetInputConnection((vtkAlgorithmOutput)connect2.GetOutputPort());
            cf.SetValue((int)0, (double).5);
            contourMapper = vtkPolyDataMapper.New();
            contourMapper.SetInputConnection((vtkAlgorithmOutput)cf.GetOutputPort());
            contours = new vtkActor();
            contours.SetMapper((vtkMapper)contourMapper);
            // Create graphics stuff[]
            ren1   = vtkRenderer.New();
            renWin = vtkRenderWindow.New();
            renWin.AddRenderer((vtkRenderer)ren1);
            iren = new vtkRenderWindowInteractor();
            iren.SetRenderWindow((vtkRenderWindow)renWin);
            // Add the actors to the renderer, set the background and size[]
            ren1.AddActor((vtkProp)moldActor);
            ren1.AddActor((vtkProp)parisonActor);
            ren1.AddActor((vtkProp)contours);
            ren1.ResetCamera();
            ren1.GetActiveCamera().Azimuth((double)60);
            ren1.GetActiveCamera().Roll((double)-90);
            ren1.GetActiveCamera().Dolly((double)2);
            ren1.ResetCameraClippingRange();
            ren1.SetBackground((double)1, (double)1, (double)1);
            renWin.SetSize((int)375, (int)200);
            iren.Initialize();
        }


        // prevent the tk window from showing up then start the event loop[]

//deleteAllVTKObjects();
    }
 ///<summary> A Set Method for Static Variables </summary>
 public static void Setpdn(vtkPolyDataNormals toSet)
 {
     pdn = toSet;
 }
Ejemplo n.º 21
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVTestPolyDataPieces(String [] argv)
    {
        //Prefix Content is: ""

          math = new vtkMath();
          vtkMath.RandomSeed((int)22);
          pf = new vtkParallelFactory();
          vtkParallelFactory.RegisterFactory((vtkObjectFactory)pf);
          sphere = new vtkSphereSource();
          sphere.SetPhiResolution((int)32);
          sphere.SetThetaResolution((int)32);
          extract = new vtkExtractPolyDataPiece();
          extract.SetInputConnection((vtkAlgorithmOutput)sphere.GetOutputPort());
          normals = new vtkPolyDataNormals();
          normals.SetInputConnection((vtkAlgorithmOutput)extract.GetOutputPort());
          ps = new vtkPieceScalars();
          ps.SetInputConnection((vtkAlgorithmOutput)normals.GetOutputPort());
          mapper = vtkPolyDataMapper.New();
          mapper.SetInputConnection((vtkAlgorithmOutput)ps.GetOutputPort());
          mapper.SetNumberOfPieces((int)2);
          actor = new vtkActor();
          actor.SetMapper((vtkMapper)mapper);
          sphere2 = new vtkSphereSource();
          sphere2.SetPhiResolution((int)32);
          sphere2.SetThetaResolution((int)32);
          extract2 = new vtkExtractPolyDataPiece();
          extract2.SetInputConnection((vtkAlgorithmOutput)sphere2.GetOutputPort());
          mapper2 = vtkPolyDataMapper.New();
          mapper2.SetInputConnection((vtkAlgorithmOutput)extract2.GetOutputPort());
          mapper2.SetNumberOfPieces((int)2);
          mapper2.SetPiece((int)1);
          mapper2.SetScalarRange((double)0,(double)4);
          mapper2.SetScalarModeToUseCellFieldData();
          mapper2.SetColorModeToMapScalars();
          mapper2.ColorByArrayComponent((string)"vtkGhostLevels",(int)0);
          mapper2.SetGhostLevel((int)4);
          // check the pipeline size[]
          extract2.UpdateInformation();
          psize = new vtkPipelineSize();
          if ((psize.GetEstimatedSize((vtkAlgorithm)extract2,(int)0,(int)0)) > 100)
        {
          //puts skipedputs ['stderr', '"ERROR: Pipeline Size increased"']
        }

          if ((psize.GetNumberOfSubPieces((uint)10,(vtkPolyDataMapper)mapper2)) != 2)
        {
          //puts skipedputs ['stderr', '"ERROR: Number of sub pieces changed"']
        }

          actor2 = new vtkActor();
          actor2.SetMapper((vtkMapper)mapper2);
          actor2.SetPosition((double)1.5,(double)0,(double)0);
          sphere3 = new vtkSphereSource();
          sphere3.SetPhiResolution((int)32);
          sphere3.SetThetaResolution((int)32);
          extract3 = new vtkExtractPolyDataPiece();
          extract3.SetInputConnection((vtkAlgorithmOutput)sphere3.GetOutputPort());
          ps3 = new vtkPieceScalars();
          ps3.SetInputConnection((vtkAlgorithmOutput)extract3.GetOutputPort());
          mapper3 = vtkPolyDataMapper.New();
          mapper3.SetInputConnection((vtkAlgorithmOutput)ps3.GetOutputPort());
          mapper3.SetNumberOfSubPieces((int)8);
          mapper3.SetScalarRange((double)0,(double)8);
          actor3 = new vtkActor();
          actor3.SetMapper((vtkMapper)mapper3);
          actor3.SetPosition((double)0,(double)-1.5,(double)0);
          sphere4 = new vtkSphereSource();
          sphere4.SetPhiResolution((int)32);
          sphere4.SetThetaResolution((int)32);
          extract4 = new vtkExtractPolyDataPiece();
          extract4.SetInputConnection((vtkAlgorithmOutput)sphere4.GetOutputPort());
          ps4 = new vtkPieceScalars();
          ps4.RandomModeOn();
          ps4.SetScalarModeToCellData();
          ps4.SetInputConnection((vtkAlgorithmOutput)extract4.GetOutputPort());
          mapper4 = vtkPolyDataMapper.New();
          mapper4.SetInputConnection((vtkAlgorithmOutput)ps4.GetOutputPort());
          mapper4.SetNumberOfSubPieces((int)8);
          mapper4.SetScalarRange((double)0,(double)8);
          actor4 = new vtkActor();
          actor4.SetMapper((vtkMapper)mapper4);
          actor4.SetPosition((double)1.5,(double)-1.5,(double)0);
          ren = vtkRenderer.New();
          ren.AddActor((vtkProp)actor);
          ren.AddActor((vtkProp)actor2);
          ren.AddActor((vtkProp)actor3);
          ren.AddActor((vtkProp)actor4);
          renWin = vtkRenderWindow.New();
          renWin.AddRenderer((vtkRenderer)ren);
          iren = new vtkRenderWindowInteractor();
          iren.SetRenderWindow((vtkRenderWindow)renWin);
          iren.Initialize();

        //deleteAllVTKObjects();
    }
Ejemplo n.º 22
0
 ///<summary> A Set Method for Static Variables </summary>
 public static void Setnormals2(vtkPolyDataNormals toSet)
 {
     normals2 = toSet;
 }
Ejemplo n.º 23
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVTenEllip(String [] argv)
    {
        //Prefix Content is: ""

        // create tensor ellipsoids[]
        // Create the RenderWindow, Renderer and interactive renderer[]
        //[]
        ren1   = vtkRenderer.New();
        renWin = vtkRenderWindow.New();
        renWin.SetMultiSamples(0);
        renWin.AddRenderer((vtkRenderer)ren1);
        iren = new vtkRenderWindowInteractor();
        iren.SetRenderWindow((vtkRenderWindow)renWin);
        //[]
        // Create tensor ellipsoids[]
        //[]
        // generate tensors[]
        ptLoad = new vtkPointLoad();
        ptLoad.SetLoadValue((double)100.0);
        ptLoad.SetSampleDimensions((int)6, (int)6, (int)6);
        ptLoad.ComputeEffectiveStressOn();
        ptLoad.SetModelBounds((double)-10, (double)10, (double)-10, (double)10, (double)-10, (double)10);
        // extract plane of data[]
        plane = new vtkImageDataGeometryFilter();
        plane.SetInputConnection((vtkAlgorithmOutput)ptLoad.GetOutputPort());
        plane.SetExtent((int)2, (int)2, (int)0, (int)99, (int)0, (int)99);
        // Generate ellipsoids[]
        sphere = new vtkSphereSource();
        sphere.SetThetaResolution((int)8);
        sphere.SetPhiResolution((int)8);
        ellipsoids = new vtkTensorGlyph();
        ellipsoids.SetInputConnection((vtkAlgorithmOutput)ptLoad.GetOutputPort());
        ellipsoids.SetSourceConnection((vtkAlgorithmOutput)sphere.GetOutputPort());
        ellipsoids.SetScaleFactor((double)10);
        ellipsoids.ClampScalingOn();
        ellipNormals = new vtkPolyDataNormals();
        ellipNormals.SetInputConnection((vtkAlgorithmOutput)ellipsoids.GetOutputPort());
        // Map contour[]
        lut = new vtkLogLookupTable();
        lut.SetHueRange((double).6667, (double)0.0);
        ellipMapper = vtkPolyDataMapper.New();
        ellipMapper.SetInputConnection((vtkAlgorithmOutput)ellipNormals.GetOutputPort());
        ellipMapper.SetLookupTable((vtkScalarsToColors)lut);
        plane.Update();
        //force update for scalar range[]
        ellipMapper.SetScalarRange((double)((vtkDataSet)plane.GetOutput()).GetScalarRange()[0], (double)((vtkDataSet)plane.GetOutput()).GetScalarRange()[1]);
        ellipActor = new vtkActor();
        ellipActor.SetMapper((vtkMapper)ellipMapper);
        //[]
        // Create outline around data[]
        //[]
        outline = new vtkOutlineFilter();
        outline.SetInputConnection((vtkAlgorithmOutput)ptLoad.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);
        //[]
        // Create cone indicating application of load[]
        //[]
        coneSrc = new vtkConeSource();
        coneSrc.SetRadius((double).5);
        coneSrc.SetHeight((double)2);
        coneMap = vtkPolyDataMapper.New();
        coneMap.SetInputConnection((vtkAlgorithmOutput)coneSrc.GetOutputPort());
        coneActor = new vtkActor();
        coneActor.SetMapper((vtkMapper)coneMap);
        coneActor.SetPosition((double)0, (double)0, (double)11);
        coneActor.RotateY((double)90);
        coneActor.GetProperty().SetColor((double)1, (double)0, (double)0);
        camera = new vtkCamera();
        camera.SetFocalPoint((double)0.113766, (double)-1.13665, (double)-1.01919);
        camera.SetPosition((double)-29.4886, (double)-63.1488, (double)26.5807);
        camera.SetViewAngle((double)24.4617);
        camera.SetViewUp((double)0.17138, (double)0.331163, (double)0.927879);
        camera.SetClippingRange((double)1, (double)100);
        ren1.AddActor((vtkProp)ellipActor);
        ren1.AddActor((vtkProp)outlineActor);
        ren1.AddActor((vtkProp)coneActor);
        ren1.SetBackground((double)1.0, (double)1.0, (double)1.0);
        ren1.SetActiveCamera((vtkCamera)camera);
        renWin.SetSize((int)400, (int)400);
        renWin.Render();
        // prevent the tk window from showing up then start the event loop[]

//deleteAllVTKObjects();
    }
Ejemplo n.º 24
0
 ///<summary> A Set Method for Static Variables </summary>
 public static void Setpdn(vtkPolyDataNormals toSet)
 {
     pdn = toSet;
 }
Ejemplo n.º 25
0
 ///<summary> A Set Method for Static Variables </summary>
 public static void SetellipNormals(vtkPolyDataNormals toSet)
 {
     ellipNormals = toSet;
 }