Commit 33ec0cdc9cd7a7f78621f2a8bb5898fa0ae90e43

Authored by Charles Otto
1 parent c860d36e

Don't create temporary transforms containing idenity

Instead, we just prepend/append to transform lists as needed. Maybe this
is less confusing.
Showing 1 changed file with 13 additions and 13 deletions
openbr/core/core.cpp
@@ -47,12 +47,12 @@ struct AlgorithmCore @@ -47,12 +47,12 @@ struct AlgorithmCore
47 qDebug("Training on %s%s", qPrintable(input.flat()), 47 qDebug("Training on %s%s", qPrintable(input.flat()),
48 model.isEmpty() ? "" : qPrintable(" to " + model)); 48 model.isEmpty() ? "" : qPrintable(" to " + model));
49 49
50 - QScopedPointer<Transform> trainingWrapper(Transform::make("DirectStream([Identity], readMode=DistributeFrames)", NULL)); 50 + QScopedPointer<Transform> trainingWrapper(Transform::make("DirectStream(readMode=DistributeFrames)", NULL));
51 51
52 CompositeTransform * downcast = dynamic_cast<CompositeTransform *>(trainingWrapper.data()); 52 CompositeTransform * downcast = dynamic_cast<CompositeTransform *>(trainingWrapper.data());
53 if (downcast == NULL) 53 if (downcast == NULL)
54 qFatal("downcast failed?"); 54 qFatal("downcast failed?");
55 - downcast->transforms[0] = this->transform.data(); 55 + downcast->transforms.append(this->transform.data());
56 56
57 downcast->init(); 57 downcast->init();
58 58
@@ -163,14 +163,14 @@ struct AlgorithmCore @@ -163,14 +163,14 @@ struct AlgorithmCore
163 163
164 if (!multiProcess) 164 if (!multiProcess)
165 { 165 {
166 - QString pipeDesc = "Identity+GalleryOutput("+gallery.flat()+")+ProgressCounter("+QString::number(data.length())+")+Discard"; 166 + QString pipeDesc = "GalleryOutput("+gallery.flat()+")+ProgressCounter("+QString::number(data.length())+")+Discard";
167 basePipe.reset(Transform::make(pipeDesc,NULL)); 167 basePipe.reset(Transform::make(pipeDesc,NULL));
168 CompositeTransform * downcast = dynamic_cast<CompositeTransform *>(basePipe.data()); 168 CompositeTransform * downcast = dynamic_cast<CompositeTransform *>(basePipe.data());
169 if (downcast == NULL) 169 if (downcast == NULL)
170 qFatal("downcast failed?"); 170 qFatal("downcast failed?");
171 171
172 // replace that placeholder with the current algorithm 172 // replace that placeholder with the current algorithm
173 - downcast->transforms[0] = this->transform.data(); 173 + downcast->transforms.prepend(this->transform.data());
174 174
175 // call init on the pipe to collapse the algorithm (if its top level is a pipe) 175 // call init on the pipe to collapse the algorithm (if its top level is a pipe)
176 downcast->init(); 176 downcast->init();
@@ -182,7 +182,7 @@ struct AlgorithmCore @@ -182,7 +182,7 @@ struct AlgorithmCore
182 } 182 }
183 183
184 // Next, we make a Stream (with placeholder transform) 184 // Next, we make a Stream (with placeholder transform)
185 - QString streamDesc = "Stream(Identity, readMode=DistributeFrames)"; 185 + QString streamDesc = "Stream(readMode=DistributeFrames)";
186 QScopedPointer<Transform> baseStream(Transform::make(streamDesc, NULL)); 186 QScopedPointer<Transform> baseStream(Transform::make(streamDesc, NULL));
187 WrapperTransform * wrapper = dynamic_cast<WrapperTransform *> (baseStream.data()); 187 WrapperTransform * wrapper = dynamic_cast<WrapperTransform *> (baseStream.data());
188 188
@@ -428,7 +428,7 @@ struct AlgorithmCore @@ -428,7 +428,7 @@ struct AlgorithmCore
428 // The actual comparison step is done by a GalleryCompare transform, which has a Distance, and a gallery as data. 428 // The actual comparison step is done by a GalleryCompare transform, which has a Distance, and a gallery as data.
429 // Incoming templates are compared against the templates in the gallery, and the output is the resulting score 429 // Incoming templates are compared against the templates in the gallery, and the output is the resulting score
430 // vector. 430 // vector.
431 - QString compareRegionDesc = "GalleryCompare("+Globals->algorithm + "," + colEnrolledGallery.flat() + ")"; 431 + QString compareRegionDesc = "Pipe([GalleryCompare("+Globals->algorithm + "," + colEnrolledGallery.flat() + ")])";
432 432
433 433
434 QScopedPointer<Transform> compareRegion; 434 QScopedPointer<Transform> compareRegion;
@@ -438,13 +438,13 @@ struct AlgorithmCore @@ -438,13 +438,13 @@ struct AlgorithmCore
438 { 438 {
439 if (!multiProcess) 439 if (!multiProcess)
440 { 440 {
441 - compareRegionDesc = "Identity+" + compareRegionDesc; 441 + compareRegionDesc = compareRegionDesc;
442 compareRegion.reset(Transform::make(compareRegionDesc,NULL)); 442 compareRegion.reset(Transform::make(compareRegionDesc,NULL));
443 CompositeTransform * downcast = dynamic_cast<CompositeTransform *> (compareRegion.data()); 443 CompositeTransform * downcast = dynamic_cast<CompositeTransform *> (compareRegion.data());
444 if (downcast == NULL) 444 if (downcast == NULL)
445 qFatal("Pipe downcast failed in compare"); 445 qFatal("Pipe downcast failed in compare");
446 446
447 - downcast->transforms[0] = this->transform.data(); 447 + downcast->transforms.prepend(this->transform.data());
448 downcast->init(); 448 downcast->init();
449 } 449 }
450 else 450 else
@@ -467,7 +467,7 @@ struct AlgorithmCore @@ -467,7 +467,7 @@ struct AlgorithmCore
467 467
468 // We also need to add Output and progress counting to the algorithm we are building, so we will assign them to 468 // We also need to add Output and progress counting to the algorithm we are building, so we will assign them to
469 // two stages of a pipe. 469 // two stages of a pipe.
470 - QString joinDesc = "Identity+Identity"; 470 + QString joinDesc = "Pipe()";
471 QScopedPointer<Transform> join(Transform::make(joinDesc, NULL)); 471 QScopedPointer<Transform> join(Transform::make(joinDesc, NULL));
472 472
473 // The output transform takes the metadata memGalleries we set up previously as input, along with the 473 // The output transform takes the metadata memGalleries we set up previously as input, along with the
@@ -481,8 +481,8 @@ struct AlgorithmCore @@ -481,8 +481,8 @@ struct AlgorithmCore
481 // Assign the comparison transform we previously built, and the output transform we just built to 481 // Assign the comparison transform we previously built, and the output transform we just built to
482 // two stages of a pipe. 482 // two stages of a pipe.
483 CompositeTransform * downcast = dynamic_cast<CompositeTransform *> (join.data()); 483 CompositeTransform * downcast = dynamic_cast<CompositeTransform *> (join.data());
484 - downcast->transforms[0] = compareRegion.data();  
485 - downcast->transforms[1] = outputTform.data(); 484 + downcast->transforms.append(compareRegion.data());
  485 + downcast->transforms.append(outputTform.data());
486 486
487 // With this, we have set up a transform which (optionally) enrolls templates, compares them 487 // With this, we have set up a transform which (optionally) enrolls templates, compares them
488 // against a gallery, and outputs them. 488 // against a gallery, and outputs them.
@@ -490,7 +490,7 @@ struct AlgorithmCore @@ -490,7 +490,7 @@ struct AlgorithmCore
490 490
491 // Now, we will give that base transform to a stream, which will incrementally read the row gallery 491 // Now, we will give that base transform to a stream, which will incrementally read the row gallery
492 // and pass the transforms it reads through the base algorithm. 492 // and pass the transforms it reads through the base algorithm.
493 - QString streamDesc = "Stream(Identity, readMode=StreamGallery)"; 493 + QString streamDesc = "Stream(readMode=StreamGallery)";
494 QScopedPointer<Transform> streamBase(Transform::make(streamDesc, NULL)); 494 QScopedPointer<Transform> streamBase(Transform::make(streamDesc, NULL));
495 WrapperTransform * streamWrapper = dynamic_cast<WrapperTransform *> (streamBase.data()); 495 WrapperTransform * streamWrapper = dynamic_cast<WrapperTransform *> (streamBase.data());
496 streamWrapper->transform = join.data(); 496 streamWrapper->transform = join.data();
@@ -706,7 +706,7 @@ QSharedPointer&lt;br::Transform&gt; br::Transform::fromAlgorithm(const QString &amp;algori @@ -706,7 +706,7 @@ QSharedPointer&lt;br::Transform&gt; br::Transform::fromAlgorithm(const QString &amp;algori
706 return AlgorithmManager::getAlgorithm(algorithm)->transform; 706 return AlgorithmManager::getAlgorithm(algorithm)->transform;
707 else { 707 else {
708 QSharedPointer<Transform> orig_tform = AlgorithmManager::getAlgorithm(algorithm)->transform; 708 QSharedPointer<Transform> orig_tform = AlgorithmManager::getAlgorithm(algorithm)->transform;
709 - QSharedPointer<Transform> newRoot = QSharedPointer<Transform>(Transform::make("Stream(Identity, readMode=DistributeFrames)", NULL)); 709 + QSharedPointer<Transform> newRoot = QSharedPointer<Transform>(Transform::make("Stream(readMode=DistributeFrames)", NULL));
710 WrapperTransform * downcast = dynamic_cast<WrapperTransform *> (newRoot.data()); 710 WrapperTransform * downcast = dynamic_cast<WrapperTransform *> (newRoot.data());
711 downcast->transform = orig_tform.data(); 711 downcast->transform = orig_tform.data();
712 downcast->init(); 712 downcast->init();