Commit 6f130e93e17f698322c362962de45bb2d19b8b5b
1 parent
5bd7cd9a
Make janus_create_templates multi-threaded
Showing
1 changed file
with
27 additions
and
0 deletions
openbr/janus_io.cpp
| @@ -2,6 +2,7 @@ | @@ -2,6 +2,7 @@ | ||
| 2 | 2 | ||
| 3 | #define JANUS_CUSTOM_ADD_SAMPLE | 3 | #define JANUS_CUSTOM_ADD_SAMPLE |
| 4 | #define JANUS_CUSTOM_CREATE_GALLERY | 4 | #define JANUS_CUSTOM_CREATE_GALLERY |
| 5 | +#define JANUS_CUSTOM_CREATE_TEMPLATES | ||
| 5 | #include "janus/src/janus_io.cpp" | 6 | #include "janus/src/janus_io.cpp" |
| 6 | 7 | ||
| 7 | static void _janus_add_sample(vector<double> &samples, double sample) | 8 | static void _janus_add_sample(vector<double> &samples, double sample) |
| @@ -35,3 +36,29 @@ janus_error janus_create_gallery(const char *data_path, janus_metadata metadata, | @@ -35,3 +36,29 @@ janus_error janus_create_gallery(const char *data_path, janus_metadata metadata, | ||
| 35 | futures.waitForFinished(); | 36 | futures.waitForFinished(); |
| 36 | return JANUS_SUCCESS; | 37 | return JANUS_SUCCESS; |
| 37 | } | 38 | } |
| 39 | + | ||
| 40 | +janus_error janus_create_templates(const char *data_path, janus_metadata metadata, const char *gallery_file, int verbose) | ||
| 41 | +{ | ||
| 42 | + TemplateIterator ti(metadata, true); | ||
| 43 | + TemplateData templateData = ti.next(); | ||
| 44 | + unsigned int num_templates = 1; | ||
| 45 | + | ||
| 46 | + janus_gallery gallery; | ||
| 47 | + JANUS_ASSERT(janus_allocate_gallery(&gallery)) | ||
| 48 | + QFutureSynchronizer<void> futures; | ||
| 49 | + while (!templateData.templateIDs.empty()) { | ||
| 50 | + futures.addFuture(QtConcurrent::run(_janus_create_template, data_path, templateData, gallery, verbose)); | ||
| 51 | + templateData = ti.next(); | ||
| 52 | + num_templates++; | ||
| 53 | + } | ||
| 54 | + futures.waitForFinished(); | ||
| 55 | + janus_flat_gallery flat_gallery = new janus_data[num_templates*janus_max_template_size()]; | ||
| 56 | + size_t bytes; | ||
| 57 | + JANUS_ASSERT(janus_flatten_gallery(gallery, flat_gallery, &bytes)) | ||
| 58 | + | ||
| 59 | + std::ofstream file; | ||
| 60 | + file.open(gallery_file, std::ios::out | std::ios::binary | std::ios::ate); | ||
| 61 | + file.write((char*)flat_gallery, bytes); | ||
| 62 | + file.close(); | ||
| 63 | + return JANUS_SUCCESS; | ||
| 64 | +} |