Visual debugger classifies the given sample, displays the results and solicits user input to display other classifications. Returns when the user has finished with debugging the sample. Probably doesn't need to be overridden if the subclass provides DisplayClassifyAs.
| 95 | // Probably doesn't need to be overridden if the subclass provides |
| 96 | // DisplayClassifyAs. |
| 97 | void ShapeClassifier::DebugDisplay(const TrainingSample& sample, |
| 98 | Pix* page_pix, |
| 99 | UNICHAR_ID unichar_id) { |
| 100 | #ifndef GRAPHICS_DISABLED |
| 101 | static ScrollView* terminator = NULL; |
| 102 | if (terminator == NULL) { |
| 103 | terminator = new ScrollView("XIT", 0, 0, 50, 50, 50, 50, true); |
| 104 | } |
| 105 | ScrollView* debug_win = CreateFeatureSpaceWindow("ClassifierDebug", 0, 0); |
| 106 | // Provide a right-click menu to choose the class. |
| 107 | SVMenuNode* popup_menu = new SVMenuNode(); |
| 108 | popup_menu->AddChild("Choose class to debug", 0, "x", "Class to debug"); |
| 109 | popup_menu->BuildMenu(debug_win, false); |
| 110 | // Display the features in green. |
| 111 | const INT_FEATURE_STRUCT* features = sample.features(); |
| 112 | int num_features = sample.num_features(); |
| 113 | for (int f = 0; f < num_features; ++f) { |
| 114 | RenderIntFeature(debug_win, &features[f], ScrollView::GREEN); |
| 115 | } |
| 116 | debug_win->Update(); |
| 117 | GenericVector<UnicharRating> results; |
| 118 | // Debug classification until the user quits. |
| 119 | const UNICHARSET& unicharset = GetUnicharset(); |
| 120 | SVEvent* ev; |
| 121 | SVEventType ev_type; |
| 122 | do { |
| 123 | PointerVector<ScrollView> windows; |
| 124 | if (unichar_id >= 0) { |
| 125 | tprintf("Debugging class %d = %s\n", |
| 126 | unichar_id, unicharset.id_to_unichar(unichar_id)); |
| 127 | UnicharClassifySample(sample, page_pix, 1, unichar_id, &results); |
| 128 | DisplayClassifyAs(sample, page_pix, unichar_id, 1, &windows); |
| 129 | } else { |
| 130 | tprintf("Invalid unichar_id: %d\n", unichar_id); |
| 131 | UnicharClassifySample(sample, page_pix, 1, -1, &results); |
| 132 | } |
| 133 | if (unichar_id >= 0) { |
| 134 | tprintf("Debugged class %d = %s\n", |
| 135 | unichar_id, unicharset.id_to_unichar(unichar_id)); |
| 136 | } |
| 137 | tprintf("Right-click in ClassifierDebug window to choose debug class,"); |
| 138 | tprintf(" Left-click or close window to quit...\n"); |
| 139 | UNICHAR_ID old_unichar_id; |
| 140 | do { |
| 141 | old_unichar_id = unichar_id; |
| 142 | ev = debug_win->AwaitEvent(SVET_ANY); |
| 143 | ev_type = ev->type; |
| 144 | if (ev_type == SVET_POPUP) { |
| 145 | if (unicharset.contains_unichar(ev->parameter)) { |
| 146 | unichar_id = unicharset.unichar_to_id(ev->parameter); |
| 147 | } else { |
| 148 | tprintf("Char class '%s' not found in unicharset", ev->parameter); |
| 149 | } |
| 150 | } |
| 151 | delete ev; |
| 152 | } while (unichar_id == old_unichar_id && |
| 153 | ev_type != SVET_CLICK && ev_type != SVET_DESTROY); |
| 154 | } while (ev_type != SVET_CLICK && ev_type != SVET_DESTROY); |
no test coverage detected