Commit 659370e6b96bd37fb1749c203a4367317784b623
1 parent
9240e10e
cleaned up Context
Showing
2 changed files
with
28 additions
and
30 deletions
sdk/openbr_plugin.cpp
| ... | ... | @@ -667,20 +667,6 @@ void Object::init(const File &file_) |
| 667 | 667 | } |
| 668 | 668 | |
| 669 | 669 | /* Context - public methods */ |
| 670 | -br::Context::Context() | |
| 671 | -{ | |
| 672 | - QCoreApplication::setOrganizationName(COMPANY_NAME); | |
| 673 | - QCoreApplication::setApplicationName(PRODUCT_NAME); | |
| 674 | - QCoreApplication::setApplicationVersion(PRODUCT_VERSION); | |
| 675 | - | |
| 676 | - parallelism = std::max(1, QThread::idealThreadCount()); | |
| 677 | - blockSize = parallelism * ((sizeof(void*) == 4) ? 128 : 1024); | |
| 678 | - quiet = verbose = false; | |
| 679 | - currentStep = totalSteps = 0; | |
| 680 | - enrollAll = false; | |
| 681 | - backProject = false; | |
| 682 | -} | |
| 683 | - | |
| 684 | 670 | int br::Context::blocks(int size) const |
| 685 | 671 | { |
| 686 | 672 | return std::ceil(1.f*size/blockSize); |
| ... | ... | @@ -757,13 +743,11 @@ bool br::Context::checkSDKPath(const QString &sdkPath) |
| 757 | 743 | |
| 758 | 744 | void br::Context::initialize(int argc, char *argv[], const QString &sdkPath) |
| 759 | 745 | { |
| 760 | - qRegisterMetaType< QList<float> >(); | |
| 761 | - qRegisterMetaType< QList<int> >(); | |
| 762 | - qRegisterMetaType< br::Transform* >(); | |
| 763 | - qRegisterMetaType< QList<br::Transform*> >(); | |
| 764 | - qRegisterMetaType< cv::Mat >(); | |
| 746 | + if (Globals == NULL) { | |
| 747 | + Globals = new Context(); | |
| 748 | + Globals->init(File()); | |
| 749 | + } | |
| 765 | 750 | |
| 766 | - if (Globals == NULL) Globals = new Context(); | |
| 767 | 751 | Globals->coreApplication = QSharedPointer<QCoreApplication>(new QCoreApplication(argc, argv)); |
| 768 | 752 | initializeQt(sdkPath); |
| 769 | 753 | |
| ... | ... | @@ -772,13 +756,27 @@ void br::Context::initialize(int argc, char *argv[], const QString &sdkPath) |
| 772 | 756 | MPI_Init(&argc, &argv); |
| 773 | 757 | MPI_Cobr_rank(MPI_CObr_WORLD, &rank); |
| 774 | 758 | MPI_Cobr_size(MPI_CObr_WORLD, &size); |
| 775 | - if (!Quiet) qDebug() << "OpenBR distributed process" << rank << "of" << size; | |
| 759 | + if (!quiet) qDebug() << "OpenBR distributed process" << rank << "of" << size; | |
| 776 | 760 | #endif // BR_DISTRIBUTED |
| 777 | 761 | } |
| 778 | 762 | |
| 779 | 763 | void br::Context::initializeQt(QString sdkPath) |
| 780 | 764 | { |
| 781 | - if (Globals == NULL) Globals = new Context(); | |
| 765 | + if (Globals == NULL) { | |
| 766 | + Globals = new Context(); | |
| 767 | + Globals->init(File()); | |
| 768 | + } | |
| 769 | + | |
| 770 | + QCoreApplication::setOrganizationName(COMPANY_NAME); | |
| 771 | + QCoreApplication::setApplicationName(PRODUCT_NAME); | |
| 772 | + QCoreApplication::setApplicationVersion(PRODUCT_VERSION); | |
| 773 | + | |
| 774 | + qRegisterMetaType< QList<float> >(); | |
| 775 | + qRegisterMetaType< QList<int> >(); | |
| 776 | + qRegisterMetaType< br::Transform* >(); | |
| 777 | + qRegisterMetaType< QList<br::Transform*> >(); | |
| 778 | + qRegisterMetaType< cv::Mat >(); | |
| 779 | + | |
| 782 | 780 | qInstallMsgHandler(messageHandler); |
| 783 | 781 | |
| 784 | 782 | // Search for SDK | ... | ... |
sdk/openbr_plugin.h
| ... | ... | @@ -34,6 +34,7 @@ |
| 34 | 34 | #include <QSharedPointer> |
| 35 | 35 | #include <QString> |
| 36 | 36 | #include <QStringList> |
| 37 | +#include <QThread> | |
| 37 | 38 | #include <QTime> |
| 38 | 39 | #include <QVariant> |
| 39 | 40 | #include <QVector> |
| ... | ... | @@ -394,6 +395,7 @@ public: |
| 394 | 395 | |
| 395 | 396 | private: |
| 396 | 397 | template <typename T> friend struct Factory; |
| 398 | + friend class Context; | |
| 397 | 399 | void init(const File &file); /*!< \brief Initializes the plugin's properties from the file's metadata. */ |
| 398 | 400 | }; |
| 399 | 401 | |
| ... | ... | @@ -439,16 +441,16 @@ public: |
| 439 | 441 | BR_PROPERTY(QString, path, "") |
| 440 | 442 | |
| 441 | 443 | /*! |
| 442 | - * \brief The maximum number of templates to process in parallel. | |
| 444 | + * \brief The number of threads to use. | |
| 443 | 445 | */ |
| 444 | - Q_PROPERTY(int blockSize READ get_blockSize WRITE set_blockSize RESET reset_blockSize) | |
| 445 | - BR_PROPERTY(int, blockSize, 1) | |
| 446 | + Q_PROPERTY(int parallelism READ get_parallelism WRITE set_parallelism RESET reset_parallelism) | |
| 447 | + BR_PROPERTY(int, parallelism, std::max(1, QThread::idealThreadCount())) | |
| 446 | 448 | |
| 447 | 449 | /*! |
| 448 | - * \brief The number of threads to use. | |
| 450 | + * \brief The maximum number of templates to process in parallel. | |
| 449 | 451 | */ |
| 450 | - Q_PROPERTY(int parallelism READ get_parallelism WRITE set_parallelism RESET reset_parallelism) | |
| 451 | - BR_PROPERTY(int, parallelism, 0) | |
| 452 | + Q_PROPERTY(int blockSize READ get_blockSize WRITE set_blockSize RESET reset_blockSize) | |
| 453 | + BR_PROPERTY(int, blockSize, parallelism * ((sizeof(void*) == 4) ? 128 : 1024)) | |
| 452 | 454 | |
| 453 | 455 | /*! |
| 454 | 456 | * \brief true if backProject should be used instead of project (the algorithm should be inverted) |
| ... | ... | @@ -515,8 +517,6 @@ public: |
| 515 | 517 | QHash<QString,int> classes; /*!< \brief Used by classifiers to associate text class labels with unique integers IDs. */ |
| 516 | 518 | QTime startTime; /*!< \brief Used to estimate timeRemaining(). */ |
| 517 | 519 | |
| 518 | - Context(); | |
| 519 | - | |
| 520 | 520 | /*! |
| 521 | 521 | * \brief Returns the suggested number of partitions \em size should be divided into for processing. |
| 522 | 522 | * \param size The length of the list to be partitioned. | ... | ... |