tesseract  5.0.0
tesseract::IntFeatureMap Class Reference

#include <intfeaturemap.h>

Public Member Functions

 IntFeatureMap ()
 
 ~IntFeatureMap ()
 
int sparse_size () const
 
int compact_size () const
 
const IntFeatureSpacefeature_space () const
 
const IndexMapBiDifeature_map () const
 
int IndexFeature (const INT_FEATURE_STRUCT &f) const
 
int MapFeature (const INT_FEATURE_STRUCT &f) const
 
int MapIndexFeature (int index_feature) const
 
INT_FEATURE_STRUCT InverseIndexFeature (int index_feature) const
 
INT_FEATURE_STRUCT InverseMapFeature (int map_feature) const
 
void DeleteMapFeature (int map_feature)
 
bool IsMapFeatureDeleted (int map_feature) const
 
void Init (const IntFeatureSpace &feature_space)
 
int OffsetFeature (int index_feature, int dir) const
 
int FindNZFeatureMapping (SampleIterator *it)
 
int FinalizeMapping (SampleIterator *it)
 
void IndexAndSortFeatures (const INT_FEATURE_STRUCT *features, int num_features, std::vector< int > *sorted_features) const
 
int MapIndexedFeatures (const std::vector< int > &index_features, std::vector< int > *map_features) const
 
void DebugMapFeatures (const std::vector< int > &map_features) const
 

Detailed Description

Definition at line 48 of file intfeaturemap.h.

Constructor & Destructor Documentation

◆ IntFeatureMap()

tesseract::IntFeatureMap::IntFeatureMap ( )

Definition at line 33 of file intfeaturemap.cpp.

33  : mapping_changed_(true), compact_size_(0) {
34  for (int dir = 0; dir < kNumOffsetMaps; ++dir) {
35  offset_plus_[dir] = nullptr;
36  offset_minus_[dir] = nullptr;
37  }
38 }

◆ ~IntFeatureMap()

tesseract::IntFeatureMap::~IntFeatureMap ( )

Definition at line 40 of file intfeaturemap.cpp.

40  {
41  Clear();
42 }

Member Function Documentation

◆ compact_size()

int tesseract::IntFeatureMap::compact_size ( ) const
inline

Definition at line 57 of file intfeaturemap.h.

57  {
58  return compact_size_;
59  }

◆ DebugMapFeatures()

void tesseract::IntFeatureMap::DebugMapFeatures ( const std::vector< int > &  map_features) const

Definition at line 168 of file intfeaturemap.cpp.

168  {
169  for (int map_feature : map_features) {
170  INT_FEATURE_STRUCT f = InverseMapFeature(map_feature);
171  f.print();
172  }
173 }
INT_FEATURE_STRUCT InverseMapFeature(int map_feature) const

◆ DeleteMapFeature()

void tesseract::IntFeatureMap::DeleteMapFeature ( int  map_feature)

Definition at line 61 of file intfeaturemap.cpp.

61  {
62  feature_map_.Merge(-1, map_feature);
63  mapping_changed_ = true;
64 }
bool Merge(int compact_index1, int compact_index2)

◆ feature_map()

const IndexMapBiDi& tesseract::IntFeatureMap::feature_map ( ) const
inline

Definition at line 63 of file intfeaturemap.h.

63  {
64  return feature_map_;
65  }

◆ feature_space()

const IntFeatureSpace& tesseract::IntFeatureMap::feature_space ( ) const
inline

Definition at line 60 of file intfeaturemap.h.

60  {
61  return feature_space_;
62  }

◆ FinalizeMapping()

int tesseract::IntFeatureMap::FinalizeMapping ( SampleIterator it)

Definition at line 155 of file intfeaturemap.cpp.

155  {
156  if (mapping_changed_) {
157  feature_map_.CompleteMerges();
158  compact_size_ = feature_map_.CompactSize();
159 #ifdef EXPERIMENT_ON
160  it->MapSampleFeatures(*this);
161 #endif
162  mapping_changed_ = false;
163  }
164  return compact_size_;
165 }
int CompactSize() const
Definition: indexmapbidi.h:63

◆ FindNZFeatureMapping()

int tesseract::IntFeatureMap::FindNZFeatureMapping ( SampleIterator it)

◆ IndexAndSortFeatures()

void tesseract::IntFeatureMap::IndexAndSortFeatures ( const INT_FEATURE_STRUCT features,
int  num_features,
std::vector< int > *  sorted_features 
) const
inline

Definition at line 104 of file intfeaturemap.h.

105  {
106  feature_space_.IndexAndSortFeatures(features, num_features, sorted_features);
107  }
void IndexAndSortFeatures(const INT_FEATURE_STRUCT *features, int num_features, std::vector< int > *sorted_features) const

◆ IndexFeature()

int tesseract::IntFeatureMap::IndexFeature ( const INT_FEATURE_STRUCT f) const

Definition at line 45 of file intfeaturemap.cpp.

45  {
46  return feature_space_.Index(f);
47 }
int Index(const INT_FEATURE_STRUCT &f) const

◆ Init()

void tesseract::IntFeatureMap::Init ( const IntFeatureSpace feature_space)

Definition at line 71 of file intfeaturemap.cpp.

71  {
72  feature_space_ = feature_space;
73  mapping_changed_ = false;
74  int sparse_size = feature_space_.Size();
75  feature_map_.Init(sparse_size, true);
76  feature_map_.Setup();
77  compact_size_ = feature_map_.CompactSize();
78  // Initialize look-up tables if needed.
79  FCOORD dir = FeatureDirection(0);
80  if (dir.x() == 0.0f && dir.y() == 0.0f) {
81  InitIntegerFX();
82  }
83  // Compute look-up tables to generate offset features.
84  for (int dir = 0; dir < kNumOffsetMaps; ++dir) {
85  delete[] offset_plus_[dir];
86  delete[] offset_minus_[dir];
87  offset_plus_[dir] = new int[sparse_size];
88  offset_minus_[dir] = new int[sparse_size];
89  }
90  for (int dir = 1; dir <= kNumOffsetMaps; ++dir) {
91  for (int i = 0; i < sparse_size; ++i) {
92  int offset_index = ComputeOffsetFeature(i, dir);
93  offset_plus_[dir - 1][i] = offset_index;
94  offset_index = ComputeOffsetFeature(i, -dir);
95  offset_minus_[dir - 1][i] = offset_index;
96  }
97  }
98 }
FCOORD FeatureDirection(uint8_t theta)
Definition: intfx.cpp:70
void InitIntegerFX()
Definition: intfx.cpp:54
void Init(int size, bool all_mapped)
const IntFeatureSpace & feature_space() const
Definition: intfeaturemap.h:60

◆ InverseIndexFeature()

INT_FEATURE_STRUCT tesseract::IntFeatureMap::InverseIndexFeature ( int  index_feature) const

Definition at line 54 of file intfeaturemap.cpp.

54  {
55  return feature_space_.PositionFromIndex(index_feature);
56 }
INT_FEATURE_STRUCT PositionFromIndex(int index) const

◆ InverseMapFeature()

INT_FEATURE_STRUCT tesseract::IntFeatureMap::InverseMapFeature ( int  map_feature) const

Definition at line 57 of file intfeaturemap.cpp.

57  {
58  int index = feature_map_.CompactToSparse(map_feature);
59  return feature_space_.PositionFromIndex(index);
60 }
int CompactToSparse(int compact_index) const
Definition: indexmapbidi.h:55

◆ IsMapFeatureDeleted()

bool tesseract::IntFeatureMap::IsMapFeatureDeleted ( int  map_feature) const

Definition at line 65 of file intfeaturemap.cpp.

65  {
66  return feature_map_.IsCompactDeleted(map_feature);
67 }
bool IsCompactDeleted(int index) const
Definition: indexmapbidi.h:132

◆ MapFeature()

int tesseract::IntFeatureMap::MapFeature ( const INT_FEATURE_STRUCT f) const

Definition at line 48 of file intfeaturemap.cpp.

48  {
49  return feature_map_.SparseToCompact(feature_space_.Index(f));
50 }
int SparseToCompact(int sparse_index) const override
Definition: indexmapbidi.h:140

◆ MapIndexedFeatures()

int tesseract::IntFeatureMap::MapIndexedFeatures ( const std::vector< int > &  index_features,
std::vector< int > *  map_features 
) const
inline

Definition at line 113 of file intfeaturemap.h.

114  {
115  return feature_map_.MapFeatures(index_features, map_features);
116  }
int MapFeatures(const std::vector< int > &sparse, std::vector< int > *compact) const

◆ MapIndexFeature()

int tesseract::IntFeatureMap::MapIndexFeature ( int  index_feature) const

Definition at line 51 of file intfeaturemap.cpp.

51  {
52  return feature_map_.SparseToCompact(index_feature);
53 }

◆ OffsetFeature()

int tesseract::IntFeatureMap::OffsetFeature ( int  index_feature,
int  dir 
) const

Definition at line 112 of file intfeaturemap.cpp.

112  {
113  if (dir > 0 && dir <= kNumOffsetMaps) {
114  return offset_plus_[dir - 1][index_feature];
115  } else if (dir < 0 && -dir <= kNumOffsetMaps) {
116  return offset_minus_[-dir - 1][index_feature];
117  } else if (dir == 0) {
118  return index_feature;
119  } else {
120  return -1;
121  }
122 }

◆ sparse_size()

int tesseract::IntFeatureMap::sparse_size ( ) const
inline

Definition at line 54 of file intfeaturemap.h.

54  {
55  return feature_space_.Size();
56  }

The documentation for this class was generated from the following files: