Ejemplo n.º 1
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);
        }