Exemplo n.º 1
0
        static public vtkProp3D genQuadricSurfaceActor(CompontData data, vtkProperty pro)
        {
            if (data.restriction != null)
            {
                return(genActorByRestriction(data, pro));
            }
            QuadricSurfaceData s = (QuadricSurfaceData)data;

            vtkQuadric quadric = vtkQuadric.New();

            quadric.SetCoefficients(s.param[0], s.param[1], s.param[2], s.param[3], s.param[4], s.param[5], s.param[6],
                                    s.param[7], s.param[8], s.param[9] + 1);

            //二次函数采样分辨率
            vtkSampleFunction sample = vtkSampleFunction.New();

            sample.SetSampleDimensions(60, 60, 30);
            sample.SetImplicitFunction(quadric);
            sample.SetModelBounds(s.param[10], s.param[11], s.param[12], s.param[13], s.param[14], s.param[15]);
            vtkContourFilter contourFilter = vtkContourFilter.New();

            contourFilter.SetInputConnection(sample.GetOutputPort());
            contourFilter.GenerateValues(1, 1, 1);
            contourFilter.Update();

            return(genUserActor(data, contourFilter.GetOutputPort(), pro));
        }
Exemplo n.º 2
0
 static public vtkProp3D genActor(CompontData data, vtkProperty pro = null)
 {
     if (pro == null)
     {
         pro = new vtkProperty();
         // 默认颜色
         pro.SetColor(config.default_color[0], config.default_color[1],
                      config.default_color[2]);
     }
     if (data.type == CmpontType.PLANEMIRROR ||
         data.type == CmpontType.PARABOLOIDMIRROR ||
         data.type == CmpontType.HYPERNOLOIDMIRROR ||
         data.type == CmpontType.ELLIPSOIDMIRROR)
     {
         return(genQuadricSurfaceActor(data, pro));
     }
     else if (data.type == CmpontType.GUASSIANSOURCE)
     {
         SourceData tmp = (SourceData)data;
         return(genFieldActor(tmp.field));
     }
     else if (data.type == CmpontType.RES_CYLINDER)
     {
         return(genCylinderActor(data, pro));
     }
     else if (data.type == CmpontType.STLMIRROR)
     {
         return(genSTLActor(data, pro));
     }
     return(null);
 }
Exemplo n.º 3
0
        static public vtkProperty genClickProperty()
        {
            vtkProperty pro = new vtkProperty();

            pro.SetColor(config.click_color[0], config.click_color[1],
                         config.click_color[2]);
            pro.SetOpacity(0.5);
            return(pro);
        }
Exemplo n.º 4
0
        public void AddCylinderEdgeToActors(byte[] bgColor, ref vtkActorCollection actors)
        {
            vtkProperty pp = vtkProperty.New();

            pp.SetOpacity(0.7);
            pp.SetColor(bgColor[0], bgColor[1], bgColor[2]);
            pp.SetLineWidth(5);
            pp.SetLighting(false);

            vtkRegularPolygonSource circle = vtkRegularPolygonSource.New();

            circle.GeneratePolygonOn();
            circle.SetNumberOfSides(50);
            circle.SetRadius(radius);
            circle.SetCenter(0, 0, 0);

            vtkPolyDataMapper mappper = vtkPolyDataMapper.New();

            mappper.SetInputConnection(circle.GetOutputPort());

            vtkActor actor = vtkActor.New();

            actor.SetProperty(pp);
            actor.SetMapper(mappper);
            actors.AddItem(actor);

            actor.SetProperty(pp);
            actors.AddItem(actor);


            vtkLineSource ls = vtkLineSource.New();

            ls.SetPoint1(0, 0, 0);
            ls.SetPoint2(0, 0, height);
            vtkTubeFilter tf = vtkTubeFilter.New();

            tf.SetInputConnection(ls.GetOutputPort());
            tf.SetRadius(radius);
            tf.SetNumberOfSides(100);
            tf.CappingOff();

            vtkPolyDataMapper dm = vtkPolyDataMapper.New();

            dm.SetInputConnection(tf.GetOutputPort());

            vtkActor a2 = vtkActor.New();

            a2.SetMapper(dm);

            a2.SetProperty(pp);

            pp.SetOpacity(0.5);
            actor.SetProperty(pp);

            actors.AddItem(a2);
        }
Exemplo n.º 5
0
        static public vtkProp3D genSTLActor(CompontData data, vtkProperty pro)
        {
            if (data.restriction != null)
            {
                return(genActorByRestriction(data, pro));
            }
            vtkSTLReader reader = vtkSTLReader.New();

            reader.SetFileName(data.param_str);
            reader.Update();
            return(genUserActor(data, reader.GetOutputPort(), pro));
        }
Exemplo n.º 6
0
        static public vtkProp3D genActorByRestriction(CompontData data, vtkProperty pro)
        {
            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();

            mapper.SetInputConnection(calcRestriction(data));
            mapper.ScalarVisibilityOff();
            // The actor links the data pipeline to the rendering subsystem
            vtkActor actor = vtkActor.New();

            actor.SetProperty(pro);
            actor.SetMapper(mapper);
            return(actor);
        }
Exemplo n.º 7
0
        private vtkActor DiskSector(double innerRadius, double radius, double clip1X, double clip1Y, double clip2X, double clip2Y, Color color)
        {
            vtkProperty arcColor = vtkProperty.New();

            arcColor.SetColor(color.r, color.g, color.b);

            vtkDiskSource outerDisk = vtkDiskSource.New();

            outerDisk.SetCircumferentialResolution(50);
            outerDisk.SetRadialResolution(50);
            outerDisk.SetInnerRadius(innerRadius);
            outerDisk.SetOuterRadius(innerRadius + radius);

            // Define a clipping plane
            vtkPlane clipPlane = vtkPlane.New();

            clipPlane.SetNormal(clip1X, clip1Y, 0);
            clipPlane.SetOrigin(0.0, 0.0, 0.0);

            // Define a clipping plane
            vtkPlane clipPlane2 = vtkPlane.New();

            clipPlane2.SetNormal(clip2X, clip2Y, 0);
            clipPlane2.SetOrigin(0, 0, 0);


            vtkClipPolyData clipper = vtkClipPolyData.New();

            clipper.SetInputConnection(outerDisk.GetOutputPort());
            clipper.SetClipFunction(clipPlane);

            vtkClipPolyData clipper2 = vtkClipPolyData.New();

            clipper2.SetInputConnection(clipper.GetOutputPort());
            clipper2.SetClipFunction(clipPlane2);


            // Visualize
            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();

            mapper.SetInputConnection(clipper2.GetOutputPort());


            vtkActor actor = vtkActor.New();

            actor.SetMapper(mapper);
            actor.SetProperty(arcColor);


            return(actor);
        }
Exemplo n.º 8
0
        private void SolidClip()
        {
            // Create a superquadric
            vtkSuperquadricSource superquadricSource = vtkSuperquadricSource.New();

            superquadricSource.SetPhiRoundness(3.1);
            superquadricSource.SetThetaRoundness(2.2);

            // Define a clipping plane
            vtkPlane clipPlane = vtkPlane.New();

            clipPlane.SetNormal(1.0, -1.0, -1.0);
            clipPlane.SetOrigin(0.0, 0.0, 0.0);

            // Clip the source with the plane
            vtkClipPolyData clipper = vtkClipPolyData.New();

#if VTK_MAJOR_VERSION_5
            clipper.SetInputConnection(superquadricSource.GetOutputPort());
#else
            clipper.SetInputData(superquadricSource);
#endif
            clipper.SetClipFunction(clipPlane);

            //Create a mapper and actor
            vtkPolyDataMapper superquadricMapper = vtkPolyDataMapper.New();
#if VTK_MAJOR_VERSION_5
            superquadricMapper.SetInputConnection(clipper.GetOutputPort());
#else
            superquadricMapper.SetInputData(clipper);
#endif
            vtkActor superquadricActor = vtkActor.New();
            superquadricActor.SetMapper(superquadricMapper);

            // Create a property to be used for the back faces. Turn off all
            // shading by specifying 0 weights for specular and diffuse. Max the
            // ambient.
            vtkProperty backFaces = vtkProperty.New();
            backFaces.SetSpecular(0.0);
            backFaces.SetDiffuse(0.0);
            backFaces.SetAmbient(1.0);
            backFaces.SetAmbientColor(1.0000, 0.3882, 0.2784);

            superquadricActor.SetBackfaceProperty(backFaces);
            // get a reference to the renderwindow of our renderWindowControl1
            vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;
            // renderer
            vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer();
            // add our actor to the renderer
            renderer.AddActor(superquadricActor);
        }
    /// <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();
    }
Exemplo n.º 10
0
        static public vtkProp3D genActor(List <GaussianCluster> data)
        {
            vtkProperty pro = new vtkProperty();

            // 默认颜色
            pro.SetColor(config.cone_color[0], config.cone_color[1],
                         config.cone_color[2]);
            pro.SetOpacity(0.4);
            vtkAppendPolyData polydata = vtkAppendPolyData.New();

            for (int i = 1; i < data.Count; i++)
            {
                var cluster = data[i];
                System.Windows.Forms.MessageBox.Show("cluster.start_radius:" + cluster.start_radius.ToString() +
                                                     "cluster.distance:" + cluster.distance.ToString() +
                                                     "cluster.is_foucs:" + cluster.is_foucs.ToString() +
                                                     "cluster.foucs_radius:" + cluster.foucs_radius.ToString());
                vtkTransform transform = vtkTransform.New();
                transform.Translate(cluster.coordinate.pos.x, cluster.coordinate.pos.y, cluster.coordinate.pos.z);
                transform.RotateWXYZ(cluster.coordinate.rotate_theta, cluster.coordinate.rotate_axis.x,
                                     cluster.coordinate.rotate_axis.y, cluster.coordinate.rotate_axis.z);

                vtkTransformPolyDataFilter transFilter = vtkTransformPolyDataFilter.New();
                transFilter.SetInputConnection(combiFrustumCone(cluster.start_radius,
                                                                1, cluster.angle, true, 0.01));
                transFilter.SetTransform(transform);
                transFilter.Update();
                polydata.AddInputConnection(transFilter.GetOutputPort());
            }

            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();

            mapper.SetInputConnection(polydata.GetOutputPort());
            mapper.ScalarVisibilityOff();
            // The actor links the data pipeline to the rendering subsystem
            vtkActor actor = vtkActor.New();

            actor.SetProperty(pro);
            actor.SetMapper(mapper);
            return(actor);
        }
