Example #1
0
 public override System.Drawing.Point GetFirstPointOnXAxis(ImageInstance theImage, ref System.Drawing.Point theFirstPoint)
 {
     mMainROI.GetFirstPointOnXAxis(theImage, ref theFirstPoint);
     while (theFirstPoint.X != -1 && theFirstPoint.Y != -1 && mColorException.Matches(theImage.GetColor(theFirstPoint.X, theFirstPoint.Y)))
     {
         mMainROI.GetNextPointOnXAxis(theImage, ref theFirstPoint);
     }
     return(theFirstPoint);
 }
        public bool PixelMatches(int location, bool initializing)
        {
            // TODO: convert this from a method to an abstract class so I can have many different matchers (ie ColorMatchDefinition, Color, Gray Value, etc)...this will be easier after switching from LockBits to EditableBitmap
            int x;
            int y;

            switch (mEdgeAxis)
            {
            case Axis.X:
                x = location;
                y = pos;
                break;

            case Axis.Y:
                x = pos;
                y = location;
                break;

            default:
                throw new ArgumentException("Axis not defined alkjdlk");
                break;
            }
            if (mSearchRecord[x, y] == mSearchMarker)
            {
                // optimization...
                // THIS LOGIC CREATED A BUG: we've already looked at this pixel and it matched...so it must belong to a previous search which terminated because the object was too big...since we ran into it, this object is too big too
                // BUG DISCOVERED 8/18/08...the previous search could have been terminated because the object was TOO SMALL...it depends how shapes of the blobs and their spacial relationship...ie what about a big blob with a small piece cut off by a mark (e.g. weld)
                // Possible solution... don't mark the pixels searched immediately, but rather create a list of searched pixels and then mark them only if the blob is too big or runs into the edge of the ROI...might require a BIG list...list needs to be 2D to store X & Y
                // easiest solution I can think of: if a blob is too small, then clear all markings within it's bounding rectangle
                abort = true;
                return(false); // it must match since we've marked it previously, but we don't want to treat it as a find since we're aborting
            }
            Color theColor = ownerTool.GetPixelColor(x, y);
            bool  matches  = colorMatch.Matches(theColor);

            if (matches && !initializing)
            {
                mSearchRecord[x, y] = mSearchMarker;
            }
            return(matches);
        }
        public override void DoWork()
        {
            /*
             * if (!mStartX.IsComplete() ||
             *  !mStartY.IsComplete() ||
             *  !mSlopeRise.IsComplete() ||
             *  !mSlopeRun.IsComplete() ||
             *  !mRequiredConsecutivePixels.IsComplete() ||
             *  !mColorMatcher.IsComplete() ||
             *  !mSourceImage.IsComplete() ||
             *  !AreExplicitDependenciesComplete()
             *  ) return;*/

            TestExecution().LogMessageWithTimeFromTrigger("FindColorOnLine " + Name + " started");

            int resultX = -1;
            int resultY = -1;

            if (mSourceImage.Bitmap != null)
            {
                Color pixelColor;
                int   consecutivePixels = 0;
                bool  done = false;
                int   x    = (int)mStartX.ValueAsLong();
                int   y    = (int)mStartY.ValueAsLong();
                int   rise = (int)mSlopeRise.ValueAsLong();
                int   run  = (int)mSlopeRun.ValueAsLong();
                TestExecution().LogMessageWithTimeFromTrigger(Name + " starting searching at " + x + "," + y);
                while (!done && x >= 0 && x < mSourceImage.Bitmap.Width && y >= 0 && y < mSourceImage.Bitmap.Height)
                {
                    pixelColor = SourceImage.Bitmap.GetPixel(x, y);
                    if (mColorMatcher.Matches(pixelColor))
                    {
                        if (consecutivePixels == 0)
                        {
                            resultX = x;
                            resultY = y;
                            TestExecution().LogMessageWithTimeFromTrigger(Name + " found 1st match at " + x + "," + y);
                        }
                        consecutivePixels++;
                        if (consecutivePixels >= mRequiredConsecutivePixels.ValueAsLong())
                        {
                            TestExecution().LogMessageWithTimeFromTrigger(Name + " found last consecutive match at " + x + "," + y);
                            done = true;
                        }
                    }
                    else
                    {
                        consecutivePixels = 0;
                        resultX           = -2;
                        resultY           = -2;
                    }

                    mSearchEndX.SetValue(x);
                    mSearchEndY.SetValue(y);

                    x += run;
                    y += rise;
                }
            }
            else
            {
                mSearchEndX.SetValue(-1);
                mSearchEndY.SetValue(-1);
            }

            mResultX.SetValue(resultX);
            mResultY.SetValue(resultY);

            mResultX.SetIsComplete();
            mResultY.SetIsComplete();
            mSearchEndX.SetIsComplete();
            mSearchEndY.SetIsComplete();

            TestExecution().LogMessageWithTimeFromTrigger("FindColorOnLine " + Name + " completed; result=" + resultX + "," + resultY);
        }
Example #4
0
        public override void DoWork()
        {
            // NOTE: this code was adapted from FindObjectCenterOnLine; one difference is that it searched until it found the object, then quit.  We search the entire path
            DateTime startTime = DateTime.Now;

            TestExecution().LogMessageWithTimeFromTrigger("[" + Name + "] started at " + startTime + Environment.NewLine);

            int resultX = -1;
            int resultY = -1;

            if (mSourceImage.Bitmap == null)
            {
                TestExecution().LogErrorWithTimeFromTrigger("source image for '" + Name + "' does not exist.");
            }
            else if (mSearchPath == null)
            {
                TestExecution().LogErrorWithTimeFromTrigger("search line for '" + Name + "' isn't defined.");
            }
            else if (mSearchPath.StartX == null || mSearchPath.StartY == null || mSearchPath.EndX == null || mSearchPath.EndY == null)
            {
                TestExecution().LogErrorWithTimeFromTrigger("search line '" + mSearchPath.Name + "' for '" + Name + "' isn't fully defined.");
            }
            else if (mSearchPath.StartX.ValueAsLong() < 0 || mSearchPath.StartX.ValueAsLong() >= mSourceImage.Bitmap.Width ||
                     mSearchPath.StartY.ValueAsLong() < 0 || mSearchPath.StartY.ValueAsLong() >= mSourceImage.Bitmap.Height)
            {
                TestExecution().LogErrorWithTimeFromTrigger("The search line start point for '" + Name + "' isn't valid: " + mSearchPath.StartX.ValueAsLong() + "," + mSearchPath.StartY.ValueAsLong());
            }
            else if (mSearchPath.EndX.ValueAsLong() < 0 || mSearchPath.EndX.ValueAsLong() >= mSourceImage.Bitmap.Width ||
                     mSearchPath.EndY.ValueAsLong() < 0 || mSearchPath.EndY.ValueAsLong() >= mSourceImage.Bitmap.Height)
            {
                TestExecution().LogErrorWithTimeFromTrigger("The search line end point for '" + Name + "' isn't valid: " + mSearchPath.EndX.ValueAsLong() + "," + mSearchPath.EndY.ValueAsLong());
            }
            else if (Math.Abs(mSearchPath.StartX.ValueAsLong() - mSearchPath.EndX.ValueAsLong()) < 1 && Math.Abs(mSearchPath.StartY.ValueAsLong() - mSearchPath.EndY.ValueAsLong()) < 1)
            {
                TestExecution().LogErrorWithTimeFromTrigger("Search path is too small.");
            }
            else
            {
                long     width  = Math.Abs(mSearchPath.StartX.ValueAsLong() - mSearchPath.EndX.ValueAsLong()) + 1;
                long     height = Math.Abs(mSearchPath.StartY.ValueAsLong() - mSearchPath.EndY.ValueAsLong()) + 1;
                double   run;
                double   rise;
                double   angle;
                double   sineOfAngle   = -1;
                double   cosineOfAngle = -1;
                LineType lineType;
                long     length;
                startX = mSearchPath.StartX.ValueAsLong();
                startY = mSearchPath.StartY.ValueAsLong();
                endX   = mSearchPath.EndX.ValueAsLong();
                endY   = mSearchPath.EndY.ValueAsLong();
                if (mSearchPath.StartY.ValueAsLong() == mSearchPath.EndY.ValueAsLong()) // if it is horizonal line (no Y deviation)
                {
                    lineType      = LineType.Horizontal;
                    length        = width;
                    ySearchChange = 0;
                    if (mSearchPath.StartX.ValueAsLong() < mSearchPath.EndX.ValueAsLong())
                    {
                        xSearchChange = 1;
                    }
                    else
                    {
                        xSearchChange = -1;
                    }
                }
                else if (mSearchPath.StartX.ValueAsLong() == mSearchPath.EndX.ValueAsLong()) // if it is vertical line (no X deviation)
                {
                    lineType      = LineType.Vertical;
                    length        = height;
                    xSearchChange = 0;
                    if (mSearchPath.StartY.ValueAsLong() < mSearchPath.EndY.ValueAsLong()) // line is down
                    {
                        ySearchChange = 1;
                    }
                    else // line is up
                    {
                        ySearchChange = -1;
                    }
                }
                else // slanted line
                {
                    run           = mSearchPath.EndX.ValueAsLong() - mSearchPath.StartX.ValueAsLong();
                    rise          = mSearchPath.EndY.ValueAsLong() - mSearchPath.StartY.ValueAsLong();
                    angle         = Math.Atan(rise / run);
                    sineOfAngle   = Math.Sin(angle);
                    cosineOfAngle = Math.Cos(angle);
                    lineType      = LineType.Slanted;
                    length        = (long)Math.Sqrt(height * height + width * width);
                }
                leftEdgeOfSearch   = Math.Max(0, Math.Min(startX, endX));
                rightEdgeOfSearch  = Math.Min(mSourceImage.Bitmap.Width, Math.Max(startX, endX));
                topEdgeOfSearch    = Math.Max(0, Math.Min(startY, endY));
                bottomEdgeOfSearch = Math.Min(mSourceImage.Bitmap.Height, Math.Max(startY, endY));

                x = (int)startX;
                y = (int)startY;
                TestExecution().LogMessage(Name + " starting at " + x + "," + y);

                abort = false;
                Point firstPoint = new Point(-1, -1);
                Point lastPoint  = new Point(-1, -1);
                for (int searchIndex = 0; searchIndex <= length && !abort; searchIndex++)
                {
                    switch (lineType)
                    {
                    case LineType.Horizontal:
                        x = (int)(startX + (searchIndex * xSearchChange));
                        break;

                    case LineType.Vertical:
                        y = (int)(startY + (searchIndex * ySearchChange));
                        break;

                    case LineType.Slanted:
                        x = (int)(startX + Math.Round(searchIndex * cosineOfAngle));
                        y = (int)(startY + Math.Round(searchIndex * sineOfAngle));
                        break;
                    }

                    if (x < leftEdgeOfSearch || x > rightEdgeOfSearch || y < topEdgeOfSearch || y > bottomEdgeOfSearch)
                    {
                        TestExecution().LogErrorWithTimeFromTrigger(Name + " aborting at " + x + "," + y + ". Out of range from path for some reason.");
                        abort = true;
                    }
                    else
                    {
                        pixelColor = mSourceImage.GetColor(x, y);
                        if (mSearchColorDefinition.Matches(pixelColor))
                        {
                            TestExecution().LogMessage(Name + " found color match at " + x + "," + y);
                            if (firstPoint.X < 0)
                            {
                                firstPoint.X = x;
                                firstPoint.Y = y;
                            }
                            lastPoint.X = x;
                            lastPoint.Y = y;
                        }
                        else
                        {
                            //mSourceImage.SetColor(x, y, Color.Lime);
                            //TestExecution().LogMessage(Name + " " + x + "," + y + " is not a match");
                        }
                    } // end if for x,y verification
                }     // end search loop
                resultX = (firstPoint.X + lastPoint.X) / 2;
                resultY = (firstPoint.Y + lastPoint.Y) / 2;
            } // end main block ("else" after all initial setup error checks)
            mResultX.SetValue(resultX);
            mResultY.SetValue(resultY);
            mResultX.SetIsComplete();
            mResultY.SetIsComplete();
            DateTime doneTime    = DateTime.Now;
            TimeSpan computeTime = doneTime - startTime;

            TestExecution().LogMessage(Name + " computed object center at " + resultX + "," + resultY);
            TestExecution().LogMessageWithTimeFromTrigger(Name + " finished at " + doneTime + "  | took " + computeTime.TotalMilliseconds + "ms");
        }
Example #5
0
//		public const string AnalysisType = "Color Present Fails";
//		public override string Type() { return AnalysisType; }

        public override void DoWork()
        {
            TestExecution().LogMessageWithTimeFromTrigger("ColorMatchCount " + Name + " started");

            DateTime startTime = DateTime.Now;

            mMatchCount = 0;
            if (mSourceImage.Bitmap != null)
            {
                if (true)
                {
                    Point currentPoint = new Point(-1, -1);
                    mROI.GetFirstPointOnXAxis(mSourceImage, ref currentPoint);

                    Color color;
                    while (currentPoint.X != -1 && currentPoint.Y != -1)
                    {
                        color = mSourceImage.GetColor(currentPoint.X, currentPoint.Y);
                        if (mColorMatcher.Matches(color))
                        {
                            mMatchCount++;
                            if (mImageToMark != null && mImageToMark.Bitmap != null)
                            {
                                mImageToMark.SetColor(currentPoint.X, currentPoint.Y, mMarkColor);
                            }
                        }
                        mROI.GetNextPointOnXAxis(mSourceImage, ref currentPoint);
                    }
                }
                else
                {
                    Bitmap sourceBitmap = SourceImage.Bitmap;
                    Bitmap markedBitmap = null;

                    if (mCreateMarkedImage && mImageToMark != null && mImageToMark.Bitmap != null)
                    {
                        markedBitmap = mImageToMark.Bitmap;
                    }

                    // for LockBits see http://www.bobpowell.net/lockingbits.htm & http://www.codeproject.com/csharp/quickgrayscale.asp?df=100&forumid=293759&select=2214623&msg=2214623
                    BitmapData sourceBitmapData = null;
                    BitmapData markedBitmapData = null;
                    try
                    {
                        sourceBitmapData = sourceBitmap.LockBits(new Rectangle(0, 0, sourceBitmap.Width, sourceBitmap.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
                        if (markedBitmap != null)
                        {
                            markedBitmapData = markedBitmap.LockBits(new Rectangle(0, 0, markedBitmap.Width, markedBitmap.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
                        }
                        const int pixelByteWidth = 4; // determined by PixelFormat.Format32bppArgb
                        int       stride         = sourceBitmapData.Stride;
                        int       strideOffset   = stride - (sourceBitmapData.Width * pixelByteWidth);

                        Point currentPoint = new Point(-1, -1);
                        mROI.GetFirstPointOnXAxis(mSourceImage, ref currentPoint);

                        unsafe // see http://www.codeproject.com/csharp/quickgrayscale.asp?df=100&forumid=293759&select=2214623&msg=2214623
                        {
                            byte *sourcePointer;
                            byte *markedPointer;

                            Color color;
                            while (currentPoint.X != -1 && currentPoint.Y != -1)
                            {
                                sourcePointer  = (byte *)sourceBitmapData.Scan0;                                                         // init to first byte of image
                                sourcePointer += (currentPoint.Y * stride) + (currentPoint.X * pixelByteWidth);                          // adjust to current point
                                color          = Color.FromArgb(sourcePointer[3], sourcePointer[2], sourcePointer[1], sourcePointer[0]); // Array index 0 is blue, 1 is green, 2 is red, 0 is alpha
                                if (mColorMatcher.Matches(color))
                                {
                                    mMatchCount++;
                                    if (markedBitmap != null)
                                    {
                                        markedPointer    = (byte *)markedBitmapData.Scan0;
                                        markedPointer   += (currentPoint.Y * stride) + (currentPoint.X * pixelByteWidth);
                                        markedPointer[3] = mMarkColor.A;
                                        markedPointer[2] = mMarkColor.R;
                                        markedPointer[1] = mMarkColor.G;
                                        markedPointer[0] = mMarkColor.B;
                                    }
                                }
                                mROI.GetNextPointOnXAxis(mSourceImage, ref currentPoint);
                            }
                        } // end unsafe block
                    }
                    finally
                    {
                        sourceBitmap.UnlockBits(sourceBitmapData);
                        if (markedBitmap != null)
                        {
                            markedBitmap.UnlockBits(markedBitmapData);
                        }
                    }
                }
            }
            mResult.SetValue(mMatchCount);

            mResult.SetIsComplete();
            DateTime doneTime    = DateTime.Now;
            TimeSpan computeTime = doneTime - startTime;

            TestExecution().LogMessageWithTimeFromTrigger(Name + " took " + computeTime.TotalMilliseconds + "ms");
            //MessageBox.Show("done in color count for " + Name);
        }
        public static readonly int PIXEL_BYTE_WIDTH     = 4; // determined by PixelFormat.Format32bppArgb; http://www.bobpowell.net/lockingbits.htm
        public override void DoWork()
        {
            DateTime startTime = DateTime.Now;

            TestExecution().LogMessageWithTimeFromTrigger("[" + Name + "] started at " + startTime + Environment.NewLine);

            int startX = (int)mStartPoint_X.ValueAsLong();
            int startY = (int)mStartPoint_Y.ValueAsLong();

            int leftEdge   = -1;
            int rightEdge  = -1;
            int topEdge    = -1;
            int bottomEdge = -1;

            if (mPrerequisite != null && !mPrerequisite.ValueAsBoolean())
            {
                TestExecution().LogMessageWithTimeFromTrigger(Name + ": prerequisites not met.  Skipping.");
            }
            else if (mSourceImage.Bitmap == null)
            {
                TestExecution().LogErrorWithTimeFromTrigger("source image for '" + Name + "' does not exist.");
            }
            else if (startX < 0 || startX >= mSourceImage.Bitmap.Width ||
                     startY < 0 || startY >= mSourceImage.Bitmap.Height)
            {
                TestExecution().LogErrorWithTimeFromTrigger("Start position for '" + Name + "' isn't within the image bounds; start=" + startX + "," + startY + "; image size=" + mSourceImage.Bitmap.Width + "x" + mSourceImage.Bitmap.Height);
            }
            else
            {
                int  stepSize            = (int)mStepSize.ValueAsLong();
                bool detailedSearchAtEnd = mDetailedSearch.ValueAsBoolean();

                sourceBitmap = SourceImage.Bitmap;
                if (mImageToMark != null && mImageToMark.Bitmap != null)
                {
                    markedBitmap = mImageToMark.Bitmap;
                }

                try
                {
                    sourceBitmapData = sourceBitmap.LockBits(new Rectangle(0, 0, sourceBitmap.Width, sourceBitmap.Height), ImageLockMode.ReadOnly, PIXEL_FORMAT);
                    if (markedBitmap != null)
                    {
                        markedBitmapData = markedBitmap.LockBits(new Rectangle(0, 0, markedBitmap.Width, markedBitmap.Height), ImageLockMode.ReadWrite, PIXEL_FORMAT);
                    }
                    sourceStride       = sourceBitmapData.Stride;
                    sourceStrideOffset = sourceStride - (sourceBitmapData.Width * PIXEL_BYTE_WIDTH);

                    unsafe // see http://www.codeproject.com/csharp/quickgrayscale.asp?df=100&forumid=293759&select=2214623&msg=2214623
                    {
                        byte *sourcePointer;
                        byte *markedPointer;

                        sourcePointer  = (byte *)sourceBitmapData.Scan0;                        // init to first byte of image
                        sourcePointer += (startY * sourceStride) + (startX * PIXEL_BYTE_WIDTH); // adjust to current point

                        Color theColor = Color.FromArgb(sourcePointer[2], sourcePointer[1], sourcePointer[0]);
                        if (!mColorMatchDefinition.Matches(theColor))
                        {
                            TestExecution().LogErrorWithTimeFromTrigger(Name + " start position isn't within the match color; start=" + startX + "," + startY + "   color=" + theColor);
                        }
                        else
                        {
                            if (mFindBoundingRectangleDefinition.SearchRecord.GetLength(0) < sourceBitmap.Width || mFindBoundingRectangleDefinition.SearchRecord.GetLength(1) < sourceBitmap.Height)
                            {
                                mFindBoundingRectangleDefinition.SearchRecord   = new short[sourceBitmap.Width, sourceBitmap.Height];
                                mFindBoundingRectangleDefinition.LastMarkerUsed = 0;
                            }
                            if (mFindBoundingRectangleDefinition.LastMarkerUsed == int.MaxValue)
                            {
                                for (int x = 0; x < mFindBoundingRectangleDefinition.SearchRecord.GetLength(0); x++)
                                {
                                    for (int y = 0; y < mFindBoundingRectangleDefinition.SearchRecord.GetLength(1); y++)
                                    {
                                        mFindBoundingRectangleDefinition.SearchRecord[x, y] = 0;
                                    }
                                }
                                mFindBoundingRectangleDefinition.LastMarkerUsed = 0;
                            }
                            mFindBoundingRectangleDefinition.LastMarkerUsed++;

                            EdgeSearch topEdgeSearch    = new EdgeSearch(this, mColorMatchDefinition, Axis.X, startY, -1 * stepSize, 0, startX, 0, sourceBitmap.Width - 1, mFindBoundingRectangleDefinition.SearchRecord, mFindBoundingRectangleDefinition.LastMarkerUsed);
                            EdgeSearch bottomEdgeSearch = new EdgeSearch(this, mColorMatchDefinition, Axis.X, startY, +1 * stepSize, sourceBitmap.Height - 1, startX, 0, sourceBitmap.Width - 1, mFindBoundingRectangleDefinition.SearchRecord, mFindBoundingRectangleDefinition.LastMarkerUsed);
                            EdgeSearch leftEdgeSearch   = new EdgeSearch(this, mColorMatchDefinition, Axis.Y, startX, -1 * stepSize, 0, startY, 0, sourceBitmap.Height - 1, mFindBoundingRectangleDefinition.SearchRecord, mFindBoundingRectangleDefinition.LastMarkerUsed);
                            EdgeSearch rightEdgeSearch  = new EdgeSearch(this, mColorMatchDefinition, Axis.Y, startX, +1 * stepSize, sourceBitmap.Width - 1, startY, 0, sourceBitmap.Height - 1, mFindBoundingRectangleDefinition.SearchRecord, mFindBoundingRectangleDefinition.LastMarkerUsed);
                            topEdgeSearch.minSideEdge    = leftEdgeSearch;
                            topEdgeSearch.maxSideEdge    = rightEdgeSearch;
                            bottomEdgeSearch.minSideEdge = leftEdgeSearch;
                            bottomEdgeSearch.maxSideEdge = rightEdgeSearch;
                            leftEdgeSearch.minSideEdge   = topEdgeSearch;
                            leftEdgeSearch.maxSideEdge   = bottomEdgeSearch;
                            rightEdgeSearch.minSideEdge  = topEdgeSearch;
                            rightEdgeSearch.maxSideEdge  = bottomEdgeSearch;

                            while (!(topEdgeSearch.Done() && bottomEdgeSearch.Done() && leftEdgeSearch.Done() && rightEdgeSearch.Done()))
                            {
                                if (!topEdgeSearch.Done())
                                {
                                    topEdgeSearch.TestLine();
                                }
                                if (!bottomEdgeSearch.Done())
                                {
                                    bottomEdgeSearch.TestLine();
                                }
                                if (!leftEdgeSearch.Done())
                                {
                                    leftEdgeSearch.TestLine();
                                }
                                if (!rightEdgeSearch.Done())
                                {
                                    rightEdgeSearch.TestLine();
                                }
                            }

                            if (detailedSearchAtEnd)
                            {
                                //topEdgeSearch.mStep
                            }

                            leftEdge   = leftEdgeSearch.lastPosWhereObjectSeen;
                            rightEdge  = rightEdgeSearch.lastPosWhereObjectSeen;
                            topEdge    = topEdgeSearch.lastPosWhereObjectSeen;
                            bottomEdge = bottomEdgeSearch.lastPosWhereObjectSeen;

                            /* TODO: rectangle decoration? force user to use ROI?
                             * mResultantRay.SetStartX(centerX);
                             * mResultantRay.SetStartY(centerY);
                             * mResultantRay.SetEndX((int)(centerX + outerRadius * Math.Cos(overallRad)));
                             * mResultantRay.SetEndY((int)(centerY + outerRadius * Math.Sin(overallRad)));
                             * mResultantRay.SetIsComplete();
                             */
                        }
                    } // end unsafe block
                }
                catch (Exception e)
                {
                    TestExecution().LogMessageWithTimeFromTrigger("ERROR: Failure in " + Name + "; msg=" + e.Message + " " + Environment.NewLine + e.StackTrace);
                }
                finally
                {
                    sourceBitmap.UnlockBits(sourceBitmapData);
                    if (markedBitmap != null)
                    {
                        markedBitmap.UnlockBits(markedBitmapData);
                    }
                }
            } // end main block ("else" after all initial setup error checks)
            mLeftBound.SetValue(leftEdge);
            mLeftBound.SetIsComplete();
            mRightBound.SetValue(rightEdge);
            mRightBound.SetIsComplete();
            mTopBound.SetValue(topEdge);
            mTopBound.SetIsComplete();
            mBottomBound.SetValue(bottomEdge);
            mBottomBound.SetIsComplete();
            DateTime doneTime    = DateTime.Now;
            TimeSpan computeTime = doneTime - startTime;

            TestExecution().LogMessageWithTimeFromTrigger(Name + " found bounding rectangle; left=" + leftEdge + " right=" + rightEdge + " top=" + topEdge + " bottom=" + bottomEdge);

            if (mAutoSave)
            {
                try
                {
                    string filePath = ((FindRadialLineDefinition)Definition()).AutoSavePath;
                    mSourceImage.Save(filePath, Name, true);
                    if (mImageToMark != null)
                    {
                        mImageToMark.Save(filePath, Name, "_marked_" + leftEdge + "_" + rightEdge + "_" + topEdge + "_" + bottomEdge);
                    }
                    TestExecution().LogMessageWithTimeFromTrigger("Snapshot saved");
                }
                catch (ArgumentException e)
                {
                    Project().Window().logMessage("ERROR: " + e.Message);
                    TestExecution().LogErrorWithTimeFromTrigger(e.Message);
                }
                catch (Exception e)
                {
                    Project().Window().logMessage("ERROR: Unable to AutoSave snapshot from " + Name + ".  Ensure path valid and disk not full.  Low-level message=" + e.Message);
                    TestExecution().LogErrorWithTimeFromTrigger("Unable to AutoSave snapshot from " + Name + ".  Ensure path valid and disk not full.");
                }
            }
            TestExecution().LogMessageWithTimeFromTrigger(Name + " finished at " + doneTime + "  | took " + computeTime.TotalMilliseconds + "ms");
        }
        public override void DoWork()
        {
            DateTime startTime = DateTime.Now;

            TestExecution().LogMessageWithTimeFromTrigger("[" + Name + "] started at " + startTime + Environment.NewLine);

            int objectStartEdgeX = -1;
            int objectStartEdgeY = -1;
            int objectEndEdgeX   = -1;
            int objectEndEdgeY   = -1;
            int resultX          = -1;
            int resultY          = -1;

            long requiredConsecMatches = mRequiredConsecutiveColorMatches.ValueAsLong();
            int  consecutiveMatches    = 0;
            int  firstMatch_x          = -1;
            int  firstMatch_y          = -1;

            if (mSourceImage.Bitmap == null)
            {
                TestExecution().LogMessage("ERROR: source image for '" + Name + "' does not exist.");
            }
            else if (mSearchPath == null)
            {
                TestExecution().LogMessage("ERROR: search line for '" + Name + "' isn't defined.");
            }
            else if (mSearchPath.StartX == null || mSearchPath.StartY == null || mSearchPath.EndX == null || mSearchPath.EndY == null)
            {
                TestExecution().LogMessage("ERROR: search line '" + mSearchPath.Name + "' for '" + Name + "' isn't fully defined.");
            }
            else if (mSearchPath.StartX.ValueAsLong() < 0 || mSearchPath.StartX.ValueAsLong() >= mSourceImage.Bitmap.Width ||
                     mSearchPath.StartY.ValueAsLong() < 0 || mSearchPath.StartY.ValueAsLong() >= mSourceImage.Bitmap.Height)
            {
                TestExecution().LogMessage("ERROR: The search line start point for '" + Name + "' isn't valid: " + mSearchPath.StartX.ValueAsLong() + "," + mSearchPath.StartY.ValueAsLong());
            }
            else if (mSearchPath.EndX.ValueAsLong() < 0 || mSearchPath.EndX.ValueAsLong() >= mSourceImage.Bitmap.Width ||
                     mSearchPath.EndY.ValueAsLong() < 0 || mSearchPath.EndY.ValueAsLong() >= mSourceImage.Bitmap.Height)
            {
                TestExecution().LogMessage("ERROR: The search line end point for '" + Name + "' isn't valid: " + mSearchPath.EndX.ValueAsLong() + "," + mSearchPath.EndY.ValueAsLong());
            }
            else
            {
                switch (mSearchDirection)
                {
                case Direction.Left:
                    xSearchChange = -1;
                    ySearchChange = 0;
                    if (mSearchPath.StartX.ValueAsLong() == mSearchPath.EndX.ValueAsLong() && mSearchPath.StartY.ValueAsLong() != mSearchPath.EndY.ValueAsLong())
                    {
                        TestExecution().LogMessage("ERROR: can't search left on line '" + mSearchPath.Name + "' for '" + Name + "' since line is vertical.");
                    }
                    else if (mSearchPath.StartX.ValueAsLong() < mSearchPath.EndX.ValueAsLong())
                    {
                        startX = mSearchPath.EndX.ValueAsLong();
                        startY = mSearchPath.EndY.ValueAsLong();
                        endX   = mSearchPath.StartX.ValueAsLong();
                        endY   = mSearchPath.StartY.ValueAsLong();
                    }
                    else
                    {
                        startX = mSearchPath.StartX.ValueAsLong();
                        startY = mSearchPath.StartY.ValueAsLong();
                        endX   = mSearchPath.EndX.ValueAsLong();
                        endY   = mSearchPath.EndY.ValueAsLong();
                    }
                    break;

                case Direction.Right:
                    xSearchChange = 1;
                    ySearchChange = 0;
                    if (mSearchPath.StartX.ValueAsLong() == mSearchPath.EndX.ValueAsLong() && mSearchPath.StartY.ValueAsLong() != mSearchPath.EndY.ValueAsLong())
                    {
                        TestExecution().LogMessage("ERROR: can't search right on line '" + mSearchPath.Name + "' for '" + Name + "' since line is vertical.");
                    }
                    else if (mSearchPath.StartX.ValueAsLong() < mSearchPath.EndX.ValueAsLong())
                    {
                        startX = mSearchPath.StartX.ValueAsLong();
                        startY = mSearchPath.StartY.ValueAsLong();
                        endX   = mSearchPath.EndX.ValueAsLong();
                        endY   = mSearchPath.EndY.ValueAsLong();
                    }
                    else
                    {
                        startX = mSearchPath.EndX.ValueAsLong();
                        startY = mSearchPath.EndY.ValueAsLong();
                        endX   = mSearchPath.StartX.ValueAsLong();
                        endY   = mSearchPath.StartY.ValueAsLong();
                    }
                    break;

                case Direction.Up:
                    xSearchChange = 0;
                    ySearchChange = -1;
                    if (mSearchPath.StartY.ValueAsLong() == mSearchPath.EndY.ValueAsLong() && mSearchPath.StartX.ValueAsLong() != mSearchPath.EndX.ValueAsLong())
                    {
                        TestExecution().LogMessage("ERROR: can't search up on line '" + mSearchPath.Name + "' for '" + Name + "' since line is horizontal.");
                    }
                    else if (mSearchPath.StartY.ValueAsLong() < mSearchPath.EndY.ValueAsLong())     // line is down
                    {
                        startX = mSearchPath.EndX.ValueAsLong();
                        startY = mSearchPath.EndY.ValueAsLong();
                        endX   = mSearchPath.StartX.ValueAsLong();
                        endY   = mSearchPath.StartY.ValueAsLong();
                    }
                    else     // line is up
                    {
                        startX = mSearchPath.StartX.ValueAsLong();
                        startY = mSearchPath.StartY.ValueAsLong();
                        endX   = mSearchPath.EndX.ValueAsLong();
                        endY   = mSearchPath.EndY.ValueAsLong();
                    }
                    break;

                case Direction.Down:
                    xSearchChange = 0;
                    ySearchChange = 1;
                    if (mSearchPath.StartY.ValueAsLong() == mSearchPath.EndY.ValueAsLong() && mSearchPath.StartX.ValueAsLong() != mSearchPath.EndX.ValueAsLong())
                    {
                        TestExecution().LogMessage("ERROR: can't search down on line '" + mSearchPath.Name + "' for '" + Name + "' since line is horizontal.");
                    }
                    else if (mSearchPath.StartY.ValueAsLong() < mSearchPath.EndY.ValueAsLong())     // line is down
                    {
                        startX = mSearchPath.StartX.ValueAsLong();
                        startY = mSearchPath.StartY.ValueAsLong();
                        endX   = mSearchPath.EndX.ValueAsLong();
                        endY   = mSearchPath.EndY.ValueAsLong();
                    }
                    else     // line is up
                    {
                        startX = mSearchPath.EndX.ValueAsLong();
                        startY = mSearchPath.EndY.ValueAsLong();
                        endX   = mSearchPath.StartX.ValueAsLong();
                        endY   = mSearchPath.StartY.ValueAsLong();
                    }
                    break;

                case Direction.NotDefined:
                    TestExecution().LogMessage("ERROR: Search direction not defined.");
                    abort = true;
                    break;

                default:
                    TestExecution().LogMessage("ERROR: Unsupported Search direction; direction=" + mSearchDirection);
                    abort = true;
                    break;
                }

                leftEdgeOfSearch   = Math.Max(0, Math.Min(startX, endX));
                rightEdgeOfSearch  = Math.Min(mSourceImage.Bitmap.Width, Math.Max(startX, endX));
                topEdgeOfSearch    = Math.Max(0, Math.Min(startY, endY));
                bottomEdgeOfSearch = Math.Min(mSourceImage.Bitmap.Height, Math.Max(startY, endY));

                LineType lineType;
                if (startY == endY)
                {
                    lineType = LineType.Horizontal;
                    slope    = 0;
                }
                else if (startX == endX)
                {
                    lineType = LineType.Vertical;
                    slope    = 999999999999 / 0.000000001;
                }
                else
                {
                    lineType = LineType.Slanted;
                    slope    = (double)(endY - startY) / (double)(endX - startX);
                }

                x = (int)startX;
                y = (int)startY;

                TestExecution().LogMessage(Name + " starting at " + x + "," + y);

                abort = false;
                state = SearchState.FindBackground;
                int searchIndex = 0;
                while (state != SearchState.Done && !abort)
                {
                    switch (lineType)
                    {
                    case LineType.Horizontal:
                        x = (int)(startX + (searchIndex * xSearchChange));
                        break;

                    case LineType.Vertical:
                        y = (int)(startY + (searchIndex * ySearchChange));
                        break;

                    case LineType.Slanted:
                        x = (int)(startX + (searchIndex * xSearchChange) + ((searchIndex * ySearchChange) / slope));
                        y = (int)(startY + (searchIndex * ySearchChange) + ((searchIndex * xSearchChange) * slope));
                        break;
                    }

                    if (x < leftEdgeOfSearch || x > rightEdgeOfSearch || y < topEdgeOfSearch || y > bottomEdgeOfSearch)
                    {
                        TestExecution().LogMessage("ERROR: " + Name + " exhausted search without finding full object; end position = " + x + "," + y + "; state = " + state);
                        state = SearchState.Done;
                    }
                    else
                    {
                        pixelColor = SourceImage.Bitmap.GetPixel(x, y);

                        switch (state)
                        {
                        case SearchState.FindBackground:
                            if (mSearchBackgroundColorDefinition.Matches(pixelColor))
                            {
                                TestExecution().LogMessage(Name + " found background at " + x + "," + y);
                                state = SearchState.FindObject;
                            }
                            else if (mObjectColorDefinition.Matches(pixelColor))
                            {
                            }
                            else
                            {
                                LogWarning(Name + " found unexpected color searching for initial background at " + x + "," + y);
                            }
                            break;

                        case SearchState.FindObject:
                            if (mSearchBackgroundColorDefinition.Matches(pixelColor))
                            {
                                consecutiveMatches = 0;
                                firstMatch_x       = -1;
                                firstMatch_y       = -1;
                            }
                            else if (mObjectColorDefinition.Matches(pixelColor))
                            {
                                TestExecution().LogMessage(Name + " found start of object at " + x + "," + y);
                                consecutiveMatches++;
                                if (consecutiveMatches == 1)
                                {
                                    firstMatch_x = x;
                                    firstMatch_y = y;
                                }
                                if (consecutiveMatches >= requiredConsecMatches)
                                {
                                    // remember edge
                                    objectStartEdgeX = firstMatch_x;
                                    objectStartEdgeY = firstMatch_y;
                                    TestExecution().LogMessage(Name + " found the " + requiredConsecMatches + " needed consec matches for start of object at " + x + "," + y + "; set start to " + objectStartEdgeX + "," + objectStartEdgeY);

                                    // get ready for next state
                                    state = SearchState.FindFarEdgeOfObject;
                                    consecutiveMatches = 0;
                                    firstMatch_x       = -1;
                                    firstMatch_y       = -1;
                                }
                            }
                            else
                            {
                                consecutiveMatches = 0;
                                firstMatch_x       = -1;
                                firstMatch_y       = -1;
                                LogWarning(Name + " found unexpected color before object at " + x + "," + y);
                            }
                            break;

                        case SearchState.FindFarEdgeOfObject:
                            if (mSearchBackgroundColorDefinition.Matches(pixelColor))
                            {
                                TestExecution().LogMessage(Name + " found end of object at " + x + "," + y);
                                consecutiveMatches++;
                                if (consecutiveMatches == 1)
                                {
                                    firstMatch_x = x;
                                    firstMatch_y = y;
                                }
                                if (consecutiveMatches >= requiredConsecMatches)
                                {
                                    // remember edge
                                    objectEndEdgeX = firstMatch_x;
                                    objectEndEdgeY = firstMatch_y;
                                    resultX        = (objectStartEdgeX + objectEndEdgeX) / 2;
                                    resultY        = (objectStartEdgeY + objectEndEdgeY) / 2;
                                    TestExecution().LogMessage(Name + " found the " + requiredConsecMatches + " needed consec matches for end of object at " + x + "," + y + "; set end to " + objectEndEdgeX + "," + objectEndEdgeY);

                                    // get ready for next state
                                    state = SearchState.Done;
                                    consecutiveMatches = 0;
                                    firstMatch_x       = -1;
                                    firstMatch_y       = -1;
                                }
                            }
                            else if (mObjectColorDefinition.Matches(pixelColor))
                            {
                                consecutiveMatches = 0;
                                firstMatch_x       = -1;
                                firstMatch_y       = -1;
                            }
                            else
                            {
                                consecutiveMatches = 0;
                                firstMatch_x       = -1;
                                firstMatch_y       = -1;
                                LogWarning(Name + " found unexpected color within object at " + x + "," + y);
                            }
                            break;
                        } // end switch
                        searchIndex++;
                    }     // end if for x,y verification
                }         // end search loop
            }             // end main block ("else" after all initial setup error checks)
            mResultX.SetValue(resultX);
            mResultY.SetValue(resultY);
            mResultX.SetIsComplete();
            mResultY.SetIsComplete();
            DateTime doneTime    = DateTime.Now;
            TimeSpan computeTime = doneTime - startTime;

            TestExecution().LogMessage(Name + " computed object center at " + resultX + "," + resultY);
            TestExecution().LogMessageWithTimeFromTrigger(Name + " finished at " + doneTime + "  | took " + computeTime.TotalMilliseconds + "ms");
        }
//		public const string AnalysisType = "Color Present Fails";
//		public override string Type() { return AnalysisType; }

        public override void DoWork()
        {
            //if (!mSourceImage.IsComplete() || !mROI.IsComplete() || !AreExplicitDependenciesComplete()) return;

            DateTime startTime = DateTime.Now;

            Bitmap sourceBitmap = SourceImage.Bitmap;
            Bitmap markedBitmap = null;

            TestExecution().LogMessageWithTimeFromTrigger("ColorMatchCount " + Name + " started");

            // All ROI are taken at 640x480
            // We need to scale ROIs to the actual image dimensions
//            RectangleROI rectangleROI = ScaleROI(roi.NetworkCamera().Resolution);
//            RectangleROI_old rectangleROI = Project().FindCamera(Camera).GetROI(TestExecution(),ROI);

            if (mCreateMarkedImage && mImageToMark != null && mImageToMark.Bitmap != null)
            {
                markedBitmap = mImageToMark.Bitmap;
            }

            mMatchCount = 0;
            if (sourceBitmap != null)
            {
                // for LockBits see http://www.bobpowell.net/lockingbits.htm & http://www.codeproject.com/csharp/quickgrayscale.asp?df=100&forumid=293759&select=2214623&msg=2214623
                BitmapData sourceBitmapData = null;
                BitmapData markedBitmapData = null;
                try
                {
                    sourceBitmapData = sourceBitmap.LockBits(new Rectangle(0, 0, sourceBitmap.Width, sourceBitmap.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
                    if (markedBitmap != null)
                    {
                        markedBitmapData = markedBitmap.LockBits(new Rectangle(0, 0, markedBitmap.Width, markedBitmap.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
                    }
                    const int pixelByteWidth = 4; // determined by PixelFormat.Format32bppArgb
                    int       stride         = sourceBitmapData.Stride;
                    int       strideOffset   = stride - (sourceBitmapData.Width * pixelByteWidth);

                    int   bottom = Math.Min(sourceBitmap.Height - 1, ROI.Bottom);
                    int   top    = Math.Max(0, ROI.Top);
                    int   left   = Math.Max(0, ROI.Left);
                    int   right  = Math.Min(sourceBitmap.Width - 1, ROI.Right);
                    Color color;

                    unsafe // see http://www.codeproject.com/csharp/quickgrayscale.asp?df=100&forumid=293759&select=2214623&msg=2214623
                    {
                        byte *sourcePointer;
                        byte *markedPointer;
                        for (int j = top; j <= bottom; j++)
                        {
                            sourcePointer  = (byte *)sourceBitmapData.Scan0;         // init to first byte of image
                            sourcePointer += (j * stride) + (left * pixelByteWidth); // adjust to first byte of ROI
                            for (int i = left; i <= right; i++)
                            {
                                color = Color.FromArgb(sourcePointer[3], sourcePointer[2], sourcePointer[1], sourcePointer[0]); // Array index 0 is blue, 1 is green, 2 is red, 0 is alpha
                                if (mColorMatcher.Matches(color))
                                {
                                    mMatchCount++;
                                    if (markedBitmap != null)
                                    {
                                        markedPointer    = (byte *)markedBitmapData.Scan0;
                                        markedPointer   += (j * stride) + (i * pixelByteWidth);
                                        markedPointer[3] = Color.Magenta.A;
                                        markedPointer[2] = Color.Magenta.R;
                                        markedPointer[1] = Color.Magenta.G;
                                        markedPointer[0] = Color.Magenta.B;
                                    }
                                }
                                sourcePointer += pixelByteWidth; // adjust to next pixel to the right
                            }
                            //sourcePointer += (((width-right) * pixelByteWidth) + strideOffset + (left * pixelByteWidth)); // adjust to the first pixel of the next row by skipping the "extra bytes" (stride offset)
                        }
                    } // end unsafe block
                }
                finally
                {
                    sourceBitmap.UnlockBits(sourceBitmapData);
                    if (markedBitmap != null)
                    {
                        markedBitmap.UnlockBits(markedBitmapData);
                    }
                }
            }

            mResult.SetValue(mMatchCount);

            mResult.SetIsComplete();
            DateTime doneTime    = DateTime.Now;
            TimeSpan computeTime = doneTime - startTime;

            TestExecution().LogMessageWithTimeFromTrigger(Name + " took " + computeTime.TotalMilliseconds + "ms");
            //MessageBox.Show("done in color count for " + Name);
        }
        public override void DoWork()
        {
            /*
             * if (!mStartX.IsComplete() ||
             *  !mStartY.IsComplete() ||
             *  !mSearchBackgroundColorDefinition.IsComplete() ||
             *  !mFollowingEdgeColorDefinition.IsComplete() ||
             *  !mTargetEdgeColorDefinition.IsComplete() ||
             *  !mTargetEdgeWidth.IsComplete() ||
             *  !mSourceImage.IsComplete() ||
             *  !AreExplicitDependenciesComplete()
             *  ) return;*/

            //MessageBox.Show("in find corner for " + Name);
            DateTime startTime = DateTime.Now;

            TestExecution().LogMessageWithTimeFromTrigger("[" + Name + "] started at " + startTime + Environment.NewLine);

            int resultX = -1;
            int resultY = -1;

            if (mSourceImage.Bitmap == null)
            {
                TestExecution().LogMessage("ERROR: source image does not exist.");
            }
            else if (mStartX.ValueAsLong() < 0 || mStartX.ValueAsLong() >= mSourceImage.Bitmap.Width || mStartY.ValueAsLong() < 0 || mStartY.ValueAsLong() >= mSourceImage.Bitmap.Height)
            {
                TestExecution().LogMessage("ERROR: The search start point isn't valid: " + mStartX.ValueAsLong() + "," + mStartY.ValueAsLong());
            }
            else
            {
                switch (mSearchDirection)
                {
                case Direction.Left:
                    xSearchChange = -1;
                    ySearchChange = 0;
                    break;

                case Direction.Right:
                    xSearchChange = 1;
                    ySearchChange = 0;
                    break;

                case Direction.Up:
                    xSearchChange = 0;
                    ySearchChange = -1;
                    break;

                case Direction.Down:
                    xSearchChange = 0;
                    ySearchChange = 1;
                    break;

                case Direction.NotDefined:
                    TestExecution().LogMessage("ERROR: Search direction not defined.");
                    abort = true;
                    break;

                default:
                    TestExecution().LogMessage("ERROR: Unsupported Search direction; direction=" + mSearchDirection);
                    abort = true;
                    break;
                }
                switch (mTargetEdgeDirection)
                {
                case Direction.Left:
                    xStepAwayChange = -1;
                    yStepAwayChange = 0;
                    break;

                case Direction.Right:
                    xStepAwayChange = 1;
                    yStepAwayChange = 0;
                    break;

                case Direction.Up:
                    xStepAwayChange = 0;
                    yStepAwayChange = -1;
                    break;

                case Direction.Down:
                    xStepAwayChange = 0;
                    yStepAwayChange = 1;
                    break;

                case Direction.NotDefined:
                    TestExecution().LogMessage("ERROR: Target Edge Direction not defined.");
                    abort = true;
                    break;

                default:
                    TestExecution().LogMessage("ERROR: Unsupported Target Edge Direction; direction=" + mTargetEdgeDirection);
                    abort = true;
                    break;
                }

                x = (int)mStartX.ValueAsLong();
                y = (int)mStartY.ValueAsLong();

                pixelColor = mSourceImage.Bitmap.GetPixel(x, y);
                if (!mFollowingEdgeColorDefinition.Matches(pixelColor))
                {
                    TestExecution().LogMessage("ERROR: Start position isn't on the following edge.");
                    abort = true;
                    // TODO: try to find it by search in the opposite direction of the target edge for about 5-10 pixels.
                }

                lastXOnFollowingEdge        = x;
                lastYOnFollowingEdge        = y;
                searchDistFromFollowingEdge = Math.Min(10, (int)(mTargetEdgeWidth.ValueAsLong() * 0.75));
                searchLength    = searchDistFromFollowingEdge;
                maxSearchLength = searchLength; // this will be updated with the slope
                int searchIndex = 0;

                TestExecution().LogMessage("Starting at " + x + "," + y + " searchLength=" + searchLength + "  searchDistFromFollowingEdge=" + searchDistFromFollowingEdge + "  xStepAwayChange=" + xStepAwayChange + "  yStepAwayChange=" + yStepAwayChange + "  xSearchChange=" + xSearchChange + "  ySearchChange=" + ySearchChange);

                abort       = false;
                foundTarget = false;
                while (!foundTarget && !abort && x >= 0 && x < mSourceImage.Bitmap.Width && y >= 0 && y < mSourceImage.Bitmap.Height)
                {
                    //                LineDecorationInstance searchPath = new LineDecorationInstance(theDefinition.SearchPath, testExecution);

                    // move away from following edge and one pixel along it to start searching for the target edge.  We want to stay far enough away from the following edge so that we don't accidently run into it if it isn't not exactly parallel.
                    x = lastXOnFollowingEdge + xSearchChange + (xStepAwayChange * searchDistFromFollowingEdge);
                    y = lastYOnFollowingEdge + ySearchChange + (yStepAwayChange * searchDistFromFollowingEdge);

                    // move a certain distance (searchLength) along the Following Edge in search of the Target Edge
                    searchIndex = 0;
                    int consecutiveUnexpectedColors = 0;
                    int totalUnexpectedColors       = 0;
                    while (!foundTarget && !abort && searchIndex < searchLength && x >= 0 && x < mSourceImage.Bitmap.Width && y >= 0 && y < mSourceImage.Bitmap.Height)
                    {
                        pixelColor = SourceImage.Bitmap.GetPixel(x, y);
                        if (mTargetEdgeColorDefinition.Matches(pixelColor))
                        {
                            consecutiveUnexpectedColors = 0;
                            TestExecution().LogMessage("Found target at x=" + x + "  y=" + y);
                            foundTarget = true;
                        }
                        else if (mFollowingEdgeColorDefinition.Matches(pixelColor))
                        {
                            // NOTE: must test this after the TargettedEdgeColor since these may be the exact same color defs!
                            TestExecution().LogMessage("ERROR: Unexpectedly ran into Following Edge.");
                            abort = true;
                            // TODO: does it also match the background? if so, throw an error about definition overlap
                            // TODO: handle differently if slope computed and we were near following edge?
                        }
                        else
                        {
                            if (!mSearchBackgroundColorDefinition.Matches(pixelColor))
                            {
                                TestExecution().LogMessage("WARNING: Ran into unexpected color at " + x + "," + y + ".");
                                totalUnexpectedColors++;
                                consecutiveUnexpectedColors++;
                            }
                            else
                            {
                                consecutiveUnexpectedColors = 0;
                            }

                            if (consecutiveUnexpectedColors > 2 || totalUnexpectedColors > 10)
                            {
                                abort = true;
                                TestExecution().LogMessage("ERROR: aborting due to too many unexpected colors; consecutive=" + consecutiveUnexpectedColors + "   total=" + totalUnexpectedColors);
                            }
                            else
                            {
                                x += xSearchChange;
                                y += ySearchChange;
                                searchIndex++;
                            }
                        }
                    }

                    if (!foundTarget && !abort)
                    {
                        TestExecution().LogMessage("Finished search stint at x=" + x + "  y=" + y + "; search length=" + searchLength + "  max=" + maxSearchLength);

                        ReFindFollowingEdge();

                        if (foundFollowingEdge)
                        {
                            ComputeSlope();
                        }
                    }
                }

                if (foundTarget)
                {
                    const int backupDistance = 5;
                    // back away 5 pixels from the Target Edge and then re-find the following edge.  From there we will estimate the corner
                    x -= xSearchChange * backupDistance;
                    y -= ySearchChange * backupDistance;

                    ReFindFollowingEdge();

                    if (foundFollowingEdge)
                    {
                        ComputeSlope();
                    }
                    else
                    {
                        TestExecution().LogMessage("WARNING: couldn't find Following Edge " + backupDistance + " pixel away from Target Edge");
                    }

                    if (numSummedSlopes > 0)
                    {
                        resultX = (int)(lastXOnFollowingEdge + backupDistance * xSearchChange + bigSlope * backupDistance * xStepAwayChange);
                        resultY = (int)(lastYOnFollowingEdge + backupDistance * ySearchChange + bigSlope * backupDistance * yStepAwayChange);
                    }
                    else
                    {
                        resultX = lastXOnFollowingEdge + backupDistance * xSearchChange;
                        resultY = lastYOnFollowingEdge + backupDistance * ySearchChange;
                    }
                }
                else
                {
                    TestExecution().LogMessage("ERROR: Couldn't find Target Edge. x=" + x + "  y=" + y);
                    abort = true;
                }
            }
            mResultX.SetValue(resultX);
            mResultY.SetValue(resultY);
            mResultX.SetIsComplete();
            mResultY.SetIsComplete();
            DateTime doneTime    = DateTime.Now;
            TimeSpan computeTime = doneTime - startTime;

            TestExecution().LogMessage("Corner at x=" + resultX + "  y=" + resultY);
            TestExecution().LogMessageWithTimeFromTrigger(Name + " finished at " + doneTime + "  | took " + computeTime.TotalMilliseconds + "ms");
            //            mSearchEndX.SetIsComplete();
//            mSearchEndY.SetIsComplete();
            //MessageBox.Show("done in find corner for " + Name);
        }
        public static readonly int PIXEL_BYTE_WIDTH     = 4; // determined by PixelFormat.Format32bppArgb; http://www.bobpowell.net/lockingbits.htm
        public override void DoWork()
        {
            DateTime startTime = DateTime.Now;

            TestExecution().LogMessageWithTimeFromTrigger("[" + Name + "] started at " + startTime + Environment.NewLine);

            int leftEdge   = -1;
            int rightEdge  = -1;
            int topEdge    = -1;
            int bottomEdge = -1;

            int    minObjectHeight            = -1;
            int    maxObjectHeight            = -1;
            int    minObjectWidth             = -1;
            int    maxObjectWidth             = -1;
            double allowedObjectSizeVariation = 0;

            if (mAllowedSizeVariation != null)
            {
                allowedObjectSizeVariation = mAllowedSizeVariation.ValueAsDecimal() / 100.0;
            }

            if (mExpectedObjectHeight != null)
            {
                minObjectHeight = (int)(mExpectedObjectHeight.ValueAsDecimal() * (1 - allowedObjectSizeVariation));
                maxObjectHeight = (int)(mExpectedObjectHeight.ValueAsDecimal() * (1 + allowedObjectSizeVariation));
            }
            if (mExpectedObjectWidth != null)
            {
                minObjectWidth = (int)(mExpectedObjectWidth.ValueAsDecimal() * (1 - allowedObjectSizeVariation));
                maxObjectWidth = (int)(mExpectedObjectWidth.ValueAsDecimal() * (1 + allowedObjectSizeVariation));
            }

            if (mMinObjectHeight != null)
            {
                minObjectHeight = (int)mMinObjectHeight.ValueAsLong();
            }
            if (mMinObjectWidth != null)
            {
                minObjectWidth = (int)mMinObjectWidth.ValueAsLong();
            }
            if (mMaxObjectHeight != null)
            {
                maxObjectHeight = (int)mMaxObjectHeight.ValueAsLong();
            }
            if (mMaxObjectWidth != null)
            {
                maxObjectWidth = (int)mMaxObjectWidth.ValueAsLong();
            }

            if (minObjectHeight < 0)
            {
                TestExecution().LogErrorWithTimeFromTrigger("A minimum height for the object hasn't been defined within '" + Name + "'.");
            }
            else if (maxObjectHeight < 0)
            {
                TestExecution().LogErrorWithTimeFromTrigger("A maximum height for the object hasn't been defined within '" + Name + "'.");
            }
            else if (minObjectWidth < 0)
            {
                TestExecution().LogErrorWithTimeFromTrigger("A minimum width for the object hasn't been defined within '" + Name + "'.");
            }
            else if (maxObjectWidth < 0)
            {
                TestExecution().LogErrorWithTimeFromTrigger("A maximum width for the object hasn't been defined within '" + Name + "'.");
            }
            else if (mPrerequisite != null && !mPrerequisite.ValueAsBoolean())
            {
                TestExecution().LogMessageWithTimeFromTrigger(Name + ": prerequisites not met.  Skipping.");
            }
            else if (mSourceImage.Bitmap == null)
            {
                TestExecution().LogErrorWithTimeFromTrigger("Source image for '" + Name + "' does not exist.");
            }
            else
            {
                int searchXStep = Math.Max(1, (int)(minObjectWidth * 0.3));
                int searchYStep = Math.Max(1, (int)(minObjectHeight * 0.3));
                int startX      = (int)mROI.Left + searchXStep;
                int startY      = (int)mROI.Top + searchYStep;

                if (startX < 0 || startX >= mSourceImage.Bitmap.Width || startY < 0 || startY >= mSourceImage.Bitmap.Height)
                {
                    TestExecution().LogErrorWithTimeFromTrigger("Start position for '" + Name + "' isn't within the image bounds; start=" + startX + "," + startY + "; image size=" + mSourceImage.Bitmap.Width + "x" + mSourceImage.Bitmap.Height);
                }
                else
                {
                    int  stepSize            = (int)mStepSize.ValueAsLong();
                    bool detailedSearchAtEnd = mDetailedSearch.ValueAsBoolean();

                    sourceBitmap = SourceImage.Bitmap;
                    if (mImageMarkingEnabled.ValueAsBoolean() && mImageToMark != null && mImageToMark.Bitmap != null)
                    {
                        markedBitmap = mImageToMark.Bitmap;
                    }

                    // TODO: replace LockBits implementation with array pointer

                    try
                    {
                        sourceBitmapData = sourceBitmap.LockBits(new Rectangle(0, 0, sourceBitmap.Width, sourceBitmap.Height), ImageLockMode.ReadOnly, PIXEL_FORMAT);
                        if (markedBitmap != null)
                        {
                            markedBitmapData = markedBitmap.LockBits(new Rectangle(0, 0, markedBitmap.Width, markedBitmap.Height), ImageLockMode.ReadWrite, PIXEL_FORMAT);
                        }
                        sourceStride       = sourceBitmapData.Stride;
                        sourceStrideOffset = sourceStride - (sourceBitmapData.Width * PIXEL_BYTE_WIDTH);

                        unsafe // see http://www.codeproject.com/csharp/quickgrayscale.asp?df=100&forumid=293759&select=2214623&msg=2214623
                        {
                            byte *sourcePointer;
                            byte *markedPointer;

                            if (mFindBlobOfSizeAndColorDefinition.SearchRecord.GetLength(0) < sourceBitmap.Width || mFindBlobOfSizeAndColorDefinition.SearchRecord.GetLength(1) < sourceBitmap.Height)
                            {
                                mFindBlobOfSizeAndColorDefinition.SearchRecord   = new short[sourceBitmap.Width, sourceBitmap.Height];
                                mFindBlobOfSizeAndColorDefinition.LastMarkerUsed = 0;
                            }
                            if (mFindBlobOfSizeAndColorDefinition.LastMarkerUsed == short.MaxValue)
                            {
                                short initialValue = short.MinValue + 1; // we don't use short.MinValue since that is a special case (see ClearSearchRecordArea(); before switching from int to short, we were initializing to 0 here and -1 in ClearSearchRecordArea())
                                for (int x = 0; x < mFindBlobOfSizeAndColorDefinition.SearchRecord.GetLength(0); x++)
                                {
                                    for (int y = 0; y < mFindBlobOfSizeAndColorDefinition.SearchRecord.GetLength(1); y++)
                                    {
                                        mFindBlobOfSizeAndColorDefinition.SearchRecord[x, y] = initialValue;
                                    }
                                }
                                mFindBlobOfSizeAndColorDefinition.LastMarkerUsed = 0;
                            }
                            mFindBlobOfSizeAndColorDefinition.LastMarkerUsed++;

                            for (int x = startX; x < ROI.Right && leftEdge < 0; x += searchXStep)
                            {
                                for (int y = startY; y < ROI.Bottom && leftEdge < 0; y += searchYStep)
                                {
                                    if (markedBitmap != null)
                                    {
                                        markedPointer    = (byte *)markedBitmapData.Scan0;              // init to first byte of image
                                        markedPointer   += (y * sourceStride) + (x * PIXEL_BYTE_WIDTH); // adjust to current point
                                        markedPointer[3] = Color.Lime.A;
                                        markedPointer[2] = Color.Lime.R;
                                        markedPointer[1] = Color.Lime.G;
                                        markedPointer[0] = Color.Lime.B;
                                    }

                                    bool failed = false;
                                    sourcePointer  = (byte *)sourceBitmapData.Scan0;              // init to first byte of image
                                    sourcePointer += (y * sourceStride) + (x * PIXEL_BYTE_WIDTH); // adjust to current point

                                    Color theColor = Color.FromArgb(sourcePointer[2], sourcePointer[1], sourcePointer[0]);
                                    if (mColorMatchDefinition.Matches(theColor))
                                    {
                                        TestExecution().LogMessageWithTimeFromTrigger(Name + ": found match at " + x + "," + y + "; beginning search of area");

                                        EdgeSearch topEdgeSearch    = new EdgeSearch(this, mColorMatchDefinition, Axis.X, y, -1 * stepSize, mROI.Top, x, mROI.Left, mROI.Right, mFindBlobOfSizeAndColorDefinition.SearchRecord, mFindBlobOfSizeAndColorDefinition.LastMarkerUsed);
                                        EdgeSearch bottomEdgeSearch = new EdgeSearch(this, mColorMatchDefinition, Axis.X, y, +1 * stepSize, mROI.Bottom, x, mROI.Left, mROI.Right, mFindBlobOfSizeAndColorDefinition.SearchRecord, mFindBlobOfSizeAndColorDefinition.LastMarkerUsed);
                                        EdgeSearch leftEdgeSearch   = new EdgeSearch(this, mColorMatchDefinition, Axis.Y, x, -1 * stepSize, mROI.Left, y, mROI.Top, mROI.Bottom, mFindBlobOfSizeAndColorDefinition.SearchRecord, mFindBlobOfSizeAndColorDefinition.LastMarkerUsed);
                                        EdgeSearch rightEdgeSearch  = new EdgeSearch(this, mColorMatchDefinition, Axis.Y, x, +1 * stepSize, mROI.Right, y, mROI.Top, mROI.Bottom, mFindBlobOfSizeAndColorDefinition.SearchRecord, mFindBlobOfSizeAndColorDefinition.LastMarkerUsed);
                                        topEdgeSearch.minSideEdge     = leftEdgeSearch;
                                        topEdgeSearch.maxSideEdge     = rightEdgeSearch;
                                        topEdgeSearch.opposingEdge    = bottomEdgeSearch;
                                        bottomEdgeSearch.minSideEdge  = leftEdgeSearch;
                                        bottomEdgeSearch.maxSideEdge  = rightEdgeSearch;
                                        bottomEdgeSearch.opposingEdge = topEdgeSearch;
                                        leftEdgeSearch.minSideEdge    = topEdgeSearch;
                                        leftEdgeSearch.maxSideEdge    = bottomEdgeSearch;
                                        leftEdgeSearch.opposingEdge   = rightEdgeSearch;
                                        rightEdgeSearch.minSideEdge   = topEdgeSearch;
                                        rightEdgeSearch.maxSideEdge   = bottomEdgeSearch;
                                        rightEdgeSearch.opposingEdge  = leftEdgeSearch;
                                        topEdgeSearch.maxSize         = maxObjectHeight;
                                        bottomEdgeSearch.maxSize      = maxObjectHeight;
                                        leftEdgeSearch.maxSize        = maxObjectWidth;
                                        rightEdgeSearch.maxSize       = maxObjectWidth;

                                        do
                                        {
                                            if (!topEdgeSearch.Done())
                                            {
                                                topEdgeSearch.TestLine();
                                            }
                                            if (!bottomEdgeSearch.Done())
                                            {
                                                bottomEdgeSearch.TestLine();
                                            }
                                            if (!leftEdgeSearch.Done())
                                            {
                                                leftEdgeSearch.TestLine();
                                            }
                                            if (!rightEdgeSearch.Done())
                                            {
                                                rightEdgeSearch.TestLine();
                                            }
                                            if (bottomEdgeSearch.lastPosWhereObjectSeen - topEdgeSearch.lastPosWhereObjectSeen > maxObjectHeight)
                                            {
                                                TestExecution().LogMessageWithTimeFromTrigger(Name + ": aborting area search because y-axis size exceeded; top=" + topEdgeSearch.lastPosWhereObjectSeen + " bottom=" + bottomEdgeSearch.lastPosWhereObjectSeen + " left=" + leftEdgeSearch.lastPosWhereObjectSeen + " right=" + rightEdgeSearch.lastPosWhereObjectSeen);
                                                failed = true;
                                                break;
                                            }
                                            if (rightEdgeSearch.lastPosWhereObjectSeen - leftEdgeSearch.lastPosWhereObjectSeen > maxObjectWidth)
                                            {
                                                TestExecution().LogMessageWithTimeFromTrigger(Name + ": aborting area search because x-axis size exceeded; top=" + topEdgeSearch.lastPosWhereObjectSeen + " bottom=" + bottomEdgeSearch.lastPosWhereObjectSeen + " left=" + leftEdgeSearch.lastPosWhereObjectSeen + " right=" + rightEdgeSearch.lastPosWhereObjectSeen);
                                                failed = true;
                                                break;
                                            }
                                            if (rightEdgeSearch.lastPosWhereObjectSeen == mROI.Right)
                                            {
                                                TestExecution().LogMessageWithTimeFromTrigger(Name + ": aborting area search because ran into right edge of ROI; top=" + topEdgeSearch.lastPosWhereObjectSeen + " bottom=" + bottomEdgeSearch.lastPosWhereObjectSeen + " left=" + leftEdgeSearch.lastPosWhereObjectSeen + " right=" + rightEdgeSearch.lastPosWhereObjectSeen);
                                                failed = true;
                                                break;
                                            }
                                            if (leftEdgeSearch.lastPosWhereObjectSeen == mROI.Left)
                                            {
                                                TestExecution().LogMessageWithTimeFromTrigger(Name + ": aborting area search because ran into left edge of ROI; top=" + topEdgeSearch.lastPosWhereObjectSeen + " bottom=" + bottomEdgeSearch.lastPosWhereObjectSeen + " left=" + leftEdgeSearch.lastPosWhereObjectSeen + " right=" + rightEdgeSearch.lastPosWhereObjectSeen);
                                                failed = true;
                                                break;
                                            }
                                            if (topEdgeSearch.lastPosWhereObjectSeen == mROI.Top)
                                            {
                                                TestExecution().LogMessageWithTimeFromTrigger(Name + ": aborting area search because ran into top edge of ROI; top=" + topEdgeSearch.lastPosWhereObjectSeen + " bottom=" + bottomEdgeSearch.lastPosWhereObjectSeen + " left=" + leftEdgeSearch.lastPosWhereObjectSeen + " right=" + rightEdgeSearch.lastPosWhereObjectSeen);
                                                failed = true;
                                                break;
                                            }
                                            if (bottomEdgeSearch.lastPosWhereObjectSeen == mROI.Bottom)
                                            {
                                                TestExecution().LogMessageWithTimeFromTrigger(Name + ": aborting area search because ran into bottom edge of ROI; top=" + topEdgeSearch.lastPosWhereObjectSeen + " bottom=" + bottomEdgeSearch.lastPosWhereObjectSeen + " left=" + leftEdgeSearch.lastPosWhereObjectSeen + " right=" + rightEdgeSearch.lastPosWhereObjectSeen);
                                                failed = true;
                                                break;
                                            }
                                        } while (!(topEdgeSearch.Done() && bottomEdgeSearch.Done() && leftEdgeSearch.Done() && rightEdgeSearch.Done()));

                                        if (detailedSearchAtEnd)
                                        {
                                            //topEdgeSearch.mStep
                                            //TODO: finish
                                            //TODO: recheck if object too big
                                        }

                                        if (leftEdgeSearch.abort || rightEdgeSearch.abort || topEdgeSearch.abort || bottomEdgeSearch.abort)
                                        {
                                            TestExecution().LogMessageWithTimeFromTrigger(Name + ": aborting area search because an edge search aborted (probably ran into an already searched pixel); top=" + topEdgeSearch.lastPosWhereObjectSeen + " bottom=" + bottomEdgeSearch.lastPosWhereObjectSeen + " left=" + leftEdgeSearch.lastPosWhereObjectSeen + " right=" + rightEdgeSearch.lastPosWhereObjectSeen);
                                            failed = true;
                                        }
                                        if (bottomEdgeSearch.lastPosWhereObjectSeen - topEdgeSearch.lastPosWhereObjectSeen < minObjectHeight)
                                        {
                                            TestExecution().LogMessageWithTimeFromTrigger(Name + ": excluding object since size too small on y-axis; top=" + topEdgeSearch.lastPosWhereObjectSeen + " bottom=" + bottomEdgeSearch.lastPosWhereObjectSeen + " left=" + leftEdgeSearch.lastPosWhereObjectSeen + " right=" + rightEdgeSearch.lastPosWhereObjectSeen);
                                            failed = true;

                                            // if the object/blob was too small, then if we re-check one of the pixels during a future search we don't want to abort on the assumption the object must be too big
                                            // ...this issue came up in Head Rest's Weld Orrient 9/18/08...in certain cases we would first find a small blob to the left of the weld, but would abort because it was too small...it's edges would be close to, but below the search color boundary.  Then we would find the main chunk of the light, which would wrap partially around the small blob (to the right and below)....during it's not-so-smart-but-fast search it would retest a pixel of the small blob and immediately abort...mistakenly assuming it bumped into a previous "too large" blob.
                                            // ...it could bump into a previous "too small" blob because of the way to search within the entire bounding rectangle...as a simplified method of catching "U" or "Z" shaped blobs (ie ones that double back)
                                            ClearSearchRecordArea(leftEdgeSearch.lastPosWhereObjectSeen, rightEdgeSearch.lastPosWhereObjectSeen, topEdgeSearch.lastPosWhereObjectSeen, bottomEdgeSearch.lastPosWhereObjectSeen);
                                        }
                                        else if (rightEdgeSearch.lastPosWhereObjectSeen - leftEdgeSearch.lastPosWhereObjectSeen < minObjectWidth)
                                        {
                                            TestExecution().LogMessageWithTimeFromTrigger(Name + ": excluding object since size too small on x-axis; top=" + topEdgeSearch.lastPosWhereObjectSeen + " bottom=" + bottomEdgeSearch.lastPosWhereObjectSeen + " left=" + leftEdgeSearch.lastPosWhereObjectSeen + " right=" + rightEdgeSearch.lastPosWhereObjectSeen);
                                            failed = true;

                                            // if the object/blob was too small, then if we re-check one of the pixels during a future search we don't want to abort on the assumption the object must be too big
                                            // ...this issue came up in Head Rest's Weld Orrient 9/18/08...in certain cases we would first find a small blob to the left of the weld, but would abort because it was too small...it's edges would be close to, but below the search color boundary.  Then we would find the main chunk of the light, which would wrap partially around the small blob (to the right and below)....during it's not-so-smart-but-fast search it would retest a pixel of the small blob and immediately abort...mistakenly assuming it bumped into a previous "too large" blob.
                                            // ...it could bump into a previous "too small" blob because of the way to search within the entire bounding rectangle...as a simplified method of catching "U" or "Z" shaped blobs (ie ones that double back)
                                            ClearSearchRecordArea(leftEdgeSearch.lastPosWhereObjectSeen, rightEdgeSearch.lastPosWhereObjectSeen, topEdgeSearch.lastPosWhereObjectSeen, bottomEdgeSearch.lastPosWhereObjectSeen);
                                        }
                                        if (!failed)
                                        {
                                            TestExecution().LogMessageWithTimeFromTrigger(Name + ": selected object bounded by: top=" + topEdgeSearch.lastPosWhereObjectSeen + " bottom=" + bottomEdgeSearch.lastPosWhereObjectSeen + " left=" + leftEdgeSearch.lastPosWhereObjectSeen + " right=" + rightEdgeSearch.lastPosWhereObjectSeen);
                                            leftEdge   = leftEdgeSearch.lastPosWhereObjectSeen;
                                            rightEdge  = rightEdgeSearch.lastPosWhereObjectSeen;
                                            topEdge    = topEdgeSearch.lastPosWhereObjectSeen;
                                            bottomEdge = bottomEdgeSearch.lastPosWhereObjectSeen;
                                        }
                                    }
                                }
                            }
                        } // end unsafe block
                    }
                    catch (Exception e)
                    {
                        TestExecution().LogMessageWithTimeFromTrigger("ERROR: Failure in " + Name + "; msg=" + e.Message + " " + Environment.NewLine + e.StackTrace);
                    }
                    finally
                    {
                        sourceBitmap.UnlockBits(sourceBitmapData);
                        if (markedBitmap != null)
                        {
                            markedBitmap.UnlockBits(markedBitmapData);
                        }
                    }
                }
            } // end main block ("else" after all initial setup error checks)
            mLeftBound.SetValue(leftEdge);
            mLeftBound.SetIsComplete();
            mRightBound.SetValue(rightEdge);
            mRightBound.SetIsComplete();
            mTopBound.SetValue(topEdge);
            mTopBound.SetIsComplete();
            mBottomBound.SetValue(bottomEdge);
            mBottomBound.SetIsComplete();
            DateTime doneTime    = DateTime.Now;
            TimeSpan computeTime = doneTime - startTime;

            if (leftEdge < 0)
            {
                TestExecution().LogMessageWithTimeFromTrigger(Name + " FAILED TO FIND BLOB");
            }

            if (mAutoSave)
            {
                try
                {
                    string filePath = ((FindRadialLineDefinition)Definition()).AutoSavePath;
                    mSourceImage.Save(filePath, Name, true);
                    if (mImageToMark != null)
                    {
                        mImageToMark.Save(filePath, Name, "_marked_" + leftEdge + "_" + rightEdge + "_" + topEdge + "_" + bottomEdge);
                    }
                    TestExecution().LogMessageWithTimeFromTrigger("Snapshot saved");
                }
                catch (ArgumentException e)
                {
                    Project().Window().logMessage("ERROR: " + e.Message);
                    TestExecution().LogErrorWithTimeFromTrigger(e.Message);
                }
                catch (Exception e)
                {
                    Project().Window().logMessage("ERROR: Unable to AutoSave snapshot from " + Name + ".  Ensure path valid and disk not full.  Low-level message=" + e.Message);
                    TestExecution().LogErrorWithTimeFromTrigger("Unable to AutoSave snapshot from " + Name + ".  Ensure path valid and disk not full.");
                }
            }
            TestExecution().LogMessageWithTimeFromTrigger(Name + " finished at " + doneTime + "  | took " + computeTime.TotalMilliseconds + "ms");
        }