// Path: src/main/java/com/quantumsoft/qupathcloud/exception/QuPathCloudException.java
// public class QuPathCloudException extends Exception {
// 
//   /**
//    * Instantiates a new QuPath cloud exception.
//    *
//    * @param message the message
//    */
//   public QuPathCloudException(String message) {
//     super(message);
//   }
// 
//   /**
//    * Instantiates a new QuPath cloud exception.
//    *
//    * @param e the exception
//    */
//   public QuPathCloudException(Throwable e) {
//     super(e);
//   }
// }


import com.quantumsoft.qupathcloud.exception.QuPathCloudException;
import java.nio.file.Path;
import java.util.Map;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.openslide.OpenSlide;
// Copyright (C) 2019 Google LLC
//
// This program 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.
//
// This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.

package com.quantumsoft.qupathcloud.converter.dicomizer;


/**
 * Converter for dicomization of whole-slide images.
 */
public class ImageToWsiDcmConverter {

  private static final Logger LOGGER = LogManager.getLogger();
  private static final long MAX_TOP_SIZE = 2048;
  private static final int MAX_TILE_SIZE = 512;
  private static final int MIN_TILE_SIZE = 64;
  private static final int DEFAULT_TILE_SIZE = 256;
  private final Path pathToImage;
  private final Path pathToFolder;

  /**
   * Instantiates a new Image to wsi dcm converter.
   *
   * @param pathToImage the path to the image
   * @param pathToFolder the path to the folder
   */
  public ImageToWsiDcmConverter(Path pathToImage, Path pathToFolder) {
    this.pathToImage = pathToImage;
    this.pathToFolder = pathToFolder;
  }

  /**
   * Converts image to DICOM.
   *
   * @param imageName the image name
   * @throws QuPathCloudException if an error occurs
   */
  public void convertImageToWsiDcm(String imageName) throws QuPathCloudException {
    try {
      Dicomizer.Options options = new Dicomizer.Options()
          .inputPath(pathToImage.toString())
          .outputFolder(pathToFolder.toString())
          .imageName(imageName);
      configurePyramidParameters(options);

      Dicomizer.run(options);
    } catch (Throwable e) {
      LOGGER.error("Error converting image to dcm!", e);
// Path: src/main/java/com/quantumsoft/qupathcloud/exception/QuPathCloudException.java
// public class QuPathCloudException extends Exception {
// 
//   /**
//    * Instantiates a new QuPath cloud exception.
//    *
//    * @param message the message
//    */
//   public QuPathCloudException(String message) {
//     super(message);
//   }
// 
//   /**
//    * Instantiates a new QuPath cloud exception.
//    *
//    * @param e the exception
//    */
//   public QuPathCloudException(Throwable e) {
//     super(e);
//   }
// }


// Path: src/main/java/com/quantumsoft/qupathcloud/converter/dicomizer/ImageToWsiDcmConverter.java
import com.quantumsoft.qupathcloud.exception.QuPathCloudException;
import java.nio.file.Path;
import java.util.Map;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.openslide.OpenSlide;

// Copyright (C) 2019 Google LLC
//
// This program 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.
//
// This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.

package com.quantumsoft.qupathcloud.converter.dicomizer;


/**
 * Converter for dicomization of whole-slide images.
 */
public class ImageToWsiDcmConverter {

  private static final Logger LOGGER = LogManager.getLogger();
  private static final long MAX_TOP_SIZE = 2048;
  private static final int MAX_TILE_SIZE = 512;
  private static final int MIN_TILE_SIZE = 64;
  private static final int DEFAULT_TILE_SIZE = 256;
  private final Path pathToImage;
  private final Path pathToFolder;

  /**
   * Instantiates a new Image to wsi dcm converter.
   *
   * @param pathToImage the path to the image
   * @param pathToFolder the path to the folder
   */
  public ImageToWsiDcmConverter(Path pathToImage, Path pathToFolder) {
    this.pathToImage = pathToImage;
    this.pathToFolder = pathToFolder;
  }

  /**
   * Converts image to DICOM.
   *
   * @param imageName the image name
   * @throws QuPathCloudException if an error occurs
   */
  public void convertImageToWsiDcm(String imageName) throws QuPathCloudException {
    try {
      Dicomizer.Options options = new Dicomizer.Options()
          .inputPath(pathToImage.toString())
          .outputFolder(pathToFolder.toString())
          .imageName(imageName);
      configurePyramidParameters(options);

      Dicomizer.run(options);
    } catch (Throwable e) {
      LOGGER.error("Error converting image to dcm!", e);
      throw new QuPathCloudException(e);