Example #1
0
        public void InitializeFaces()
        {
            vtkCleanPolyData Clean = vtkCleanPolyData.New();

            Clean.SetInputConnection(AppendFaces.GetOutputPort());
            Clean.Update();
            Faces = Clean.GetOutput();
        }
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVTestExtrudePiece(String [] argv)
    {
        //Prefix Content is: ""

          disk = new vtkDiskSource();
          disk.SetRadialResolution((int)2);
          disk.SetCircumferentialResolution((int)9);
          clean = new vtkCleanPolyData();
          clean.SetInputConnection((vtkAlgorithmOutput)disk.GetOutputPort());
          clean.SetTolerance((double)0.01);
          piece = new vtkExtractPolyDataPiece();
          piece.SetInputConnection((vtkAlgorithmOutput)clean.GetOutputPort());
          extrude = new vtkPLinearExtrusionFilter();
          extrude.SetInputConnection((vtkAlgorithmOutput)piece.GetOutputPort());
          extrude.PieceInvariantOn();
          // Create the RenderWindow, Renderer and both Actors[]
          //[]
          ren1 = vtkRenderer.New();
          renWin = vtkRenderWindow.New();
          renWin.AddRenderer((vtkRenderer)ren1);
          iren = new vtkRenderWindowInteractor();
          iren.SetRenderWindow((vtkRenderWindow)renWin);
          mapper = vtkPolyDataMapper.New();
          mapper.SetInputConnection((vtkAlgorithmOutput)extrude.GetOutputPort());
          mapper.SetNumberOfPieces((int)2);
          mapper.SetPiece((int)1);
          bf = new vtkProperty();
          bf.SetColor((double)1,(double)0,(double)0);
          actor = new vtkActor();
          actor.SetMapper((vtkMapper)mapper);
          actor.GetProperty().SetColor((double)1,(double)1,(double)0.8);
          actor.SetBackfaceProperty((vtkProperty)bf);
          // Add the actors to the renderer, set the background and size[]
          //[]
          ren1.AddActor((vtkProp)actor);
          ren1.SetBackground((double)0.1,(double)0.2,(double)0.4);
          renWin.SetSize((int)300,(int)300);
          // render the image[]
          //[]
          cam1 = ren1.GetActiveCamera();
          cam1.Azimuth((double)20);
          cam1.Elevation((double)40);
          ren1.ResetCamera();
          cam1.Zoom((double)1.2);
          iren.Initialize();
          // prevent the tk window from showing up then start the event loop[]

        //deleteAllVTKObjects();
    }
Example #3
0
        public void SetPosition(double[] xyz1, double[] xyz2)
        {
            vtkPoints points = vtkPoints.New();

            points.InsertPoint(0, xyz1[0], xyz1[1], xyz1[2]);
            points.InsertPoint(1, xyz2[0], xyz2[1], xyz2[2]);

            vtkCellArray lines = vtkCellArray.New();

            lines.InsertNextCell(2);

            lines.InsertCellPoint(0);
            lines.InsertCellPoint(1);

            vtkPolyData profileData = new vtkPolyData();

            profileData.SetPoints(points);
            profileData.SetLines(lines);
            profileData.SetVerts(lines);
            profileData.Update();

            vtkCleanPolyData cleanFilter = new vtkCleanPolyData();

            cleanFilter.SetInput(profileData);
            cleanFilter.Update();

            vtkTubeFilter profileTubes = new vtkTubeFilter();

            profileTubes.SetNumberOfSides(10);
            profileTubes.SetInput(cleanFilter.GetOutput());
            //profileTubes.SetVaryRadiusToVaryRadiusByVector();
            profileTubes.SetRadius(1);
            profileTubes.SetInputArrayToProcess(1, 0, 0, 0, "vectors");

            //vtkPolyDataMapper profileMapper = new vtkPolyDataMapper();
            //profileMapper.SetInputConnection(profileTubes.GetOutputPort());

            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();

            mapper.SetInput(profileTubes.GetOutput());

            centerLineActor.SetMapper(mapper);
            centerLineActor.GetProperty().SetOpacity(0.5);
        }
Example #4
0
        public static vtkPolyData Create(List <double[]> xyz1, double radius)
        {
            vtkPoints points = new vtkPoints();

            for (int index = 0; index < xyz1.Count; index++)
            {
                double[] doubles = xyz1[index];
                points.InsertPoint(index, doubles[0], doubles[1], doubles[2]);
            }

            vtkCellArray lines = new vtkCellArray();

            lines.InsertNextCell(xyz1.Count);

            for (int index = 0; index < xyz1.Count; index++)
            {
                lines.InsertCellPoint(index);
            }

            vtkPolyData profileData = new vtkPolyData();

            profileData.SetPoints(points);
            profileData.SetLines(lines);
            profileData.SetVerts(lines);
            profileData.Update();

            vtkCleanPolyData cleanFilter = new vtkCleanPolyData();

            cleanFilter.SetInput(profileData);
            cleanFilter.Update();

            vtkTubeFilter profileTubes = new vtkTubeFilter();

            profileTubes.SetNumberOfSides(10);
            profileTubes.SetInput(cleanFilter.GetOutput());
            //profileTubes.SetVaryRadiusToVaryRadiusByVector();
            profileTubes.SetRadius(radius);
            profileTubes.SetInputArrayToProcess(1, 0, 0, 0, "vectors");

            return(profileTubes.GetOutput());
        }
