Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkAbstractToFDeviceFactory.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
17 #include <mitkCameraIntrinsics.h>
19 //Microservices
20 #include <usModuleContext.h>
21 #include <usGetModuleContext.h>
22 #include <usModule.h>
23 #include <usModuleResource.h>
24 #include <usModuleResourceStream.h>
25 
26 #include <tinyxml.h>
27 
29 {
32  device->SetProperty("CameraIntrinsics", mitk::CameraIntrinsicsProperty::New(cameraIntrinsics));
33  m_Devices.push_back(device);
34 
35  us::ModuleContext* context = us::GetModuleContext();
36  us::ServiceProperties deviceProps;
37  deviceProps["ToFDeviceName"] = GetCurrentDeviceName();
38  m_DeviceRegistrations.insert(std::make_pair(device.GetPointer(), context->RegisterService(device.GetPointer(),deviceProps)));
39  return device;
40 }
41 
43 {
44  std::map<ToFCameraDevice*,us::ServiceRegistration<ToFCameraDevice> >::iterator i = m_DeviceRegistrations.find(device.GetPointer());
45  if (i == m_DeviceRegistrations.end()) return;
46 
47  i->second.Unregister();
48  m_DeviceRegistrations.erase(i);
49 
50  m_Devices.erase(std::remove(m_Devices.begin(), m_Devices.end(), device), m_Devices.end());
51 }
52 
54 {
55  return m_Devices.size();
56 }
57 
59 {
60  us::ModuleResource resource = GetIntrinsicsResource();
61  if (! resource.IsValid())
62  {
63  MITK_WARN << "Could not load resource '" << resource.GetName() << "'. CameraIntrinsics are invalid!";
64  }
65 
66  // Create ResourceStream from Resource
67  us::ModuleResourceStream resStream(resource);
68 
69  // Parse XML
70  TiXmlDocument xmlDocument;
71  resStream >> xmlDocument;
72 
73  //Retrieve Child Element and convert to CamerIntrinsics
74  TiXmlElement* element = xmlDocument.FirstChildElement();
76  intrinsics->FromXML(element);
77 
78  return intrinsics;
79 }
80 
82 {
84  return module->GetResource("CalibrationFiles/Default_Parameters.xml");
85  MITK_WARN << "Loaded Default CameraIntrinsics. Overwrite AbstractToFDeviceFactory::GetIntrinsicsResource() if you want to define your own.";
86 }
itk::SmartPointer< Self > Pointer
std::vector< ToFCameraDevice::Pointer > m_Devices
m_Devices A list (vector) containing all connected devices of the respective factory.
std::string GetName() const
std::string GetCurrentDeviceName() override
GetCurrentDeviceName Get the human readable name of the current device. A factory can produce many de...
virtual ToFCameraDevice::Pointer CreateToFCameraDevice()=0
CreateToFCameraDevice Create a new device of the respective factory. E.g. a "KinectFactory" creates a...
CameraIntrinsics::Pointer GetCameraIntrinsics()
Returns the CameraIntrinsics for the cameras created by this factory.
#define MITK_WARN
Definition: mitkLogMacros.h:23
vcl_size_t GetNumberOfDevices()
GetNumberOfDevices Get the number of devices produced by this factory. This function will return the ...
void DisconnectToFDevice(const ToFCameraDevice::Pointer &device)
DisconnectToFDevice Use this method to disconnect a device.
Module * GetModule() const
US_UNORDERED_MAP_TYPE< std::string, Any > ServiceProperties
static Pointer New()
ModuleResource GetResource(const std::string &path) const
Definition: usModule.cpp:267
virtual us::ModuleResource GetIntrinsicsResource()
Returns the ModuleResource that contains a xml definition of the CameraIntrinsics.
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.
ToFCameraDevice::Pointer ConnectToFDevice()
ConnectToFDevice Use this method to connect a device.
std::map< ToFCameraDevice *, us::ServiceRegistration< ToFCameraDevice > > m_DeviceRegistrations
m_DeviceRegistrations A map containing all the pairs of device registration numbers and devices...