Exemplo n.º 11
0
        static public vtkProp3D genCylinderActor(CompontData data, vtkProperty pro)
        {
            double            r        = data.param[0];
            double            h        = data.param[1];
            vtkCylinderSource cylinder = vtkCylinderSource.New();

            cylinder.SetHeight(h);
            cylinder.SetRadius(r);
            cylinder.SetCenter(0, h / 2, 0);
            cylinder.SetResolution(40);
            cylinder.Update();
            vtkTransform transform = vtkTransform.New();

            transform.RotateWXYZ(90, 1, 0, 0);

            vtkTransformPolyDataFilter transFilter = vtkTransformPolyDataFilter.New();

            transFilter.SetInputConnection(cylinder.GetOutputPort());
            transFilter.SetTransform(transform); //use vtkTransform (or maybe vtkLinearTransform)
            transFilter.Update();

            return(genUserActor(data, transFilter.GetOutputPort(), pro));
        }
Exemplo n.º 12
0
        static public vtkProp3D genUserActor(CompontData data, vtkAlgorithmOutput vtkAlgorithmOutput,
                                             vtkProperty pro)
        {
            vtkTransform transform = vtkTransform.New();

            // 用户自定义平移旋转 (先移动后旋转)
            transform.Translate(data.coor.pos.x, data.coor.pos.y, data.coor.pos.z);
            transform.RotateWXYZ(data.coor.rotate_theta, data.coor.rotate_axis.x, data.coor.rotate_axis.y, data.coor.rotate_axis.z);

            vtkTransformPolyDataFilter transFilter = vtkTransformPolyDataFilter.New();

            transFilter.SetInputConnection(vtkAlgorithmOutput);
            transFilter.SetTransform(transform); //use vtkTransform (or maybe vtkLinearTransform)
            transFilter.Update();

            //vtkShrinkPolyData shrink = vtkShrinkPolyData.New();
            //shrink.SetInputConnection(transFilter.GetOutputPort());
            //shrink.SetShrinkFactor(1);

            // 改
            //vtkSTLWriter writer = vtkSTLWriter.New();
            //calPolyData(polyData, 0.01);
            //writer.SetInputConnection(transFilter.GetOutputPort());
            //writer.SetFileName("test.stl");
            //writer.Update();

            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();

            mapper.SetInputConnection(transFilter.GetOutputPort());
            mapper.ScalarVisibilityOff();
            // The actor links the data pipeline to the rendering subsystem
            vtkActor actor = vtkActor.New();

            actor.SetProperty(pro);
            actor.SetMapper(mapper);
            return(actor);
        }
Exemplo n.º 13
0
        protected override void OnMouseDoubleClick(MouseEventArgs e)
        {
            if (pick_trigger == false)
            {
                MessageBox.Show("请先选择靶点或穿刺点!");
                return;
            }
            if (pick_tag == true)
            {
                control_renderer.RemoveActor(this.spheres[this.sphere_num - 1]);
                this.point_num  -= 1;
                this.sphere_num -= 1;
            }
            if (this.sphere_num >= 6)
            {
                MessageBoxButtons messButton = MessageBoxButtons.OKCancel;
                DialogResult      dr         = MessageBox.Show("点数已满,是否清空?", "系统提示", messButton);
                if (dr == DialogResult.OK)
                {
                    for (int i = 0; i < this.sphere_num; i++)
                    {
                        control_renderer.RemoveActor(this.spheres[i]);
                        this.points = new double[20, 3];
                    }
                    this.point_num  = 0;
                    this.sphere_num = 0;
                }
                return;
            }
            //vtkRenderWindowInteractor inter_ren = this.GetInteractor();
            Console.WriteLine(this.point_num.ToString());
            double[] temp   = new double[2];
            double[] picked = new double[3];
            temp[0] = this.GetInteractor().GetEventPosition()[0];
            temp[1] = this.GetInteractor().GetEventPosition()[1];
            Console.WriteLine("picked position" + temp[0].ToString() + " , " + temp[1].ToString());
            this.GetInteractor().GetPicker().Pick(temp[0], temp[1], 0, this.GetInteractor().GetRenderWindow().GetRenderers().GetFirstRenderer());
            picked = this.GetInteractor().GetPicker().GetPickPosition();
            Console.WriteLine("picked point:" + picked[0].ToString() + " , " + picked[1].ToString() + " , " + picked[2].ToString());
            for (int i = 0; i < 3; i++)
            {
                this.points[point_num, i] = picked[i];
            }
            this.point_num++;
            base.OnMouseDoubleClick(e);

            //import a sphere object into scence
            vtkSphereSource sphere = new vtkSphereSource();

            sphere.SetCenter(picked[0], picked[1], picked[2]);
            sphere.SetRadius(3.0);

            vtkPolyDataMapper mapper = new vtkPolyDataMapper();

            mapper.SetInputConnection(sphere.GetOutputPort());

            vtkProperty property = new vtkProperty();

            property.SetColor(color[0], color[1], color[2]);
            property.SetOpacity(1);

            this.spheres[this.sphere_num] = new vtkActor();
            this.spheres[this.sphere_num].SetMapper(mapper);
            this.spheres[this.sphere_num].SetProperty(property);

            this.control_renderer.AddActor(this.spheres[this.sphere_num]);

            this.sphere_num++;
            this.pick_tag = true;
            //点数越界后弹窗确定是否清空
        }
