📄 ltkpreprocessor.cpp
字号:
if( (errorCode = outTrace.setAllChannelValues(allChannelValuesVec)) != SUCCESS)
{
LOG(LTKLogger::LTK_LOGLEVEL_ERR)
<<"Error: LTKPreprocessor::resampleTrace"<<endl;
LTKReturnError(errorCode);
}
/*if( (errorCode = outTrace.setChannelValues(X_CHANNEL_NAME, resampledXVec)) != SUCCESS)
{
LOG(LTKLogger::LTK_LOGLEVEL_ERR)
<<"Error: LTKPreprocessor::resampleTrace"<<endl;
LTKReturnError(errorCode);
}
if( (errorCode = outTrace.setChannelValues(Y_CHANNEL_NAME, resampledYVec)) != SUCCESS)
{
LOG(LTKLogger::LTK_LOGLEVEL_ERR)
<<"Error: LTKPreprocessor::resampleTrace"<<endl;
LTKReturnError(errorCode);
}*/
}
LOG( LTKLogger::LTK_LOGLEVEL_DEBUG)<< "Exiting LTKPreprocessor::resampleTrace" <<endl;
return SUCCESS;
}
/**********************************************************************************
* AUTHOR : Mehul Patel
* DATE : 04-APR-2005
* NAME : smoothenTraceGroup
* DESCRIPTION : smoothens the given tracegroup using moving average
* ARGUMENTS : inTraceGroup - tracegroup to be smoothened
* m_filterLength - configurable parameter used for filtering
* outTraceGroup - smoothened TraceGroup
* RETURNS : SUCCESS on successful smoothening operation
* NOTES :
* CHANGE HISTROY
* Author Date Description of change
*************************************************************************************/
int LTKPreprocessor::smoothenTraceGroup(const LTKTraceGroup& inTraceGroup,
LTKTraceGroup& outTraceGroup)
{
LOG( LTKLogger::LTK_LOGLEVEL_DEBUG)<<
"Entered LTKPreprocessor::smoothenTrace" << endl;
int loopIndex; // Index used for looping
int pointIndex; // Index over all the points in the trace
int traceIndex; // Index over all the traces of a tracegroup
int numTraces = inTraceGroup.getNumTraces();
int actualIndex; //
float sumX, sumY; //partial sum
vector<LTKTrace> tempTraceVector;
for(traceIndex = 0; traceIndex < numTraces; ++traceIndex)
{
LTKTrace inTrace;
inTraceGroup.getTraceAt(traceIndex, inTrace);
int numPoints = inTrace.getNumberOfPoints(); // total number of points in the trace
floatVector newXChannel, newYChannel; // temp vector to store the channelValues of outTrace
//Retrieving the channels
floatVector xChannel, yChannel;
if( (errorCode = inTrace.getChannelValues(X_CHANNEL_NAME, xChannel))!= SUCCESS)
{
LOG(LTKLogger::LTK_LOGLEVEL_ERR)
<<"Error: LTKPreprocessor::smoothenTraceGroup"<<endl;
LTKReturnError(errorCode);
}
if( (errorCode = inTrace.getChannelValues(Y_CHANNEL_NAME, yChannel)) != SUCCESS)
{
LOG(LTKLogger::LTK_LOGLEVEL_ERR)
<<"Error: LTKPreprocessor::smoothenTraceGroup"<<endl;
LTKReturnError(errorCode);
}
//iterating through the points
for(pointIndex = 0; pointIndex < numPoints ; ++pointIndex)
{
sumX = sumY = 0;
for(loopIndex = 0; loopIndex < m_filterLength; ++loopIndex)
{
actualIndex = (pointIndex-loopIndex);
//checking for bounding conditions
if (actualIndex <0 )
{
actualIndex = 0;
}
else if (actualIndex >= numPoints )
{
actualIndex = numPoints -1;
}
//accumulating values
sumX += xChannel[actualIndex];
sumY += yChannel[actualIndex];
}
//calculating average value
sumX /= m_filterLength;
sumY /= m_filterLength;
//adding the values to the pre processed channels
newXChannel.push_back(sumX);
newYChannel.push_back(sumY);
}
/*outTrace.reassignChannelValues(X_CHANNEL_NAME, newXChannel);
outTrace.reassignChannelValues(Y_CHANNEL_NAME, newYChannel);*/
float2DVector allChannelValuesVec;
allChannelValuesVec.push_back(newXChannel);
allChannelValuesVec.push_back(newYChannel);
LTKTrace outTrace;
if( (errorCode = outTrace.setAllChannelValues(allChannelValuesVec)) != SUCCESS)
{
LOG(LTKLogger::LTK_LOGLEVEL_ERR)
<<"Error: LTKPreprocessor::removeDuplicatePoints"<<endl;
LTKReturnError(errorCode);
}
//adding the smoothed trace to the output trace group
tempTraceVector.push_back(outTrace);
} //traceIndex
outTraceGroup.setAllTraces(tempTraceVector,
inTraceGroup.getXScaleFactor(),
inTraceGroup.getYScaleFactor());
LOG( LTKLogger::LTK_LOGLEVEL_DEBUG)<< "Exiting LTKPreprocessor::smoothenTrace" <<endl;
return SUCCESS;
}
/**********************************************************************************
* AUTHOR : Balaji R.
* DATE : 23-DEC-2004
* NAME : centerTraces
* DESCRIPTION : centers the traces of a trace group to the center of its bounding box
* ARGUMENTS : inTraceGroup - trace group whose traces are to be centered
* outTraceGroup - trace group after its traces are centered
* RETURNS : SUCCESS on successful centering operation
* NOTES :
* CHANGE HISTROY
* Author Date Description of change
*************************************************************************************/
int LTKPreprocessor::centerTraces (const LTKTraceGroup& inTraceGroup,
LTKTraceGroup& outTraceGroup)
{
LOG( LTKLogger::LTK_LOGLEVEL_DEBUG)<<
"Entered LTKPreprocessor::centerTraces" <<endl;
int traceIndex; // a variable to loop over the traces of the trace group
int pointIndex; // a variable to loop over the points of a trace
int numTraces; // number of traces in the trace group
int numTracePoints; // number of points in a trace
LTKTrace trace; // a trace of the trace group
vector<LTKTrace> centeredTracesVec; // centered traces of the trace group
float xAvg,yAvg; // average x and y co-ordinate values
floatVector xVec; // x coords of a trace
floatVector yVec; // y coords of a trace
int errorCode;
vector<LTKTrace> tempTraceVector;
/* calculating the average x and y coordinate values and
using them to center the traces of the trace group */
numTraces = inTraceGroup.getNumTraces();
LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) <<
"numTraces = " << numTraces <<endl;
for(traceIndex=0; traceIndex< numTraces; traceIndex++)
{
inTraceGroup.getTraceAt(traceIndex, trace);
numTracePoints = trace.getNumberOfPoints();
LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) <<
"numTracePoints = " << numTracePoints <<endl;
if( (errorCode = trace.getChannelValues(X_CHANNEL_NAME, xVec))!= SUCCESS)
{
LOG(LTKLogger::LTK_LOGLEVEL_ERR)
<<"Error: LTKPreprocessor::centerTraces"<<endl;
LTKReturnError(errorCode);
}
if( (errorCode = trace.getChannelValues(Y_CHANNEL_NAME, yVec)) != SUCCESS)
{
LOG(LTKLogger::LTK_LOGLEVEL_ERR)
<<"Error: LTKPreprocessor::centerTraces"<<endl;
LTKReturnError(errorCode);
}
for(pointIndex=0; pointIndex< numTracePoints; pointIndex++)
{
xAvg += xVec.at(pointIndex);
yAvg += yVec.at(pointIndex);
}
xAvg /= numTracePoints;
yAvg /= numTracePoints;
LOG( LTKLogger::LTK_LOGLEVEL_DEBUG)<< "xAvg = " << xAvg <<endl;
LOG( LTKLogger::LTK_LOGLEVEL_DEBUG)<< "yAvg = " << yAvg <<endl;
for(pointIndex=0; pointIndex< numTracePoints; pointIndex++)
{
xVec.at(pointIndex) -= xAvg;
yVec.at(pointIndex) -= yAvg;
LOG( LTKLogger::LTK_LOGLEVEL_DEBUG)<< "centered point " << xVec.at(pointIndex) << yVec.at(pointIndex) <<endl;
}
if( (errorCode = trace.reassignChannelValues(X_CHANNEL_NAME,xVec)) != SUCCESS)
{
LOG(LTKLogger::LTK_LOGLEVEL_ERR)
<<"Error: LTKPreprocessor::centerTraces"<<endl;
LTKReturnError(errorCode);
}
if( (errorCode = trace.reassignChannelValues(Y_CHANNEL_NAME,yVec)) != SUCCESS)
{
LOG(LTKLogger::LTK_LOGLEVEL_ERR)
<<"Error: LTKPreprocessor::centerTraces"<<endl;
LTKReturnError(errorCode);
}
tempTraceVector.push_back(trace);
}
outTraceGroup.setAllTraces(tempTraceVector,
inTraceGroup.getXScaleFactor(),
inTraceGroup.getYScaleFactor());
LOG( LTKLogger::LTK_LOGLEVEL_DEBUG)<< "Exiting LTKPreprocessor::centerTraces" <<endl;
return SUCCESS;
}
/**********************************************************************************
* AUTHOR : Balaji R.
* DATE : 23-DEC-2004
* NAME : dehookTraces
* DESCRIPTION : dehooks the traces of the tracegroup
* ARGUMENTS :
* RETURNS : SUCCESS on successful dehooking operation
* NOTES :
* CHANGE HISTROY
* Author Date Description of change
*************************************************************************************/
int LTKPreprocessor::dehookTraces(const LTKTraceGroup& inTraceGroup,
LTKTraceGroup& outTraceGroup)
{
int traceIndex;
float numTraces;
float dPX1, dPY1;
float dPX2, dPY2;
float dPX3, dPY3;
float dPX4, dPY4;
float L0;
float angle;
int firstPoint, lastPoint;
int numDominantPoints;
vector<int> quantizedSlopes;
vector<int> dominantPoints;
vector<string> channelNames;
channelNames.push_back(X_CHANNEL_NAME);
channelNames.push_back(Y_CHANNEL_NAME);
floatVector maxValues, minValues;
float scale;
int errorCode;
numTraces = inTraceGroup.getNumTraces();
vector<LTKTrace> tempTraceVector;
LOG( LTKLogger::LTK_LOGLEVEL_DEBUG)<< "numTraces = " << numTraces <<endl;
for(traceIndex=0; traceIndex< numTraces; traceIndex++)
{
LTKTrace trace;
inTraceGroup.getTraceAt(traceIndex, trace);
if( (errorCode = LTKInkUtils::computeChannelMaxMin(trace, channelNames, maxValues, minValues)) != SUCCESS)
{
LOG(LTKLogger::LTK_LOGLEVEL_ERR)
<<"Error: LTKPreprocessor::dehookTraces"<<endl;
LTKReturnError(errorCode);
}
if( (errorCode = computeTraceLength(trace, 0, trace.getNumberOfPoints() - 1,scale)) != SUCCESS)
{
LOG(LTKLogger::LTK_LOGLEVEL_ERR)
<<"Error: LTKPreprocessor::dehookTraces"<<endl;
LTKReturnError(errorCode);
}
floatVector xVec, yVec;
if( (errorCode = trace.getChannelValues(X_CHANNEL_NAME, xVec))!= SUCCESS)
{
LOG(LTKLogger::LTK_LOGLEVEL_ERR)
<<"Error: LTKPreprocessor::dehookTraces"<<endl;
LTKReturnError(errorCode);
}
if( (errorCode = trace.getChannelValues(Y_CHANNEL_NAME, yVec)) != SUCCESS)
{
LOG(LTKLogger::LTK_LOGLEVEL_ERR)
<<"Error: LTKPreprocessor::dehookTraces"<<endl;
LTKReturnError(errorCode);
}
if( (errorCode = getQuantisedSlope(trace, quantizedSlopes)) != SUCCESS)
{
LOG(LTKLogger::LTK_LOGLEVEL_ERR)
<<"Error: LTKPreprocessor::dehookTraces"<<endl;
LTKReturnError(errorCode);
}
if( (errorCode = determineDominantPoints(quantizedSlopes, 3, dominantPoints)) != SUCCESS)
{
LOG(LTKLogger::LTK_LOGLEVEL_ERR)
<<"Error: LTKPreprocessor::dehookTraces"<<endl;
LTKReturnError(errorCode);
}
numDominantPoints = dominantPoints.size();
if(numDominantPoints > 2)
{
dPX1 = xVec[dominantPoints[0]];
dPY1 = yVec[dominantPoints[0]];
dPX2 = xVec[dominantPoints[1]];
dPY2 = yVec[dominantPoints[1]];
dPX3 = xVec[dominantPoints[1] + 1];
dPY3 = yVec[dominantPoints[1] + 1];
dPX4 = xVec[dominantPoints[1] - 1];
dPY4 = yVec[dominantPoints[1] - 1];
if( (errorCode = computeTraceLength(trace, dominantPoints[0], dominantPoints[1],L0))!= SUCCESS)
{
LOG(LTKLogger::LTK_LOGLEVEL_ERR)
<<"Error: LTKPreprocessor::resampleTraceGroup"<<endl;
LTKReturnError(errorCode);
}
angle = ( acos(((dPX1 - dPX2) * (dPX3 - dPX2) + (dPY1 - dPY2) * (dPY3 - dPY2)) /
(calculateEuclidDist(dPX2, dPX1, dPY2, dPY1) * calculateEuclidDist(dPX2, dPX3, dPY2, dPY3))) ) * 180 / 3.14;
if((L0/scale) < this->m_hookLengthThreshold1 || (((L0/scale) < this->m_hookLengthThreshold2) &&
(angle < this->m_hookAngleThreshold)))
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -