/// <summary>
 /// add a line segment
 /// initialize it before adding
 /// </summary>
 /// <param name="l"></param>
 public void Add(LineSegment l)
 {
     // assigne data term
     //l.Initialize(_srcImage, _gvfU, _gvfV, _gvfMagnitude);
     //l.Index = _n;
     // add line segment
     _configuration.Add(l);
     _n++;
 }
Beispiel #2
0
        /// <summary>
        /// is the line segment part of l?
        /// </summary>
        /// <param name="l"></param>
        /// <returns></returns>
        public bool IsPartOf(LineSegment l)
        {
            if (_pointList.Count > l.PointList.Count)
                return false;

            foreach (PZPoint p in _pointList)
            {
                bool pIsPart = false;

                foreach (PZPoint q in l.PointList)
                {
                    if (p.EqualTo(q))
                    {
                        pIsPart = true;
                        break;
                    }
                }

                if (!pIsPart)
                {
                    return false;
                }
            }

            return true;
        }
Beispiel #3
0
 /// <summary>
 /// merge the current line segment to the other, end to end
 /// only merge point list, so that the merged line segment needs Initialize()
 /// connections are copied. 
 /// </summary>
 /// <returns></returns>
 public LineSegment MergeTo(LineSegment l)
 {
     LineSegment newl = new LineSegment();
     // this is a, and input (l) is b
     int aLength = this.Ls;
     int bLength = l.Ls;
     int newLength = aLength + bLength - 1;
     int[] pointIndex = new int[newLength];
     #region find start and end points
     // find start and end point
     PZPoint aStart = _startPoint;
     PZPoint aEnd = _endPoint;
     PZPoint bStart = l.StartPoint;
     PZPoint bEnd = l.EndPoint;
     if (aStart.Equals(bStart))
     {
         // aEnd -> aStart(bStart) -> bEnd
         for (int i = 0; i < aLength; i++)
             pointIndex[i] = aLength - i - 1;
         for (int i = 1; i < bLength; i++)
             pointIndex[i + aLength - 1] = i;
     }
     else if (aStart.Equals(bEnd))
     {
         // aEnd -> aStart(bEnd) -> bStart
         for (int i = 0; i < aLength; i++)
             pointIndex[i] = aLength - i - 1;
         for (int i = 1; i < bLength; i++)
             pointIndex[i + aLength - 1] = bLength - i - 1;
     }
     else if (aEnd.Equals(bStart))
     {
         // aStart -> aEnd(bStart) -> bEnd
         for (int i = 0; i < aLength; i++)
             pointIndex[i] = i;
         for (int i = 1; i < bLength; i++)
             pointIndex[i + aLength - 1] = i;
     }
     else
     {
         // aStart- -> aEnd(bEnd) -> bStart
         for (int i = 0; i < aLength; i++)
             pointIndex[i] = i;
         for (int i = 1; i < bLength; i++)
             pointIndex[i + aLength - 1] = bLength - i - 1;
     }
     #endregion
     // generate the new line segment
     newl.Ls = newLength;
     // a -> b
     newl.StartPoint = new PZPoint(_pointList[pointIndex[0]]);
     newl.EndPoint = new PZPoint(l.PointList[pointIndex[newLength - 1]]);
     int indexCount = 0;
     for (int i = 0; i < aLength; i++)
     {
         newl.PointList.Add(_pointList[pointIndex[indexCount]]);
         indexCount++;
     }
     for (int i = 1; i < bLength; i++)
     {
         newl.PointList.Add(l.PointList[pointIndex[indexCount]]);
         indexCount++;
     }
     return newl;
 }
Beispiel #4
0
 /// <summary>
 /// is the line segment connected with l?
 /// </summary>
 /// <param name="l"></param>
 /// <returns></returns>
 public bool IsConnectedWith(LineSegment l)
 {
     bool isConnected = true;
     if ((_startPoint.EqualTo(l._startPoint) && _endPoint.EqualTo(l._endPoint))
         || (_startPoint.EqualTo(l._endPoint) && _endPoint.EqualTo(l._startPoint)))
         // a loop
         isConnected = false;
     else
     {
         if (_startPoint.EqualTo(l._startPoint))
         {
             _startPointConnectionList.Add(l);
             _startPointConnectionTypeList.Add(ConnectionPointType.Start);
         }
         else if (_startPoint.EqualTo(l._endPoint))
         {
             _startPointConnectionList.Add(l);
             _startPointConnectionTypeList.Add(ConnectionPointType.End);
         }
         else if (_endPoint.EqualTo(l._startPoint))
         {
             _endPointConnectionList.Add(l);
             _endPointConnectionTypeList.Add(ConnectionPointType.Start);
         }
         else if (_endPoint.EqualTo(l._endPoint))
         {
             _endPointConnectionList.Add(l);
             _endPointConnectionTypeList.Add(ConnectionPointType.End);
         }
         else
             isConnected = false;
     }
     return isConnected;
 }