Exemplo n.º 14
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVtextureThreshold(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[]
          //[]
          pl3d = new vtkMultiBlockPLOT3DReader();
          pl3d.SetXYZFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/bluntfinxyz.bin");
          pl3d.SetQFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/bluntfinq.bin");
          pl3d.SetScalarFunctionNumber((int)100);
          pl3d.SetVectorFunctionNumber((int)202);
          pl3d.Update();
          // wall[]
          //[]
          wall = new vtkStructuredGridGeometryFilter();
          wall.SetInputData(pl3d.GetOutput().GetBlock(0));
          wall.SetExtent((int)0,(int)100,(int)0,(int)0,(int)0,(int)100);
          wallMap = vtkPolyDataMapper.New();
          wallMap.SetInputConnection((vtkAlgorithmOutput)wall.GetOutputPort());
          wallMap.ScalarVisibilityOff();
          wallActor = new vtkActor();
          wallActor.SetMapper((vtkMapper)wallMap);
          wallActor.GetProperty().SetColor((double)0.8,(double)0.8,(double)0.8);
          // fin[]
          // []
          fin = new vtkStructuredGridGeometryFilter();
          fin.SetInputData(pl3d.GetOutput().GetBlock(0));
          fin.SetExtent((int)0,(int)100,(int)0,(int)100,(int)0,(int)0);
          finMap = vtkPolyDataMapper.New();
          finMap.SetInputConnection((vtkAlgorithmOutput)fin.GetOutputPort());
          finMap.ScalarVisibilityOff();
          finActor = new vtkActor();
          finActor.SetMapper((vtkMapper)finMap);
          finActor.GetProperty().SetColor((double)0.8,(double)0.8,(double)0.8);
          // planes to threshold[]
          tmap = new vtkStructuredPointsReader();
          tmap.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/texThres2.vtk");
          texture = new vtkTexture();
          texture.SetInputConnection((vtkAlgorithmOutput)tmap.GetOutputPort());
          texture.InterpolateOff();
          texture.RepeatOff();
          plane1 = new vtkStructuredGridGeometryFilter();
          plane1.SetInputData(pl3d.GetOutput().GetBlock(0));
          plane1.SetExtent((int)10,(int)10,(int)0,(int)100,(int)0,(int)100);
          thresh1 = new vtkThresholdTextureCoords();
          thresh1.SetInputConnection((vtkAlgorithmOutput)plane1.GetOutputPort());
          thresh1.ThresholdByUpper((double)1.5);
          plane1Map = new vtkDataSetMapper();
          plane1Map.SetInputConnection((vtkAlgorithmOutput)thresh1.GetOutputPort());
          plane1Map.SetScalarRange((double)((vtkDataSet)pl3d.GetOutput().GetBlock(0)).GetScalarRange()[0],
          (double)((vtkDataSet)pl3d.GetOutput().GetBlock(0)).GetScalarRange()[1]);
          plane1Actor = new vtkActor();
          plane1Actor.SetMapper((vtkMapper)plane1Map);
          plane1Actor.SetTexture((vtkTexture)texture);
          plane1Actor.GetProperty().SetOpacity((double)0.999);
          plane2 = new vtkStructuredGridGeometryFilter();
          plane2.SetInputData(pl3d.GetOutput().GetBlock(0));
          plane2.SetExtent((int)30,(int)30,(int)0,(int)100,(int)0,(int)100);
          thresh2 = new vtkThresholdTextureCoords();
          thresh2.SetInputConnection((vtkAlgorithmOutput)plane2.GetOutputPort());
          thresh2.ThresholdByLower((double)1.5);
          plane2Map = new vtkDataSetMapper();
          plane2Map.SetInputConnection((vtkAlgorithmOutput)thresh2.GetOutputPort());
          plane2Map.SetScalarRange((double)((vtkDataSet)pl3d.GetOutput().GetBlock(0)).GetScalarRange()[0],
          (double)((vtkDataSet)pl3d.GetOutput().GetBlock(0)).GetScalarRange()[1]);
          plane2Actor = new vtkActor();
          plane2Actor.SetMapper((vtkMapper)plane2Map);
          plane2Actor.SetTexture((vtkTexture)texture);
          plane2Actor.GetProperty().SetOpacity((double)0.999);
          plane3 = new vtkStructuredGridGeometryFilter();
          plane3.SetInputData(pl3d.GetOutput().GetBlock(0));
          plane3.SetExtent((int)35,(int)35,(int)0,(int)100,(int)0,(int)100);
          thresh3 = new vtkThresholdTextureCoords();
          thresh3.SetInputConnection((vtkAlgorithmOutput)plane3.GetOutputPort());
          thresh3.ThresholdBetween((double)1.5,(double)1.8);
          plane3Map = new vtkDataSetMapper();
          plane3Map.SetInputConnection((vtkAlgorithmOutput)thresh3.GetOutputPort());
          plane3Map.SetScalarRange((double)((vtkDataSet)pl3d.GetOutput().GetBlock(0)).GetScalarRange()[0],
          (double)((vtkDataSet)pl3d.GetOutput().GetBlock(0)).GetScalarRange()[1]);
          plane3Actor = new vtkActor();
          plane3Actor.SetMapper((vtkMapper)plane3Map);
          plane3Actor.SetTexture((vtkTexture)texture);
          plane3Actor.GetProperty().SetOpacity((double)0.999);
          // outline[]
          outline = new vtkStructuredGridOutlineFilter();
          outline.SetInputData(pl3d.GetOutput().GetBlock(0));
          outlineMapper = vtkPolyDataMapper.New();
          outlineMapper.SetInputConnection((vtkAlgorithmOutput)outline.GetOutputPort());
          outlineActor = new vtkActor();
          outlineActor.SetMapper((vtkMapper)outlineMapper);
          outlineProp = outlineActor.GetProperty();
          outlineProp.SetColor((double)0,(double)0,(double)0);
          // Add the actors to the renderer, set the background and size[]
          //[]
          ren1.AddActor((vtkProp)outlineActor);
          ren1.AddActor((vtkProp)wallActor);
          ren1.AddActor((vtkProp)finActor);
          ren1.AddActor((vtkProp)plane1Actor);
          ren1.AddActor((vtkProp)plane2Actor);
          ren1.AddActor((vtkProp)plane3Actor);
          ren1.SetBackground((double)1,(double)1,(double)1);
          renWin.SetSize((int)256,(int)256);
          cam1 = new vtkCamera();
          cam1.SetClippingRange((double)1.51176,(double)75.5879);
          cam1.SetFocalPoint((double)2.33749,(double)2.96739,(double)3.61023);
          cam1.SetPosition((double)10.8787,(double)5.27346,(double)15.8687);
          cam1.SetViewAngle((double)30);
          cam1.SetViewUp((double)-0.0610856,(double)0.987798,(double)-0.143262);
          ren1.SetActiveCamera((vtkCamera)cam1);
          iren.Initialize();
          // render the image[]
          //[]
          // prevent the tk window from showing up then start the event loop[]

        //deleteAllVTKObjects();
    }
 ///<summary> A Set Method for Static Variables </summary>
 public static void Setbf(vtkProperty toSet)
 {
     bf = toSet;
 }
