<commit_before>/*===================================================================

The Medical Imaging Interaction Toolkit (MITK)

Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.

This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.

See LICENSE.txt or http://www.mitk.org for details.

===================================================================*/
#include <mitkToFCameraMITKPlayerController.h>
#include <itksys/SystemTools.hxx>

// mitk includes
#include "mitkItkImageFileReader.h"
#include "mitkIOUtil.h"
#include <mitkIpPic.h>
#include "mitkImageReadAccessor.h"

namespace mitk
{

  ToFCameraMITKPlayerController::ToFCameraMITKPlayerController() :
    m_PixelNumber(0),
    m_NumberOfBytes(0),
    m_CaptureWidth(0),
    m_CaptureHeight(0),
    m_ConnectionCheck(false),
    m_InputFileName(""),
    // m_Extension(""),
    m_ToFImageType(ToFImageType3D),
    m_DistanceImage(0),
    m_AmplitudeImage(0),
    m_IntensityImage(0),
    m_RGBImage(0),
    m_DistanceInfile(NULL),
    m_AmplitudeInfile(NULL),
    m_IntensityInfile(NULL),
    m_RGBInfile(NULL),
    m_IntensityArray(NULL),
    m_DistanceArray(NULL),
    m_AmplitudeArray(NULL),
    m_RGBArray(NULL),
    m_DistanceImageFileName(""),
    m_AmplitudeImageFileName(""),
    m_IntensityImageFileName(""),
    m_RGBImageFileName(""),
    m_PixelStartInFile(0),
    m_CurrentFrame(-1),
    m_NumOfFrames(0)
  {
    m_ImageStatus = std::vector<bool>(4,true);
  }

  ToFCameraMITKPlayerController::~ToFCameraMITKPlayerController()
  {
    this->CleanUp();
  }

  void ToFCameraMITKPlayerController::CleanUp()
  {
    if(m_DistanceImage.IsNotNull())
    {
      m_DistanceImage->ReleaseData();
      m_DistanceImage = NULL;
    }
    if(m_AmplitudeImage.IsNotNull())
    {
      m_AmplitudeImage->ReleaseData();
      m_AmplitudeImage = NULL;
    }
    if(m_IntensityImage.IsNotNull())
    {
      m_IntensityImage->ReleaseData();
      m_IntensityImage = NULL;
    }
    if(m_RGBImage.IsNotNull())
    {
      m_RGBImage->ReleaseData();
      m_RGBImage = NULL;
    }

    delete[] this->m_DistanceArray;
    this->m_DistanceArray = NULL;
    delete[] this->m_AmplitudeArray;
    this->m_AmplitudeArray = NULL;
    delete[] this->m_IntensityArray;
    this->m_IntensityArray = NULL;
    delete[] this->m_RGBArray;
    this->m_RGBArray = NULL;
  }
/*
 bool ToFCameraMITKPlayerController::CheckCurrentFileType()
  {
    if(!this->m_DistanceImageFileName.empty())
    {
      if(ItkImageFileReader::CanReadFile(m_DistanceImageFileName,"",".nrrd"))
      {
        m_Extension = ".nrrd";
        return true;
      }
      else if (PicFileReader::CanReadFile(m_DistanceImageFileName,"",".pic"))
      {
        m_Extension = ".pic";
        return true;
      }
    }

    if(!this->m_AmplitudeImageFileName.empty())
    {
      if(ItkImageFileReader::CanReadFile(m_AmplitudeImageFileName,"",".nrrd"))
      {
        m_Extension = ".nrrd";
        return true;
      }
      else if (PicFileReader::CanReadFile(m_AmplitudeImageFileName,"",".pic"))
      {
        m_Extension = ".pic";
        return true;
      }
    }

    if(!this->m_IntensityImageFileName.empty())
    {
      if(ItkImageFileReader::CanReadFile(m_IntensityImageFileName,"",".nrrd"))
      {
        m_Extension = ".nrrd";
        return true;
      }
      else if (PicFileReader::CanReadFile(m_IntensityImageFileName,"",".pic"))
      {
        m_Extension = ".pic";
        return true;
      }
    }
    if(!this->m_RGBImageFileName.empty())
    {
      if(ItkImageFileReader::CanReadFile(m_RGBImageFileName,"",".nrrd"))
      {
        m_Extension = ".nrrd";
        return true;
      }
      else if (PicFileReader::CanReadFile(m_RGBImageFileName,"",".pic"))
      {
        m_Extension = ".pic";
        return true;
      }
    }
    return false;
  }
  */

