📄 ltkinkfilereader.cpp
字号:
vector<LTKChannel> channels; // channels of a trace
LTKTraceFormat traceFormat; // format of the trace
// reading the ink file
string keyWord; // a key word of the unipen format
while(infile)
{
keyWord = "";
infile >> keyWord;
if(keyWord == ".COORD")
{
coordFlag = true;
getline(infile, channelNames);
LTKStringUtil::tokenizeString(channelNames, " \t", channelNamesVector);
for(channelIndex = 0; channelIndex < channelNamesVector.size(); ++channelIndex)
{
if(channelNamesVector[channelIndex] == "T")
{
LTKChannel channel(channelNamesVector[channelIndex], DT_LONG, true);
channels.push_back(channel);
}
else
{
LTKChannel channel(channelNamesVector[channelIndex], DT_FLOAT, true);
channels.push_back(channel);
}
}
traceFormat.setChannelFormat(channels);
}
else if(keyWord == ".X_POINTS_PER_INCH")
{
infile >> xDpi;
captureDevice.setXDPI(xDpi);
}
else if(keyWord == ".Y_POINTS_PER_INCH")
{
infile >> yDpi;
captureDevice.setYDPI(yDpi);
}
else if(keyWord == ".H_LINE")
{
infile >> bboxBottom >> bboxTop;
screenContext.setBboxBottom(bboxBottom);
screenContext.setBboxTop(bboxTop);
}
else if(keyWord == ".V_LINE")
{
infile >> bboxLeft >> bboxRight;
screenContext.setBboxLeft(bboxLeft);
screenContext.setBboxRight(bboxRight);
}
else if(keyWord==".SEGMENT")
{
string strHierarchyLevel; //stores the hierarchy level (ex. CHARACTER or WORD)
string strStrokeIndices; //comma separated stroke indices
string strQuality; //annotated quality of the trace/trace group
string strComments; //comments about the ink
infile >> strHierarchyLevel;
if(strHierarchyLevel==hierarchyLevel) //if the encountered hierarchy level is the required
{
string checkString;
getline(infile,checkString,'\n');
if(checkString.empty())
{
LOG( LTKLogger::LTK_LOGLEVEL_ERR) <<
"Annotation not found at the specified hierarchy level:" <<
hierarchyLevel << " in "+inkFile << endl;
//return FAILURE;
continue;
}
vector<string> tokens;
LTKStringUtil::tokenizeString(checkString," ", tokens);
if(tokens.size()>=3)
{
strStrokeIndices=tokens[0];
strQuality=tokens[1];
for(int i=2;i<tokens.size();++i)
{
strComments=strComments+tokens[i]+" ";
}
strComments=strComments.substr(0,strComments.length()-1); //removing the last space added
}
else
{
LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) <<
"Invalid annotation format at the specified hierarchy level:" <<
hierarchyLevel << " in " << inkFile << endl;
//return FAILURE;
continue;
}
strComments=strComments.substr(1,strComments.length()-2); //to remove the leading space and double quoutes
bool isRequiredQuality=false;
if(quality=="ALL") //if no condition on quality
{
isRequiredQuality=true;
}
else
{
for(vector<string>::iterator iter=qualityLevels.begin();iter!=qualityLevels.end();++iter)
{
if((*iter)==strQuality)
{
isRequiredQuality=true;
break;
}
}
}
if(isRequiredQuality)
{
//if the trace/trace group is of required quality stores the stroke
//indices and comments in the output map
traceIndicesCommentsMap.insert(make_pair(strStrokeIndices,strComments));
}
}
else //if not the required hierarchy level, just get the remaining line
{
if(keyWord == ".VERSION")
verFlag = true;
else if ((keyWord == ".HIERARCHY"))
hlevelFlag = true;
getline(infile,remainingLine);
}
}
else if(keyWord == ".PEN_DOWN")
{
if (pendownFlag)
{
LOG(LTKLogger::LTK_LOGLEVEL_ERR)
<<"Error : "<< EINKFILE_CORRUPTED <<":"<< getErrorMessage(EINKFILE_CORRUPTED)
<<"LTKInkFileReader::readUnipenInkFileWithAnnotation()" <<endl;
LTKReturnError(EINKFILE_CORRUPTED);
}
pendownFlag = true;
LTKTrace trace(traceFormat);
while(infile)
{
infile >> keyWord;
if(keyWord == ".PEN_UP")
{
if (!pendownFlag)
{
LOG(LTKLogger::LTK_LOGLEVEL_ERR)
<<"Error : "<< EINKFILE_CORRUPTED <<":"<< getErrorMessage(EINKFILE_CORRUPTED)
<<"LTKInkFileReader::readUnipenInkFileWithAnnotation()" <<endl;
LTKReturnError(EINKFILE_CORRUPTED);
}
pendownFlag = false;
if(trace.getNumberOfPoints() == 0)
{
LOG(LTKLogger::LTK_LOGLEVEL_ERR)
<<"Error: LTKInkFileReader::readUnipenInkFileWithAnnotation()"<<endl;
LTKReturnError(EEMPTY_TRACE);
}
traceGroup.addTrace(trace);
break;
}
else
{
// BUGFIX : if no attributes in input ink file, throw error and stop
if(channelNamesVector.empty())
{
//if(!verFlag)
//{
//}
// cout<<" keyword = "<<keyWord<<endl;
LOG(LTKLogger::LTK_LOGLEVEL_ERR)
<<"Error : "<< EINKFILE_CORRUPTED <<":"<< getErrorMessage(EINKFILE_CORRUPTED)
<<"LTKInkFileReader::readUnipenInkFileWithAnnotation()" <<endl;
LTKReturnError(EINKFILE_CORRUPTED);
}
if(channelNamesVector[0] == "T")
{
longChannelValue = atol(keyWord.c_str());
point.push_back(longChannelValue);
}
else
{
floatChannelValue = atof(keyWord.c_str());
point.push_back(floatChannelValue);
}
getline(infile,remainingLine);
coordVals.clear();
LTKStringUtil::tokenizeString(remainingLine,string(" "), coordVals);
if (coordVals.size() != (channelNamesVector.size() -1))
{
int index;
for (index = 0 ; index < channelNamesVector.size(); ++index)
{
cout << "coord name at index "<<channelNamesVector.at(index) <<endl;
}
cout<<"first coord val "<<keyWord;
for (index = 0 ; index < coordVals.size(); ++index)
{
cout << "coord val at index "<<coordVals.at(index) <<endl;
}
LOG(LTKLogger::LTK_LOGLEVEL_ERR)
<<"Error : "<< EINKFILE_CORRUPTED <<":"<< getErrorMessage(EINKFILE_CORRUPTED)
<<"LTKInkFileReader::readUnipenInkFileWithAnnotation()" <<endl;
LTKReturnError(EINKFILE_CORRUPTED);
}
for(channelIndex = 1; channelIndex < channelNamesVector.size(); ++channelIndex)
{
if(channelNamesVector[channelIndex] == "T")
{
longChannelValue = atol((coordVals.at(channelIndex -1 )).c_str());
point.push_back(longChannelValue);
}
else
{
floatChannelValue = atof((coordVals.at(channelIndex -1 )).c_str());
point.push_back(floatChannelValue);
}
}
trace.addPoint(point);
point.clear();
}
}
}
else if(keyWord == ".PEN_UP")
{
if (!pendownFlag)
{
LOG(LTKLogger::LTK_LOGLEVEL_ERR)
<<"Error : "<< EINKFILE_CORRUPTED <<":"<< getErrorMessage(EINKFILE_CORRUPTED)
<<"LTKInkFileReader::readUnipenInkFileWithAnnotation()" <<endl;
LTKReturnError(EINKFILE_CORRUPTED);
}
}
else
{
if(keyWord == ".VERSION")
verFlag = true;
else if ((keyWord == ".HIERARCHY"))
hlevelFlag = true;
getline(infile, keyWord);
}
}
int numberOfTraces = traceGroup.getNumTraces();
if(numberOfTraces == 0)
{
LOG(LTKLogger::LTK_LOGLEVEL_ERR)
<<"Error : LTKInkFileReader::readUnipenInkFileWithAnnotation()" <<endl;
LTKReturnError(EEMPTY_TRACE_GROUP);
}
LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) <<
" Exiting: LTKInkFileReader::readUnipenInkFileWithAnnotation()" << endl;
return SUCCESS;
}
/**********************************************************************************
* AUTHOR : Balaji R.
* DATE : 23-DEC-2004
* NAME : ~LTKInkFileReader
* DESCRIPTION : destructor
* ARGUMENTS :
* RETURNS :
* NOTES :
* CHANGE HISTROY
* Author Date Description of change
*************************************************************************************/
LTKInkFileReader::~LTKInkFileReader(){}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -