35 #define _USE_MATH_DEFINES 39 #define M_PI 3.14159265358979323846 72 #define PROGRAM_FEATURE_TYPE "mf" 90 #ifndef GRAPHICS_DISABLED 91 static void DisplayProtoList(
const char* ch,
LIST protolist) {
93 520, 520, -130.0, 130.0, -130.0, 130.0);
94 LIST proto = protolist;
101 else if (prototype->
Merged)
108 float dx =
static_cast<float>(
LengthOf(prototype->
Mean) * cos(angle) / 2);
109 float dy =
static_cast<float>(
LengthOf(prototype->
Mean) * sin(angle) / 2);
110 c_move(window, (x - dx) * 256, (y - dy) * 256);
111 c_draw(window, (x + dx) * 256, (y + dy) * 256);
113 tprintf(
"Green proto at (%g,%g)+(%g,%g) %d samples\n",
116 tprintf(
"Red proto at (%g,%g)+(%g,%g) %d samples\n",
121 #endif // GRAPHICS_DISABLED 125 static LIST ClusterOneConfig(
int shape_id,
const char* class_label,
141 #ifndef GRAPHICS_DISABLED 142 if (strcmp(FLAGS_test_ch.c_str(), class_label) == 0)
143 DisplayProtoList(FLAGS_test_ch.c_str(), proto_list);
144 #endif // GRAPHICS_DISABLED 151 if (merge_class == NULL) {
153 mf_classes =
push(mf_classes, merge_class);
157 LIST proto_it = proto_list;
173 static_cast<FLOAT32>(merge_class->
NumMerged[p_id]),
190 int num_configs = shape_table->
NumShapes();
191 config_map->
Init(num_configs,
true);
193 for (
int c1 = 0; c1 < num_configs; ++c1) {
198 for (
int c2 = c1 + 1; c2 < num_configs; ++c2) {
200 config_map->
Merge(c1, c2);
238 int main (
int argc,
char **argv) {
256 SetupConfigMap(shape_table, &config_map);
268 unicharset = &shape_set;
272 for (
int s = 0; s < num_shapes; ++s) {
280 int num_configs = shape_table->
NumShapes();
282 for (
int s = 0; s < num_configs; ++s) {
283 int unichar_id, font_id;
284 if (unicharset == &shape_set) {
291 const char* class_label = unicharset->
id_to_unichar(unichar_id);
292 mf_classes = ClusterOneConfig(s, class_label, mf_classes, *shape_table,
295 STRING inttemp_file = file_prefix;
296 inttemp_file +=
"inttemp";
297 STRING pffmtable_file = file_prefix;
298 pffmtable_file +=
"pffmtable";
302 *shape_table, float_classes,
305 for (
int c = 0; c < unicharset->
size(); ++c) {
308 delete [] float_classes;
313 if (!FLAGS_test_ch.empty()) {
315 printf(
"Hit return to exit...\n");
316 while (getchar() !=
'\n');
void c_draw(void *win, double x, double y)
FEATURE_DEFS_STRUCT feature_defs
ScrollView * c_create_window(const char *name, inT16 xpos, inT16 ypos, inT16 xsize, inT16 ysize, double xmin, double xmax, double ymin, double ymax)
void c_make_current(void *win)
virtual int SparseToCompact(int sparse_index) const
int AddConfigToClass(CLASS_TYPE Class)
CLASS_STRUCT * SetUpForFloat2Int(const UNICHARSET &unicharset, LIST LabeledClassList)
UnicityTableEqEq< int > font_set
#define AddProtoToConfig(Pid, Config)
int FindClosestExistingProto(CLASS_TYPE Class, int NumMerged[], PROTOTYPE *Prototype)
void FreeClassFields(CLASS_TYPE Class)
void ParseArguments(int *argc, char ***argv)
LIST RemoveInsignificantProtos(LIST ProtoList, BOOL8 KeepSigProtos, BOOL8 KeepInsigProtos, int N)
void c_line_color_index(void *win, C_COL index)
void MakeNewFromOld(PROTO New, PROTOTYPE *Old)
int NumMerged[MAX_NUM_PROTOS]
const int kMaxShapeLabelLength
const char * string() const
DECLARE_STRING_PARAM_FLAG(test_ch)
void CleanUpUnusedData(LIST ProtoList)
bool IsEqualUnichars(Shape *other)
bool Merge(int compact_index1, int compact_index2)
void FreeClusterer(CLUSTERER *Clusterer)
MasterTrainer * LoadTrainingData(int argc, const char *const *argv, bool replication, ShapeTable **shape_table, STRING *file_prefix)
void WriteShapeTable(const STRING &file_prefix, const ShapeTable &shape_table)
bool AnyMultipleUnichars() const
LIST ClusterSamples(CLUSTERER *Clusterer, CLUSTERCONFIG *Config)
void WriteInttempAndPFFMTable(const UNICHARSET &unicharset, const UNICHARSET &shape_set, const ShapeTable &shape_table, CLASS_STRUCT *float_classes, const char *inttemp_file, const char *pffmtable_file)
Shape * MutableShape(int shape_id)
void TESS_API unichar_insert(const char *const unichar_repr)
void GetFirstUnicharAndFont(int shape_id, int *unichar_id, int *font_id) const
LIST push(LIST list, void *element)
void c_move(void *win, double x, double y)
void MergeInsignificantProtos(LIST ProtoList, const char *label, CLUSTERER *Clusterer, CLUSTERCONFIG *Config)
void Init(int size, bool all_mapped)
void ComputeMergedProto(PROTO p1, PROTO p2, FLOAT32 w1, FLOAT32 w2, PROTO MergedProto)
#define ProtoIn(Class, Pid)
void FreeLabeledClassList(LIST ClassList)
MERGE_CLASS NewLabeledClass(const char *Label)
const char * id_to_unichar(UNICHAR_ID id) const
MERGE_CLASS FindClass(LIST List, const char *Label)
int AddProtoToClass(CLASS_TYPE Class)
int push_back(T object)
Add an element in the table.
const UNICHARSET & unicharset() const
void FreeProtoList(LIST *ProtoList)
CLUSTERER * SetupForClustering(const ShapeTable &shape_table, const FEATURE_DEFS_STRUCT &feature_defs, int shape_id, int *num_samples)
int main(int argc, char **argv)