/*********************************************************************/
/* */
/* 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
#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;
std::vector 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 SLList::distance(SLList* sllist1, SLList* sllist2, QImage* img)
{
std::pair d1 = sllist1->distance_avg(sllist2, img);
std::pair d2 = sllist2->distance_avg(sllist1, img);
return std::make_pair((std::get<0>(d1)+std::get<0>(d2))/2, std::get<1>(d1));
}
/*
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());
}
*/