#include <mil.h>
#include <math.h>
#include "MeasOverviewExample.h"
#include "ProfileDisplay.h"
CMeasOverviewExample::CMeasOverviewExample(bool UseProfileDisplay)
: m_pProfileDisplay(NULL)
{
MappAlloc(M_DEFAULT, &m_MilApplication);
m_MilSystem = M_DEFAULT_HOST;
MdispAlloc(m_MilSystem, M_DEFAULT, MIL_TEXT("M_DEFAULT"), M_WINDOWED, &m_MilDisplay);
MgraAllocList(m_MilSystem, M_DEFAULT, &m_MilGraList);
MdispControl(m_MilDisplay, M_ASSOCIATED_GRAPHIC_LIST_ID, m_MilGraList);
if(UseProfileDisplay)
{
m_pProfileDisplay = new CProfileDisplay(m_MilSystem);
MdispControl(m_MilDisplay, M_WINDOW_INITIAL_POSITION_Y, m_pProfileDisplay->ProfileImageSizeY() + WINDOWS_OFFSET_Y);
}
}
CMeasOverviewExample::~CMeasOverviewExample()
{
if(m_pProfileDisplay)
delete m_pProfileDisplay;
MgraFree(m_MilGraList);
MdispFree(m_MilDisplay);
if (m_MilSystem != M_DEFAULT_HOST)
MsysFree(m_MilSystem);
MappFree(m_MilApplication);
}
void CMeasOverviewExample::RunMeasCase(MIL_CONST_TEXT_PTR ImageFile, MIL_INT MarkerType, const SMeasRegion& rMeasBox, SetupFunc pSetupFunc, MIL_INT MeasurementList, const SDrawList& rDrawList)
{
MdispControl(m_MilDisplay, M_UPDATE, M_DISABLE);
MgraClear(M_DEFAULT, m_MilGraList);
if (m_pProfileDisplay)
{
m_pProfileDisplay->SetUpdate(M_DISABLE);
m_pProfileDisplay->ClearAnnotations();
}
MIL_ID MilMeasMarker = MmeasAllocMarker(m_MilSystem, MarkerType, M_DEFAULT, M_NULL);
rMeasBox.SetMarkerRegion(MilMeasMarker, MarkerType);
if(pSetupFunc)
(pSetupFunc)(MilMeasMarker);
MIL_ID MilImage = MbufRestore(ImageFile, m_MilSystem, M_NULL);
MIL_INT ImageSizeX = MbufInquire(MilImage, M_SIZE_X, M_NULL);
MIL_INT ImageSizeY = MbufInquire(MilImage, M_SIZE_Y, M_NULL);
McalUniform(MilImage, 0.0, 0.0, 1.0, 1.0, 0.0, M_DEFAULT);
MdispSelect(m_MilDisplay, MilImage);
MgraControl(M_DEFAULT, M_INPUT_UNITS, M_WORLD);
if(MarkerType != M_CIRCLE)
MmeasSetMarker(MilMeasMarker, M_DRAW_PROFILE_SCALE_OFFSET, M_AUTO_SCALE_PROFILE, M_DEFAULT);
MmeasFindMarker(M_DEFAULT, MilImage, MilMeasMarker, MeasurementList);
MIL_INT ValidFlag;
MmeasGetResult(MilMeasMarker, M_VALID_FLAG + M_TYPE_MIL_INT, &ValidFlag, M_NULL);
if(ValidFlag == M_TRUE)
{
rDrawList.DrawList(MilMeasMarker, m_MilGraList);
if(m_pProfileDisplay)
m_pProfileDisplay->CreateProfile(MilImage, MilMeasMarker);
}
else
MosPrintf(MIL_TEXT("Unable to find the marker..."));
MdispControl(m_MilDisplay, M_UPDATE, M_ENABLE);
if(m_pProfileDisplay)
m_pProfileDisplay->SetUpdate(M_ENABLE);
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
MbufFree(MilImage);
MmeasFree(MilMeasMarker);
}
void CMeasOverviewExample::SetDisplayZoom(MIL_DOUBLE DisplayZoom)
{
MdispZoom(m_MilDisplay, DisplayZoom, DisplayZoom);
}