CustusX  2023.01.05-dev+develop.0da12
An IGT application
cxTrackingSystemBronchoscopyService.cpp
Go to the documentation of this file.
1  /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
33 
34 
35 #include "cxReporter.h"
36 #include "cxTime.h"
37 #include "cxPlaybackTime.h"
38 #include "cxBronchoscopyTool.h"
39 #include <QApplication>
40 #include "cxUtilHelpers.h"
41 #include "cxManualTool.h"
42 #include "cxTrackerConfiguration.h"
44 
45 
46 namespace cx
47 {
48 
50  mTrackingService(trackingService),
51  mProjectionCenterline(projectionCenterline),
52  mTool(tool)
53 {
54  mBase = this->getIGSTKTrackingSystemService();
55 
56  connect(mBase.get(), &TrackingSystemService::stateChanged, this, &TrackingSystemBronchoscopyService::onStateChanged);
57  if (!mTool)
58  mTool = mTrackingService->getActiveTool(); // Use active tool if tool is not set
59  this->onStateChanged();
60 }
61 
63 {
64 }
65 
67 {
68  std::vector<TrackingSystemServicePtr> trackingSystems = mTrackingService->getTrackingSystems();
69  for (int i=0; i<trackingSystems.size(); i++)
70  if (trackingSystems[i]->getUid() == trackingSystemName)
71  {
72  mBase = trackingSystems[i];
73  this->onStateChanged();
74  return true;
75  }
76  return false;
77 }
78 
79 TrackingSystemServicePtr TrackingSystemBronchoscopyService::getIGSTKTrackingSystemService()
80 {
81  std::vector<TrackingSystemServicePtr> trackingSystems = mTrackingService->getTrackingSystems();
82  for (unsigned i = 0; i < trackingSystems.size(); ++i)
83  {
84  if(trackingSystems[i]->getUid() == "org.custusx.core.tracking.system.igstk")
85  return trackingSystems[i];
86  }
87  return TrackingSystemServicePtr();
88 }
89 
91 {
92  mTool = tool;
93 }
94 
95 void TrackingSystemBronchoscopyService::onStateChanged()
96 {
97  std::vector<ToolPtr> tools = mBase->getTools();
98  mTools.clear();
99  for (unsigned i=0; i<tools.size(); ++i)
100  {
101  if (tools[i] == mTool)
102  {
103  BronchoscopyToolPtr current(new BronchoscopyTool(tools[i], mProjectionCenterline));
104  mTools.push_back(current);
105  }
106  else
107  mTools.push_back(tools[i]);
108  }
109  emit stateChanged();
110 }
111 
113 {
114  return mBase->getReference();
115 }
116 
117 
119 {
120  return mTools;
121 }
122 
124 {
125  return mBase->getState();
126 }
127 
129 {
130  mBase->setState(val);
131 }
132 
134 {
135  mBase->setLoggingFolder(loggingFolder);
136 }
137 
139 {
140  return mBase->getConfiguration();
141 }
142 
143 
144 } // namespace cx
boost::shared_ptr< class TrackingService > TrackingServicePtr
ToolPtr getReference()
reference tool used by entire tracking service - NOTE: system fails if several TrackingSystemServices...
virtual void setState(const Tool::State val)
asynchronously request a state. Wait for signal stateChanged()
void stateChanged()
Reset time synchronization. Used for resetting time synchronization of incoming timestamps in OpenIGT...
boost::shared_ptr< class TrackerConfiguration > TrackerConfigurationPtr
TrackingSystemBronchoscopyService(TrackingServicePtr trackingService, BronchoscopePositionProjectionPtr projectionCenterline, ToolPtr tool=NULL)
A tool used during playback.
boost::shared_ptr< class BronchoscopePositionProjection > BronchoscopePositionProjectionPtr
boost::shared_ptr< class BronchoscopyTool > BronchoscopyToolPtr
Namespace for all CustusX production code.
boost::shared_ptr< class Tool > ToolPtr
boost::shared_ptr< class TrackingSystemService > TrackingSystemServicePtr