Exemplo n.º 1
0
        public CPolygon GetDataAddressW()
        {
            global::System.IntPtr cPtr = C4dApiPINVOKE.PolygonTag_GetDataAddressW(swigCPtr);
            CPolygon ret = (cPtr == global::System.IntPtr.Zero) ? null : new CPolygon(cPtr, false);

            return(ret);
        }
Exemplo n.º 2
0
        protected override AbstractShape createShapes(string code)
        {
            AbstractShape shape = null;

            switch (code)
            {
            case "Circle":
                shape = new CCircle();
                break;

            case "Rectangle":
                shape = new CRectangle();
                break;

            case "Polygon":
                shape = new CPolygon();
                break;

            case "Star":
                shape = new CStar();
                break;

            case "Group":
                shape = new CGroup();
                break;
            }

            return(shape);
        }
Exemplo n.º 3
0
        private static List <CPoint> SimplifyAccordExistEdges(CPolygon EnlargedCpg,
                                                              List <CEdge> OriginalCEdgeLt, string strSimplification, double dblThreshold)
        {
            //EnlargedCpg.SetGeometricProperties();
            EnlargedCpg.FormCEdgeLt();
            //EnlargedCpg.SetCEdgeLtLength();
            EnlargedCpg.SetCEdgeToCpts();
            //EnlargedCpg.SetCEdgeLtAxisAngle();
            //EnlargedCpg.SetAngleDiffLt();


            //CSaveFeature.SaveCpgEb(clipperMethods.ScaleCpgEb(CHelpFunc.MakeLt(EnlargedCpg), 1 / CConstants.dblFclipper),
            //"EnlargedCpg", pesriSimpleFillStyle: esriSimpleFillStyle.esriSFSHollow, blnVisible: false);

            var EnlargedCEdgeHS = new HashSet <CEdge>(EnlargedCpg.CEdgeLt);

            //CSaveFeature.SaveCEdgeEb(clipperMethods.ScaleCEdgeEb( EnlargedCEdgeHS, 1 / CConstants.dblFclipper), "EnlargedCEdgeHS",
            //     blnVisible: false);
            _intEdgeCountBefore += EnlargedCpg.CptLt.Count - 1;
            var simplifiedcptlt = SimplifyAccordExistEdges(EnlargedCpg.CptLt, OriginalCEdgeLt,
                                                           EnlargedCEdgeHS, strSimplification, dblThreshold).ToList();

            _intEdgeCountAfter += simplifiedcptlt.Count - 1;

            //CPolygon simplifiedcpg = new CPolygon(EnlargedCpg.ID,
            //    clipperMethods.ScaleCptEb(simplifiedcptlt, 1 / CConstants.dblFclipper).ToList());
            //CSaveFeature.SaveCpg(simplifiedcpg, "simplifiedcpg",
            //    pesriSimpleFillStyle: esriSimpleFillStyle.esriSFSHollow, blnVisible: false);

            return(simplifiedcptlt);
        }
