diff --git a/openbr/core/core.cpp b/openbr/core/core.cpp index c827045..0b56d71 100644 --- a/openbr/core/core.cpp +++ b/openbr/core/core.cpp @@ -207,38 +207,6 @@ struct AlgorithmCore data >> *transform; } - // Read metadata for all templates stored in the specified gallery, return the read - // TeamplateList. If the gallery contains matrices, they are dropped. - void emptyRead(const File & file, TemplateList & templates) - { - // Is this a gallery type containing matrices? - if ((QStringList() << "gal" << "mem" << "template").contains(file.suffix())) { - // Retrieve it block by block, dropping matrices from read templates. - QScopedPointer gallery(Gallery::make(file)); - gallery->set_readBlockSize(10); - bool done = false; - while (!done) - { - TemplateList tList = gallery->readBlock(&done); - for (int i=0; i < tList.size();i++) - { - tList[i].clear(); - templates.append(tList[i]); - } - } - } - else { - // The file may have already been enrolled to a memory gallery - emptyRead(getMemoryGallery(file), templates); - if (!templates.empty()) - return; - - // Nope, just retrieve the metadata - QScopedPointer gallery(Gallery::make(file)); - templates = gallery->read(); - } - } - void retrieveOrEnroll(const File &file, QScopedPointer &gallery, FileList &galleryFiles) { if (!file.getBool("enroll") && (QStringList() << "gal" << "mem" << "template").contains(file.suffix())) { @@ -378,32 +346,13 @@ struct AlgorithmCore // To decide which gallery is larger, we need to read both, but at this point we just want the // metadata, and don't need the enrolled matrices. - TemplateList targetMetadata; - TemplateList queryMetadata; + FileList targetMetadata; + FileList queryMetadata; // Emptyread reads a gallery, and discards any matrices present, keeping only the metadata. emptyRead(targetGallery, targetMetadata); emptyRead(queryGallery, queryMetadata); - // We store the metadata for the target and query sets as separate memory galleries. - // This is necessary because we need to intialize the Output with this data, but we don't - // create the Output directly in this function (going instead through OutputTransform) - File targetMetaMem = targetGallery; - targetMetaMem.name = name + targetMetaMem.baseName()+ "_meta" + targetMetaMem.hash()+ ".mem"; - File queryMetaMem = queryGallery; - queryMetaMem.name = name + queryMetaMem.baseName() + "_meta" + queryMetaMem.hash() + ".mem"; - - - - // Store the metadata in memory galleries. - QScopedPointer targetMeta(Gallery::make(targetMetaMem)); - if (targetMeta->files().isEmpty() ) - targetMeta->writeBlock(targetMetadata); - - QScopedPointer queryMeta(Gallery::make(queryMetaMem)); - if (queryMeta->files().isEmpty()) - queryMeta->writeBlock(queryMetadata); - // Is the target or query set larger? We will use the larger as the rows of our comparison matrix (and transpose the output if necessary) transposeMode = targetMetadata.size() > queryMetadata.size(); @@ -524,7 +473,7 @@ struct AlgorithmCore // The output transform takes the metadata memGalleries we set up previously as input, along with the // output specification we were passed. Gallery metadata is necessary for some Outputs to function correctly. QString outputString = output.flat().isEmpty() ? "Empty" : output.flat(); - QString outputRegionDesc = "Output("+ outputString +"," + targetMetaMem.flat() +"," + queryMetaMem.flat() + ","+ QString::number(transposeMode ? 1 : 0) + ")"; + QString outputRegionDesc = "Output("+ outputString +"," + targetGallery.flat() +"," + queryGallery.flat() + ","+ QString::number(transposeMode ? 1 : 0) + ")"; // The ProgressCounter transform will simply provide a display about the number of rows completed. outputRegionDesc += "+ProgressCounter("+QString::number(rowSize)+")+Discard"; QScopedPointer outputTform(Transform::make(outputRegionDesc, NULL)); @@ -770,4 +719,5 @@ QSharedPointer br::Distance::fromAlgorithm(const QString &algorith return AlgorithmManager::getAlgorithm(algorithm)->distance; } + #include "core.moc" diff --git a/openbr/plugins/gallery.cpp b/openbr/plugins/gallery.cpp index e1e2144..d427e8e 100644 --- a/openbr/plugins/gallery.cpp +++ b/openbr/plugins/gallery.cpp @@ -393,6 +393,49 @@ class memGallery : public Gallery BR_REGISTER(Gallery, memGallery) +void emptyRead(const File & file, FileList & fileData, bool cache) +{ + File targetMeta = file; + targetMeta.name = targetMeta.path() + targetMeta.baseName() + "_meta" + targetMeta.hash() + ".mem"; + + // Did we already read the data? + if (MemoryGalleries::galleries.contains(targetMeta)) + { + fileData = MemoryGalleries::galleries[targetMeta].files(); + return; + } + + TemplateList templates; + // OK we read the data in some form, does the gallery type containing matrices? + if ((QStringList() << "gal" << "mem" << "template").contains(file.suffix())) { + // Retrieve it block by block, dropping matrices from read templates. + QScopedPointer gallery(Gallery::make(file)); + gallery->set_readBlockSize(10); + bool done = false; + while (!done) + { + TemplateList tList = gallery->readBlock(&done); + for (int i=0; i < tList.size();i++) + { + tList[i].clear(); + templates.append(tList[i].file); + } + } + } + else { + // this is a gallery format that doesn't include matrices, so we can just read it + QScopedPointer gallery(Gallery::make(file)); + templates= gallery->read(); + } + + if (cache) + { + QScopedPointer memOutput(Gallery::make(targetMeta)); + memOutput->writeBlock(templates); + } + fileData = templates.files(); +} + /*! * \ingroup galleries * \brief Treats each line as a file. diff --git a/openbr/plugins/misc.cpp b/openbr/plugins/misc.cpp index eee78ca..547e453 100644 --- a/openbr/plugins/misc.cpp +++ b/openbr/plugins/misc.cpp @@ -636,11 +636,10 @@ class OutputTransform : public TimeVaryingTransform if (targetName.isEmpty() || queryName.isEmpty() || outputString.isEmpty()) return; - QScopedPointer tGallery(Gallery::make(targetName)); - QScopedPointer qGallery(Gallery::make(queryName)); - - FileList targetFiles = tGallery->files(); - FileList queryFiles = qGallery->files(); + FileList targetFiles; + FileList queryFiles; + emptyRead(targetName, targetFiles, false); + emptyRead(queryName, queryFiles, false); currentBlockRow = 0; currentBlockCol = 0; diff --git a/openbr/plugins/openbr_internal.h b/openbr/plugins/openbr_internal.h index 98fab50..ad80050 100644 --- a/openbr/plugins/openbr_internal.h +++ b/openbr/plugins/openbr_internal.h @@ -314,6 +314,11 @@ struct WorkerProcess void mainLoop(); }; + +// Read metadata for all templates stored in the specified gallery, return the read +// TeamplateList. If the gallery contains matrices, they are dropped. +void emptyRead(const File & file, FileList & templates, bool cache = true); + } #endif // OPENBR_INTERNAL_H