diff --git a/openbr/core/core.cpp b/openbr/core/core.cpp index 677fc81..669d42c 100644 --- a/openbr/core/core.cpp +++ b/openbr/core/core.cpp @@ -198,12 +198,10 @@ struct AlgorithmCore QScopedPointer outputTform(Transform::make(outputDesc, NULL)); stages.append(outputTform.data()); stages.append(progressCounter.data()); - QScopedPointer discard(Transform::make("Discard",NULL)); - stages.append(discard.data()); QScopedPointer pipeline(br::pipeTransforms(stages)); - QScopedPointer stream(br::wrapTransform(pipeline.data(), "Stream(readMode=StreamGallery)")); + QScopedPointer stream(br::wrapTransform(pipeline.data(), "Stream(readMode=StreamGallery, endPoint=DiscardTemplates)")); TemplateList data, output; data.append(input); @@ -486,8 +484,6 @@ struct AlgorithmCore // The ProgressCounter transform will simply provide a display about the number of rows completed. compareOutput.append(progressCounter.data()); - QScopedPointer discard(Transform::make("Discard",NULL)); - compareOutput.append(discard.data()); // With this, we have set up a transform which (optionally) enrolls templates, compares them // against a gallery, and outputs them. @@ -495,7 +491,7 @@ struct AlgorithmCore // Now, we will give that base transform to a stream, which will incrementally read the row gallery // and pass the transforms it reads through the base algorithm. - QScopedPointer streamWrapper(br::wrapTransform(pipeline, "Stream(readMode=StreamGallery)")); + QScopedPointer streamWrapper(br::wrapTransform(pipeline, "Stream(readMode=StreamGallery, endPoint=DiscardTemplates)")); // We set up a template containing the rowGallery we want to compare. TemplateList rowGalleryTemplate; diff --git a/openbr/plugins/misc.cpp b/openbr/plugins/misc.cpp index dc7d76a..a5e72c8 100644 --- a/openbr/plugins/misc.cpp +++ b/openbr/plugins/misc.cpp @@ -278,6 +278,23 @@ class DiscardTransform : public UntrainableMetaTransform BR_REGISTER(Transform, DiscardTransform) +class DiscardTemplatesTransform : public UntrainableMetaTransform +{ + Q_OBJECT + + void project(const Template &src, Template &dst) const + { + (void) src; (void) dst; + qFatal("Incorrect project called on DiscardTemplatesTransform"); + } + void project(const TemplateList &src, TemplateList &dst) const + { + (void) src; + dst.clear(); + } +}; +BR_REGISTER(Transform, DiscardTemplatesTransform) + /*! * \ingroup transforms * \brief Removes all but the first matrix from the template. diff --git a/openbr/plugins/stream.cpp b/openbr/plugins/stream.cpp index 72c32b8..b9eef58 100644 --- a/openbr/plugins/stream.cpp +++ b/openbr/plugins/stream.cpp @@ -1085,6 +1085,32 @@ public: }; +class CollectOutputTransform : public TimeVaryingTransform +{ + Q_OBJECT +public: + CollectOutputTransform() : TimeVaryingTransform(false, false) {} + + TemplateList data; + + void projectUpdate(const TemplateList &src, TemplateList &dst) + { + (void) dst; + data.append(src); + } + + void finalize(TemplateList & output) + { + output = data; + data.clear(); + } + void train(const TemplateList &data) + { + (void) data; + } +}; +BR_REGISTER(Transform, CollectOutputTransform) + // This stage reads new frames from the data source. class ReadStage : public SingleThreadStage { @@ -1204,11 +1230,12 @@ class DirectStreamTransform : public CompositeTransform { Q_OBJECT public: - Q_PROPERTY(int activeFrames READ get_activeFrames WRITE set_activeFrames RESET reset_activeFrames) Q_PROPERTY(br::Idiocy::StreamModes readMode READ get_readMode WRITE set_readMode RESET reset_readMode) + Q_PROPERTY(br::Transform* endPoint READ get_endPoint WRITE set_endPoint RESET reset_endPoint STORED true) BR_PROPERTY(int, activeFrames, 100) BR_PROPERTY(br::Idiocy::StreamModes, readMode, br::Idiocy::Auto) + BR_PROPERTY(br::Transform*, endPoint, make("CollectOutput")) friend class StreamTransfrom; @@ -1349,22 +1376,19 @@ public: } final_output.append(output_set); } + endPoint->projectUpdate(final_output); // Clear dst, since we set it to src so that the datasource could open it dst.clear(); // dst is set to all output received by the final stage, along // with anything output via the calls to finalize. - foreach (const TemplateList &list, collector->sets) - dst.append(list); - - collector->sets.clear(); - - dst.append(final_output); + TemplateList output; + endPoint->finalize(output); + dst.append(output); foreach (ProcessingStage *stage, processingStages) stage->reset(); - } @@ -1387,7 +1411,7 @@ public: QMutexLocker poolLock(&poolsAccess); QHash::Iterator it; if (!pools.contains(this->parent())) { - it = pools.insert(this->parent(), new QThreadPool(this->parent())); + it = pools.insert(this->parent(), new QThreadPool()); it.value()->setMaxThreadCount(Globals->parallelism); } else it = pools.find(this->parent()); @@ -1440,7 +1464,7 @@ public: // We also have the last stage, which just puts the output of the // previous stages on a template list. collectionStage = new SingleThreadStage(prev_stage_variance); - collectionStage->transform = this->collector.data(); + collectionStage->transform = this->endPoint; processingStages.append(collectionStage); @@ -1456,11 +1480,6 @@ public: collectionStage->nextStage = readStage; } - DirectStreamTransform() - { - this->collector = QSharedPointer(new CollectSets()); - } - ~DirectStreamTransform() { // Delete all the stages @@ -1476,7 +1495,6 @@ protected: ReadStage *readStage; SingleThreadStage *collectionStage; - QSharedPointer collector; QList processingStages; @@ -1525,11 +1543,13 @@ public: { } + Q_PROPERTY(br::Transform* endPoint READ get_endPoint WRITE set_endPoint RESET reset_endPoint STORED true) Q_PROPERTY(int activeFrames READ get_activeFrames WRITE set_activeFrames RESET reset_activeFrames) Q_PROPERTY(br::Idiocy::StreamModes readMode READ get_readMode WRITE set_readMode RESET reset_readMode) BR_PROPERTY(int, activeFrames, 100) BR_PROPERTY(br::Idiocy::StreamModes, readMode, br::Idiocy::Auto) + BR_PROPERTY(br::Transform*, endPoint, make("CollectOutput")) bool timeVarying() const { return true; } @@ -1571,6 +1591,7 @@ public: basis->transforms.clear(); basis->activeFrames = this->activeFrames; basis->readMode = this->readMode; + basis->endPoint = this->endPoint; // We need at least a CompositeTransform * to acess transform's children. CompositeTransform *downcast = dynamic_cast (transform);