Exemplo n.º 16
0
 ///<summary> A Set Method for Static Variables </summary>
 public static void SetoutlineProp(vtkProperty toSet)
 {
     outlineProp = toSet;
 }
Exemplo n.º 17
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVSelectionLoop(String [] argv)
    {
        //Prefix Content is: ""

        //[]
        // Demonstrate the use of implicit selection loop as well as closest point[]
        // connectivity[]
        //[]
        // create pipeline[]
        //[]
        sphere = new vtkSphereSource();
        sphere.SetRadius((double)1);
        sphere.SetPhiResolution((int)100);
        sphere.SetThetaResolution((int)100);
        selectionPoints = new vtkPoints();
        selectionPoints.InsertPoint((int)0, (double)0.07325, (double)0.8417, (double)0.5612);
        selectionPoints.InsertPoint((int)1, (double)0.07244, (double)0.6568, (double)0.7450);
        selectionPoints.InsertPoint((int)2, (double)0.1727, (double)0.4597, (double)0.8850);
        selectionPoints.InsertPoint((int)3, (double)0.3265, (double)0.6054, (double)0.7309);
        selectionPoints.InsertPoint((int)4, (double)0.5722, (double)0.5848, (double)0.5927);
        selectionPoints.InsertPoint((int)5, (double)0.4305, (double)0.8138, (double)0.4189);
        loop = new vtkImplicitSelectionLoop();
        loop.SetLoop((vtkPoints)selectionPoints);
        extract = new vtkExtractGeometry();
        extract.SetInputConnection((vtkAlgorithmOutput)sphere.GetOutputPort());
        extract.SetImplicitFunction((vtkImplicitFunction)loop);
        connect = new vtkConnectivityFilter();
        connect.SetInputConnection((vtkAlgorithmOutput)extract.GetOutputPort());
        connect.SetExtractionModeToClosestPointRegion();
        connect.SetClosestPoint((double)selectionPoints.GetPoint((int)0)[0], (double)selectionPoints.GetPoint((int)0)[1], (double)selectionPoints.GetPoint((int)0)[2]);
        clipMapper = new vtkDataSetMapper();
        clipMapper.SetInputConnection((vtkAlgorithmOutput)connect.GetOutputPort());
        backProp = new vtkProperty();
        backProp.SetDiffuseColor((double)1.0000, 0.3882, 0.2784);
        clipActor = new vtkActor();
        clipActor.SetMapper((vtkMapper)clipMapper);
        clipActor.GetProperty().SetColor((double)0.2000, 0.6300, 0.7900);
        clipActor.SetBackfaceProperty((vtkProperty)backProp);
        // 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)clipActor);
        ren1.SetBackground((double)1, (double)1, (double)1);
        ren1.ResetCamera();
        ren1.GetActiveCamera().Azimuth((double)30);
        ren1.GetActiveCamera().Elevation((double)30);
        ren1.GetActiveCamera().Dolly((double)1.2);
        ren1.ResetCameraClippingRange();
        renWin.SetSize((int)400, (int)400);
        renWin.Render();
        // render the image[]
        //[]
        // prevent the tk window from showing up then start the event loop[]

//deleteAllVTKObjects();
    }
Exemplo n.º 18
0
 ///<summary> A Set Method for Static Variables </summary>
 public static void SetoutlineProp(vtkProperty toSet)
 {
     outlineProp = toSet;
 }
Exemplo n.º 19
0
        /// <summary>
        /// 绘制立长方体的边缘
        /// </summary>
        /// <param name="bgColor">边缘的颜色</param>
        /// <param name="actors">添加至该对象</param>
        public void AddContainerEdgeToActorCollection(byte[] bgColor, ref vtkActorCollection actors)
        {
            vtkProperty pp = vtkProperty.New();

            pp.SetOpacity(0.5);
            pp.SetColor(bgColor[0], bgColor[1], bgColor[2]);
            pp.SetLineWidth(5);
            pp.SetLighting(false);

            vtkCubeSource cs = vtkCubeSource.New();

            cs.SetCenter(sideLen / 2, sideLen / 2, height / 2);
            cs.SetXLength(sideLen);
            cs.SetYLength(sideLen);
            cs.SetZLength(height);

            #region 采用描点的方式绘制长方体 只需要添加到mapper.SetInput(pd);即可
            //vtkPoints points = vtkPoints.New();
            //points.InsertNextPoint(0 + offset[0], 0 + offset[1], 0 + offset[2]);
            //points.InsertNextPoint(sideLen + offset[0], 0 + offset[1], 0 + offset[2]);
            //points.InsertNextPoint(sideLen + offset[0], sideLen + offset[1], 0 + offset[2]);
            //points.InsertNextPoint(0 + offset[0], sideLen + offset[1], 0 + offset[2]);

            //points.InsertNextPoint(0 + offset[0], sideLen + offset[1], height + offset[2]);
            //points.InsertNextPoint(sideLen + offset[0], sideLen + offset[1], height + offset[2]);
            //points.InsertNextPoint(sideLen + offset[0], 0 + offset[1], height + offset[2]);
            //points.InsertNextPoint(0 + offset[0], 0 + offset[1], height + offset[2]);

            //vtkPolyData pd = vtkPolyData.New();

            //vtkLine line = vtkLine.New();

            //vtkCellArray cellArr = vtkCellArray.New();

            ////描出边框
            //for (int i = 0; i < 4; i++)
            //{
            //    line.GetPointIds().SetId(0, i);
            //    line.GetPointIds().SetId(1, (i + 1) % 4);
            //    cellArr.InsertNextCell(line);

            //    line.GetPointIds().SetId(0, i + 4);
            //    line.GetPointIds().SetId(1, (i + 1) % 4 + 4);
            //    cellArr.InsertNextCell(line);

            //    line.GetPointIds().SetId(0, i);
            //    line.GetPointIds().SetId(1, 7 - i);
            //    cellArr.InsertNextCell(line);

            //}

            //IntPtr iColor = Marshal.AllocHGlobal(bgColor.Length);
            //Marshal.Copy(bgColor, 0, iColor, bgColor.Length);

            //vtkUnsignedCharArray colors = vtkUnsignedCharArray.New();

            //colors.SetNumberOfComponents(3);
            //for (int i = 0; i < cellArr.GetNumberOfCells(); i++)
            //{
            //    colors.InsertNextTupleValue(iColor);
            //}

            //pd.SetPoints(points);
            //pd.SetLines(cellArr);
            //pd.GetCellData().SetScalars(colors);
            //Marshal.FreeHGlobal(iColor);
            #endregion

            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();
            //mapper.SetInput(pd);
            mapper.SetInputConnection(cs.GetOutputPort());
            vtkActor actor = vtkActor.New();
            actor.SetMapper(mapper);
            actor.SetProperty(pp);

            actors.AddItem(actor);
        }
