MCPcopy Create free account
hub / github.com/creatale/node-dv / BuildListOfAllLeaves

Method BuildListOfAllLeaves

deps/tesseract/ccmain/paramsd.cpp:196–266  ·  view source on GitHub ↗

Find all editable parameters used within tesseract and create a SVMenuNode tree from it. TODO (wanke): This is actually sort of hackish.

Source from the content-addressed store, hash-verified

194// SVMenuNode tree from it.
195// TODO (wanke): This is actually sort of hackish.
196SVMenuNode* ParamsEditor::BuildListOfAllLeaves(tesseract::Tesseract *tess) {
197 SVMenuNode* mr = new SVMenuNode();
198 ParamContent_LIST vclist;
199 ParamContent_IT vc_it(&vclist);
200 // Amount counts the number of entries for a specific char*.
201 // TODO(rays) get rid of the use of std::map.
202 std::map<const char*, int> amount;
203
204 // Add all parameters to a list.
205 int v, i;
206 int num_iterations = (tess->params() == NULL) ? 1 : 2;
207 for (v = 0; v < num_iterations; ++v) {
208 tesseract::ParamsVectors *vec = (v == 0) ? GlobalParams() : tess->params();
209 for (i = 0; i < vec->int_params.size(); ++i) {
210 vc_it.add_after_then_move(new ParamContent(vec->int_params[i]));
211 }
212 for (i = 0; i < vec->bool_params.size(); ++i) {
213 vc_it.add_after_then_move(new ParamContent(vec->bool_params[i]));
214 }
215 for (i = 0; i < vec->string_params.size(); ++i) {
216 vc_it.add_after_then_move(new ParamContent(vec->string_params[i]));
217 }
218 for (i = 0; i < vec->double_params.size(); ++i) {
219 vc_it.add_after_then_move(new ParamContent(vec->double_params[i]));
220 }
221 }
222
223 // Count the # of entries starting with a specific prefix.
224 for (vc_it.mark_cycle_pt(); !vc_it.cycled_list(); vc_it.forward()) {
225 ParamContent* vc = vc_it.data();
226 STRING tag;
227 STRING tag2;
228 STRING tag3;
229
230 GetPrefixes(vc->GetName(), &tag, &tag2, &tag3);
231 amount[tag.string()]++;
232 amount[tag2.string()]++;
233 amount[tag3.string()]++;
234 }
235
236 vclist.sort(ParamContent::Compare); // Sort the list alphabetically.
237
238 SVMenuNode* other = mr->AddChild("OTHER");
239
240 // go through the list again and this time create the menu structure.
241 vc_it.move_to_first();
242 for (vc_it.mark_cycle_pt(); !vc_it.cycled_list(); vc_it.forward()) {
243 ParamContent* vc = vc_it.data();
244 STRING tag;
245 STRING tag2;
246 STRING tag3;
247 GetPrefixes(vc->GetName(), &tag, &tag2, &tag3);
248
249 if (amount[tag.string()] == 1) {
250 other->AddChild(vc->GetName(), vc->GetId(), vc->GetValue().string(),
251 vc->GetDescription());
252 } else { // More than one would use this submenu -> create submenu.
253 SVMenuNode* sv = mr->AddChild(tag.string());

Callers

nothing calls this directly

Calls 15

GlobalParamsFunction · 0.85
paramsMethod · 0.80
dataMethod · 0.80
AddChildMethod · 0.80
GetValueMethod · 0.80
GetDescriptionMethod · 0.80
sizeMethod · 0.45
add_after_then_moveMethod · 0.45
mark_cycle_ptMethod · 0.45
cycled_listMethod · 0.45
forwardMethod · 0.45
GetNameMethod · 0.45

Tested by

no test coverage detected