static void SimpleImageExample(MIL_ID MilSystem, MIL_ID MilDisplay) { MIL_ID MilImage = MIL.M_NULL; // Image buffer identifier. MIL_ID GraphicList = MIL.M_NULL; // Graphic list identifier. MIL_ID MilMetrolContext = MIL.M_NULL; // Metrology Context MIL_ID MilMetrolResult = MIL.M_NULL; // Metrology Result double Status = 0.0; double Value = 0.0; MIL_INT FeatureIndexForTopConstructedPoint = MIL.M_FEATURE_INDEX(1); MIL_INT FeatureIndexForMiddleConstructedPoint = MIL.M_FEATURE_INDEX(2); MIL_INT[] FeatureIndexForConstructedSegment = new MIL_INT[2]; MIL_INT[] FeatureIndexForTolerance = new MIL_INT[2]; FeatureIndexForConstructedSegment[0] = MIL.M_FEATURE_INDEX(3); FeatureIndexForConstructedSegment[1] = MIL.M_FEATURE_INDEX(4); FeatureIndexForTolerance[0] = MIL.M_FEATURE_INDEX(5); FeatureIndexForTolerance[1] = MIL.M_FEATURE_INDEX(6); // Restore and display the source image. MIL.MbufRestore(METROL_SIMPLE_IMAGE_FILE, MilSystem, ref MilImage); MIL.MdispSelect(MilDisplay, MilImage); // Allocate a graphic list to hold the subpixel annotations to draw. MIL.MgraAllocList(MilSystem, MIL.M_DEFAULT, ref GraphicList); // Associate the graphic list to the display for annotations. MIL.MdispControl(MilDisplay, MIL.M_ASSOCIATED_GRAPHIC_LIST_ID, GraphicList); // Allocate metrology context and result. MIL.MmetAlloc(MilSystem, MIL.M_DEFAULT, ref MilMetrolContext); MIL.MmetAllocResult(MilSystem, MIL.M_DEFAULT, ref MilMetrolResult); // Add a first measured circle feature to context and set its search region MIL.MmetAddFeature(MilMetrolContext, MIL.M_MEASURED, MIL.M_CIRCLE, MIL.M_DEFAULT, MIL.M_DEFAULT, MIL.M_NULL, MIL.M_NULL, MIL.M_DEFAULT, MIL.M_DEFAULT); MIL.MmetSetRegion(MilMetrolContext, MIL.M_FEATURE_INDEX(1), MIL.M_DEFAULT, MIL.M_RING, TOP_RING_POSITION_X, TOP_RING_POSITION_Y, TOP_RING_START_RADIUS, TOP_RING_END_RADIUS, MIL.M_NULL, MIL.M_NULL); // Add a second measured circle feature to context and set its search region MIL.MmetAddFeature(MilMetrolContext, MIL.M_MEASURED, MIL.M_CIRCLE, MIL.M_DEFAULT, MIL.M_DEFAULT, MIL.M_NULL, MIL.M_NULL, MIL.M_DEFAULT, MIL.M_DEFAULT); MIL.MmetSetRegion(MilMetrolContext, MIL.M_FEATURE_INDEX(2), MIL.M_DEFAULT, MIL.M_RING, MIDDLE_RING_POSITION_X, MIDDLE_RING_POSITION_Y, MIDDLE_RING_START_RADIUS, MIDDLE_RING_END_RADIUS, MIL.M_NULL, MIL.M_NULL); // Add a first constructed point feature to context MIL.MmetAddFeature(MilMetrolContext, MIL.M_CONSTRUCTED, MIL.M_POINT, MIL.M_DEFAULT, MIL.M_CENTER, ref FeatureIndexForTopConstructedPoint, MIL.M_NULL, 1, MIL.M_DEFAULT); // Add a second constructed point feature to context MIL.MmetAddFeature(MilMetrolContext, MIL.M_CONSTRUCTED, MIL.M_POINT, MIL.M_DEFAULT, MIL.M_CENTER, ref FeatureIndexForMiddleConstructedPoint, MIL.M_NULL, 1, MIL.M_DEFAULT); // Add a constructed segment feature to context passing through the two points MIL.MmetAddFeature(MilMetrolContext, MIL.M_CONSTRUCTED, MIL.M_SEGMENT, MIL.M_DEFAULT, MIL.M_CONSTRUCTION, FeatureIndexForConstructedSegment, MIL.M_NULL, 2, MIL.M_DEFAULT); // Add a first segment feature to context and set its search region MIL.MmetAddFeature(MilMetrolContext, MIL.M_MEASURED, MIL.M_SEGMENT, MIL.M_DEFAULT, MIL.M_DEFAULT, MIL.M_NULL, MIL.M_NULL, MIL.M_DEFAULT, MIL.M_DEFAULT); MIL.MmetSetRegion(MilMetrolContext, MIL.M_FEATURE_INDEX(6), MIL.M_DEFAULT, MIL.M_RECTANGLE, BOTTOM_RECT_POSITION_X, BOTTOM_RECT_POSITION_Y, BOTTOM_RECT_WIDTH, BOTTOM_RECT_HEIGHT, BOTTOM_RECT_ANGLE, MIL.M_NULL); // Add perpendicularity tolerance MIL.MmetAddTolerance(MilMetrolContext, MIL.M_PERPENDICULARITY, MIL.M_DEFAULT, PERPENDICULARITY_MIN, PERPENDICULARITY_MAX, FeatureIndexForTolerance, MIL.M_NULL, 2, MIL.M_DEFAULT); // Calculate MIL.MmetCalculate(MilMetrolContext, MilImage, MilMetrolResult, MIL.M_DEFAULT); // Draw region MIL.MgraColor(MIL.M_DEFAULT, REGION_COLOR); MIL.MmetDraw(MIL.M_DEFAULT, MilMetrolResult, GraphicList, MIL.M_DRAW_REGION, MIL.M_DEFAULT, MIL.M_DEFAULT); Console.Write("Regions used to calculate measured features:\n"); Console.Write("- two measured circles\n"); Console.Write("- one measured segment\n"); Console.Write("Press <Enter> to continue.\n\n"); Console.ReadKey(); // Clear annotations. MIL.MgraClear(MIL.M_DEFAULT, GraphicList); MIL.MgraColor(MIL.M_DEFAULT, FEATURE_COLOR); MIL.MmetDraw(MIL.M_DEFAULT, MilMetrolResult, GraphicList, MIL.M_DRAW_FEATURE, MIL.M_DEFAULT, MIL.M_DEFAULT); Console.Write("Calculated features:\n"); MIL.MmetGetResult(MilMetrolResult, MIL.M_FEATURE_INDEX(1), MIL.M_RADIUS, ref Value); Console.Write("- first measured circle: radius={0:0.00}\n", Value); MIL.MmetGetResult(MilMetrolResult, MIL.M_FEATURE_INDEX(2), MIL.M_RADIUS, ref Value); Console.Write("- second measured circle: radius={0:0.00}\n", Value); MIL.MmetGetResult(MilMetrolResult, MIL.M_FEATURE_INDEX(5), MIL.M_LENGTH, ref Value); Console.Write("- constructed segment between the two circle centers: length={0:0.00}\n", Value); MIL.MmetGetResult(MilMetrolResult, MIL.M_FEATURE_INDEX(6), MIL.M_LENGTH, ref Value); Console.Write("- measured segment: length={0:0.00}\n", Value); Console.Write("Press <Enter> to continue.\n\n"); Console.ReadKey(); // Get angularity tolerance status and value MIL.MmetGetResult(MilMetrolResult, MIL.M_TOLERANCE_INDEX(0), MIL.M_STATUS, ref Status); MIL.MmetGetResult(MilMetrolResult, MIL.M_TOLERANCE_INDEX(0), MIL.M_TOLERANCE_VALUE, ref Value); if (Status == MIL.M_PASS) { MIL.MgraColor(MIL.M_DEFAULT, PASS_COLOR); Console.Write("Perpendicularity between the two segments: {0:0.00} degrees.\n", Value); } else { MIL.MgraColor(MIL.M_DEFAULT, FAIL_COLOR); Console.Write("Perpendicularity between the two segments - Fail.\n"); } MIL.MmetDraw(MIL.M_DEFAULT, MilMetrolResult, GraphicList, MIL.M_DRAW_TOLERANCE, MIL.M_TOLERANCE_INDEX(0), MIL.M_DEFAULT); Console.Write("Press <Enter> to continue.\n\n"); Console.ReadKey(); // Free all allocations. MIL.MgraFree(GraphicList); MIL.MmetFree(MilMetrolResult); MIL.MmetFree(MilMetrolContext); MIL.MbufFree(MilImage); }