Commit b340693eeb1211095da1ef8be1011f747c8e57e5

Authored by Josh Klontz
1 parent 49e31863

refactored initialization

openbr/gui/initialize.cpp deleted
1 -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *  
2 - * Copyright 2012 The MITRE Corporation *  
3 - * *  
4 - * Licensed under the Apache License, Version 2.0 (the "License"); *  
5 - * you may not use this file except in compliance with the License. *  
6 - * You may obtain a copy of the License at *  
7 - * *  
8 - * http://www.apache.org/licenses/LICENSE-2.0 *  
9 - * *  
10 - * Unless required by applicable law or agreed to in writing, software *  
11 - * distributed under the License is distributed on an "AS IS" BASIS, *  
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *  
13 - * See the License for the specific language governing permissions and *  
14 - * limitations under the License. *  
15 - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */  
16 -  
17 -#include <QDesktopServices>  
18 -#include <QMetaType>  
19 -#include <openbr/openbr_plugin.h>  
20 -  
21 -#include "initialize.h"  
22 -  
23 -void br_initialize_gui(const char *sdk_path)  
24 -{  
25 - qRegisterMetaType<br::File>("br::File");  
26 - qRegisterMetaType<br::FileList>("br::FileList");  
27 - qRegisterMetaType<br::Template>("br::Template");  
28 - qRegisterMetaType<br::TemplateList>("br::TemplateList");  
29 - br_initialize_qt(sdk_path);  
30 - br_set_property("log", qPrintable(QString("%1/log.txt").arg(br_scratch_path())));  
31 -}  
openbr/gui/initialize.h deleted
1 -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *  
2 - * Copyright 2012 The MITRE Corporation *  
3 - * *  
4 - * Licensed under the Apache License, Version 2.0 (the "License"); *  
5 - * you may not use this file except in compliance with the License. *  
6 - * You may obtain a copy of the License at *  
7 - * *  
8 - * http://www.apache.org/licenses/LICENSE-2.0 *  
9 - * *  
10 - * Unless required by applicable law or agreed to in writing, software *  
11 - * distributed under the License is distributed on an "AS IS" BASIS, *  
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *  
13 - * See the License for the specific language governing permissions and *  
14 - * limitations under the License. *  
15 - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */  
16 -  
17 -#ifndef __INITIALIZE_H  
18 -#define __INITIALIZE_H  
19 -  
20 -#include <openbr/openbr_export.h>  
21 -  
22 -BR_EXPORT void br_initialize_gui(const char *sdk_path = "");  
23 -  
24 -#endif // __INITIALIZE_H  
openbr/openbr.cpp
@@ -108,11 +108,6 @@ void br_initialize(int &amp;argc, char *argv[], const char *sdk_path) @@ -108,11 +108,6 @@ void br_initialize(int &amp;argc, char *argv[], const char *sdk_path)
108 Context::initialize(argc, argv, sdk_path); 108 Context::initialize(argc, argv, sdk_path);
109 } 109 }
110 110
111 -void br_initialize_qt(const char *sdk_path)  
112 -{  
113 - Context::initializeQt(sdk_path);  
114 -}  
115 -  
116 bool br_is_classifier(const char *algorithm) 111 bool br_is_classifier(const char *algorithm)
117 { 112 {
118 return IsClassifier(algorithm); 113 return IsClassifier(algorithm);
openbr/openbr.h
@@ -209,17 +209,11 @@ BR_EXPORT void br_fuse(int num_input_simmats, const char *input_simmats[], const @@ -209,17 +209,11 @@ BR_EXPORT void br_fuse(int num_input_simmats, const char *input_simmats[], const
209 209
210 /*! 210 /*!
211 * \brief Wraps br::Context::initialize() 211 * \brief Wraps br::Context::initialize()
212 - * \see br_initialize_qt br_finalize 212 + * \see br_finalize
213 */ 213 */
214 BR_EXPORT void br_initialize(int &argc, char *argv[], const char *sdk_path = ""); 214 BR_EXPORT void br_initialize(int &argc, char *argv[], const char *sdk_path = "");
215 215
216 /*! 216 /*!
217 - * \brief Wraps br::Context::initializeQt()  
218 - * \see br_initialize br_finalize  
219 - */  
220 -BR_EXPORT void br_initialize_qt(const char *sdk_path = "");  
221 -  
222 -/*!  
223 * \brief Wraps br::IsClassifier() 217 * \brief Wraps br::IsClassifier()
224 */ 218 */
225 BR_EXPORT bool br_is_classifier(const char *algorithm); 219 BR_EXPORT bool br_is_classifier(const char *algorithm);
openbr/openbr_plugin.cpp
@@ -819,14 +819,16 @@ bool br::Context::checkSDKPath(const QString &amp;sdkPath) @@ -819,14 +819,16 @@ bool br::Context::checkSDKPath(const QString &amp;sdkPath)
819 return QFileInfo(sdkPath + "/share/openbr/openbr.bib").exists(); 819 return QFileInfo(sdkPath + "/share/openbr/openbr.bib").exists();
820 } 820 }
821 821
822 -void br::Context::initialize(int &argc, char *argv[], const QString &sdkPath) 822 +// We create our own when the user hasn't
  823 +static QCoreApplication *application = NULL;
  824 +
  825 +void br::Context::initialize(int &argc, char *argv[], QString sdkPath)
823 { 826 {
824 // We take in argc as a reference due to: 827 // We take in argc as a reference due to:
825 // https://bugreports.qt-project.org/browse/QTBUG-5637 828 // https://bugreports.qt-project.org/browse/QTBUG-5637
826 // QApplication should be initialized before anything else. 829 // QApplication should be initialized before anything else.
827 // Since we can't ensure that it gets deleted last, we never delete it. 830 // Since we can't ensure that it gets deleted last, we never delete it.
828 - static QCoreApplication *application = NULL;  
829 - if (application == NULL) { 831 + if (QCoreApplication::instance() == NULL) {
830 #ifndef BR_EMBEDDED 832 #ifndef BR_EMBEDDED
831 application = new QApplication(argc, argv); 833 application = new QApplication(argc, argv);
832 #else 834 #else
@@ -834,40 +836,24 @@ void br::Context::initialize(int &amp;argc, char *argv[], const QString &amp;sdkPath) @@ -834,40 +836,24 @@ void br::Context::initialize(int &amp;argc, char *argv[], const QString &amp;sdkPath)
834 #endif 836 #endif
835 } 837 }
836 838
837 - if (Globals == NULL) {  
838 - Globals = new Context();  
839 - Globals->init(File());  
840 - }  
841 -  
842 - initializeQt(sdkPath);  
843 -  
844 -#ifdef BR_DISTRIBUTED  
845 - int rank, size;  
846 - MPI_Init(&argc, &argv);  
847 - MPI_Cobr_rank(MPI_CObr_WORLD, &rank);  
848 - MPI_Cobr_size(MPI_CObr_WORLD, &size);  
849 - if (!quiet) qDebug() << "OpenBR distributed process" << rank << "of" << size;  
850 -#endif // BR_DISTRIBUTED  
851 -}  
852 -  
853 -void br::Context::initializeQt(QString sdkPath)  
854 -{  
855 - if (Globals == NULL) {  
856 - Globals = new Context();  
857 - Globals->init(File());  
858 - }  
859 -  
860 QCoreApplication::setOrganizationName(COMPANY_NAME); 839 QCoreApplication::setOrganizationName(COMPANY_NAME);
861 QCoreApplication::setApplicationName(PRODUCT_NAME); 840 QCoreApplication::setApplicationName(PRODUCT_NAME);
862 QCoreApplication::setApplicationVersion(PRODUCT_VERSION); 841 QCoreApplication::setApplicationVersion(PRODUCT_VERSION);
863 842
864 - qRegisterMetaType< QList<float> >();  
865 - qRegisterMetaType< QList<int> >(); 843 + qRegisterMetaType<cv::Mat>();
  844 + qRegisterMetaType<br::File>();
  845 + qRegisterMetaType<br::FileList>();
  846 + qRegisterMetaType<br::Template>();
  847 + qRegisterMetaType<br::TemplateList>();
866 qRegisterMetaType< br::Transform* >(); 848 qRegisterMetaType< br::Transform* >();
867 - qRegisterMetaType< QList<br::Transform*> >();  
868 qRegisterMetaType< br::Distance* >(); 849 qRegisterMetaType< br::Distance* >();
  850 + qRegisterMetaType< QList<int> >();
  851 + qRegisterMetaType< QList<float> >();
  852 + qRegisterMetaType< QList<br::Transform*> >();
869 qRegisterMetaType< QList<br::Distance*> >(); 853 qRegisterMetaType< QList<br::Distance*> >();
870 - qRegisterMetaType< cv::Mat >(); 854 +
  855 + Globals = new Context();
  856 + Globals->init(File());
871 857
872 qInstallMessageHandler(messageHandler); 858 qInstallMessageHandler(messageHandler);
873 859
@@ -890,7 +876,6 @@ void br::Context::initializeQt(QString sdkPath) @@ -890,7 +876,6 @@ void br::Context::initializeQt(QString sdkPath)
890 } else { 876 } else {
891 if (!checkSDKPath(sdkPath)) qFatal("Unable to locate SDK from %s.", qPrintable(sdkPath)); 877 if (!checkSDKPath(sdkPath)) qFatal("Unable to locate SDK from %s.", qPrintable(sdkPath));
892 } 878 }
893 -  
894 Globals->sdkPath = sdkPath; 879 Globals->sdkPath = sdkPath;
895 880
896 // Trigger registered initializers 881 // Trigger registered initializers
@@ -906,12 +891,11 @@ void br::Context::finalize() @@ -906,12 +891,11 @@ void br::Context::finalize()
906 foreach (const QSharedPointer<Initializer> &initializer, initializers) 891 foreach (const QSharedPointer<Initializer> &initializer, initializers)
907 initializer->finalize(); 892 initializer->finalize();
908 893
909 -#ifdef BR_DISTRIBUTED  
910 - MPI_Finalize();  
911 -#endif // BR_DISTRIBUTED  
912 -  
913 delete Globals; 894 delete Globals;
914 Globals = NULL; 895 Globals = NULL;
  896 +
  897 + delete application;
  898 + application = NULL;
915 } 899 }
916 900
917 QString br::Context::about() 901 QString br::Context::about()
openbr/openbr_plugin.h
@@ -652,33 +652,10 @@ public: @@ -652,33 +652,10 @@ public:
652 * -# The working directory 652 * -# The working directory
653 * -# The executable's location 653 * -# The executable's location
654 * \note Tiggers \em abort() on failure to locate <tt>share/openbr/openbr.bib</tt>. 654 * \note Tiggers \em abort() on failure to locate <tt>share/openbr/openbr.bib</tt>.
655 - * \note <a href="http://qt-project.org/">Qt</a> users should instead call initializeQt().  
656 - * \see initializeQt finalize 655 + * \note <a href="http://qt-project.org/">Qt</a> users should instead call this <i>after</i> initializing QApplication.
  656 + * \see finalize
