tesseract  5.0.0-alpha-619-ge9db
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, GenericVector< int > *sorted_features) const
 
int MapIndexedFeatures (const GenericVector< int > &index_features, GenericVector< int > *map_features) const
 
void DebugMapFeatures (const GenericVector< int > &map_features) const
 

Detailed Description

Definition at line 48 of file intfeaturemap.h.

Constructor & Destructor Documentation

◆ IntFeatureMap()

tesseract::IntFeatureMap::IntFeatureMap ( )

Definition at line 34 of file intfeaturemap.cpp.

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

◆ ~IntFeatureMap()

tesseract::IntFeatureMap::~IntFeatureMap ( )

Definition at line 42 of file intfeaturemap.cpp.

42  {
43  Clear();
44 }

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 GenericVector< int > &  map_features) const

Definition at line 172 of file intfeaturemap.cpp.

173  {
174  for (int i = 0; i < map_features.size(); ++i) {
175  INT_FEATURE_STRUCT f = InverseMapFeature(map_features[i]);
176  f.print();
177  }
178 }

◆ DeleteMapFeature()

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

Definition at line 63 of file intfeaturemap.cpp.

63  {
64  feature_map_.Merge(-1, map_feature);
65  mapping_changed_ = true;
66 }

◆ 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 159 of file intfeaturemap.cpp.

159  {
160  if (mapping_changed_) {
161  feature_map_.CompleteMerges();
162  compact_size_ = feature_map_.CompactSize();
163 #ifdef EXPERIMENT_ON
164  it->MapSampleFeatures(*this);
165 #endif
166  mapping_changed_ = false;
167  }
168  return compact_size_;
169 }

◆ FindNZFeatureMapping()

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

◆ IndexAndSortFeatures()

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

Definition at line 104 of file intfeaturemap.h.

106  {
107  feature_space_.IndexAndSortFeatures(features, num_features,
108  sorted_features);
109  }

◆ IndexFeature()

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

Definition at line 47 of file intfeaturemap.cpp.

47  {
48  return feature_space_.Index(f);
49 }

◆ Init()

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

Definition at line 73 of file intfeaturemap.cpp.

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

◆ InverseIndexFeature()

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

Definition at line 56 of file intfeaturemap.cpp.

56  {
57  return feature_space_.PositionFromIndex(index_feature);
58 }

◆ InverseMapFeature()

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

Definition at line 59 of file intfeaturemap.cpp.

59  {
60  int index = feature_map_.CompactToSparse(map_feature);
61  return feature_space_.PositionFromIndex(index);
62 }

◆ IsMapFeatureDeleted()

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

Definition at line 67 of file intfeaturemap.cpp.

67  {
68  return feature_map_.IsCompactDeleted(map_feature);
69 }

◆ MapFeature()

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

Definition at line 50 of file intfeaturemap.cpp.

50  {
51  return feature_map_.SparseToCompact(feature_space_.Index(f));
52 }

◆ MapIndexedFeatures()

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

Definition at line 115 of file intfeaturemap.h.

116  {
117  return feature_map_.MapFeatures(index_features, map_features);
118  }

◆ MapIndexFeature()

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

Definition at line 53 of file intfeaturemap.cpp.

53  {
54  return feature_map_.SparseToCompact(index_feature);
55 }

◆ OffsetFeature()

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

Definition at line 113 of file intfeaturemap.cpp.

113  {
114  if (dir > 0 && dir <= kNumOffsetMaps)
115  return offset_plus_[dir - 1][index_feature];
116  else if (dir < 0 && -dir <= kNumOffsetMaps)
117  return offset_minus_[-dir - 1][index_feature];
118  else if (dir == 0)
119  return index_feature;
120  else
121  return -1;
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:
tesseract::IndexMapBiDi::CompleteMerges
void CompleteMerges()
Definition: indexmapbidi.cpp:160
tesseract::IndexMapBiDi::MapFeatures
int MapFeatures(const GenericVector< int > &sparse, GenericVector< int > *compact) const
Definition: indexmapbidi.cpp:236
tesseract::IntFeatureSpace::IndexAndSortFeatures
void IndexAndSortFeatures(const INT_FEATURE_STRUCT *features, int num_features, GenericVector< int > *sorted_features) const
Definition: intfeaturespace.cpp:68
FCOORD::y
float y() const
Definition: points.h:209
FCOORD::x
float x() const
Definition: points.h:206
tesseract::IndexMapBiDi::SparseToCompact
int SparseToCompact(int sparse_index) const override
Definition: indexmapbidi.h:138
tesseract::IndexMap::CompactToSparse
int CompactToSparse(int compact_index) const
Definition: indexmapbidi.h:53
FCOORD
Definition: points.h:187
tesseract::IntFeatureSpace::Size
int Size() const
Definition: intfeaturespace.h:51
InitIntegerFX
void InitIntegerFX()
Definition: intfx.cpp:48
INT_FEATURE_STRUCT::print
void print() const
Definition: intproto.h:144
tesseract::IntFeatureMap::InverseMapFeature
INT_FEATURE_STRUCT InverseMapFeature(int map_feature) const
Definition: intfeaturemap.cpp:59
tesseract::IndexMapBiDi::Merge
bool Merge(int compact_index1, int compact_index2)
Definition: indexmapbidi.cpp:128
tesseract::IndexMapBiDi::Setup
void Setup()
Definition: indexmapbidi.cpp:102
tesseract::IntFeatureSpace::PositionFromIndex
INT_FEATURE_STRUCT PositionFromIndex(int index) const
Definition: intfeaturespace.cpp:50
tesseract::IntFeatureMap::feature_space
const IntFeatureSpace & feature_space() const
Definition: intfeaturemap.h:60
INT_FEATURE_STRUCT
Definition: intproto.h:131
tesseract::IndexMapBiDi::Init
void Init(int size, bool all_mapped)
Definition: indexmapbidi.cpp:86
FeatureDirection
FCOORD FeatureDirection(uint8_t theta)
Definition: intfx.cpp:64
tesseract::IndexMapBiDi::IsCompactDeleted
bool IsCompactDeleted(int index) const
Definition: indexmapbidi.h:130
tesseract::IntFeatureMap::sparse_size
int sparse_size() const
Definition: intfeaturemap.h:54
tesseract::IndexMap::CompactSize
int CompactSize() const
Definition: indexmapbidi.h:61
GenericVector::size
int size() const
Definition: genericvector.h:71
tesseract::IntFeatureSpace::Index
int Index(const INT_FEATURE_STRUCT &f) const
Definition: intfeaturespace.h:60