예제 #1
0
        private void GenerateUnclosedContours(double contourValue)
        {
            crtContourValue = contourValue;
            int       tCount = _borderTriangles.Length;
            VTriangle tri    = new VTriangle();

            crtCandidateTriansForUnclosed = new Dictionary <int, VTriangle>();
            for (int i = 0; i < tCount; i++)
            {
                tri = new VTriangle();
                ValIsContainedByTriangle(_borderTriangles[i], ToTValue(contourValue), ref tri);
                if (!tri.Is2Contained())
                {
                    continue;
                }
                if (crtCandidateTriansForUnclosed.ContainsKey(_borderTriangles[i]))//左下角和右上角的三角形是重复的
                {
                    continue;
                }
                crtCandidateTriansForUnclosed.Add(_borderTriangles[i], tri);
            }
            //并行算法
            if (_isParallel)
            {
                Parallel.ForEach <int>(crtCandidateTriansForUnclosed.Keys, new Action <int>(ActionTrackUnclosedContour));
            }
            else//串行算法
            {
                foreach (int key in crtCandidateTriansForUnclosed.Keys)
                {
                    ActionTrackUnclosedContour(key);
                }
            }
        }
예제 #2
0
        public void ValIsContainedByTriangle(int idx, T val, ref VTriangle triangle)
        {
            int  pixelRow    = idx / _triWidth;
            int  pixelCol    = idx % _triWidth / 2;
            bool isContained = false;
            int  pixelIdx    = 0;

            if (idx % 2 == 0)//偶数,左下三角形
            {
                pixelRow   += 1;
                pixelIdx    = pixelRow * _width + pixelCol;
                isContained = CheckIsContained(_bandValues[pixelIdx], _bandValues[pixelIdx + 1], val);          //left -> right
                if (isContained)
                {
                    triangle.SetAContained();
                }
                isContained = CheckIsContained(_bandValues[pixelIdx - _width], _bandValues[pixelIdx], val);     //top -> bottom
                if (isContained)
                {
                    triangle.SetBContained();
                }
                isContained = CheckIsContained(_bandValues[pixelIdx - _width], _bandValues[pixelIdx + 1], val); //lefttop -> rightbottom
                if (isContained)
                {
                    triangle.SetCContained();
                }
            }
            else//奇数,右上三角形
            {
                pixelCol   += 1;
                pixelIdx    = pixelRow * _width + pixelCol;
                isContained = CheckIsContained(_bandValues[pixelIdx - 1], _bandValues[pixelIdx], val);         //left -> right
                if (isContained)
                {
                    triangle.SetAContained();
                }
                isContained = CheckIsContained(_bandValues[pixelIdx], _bandValues[pixelIdx + _width], val);    //top -> bottom
                if (isContained)
                {
                    triangle.SetBContained();
                }
                isContained = CheckIsContained(_bandValues[pixelIdx - 1], _bandValues[pixelIdx + _width], val);//lefttop -> rightbottom
                if (isContained)
                {
                    triangle.SetCContained();
                }
            }
        }