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

        // to mark the origin[]
        sphere = new vtkSphereSource();
        sphere.SetRadius((double)2.0);
        sphereMapper = vtkPolyDataMapper.New();
        sphereMapper.SetInputConnection((vtkAlgorithmOutput)sphere.GetOutputPort());
        sphereMapper.ImmediateModeRenderingOn();
        sphereActor = new vtkActor();
        sphereActor.SetMapper((vtkMapper)sphereMapper);
        rt = new vtkRTAnalyticSource();
        rt.SetWholeExtent((int)-50, (int)50, (int)-50, (int)50, (int)0, (int)0);
        voi = new vtkExtractVOI();
        voi.SetInputConnection((vtkAlgorithmOutput)rt.GetOutputPort());
        voi.SetVOI((int)-11, (int)39, (int)5, (int)45, (int)0, (int)0);
        voi.SetSampleRate((int)5, (int)5, (int)1);
        // Get rid ambiguous triagulation issues.[]
        surf = new vtkDataSetSurfaceFilter();
        surf.SetInputConnection((vtkAlgorithmOutput)voi.GetOutputPort());
        tris = new vtkTriangleFilter();
        tris.SetInputConnection((vtkAlgorithmOutput)surf.GetOutputPort());
        mapper = vtkPolyDataMapper.New();
        mapper.SetInputConnection((vtkAlgorithmOutput)tris.GetOutputPort());
        mapper.ImmediateModeRenderingOn();
        mapper.SetScalarRange((double)130, (double)280);
        actor = new vtkActor();
        actor.SetMapper((vtkMapper)mapper);
        ren = vtkRenderer.New();
        ren.AddActor((vtkProp)actor);
        ren.AddActor((vtkProp)sphereActor);
        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();
    }
Example #2
0
        /// <summary>
        /// 将一个actor保存为stl格式
        /// </summary>
        /// <param name="actor"></param>
        void SaveActorToStl(vtkActor actor, string stlFileName)
        {
            //通过actor模型生成stl文件
            vtkPolyDataMapper mapper   = (vtkPolyDataMapper)actor.GetMapper();//获取mapper
            vtkPolyData       polyData = vtkPolyData.New();

            polyData = mapper.GetInput();//从mapper中提取数据
            vtkTriangleFilter filter = vtkTriangleFilter.New();

            filter.SetInput(polyData);//三角化后才能保存为正常的stl格式

            vtkSTLWriter stlWriter = vtkSTLWriter.New();

            stlWriter.SetFileName(stlFileName);
            stlWriter.SetInputConnection(filter.GetOutputPort());//提取数据
            stlWriter.Write();
        }
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVTestExtractVOI(String [] argv)
    {
        //Prefix Content is: ""

          // to mark the origin[]
          sphere = new vtkSphereSource();
          sphere.SetRadius((double)2.0);
          sphereMapper = vtkPolyDataMapper.New();
          sphereMapper.SetInputConnection((vtkAlgorithmOutput)sphere.GetOutputPort());
          sphereMapper.ImmediateModeRenderingOn();
          sphereActor = new vtkActor();
          sphereActor.SetMapper((vtkMapper)sphereMapper);
          rt = new vtkRTAnalyticSource();
          rt.SetWholeExtent((int)-50,(int)50,(int)-50,(int)50,(int)0,(int)0);
          voi = new vtkExtractVOI();
          voi.SetInputConnection((vtkAlgorithmOutput)rt.GetOutputPort());
          voi.SetVOI((int)-11,(int)39,(int)5,(int)45,(int)0,(int)0);
          voi.SetSampleRate((int)5,(int)5,(int)1);
          // Get rid ambiguous triagulation issues.[]
          surf = new vtkDataSetSurfaceFilter();
          surf.SetInputConnection((vtkAlgorithmOutput)voi.GetOutputPort());
          tris = new vtkTriangleFilter();
          tris.SetInputConnection((vtkAlgorithmOutput)surf.GetOutputPort());
          mapper = vtkPolyDataMapper.New();
          mapper.SetInputConnection((vtkAlgorithmOutput)tris.GetOutputPort());
          mapper.ImmediateModeRenderingOn();
          mapper.SetScalarRange((double)130,(double)280);
          actor = new vtkActor();
          actor.SetMapper((vtkMapper)mapper);
          ren = vtkRenderer.New();
          ren.AddActor((vtkProp)actor);
          ren.AddActor((vtkProp)sphereActor);
          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> A Set Method for Static Variables </summary>
 public static void Settf3(vtkTriangleFilter toSet)
 {
     tf3 = toSet;
 }
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVTestBranchExtentTranslator(String [] argv)
    {
        //Prefix Content is: ""

        gauss = new vtkImageGaussianSource();
        gauss.SetWholeExtent((int)0, (int)30, (int)0, (int)30, (int)0, (int)2);
        gauss.SetCenter((double)18, (double)12, (double)0);
        gauss.SetMaximum((double)1.0);
        gauss.SetStandardDeviation((double)6.0);
        gauss.Update();
        translator = new vtkBranchExtentTranslator();
        translator.SetOriginalSource((vtkImageData)gauss.GetOutput());
        gauss.GetOutput().SetExtentTranslator((vtkExtentTranslator)translator);
        clip1 = new vtkImageClip();
        clip1.SetOutputWholeExtent((int)7, (int)28, (int)0, (int)15, (int)1, (int)1);
        clip1.SetInputConnection((vtkAlgorithmOutput)gauss.GetOutputPort());
        surf1 = new vtkDataSetSurfaceFilter();
        surf1.SetInputConnection((vtkAlgorithmOutput)clip1.GetOutputPort());
        tf1 = new vtkTriangleFilter();
        tf1.SetInputConnection((vtkAlgorithmOutput)surf1.GetOutputPort());
        mapper1 = vtkPolyDataMapper.New();
        mapper1.SetInputConnection((vtkAlgorithmOutput)tf1.GetOutputPort());
        mapper1.SetScalarRange((double)0, (double)1);
        mapper1.SetNumberOfPieces((int)4);
        mapper1.SetPiece((int)1);
        actor1 = new vtkActor();
        actor1.SetMapper((vtkMapper)mapper1);
        actor1.SetPosition((double)0, (double)0, (double)0);
        // For coverage, a case where all four sides get clipped by the whole extent.[]
        clip2 = new vtkImageClip();
        clip2.SetOutputWholeExtent((int)16, (int)18, (int)3, (int)10, (int)0, (int)0);
        clip2.SetInputConnection((vtkAlgorithmOutput)gauss.GetOutputPort());
        surf2 = new vtkDataSetSurfaceFilter();
        surf2.SetInputConnection((vtkAlgorithmOutput)clip2.GetOutputPort());
        tf2 = new vtkTriangleFilter();
        tf2.SetInputConnection((vtkAlgorithmOutput)surf2.GetOutputPort());
        mapper2 = vtkPolyDataMapper.New();
        mapper2.SetInputConnection((vtkAlgorithmOutput)tf2.GetOutputPort());
        mapper2.SetScalarRange((double)0, (double)1);
        mapper2.SetNumberOfPieces((int)4);
        mapper2.SetPiece((int)1);
        actor2 = new vtkActor();
        actor2.SetMapper((vtkMapper)mapper2);
        actor2.SetPosition((double)15, (double)0, (double)0);
        // nothing in intersection (empty case)[]
        clip3 = new vtkImageClip();
        clip3.SetOutputWholeExtent((int)1, (int)10, (int)0, (int)15, (int)0, (int)2);
        clip3.SetInputConnection((vtkAlgorithmOutput)gauss.GetOutputPort());
        surf3 = new vtkDataSetSurfaceFilter();
        surf3.SetInputConnection((vtkAlgorithmOutput)clip3.GetOutputPort());
        tf3 = new vtkTriangleFilter();
        tf3.SetInputConnection((vtkAlgorithmOutput)surf3.GetOutputPort());
        mapper3 = vtkPolyDataMapper.New();
        mapper3.SetInputConnection((vtkAlgorithmOutput)tf3.GetOutputPort());
        mapper3.SetScalarRange((double)0, (double)1);
        mapper3.SetNumberOfPieces((int)4);
        mapper3.SetPiece((int)1);
        actor3 = new vtkActor();
        actor3.SetMapper((vtkMapper)mapper3);
        actor3.SetPosition((double)30, (double)0, (double)0);
        ren = vtkRenderer.New();
        ren.AddActor((vtkProp)actor1);
        ren.AddActor((vtkProp)actor2);
        ren.AddActor((vtkProp)actor3);
        renWin = vtkRenderWindow.New();
        renWin.AddRenderer((vtkRenderer)ren);
        //set cam [ren GetActiveCamera][]
        //ren ResetCamera[]
        iren = new vtkRenderWindowInteractor();
        iren.SetRenderWindow((vtkRenderWindow)renWin);
        iren.Initialize();
        renWin.Render();
        // break loop to avoid a memory leak.[]
        translator.SetOriginalSource(null);

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

          gauss = new vtkImageGaussianSource();
          gauss.SetWholeExtent((int)0,(int)30,(int)0,(int)30,(int)0,(int)2);
          gauss.SetCenter((double)18,(double)12,(double)0);
          gauss.SetMaximum((double)1.0);
          gauss.SetStandardDeviation((double)6.0);
          gauss.Update();
          translator = new vtkBranchExtentTranslator();
          translator.SetOriginalSource((vtkImageData)gauss.GetOutput());
          gauss.GetOutput().SetExtentTranslator((vtkExtentTranslator)translator);
          clip1 = new vtkImageClip();
          clip1.SetOutputWholeExtent((int)7,(int)28,(int)0,(int)15,(int)1,(int)1);
          clip1.SetInputConnection((vtkAlgorithmOutput)gauss.GetOutputPort());
          surf1 = new vtkDataSetSurfaceFilter();
          surf1.SetInputConnection((vtkAlgorithmOutput)clip1.GetOutputPort());
          tf1 = new vtkTriangleFilter();
          tf1.SetInputConnection((vtkAlgorithmOutput)surf1.GetOutputPort());
          mapper1 = vtkPolyDataMapper.New();
          mapper1.SetInputConnection((vtkAlgorithmOutput)tf1.GetOutputPort());
          mapper1.SetScalarRange((double)0,(double)1);
          mapper1.SetNumberOfPieces((int)4);
          mapper1.SetPiece((int)1);
          actor1 = new vtkActor();
          actor1.SetMapper((vtkMapper)mapper1);
          actor1.SetPosition((double)0,(double)0,(double)0);
          // For coverage, a case where all four sides get clipped by the whole extent.[]
          clip2 = new vtkImageClip();
          clip2.SetOutputWholeExtent((int)16,(int)18,(int)3,(int)10,(int)0,(int)0);
          clip2.SetInputConnection((vtkAlgorithmOutput)gauss.GetOutputPort());
          surf2 = new vtkDataSetSurfaceFilter();
          surf2.SetInputConnection((vtkAlgorithmOutput)clip2.GetOutputPort());
          tf2 = new vtkTriangleFilter();
          tf2.SetInputConnection((vtkAlgorithmOutput)surf2.GetOutputPort());
          mapper2 = vtkPolyDataMapper.New();
          mapper2.SetInputConnection((vtkAlgorithmOutput)tf2.GetOutputPort());
          mapper2.SetScalarRange((double)0,(double)1);
          mapper2.SetNumberOfPieces((int)4);
          mapper2.SetPiece((int)1);
          actor2 = new vtkActor();
          actor2.SetMapper((vtkMapper)mapper2);
          actor2.SetPosition((double)15,(double)0,(double)0);
          // nothing in intersection (empty case)[]
          clip3 = new vtkImageClip();
          clip3.SetOutputWholeExtent((int)1,(int)10,(int)0,(int)15,(int)0,(int)2);
          clip3.SetInputConnection((vtkAlgorithmOutput)gauss.GetOutputPort());
          surf3 = new vtkDataSetSurfaceFilter();
          surf3.SetInputConnection((vtkAlgorithmOutput)clip3.GetOutputPort());
          tf3 = new vtkTriangleFilter();
          tf3.SetInputConnection((vtkAlgorithmOutput)surf3.GetOutputPort());
          mapper3 = vtkPolyDataMapper.New();
          mapper3.SetInputConnection((vtkAlgorithmOutput)tf3.GetOutputPort());
          mapper3.SetScalarRange((double)0,(double)1);
          mapper3.SetNumberOfPieces((int)4);
          mapper3.SetPiece((int)1);
          actor3 = new vtkActor();
          actor3.SetMapper((vtkMapper)mapper3);
          actor3.SetPosition((double)30,(double)0,(double)0);
          ren = vtkRenderer.New();
          ren.AddActor((vtkProp)actor1);
          ren.AddActor((vtkProp)actor2);
          ren.AddActor((vtkProp)actor3);
          renWin = vtkRenderWindow.New();
          renWin.AddRenderer((vtkRenderer)ren);
          //set cam [ren GetActiveCamera][]
          //ren ResetCamera[]
          iren = new vtkRenderWindowInteractor();
          iren.SetRenderWindow((vtkRenderWindow)renWin);
          iren.Initialize();
          renWin.Render();
          // break loop to avoid a memory leak.[]
          translator.SetOriginalSource(null);

        //deleteAllVTKObjects();
    }
 ///<summary> A Set Method for Static Variables </summary>
 public static void Settf3(vtkTriangleFilter toSet)
 {
     tf3 = toSet;
 }
Example #8
0
        private void Subdivision(string filePath)
        {
            vtkPolyData originalMesh;

            if (filePath != null)
            {
                vtkXMLPolyDataReader reader = vtkXMLPolyDataReader.New();
                reader.SetFileName(filePath);
                // Subdivision filters only work on triangles
                vtkTriangleFilter triangles = vtkTriangleFilter.New();
                triangles.SetInputConnection(reader.GetOutputPort());
                triangles.Update();
                originalMesh = triangles.GetOutput();
            }
            else
            {
                vtkSphereSource sphereSource = vtkSphereSource.New();
                sphereSource.Update();
                originalMesh = sphereSource.GetOutput();
            }
            Debug.WriteLine("Before subdivision");
            Debug.WriteLine("    There are " + originalMesh.GetNumberOfPoints()
                            + " points.");
            Debug.WriteLine("    There are " + originalMesh.GetNumberOfPolys()
                            + " triangles.");

            int numberOfViewports = 3;

            vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;

            this.Size  = new System.Drawing.Size(200 * numberOfViewports + 12, 252);
            this.Text += " - Subdivision";
            Random rnd = new Random(2);
            int    numberOfSubdivisions = 2;

            // Create one text property for all
            vtkTextProperty textProperty = vtkTextProperty.New();

            textProperty.SetFontSize(14);
            textProperty.SetJustificationToCentered();

            for (int i = 0; i < numberOfViewports; i++)
            {
                // Note: Here we create a superclass pointer (vtkPolyDataAlgorithm) so that we can easily instantiate different
                // types of subdivision filters. Typically you would not want to do this, but rather create the pointer to be the type
                // filter you will actually use, e.g.
                // <vtkLinearSubdivisionFilter>  subdivisionFilter = <vtkLinearSubdivisionFilter>.New();
                vtkPolyDataAlgorithm subdivisionFilter;
                switch (i)
                {
                case 0:
                    subdivisionFilter = vtkLinearSubdivisionFilter.New();
                    ((vtkLinearSubdivisionFilter)subdivisionFilter).SetNumberOfSubdivisions(numberOfSubdivisions);
                    break;

                case 1:
                    subdivisionFilter = vtkLoopSubdivisionFilter.New();
                    ((vtkLoopSubdivisionFilter)subdivisionFilter).SetNumberOfSubdivisions(numberOfSubdivisions);
                    break;

                case 2:
                    subdivisionFilter = vtkButterflySubdivisionFilter.New();
                    ((vtkButterflySubdivisionFilter)subdivisionFilter).SetNumberOfSubdivisions(numberOfSubdivisions);
                    break;

                default:
                    subdivisionFilter = vtkLinearSubdivisionFilter.New();
                    ((vtkLinearSubdivisionFilter)subdivisionFilter).SetNumberOfSubdivisions(numberOfSubdivisions);
                    break;
                }
#if VTK_MAJOR_VERSION_5
                subdivisionFilter.SetInputConnection(originalMesh.GetProducerPort());
#else
                subdivisionFilter.SetInputData(originalMesh);
#endif
                subdivisionFilter.Update();
                vtkRenderer renderer = vtkRenderer.New();
                renderWindow.AddRenderer(renderer);
                renderer.SetViewport((float)i / numberOfViewports, 0, (float)(i + 1) / numberOfViewports, 1);
                renderer.SetBackground(.2 + rnd.NextDouble() / 8, .3 + rnd.NextDouble() / 8, .4 + rnd.NextDouble() / 8);

                vtkTextMapper textMapper = vtkTextMapper.New();
                vtkActor2D    textActor  = vtkActor2D.New();
                textMapper.SetInput(subdivisionFilter.GetClassName());
                textMapper.SetTextProperty(textProperty);

                textActor.SetMapper(textMapper);
                textActor.SetPosition(100, 16);

                //Create a mapper and actor
                vtkPolyDataMapper mapper = vtkPolyDataMapper.New();
                mapper.SetInputConnection(subdivisionFilter.GetOutputPort());
                vtkActor actor = vtkActor.New();
                actor.SetMapper(mapper);
                renderer.AddActor(actor);
                renderer.AddActor(textActor);
                renderer.ResetCamera();
            }
            renderWindow.Render();
        }
        private void HighLightBadCells()
        {
            vtkSphereSource sphereSource = vtkSphereSource.New();

            sphereSource.Update();

            vtkTriangleFilter triangleFilter = vtkTriangleFilter.New();

            triangleFilter.SetInputConnection(sphereSource.GetOutputPort());
            triangleFilter.Update();

            //Create a mapper and actor
            vtkDataSetMapper sphereMapper = vtkDataSetMapper.New();

            sphereMapper.SetInputConnection(triangleFilter.GetOutputPort());
            vtkActor sphereActor = vtkActor.New();

            sphereActor.SetMapper(sphereMapper);

            vtkPolyData mesh = triangleFilter.GetOutput();

            Debug.WriteLine("There are " + mesh.GetNumberOfCells() + " cells.");

            vtkMeshQuality qualityFilter = vtkMeshQuality.New();

#if VTK_MAJOR_VERSION_5
            qualityFilter.SetInput(mesh);
#else
            qualityFilter.SetInputData(mesh);
#endif
            qualityFilter.SetTriangleQualityMeasureToArea();
            qualityFilter.Update();

            vtkDataSet     qualityMesh  = qualityFilter.GetOutput();
            vtkDoubleArray qualityArray = vtkDoubleArray.SafeDownCast(qualityMesh.GetCellData().GetArray("Quality"));
            Debug.WriteLine("There are " + qualityArray.GetNumberOfTuples() + " values.");

            for (int i = 0; i < qualityArray.GetNumberOfTuples(); i++)
            {
                double val = qualityArray.GetValue(i);
                Debug.WriteLine("value " + i + ": " + val);
            }

            vtkThreshold selectCells = vtkThreshold.New();
            selectCells.ThresholdByLower(.02);
            selectCells.SetInputArrayToProcess(
                0,
                0,
                0,
                1, // POINTS = 0, CELLS = 1, NONE = 2, POINTS_THEN_CELLS = 3, VERTICES = 4, EDGES = 5, ROWS = 6
                0  // SCALARS = 0, VECTORS = 1, NORMALS = 2, TCOORDS = 3, TENSORS = 4, GLOBALIDS = 5, PEDIGREEIDS = 6, EDGEFLAG = 7
                );

#if VTK_MAJOR_VERSION_5
            selectCells.SetInput(qualityMesh);
#else
            selectCells.SetInputData(qualityMesh);
#endif
            selectCells.Update();
            vtkUnstructuredGrid ug = selectCells.GetOutput();

            // Create a mapper and actor
            vtkDataSetMapper mapper = vtkDataSetMapper.New();
#if VTK_MAJOR_VERSION_5
            mapper.SetInput(ug);
#else
            mapper.SetInputData(ug);
#endif
            vtkActor actor = vtkActor.New();
            actor.SetMapper(mapper);
            actor.GetProperty().SetColor(1.0, 0.0, 0.0);
            actor.GetProperty().SetRepresentationToWireframe();
            actor.GetProperty().SetLineWidth(5);
            // get a reference to the renderwindow of our renderWindowControl1
            vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;
            // renderer
            vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer();
            // set background color
            renderer.SetBackground(1.0, 1.0, 1.0);
            // add our actors to the renderer
            renderer.AddActor(actor);
            renderer.AddActor(sphereActor);
        }
 ///<summary> A Set Method for Static Variables </summary>
 public static void Settris(vtkTriangleFilter toSet)
 {
     tris = toSet;
 }
Example #11
0
 ///<summary> A Set Method for Static Variables </summary>
 public static void Settri(vtkTriangleFilter toSet)
 {
     tri = toSet;
 }
Example #12
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVEnSightRectGridBin(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_bin.case");
        reader.Update();
        toRectilinearGrid = new vtkCastToConcrete();
        //    toRectilinearGrid SetInputConnection [reader GetOutputPort] []
        toRectilinearGrid.SetInputData((vtkDataObject)reader.GetOutput().GetBlock((uint)0));
        toRectilinearGrid.Update();
        plane = new vtkRectilinearGridGeometryFilter();
        plane.SetInputData((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)((vtkMultiBlockDataSet)reader.GetOutput()).GetBlock((uint)0)).GetCenter()[0],
            (double)((vtkDataSet)((vtkMultiBlockDataSet)reader.GetOutput()).GetBlock((uint)0)).GetCenter()[1],
            (double)((vtkDataSet)((vtkMultiBlockDataSet)reader.GetOutput()).GetBlock((uint)0)).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)((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.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 [reader GetOutputPort][]
        streamer.SetInputData((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)((vtkMultiBlockDataSet)reader.GetOutput()).GetBlock((uint)0)).GetPointData().GetScalars().GetRange()[0],
            (double)((vtkDataSet)((vtkMultiBlockDataSet)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.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[]
        vtkGenericEnSightReader.SetDefaultExecutivePrototype(null);
//deleteAllVTKObjects();
    }
Example #13
0
        private void PolygonalSurfaceContourLineInterpolator()
        {
            vtkPolyData     polyData;
            vtkSphereSource sphereSource = vtkSphereSource.New();

            sphereSource.SetThetaResolution(40);
            sphereSource.SetPhiResolution(20);
            sphereSource.Update();

            polyData = sphereSource.GetOutput();
            // The Dijkstra interpolator will not accept cells that aren't triangles
            vtkTriangleFilter triangleFilter = vtkTriangleFilter.New();

#if VTK_MAJOR_VERSION_5
            triangleFilter.SetInput(polyData);
#else
            triangleFilter.SetInputData(polyData);
#endif
            triangleFilter.Update();

            vtkPolyData pd = triangleFilter.GetOutput();

            //Create a mapper and actor
            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();
            mapper.SetInputConnection(triangleFilter.GetOutputPort());

            vtkActor actor = vtkActor.New();
            actor.SetMapper(mapper);
            actor.GetProperty().SetInterpolationToFlat();

            // get a reference to the renderwindow of our renderWindowControl1
            vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;
            // renderer
            vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer();
            // set background color
            renderer.SetBackground(0.3, 0.4, 0.5);
            // add our actor to the renderer
            renderer.AddActor(actor);

            // Here comes the contour widget stuff.....
            vtkContourWidget contourWidget = vtkContourWidget.New();
            contourWidget.SetInteractor(renderWindow.GetInteractor());
            vtkOrientedGlyphContourRepresentation rep =
                vtkOrientedGlyphContourRepresentation.SafeDownCast(
                    contourWidget.GetRepresentation());
            rep.GetLinesProperty().SetColor(1, 0.2, 0);
            rep.GetLinesProperty().SetLineWidth(3.0f);

            vtkPolygonalSurfacePointPlacer pointPlacer =
                vtkPolygonalSurfacePointPlacer.New();
            pointPlacer.AddProp(actor);
            pointPlacer.GetPolys().AddItem(pd);
            rep.SetPointPlacer(pointPlacer);

            vtkPolygonalSurfaceContourLineInterpolator interpolator =
                vtkPolygonalSurfaceContourLineInterpolator.New();
            interpolator.GetPolys().AddItem(pd);
            rep.SetLineInterpolator(interpolator);

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

          // Create the RenderWindow, Renderer and both Actors[]
          //[]
          ren1 = vtkRenderer.New();
          renWin = vtkRenderWindow.New();
          renWin.AddRenderer((vtkRenderer)ren1);
          iren = new vtkRenderWindowInteractor();
          iren.SetRenderWindow((vtkRenderWindow)renWin);
          // read data[]
          //[]
          input = new vtkPolyDataReader();
          input.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/brainImageSmooth.vtk");
          //[]
          // generate vectors[]
          clean = new vtkCleanPolyData();
          clean.SetInputConnection((vtkAlgorithmOutput)input.GetOutputPort());
          smooth = new vtkWindowedSincPolyDataFilter();
          smooth.SetInputConnection((vtkAlgorithmOutput)clean.GetOutputPort());
          smooth.GenerateErrorVectorsOn();
          smooth.GenerateErrorScalarsOn();
          smooth.Update();
          mapper = vtkPolyDataMapper.New();
          mapper.SetInputConnection((vtkAlgorithmOutput)smooth.GetOutputPort());
          mapper.SetScalarRange((double)((vtkDataSet)smooth.GetOutput()).GetScalarRange()[0],
          (double)((vtkDataSet)smooth.GetOutput()).GetScalarRange()[1]);
          brain = new vtkActor();
          brain.SetMapper((vtkMapper)mapper);
          // Add the actors to the renderer, set the background and size[]
          //[]
          ren1.AddActor((vtkProp)brain);
          renWin.SetSize((int)320,(int)240);
          ren1.GetActiveCamera().SetPosition((double)149.653,(double)-65.3464,(double)96.0401);
          ren1.GetActiveCamera().SetFocalPoint((double)146.003,(double)22.3839,(double)0.260541);
          ren1.GetActiveCamera().SetViewAngle((double)30);
          ren1.GetActiveCamera().SetViewUp((double)-0.255578,(double)-0.717754,(double)-0.647695);
          ren1.GetActiveCamera().SetClippingRange((double)79.2526,(double)194.052);
          iren.Initialize();
          renWin.Render();
          // render the image[]
          //[]
          // prevent the tk window from showing up then start the event loop[]
          //[]
          // If the current directory is writable, then test the witers[]
          //[]
          try
          {
         channel = new StreamWriter("test.tmp");
          tryCatchError = "NOERROR";
          }
          catch(Exception)
          {tryCatchError = "ERROR";}

        if(tryCatchError.Equals("NOERROR"))
          {
          channel.Close();
          File.Delete("test.tmp");
          //[]
          //[]
          // test the writers[]
          dsw = new vtkDataSetWriter();
          dsw.SetInputConnection((vtkAlgorithmOutput)smooth.GetOutputPort());
          dsw.SetFileName((string)"brain.dsw");
          dsw.Write();
          File.Delete("brain.dsw");
          pdw = new vtkPolyDataWriter();
          pdw.SetInputConnection((vtkAlgorithmOutput)smooth.GetOutputPort());
          pdw.SetFileName((string)"brain.pdw");
          pdw.Write();
          File.Delete("brain.pdw");
          iv = new vtkIVWriter();
          iv.SetInputConnection((vtkAlgorithmOutput)smooth.GetOutputPort());
          iv.SetFileName((string)"brain.iv");
          iv.Write();
          File.Delete("brain.iv");

          //[]
          // the next writers only handle triangles[]
          triangles = new vtkTriangleFilter();
          triangles.SetInputConnection((vtkAlgorithmOutput)smooth.GetOutputPort());
          iv2 = new vtkIVWriter();
          iv2.SetInputConnection((vtkAlgorithmOutput)triangles.GetOutputPort());
          iv2.SetFileName((string)"brain2.iv");
          iv2.Write();
          File.Delete("brain2.iv");

          edges = new vtkExtractEdges();
          edges.SetInputConnection((vtkAlgorithmOutput)triangles.GetOutputPort());
          iv3 = new vtkIVWriter();
          iv3.SetInputConnection((vtkAlgorithmOutput)edges.GetOutputPort());
          iv3.SetFileName((string)"brain3.iv");
          iv3.Write();
          File.Delete("brain3.iv");

          byu = new vtkBYUWriter();
          byu.SetGeometryFileName((string)"brain.g");
          byu.SetScalarFileName((string)"brain.s");
          byu.SetDisplacementFileName((string)"brain.d");
          byu.SetInputConnection((vtkAlgorithmOutput)triangles.GetOutputPort());
          byu.Write();
          File.Delete("brain.g");
          File.Delete("brain.s");
          File.Delete("brain.d");
          mcubes = new vtkMCubesWriter();
          mcubes.SetInputConnection((vtkAlgorithmOutput)triangles.GetOutputPort());
          mcubes.SetFileName((string)"brain.tri");
          mcubes.SetLimitsFileName((string)"brain.lim");
          mcubes.Write();
          File.Delete("brain.lim");
          File.Delete("brain.tri");
          stl = new vtkSTLWriter();
          stl.SetInputConnection((vtkAlgorithmOutput)triangles.GetOutputPort());
          stl.SetFileName((string)"brain.stl");
          stl.Write();
          File.Delete("brain.stl");
          stlBinary = new vtkSTLWriter();
          stlBinary.SetInputConnection((vtkAlgorithmOutput)triangles.GetOutputPort());
          stlBinary.SetFileName((string)"brainBinary.stl");
          stlBinary.SetFileType((int)2);
          stlBinary.Write();
          File.Delete("brainBinary.stl");
        }

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

        // Create the RenderWindow, Renderer and both Actors[]
        //[]
        ren1   = vtkRenderer.New();
        renWin = vtkRenderWindow.New();
        renWin.AddRenderer((vtkRenderer)ren1);
        iren = new vtkRenderWindowInteractor();
        iren.SetRenderWindow((vtkRenderWindow)renWin);
        // read data[]
        //[]
        input = new vtkPolyDataReader();
        input.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/brainImageSmooth.vtk");
        //[]
        // generate vectors[]
        clean = new vtkCleanPolyData();
        clean.SetInputConnection((vtkAlgorithmOutput)input.GetOutputPort());
        smooth = new vtkWindowedSincPolyDataFilter();
        smooth.SetInputConnection((vtkAlgorithmOutput)clean.GetOutputPort());
        smooth.GenerateErrorVectorsOn();
        smooth.GenerateErrorScalarsOn();
        smooth.Update();
        mapper = vtkPolyDataMapper.New();
        mapper.SetInputConnection((vtkAlgorithmOutput)smooth.GetOutputPort());
        mapper.SetScalarRange((double)((vtkDataSet)smooth.GetOutput()).GetScalarRange()[0],
                              (double)((vtkDataSet)smooth.GetOutput()).GetScalarRange()[1]);
        brain = new vtkActor();
        brain.SetMapper((vtkMapper)mapper);
        // Add the actors to the renderer, set the background and size[]
        //[]
        ren1.AddActor((vtkProp)brain);
        renWin.SetSize((int)320, (int)240);
        ren1.GetActiveCamera().SetPosition((double)149.653, (double)-65.3464, (double)96.0401);
        ren1.GetActiveCamera().SetFocalPoint((double)146.003, (double)22.3839, (double)0.260541);
        ren1.GetActiveCamera().SetViewAngle((double)30);
        ren1.GetActiveCamera().SetViewUp((double)-0.255578, (double)-0.717754, (double)-0.647695);
        ren1.GetActiveCamera().SetClippingRange((double)79.2526, (double)194.052);
        iren.Initialize();
        renWin.Render();
        // render the image[]
        //[]
        // prevent the tk window from showing up then start the event loop[]
        //[]
        // If the current directory is writable, then test the witers[]
        //[]
        try
        {
            channel       = new StreamWriter("test.tmp");
            tryCatchError = "NOERROR";
        }
        catch (Exception)
        { tryCatchError = "ERROR"; }

        if (tryCatchError.Equals("NOERROR"))
        {
            channel.Close();
            File.Delete("test.tmp");
            //[]
            //[]
            // test the writers[]
            dsw = new vtkDataSetWriter();
            dsw.SetInputConnection((vtkAlgorithmOutput)smooth.GetOutputPort());
            dsw.SetFileName((string)"brain.dsw");
            dsw.Write();
            File.Delete("brain.dsw");
            pdw = new vtkPolyDataWriter();
            pdw.SetInputConnection((vtkAlgorithmOutput)smooth.GetOutputPort());
            pdw.SetFileName((string)"brain.pdw");
            pdw.Write();
            File.Delete("brain.pdw");
            iv = new vtkIVWriter();
            iv.SetInputConnection((vtkAlgorithmOutput)smooth.GetOutputPort());
            iv.SetFileName((string)"brain.iv");
            iv.Write();
            File.Delete("brain.iv");


            //[]
            // the next writers only handle triangles[]
            triangles = new vtkTriangleFilter();
            triangles.SetInputConnection((vtkAlgorithmOutput)smooth.GetOutputPort());
            iv2 = new vtkIVWriter();
            iv2.SetInputConnection((vtkAlgorithmOutput)triangles.GetOutputPort());
            iv2.SetFileName((string)"brain2.iv");
            iv2.Write();
            File.Delete("brain2.iv");


            edges = new vtkExtractEdges();
            edges.SetInputConnection((vtkAlgorithmOutput)triangles.GetOutputPort());
            iv3 = new vtkIVWriter();
            iv3.SetInputConnection((vtkAlgorithmOutput)edges.GetOutputPort());
            iv3.SetFileName((string)"brain3.iv");
            iv3.Write();
            File.Delete("brain3.iv");


            byu = new vtkBYUWriter();
            byu.SetGeometryFileName((string)"brain.g");
            byu.SetScalarFileName((string)"brain.s");
            byu.SetDisplacementFileName((string)"brain.d");
            byu.SetInputConnection((vtkAlgorithmOutput)triangles.GetOutputPort());
            byu.Write();
            File.Delete("brain.g");
            File.Delete("brain.s");
            File.Delete("brain.d");
            mcubes = new vtkMCubesWriter();
            mcubes.SetInputConnection((vtkAlgorithmOutput)triangles.GetOutputPort());
            mcubes.SetFileName((string)"brain.tri");
            mcubes.SetLimitsFileName((string)"brain.lim");
            mcubes.Write();
            File.Delete("brain.lim");
            File.Delete("brain.tri");
            stl = new vtkSTLWriter();
            stl.SetInputConnection((vtkAlgorithmOutput)triangles.GetOutputPort());
            stl.SetFileName((string)"brain.stl");
            stl.Write();
            File.Delete("brain.stl");
            stlBinary = new vtkSTLWriter();
            stlBinary.SetInputConnection((vtkAlgorithmOutput)triangles.GetOutputPort());
            stlBinary.SetFileName((string)"brainBinary.stl");
            stlBinary.SetFileType((int)2);
            stlBinary.Write();
            File.Delete("brainBinary.stl");
        }



//deleteAllVTKObjects();
    }
Example #16
0
        private void Triangulate()
        {
            vtkRegularPolygonSource polygonSource = vtkRegularPolygonSource.New();

            polygonSource.Update();

            vtkTriangleFilter triangleFilter = vtkTriangleFilter.New();

#if VTK_MAJOR_VERSION_5
            triangleFilter.SetInputConnection(polygonSource.GetOutputPort());
#else
            triangleFilter.SetInputData(polygonSource);
#endif
            triangleFilter.Update();

            vtkPolyDataMapper inputMapper = vtkPolyDataMapper.New();
#if VTK_MAJOR_VERSION_5
            inputMapper.SetInputConnection(polygonSource.GetOutputPort());
#else
            inputMapper.SetInputData(polygonSource);
#endif
            vtkActor inputActor = vtkActor.New();
            inputActor.SetMapper(inputMapper);
            inputActor.GetProperty().SetRepresentationToWireframe();

            vtkPolyDataMapper triangleMapper = vtkPolyDataMapper.New();
#if VTK_MAJOR_VERSION_5
            triangleMapper.SetInputConnection(triangleFilter.GetOutputPort());
#else
            triangleMapper.SetInputData(triangleFilter);
#endif
            vtkActor triangleActor = vtkActor.New();
            triangleActor.SetMapper(triangleMapper);
            triangleActor.GetProperty().SetRepresentationToWireframe();

            vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;
            this.Size = new System.Drawing.Size(612, 352);

            // Define viewport ranges
            // (xmin, ymin, xmax, ymax)
            double[] leftViewport  = new double[] { 0.0, 0.0, 0.5, 1.0 };
            double[] rightViewport = new double[] { 0.5, 0.0, 1.0, 1.0 };

            // Setup both renderers
            vtkRenderer leftRenderer = vtkRenderer.New();
            renderWindow.AddRenderer(leftRenderer);
            leftRenderer.SetViewport(leftViewport[0], leftViewport[1], leftViewport[2], leftViewport[3]);
            leftRenderer.SetBackground(.6, .5, .4);

            vtkRenderer rightRenderer = vtkRenderer.New();
            renderWindow.AddRenderer(rightRenderer);
            rightRenderer.SetViewport(rightViewport[0], rightViewport[1], rightViewport[2], rightViewport[3]);
            rightRenderer.SetBackground(.4, .5, .6);

            // Add the sphere to the left and the cube to the right
            leftRenderer.AddActor(inputActor);
            rightRenderer.AddActor(triangleActor);
            leftRenderer.ResetCamera();
            rightRenderer.ResetCamera();
            renderWindow.Render();
        }
    /// <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();
    }
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVextractRectGrid(String [] argv)
    {
        //Prefix Content is: ""

          // create pipeline - rectilinear grid[]
          //[]
          rgridReader = new vtkRectilinearGridReader();
          rgridReader.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/RectGrid2.vtk");
          outline = new vtkOutlineFilter();
          outline.SetInputConnection((vtkAlgorithmOutput)rgridReader.GetOutputPort());
          mapper = vtkPolyDataMapper.New();
          mapper.SetInputConnection((vtkAlgorithmOutput)outline.GetOutputPort());
          actor = new vtkActor();
          actor.SetMapper((vtkMapper)mapper);
          rgridReader.Update();
          extract1 = new vtkExtractRectilinearGrid();
          extract1.SetInputConnection((vtkAlgorithmOutput)rgridReader.GetOutputPort());
          //extract1 SetVOI 0 46 0 32 0 10[]
          extract1.SetVOI((int)23,(int)40,(int)16,(int)30,(int)9,(int)9);
          extract1.SetSampleRate((int)2,(int)2,(int)1);
          extract1.IncludeBoundaryOn();
          extract1.Update();
          surf1 = new vtkDataSetSurfaceFilter();
          surf1.SetInputConnection((vtkAlgorithmOutput)extract1.GetOutputPort());
          tris = new vtkTriangleFilter();
          tris.SetInputConnection((vtkAlgorithmOutput)surf1.GetOutputPort());
          mapper1 = vtkPolyDataMapper.New();
          mapper1.SetInputConnection((vtkAlgorithmOutput)tris.GetOutputPort());
          mapper1.SetScalarRange((double)((vtkDataSet)extract1.GetOutput()).GetScalarRange()[0], (double)((vtkDataSet)extract1.GetOutput()).GetScalarRange()[1]);
          actor1 = new vtkActor();
          actor1.SetMapper((vtkMapper)mapper1);
          // write out a rect grid[]
          // write to the temp directory if possible, otherwise use .[]
          dir = ".";
          dir = TclToCsScriptTestDriver.GetTempDirectory();

          // make sure the directory is writeable first[]
          try
          {
         channel = new StreamWriter("" + (dir.ToString()) + "/test.tmp");
          tryCatchError = "NOERROR";
          }
          catch(Exception)
          {tryCatchError = "ERROR";}

        if(tryCatchError.Equals("NOERROR"))
          {
          channel.Close();
          File.Delete("" + (dir.ToString()) + "/test.tmp");
          rectWriter = new vtkRectilinearGridWriter();
          rectWriter.SetInputConnection((vtkAlgorithmOutput)extract1.GetOutputPort());
          rectWriter.SetFileName((string)"" + (dir.ToString()) + "/rect.tmp");
          rectWriter.Write();
          // delete the file[]
          File.Delete("" + (dir.ToString()) + "/rect.tmp");
        }

          // Create the RenderWindow, Renderer and both Actors[]
          //[]
          ren1 = vtkRenderer.New();
          renWin = vtkRenderWindow.New();
          renWin.AddRenderer((vtkRenderer)ren1);
          iren = new vtkRenderWindowInteractor();
          iren.SetRenderWindow((vtkRenderWindow)renWin);
          //ren1 AddActor actor[]
          ren1.AddActor((vtkProp)actor1);
          renWin.SetSize((int)340,(int)400);
          iren.Initialize();
          // render the image[]
          //[]
          // prevent the tk window from showing up then start the event loop[]

        //deleteAllVTKObjects();
    }
Example #19
0
        protected virtual void Initialize()
        {
            //InitAlgorithmModifiedEvent();

            if (_vtkMesh == null)
                _vtkMesh = new VtkMesh();
            if (_gameObject == null)
            {
                _gameObject = new GameObject(Name);
                _gameObject.transform.parent = transform;
                _gameObject.transform.localPosition = new Vector3();
            //				_gameObject.AddComponent<MeshFilter>();
            //				var meshRenderer = _gameObject.AddComponent<MeshRenderer>();
            }

            if (_triangleFilter == null)
                _triangleFilter = vtkTriangleFilter.New();

            if (_polyDataOutput == null)
                _polyDataOutput = _triangleFilter.GetOutput();
        }
Example #20
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVextractRectGrid(String [] argv)
    {
        //Prefix Content is: ""

        // create pipeline - rectilinear grid[]
        //[]
        rgridReader = new vtkRectilinearGridReader();
        rgridReader.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/RectGrid2.vtk");
        outline = new vtkOutlineFilter();
        outline.SetInputConnection((vtkAlgorithmOutput)rgridReader.GetOutputPort());
        mapper = vtkPolyDataMapper.New();
        mapper.SetInputConnection((vtkAlgorithmOutput)outline.GetOutputPort());
        actor = new vtkActor();
        actor.SetMapper((vtkMapper)mapper);
        rgridReader.Update();
        extract1 = new vtkExtractRectilinearGrid();
        extract1.SetInputConnection((vtkAlgorithmOutput)rgridReader.GetOutputPort());
        //extract1 SetVOI 0 46 0 32 0 10[]
        extract1.SetVOI((int)23, (int)40, (int)16, (int)30, (int)9, (int)9);
        extract1.SetSampleRate((int)2, (int)2, (int)1);
        extract1.IncludeBoundaryOn();
        extract1.Update();
        surf1 = new vtkDataSetSurfaceFilter();
        surf1.SetInputConnection((vtkAlgorithmOutput)extract1.GetOutputPort());
        tris = new vtkTriangleFilter();
        tris.SetInputConnection((vtkAlgorithmOutput)surf1.GetOutputPort());
        mapper1 = vtkPolyDataMapper.New();
        mapper1.SetInputConnection((vtkAlgorithmOutput)tris.GetOutputPort());
        mapper1.SetScalarRange((double)((vtkDataSet)extract1.GetOutput()).GetScalarRange()[0], (double)((vtkDataSet)extract1.GetOutput()).GetScalarRange()[1]);
        actor1 = new vtkActor();
        actor1.SetMapper((vtkMapper)mapper1);
        // write out a rect grid[]
        // write to the temp directory if possible, otherwise use .[]
        dir = ".";
        dir = TclToCsScriptTestDriver.GetTempDirectory();


        // make sure the directory is writeable first[]
        try
        {
            channel       = new StreamWriter("" + (dir.ToString()) + "/test.tmp");
            tryCatchError = "NOERROR";
        }
        catch (Exception)
        { tryCatchError = "ERROR"; }

        if (tryCatchError.Equals("NOERROR"))
        {
            channel.Close();
            File.Delete("" + (dir.ToString()) + "/test.tmp");
            rectWriter = new vtkRectilinearGridWriter();
            rectWriter.SetInputConnection((vtkAlgorithmOutput)extract1.GetOutputPort());
            rectWriter.SetFileName((string)"" + (dir.ToString()) + "/rect.tmp");
            rectWriter.Write();
            // delete the file[]
            File.Delete("" + (dir.ToString()) + "/rect.tmp");
        }


        // Create the RenderWindow, Renderer and both Actors[]
        //[]
        ren1   = vtkRenderer.New();
        renWin = vtkRenderWindow.New();
        renWin.AddRenderer((vtkRenderer)ren1);
        iren = new vtkRenderWindowInteractor();
        iren.SetRenderWindow((vtkRenderWindow)renWin);
        //ren1 AddActor actor[]
        ren1.AddActor((vtkProp)actor1);
        renWin.SetSize((int)340, (int)400);
        iren.Initialize();
        // render the image[]
        //[]
        // prevent the tk window from showing up then start the event loop[]

//deleteAllVTKObjects();
    }