diff --git a/openbr/gui/initialize.cpp b/openbr/gui/initialize.cpp deleted file mode 100644 index 4b1ed74..0000000 --- a/openbr/gui/initialize.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Copyright 2012 The MITRE Corporation * - * * - * Licensed under the Apache License, Version 2.0 (the "License"); * - * you may not use this file except in compliance with the License. * - * You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, software * - * distributed under the License is distributed on an "AS IS" BASIS, * - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * - * See the License for the specific language governing permissions and * - * limitations under the License. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -#include -#include -#include - -#include "initialize.h" - -void br_initialize_gui(const char *sdk_path) -{ - qRegisterMetaType("br::File"); - qRegisterMetaType("br::FileList"); - qRegisterMetaType("br::Template"); - qRegisterMetaType("br::TemplateList"); - br_initialize_qt(sdk_path); - br_set_property("log", qPrintable(QString("%1/log.txt").arg(br_scratch_path()))); -} diff --git a/openbr/gui/initialize.h b/openbr/gui/initialize.h deleted file mode 100644 index c7337bb..0000000 --- a/openbr/gui/initialize.h +++ /dev/null @@ -1,24 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Copyright 2012 The MITRE Corporation * - * * - * Licensed under the Apache License, Version 2.0 (the "License"); * - * you may not use this file except in compliance with the License. * - * You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, software * - * distributed under the License is distributed on an "AS IS" BASIS, * - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * - * See the License for the specific language governing permissions and * - * limitations under the License. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -#ifndef __INITIALIZE_H -#define __INITIALIZE_H - -#include - -BR_EXPORT void br_initialize_gui(const char *sdk_path = ""); - -#endif // __INITIALIZE_H diff --git a/openbr/openbr.cpp b/openbr/openbr.cpp index 85fb78d..b0318bf 100644 --- a/openbr/openbr.cpp +++ b/openbr/openbr.cpp @@ -108,11 +108,6 @@ void br_initialize(int &argc, char *argv[], const char *sdk_path) Context::initialize(argc, argv, sdk_path); } -void br_initialize_qt(const char *sdk_path) -{ - Context::initializeQt(sdk_path); -} - bool br_is_classifier(const char *algorithm) { return IsClassifier(algorithm); diff --git a/openbr/openbr.h b/openbr/openbr.h index 50e3ffd..627bc65 100644 --- a/openbr/openbr.h +++ b/openbr/openbr.h @@ -209,17 +209,11 @@ BR_EXPORT void br_fuse(int num_input_simmats, const char *input_simmats[], const /*! * \brief Wraps br::Context::initialize() - * \see br_initialize_qt br_finalize + * \see br_finalize */ BR_EXPORT void br_initialize(int &argc, char *argv[], const char *sdk_path = ""); /*! - * \brief Wraps br::Context::initializeQt() - * \see br_initialize br_finalize - */ -BR_EXPORT void br_initialize_qt(const char *sdk_path = ""); - -/*! * \brief Wraps br::IsClassifier() */ BR_EXPORT bool br_is_classifier(const char *algorithm); diff --git a/openbr/openbr_plugin.cpp b/openbr/openbr_plugin.cpp index 0a632c8..5eba9a9 100644 --- a/openbr/openbr_plugin.cpp +++ b/openbr/openbr_plugin.cpp @@ -819,14 +819,16 @@ bool br::Context::checkSDKPath(const QString &sdkPath) return QFileInfo(sdkPath + "/share/openbr/openbr.bib").exists(); } -void br::Context::initialize(int &argc, char *argv[], const QString &sdkPath) +// We create our own when the user hasn't +static QCoreApplication *application = NULL; + +void br::Context::initialize(int &argc, char *argv[], QString sdkPath) { // We take in argc as a reference due to: // https://bugreports.qt-project.org/browse/QTBUG-5637 // QApplication should be initialized before anything else. // Since we can't ensure that it gets deleted last, we never delete it. - static QCoreApplication *application = NULL; - if (application == NULL) { + if (QCoreApplication::instance() == NULL) { #ifndef BR_EMBEDDED application = new QApplication(argc, argv); #else @@ -834,40 +836,24 @@ void br::Context::initialize(int &argc, char *argv[], const QString &sdkPath) #endif } - if (Globals == NULL) { - Globals = new Context(); - Globals->init(File()); - } - - initializeQt(sdkPath); - -#ifdef BR_DISTRIBUTED - int rank, size; - 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; -#endif // BR_DISTRIBUTED -} - -void br::Context::initializeQt(QString sdkPath) -{ - 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(); + qRegisterMetaType(); + qRegisterMetaType(); + qRegisterMetaType(); + qRegisterMetaType(); qRegisterMetaType< br::Transform* >(); - qRegisterMetaType< QList >(); qRegisterMetaType< br::Distance* >(); + qRegisterMetaType< QList >(); + qRegisterMetaType< QList >(); + qRegisterMetaType< QList >(); qRegisterMetaType< QList >(); - qRegisterMetaType< cv::Mat >(); + + Globals = new Context(); + Globals->init(File()); qInstallMessageHandler(messageHandler); @@ -890,7 +876,6 @@ void br::Context::initializeQt(QString sdkPath) } else { if (!checkSDKPath(sdkPath)) qFatal("Unable to locate SDK from %s.", qPrintable(sdkPath)); } - Globals->sdkPath = sdkPath; // Trigger registered initializers @@ -906,12 +891,11 @@ void br::Context::finalize() foreach (const QSharedPointer &initializer, initializers) initializer->finalize(); -#ifdef BR_DISTRIBUTED - MPI_Finalize(); -#endif // BR_DISTRIBUTED - delete Globals; Globals = NULL; + + delete application; + application = NULL; } QString br::Context::about() diff --git a/openbr/openbr_plugin.h b/openbr/openbr_plugin.h index 2f6dd80..0189030 100644 --- a/openbr/openbr_plugin.h +++ b/openbr/openbr_plugin.h @@ -652,33 +652,10 @@ public: * -# The working directory * -# The executable's location * \note Tiggers \em abort() on failure to locate share/openbr/openbr.bib. - * \note Qt users should instead call initializeQt(). - * \see initializeQt finalize + * \note Qt users should instead call this after initializing QApplication. + * \see finalize */ - static void initialize(int &argc, char *argv[], const QString &sdkPath = ""); - - /*! - * \brief Alternative to initialize() for Qt users. - * - * This alternative to initialize() should be used when a - * QCoreApplication - * has already been defined. - * \code - * int main(int argc, char *argv[]) - * { - * QApplication a(argc, argv); - * br::Context::initializeQt(); - * - * // ... - * - * int result = a.exec(); - * br::Context::finalize(); - * return result; - * } - * \endcode - * \see initialize - */ - static void initializeQt(QString sdkPath); + static void initialize(int &argc, char *argv[], QString sdkPath = ""); /*! * \brief Call \em once at the end of the application to deallocate global variables. @@ -1306,12 +1283,16 @@ BR_EXPORT void Cat(const QStringList &inputGalleries, const QString &outputGalle } // namespace br -Q_DECLARE_METATYPE(QList) -Q_DECLARE_METATYPE(QList) +Q_DECLARE_METATYPE(cv::Mat) +Q_DECLARE_METATYPE(br::File) +Q_DECLARE_METATYPE(br::FileList) +Q_DECLARE_METATYPE(br::Template) +Q_DECLARE_METATYPE(br::TemplateList) Q_DECLARE_METATYPE(br::Transform*) -Q_DECLARE_METATYPE(QList) Q_DECLARE_METATYPE(br::Distance*) +Q_DECLARE_METATYPE(QList) +Q_DECLARE_METATYPE(QList) +Q_DECLARE_METATYPE(QList) Q_DECLARE_METATYPE(QList) -Q_DECLARE_METATYPE(cv::Mat) #endif // __OPENBR_PLUGIN_H