📄 ltkinkfilereader.cpp
字号:
/*****************************************************************************************
* Copyright (c) 2007 Hewlett-Packard Development Company, L.P.
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*****************************************************************************************/
/************************************************************************
* SVN MACROS
*
* $LastChangedDate: 2008-07-18 15:00:39 +0530 (Fri, 18 Jul 2008) $
* $Revision: 561 $
* $Author: sharmnid $
*
************************************************************************/
/************************************************************************
* FILE DESCR: Implementation of the Ink File Reader Module
*
* CONTENTS:
* readInkFile
*
* AUTHOR: Balaji R.
*
* DATE: December 23, 2004
* CHANGE HISTORY:
* Author Date Description of change
* Deepu V. 14 Sept 2005 Added unipen file reading function
* that reads annotation.
************************************************************************/
#include "LTKChannel.h"
#include "LTKTraceFormat.h"
#include "LTKTrace.h"
#include "LTKTraceGroup.h"
#include "LTKCaptureDevice.h"
#include "LTKScreenContext.h"
#include "LTKStringUtil.h"
#include "LTKInc.h"
#include "LTKException.h"
#include "LTKMacros.h"
#include "LTKErrors.h"
#include "LTKErrorsList.h"
#include "LTKLoggerUtil.h"
#include "LTKInkFileReader.h"
/**********************************************************************************
* AUTHOR : Balaji R.
* DATE : 23-DEC-2004
* NAME : LTKInkFileReader
* DESCRIPTION : Default Constructor
* ARGUMENTS :
* RETURNS :
* NOTES :
* CHANGE HISTROY
* Author Date Description of change
*************************************************************************************/
LTKInkFileReader::LTKInkFileReader(){}
/**********************************************************************************
* AUTHOR : Balaji R.
* DATE : 23-DEC-2004
* NAME : readRawInkFile
* DESCRIPTION : reads contents of a file containing raw ink stored in a specified format into
* a trace group object. Also the device information stored in the ink file is read
* into a capture device object.
* ARGUMENTS : inkFile - name of the file containing the ink
* traceGroup - trace group into which the ink has to be read into
* captureDevice - capture device object into which device info is to be read into
* screenContext - writing area information
* RETURNS : SUCCESS on successfully reading the ink file into
* NOTES :
* CHANGE HISTROY
* Author Date Description of change
*************************************************************************************/
int LTKInkFileReader::readRawInkFile(const string& inkFile, LTKTraceGroup& traceGroup, LTKCaptureDevice& captureDevice, LTKScreenContext& screenContext)
{
LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) <<
" Entering: LTKInkFileReader::readRawInkFile()" << endl;
string dataLine;
vector<string> dataVector;
vector<float> point; // a point of a trace
int pointIndex;
if(inkFile.empty())
{
LOG(LTKLogger::LTK_LOGLEVEL_ERR)
<<"Error : "<< EINKFILE_EMPTY <<":"<< getErrorMessage(EINKFILE_EMPTY)
<<"LTKInkFileReader::readRawInkFile()" <<endl;
LTKReturnError(EINKFILE_EMPTY);
}
// opening the ink file
ifstream infile(inkFile.c_str());
// checking if the file open was successful
if(!infile)
{
LOG(LTKLogger::LTK_LOGLEVEL_ERR)
<<"Error: LTKInkFileReader::readRawInkFile()"<<endl;
LTKReturnError(EINK_FILE_OPEN);
}
vector<LTKChannel> channels; // channels of a trace
LTKChannel xChannel("X", DT_FLOAT, true); // x-coordinate channel of the trace
LTKChannel yChannel("Y", DT_FLOAT, true); // y-coordinate channel of the trace
LTKChannel tChannel("T", DT_FLOAT, true); // time channel of the trace
// initializing the channels of the trace
channels.push_back(xChannel);
channels.push_back(yChannel);
channels.push_back(tChannel);
// composing the trace format object
LTKTraceFormat traceFormat(channels);
// reading the ink file
while(infile)
{
LTKTrace trace(traceFormat);
while(infile)
{
getline(infile, dataLine);
LTKStringUtil::tokenizeString(dataLine, " \t", dataVector);
if(fabs( atof(dataVector[0].c_str()) + 1 ) < EPS)
{
traceGroup.addTrace(trace);
break;
}
else if(fabs( atof(dataVector[0].c_str()) + 2 ) < EPS)
{
return SUCCESS;
}
else if(fabs( atof(dataVector[0].c_str()) + 6 ) < EPS)
{
captureDevice.setXDPI(atof(dataVector[1].c_str()));
captureDevice.setYDPI(atof(dataVector[2].c_str()));
}
else if(atof(dataVector[0].c_str()) < 0)
{
// unknown tag. skipping line
continue;
}
else
{
for(pointIndex = 0; pointIndex < dataVector.size(); ++pointIndex)
{
point.push_back(atof(dataVector[pointIndex].c_str()));
}
if(dataVector.size() == 2)
{
point.push_back(0.0);
}
trace.addPoint(point);
point.clear();
}
}
}
LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) <<
" Exiting: LTKInkFileReader::readRawInkFile()" << endl;
return FAILURE;
}
/**********************************************************************************
* AUTHOR : Balaji R.
* DATE : 23-DEC-2004
* NAME : readUnipenInkFile
* DESCRIPTION : reads contents of a file containing unipen ink stored in a specified format into
* a trace group object. Also the device information stored in the ink file is read
* into a capture device object.
* ARGUMENTS : inkFile - name of the file containing the ink
* traceGroup - trace group into which the ink has to be read into
* captureDevice - capture device object into which device info is to be read into
* screenContext - writing area information
* RETURNS : SUCCESS on successfully reading the ink file into
* NOTES :
* CHANGE HISTROY
* Author Date Description of change
*************************************************************************************/
int LTKInkFileReader::readUnipenInkFile(const string& inkFile, LTKTraceGroup& traceGroup, LTKCaptureDevice& captureDevice, LTKScreenContext& screenContext)
{
LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) <<
" Entering: LTKInkFileReader::readUnipenInkFile()" << endl;
map<string,string> traceIndicesCommentsMap;
string hierarchyLevel;
string quality("ALL");
LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) <<
" Exiting: LTKInkFileReader::readUnipenInkFile()" << endl;
return (readUnipenInkFileWithAnnotation(inkFile,hierarchyLevel,quality,traceGroup,traceIndicesCommentsMap,captureDevice,screenContext));
}
/**********************************************************************************
* AUTHOR : Deepu V.
* DATE : 14-SEP-2004
* NAME : readUnipenInkFileWithAnnotation
* DESCRIPTION : reads contents of a unipen file containing ink stored in a specified format into
* a trace group object. Also the device information stored in the ink file is read
* into a capture device object.The screen information is captured in screen context object.
* ARGUMENTS : inkFile - name of the file containing the ink
* hierarchyLevel - level at which the ink is required, ex. WORD or CHARACTER that follows .SEGMENT
* quality - quality of the ink that is required. Can be GOOD,BAD,OK or ALL. Example, if ink of quality
* GOOD and BAD are required, then quality="GOOD,BAD" (NOTE:comma(,) is the delimiter) else if all ink
* are required, quality="ALL"
* traceGroup - trace group into which the ink has to be read into
* traceIndicesCommentsMap - Map containing list of strokes separated by commas as key and the comments
* to that trace group unit as value (ex. key-"2,4,5" value-"delayed stroke"
* captureDevice - capture device object into which device info is to be read into
* screenContext - writing area information
* RETURNS : SUCCESS on successfully reading the ink file into
* NOTES :
* CHANGE HISTROY
* Author Date Description of change
*************************************************************************************/
int LTKInkFileReader::readUnipenInkFileWithAnnotation(const string& inkFile,const string& hierarchyLevel,const string& quality, LTKTraceGroup& traceGroup,map<string,string>& traceIndicesCommentsMap,LTKCaptureDevice& captureDevice, LTKScreenContext& screenContext)
{
LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) <<
" Entering: LTKInkFileReader::readUnipenInkFileWithAnnotation()" << endl;
vector<float> point; // a point of a trace
float xDpi; // device resolution in the x direction
float yDpi; // device resolution in the y direction
float bboxLeft; // leftmost x-coord of the writing area
float bboxBottom; // bottommost y-coord of the writing area
float bboxRight; // rightmost x-coord of the writing area
float bboxTop; // topmost y-coord of the writing area
float floatChannelValue; // channel value of type float
long longChannelValue; // channel value of type long
string channelNames; // string containing all the channel names
vector<string> channelNamesVector; // vector of channel names
int channelIndex; // index to loop over all channels in the channel list
vector<string> qualityLevels; // list of quality levels required
vector<string> coordVals; // list of coordinate values present
string remainingLine; //remaining of the line that does not contain the required hierarchy level
bool verFlag = false, hlevelFlag = false, coordFlag = false;// bool level that denote whether version Info, Hierarchy level and coordinate info are set
bool pendownFlag = false;
LTKStringUtil::tokenizeString(quality,",", qualityLevels);
// opening the ink file
if(inkFile.empty())
{
LOG(LTKLogger::LTK_LOGLEVEL_ERR)
<<"Error : "<< EINKFILE_EMPTY <<":"<< getErrorMessage(EINKFILE_EMPTY)
<<"LTKInkFileReader::readUnipenInkFileWithAnnotation()" <<endl;
LTKReturnError(EINKFILE_EMPTY);
}
ifstream infile(inkFile.c_str()); //
// checking if the file open was successful
if(!infile)
{
LOG(LTKLogger::LTK_LOGLEVEL_ERR)
<<"Error : "<< EINK_FILE_OPEN <<":"<< getErrorMessage(EINK_FILE_OPEN)
<<"LTKInkFileReader::readUnipenInkFileWithAnnotation()" <<endl;
LTKReturnError(EINK_FILE_OPEN);
}
LTKTrace *trace = NULL; // initializing trace to NULL
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -