From 659370e6b96bd37fb1749c203a4367317784b623 Mon Sep 17 00:00:00 2001 From: Josh Klontz Date: Tue, 22 Jan 2013 09:07:07 -0500 Subject: [PATCH] cleaned up Context --- sdk/openbr_plugin.cpp | 42 ++++++++++++++++++++---------------------- sdk/openbr_plugin.h | 16 ++++++++-------- 2 files changed, 28 insertions(+), 30 deletions(-) diff --git a/sdk/openbr_plugin.cpp b/sdk/openbr_plugin.cpp index 4fb5aee..3e0f31a 100644 --- a/sdk/openbr_plugin.cpp +++ b/sdk/openbr_plugin.cpp @@ -667,20 +667,6 @@ void Object::init(const File &file_) } /* Context - public methods */ -br::Context::Context() -{ - QCoreApplication::setOrganizationName(COMPANY_NAME); - QCoreApplication::setApplicationName(PRODUCT_NAME); - QCoreApplication::setApplicationVersion(PRODUCT_VERSION); - - parallelism = std::max(1, QThread::idealThreadCount()); - blockSize = parallelism * ((sizeof(void*) == 4) ? 128 : 1024); - quiet = verbose = false; - currentStep = totalSteps = 0; - enrollAll = false; - backProject = false; -} - int br::Context::blocks(int size) const { return std::ceil(1.f*size/blockSize); @@ -757,13 +743,11 @@ bool br::Context::checkSDKPath(const QString &sdkPath) void br::Context::initialize(int argc, char *argv[], const QString &sdkPath) { - qRegisterMetaType< QList >(); - qRegisterMetaType< QList >(); - qRegisterMetaType< br::Transform* >(); - qRegisterMetaType< QList >(); - qRegisterMetaType< cv::Mat >(); + if (Globals == NULL) { + Globals = new Context(); + Globals->init(File()); + } - if (Globals == NULL) Globals = new Context(); Globals->coreApplication = QSharedPointer(new QCoreApplication(argc, argv)); initializeQt(sdkPath); @@ -772,13 +756,27 @@ void br::Context::initialize(int argc, char *argv[], const QString &sdkPath) MPI_Init(&argc, &argv); MPI_Cobr_rank(MPI_CObr_WORLD, &rank); MPI_Cobr_size(MPI_CObr_WORLD, &size); - if (!Quiet) qDebug() << "OpenBR distributed process" << rank << "of" << size; + if (!quiet) qDebug() << "OpenBR distributed process" << rank << "of" << size; #endif // BR_DISTRIBUTED } void br::Context::initializeQt(QString sdkPath) { - if (Globals == NULL) Globals = new Context(); + if (Globals == NULL) { + Globals = new Context(); + Globals->init(File()); + } + + QCoreApplication::setOrganizationName(COMPANY_NAME); + QCoreApplication::setApplicationName(PRODUCT_NAME); + QCoreApplication::setApplicationVersion(PRODUCT_VERSION); + + qRegisterMetaType< QList >(); + qRegisterMetaType< QList >(); + qRegisterMetaType< br::Transform* >(); + qRegisterMetaType< QList >(); + qRegisterMetaType< cv::Mat >(); + qInstallMsgHandler(messageHandler); // Search for SDK diff --git a/sdk/openbr_plugin.h b/sdk/openbr_plugin.h index 5435060..d3f7980 100644 --- a/sdk/openbr_plugin.h +++ b/sdk/openbr_plugin.h @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -394,6 +395,7 @@ public: private: template friend struct Factory; + friend class Context; void init(const File &file); /*!< \brief Initializes the plugin's properties from the file's metadata. */ }; @@ -439,16 +441,16 @@ public: BR_PROPERTY(QString, path, "") /*! - * \brief The maximum number of templates to process in parallel. + * \brief The number of threads to use. */ - Q_PROPERTY(int blockSize READ get_blockSize WRITE set_blockSize RESET reset_blockSize) - BR_PROPERTY(int, blockSize, 1) + Q_PROPERTY(int parallelism READ get_parallelism WRITE set_parallelism RESET reset_parallelism) + BR_PROPERTY(int, parallelism, std::max(1, QThread::idealThreadCount())) /*! - * \brief The number of threads to use. + * \brief The maximum number of templates to process in parallel. */ - Q_PROPERTY(int parallelism READ get_parallelism WRITE set_parallelism RESET reset_parallelism) - BR_PROPERTY(int, parallelism, 0) + Q_PROPERTY(int blockSize READ get_blockSize WRITE set_blockSize RESET reset_blockSize) + BR_PROPERTY(int, blockSize, parallelism * ((sizeof(void*) == 4) ? 128 : 1024)) /*! * \brief true if backProject should be used instead of project (the algorithm should be inverted) @@ -515,8 +517,6 @@ public: QHash classes; /*!< \brief Used by classifiers to associate text class labels with unique integers IDs. */ QTime startTime; /*!< \brief Used to estimate timeRemaining(). */ - Context(); - /*! * \brief Returns the suggested number of partitions \em size should be divided into for processing. * \param size The length of the list to be partitioned. -- libgit2 0.21.4