Exemplo n.º 4
0
        public static IEnumerable <CPolygon> ScaleCpgEb(IEnumerable <CPolygon> cpgeb, double dblFactor)
        {
            foreach (var cpg in cpgeb)
            {
                var scaledcpg = new CPolygon(cpg.ID, ScaleCptEb(cpg.CptLt, dblFactor).ToList());

                //scale the holes of cpg
                var cpgPairSK = new Stack <CValPair <CPolygon, CPolygon> >();
                cpgPairSK.Push(new CValPair <CPolygon, CPolygon>(cpg, scaledcpg));
                do
                {
                    var cpggroup           = cpgPairSK.Pop();
                    var recursivecpg       = cpggroup.val1;
                    var scaledrecursivecpg = cpggroup.val2;
                    if (recursivecpg.HoleCpgLt != null && recursivecpg.HoleCpgLt.Count > 0)
                    {
                        scaledrecursivecpg.HoleCpgLt = new List <CPolygon>(recursivecpg.HoleCpgLt.Count);
                        foreach (var holecpg in recursivecpg.HoleCpgLt)
                        {
                            var scaledholecpg = new CPolygon(holecpg.ID, ScaleCptEb(holecpg.CptLt, dblFactor).ToList());
                            scaledholecpg.IsHole = true;
                            scaledrecursivecpg.HoleCpgLt.Add(scaledholecpg);
                            //scaledholecpg.ParentCpg = scaledrecursivecpg;

                            cpgPairSK.Push(new CValPair <CPolygon, CPolygon>(holecpg, scaledholecpg));
                        }
                    }
                } while (cpgPairSK.Count > 0);

                yield return(scaledcpg);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Save a feature layer of IPolygon to Ipe
        /// </summary>
        public static string TranCpgToIpe(CPolygon cpg, IFillSymbol pFillSymbol,
                                          IEnvelope pFLayerEnv, CEnvelope pIpeEnv, string strBoundWidth = "normal")
        {
            //get the color of the filled part
            //we are not allowed to directly use "var pFillRgbColor = pFillSymbol.Color as IRgbColor;"
            //Nor can we use "var pFillRgbColor = pFillSymbol.Color.RGB as IRgbColor;"
            //pFillSymbol.Color.RGB has type 'int'
            IColor pFillSymbolColor = new RgbColorClass();

            pFillSymbolColor.RGB = pFillSymbol.Color.RGB;
            CColor cColor            = new CUtility.CColor(pFillSymbolColor as IRgbColor);
            var    pSimpleFillSymbol = pFillSymbol as ISimpleFillSymbol;

            if (pSimpleFillSymbol != null)
            {
                if (pSimpleFillSymbol.Style == esriSimpleFillStyle.esriSFSHollow ||
                    pSimpleFillSymbol.Style == esriSimpleFillStyle.esriSFSNull)
                {
                    cColor = null;
                }
            }


            //get the color of the out line
            var pOutlineRgbColor = pFillSymbol.Outline.Color as IRgbColor;

            if (strBoundWidth == "")
            {
                strBoundWidth = pFillSymbol.Outline.Width.ToString();
            }

            //append the string
            return(CIpeDraw.DrawCpg(cpg, pFLayerEnv, pIpeEnv, new CColor(pOutlineRgbColor), cColor, strBoundWidth));
        }
Exemplo n.º 6
0
        //public static CPolygon SimplifyCpgFreeEdges(CPolygon EnlargedCpg, List<CEdge> OriginalCEdgeLt, double dblDepsilon)
        //{
        //    //var ConflictCEdgeLt = new List<CEdge>(OriginalCEdgeLt);
        //    EnlargedCpg.SetGeometricProperties();
        //    //ConflictCEdgeLt.AddRange(EnlargedCpg.CEdgeLt);

        //    ////***********why do we consider holes?
        //    //if (EnlargedCpg.HoleCpgLt != null)
        //    //{
        //    //    EnlargedCpg.HoleCpgLt.ForEach(holecpg => ConflictCEdgeLt.AddRange(holecpg.CEdgeLt));
        //    //}

        //    return SimplifyAccordRightAnglesAndExistEdges(EnlargedCpg, ConflictCEdgeLt, dblDepsilon);
        //}



        /// <summary>
        /// the angle from the baseline to the firstedge should smaller than PI
        /// </summary>
        /// <param name="cpg"></param>
        /// <param name="ocpg"></param>
        /// <param name="dblThreshold"></param>
        /// <returns>the first vertex and the last vertex are identical</returns>
        public static CPolygon SimplifyCpgAccordExistEdges(CPolygon EnlargedCpg,
                                                           List <CEdge> OriginalCEdgeLt, string strSimplification, double dblThreshold)
        {
            //generate new polygon
            var newcptlt = SimplifyAccordExistEdges(EnlargedCpg, OriginalCEdgeLt, strSimplification, dblThreshold);

            if (EnlargedCpg.HoleCpgLt != null)
            {
                List <List <CPoint> > newholecptltlt;
                newholecptltlt = new List <List <CPoint> >(EnlargedCpg.HoleCpgLt.Count);
                foreach (var holeEnlargedCpg in EnlargedCpg.HoleCpgLt)
                {
                    var newholecptlt = SimplifyAccordExistEdges(holeEnlargedCpg, OriginalCEdgeLt, strSimplification, dblThreshold);
                    newholecptltlt.Add(newholecptlt);
                }
                var simplifiedCpg = new CPolygon(EnlargedCpg.ID, newcptlt, newholecptltlt);
                //simplifiedCpg.HoleCpgLt.ForEach(holecpg => holecpg.IsOriginal = false);  //these holes are

                return(simplifiedCpg);
            }
            else
            {
                return(new CPolygon(EnlargedCpg.ID, newcptlt));
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Save a feature layer of IPolygon to Ipe
        /// </summary>
        public static string TranIpgBoundToIpe(IPolygon ipg,
                                               IEnvelope pFLayerEnv, CEnvelope pIpeEnv, CColor StrokeColor,
                                               string strBoundWidth = "normal", string strDash = "normal")
        {
            ////get the color of the filled part
            ////we are not allowed to directly use "var pFillRgbColor = pFillSymbol.Color as IRgbColor;"
            ////Nor can we use "var pFillRgbColor = pFillSymbol.Color.RGB as IRgbColor;"
            ////pFillSymbol.Color.RGB has type 'int'
            //IColor pFillSymbolColor = new RgbColorClass();
            //pFillSymbolColor.RGB = pFillSymbol.Color.RGB;
            //var pFillSymbolRgbColor = pFillSymbolColor as IRgbColor;

            ////get the color of the out line
            //var pOutlineRgbColor = pFillSymbol.Outline.Color as IRgbColor;
            //if (strBoundWidth == "")
            //{
            //    strBoundWidth = pFillSymbol.Outline.Width.ToString();
            //}

            //get the feature
            CPolygon cpg = new CPolygon(0, ipg as IPolygon4);

            //append the string
            return(CIpeDraw.DrawCpgBound(cpg, pFLayerEnv, pIpeEnv, StrokeColor, strBoundWidth, strDash));
        }
Exemplo n.º 8
0
        public CPolygon GetPolygonR()
        {
            global::System.IntPtr cPtr = C4dApiPINVOKE.PolygonObject_GetPolygonR(swigCPtr);
            CPolygon ret = (cPtr == global::System.IntPtr.Zero) ? null : new CPolygon(cPtr, false);

            return(ret);
        }
Exemplo n.º 9
0
        public override bool UnPack(BinaryReader reader)
        {
            LeafIndex = reader.ReadInt32();

            if (PackTreeType != BspTreeType.Physics)
            {
                return(true);
            }

            Solid = reader.ReadUInt32();
            Sphere.UnPack(reader);

            uint numPolys = reader.ReadUInt32();

            if (numPolys > 0u)
            {
                InPolys = new CPolygon[numPolys];
                for (uint i = 0u; i < numPolys; i++)
                {
                    InPolys[i] = PackPolys[reader.ReadUInt16()];
                }
            }

            return(true);
        }
Exemplo n.º 10
0
 public void SetPolygonAt(int inx, CPolygon v)
 {
     C4dApiPINVOKE.PolygonObject_SetPolygonAt(swigCPtr, inx, CPolygon.getCPtr(v));
     if (C4dApiPINVOKE.SWIGPendingException.Pending)
     {
         throw C4dApiPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Exemplo n.º 11
0
        private static HashSet <CptEdgeDis> GroupCpgsAndBridgesForEachCluster_Prim(IEnumerable <CptEdgeDis> CptEdgeDisEb)
        {
            foreach (var cptEdgeDis in CptEdgeDisEb)
            {
                cptEdgeDis.CpgPairIncr.val1.isTraversed = false;
                cptEdgeDis.CpgPairIncr.val2.isTraversed = false;
            }

            var CpgCptEdgeDisLtDt = AttachCptEdgeDisLtToCpg(CptEdgeDisEb);

            var mincptEdgeDis = CptEdgeDisEb.GetMin(cptEdgeDis => cptEdgeDis.dblDis).Item1;

            var intCpgCount = CpgCptEdgeDisLtDt.Count;
            var FirstCpg    = mincptEdgeDis.CpgPairIncr.val1;

            FirstCpg.isTraversed = true;
            var groupcpglt = new List <CPolygon>(intCpgCount);

            groupcpglt.Add(FirstCpg);
            var BridgeCptEdgeDisSS = new HashSet <CptEdgeDis>();
            var QueueSS            = new SortedSet <CptEdgeDis>(CCmpCptEdgeDis_Dis.sComparer);

            FindandAddBridgeCptEdgeDisIntoQueue(QueueSS, FirstCpg, CpgCptEdgeDisLtDt);
            do
            {
                //brige polygons by shortest connections, to avoid crossed bridges
                var minCptEdgeDis = QueueSS.Min;
                QueueSS.Remove(minCptEdgeDis);

                var      cpg1       = minCptEdgeDis.CpgPairIncr.val1;
                var      cpg2       = minCptEdgeDis.CpgPairIncr.val2;
                CPolygon BridgedCpg = null;
                if (cpg1.isTraversed == true && cpg2.isTraversed == true)
                {
                    continue;
                }
                else if (cpg1.isTraversed == false && cpg2.isTraversed == true)
                {
                    BridgedCpg = cpg1;
                }
                else if (cpg1.isTraversed == true && cpg2.isTraversed == false)
                {
                    BridgedCpg = cpg2;
                }
                else
                {
                    throw new ArgumentException("impossible!");
                }
                BridgedCpg.isTraversed = true;
                groupcpglt.Add(BridgedCpg);
                BridgeCptEdgeDisSS.Add(minCptEdgeDis);

                FindandAddBridgeCptEdgeDisIntoQueue(QueueSS, BridgedCpg, CpgCptEdgeDisLtDt);
            } while (QueueSS.Count > 0 && groupcpglt.Count < intCpgCount);


            return(BridgeCptEdgeDisSS);
        }
Exemplo n.º 12
0
        private IEnumerable <CPolygon> GrowAndClipMergedCpg_Overlap(CPolygon mergedcpg,
                                                                    double dblProp, string strSimplification, string strBufferStyle, double dblMiterLimit)
        {
            //dblProp = 0.2;
            //dblProp = 1;
            double dblCurrentScale   = _dblStartScale + dblProp * (_dblTargetScale - _dblStartScale);
            double dblCurrentGrow    = dblProp * _dblTotalGrow * CConstants.dblFclipper;
            double dblCurrentEpsilon = Math.Min(dblCurrentGrow / dblMiterLimit, _dblEpsilon * dblCurrentScale * CConstants.dblFclipper);
            double dblCurrentErosion = _dblErosion * dblCurrentScale * CConstants.dblFclipper;

            //double dblCurrentDilation = Math.Max(dblCurrentEpsilon / 2, dblProp * _dblDilation * dblCurrentScale * CConstants.dblFclipper);
            double dblCurrentDilation = (dblCurrentGrow - dblMiterLimit * dblCurrentErosion) / (dblMiterLimit - 1);
            //dblCurrentErosion = 0;
            //dblCurrentDilation = 0;

            var clipPathsFirstLevel = clipperMethods.GenerateClipPathsByCpgEb(mergedcpg.ClipCpgLt);
            var LastAndClippedPath  = new Paths();

            if (mergedcpg.SubCpgLt == null || mergedcpg.SubCpgLt.Count < 2)
            {
                LastAndClippedPath.AddRange(DilateErodeOffsetSimplifyCpg(mergedcpg,
                                                                         dblCurrentGrow, dblCurrentDilation, dblCurrentErosion, dblCurrentEpsilon,
                                                                         strSimplification, strBufferStyle, dblMiterLimit));
            }
            else
            {
                //var SubCpgLt = mergedcpg.SubCpgLt;
                var submergedcpglt = MergeCloseCpgsAndAddBridges(mergedcpg.SubCpgLt, false,  //---Merge---//
                                                                 dblCurrentGrow, dblCurrentDilation, dblCurrentEpsilon);
                //var BridgeCpipeDt = mergedcpg.BridgeCpipeDt;
                foreach (var submergedcpg in submergedcpglt)
                {
                    LastAndClippedPath.AddRange(DilateErodeOffsetSimplifyCpg(submergedcpg,
                                                                             dblCurrentGrow, dblCurrentDilation, dblCurrentErosion, dblCurrentEpsilon,
                                                                             strSimplification, strBufferStyle, dblMiterLimit));
                }
            }

            //CSaveFeature.SaveCEdgeEb(clipperMethods.ScaleCEdgeEb(
            //    clipperMethods.ConvertPathsToCEdgeEb(LastAndClippedPath, true), 1 / CConstants.dblFclipper),
            //    "GrownPathsWithoutMergeOrClip", blnVisible: false);

            LastAndClippedPath.AddRange(mergedcpg.LastTimePaths);
            var unitedPaths = clipperMethods.Clip_Paths(LastAndClippedPath, true, mergedcpg.LastTimePaths, true, ClipType.ctUnion);
            //var unitedPaths = LastAndClippedPath;

            var clippedPolyTree =
                clipperMethods.Clip_PolyTree(unitedPaths, true, clipPathsFirstLevel, true, ClipType.ctIntersection);

            mergedcpg.LastTimePaths = Clipper.PolyTreeToPaths(clippedPolyTree);
            var GrownAndClippedCpg = clipperMethods.GenerateCpgEbByPolyTree(clippedPolyTree, mergedcpg.ID, true);

            //CSaveFeature.SavePolyTreeAsCpgEb(clippedPolyTree, "GrownMergeClipPolyTree",
            //    pesriSimpleFillStyle: esriSimpleFillStyle.esriSFSNull, blnVisible: false);

            return(GrownAndClippedCpg);
        }
Exemplo n.º 13
0
 private static void UpdateCpgCptEdgeDisLtDt(
     ref Dictionary <CPolygon, List <CptEdgeDis> > CpgCptEdgeDisLtDt, CPolygon cpg, CptEdgeDis cptEdgeDis)
 {
     if (CpgCptEdgeDisLtDt.ContainsKey(cpg) == false)
     {
         CpgCptEdgeDisLtDt[cpg] = new List <CptEdgeDis>();
     }
     CpgCptEdgeDisLtDt[cpg].Add(cptEdgeDis);
 }
Exemplo n.º 14
0
 public static IFeatureLayer SaveCpg(CPolygon Cpg, string strFileName,
                                     List <string> pstrFieldNameLt = null, List <esriFieldType> pesriFieldTypeLt = null, List <List <object> > pobjectValueLtLt = null,
                                     int intRed        = _intColor, int intGreen = _intColor, int intBlue = _intColor, double dblWidth = 1,
                                     int intOutlineRed = _intColor, int intOutlineGreen = _intColor, int intOutlineBlue = _intColor,
                                     esriSimpleFillStyle pesriSimpleFillStyle = esriSimpleFillStyle.esriSFSSolid, string strSymbolLayerPath = null, bool blnVisible = true)
 {
     return(SaveCGeoEb(CHelpFunc.MakeLt(Cpg), esriGeometryType.esriGeometryPolygon, strFileName,
                       pstrFieldNameLt, pesriFieldTypeLt, pobjectValueLtLt,
                       intRed, intGreen, intBlue, dblWidth, intOutlineRed, intOutlineGreen, intOutlineBlue,
                       pesriSimpleFillStyle, strSymbolLayerPath, blnVisible));
 }
Exemplo n.º 15
0
        private void btnArea_Click(object sender, EventArgs e)
        {
            string strType = "";
            var    cptlt   = GetCptLt(rtbInput.Text, out strType);

            cptlt.Add(cptlt[0]);
            CPolygon cpg = new CPolygon(0, cptlt);

            cpg.SetAreaSimple();
            txtArea.Text = cpg.dblAreaSimple.ToString();
        }
Exemplo n.º 16
0
        public void AddWeightData(SceneNodeContainer snc, PolygonObject polyOb, CAWeightTag weightTag, IEnumerable <int> range)
        {
            if (weightTag == null || polyOb == null)
            {
                return;
            }

            List <VertexWeightList> weightMap       = new List <VertexWeightList>();
            List <float4x4>         bindingMatrices = new List <float4x4>();

            foreach (int j in range)
            {
                using (CPolygon poly = polyOb.GetPolygonAt(j))
                {
                    foreach (int iVert in GetPolyPointIndices(poly, polyOb))
                    {
                        var vertexWeights = new List <VertexWeight>();

                        for (int iJoint = 0; iJoint < weightTag.GetJointCount(); iJoint++)
                        {
                            double weight = weightTag.GetWeight(iJoint, iVert);

                            // Leave out zero weights. This will save space for the sparse weight table.
                            if (Math.Abs(weight) > double.Epsilon)
                            {
                                vertexWeights.Add(new VertexWeight {
                                    JointIndex = iJoint, Weight = (float)weight
                                });
                            }
                        }

                        vertexWeights.Sort((vw1, vw2) => ((int)(vw1.Weight - vw2.Weight)));
                        weightMap.Add(new VertexWeightList {
                            VertexWeights = vertexWeights
                        });
                    }
                }
            }
            for (int iJoint = 0; iJoint < weightTag.GetJointCount(); iJoint++)
            {
                // Add Binding Matrix
                JointRestState jointRestState = weightTag.GetJointRestState(iJoint);
                float4x4       mat            = (float4x4)(jointRestState.m_oMi * weightTag.GetGeomMg());
                bindingMatrices.Add(mat);
            }

            _weightObjects.Add(new WeightObject()
            {
                SceneNodeContainer = snc,
                WeightTag          = weightTag,
                WeightMap          = weightMap,
                BindingMatrices    = bindingMatrices
            });
        }
Exemplo n.º 17
0
        //private static CPolygon GenerateCpgEbByPolyNode(PolyNode cpgnode, int intID, bool blnReverse = false)
        //{
        //    var cptlt = ContourToCptEb(cpgnode.Contour, blnReverse).ToList();
        //    var holecptlt = GetOLHCptLtEb(cpgnode, blnReverse).ToLtLt();

        //    return new CPolygon(intID, cptlt, holecptlt);
        //}


        //public static IEnumerable<CPolygon> GenerateOLHCpgEbByPolyTree(PolyTree pPolyTree, int intID, bool blnReverse = false)
        //{
        //    foreach (var polyNode in pPolyTree.Childs)
        //    {
        //        yield return GenerateOLHCpgEbByPolyNode(polyNode, intID, blnReverse);
        //    }
        //}

        private static CPolygon GenerateOLHCpgEbByPolyNode(PolyNode cpgnode, int intID, bool blnReverse = false)
        {
            //tiny edges cause problems for our Imai-Iri algorithm
            var cptlt     = CGeoFunc.RemoveClosePointsForCptEb(ConvertPathToCptEb(cpgnode.Contour, blnReverse)).ToList();
            var holecptlt = GetOLHCptLtEb(cpgnode, blnReverse).ToLtLt();

            var cpg = new CPolygon(intID, cptlt, holecptlt);

            //CSaveFeature.SaveCpgEb(clipperMethods.ScaleCpgEb(CHelpFunc.MakeLt(cpg), 1 / CConstants.dblFclipper), "Cpg");

            return(cpg);
        }
Exemplo n.º 18
0
        /**********************************************************
         * To check the Pt is in the Triangle or not.
         * If the Pt is in the line or is a vertex, then return true.
         * If the Pt is out of the Triangle, then return false.
         *
         * This method is used for triangle only.
         ***********************************************************/
        private bool TriangleContainsPoint(CPoint2D[] trianglePts, CPoint2D pt)
        {
            if (trianglePts.Length != 3)
            {
                return(false);
            }

            for (int i = trianglePts.GetLowerBound(0);
                 i < trianglePts.GetUpperBound(0); i++)
            {
                if (pt.EqualsPoint(trianglePts[i]))
                {
                    return(true);
                }
            }

            bool bIn = false;

            CLineSegment line0 = new CLineSegment(trianglePts[0], trianglePts[1]);
            CLineSegment line1 = new CLineSegment(trianglePts[1], trianglePts[2]);
            CLineSegment line2 = new CLineSegment(trianglePts[2], trianglePts[0]);

            if (pt.InLine(line0) || pt.InLine(line1) ||
                pt.InLine(line2))
            {
                bIn = true;
            }
            else             //point is not in the lines
            {
                double dblArea0 = CPolygon.PolygonArea(new CPoint2D[]
                                                       { trianglePts[0], trianglePts[1], pt });
                double dblArea1 = CPolygon.PolygonArea(new CPoint2D[]
                                                       { trianglePts[1], trianglePts[2], pt });
                double dblArea2 = CPolygon.PolygonArea(new CPoint2D[]
                                                       { trianglePts[2], trianglePts[0], pt });

                if (dblArea0 > 0)
                {
                    if ((dblArea1 > 0) && (dblArea2 > 0))
                    {
                        bIn = true;
                    }
                }
                else if (dblArea0 < 0)
                {
                    if ((dblArea1 < 0) && (dblArea2 < 0))
                    {
                        bIn = true;
                    }
                }
            }
            return(bIn);
        }
Exemplo n.º 19
0
        private static IEnumerable <Path> GeneratePathEbByCpg(CPolygon cpg)
        {
            yield return(GeneratePathByCptEb(cpg.CptLt, true));

            if (cpg.HoleCpgLt != null)
            {
                foreach (var holecpg in cpg.HoleCpgLt)
                {
                    yield return(GeneratePathByCptEb(cpg.CptLt, true));
                }
            }
        }
Exemplo n.º 20
0
        public static CPolygon ConvertToClipper(Polygon2d poly, double nIntScale)
        {
            int      N            = poly.VertexCount;
            CPolygon clipper_poly = new CPolygon(N);

            for (int i = 0; i < N; ++i)
            {
                Vector2d v = poly[i];
                clipper_poly.Add(new IntPoint(nIntScale * v.x, nIntScale * v.y));
            }
            return(clipper_poly);
        }
Exemplo n.º 21
0
        public static IEnumerable <int> GetPolyPointIndices(CPolygon polygon, PolygonObject polyOb)
        {
            yield return(polygon.a);

            yield return(polygon.b);

            yield return(polygon.c);

            if (!IsTri(polygon, polyOb))
            {
                yield return(polygon.d);
            }
        }
Exemplo n.º 22
0
        public static Paths DilateErodeOffsetCpgExterior_Paths(CPolygon Cpg,
                                                               double dblGrow, double dblDilation, double dblErosion, string strBufferStyle, double dblMiterLimit)
        {
            double dblHoleIndicator = 1;

            if (Cpg.IsHole == true)
            {
                dblHoleIndicator = -1;
            }

            if (Cpg.ExteriorPath == null)
            {
                Cpg.SetExteriorPath();
            }
            var overdilationPaths = Offset_Paths(CHelpFunc.MakeLt(Cpg.ExteriorPath),
                                                 dblHoleIndicator * (dblGrow + dblDilation), strBufferStyle, dblMiterLimit);
            var erosionpaths = Offset_Paths(overdilationPaths,
                                            dblHoleIndicator * (-dblDilation - dblErosion), strBufferStyle, dblMiterLimit);


            //var ExteriorPath = GeneratePathByCpgExterior(Cpg);

            //var growndilationPaths = Offset_Paths(CHelpFunc.MakeLt(ExteriorPath),
            //    dblHoleIndicator * (dblGrow ), strBufferStyle, dblMiterLimit);

            //var overdilationPaths = Offset_Paths(growndilationPaths,
            //    dblHoleIndicator * (dblDilation), strBufferStyle, dblMiterLimit);

            //var backPaths = Offset_Paths(overdilationPaths,
            //    dblHoleIndicator * (-dblDilation), strBufferStyle, dblMiterLimit);

            //var erosionpaths = Offset_Paths(backPaths,
            //    dblHoleIndicator * (- dblErosion), strBufferStyle, dblMiterLimit);



            //CSaveFeature.SaveCpgEb(clipperMethods.ScaleCpgLt(CHelpFunc.MakeLt(Cpg), 1 / CConstants.dblFclipper),
            //    "Cpg");
            ////            CSaveFeature.SaveCEdgeEb(clipperMethods.ScaleCEdgeEb(clipperMethods.ConvertPathsToCEdgeLt(
            ////growndilationPaths, true), 1 / CConstants.dblFclipper), "growndilationPaths", CConstants.ParameterInitialize);
            //CSaveFeature.SaveCEdgeEb(clipperMethods.ScaleCEdgeEb(clipperMethods.ConvertPathsToCEdgeLt(overdilationPaths, true),
            //    1 / CConstants.dblFclipper), "overdilationPaths");
            ////            CSaveFeature.SaveCEdgeEb(clipperMethods.ScaleCEdgeEb(clipperMethods.ConvertPathsToCEdgeLt(
            ////backPaths, true), 1 / CConstants.dblFclipper), "backPaths", CConstants.ParameterInitialize);
            //CSaveFeature.SaveCEdgeEb(clipperMethods.ScaleCEdgeEb(clipperMethods.ConvertPathsToCEdgeLt(erosionpaths, true),
            //    1 / CConstants.dblFclipper), "erosionpaths");


            return(Offset_Paths(erosionpaths, dblHoleIndicator * dblErosion, strBufferStyle, dblMiterLimit));
        }
Exemplo n.º 23
0
        private void btnCentroid_Click(object sender, EventArgs e)
        {
            string strType = "";
            var    cptlt   = GetCptLt(rtbInput.Text, out strType);

            cptlt.Add(cptlt[0]);
            CPolygon cpg = new CPolygon(0, cptlt);

            var ccpt = cpg.SetCentroidCptSimple();

            txtCentroidX.Text  = ccpt.X.ToString();
            txtCentroidY.Text  = ccpt.Y.ToString();
            txtCentroidXY.Text = txtCentroidX.Text + " " + txtCentroidY.Text;
        }
Exemplo n.º 24
0
        public static Polygon2d ConvertFromClipper(CPolygon clipper_poly, double nIntScale)
        {
            double scale = 1.0 / (double)nIntScale;

            int       N    = clipper_poly.Count;
            Polygon2d poly = new Polygon2d();

            for (int i = 0; i < N; ++i)
            {
                IntPoint p = clipper_poly[i];
                Vector2d v = new Vector2d((double)p.X * scale, (double)p.Y * scale);
                poly.AppendVertex(v);
            }
            return(poly);
        }
Exemplo n.º 25
0
        /*******************************************************
        *  To cut an ear from polygon to make ears and an updated polygon:
        *******************************************************/
        public void CutEar()
        {
            CPolygon polygon = new CPolygon(m_aUpdatedPolygonVertices);
            bool     bFinish = false;

            //if (polygon.GetPolygonType()==PolygonType.Convex) //don't have to cut ear
            //	bFinish=true;

            if (m_aUpdatedPolygonVertices.Length == 3)           //triangle, don't have to cut ear
            {
                bFinish = true;
            }

            CPoint2D pt = new CPoint2D();

            while (bFinish == false)           //UpdatedPolygon
            {
                int  i         = 0;
                bool bNotFound = true;
                while (bNotFound &&
                       (i < m_aUpdatedPolygonVertices.Length))                   //loop till find an ear
                {
                    pt = m_aUpdatedPolygonVertices[i];
                    if (IsEarOfUpdatedPolygon(pt))
                    {
                        bNotFound = false;                       //got one, pt is an ear
                    }
                    else
                    {
                        i++;
                    }
                }                 //bNotFount
                //An ear found:}
                if (pt != null)
                {
                    UpdatePolygonVertices(pt);
                }

                polygon = new CPolygon(m_aUpdatedPolygonVertices);
                //if ((polygon.GetPolygonType()==PolygonType.Convex)
                //	&& (m_aUpdatedPolygonVertices.Length==3))
                if (m_aUpdatedPolygonVertices.Length == 3)
                {
                    bFinish = true;
                }
            }             //bFinish=false
            SetPolygons();
        }
Exemplo n.º 26
0
        private void btnLength_Click(object sender, EventArgs e)
        {
            string strType = "";
            var    cptlt   = GetCptLt(rtbInput.Text, out strType);

            if (strType == "Polyline")
            {
                CPolyline cpl = new CPolyline(0, cptlt);
                txtLength.Text = cpl.SetLengthSimple().ToString();
            }
            else
            {
                cptlt.Add(cptlt[0]);
                CPolygon cpg = new CPolygon(0, cptlt);
                txtLength.Text = cpg.SetLengthSimple().ToString();
            }
        }
Exemplo n.º 27
0
        private Paths DilateErodeOffsetSimplifyCpg(CPolygon cpg,
                                                   double dblGrow, double dblDilation, double dblErosion, double dblEpsilon,
                                                   string strSimplification, string strBufferStyle, double dblMiterLimit)
        {
            var rawPaths = new Paths();

            var rawCpgEb = clipperMethods.DilateErodeOffsetSimplifyOneComponent(cpg,
                                                                                dblGrow, dblDilation, dblErosion, dblEpsilon,
                                                                                strSimplification, true, strBufferStyle, dblMiterLimit);

            //CSaveFeature.SaveCpgEb(rawCpgEb, "rawCpgEb" + CHelpFunc.GetTimeStampWithPrefix());
            foreach (var rawCpg in rawCpgEb)
            {
                rawCpg.SetExteriorPath();
                rawPaths.AddRange(rawCpg.GetAllPaths());
            }


            if (cpg.HoleCpgLt != null && cpg.HoleCpgLt.Count > 0)
            {
                foreach (var holecpg in cpg.HoleCpgLt)
                {
                    if (holecpg.ClipCpgLt == null || holecpg.ClipCpgLt.Count == 0)
                    {
                        continue;
                    }

                    var rawholePaths = new Paths();
                    var rawholeCpgEb = clipperMethods.DilateErodeOffsetSimplifyOneComponent(holecpg,
                                                                                            dblGrow, dblDilation, dblErosion, dblEpsilon,
                                                                                            strSimplification, true, strBufferStyle, dblMiterLimit);
                    foreach (var rawholeCpg in rawholeCpgEb)
                    {
                        rawholeCpg.SetExteriorPath();
                        rawholePaths.AddRange(rawholeCpg.GetAllPaths());
                    }


                    var clipPaths    = clipperMethods.GenerateClipPathsByCpgEb(holecpg.ClipCpgLt);
                    var clippedPaths = clipperMethods.Clip_Paths(rawholePaths, true, clipPaths, true, ClipType.ctIntersection);
                    rawPaths.AddRange(clippedPaths);
                }
            }

            return(rawPaths);
        }
Exemplo n.º 28
0
        public void UnPack(BinaryReader reader)
        {
            CellStructId    = reader.ReadUInt32();
            Polygons        = new CPolygon[reader.ReadUInt32()];
            PhysicsPolygons = new CPolygon[reader.ReadUInt32()];
            Portals         = new CPolygon[reader.ReadUInt32()];

            VertexArray.UnPack(reader);

            for (int i = 0; i < Polygons.Length; i++)
            {
                Polygons[i] = new CPolygon();
                Polygons[i].UnPack(reader);
            }

            for (int i = 0; i < Portals.Length; i++)
            {
                Portals[i] = Polygons[reader.ReadUInt16()];
            }

            reader.Align();

            BspNode.PackPolys    = Polygons;
            BspNode.PackTreeType = BspTreeType.Cell;
            CellBsp.UnPack(reader);

            for (int i = 0; i < PhysicsPolygons.Length; i++)
            {
                PhysicsPolygons[i] = new CPolygon();
                PhysicsPolygons[i].UnPack(reader);
            }

            BspNode.PackPolys    = PhysicsPolygons;
            BspNode.PackTreeType = BspTreeType.Physics;
            PhysicsBsp.UnPack(reader);

            if (reader.ReadUInt32() != 0u)
            {
                BspNode.PackPolys    = Polygons;
                BspNode.PackTreeType = BspTreeType.Drawing;
                DrawingBsp.UnPack(reader);
            }

            reader.Align();
        }
Exemplo n.º 29
0
        /****************************************************
         * To fill m_aUpdatedPolygonVertices array with input array.
         *
         * m_aUpdatedPolygonVertices is a working array that will
         * be updated when an ear is cut till m_aUpdatedPolygonVertices
         * makes triangle (a convex polygon).
         ******************************************************/
        private void SetUpdatedPolygonVertices()
        {
            int nVertices = m_aInputVertices.Length;

            m_aUpdatedPolygonVertices = new CPoint2D[nVertices];

            for (int i = 0; i < nVertices; i++)
            {
                m_aUpdatedPolygonVertices[i] = m_aInputVertices[i];
            }

            //m_aUpdatedPolygonVertices should be in count clock wise
            if (CPolygon.PointsDirection(m_aUpdatedPolygonVertices)
                == PolygonDirection.Clockwise)
            {
                CPolygon.ReversePointsDirection(m_aUpdatedPolygonVertices);
            }
        }
Exemplo n.º 30
0
        private double ComputeCpgAreaAndRemoveSmallHoles(CPolygon cpg, double dblHoleAreaLimit)
        {
            cpg.SetAreaSimple();

            if (cpg.HoleCpgLt != null)
            {
                var holecpglt = new List <CPolygon>(cpg.HoleCpgLt.Count);
                foreach (var holecpg in cpg.HoleCpgLt)
                {
                    if (holecpg.dblAreaSimple >= dblHoleAreaLimit)
                    {
                        holecpglt.Add(holecpg);
                    }
                }
                cpg.HoleCpgLt = holecpglt;
            }
            return(cpg.dblAreaSimple);
        }