Exemplo n.º 20
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVSelectionLoop(String [] argv)
    {
        //Prefix Content is: ""

          //[]
          // Demonstrate the use of implicit selection loop as well as closest point[]
          // connectivity[]
          //[]
          // create pipeline[]
          //[]
          sphere = new vtkSphereSource();
          sphere.SetRadius((double)1);
          sphere.SetPhiResolution((int)100);
          sphere.SetThetaResolution((int)100);
          selectionPoints = new vtkPoints();
          selectionPoints.InsertPoint((int)0,(double)0.07325,(double)0.8417,(double)0.5612);
          selectionPoints.InsertPoint((int)1,(double)0.07244,(double)0.6568,(double)0.7450);
          selectionPoints.InsertPoint((int)2,(double)0.1727,(double)0.4597,(double)0.8850);
          selectionPoints.InsertPoint((int)3,(double)0.3265,(double)0.6054,(double)0.7309);
          selectionPoints.InsertPoint((int)4,(double)0.5722,(double)0.5848,(double)0.5927);
          selectionPoints.InsertPoint((int)5,(double)0.4305,(double)0.8138,(double)0.4189);
          loop = new vtkImplicitSelectionLoop();
          loop.SetLoop((vtkPoints)selectionPoints);
          extract = new vtkExtractGeometry();
          extract.SetInputConnection((vtkAlgorithmOutput)sphere.GetOutputPort());
          extract.SetImplicitFunction((vtkImplicitFunction)loop);
          connect = new vtkConnectivityFilter();
          connect.SetInputConnection((vtkAlgorithmOutput)extract.GetOutputPort());
          connect.SetExtractionModeToClosestPointRegion();
          connect.SetClosestPoint((double)selectionPoints.GetPoint((int)0)[0], (double)selectionPoints.GetPoint((int)0)[1],(double)selectionPoints.GetPoint((int)0)[2]);
          clipMapper = new vtkDataSetMapper();
          clipMapper.SetInputConnection((vtkAlgorithmOutput)connect.GetOutputPort());
          backProp = new vtkProperty();
          backProp.SetDiffuseColor((double) 1.0000, 0.3882, 0.2784 );
          clipActor = new vtkActor();
          clipActor.SetMapper((vtkMapper)clipMapper);
          clipActor.GetProperty().SetColor((double) 0.2000, 0.6300, 0.7900 );
          clipActor.SetBackfaceProperty((vtkProperty)backProp);
          // 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)clipActor);
          ren1.SetBackground((double)1,(double)1,(double)1);
          ren1.ResetCamera();
          ren1.GetActiveCamera().Azimuth((double)30);
          ren1.GetActiveCamera().Elevation((double)30);
          ren1.GetActiveCamera().Dolly((double)1.2);
          ren1.ResetCameraClippingRange();
          renWin.SetSize((int)400,(int)400);
          renWin.Render();
          // render the image[]
          //[]
          // prevent the tk window from showing up then start the event loop[]

        //deleteAllVTKObjects();
    }
Exemplo n.º 21
0
 ///<summary> A Set Method for Static Variables </summary>
 public static void SetbackProp(vtkProperty toSet)
 {
     backProp = toSet;
 }
Exemplo n.º 22
0
 ///<summary> A Set Method for Static Variables </summary>
 public static void SetbackProp(vtkProperty toSet)
 {
     backProp = toSet;
 }
Exemplo n.º 23
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVpolyConn(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[]
          //[]
          pl3d = new vtkMultiBlockPLOT3DReader();
          pl3d.SetXYZFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/combxyz.bin");
          pl3d.SetQFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/combq.bin");
          pl3d.SetScalarFunctionNumber((int)100);
          pl3d.SetVectorFunctionNumber((int)202);
          pl3d.Update();
          // planes to connect[]
          plane1 = new vtkStructuredGridGeometryFilter();
          plane1.SetInputData((vtkDataSet)pl3d.GetOutput().GetBlock(0));
          plane1.SetExtent((int)20,(int)20,(int)0,(int)100,(int)0,(int)100);
          conn = new vtkPolyDataConnectivityFilter();
          conn.SetInputConnection((vtkAlgorithmOutput)plane1.GetOutputPort());
          conn.ScalarConnectivityOn();
          conn.SetScalarRange((double)0.19,(double)0.25);
          plane1Map = vtkPolyDataMapper.New();
          plane1Map.SetInputConnection((vtkAlgorithmOutput)conn.GetOutputPort());
          plane1Map.SetScalarRange((double)((vtkDataSet)pl3d.GetOutput().GetBlock(0)).GetScalarRange()[0],
          (double)((vtkDataSet)pl3d.GetOutput().GetBlock(0)).GetScalarRange()[1]);
          plane1Actor = new vtkActor();
          plane1Actor.SetMapper((vtkMapper)plane1Map);
          plane1Actor.GetProperty().SetOpacity((double)0.999);
          // outline[]
          outline = new vtkStructuredGridOutlineFilter();
          outline.SetInputData((vtkDataSet)pl3d.GetOutput().GetBlock(0));
          outlineMapper = vtkPolyDataMapper.New();
          outlineMapper.SetInputConnection((vtkAlgorithmOutput)outline.GetOutputPort());
          outlineActor = new vtkActor();
          outlineActor.SetMapper((vtkMapper)outlineMapper);
          outlineProp = outlineActor.GetProperty();
          outlineProp.SetColor((double)0,(double)0,(double)0);
          // Add the actors to the renderer, set the background and size[]
          //[]
          ren1.AddActor((vtkProp)outlineActor);
          ren1.AddActor((vtkProp)plane1Actor);
          ren1.SetBackground((double)1,(double)1,(double)1);
          renWin.SetSize((int)300,(int)300);
          cam1 = new vtkCamera();
          cam1.SetClippingRange((double)14.29,(double)63.53);
          cam1.SetFocalPoint((double)8.58522,(double)1.58266,(double)30.6486);
          cam1.SetPosition((double)37.6808,(double)-20.1298,(double)35.4016);
          cam1.SetViewAngle((double)30);
          cam1.SetViewUp((double)-0.0566235,(double)0.140504,(double)0.98846);
          ren1.SetActiveCamera((vtkCamera)cam1);
          iren.Initialize();
          // render the image[]
          //[]
          // prevent the tk window from showing up then start the event loop[]

        //deleteAllVTKObjects();
    }
