Example #1
0
        public bool AddConstraints(List <TriangulationConstraint> constraints)
        {
            if (constraints == null || constraints.Count < 1)
            {
                return(false);
            }

            bool bOK = true;

            foreach (TriangulationConstraint tc in constraints)
            {
                if (ConstrainPointToBounds(tc.P) || ConstrainPointToBounds(tc.Q))
                {
                    tc.CalculateContraintCode();
                }

                TriangulationConstraint tcTmp = null;
                if (!mConstraintMap.TryGetValue(tc.ConstraintCode, out tcTmp))
                {
                    tcTmp = tc;
                    bOK   = AddConstraint(tcTmp) && bOK;
                }
            }

            return(bOK);
        }
Example #2
0
        public ConstrainedPointSet(List <TriangulationPoint> bounds, int[] indices) : base(bounds)
        {
            AddBoundaryConstraints();
            List <TriangulationConstraint> l = new List <TriangulationConstraint>();

            for (int i = 0; i < indices.Length; i += 2)
            {
                TriangulationConstraint tc = new TriangulationConstraint(bounds[i], bounds[i + 1]);
                l.Add(tc);
            }
            AddConstraints(l);
        }
Example #3
0
        public override void Prepare(TriangulationContext tcx)
        {
            if (!Initialize())
            {
                return;
            }

            base.Prepare(tcx);

            Dictionary <uint, TriangulationConstraint> .Enumerator it = mConstraintMap.GetEnumerator();
            while (it.MoveNext())
            {
                TriangulationConstraint tc = it.Current.Value;
                tcx.NewConstraint(tc.P, tc.Q);
            }
        }
Example #4
0
        protected void AddBoundaryConstraints()
        {
            TriangulationPoint ptLL = null;
            TriangulationPoint ptLR = null;
            TriangulationPoint ptUR = null;
            TriangulationPoint ptUL = null;

            if (!TryGetPoint(MinX, MinY, out ptLL))
            {
                ptLL = new TriangulationPoint(MinX, MinY);
                Add(ptLL);
            }
            if (!TryGetPoint(MaxX, MinY, out ptLR))
            {
                ptLR = new TriangulationPoint(MaxX, MinY);
                Add(ptLR);
            }
            if (!TryGetPoint(MaxX, MaxY, out ptUR))
            {
                ptUR = new TriangulationPoint(MaxX, MaxY);
                Add(ptUR);
            }
            if (!TryGetPoint(MinX, MaxY, out ptUL))
            {
                ptUL = new TriangulationPoint(MinX, MaxY);
                Add(ptUL);
            }
            TriangulationConstraint tcLLtoLR = new TriangulationConstraint(ptLL, ptLR);

            AddConstraint(tcLLtoLR);
            TriangulationConstraint tcLRtoUR = new TriangulationConstraint(ptLR, ptUR);

            AddConstraint(tcLRtoUR);
            TriangulationConstraint tcURtoUL = new TriangulationConstraint(ptUR, ptUL);

            AddConstraint(tcURtoUL);
            TriangulationConstraint tcULtoLL = new TriangulationConstraint(ptUL, ptLL);

            AddConstraint(tcULtoLL);
        }
Example #5
0
        public bool AddConstraint(TriangulationConstraint tc)
        {
            if (tc == null || tc.P == null || tc.Q == null)
            {
                return(false);
            }

            if (mConstraintMap.ContainsKey(tc.ConstraintCode))
            {
                return(true);
            }

            TriangulationPoint p;

            if (TryGetPoint(tc.P.X, tc.P.Y, out p))
            {
                tc.P = p;
            }
            else
            {
                Add(tc.P);
            }

            if (TryGetPoint(tc.Q.X, tc.Q.Y, out p))
            {
                tc.Q = p;
            }
            else
            {
                Add(tc.Q);
            }

            mConstraintMap.Add(tc.ConstraintCode, tc);

            return(true);
        }
