123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- /*********************************************************************/
- /* */
- /* 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 "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;
- if(size() > sllist->size())
- {
- list1 = sllist;
- list2 = this;
- }
- double sum = 0;
- double min;
- for(unsigned int i = 0 ; i < list1->size(); i++)
- {
- // std::cout << "--------------------------------------" << std::endl;
- // std::cout << *(list1->get(i)) << std::endl << std::endl;
- min = list1->get(i)->distance(list2->get(0), img->width(), img->height());
- // std::cout << *(list2->get(0)) << " -> " << min << std::endl << "Min : " << min << std::endl;
-
- for(unsigned int j = 1 ; j < list2->size(); j++)
- {
- double temp = list1->get(i)->distance(list2->get(j), img->width(), img->height());
- // std::cout << *(list2->get(j)) << " -> " << temp << std::endl;
- if(temp < min)
- min = temp;
- // std::cout << "Min : " << min << std::endl;
- }
- sum += min;
- // std::cout << std::endl << "Sum : " << sum << std::endl << std::endl;
- }
- return std::make_pair(sum/list1->size(), size()-sllist->size());
- }
- 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());
- }
|