diff --git a/src/ccutil/host.h b/src/ccutil/host.h index ae031995d9..148399f29c 100644 --- a/src/ccutil/host.h +++ b/src/ccutil/host.h @@ -31,7 +31,6 @@ #include // int32_t, ... // definitions of portable data types (numbers and characters) -using FLOAT32 = float; using BOOL8 = unsigned char; #if defined(_WIN32) diff --git a/src/classify/adaptmatch.cpp b/src/classify/adaptmatch.cpp index e8d20ca181..cb482dc6cc 100644 --- a/src/classify/adaptmatch.cpp +++ b/src/classify/adaptmatch.cpp @@ -43,7 +43,7 @@ #include "fontinfo.h" // for ScoredFont, FontSet #include "genericvector.h" // for GenericVector #include "helpers.h" // for IntCastRounded, ClipToRange -#include "host.h" // for FLOAT32, FALSE, TRUE +#include "host.h" // for FALSE, TRUE #include "intfx.h" // for BlobToTrainingSample, INT_FX_RESULT_S... #include "intmatcher.h" // for CP_RESULT_STRUCT, IntegerMatcher #include "intproto.h" // for INT_FEATURE_STRUCT, (anonymous), Clas... @@ -95,7 +95,7 @@ struct ADAPT_RESULTS { bool HasNonfragment; UNICHAR_ID best_unichar_id; int best_match_index; - FLOAT32 best_rating; + float best_rating; GenericVector match; GenericVector CPResults; @@ -155,11 +155,11 @@ static float ScoredUnichar(UNICHAR_ID id, const ADAPT_RESULTS& results) { return results.match[index].rating; } -void InitMatcherRatings(FLOAT32 *Rating); +void InitMatcherRatings(float *Rating); int MakeTempProtoPerm(void *item1, void *item2); -void SetAdaptiveThreshold(FLOAT32 Threshold); +void SetAdaptiveThreshold(float Threshold); /*----------------------------------------------------------------------------- @@ -879,7 +879,7 @@ bool Classify::AdaptableWord(WERD_RES* word) { * @note History: Thu Mar 14 09:36:03 1991, DSJ, Created. */ void Classify::AdaptToChar(TBLOB* Blob, CLASS_ID ClassId, int FontinfoId, - FLOAT32 Threshold, + float Threshold, ADAPT_TEMPLATES adaptive_templates) { int NumFeatures; INT_FEATURE_ARRAY IntFeatures; @@ -1456,8 +1456,8 @@ void Classify::ConvertMatchesToChoices(const DENORM& denorm, const TBOX& box, ADAPT_RESULTS *Results, BLOB_CHOICE_LIST *Choices) { assert(Choices != nullptr); - FLOAT32 Rating; - FLOAT32 Certainty; + float Rating; + float Certainty; BLOB_CHOICE_IT temp_it; bool contains_nonfrag = false; temp_it.set_to_list(Choices); @@ -1893,9 +1893,9 @@ PROTO_ID Classify::MakeNewTempProtos(FEATURE_SET Features, TEMP_PROTO TempProto; PROTO Proto; FEATURE F1, F2; - FLOAT32 X1, X2, Y1, Y2; - FLOAT32 A1, A2, AngleDelta; - FLOAT32 SegmentLength; + float X1, X2, Y1, Y2; + float A1, A2, AngleDelta; + float SegmentLength; PROTO_ID Pid; for (ProtoStart = BadFeat, LastBad = ProtoStart + NumBadFeat; @@ -2093,7 +2093,7 @@ void Classify::PrintAdaptiveMatchResults(const ADAPT_RESULTS& results) { */ void Classify::RemoveBadMatches(ADAPT_RESULTS *Results) { int Next, NextGood; - FLOAT32 BadMatchThreshold; + float BadMatchThreshold; static const char* romans = "i v x I V X"; BadMatchThreshold = Results->best_rating - matcher_bad_match_pad; @@ -2204,7 +2204,7 @@ void Classify::RemoveExtraPuncs(ADAPT_RESULTS *Results) { * @note Exceptions: none * @note History: Tue Apr 9 08:33:13 1991, DSJ, Created. */ -void Classify::SetAdaptiveThreshold(FLOAT32 Threshold) { +void Classify::SetAdaptiveThreshold(float Threshold) { Threshold = (Threshold == matcher_good_threshold) ? 0.9: (1.0 - Threshold); classify_adapt_proto_threshold.set_value( ClipToRange(255 * Threshold, 0, 255)); diff --git a/src/classify/classify.h b/src/classify/classify.h index 7e7ee934dc..a3056ca18d 100644 --- a/src/classify/classify.h +++ b/src/classify/classify.h @@ -107,8 +107,8 @@ class Classify : public CCStruct { void WriteAdaptedTemplates(FILE *File, ADAPT_TEMPLATES Templates); ADAPT_TEMPLATES ReadAdaptedTemplates(TFile* File); /* normmatch.cpp ************************************************************/ - FLOAT32 ComputeNormMatch(CLASS_ID ClassId, - const FEATURE_STRUCT& feature, bool DebugMatch); + float ComputeNormMatch(CLASS_ID ClassId, + const FEATURE_STRUCT& feature, bool DebugMatch); void FreeNormProtos(); NORM_PROTOS* ReadNormProtos(TFile* fp); /* protos.cpp ***************************************************************/ @@ -213,7 +213,7 @@ class Classify : public CCStruct { void PrintAdaptiveMatchResults(const ADAPT_RESULTS& results); void RemoveExtraPuncs(ADAPT_RESULTS *Results); void RemoveBadMatches(ADAPT_RESULTS *Results); - void SetAdaptiveThreshold(FLOAT32 Threshold); + void SetAdaptiveThreshold(float Threshold); void ShowBestMatchFor(int shape_id, const INT_FEATURE_STRUCT* features, int num_features); @@ -252,7 +252,7 @@ class Classify : public CCStruct { UNICHAR_ID *GetAmbiguities(TBLOB *Blob, CLASS_ID CorrectClass); void DoAdaptiveMatch(TBLOB *Blob, ADAPT_RESULTS *Results); void AdaptToChar(TBLOB* Blob, CLASS_ID ClassId, int FontinfoId, - FLOAT32 Threshold, ADAPT_TEMPLATES adaptive_templates); + float Threshold, ADAPT_TEMPLATES adaptive_templates); void DisplayAdaptedChar(TBLOB* blob, INT_CLASS_STRUCT* int_class); bool AdaptableWord(WERD_RES* word); void EndAdaptiveClassifier(); @@ -350,7 +350,7 @@ class Classify : public CCStruct { return fontset_table_; } /* mfoutline.cpp ***********************************************************/ - void NormalizeOutlines(LIST Outlines, FLOAT32 *XScale, FLOAT32 *YScale); + void NormalizeOutlines(LIST Outlines, float *XScale, float *YScale); /* outfeat.cpp ***********************************************************/ FEATURE_SET ExtractOutlineFeatures(TBLOB *Blob); /* picofeat.cpp ***********************************************************/ diff --git a/src/classify/cluster.cpp b/src/classify/cluster.cpp index 9f72346828..bc0ce2685c 100644 --- a/src/classify/cluster.cpp +++ b/src/classify/cluster.cpp @@ -169,10 +169,10 @@ using ClusterPair = tesseract::KDPairInc; using ClusterHeap = tesseract::GenericHeap; struct STATISTICS { - FLOAT32 AvgVariance; - FLOAT32 *CoVariance; - FLOAT32 *Min; // largest negative distance from the mean - FLOAT32 *Max; // largest positive distance from the mean + float AvgVariance; + float *CoVariance; + float *Min; // largest negative distance from the mean + float *Max; // largest positive distance from the mean }; struct BUCKETS { @@ -183,7 +183,7 @@ struct BUCKETS { uint16_t NumberOfBuckets; // number of cells in histogram uint16_t Bucket[BUCKETTABLESIZE]; // mapping to histogram buckets uint32_t *Count; // frequency of occurrence histogram - FLOAT32 *ExpectedCount; // expected histogram + float *ExpectedCount; // expected histogram }; struct CHISTRUCT{ @@ -246,7 +246,7 @@ void MakePotentialClusters(ClusteringContext *context, CLUSTER *Cluster, CLUSTER *FindNearestNeighbor(KDTREE *Tree, CLUSTER *Cluster, - FLOAT32 *Distance); + float *Distance); CLUSTER *MakeNewCluster(CLUSTERER *Clusterer, TEMPCLUSTER *TempCluster); @@ -254,8 +254,8 @@ int32_t MergeClusters (int16_t N, PARAM_DESC ParamDesc[], int32_t n1, int32_t n2, -FLOAT32 m[], -FLOAT32 m1[], FLOAT32 m2[]); +float m[], +float m1[], float m2[]); void ComputePrototypes(CLUSTERER *Clusterer, CLUSTERCONFIG *Config); @@ -310,7 +310,7 @@ PROTOTYPE *NewMixedProto(int16_t N, CLUSTER *Cluster, STATISTICS *Statistics); PROTOTYPE *NewSimpleProto(int16_t N, CLUSTER *Cluster); bool Independent(PARAM_DESC* ParamDesc, - int16_t N, FLOAT32* CoVariance, FLOAT32 Independence); + int16_t N, float* CoVariance, float Independence); BUCKETS *GetBuckets(CLUSTERER* clusterer, DISTRIBUTION Distribution, @@ -335,18 +335,18 @@ void FillBuckets(BUCKETS *Buckets, CLUSTER *Cluster, uint16_t Dim, PARAM_DESC *ParamDesc, - FLOAT32 Mean, - FLOAT32 StdDev); + float Mean, + float StdDev); uint16_t NormalBucket(PARAM_DESC *ParamDesc, - FLOAT32 x, - FLOAT32 Mean, - FLOAT32 StdDev); + float x, + float Mean, + float StdDev); uint16_t UniformBucket(PARAM_DESC *ParamDesc, - FLOAT32 x, - FLOAT32 Mean, - FLOAT32 StdDev); + float x, + float Mean, + float StdDev); bool DistributionOK(BUCKETS* Buckets); @@ -381,7 +381,7 @@ double ChiArea(CHISTRUCT *ChiParams, double x); bool MultipleCharSamples(CLUSTERER* Clusterer, CLUSTER* Cluster, - FLOAT32 MaxIllegal); + float MaxIllegal); double InvertMatrix(const float* input, int size, float* inv); @@ -453,7 +453,7 @@ MakeClusterer (int16_t SampleSize, const PARAM_DESC ParamDesc[]) { * ClusterSamples has been called * @note History: 5/29/89, DSJ, Created. */ -SAMPLE* MakeSample(CLUSTERER * Clusterer, const FLOAT32* Feature, +SAMPLE* MakeSample(CLUSTERER * Clusterer, const float* Feature, int32_t CharID) { SAMPLE *Sample; int i; @@ -466,7 +466,7 @@ SAMPLE* MakeSample(CLUSTERER * Clusterer, const FLOAT32* Feature, // allocate the new sample and initialize it Sample = (SAMPLE *) Emalloc (sizeof (SAMPLE) + (Clusterer->SampleSize - - 1) * sizeof (FLOAT32)); + 1) * sizeof (float)); Sample->Clustered = FALSE; Sample->Prototype = FALSE; Sample->SampleCount = 1; @@ -642,7 +642,7 @@ CLUSTER *NextSample(LIST *SearchState) { * @note Exceptions: none * @note History: 7/6/89, DSJ, Created. */ -FLOAT32 Mean(PROTOTYPE *Proto, uint16_t Dimension) { +float Mean(PROTOTYPE *Proto, uint16_t Dimension) { return (Proto->Mean[Dimension]); } // Mean @@ -655,17 +655,17 @@ FLOAT32 Mean(PROTOTYPE *Proto, uint16_t Dimension) { * @note Exceptions: none * @note History: 7/6/89, DSJ, Created. */ -FLOAT32 StandardDeviation(PROTOTYPE *Proto, uint16_t Dimension) { +float StandardDeviation(PROTOTYPE *Proto, uint16_t Dimension) { switch (Proto->Style) { case spherical: - return ((FLOAT32) sqrt ((double) Proto->Variance.Spherical)); + return ((float) sqrt ((double) Proto->Variance.Spherical)); case elliptical: - return ((FLOAT32) + return ((float) sqrt ((double) Proto->Variance.Elliptical[Dimension])); case mixed: switch (Proto->Distrib[Dimension]) { case normal: - return ((FLOAT32) + return ((float) sqrt ((double) Proto->Variance.Elliptical[Dimension])); case uniform: case D_random: @@ -796,12 +796,12 @@ void MakePotentialClusters(ClusteringContext *context, * 7/13/89, DSJ, Removed visibility of kd-tree node data struct */ CLUSTER * -FindNearestNeighbor(KDTREE * Tree, CLUSTER * Cluster, FLOAT32 * Distance) +FindNearestNeighbor(KDTREE * Tree, CLUSTER * Cluster, float * Distance) #define MAXNEIGHBORS 2 #define MAXDISTANCE FLT_MAX { CLUSTER *Neighbor[MAXNEIGHBORS]; - FLOAT32 Dist[MAXNEIGHBORS]; + float Dist[MAXNEIGHBORS]; int NumberOfNeighbors; int32_t i; CLUSTER *BestNeighbor; @@ -839,7 +839,7 @@ CLUSTER *MakeNewCluster(CLUSTERER *Clusterer, TEMPCLUSTER *TempCluster) { // allocate the new cluster and initialize it Cluster = (CLUSTER *) Emalloc( - sizeof(CLUSTER) + (Clusterer->SampleSize - 1) * sizeof(FLOAT32)); + sizeof(CLUSTER) + (Clusterer->SampleSize - 1) * sizeof(float)); Cluster->Clustered = FALSE; Cluster->Prototype = FALSE; Cluster->Left = TempCluster->Cluster; @@ -882,8 +882,8 @@ int32_t MergeClusters(int16_t N, PARAM_DESC ParamDesc[], int32_t n1, int32_t n2, - FLOAT32 m[], - FLOAT32 m1[], FLOAT32 m2[]) { + float m[], + float m1[], float m2[]) { int32_t i, n; n = n1 + n2; @@ -1123,10 +1123,10 @@ PROTOTYPE *TestEllipticalProto(CLUSTERER *Clusterer, int TotalDims = Left->SampleCount + Right->SampleCount; if (TotalDims < N + 1 || TotalDims < 2) return nullptr; - const int kMatrixSize = N * N * sizeof(FLOAT32); - FLOAT32 *Covariance = static_cast(Emalloc(kMatrixSize)); - FLOAT32 *Inverse = static_cast(Emalloc(kMatrixSize)); - FLOAT32 *Delta = static_cast(Emalloc(N * sizeof(FLOAT32))); + const int kMatrixSize = N * N * sizeof(float); + float *Covariance = static_cast(Emalloc(kMatrixSize)); + float *Inverse = static_cast(Emalloc(kMatrixSize)); + float *Delta = static_cast(Emalloc(N * sizeof(float))); // Compute a new covariance matrix that only uses essential features. for (int i = 0; i < N; ++i) { int row_offset = i * N; @@ -1413,20 +1413,20 @@ STATISTICS * ComputeStatistics (int16_t N, PARAM_DESC ParamDesc[], CLUSTER * Cluster) { STATISTICS *Statistics; int i, j; - FLOAT32 *CoVariance; - FLOAT32 *Distance; + float *CoVariance; + float *Distance; LIST SearchState; SAMPLE *Sample; uint32_t SampleCountAdjustedForBias; // allocate memory to hold the statistics results Statistics = (STATISTICS *) Emalloc (sizeof (STATISTICS)); - Statistics->CoVariance = (FLOAT32 *) Emalloc (N * N * sizeof (FLOAT32)); - Statistics->Min = (FLOAT32 *) Emalloc (N * sizeof (FLOAT32)); - Statistics->Max = (FLOAT32 *) Emalloc (N * sizeof (FLOAT32)); + Statistics->CoVariance = (float *) Emalloc (N * N * sizeof (float)); + Statistics->Min = (float *) Emalloc (N * sizeof (float)); + Statistics->Max = (float *) Emalloc (N * sizeof (float)); // allocate temporary memory to hold the sample to mean distances - Distance = (FLOAT32 *) Emalloc (N * sizeof (FLOAT32)); + Distance = (float *) Emalloc (N * sizeof (float)); // initialize the statistics Statistics->AvgVariance = 1.0; @@ -1534,13 +1534,13 @@ PROTOTYPE *NewEllipticalProto(int16_t N, CLUSTER *Cluster, STATISTICS *Statistics) { PROTOTYPE *Proto; - FLOAT32 *CoVariance; + float *CoVariance; int i; Proto = NewSimpleProto (N, Cluster); - Proto->Variance.Elliptical = (FLOAT32 *) Emalloc (N * sizeof (FLOAT32)); - Proto->Magnitude.Elliptical = (FLOAT32 *) Emalloc (N * sizeof (FLOAT32)); - Proto->Weight.Elliptical = (FLOAT32 *) Emalloc (N * sizeof (FLOAT32)); + Proto->Variance.Elliptical = (float *) Emalloc (N * sizeof (float)); + Proto->Magnitude.Elliptical = (float *) Emalloc (N * sizeof (float)); + Proto->Weight.Elliptical = (float *) Emalloc (N * sizeof (float)); CoVariance = Statistics->CoVariance; Proto->TotalMagnitude = 1.0; @@ -1603,7 +1603,7 @@ PROTOTYPE *NewSimpleProto(int16_t N, CLUSTER *Cluster) { int i; Proto = (PROTOTYPE *) Emalloc (sizeof (PROTOTYPE)); - Proto->Mean = (FLOAT32 *) Emalloc (N * sizeof (FLOAT32)); + Proto->Mean = (float *) Emalloc (N * sizeof (float)); for (i = 0; i < N; i++) Proto->Mean[i] = Cluster->Mean[i]; @@ -1640,11 +1640,11 @@ PROTOTYPE *NewSimpleProto(int16_t N, CLUSTER *Cluster) { */ bool Independent(PARAM_DESC* ParamDesc, - int16_t N, FLOAT32* CoVariance, FLOAT32 Independence) { + int16_t N, float* CoVariance, float Independence) { int i, j; - FLOAT32 *VARii; // points to ith on-diagonal element - FLOAT32 *VARjj; // points to jth on-diagonal element - FLOAT32 CorrelationCoeff; + float *VARii; // points to ith on-diagonal element + float *VARjj; // points to jth on-diagonal element + float CorrelationCoeff; VARii = CoVariance; for (i = 0; i < N; i++, VARii += N + 1) { @@ -1756,8 +1756,8 @@ BUCKETS *MakeBuckets(DISTRIBUTION Distribution, Buckets->Confidence = Confidence; Buckets->Count = static_cast(Emalloc(Buckets->NumberOfBuckets * sizeof(uint32_t))); - Buckets->ExpectedCount = static_cast( - Emalloc(Buckets->NumberOfBuckets * sizeof(FLOAT32))); + Buckets->ExpectedCount = static_cast( + Emalloc(Buckets->NumberOfBuckets * sizeof(float))); // initialize simple fields Buckets->Distribution = Distribution; @@ -1796,12 +1796,12 @@ BUCKETS *MakeBuckets(DISTRIBUTION Distribution, } Buckets->Bucket[i] = CurrentBucket; Buckets->ExpectedCount[CurrentBucket] += - (FLOAT32) (ProbabilityDelta * SampleCount); + (float) (ProbabilityDelta * SampleCount); LastProbDensity = ProbDensity; } // place any leftover probability into the last bucket Buckets->ExpectedCount[CurrentBucket] += - (FLOAT32) ((0.5 - Probability) * SampleCount); + (float) ((0.5 - Probability) * SampleCount); // copy upper half of distribution to lower half for (i = 0, j = BUCKETTABLESIZE - 1; i < j; i++, j--) @@ -1832,15 +1832,15 @@ BUCKETS *MakeBuckets(DISTRIBUTION Distribution, */ uint16_t OptimumNumberOfBuckets(uint32_t SampleCount) { uint8_t Last, Next; - FLOAT32 Slope; + float Slope; if (SampleCount < kCountTable[0]) return kBucketsTable[0]; for (Last = 0, Next = 1; Next < LOOKUPTABLESIZE; Last++, Next++) { if (SampleCount <= kCountTable[Next]) { - Slope = (FLOAT32) (kBucketsTable[Next] - kBucketsTable[Last]) / - (FLOAT32) (kCountTable[Next] - kCountTable[Last]); + Slope = (float) (kBucketsTable[Next] - kBucketsTable[Last]) / + (float) (kCountTable[Next] - kCountTable[Last]); return ((uint16_t) (kBucketsTable[Last] + Slope * (SampleCount - kCountTable[Last]))); } @@ -1986,8 +1986,8 @@ void FillBuckets(BUCKETS *Buckets, CLUSTER *Cluster, uint16_t Dim, PARAM_DESC *ParamDesc, - FLOAT32 Mean, - FLOAT32 StdDev) { + float Mean, + float StdDev) { uint16_t BucketID; int i; LIST SearchState; @@ -2055,10 +2055,10 @@ void FillBuckets(BUCKETS *Buckets, * @note History: 6/5/89, DSJ, Created. */ uint16_t NormalBucket(PARAM_DESC *ParamDesc, - FLOAT32 x, - FLOAT32 Mean, - FLOAT32 StdDev) { - FLOAT32 X; + float x, + float Mean, + float StdDev) { + float X; // wraparound circular parameters if necessary if (ParamDesc->Circular) { @@ -2090,10 +2090,10 @@ uint16_t NormalBucket(PARAM_DESC *ParamDesc, * @note History: 6/5/89, DSJ, Created. */ uint16_t UniformBucket(PARAM_DESC *ParamDesc, - FLOAT32 x, - FLOAT32 Mean, - FLOAT32 StdDev) { - FLOAT32 X; + float x, + float Mean, + float StdDev) { + float X; // wraparound circular parameters if necessary if (ParamDesc->Circular) { @@ -2124,8 +2124,8 @@ uint16_t UniformBucket(PARAM_DESC *ParamDesc, * @note History: 6/5/89, DSJ, Created. */ bool DistributionOK(BUCKETS* Buckets) { - FLOAT32 FrequencyDifference; - FLOAT32 TotalDifference; + float FrequencyDifference; + float TotalDifference; int i; // compute how well the histogram matches the expected histogram @@ -2464,7 +2464,7 @@ double ChiArea(CHISTRUCT *ChiParams, double x) { */ bool MultipleCharSamples(CLUSTERER* Clusterer, - CLUSTER* Cluster, FLOAT32 MaxIllegal) + CLUSTER* Cluster, float MaxIllegal) #define ILLEGAL_CHAR 2 { static BOOL8 *CharFlags = nullptr; @@ -2475,7 +2475,7 @@ MultipleCharSamples(CLUSTERER* Clusterer, int32_t CharID; int32_t NumCharInCluster; int32_t NumIllegalInCluster; - FLOAT32 PercentIllegal; + float PercentIllegal; // initial estimate assumes that no illegal chars exist in the cluster NumCharInCluster = Cluster->SampleCount; @@ -2503,7 +2503,7 @@ MultipleCharSamples(CLUSTERER* Clusterer, CharFlags[CharID] = ILLEGAL_CHAR; } NumCharInCluster--; - PercentIllegal = (FLOAT32) NumIllegalInCluster / NumCharInCluster; + PercentIllegal = (float) NumIllegalInCluster / NumCharInCluster; if (PercentIllegal > MaxIllegal) { destroy(SearchState); return true; diff --git a/src/classify/cluster.h b/src/classify/cluster.h index 84e0cbd97c..99c9c879dc 100644 --- a/src/classify/cluster.h +++ b/src/classify/cluster.h @@ -1,10 +1,9 @@ /****************************************************************************** - ** Filename: cluster.h - ** Purpose: Definition of feature space clustering routines - ** Author: Dan Johnson - ** History: 5/29/89, DSJ, Created. + ** Filename: cluster.h + ** Purpose: Definition of feature space clustering routines + ** Author: Dan Johnson ** - ** (c) Copyright Hewlett-Packard Company, 1988. + ** (c) Copyright Hewlett-Packard Company, 1988. ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. ** You may obtain a copy of the License at @@ -14,9 +13,10 @@ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ** See the License for the specific language governing permissions and ** limitations under the License. - ******************************************************************************/ -#ifndef CLUSTER_H -#define CLUSTER_H + *****************************************************************************/ + +#ifndef CLUSTER_H +#define CLUSTER_H #include "kdtree.h" #include "oldlist.h" @@ -30,13 +30,13 @@ struct BUCKETS; Types ----------------------------------------------------------------------*/ typedef struct sample { - unsigned Clustered:1; // TRUE if included in a higher cluster - unsigned Prototype:1; // TRUE if cluster represented by a proto - unsigned SampleCount:30; // number of samples in this cluster - struct sample *Left; // ptr to left sub-cluster - struct sample *Right; // ptr to right sub-cluster - int32_t CharID; // identifier of char sample came from - FLOAT32 Mean[1]; // mean of cluster - SampleSize floats + unsigned Clustered:1; // TRUE if included in a higher cluster + unsigned Prototype:1; // TRUE if cluster represented by a proto + unsigned SampleCount:30; // number of samples in this cluster + struct sample *Left; // ptr to left sub-cluster + struct sample *Right; // ptr to right sub-cluster + int32_t CharID; // identifier of char sample came from + float Mean[1]; // mean of cluster - SampleSize floats } CLUSTER; typedef CLUSTER SAMPLE; // can refer to as either sample or cluster @@ -45,14 +45,14 @@ typedef enum { spherical, elliptical, mixed, automatic } PROTOSTYLE; -typedef struct { // parameters to control clustering - PROTOSTYLE ProtoStyle; // specifies types of protos to be made - FLOAT32 MinSamples; // min # of samples per proto - % of total - FLOAT32 MaxIllegal; // max percentage of samples in a cluster which have - // more than 1 feature in that cluster - FLOAT32 Independence; // desired independence between dimensions - double Confidence; // desired confidence in prototypes created - int MagicSamples; // Ideal number of samples in a cluster. +typedef struct { // parameters to control clustering + PROTOSTYLE ProtoStyle; // specifies types of protos to be made + float MinSamples; // min # of samples per proto - % of total + float MaxIllegal; // max percentage of samples in a cluster which + // have more than 1 feature in that cluster + float Independence; // desired independence between dimensions + double Confidence; // desired confidence in prototypes created + int MagicSamples; // Ideal number of samples in a cluster. } CLUSTERCONFIG; typedef enum { @@ -60,8 +60,8 @@ typedef enum { } DISTRIBUTION; typedef union { - FLOAT32 Spherical; - FLOAT32 *Elliptical; + float Spherical; + float *Elliptical; } FLOATUNION; typedef struct { @@ -75,29 +75,29 @@ typedef struct { unsigned NumSamples:28; // number of samples in the cluster CLUSTER *Cluster; // ptr to cluster which made prototype DISTRIBUTION *Distrib; // different distribution for each dimension - FLOAT32 *Mean; // prototype mean - FLOAT32 TotalMagnitude; // total magnitude over all dimensions - FLOAT32 LogMagnitude; // log base e of TotalMagnitude + float *Mean; // prototype mean + float TotalMagnitude; // total magnitude over all dimensions + float LogMagnitude; // log base e of TotalMagnitude FLOATUNION Variance; // prototype variance FLOATUNION Magnitude; // magnitude of density function FLOATUNION Weight; // weight of density function } PROTOTYPE; typedef struct { - int16_t SampleSize; // number of parameters per sample + int16_t SampleSize; // number of parameters per sample PARAM_DESC *ParamDesc; // description of each parameter - int32_t NumberOfSamples; // total number of samples being clustered + int32_t NumberOfSamples; // total number of samples being clustered KDTREE *KDTree; // for optimal nearest neighbor searching CLUSTER *Root; // ptr to root cluster of cluster tree LIST ProtoList; // list of prototypes - int32_t NumChar; // # of characters represented by samples + int32_t NumChar; // # of characters represented by samples // cache of reusable histograms by distribution type and number of buckets. BUCKETS* bucket_cache[DISTRIBUTION_COUNT][MAXBUCKETS + 1 - MINBUCKETS]; } CLUSTERER; typedef struct { - int32_t NumSamples; // number of samples in list - int32_t MaxNumSamples; // maximum size of list + int32_t NumSamples; // number of samples in list + int32_t MaxNumSamples; // maximum size of list SAMPLE *Sample[1]; // array of ptrs to sample data structures } SAMPLELIST; @@ -109,7 +109,7 @@ typedef struct { --------------------------------------------------------------------------*/ CLUSTERER *MakeClusterer (int16_t SampleSize, const PARAM_DESC ParamDesc[]); -SAMPLE *MakeSample(CLUSTERER * Clusterer, const FLOAT32* Feature, int32_t CharID); +SAMPLE *MakeSample(CLUSTERER* Clusterer, const float* Feature, int32_t CharID); LIST ClusterSamples(CLUSTERER *Clusterer, CLUSTERCONFIG *Config); @@ -121,12 +121,12 @@ void FreePrototype(void *arg); // PROTOTYPE *Prototype); CLUSTER *NextSample(LIST *SearchState); -FLOAT32 Mean(PROTOTYPE *Proto, uint16_t Dimension); +float Mean(PROTOTYPE *Proto, uint16_t Dimension); -FLOAT32 StandardDeviation(PROTOTYPE *Proto, uint16_t Dimension); +float StandardDeviation(PROTOTYPE *Proto, uint16_t Dimension); int32_t MergeClusters(int16_t N, PARAM_DESC ParamDesc[], int32_t n1, int32_t n2, - FLOAT32 m[], FLOAT32 m1[], FLOAT32 m2[]); + float m[], float m1[], float m2[]); //--------------Global Data Definitions and Declarations--------------------------- // define errors that can be trapped diff --git a/src/classify/clusttool.cpp b/src/classify/clusttool.cpp index fa2d75a89d..632b787c9e 100644 --- a/src/classify/clusttool.cpp +++ b/src/classify/clusttool.cpp @@ -2,7 +2,6 @@ ** Filename: clustertool.c ** Purpose: Misc. tools for use with the clustering routines ** Author: Dan Johnson - ** History: 6/6/89, DSJ, Created. ** ** (c) Copyright Hewlett-Packard Company, 1988. ** Licensed under the Apache License, Version 2.0 (the "License"); @@ -171,8 +170,8 @@ PROTOTYPE *ReadPrototype(TFile *fp, uint16_t N) { Proto->Variance.Elliptical = ReadNFloats(fp, N, nullptr); if (Proto->Variance.Elliptical == nullptr) DoError(ILLEGALVARIANCESPEC, "Illegal prototype variance"); - Proto->Magnitude.Elliptical = (FLOAT32 *)Emalloc(N * sizeof(FLOAT32)); - Proto->Weight.Elliptical = (FLOAT32 *)Emalloc(N * sizeof(FLOAT32)); + Proto->Magnitude.Elliptical = (float *)Emalloc(N * sizeof(float)); + Proto->Weight.Elliptical = (float *)Emalloc(N * sizeof(float)); Proto->TotalMagnitude = 1.0; for (i = 0; i < N; i++) { Proto->Magnitude.Elliptical[i] = @@ -205,7 +204,7 @@ PROTOTYPE *ReadPrototype(TFile *fp, uint16_t N) { * @note Exceptions: ILLEGALFLOAT * @note History: 6/6/89, DSJ, Created. */ -FLOAT32 *ReadNFloats(TFile *fp, uint16_t N, FLOAT32 Buffer[]) { +float *ReadNFloats(TFile *fp, uint16_t N, float Buffer[]) { const int kMaxLineSize = 1024; char line[kMaxLineSize]; if (fp->FGets(line, kMaxLineSize) == nullptr) { @@ -215,7 +214,7 @@ FLOAT32 *ReadNFloats(TFile *fp, uint16_t N, FLOAT32 Buffer[]) { bool needs_free = false; if (Buffer == nullptr) { - Buffer = static_cast(Emalloc(N * sizeof(FLOAT32))); + Buffer = static_cast(Emalloc(N * sizeof(float))); needs_free = true; } @@ -323,7 +322,7 @@ void WritePrototype(FILE *File, uint16_t N, PROTOTYPE *Proto) { * @note Exceptions: None * @note History: 6/6/89, DSJ, Created. */ -void WriteNFloats(FILE * File, uint16_t N, FLOAT32 Array[]) { +void WriteNFloats(FILE * File, uint16_t N, float Array[]) { for (int i = 0; i < N; i++) fprintf(File, " %9.6f", Array[i]); fprintf(File, "\n"); diff --git a/src/classify/clusttool.h b/src/classify/clusttool.h index ff0ad6edd5..6b47464470 100644 --- a/src/classify/clusttool.h +++ b/src/classify/clusttool.h @@ -2,7 +2,6 @@ ** Filename: clusttool.h ** Purpose: Definition of clustering utility tools ** Author: Dan Johnson - ** History: 6/6/89, DSJ, Created. ** ** (c) Copyright Hewlett-Packard Company, 1988. ** Licensed under the Apache License, Version 2.0 (the "License"); @@ -34,13 +33,13 @@ PARAM_DESC *ReadParamDesc(tesseract::TFile *fp, uint16_t N); PROTOTYPE *ReadPrototype(tesseract::TFile *fp, uint16_t N); -FLOAT32 *ReadNFloats(tesseract::TFile *fp, uint16_t N, FLOAT32 Buffer[]); +float *ReadNFloats(tesseract::TFile *fp, uint16_t N, float Buffer[]); void WriteParamDesc(FILE *File, uint16_t N, const PARAM_DESC ParamDesc[]); void WritePrototype(FILE *File, uint16_t N, PROTOTYPE *Proto); -void WriteNFloats (FILE * File, uint16_t N, FLOAT32 Array[]); +void WriteNFloats (FILE * File, uint16_t N, float Array[]); void WriteProtoStyle(FILE *File, PROTOSTYLE ProtoStyle); @@ -61,4 +60,5 @@ void WriteProtoList(FILE* File, uint16_t N, PARAM_DESC* ParamDesc, #define ILLEGALDISTRIBUTION 5008 #define ILLEGALFLOAT 5009 #define ILLEGALESSENTIALSPEC 5013 + #endif // TESSERACT_CLASSIFY_CLUSTTOOL_H_ diff --git a/src/classify/featdefs.cpp b/src/classify/featdefs.cpp index 1fce5d8cf2..a12c243b5b 100644 --- a/src/classify/featdefs.cpp +++ b/src/classify/featdefs.cpp @@ -1,8 +1,7 @@ /****************************************************************************** - ** Filename: featdefs.c + ** Filename: featdefs.cpp ** Purpose: Definitions of currently defined feature types. ** Author: Dan Johnson - ** History: Mon May 21 10:26:21 1990, DSJ, Created. ** ** (c) Copyright Hewlett-Packard Company, 1988. ** Licensed under the Apache License, Version 2.0 (the "License"); @@ -84,7 +83,7 @@ DefineFeature(GeoFeatDesc, 3, 0, kGeoFeatureType, GeoFeatParams) // Define all of the parameters for the PicoFeature type // define knob that can be used to adjust pico-feature length. -FLOAT32 PicoFeatureLength = PICO_FEATURE_LENGTH; +float PicoFeatureLength = PICO_FEATURE_LENGTH; StartParamDesc(PicoFeatParams) DefineParam(0, 0, -0.25, 0.75) DefineParam(1, 0, 0.0, 1.0) diff --git a/src/classify/float2int.cpp b/src/classify/float2int.cpp index 2af74d710b..3de261071c 100644 --- a/src/classify/float2int.cpp +++ b/src/classify/float2int.cpp @@ -1,10 +1,9 @@ /****************************************************************************** - ** Filename: float2int.c - ** Purpose: Routines for converting float features to int features - ** Author: Dan Johnson - ** History: Wed Mar 13 07:47:48 1991, DSJ, Created. + ** Filename: float2int.cpp + ** Purpose: Routines for converting float features to int features + ** Author: Dan Johnson ** - ** (c) Copyright Hewlett-Packard Company, 1988. + ** (c) Copyright Hewlett-Packard Company, 1988. ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. ** You may obtain a copy of the License at @@ -99,8 +98,7 @@ void Classify::ComputeIntCharNormArray(const FEATURE_STRUCT& norm_feature, */ void Classify::ComputeIntFeatures(FEATURE_SET Features, INT_FEATURE_ARRAY IntFeatures) { - FEATURE Feature; - FLOAT32 YShift; + float YShift; if (classify_norm_method == baseline) YShift = BASELINE_Y_SHIFT; @@ -108,7 +106,7 @@ void Classify::ComputeIntFeatures(FEATURE_SET Features, YShift = Y_SHIFT; for (int Fid = 0; Fid < Features->NumFeatures; Fid++) { - Feature = Features->Features[Fid]; + FEATURE Feature = Features->Features[Fid]; IntFeatures[Fid].X = Bucket8For(Feature->Params[PicoFeatX], X_SHIFT, INT_FEAT_RANGE); diff --git a/src/classify/fpoint.cpp b/src/classify/fpoint.cpp index 4102c03ec8..9d4a4203d0 100644 --- a/src/classify/fpoint.cpp +++ b/src/classify/fpoint.cpp @@ -2,7 +2,6 @@ ** Filename: fpoint.c ** Purpose: Abstract data type for a 2D point (floating point coords) ** Author: Dan Johnson - ** History: Thu Apr 12 10:44:15 1990, DSJ, Created. ** ** (c) Copyright Hewlett-Packard Company, 1988. ** Licensed under the Apache License, Version 2.0 (the "License"); @@ -27,7 +26,7 @@ Public Code ----------------------------------------------------------------------------*/ -FLOAT32 DistanceBetween(FPOINT A, FPOINT B) { +float DistanceBetween(FPOINT A, FPOINT B) { const double xd = XDelta(A, B); const double yd = YDelta(A, B); return sqrt(static_cast(xd * xd + yd * yd)); @@ -45,13 +44,10 @@ FLOAT32 DistanceBetween(FPOINT A, FPOINT B) { * @note Exceptions: none * @note History: Wed Mar 28 14:27:25 1990, DSJ, Created. */ -FLOAT32 NormalizedAngleFrom(FPOINT *Point1, - FPOINT *Point2, - FLOAT32 FullScale) { - FLOAT32 Angle; - FLOAT32 NumRadsInCircle = 2.0 * PI; +float NormalizedAngleFrom(FPOINT *Point1, FPOINT *Point2, float FullScale) { + float NumRadsInCircle = 2.0 * PI; - Angle = AngleFrom (*Point1, *Point2); + float Angle = AngleFrom (*Point1, *Point2); if (Angle < 0.0) Angle += NumRadsInCircle; Angle *= FullScale / NumRadsInCircle; diff --git a/src/classify/fpoint.h b/src/classify/fpoint.h index ee73f94ca0..bce12e6583 100644 --- a/src/classify/fpoint.h +++ b/src/classify/fpoint.h @@ -1,10 +1,10 @@ /****************************************************************************** - ** Filename: fpoint.h - ** Purpose: Abstract data type for 2D points (floating point coords) - ** Author: Dan Johnson - ** History: Thu Apr 12 10:50:01 1990, DSJ, Created. + ** Filename: fpoint.h + ** Purpose: Abstract data type for 2D points (floating point coords) + ** Author: Dan Johnson ** - ** (c) Copyright Hewlett-Packard Company, 1988. + ** (c) Copyright Hewlett-Packard Company, 1988. + ** (c) Copyright Hewlett-Packard Company, 1988. ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. ** You may obtain a copy of the License at @@ -15,20 +15,20 @@ ** See the License for the specific language governing permissions and ** limitations under the License. ******************************************************************************/ -#ifndef FPOINT_H -#define FPOINT_H + +#ifndef FPOINT_H +#define FPOINT_H /**---------------------------------------------------------------------------- Include Files and Type Defines ----------------------------------------------------------------------------**/ -#include "host.h" -#include #include +#include +#include "host.h" /* define data structure to hold 2D points or vectors using floating point */ -typedef struct -{ - FLOAT32 x, y; +typedef struct { + float x, y; } FPOINT; using FVECTOR = FPOINT; @@ -36,19 +36,19 @@ using FVECTOR = FPOINT; Macros ----------------------------------------------------------------------------**/ /* macros for computing miscellaneous functions of 2 points */ -#define XDelta(A,B) ( (B).x - (A).x ) -#define YDelta(A,B) ( (B).y - (A).y ) -#define SlopeFrom(A,B) ( YDelta(A,B) / XDelta(A,B) ) -#define AngleFrom(A,B) ( atan2((double) YDelta(A,B), \ - (double) XDelta(A,B) ) ) +#define XDelta(A, B) ((B).x - (A).x) +#define YDelta(A, B) ((B).y - (A).y) +#define SlopeFrom(A, B) (YDelta(A, B) / XDelta(A, B)) +#define AngleFrom(A, B) (atan2((double)YDelta(A, B), (double)XDelta(A, B))) -#define XIntersectionOf(A,B,X) ( SlopeFrom(A,B) * ((X) - A.x) + A.y) +#define XIntersectionOf(A, B, X) (SlopeFrom(A, B) * ((X)-A.x) + A.y) /*------------------------------------------------------------------------- Public Function Prototypes ---------------------------------------------------------------------------*/ -FLOAT32 DistanceBetween(FPOINT A, FPOINT B); +float DistanceBetween(FPOINT A, FPOINT B); + +float NormalizedAngleFrom(FPOINT* Point1, FPOINT* Point2, float FullScale); -FLOAT32 NormalizedAngleFrom(FPOINT *Point1, FPOINT *Point2, FLOAT32 FullScale); #endif diff --git a/src/classify/intmatcher.cpp b/src/classify/intmatcher.cpp index a39adc2f4d..f53ab19e39 100644 --- a/src/classify/intmatcher.cpp +++ b/src/classify/intmatcher.cpp @@ -1,11 +1,8 @@ /****************************************************************************** - ** Filename: intmatcher.c - ** Purpose: Generic high level classification routines. - ** Author: Robert Moss - ** History: Wed Feb 13 17:35:28 MST 1991, RWM, Created. - ** Mon Mar 11 16:33:02 MST 1991, RWM, Modified to add - ** support for adaptive matching. - ** (c) Copyright Hewlett-Packard Company, 1988. + ** Filename: intmatcher.cpp + ** Purpose: Generic high level classification routines. + ** Author: Robert Moss + ** (c) Copyright Hewlett-Packard Company, 1988. ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. ** You may obtain a copy of the License at @@ -927,7 +924,7 @@ void IntegerMatcher::DebugFeatureProtoError( const ScratchEvidence& tables, int16_t NumFeatures, int Debug) { - FLOAT32 ProtoConfigs[MAX_NUM_CONFIGS]; + float ProtoConfigs[MAX_NUM_CONFIGS]; int ConfigNum; uint32_t ConfigWord; int ProtoSetIndex; @@ -946,8 +943,7 @@ void IntegerMatcher::DebugFeatureProtoError( for (ConfigNum = 0; ConfigNum < ClassTemplate->NumConfigs; ConfigNum++) { cprintf( " %5.1f", - 100.0 * (1.0 - - (FLOAT32) tables.sum_feature_evidence_[ConfigNum] + 100.0 * (1.0 - (float)tables.sum_feature_evidence_[ConfigNum] / NumFeatures / 256.0)); } cprintf("\n\n\n"); diff --git a/src/classify/intmatcher.h b/src/classify/intmatcher.h index fac195f5b9..af2f211825 100644 --- a/src/classify/intmatcher.h +++ b/src/classify/intmatcher.h @@ -45,7 +45,7 @@ struct UnicharRating; struct CP_RESULT_STRUCT { CP_RESULT_STRUCT() : Rating(0.0f), Class(0) {} - FLOAT32 Rating; + float Rating; CLASS_ID Class; }; diff --git a/src/classify/intproto.cpp b/src/classify/intproto.cpp index f61290b3ce..72750f88ab 100644 --- a/src/classify/intproto.cpp +++ b/src/classify/intproto.cpp @@ -125,9 +125,9 @@ FILL_SPEC; /*--------------------------------------------------------------------------- Private Function Prototypes ----------------------------------------------------------------------------*/ -FLOAT32 BucketStart(int Bucket, FLOAT32 Offset, int NumBuckets); +float BucketStart(int Bucket, float Offset, int NumBuckets); -FLOAT32 BucketEnd(int Bucket, FLOAT32 Offset, int NumBuckets); +float BucketEnd(int Bucket, float Offset, int NumBuckets); void DoFill(FILL_SPEC *FillSpec, CLASS_PRUNER_STRUCT* Pruner, @@ -139,23 +139,23 @@ bool FillerDone(TABLE_FILLER* Filler); void FillPPCircularBits(uint32_t ParamTable[NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR], - int Bit, FLOAT32 Center, FLOAT32 Spread, bool debug); + int Bit, float Center, float Spread, bool debug); void FillPPLinearBits(uint32_t ParamTable[NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR], - int Bit, FLOAT32 Center, FLOAT32 Spread, bool debug); + int Bit, float Center, float Spread, bool debug); void GetCPPadsForLevel(int Level, - FLOAT32 *EndPad, - FLOAT32 *SidePad, - FLOAT32 *AnglePad); + float *EndPad, + float *SidePad, + float *AnglePad); -ScrollView::Color GetMatchColorFor(FLOAT32 Evidence); +ScrollView::Color GetMatchColorFor(float Evidence); void GetNextFill(TABLE_FILLER *Filler, FILL_SPEC *Fill); -void InitTableFiller(FLOAT32 EndPad, - FLOAT32 SidePad, - FLOAT32 AnglePad, +void InitTableFiller(float EndPad, + float SidePad, + float AnglePad, PROTO Proto, TABLE_FILLER *Filler); @@ -169,7 +169,7 @@ void RenderIntProto(ScrollView *window, ScrollView::Color color); #endif // GRAPHICS_DISABLED -int TruncateParam(FLOAT32 Param, int Min, int Max, char *Id); +int TruncateParam(float Param, int Min, int Max, char *Id); /*----------------------------------------------------------------------------- Global Data Definitions and Declarations @@ -348,7 +348,7 @@ void AddProtoToClassPruner (PROTO Proto, CLASS_ID ClassId, uint32_t ClassCount; uint32_t WordIndex; int Level; - FLOAT32 EndPad, SidePad, AnglePad; + float EndPad, SidePad, AnglePad; TABLE_FILLER TableFiller; FILL_SPEC FillSpec; @@ -383,8 +383,8 @@ void AddProtoToClassPruner (PROTO Proto, CLASS_ID ClassId, */ void AddProtoToProtoPruner(PROTO Proto, int ProtoId, INT_CLASS Class, bool debug) { - FLOAT32 Angle, X, Y, Length; - FLOAT32 Pad; + float Angle, X, Y, Length; + float Pad; int Index; PROTO_SET ProtoSet; @@ -432,11 +432,11 @@ void AddProtoToProtoPruner(PROTO Proto, int ProtoId, * notionally (param + offset) * num_buckets, but clipped and casted to the * appropriate type. */ -uint8_t Bucket8For(FLOAT32 param, FLOAT32 offset, int num_buckets) { +uint8_t Bucket8For(float param, float offset, int num_buckets) { int bucket = IntCastRounded(MapParam(param, offset, num_buckets)); return static_cast(ClipToRange(bucket, 0, num_buckets - 1)); } -uint16_t Bucket16For(FLOAT32 param, FLOAT32 offset, int num_buckets) { +uint16_t Bucket16For(float param, float offset, int num_buckets) { int bucket = IntCastRounded(MapParam(param, offset, num_buckets)); return static_cast(ClipToRange(bucket, 0, num_buckets - 1)); } @@ -446,7 +446,7 @@ uint16_t Bucket16For(FLOAT32 param, FLOAT32 offset, int num_buckets) { * notionally (param + offset) * num_buckets, but modded and casted to the * appropriate type. */ -uint8_t CircBucketFor(FLOAT32 param, FLOAT32 offset, int num_buckets) { +uint8_t CircBucketFor(float param, float offset, int num_buckets) { int bucket = IntCastRounded(MapParam(param, offset, num_buckets)); return static_cast(Modulo(bucket, num_buckets)); } /* CircBucketFor */ @@ -515,7 +515,7 @@ namespace tesseract { */ void Classify::ConvertProto(PROTO Proto, int ProtoId, INT_CLASS Class) { INT_PROTO P; - FLOAT32 Param; + float Param; assert(ProtoId < Class->NumProtos); @@ -620,7 +620,7 @@ INT_TEMPLATES Classify::CreateIntTemplates(CLASSES FloatProtos, * @note Exceptions: none * @note History: Thu Mar 21 14:45:04 1991, DSJ, Created. */ -void DisplayIntFeature(const INT_FEATURE_STRUCT *Feature, FLOAT32 Evidence) { +void DisplayIntFeature(const INT_FEATURE_STRUCT *Feature, float Evidence) { ScrollView::Color color = GetMatchColorFor(Evidence); RenderIntFeature(IntMatchWindow, Feature, color); if (FeatureDisplayWindow) { @@ -641,7 +641,7 @@ void DisplayIntFeature(const INT_FEATURE_STRUCT *Feature, FLOAT32 Evidence) { * @note Exceptions: none * @note History: Thu Mar 21 14:45:04 1991, DSJ, Created. */ -void DisplayIntProto(INT_CLASS Class, PROTO_ID ProtoId, FLOAT32 Evidence) { +void DisplayIntProto(INT_CLASS Class, PROTO_ID ProtoId, float Evidence) { ScrollView::Color color = GetMatchColorFor(Evidence); RenderIntProto(IntMatchWindow, Class, ProtoId, color); if (ProtoDisplayWindow) { @@ -1142,8 +1142,8 @@ void Classify::WriteIntTemplates(FILE *File, INT_TEMPLATES Templates, * @note Exceptions: none * @note History: Thu Feb 14 13:24:33 1991, DSJ, Created. */ -FLOAT32 BucketStart(int Bucket, FLOAT32 Offset, int NumBuckets) { - return (((FLOAT32) Bucket / NumBuckets) - Offset); +float BucketStart(int Bucket, float Offset, int NumBuckets) { + return (((float) Bucket / NumBuckets) - Offset); } /* BucketStart */ @@ -1160,8 +1160,8 @@ FLOAT32 BucketStart(int Bucket, FLOAT32 Offset, int NumBuckets) { * @note Exceptions: none * @note History: Thu Feb 14 13:24:33 1991, DSJ, Created. */ -FLOAT32 BucketEnd(int Bucket, FLOAT32 Offset, int NumBuckets) { - return (((FLOAT32) (Bucket + 1) / NumBuckets) - Offset); +float BucketEnd(int Bucket, float Offset, int NumBuckets) { + return (((float) (Bucket + 1) / NumBuckets) - Offset); } /* BucketEnd */ /** @@ -1247,7 +1247,7 @@ bool FillerDone(TABLE_FILLER* Filler) { * @note History: Tue Oct 16 09:26:54 1990, DSJ, Created. */ void FillPPCircularBits(uint32_t ParamTable[NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR], - int Bit, FLOAT32 Center, FLOAT32 Spread, bool debug) { + int Bit, float Center, float Spread, bool debug) { int i, FirstBucket, LastBucket; if (Spread > 0.5) @@ -1290,7 +1290,7 @@ void FillPPCircularBits(uint32_t ParamTable[NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR] * @note History: Tue Oct 16 09:26:54 1990, DSJ, Created. */ void FillPPLinearBits(uint32_t ParamTable[NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR], - int Bit, FLOAT32 Center, FLOAT32 Spread, bool debug) { + int Bit, float Center, float Spread, bool debug) { int i, FirstBucket, LastBucket; FirstBucket = (int) floor ((Center - Spread) * NUM_PP_BUCKETS); @@ -1404,9 +1404,9 @@ CLASS_ID Classify::GetClassToDebug(const char *Prompt, bool* adaptive_on, * @note History: Thu Feb 14 08:26:49 1991, DSJ, Created. */ void GetCPPadsForLevel(int Level, - FLOAT32 *EndPad, - FLOAT32 *SidePad, - FLOAT32 *AnglePad) { + float *EndPad, + float *SidePad, + float *AnglePad) { switch (Level) { case 0: *EndPad = classify_cp_end_pad_loose * GetPicoFeatureLength (); @@ -1444,7 +1444,7 @@ void GetCPPadsForLevel(int Level, * @note Exceptions: none * @note History: Thu Mar 21 15:24:52 1991, DSJ, Created. */ -ScrollView::Color GetMatchColorFor(FLOAT32 Evidence) { +ScrollView::Color GetMatchColorFor(float Evidence) { assert (Evidence >= 0.0); assert (Evidence <= 1.0); @@ -1522,17 +1522,17 @@ void GetNextFill(TABLE_FILLER *Filler, FILL_SPEC *Fill) { * @note Exceptions: none * @note History: Thu Feb 14 09:27:05 1991, DSJ, Created. */ -void InitTableFiller (FLOAT32 EndPad, FLOAT32 SidePad, - FLOAT32 AnglePad, PROTO Proto, TABLE_FILLER * Filler) +void InitTableFiller (float EndPad, float SidePad, + float AnglePad, PROTO Proto, TABLE_FILLER * Filler) #define XS X_SHIFT #define YS Y_SHIFT #define AS ANGLE_SHIFT #define NB NUM_CP_BUCKETS { - FLOAT32 Angle; - FLOAT32 X, Y, HalfLength; - FLOAT32 Cos, Sin; - FLOAT32 XAdjust, YAdjust; + float Angle; + float X, Y, HalfLength; + float Cos, Sin; + float XAdjust, YAdjust; FPOINT Start, Switch1, Switch2, End; int S1 = 0; int S2 = 1; @@ -1689,7 +1689,7 @@ void InitTableFiller (FLOAT32 EndPad, FLOAT32 SidePad, */ void RenderIntFeature(ScrollView *window, const INT_FEATURE_STRUCT* Feature, ScrollView::Color color) { - FLOAT32 X, Y, Dx, Dy, Length; + float X, Y, Dx, Dy, Length; window->Pen(color); assert(Feature != nullptr); @@ -1731,9 +1731,9 @@ void RenderIntProto(ScrollView *window, INT_PROTO Proto; int ProtoSetIndex; int ProtoWordIndex; - FLOAT32 Length; + float Length; int Xmin, Xmax, Ymin, Ymax; - FLOAT32 X, Y, Dx, Dy; + float X, Y, Dx, Dy; uint32_t ProtoMask; int Bucket; @@ -1790,7 +1790,7 @@ void RenderIntProto(ScrollView *window, * @note Exceptions: none * @note History: Fri Feb 8 11:54:28 1991, DSJ, Created. */ -int TruncateParam(FLOAT32 Param, int Min, int Max, char *Id) { +int TruncateParam(float Param, int Min, int Max, char *Id) { if (Param < Min) { if (Id) cprintf("Warning: Param %s truncated from %f to %d!\n", diff --git a/src/classify/intproto.h b/src/classify/intproto.h index 04259b7513..90e2711168 100644 --- a/src/classify/intproto.h +++ b/src/classify/intproto.h @@ -1,10 +1,10 @@ /****************************************************************************** - ** Filename: intproto.h - ** Purpose: Definition of data structures for integer protos. - ** Author: Dan Johnson - ** History: Thu Feb 7 12:58:45 1991, DSJ, Created. + ** Filename: intproto.h + ** Purpose: Definition of data structures for integer protos. + ** Author: Dan Johnson + ** History: Thu Feb 7 12:58:45 1991, DSJ, Created. ** - ** (c) Copyright Hewlett-Packard Company, 1988. + ** (c) Copyright Hewlett-Packard Company, 1988. ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. ** You may obtain a copy of the License at @@ -14,7 +14,8 @@ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ** See the License for the specific language governing permissions and ** limitations under the License. - ******************************************************************************/ + *****************************************************************************/ + #ifndef INTPROTO_H #define INTPROTO_H @@ -31,42 +32,41 @@ class FCOORD; /* define order of params in pruners */ -#define PRUNER_X 0 -#define PRUNER_Y 1 -#define PRUNER_ANGLE 2 +#define PRUNER_X 0 +#define PRUNER_Y 1 +#define PRUNER_ANGLE 2 /* definition of coordinate system offsets for each table parameter */ #define ANGLE_SHIFT (0.0) -#define X_SHIFT (0.5) -#define Y_SHIFT (0.5) +#define X_SHIFT (0.5) +#define Y_SHIFT (0.5) -#define MAX_PROTO_INDEX 24 -#define BITS_PER_WERD static_cast(8 * sizeof(uint32_t)) +#define MAX_PROTO_INDEX 24 +#define BITS_PER_WERD static_cast(8 * sizeof(uint32_t)) /* Script detection: increase this number to 128 */ -#define MAX_NUM_CONFIGS 64 -#define MAX_NUM_PROTOS 512 -#define PROTOS_PER_PROTO_SET 64 -#define MAX_NUM_PROTO_SETS (MAX_NUM_PROTOS / PROTOS_PER_PROTO_SET) -#define NUM_PP_PARAMS 3 -#define NUM_PP_BUCKETS 64 -#define NUM_CP_BUCKETS 24 -#define CLASSES_PER_CP 32 -#define NUM_BITS_PER_CLASS 2 +#define MAX_NUM_CONFIGS 64 +#define MAX_NUM_PROTOS 512 +#define PROTOS_PER_PROTO_SET 64 +#define MAX_NUM_PROTO_SETS (MAX_NUM_PROTOS / PROTOS_PER_PROTO_SET) +#define NUM_PP_PARAMS 3 +#define NUM_PP_BUCKETS 64 +#define NUM_CP_BUCKETS 24 +#define CLASSES_PER_CP 32 +#define NUM_BITS_PER_CLASS 2 #define CLASS_PRUNER_CLASS_MASK (~(~0u << NUM_BITS_PER_CLASS)) #define CLASSES_PER_CP_WERD (CLASSES_PER_CP / NUM_BITS_PER_CLASS) -#define PROTOS_PER_PP_WERD BITS_PER_WERD -#define BITS_PER_CP_VECTOR (CLASSES_PER_CP * NUM_BITS_PER_CLASS) -#define MAX_NUM_CLASS_PRUNERS ((MAX_NUM_CLASSES + CLASSES_PER_CP - 1) / \ - CLASSES_PER_CP) +#define PROTOS_PER_PP_WERD BITS_PER_WERD +#define BITS_PER_CP_VECTOR (CLASSES_PER_CP * NUM_BITS_PER_CLASS) +#define MAX_NUM_CLASS_PRUNERS \ + ((MAX_NUM_CLASSES + CLASSES_PER_CP - 1) / CLASSES_PER_CP) #define WERDS_PER_CP_VECTOR (BITS_PER_CP_VECTOR / BITS_PER_WERD) -#define WERDS_PER_PP_VECTOR ((PROTOS_PER_PROTO_SET+BITS_PER_WERD-1)/ \ - BITS_PER_WERD) -#define WERDS_PER_PP (NUM_PP_PARAMS * NUM_PP_BUCKETS * \ - WERDS_PER_PP_VECTOR) -#define WERDS_PER_CP (NUM_CP_BUCKETS * NUM_CP_BUCKETS * \ - NUM_CP_BUCKETS * WERDS_PER_CP_VECTOR) -#define WERDS_PER_CONFIG_VEC ((MAX_NUM_CONFIGS + BITS_PER_WERD - 1) / \ - BITS_PER_WERD) +#define WERDS_PER_PP_VECTOR \ + ((PROTOS_PER_PROTO_SET + BITS_PER_WERD - 1) / BITS_PER_WERD) +#define WERDS_PER_PP (NUM_PP_PARAMS * NUM_PP_BUCKETS * WERDS_PER_PP_VECTOR) +#define WERDS_PER_CP \ + (NUM_CP_BUCKETS * NUM_CP_BUCKETS * NUM_CP_BUCKETS * WERDS_PER_CP_VECTOR) +#define WERDS_PER_CONFIG_VEC \ + ((MAX_NUM_CONFIGS + BITS_PER_WERD - 1) / BITS_PER_WERD) /* The first 3 dimensions of the CLASS_PRUNER_STRUCT are the * 3 axes of the quantized feature space. @@ -74,11 +74,11 @@ class FCOORD; * 4th dimension is determined by using CPrunerWordIndexFor(c), * where c is the corresponding class id. */ struct CLASS_PRUNER_STRUCT { - uint32_t p[NUM_CP_BUCKETS][NUM_CP_BUCKETS][NUM_CP_BUCKETS][WERDS_PER_CP_VECTOR]; + uint32_t p[NUM_CP_BUCKETS][NUM_CP_BUCKETS][NUM_CP_BUCKETS] + [WERDS_PER_CP_VECTOR]; }; -typedef struct -{ +typedef struct { int8_t A; uint8_t B; int8_t C; @@ -86,54 +86,51 @@ typedef struct uint32_t Configs[WERDS_PER_CONFIG_VEC]; } +INT_PROTO_STRUCT, + *INT_PROTO; -INT_PROTO_STRUCT, *INT_PROTO; - -typedef uint32_t PROTO_PRUNER[NUM_PP_PARAMS][NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR]; +typedef uint32_t PROTO_PRUNER[NUM_PP_PARAMS][NUM_PP_BUCKETS] + [WERDS_PER_PP_VECTOR]; -typedef struct -{ +typedef struct { PROTO_PRUNER ProtoPruner; INT_PROTO_STRUCT Protos[PROTOS_PER_PROTO_SET]; } - -PROTO_SET_STRUCT, *PROTO_SET; +PROTO_SET_STRUCT, + *PROTO_SET; typedef uint32_t CONFIG_PRUNER[NUM_PP_PARAMS][NUM_PP_BUCKETS][4]; - -typedef struct -{ +typedef struct { uint16_t NumProtos; uint8_t NumProtoSets; uint8_t NumConfigs; PROTO_SET ProtoSets[MAX_NUM_PROTO_SETS]; - uint8_t *ProtoLengths; + uint8_t* ProtoLengths; uint16_t ConfigLengths[MAX_NUM_CONFIGS]; int font_set_id; // FontSet id, see above } +INT_CLASS_STRUCT, + *INT_CLASS; -INT_CLASS_STRUCT, *INT_CLASS; - -typedef struct -{ +typedef struct { int NumClasses; int NumClassPruners; INT_CLASS Class[MAX_NUM_CLASSES]; CLASS_PRUNER_STRUCT* ClassPruners[MAX_NUM_CLASS_PRUNERS]; } - -INT_TEMPLATES_STRUCT, *INT_TEMPLATES; +INT_TEMPLATES_STRUCT, + *INT_TEMPLATES; /* definitions of integer features*/ #define MAX_NUM_INT_FEATURES 512 -#define INT_CHAR_NORM_RANGE 256 +#define INT_CHAR_NORM_RANGE 256 struct INT_FEATURE_STRUCT { - INT_FEATURE_STRUCT() : X(0), Y(0), Theta(0), CP_misses(0) { } + INT_FEATURE_STRUCT() : X(0), Y(0), Theta(0), CP_misses(0) {} // Builds a feature from an FCOORD for position with all the necessary // clipping and rounding. INT_FEATURE_STRUCT(const FCOORD& pos, uint8_t theta); @@ -145,12 +142,10 @@ struct INT_FEATURE_STRUCT { uint8_t Theta; int8_t CP_misses; - void print() const { - tprintf("(%d,%d):%d\n", X, Y, Theta); - } + void print() const { tprintf("(%d,%d):%d\n", X, Y, Theta); } }; -typedef INT_FEATURE_STRUCT *INT_FEATURE; +typedef INT_FEATURE_STRUCT* INT_FEATURE; typedef INT_FEATURE_STRUCT INT_FEATURE_ARRAY[MAX_NUM_INT_FEATURES]; @@ -165,26 +160,27 @@ enum IntmatcherDebugAction { Macros ----------------------------------------------------------------------------**/ -#define MaxNumIntProtosIn(C) (C->NumProtoSets * PROTOS_PER_PROTO_SET) -#define SetForProto(P) (P / PROTOS_PER_PROTO_SET) -#define IndexForProto(P) (P % PROTOS_PER_PROTO_SET) -#define ProtoForProtoId(C,P) (&((C->ProtoSets[SetForProto (P)])-> \ - Protos [IndexForProto (P)])) -#define PPrunerWordIndexFor(I) (((I) % PROTOS_PER_PROTO_SET) / \ - PROTOS_PER_PP_WERD) +#define MaxNumIntProtosIn(C) (C->NumProtoSets * PROTOS_PER_PROTO_SET) +#define SetForProto(P) (P / PROTOS_PER_PROTO_SET) +#define IndexForProto(P) (P % PROTOS_PER_PROTO_SET) +#define ProtoForProtoId(C, P) \ + (&((C->ProtoSets[SetForProto(P)])->Protos[IndexForProto(P)])) +#define PPrunerWordIndexFor(I) \ + (((I) % PROTOS_PER_PROTO_SET) / PROTOS_PER_PP_WERD) #define PPrunerBitIndexFor(I) ((I) % PROTOS_PER_PP_WERD) -#define PPrunerMaskFor(I) (1 << PPrunerBitIndexFor (I)) - -#define MaxNumClassesIn(T) (T->NumClassPruners * CLASSES_PER_CP) -#define LegalClassId(c) ((c) >= 0 && (c) <= MAX_CLASS_ID) -#define UnusedClassIdIn(T,c) ((T)->Class[c] == nullptr) -#define ClassForClassId(T,c) ((T)->Class[c]) -#define ClassPrunersFor(T) ((T)->ClassPruner) -#define CPrunerIdFor(c) ((c) / CLASSES_PER_CP) -#define CPrunerFor(T,c) ((T)->ClassPruners[CPrunerIdFor(c)]) -#define CPrunerWordIndexFor(c) (((c) % CLASSES_PER_CP) / CLASSES_PER_CP_WERD) +#define PPrunerMaskFor(I) (1 << PPrunerBitIndexFor(I)) + +#define MaxNumClassesIn(T) (T->NumClassPruners * CLASSES_PER_CP) +#define LegalClassId(c) ((c) >= 0 && (c) <= MAX_CLASS_ID) +#define UnusedClassIdIn(T, c) ((T)->Class[c] == nullptr) +#define ClassForClassId(T, c) ((T)->Class[c]) +#define ClassPrunersFor(T) ((T)->ClassPruner) +#define CPrunerIdFor(c) ((c) / CLASSES_PER_CP) +#define CPrunerFor(T, c) ((T)->ClassPruners[CPrunerIdFor(c)]) +#define CPrunerWordIndexFor(c) (((c) % CLASSES_PER_CP) / CLASSES_PER_CP_WERD) #define CPrunerBitIndexFor(c) (((c) % CLASSES_PER_CP) % CLASSES_PER_CP_WERD) -#define CPrunerMaskFor(L,c) (((L)+1) << CPrunerBitIndexFor (c) * NUM_BITS_PER_CLASS) +#define CPrunerMaskFor(L, c) \ + (((L) + 1) << CPrunerBitIndexFor(c) * NUM_BITS_PER_CLASS) /* DEBUG macros*/ #define PRINT_MATCH_SUMMARY 0x001 @@ -194,13 +190,13 @@ enum IntmatcherDebugAction { #define PRINT_PROTO_MATCHES 0x010 #define CLIP_MATCH_EVIDENCE 0x020 -#define MatchDebuggingOn(D) (D) -#define PrintMatchSummaryOn(D) ((D) & PRINT_MATCH_SUMMARY) -#define DisplayFeatureMatchesOn(D) ((D) & DISPLAY_FEATURE_MATCHES) -#define DisplayProtoMatchesOn(D) ((D) & DISPLAY_PROTO_MATCHES) -#define PrintFeatureMatchesOn(D) ((D) & PRINT_FEATURE_MATCHES) -#define PrintProtoMatchesOn(D) ((D) & PRINT_PROTO_MATCHES) -#define ClipMatchEvidenceOn(D) ((D) & CLIP_MATCH_EVIDENCE) +#define MatchDebuggingOn(D) (D) +#define PrintMatchSummaryOn(D) ((D)&PRINT_MATCH_SUMMARY) +#define DisplayFeatureMatchesOn(D) ((D)&DISPLAY_FEATURE_MATCHES) +#define DisplayProtoMatchesOn(D) ((D)&DISPLAY_PROTO_MATCHES) +#define PrintFeatureMatchesOn(D) ((D)&PRINT_FEATURE_MATCHES) +#define PrintProtoMatchesOn(D) ((D)&PRINT_PROTO_MATCHES) +#define ClipMatchEvidenceOn(D) ((D)&CLIP_MATCH_EVIDENCE) /**---------------------------------------------------------------------------- Public Function Prototypes @@ -211,25 +207,24 @@ int AddIntConfig(INT_CLASS Class); int AddIntProto(INT_CLASS Class); -void AddProtoToClassPruner(PROTO Proto, - CLASS_ID ClassId, +void AddProtoToClassPruner(PROTO Proto, CLASS_ID ClassId, INT_TEMPLATES Templates); -void AddProtoToProtoPruner(PROTO Proto, int ProtoId, - INT_CLASS Class, bool debug); +void AddProtoToProtoPruner(PROTO Proto, int ProtoId, INT_CLASS Class, + bool debug); -uint8_t Bucket8For(FLOAT32 param, FLOAT32 offset, int num_buckets); -uint16_t Bucket16For(FLOAT32 param, FLOAT32 offset, int num_buckets); +uint8_t Bucket8For(float param, float offset, int num_buckets); +uint16_t Bucket16For(float param, float offset, int num_buckets); -uint8_t CircBucketFor(FLOAT32 param, FLOAT32 offset, int num_buckets); +uint8_t CircBucketFor(float param, float offset, int num_buckets); void UpdateMatchDisplay(); void ConvertConfig(BIT_VECTOR Config, int ConfigId, INT_CLASS Class); -void DisplayIntFeature(const INT_FEATURE_STRUCT* Feature, FLOAT32 Evidence); +void DisplayIntFeature(const INT_FEATURE_STRUCT* Feature, float Evidence); -void DisplayIntProto(INT_CLASS Class, PROTO_ID ProtoId, FLOAT32 Evidence); +void DisplayIntProto(INT_CLASS Class, PROTO_ID ProtoId, float Evidence); INT_CLASS NewIntClass(int MaxNumProtos, int MaxNumConfigs); @@ -249,7 +244,7 @@ void ClearFeatureSpaceWindow(NORM_METHOD norm_method, ScrollView* window); /*----------------------------------------------------------------------------*/ #ifndef GRAPHICS_DISABLED -void RenderIntFeature(ScrollView *window, const INT_FEATURE_STRUCT* Feature, +void RenderIntFeature(ScrollView* window, const INT_FEATURE_STRUCT* Feature, ScrollView::Color color); void InitIntMatchWindowIfReqd(); diff --git a/src/classify/kdtree.cpp b/src/classify/kdtree.cpp index 8e4860bad1..0bc70ea94e 100644 --- a/src/classify/kdtree.cpp +++ b/src/classify/kdtree.cpp @@ -2,9 +2,6 @@ ** Filename: kdtree.cpp ** Purpose: Routines for managing K-D search trees ** Author: Dan Johnson - ** History: 3/10/89, DSJ, Created. - ** 5/23/89, DSJ, Added circular feature capability. - ** 7/13/89, DSJ, Made tree nodes invisible to outside. ** ** (c) Copyright Hewlett-Packard Company, 1988. ** Licensed under the Apache License, Version 2.0 (the "License"); @@ -123,27 +120,27 @@ bool MinK::insert(Key key, Value value) { */ class KDTreeSearch { public: - KDTreeSearch(KDTREE* tree, FLOAT32 *query_point, int k_closest); + KDTreeSearch(KDTREE* tree, float *query_point, int k_closest); ~KDTreeSearch(); /** Return the k nearest points' data. */ - void Search(int *result_count, FLOAT32 *distances, void **results); + void Search(int *result_count, float *distances, void **results); private: void SearchRec(int Level, KDNODE *SubTree); - bool BoxIntersectsSearch(FLOAT32 *lower, FLOAT32 *upper); + bool BoxIntersectsSearch(float *lower, float *upper); KDTREE *tree_; - FLOAT32 *query_point_; - FLOAT32 *sb_min_; //< search box minimum - FLOAT32 *sb_max_; //< search box maximum - MinK results_; + float *query_point_; + float *sb_min_; //< search box minimum + float *sb_max_; //< search box maximum + MinK results_; }; -KDTreeSearch::KDTreeSearch(KDTREE *tree, FLOAT32 *query_point, int k_closest) +KDTreeSearch::KDTreeSearch(KDTREE *tree, float *query_point, int k_closest) : tree_(tree), query_point_(query_point), results_(MAXSEARCH, k_closest) { - sb_min_ = new FLOAT32[tree->KeySize]; - sb_max_ = new FLOAT32[tree->KeySize]; + sb_min_ = new float[tree->KeySize]; + sb_max_ = new float[tree->KeySize]; } KDTreeSearch::~KDTreeSearch() { @@ -154,7 +151,7 @@ KDTreeSearch::~KDTreeSearch() { /// Locate the k_closest points to query_point_, and return their distances and /// data into the given buffers. void KDTreeSearch::Search(int *result_count, - FLOAT32 *distances, + float *distances, void **results) { if (tree_->Root.Left == nullptr) { *result_count = 0; @@ -169,7 +166,7 @@ void KDTreeSearch::Search(int *result_count, for (int j = 0; j < count; j++) { // Pre-cast to float64 as key is a template type and we have no control // over its actual type. - distances[j] = (FLOAT32)sqrt((double)results_.elements()[j].key); + distances[j] = (float)sqrt((double)results_.elements()[j].key); results[j] = results_.elements()[j].value; } } @@ -217,7 +214,7 @@ KDTREE *MakeKDTree(int16_t KeySize, const PARAM_DESC KeyDesc[]) { * @note History: 3/10/89, DSJ, Created. * 7/13/89, DSJ, Changed return to void. */ -void KDStore(KDTREE *Tree, FLOAT32 *Key, void *Data) { +void KDStore(KDTREE *Tree, float *Key, void *Data) { int Level; KDNODE *Node; KDNODE **PtrToNode; @@ -263,7 +260,7 @@ void KDStore(KDTREE *Tree, FLOAT32 *Key, void *Data) { * 7/13/89, DSJ, Specify node indirectly by key and data. */ void -KDDelete (KDTREE * Tree, FLOAT32 Key[], void *Data) { +KDDelete (KDTREE * Tree, float Key[], void *Data) { int Level; KDNODE *Current; KDNODE *Father; @@ -320,8 +317,8 @@ KDDelete (KDTREE * Tree, FLOAT32 Key[], void *Data) { * - 7/13/89, DSJ, Return contents of node instead of node itself. */ void KDNearestNeighborSearch( - KDTREE *Tree, FLOAT32 Query[], int QuerySize, FLOAT32 MaxDistance, - int *NumberOfResults, void **NBuffer, FLOAT32 DBuffer[]) { + KDTREE *Tree, float Query[], int QuerySize, float MaxDistance, + int *NumberOfResults, void **NBuffer, float DBuffer[]) { KDTreeSearch search(Tree, Query, QuerySize); search.Search(NumberOfResults, DBuffer, NBuffer); } @@ -371,7 +368,7 @@ void FreeKDTree(KDTREE *Tree) { * @note Exceptions: None * @note History: 3/11/89, DSJ, Created. */ -KDNODE *MakeKDNode(KDTREE *tree, FLOAT32 Key[], void *Data, int Index) { +KDNODE *MakeKDNode(KDTREE *tree, float Key[], void *Data, int Index) { KDNODE *NewNode; NewNode = (KDNODE *) Emalloc (sizeof (KDNODE)); @@ -410,26 +407,26 @@ void KDTreeSearch::SearchRec(int level, KDNODE *sub_tree) { if (query_point_[level] < sub_tree->BranchPoint) { if (sub_tree->Left != nullptr) { - FLOAT32 tmp = sb_max_[level]; + float tmp = sb_max_[level]; sb_max_[level] = sub_tree->LeftBranch; SearchRec(NextLevel(tree_, level), sub_tree->Left); sb_max_[level] = tmp; } if (sub_tree->Right != nullptr) { - FLOAT32 tmp = sb_min_[level]; + float tmp = sb_min_[level]; sb_min_[level] = sub_tree->RightBranch; SearchRec(NextLevel(tree_, level), sub_tree->Right); sb_min_[level] = tmp; } } else { if (sub_tree->Right != nullptr) { - FLOAT32 tmp = sb_min_[level]; + float tmp = sb_min_[level]; sb_min_[level] = sub_tree->RightBranch; SearchRec(NextLevel(tree_, level), sub_tree->Right); sb_min_[level] = tmp; } if (sub_tree->Left != nullptr) { - FLOAT32 tmp = sb_max_[level]; + float tmp = sb_max_[level]; sb_max_[level] = sub_tree->LeftBranch; SearchRec(NextLevel(tree_, level), sub_tree->Left); sb_max_[level] = tmp; @@ -446,19 +443,19 @@ void KDTreeSearch::SearchRec(int level, KDNODE *sub_tree) { * @param dim dimension descriptions (essential, circular, etc) * @param p1,p2 two different points in K-D space */ -FLOAT32 DistanceSquared(int k, PARAM_DESC *dim, FLOAT32 p1[], FLOAT32 p2[]) { - FLOAT32 total_distance = 0; +float DistanceSquared(int k, PARAM_DESC *dim, float p1[], float p2[]) { + float total_distance = 0; for (; k > 0; k--, p1++, p2++, dim++) { if (dim->NonEssential) continue; - FLOAT32 dimension_distance = *p1 - *p2; + float dimension_distance = *p1 - *p2; /* if this dimension is circular - check wraparound distance */ if (dim->Circular) { dimension_distance = Magnitude(dimension_distance); - FLOAT32 wrap_distance = dim->Max - dim->Min - dimension_distance; + float wrap_distance = dim->Max - dim->Min - dimension_distance; dimension_distance = std::min(dimension_distance, wrap_distance); } @@ -467,7 +464,7 @@ FLOAT32 DistanceSquared(int k, PARAM_DESC *dim, FLOAT32 p1[], FLOAT32 p2[]) { return total_distance; } -FLOAT32 ComputeDistance(int k, PARAM_DESC *dim, FLOAT32 p1[], FLOAT32 p2[]) { +float ComputeDistance(int k, PARAM_DESC *dim, float p1[], float p2[]) { return sqrt(DistanceSquared(k, dim, p1, p2)); } @@ -476,8 +473,8 @@ FLOAT32 ComputeDistance(int k, PARAM_DESC *dim, FLOAT32 p1[], FLOAT32 p2[]) { /// query_point_ containing results->k_ points) intersects the box specified /// between lower and upper. For circular dimensions, we also check the point /// one wrap distance away from the query. -bool KDTreeSearch::BoxIntersectsSearch(FLOAT32 *lower, FLOAT32 *upper) { - FLOAT32 *query = query_point_; +bool KDTreeSearch::BoxIntersectsSearch(float *lower, float *upper) { + float *query = query_point_; // Compute the sum in higher precision. double total_distance = 0.0; double radius_squared = @@ -488,7 +485,7 @@ bool KDTreeSearch::BoxIntersectsSearch(FLOAT32 *lower, FLOAT32 *upper) { if (dim->NonEssential) continue; - FLOAT32 dimension_distance; + float dimension_distance; if (*query < *lower) dimension_distance = *lower - *query; else if (*query > *upper) @@ -498,7 +495,7 @@ bool KDTreeSearch::BoxIntersectsSearch(FLOAT32 *lower, FLOAT32 *upper) { /* if this dimension is circular - check wraparound distance */ if (dim->Circular) { - FLOAT32 wrap_distance = FLT_MAX; + float wrap_distance = FLT_MAX; if (*query < *lower) wrap_distance = *query + dim->Max - dim->Min - *upper; else if (*query > *upper) diff --git a/src/classify/kdtree.h b/src/classify/kdtree.h index a4e0c18365..5a5b5d49b3 100644 --- a/src/classify/kdtree.h +++ b/src/classify/kdtree.h @@ -1,11 +1,9 @@ /****************************************************************************** - ** Filename: kdtree.h - ** Purpose: Definition of K-D tree access routines. - ** Author: Dan Johnson - ** History: 3/11/89, DSJ, Created. - ** 5/23/89, DSJ, Added circular feature capability. + ** Filename: kdtree.h + ** Purpose: Definition of K-D tree access routines. + ** Author: Dan Johnson ** - ** (c) Copyright Hewlett-Packard Company, 1988. + ** (c) Copyright Hewlett-Packard Company, 1988. ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. ** You may obtain a copy of the License at @@ -37,17 +35,17 @@ correctly if circular parameters outside the specified range are used. */ struct KDNODE { - FLOAT32 *Key; /**< search key */ - void *Data; /**< data that corresponds to key */ - FLOAT32 BranchPoint; /**< needed to make deletes work efficiently */ - FLOAT32 LeftBranch; /**< used to optimize search pruning */ - FLOAT32 RightBranch; /**< used to optimize search pruning */ - struct KDNODE *Left; /**< ptrs for KD tree structure */ + float *Key; /**< search key */ + void *Data; /**< data that corresponds to key */ + float BranchPoint; /**< needed to make deletes work efficiently */ + float LeftBranch; /**< used to optimize search pruning */ + float RightBranch; /**< used to optimize search pruning */ + struct KDNODE *Left; /**< ptrs for KD tree structure */ struct KDNODE *Right; }; struct KDTREE { - int16_t KeySize; /* number of dimensions in the tree */ + int16_t KeySize; /* number of dimensions in the tree */ KDNODE Root; /* Root.Left points to actual root node */ PARAM_DESC KeyDesc[1]; /* description of each dimension */ }; @@ -62,13 +60,13 @@ struct KDTREE { -----------------------------------------------------------------------------*/ KDTREE *MakeKDTree(int16_t KeySize, const PARAM_DESC KeyDesc[]); -void KDStore(KDTREE *Tree, FLOAT32 *Key, void *Data); +void KDStore(KDTREE *Tree, float *Key, void *Data); -void KDDelete(KDTREE * Tree, FLOAT32 Key[], void *Data); +void KDDelete(KDTREE * Tree, float Key[], void *Data); void KDNearestNeighborSearch( - KDTREE *Tree, FLOAT32 Query[], int QuerySize, FLOAT32 MaxDistance, - int *NumberOfResults, void **NBuffer, FLOAT32 DBuffer[]); + KDTREE *Tree, float Query[], int QuerySize, float MaxDistance, + int *NumberOfResults, void **NBuffer, float DBuffer[]); void KDWalk(KDTREE *Tree, void_proc Action, void *context); @@ -77,13 +75,13 @@ void FreeKDTree(KDTREE *Tree); /*----------------------------------------------------------------------------- Private Function Prototypes -----------------------------------------------------------------------------*/ -KDNODE *MakeKDNode(KDTREE *tree, FLOAT32 Key[], void *Data, int Index); +KDNODE *MakeKDNode(KDTREE *tree, float Key[], void *Data, int Index); void FreeKDNode(KDNODE *Node); -FLOAT32 DistanceSquared(int k, PARAM_DESC *dim, FLOAT32 p1[], FLOAT32 p2[]); +float DistanceSquared(int k, PARAM_DESC *dim, float p1[], float p2[]); -FLOAT32 ComputeDistance(int k, PARAM_DESC *dim, FLOAT32 p1[], FLOAT32 p2[]); +float ComputeDistance(int k, PARAM_DESC *dim, float p1[], float p2[]); int QueryInSearch(KDTREE *tree); diff --git a/src/classify/mfdefs.h b/src/classify/mfdefs.h index 20a3e2189b..141891c450 100644 --- a/src/classify/mfdefs.h +++ b/src/classify/mfdefs.h @@ -1,10 +1,10 @@ /****************************************************************************** - ** Filename: mfdefs.h - ** Purpose: Definition of micro-features - ** Author: Dan Johnson - ** History: Mon Jan 22 08:42:13 1990, DSJ, Created. + ** Filename: mfdefs.h + ** Purpose: Definition of micro-features + ** Author: Dan Johnson + ** History: Mon Jan 22 08:42:13 1990, DSJ, Created. ** - ** (c) Copyright Hewlett-Packard Company, 1988. + ** (c) Copyright Hewlett-Packard Company, 1988. ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. ** You may obtain a copy of the License at @@ -29,8 +29,8 @@ typedef LIST MICROFEATURES; /* definition of structure of micro-features */ #define MFSIZE 6 -typedef FLOAT32 MFBLOCK[MFSIZE]; -typedef FLOAT32 *MICROFEATURE; +typedef float MFBLOCK[MFSIZE]; +typedef float *MICROFEATURE; /* definitions of individual micro-feature parameters */ #define XPOSITION 0 diff --git a/src/classify/mfoutline.cpp b/src/classify/mfoutline.cpp index bde7a055d2..dbbc98d920 100644 --- a/src/classify/mfoutline.cpp +++ b/src/classify/mfoutline.cpp @@ -119,8 +119,8 @@ LIST ConvertOutlines(TESSLINE *outline, * @note History: 7/21/89, DSJ, Created. */ void FindDirectionChanges(MFOUTLINE Outline, - FLOAT32 MinSlope, - FLOAT32 MaxSlope) { + float MinSlope, + float MaxSlope) { MFEDGEPT *Current; MFEDGEPT *Last; MFOUTLINE EdgePoint; @@ -262,7 +262,7 @@ MFOUTLINE NextExtremity(MFOUTLINE EdgePoint) { * @note History: 8/2/89, DSJ, Created. */ void NormalizeOutline(MFOUTLINE Outline, - FLOAT32 XOrigin) { + float XOrigin) { if (Outline == NIL_LIST) return; @@ -298,8 +298,8 @@ namespace tesseract { * @note History: Fri Dec 14 08:14:55 1990, DSJ, Created. */ void Classify::NormalizeOutlines(LIST Outlines, - FLOAT32 *XScale, - FLOAT32 *YScale) { + float *XScale, + float *YScale) { MFOUTLINE Outline; switch (classify_norm_method) { @@ -398,8 +398,8 @@ void CharNormalizeOutline(MFOUTLINE Outline, const DENORM& cn_denorm) { */ void ComputeDirection(MFEDGEPT *Start, MFEDGEPT *Finish, - FLOAT32 MinSlope, - FLOAT32 MaxSlope) { + float MinSlope, + float MaxSlope) { FVECTOR Delta; Delta.x = Finish->Point.x - Start->Point.x; diff --git a/src/classify/mfoutline.h b/src/classify/mfoutline.h index 750d83911c..a8b934ae07 100644 --- a/src/classify/mfoutline.h +++ b/src/classify/mfoutline.h @@ -1,10 +1,10 @@ /****************************************************************************** - ** Filename: mfoutline.h - ** Purpose: Interface spec for fx outline structures - ** Author: Dan Johnson - ** History: Thu May 17 08:55:32 1990, DSJ, Created. + ** Filename: mfoutline.h + ** Purpose: Interface spec for fx outline structures + ** Author: Dan Johnson + ** History: Thu May 17 08:55:32 1990, DSJ, Created. ** - ** (c) Copyright Hewlett-Packard Company, 1988. + ** (c) Copyright Hewlett-Packard Company, 1988. ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. ** You may obtain a copy of the License at @@ -15,8 +15,9 @@ ** See the License for the specific language governing permissions and ** limitations under the License. ******************************************************************************/ -#ifndef MFOUTLINE_H -#define MFOUTLINE_H + +#ifndef MFOUTLINE_H +#define MFOUTLINE_H /**---------------------------------------------------------------------------- Include Files and Type Defines @@ -38,7 +39,7 @@ typedef enum { typedef struct { FPOINT Point; - FLOAT32 Slope; + float Slope; unsigned Padding:20; BOOL8 Hidden:TRUE; BOOL8 ExtremityMark:TRUE; @@ -85,11 +86,11 @@ LIST ConvertOutlines(TESSLINE *Outline, LIST ConvertedOutlines, OUTLINETYPE OutlineType); -void FilterEdgeNoise(MFOUTLINE Outline, FLOAT32 NoiseSegmentLength); +void FilterEdgeNoise(MFOUTLINE Outline, float NoiseSegmentLength); void FindDirectionChanges(MFOUTLINE Outline, - FLOAT32 MinSlope, - FLOAT32 MaxSlope); + float MinSlope, + float MaxSlope); void FreeMFOutline(void *agr); //MFOUTLINE Outline); @@ -102,7 +103,7 @@ MFEDGEPT *NewEdgePoint(); MFOUTLINE NextExtremity(MFOUTLINE EdgePoint); void NormalizeOutline(MFOUTLINE Outline, - FLOAT32 XOrigin); + float XOrigin); /*---------------------------------------------------------------------------- Private Function Prototypes @@ -116,8 +117,8 @@ void CharNormalizeOutline(MFOUTLINE Outline, const DENORM& cn_denorm); void ComputeDirection(MFEDGEPT *Start, MFEDGEPT *Finish, - FLOAT32 MinSlope, - FLOAT32 MaxSlope); + float MinSlope, + float MaxSlope); MFOUTLINE NextDirectionChange(MFOUTLINE EdgePoint); diff --git a/src/classify/mfx.cpp b/src/classify/mfx.cpp index 54c6588e25..5b1905eaf3 100644 --- a/src/classify/mfx.cpp +++ b/src/classify/mfx.cpp @@ -47,7 +47,7 @@ double_VAR(classify_max_slope, 2.414213562, /*---------------------------------------------------------------------------- Private Function Prototypes -----------------------------------------------------------------------------*/ -FLOAT32 ComputeOrientation(MFEDGEPT *Start, MFEDGEPT *End); +float ComputeOrientation(MFEDGEPT *Start, MFEDGEPT *End); MICROFEATURES ConvertToMicroFeatures(MFOUTLINE Outline, MICROFEATURES MicroFeatures); @@ -117,10 +117,8 @@ MICROFEATURES BlobMicroFeatures(TBLOB* Blob, const DENORM& cn_denorm) { * @note Exceptions: none * @note History: 7/27/89, DSJ, Created. */ -FLOAT32 ComputeOrientation(MFEDGEPT *Start, MFEDGEPT *End) { - FLOAT32 Orientation; - - Orientation = NormalizeAngle (AngleFrom (Start->Point, End->Point)); +float ComputeOrientation(MFEDGEPT *Start, MFEDGEPT *End) { + float Orientation = NormalizeAngle(AngleFrom(Start->Point, End->Point)); /* ensure that round-off errors do not put circular param out of range */ if ((Orientation < 0) || (Orientation >= 1)) diff --git a/src/classify/normfeat.cpp b/src/classify/normfeat.cpp index f297b3b05d..233f2f57cc 100644 --- a/src/classify/normfeat.cpp +++ b/src/classify/normfeat.cpp @@ -29,7 +29,7 @@ ----------------------------------------------------------------------------*/ /** Return the length of the outline in baseline normalized form. */ -FLOAT32 ActualOutlineLength(FEATURE Feature) { +float ActualOutlineLength(FEATURE Feature) { return (Feature->Params[CharNormLength] * LENGTH_COMPRESSION); } diff --git a/src/classify/normfeat.h b/src/classify/normfeat.h index 1478b827d4..5660b81e54 100644 --- a/src/classify/normfeat.h +++ b/src/classify/normfeat.h @@ -1,10 +1,10 @@ /****************************************************************************** - ** Filename: normfeat.h - ** Purpose: Definition of character normalization features. - ** Author: Dan Johnson - ** History: 12/14/90, DSJ, Created. + ** Filename: normfeat.h + ** Purpose: Definition of character normalization features. + ** Author: Dan Johnson + ** History: 12/14/90, DSJ, Created. ** - ** (c) Copyright Hewlett-Packard Company, 1988. + ** (c) Copyright Hewlett-Packard Company, 1988. ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. ** You may obtain a copy of the License at @@ -14,9 +14,10 @@ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ** See the License for the specific language governing permissions and ** limitations under the License. - ******************************************************************************/ -#ifndef NORMFEAT_H -#define NORMFEAT_H + *****************************************************************************/ + +#ifndef NORMFEAT_H +#define NORMFEAT_H /**---------------------------------------------------------------------------- Include Files and Type Defines @@ -32,7 +33,7 @@ typedef enum { /**---------------------------------------------------------------------------- Public Function Prototypes ----------------------------------------------------------------------------**/ -FLOAT32 ActualOutlineLength(FEATURE Feature); +float ActualOutlineLength(FEATURE Feature); FEATURE_SET ExtractCharNormFeatures(const INT_FX_RESULT_STRUCT& fx_info); diff --git a/src/classify/normmatch.cpp b/src/classify/normmatch.cpp index ed1c15f9af..44ef7fe268 100644 --- a/src/classify/normmatch.cpp +++ b/src/classify/normmatch.cpp @@ -84,13 +84,13 @@ namespace tesseract { * @note Exceptions: none * @note History: Wed Dec 19 16:56:12 1990, DSJ, Created. */ -FLOAT32 Classify::ComputeNormMatch(CLASS_ID ClassId, - const FEATURE_STRUCT& feature, - bool DebugMatch) { +float Classify::ComputeNormMatch(CLASS_ID ClassId, + const FEATURE_STRUCT& feature, + bool DebugMatch) { LIST Protos; - FLOAT32 BestMatch; - FLOAT32 Match; - FLOAT32 Delta; + float BestMatch; + float Match; + float Delta; PROTOTYPE *Proto; int ProtoId; @@ -210,8 +210,8 @@ void PrintNormMatch(FILE *File, PROTOTYPE *Proto, FEATURE Feature) { int i; - FLOAT32 ParamMatch; - FLOAT32 TotalMatch; + float ParamMatch; + float TotalMatch; for (i = 0, TotalMatch = 0.0; i < NumParams; i++) { ParamMatch = (Feature->Params[i] - Mean(Proto, i)) / diff --git a/src/classify/ocrfeatures.cpp b/src/classify/ocrfeatures.cpp index 851e087531..4d06776708 100644 --- a/src/classify/ocrfeatures.cpp +++ b/src/classify/ocrfeatures.cpp @@ -87,7 +87,7 @@ FEATURE NewFeature(const FEATURE_DESC_STRUCT* FeatureDesc) { FEATURE Feature; Feature = (FEATURE)malloc(sizeof(FEATURE_STRUCT) + - (FeatureDesc->NumParams - 1) * sizeof(FLOAT32)); + (FeatureDesc->NumParams - 1) * sizeof(float)); Feature->Type = FeatureDesc; return (Feature); diff --git a/src/classify/ocrfeatures.h b/src/classify/ocrfeatures.h index f2808217c2..54e60c1af1 100644 --- a/src/classify/ocrfeatures.h +++ b/src/classify/ocrfeatures.h @@ -1,10 +1,10 @@ /****************************************************************************** - ** Filename: features.h - ** Purpose: Generic definition of a feature. - ** Author: Dan Johnson - ** History: Sun May 20 10:28:30 1990, DSJ, Created. + ** Filename: features.h + ** Purpose: Generic definition of a feature. + ** Author: Dan Johnson + ** History: Sun May 20 10:28:30 1990, DSJ, Created. ** - ** (c) Copyright Hewlett-Packard Company, 1988. + ** (c) Copyright Hewlett-Packard Company, 1988. ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. ** You may obtain a copy of the License at @@ -15,8 +15,9 @@ ** See the License for the specific language governing permissions and ** limitations under the License. ******************************************************************************/ -#ifndef FEATURES_H -#define FEATURES_H + +#ifndef FEATURES_H +#define FEATURES_H /**---------------------------------------------------------------------------- Include Files and Type Defines @@ -30,11 +31,11 @@ struct INT_FX_RESULT_STRUCT; #undef Min #undef Max -#define FEAT_NAME_SIZE 80 +#define FEAT_NAME_SIZE 80 // define trap errors which can be caused by this module #define ILLEGAL_FEATURE_PARAM 1000 -#define ILLEGAL_NUM_FEATURES 1001 +#define ILLEGAL_NUM_FEATURES 1001 // A character is described by multiple sets of extracted features. Each // set contains a number of features of a particular type, for example, a @@ -44,52 +45,55 @@ struct INT_FX_RESULT_STRUCT; // parameters are required to be the first parameters in the feature. struct PARAM_DESC { - int8_t Circular; // TRUE if dimension wraps around - int8_t NonEssential; // TRUE if dimension not used in searches - FLOAT32 Min; // low end of range for circular dimensions - FLOAT32 Max; // high end of range for circular dimensions - FLOAT32 Range; // Max - Min - FLOAT32 HalfRange; // (Max - Min)/2 - FLOAT32 MidRange; // (Max + Min)/2 + int8_t Circular; // TRUE if dimension wraps around + int8_t NonEssential; // TRUE if dimension not used in searches + float Min; // low end of range for circular dimensions + float Max; // high end of range for circular dimensions + float Range; // Max - Min + float HalfRange; // (Max - Min)/2 + float MidRange; // (Max + Min)/2 }; struct FEATURE_DESC_STRUCT { - uint16_t NumParams; // total # of params - const char *ShortName; // short name for feature - const PARAM_DESC *ParamDesc; // array - one per param + uint16_t NumParams; // total # of params + const char* ShortName; // short name for feature + const PARAM_DESC* ParamDesc; // array - one per param }; -using FEATURE_DESC = FEATURE_DESC_STRUCT *; +using FEATURE_DESC = FEATURE_DESC_STRUCT*; struct FEATURE_STRUCT { - const FEATURE_DESC_STRUCT *Type; // points to description of feature type - FLOAT32 Params[1]; // variable size array - params for feature + const FEATURE_DESC_STRUCT* Type; // points to description of feature type + float Params[1]; // variable size array - params for feature }; -using FEATURE = FEATURE_STRUCT *; +using FEATURE = FEATURE_STRUCT*; struct FEATURE_SET_STRUCT { - uint16_t NumFeatures; // number of features in set - uint16_t MaxNumFeatures; // maximum size of feature set - FEATURE Features[1]; // variable size array of features + uint16_t NumFeatures; // number of features in set + uint16_t MaxNumFeatures; // maximum size of feature set + FEATURE Features[1]; // variable size array of features }; -using FEATURE_SET = FEATURE_SET_STRUCT *; +using FEATURE_SET = FEATURE_SET_STRUCT*; // A generic character description as a char pointer. In reality, it will be // a pointer to some data structure. Paired feature extractors/matchers need // to agree on the data structure to be used, however, the high level // classifier does not need to know the details of this data structure. -using CHAR_FEATURES = char *; +using CHAR_FEATURES = char*; /*---------------------------------------------------------------------- Macros for defining the parameters of a new features ----------------------------------------------------------------------*/ -#define StartParamDesc(Name) \ -const PARAM_DESC Name[] = { - -#define DefineParam(Circular, NonEssential, Min, Max) \ - {Circular, NonEssential, Min, Max, \ - (Max) - (Min), (((Max) - (Min))/2.0), (((Max) + (Min))/2.0)}, - -#define EndParamDesc }; +#define StartParamDesc(Name) const PARAM_DESC Name[] = { +#define DefineParam(Circular, NonEssential, Min, Max) \ + {Circular, \ + NonEssential, \ + Min, \ + Max, \ + (Max) - (Min), \ + (((Max) - (Min)) / 2.0), \ + (((Max) + (Min)) / 2.0)}, + +#define EndParamDesc }; /*---------------------------------------------------------------------- Macro for describing a new feature. The parameters of the macro @@ -97,9 +101,8 @@ are as follows: DefineFeature (Name, NumLinear, NumCircular, ShortName, ParamName) ----------------------------------------------------------------------*/ -#define DefineFeature(Name, NL, NC, SN, PN) \ -const FEATURE_DESC_STRUCT Name = { \ - ((NL) + (NC)), SN, PN}; +#define DefineFeature(Name, NL, NC, SN, PN) \ + const FEATURE_DESC_STRUCT Name = {((NL) + (NC)), SN, PN}; /*---------------------------------------------------------------------- Generic routines that work for all feature types @@ -110,13 +113,13 @@ void FreeFeature(FEATURE Feature); void FreeFeatureSet(FEATURE_SET FeatureSet); -FEATURE NewFeature(const FEATURE_DESC_STRUCT *FeatureDesc); +FEATURE NewFeature(const FEATURE_DESC_STRUCT* FeatureDesc); FEATURE_SET NewFeatureSet(int NumFeatures); -FEATURE ReadFeature(FILE *File, const FEATURE_DESC_STRUCT *FeatureDesc); +FEATURE ReadFeature(FILE* File, const FEATURE_DESC_STRUCT* FeatureDesc); -FEATURE_SET ReadFeatureSet(FILE *File, const FEATURE_DESC_STRUCT *FeatureDesc); +FEATURE_SET ReadFeatureSet(FILE* File, const FEATURE_DESC_STRUCT* FeatureDesc); void WriteFeature(FEATURE Feature, STRING* str); diff --git a/src/classify/outfeat.cpp b/src/classify/outfeat.cpp index 1ece8c637b..a05319ad3b 100644 --- a/src/classify/outfeat.cpp +++ b/src/classify/outfeat.cpp @@ -49,7 +49,7 @@ FEATURE_SET Classify::ExtractOutlineFeatures(TBLOB *Blob) { LIST RemainingOutlines; MFOUTLINE Outline; FEATURE_SET FeatureSet; - FLOAT32 XScale, YScale; + float XScale, YScale; FeatureSet = NewFeatureSet (MAX_OUTLINE_FEATURES); if (Blob == nullptr) @@ -163,10 +163,10 @@ void ConvertToOutlineFeatures(MFOUTLINE Outline, FEATURE_SET FeatureSet) { void NormalizeOutlineX(FEATURE_SET FeatureSet) { int i; FEATURE Feature; - FLOAT32 Length; - FLOAT32 TotalX = 0.0; - FLOAT32 TotalWeight = 0.0; - FLOAT32 Origin; + float Length; + float TotalX = 0.0; + float TotalWeight = 0.0; + float Origin; if (FeatureSet->NumFeatures <= 0) return; diff --git a/src/classify/picofeat.cpp b/src/classify/picofeat.cpp index c8fd778f0d..a0657cb56b 100644 --- a/src/classify/picofeat.cpp +++ b/src/classify/picofeat.cpp @@ -69,7 +69,7 @@ FEATURE_SET Classify::ExtractPicoFeatures(TBLOB *Blob) { LIST RemainingOutlines; MFOUTLINE Outline; FEATURE_SET FeatureSet; - FLOAT32 XScale, YScale; + float XScale, YScale; FeatureSet = NewFeatureSet(MAX_PICO_FEATURES); Outlines = ConvertBlob(Blob); @@ -110,8 +110,8 @@ void ConvertSegmentToPicoFeat(FPOINT *Start, FPOINT *End, FEATURE_SET FeatureSet) { FEATURE Feature; - FLOAT32 Angle; - FLOAT32 Length; + float Angle; + float Length; int NumFeatures; FPOINT Center; FPOINT Delta; @@ -204,7 +204,7 @@ void ConvertToPicoFeatures2(MFOUTLINE Outline, FEATURE_SET FeatureSet) { void NormalizePicoX(FEATURE_SET FeatureSet) { int i; FEATURE Feature; - FLOAT32 Origin = 0.0; + float Origin = 0.0; for (i = 0; i < FeatureSet->NumFeatures; i++) { Feature = FeatureSet->Features[i]; diff --git a/src/classify/picofeat.h b/src/classify/picofeat.h index 966ffc32e7..b3f0b90f74 100644 --- a/src/classify/picofeat.h +++ b/src/classify/picofeat.h @@ -1,10 +1,10 @@ /****************************************************************************** - ** Filename: picofeat.h - ** Purpose: Definition of pico features. - ** Author: Dan Johnson - ** History: 9/4/90, DSJ, Created. + ** Filename: picofeat.h + ** Purpose: Definition of pico features. + ** Author: Dan Johnson + ** History: 9/4/90, DSJ, Created. ** - ** (c) Copyright Hewlett-Packard Company, 1988. + ** (c) Copyright Hewlett-Packard Company, 1988. ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. ** You may obtain a copy of the License at @@ -15,8 +15,9 @@ ** See the License for the specific language governing permissions and ** limitations under the License. ******************************************************************************/ -#ifndef PICOFEAT_H -#define PICOFEAT_H + +#ifndef PICOFEAT_H +#define PICOFEAT_H /**---------------------------------------------------------------------------- Include Files and Type Defines @@ -33,16 +34,14 @@ enum IntParams { // Enum for the order/type of params in GeoFeatDesc. enum GeoParams { - GeoBottom, // Bounding box bottom in baseline space (0-255). - GeoTop, // Bounding box top in baseline space (0-255). - GeoWidth, // Bounding box width in baseline space (0-255). + GeoBottom, // Bounding box bottom in baseline space (0-255). + GeoTop, // Bounding box top in baseline space (0-255). + GeoWidth, // Bounding box width in baseline space (0-255). - GeoCount // Number of geo features. + GeoCount // Number of geo features. }; -typedef enum -{ PicoFeatY, PicoFeatDir, PicoFeatX } -PICO_FEAT_PARAM_NAME; +typedef enum { PicoFeatY, PicoFeatDir, PicoFeatX } PICO_FEAT_PARAM_NAME; #define MAX_PICO_FEATURES (1000) @@ -52,14 +51,14 @@ PICO_FEAT_PARAM_NAME; extern double_VAR_H(classify_pico_feature_length, 0.05, "Pico Feature Length"); - /**---------------------------------------------------------------------------- Public Function Prototypes ----------------------------------------------------------------------------**/ -#define GetPicoFeatureLength() (PicoFeatureLength) +#define GetPicoFeatureLength() (PicoFeatureLength) /**---------------------------------------------------------------------------- Global Data Definitions and Declarations ----------------------------------------------------------------------------**/ -extern TESS_API FLOAT32 PicoFeatureLength; +extern TESS_API float PicoFeatureLength; + #endif diff --git a/src/classify/protos.cpp b/src/classify/protos.cpp index cd51485c1e..0483f96e9e 100644 --- a/src/classify/protos.cpp +++ b/src/classify/protos.cpp @@ -137,9 +137,9 @@ int AddProtoToClass(CLASS_TYPE Class) { * @param Class The class to add to * @param Config FIXME */ -FLOAT32 ClassConfigLength(CLASS_TYPE Class, BIT_VECTOR Config) { +float ClassConfigLength(CLASS_TYPE Class, BIT_VECTOR Config) { int16_t Pid; - FLOAT32 TotalLength = 0; + float TotalLength = 0; for (Pid = 0; Pid < Class->NumProtos; Pid++) { if (test_bit (Config, Pid)) { @@ -158,9 +158,9 @@ FLOAT32 ClassConfigLength(CLASS_TYPE Class, BIT_VECTOR Config) { * * @param Class The class to use */ -FLOAT32 ClassProtoLength(CLASS_TYPE Class) { +float ClassProtoLength(CLASS_TYPE Class) { int16_t Pid; - FLOAT32 TotalLength = 0; + float TotalLength = 0; for (Pid = 0; Pid < Class->NumProtos; Pid++) { TotalLength += (ProtoIn (Class, Pid))->Length; @@ -194,7 +194,7 @@ void CopyProto(PROTO Src, PROTO Dest) { * Fill in Protos A, B, C fields based on the X, Y, Angle fields. **********************************************************************/ void FillABC(PROTO Proto) { - FLOAT32 Slope, Intercept, Normalizer; + float Slope, Intercept, Normalizer; Slope = tan (Proto->Angle * 2.0 * PI); Intercept = Proto->Y - Slope * Proto->X; diff --git a/src/classify/protos.h b/src/classify/protos.h index d53fe467f4..51ac1a467f 100644 --- a/src/classify/protos.h +++ b/src/classify/protos.h @@ -1,7 +1,7 @@ /* -*-C-*- - ******************************************************************************** + ****************************************************************************** * - * File: protos.h (Formerly protos.h) + * File: protos.h * Description: * Author: Mark Seaman, SW Productivity * Created: Fri Oct 16 14:37:00 1987 @@ -21,7 +21,8 @@ ** See the License for the specific language governing permissions and ** limitations under the License. * - *********************************************************************************/ + *****************************************************************************/ + #ifndef PROTOS_H #define PROTOS_H @@ -30,32 +31,34 @@ ----------------------------------------------------------------------*/ #include "bitvec.h" #include "cutil.h" +#include "params.h" #include "unichar.h" #include "unicity_table.h" -#include "params.h" /*---------------------------------------------------------------------- T y p e s ----------------------------------------------------------------------*/ -using CONFIGS = BIT_VECTOR *; - -typedef struct -{ - FLOAT32 A; - FLOAT32 B; - FLOAT32 C; - FLOAT32 X; - FLOAT32 Y; - FLOAT32 Angle; - FLOAT32 Length; +using CONFIGS = BIT_VECTOR*; + +typedef struct { + float A; + float B; + float C; + float X; + float Y; + float Angle; + float Length; } PROTO_STRUCT; -using PROTO = PROTO_STRUCT *; +using PROTO = PROTO_STRUCT*; struct CLASS_STRUCT { CLASS_STRUCT() - : NumProtos(0), MaxNumProtos(0), Prototypes(nullptr), - NumConfigs(0), MaxNumConfigs(0), Configurations(nullptr) { - } + : NumProtos(0), + MaxNumProtos(0), + Prototypes(nullptr), + NumConfigs(0), + MaxNumConfigs(0), + Configurations(nullptr) {} int16_t NumProtos; int16_t MaxNumProtos; PROTO Prototypes; @@ -64,15 +67,15 @@ struct CLASS_STRUCT { CONFIGS Configurations; UnicityTableEqEq font_set; }; -using CLASS_TYPE = CLASS_STRUCT *; -using CLASSES = CLASS_STRUCT *; +using CLASS_TYPE = CLASS_STRUCT*; +using CLASSES = CLASS_STRUCT*; /*---------------------------------------------------------------------- C o n s t a n t s ----------------------------------------------------------------------*/ -#define NUMBER_OF_CLASSES MAX_NUM_CLASSES -#define Y_OFFSET -40.0 -#define FEATURE_SCALE 100.0 +#define NUMBER_OF_CLASSES MAX_NUM_CLASSES +#define Y_OFFSET -40.0 +#define FEATURE_SCALE 100.0 /*---------------------------------------------------------------------- V a r i a b l e s @@ -90,8 +93,7 @@ extern STRING_VAR_H(classify_training_file, "MicroFeatures", "Training file"); * Set a single proto bit in the specified configuration. */ -#define AddProtoToConfig(Pid,Config) \ -(SET_BIT (Config, Pid)) +#define AddProtoToConfig(Pid, Config) (SET_BIT(Config, Pid)) /** * RemoveProtoFromConfig @@ -99,8 +101,7 @@ extern STRING_VAR_H(classify_training_file, "MicroFeatures", "Training file"); * Clear a single proto bit in the specified configuration. */ -#define RemoveProtoFromConfig(Pid,Config) \ -(reset_bit (Config, Pid)) +#define RemoveProtoFromConfig(Pid, Config) (reset_bit(Config, Pid)) /** * ClassOfChar @@ -108,10 +109,8 @@ extern STRING_VAR_H(classify_training_file, "MicroFeatures", "Training file"); * Return the class of a particular ASCII character value. */ -#define ClassOfChar(Char) \ -((TrainingData [Char].NumProtos) ? \ - (& TrainingData [Char]) : \ - NO_CLASS) +#define ClassOfChar(Char) \ + ((TrainingData[Char].NumProtos) ? (&TrainingData[Char]) : NO_CLASS) /** * ProtoIn @@ -120,8 +119,7 @@ extern STRING_VAR_H(classify_training_file, "MicroFeatures", "Training file"); * pointer to it (type PROTO). */ -#define ProtoIn(Class,Pid) \ -(& (Class)->Prototypes [Pid]) +#define ProtoIn(Class, Pid) (&(Class)->Prototypes[Pid]) /** * PrintProto @@ -130,13 +128,9 @@ extern STRING_VAR_H(classify_training_file, "MicroFeatures", "Training file"); * type 'PROTO'. */ -#define PrintProto(Proto) \ -(tprintf("X=%4.2f, Y=%4.2f, Length=%4.2f, Angle=%4.2f", \ - Proto->X, \ - Proto->Y, \ - Proto->Length, \ - Proto->Angle)) \ - +#define PrintProto(Proto) \ + (tprintf("X=%4.2f, Y=%4.2f, Length=%4.2f, Angle=%4.2f", Proto->X, Proto->Y, \ + Proto->Length, Proto->Angle)) /** * PrintProtoLine @@ -145,11 +139,8 @@ extern STRING_VAR_H(classify_training_file, "MicroFeatures", "Training file"); * type 'PROTO'. */ -#define PrintProtoLine(Proto) \ -(cprintf ("A=%4.2f, B=%4.2f, C=%4.2f", \ - Proto->A, \ - Proto->B, \ - Proto->C)) \ +#define PrintProtoLine(Proto) \ + (cprintf("A=%4.2f, B=%4.2f, C=%4.2f", Proto->A, Proto->B, Proto->C)) /*---------------------------------------------------------------------- F u n c t i o n s @@ -158,9 +149,9 @@ int AddConfigToClass(CLASS_TYPE Class); int AddProtoToClass(CLASS_TYPE Class); -FLOAT32 ClassConfigLength(CLASS_TYPE Class, BIT_VECTOR Config); +float ClassConfigLength(CLASS_TYPE Class, BIT_VECTOR Config); -FLOAT32 ClassProtoLength(CLASS_TYPE Class); +float ClassProtoLength(CLASS_TYPE Class); void CopyProto(PROTO Src, PROTO Dest); diff --git a/src/dict/dict.h b/src/dict/dict.h index 4e1155d4cd..0bb5c2b17d 100644 --- a/src/dict/dict.h +++ b/src/dict/dict.h @@ -507,7 +507,7 @@ class Dict { /** Same as above, but for ambiguities with replace flag set. */ UnicharAmbigs *replace_ambigs_table_; /** Additional certainty padding allowed before a word is rejected. */ - FLOAT32 reject_offset_; + float reject_offset_; // Cached UNICHAR_IDs: UNICHAR_ID wildcard_unichar_id_; // kDictWildcard. UNICHAR_ID apostrophe_unichar_id_; // kApostropheSymbol. diff --git a/src/dict/matchdefs.h b/src/dict/matchdefs.h index 719b2a59e6..fe4a97091d 100644 --- a/src/dict/matchdefs.h +++ b/src/dict/matchdefs.h @@ -1,10 +1,10 @@ /****************************************************************************** - ** Filename: matchdefs.h - ** Purpose: Generic interface definitions for feature matchers. - ** Author: Dan Johnson - ** History: Fri Jan 19 09:21:25 1990, DSJ, Created. + ** Filename: matchdefs.h + ** Purpose: Generic interface definitions for feature matchers. + ** Author: Dan Johnson + ** History: Fri Jan 19 09:21:25 1990, DSJ, Created. ** - ** (c) Copyright Hewlett-Packard Company, 1988. + ** (c) Copyright Hewlett-Packard Company, 1988. ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. ** You may obtain a copy of the License at @@ -15,8 +15,9 @@ ** See the License for the specific language governing permissions and ** limitations under the License. ******************************************************************************/ -#ifndef MATCHDEFS_H -#define MATCHDEFS_H + +#ifndef MATCHDEFS_H +#define MATCHDEFS_H /**---------------------------------------------------------------------------- Include Files and Type Defines @@ -53,13 +54,13 @@ using FEATURE_ID = uint8_t; /** a RATING is the match rating returned by a classifier. Higher is better. */ -using RATING = FLOAT32; +using RATING = float; /** a CERTAINTY is an indication of the degree of confidence of the classifier. Higher is better. 0 means the match is as good as the mean of the matches seen in training. -1 means the match was one standard deviation worse than the training matches, etc. */ -using CERTAINTY = FLOAT32; +using CERTAINTY = float; /** define a data structure to hold a single match result */ typedef struct diff --git a/src/dict/stopper.cpp b/src/dict/stopper.cpp index 20717c12cb..47986aedc7 100644 --- a/src/dict/stopper.cpp +++ b/src/dict/stopper.cpp @@ -468,7 +468,7 @@ int Dict::UniformCertainties(const WERD_CHOICE& word) { double TotalCertainty; double TotalCertaintySquared; double Variance; - FLOAT32 Mean, StdDev; + float Mean, StdDev; int word_length = word.length(); if (word_length < 3) diff --git a/src/textord/edgblob.cpp b/src/textord/edgblob.cpp index 9f68b08d8e..920100a1d8 100644 --- a/src/textord/edgblob.cpp +++ b/src/textord/edgblob.cpp @@ -1,8 +1,8 @@ /********************************************************************** * File: edgblob.cpp (Formerly edgeloop.c) * Description: Functions to clean up an outline before approximation. - * Author: Ray Smith - * Created: Tue Mar 26 16:56:25 GMT 1991 + * Author: Ray Smith + * Created: Tue Mar 26 16:56:25 GMT 1991 * *(C) Copyright 1991, Hewlett-Packard Ltd. ** Licensed under the Apache License, Version 2.0(the "License"); @@ -180,23 +180,23 @@ int32_t OL_BUCKETS::outline_complexity( * Find number of descendants of this outline. */ // TODO(rays) Merge with outline_complexity. -int32_t OL_BUCKETS::count_children( // recursive count +int32_t OL_BUCKETS::count_children( // recursive count C_OUTLINE *outline, // parent outline - int32_t max_count // max output + int32_t max_count // max output ) { bool parent_box; // could it be boxy - int16_t xmin, xmax; // coord limits + int16_t xmin, xmax; // coord limits int16_t ymin, ymax; - int16_t xindex, yindex; // current bucket - C_OUTLINE *child; // current child - int32_t child_count; // no of children - int32_t grandchild_count; // no of grandchildren - int32_t parent_area; // potential box - FLOAT32 max_parent_area; // potential box - int32_t child_area; // current child - int32_t child_length; // current child + int16_t xindex, yindex; // current bucket + C_OUTLINE *child; // current child + int32_t child_count; // no of children + int32_t grandchild_count; // no of grandchildren + int32_t parent_area; // potential box + float max_parent_area; // potential box + int32_t child_area; // current child + int32_t child_length; // current child TBOX olbox; - C_OUTLINE_IT child_it; // search iterator + C_OUTLINE_IT child_it; // search iterator olbox = outline->bounding_box(); xmin =(olbox.left() - bl.x()) / BUCKETSIZE; diff --git a/src/training/commontraining.cpp b/src/training/commontraining.cpp index a1e1217c2c..4e099ca0c0 100644 --- a/src/training/commontraining.cpp +++ b/src/training/commontraining.cpp @@ -479,7 +479,7 @@ CLUSTERER *SetUpForClustering(const FEATURE_DEFS_STRUCT &FeatureDefs, const char* program_feature_type) { uint16_t N; int i, j; - FLOAT32* Sample = nullptr; + float* Sample = nullptr; CLUSTERER *Clusterer; int32_t CharID; LIST FeatureList = nullptr; @@ -495,7 +495,7 @@ CLUSTERER *SetUpForClustering(const FEATURE_DEFS_STRUCT &FeatureDefs, iterate(FeatureList) { FeatureSet = (FEATURE_SET) first_node(FeatureList); for (i = 0; i < FeatureSet->MaxNumFeatures; i++) { - if (Sample == nullptr) Sample = (FLOAT32*)Emalloc(N * sizeof(FLOAT32)); + if (Sample == nullptr) Sample = (float*)Emalloc(N * sizeof(float)); for (j = 0; j < N; j++) Sample[j] = FeatureSet->Features[i]->Params[j]; MakeSample (Clusterer, Sample, CharID); @@ -518,16 +518,16 @@ void MergeInsignificantProtos(LIST ProtoList, const char* label, Prototype = (PROTOTYPE *) first_node (pProtoList); if (Prototype->Significant || Prototype->Merged) continue; - FLOAT32 best_dist = 0.125; + float best_dist = 0.125; PROTOTYPE* best_match = nullptr; // Find the nearest alive prototype. LIST list_it = ProtoList; iterate(list_it) { PROTOTYPE* test_p = (PROTOTYPE *) first_node (list_it); if (test_p != Prototype && !test_p->Merged) { - FLOAT32 dist = ComputeDistance(Clusterer->SampleSize, - Clusterer->ParamDesc, - Prototype->Mean, test_p->Mean); + float dist = ComputeDistance(Clusterer->SampleSize, + Clusterer->ParamDesc, + Prototype->Mean, test_p->Mean); if (dist < best_dist) { best_match = test_p; best_dist = dist; @@ -613,7 +613,7 @@ LIST RemoveInsignificantProtos( { NewProto = (PROTOTYPE *)Emalloc(sizeof(PROTOTYPE)); - NewProto->Mean = (FLOAT32 *)Emalloc(N * sizeof(FLOAT32)); + NewProto->Mean = (float *)Emalloc(N * sizeof(float)); NewProto->Significant = Proto->Significant; NewProto->Style = Proto->Style; NewProto->NumSamples = Proto->NumSamples; @@ -623,7 +623,7 @@ LIST RemoveInsignificantProtos( for (i=0; i < N; i++) NewProto->Mean[i] = Proto->Mean[i]; if (Proto->Variance.Elliptical != nullptr) { - NewProto->Variance.Elliptical = (FLOAT32 *)Emalloc(N * sizeof(FLOAT32)); + NewProto->Variance.Elliptical = (float *)Emalloc(N * sizeof(float)); for (i=0; i < N; i++) NewProto->Variance.Elliptical[i] = Proto->Variance.Elliptical[i]; } @@ -631,7 +631,7 @@ LIST RemoveInsignificantProtos( NewProto->Variance.Elliptical = nullptr; //--------------------------------------------- if (Proto->Magnitude.Elliptical != nullptr) { - NewProto->Magnitude.Elliptical = (FLOAT32 *)Emalloc(N * sizeof(FLOAT32)); + NewProto->Magnitude.Elliptical = (float *)Emalloc(N * sizeof(float)); for (i=0; i < N; i++) NewProto->Magnitude.Elliptical[i] = Proto->Magnitude.Elliptical[i]; } @@ -639,7 +639,7 @@ LIST RemoveInsignificantProtos( NewProto->Magnitude.Elliptical = nullptr; //------------------------------------------------ if (Proto->Weight.Elliptical != nullptr) { - NewProto->Weight.Elliptical = (FLOAT32 *)Emalloc(N * sizeof(FLOAT32)); + NewProto->Weight.Elliptical = (float *)Emalloc(N * sizeof(float)); for (i=0; i < N; i++) NewProto->Weight.Elliptical[i] = Proto->Weight.Elliptical[i]; } diff --git a/src/training/mergenf.cpp b/src/training/mergenf.cpp index 97179fd84a..94bdc215c9 100644 --- a/src/training/mergenf.cpp +++ b/src/training/mergenf.cpp @@ -63,11 +63,11 @@ double_VAR(training_angle_pad, 45.0, "Angle pad ..."); * @note Exceptions: none * @note History: Mon Nov 26 08:27:53 1990, DSJ, Created. */ -FLOAT32 CompareProtos(PROTO p1, PROTO p2) { +float CompareProtos(PROTO p1, PROTO p2) { FEATURE Feature; - FLOAT32 WorstEvidence = WORST_EVIDENCE; - FLOAT32 Evidence; - FLOAT32 Angle, Length; + float WorstEvidence = WORST_EVIDENCE; + float Evidence; + float Angle, Length; /* if p1 and p2 are not close in length, don't let them match */ Length = fabs (p1->Length - p2->Length); @@ -131,10 +131,10 @@ FLOAT32 CompareProtos(PROTO p1, PROTO p2) { */ void ComputeMergedProto (PROTO p1, PROTO p2, - FLOAT32 w1, - FLOAT32 w2, + float w1, + float w2, PROTO MergedProto) { - FLOAT32 TotalWeight; + float TotalWeight; TotalWeight = w1 + w2; w1 /= TotalWeight; @@ -168,10 +168,10 @@ int FindClosestExistingProto(CLASS_TYPE Class, int NumMerged[], PROTO_STRUCT NewProto; PROTO_STRUCT MergedProto; int Pid; - PROTO Proto; + PROTO Proto; int BestProto; - FLOAT32 BestMatch; - FLOAT32 Match, OldMatch, NewMatch; + float BestMatch; + float Match, OldMatch, NewMatch; MakeNewFromOld (&NewProto, Prototype); @@ -180,7 +180,7 @@ int FindClosestExistingProto(CLASS_TYPE Class, int NumMerged[], for (Pid = 0; Pid < Class->NumProtos; Pid++) { Proto = ProtoIn(Class, Pid); ComputeMergedProto(Proto, &NewProto, - (FLOAT32) NumMerged[Pid], 1.0, &MergedProto); + (float) NumMerged[Pid], 1.0, &MergedProto); OldMatch = CompareProtos(Proto, &MergedProto); NewMatch = CompareProtos(&NewProto, &MergedProto); Match = std::min(OldMatch, NewMatch); @@ -219,7 +219,7 @@ void MakeNewFromOld(PROTO New, PROTOTYPE *Old) { * * Compare a feature to a prototype. Print the result. */ -FLOAT32 SubfeatureEvidence(FEATURE Feature, PROTO Proto) { +float SubfeatureEvidence(FEATURE Feature, PROTO Proto) { float Distance; float Dangle; @@ -273,9 +273,9 @@ double EvidenceOf (double Similarity) { */ bool DummyFastMatch(FEATURE Feature, PROTO Proto) { - FRECT BoundingBox; - FLOAT32 MaxAngleError; - FLOAT32 AngleError; + FRECT BoundingBox; + float MaxAngleError; + float AngleError; MaxAngleError = training_angle_pad / 360.0; AngleError = fabs (Proto->Angle - Feature->Params[PicoFeatDir]); @@ -311,17 +311,14 @@ bool DummyFastMatch(FEATURE Feature, PROTO Proto) * @note Exceptions: none * @note History: Wed Nov 14 14:55:30 1990, DSJ, Created. */ -void ComputePaddedBoundingBox (PROTO Proto, FLOAT32 TangentPad, - FLOAT32 OrthogonalPad, FRECT *BoundingBox) { - FLOAT32 Pad, Length, Angle; - FLOAT32 CosOfAngle, SinOfAngle; - - Length = Proto->Length / 2.0 + TangentPad; - Angle = Proto->Angle * 2.0 * PI; - CosOfAngle = fabs(cos(Angle)); - SinOfAngle = fabs(sin(Angle)); - - Pad = std::max(CosOfAngle * Length, SinOfAngle * OrthogonalPad); +void ComputePaddedBoundingBox (PROTO Proto, float TangentPad, + float OrthogonalPad, FRECT *BoundingBox) { + float Length = Proto->Length / 2.0 + TangentPad; + float Angle = Proto->Angle * 2.0 * PI; + float CosOfAngle = fabs(cos(Angle)); + float SinOfAngle = fabs(sin(Angle)); + + float Pad = std::max(CosOfAngle * Length, SinOfAngle * OrthogonalPad); BoundingBox->MinX = Proto->X - Pad; BoundingBox->MaxX = Proto->X + Pad; @@ -339,7 +336,7 @@ void ComputePaddedBoundingBox (PROTO Proto, FLOAT32 TangentPad, * @return true if point (X,Y) is inside of Rectangle. * @note Exceptions: none */ -bool PointInside(FRECT *Rectangle, FLOAT32 X, FLOAT32 Y) { +bool PointInside(FRECT *Rectangle, float X, float Y) { return (X >= Rectangle->MinX) && (X <= Rectangle->MaxX) && (Y >= Rectangle->MinY) && diff --git a/src/training/mergenf.h b/src/training/mergenf.h index e105de5531..84e0f2d765 100644 --- a/src/training/mergenf.h +++ b/src/training/mergenf.h @@ -1,10 +1,10 @@ /****************************************************************************** -** Filename: MergeNF.c -** Purpose: Program for merging similar nano-feature protos -** Author: Dan Johnson -** History: Wed Nov 21 09:55:23 1990, DSJ, Created. -** - ** (c) Copyright Hewlett-Packard Company, 1988. + ** Filename: MergeNF.c + ** Purpose: Program for merging similar nano-feature protos + ** Author: Dan Johnson + ** History: Wed Nov 21 09:55:23 1990, DSJ, Created. + ** + ** (c) Copyright Hewlett-Packard Company, 1988. ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. ** You may obtain a copy of the License at @@ -14,85 +14,66 @@ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ** See the License for the specific language governing permissions and ** limitations under the License. -******************************************************************************/ + *****************************************************************************/ #ifndef TESSERACT_TRAINING_MERGENF_H_ #define TESSERACT_TRAINING_MERGENF_H_ /**---------------------------------------------------------------------------- - Include Files and Type Defines + Include Files and Type Defines ----------------------------------------------------------------------------**/ -#include "protos.h" +#include "callcpp.h" #include "cluster.h" #include "ocrfeatures.h" -#include "callcpp.h" #include "picofeat.h" +#include "protos.h" - -#define WORST_MATCH_ALLOWED (0.9) +#define WORST_MATCH_ALLOWED (0.9) #define WORST_EVIDENCE (1.0) -#define MAX_LENGTH_MISMATCH (2.0 * GetPicoFeatureLength ()) - - -#define PROTO_SUFFIX ".mf.p" -#define CONFIG_SUFFIX ".cl" -#define NO_PROTO (-1) -#define XPOSITION 0 -#define YPOSITION 1 -#define MFLENGTH 2 -#define ORIENTATION 3 - -typedef struct -{ - FLOAT32 MinX, MaxX, MinY, MaxY; +#define MAX_LENGTH_MISMATCH (2.0 * GetPicoFeatureLength()) + +#define PROTO_SUFFIX ".mf.p" +#define CONFIG_SUFFIX ".cl" +#define NO_PROTO (-1) +#define XPOSITION 0 +#define YPOSITION 1 +#define MFLENGTH 2 +#define ORIENTATION 3 + +typedef struct { + float MinX, MaxX, MinY, MaxY; } FRECT; /**---------------------------------------------------------------------------- - Public Macros + Public Macros ----------------------------------------------------------------------------**/ -#define CenterX(M) ( (M)[XPOSITION] ) -#define CenterY(M) ( (M)[YPOSITION] ) -#define LengthOf(M) ( (M)[MFLENGTH] ) -#define OrientationOf(M) ( (M)[ORIENTATION] ) +#define CenterX(M) ((M)[XPOSITION]) +#define CenterY(M) ((M)[YPOSITION]) +#define LengthOf(M) ((M)[MFLENGTH]) +#define OrientationOf(M) ((M)[ORIENTATION]) /**---------------------------------------------------------------------------- - Public Function Prototypes + Public Function Prototypes ----------------------------------------------------------------------------**/ -FLOAT32 CompareProtos ( - PROTO p1, - PROTO p2); +float CompareProtos(PROTO p1, PROTO p2); -void ComputeMergedProto ( - PROTO p1, - PROTO p2, - FLOAT32 w1, - FLOAT32 w2, - PROTO MergedProto); +void ComputeMergedProto(PROTO p1, PROTO p2, float w1, float w2, + PROTO MergedProto); -int FindClosestExistingProto ( - CLASS_TYPE Class, - int NumMerged[], - PROTOTYPE *Prototype); +int FindClosestExistingProto(CLASS_TYPE Class, int NumMerged[], + PROTOTYPE* Prototype); -void MakeNewFromOld ( - PROTO New, - PROTOTYPE *Old); +void MakeNewFromOld(PROTO New, PROTOTYPE* Old); -FLOAT32 SubfeatureEvidence ( - FEATURE Feature, - PROTO Proto); +float SubfeatureEvidence(FEATURE Feature, PROTO Proto); -double EvidenceOf ( - double Similarity); +double EvidenceOf(double Similarity); bool DummyFastMatch(FEATURE Feature, PROTO Proto); -void ComputePaddedBoundingBox ( - PROTO Proto, - FLOAT32 TangentPad, - FLOAT32 OrthogonalPad, - FRECT *BoundingBox); +void ComputePaddedBoundingBox(PROTO Proto, float TangentPad, + float OrthogonalPad, FRECT* BoundingBox); -bool PointInside(FRECT *Rectangle, FLOAT32 X, FLOAT32 Y); +bool PointInside(FRECT* Rectangle, float X, float Y); #endif // TESSERACT_TRAINING_MERGENF_H_ diff --git a/src/training/mftraining.cpp b/src/training/mftraining.cpp index ec94db19ef..82863d0bed 100644 --- a/src/training/mftraining.cpp +++ b/src/training/mftraining.cpp @@ -1,17 +1,11 @@ /****************************************************************************** -** Filename: mftraining.c -** Purpose: Separates training pages into files for each character. -** Strips from files only the features and there parameters of - the feature type mf. -** Author: Dan Johnson -** Revisment: Christy Russon -** Environment: HPUX 6.5 -** Library: HPUX 6.5 -** History: Fri Aug 18 08:53:50 1989, DSJ, Created. -** 5/25/90, DSJ, Adapted to multiple feature types. -** Tuesday, May 17, 1998 Changes made to make feature specific and -** simplify structures. First step in simplifying training process. -** + ** Filename: mftraining.c + ** Purpose: Separates training pages into files for each character. + ** Strips from files only the features and there parameters of + ** the feature type mf. + ** Author: Dan Johnson + ** Revisment: Christy Russon + ** ** (c) Copyright Hewlett-Packard Company, 1988. ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. @@ -161,7 +155,7 @@ static LIST ClusterOneConfig(int shape_id, const char* class_label, MakeNewFromOld(&dummy_proto, prototype); // Merge with the similar proto. ComputeMergedProto(ProtoIn(merge_class->Class, p_id), &dummy_proto, - static_cast(merge_class->NumMerged[p_id]), + static_cast(merge_class->NumMerged[p_id]), 1.0, ProtoIn(merge_class->Class, p_id)); merge_class->NumMerged[p_id]++;