Пример #1
0
        public void CreateLineLoops()
        {
            bool[] hasBeenAddedList = new bool[LineSegments.Count];

            for (int segmentToAddIndex = 0; segmentToAddIndex < LineSegments.Count; segmentToAddIndex++)
            {
                if (!hasBeenAddedList[segmentToAddIndex])
                {
                    // now find all the connected segments until we get back to this one
                    List <Vector2> loopToAdd = new List <Vector2>();

                    // walk the loop
                    int currentSegmentIndex           = segmentToAddIndex;
                    LineSegmentFloat currentSegment   = LineSegments[currentSegmentIndex];
                    Vector2          connectionVertex = currentSegment.end;
                    loopToAdd.Add(connectionVertex);
                    hasBeenAddedList[currentSegmentIndex] = true;
                    bool addedToLoop = false;
                    do
                    {
                        bool foundNextSegment = false;
                        addedToLoop = false;
                        for (int segmentToCheckIndex = 0; segmentToCheckIndex < LineSegments.Count; segmentToCheckIndex++)
                        {
                            LineSegmentFloat segmentToCheck = LineSegments[segmentToCheckIndex];
                            if (!hasBeenAddedList[segmentToCheckIndex])
                            {
                                if (connectionVertex == segmentToCheck.start)
                                {
                                    connectionVertex = segmentToCheck.end;
                                    foundNextSegment = true;
                                }
                                else if (connectionVertex == segmentToCheck.end)
                                {
                                    connectionVertex = segmentToCheck.start;
                                    foundNextSegment = true;
                                }
                                else
                                {
                                    int i = 0;
                                }

                                if (foundNextSegment)
                                {
                                    hasBeenAddedList[segmentToCheckIndex] = true;
                                    currentSegmentIndex = segmentToCheckIndex;
                                    currentSegment      = segmentToCheck;
                                    loopToAdd.Add(connectionVertex);
                                    addedToLoop = true;
                                    break;
                                }
                            }
                        }
                    } while (addedToLoop);

                    LineLoops.Add(loopToAdd);
                }
            }
        }
Пример #2
0
        LineSegmentFloat GetInterpolatedSegment(LineSegmentFloat segmentA, LineSegmentFloat segmentB)
        {
#if false
            float colorAStart = Math.Min(imageToMarch.GetBuffer()[imageToMarch.GetBufferOffsetXY((int)segmentA.start.x, (int)segmentA.start.y)], 1);
            float colorAEnd   = Math.Min(imageToMarch.GetBuffer()[imageToMarch.GetBufferOffsetXY((int)segmentA.end.x, (int)segmentA.end.y)], 1);

            Vector2 directionA = segmentA.end - segmentA.start;
            double  offsetA    = 1 - (colorAEnd + colorAStart) / 2.0;
            directionA *= offsetA;

            float colorBStart = Math.Min(imageToMarch.GetBuffer()[imageToMarch.GetBufferOffsetXY((int)segmentB.start.x, (int)segmentB.start.y)], 1);
            float colorBEnd   = Math.Min(imageToMarch.GetBuffer()[imageToMarch.GetBufferOffsetXY((int)segmentB.end.x, (int)segmentB.end.y)], 1);
#else
            float colorAStart = imageToMarch.GetBuffer()[imageToMarch.GetBufferOffsetXY((int)segmentA.start.x, (int)segmentA.start.y)];
            float colorAEnd   = imageToMarch.GetBuffer()[imageToMarch.GetBufferOffsetXY((int)segmentA.end.x, (int)segmentA.end.y)];

            Vector2 directionA = segmentA.end - segmentA.start;
            double  offsetA    = 1 - (colorAEnd + colorAStart) / 2.0;
            directionA *= offsetA;

            float colorBStart = imageToMarch.GetBuffer()[imageToMarch.GetBufferOffsetXY((int)segmentB.start.x, (int)segmentB.start.y)];
            float colorBEnd   = imageToMarch.GetBuffer()[imageToMarch.GetBufferOffsetXY((int)segmentB.end.x, (int)segmentB.end.y)];
#endif

            Vector2 directionB = segmentB.end - segmentB.start;
            double  ratioB     = 1 - (colorBEnd + colorBStart) / 2.0;
            directionB *= ratioB;

            double           offsetToPixelCenter = .5;
            LineSegmentFloat segment             = new LineSegmentFloat(
                (segmentA.start.x + directionA.x) + offsetToPixelCenter,
                (segmentA.start.y + directionA.y) + offsetToPixelCenter,
                (segmentB.start.x + directionB.x) + offsetToPixelCenter,
                (segmentB.start.y + directionB.y) + offsetToPixelCenter);

            return(segment);
        }
Пример #3
0
		private LineSegmentFloat GetInterpolatedSegment(LineSegmentFloat segmentA, LineSegmentFloat segmentB)
		{
#if false
            float colorAStart = Math.Min(imageToMarch.GetBuffer()[imageToMarch.GetBufferOffsetXY((int)segmentA.start.x, (int)segmentA.start.y)], 1);
            float colorAEnd = Math.Min(imageToMarch.GetBuffer()[imageToMarch.GetBufferOffsetXY((int)segmentA.end.x, (int)segmentA.end.y)], 1);

            Vector2 directionA = segmentA.end - segmentA.start;
            double offsetA = 1 - (colorAEnd + colorAStart) / 2.0;
            directionA *= offsetA;

            float colorBStart = Math.Min(imageToMarch.GetBuffer()[imageToMarch.GetBufferOffsetXY((int)segmentB.start.x, (int)segmentB.start.y)], 1);
            float colorBEnd = Math.Min(imageToMarch.GetBuffer()[imageToMarch.GetBufferOffsetXY((int)segmentB.end.x, (int)segmentB.end.y)], 1);
#else
			float colorAStart = imageToMarch.GetBuffer()[imageToMarch.GetBufferOffsetXY((int)segmentA.start.x, (int)segmentA.start.y)];
			float colorAEnd = imageToMarch.GetBuffer()[imageToMarch.GetBufferOffsetXY((int)segmentA.end.x, (int)segmentA.end.y)];

			Vector2 directionA = segmentA.end - segmentA.start;
			double offsetA = 1 - (colorAEnd + colorAStart) / 2.0;
			directionA *= offsetA;

			float colorBStart = imageToMarch.GetBuffer()[imageToMarch.GetBufferOffsetXY((int)segmentB.start.x, (int)segmentB.start.y)];
			float colorBEnd = imageToMarch.GetBuffer()[imageToMarch.GetBufferOffsetXY((int)segmentB.end.x, (int)segmentB.end.y)];
#endif

			Vector2 directionB = segmentB.end - segmentB.start;
			double ratioB = 1 - (colorBEnd + colorBStart) / 2.0;
			directionB *= ratioB;

			double offsetToPixelCenter = .5;
			LineSegmentFloat segment = new LineSegmentFloat(
				(segmentA.start.x + directionA.x) + offsetToPixelCenter,
				(segmentA.start.y + directionA.y) + offsetToPixelCenter,
				(segmentB.start.x + directionB.x) + offsetToPixelCenter,
				(segmentB.start.y + directionB.y) + offsetToPixelCenter);

			return segment;
		}