|
From: Herton R. K. <he...@us...> - 2005-07-07 03:20:04
|
Update of /cvsroot/kimageprocess/kimageprocess/src/libkimageprocess In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22048/src/libkimageprocess Modified Files: ktclassifbackend.cpp ktfeaturemanager.cpp ktfeaturemanager.h ktmethodmanager.h ktpluginmanager.cpp ktpluginmanager.h ktproject.cpp ktproject.h Log Message: - Added support to select different classifiers. - Cosmetics. - Remove some debug. - Fix warning (variable j not used). Index: ktproject.cpp =================================================================== RCS file: /cvsroot/kimageprocess/kimageprocess/src/libkimageprocess/ktproject.cpp,v retrieving revision 1.19 retrieving revision 1.20 diff -u -d -r1.19 -r1.20 --- ktproject.cpp 6 Jul 2005 01:34:43 -0000 1.19 +++ ktproject.cpp 7 Jul 2005 03:19:54 -0000 1.20 @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2004-2005 by * + * Copyright (C) 2004-2005 by * * Gustavo Pichorim Boiko <gus...@kd...> * * Herton Ronaldo Krzesinski <he...@my...> * * * @@ -32,6 +32,9 @@ #include <qfile.h> #include "ktcalculation.h" +#include "ktmethod.h" +#include "ktmethodmanager.h" +#include "ktpluginmanager.h" KTProject::KTProject(QObject *parent, const char *name) : QObject(parent, name)/*, @@ -73,21 +76,21 @@ { // close the current project closeProject(); - + // load the project from a XML file if (!KIO::NetAccess::download(project, m_tmpfile, 0)) return; - + QFile file(m_tmpfile); - + if (file.open(IO_ReadOnly)) { QDomDocument doc; - + doc.setContent(&file); - + QDomElement root = doc.documentElement(); - + if (root.nodeName() != "kimageprocess") { KMessageBox::error(0, i18n("This file is not a valid kimageprocess project"), @@ -136,7 +139,7 @@ KTImageManager::self()->clear(); m_isSaved = false; m_changed = false; - m_url = ""; + m_url = ""; } bool KTProject::isSaved() @@ -156,7 +159,7 @@ } void KTProject::addSampleImage(const KURL &url) -{ +{ m_changed = true; KTImageManager::self()->addSampleImage(url); } @@ -180,7 +183,17 @@ QDomElement rootElem = m_doc.createElement("kimageprocess"); m_doc.appendChild(rootElem); - emit aboutToSave(&m_doc, &rootElem); + emit aboutToSave(&m_doc, &rootElem); + + //saving the current method + QDomElement activeMethod = m_doc.createElement("selected_method"); + rootElem.appendChild(activeMethod); + activeMethod.setAttribute("name", KTMethodManager::self()->activeMethod()->methodName()); + + //saving the current classifier + QDomElement activeClassifier = m_doc.createElement("selected_classifier"); + rootElem.appendChild(activeClassifier); + activeClassifier.setAttribute("name", KTPluginManager::self()->classifier()->classifierName()); //saving the sample images QDomElement samplesGroup = m_doc.createElement("sample_images"); @@ -233,7 +246,7 @@ void KTProject::loadProject(QDomElement *rootElem) { bool ok; - unsigned int i, j; + unsigned int i; QDomNodeList nodes = rootElem->childNodes(); QDomElement samplesGroup; @@ -243,13 +256,23 @@ for (i=0; i < nodes.count(); i++) { QString nodeName = nodes.item(i).nodeName(); - + if (nodeName == "sample_images") samplesGroup = nodes.item(i).toElement(); else if (nodeName == "testing_images") testingGroup = nodes.item(i).toElement(); else if (nodeName == "texture_options") trOptions = nodes.item(i).toElement(); + else if (nodeName == "selected_method") + { + QDomElement activeMethod = nodes.item(i).toElement(); + KTMethodManager::self()->setActiveMethod(activeMethod.attribute("name", "glcm")); + } + else if (nodeName == "selected_classifier") + { + QDomElement activeClassifier = nodes.item(i).toElement(); + KTPluginManager::self()->setClassifier(activeClassifier.attribute("name", "fann")); + } } emit aboutToLoad(rootElem); @@ -263,14 +286,14 @@ if (samples.item(i).nodeName() == "sample") { QDomElement sample = samples.item(i).toElement(); - + QString filename = sample.attribute("url", QString::null); - + if (filename != QString::null) addSampleImage(KURL(filename)); } } - + // load the sample images from the project QDomNodeList images = testingGroup.childNodes(); for (i=0; i < images.count(); i++) @@ -278,14 +301,14 @@ if (images.item(i).nodeName() == "image") { QDomElement image = images.item(i).toElement(); - + QString filename = image.attribute("url", QString::null); - + if (filename != QString::null) addTestingImage(KURL(filename)); } } - + //load the texture options QDomNodeList options = trOptions.childNodes(); for (i=0; i < options.count(); i++) Index: ktproject.h =================================================================== RCS file: /cvsroot/kimageprocess/kimageprocess/src/libkimageprocess/ktproject.h,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- ktproject.h 1 Jul 2005 22:15:13 -0000 1.6 +++ ktproject.h 7 Jul 2005 03:19:54 -0000 1.7 @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2004-2005 by * + * Copyright (C) 2004-2005 by * * Gustavo Pichorim Boiko <gus...@kd...> * * Herton Ronaldo Krzesinski <he...@my...> * * * @@ -44,64 +44,64 @@ KTProject(QObject *parent = 0, const char *name = 0); ~KTProject(); - + /** Create a new project */ void newProject(); - + /** Open an existent project */ void openProject(const KURL &project); - + /** Open an URL */ void openURL(QString url); - + /** Save the current project */ void saveProject(const KURL &url = 0); - + /** Close the currently opened project */ void closeProject(); - + /** Return true if the project has benn saved, otherwise, return false */ bool isSaved(); - + /** Return true if the project has changed */ bool changed(); void setChanged() { m_changed = true; } - + /** Remove a training sample image */ void removeSampleImage(KTImage *image); - + /** Add a training sample image */ void addSampleImage(const KURL &url); - + /** Remove a training sample image */ void removeTestingImage(KTImage *image); - + /** Add a training sample image */ void addTestingImage(const KURL &url); - + /** Return the url of the project */ KURL url() { return m_url; } - + static KTProject *self(); - + signals: void addToRecent(const KURL &url); - void aboutToSave(QDomDocument *doc, QDomElement *rootElem); - void aboutToLoad(QDomElement *elem); - + void aboutToSave(QDomDocument *doc, QDomElement *rootElem); + void aboutToLoad(QDomElement *elem); + private: /** Generate the XML document in a QString */ QString generateDoc(); - + /** Load the project from a root element */ void loadProject(QDomElement *rootElem); - + KURL m_url; QString m_tmpfile; bool m_isSaved; bool m_changed; - + static KTProject *s_self; }; Index: ktpluginmanager.h =================================================================== RCS file: /cvsroot/kimageprocess/kimageprocess/src/libkimageprocess/ktpluginmanager.h,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- ktpluginmanager.h 3 Jul 2005 01:42:13 -0000 1.6 +++ ktpluginmanager.h 7 Jul 2005 03:19:54 -0000 1.7 @@ -47,21 +47,22 @@ ~KTPluginManager(); void setPatternManager(KTImageManager *pm); - + void loadPlugins(); - + static KTPluginManager *self(); - + KTClassifBackend *classifier(); - + ClassifierList availableClassifiers() const { return m_backends; } - + void setClassifier(const QString &classif); - + private: //KMainWindow *m_window; ClassifierList m_backends; static KTPluginManager *s_self; + QString m_classif; }; #endif Index: ktmethodmanager.h =================================================================== RCS file: /cvsroot/kimageprocess/kimageprocess/src/libkimageprocess/ktmethodmanager.h,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- ktmethodmanager.h 1 Jul 2005 00:37:20 -0000 1.6 +++ ktmethodmanager.h 7 Jul 2005 03:19:54 -0000 1.7 @@ -47,7 +47,7 @@ MethodList methods(); - KTMethod *activeMethod(); + KTMethod *activeMethod(); void setActiveMethod(const QString &method); static KTMethodManager *self(); Index: ktclassifbackend.cpp =================================================================== RCS file: /cvsroot/kimageprocess/kimageprocess/src/libkimageprocess/ktclassifbackend.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- ktclassifbackend.cpp 23 Jun 2005 23:19:41 -0000 1.6 +++ ktclassifbackend.cpp 7 Jul 2005 03:19:54 -0000 1.7 @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2004-2005 by * + * Copyright (C) 2004-2005 by * * Gustavo Pichorim Boiko <gus...@kd...> * * Herton Ronaldo Krzesinski <he...@my...> * * * @@ -41,7 +41,7 @@ { Q_UNUSED(data); Q_UNUSED(inputs); - Q_UNUSED(outputs); + Q_UNUSED(outputs); } QString KTClassifBackend::classifierName() Index: ktfeaturemanager.cpp =================================================================== RCS file: /cvsroot/kimageprocess/kimageprocess/src/libkimageprocess/ktfeaturemanager.cpp,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- ktfeaturemanager.cpp 6 Jul 2005 01:34:43 -0000 1.12 +++ ktfeaturemanager.cpp 7 Jul 2005 03:19:54 -0000 1.13 @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2004-2005 by * + * Copyright (C) 2004-2005 by * * Gustavo Pichorim Boiko <gus...@kd...> * * Herton Ronaldo Krzesinski <he...@my...> * * * @@ -91,7 +91,7 @@ if (list) return *list; - return FeatureList(); + return FeatureList(); } void KTFeatureManager::resolveDeps() @@ -152,12 +152,10 @@ void KTFeatureManager::slotSave(QDomDocument *doc, QDomElement *elem) { - kdDebug() << "BLABLABLABLABLABLA" << endl; QDomElement rootElem = doc->createElement("Features"); QDomElement featElem; QDictIterator<FeatureList> features(m_features); - kdDebug() << "ASDF" << endl; for (; features.current(); ++features) { QDictIterator<KTFeature> it(*features.current()); @@ -205,7 +203,6 @@ (*list)[*it]->setEnabled(true); } } - } } } Index: ktfeaturemanager.h =================================================================== RCS file: /cvsroot/kimageprocess/kimageprocess/src/libkimageprocess/ktfeaturemanager.h,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- ktfeaturemanager.h 23 Jun 2005 18:33:51 -0000 1.6 +++ ktfeaturemanager.h 7 Jul 2005 03:19:54 -0000 1.7 @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2004-2005 by * + * Copyright (C) 2004-2005 by * * Gustavo Pichorim Boiko <gus...@kd...> * * Herton Ronaldo Krzesinski <he...@my...> * * * @@ -44,7 +44,7 @@ ~KTFeatureManager(); static KTFeatureManager *self(); - + void loadFeatures(); FeatureList features(const QString &type); @@ -53,17 +53,17 @@ KTFeature *getFeature(const QString &type, const QString &feature); - void disableFeatures(const QString &type); + void disableFeatures(const QString &type); QDict<FeatureList> *allFeatures(); - + public slots: - void slotSave(QDomDocument *doc, QDomElement *elem); - void slotLoad(QDomElement *elem); + void slotSave(QDomDocument *doc, QDomElement *elem); + void slotLoad(QDomElement *elem); private: void resolveDeps(); - + QDict<FeatureList> m_features; static KTFeatureManager *s_self; Index: ktpluginmanager.cpp =================================================================== RCS file: /cvsroot/kimageprocess/kimageprocess/src/libkimageprocess/ktpluginmanager.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- ktpluginmanager.cpp 23 Jun 2005 23:19:41 -0000 1.6 +++ ktpluginmanager.cpp 7 Jul 2005 03:19:54 -0000 1.7 @@ -32,7 +32,6 @@ { } - KTPluginManager::~KTPluginManager() { } @@ -56,12 +55,24 @@ void KTPluginManager::loadPlugins() { KTClassifBackend *plugin; - + KTrader::OfferList offers = KTrader::self()->query("KImageProcess/Plugin"); - + KTrader::OfferList::ConstIterator iter; - + kdDebug() << "Loading plugins..." << endl; + + iter = offers.begin(); + if (iter != offers.end()) + { + KService::Ptr service = *iter; + int errCode = 0; + plugin = KParts::ComponentFactory::createInstanceFromService<KTClassifBackend> + ( service, this, 0, QStringList(), &errCode); + if (plugin) + m_classif = plugin->classifierName(); + } + for(iter = offers.begin(); iter != offers.end(); ++iter) { KService::Ptr service = *iter; @@ -70,7 +81,7 @@ ( service, this, 0, QStringList(), &errCode); // here we ought to check the error code. - if (plugin) + if (plugin) { //m_window->guiFactory()->addClient(plugin); kdDebug() << "Loaded classifier: " << plugin->classifierName() << endl; @@ -82,7 +93,13 @@ KTClassifBackend *KTPluginManager::classifier() { - //FIXME: hardcoded to snns - return m_backends["snns"]; + return m_backends[m_classif]; } + +void KTPluginManager::setClassifier(const QString &classif) +{ + if (m_backends[classif]) + m_classif = classif; +} + #include "ktpluginmanager.moc" |