See class comment for arguments.
| 45 | |
| 46 | // See class comment for arguments. |
| 47 | void SampleIterator::Init(const IndexMapBiDi* charset_map, |
| 48 | const ShapeTable* shape_table, |
| 49 | bool randomize, |
| 50 | TrainingSampleSet* sample_set) { |
| 51 | Clear(); |
| 52 | charset_map_ = charset_map; |
| 53 | shape_table_ = shape_table; |
| 54 | sample_set_ = sample_set; |
| 55 | randomize_ = randomize; |
| 56 | if (shape_table_ == NULL && charset_map_ != NULL) { |
| 57 | // The caller wishes to iterate by class. The easiest way to do this |
| 58 | // is to create a dummy shape_table_ that we will own. |
| 59 | int num_fonts = sample_set_->NumFonts(); |
| 60 | owned_shape_table_ = new ShapeTable(sample_set_->unicharset()); |
| 61 | int charsetsize = sample_set_->unicharset().size(); |
| 62 | for (int c = 0; c < charsetsize; ++c) { |
| 63 | // We always add a shape for each character to keep the index in sync |
| 64 | // with the unichar_id. |
| 65 | int shape_id = owned_shape_table_->AddShape(c, 0); |
| 66 | for (int f = 1; f < num_fonts; ++f) { |
| 67 | if (sample_set_->NumClassSamples(f, c, true) > 0) { |
| 68 | owned_shape_table_->AddToShape(shape_id, c, f); |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | shape_table_ = owned_shape_table_; |
| 73 | } |
| 74 | if (shape_table_ != NULL) { |
| 75 | num_shapes_ = shape_table_->NumShapes(); |
| 76 | } else { |
| 77 | num_shapes_ = randomize ? sample_set_->num_samples() |
| 78 | : sample_set_->num_raw_samples(); |
| 79 | } |
| 80 | Begin(); |
| 81 | } |
| 82 | |
| 83 | // Iterator functions designed for use with a simple for loop: |
| 84 | // for (it.Begin(); !it.AtEnd(); it.Next()) { |
nothing calls this directly
no test coverage detected