|
From: Herton R. K. <he...@us...> - 2005-07-01 00:37:33
|
Update of /cvsroot/kimageprocess/kimageprocess/src/libkimageprocess In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6681/src/libkimageprocess Modified Files: ktcalculation.cpp ktcalculation.h ktfeaturemanager.cpp ktmethod.h ktmethodmanager.h ktproject.cpp Log Message: - Cosmetics. - Added code to save current selected method and its features on the project file that is saved. Index: ktproject.cpp =================================================================== RCS file: /cvsroot/kimageprocess/kimageprocess/src/libkimageprocess/ktproject.cpp,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- ktproject.cpp 23 Jun 2005 23:19:41 -0000 1.15 +++ ktproject.cpp 1 Jul 2005 00:37:20 -0000 1.16 @@ -31,8 +31,12 @@ #include <qstringlist.h> #include <qfile.h> -#include "ktpatternmanager.h" #include "ktcalculation.h" +#include "ktfeature.h" +#include "ktfeaturemanager.h" +#include "ktmethod.h" +#include "ktmethodmanager.h" +#include "ktpatternmanager.h" KTProject::KTProject(QObject *parent, const char *name) : QObject(parent, name)/*, @@ -112,15 +116,15 @@ void KTProject::saveProject(const KURL &url) { QString doc(generateDoc()); - + KTempFile tmpfile; QTextStream stream(tmpfile.file()); - + tmpfile.setAutoDelete(false); - + stream << doc; tmpfile.close(); - + if (KIO::NetAccess::upload(tmpfile.name(),url,0)) { m_isSaved = true; @@ -165,26 +169,26 @@ m_changed = true; KTImageManager::self()->removeTestingImage(image); } - + void KTProject::addTestingImage(const KURL &url) { m_changed = true; KTImageManager::self()->addTestingImage(url); } - + QString KTProject::generateDoc() { QDomDocument m_doc; - + QDomElement rootElem = m_doc.createElement("kimageprocess"); m_doc.appendChild(rootElem); - + emit aboutToSave(&m_doc, &rootElem); //saving the sample images QDomElement samplesGroup = m_doc.createElement("sample_images"); rootElem.appendChild(samplesGroup); - + QStringList samples = KTImageManager::self()->sampleFileNames(); for (QStringList::Iterator it = samples.begin(); it != samples.end(); ++it) { @@ -195,7 +199,7 @@ //saving the testing images QDomElement testingGroup = m_doc.createElement("testing_images"); rootElem.appendChild(testingGroup); - + QStringList images = KTImageManager::self()->testingFileNames(); for (QStringList::Iterator it = images.begin(); it != images.end(); ++it) { @@ -207,37 +211,57 @@ //saving the texture options QDomElement options = m_doc.createElement("texture_options"); rootElem.appendChild(options); - + window_size temp; QDomElement option; - option = m_doc.createElement("windowType"); - option.setAttribute("value", QString::number(KTCalculation::self()->windowType(), 10)); - options.appendChild(option); - - option = m_doc.createElement("numberIterations"); - option.setAttribute("value", QString::number(KTCalculation::self()->numberIterations(), 10)); - options.appendChild(option); - - temp = KTCalculation::self()->windowSize(); - option = m_doc.createElement("windowSize"); - option.setAttribute("type", temp.type?"true":"false"); - option.setAttribute("x", QString::number(temp.width, 10)); - option.setAttribute("y", QString::number(temp.height, 10)); - options.appendChild(option); - + QString active_method; + + option = m_doc.createElement("activeMethod"); + active_method = KTMethodManager::self()->activeMethod()->methodName(); + option.setAttribute("name", active_method); + options.appendChild(option); + + QDomElement method_options; + method_options = m_doc.createElement("method_options"); + FeatureList features = KTFeatureManager::self()->features(active_method); + + for (QDictIterator<KTFeature> it(features); it.current(); ++it) + { + QDomElement feature = m_doc.createElement("feature"); + method_options.appendChild(feature); + feature.setAttribute("name", it.current()->featureName()); + feature.setAttribute("enabled", it.current()->enabled() ? "true" : "false"); + } + option.appendChild(method_options); + + option = m_doc.createElement("windowType"); + option.setAttribute("value", QString::number(KTCalculation::self()->windowType(), 10)); + options.appendChild(option); + + option = m_doc.createElement("numberIterations"); + option.setAttribute("value", QString::number(KTCalculation::self()->numberIterations(), 10)); + options.appendChild(option); + + temp = KTCalculation::self()->windowSize(); + option = m_doc.createElement("windowSize"); + option.setAttribute("type", temp.type?"true":"false"); + option.setAttribute("x", QString::number(temp.width, 10)); + option.setAttribute("y", QString::number(temp.height, 10)); + options.appendChild(option); + return m_doc.toString(3); } void KTProject::loadProject(QDomElement *rootElem) { bool ok; - unsigned int i; + unsigned int i, j; QDomNodeList nodes = rootElem->childNodes(); - + QDomElement samplesGroup; QDomElement testingGroup; QDomElement trOptions; - + for (i=0; i < nodes.count(); i++) { QString nodeName = nodes.item(i).nodeName(); @@ -249,10 +273,10 @@ else if (nodeName == "texture_options") trOptions = nodes.item(i).toElement(); } - + emit aboutToLoad(rootElem); - KTImageManager::self()->clear(); + KTImageManager::self()->clear(); // load the sample images from the project QDomNodeList samples = samplesGroup.childNodes(); @@ -284,21 +308,41 @@ } } - //load the texture options QDomNodeList options = trOptions.childNodes(); for (i=0; i < options.count(); i++) { QDomElement option = options.item(i).toElement(); - - if (option.nodeName() == "windowType") + QDomElement methodOptionsGroup; + + if (option.nodeName() == "activeMethod") + KTMethodManager::self()->setActiveMethod(option.attribute("name", "glcm")); + else if (option.nodeName() == "method_options") + methodOptionsGroup = options.item(i).toElement(); + else if (option.nodeName() == "windowType") KTCalculation::self()->setWindowType(option.attribute("value").toInt(&ok, 10)); else if (option.nodeName() == "numberIterations") KTCalculation::self()->setNumberIterations(option.attribute("value").toInt(&ok, 10)); else if (option.nodeName() == "windowSize") KTCalculation::self()->setWindowSize((option.attribute("type","true")=="true")? true : false, - option.attribute("x").toInt(&ok, 10), - option.attribute("y").toInt(&ok, 10)); + option.attribute("x").toInt(&ok, 10), + option.attribute("y").toInt(&ok, 10)); + + QDomNodeList features = methodOptionsGroup.childNodes(); + for (j=0; j < features.count(); ++j) + { + if (features.item(i).nodeName() == "feature") + { + QDomElement feature = features.item(i).toElement(); + QString feature_name = feature.attribute("name", QString::null); + if (feature_name == QString::null) + continue; + QString active_method = KTMethodManager::self()->activeMethod()->methodName(); + KTFeature *feature_option = + KTFeatureManager::self()->getFeature(active_method, feature_name); + feature_option->setEnabled((feature.attribute("enabled", "true") == "true") ? true : false); + } + } } m_isSaved = true; m_changed = false; Index: ktcalculation.h =================================================================== RCS file: /cvsroot/kimageprocess/kimageprocess/src/libkimageprocess/ktcalculation.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- ktcalculation.h 28 Jun 2005 22:11:34 -0000 1.4 +++ ktcalculation.h 1 Jul 2005 00:37:19 -0000 1.5 @@ -18,6 +18,7 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ + #ifndef KTCALCULATION_H #define KTCALCULATION_H @@ -27,11 +28,10 @@ class KTImage; class KTMethod; - // texture window types -#define WIN_SEQ 0 // windows are gathered in sequential iterations -#define WIN_CASC 1 // windows are gathered in sequential cascated iterations -#define WIN_RAND 2 // windows are gathered in random iterations +#define WIN_SEQ 0 // windows are gathered in sequential iterations +#define WIN_CASC 1 // windows are gathered in sequential cascated iterations +#define WIN_RAND 2 // windows are gathered in random iterations #define WIN_ALLPIX 3 //windows are generated for all pixels from the image typedef struct @@ -49,7 +49,6 @@ /** A class that actually does the calculation for the images at all - */ class KTCalculation : public QObject { @@ -60,14 +59,14 @@ ~KTCalculation(); static KTCalculation *self(); - + /* functions to handle texture options */ void setWindowType(int type) { m_window_type = type; } int windowType() { return m_window_type; } - + void setNumberIterations(int number) { m_iterations = number; } int numberIterations() { return m_iterations; } - + void setWindowSize(bool type, int height, int width); window_size windowSize(); @@ -76,8 +75,7 @@ public slots: void calculateSampleData(); - void calculateTestData(); - + void calculateTestData(); signals: void updateProgress(); @@ -107,7 +105,6 @@ KTMethod *m_method; static KTCalculation *s_self; - }; #endif Index: ktmethodmanager.h =================================================================== RCS file: /cvsroot/kimageprocess/kimageprocess/src/libkimageprocess/ktmethodmanager.h,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- ktmethodmanager.h 23 Jun 2005 18:33:51 -0000 1.5 +++ ktmethodmanager.h 1 Jul 2005 00:37:20 -0000 1.6 @@ -49,7 +49,7 @@ KTMethod *activeMethod(); void setActiveMethod(const QString &method); - + static KTMethodManager *self(); KTMethod *getMethod(const QString &name); @@ -60,7 +60,7 @@ private: void resolveDeps(); - + MethodList m_methods; KTMethod *m_activeMethod; static KTMethodManager *s_self; Index: ktmethod.h =================================================================== RCS file: /cvsroot/kimageprocess/kimageprocess/src/libkimageprocess/ktmethod.h,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- ktmethod.h 23 Jun 2005 23:19:41 -0000 1.9 +++ ktmethod.h 1 Jul 2005 00:37:19 -0000 1.10 @@ -18,6 +18,7 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ + #ifndef KTMETHOD_H #define KTMETHOD_H @@ -43,7 +44,7 @@ ///must be reimplemented by child classes virtual void calculate(KTImage *img, int imgClass = 0); - + QString methodName(); QString longName(); @@ -56,9 +57,8 @@ protected: QString m_methodName; QString m_longName; - + bool m_testingData; - }; #endif Index: ktfeaturemanager.cpp =================================================================== RCS file: /cvsroot/kimageprocess/kimageprocess/src/libkimageprocess/ktfeaturemanager.cpp,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- ktfeaturemanager.cpp 23 Jun 2005 18:33:50 -0000 1.10 +++ ktfeaturemanager.cpp 1 Jul 2005 00:37:19 -0000 1.11 @@ -82,7 +82,7 @@ kdDebug() << "Loaded " << category << " feature: " << feature->featureName() << endl; } } - + resolveDeps(); } @@ -91,7 +91,7 @@ FeatureList *list = m_features.find(type); if (list) return *list; - + return FeatureList(); } @@ -110,7 +110,7 @@ { int count = 0; FeatureList *features = m_features[type]; - + if (features) { QDictIterator<KTFeature> it(*features); Index: ktcalculation.cpp =================================================================== RCS file: /cvsroot/kimageprocess/kimageprocess/src/libkimageprocess/ktcalculation.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- ktcalculation.cpp 30 Jun 2005 02:37:47 -0000 1.8 +++ ktcalculation.cpp 1 Jul 2005 00:37:19 -0000 1.9 @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2004-2005 by * + * Copyright (C) 2004-2005 by * * Gustavo Pichorim Boiko <gus...@kd...> * * Herton Ronaldo Krzesinski <he...@my...> * * * @@ -18,6 +18,7 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ + #include "ktimage.h" #include "ktcalculation.h" #include "ktfeaturemanager.h" @@ -39,10 +40,8 @@ m_window_size.width = 5; m_window_size.height = 5; m_iterations = 0; - } - KTCalculation::~KTCalculation() { } @@ -68,7 +67,7 @@ m_testing = false; m_method = KTMethodManager::self()->activeMethod(); - + m_inputs = KTFeatureManager::self()->enabledFeaturesCount(m_method->methodName()); m_outputs = KTImageManager::self()->sampleCount(); |