/*********************************************************************/
/* */
/* 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 . */
/* */
/*********************************************************************/
#include
#include
#include
#include
#include
#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 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 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());
}