#include "stdafx.h" #include "ThresProcess.h" #include "VisionRecipe.h" #include "FileRecipe.h" CThresProcess::CThresProcess(){ /* code */ for (int i = 0; i < 12; i++) { m_dots[i] = NULL; } m_eDir = DIMENSION_NONE; init(); } CThresProcess::CThresProcess(DimensionDir eDir) { /* code */ for (int i = 0; i < 12; i++) { m_dots[i] = NULL; } m_eDir = eDir; init(); } CThresProcess::~CThresProcess(){ /* code */ release(); } int CThresProcess::init(void) { /* code */ release(); for (int i = 0; i < 12; i++) { m_dots[i] = new CThresDotProcess(m_eDir, i + 1); } return 0; } void CThresProcess::release(void) { /* code */ int nCount = 12; for (int i = 0; i < nCount; i++) { CThresDotProcess *dot = m_dots[i]; if (NULL == dot) continue; delete dot; dot = NULL; m_dots[i] = NULL; } } int CThresProcess::execute(DimensionDir eDir) { /* code */ if (m_eDir != eDir) return -1; int nCount = 12; Point2I offset; for (int i = 0; i < nCount; i++) { CThresDotProcess *dot = m_dots[i]; if (NULL == dot) continue; if (1 != dot->m_nUse) continue; offset.x = i; offset.y = i; dot->Execute(m_eDir, offset); } return 0; } Json::Value CThresProcess::WriteToJson(void) { /* code */ Json::Value jsValue; jsValue["alg type"] = THRES_VISION_PROCESS; jsValue["side"] = (int)(m_eDir); for (int i = 0; i < 12; i++) { std::string name = ClsVision::FormatString("Dot%d", i); jsValue[name.c_str()] = m_dots[i]->WriteToJson(); } return jsValue; } void CThresProcess::DecodeJson(Json::Value &jsValue) { /* code */ int num = (int)jsValue.size(); if (num < 1) return; //1. Side std::string strName = "side"; if (jsValue.isMember(strName.c_str()) && jsValue[strName.c_str()].isInt()) { m_eDir = (DimensionDir)(jsValue[strName.c_str()].asInt()); } for (int i = 0; i < 12; i++) { std::string name = ClsVision::FormatString("Dot%d", i); if (jsValue.isMember(name.c_str()) && jsValue[name.c_str()].isObject()) { Json::Value jsData = jsValue[name.c_str()]; m_dots[i]->DecodeJson(jsData); } } }