657 */ 657 */
658 - static void initialize(int &argc, char *argv[], const QString &sdkPath = "");  
659 -  
660 - /*!  
661 - * \brief Alternative to initialize() for <a href="http://qt-project.org/">Qt</a> users.  
662 - *  
663 - * This alternative to initialize() should be used when a  
664 - * <a href="http://doc.qt.digia.com/stable/qcoreapplication.html">QCoreApplication</a>  
665 - * has already been defined.  
666 - * \code  
667 - * int main(int argc, char *argv[])  
668 - * {  
669 - * QApplication a(argc, argv);  
670 - * br::Context::initializeQt();  
671 - *  
672 - * // ...  
673 - *  
674 - * int result = a.exec();  
675 - * br::Context::finalize();  
676 - * return result;  
677 - * }  
678 - * \endcode  
679 - * \see initialize  
680 - */  
681 - static void initializeQt(QString sdkPath); 658 + static void initialize(int &argc, char *argv[], QString sdkPath = "");
682 659
683 /*! 660 /*!
684 * \brief Call \em once at the end of the application to deallocate global variables. 661 * \brief Call \em once at the end of the application to deallocate global variables.
@@ -1306,12 +1283,16 @@ BR_EXPORT void Cat(const QStringList &amp;inputGalleries, const QString &amp;outputGalle @@ -1306,12 +1283,16 @@ BR_EXPORT void Cat(const QStringList &amp;inputGalleries, const QString &amp;outputGalle
1306 1283
1307 } // namespace br 1284 } // namespace br
1308 1285
1309 -Q_DECLARE_METATYPE(QList<float>)  
1310 -Q_DECLARE_METATYPE(QList<int>) 1286 +Q_DECLARE_METATYPE(cv::Mat)
  1287 +Q_DECLARE_METATYPE(br::File)
  1288 +Q_DECLARE_METATYPE(br::FileList)
  1289 +Q_DECLARE_METATYPE(br::Template)
  1290 +Q_DECLARE_METATYPE(br::TemplateList)
1311 Q_DECLARE_METATYPE(br::Transform*) 1291 Q_DECLARE_METATYPE(br::Transform*)
1312 -Q_DECLARE_METATYPE(QList<br::Transform*>)  
1313 Q_DECLARE_METATYPE(br::Distance*) 1292 Q_DECLARE_METATYPE(br::Distance*)
  1293 +Q_DECLARE_METATYPE(QList<int>)
  1294 +Q_DECLARE_METATYPE(QList<float>)
  1295 +Q_DECLARE_METATYPE(QList<br::Transform*>)
1314 Q_DECLARE_METATYPE(QList<br::Distance*>) 1296 Q_DECLARE_METATYPE(QList<br::Distance*>)
1315 -Q_DECLARE_METATYPE(cv::Mat)  
1316 1297
1317 #endif // __OPENBR_PLUGIN_H 1298 #endif // __OPENBR_PLUGIN_H