Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkTrackingVolumeGenerator.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 ===================================================================*/
16 
19 #include "mitkConfig.h"
20 #include <vtkCubeSource.h>
21 #include <mitkTrackingTypes.h>
22 #include <mitkTrackingDevice.h>
24 #include <vtkSmartPointer.h>
25 #include <mitkSurface.h>
26 #include <mitkIOMimeTypes.h>
27 #include <mitkFileReaderRegistry.h>
28 
29 #include <usModuleContext.h>
30 #include <usGetModuleContext.h>
31 #include <usModule.h>
32 #include <usModuleResource.h>
33 #include <usModuleResourceStream.h>
34 
35 #include <mitkIOUtil.h>
36 
39 
40 
42 {
44 }
45 
47 {
48  std::vector<us::ServiceReference<mitk::TrackingDeviceTypeCollection> > refs = us::GetModuleContext()->GetServiceReferences<mitk::TrackingDeviceTypeCollection>();
49  if (refs.empty())
50  {
51  MITK_ERROR << "No tracking device service found!";
52  }
54 
55  this->m_Data = deviceTypeCollection->GetFirstCompatibleDeviceDataForLine(tracker->GetType());
56 }
57 
59 {
60  mitk::Surface::Pointer output = this->GetOutput(); //the surface wich represents the tracking volume
61 
62  std::string filepath = ""; // Full path to file (wil be resolved later)
63  std::string filename = this->m_Data.VolumeModelLocation; // Name of the file or possibly a magic String, e.g. "cube"
64 
65  MITK_INFO << "volume: " << filename;
66 
67  // See if filename matches a magic string.
68  if (filename.compare("cube") == 0){
69  vtkSmartPointer<vtkCubeSource> cubeSource = vtkSmartPointer<vtkCubeSource>::New();
70  double bounds[6];
71  bounds[0] = bounds[2] = bounds[4] = -400.0; // initialize bounds to -400 ... +400 cube. This is the default value of the
72  bounds[1] = bounds[3] = bounds[5] = 400.0; // virtual tracking device, but it can be changed. In that case,
73  // the tracking volume polydata has to be updated manually
74  cubeSource->SetBounds(bounds);
75  cubeSource->Update();
76 
77  output->SetVtkPolyData(cubeSource->GetOutput()); //set the vtkCubeSource as polyData of the surface
78  return;
79  }
80  if (filename.compare("") == 0) // empty String means no model, return empty output
81  {
82  // initialize with empty poly data (otherwise old surfaces may be returned) => so an empty surface is returned
83  vtkPolyData *emptyPolyData = vtkPolyData::New();
84  output->SetVtkPolyData(emptyPolyData);
85  emptyPolyData->Delete();
86  return;
87  }
88 
89  // from here on, we assume that filename contains an actual filename and not a magic string
90 
92 
93  us::ModuleResource moduleResource = module->GetResource(filename);
94 
95  std::vector<mitk::BaseData::Pointer> data = mitk::IOUtil::Load(moduleResource);
96 
97  if(data.empty())
98  MITK_ERROR << "Exception while reading file:";
99 
100  mitk::Surface::Pointer fileoutput = dynamic_cast<mitk::Surface*>(data[0].GetPointer());
101 
102  output->SetVtkPolyData(fileoutput->GetVtkPolyData());
103 
104 }
105 
107 {
108  std::vector<us::ServiceReference<mitk::TrackingDeviceTypeCollection> > refs = us::GetModuleContext()->GetServiceReferences<mitk::TrackingDeviceTypeCollection>();
109  if (refs.empty())
110  {
111  MITK_ERROR << "No tracking device service found!";
112  }
114 
115  m_Data = deviceTypeCollection->GetFirstCompatibleDeviceDataForLine(deviceType);
116 }
117 
119 {
120  return m_Data.Line;
121 }
122 
124 {
125  m_Data= deviceData;
126 }
127 
129 {
130  return m_Data;
131 }
mitk::TrackingDeviceType GetTrackingDeviceType() const
Class for storing surfaces (vtkPolyData).
Definition: mitkSurface.h:32
itk::SmartPointer< Self > Pointer
#define MITK_INFO
Definition: mitkLogMacros.h:22
#define MITK_ERROR
Definition: mitkLogMacros.h:24
void SetTrackingDevice(mitk::TrackingDevice::Pointer tracker)
Deprecated! Use set DeviceData instead. Sets the tracking device type of the volume. After doing this the tracking volume gets generated and is set to the correct dimensions in the correct coordinate system. The TV of a VirtualTrackingDevice is always a 400*400 cube.
This class is a collection for information of all Tracking Device Types (derived from abstract Tracki...
void SetTrackingDeviceType(mitk::TrackingDeviceType deviceType)
Deprecated! Use set DeviceData instead. Sets the tracking device type of the volume. Warning: there are different possible volumes for some device types. In this case a default volume is chosen automatically. All tracking volumes are defined by TrackingDeviceData objects (see file mitkTrackingTypes.h) for a list.
void * GetService(const ServiceReferenceBase &reference)
void SetTrackingDeviceData(mitk::TrackingDeviceData deviceData)
Sets the tracking device data object which will be used to generate the volume. Each tracking device ...
TrackingDeviceData GetFirstCompatibleDeviceDataForLine(TrackingDeviceType type)
Module * GetModule() const
static const std::string filename
mitk::TrackingDeviceData GetTrackingDeviceData() const
std::vector< ServiceReferenceU > GetServiceReferences(const std::string &clazz, const std::string &filter=std::string())
std::string TrackingDeviceType
static DataStorage::SetOfObjects::Pointer Load(const std::string &path, DataStorage &storage)
Load a file into the given DataStorage.
Definition: mitkIOUtil.cpp:483
ModuleResource GetResource(const std::string &path) const
Definition: usModule.cpp:267
mitk::TrackingDeviceData m_Data
Holds the current tracking device data object, which is used to generate the volume.
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.