Exemple #1
0
        static public vtkAlgorithmOutput genFrustumCone(double total_dis, double end_radius,
                                                        double distance, bool is_reverse)
        {
            vtkConeSource cone = vtkConeSource.New();

            cone.SetHeight(total_dis * 1.2);
            cone.SetRadius(end_radius * 1.2);
            cone.SetCenter(0, 0, total_dis * 0.4);
            cone.SetResolution(80);
            cone.SetDirection(0, 0, 1);
            cone.Update();

            vtkPlane plane = vtkPlane.New();

            plane.SetOrigin(0, 0, 0);
            plane.SetNormal(0, 0, 1);

            vtkClipPolyData clipPolyData = vtkClipPolyData.New();

            clipPolyData.SetInputConnection(cone.GetOutputPort());
            clipPolyData.SetClipFunction(plane);
            clipPolyData.GenerateClippedOutputOn();
            clipPolyData.Update();

            vtkPlane plane2 = vtkPlane.New();

            plane2.SetOrigin(0, 0, distance);
            plane2.SetNormal(0, 0, -1);

            vtkClipPolyData clipPolyData2 = vtkClipPolyData.New();

            clipPolyData2.SetInputConnection(clipPolyData.GetOutputPort());
            clipPolyData2.SetClipFunction(plane2);
            clipPolyData2.GenerateClippedOutputOn();
            clipPolyData2.Update();

            if (is_reverse)
            {
                vtkTransform transform = vtkTransform.New();
                transform.RotateWXYZ(180, 0, 1, 0);
                transform.Translate(0, 0, -distance);

                vtkTransformPolyDataFilter transFilter = vtkTransformPolyDataFilter.New();
                transFilter.SetInputConnection(clipPolyData2.GetOutputPort());
                transFilter.SetTransform(transform); //use vtkTransform (or maybe vtkLinearTransform)
                transFilter.Update();
                return(transFilter.GetOutputPort());
            }
            return(clipPolyData2.GetOutputPort());
        }
Exemple #2
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);
        }
Exemple #3
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));
        }
Exemple #4
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);
        }
Exemple #5
0
        static public vtkProp3D genFieldActor(FieldBase data)
        {
            int    N_width = data.Ex.Count;
            int    M_depth = data.Ex.Count;
            double ds      = data.ds_x;
            double width   = N_width * ds;
            double depth   = M_depth * ds;

            vtkImageData img = vtkImageData.New();

            img.SetDimensions(N_width, M_depth, 1);
            img.SetSpacing(0.01 * ds / 0.01, 0.01 * ds / 0.01, 1);
            img.SetScalarTypeToDouble();
            img.SetNumberOfScalarComponents(1);

            double max = -100000000, min = 0;
            List <List <Complex> > tempEH = null;

            int          content          = 1;
            bool         isPhs            = false;
            bool         isLinear         = true;
            const double dB_RABNGE        = 60;

            switch (content)
            {
            case 0:
                tempEH = data.Ex;
                break;

            case 1:
                tempEH = data.Ey;
                break;

            case 2:
                tempEH = data.Ez;
                break;

            case 3:
                tempEH = data.Hx;
                break;

            case 4:
                tempEH = data.Hy;
                break;

            case 5:
                tempEH = data.Hz;
                break;

            default:
                break;
            }
            double[] data_tmp = new double[M_depth * N_width];
            int      count    = 0;

            for (int j = 0; j < M_depth; j++)
            {
                for (int i = 0; i < N_width; i++)
                {
                    double  tempD;
                    Complex temp;
                    temp = tempEH[i][j];

                    if (isPhs)
                    {
                        if (temp.real != 0)
                        {
                            tempD = Math.Atan2(temp.imag, temp.real);
                        }
                        else
                        {
                            tempD = 0;
                        }
                    }
                    else
                    {
                        tempD = Math.Pow((temp.real * temp.real + temp.imag * temp.imag), 0.5);
                    }
                    if (!isLinear && !isPhs)
                    {
                        tempD = 20 * Math.Log(tempD + 0.000000001);
                        if (min > tempD)
                        {
                            min = tempD;
                        }
                        if (max < tempD)
                        {
                            max = tempD;
                        }
                    }
                    else
                    {
                        if (max < tempD)
                        {
                            max = tempD;
                        }
                        if (min > tempD)
                        {
                            min = tempD;
                        }
                    }
                    data_tmp[count++] = tempD;
                }
            }

            //ptr = img.GetScalarPointer();
            vtkLookupTable colorTable = vtkLookupTable.New();

            if (!isLinear && !isPhs)
            {
                min = max - dB_RABNGE;
            }
            if (!isPhs)
            {
                for (int i = 0; i < N_width * M_depth * 1; i++)
                {
                    data_tmp[i] = max - data_tmp[i];
                }
                colorTable.SetRange(0, max - min);
            }
            else
            {
                colorTable.SetRange(min, max);
            }

            IntPtr ptr = img.GetScalarPointer();

            System.Runtime.InteropServices.Marshal.Copy(data_tmp, 0, ptr, M_depth * N_width);
            colorTable.Build();

            vtkImageMapToColors colorMap = vtkImageMapToColors.New();

            colorMap.SetInput(img);
            colorMap.SetLookupTable(colorTable);
            colorMap.Update();

            vtkTransform transform = vtkTransform.New();

            transform.Translate(data.coordinate.pos.x, data.coordinate.pos.y, data.coordinate.pos.z);
            transform.RotateWXYZ(data.coordinate.rotate_theta, data.coordinate.rotate_axis.x,
                                 data.coordinate.rotate_axis.y, data.coordinate.rotate_axis.z);
            transform.Translate(-width / 2, -depth / 2, 0);

            vtkImageActor actor = vtkImageActor.New();

            actor.SetInput(colorMap.GetOutput());
            actor.SetUserTransform(transform);

            return(actor);
        }
