// +-------------------------------- DISCLAIMER ---------------------------------+
// |                                                                             |
// | This program is provided to you free of charge "as such".                   |
// | You should not assume that this program is error-free or suitable for any   |
// | purpose whatsoever.                                                         |
// |                                                                             |
// | EURESYS does not give any representation, warranty or undertaking that this |
// | program is free of any defect or error or suitable for any purpose. EURESYS |
// | shall not be liable, in contract, in torts or otherwise, for any damages,   |
// | loss, costs, expenses or other claims for compensation, including those     |
// | asserted by third parties, arising out of or in connection with the use of  |
// | this program.                                                               |
// +-----------------------------------------------------------------------------+

#ifndef PROCESSINGHANDLER_H
#define PROCESSINGHANDLER_H
#include <thread>
#include <string>
#include <QObject>

class CameraHandler;
namespace Euresys
{
  namespace Open_eVision
  {
    class EImageC24;
    class EDrawAdapter;
    namespace EasyDeepLearning
    {
      // Predeclaration for deep learning tools.
      class EClassifier;
      class EUnsupervisedSegmenter;
      class ESupervisedSegmenter;
      class ELocatorBase;
    }
  }
}

class ProcessingHandler : public QObject
{
  Q_OBJECT
Q_SIGNALS:
  void renderedImage(const QImage& image, const QString& label);

public:
  ProcessingHandler(const std::string& deepLearningModel, CameraHandler* cameraHandler);
  ~ProcessingHandler();

  void start();
  bool abort_;

private:
  void run();

  void ProcessImage(const Euresys::Open_eVision::EImageC24& img, std::shared_ptr<Euresys::Open_eVision::EasyDeepLearning::EClassifier> classifier, Euresys::Open_eVision::EDrawAdapter* drawAdapter);
  void ProcessImage(const Euresys::Open_eVision::EImageC24& img, std::shared_ptr<Euresys::Open_eVision::EasyDeepLearning::EUnsupervisedSegmenter> segmenter, Euresys::Open_eVision::EDrawAdapter* drawAdapter);
  void ProcessImage(const Euresys::Open_eVision::EImageC24& img, std::shared_ptr<Euresys::Open_eVision::EasyDeepLearning::ESupervisedSegmenter> segmenter, Euresys::Open_eVision::EDrawAdapter* drawAdapter);
  void ProcessImage(const Euresys::Open_eVision::EImageC24& img, std::shared_ptr<Euresys::Open_eVision::EasyDeepLearning::ELocatorBase> locator, Euresys::Open_eVision::EDrawAdapter* drawAdapter);

  float zoom_;
  std::string model_;
  CameraHandler* cameraHandler_;
  std::thread processingThread_;
};

#endif // PROCESSINGHANDLER_H


