Beispiel #1
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);
        }
Beispiel #2
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);
        }
Beispiel #3
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);
        }
Beispiel #4
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;
            //点数越界后弹窗确定是否清空
        }
Beispiel #5
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);
        }