  bool ToFCameraMITKPlayerController::OpenCameraConnection()
  {
    if(!this->m_ConnectionCheck)
    {
      try
      {
        m_DistanceImage = mitk::IOUtil::LoadImage(this->m_DistanceImageFileName);
        m_AmplitudeImage = mitk::IOUtil::LoadImage(this->m_AmplitudeImageFileName);
        m_IntensityImage = mitk::IOUtil::LoadImage(this->m_IntensityImageFileName);
        m_RGBImage = mitk::IOUtil::LoadImage(this->m_RGBImageFileName);
        /*<commit_msg>Restored semantics prior to MitkExt removal.<commit_after>/*===================================================================

The Medical Imaging Interaction Toolkit (MITK)

Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.

This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.

See LICENSE.txt or http://www.mitk.org for details.

===================================================================*/
#include <mitkToFCameraMITKPlayerController.h>
#include <itksys/SystemTools.hxx>

// mitk includes
#include "mitkItkImageFileReader.h"
#include "mitkIOUtil.h"
#include <mitkIpPic.h>
#include "mitkImageReadAccessor.h"

namespace mitk
{

  ToFCameraMITKPlayerController::ToFCameraMITKPlayerController() :
    m_PixelNumber(0),
    m_NumberOfBytes(0),
    m_CaptureWidth(0),
    m_CaptureHeight(0),
    m_ConnectionCheck(false),
    m_InputFileName(""),
    // m_Extension(""),
    m_ToFImageType(ToFImageType3D),
    m_DistanceImage(0),
    m_AmplitudeImage(0),
    m_IntensityImage(0),
    m_RGBImage(0),
    m_DistanceInfile(NULL),
    m_AmplitudeInfile(NULL),
    m_IntensityInfile(NULL),
    m_RGBInfile(NULL),
    m_IntensityArray(NULL),
    m_DistanceArray(NULL),
    m_AmplitudeArray(NULL),
    m_RGBArray(NULL),
    m_DistanceImageFileName(""),
    m_AmplitudeImageFileName(""),
    m_IntensityImageFileName(""),
    m_RGBImageFileName(""),
    m_PixelStartInFile(0),
    m_CurrentFrame(-1),
    m_NumOfFrames(0)
  {
    m_ImageStatus = std::vector<bool>(4,true);
  }

  ToFCameraMITKPlayerController::~ToFCameraMITKPlayerController()
  {
    this->CleanUp();
  }

  void ToFCameraMITKPlayerController::CleanUp()
  {
    if(m_DistanceImage.IsNotNull())
    {
      m_DistanceImage->ReleaseData();
      m_DistanceImage = NULL;
    }
    if(m_AmplitudeImage.IsNotNull())
    {
      m_AmplitudeImage->ReleaseData();
      m_AmplitudeImage = NULL;
    }
    if(m_IntensityImage.IsNotNull())
    {
      m_IntensityImage->ReleaseData();
      m_IntensityImage = NULL;
    }
    if(m_RGBImage.IsNotNull())
    {
      m_RGBImage->ReleaseData();
      m_RGBImage = NULL;
    }

    delete[] this->m_DistanceArray;
    this->m_DistanceArray = NULL;
    delete[] this->m_AmplitudeArray;
    this->m_AmplitudeArray = NULL;
    delete[] this->m_IntensityArray;
    this->m_IntensityArray = NULL;
    delete[] this->m_RGBArray;
    this->m_RGBArray = NULL;
  }
/*
 bool ToFCameraMITKPlayerController::CheckCurrentFileType()
  {
    if(!this->m_DistanceImageFileName.empty())
    {
      if(ItkImageFileReader::CanReadFile(m_DistanceImageFileName,"",".nrrd"))
      {
        m_Extension = ".nrrd";
        return true;
      }
      else if (PicFileReader::CanReadFile(m_DistanceImageFileName,"",".pic"))
      {
        m_Extension = ".pic";
        return true;
      }
    }

    if(!this->m_AmplitudeImageFileName.empty())
    {
      if(ItkImageFileReader::CanReadFile(m_AmplitudeImageFileName,"",".nrrd"))
      {
        m_Extension = ".nrrd";
        return true;
      }
      else if (PicFileReader::CanReadFile(m_AmplitudeImageFileName,"",".pic"))
      {
        m_Extension = ".pic";
        return true;
      }
    }

    if(!this->m_IntensityImageFileName.empty())
    {
      if(ItkImageFileReader::CanReadFile(m_IntensityImageFileName,"",".nrrd"))
      {
        m_Extension = ".nrrd";
        return true;
      }
      else if (PicFileReader::CanReadFile(m_IntensityImageFileName,"",".pic"))
      {
        m_Extension = ".pic";
        return true;
      }
    }
    if(!this->m_RGBImageFileName.empty())
    {
      if(ItkImageFileReader::CanReadFile(m_RGBImageFileName,"",".nrrd"))
      {
        m_Extension = ".nrrd";
        return true;
      }
      else if (PicFileReader::CanReadFile(m_RGBImageFileName,"",".pic"))
      {
        m_Extension = ".pic";
        return true;
      }
    }
    return false;
  }
  */

  bool ToFCameraMITKPlayerController::OpenCameraConnection()
  {
    if(!this->m_ConnectionCheck)
    {
      try
      {
        if (this->m_DistanceImageFileName.empty() &&
            this->m_AmplitudeImageFileName.empty() &&
            this->m_IntensityImageFileName.empty() &&
            this->m_RGBImageFileName.empty())
        {
          throw std::logic_error("No image data file names set");
        }

        if (!this->m_DistanceImageFileName.empty())
        {
          m_DistanceImage = mitk::IOUtil::LoadImage(this->m_DistanceImageFileName);
        }
        else
        {
          MITK_ERROR << "ToF distance image data file empty";
        }
        if (!this->m_AmplitudeImageFileName.empty())
        {
          m_AmplitudeImage = mitk::IOUtil::LoadImage(this->m_AmplitudeImageFileName);
        }
        else
        {
          MITK_ERROR << "ToF amplitude image data file empty";
        }
        if (!this->m_IntensityImageFileName.empty())
        {
          m_IntensityImage = mitk::IOUtil::LoadImage(this->m_IntensityImageFileName);
        }
        else
        {
          MITK_ERROR << "ToF amplitude image data file empty";
        }
        if (!this->m_RGBImageFileName.empty())
        {
          m_RGBImage = mitk::IOUtil::LoadImage(this->m_RGBImageFileName);
        }
        else
        {
          MITK_ERROR << "ToF RGB image data file empty";
        }

        /*
{'fraction_non_alphanumeric': 0.14868982327848873, 'fraction_numerical': 0.002640666260410319, 'mean_word_length': 3.0422824302134646, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7657017', 'n_tokens_mistral': 3194, 'n_tokens_neox': 3151, 'n_words': 453}