Exemplo n.º 24
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVprobe(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);
          // cut data[]
          pl3d = new vtkPLOT3DReader();
          pl3d.SetXYZFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/combxyz.bin");
          pl3d.SetQFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/combq.bin");
          pl3d.SetScalarFunctionNumber((int)100);
          pl3d.SetVectorFunctionNumber((int)202);
          pl3d.Update();
          plane = new vtkPlane();
          plane.SetOrigin(pl3d.GetOutput().GetCenter()[0],pl3d.GetOutput().GetCenter()[1],pl3d.GetOutput().GetCenter()[2]);
          plane.SetNormal((double)-0.287,(double)0,(double)0.9579);
          planeCut = new vtkCutter();
          planeCut.SetInputConnection((vtkAlgorithmOutput)pl3d.GetOutputPort());
          planeCut.SetCutFunction((vtkImplicitFunction)plane);
          probe = new vtkProbeFilter();
          probe.SetInputConnection((vtkAlgorithmOutput)planeCut.GetOutputPort());
          probe.SetSourceConnection((vtkAlgorithmOutput)pl3d.GetOutputPort());
          cutMapper = new vtkDataSetMapper();
          cutMapper.SetInputConnection((vtkAlgorithmOutput)probe.GetOutputPort());
          cutMapper.SetScalarRange((double)((vtkStructuredGrid)pl3d.GetOutput()).GetPointData().GetScalars().GetRange()[0],
          (double)((vtkStructuredGrid)pl3d.GetOutput()).GetPointData().GetScalars().GetRange()[1]);
          cutActor = new vtkActor();
          cutActor.SetMapper((vtkMapper)cutMapper);
          //extract plane[]
          compPlane = new vtkStructuredGridGeometryFilter();
          compPlane.SetInputConnection((vtkAlgorithmOutput)pl3d.GetOutputPort());
          compPlane.SetExtent((int)0,(int)100,(int)0,(int)100,(int)9,(int)9);
          planeMapper = vtkPolyDataMapper.New();
          planeMapper.SetInputConnection((vtkAlgorithmOutput)compPlane.GetOutputPort());
          planeMapper.ScalarVisibilityOff();
          planeActor = new vtkActor();
          planeActor.SetMapper((vtkMapper)planeMapper);
          planeActor.GetProperty().SetRepresentationToWireframe();
          planeActor.GetProperty().SetColor((double)0,(double)0,(double)0);
          //outline[]
          outline = new vtkStructuredGridOutlineFilter();
          outline.SetInputConnection((vtkAlgorithmOutput)pl3d.GetOutputPort());
          outlineMapper = vtkPolyDataMapper.New();
          outlineMapper.SetInputConnection((vtkAlgorithmOutput)outline.GetOutputPort());
          outlineActor = new vtkActor();
          outlineActor.SetMapper((vtkMapper)outlineMapper);
          outlineProp = outlineActor.GetProperty();
          outlineProp.SetColor((double)0,(double)0,(double)0);
          // Add the actors to the renderer, set the background and size[]
          //[]
          ren1.AddActor((vtkProp)outlineActor);
          ren1.AddActor((vtkProp)planeActor);
          ren1.AddActor((vtkProp)cutActor);
          ren1.SetBackground((double)1,(double)1,(double)1);
          renWin.SetSize((int)400,(int)300);
          cam1 = ren1.GetActiveCamera();
          cam1.SetClippingRange((double)11.1034,(double)59.5328);
          cam1.SetFocalPoint((double)9.71821,(double)0.458166,(double)29.3999);
          cam1.SetPosition((double)-2.95748,(double)-26.7271,(double)44.5309);
          cam1.SetViewUp((double)0.0184785,(double)0.479657,(double)0.877262);
          iren.Initialize();
          // render the image[]
          //[]
          // prevent the tk window from showing up then start the event loop[]

        //deleteAllVTKObjects();
    }