Tesseract  3.02
tesseract::IntFeatureSpace Class Reference

#include <intfeaturespace.h>

List of all members.

Public Member Functions

 IntFeatureSpace ()
void Init (uinT8 xbuckets, uinT8 ybuckets, uinT8 thetabuckets)
bool Serialize (FILE *fp) const
bool DeSerialize (bool swap, FILE *fp)
int Size () const
INT_FEATURE_STRUCT PositionFromIndex (int index) const
int Index (const INT_FEATURE_STRUCT &f) const
void IndexFeatures (const INT_FEATURE_STRUCT *features, int num_features, GenericVector< int > *mapped_features) const
void IndexAndSortFeatures (const INT_FEATURE_STRUCT *features, int num_features, GenericVector< int > *sorted_features) const
int XYToFeatureIndex (int x, int y) const

Protected Member Functions

int XBucket (int x) const
int YBucket (int y) const
int ThetaBucket (int theta) const
INT_FEATURE_STRUCT PositionFromBuckets (int x, int y, int theta) const

Protected Attributes

uinT8 x_buckets_
uinT8 y_buckets_
uinT8 theta_buckets_

Detailed Description

Definition at line 38 of file intfeaturespace.h.


Constructor & Destructor Documentation

tesseract::IntFeatureSpace::IntFeatureSpace ( )

Definition at line 25 of file intfeaturespace.cpp.


Member Function Documentation

bool tesseract::IntFeatureSpace::DeSerialize ( bool  swap,
FILE *  fp 
)

Definition at line 50 of file intfeaturespace.cpp.

                                                     {
  if (fread(&x_buckets_, sizeof(x_buckets_), 1, fp) != 1)
    return false;
  if (fread(&y_buckets_, sizeof(y_buckets_), 1, fp) != 1)
    return false;
  if (fread(&theta_buckets_, sizeof(theta_buckets_), 1, fp) != 1)
    return false;
  return true;
}
int tesseract::IntFeatureSpace::Index ( const INT_FEATURE_STRUCT f) const [inline]

Definition at line 65 of file intfeaturespace.h.

                                               {
    return (XBucket(f.X) * y_buckets_ + YBucket(f.Y)) * theta_buckets_ +
        ThetaBucket(f.Theta);
  }
void tesseract::IntFeatureSpace::IndexAndSortFeatures ( const INT_FEATURE_STRUCT features,
int  num_features,
GenericVector< int > *  sorted_features 
) const

Definition at line 80 of file intfeaturespace.cpp.

                                               {
  sorted_features->truncate(0);
  for (int f = 0; f < num_features; ++f)
    sorted_features->push_back(Index(features[f]));
  sorted_features->sort();
}
void tesseract::IntFeatureSpace::IndexFeatures ( const INT_FEATURE_STRUCT features,
int  num_features,
GenericVector< int > *  mapped_features 
) const

Definition at line 70 of file intfeaturespace.cpp.

                                                                               {
  mapped_features->truncate(0);
  for (int f = 0; f < num_features; ++f)
    mapped_features->push_back(Index(features[f]));
}
void tesseract::IntFeatureSpace::Init ( uinT8  xbuckets,
uinT8  ybuckets,
uinT8  thetabuckets 
)

Definition at line 29 of file intfeaturespace.cpp.

                                                                             {
  x_buckets_ = xbuckets;
  y_buckets_ = ybuckets;
  theta_buckets_ = thetabuckets;
}
INT_FEATURE_STRUCT tesseract::IntFeatureSpace::PositionFromBuckets ( int  x,
int  y,
int  theta 
) const [protected]

Definition at line 127 of file intfeaturespace.cpp.

                                                                         {
  INT_FEATURE_STRUCT pos = {
      static_cast<uinT8>(ClipToRange(
          (x * kIntFeatureExtent + kIntFeatureExtent / 2) / x_buckets_,
          0, MAX_UINT8)),
      static_cast<uinT8>(ClipToRange(
          (y * kIntFeatureExtent + kIntFeatureExtent / 2) / y_buckets_,
          0, MAX_UINT8)),
      static_cast<uinT8>(ClipToRange(
          DivRounded(theta * kIntFeatureExtent, theta_buckets_),
          0, MAX_UINT8))};
  return pos;
}
INT_FEATURE_STRUCT tesseract::IntFeatureSpace::PositionFromIndex ( int  index) const

