All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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

tesseract::IntFeatureMap::IntFeatureMap ( )

Definition at line 35 of file intfeaturemap.cpp.

36  : mapping_changed_(true), compact_size_(0) {
37  for (int dir = 0; dir < kNumOffsetMaps; ++dir) {
38  offset_plus_[dir] = NULL;
39  offset_minus_[dir] = NULL;
40  }
41 }
#define NULL
Definition: host.h:144
tesseract::IntFeatureMap::~IntFeatureMap ( )

Definition at line 43 of file intfeaturemap.cpp.

43  {
44  Clear();
45 }

Member Function Documentation

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

Definition at line 57 of file intfeaturemap.h.

57  {
58  return compact_size_;
59  }
void tesseract::IntFeatureMap::DebugMapFeatures ( const GenericVector< int > &  map_features) const

Definition at line 173 of file intfeaturemap.cpp.

174  {
175  for (int i = 0; i < map_features.size(); ++i) {
176  INT_FEATURE_STRUCT f = InverseMapFeature(map_features[i]);
177  f.print();
178  }
179 }
int size() const
Definition: genericvector.h:72
INT_FEATURE_STRUCT InverseMapFeature(int map_feature) const
void print() const
Definition: intproto.h:148
void tesseract::IntFeatureMap::DeleteMapFeature ( int  map_feature)

Definition at line 64 of file intfeaturemap.cpp.

64  {
65  feature_map_.Merge(-1, map_feature);
66  mapping_changed_ = true;
67 }
bool Merge(int compact_index1, int compact_index2)
const IndexMapBiDi& tesseract::IntFeatureMap::feature_map ( ) const
inline

Definition at line 63 of file intfeaturemap.h.

63  {
64  return feature_map_;
65  }
const IntFeatureSpace& tesseract::IntFeatureMap::feature_space ( ) const
inline

Definition at line 60 of file intfeaturemap.h.

60  {
61  return feature_space_;
62  }
int tesseract::IntFeatureMap::FinalizeMapping ( SampleIterator it)

Definition at line 160 of file intfeaturemap.cpp.

160  {
161  if (mapping_changed_) {
162  feature_map_.CompleteMerges();
163  compact_size_ = feature_map_.CompactSize();
164 #ifdef EXPERIMENT_ON
165  it->MapSampleFeatures(*this);
166 #endif
167  mapping_changed_ = false;
168  }
169  return compact_size_;
170 }
int CompactSize() const
Definition: indexmapbidi.h:61
int tesseract::IntFeatureMap::FindNZFeatureMapping ( SampleIterator it)
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  }
void IndexAndSortFeatures(const INT_FEATURE_STRUCT *features, int num_features, GenericVector< int > *sorted_features) const
int tesseract::IntFeatureMap::IndexFeature ( const INT_FEATURE_STRUCT f) const

Definition at line 48 of file intfeaturemap.cpp.

48  {
49  return feature_space_.Index(f);
50 }
int Index(const INT_FEATURE_STRUCT &f) const
void tesseract::IntFeatureMap::Init ( const IntFeatureSpace feature_space)

Definition at line 74 of file intfeaturemap.cpp.

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

Definition at line 57 of file intfeaturemap.cpp.

57  {
58  return feature_space_.PositionFromIndex(index_feature);
59 }
INT_FEATURE_STRUCT PositionFromIndex(int index) const
INT_FEATURE_STRUCT tesseract::IntFeatureMap::InverseMapFeature ( int  map_feature) const

Definition at line 60 of file intfeaturemap.cpp.

60  {
61  int index = feature_map_.CompactToSparse(map_feature);
62  return feature_space_.PositionFromIndex(index);
63 }
INT_FEATURE_STRUCT PositionFromIndex(int index) const
int CompactToSparse(int compact_index) const
Definition: indexmapbidi.h:53
bool tesseract::IntFeatureMap::IsMapFeatureDeleted ( int  map_feature) const

Definition at line 68 of file intfeaturemap.cpp.

68  {
69  return feature_map_.IsCompactDeleted(map_feature);
70 }
bool IsCompactDeleted(int index) const
Definition: indexmapbidi.h:130
int tesseract::IntFeatureMap::MapFeature ( const INT_FEATURE_STRUCT f) const

Definition at line 51 of file intfeaturemap.cpp.

51  {
52  return feature_map_.SparseToCompact(feature_space_.Index(f));
53 }
virtual int SparseToCompact(int sparse_index) const
Definition: indexmapbidi.h:138
int Index(const INT_FEATURE_STRUCT &f) const
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  }
int MapFeatures(const GenericVector< int > &sparse, GenericVector< int > *compact) const
int tesseract::IntFeatureMap::MapIndexFeature ( int  index_feature) const

Definition at line 54 of file intfeaturemap.cpp.

54  {
55  return feature_map_.SparseToCompact(index_feature);
56 }
virtual int SparseToCompact(int sparse_index) const
Definition: indexmapbidi.h:138
int tesseract::IntFeatureMap::OffsetFeature ( int  index_feature,
int  dir 
) const

Definition at line 114 of file intfeaturemap.cpp.

114  {
115  if (dir > 0 && dir <= kNumOffsetMaps)
116  return offset_plus_[dir - 1][index_feature];
117  else if (dir < 0 && -dir <= kNumOffsetMaps)
118  return offset_minus_[-dir - 1][index_feature];
119  else if (dir == 0)
120  return index_feature;
121  else
122  return -1;
123 }
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: