123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- /*********************************************************************/
- /* */
- /* Copyright 2022-2023 Rémi Synave - remi.synave@univ-littoral.fr */
- /* */
- /* This file is part of DSL. */
- /* This software uses Qt to build the Graphical User Interface */
- /* https://www.qt.io/ */
- /* */
- /* DSL is free software: you can redistribute it and/or modify */
- /* it under the terms of the GNU General Public License as published */
- /* by the Free Software Foundation, either version 3 of the License, */
- /* or (at your option) any later version. */
- /* */
- /* DSL is distributed in the hope that it will be useful, */
- /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
- /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
- /* GNU General Public License for more details. */
- /* */
- /* You should have received a copy of the GNU General Public License */
- /* along with DSL. If not, see <http://www.gnu.org/licenses/>. */
- /* */
- /*********************************************************************/
- #include <QDebug>
- #include <QFile>
- #include <QJsonObject>
- #include <QJsonArray>
- #include <QJsonDocument>
- #include <vector>
- #include <cmath>
- #include "SLList.hpp"
- SLList::SLList (const char* file)
- {
- list.clear();
-
- QFile fin(QString::fromStdString (file));
- fin.open(QIODevice::ReadOnly);
- QByteArray ba = fin.readAll();
- QJsonParseError parseError;
- QJsonDocument doc = QJsonDocument::fromJson(ba, &parseError);
- QJsonArray lines = doc["lines"].toArray();
- for(int i=0; i<lines.size(); i++){
- QJsonArray line = lines[i].toArray();
- QJsonArray point1 = line[0].toArray();
- QJsonArray point2 = line[1].toArray();
- list << new StrengthLine(point1[0].toDouble(), point1[1].toDouble(), point2[0].toDouble(), point2[1].toDouble());
- }
- }
- std::pair<double, int> SLList::distance_avg(SLList* sllist, QImage* img) const
- {
- const SLList *list1 = this, *list2 = sllist;
- std::vector<double> mins;
- double sum = 0;
- double min;
- for(unsigned int i = 0 ; i < list1->size(); i++)
- {
- min = list1->get(i)->distance(list2->get(0), img->width(), img->height());
-
- for(unsigned int j = 1 ; j < list2->size(); j++)
- {
- double temp = list1->get(i)->distance(list2->get(j), img->width(), img->height());
- if(temp < min)
- min = temp;
- }
- mins.push_back(min);
- }
- unsigned int minsize = this->size();
- if(list2->size() < minsize)
- minsize = list2->size();
- sort(mins.begin(), mins.end());
-
- for(unsigned int i = 0 ; i < minsize ; i++)
- sum+=mins[i];
- sum/=minsize;
-
- return std::make_pair(sum, size()-sllist->size());
- }
- std::pair<double, int> SLList::distance(SLList* sllist1, SLList* sllist2, QImage* img)
- {
- std::pair<double, int> d1 = sllist1->distance_avg(sllist2, img);
- std::pair<double, int> d2 = sllist2->distance_avg(sllist1, img);
- return std::make_pair((std::get<0>(d1)+std::get<0>(d2))/2, abs(std::get<1>(d1)));
- }
- /*
- std::pair<double, int> SLList::distance_hausdorff(SLList* sllist, QImage* img) const
- {
- const SLList *list1 = this, *list2 = sllist;
- if(size() > sllist->size())
- {
- list1 = sllist;
- list2 = this;
- }
- double max = -1;
- double min;
- for(unsigned int i = 0 ; i < list1->size(); i++)
- {
- min = list1->get(i)->distance(list2->get(0), img->width(), img->height());
-
- for(unsigned int j = 1 ; j < list2->size(); j++)
- {
- double temp = list1->get(i)->distance(list2->get(j), img->width(), img->height());
- if(temp < min)
- min = temp;
- }
- if(max<0)
- max = min;
- else
- if(min>max)
- max=min;
- }
- return std::make_pair(max, size()-sllist->size());
- }
- */
|