Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
states.h File Reference
#include "host.h"
#include "strngs.h"

Go to the source code of this file.

Classes

struct  STATE

Macros

#define MAX_NUM_CHUNKS   64 /* Limit on pieces */

Typedefs

typedef int * SEARCH_STATE
typedef uinT8 PIECES_STATE [MAX_NUM_CHUNKS+2]

Functions

SEARCH_STATE bin_to_chunks (STATE *state, int num_joints)
void bin_to_pieces (STATE *state, int num_joints, PIECES_STATE pieces)
void insert_new_chunk (register STATE *state, register int index, int num_joints)
STATEnew_state (STATE *oldstate)
int ones_in_state (STATE *state, int num_joints)
void print_state (const char *label, STATE *state, int num_joints)
void print_state (STATE *state, int num_joints, STRING *toappend)
void set_n_ones (STATE *state, int n)
void free_state (STATE *)

Macro Definition Documentation

#define MAX_NUM_CHUNKS   64 /* Limit on pieces */

Definition at line 37 of file states.h.


Typedef Documentation

typedef uinT8 PIECES_STATE[MAX_NUM_CHUNKS+2]

State variable for search

Definition at line 49 of file states.h.

typedef int* SEARCH_STATE

State variable for search

Definition at line 46 of file states.h.


Function Documentation

SEARCH_STATE bin_to_chunks ( STATE state,
int  num_joints 
)

Definition at line 49 of file states.cpp.

{
int x;
unsigned int mask;
int depth;
int pieces = 0;
s = memalloc (sizeof (int) * (ones_in_state (state, num_joints) + 1));
depth = 1;
mask = 1 << (num_joints - 1 - 32);
for (x = num_joints; x > 32; x--) {
if (state->part1 & mask) {
s[depth++] = pieces;
pieces = 0;
}
else {
pieces++;
}
mask >>= 1;
}
if (num_joints > 32)
mask = 1 << 31;
else
mask = 1 << (num_joints - 1);
while (x--) {
if (state->part2 & mask) {
s[depth++] = pieces;
pieces = 0;
}
else {
pieces++;
}
mask >>= 1;
}
s[0] = depth - 1;
return (s);
}
void bin_to_pieces ( STATE state,
int  num_joints,
PIECES_STATE  pieces 
)

bin_to_pieces

Convert the binary (bit vector) format of a search state to an array of piece counts. This array has a zero element after the last valid character.

Definition at line 99 of file states.cpp.

{
int x;
unsigned int mask; /* Bit mask */
inT16 num_pieces = 0;
/* Preset mask */
mask = ((num_joints > 32) ?
(1 << (num_joints - 1 - 32)) : (1 << (num_joints - 1)));
pieces[num_pieces] = 0;
for (x = num_joints - 1; x >= 0; x--) {
/* Iterate all bits */
pieces[num_pieces]++;
if ((x < 32) ? /* Test for 1 bit */
((state->part2 & mask) ? TRUE : FALSE) :
((state->part1 & mask) ? TRUE : FALSE)) {
pieces[++num_pieces] = 0;
}
/* Next mask value */
mask = ((mask == 1) ? (1 << 31) : (mask >> 1));
}
pieces[num_pieces]++;
pieces[++num_pieces] = 0;
ASSERT_HOST (num_pieces < MAX_NUM_CHUNKS + 2);
}
void free_state ( STATE )
void insert_new_chunk ( register STATE state,
register int  index,
int  num_joints 
)
STATE* new_state ( STATE oldstate)

new_state

Create a memory space for a new state variable. Set its initial value according to the parameters.

Definition at line 166 of file states.cpp.

{
STATE *this_state;
this_state = newstate ();
this_state->part1 = oldstate->part1;
this_state->part2 = oldstate->part2;
return (this_state);
}
int ones_in_state ( STATE state,
int  num_joints 
)

ones_in_state

Return the number of ones that are in this state.

Definition at line 181 of file states.cpp.

{
inT8 num_ones = 0;
inT8 x;
unsigned int mask;
if (num_joints > 32) /* Preset mask */
mask = 1 << (num_joints - 1 - 32);
else
mask = 1 << (num_joints - 1);
for (x = num_joints - 1; x >= 0; x--) {
/* Iterate all bits */
if (x < 32)
num_ones += ((state->part2 & mask) ? 1 : 0);
else
num_ones += ((state->part1 & mask) ? 1 : 0);
if (mask == 1) /* Next mask value */
mask = 1 << 31;
else
mask >>= 1;
}
return (num_ones);
}
void print_state ( const char *  label,
STATE state,
int  num_joints 
)

print_state

Print out the current state variable on a line with a label.

Definition at line 214 of file states.cpp.

{
int x;
unsigned int mask; /* Bit mask */
if (num_joints > 32) /* Preset mask */
mask = 1 << (num_joints - 1 - 32);
else
mask = 1 << (num_joints - 1);
cprintf ("%s ", label);
for (x = num_joints - 1; x >= 0; x--) {
/* Iterate all bits */
if (x < 32)
cprintf ("%d", ((state->part2 & mask) ? 1 : 0));
else
cprintf ("%d", ((state->part1 & mask) ? 1 : 0));
if (x % 4 == 0)
cprintf (" ");
if (mask == 1) /* Next mask value */
mask = 1 << 31;
else
mask >>= 1;
}
}
void print_state ( STATE state,
int  num_joints,
STRING toappend 
)

Definition at line 246 of file states.cpp.

{
PIECES_STATE pieces;
bin_to_pieces(state, num_joints, pieces);
for (int i = 0; pieces[i] > 0; i++) {
if (i > 0) {
toappend->add_str_int(" ", pieces[i]);
} else {
toappend->add_str_int("", pieces[i]);
}
}
}
void set_n_ones ( STATE state,
int  n 
)

set_n_ones

Set the first n bits in a state.

Definition at line 263 of file states.cpp.

{
if (n < 32) {
state->part2 = ~0;
state->part2 >>= 32 - n;
state->part1 = 0;
}
else {
state->part2 = ~0;
state->part1 = ~0;
state->part1 >>= 64 - n;
}
}