Definition at line 62 of file intfeaturespace.cpp.

                                                                     {
  return PositionFromBuckets(index / (y_buckets_ * theta_buckets_),
                             index / theta_buckets_ % y_buckets_,
                             index % theta_buckets_);
}
bool tesseract::IntFeatureSpace::Serialize ( FILE *  fp) const

Definition at line 37 of file intfeaturespace.cpp.

                                              {
  if (fwrite(&x_buckets_, sizeof(x_buckets_), 1, fp) != 1)
    return false;
  if (fwrite(&y_buckets_, sizeof(y_buckets_), 1, fp) != 1)
    return false;
  if (fwrite(&theta_buckets_, sizeof(theta_buckets_), 1, fp) != 1)
    return false;
  return true;
}
int tesseract::IntFeatureSpace::Size ( ) const [inline]

Definition at line 56 of file intfeaturespace.h.

                   {
    return static_cast<int>(x_buckets_) * y_buckets_ * theta_buckets_;
  }
int tesseract::IntFeatureSpace::ThetaBucket ( int  theta) const [inline, protected]

Definition at line 94 of file intfeaturespace.h.

                                   {
    int bucket = DivRounded(theta * theta_buckets_, kIntFeatureExtent);
    return Modulo(bucket, theta_buckets_);
  }
int tesseract::IntFeatureSpace::XBucket ( int  x) const [inline, protected]

Definition at line 84 of file intfeaturespace.h.

                           {
    int bucket = x * x_buckets_ / kIntFeatureExtent;
    return ClipToRange(bucket, 0, static_cast<int>(x_buckets_) - 1);
  }
int tesseract::IntFeatureSpace::XYToFeatureIndex ( int  x,
int  y 
) const

Definition at line 91 of file intfeaturespace.cpp.

                                                        {
  // Round the x,y position to a feature. Search for a valid theta.
  INT_FEATURE_STRUCT feature = {static_cast<uinT8>(x), static_cast<uinT8>(y),
                                0, 0};
  int index = -1;
  for (int theta = 0; theta <= MAX_UINT8 && index < 0; ++theta) {
    feature.Theta = theta;
    index = Index(feature);
  }
  if (index < 0) {
    tprintf("(%d,%d) does not exist in feature space!\n", x, y);
    return -1;
  }
  feature = PositionFromIndex(index);
  tprintf("Click at (%d, %d) ->(%d, %d), ->(%d, %d)\n",
          x, y, feature.X, feature.Y, x - feature.X, y - feature.Y);
  // Get the relative position of x,y from the rounded feature.
  x -= feature.X;
  y -= feature.Y;
  if (x != 0 || y != 0) {
    double angle = atan2(static_cast<double>(y), static_cast<double>(x)) + PI;
    angle *= kIntFeatureExtent / (2.0 * PI);
    feature.Theta = static_cast<uinT8>(angle + 0.5);
    index = Index(feature);
    if (index < 0) {
      tprintf("Feature failed to map to a valid index:");
      feature.print();
      return -1;
    }
    feature = PositionFromIndex(index);
  }
  feature.print();
  return index;
}
int tesseract::IntFeatureSpace::YBucket ( int  y) const [inline, protected]

Definition at line 88 of file intfeaturespace.h.

                           {
    int bucket = y * y_buckets_ / kIntFeatureExtent;
    return ClipToRange(bucket, 0, static_cast<int>(y_buckets_) - 1);
  }

Member Data Documentation

Definition at line 104 of file intfeaturespace.h.

Definition at line 102 of file intfeaturespace.h.

Definition at line 103 of file intfeaturespace.h.


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