Commit c9e43a5f78f2ee7d2f65847002cb4281ec6c5ebd

Authored by Josh Klontz
1 parent b5f4124c

optimized enrollment from a directory

sdk/core/qtutils.cpp
@@ -39,7 +39,7 @@ QStringList QtUtils::getFiles(QDir dir, bool recursive) @@ -39,7 +39,7 @@ QStringList QtUtils::getFiles(QDir dir, bool recursive)
39 39
40 QStringList files; 40 QStringList files;
41 foreach (const QString &file, NaturalStringSort(dir.entryList(QDir::Files))) 41 foreach (const QString &file, NaturalStringSort(dir.entryList(QDir::Files)))
42 - files.append(QDir::cleanPath(dir.absoluteFilePath(file))); 42 + files.append(dir.absoluteFilePath(file));
43 43
44 if (!recursive) return files; 44 if (!recursive) return files;
45 45
sdk/openbr_plugin.cpp
@@ -383,6 +383,15 @@ TemplateList TemplateList::fromGallery(const br::File &gallery) @@ -383,6 +383,15 @@ TemplateList TemplateList::fromGallery(const br::File &gallery)
383 QScopedPointer<Gallery> i(Gallery::make(file)); 383 QScopedPointer<Gallery> i(Gallery::make(file));
384 TemplateList newTemplates = i->read(); 384 TemplateList newTemplates = i->read();
385 newTemplates = newTemplates.mid(gallery.get<int>("pos", 0), gallery.get<int>("length", -1)); 385 newTemplates = newTemplates.mid(gallery.get<int>("pos", 0), gallery.get<int>("length", -1));
  386 +
  387 + const int step = gallery.get<int>("step", 1);
  388 + if (step > 1) {
  389 + TemplateList downsampled; downsampled.reserve(newTemplates.size()/step);
  390 + for (int i=0; i<newTemplates.size(); i+=step)
  391 + downsampled.append(newTemplates[i]);
  392 + newTemplates = downsampled;
  393 + }
  394 +
386 if (gallery.get<bool>("reduce", false)) newTemplates = newTemplates.reduced(); 395 if (gallery.get<bool>("reduce", false)) newTemplates = newTemplates.reduced();
387 const int crossValidate = gallery.get<int>("crossValidate"); 396 const int crossValidate = gallery.get<int>("crossValidate");
388 if (crossValidate > 0) srand(0); 397 if (crossValidate > 0) srand(0);
sdk/plugins/gallery.cpp
@@ -14,6 +14,7 @@ @@ -14,6 +14,7 @@
14 * limitations under the License. * 14 * limitations under the License. *
15 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 15 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
16 16
  17 +#include <QtConcurrentRun>
17 #ifndef BR_EMBEDDED 18 #ifndef BR_EMBEDDED
18 #include <QNetworkAccessManager> 19 #include <QNetworkAccessManager>
19 #include <QNetworkReply> 20 #include <QNetworkReply>
@@ -103,9 +104,14 @@ class EmptyGallery : public Gallery @@ -103,9 +104,14 @@ class EmptyGallery : public Gallery
103 104
104 // Add immediate subfolders 105 // Add immediate subfolders
105 QDir dir(file); 106 QDir dir(file);
106 - foreach (const QString &folder, NaturalStringSort(dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)))  
107 - foreach (const QString &file, QtUtils::getFiles(dir.absoluteFilePath(folder), true))  
108 - templates.append(File(file, folder)); 107 + QList< QFuture<TemplateList> > futures;
  108 + foreach (const QString &folder, NaturalStringSort(dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot))) {
  109 + const QDir subdir = dir.absoluteFilePath(folder);
  110 + if (Globals->parallelism) futures.append(QtConcurrent::run(&EmptyGallery::getTemplates, subdir));
  111 + else templates.append(getTemplates(subdir));
  112 + }
  113 + foreach (const QFuture<TemplateList> &future, futures)
  114 + templates.append(future.result());
109 115
110 // Add root folder 116 // Add root folder
111 foreach (const QString &fileName, QtUtils::getFiles(file.name, false)) 117 foreach (const QString &fileName, QtUtils::getFiles(file.name, false))
@@ -130,6 +136,15 @@ class EmptyGallery : public Gallery @@ -130,6 +136,15 @@ class EmptyGallery : public Gallery
130 format->write(t); 136 format->write(t);
131 } 137 }
132 } 138 }
  139 +
  140 + static TemplateList getTemplates(const QDir &dir)
  141 + {
  142 + const QStringList files = QtUtils::getFiles(dir, true);
  143 + TemplateList templates; templates.reserve(files.size());
  144 + foreach (const QString &file, files)
  145 + templates.append(File(file, dir.dirName()));
  146 + return templates;
  147 + }
133 }; 148 };
134 149
135 BR_REGISTER(Gallery, EmptyGallery) 150 BR_REGISTER(Gallery, EmptyGallery)