Example #6
0
 public bool TryGetConstraint(uint constraintCode, out TriangulationConstraint tc)
 {
     return(mConstraintMap.TryGetValue(constraintCode, out tc));
 }
Example #7
0
        public bool AddHole(List <TriangulationPoint> points, string name)
        {
            if (points == null)
            {
                return(false);
            }

            List <Contour> pts     = new List <Contour>();
            int            listIdx = 0;

            {
                Contour c = new Contour(this, points, WindingOrderType.Unknown);
                pts.Add(c);

                if (mPoints.Count > 1)
                {
                    int numPoints = pts[listIdx].Count;
                    for (int i = 0; i < numPoints; ++i)
                    {
                        ConstrainPointToBounds(pts[listIdx][i]);
                    }
                }
            }

            while (listIdx < pts.Count)
            {
                pts[listIdx].RemoveDuplicateNeighborPoints();
                pts[listIdx].WindingOrder = Point2DList.WindingOrderType.Default;

                bool bListOK = true;
                Point2DList.PolygonError err = pts[listIdx].CheckPolygon();
                while (bListOK && err != PolygonError.None)
                {
                    if ((err & PolygonError.NotEnoughVertices) == PolygonError.NotEnoughVertices)
                    {
                        bListOK = false;
                        continue;
                    }
                    if ((err & PolygonError.NotSimple) == PolygonError.NotSimple)
                    {
                        List <Point2DList> l = PolygonUtil.SplitComplexPolygon(pts[listIdx], pts[listIdx].Epsilon);
                        pts.RemoveAt(listIdx);
                        foreach (Point2DList newList in l)
                        {
                            Contour c = new Contour(this);
                            c.AddRange(newList);
                            pts.Add(c);
                        }
                        err = pts[listIdx].CheckPolygon();
                        continue;
                    }
                    if ((err & PolygonError.Degenerate) == PolygonError.Degenerate)
                    {
                        pts[listIdx].Simplify(this.Epsilon);
                        err = pts[listIdx].CheckPolygon();
                        continue;
                    }
                    if ((err & PolygonError.AreaTooSmall) == PolygonError.AreaTooSmall || (err & PolygonError.SidesTooCloseToParallel) == PolygonError.SidesTooCloseToParallel || (err & PolygonError.TooThin) == PolygonError.TooThin || (err & PolygonError.Unknown) == PolygonError.Unknown)
                    {
                        bListOK = false;
                        continue;
                    }
                }
                if (!bListOK && pts[listIdx].Count != 2)
                {
                    pts.RemoveAt(listIdx);
                }
                else
                {
                    ++listIdx;
                }
            }

            bool bOK = true;

            listIdx = 0;
            while (listIdx < pts.Count)
            {
                int numPoints = pts[listIdx].Count;
                if (numPoints < 2)
                {
                    ++listIdx;
                    bOK = false;
                    continue;
                }
                else if (numPoints == 2)
                {
                    uint constraintCode        = TriangulationConstraint.CalculateContraintCode(pts[listIdx][0], pts[listIdx][1]);
                    TriangulationConstraint tc = null;
                    if (!mConstraintMap.TryGetValue(constraintCode, out tc))
                    {
                        tc = new TriangulationConstraint(pts[listIdx][0], pts[listIdx][1]);
                        AddConstraint(tc);
                    }
                }
                else
                {
                    Contour ph = new Contour(this, pts[listIdx], Point2DList.WindingOrderType.Unknown);
                    ph.WindingOrder = Point2DList.WindingOrderType.Default;
                    ph.Name         = name + ":" + listIdx.ToString();
                    mHoles.Add(ph);
                }
                ++listIdx;
            }

            return(bOK);
        }
Example #8
0
 public void CalculateContraintCode()
 {
     mContraintCode = TriangulationConstraint.CalculateContraintCode(P, Q);
 }