SLList.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*********************************************************************/
  2. /* */
  3. /* Copyright 2022-2023 Rémi Synave - remi.synave@univ-littoral.fr */
  4. /* */
  5. /* This file is part of DSL. */
  6. /* This software uses Qt to build the Graphical User Interface */
  7. /* https://www.qt.io/ */
  8. /* */
  9. /* DSL is free software: you can redistribute it and/or modify */
  10. /* it under the terms of the GNU General Public License as published */
  11. /* by the Free Software Foundation, either version 3 of the License, */
  12. /* or (at your option) any later version. */
  13. /* */
  14. /* DSL is distributed in the hope that it will be useful, */
  15. /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
  16. /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
  17. /* GNU General Public License for more details. */
  18. /* */
  19. /* You should have received a copy of the GNU General Public License */
  20. /* along with DSL. If not, see <http://www.gnu.org/licenses/>. */
  21. /* */
  22. /*********************************************************************/
  23. #include <QDebug>
  24. #include <QFile>
  25. #include <QJsonObject>
  26. #include <QJsonArray>
  27. #include <QJsonDocument>
  28. #include "SLList.hpp"
  29. SLList::SLList (const char* file)
  30. {
  31. list.clear();
  32. QFile fin(QString::fromStdString (file));
  33. fin.open(QIODevice::ReadOnly);
  34. QByteArray ba = fin.readAll();
  35. QJsonParseError parseError;
  36. QJsonDocument doc = QJsonDocument::fromJson(ba, &parseError);
  37. QJsonArray lines = doc["lines"].toArray();
  38. for(int i=0; i<lines.size(); i++){
  39. QJsonArray line = lines[i].toArray();
  40. QJsonArray point1 = line[0].toArray();
  41. QJsonArray point2 = line[1].toArray();
  42. list << StrengthLine(point1[0].toDouble(), point1[1].toDouble(), point2[0].toDouble(), point2[1].toDouble());
  43. }
  44. }
  45. std::pair<double, int> SLList::distance(SLList*, QImage*) const
  46. {
  47. return std::make_pair(1, -1);
  48. }