#include "stdafx.h"
|
#include "TranformCoordinate.h"
|
|
CTranformCoordinate::CTranformCoordinate()
|
{
|
/* code */
|
}
|
|
CTranformCoordinate::~CTranformCoordinate()
|
{
|
/* code */
|
}
|
|
Point2I CTranformCoordinate::Execute(DimensionDir eDir, Point2I pose) {
|
/* code */
|
Point2I ptResult = getPose(eDir, pose);
|
|
Point2I result = TranformPose(eDir, ptResult);
|
|
if (result.x < 0 || result.y < 0) {
|
Print(eDir, pose);
|
}
|
|
return result;
|
}
|
|
void CTranformCoordinate::Print(DimensionDir eDir, Point2I pose) {
|
/* code */
|
ILogger *pLogger = Log_GetDebug();
|
if (NULL == pLogger) return;
|
|
CBlSideData *pSideData = CVisionRecipe::getInstance()->getSideData(eDir);
|
if (NULL == pSideData) return;
|
|
pLogger->TraceInfo("Trace Tf %d: (%d, %d), %d", (int)eDir, pose.x, pose.y, __LINE__);
|
Point2I ptResult = getPose(eDir, pose);
|
pLogger->TraceInfo("Trace Tf %d: (%d, %d), %d", (int)eDir, ptResult.x, ptResult.y, __LINE__);
|
|
for (auto iter = pSideData->m_mapSideLineInf.begin(); iter != pSideData->m_mapSideLineInf.begin(); iter++) {
|
pLogger->TraceInfo("Trace Tf %d: %d, (%d, %d), %d",
|
(int)eDir, iter->first,
|
iter->second.nSideLine, iter->second.top, __LINE__);
|
}
|
|
ScanSetting scanSetting = CVisionRecipe::getInstance()->getScanSetting();
|
pLogger->TraceInfo("Trace Tf %d: (%d, %d, %d, %d, %d, %d, %d, %d, %d), %d",
|
(int)eDir,
|
scanSetting.lengthSize, scanSetting.shortSize, scanSetting.nStdIndex,
|
scanSetting.nIndex0, scanSetting.nIndex1, scanSetting.nIndex2, scanSetting.nIndex3,
|
scanSetting.nLengthScan, scanSetting.nShortScan,
|
__LINE__);
|
}
|
|
Point2I CTranformCoordinate::tfPose(DimensionDir eDir, Point2I pose) {
|
/* code */
|
return TranformPose(eDir, pose);
|
}
|
|
Point2I CTranformCoordinate::TranformPose(DimensionDir eDir, Point2I pose) {
|
/* code */
|
Point2I result = pose;
|
switch (eDir)
|
{
|
case GLOBAL_DEFINE::DIMENSION_A:
|
result = TransformPoseTopA(pose);
|
break;
|
|
case GLOBAL_DEFINE::DIMENSION_B:
|
result = TransformPoseTopB(pose);
|
break;
|
|
case GLOBAL_DEFINE::DIMENSION_C:
|
result = TransformPoseTopC(pose);
|
break;
|
|
case GLOBAL_DEFINE::DIMENSION_D:
|
result = TransformPoseTopD(pose);
|
break;
|
|
case GLOBAL_DEFINE::DIMENSION_A_DN:
|
result = TransformPoseBotA(pose);
|
break;
|
|
case GLOBAL_DEFINE::DIMENSION_B_DN:
|
result = TransformPoseBotB(pose);
|
break;
|
|
case GLOBAL_DEFINE::DIMENSION_C_DN:
|
result = TransformPoseBotC(pose);
|
break;
|
|
case GLOBAL_DEFINE::DIMENSION_D_DN:
|
result = TransformPoseBotD(pose);
|
break;
|
|
default:
|
break;
|
}
|
|
return result;
|
}
|
|
Point2I CTranformCoordinate::TransformPoseTopA(Point2I pose) {
|
/* code */
|
ScanSetting scanSetting = CVisionRecipe::getInstance()->getScanSetting();
|
int idx0 = scanSetting.nIndex0;
|
if (1 == scanSetting.nLengthScan) idx0 = scanSetting.nIndex1;
|
|
int idx1 = scanSetting.nStdIndex;
|
|
return TransformResult(pose, true, idx0, idx1, scanSetting);
|
}
|
|
Point2I CTranformCoordinate::TransformPoseTopB(Point2I pose) {
|
/* code */
|
ScanSetting scanSetting = CVisionRecipe::getInstance()->getScanSetting();
|
int idx0 = scanSetting.nIndex2;
|
if (1 == scanSetting.nShortScan) idx0 = scanSetting.nIndex1;
|
|
int idx1 = scanSetting.nStdIndex;
|
|
return TransformResult(pose, false, idx0, idx1, scanSetting);
|
}
|
|
Point2I CTranformCoordinate::TransformPoseTopC(Point2I pose) {
|
/* code */
|
ScanSetting scanSetting = CVisionRecipe::getInstance()->getScanSetting();
|
int idx0 = scanSetting.nIndex3;
|
if (1 == scanSetting.nLengthScan) idx0 = scanSetting.nIndex2;
|
|
int idx1 = scanSetting.nStdIndex;
|
|
return TransformResult(pose, true, idx0, idx1, scanSetting);
|
}
|
|
Point2I CTranformCoordinate::TransformPoseTopD(Point2I pose) {
|
/* code */
|
ScanSetting scanSetting = CVisionRecipe::getInstance()->getScanSetting();
|
int idx0 = scanSetting.nIndex3;
|
if (1 == scanSetting.nShortScan) idx0 = scanSetting.nIndex0;
|
|
int idx1 = scanSetting.nStdIndex;
|
|
return TransformResult(pose, false, idx0, idx1, scanSetting);
|
}
|
|
Point2I CTranformCoordinate::TransformPoseBotA(Point2I pose) {
|
/* code */
|
ScanSetting scanSetting = CVisionRecipe::getInstance()->getScanSetting();
|
int idx0 = scanSetting.nIndex0;
|
if (1 == scanSetting.nLengthScan) idx0 = scanSetting.nIndex1;
|
|
int idx1 = scanSetting.nStdIndex;
|
|
return TransformResult(pose, true, idx0, idx1, scanSetting);
|
}
|
|
Point2I CTranformCoordinate::TransformPoseBotB(Point2I pose) {
|
/* code */
|
ScanSetting scanSetting = CVisionRecipe::getInstance()->getScanSetting();
|
int idx0 = scanSetting.nIndex2;
|
if (1 == scanSetting.nShortScan) idx0 = scanSetting.nIndex1;
|
|
int idx1 = scanSetting.nStdIndex;
|
|
return TransformResult(pose, false, idx0, idx1, scanSetting);
|
}
|
|
Point2I CTranformCoordinate::TransformPoseBotC(Point2I pose) {
|
/* code */
|
ScanSetting scanSetting = CVisionRecipe::getInstance()->getScanSetting();
|
int idx0 = scanSetting.nIndex3;
|
if (1 == scanSetting.nLengthScan) idx0 = scanSetting.nIndex2;
|
|
int idx1 = scanSetting.nStdIndex;
|
|
return TransformResult(pose, true, idx0, idx1, scanSetting);
|
}
|
|
Point2I CTranformCoordinate::TransformPoseBotD(Point2I pose) {
|
/* code */
|
ScanSetting scanSetting = CVisionRecipe::getInstance()->getScanSetting();
|
int idx0 = scanSetting.nIndex3;
|
if (1 == scanSetting.nShortScan) idx0 = scanSetting.nIndex0;
|
|
int idx1 = scanSetting.nStdIndex;
|
|
return TransformResult(pose, false, idx0, idx1, scanSetting);
|
}
|
|
Point2I CTranformCoordinate::TransformResult(Point2I pose, bool isScanLength, int idx0, int idx1, ScanSetting scanSetting) {
|
/* code */
|
Point2I result = pose;
|
int id0 = getIndex(idx0, scanSetting);
|
int id1 = getIndex(idx1, scanSetting);
|
if (-1 == id0 || -1 == id1) return result;
|
|
Point2I pt = pose;
|
if (isScanLength) {
|
pt.x = pose.y;
|
pt.y = pose.x;
|
}
|
|
switch (id0){
|
case 0: {
|
if (0 == id1) {
|
result = pt;
|
}
|
else if (1 == id1) {
|
result.x = scanSetting.lengthSize - pt.x;
|
result.y = pt.y;
|
}
|
else if (2 == id1) {
|
result.x = scanSetting.lengthSize - pt.x;
|
result.y = scanSetting.shortSize - pt.y;
|
}
|
else if (3 == id1) {
|
result.x = pt.x;
|
result.y = scanSetting.shortSize - pt.y;
|
}
|
break;
|
}
|
|
case 1: {
|
if (0 == id1) {
|
result.x = scanSetting.lengthSize - pt.x;
|
result.y = pt.y;
|
}
|
else if (1 == id1) {
|
result = pt;
|
}
|
else if (2 == id1) {
|
result.x = pt.x;
|
result.y = scanSetting.shortSize - pt.y;
|
}
|
else if (3 == id1) {
|
result.x = scanSetting.lengthSize - pt.x;
|
result.y = scanSetting.shortSize - pt.y;
|
}
|
break;
|
}
|
|
case 2: {
|
if (0 == id1) {
|
result.x = scanSetting.lengthSize - pt.x;
|
result.y = scanSetting.shortSize - pt.y;
|
}
|
else if (1 == id1) {
|
result.x = pt.x;
|
result.y = scanSetting.shortSize - pt.y;
|
}
|
else if (2 == id1) {
|
result = pt;
|
}
|
else if (3 == id1) {
|
result.x = scanSetting.lengthSize - pt.x;
|
result.y = pt.y;
|
}
|
break;
|
}
|
|
case 3: {
|
if (0 == id1) {
|
result.x = pt.x;
|
result.y = scanSetting.shortSize - pt.y;
|
}
|
else if (1 == id1) {
|
result.x = scanSetting.lengthSize - pt.x;
|
result.y = scanSetting.shortSize - pt.y;
|
}
|
else if (2 == id1) {
|
result.x = scanSetting.lengthSize - pt.x;
|
result.y = pt.y;
|
}
|
else if (3 == id1) {
|
result = pt;
|
}
|
break;
|
}
|
|
default:
|
break;
|
}
|
|
return result;
|
}
|
|
int CTranformCoordinate::getIndex(int idx, ScanSetting scanSetting) {
|
/* code */
|
int id = -1;
|
if (idx == scanSetting.nIndex0) {
|
id = 0;
|
}
|
else if (idx == scanSetting.nIndex1) {
|
id = 1;
|
}
|
else if (idx == scanSetting.nIndex2) {
|
id = 2;
|
}
|
else if (idx == scanSetting.nIndex3) {
|
id = 3;
|
}
|
|
return id;
|
}
|
|
Point2I CTranformCoordinate::getPose(DimensionDir eDir, Point2I pose) {
|
/* code */
|
Point2I result = pose;
|
CBlSideData *pSideData = CVisionRecipe::getInstance()->getSideData(eDir);
|
|
int nCount = (int)(pSideData->m_mapSideLineInf.size());
|
if (nCount < 1) return result;
|
|
SideLineInf inf;
|
bool isFind = false;
|
int minDist = MAXINT;
|
int dist = 0;
|
for (auto iter = pSideData->m_mapSideLineInf.begin(); iter != pSideData->m_mapSideLineInf.end(); iter++) {
|
if (pose.y < iter->second.top) continue;
|
|
dist = abs(pose.y - iter->second.top);
|
if (dist > minDist) continue;
|
|
inf = iter->second;
|
isFind = true;
|
minDist = dist;
|
}
|
|
if (!isFind) {
|
for (auto iter = pSideData->m_mapSideLineInf.begin(); iter != pSideData->m_mapSideLineInf.end(); iter++) {
|
dist = abs(pose.y - iter->second.top);
|
if (dist > minDist) continue;
|
|
inf = iter->second;
|
isFind = true;
|
minDist = dist;
|
}
|
}
|
|
if (!isFind) return result;
|
|
result.x = (int)(pSideData->m_dPixelSizeX * (pose.x - inf.nSideLine));
|
result.y = (int)(pSideData->m_dPixelSizeY * (pose.y - pSideData->m_nStartLine));
|
|
ScanSetting scanSetting = CVisionRecipe::getInstance()->getScanSetting();
|
if (result.y > scanSetting.lengthSize) {
|
result.y = scanSetting.lengthSize - (int)(pSideData->m_dPixelSizeY * abs(pSideData->m_nEndLine - pose.y));
|
}
|
|
return result;
|
}
|