<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 "mitkAbstractToFDeviceFactory.h"
#include <mitkCameraIntrinsics.h>
//Microservices
#include <mitkModuleContext.h>
#include <usGetModuleContext.h>
#include <mitkModule.h>
#include <mitkModuleResource.h>
#include <mitkModuleResourceStream.h>

//TinyXML
#include <tinyxml.h>

mitk::ToFCameraDevice::Pointer mitk::AbstractToFDeviceFactory::ConnectToFDevice()
{
   ToFCameraDevice::Pointer device = createToFCameraDevice();
   m_Devices.push_back(device);

  ModuleContext* context = mitk::GetModuleContext();
  ServiceProperties deviceProps;
//-------------Take a look at this part to change the name given to a device
  deviceProps["ToFDeviceName"] = GetCurrentDeviceName();
  m_DeviceRegistrations.insert(std::make_pair(device.GetPointer(), context->RegisterService<ToFCameraDevice>(device.GetPointer(),deviceProps)));
  return device;
}

void mitk::AbstractToFDeviceFactory::DisconnectToFDevice(const ToFCameraDevice::Pointer& device)
{
   std::map<ToFCameraDevice*,ServiceRegistration>::iterator i = m_DeviceRegistrations.find(device.GetPointer());
   if (i == m_DeviceRegistrations.end()) return;

   i->second.Unregister();
   m_DeviceRegistrations.erase(i);

   m_Devices.erase(std::remove(m_Devices.begin(), m_Devices.end(), device), m_Devices.end());
}

mitk::CameraIntrinsics::Pointer mitk::AbstractToFDeviceFactory::getCameraIntrinsics()
{
  mitk::Module* module = mitk::GetModuleContext()->GetModule();
  mitk::ModuleResource resource = module->GetResource("CalibrationFiles/DefaultParameters.xml");
  mitk::ModuleResourceStream resStream(resource);

  TiXmlNode* xmlDocument;
  resStream>>&xmlDocument;

//  resource->GetData();
//  cameraIntrinsics->FromXMLFile(pathToDefaulCalibrationFile);
//  device->SetProperty("CameraIntrinsics", mitk::CameraIntrinsicsProperty::New(cameraIntrinsics));
}<commit_msg>Implemented first mechanism to load CameraIntrinsics from resourceStream<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 "mitkAbstractToFDeviceFactory.h"
#include <mitkCameraIntrinsics.h>
//Microservices
#include <mitkModuleContext.h>
#include <usGetModuleContext.h>
#include <mitkModule.h>
#include <mitkModuleResource.h>
#include <mitkModuleResourceStream.h>

//TinyXML
#include <tinyxml.h>

mitk::ToFCameraDevice::Pointer mitk::AbstractToFDeviceFactory::ConnectToFDevice()
{
   ToFCameraDevice::Pointer device = createToFCameraDevice();
   m_Devices.push_back(device);

  ModuleContext* context = mitk::GetModuleContext();
  ServiceProperties deviceProps;
//-------------Take a look at this part to change the name given to a device
  deviceProps["ToFDeviceName"] = GetCurrentDeviceName();
  m_DeviceRegistrations.insert(std::make_pair(device.GetPointer(), context->RegisterService<ToFCameraDevice>(device.GetPointer(),deviceProps)));
  return device;
}

void mitk::AbstractToFDeviceFactory::DisconnectToFDevice(const ToFCameraDevice::Pointer& device)
{
   std::map<ToFCameraDevice*,ServiceRegistration>::iterator i = m_DeviceRegistrations.find(device.GetPointer());
   if (i == m_DeviceRegistrations.end()) return;

   i->second.Unregister();
   m_DeviceRegistrations.erase(i);

   m_Devices.erase(std::remove(m_Devices.begin(), m_Devices.end(), device), m_Devices.end());
}

mitk::CameraIntrinsics::Pointer mitk::AbstractToFDeviceFactory::getCameraIntrinsics()
{
  mitk::Module* module = mitk::GetModuleContext()->GetModule();
  mitk::ModuleResource resource = module->GetResource("CalibrationFiles/DefaultParameters.xml");
  mitk::ModuleResourceStream resStream(resource);

  TiXmlDocument xmlDocument;
  //xmlDocument->
  resStream >> xmlDocument;

  TiXmlElement* element = xmlDocument.FirstChildElement();
  mitk::CameraIntrinsics::Pointer intrinsics = mitk::CameraIntrinsics::New();
  intrinsics->FromXML(element);
  return intrinsics;
}
{'fraction_non_alphanumeric': 0.1723413198823035, 'fraction_numerical': 0.0, 'mean_word_length': 7.498214285714286, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 38, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 10}, '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': '3429662', 'n_tokens_mistral': 1383, 'n_tokens_neox': 1353, 'n_words': 276}