Example #5
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();
        }
 ///<summary> A Set Method for Static Variables </summary>
 public static void Setclean(vtkCleanPolyData toSet)
 {
     clean = toSet;
 }
    /// <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 #8
0
 ///<summary> A Set Method for Static Variables </summary>
 public static void Setclean(vtkCleanPolyData toSet)
 {
     clean = toSet;
 }
Example #9
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 #10
0
        private void FilledContours(string filePath, int numberOfContours)
        {
            // Read the file
            vtkXMLPolyDataReader reader = vtkXMLPolyDataReader.New();

            reader.SetFileName(filePath);
            reader.Update(); // Update so that we can get the scalar range

            double[] scalarRange = reader.GetOutput().GetPointData().GetScalars().GetRange();

            vtkAppendPolyData appendFilledContours = vtkAppendPolyData.New();

            double delta = (scalarRange[1] - scalarRange[0]) / (numberOfContours - 1);

            // Keep the clippers alive
            List <vtkClipPolyData> clippersLo = new List <vtkClipPolyData>();
            List <vtkClipPolyData> clippersHi = new List <vtkClipPolyData>();

            for (int i = 0; i < numberOfContours; i++)
            {
                double valueLo = scalarRange[0] + i * delta;
                double valueHi = scalarRange[0] + (i + 1) * delta;

                clippersLo.Add(vtkClipPolyData.New());
                clippersLo[i].SetValue(valueLo);
                if (i == 0)
                {
                    clippersLo[i].SetInputConnection(reader.GetOutputPort());
                }
                else
                {
                    clippersLo[i].SetInputConnection(clippersHi[i - 1].GetOutputPort(1));
                }
                clippersLo[i].InsideOutOff();
                clippersLo[i].Update();

                clippersHi.Add(vtkClipPolyData.New());
                clippersHi[i].SetValue(valueHi);
                clippersHi[i].SetInputConnection(clippersLo[i].GetOutputPort());
                clippersHi[i].GenerateClippedOutputOn();
                clippersHi[i].InsideOutOn();
                clippersHi[i].Update();
                if (clippersHi[i].GetOutput().GetNumberOfCells() == 0)
                {
                    continue;
                }

                vtkFloatArray cd = vtkFloatArray.New();
                cd.SetNumberOfComponents(1);
                cd.SetNumberOfTuples(clippersHi[i].GetOutput().GetNumberOfCells());
                cd.FillComponent(0, valueLo);

                clippersHi[i].GetOutput().GetCellData().SetScalars(cd);
                appendFilledContours.AddInputConnection(clippersHi[i].GetOutputPort());
            }

            vtkCleanPolyData filledContours = vtkCleanPolyData.New();

            filledContours.SetInputConnection(appendFilledContours.GetOutputPort());

            vtkLookupTable lut = vtkLookupTable.New();

            lut.SetNumberOfTableValues(numberOfContours + 1);
            lut.Build();
            vtkPolyDataMapper contourMapper = vtkPolyDataMapper.New();

            contourMapper.SetInputConnection(filledContours.GetOutputPort());
            contourMapper.SetScalarRange(scalarRange[0], scalarRange[1]);
            contourMapper.SetScalarModeToUseCellData();
            contourMapper.SetLookupTable(lut);

            vtkActor contourActor = vtkActor.New();

            contourActor.SetMapper(contourMapper);
            contourActor.GetProperty().SetInterpolationToFlat();

            vtkContourFilter contours = vtkContourFilter.New();

            contours.SetInputConnection(filledContours.GetOutputPort());
            contours.GenerateValues(numberOfContours, scalarRange[0], scalarRange[1]);

            vtkPolyDataMapper contourLineMapperer = vtkPolyDataMapper.New();

            contourLineMapperer.SetInputConnection(contours.GetOutputPort());
            contourLineMapperer.SetScalarRange(scalarRange[0], scalarRange[1]);
            contourLineMapperer.ScalarVisibilityOff();

            vtkActor contourLineActor = vtkActor.New();

            contourLineActor.SetMapper(contourLineMapperer);
            contourLineActor.GetProperty().SetLineWidth(2);

            // get a reference to the renderwindow of our renderWindowControl1
            vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;
            // renderer
            vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer();

            // set background color
            renderer.SetBackground(.2, .3, .4);
            // add our actor to the renderer
            renderer.AddActor(contourActor);
            renderer.AddActor(contourLineActor);
        }