/******************************************************************************
 * AUTHOR		: Tarun Madan
 * DATE			: Aug-07-2007
 * NAME			: convertToTraceGroup
 * DESCRIPTION	: 
 * ARGUMENTS		: 
 * RETURNS		:
 * NOTES			: 
 * CHANGE HISTROY
 * Author			Date				Description
 ******************************************************************************/
int PointFloatShapeFeatureExtractor::convertFeatVecToTraceGroup(
                                 const vector<LTKShapeFeaturePtr>& shapeFeature, 
                                 LTKTraceGroup& outTraceGroup)
{
    LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << "Entering " <<
        "PointFloatShapeFeatureExtractor::convertFeatVecToTraceGroup()" << endl;
    
	vector<LTKChannel> channels;				//	channels of a trace 

	LTKChannel xChannel("X", DT_INT, true);	//	x-coordinate channel of the trace 
	LTKChannel yChannel("Y", DT_INT, true);	//	y-coordinate channel of the trace

	//initializing the channels of the trace
	channels.push_back(xChannel);	
	channels.push_back(yChannel);

	//	composing the trace format object
	LTKTraceFormat traceFormat(channels);

	vector<float> point;				//	a point of a trace

	LTKTrace trace(traceFormat); 
	int featureVectorSize = shapeFeature.size();

	for(int count=0; count < featureVectorSize; count++)
	{
		float Xpoint, Ypoint;
		bool penUp;

		PointFloatShapeFeature* ptr = (PointFloatShapeFeature*)(shapeFeature[count].operator ->());
		Xpoint = ptr->getX();
		Ypoint = ptr->getY();
		penUp = ptr->getPenUp();

		

		point.push_back(Xpoint);
		point.push_back(Ypoint);

		trace.addPoint(point);
		point.clear();


		if(penUp == true)	// end of a trace, clearing the trace now
		{
			outTraceGroup.addTrace(trace); 
			trace.emptyTrace();
			LTKTrace tempTrace(traceFormat);
			trace = tempTrace;
		}
	}

    LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << "Exiting " <<
        "PointFloatShapeFeatureExtractor::convertFeatVecToTraceGroup()" << endl;
    
	return SUCCESS;
}
Esempio n. 2
0
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;
}