Example #1
0
        public PolyInfo GetPolyInfo(int poly)
        {
            global::System.IntPtr cPtr = C4dApiPINVOKE.Neighbor_GetPolyInfo(swigCPtr, poly);
            PolyInfo ret = (cPtr == global::System.IntPtr.Zero) ? null : new PolyInfo(cPtr, false);

            return(ret);
        }
Example #2
0
        private void AddDataSource(PointSet pointSet, Guid guid)
        {
            List <Coordinate2D> points = new List <Coordinate2D>();

            foreach (PointSetElement point in pointSet.Data)
            {
                points.Add(new Coordinate2D(point.Longitude, point.Latitude));
            }
            PolyInfo style = PolyInfo.DefaultPolyline;

            style.LineColor = Color.Red;
            style.LineWidth = 0.5;

            string layerId      = Guid.NewGuid().ToString();
            string geometryId   = Guid.NewGuid().ToString();
            string dataSourceId = Guid.NewGuid().ToString();



            trajectoriesLayers.Add(new TrajectoriesLayer
            {
                DataSource   = new TrajectoriesDataSource(host, pointSet),
                Guid         = guid,
                GeometryID   = geometryId,
                LayerID      = layerId,
                DataSourceID = dataSourceId,
                IsVisible    = true,
                Geometry     = new PolylineGeometry(layerId, geometryId, new Polyline2(Wgs84CoordinateReferenceSystem.Instance,
                                                                                       Coordinate2DCollection.CreateUnsafe(points.ToArray())), style)
            });
            AddLayerToHost(trajectoriesLayers[trajectoriesLayers.Count - 1]);
        }
Example #3
0
        void BuildMesh()
        {
            List<VoxelPos> AllVoxel = new List<VoxelPos>();

            for (int i = 0; i < VoxelCount; ++i)
            {
                for (int j = 0; j < VoxelCount; ++j)
                {
                    if (VoxelsData[i, j])
                    {
                        AllVoxel.Add(new VoxelPos(i, j));
                    }
                }
            }

            PolyInfo poly = null;
            while (AllVoxel.Count > 0)
            {
                VoxelPos vp = AllVoxel[0];
                poly = new PolyInfo();
                List<Edge> AllEdges = new List<Edge>();
                __FindAllEdges__(vp, AllEdges, AllVoxel);

                // 计算顶点的度
                Dictionary<int, int> Degrees = new Dictionary<int, int>();
                __CalcDegrees__(AllEdges, Degrees);

                __FindAllRings__(AllEdges, Degrees, poly);

                polys.Add(poly);
            }
        }
Example #4
0
 public void AddPaths(Paths poly)
 {
     if (poly.Count == 0) return;
     PolyInfo pi = new PolyInfo();
     pi.polygons = poly;
     pi.si = style.Clone();
     PolyInfoList.Add(pi);
 }
Example #5
0
        void __BuildPolyByAllRings__(List<List<VoxelPos>> AllRings, PolyInfo poly)
        {
            if (AllRings.Count == 0)
                return;

            if (AllRings.Count == 1)
            {
                poly.OutterEdges = AllRings[0];
                return;
            }

            int maxsize = 0;
            List<VoxelPos> outterEdges = null;
            foreach (var Ring in AllRings)
            {
                int minx = int.MaxValue, miny = int.MaxValue, maxx = 0, maxy = 0;
                foreach (var v in Ring)
                {
                    if (v.X < minx) minx = v.X;
                    if (v.Y < miny) miny = v.Y;
                    if (v.X > maxx) maxx = v.X;
                    if (v.Y > maxy) maxy = v.Y;
                }

                int size = (maxx - minx) * (maxy - miny);
                if (size > maxsize)
                {
                    outterEdges = Ring;
                    maxsize = size;
                }
            }

            AllRings.Remove(outterEdges);
            poly.OutterEdges = outterEdges;
            poly.InnerEdges = AllRings;

            // 定义内边中的点
            foreach (var Ring in AllRings)
            {
                VoxelPos v0, v1, v2;
                int rc = Ring.Count;
                for (int i = 0; i < rc; ++i)
                {
                    v0 = Ring[i];
                    v1 = Ring[(i + 1) % rc];
                    v2 = Ring[(i + 2) % rc];

                    if ((v1.X - v0.X) * (v2.Y - v1.Y) + (v1.Y - v0.Y) * (v2.X - v1.X) > 0)
                    {
                        float x = (float)(v2.X - v0.X) / 2 + v0.X;
                        float y = (float)(v2.Y - v0.Y) / 2 + v0.Y;

                        poly.HolesPos.Add(new PointF(x, y));
                        break;
                    }
                }
            }
        }
        /// <summary>
        /// Returns information about all monomials of an expression
        /// </summary>
        /// <param name="expr"></param>
        /// <param name="replaceVars"></param>
        /// <returns></returns>
        internal static PolyInfo GatherAllPossiblePolynomials(Entity expr, bool replaceVars)
        {
            // TODO: refactor

            expr = expr.DeepCopy();

            // Init
            var res = new PolyInfo();
            var mentionedVarList = MathS.Utils.GetUniqueVariables(expr);
            var newList          = new List <string>();

            if (replaceVars)
            {
                // Replace all variables we can
                foreach (var varMentioned in mentionedVarList.FiniteSet())
                {
                    if (expr.FindSubtree(varMentioned) == null)
                    {
                        continue;
                    }
                    var replacement = TreeAnalyzer.GetMinimumSubtree(expr, varMentioned);
                    res.replacementInfo[varMentioned.Name] = replacement;
                    FindAndReplace(ref expr, replacement, new VariableEntity(PolyInfo.NewVarName(varMentioned.Name)));
                    newList.Add(PolyInfo.NewVarName(varMentioned.Name));
                }
            }
            else
            {
                foreach (var v in mentionedVarList.FiniteSet())
                {
                    newList.Add(v.Name);
                }
            }

            // Gather info about each var as if this var was the only argument of the polynomial P(x)
            foreach (var varMentioned in newList)
            {
                List <Entity> children;
                if (expr.entType == Entity.EntType.OPERATOR && expr.Name == "sumf" || expr.Name == "minusf")
                {
                    children = TreeAnalyzer.LinearChildren(expr, "sumf", "minusf", Const.FuncIfSum);
                }
                else
                {
                    children = new List <Entity> {
                        expr
                    }
                };
                res.monoInfo[varMentioned] = PolynomialSolver.GatherMonomialInformation <decimal>(children, MathS.Var(varMentioned));
            }

            return(res);
        }
    }
Example #7
0
            public void AddPolygons(Polygons poly)
            {
                if (poly.Count == 0)
                {
                    return;
                }
                PolyInfo pi = new PolyInfo();

                pi.polygons = poly;
                pi.si       = style.Clone();
                PolyInfoList.Add(pi);
            }
Example #8
0
        private void AddDataSource(IDataSource2D <double> field, Guid guid)
        {
            List <PolylineGeometry> geometry = new List <PolylineGeometry>();
            List <VisualPushpin>    labels   = new List <VisualPushpin>();

            isolineBuilder.DataSource = field;
            IsolineCollection collection = isolineBuilder.Build();

            annotater.WayBeforeText = 20.0;

            foreach (LevelLine segment in collection.Lines)
            {
                List <Coordinate2D> points = new List <Coordinate2D>();
                points.Add(new Coordinate2D(segment.StartPoint.X, segment.StartPoint.Y));
                foreach (Point point in segment.OtherPoints)
                {
                    points.Add(new Coordinate2D(point.X, point.Y));
                }
                PolyInfo style = PolyInfo.DefaultPolyline;
                Color    color = palette.GetColor(segment.Value01);
                style.LineColor = System.Drawing.Color.FromArgb(color.A, color.R, color.G, color.B);

                geometry.Add(new PolylineGeometry(guid.ToString(), Guid.NewGuid().ToString(), new Polyline2(Wgs84CoordinateReferenceSystem.Instance,
                                                                                                            Coordinate2DCollection.CreateUnsafe(points.ToArray())), style));
            }

            foreach (IsolineTextLabel label in annotater.Annotate(collection, new Rect()))
            {
                labels.Add(new VisualPushpin(30, 30, label.Text, LatLonAlt.CreateUsingDegrees(label.Position.Y, label.Position.X, 0), this, Guid.NewGuid().ToString()));
            }

            layers.Add(new IsolinesLayer()
            {
                Geometry = geometry, IsVisible = true, Guid = guid, Labels = labels
            });
            AddLayerToHost(layers[layers.Count - 1]);
        }
Example #9
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(PolyInfo obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
Example #10
0
        void __FindAllRings__(List<Edge> AllEdges, Dictionary<int, int> Degrees, PolyInfo poly)
        {
            List<List<VoxelPos>> AllRings = new List<List<VoxelPos>>();

            while (AllEdges.Count > 0)
            {
                Edge e = AllEdges[0];
                List<VoxelPos> Ring = new List<VoxelPos>();

                AllEdges.RemoveAt(0);
                __FindAllEdges2Ring__(e, AllEdges, Degrees, Ring);
                AllRings.Add(Ring);
            }

            // 寻找外边
            __BuildPolyByAllRings__(AllRings, poly);
        }
        /// <summary>
        /// Divides one polynom over another one
        /// </summary>
        /// <param name="p"></param>
        /// <param name="q"></param>
        /// <returns></returns>
        internal static Entity DividePolynoms(Entity p, Entity q)
        {
            // ---> (x^0.6 + 2x^0.3 + 1) / (x^0.3 + 1)
            var replacementInfo = GatherAllPossiblePolynomials(p + q, replaceVars: true).replacementInfo;

            var originalP = p;
            var originalQ = q;

            // TODO remove extra copy
            p = p.DeepCopy();
            q = q.DeepCopy();

            foreach (var pair in replacementInfo)
            {
                FindAndReplace(ref p, pair.Value, new VariableEntity(PolyInfo.NewVarName(pair.Key)));
                FindAndReplace(ref q, pair.Value, new VariableEntity(PolyInfo.NewVarName(pair.Key)));
            }

            var monoinfoQ = GatherAllPossiblePolynomials(q.Expand(), replaceVars: false).monoInfo;
            var monoinfoP = GatherAllPossiblePolynomials(p.Expand(), replaceVars: false).monoInfo;

            string polyvar = null;

            // TODO use Linq to find polyvar
            // First attempt to find polynoms
            foreach (var pair in monoinfoQ)
            {
                if (pair.Value != null && monoinfoP.ContainsKey(pair.Key) && monoinfoP[pair.Key] != null)
                {
                    polyvar = pair.Key;
                    break;
                }
            }
            // cannot divide, return unchanged
            if (string.IsNullOrEmpty(polyvar))
            {
                return(originalP / originalQ);
            }

            var maxpowQ = monoinfoQ[polyvar].Keys.Max();
            var maxpowP = monoinfoP[polyvar].Keys.Max();
            var maxvalQ = monoinfoQ[polyvar][maxpowQ];
            var maxvalP = monoinfoP[polyvar][maxpowP];

            var result = new Dictionary <decimal, Entity>();

            // TODO: add case where all powers are non-positive
            // for now just return polynomials unchanged
            if (maxpowP < maxpowQ)
            {
                return(originalP / originalQ);
            }

            // possibly very long process
            while (maxpowP >= maxpowQ)
            {
                // KeyPair is ax^n with Key=n, Value=a
                decimal deltapow = maxpowP - maxpowQ;
                Entity  deltamul = maxvalP / maxvalQ;
                result[deltapow] = deltamul;

                foreach (var n in monoinfoQ[polyvar])
                {
                    // TODO: precision loss can happen here. MUST be fixed somehow
                    decimal newpow = deltapow + n.Key;
                    if (!monoinfoP[polyvar].ContainsKey(newpow))
                    {
                        monoinfoP[polyvar][newpow] = -deltamul * n.Value;
                    }
                    else
                    {
                        monoinfoP[polyvar][newpow] -= deltamul * n.Value;
                    }
                }
                if (monoinfoP[polyvar].ContainsKey(maxpowP))
                {
                    monoinfoP[polyvar].Remove(maxpowP);
                }
                if (monoinfoP[polyvar].Count == 0)
                {
                    break;
                }

                maxpowP = monoinfoP[polyvar].Keys.Max();
                maxvalP = monoinfoP[polyvar][maxpowP];
            }

            // check if all left in P is zero. If something left, division is impossible => return P / Q
            var Zero = new NumberEntity(0);

            foreach (var coef in monoinfoP[polyvar])
            {
                var simplified = coef.Value.Simplify();
                if (simplified != Zero)
                {
                    return(originalP / originalQ);
                }
            }

            Entity res = Number.Create(0);

            foreach (var pair in result)
            {
                res += pair.Value.Simplify(5) * MathS.Pow(new VariableEntity(polyvar), pair.Key);
            }
            // TODO: we know that variable is the same but with suffux '_r'. This foreach loop can be speeded-up
            while (replacementInfo.Any(rep => res.FindSubtree(new VariableEntity(PolyInfo.NewVarName(rep.Key))) != null))
            {
                foreach (var subst in replacementInfo)
                {
                    FindAndReplace(ref res, new VariableEntity(PolyInfo.NewVarName(subst.Key)), subst.Value);
                }
            }
            return(res);
        }
Example #12
0
 public void AddCutout(PolyInfo polygon)
 {
     polygons.Add(polygon);
     Validate();
 }