|
From: Gustavo P. B. <gb...@us...> - 2005-07-06 01:34:55
|
Update of /cvsroot/kimageprocess/kimageprocess/src/libkimageprocess In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8751/src/libkimageprocess Modified Files: ktcalculation.cpp ktfeature.cpp ktfeature.h ktfeaturemanager.cpp ktpatternmanager.cpp ktpatternmanager.h ktproject.cpp Log Message: "The Hitchhickers Guide to the Galaxy says that the more stupid is the bug you have the more time it takes for you to fix. And also that the more time it takes to fix and stupid it is, the more you get pissed when you fix it." Now the changes: - Remember to never do checks using memory addresses (see ktfeature.cpp changes) - removed QPtrLists<type> (they are evil) - replaced by QValueLists<type*> - removed duplicated signal connections (causing duplication in the project file) - increased a bit the desired error on fann (Herton, you should try and see a result ;) Index: ktproject.cpp =================================================================== RCS file: /cvsroot/kimageprocess/kimageprocess/src/libkimageprocess/ktproject.cpp,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- ktproject.cpp 1 Jul 2005 23:21:50 -0000 1.18 +++ ktproject.cpp 6 Jul 2005 01:34:43 -0000 1.19 @@ -98,9 +98,9 @@ loadProject(&root); m_isSaved = true; m_changed = false; - m_url = project; + m_url = project; } - } + } addToRecent(project); } Index: ktpatternmanager.h =================================================================== RCS file: /cvsroot/kimageprocess/kimageprocess/src/libkimageprocess/ktpatternmanager.h,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- ktpatternmanager.h 29 Jun 2005 03:03:00 -0000 1.16 +++ ktpatternmanager.h 6 Jul 2005 01:34:43 -0000 1.17 @@ -22,8 +22,8 @@ #define KTPATTERNMANAGER_H #include <qobject.h> -#include <qptrlist.h> #include <qstringlist.h> +#include <qvaluelist.h> #include <kurl.h> @@ -33,7 +33,7 @@ class KTClassifBackend; -typedef QPtrList<KTImage> KTImageList; +typedef QValueList<KTImage*> KTImageList; /** * This class manages all the opened pattern images. Index: ktfeature.h =================================================================== RCS file: /cvsroot/kimageprocess/kimageprocess/src/libkimageprocess/ktfeature.h,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- ktfeature.h 23 Jun 2005 18:33:50 -0000 1.5 +++ ktfeature.h 6 Jul 2005 01:34:43 -0000 1.6 @@ -50,22 +50,19 @@ QString featureName(); QString longName(); - void setManager(KTFeatureManager *manager) { m_manager = manager; } - bool enabled() { return m_enabled; } void setEnabled(bool enable) { m_enabled = enable; } protected: QString m_featureName; QString m_longName; - KTFeatureManager *manager() const { return m_manager; } + KTFeatureManager *manager(); KTMethod *method() const { return m_method; } ///must be reimplemented by child classes virtual float _calculate(KTImage *img, int direction); private: - KTFeatureManager *m_manager; KTMethod *m_method; bool m_enabled; Index: ktpatternmanager.cpp =================================================================== RCS file: /cvsroot/kimageprocess/kimageprocess/src/libkimageprocess/ktpatternmanager.cpp,v retrieving revision 1.32 retrieving revision 1.33 diff -u -d -r1.32 -r1.33 --- ktpatternmanager.cpp 23 Jun 2005 23:19:41 -0000 1.32 +++ ktpatternmanager.cpp 6 Jul 2005 01:34:43 -0000 1.33 @@ -40,9 +40,6 @@ KTImageManager::KTImageManager(QObject *parent, const char *name) : QObject(parent, name) { - // auto-destroy items on delete - m_sampleImages.setAutoDelete(true); - m_testingData = false; } @@ -84,7 +81,12 @@ { emit aboutToRemoveTrPattern(image); - m_sampleImages.remove(image); + KTImageList::iterator it = m_sampleImages.find(image); + if (it != m_sampleImages.end()) + { + delete (*it); + m_sampleImages.remove(it); + } } void KTImageManager::addTestingImage(const KURL &url) @@ -104,15 +106,20 @@ { emit aboutToRemoveTestingImage(image); - m_testingImages.remove(image); + KTImageList::iterator it = m_testingImages.find(image); + if (it != m_testingImages.end()) + { + delete (*it); + m_testingImages.remove(it); + } } QStringList KTImageManager::sampleFileNames() { QStringList list; - KTImage *it; - for ( it = m_sampleImages.first(); it; it = m_sampleImages.next()) - list.append(it->url().url()); + KTImageList::iterator it; + for ( it = m_sampleImages.begin(); it != m_sampleImages.end(); ++it) + list.append((*it)->url().url()); return list; } @@ -120,9 +127,9 @@ QStringList KTImageManager::testingFileNames() { QStringList list; - KTImage *it; - for ( it = m_testingImages.first(); it; it = m_testingImages.next()) - list.append(it->url().url()); + KTImageList::iterator it; + for ( it = m_testingImages.begin(); it != m_testingImages.end(); ++it) + list.append((*it)->url().url()); return list; } Index: ktfeature.cpp =================================================================== RCS file: /cvsroot/kimageprocess/kimageprocess/src/libkimageprocess/ktfeature.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- ktfeature.cpp 30 Jun 2005 02:37:47 -0000 1.8 +++ ktfeature.cpp 6 Jul 2005 01:34:43 -0000 1.9 @@ -54,7 +54,7 @@ float KTFeature::calculate( KTImage *img, int direction ) { - if (img == m_img) + /*if (img == m_img) { Cache::iterator value = m_cacheValue.find(direction); if (value != m_cacheValue.end()) @@ -65,9 +65,9 @@ m_img = img; m_cacheValue.clear(); } - + */ float result = _calculate(img, direction); - m_cacheValue[direction] = result; + //m_cacheValue[direction] = result; return result; } @@ -79,4 +79,9 @@ return 0.0; } +KTFeatureManager *KTFeature::manager() +{ + return KTFeatureManager::self(); +} + #include "ktfeature.moc" Index: ktfeaturemanager.cpp =================================================================== RCS file: /cvsroot/kimageprocess/kimageprocess/src/libkimageprocess/ktfeaturemanager.cpp,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- ktfeaturemanager.cpp 1 Jul 2005 00:37:19 -0000 1.11 +++ ktfeaturemanager.cpp 6 Jul 2005 01:34:43 -0000 1.12 @@ -77,7 +77,6 @@ list = new FeatureList; m_features.insert(category, list); } - feature->setManager(this); list->insert(feature->featureName(),feature); kdDebug() << "Loaded " << category << " feature: " << feature->featureName() << endl; } @@ -136,7 +135,7 @@ void KTFeatureManager::disableFeatures(const QString &type) { - FeatureList *features = m_features[type]; + FeatureList *features = m_features[type]; if (features) { @@ -153,59 +152,61 @@ void KTFeatureManager::slotSave(QDomDocument *doc, QDomElement *elem) { - QDomElement rootElem = doc->createElement("Features"); + kdDebug() << "BLABLABLABLABLABLA" << endl; + QDomElement rootElem = doc->createElement("Features"); - QDomElement featElem; - QDictIterator<FeatureList> features(m_features); + QDomElement featElem; + QDictIterator<FeatureList> features(m_features); + kdDebug() << "ASDF" << endl; for (; features.current(); ++features) { QDictIterator<KTFeature> it(*features.current()); - featElem = doc->createElement("FeatureGroup"); - featElem.setAttribute("Name",features.currentKey()); + featElem = doc->createElement("FeatureGroup"); + featElem.setAttribute("Name",features.currentKey()); - QString enabledFeatures; + QString enabledFeatures; for (; it.current(); ++it) - { + { if (it.current()->enabled()) - enabledFeatures += it.currentKey() + ","; - } - //remove the extra comma - enabledFeatures.remove(enabledFeatures.length()-1,1); - featElem.setAttribute("EnabledFeatures",enabledFeatures); - rootElem.appendChild(featElem); - } - elem->appendChild(rootElem); + enabledFeatures += it.currentKey() + ","; + } + //remove the extra comma + enabledFeatures.remove(enabledFeatures.length()-1,1); + featElem.setAttribute("EnabledFeatures",enabledFeatures); + rootElem.appendChild(featElem); + } + elem->appendChild(rootElem); } void KTFeatureManager::slotLoad(QDomElement *elem) { - QDomNode node = elem->namedItem("Features"); + QDomNode node = elem->namedItem("Features"); - if (node.isNull()) - return; + if (node.isNull()) + return; - QDomNodeList groups = node.childNodes(); + QDomNodeList groups = node.childNodes(); - for (unsigned int i=0; i < groups.count(); ++i) - { - if (groups.item(i).nodeName() == "FeatureGroup") - { - QDomElement current = groups.item(i).toElement(); - QString groupName = current.attribute("Name"); - FeatureList *list = m_features[groupName]; - if (list) - { - disableFeatures(groupName); - QStringList features = QStringList::split(',', current.attribute("EnabledFeatures")); - for (QStringList::Iterator it = features.begin(); it != features.end(); ++it ) - { - if ((*list)[*it]) - (*list)[*it]->setEnabled(true); - } - } - - } - } + for (unsigned int i=0; i < groups.count(); ++i) + { + if (groups.item(i).nodeName() == "FeatureGroup") + { + QDomElement current = groups.item(i).toElement(); + QString groupName = current.attribute("Name"); + FeatureList *list = m_features[groupName]; + if (list) + { + disableFeatures(groupName); + QStringList features = QStringList::split(',', current.attribute("EnabledFeatures")); + for (QStringList::Iterator it = features.begin(); it != features.end(); ++it ) + { + if ((*list)[*it]) + (*list)[*it]->setEnabled(true); + } + } + + } + } } #include "ktfeaturemanager.moc" Index: ktcalculation.cpp =================================================================== RCS file: /cvsroot/kimageprocess/kimageprocess/src/libkimageprocess/ktcalculation.cpp,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- ktcalculation.cpp 2 Jul 2005 23:42:52 -0000 1.11 +++ ktcalculation.cpp 6 Jul 2005 01:34:43 -0000 1.12 @@ -80,10 +80,10 @@ m_first = true; int imgClass = 1; - KTImage *it; + KTImageList::iterator it; KTImageList list = KTImageManager::self()->sampleImages(); - for ( it = list.first(); it; it = list.next()) - generateWindowResults(it, imgClass++); + for ( it = list.begin(); it != list.end(); ++it) + generateWindowResults((*it), imgClass++); //normalize the values normalize(); @@ -235,16 +235,17 @@ } m_first = false; } - - //prepare the input - for (int i=0; i < m_inputs; ++i) + else { - if (results[i] > m_max[i]) - m_max[i] = results[i]; - else if (results[i] < m_min[i]) - m_min[i] = results[i]; + for (int j=0; j < m_inputs; ++j) + { + if (results[j] > m_max[j]) + m_max[j] = results[j]; + else if (results[j] < m_min[j]) + m_min[j] = results[j]; + } } - + //prepare the input dataEntry entry; entry.inputs = results; entry.sampleClass = sampleClass; @@ -271,12 +272,12 @@ QValueList<dataEntry>::iterator end = m_data.end(); float dif[m_inputs]; for (int i=0; i < m_inputs; ++i) - dif[i] = m_max[i] - m_min[i]; + dif[i] = m_max[i] - m_min[i] + 0.0000000000001; for (QValueList<dataEntry>::iterator it = m_data.begin(); it != end; ++it) { for ( int i=0; i < m_inputs; ++i ) - (*it).inputs[i] = ((*it).inputs[i] - m_min[i]) * uplimit / dif[i]; + (*it).inputs[i] = ( ((*it).inputs[i] - m_min[i]) * uplimit ) / dif[i]; } } |