#include "StdAfx.h"
|
#include "RecipeTriangle.h"
|
#include "CHCommonClasses/MacroFile.h"
|
|
CRecipeTriangle::CRecipeTriangle(void)
|
{
|
Reset();
|
}
|
|
CRecipeTriangle::CRecipeTriangle(const CString& strFilename)
|
{
|
ReadRecipe(strFilename);
|
}
|
|
CRecipeTriangle::~CRecipeTriangle(void)
|
{
|
Reset();
|
}
|
|
void CRecipeTriangle::DelRecipeModel(UINT nIndex)
|
{
|
if (nIndex>=m_vectorRecipeModel.size()) return;
|
|
// delete recipe triangle
|
if (nIndex < m_vectorRecipeModel.size())
|
{
|
UINT nSize = (UINT)m_vectorRecipeModel.size();
|
for (UINT i=nIndex; i<m_vectorRecipeModel.size()-1; i++)
|
{
|
m_vectorRecipeModel[i] = m_vectorRecipeModel[i+1];
|
}
|
m_vectorRecipeModel.resize(nSize-1);
|
}
|
}
|
|
void CRecipeTriangle::DelRecipeMarker(UINT nIndex)
|
{
|
if (nIndex>=m_vectorRecipeMarker.size()) return;
|
|
// delete recipe triangle
|
if (nIndex < m_vectorRecipeMarker.size())
|
{
|
UINT nSize = (UINT)m_vectorRecipeMarker.size();
|
for (UINT i=nIndex; i<m_vectorRecipeMarker.size()-1; i++)
|
{
|
m_vectorRecipeMarker[i] = m_vectorRecipeMarker[i+1];
|
}
|
m_vectorRecipeMarker.resize(nSize-1);
|
}
|
}
|
|
void CRecipeTriangle::DelRecipeFormula(UINT nIndex)
|
{
|
if (nIndex>=m_vectorRecipeFormula.size()) return;
|
|
// delete recipe triangle
|
if (nIndex < m_vectorRecipeFormula.size())
|
{
|
UINT nSize = (UINT)m_vectorRecipeFormula.size();
|
for (UINT i=nIndex; i<m_vectorRecipeFormula.size()-1; i++)
|
{
|
m_vectorRecipeFormula[i] = m_vectorRecipeFormula[i+1];
|
}
|
m_vectorRecipeFormula.resize(nSize-1);
|
}
|
}
|
|
BOOL CRecipeTriangle::ReadRecipe(const CString& strFilename)
|
{
|
Reset();
|
|
CMacroFile macroFile;
|
if (!macroFile.Read(strFilename))
|
{
|
return FALSE;
|
}
|
|
UINT nModelCount = 0;
|
macroFile.GetItem(_T("MODEL_COUNT"), nModelCount);
|
|
UINT nMarkerCount = 0;
|
macroFile.GetItem(_T("MARKER_COUNT"), nMarkerCount);
|
|
UINT nFormulaCount = 0;
|
macroFile.GetItem(_T("FORMULA_COUNT"), nFormulaCount);
|
|
CString strItem = _T("");
|
|
CRecipeModel recipeModel;
|
for (UINT nIndex=0; nIndex<nModelCount; nIndex++)
|
{
|
recipeModel.Reset();
|
|
strItem.Format(_T("MODEL_TYPE_BAND_%02d"), nIndex);
|
macroFile.GetItem(strItem, recipeModel.m_nTypeBand, 3);
|
strItem.Format(_T("MODEL_TYPE_DATA_%02d"), nIndex);
|
macroFile.GetItem(strItem, recipeModel.m_nTypeData, ModelData_Intensity);
|
strItem.Format(_T("MODEL_TYPE_METHOD_%02d"), nIndex);
|
macroFile.GetItem(strItem, recipeModel.m_nTypeMethod, ModelMethod_Full);
|
|
strItem.Format(_T("MODEL_SCORE_THRES_%02d"), nIndex);
|
macroFile.GetItem(strItem, recipeModel.m_dScoreThres, 0.8);
|
strItem.Format(_T("MODEL_SOCRE_STOP_%02d"), nIndex);
|
macroFile.GetItem(strItem, recipeModel.m_dScoreStop, 0.95);
|
|
strItem.Format(_T("MODEL_LEVEL_FIRST_%02d"), nIndex);
|
macroFile.GetItem(strItem, recipeModel.m_nLevelFirst, 4);
|
strItem.Format(_T("MODEL_LEVEL_SECOND_%02d"), nIndex);
|
macroFile.GetItem(strItem, recipeModel.m_nLevelLast, 1);
|
strItem.Format(_T("MODEL_LEVEL_RANGE_%02d"), nIndex);
|
macroFile.GetItem(strItem, recipeModel.m_nLevelRange, 10);
|
|
m_vectorRecipeModel.push_back(recipeModel);
|
}
|
|
CRecipeMarker recipeMarker;
|
for (UINT nIndex=0; nIndex<nMarkerCount; nIndex++)
|
{
|
recipeMarker.Reset();
|
|
strItem.Format(_T("MARKER_TYPE_BAND_%02d"), nIndex);
|
macroFile.GetItem(strItem, recipeMarker.m_nTypeBand, 3);
|
strItem.Format(_T("MARKER_TYPE_SUBPIXEL_%02d"), nIndex);
|
macroFile.GetItem(strItem, recipeMarker.m_nTypeSubPixel, SubPixel_Quadratic);
|
strItem.Format(_T("MARKER_TYPE_PREPROCESS_%02d"), nIndex);
|
macroFile.GetItem(strItem, recipeMarker.m_nTypePreProcess, PreProc_None);
|
strItem.Format(_T("MARKER_MEASURE_TYPE_%02d"), nIndex);
|
macroFile.GetItem(strItem, recipeMarker.m_nMeasureType, Measure_Line);
|
|
strItem.Format(_T("MARKER_EDGE_LEFT_%02d"), nIndex);
|
macroFile.GetItem(strItem, recipeMarker.m_nEdgeLeft, EdgeSignal_Positive);
|
strItem.Format(_T("MARKER_EDGE_RIGHT_%02d"), nIndex);
|
macroFile.GetItem(strItem, recipeMarker.m_nEdgeRight, EdgeSignal_Negative);
|
strItem.Format(_T("MARKER_EDGE_KERNEL_SIZE_%02d"), nIndex);
|
macroFile.GetItem(strItem, recipeMarker.m_nEdgeKernelSize, 4);
|
strItem.Format(_T("MARKER_EDGE_KERNEL_SIGMA_%02d"), nIndex);
|
macroFile.GetItem(strItem, recipeMarker.m_dEdgeKernelSigma, 1.0);
|
strItem.Format(_T("MARKER_EDGE_ANGLE_%02d"), nIndex);
|
macroFile.GetItem(strItem, recipeMarker.m_dEdgeAngle, 0.0);
|
strItem.Format(_T("MARKER_EDGE_THRESHOLD_%02d"), nIndex);
|
macroFile.GetItem(strItem, recipeMarker.m_dEdgeThreshold, 5.0);
|
strItem.Format(_T("MARKER_EDGE_POSI_THRES_%02d"), nIndex);
|
macroFile.GetItem(strItem, recipeMarker.m_dEdgePosiThres, 5.0);
|
strItem.Format(_T("MARKER_EDGE_NEGA_THRES_%02d"), nIndex);
|
macroFile.GetItem(strItem, recipeMarker.m_dEdgeNegaThres, -5.0);
|
strItem.Format(_T("MARKER_EDGE_DIRECTION_%02d"), nIndex);
|
macroFile.GetItem(strItem, recipeMarker.m_nEdgeDirection, EdgeDirection_Vert);
|
strItem.Format(_T("MARKER_EDGE_SEARCH_TYPE_%02d"), nIndex);
|
macroFile.GetItem(strItem, recipeMarker.m_nEdgeSearchType, EdgeSearch_MinMax);
|
|
strItem.Format(_T("MARKER_ITERATION_%02d"), nIndex);
|
macroFile.GetItem(strItem, recipeMarker.m_nIteration, 0);
|
|
strItem.Format(_T("MARKER_LENGTH_%02d"), nIndex);
|
macroFile.GetItem(strItem, recipeMarker.m_dLength, 20.0);
|
strItem.Format(_T("MARKER_LENGTH_VARIATION_%02d"), nIndex);
|
macroFile.GetItem(strItem, recipeMarker.m_dLengthVariation, 5.0);
|
|
strItem.Format(_T("MARKER_CIRCLE_THRESHOLD_%02d"), nIndex);
|
macroFile.GetItem(strItem, recipeMarker.m_nCircleThreshold, 20);
|
strItem.Format(_T("MARKER_CIRCLE_BLOB_MARGIN_%02d"), nIndex);
|
macroFile.GetItem(strItem, recipeMarker.m_nCircleBlobMargin, 3);
|
|
strItem.Format(_T("MARKER_ROI_LEFT_%02d"), nIndex);
|
macroFile.GetItem(strItem, recipeMarker.m_nROILeft, -1);
|
strItem.Format(_T("MARKER_ROI_TOP_%02d"), nIndex);
|
macroFile.GetItem(strItem, recipeMarker.m_nROITop, -1);
|
strItem.Format(_T("MARKER_ROI_WIDTH_%02d"), nIndex);
|
macroFile.GetItem(strItem, recipeMarker.m_nROIWidth, -1);
|
strItem.Format(_T("MARKER_ROI_HEIGHT_%02d"), nIndex);
|
macroFile.GetItem(strItem, recipeMarker.m_nROIHeight, -1);
|
|
m_vectorRecipeMarker.push_back(recipeMarker);
|
}
|
|
CRecipeFormula recipeFormula;
|
for (UINT i=0; i<nFormulaCount; i++)
|
{
|
recipeFormula.Reset();
|
|
strItem.Format(_T("FORMULA_RESULT_NAME_%02d"), i);
|
macroFile.GetItem(strItem, recipeFormula.m_strResultName, _T(""));
|
strItem.Format(_T("FORMULA_FORMULATION_%02d"), i);
|
macroFile.GetItem(strItem, recipeFormula.m_strFormulation, _T(""));
|
|
//if (!CRecipeFormula::GetRecipeFormula(recipeFormula.m_strFormulation, recipeFormula)) continue;
|
|
m_vectorRecipeFormula.push_back(recipeFormula);
|
}
|
|
macroFile.Clear();
|
|
return TRUE;
|
}
|
|
BOOL CRecipeTriangle::WriteRecipe(const CString& strFilename)
|
{
|
CMacroFile macroFile;
|
|
UINT nModelCount = (UINT)m_vectorRecipeModel.size();
|
macroFile.SetItem(_T("MODEL_COUNT"), nModelCount);
|
|
UINT nMarkerCount = (UINT)m_vectorRecipeMarker.size();
|
macroFile.SetItem(_T("MARKER_COUNT"), nMarkerCount);
|
|
UINT nFormulaCount = (UINT)m_vectorRecipeFormula.size();
|
macroFile.SetItem(_T("FORMULA_COUNT"), nFormulaCount);
|
|
CString strItem = _T("");
|
int nIndex = 0;
|
for (VectorRecipeModelIt it=m_vectorRecipeModel.begin(); it!=m_vectorRecipeModel.end(); it++)
|
{
|
strItem.Format(_T("MODEL_TYPE_BAND_%02d"), nIndex);
|
macroFile.SetItem(strItem, it->m_nTypeBand);
|
strItem.Format(_T("MODEL_TYPE_DATA_%02d"), nIndex);
|
macroFile.SetItem(strItem, it->m_nTypeData);
|
strItem.Format(_T("MODEL_TYPE_METHOD_%02d"), nIndex);
|
macroFile.SetItem(strItem, it->m_nTypeMethod);
|
|
strItem.Format(_T("MODEL_SCORE_THRES_%02d"), nIndex);
|
macroFile.SetItem(strItem, it->m_dScoreThres);
|
strItem.Format(_T("MODEL_SOCRE_STOP_%02d"), nIndex);
|
macroFile.SetItem(strItem, it->m_dScoreStop);
|
|
strItem.Format(_T("MODEL_LEVEL_FIRST_%02d"), nIndex);
|
macroFile.SetItem(strItem, it->m_nLevelFirst);
|
strItem.Format(_T("MODEL_LEVEL_SECOND_%02d"), nIndex);
|
macroFile.SetItem(strItem, it->m_nLevelLast);
|
strItem.Format(_T("MODEL_LEVEL_RANGE_%02d"), nIndex);
|
macroFile.SetItem(strItem, it->m_nLevelRange);
|
|
nIndex++;
|
}
|
|
nIndex = 0;
|
for (VectorRecipeMarkerIt it=m_vectorRecipeMarker.begin(); it!=m_vectorRecipeMarker.end(); it++)
|
{
|
strItem.Format(_T("MARKER_TYPE_BAND_%02d"), nIndex);
|
macroFile.SetItem(strItem, it->m_nTypeBand);
|
strItem.Format(_T("MARKER_TYPE_SUBPIXEL_%02d"), nIndex);
|
macroFile.SetItem(strItem, it->m_nTypeSubPixel);
|
strItem.Format(_T("MARKER_TYPE_PREPROCESS_%02d"), nIndex);
|
macroFile.SetItem(strItem, it->m_nTypePreProcess);
|
strItem.Format(_T("MARKER_MEASURE_TYPE_%02d"), nIndex);
|
macroFile.SetItem(strItem, it->m_nMeasureType);
|
|
strItem.Format(_T("MARKER_EDGE_LEFT_%02d"), nIndex);
|
macroFile.SetItem(strItem, it->m_nEdgeLeft);
|
strItem.Format(_T("MARKER_EDGE_RIGHT_%02d"), nIndex);
|
macroFile.SetItem(strItem, it->m_nEdgeRight);
|
strItem.Format(_T("MARKER_EDGE_KERNEL_SIZE_%02d"), nIndex);
|
macroFile.SetItem(strItem, it->m_nEdgeKernelSize);
|
strItem.Format(_T("MARKER_EDGE_KERNEL_SIGMA_%02d"), nIndex);
|
macroFile.SetItem(strItem, it->m_dEdgeKernelSigma);
|
strItem.Format(_T("MARKER_EDGE_ANGLE_%02d"), nIndex);
|
macroFile.SetItem(strItem, it->m_dEdgeAngle);
|
strItem.Format(_T("MARKER_EDGE_THRESHOLD_%02d"), nIndex);
|
macroFile.SetItem(strItem, it->m_dEdgeThreshold);
|
strItem.Format(_T("MARKER_EDGE_POSI_THRES_%02d"), nIndex);
|
macroFile.SetItem(strItem, it->m_dEdgePosiThres);
|
strItem.Format(_T("MARKER_EDGE_NEGA_THRES_%02d"), nIndex);
|
macroFile.SetItem(strItem, it->m_dEdgeNegaThres);
|
strItem.Format(_T("MARKER_EDGE_DIRECTION_%02d"), nIndex);
|
macroFile.SetItem(strItem, it->m_nEdgeDirection);
|
strItem.Format(_T("MARKER_EDGE_SEARCH_TYPE_%02d"), nIndex);
|
macroFile.SetItem(strItem, it->m_nEdgeSearchType);
|
|
strItem.Format(_T("MARKER_ITERATION_%02d"), nIndex);
|
macroFile.SetItem(strItem, it->m_nIteration);
|
|
strItem.Format(_T("MARKER_LENGTH_%02d"), nIndex);
|
macroFile.SetItem(strItem, it->m_dLength);
|
strItem.Format(_T("MARKER_LENGTH_VARIATION_%02d"), nIndex);
|
macroFile.SetItem(strItem, it->m_dLengthVariation);
|
|
strItem.Format(_T("MARKER_CIRCLE_THRESHOLD_%02d"), nIndex);
|
macroFile.SetItem(strItem, it->m_nCircleThreshold);
|
strItem.Format(_T("MARKER_CIRCLE_BLOB_MARGIN_%02d"), nIndex);
|
macroFile.SetItem(strItem, it->m_nCircleBlobMargin);
|
|
strItem.Format(_T("MARKER_ROI_LEFT_%02d"), nIndex);
|
macroFile.SetItem(strItem, it->m_nROILeft);
|
strItem.Format(_T("MARKER_ROI_TOP_%02d"), nIndex);
|
macroFile.SetItem(strItem, it->m_nROITop);
|
strItem.Format(_T("MARKER_ROI_WIDTH_%02d"), nIndex);
|
macroFile.SetItem(strItem, it->m_nROIWidth);
|
strItem.Format(_T("MARKER_ROI_HEIGHT_%02d"), nIndex);
|
macroFile.SetItem(strItem, it->m_nROIHeight);
|
|
nIndex++;
|
}
|
|
nIndex = 0;
|
for (VectorRecipeFormulaIt it=m_vectorRecipeFormula.begin(); it!=m_vectorRecipeFormula.end(); it++)
|
{
|
strItem.Format(_T("FORMULA_RESULT_NAME_%02d"), nIndex);
|
macroFile.SetItem(strItem, it->m_strResultName);
|
strItem.Format(_T("FORMULA_FORMULATION_%02d"), nIndex);
|
macroFile.SetItem(strItem, it->m_strFormulation);
|
|
nIndex++;
|
}
|
|
return macroFile.Write(strFilename);
|
}
|
|
CResultTriangle::CResultTriangle(void)
|
{
|
Reset();
|
}
|
|
CResultTriangle::~CResultTriangle(void)
|
{
|
Reset();
|
}
|