Exemplo n.º 1
0
        public void Editing(object sender, ContextMenuClickedEventArgs <CustomVectorField> e)
        {
            CustomVectorField vf = e.ContextObject as CustomVectorField;

            CreateVF.Arguments a = new CreateVF.Arguments();

            using (ITransaction txn = DataManager.NewTransaction())
            {
                txn.Lock(vf);
                a.AzField     = vf.Azimutfieldic;
                a.HeiField    = vf.Heigtfieldic;
                a.Step        = (int)vf.gridStep;
                a.VectorField = vf;
                CreateVFUI wnd = new CreateVFUI(wrapper.Workstep as CreateVF, a, null as WorkflowContext);
                Form       das = new Form();
                das.Icon   = Icon.FromHandle(PetrelImages.Modules.GetHicon());
                das.Text   = "CreateVF";
                das.Width  = 550;
                das.Height = 256;
                wnd.Parent = das;
                wnd.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                                                                   | System.Windows.Forms.AnchorStyles.Right)));
                das.Show();
                txn.Commit();
            }
        }
Exemplo n.º 2
0
        public Box2 GetBounds(object o, MapRendererContext ctx)
        {
            CustomVectorField VF    = (CustomVectorField)o;
            Point2            begin = new Point2(VF.originX, VF.originY);
            Point2            end   = new Point2(VF.originX + VF.gridStep * VF.sizeX, VF.originY + VF.gridStep * VF.sizeY);

            // Return a box that describes the area the object occupies
            return(new Box2(begin, end));
        }
Exemplo n.º 3
0
        public bool CanDraw(object o, MapRendererContext ctx)
        {
            CustomVectorField cvf = o as CustomVectorField;

            return(!(cvf.VectorField == null));
        }