Exemple #6
0
 private void TransformRobotPart(vtkActor part, Position shift, Position position)
 {
     vtkTransform transform = new vtkTransform();
     transform.Translate(position.X, position.Y, position.Z);
     transform.RotateWXYZ(position.A, 0, 0, 1);
     transform.RotateWXYZ(position.B, 0, 1, 0);
     transform.RotateWXYZ(position.C, 1, 0, 0);
     if (part == robot1part7)
         transform.RotateWXYZ(11.5, 0, 0, 1);
     transform.RotateWXYZ(shift.C, 1, 0, 0);
     transform.RotateWXYZ(shift.B, 0, 1, 0);
     transform.RotateWXYZ(shift.A, 0, 0, 1);
     transform.Translate(shift.X, shift.Y, shift.Z);
     part.SetUserTransform(transform);
 }
Exemple #7
0
 private void TransformAxes(vtkAxesActor axes, Position position)
 {
     vtkTransform transform = new vtkTransform();
     transform.Translate(position.X, position.Y, position.Z);
     transform.RotateWXYZ(position.A, 0, 0, 1);
     transform.RotateWXYZ(position.B, 0, 1, 0);
     transform.RotateWXYZ(position.C, 1, 0, 0);
     axes.SetUserTransform(transform);
 }
Exemple #8
0
        /// <summary>
        /// Rotates 3D vtk volume around x and y axes.
        /// </summary>
        /// <param name="input"></param>
        /// <param name="angle"></param>
        /// <param name="axis"></param>
        /// <param name="out_extent"></param>
        /// <returns></returns>
        public static vtkImageData rotate_sample(vtkImageData input, double angle, int axis, int out_extent = 0)
        {
            //get input data dimensions
            int[] dims = input.GetExtent();
            //Compute centers
            int[] centers = new int[] { (dims[1] + dims[0]) / 2, (dims[3] + dims[2]) / 2, (dims[5] + dims[4]) / 2 };

            //Set rotation axis
            int[] axes = new int[3];
            axes[axis] = 1;

            int[] new_dims    = new int[] { dims[0], dims[1], dims[2], dims[3], dims[4], dims[5] };
            int[] new_centers = new int[] { centers[0], centers[1], centers[2] };

            //Compute new sample dimensions
            if (axis == 0)
            {
                new_dims[3] = (int)(Math.Cos(Math.Abs(angle / 180) * Math.PI) * new_dims[3] + Math.Sin(Math.Abs(angle / 180) * Math.PI) * new_dims[5]);
                new_dims[5] = (int)(Math.Sin(Math.Abs(angle / 180) * Math.PI) * new_dims[3] + Math.Cos(Math.Abs(angle / 180) * Math.PI) * new_dims[5]);

                new_centers[1] = (Math.Abs(new_dims[3]) + Math.Abs(new_dims[2])) / 2;
                new_centers[2] = (Math.Abs(new_dims[5]) + Math.Abs(new_dims[4])) / 2;
            }
            if (axis == 1)
            {
                new_dims[1] = (int)(Math.Cos(Math.Abs(angle / 180) * Math.PI) * new_dims[1] + Math.Sin(Math.Abs(angle / 180) * Math.PI) * new_dims[5]);
                new_dims[5] = (int)(Math.Sin(Math.Abs(angle / 180) * Math.PI) * new_dims[1] + Math.Cos(Math.Abs(angle / 180) * Math.PI) * new_dims[5]);

                new_centers[0] = (Math.Abs(new_dims[0]) + Math.Abs(new_dims[1])) / 2;
                new_centers[2] = (Math.Abs(new_dims[5]) + Math.Abs(new_dims[4])) / 2;
            }


            //Image transformation
            vtkTransform transform = vtkTransform.New();

            transform.Translate(centers[0], centers[1], centers[2]);
            transform.RotateWXYZ(angle, axes[0], axes[1], axes[2]);
            if (out_extent == 0)
            {
                transform.Translate(-centers[0], -centers[1], -centers[2]);
            }
            else
            {
                transform.Translate(-new_centers[0], -new_centers[1], -new_centers[2]);
            }

            //Console.ReadKey();

            transform.Update();

            //Compute new data extent
            int[] diff = new int[] { new_dims[1] - dims[1], new_dims[3] - dims[3], new_dims[5] - dims[5] };
            new_dims[0] += diff[0] / 2; new_dims[1] -= diff[0] / 2;
            new_dims[2] += diff[1] / 2; new_dims[3] -= diff[1] / 2;
            new_dims[4] += diff[2] / 2; new_dims[5] -= diff[2] / 2;



            //Image reslicing
            vtkImageReslice rotater = vtkImageReslice.New();

            rotater.SetInput(input);
            rotater.SetInformationInput(input);
            rotater.SetResliceTransform(transform);
            rotater.SetInterpolationModeToCubic();
            //rotater.SetInterpolationModeToLinear();
            if (out_extent == 1)
            {
                rotater.SetOutputSpacing(input.GetSpacing()[0], input.GetSpacing()[1], input.GetSpacing()[2]);
                rotater.SetOutputOrigin(input.GetOrigin()[0], input.GetOrigin()[1], input.GetOrigin()[2]);
                rotater.SetOutputExtent(new_dims[0], new_dims[1], new_dims[2], new_dims[3], new_dims[4], new_dims[5]);
            }
            rotater.Update();

            vtkImageData output = vtkImageData.New();

            output.DeepCopy(rotater.GetOutput());

            rotater.Dispose();
            transform.Dispose();

            return(output);
        }