#include <mil.h>
#include <malloc.h>
#include <math.h>
#if M_MIL_USE_WINDOWS && !M_MIL_USE_CE && !M_MIL_USE_RT
#include "MdispD3D.h"
#endif
void DepthCorrectionExample(MIL_ID MilSystem, MIL_ID MilDisplay);
void CalibratedCameraExample(MIL_ID MilSystem, MIL_ID MilDisplay);
void PerformBlobAnalysis(MIL_ID MilSystem,
MIL_ID MilDisplay,
MIL_ID MilOverlayImage,
MIL_ID MilDepthMap);
void SetupColorDisplay(MIL_ID MilSystem, MIL_ID MilDisplay, MIL_INT SizeBit);
MIL_DOUBLE ComputeVolume(MIL_ID MilSystem, MIL_ID MilDepthMap);
int MosMain(void)
{
MIL_ID MilApplication,
MilSystem,
MilDisplay;
MappAllocDefault(M_DEFAULT, &MilApplication, &MilSystem, &MilDisplay, M_NULL, M_NULL);
DepthCorrectionExample(MilSystem, MilDisplay);
CalibratedCameraExample(MilSystem, MilDisplay);
MappFreeDefault(MilApplication, MilSystem, MilDisplay, M_NULL, M_NULL);
return 0;
}
#define REFERENCE_PLANES_SEQUENCE_FILE M_IMAGE_PATH MIL_TEXT("ReferencePlanes.avi")
#define OBJECT_SEQUENCE_FILE M_IMAGE_PATH MIL_TEXT("ScannedObject.avi")
#define PEAK_WIDTH_NOMINAL 10
#define PEAK_WIDTH_DELTA 8
#define MIN_CONTRAST 140
static const double CORRECTED_DEPTHS[] = {1.25, 2.50, 3.75, 5.00};
#define SCALE_FACTOR 10000.0
#define CALIB_TEXT_POS_X 400
#define CALIB_TEXT_POS_Y 15
void DepthCorrectionExample(MIL_ID MilSystem, MIL_ID MilDisplay)
{
MIL_ID MilOverlayImage,
MilImage,
MilDepthMap,
MilLaser,
MilCalibScan,
MilScan;
MIL_INT SizeX,
SizeY,
NbReferencePlanes,
NbObjectImages;
int n;
MIL_DOUBLE FrameRate,
StartTime,
EndTime,
WaitTime;
MbufDiskInquire(REFERENCE_PLANES_SEQUENCE_FILE, M_SIZE_X, &SizeX);
MbufDiskInquire(REFERENCE_PLANES_SEQUENCE_FILE, M_SIZE_Y, &SizeY);
MbufDiskInquire(REFERENCE_PLANES_SEQUENCE_FILE, M_NUMBER_OF_IMAGES, &NbReferencePlanes);
MbufDiskInquire(REFERENCE_PLANES_SEQUENCE_FILE, M_FRAME_RATE, &FrameRate);
MbufDiskInquire(OBJECT_SEQUENCE_FILE, M_NUMBER_OF_IMAGES, &NbObjectImages);
MbufAlloc2d(MilSystem, SizeX, SizeY, 8+M_UNSIGNED, M_IMAGE+M_DISP+M_PROC, &MilImage);
MbufClear(MilImage, 0.0);
MosPrintf(MIL_TEXT("\nDEPTH ANALYSIS:\n"));
MosPrintf(MIL_TEXT("---------------\n\n"));
MosPrintf(MIL_TEXT("This program performs a surface inspection to detect "));
MosPrintf(MIL_TEXT("depth defects \n"));
MosPrintf(MIL_TEXT("on a wood surface using a laser (sheet-of-light) "));
MosPrintf(MIL_TEXT("profiling system.\n\n"));
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
MdispSelect(MilDisplay, MilImage);
MdispControl(MilDisplay, M_OVERLAY, M_ENABLE);
MdispInquire(MilDisplay, M_OVERLAY_ID, &MilOverlayImage);
MgraControl(M_DEFAULT, M_BACKGROUND_MODE, M_TRANSPARENT);
MgraColor(M_DEFAULT, M_COLOR_WHITE);
M3dmapAlloc(MilSystem, M_LASER, M_DEPTH_CORRECTION, &MilLaser);
M3dmapAllocResult(MilSystem, M_LASER_CALIBRATION_DATA, M_DEFAULT, &MilCalibScan);
MIL_ID MilPeakLocator;
M3dmapInquire(MilLaser, M_CONTEXT, M_LOCATE_PEAK_1D_CONTEXT_ID+M_TYPE_MIL_ID, &MilPeakLocator);
MimControl(MilPeakLocator, M_PEAK_WIDTH_NOMINAL, PEAK_WIDTH_NOMINAL);
MimControl(MilPeakLocator, M_PEAK_WIDTH_DELTA , PEAK_WIDTH_DELTA );
MimControl(MilPeakLocator, M_MINIMUM_CONTRAST , MIN_CONTRAST );
MbufImportSequence(REFERENCE_PLANES_SEQUENCE_FILE, M_DEFAULT, M_NULL, M_NULL, NULL,
M_NULL, M_NULL, M_OPEN);
MappTimer(M_DEFAULT, M_TIMER_READ+M_SYNCHRONOUS, &StartTime);
for (n = 0; n < NbReferencePlanes; n++)
{
MIL_TEXT_CHAR CalibString[32];
MbufImportSequence(REFERENCE_PLANES_SEQUENCE_FILE, M_DEFAULT, M_LOAD, M_NULL,
&MilImage, M_DEFAULT, 1, M_READ);
MdispControl(MilDisplay, M_OVERLAY_CLEAR, M_DEFAULT);
MosSprintf(CalibString, 32, MIL_TEXT("Reference plane %d: %.2f mm"),
(int)(n+1), CORRECTED_DEPTHS[n]);
MgraText(M_DEFAULT, MilOverlayImage, CALIB_TEXT_POS_X, CALIB_TEXT_POS_Y, CalibString);
M3dmapControl(MilLaser, M_DEFAULT, M_CORRECTED_DEPTH,
CORRECTED_DEPTHS[n]*SCALE_FACTOR);
M3dmapAddScan(MilLaser, MilCalibScan, MilImage, M_NULL, M_NULL, M_DEFAULT, M_DEFAULT);
MappTimer(M_DEFAULT, M_TIMER_READ+M_SYNCHRONOUS, &EndTime);
WaitTime = (1.0/FrameRate) - (EndTime - StartTime);
if (WaitTime > 0)
MappTimer(M_DEFAULT, M_TIMER_WAIT, &WaitTime);
MappTimer(M_DEFAULT, M_TIMER_READ+M_SYNCHRONOUS, &StartTime);
}
MbufImportSequence(REFERENCE_PLANES_SEQUENCE_FILE, M_DEFAULT, M_NULL, M_NULL, NULL,
M_NULL, M_NULL, M_CLOSE);
M3dmapCalibrate(MilLaser, MilCalibScan, M_NULL, M_DEFAULT);
MosPrintf(MIL_TEXT("The laser profiling system has been calibrated using 4 reference\n"));
MosPrintf(MIL_TEXT("planes of known heights.\n\n"));
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
MosPrintf(MIL_TEXT("The wood surface is being scanned.\n\n"));
M3dmapFree(MilCalibScan);
MilCalibScan = M_NULL;
M3dmapAllocResult(MilSystem, M_DEPTH_CORRECTED_DATA, M_DEFAULT, &MilScan);
MbufDiskInquire(OBJECT_SEQUENCE_FILE, M_FRAME_RATE, &FrameRate);
MbufImportSequence(OBJECT_SEQUENCE_FILE, M_DEFAULT, M_NULL, M_NULL, NULL, M_NULL,
M_NULL, M_OPEN);
MappTimer(M_DEFAULT, M_TIMER_READ+M_SYNCHRONOUS, &StartTime);
MdispControl(MilDisplay, M_OVERLAY_CLEAR, M_DEFAULT);
for (n = 0; n < NbObjectImages; n++)
{
MbufImportSequence(OBJECT_SEQUENCE_FILE, M_DEFAULT, M_LOAD, M_NULL, &MilImage,
M_DEFAULT, 1, M_READ);
M3dmapAddScan(MilLaser, MilScan, MilImage, M_NULL, M_NULL, M_DEFAULT, M_DEFAULT);
MappTimer(M_DEFAULT, M_TIMER_READ+M_SYNCHRONOUS, &EndTime);
WaitTime = (1.0/FrameRate) - (EndTime - StartTime);
if (WaitTime > 0)
MappTimer(M_DEFAULT, M_TIMER_WAIT, &WaitTime);
MappTimer(M_DEFAULT, M_TIMER_READ+M_SYNCHRONOUS, &StartTime);
}
MbufImportSequence(OBJECT_SEQUENCE_FILE, M_DEFAULT, M_NULL, M_NULL, NULL, M_NULL,
M_NULL, M_CLOSE);
MbufAlloc2d(MilSystem, SizeX, NbObjectImages, 16+M_UNSIGNED,
M_IMAGE+M_PROC+M_DISP, &MilDepthMap);
M3dmapExtract(MilScan, MilDepthMap, M_NULL, M_CORRECTED_DEPTH_MAP, M_DEFAULT, M_DEFAULT);
SetupColorDisplay(MilSystem, MilDisplay, MbufInquire(MilDepthMap, M_SIZE_BIT, M_NULL));
MdispSelect(MilDisplay, MilDepthMap);
MdispInquire(MilDisplay, M_OVERLAY_ID, &MilOverlayImage);
MosPrintf(MIL_TEXT("The pseudo-color depth map of the surface is displayed.\n\n"));
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
PerformBlobAnalysis(MilSystem, MilDisplay, MilOverlayImage, MilDepthMap);
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
MdispLut(MilDisplay, M_DEFAULT);
MdispControl(MilDisplay, M_OVERLAY_CLEAR, M_DEFAULT);
M3dmapFree(MilScan);
M3dmapFree(MilLaser);
MbufFree(MilDepthMap);
MbufFree(MilImage);
}
#define EXPECTED_HEIGHT 3.4
#define DEFECT_THRESHOLD 0.2
#define SATURATED_DEFECT 1.0
#define MIN_BLOB_RADIUS 3L
#define TEXT_H_OFFSET_1 -50
#define TEXT_V_OFFSET_1 -6
#define TEXT_H_OFFSET_2 -30
#define TEXT_V_OFFSET_2 6
void PerformBlobAnalysis(MIL_ID MilSystem,
MIL_ID MilDisplay,
MIL_ID MilOverlayImage,
MIL_ID MilDepthMap)
{
MIL_ID MilBinImage,
MilBlobFeatureList,
MilBlobResult;
MIL_INT SizeX,
SizeY,
TotalBlobs,
n,
*MinPixels;
MIL_DOUBLE DefectThreshold,
*CogX,
*CogY;
MbufInquire(MilDepthMap, M_SIZE_X, &SizeX);
MbufInquire(MilDepthMap, M_SIZE_Y, &SizeY);
MbufAlloc2d(MilSystem, SizeX, SizeY, 1+M_UNSIGNED, M_IMAGE+M_PROC, &MilBinImage);
DefectThreshold = (EXPECTED_HEIGHT-DEFECT_THRESHOLD) * SCALE_FACTOR;
MimBinarize(MilDepthMap, MilBinImage, M_FIXED+M_LESS_OR_EQUAL, DefectThreshold, M_NULL);
MimOpen(MilBinImage, MilBinImage, MIN_BLOB_RADIUS, M_BINARY);
MblobAllocFeatureList(MilSystem, &MilBlobFeatureList);
MblobSelectFeature(MilBlobFeatureList, M_CENTER_OF_GRAVITY);
MblobSelectFeature(MilBlobFeatureList, M_MIN_PIXEL);
MblobAllocResult(MilSystem, &MilBlobResult);
MblobCalculate(MilBinImage, MilDepthMap, MilBlobFeatureList, MilBlobResult);
MblobGetNumber(MilBlobResult, &TotalBlobs);
MosPrintf(MIL_TEXT("Number of defects: %lld\n"), (long long)TotalBlobs);
if ((CogX = (MIL_DOUBLE *)malloc(TotalBlobs*sizeof(MIL_DOUBLE))) &&
(CogY = (MIL_DOUBLE *)malloc(TotalBlobs*sizeof(MIL_DOUBLE))) &&
(MinPixels = (MIL_INT *)malloc(TotalBlobs*sizeof(MIL_INT )))
)
{
MblobGetResult(MilBlobResult, M_CENTER_OF_GRAVITY_X, CogX);
MblobGetResult(MilBlobResult, M_CENTER_OF_GRAVITY_Y, CogY);
MblobGetResult(MilBlobResult, M_MIN_PIXEL+M_TYPE_MIL_INT, MinPixels);
MgraColor(M_DEFAULT, M_COLOR_RED);
MblobDraw(M_DEFAULT, MilBlobResult, MilOverlayImage,
M_DRAW_BLOBS, M_INCLUDED_BLOBS, M_DEFAULT);
MgraColor(M_DEFAULT, M_COLOR_WHITE);
for(n=0; n < TotalBlobs; n++)
{
MIL_DOUBLE DepthOfDefect;
MIL_TEXT_CHAR DepthString[16];
DepthOfDefect = EXPECTED_HEIGHT - (MinPixels[n]/SCALE_FACTOR);
MosSprintf(DepthString, 16, MIL_TEXT("%.2f mm"), DepthOfDefect);
MosPrintf(MIL_TEXT("Defect #%lld: depth =%5.2f mm\n\n"),
(long long)n, DepthOfDefect);
MgraText(M_DEFAULT, MilOverlayImage, CogX[n]+TEXT_H_OFFSET_1,
CogY[n]+TEXT_V_OFFSET_1, MIL_TEXT("Defect depth"));
MgraText(M_DEFAULT, MilOverlayImage, CogX[n]+TEXT_H_OFFSET_2,
CogY[n]+TEXT_V_OFFSET_2, DepthString);
}
free(CogX);
free(CogY);
free(MinPixels);
}
else
MosPrintf(MIL_TEXT("Error: Not enough memory.\n\n"));
MblobFree(MilBlobResult);
MblobFree(MilBlobFeatureList);
MbufFree(MilBinImage);
}
#define BLUE_HUE 171.0
#define RED_HUE 0.0
#define FULL_SATURATION 255
#define HALF_LUMINANCE 128
void SetupColorDisplay(MIL_ID MilSystem, MIL_ID MilDisplay, MIL_INT SizeBit)
{
MIL_ID MilRampLut1Band,
MilRampLut3Band,
MilColorImage;
MIL_INT DefectGrayLevel,
ExpectedGrayLevel,
NbGrayLevels;
NbGrayLevels = (MIL_INT)(1 << SizeBit);
MbufAlloc1d(MilSystem, NbGrayLevels, 8+M_UNSIGNED, M_LUT, &MilRampLut1Band);
DefectGrayLevel = (MIL_INT)((EXPECTED_HEIGHT-SATURATED_DEFECT)*SCALE_FACTOR);
ExpectedGrayLevel = (MIL_INT)(EXPECTED_HEIGHT*SCALE_FACTOR);
MgenLutRamp(MilRampLut1Band, 0, RED_HUE, DefectGrayLevel, RED_HUE);
MgenLutRamp(MilRampLut1Band, DefectGrayLevel, RED_HUE, ExpectedGrayLevel, BLUE_HUE);
MgenLutRamp(MilRampLut1Band, ExpectedGrayLevel, BLUE_HUE, NbGrayLevels-1, BLUE_HUE);
MbufAllocColor(MilSystem, 3, NbGrayLevels, 1, 8+M_UNSIGNED, M_IMAGE, &MilColorImage);
MbufClear(MilColorImage, M_RGB888(0, FULL_SATURATION, HALF_LUMINANCE));
MbufCopyColor2d(MilRampLut1Band, MilColorImage, 0, 0, 0, 0, 0, 0, NbGrayLevels, 1);
MimConvert(MilColorImage, MilColorImage, M_HSL_TO_RGB);
MbufAllocColor(MilSystem, 3, NbGrayLevels, 1, 8+M_UNSIGNED, M_LUT, &MilRampLut3Band);
MbufCopy(MilColorImage, MilRampLut3Band);
MdispLut(MilDisplay, MilRampLut3Band);
MbufFree(MilRampLut1Band);
MbufFree(MilRampLut3Band);
MbufFree(MilColorImage);
}
#define GRID_FILENAME M_IMAGE_PATH MIL_TEXT("GridForLaser.mim")
#define LASERLINE_FILENAME M_IMAGE_PATH MIL_TEXT("LaserLine.mim")
#define OBJECT2_SEQUENCE_FILE M_IMAGE_PATH MIL_TEXT("Cookie.avi")
#define GRID_NB_ROWS 13
#define GRID_NB_COLS 12
#define GRID_ROW_SPACING 5.0
#define GRID_COL_SPACING 5.0
#define CONVEYOR_SPEED -0.2
#define DEPTH_MAP_SIZE_X 480
#define DEPTH_MAP_SIZE_Y 480
#define GAP_DEPTH 1.5
#define D3D_DISPLAY_SIZE_X 640
#define D3D_DISPLAY_SIZE_Y 480
#define PEAK_WIDTH_NOMINAL_2 9
#define PEAK_WIDTH_DELTA_2 7
#define MIN_CONTRAST_2 75
#define MIN_HEIGHT_THRESHOLD 1.0
void CalibratedCameraExample(MIL_ID MilSystem, MIL_ID MilDisplay)
{
MIL_ID MilOverlayImage,
MilImage,
MilCalibration,
MilDepthMap,
MilLaser,
MilCalibScan,
MilScan;
MIL_INT CalibrationStatus,
SizeX,
SizeY,
NumberOfImages,
n;
MIL_DOUBLE FrameRate,
StartTime,
EndTime,
WaitTime,
Volume,
VolumeError;
MosPrintf(MIL_TEXT("\n3D PROFILING AND VOLUME ANALYSIS:\n"));
MosPrintf(MIL_TEXT("---------------------------------\n\n"));
MosPrintf(MIL_TEXT("This program generates fully corrected 3d data of a\n"));
MosPrintf(MIL_TEXT("scanned cookie and computes its volume.\n"));
MosPrintf(MIL_TEXT("The laser (sheet-of-light) profiling system uses a\n"));
MosPrintf(MIL_TEXT("3d-calibrated camera.\n\n"));
MbufRestore(GRID_FILENAME, MilSystem, &MilImage);
MdispSelect(MilDisplay, MilImage);
MosPrintf(MIL_TEXT("Calibrating the camera...\n\n"));
MbufInquire(MilImage, M_SIZE_X, &SizeX);
MbufInquire(MilImage, M_SIZE_Y, &SizeY);
McalAlloc(MilSystem, M_TSAI_BASED, M_DEFAULT, &MilCalibration);
McalGrid(MilCalibration, MilImage, 0.0, 0.0, 0.0, GRID_NB_ROWS, GRID_NB_COLS,
GRID_ROW_SPACING, GRID_COL_SPACING, M_DEFAULT, M_CHESSBOARD_GRID);
McalInquire(MilCalibration, M_CALIBRATION_STATUS+M_TYPE_MIL_INT, &CalibrationStatus);
if (CalibrationStatus != M_CALIBRATED)
{
McalFree(MilCalibration);
MbufFree(MilImage);
MosPrintf(MIL_TEXT("Camera calibration failed.\n"));
MosPrintf(MIL_TEXT("Press <Enter> to end.\n\n"));
MosGetch();
return;
}
MdispControl(MilDisplay, M_OVERLAY, M_ENABLE);
MdispInquire(MilDisplay, M_OVERLAY_ID, &MilOverlayImage);
MgraColor(M_DEFAULT, M_COLOR_GREEN);
McalDraw(M_DEFAULT, MilCalibration, MilOverlayImage, M_DRAW_IMAGE_POINTS,
M_DEFAULT, M_DEFAULT);
MosPrintf(MIL_TEXT("The camera was calibrated using a chessboard grid.\n\n"));
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
MdispControl(MilDisplay, M_OVERLAY, M_DISABLE);
MbufLoad(LASERLINE_FILENAME, MilImage);
M3dmapAlloc(MilSystem, M_LASER, M_CALIBRATED_CAMERA_LINEAR_MOTION, &MilLaser);
M3dmapAllocResult(MilSystem, M_LASER_CALIBRATION_DATA, M_DEFAULT, &MilCalibScan);
MIL_ID MilPeakLocator;
M3dmapInquire(MilLaser, M_CONTEXT, M_LOCATE_PEAK_1D_CONTEXT_ID+M_TYPE_MIL_ID, &MilPeakLocator);
MimControl(MilPeakLocator, M_PEAK_WIDTH_NOMINAL, PEAK_WIDTH_NOMINAL_2);
MimControl(MilPeakLocator, M_PEAK_WIDTH_DELTA , PEAK_WIDTH_DELTA_2 );
MimControl(MilPeakLocator, M_MINIMUM_CONTRAST , MIN_CONTRAST_2 );
M3dmapAddScan(MilLaser, MilCalibScan, MilImage, M_NULL, M_NULL, M_DEFAULT, M_DEFAULT);
M3dmapCalibrate(MilLaser, MilCalibScan, MilCalibration, M_DEFAULT);
MosPrintf(MIL_TEXT("The laser profiling system has been calibrated using the image\n"));
MosPrintf(MIL_TEXT("of one laser line.\n\n"));
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
M3dmapFree(MilCalibScan);
MilCalibScan = M_NULL;
M3dmapAllocResult(MilSystem, M_POINT_CLOUD_CONTAINER, M_DEFAULT, &MilScan);
M3dmapControl(MilLaser, M_DEFAULT, M_SCAN_SPEED, CONVEYOR_SPEED);
MbufDiskInquire(OBJECT2_SEQUENCE_FILE, M_NUMBER_OF_IMAGES, &NumberOfImages);
MbufDiskInquire(OBJECT2_SEQUENCE_FILE, M_FRAME_RATE, &FrameRate);
MbufImportSequence(OBJECT2_SEQUENCE_FILE, M_DEFAULT, M_NULL, M_NULL, NULL, M_NULL,
M_NULL, M_OPEN);
MosPrintf(MIL_TEXT("The cookie is being scanned to generate 3d data.\n\n"));
MappTimer(M_DEFAULT, M_TIMER_READ+M_SYNCHRONOUS, &StartTime);
for (n = 0; n < NumberOfImages; n++)
{
MbufImportSequence(OBJECT2_SEQUENCE_FILE, M_DEFAULT, M_LOAD, M_NULL, &MilImage,
M_DEFAULT, 1, M_READ);
M3dmapAddScan(MilLaser, MilScan, MilImage, M_NULL, M_NULL, M_POINT_CLOUD_LABEL(1), M_DEFAULT);
MappTimer(M_DEFAULT, M_TIMER_READ+M_SYNCHRONOUS, &EndTime);
WaitTime = (1.0/FrameRate) - (EndTime - StartTime);
if (WaitTime > 0)
MappTimer(M_DEFAULT, M_TIMER_WAIT, &WaitTime);
MappTimer(M_DEFAULT, M_TIMER_READ+M_SYNCHRONOUS, &StartTime);
}
MbufImportSequence(OBJECT2_SEQUENCE_FILE, M_DEFAULT, M_NULL, M_NULL, NULL, M_NULL,
M_NULL, M_CLOSE);
MbufAlloc2d(MilSystem, DEPTH_MAP_SIZE_X, DEPTH_MAP_SIZE_Y, 16+M_UNSIGNED,
M_IMAGE+M_PROC+M_DISP, &MilDepthMap);
M3dmapControl(MilScan, M_DEFAULT, M_AUTO_SCALE_XY, M_CLIP);
M3dmapControl(MilScan, M_DEFAULT, M_FILL_MODE, M_X_THEN_Y);
M3dmapControl(MilScan, M_DEFAULT, M_FILL_SHARP_ELEVATION, M_MIN);
M3dmapControl(MilScan, M_DEFAULT, M_FILL_SHARP_ELEVATION_DEPTH, GAP_DEPTH);
M3dmapSetBox(MilScan, M_EXTRACTION_BOX, M_BOUNDING_BOX, M_ALL, M_DEFAULT, M_DEFAULT,
M_DEFAULT, M_DEFAULT, M_DEFAULT);
M3dmapExtract(MilScan, MilDepthMap, M_NULL, M_CORRECTED_DEPTH_MAP, M_DEFAULT, M_DEFAULT);
M3dmapStat(MilDepthMap, M_NULL, M_NULL, M_NULL, M_VOLUME, M_DEFAULT, M_DEFAULT, &Volume);
M3dmapStat(MilDepthMap, M_NULL, M_NULL, M_NULL, M_VOLUME, MIN_HEIGHT_THRESHOLD,
M_DEFAULT, &VolumeError);
Volume -= VolumeError;
MosPrintf(MIL_TEXT("Fully corrected 3d data of the cookie is displayed.\n\n"));
#if M_MIL_USE_WINDOWS && !M_MIL_USE_CE && !M_MIL_USE_RT
MIL_DISP_D3D_HANDLE DispHandle;
DispHandle = MdepthD3DAlloc(MilDepthMap, M_NULL,
D3D_DISPLAY_SIZE_X,
D3D_DISPLAY_SIZE_Y,
M_DEFAULT,
M_DEFAULT,
M_DEFAULT,
M_DEFAULT,
M_DEFAULT,
M_DEFAULT,
0);
if (DispHandle != NULL)
{
MdispControl(MilDisplay, M_WINDOW_SHOW, M_DISABLE );
MdispD3DShow(DispHandle);
MdispD3DPrintHelp(DispHandle);
}
else
#endif
{
MdispControl(MilDisplay, M_VIEW_MODE, M_AUTO_SCALE);
MdispSelect(MilDisplay, MilDepthMap);
}
MosPrintf(MIL_TEXT("Volume of the cookie is %4.1f cm^3.\n\n"), -Volume/1000.0);
MosPrintf(MIL_TEXT("Press <Enter> to end.\n\n"));
MosGetch();
#if M_MIL_USE_WINDOWS && !M_MIL_USE_CE && !M_MIL_USE_RT
if (DispHandle != M_NULL)
{
MdispD3DHide(DispHandle);
MdispD3DFree(DispHandle);
}
#endif
M3dmapFree(MilScan);
M3dmapFree(MilLaser);
McalFree(MilCalibration);
MbufFree(MilDepthMap);
MbufFree(MilImage);
}