Exemplo n.º 4
0
        public void Draw(object o, MapRendererContext ctx)
        {
            // Get the World coordinates
            Graphics gworld = ctx.World;

            using (Pen pn = new Pen(Color.Black))
            {
                CustomVectorField VF = (CustomVectorField)o;
                double[, ,] field = VF.VectorField;
                float originX               = (float)VF.originX;
                float originY               = (float)VF.originY;
                float increment             = (float)VF.gridStep;
                int   sizeX                 = VF.sizeX;
                int   sizeY                 = VF.sizeY;
                Pen   pn1                   = new Pen(VF.arrowColor);
                AdjustableArrowCap bigArrow = new AdjustableArrowCap(5, 7);
                Pen pn2 = new Pen(VF.arrowColor);
                pn2.CustomEndCap = bigArrow;
                Font       drawFont  = new Font("Arial", 16);
                SolidBrush drawBrush = new SolidBrush(VF.arrowColor);
                for (int i = 0; i < sizeX; i++)
                {
                    for (int j = 0; j < sizeY; j++)
                    {
                        if (field[i, j, 0] > 0.005)
                        {
                            if (VF.haveGrid)
                            {
                                gworld.DrawRectangle(pn, originX + (float)i * increment, originY + (float)j * increment, increment, increment);
                            }
                            gworld.DrawLine(pn1, (float)field[i, j, 2], (float)field[i, j, 3], (float)field[i, j, 4], (float)field[i, j, 5]);
                            PointF point1 = new PointF((float)field[i, j, 4], (float)field[i, j, 5]);
                            PointF point2 = new PointF((float)field[i, j, 6], (float)field[i, j, 7]);
                            PointF point3 = new PointF((float)field[i, j, 12], (float)field[i, j, 13]);
                            PointF point4 = new PointF((float)field[i, j, 16], (float)field[i, j, 17]);
                            PointF point5 = new PointF((float)field[i, j, 14], (float)field[i, j, 15]);
                            PointF point6 = new PointF((float)field[i, j, 10], (float)field[i, j, 11]);
                            PointF point7 = new PointF((float)field[i, j, 8], (float)field[i, j, 9]);


                            PointF[] curvePoints =
                            {
                                point1,
                                point2,
                                point3,
                                point4,
                                point5,
                                point6,
                                point7
                            };
                            gworld.FillPolygon(drawBrush, curvePoints);
                            //gworld.DrawLine(pn1, (float)field[i, j, 4], (float)field[i, j, 5], (float)field[i, j, 6], (float)field[i, j, 7]);
                            //gworld.DrawLine(pn1, (float)field[i, j, 4], (float)field[i, j, 5], (float)field[i, j, 8], (float)field[i, j, 9]);
                            //PointF[] f = new PointF [4];
                            //for (int rrr = 0; rrr < 4 ; i++){

                            /*  f[0].X = (int)field[i, j, 6];
                             * f[0].Y = (int)field[i, j, 7];
                             * f[1].X = (int)field[i, j, 4];
                             * f[1].Y = (int)field[i, j, 5];
                             * f[2].X = (int)field[i, j, 8];
                             * f[2].Y = (int)field[i, j, 9];
                             * f[3].X = (int)field[i, j, 10];
                             * f[3].Y = (int)field[i, j, 11];
                             * gworld.DrawPolygon(pn1, f);*/
                            //}
                            //gworld.FillPolygon(drawBrush, f);
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            CustomVectorField NewVF;

            if (tmpargs.VectorField == null)
            {
                NewVF = new CustomVectorField();
            }
            else
            {
                NewVF = tmpargs.VectorField;
            }
            NewVF.koeff = double.Parse(textBoxK.Text);
            if ((NewVF.koeff > 1.0) || (NewVF.koeff <= 0.0))
            {
                PetrelLogger.ErrorBox("Коэффициент не может быть больше 1 или меньше 0!");
                return;
            }
            NewVF.gridStep   = double.Parse(textBoxStep.Text);
            NewVF.partition  = int.Parse(textBoxN.Text);
            NewVF.haveGrid   = (comboBox1.SelectedItem.Text == "Да");
            NewVF.arrowColor = colorPicker1.Color;;
            NewVF.originX    = tmpargs.HeiField.SpatialLattice.OriginalLattice.Single.OriginX;
            NewVF.originY    = tmpargs.HeiField.SpatialLattice.OriginalLattice.Single.OriginY;
            int sizeI         = tmpargs.HeiField.SpatialLattice.OriginalLattice.Single.SizeI,
                sizeJ         = tmpargs.HeiField.SpatialLattice.OriginalLattice.Single.SizeJ;
            double maxval     = 0.0,
                   spacingI   = tmpargs.HeiField.SpatialLattice.OriginalLattice.Single.SpacingI,
                   spacingJ   = tmpargs.HeiField.SpatialLattice.OriginalLattice.Single.SpacingJ,
                   spaceSizeX = spacingI * (double)sizeI,
                   spaceSizeY = spacingJ * (double)sizeJ;

            NewVF.sizeX                = (int)Math.Floor(spaceSizeX / (double)NewVF.gridStep);
            NewVF.sizeY                = (int)Math.Floor(spaceSizeY / (double)NewVF.gridStep);
            NewVF.Azimutfieldic        = tmpargs.AzField;
            NewVF.Heigtfieldic         = tmpargs.HeiField;
            double[,] NewHeightSurface = new double[sizeI, sizeJ];
            double[,] NewAzimutSurface = new double[sizeI, sizeJ];
            foreach (RegularHeightFieldSample prop in tmpargs.HeiField.Samples)
            {
                NewHeightSurface[prop.I, prop.J] = prop.Value;
            }
            foreach (RegularHeightFieldSample prop in tmpargs.AzField.Samples)
            {
                NewAzimutSurface[prop.I, prop.J] = prop.Value;
            }
            double[, ,] VectorField = new double[NewVF.sizeX, NewVF.sizeY, 18];
            for (int i = 0; i < NewVF.sizeX; i++)
            {
                for (int j = 0; j < NewVF.sizeY; j++)
                {
                    //в каждой ячейке усредняем, берем из нее N значений значений
                    for (int k = 0; k < NewVF.partition; k++)
                    {
                        for (int l = 0; l < NewVF.partition; l++)
                        {
                            int x = (int)Math.Floor(((double)i * NewVF.gridStep + k * NewVF.gridStep / (double)NewVF.partition) / (double)spacingI),
                                y = (int)Math.Floor(((double)j * NewVF.gridStep + l * NewVF.gridStep / (double)NewVF.partition) / (double)spacingJ);
                            VectorField[i, j, 0] += NewHeightSurface[x, y];
                            VectorField[i, j, 1] += NewAzimutSurface[x, y];
                        }
                        VectorField[i, j, 0] /= (double)NewVF.partition * (double)NewVF.partition;
                        VectorField[i, j, 1] /= (double)NewVF.partition * (double)NewVF.partition;
                        if (maxval < VectorField[i, j, 0])
                        {
                            maxval = VectorField[i, j, 0];
                        }
                    }
                }
            }
            double tan, ctan;

            for (int i = 0; i < NewVF.sizeX; i++)
            {
                for (int j = 0; j < NewVF.sizeY; j++)
                {
                    VectorField[i, j, 0] /= maxval;
                    tan  = Math.Tan(Math.PI / 2.0 - VectorField[i, j, 1]);
                    ctan = 1.0 / Math.Tan(Math.PI / 2.0 - VectorField[i, j, 1]);
                    if (tan > 1.0)
                    {
                        tan = 1.0;
                    }
                    else if (tan < -1.0)
                    {
                        tan = -1.0;
                    }
                    if (ctan > 1.0)
                    {
                        ctan = 1.0;
                    }
                    else if (ctan < -1.0)
                    {
                        ctan = -1.0;
                    }
                    VectorField[i, j, 2] = NewVF.originX + ((i + 0.5 * (1.0 - ctan * NewVF.koeff * VectorField[i, j, 0])) * NewVF.gridStep);
                    VectorField[i, j, 3] = NewVF.originY + ((j + 0.5 * (1.0 - tan * NewVF.koeff * VectorField[i, j, 0])) * NewVF.gridStep);
                    VectorField[i, j, 4] = NewVF.originX + ((i + 0.5 * (1.0 + ctan * NewVF.koeff * VectorField[i, j, 0])) * NewVF.gridStep);
                    VectorField[i, j, 5] = NewVF.originY + ((j + 0.5 * (1.0 + tan * NewVF.koeff * VectorField[i, j, 0])) * NewVF.gridStep);
                    float vx   = (float)VectorField[i, j, 4] - (float)VectorField[i, j, 2];
                    float vy   = (float)VectorField[i, j, 5] - (float)VectorField[i, j, 3];
                    float dist = (float)Math.Sqrt(vx * vx + vy * vy);
                    vx /= dist;
                    vy /= dist;
                    float h   = 0.5f * dist;
                    float h1  = 0.35f * dist;
                    float w   = h * (float)1 / (float)3.0;
                    float w1  = h1 * (float)1 / (float)10.0;
                    float ox  = (float)VectorField[i, j, 4] - h * vx;
                    float oy  = (float)VectorField[i, j, 5] - h * vy;
                    float ox1 = (float)VectorField[i, j, 4] - h1 * vx;
                    float oy1 = (float)VectorField[i, j, 5] - h1 * vy;
                    VectorField[i, j, 6]  = ox + w * (VectorField[i, j, 3] - VectorField[i, j, 5]) / dist;
                    VectorField[i, j, 7]  = oy + w * (VectorField[i, j, 4] - VectorField[i, j, 2]) / dist;
                    VectorField[i, j, 8]  = ox - w * (VectorField[i, j, 3] - VectorField[i, j, 5]) / dist;
                    VectorField[i, j, 9]  = oy - w * (VectorField[i, j, 4] - VectorField[i, j, 2]) / dist;
                    VectorField[i, j, 10] = ox1 - w1 * (VectorField[i, j, 3] - VectorField[i, j, 5]) / dist;
                    VectorField[i, j, 11] = oy1 - w1 * (VectorField[i, j, 4] - VectorField[i, j, 2]) / dist;
                    VectorField[i, j, 12] = ox1 + w1 * (VectorField[i, j, 3] - VectorField[i, j, 5]) / dist;
                    VectorField[i, j, 13] = oy1 + w1 * (VectorField[i, j, 4] - VectorField[i, j, 2]) / dist;
                    VectorField[i, j, 14] = (float)VectorField[i, j, 2] - w1 * (VectorField[i, j, 3] - VectorField[i, j, 5]) / dist;
                    VectorField[i, j, 15] = (float)VectorField[i, j, 3] - w1 * (VectorField[i, j, 4] - VectorField[i, j, 2]) / dist;
                    VectorField[i, j, 16] = (float)VectorField[i, j, 2] + w1 * (VectorField[i, j, 3] - VectorField[i, j, 5]) / dist;
                    VectorField[i, j, 17] = (float)VectorField[i, j, 3] + w1 * (VectorField[i, j, 4] - VectorField[i, j, 2]) / dist;
                }
            }
            NewVF.VectorField = VectorField;
            if (tmpargs.VectorField == null)
            {
                tmpargs.VectorField = NewVF;
                using (ITransaction txn = DataManager.NewTransaction())
                {
                    Project proj = PetrelProject.PrimaryProject;
                    txn.Lock(proj);
                    proj.Extensions.Add(tmpargs.VectorField);



                    txn.Commit();
                }
            }
            MapWindow map = PetrelProject.ToggleWindows.Add(WellKnownWindows.Map) as MapWindow;

            map.ShowObject(tmpargs.HeiField);
            map.ShowObject(tmpargs.AzField);
            map.ShowObject(NewVF);


            this.ParentForm.Close();
        }
Exemplo n.º 6
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            CustomVectorField NewVF;
            if (tmpargs.VectorField == null)
            {
                NewVF = new CustomVectorField();
            }
            else
            {
                NewVF = tmpargs.VectorField;
            }
            NewVF.koeff = double.Parse(textBoxK.Text);
            if ((NewVF.koeff > 1.0) || (NewVF.koeff <= 0.0))
            {
                PetrelLogger.ErrorBox("Коэффициент не может быть больше 1 или меньше 0!");
                return;
            }
            NewVF.gridStep = double.Parse(textBoxStep.Text);
            NewVF.partition = int.Parse(textBoxN.Text);
            NewVF.haveGrid = (comboBox1.SelectedItem.Text == "Да");
            NewVF.arrowColor = colorPicker1.Color; ;
            NewVF.originX = tmpargs.HeiField.SpatialLattice.OriginalLattice.Single.OriginX;
            NewVF.originY = tmpargs.HeiField.SpatialLattice.OriginalLattice.Single.OriginY;
            int sizeI = tmpargs.HeiField.SpatialLattice.OriginalLattice.Single.SizeI,
                sizeJ = tmpargs.HeiField.SpatialLattice.OriginalLattice.Single.SizeJ;
            double maxval = 0.0,
                   spacingI = tmpargs.HeiField.SpatialLattice.OriginalLattice.Single.SpacingI,
                   spacingJ = tmpargs.HeiField.SpatialLattice.OriginalLattice.Single.SpacingJ,
                   spaceSizeX = spacingI * (double)sizeI,
                   spaceSizeY = spacingJ * (double)sizeJ;
            NewVF.sizeX = (int)Math.Floor(spaceSizeX / (double)NewVF.gridStep);
            NewVF.sizeY = (int)Math.Floor(spaceSizeY / (double)NewVF.gridStep);
            NewVF.Azimutfieldic = tmpargs.AzField;
            NewVF.Heigtfieldic = tmpargs.HeiField;
            double[,] NewHeightSurface = new double[sizeI, sizeJ];
            double[,] NewAzimutSurface = new double[sizeI, sizeJ];
            foreach (RegularHeightFieldSample prop in tmpargs.HeiField.Samples)
            {
                NewHeightSurface[prop.I, prop.J] = prop.Value;
            }
            foreach (RegularHeightFieldSample prop in tmpargs.AzField.Samples)
            {
                NewAzimutSurface[prop.I, prop.J] = prop.Value;
            }
            double[, ,] VectorField = new double[NewVF.sizeX, NewVF.sizeY, 18];
            for (int i = 0; i < NewVF.sizeX; i++)
            {
                for (int j = 0; j < NewVF.sizeY; j++)
                {
                    //в каждой ячейке усредняем, берем из нее N значений значений
                    for (int k = 0; k < NewVF.partition; k++)
                    {
                        for (int l = 0; l < NewVF.partition; l++)
                        {
                            int x = (int)Math.Floor(((double)i * NewVF.gridStep + k * NewVF.gridStep / (double)NewVF.partition) / (double)spacingI),
                                y = (int)Math.Floor(((double)j * NewVF.gridStep + l * NewVF.gridStep / (double)NewVF.partition) / (double)spacingJ);
                            VectorField[i, j, 0] += NewHeightSurface[x, y];
                            VectorField[i, j, 1] += NewAzimutSurface[x, y];
                        }
                        VectorField[i, j, 0] /= (double)NewVF.partition * (double)NewVF.partition;
                        VectorField[i, j, 1] /= (double)NewVF.partition * (double)NewVF.partition;
                        if (maxval < VectorField[i, j, 0])
                        {
                            maxval = VectorField[i, j, 0];
                        }
                    }
                }
            }
            double tan, ctan;
            for (int i = 0; i < NewVF.sizeX; i++)
            {
                for (int j = 0; j < NewVF.sizeY; j++)
                {
                    VectorField[i, j, 0] /= maxval;
                    tan = Math.Tan(Math.PI / 2.0 - VectorField[i, j, 1]);
                    ctan = 1.0 / Math.Tan(Math.PI / 2.0 - VectorField[i, j, 1]);
                    if (tan > 1.0)
                    {
                        tan = 1.0;
                    }
                    else if (tan < -1.0)
                    {
                        tan = -1.0;
                    }
                    if (ctan > 1.0)
                    {
                        ctan = 1.0;
                    }
                    else if (ctan < -1.0)
                    {
                        ctan = -1.0;
                    }
                    VectorField[i, j, 2] = NewVF.originX + ((i + 0.5 * (1.0 - ctan * NewVF.koeff * VectorField[i, j, 0])) * NewVF.gridStep);
                    VectorField[i, j, 3] = NewVF.originY + ((j + 0.5 * (1.0 - tan * NewVF.koeff * VectorField[i, j, 0])) * NewVF.gridStep);
                    VectorField[i, j, 4] = NewVF.originX + ((i + 0.5 * (1.0 + ctan * NewVF.koeff * VectorField[i, j, 0])) * NewVF.gridStep);
                    VectorField[i, j, 5] = NewVF.originY + ((j + 0.5 * (1.0 + tan * NewVF.koeff * VectorField[i, j, 0])) * NewVF.gridStep);
                    float vx = (float)VectorField[i, j, 4] - (float)VectorField[i, j, 2];
                    float vy = (float)VectorField[i, j, 5] - (float)VectorField[i, j, 3];
                    float dist = (float)Math.Sqrt(vx * vx + vy * vy);
                    vx /= dist;
                    vy /= dist;
                    float h = 0.5f*dist;
                    float h1 = 0.35f*dist;
                    float w = h * (float)1/ (float)3.0;
                    float w1 = h1 * (float)1 / (float)10.0;
                    float ox = (float)VectorField[i, j, 4] - h * vx;
                    float oy = (float)VectorField[i, j, 5] - h * vy;
                    float ox1 = (float)VectorField[i, j, 4] - h1 * vx;
                    float oy1 = (float)VectorField[i, j, 5] - h1 * vy;
                    VectorField[i, j, 6] = ox + w * (VectorField[i, j, 3] - VectorField[i, j, 5])/dist;
                    VectorField[i, j, 7] = oy + w * (VectorField[i, j, 4] - VectorField[i, j, 2])/dist;
                    VectorField[i, j, 8] = ox - w * (VectorField[i, j, 3] - VectorField[i, j, 5])/dist;
                    VectorField[i, j, 9] = oy - w * (VectorField[i, j, 4] - VectorField[i, j, 2])/dist;
                    VectorField[i, j, 10] = ox1 - w1 * (VectorField[i, j, 3] - VectorField[i, j, 5]) / dist;
                    VectorField[i, j, 11] = oy1 - w1 * (VectorField[i, j, 4] - VectorField[i, j, 2]) / dist;
                    VectorField[i, j, 12] = ox1 + w1 * (VectorField[i, j, 3] - VectorField[i, j, 5]) / dist;
                    VectorField[i, j, 13] = oy1 + w1 * (VectorField[i, j, 4] - VectorField[i, j, 2]) / dist;
                    VectorField[i, j, 14] = (float)VectorField[i, j, 2] - w1 * (VectorField[i, j, 3] - VectorField[i, j, 5]) / dist;
                    VectorField[i, j, 15] = (float)VectorField[i, j, 3] - w1 * (VectorField[i, j, 4] - VectorField[i, j, 2]) / dist;
                    VectorField[i, j, 16] = (float)VectorField[i, j, 2] + w1 * (VectorField[i, j, 3] - VectorField[i, j, 5]) / dist;
                    VectorField[i, j, 17] = (float)VectorField[i, j, 3] + w1 * (VectorField[i, j, 4] - VectorField[i, j, 2]) / dist;

                }
            }
            NewVF.VectorField = VectorField;
            if (tmpargs.VectorField == null)
            {

                tmpargs.VectorField = NewVF;
                using (ITransaction txn = DataManager.NewTransaction())
                {
                    Project proj = PetrelProject.PrimaryProject;
                    txn.Lock(proj);
                    proj.Extensions.Add(tmpargs.VectorField);

                    txn.Commit();
                }
            }
            MapWindow map = PetrelProject.ToggleWindows.Add(WellKnownWindows.Map) as MapWindow;

            map.ShowObject(tmpargs.HeiField);
            map.ShowObject(tmpargs.AzField);
            map.ShowObject(NewVF);

            this.ParentForm.Close();
        }