diff options
author | Jarkko Koivikko <jarkko.koivikko@code-q.fi> | 2015-08-18 11:30:27 +0300 |
---|---|---|
committer | Jarkko Koivikko <jarkko.koivikko@code-q.fi> | 2015-08-27 06:56:30 +0000 |
commit | 8324b460466c991742a36452acca4150c2353356 (patch) | |
tree | 975ddd5d721db7f02e98153a979f4ce5ca983b9c /src/virtualkeyboard/3rdparty | |
parent | 37d8e974fd3dafa87c08b4d7b035369b3fa421ac (diff) |
lipi-toolkit: Add function level optimizations for lipi recognition
- Remove success return value from performance critical methods. The
return value is useless and adds unnecessary overhead for the
recognition process.
- Add inlining optimization for PointFloatShapeFeature::getDistance method,
which is very critical to the performance
Change-Id: If5737792b7262d4ef362388d3131912f87df9718
Reviewed-by: Mitch Curtis <mitch.curtis@theqtcompany.com>
Reviewed-by: Rainer Keller <rainer.keller@theqtcompany.com>
Diffstat (limited to 'src/virtualkeyboard/3rdparty')
15 files changed, 27 insertions, 74 deletions
diff --git a/src/virtualkeyboard/3rdparty/lipi-toolkit/src/include/LTKRefCountedPtr.h b/src/virtualkeyboard/3rdparty/lipi-toolkit/src/include/LTKRefCountedPtr.h index be4af05a..3b67c9ee 100644 --- a/src/virtualkeyboard/3rdparty/lipi-toolkit/src/include/LTKRefCountedPtr.h +++ b/src/virtualkeyboard/3rdparty/lipi-toolkit/src/include/LTKRefCountedPtr.h @@ -185,7 +185,7 @@ public: * CHANGE HISTROY * Author Date Description of change *************************************************************************************/ - TargetClass* operator->() const + inline TargetClass* operator->() const { return m_sharedCounterPtr->objPtr; } diff --git a/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/activedtw/ActiveDTWShapeRecognizer.cpp b/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/activedtw/ActiveDTWShapeRecognizer.cpp index d51d3377..7a805b81 100644 --- a/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/activedtw/ActiveDTWShapeRecognizer.cpp +++ b/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/activedtw/ActiveDTWShapeRecognizer.cpp @@ -1753,21 +1753,12 @@ int ActiveDTWShapeRecognizer::computeEuclideanDistance( for(int i = 0; i < firstFeatureVectorSize; ++i) { - float tempDistance = 0.0f; - int errorCode = getDistance(inFirstFeature[i], + float tempDistance = 0.0; + getDistance(inFirstFeature[i], inSecondFeature[i], tempDistance); - if (errorCode != SUCCESS ) - { - LOG(LTKLogger::LTK_LOGLEVEL_ERR)<<"Error: "<< errorCode << " " << - " ActiveDTWShapeRecognizer::computeEuclideanDistance()" << endl; - LTKReturnError(errorCode); - } - else - { - outEuclideanDistance += tempDistance; - } + outEuclideanDistance += tempDistance; } LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) << "Exiting " << @@ -4840,19 +4831,11 @@ void ActiveDTWShapeRecognizer::updateHeaderWithAlgoInfo() * CHANGE HISTROY * Author Date Description ******************************************************************************/ -int ActiveDTWShapeRecognizer::getDistance(const LTKShapeFeaturePtr& f1, +void ActiveDTWShapeRecognizer::getDistance(const LTKShapeFeaturePtr& f1, const LTKShapeFeaturePtr& f2, float& distance) { - - int errorCode = f1->getDistance(f2, distance); - - if (errorCode != SUCCESS ) - { - LTKReturnError(errorCode); - } - - return SUCCESS; + f1->getDistance(f2, distance); } diff --git a/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/activedtw/ActiveDTWShapeRecognizer.h b/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/activedtw/ActiveDTWShapeRecognizer.h index 20fa2d57..dc3ba171 100644 --- a/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/activedtw/ActiveDTWShapeRecognizer.h +++ b/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/activedtw/ActiveDTWShapeRecognizer.h @@ -1020,7 +1020,7 @@ private: int findOptimalDeformation(doubleVector& deformationParameters,doubleVector& eigenValues, double2DVector& eigenVector, doubleVector& clusterMean, doubleVector& testSample); - static int getDistance(const LTKShapeFeaturePtr& f1,const LTKShapeFeaturePtr& f2, float& distance); + static void getDistance(const LTKShapeFeaturePtr& f1,const LTKShapeFeaturePtr& f2, float& distance); /** diff --git a/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/common/LTKShapeFeature.h b/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/common/LTKShapeFeature.h index 2940d786..cf2018dc 100644 --- a/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/common/LTKShapeFeature.h +++ b/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/common/LTKShapeFeature.h @@ -132,7 +132,7 @@ public: * @return distance (float) Distance between two instances of LTKShapeFeature class. */ - virtual int getDistance(const LTKShapeFeaturePtr& shapeFeaturePtr, float& outDistance) const = 0; + virtual void getDistance(const LTKShapeFeaturePtr& shapeFeaturePtr, float& outDistance) const = 0; //@} diff --git a/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/l7/L7ShapeFeature.cpp b/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/l7/L7ShapeFeature.cpp index e8d1fc61..16eaaca4 100644 --- a/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/l7/L7ShapeFeature.cpp +++ b/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/l7/L7ShapeFeature.cpp @@ -383,7 +383,7 @@ LTKShapeFeaturePtr L7ShapeFeature::clone() const * CHANGE HISTROY * Author Date Description of change *************************************************************************************/ -int L7ShapeFeature::getDistance(const LTKShapeFeaturePtr& shapeFeaturePtr, float& outDistance) const +void L7ShapeFeature::getDistance(const LTKShapeFeaturePtr& shapeFeaturePtr, float& outDistance) const { float xDiff = 0, yDiff = 0; float xFirstDervDiff=0, yFirstDervDiff=0, xSecondDervDiff=0, ySecondDervDiff=0; @@ -403,8 +403,6 @@ int L7ShapeFeature::getDistance(const LTKShapeFeaturePtr& shapeFeaturePtr, float outDistance += ( (xFirstDervDiff * xFirstDervDiff) + (yFirstDervDiff * yFirstDervDiff) ); outDistance += ( (xSecondDervDiff * xSecondDervDiff) + (ySecondDervDiff * ySecondDervDiff) ); outDistance += ( (curvatureDiff * curvatureDiff)); - - return SUCCESS; } /********************************************************************************** * AUTHOR : Naveen Sundar G. diff --git a/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/l7/L7ShapeFeature.h b/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/l7/L7ShapeFeature.h index 51eeae01..6c767112 100644 --- a/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/l7/L7ShapeFeature.h +++ b/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/l7/L7ShapeFeature.h @@ -211,7 +211,7 @@ public: * @return float : Distance between two points in the LocalSeven feature representation * */ - int getDistance(const LTKShapeFeaturePtr& shapeFeaturePtr, float& outDistance) const; + void getDistance(const LTKShapeFeaturePtr& shapeFeaturePtr, float& outDistance) const; /** * @brief Adds two L7ShapeFeature instances. diff --git a/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/npen/NPenShapeFeature.cpp b/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/npen/NPenShapeFeature.cpp index 93eae6cb..a05867be 100644 --- a/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/npen/NPenShapeFeature.cpp +++ b/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/npen/NPenShapeFeature.cpp @@ -245,7 +245,7 @@ NPenShapeFeature::NPenShapeFeature():m_data_delimiter(",") - int NPenShapeFeature::getDistance(const LTKShapeFeaturePtr& shapeFeaturePtr, float& outDistance) const + void NPenShapeFeature::getDistance(const LTKShapeFeaturePtr& shapeFeaturePtr, float& outDistance) const { outDistance = 0.0; @@ -261,10 +261,6 @@ NPenShapeFeature::NPenShapeFeature():m_data_delimiter(",") outDistance += (m_curliness - inFeature->getCurliness())*(m_curliness - inFeature->getCurliness()); outDistance += (m_linearity - inFeature->getLinearity())*(m_linearity - inFeature->getLinearity()); outDistance += (m_slope - inFeature->getSlope())*(m_slope - inFeature->getSlope()); - - - return SUCCESS; - } diff --git a/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/npen/NPenShapeFeature.h b/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/npen/NPenShapeFeature.h index 4660018b..1f9f5f08 100644 --- a/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/npen/NPenShapeFeature.h +++ b/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/npen/NPenShapeFeature.h @@ -232,7 +232,7 @@ public: - int getDistance(const LTKShapeFeaturePtr& shapeFeaturePtr, float& outDistance) const; + void getDistance(const LTKShapeFeaturePtr& shapeFeaturePtr, float& outDistance) const; /** * Converts the local feature instance into a float vector. The elements of the float vector are m_x, m_y, m_cosAlpha, m_sinAlpha, m_cosBeta, m_sinBeta, m_aspect, m_curliness, m_linearity, m_slope and m_isPenUp in the order. diff --git a/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/pointfloat/PointFloatShapeFeature.cpp b/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/pointfloat/PointFloatShapeFeature.cpp index 5f989dc7..2248e1ec 100644 --- a/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/pointfloat/PointFloatShapeFeature.cpp +++ b/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/pointfloat/PointFloatShapeFeature.cpp @@ -277,25 +277,21 @@ LTKShapeFeaturePtr PointFloatShapeFeature::clone() const * CHANGE HISTROY * Author: Naveen Sundar G. Date: 13-Sept-2007 Description: Implemented Support for theta *************************************************************************************/ -int PointFloatShapeFeature::getDistance(const LTKShapeFeaturePtr& shapeFeaturePtr, +void PointFloatShapeFeature::getDistance(const LTKShapeFeaturePtr& shapeFeaturePtr, float& outDistance) const { - float xDiff = 0, yDiff = 0, sinthetaDiff=0, costhetaDiff=0; - PointFloatShapeFeature *inPointFloatFeature = (PointFloatShapeFeature*)(shapeFeaturePtr.operator ->()); - xDiff = (m_x) - inPointFloatFeature->getX(); + float xDiff = (m_x) - inPointFloatFeature->m_x; - yDiff = (m_y) - inPointFloatFeature->getY(); + float yDiff = (m_y) - inPointFloatFeature->m_y; - sinthetaDiff = (m_sinTheta) - inPointFloatFeature->getSinTheta(); + float sinthetaDiff = (m_sinTheta) - inPointFloatFeature->m_sinTheta; - costhetaDiff = (m_cosTheta) - inPointFloatFeature->getCosTheta(); + float costhetaDiff = (m_cosTheta) - inPointFloatFeature->m_cosTheta; outDistance = ( (xDiff * xDiff) + (yDiff * yDiff) + (sinthetaDiff * sinthetaDiff) + (costhetaDiff * costhetaDiff) ); - - return SUCCESS; } /********************************************************************************** diff --git a/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/pointfloat/PointFloatShapeFeature.h b/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/pointfloat/PointFloatShapeFeature.h index fce79969..0bdc97a0 100644 --- a/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/pointfloat/PointFloatShapeFeature.h +++ b/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/pointfloat/PointFloatShapeFeature.h @@ -163,7 +163,7 @@ public: LTKShapeFeaturePtr clone() const; - int getDistance(const LTKShapeFeaturePtr& shapeFeaturePtr, float& outDistance) const; + void getDistance(const LTKShapeFeaturePtr& shapeFeaturePtr, float& outDistance) const; diff --git a/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/substroke/SubStrokeShapeFeature.cpp b/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/substroke/SubStrokeShapeFeature.cpp index 16a6e5f4..fb282d31 100644 --- a/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/substroke/SubStrokeShapeFeature.cpp +++ b/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/substroke/SubStrokeShapeFeature.cpp @@ -161,7 +161,7 @@ LTKShapeFeaturePtr SubStrokeShapeFeature::clone() const * Author Date Description ******************************************************************************/ -int SubStrokeShapeFeature::getDistance(const LTKShapeFeaturePtr& shapeFeaturePtr, +void SubStrokeShapeFeature::getDistance(const LTKShapeFeaturePtr& shapeFeaturePtr, float& outDistance) const { @@ -191,7 +191,7 @@ int SubStrokeShapeFeature::getDistance(const LTKShapeFeaturePtr& shapeFeaturePtr if(numSlope != (inSubStrokeFeature->getFeatureDimension()-3)) { //write log - return FAILURE; // error + return; // error } // compute the distance between the slope vectors of two instances of SubStrokeShapeFeature @@ -221,8 +221,6 @@ int SubStrokeShapeFeature::getDistance(const LTKShapeFeaturePtr& shapeFeaturePtr lengthDiff = fabs((m_subStrokeLength) - inSubStrokeFeature->getSubStrokeLength()); outDistance = (sumSlopeDiff + (xDiff * xDiff) + (yDiff * yDiff) + lengthDiff); - - return SUCCESS; } /****************************************************************************** diff --git a/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/substroke/SubStrokeShapeFeature.h b/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/substroke/SubStrokeShapeFeature.h index c1de71b7..791ed9a7 100644 --- a/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/substroke/SubStrokeShapeFeature.h +++ b/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/substroke/SubStrokeShapeFeature.h @@ -165,7 +165,7 @@ public: /** * @brief Gives the distance between two SubStrokeShapeFeature instance */ - int getDistance(const LTKShapeFeaturePtr& shapeFeaturePtr, float& outDistance) const; + void getDistance(const LTKShapeFeaturePtr& shapeFeaturePtr, float& outDistance) const; /** * @brief Adds two SubStrokeShapeFeature instances. diff --git a/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/nn/NNShapeRecognizer.cpp b/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/nn/NNShapeRecognizer.cpp index 9d71c875..8da7e807 100644 --- a/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/nn/NNShapeRecognizer.cpp +++ b/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/nn/NNShapeRecognizer.cpp @@ -1626,20 +1626,10 @@ int NNShapeRecognizer::computeEuclideanDistance( for(int i = 0; i < firstFeatureVectorSize; ++i) { float tempDistance = 0.0f; - int errorCode = getDistance(firstFeatureVec[i], + getDistance(firstFeatureVec[i], secondFeatureVec[i], tempDistance); - - if (errorCode != SUCCESS ) - { - LOG(LTKLogger::LTK_LOGLEVEL_ERR)<<"Error: "<< errorCode << " " << - " NNShapeRecognizer::computeEuclideanDistance()" << endl; - LTKReturnError(errorCode); - } - else - { - outEuclideanDistance += tempDistance; - } + outEuclideanDistance += tempDistance; } LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) << "Exiting " << @@ -3452,19 +3442,11 @@ void NNShapeRecognizer::updateHeaderWithAlgoInfo() * CHANGE HISTROY * Author Date Description ******************************************************************************/ -int NNShapeRecognizer::getDistance(const LTKShapeFeaturePtr& f1, +void NNShapeRecognizer::getDistance(const LTKShapeFeaturePtr& f1, const LTKShapeFeaturePtr& f2, float& distance) { - - int errorCode = f1->getDistance(f2, distance); - - if (errorCode != SUCCESS ) - { - LTKReturnError(errorCode); - } - - return SUCCESS; + f1->getDistance(f2, distance); } /****************************************************************************** diff --git a/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/nn/NNShapeRecognizer.h b/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/nn/NNShapeRecognizer.h index eb317867..60b9b857 100644 --- a/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/nn/NNShapeRecognizer.h +++ b/src/virtualkeyboard/3rdparty/lipi-toolkit/src/reco/shaperec/nn/NNShapeRecognizer.h @@ -907,7 +907,7 @@ class NNShapeRecognizer: public LTKShapeRecognizer static bool sortDist(const NeighborInfo& x, const NeighborInfo& y); - static int getDistance(const LTKShapeFeaturePtr& f1,const LTKShapeFeaturePtr& f2, float& distance); + static void getDistance(const LTKShapeFeaturePtr& f1,const LTKShapeFeaturePtr& f2, float& distance); int getShapeSampleFromString(const string& inString, LTKShapeSample& outShapeSample); diff --git a/src/virtualkeyboard/3rdparty/lipi-toolkit/src/util/lib/LTKDynamicTimeWarping.h b/src/virtualkeyboard/3rdparty/lipi-toolkit/src/util/lib/LTKDynamicTimeWarping.h index 9c7e192c..c9b4e044 100644 --- a/src/virtualkeyboard/3rdparty/lipi-toolkit/src/util/lib/LTKDynamicTimeWarping.h +++ b/src/virtualkeyboard/3rdparty/lipi-toolkit/src/util/lib/LTKDynamicTimeWarping.h @@ -61,7 +61,7 @@ class DynamicTimeWarping vector<vector<int> > m_phi; // phi matrix required for path computation //function pointer type of the function that defines local distance function - typedef int (*FN_PTR_DISTANCE)(const TimeSeriesElementType&, const TimeSeriesElementType&, DistanceType&) ; + typedef void (*FN_PTR_DISTANCE)(const TimeSeriesElementType&, const TimeSeriesElementType&, DistanceType&) ; DistanceType m_maxVal; |