20 void sampleInfo2xml(
const igstk::NDITracker::TrackingSampleInfo& info, QDomElement& node)
22 node.setAttribute(
"timestamp", QString(
"%1").arg(info.m_TimeStamp, 0,
'f', 0));
23 node.setAttribute(
"error", QString(
"%1").arg(info.m_Error, 0,
'f', 3));
24 node.setAttribute(
"frame", QString(
"%1").arg(info.m_FrameNumber));
25 node.setAttribute(
"portstatus", QString(
"0b%1").arg(info.m_PortStatus, 16, 2, QChar(
'0')));
26 node.setAttribute(
"toolinformation", QString(
"0b%1").arg(info.m_ToolInformation, 8, 2, QChar(
'0')));
28 for (
unsigned i=0; i<info.m_MarkerInformation.size(); ++i)
29 markers += QString::number(info.m_MarkerInformation[i]);
30 node.setAttribute(
"markers", markers);
35 std::vector<ToolFileParser::ToolInternalStructurePtr> toolStructures,
37 mInitAnsweres(0), mInternalInitialized(false)
41 this->createTracker(trackerStructure);
42 this->createTools(toolStructures, referenceToolStructure);
43 this->setReferenceAndTrackerOnTools();
45 connect(mTracker.get(), SIGNAL(
tracking(
bool)),
this, SIGNAL(
tracking(
bool)));
46 connect(mTracker.get(), SIGNAL(
error()),
this, SIGNAL(
error()));
48 connect(mTracker.get(), SIGNAL(
initialized(
bool)),
this, SLOT(deviceInitializedSlot(
bool)));
49 connect(mTracker.get(), SIGNAL(
tracking(
bool)),
this, SLOT(trackerTrackingSlot(
bool)));
51 mTimer =
new QTimer();
52 connect(mTimer, SIGNAL(timeout()),
this, SLOT(checkTimeoutsAndRequestTransformSlot()));
54 igstk::RealTimeClock::Initialize();
65 QMutexLocker sentry(&mToolMutex);
71 QMutexLocker sentry(&mReferenceMutex);
72 return mReferenceTool;
75 void IgstkToolManager::setReferenceAndTrackerOnTools()
79 reportWarning(
"Tracking is configured without a reference tool.");
82 std::map<QString, IgstkToolPtr>::iterator it;
83 for (it = mTools.begin(); it != mTools.end(); ++it)
86 it->second->setReference(mReferenceTool);
88 it->second->setTracker(mTracker);
95 if (tracker->isValid())
101 void IgstkToolManager::createTools(std::vector<ToolFileParser::ToolInternalStructurePtr> toolStructures,
104 for (
unsigned i = 0; i < toolStructures.size(); ++i)
106 this->addIgstkTools(toolStructures[i]);
108 if (referenceToolStructure && !referenceToolStructure->mUid.isEmpty())
110 IgstkToolPtr refTool = this->addIgstkTools(referenceToolStructure);
111 if (refTool->isValid())
112 mReferenceTool = refTool;
119 if (igstkTool->isValid())
121 QMutexLocker sentry(&mToolMutex);
122 mTools[igstkTool->getUid()] = igstkTool;
123 connect(igstkTool.get(), SIGNAL(attachedToTracker(
bool)),
this, SLOT(deviceInitializedSlot(
bool)));
132 void IgstkToolManager::trackerTrackingSlot(
bool isTracking)
134 int igstkPulsingDriveRate = 10;
136 mTimer->start(igstkPulsingDriveRate);
145 connect(mTracker.get(), SIGNAL(
initialized(
bool)),
this, SLOT(attachToolsWhenTrackerIsInitializedSlot(
bool)));
146 if (!mTracker->isOpen())
151 mTracker->detachTools(mTools);
152 if (mTracker->isOpen())
159 if (on && !mTracker->isTracking())
160 mTracker->startTracking();
161 else if (!on && mTracker->isTracking())
162 mTracker->stopTracking();
165 void IgstkToolManager::checkTimeoutsAndRequestTransformSlot()
167 igstk::PulseGenerator::CheckTimeouts();
169 std::map<QString, IgstkToolPtr>::iterator it = mTools.begin();
170 for (; it != mTools.end(); ++it)
176 it->second->getPointer()->RequestComputeTransformTo(mReferenceTool->getPointer());
178 it->second->getPointer()->RequestComputeTransformTo(mTracker->getPointer());
182 void IgstkToolManager::deviceInitializedSlot(
bool deviceInit)
184 size_t numberOfDevices = mTools.size() + 1;
190 if (mInitAnsweres == numberOfDevices)
192 mInternalInitialized =
true;
200 if (mInitAnsweres < numberOfDevices)
202 if (mInternalInitialized)
205 mInternalInitialized =
false;
212 void IgstkToolManager::attachToolsWhenTrackerIsInitializedSlot(
bool open)
217 disconnect(mTracker.get(), SIGNAL(
initialized(
bool)),
this, SLOT(attachToolsWhenTrackerIsInitializedSlot(
bool)));
218 mTracker->attachTools(mTools);
221 void IgstkToolManager::printStatus()
223 std::cout <<
"mInternalInitialized " << mInternalInitialized << std::endl;
224 std::cout <<
"mInitAnsweres " << mInitAnsweres << std::endl;
225 std::cout <<
"mTracker->isValid() " << mTracker->isValid() << std::endl;
226 std::cout <<
"mTracker->isOpen() " << mTracker->isOpen() << std::endl;
227 std::cout <<
"mTracker->isInitialized() " << mTracker->isInitialized() << std::endl;
228 std::cout <<
"mTracker->isTracking() " << mTracker->isTracking() << std::endl;
229 std::cout <<
"mTools.size() " <<
string_cast(mTools.size()) << std::endl;
Class representing the navigation system.
boost::shared_ptr< class IgstkTool > IgstkToolPtr
std::string string_cast(const T &val)
void reportWarning(QString msg)
void sampleInfo2xml(const igstk::NDITracker::TrackingSampleInfo &info, QDomElement &node)
boost::shared_ptr< IgstkTracker > TrackerPtr
Namespace for all CustusX production code.