示例#1
0
        private ContourLine TrackUnclosedContour(int crtTriangle, enumEdgeType crtEdge, double contValue)
        {
            if (_triangleIsUsed.IsTrue(crtTriangle))
            {
                return(null);
            }
            ContourLine cntLine = new ContourLine(contValue);

            UpdateClassIndex(cntLine);
            enumEdgeType firstEdge     = crtEdge;
            int          firstTriangle = crtTriangle;

            enumEdgeType[] otherEdges = new enumEdgeType[2];
            int            edgeIdx    = ToEdgeIndex(crtTriangle, crtEdge);
            bool           edgeUsed   = _edgeIsUsed.IsTrue(edgeIdx);
            PointF         vpt        = TryGetVPoint(crtTriangle, crtEdge, contValue);

            if (vpt.IsEmpty || edgeUsed)
            {
                return(null);
            }
            _edgeIsUsed.SetStatus(edgeIdx, true);
            return(TrackClosedContourFromEdge(crtTriangle, crtEdge, contValue, vpt,
                                              (idx) => { return IsBorderTriangle(idx); }, 2));
        }
示例#2
0
        public object Clone()
        {
            ContourLine cntLine = new ContourLine(_contourValue);

            cntLine._classIndex  = _classIndex;
            cntLine._count       = _count;
            cntLine._envelope    = this.Envelope.Clone() as ContourEnvelope;
            cntLine._pointsArray = this.Points.Clone() as PointF[];
            return(cntLine);
        }
示例#3
0
        private void ActionGenClosedContour(int idx)
        {
            if (IsBorderTriangle(idx))
            {
                _triangleIsUsed.SetStatus(idx, true);
                return;
            }
            ContourLine cLine = TrackClosedContour(idx, enumEdgeType.A, crtContourValue);

            if (cLine != null)
            {
                _contourLines.Add(cLine);
            }
        }
示例#4
0
 private void UpdateClassIndex(ContourLine cntLine)
 {
     if (_contourValues == null || _contourValues.Length == 0)
     {
         return;
     }
     for (int i = 0; i < _contourValues.Length; i++)
     {
         if (Math.Abs(_contourValues[i] - cntLine.ContourValue) < double.Epsilon)
         {
             cntLine.ClassIndex = i;
             break;
         }
     }
 }
示例#5
0
        private ContourLine[] ReadVersion0(FileStream fs, BinaryReader br, out ContourPersist.enumCoordType coordType, out ContourLine.ContourEnvelope envelope, out string spatialRef)
        {
            int cntCount = br.ReadInt32();

            coordType = (enumCoordType)br.ReadByte();
            envelope  = ReadEnvelope(br);
            int spLen = br.ReadInt32();

            spatialRef = ReadSpatialRef(br, spLen);
            double[]           contourValues = ReadContourValues(br, cntCount);
            long[]             offsets       = ReadOffsets(br, cntCount);
            List <ContourLine> cntLines      = new List <ContourLine>(cntCount);

            for (int i = 0; i < cntCount; i++)
            {
                ContourLine cntLine = ReadCntLine(br, contourValues[i]);
                cntLines.Add(cntLine);
            }
            return(cntLines.Count > 0 ? cntLines.ToArray() : null);
        }
示例#6
0
        private void ActionTrackUnclosedContour(int idx)
        {
            ContourLine contLine = null;

            if (idx % _triWidth == 0)                 //left border
            {
                if (!crtCandidateTriansForUnclosed[idx].IsBContained)
                {
                    return;
                }
                contLine = TrackUnclosedContour(idx, enumEdgeType.B, crtContourValue);
            }
            else if ((idx + 1) % _triWidth == 0)      //right border
            {
                if (!crtCandidateTriansForUnclosed[idx].IsBContained)
                {
                    return;
                }
                contLine = TrackUnclosedContour(idx, enumEdgeType.B, crtContourValue);
            }
            else if (idx / _triWidth == 0)            //top border
            {
                if (!crtCandidateTriansForUnclosed[idx].IsAContained)
                {
                    return;
                }
                contLine = TrackUnclosedContour(idx, enumEdgeType.A, crtContourValue);
            }
            else if (idx / _triWidth == _gridHeight - 1)//bottom border
            {
                if (!crtCandidateTriansForUnclosed[idx].IsAContained)
                {
                    return;
                }
                contLine = TrackUnclosedContour(idx, enumEdgeType.A, crtContourValue);
            }
            if (contLine != null)
            {
                _contourLines.Add(contLine);
            }
        }
示例#7
0
        private unsafe ContourLine ReadCntLine(BinaryReader br, double contourValue)
        {
            ContourLine.ContourEnvelope evp = ReadEnvelope(br);
            ContourLine cntLine             = new ContourLine(contourValue);

            cntLine.ClassIndex = br.ReadInt32();
            int ptCount = br.ReadInt32();

            PointF[] pts = new PointF[ptCount];
            fixed(PointF *ptr0 = pts)
            {
                PointF *ptr = ptr0;

                for (int i = 0; i < ptCount; i++, ptr++)
                {
                    ptr->X = br.ReadSingle();
                    ptr->Y = br.ReadSingle();
                }
            }

            cntLine.AddPoints(pts);
            return(cntLine);
        }
示例#8
0
 private void GenerateClosedContours(double contourValue)
 {
     //串行算法
     if (_isParallel)
     {
         crtContourValue = contourValue;
         Parallel.For(0, _triangleCount, new Action <int>(ActionGenClosedContour));
     }
     else//并行算法
     {
         for (int i = 0; i < _triangleCount; i++)
         {
             if (IsBorderTriangle(i))
             {
                 continue;
             }
             ContourLine cLine = TrackClosedContour(i, enumEdgeType.A, contourValue);
             if (cLine != null)
             {
                 _contourLines.Add(cLine);
             }
         }
     }
 }
示例#9
0
        private ContourLine TrackClosedContourFromEdge(int crtTriangle, enumEdgeType crtEdge, double contValue, PointF vpt, Func <int, bool> isStop, int minPoints)
        {
            bool        isSharePointed = false;
            bool        edgeUsed       = false;
            ContourLine cntLine        = new ContourLine(contValue);

            UpdateClassIndex(cntLine);
            enumEdgeType[] otherEdges = new enumEdgeType[2];
            int            edgeIdx    = 0;
            bool           isClosed   = false;

            while (true)
            {
                //等值线进入当前三角形
                if (!isSharePointed)
                {
                    cntLine.AddPoint(vpt);
                }
                //查找等值线离开当前三角形的出口点
                SetOthterEdges(crtEdge, ref otherEdges);
                crtEdge  = otherEdges[0];
                edgeIdx  = ToEdgeIndex(crtTriangle, crtEdge);
                edgeUsed = _edgeIsUsed.IsTrue(edgeIdx);
                vpt      = !edgeUsed?TryGetVPoint(crtTriangle, crtEdge, contValue) : PointF.Empty;

                if (vpt.IsEmpty)//该边不包含等值点或者已被使用
                {
                    crtEdge  = otherEdges[1];
                    edgeIdx  = ToEdgeIndex(crtTriangle, crtEdge);
                    edgeUsed = _edgeIsUsed.IsTrue(edgeIdx);
                    vpt      = !edgeUsed?TryGetVPoint(crtTriangle, crtEdge, contValue) : PointF.Empty;

                    if (vpt.IsEmpty)//没有找到出口
                    {
                        break;
                    }
                    else
                    {
                        cntLine.AddPoint(vpt);
                        _edgeIsUsed.SetStatus(edgeIdx, true);
                    }
                }
                else
                {
                    cntLine.AddPoint(vpt);
                    _edgeIsUsed.SetStatus(edgeIdx, true);
                }
                //标记当前三角形已经使用
                _triangleIsUsed.SetStatus(crtTriangle, true);
                //查找当前三角形相连的三角形作为当前三角形
                crtTriangle = GetNextTriangle(crtTriangle, ref crtEdge);
                //退出条件
                if (crtTriangle == -1)
                {
                    break;
                }
                edgeIdx = ToEdgeIndex(crtTriangle, crtEdge);
                _edgeIsUsed.SetStatus(edgeIdx, false);//两个三角形的共享边标记为未使用
                if (isStop(crtTriangle))
                {
                    isClosed = true;
                    _edgeIsUsed.SetStatus(edgeIdx, true);
                    break;
                }
                if (_triangleIsUsed.IsTrue(crtTriangle))
                {
                    break;
                }
                isSharePointed = true;
            }
            if (_isOutputUncompleted)
            {
                return(cntLine.Count >= minPoints ? cntLine : null);
            }
            else
            {
                if (isClosed)
                {
                    return(cntLine.Count >= minPoints ? cntLine : null);
                }
                return(null);
            }
        }