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();
60 disconnect(mTimer, SIGNAL(timeout()),
this, SLOT(checkTimeoutsAndRequestTransformSlot()));
67 QMutexLocker sentry(&mToolMutex);
73 QMutexLocker sentry(&mReferenceMutex);
74 return mReferenceTool;
77 void IgstkToolManager::setReferenceAndTrackerOnTools()
81 reportWarning(
"Tracking is configured without a reference tool.");
84 std::map<QString, IgstkToolPtr>::iterator it;
85 for (it = mTools.begin(); it != mTools.end(); ++it)
88 it->second->setReference(mReferenceTool);
90 it->second->setTracker(mTracker);
94 void IgstkToolManager::createTracker(ToolFileParser::TrackerInternalStructure trackerStructure)
96 TrackerPtr tracker(
new IgstkTracker(trackerStructure));
97 if (tracker->isValid())
103 void IgstkToolManager::createTools(std::vector<ToolFileParser::ToolInternalStructurePtr> toolStructures,
106 for (
unsigned i = 0; i < toolStructures.size(); ++i)
108 this->addIgstkTools(toolStructures[i]);
110 if (referenceToolStructure && !referenceToolStructure->mUid.isEmpty())
112 IgstkToolPtr refTool = this->addIgstkTools(referenceToolStructure);
113 if (refTool->isValid())
114 mReferenceTool = refTool;
121 if (igstkTool->isValid())
123 QMutexLocker sentry(&mToolMutex);
124 mTools[igstkTool->getUid()] = igstkTool;
125 connect(igstkTool.get(), SIGNAL(attachedToTracker(
bool)),
this, SLOT(deviceInitializedSlot(
bool)));
134 void IgstkToolManager::trackerTrackingSlot(
bool isTracking)
136 int igstkPulsingDriveRate = 10;
138 mTimer->start(igstkPulsingDriveRate);
147 connect(mTracker.get(), SIGNAL(
initialized(
bool)),
this, SLOT(attachToolsWhenTrackerIsInitializedSlot(
bool)));
148 if (!mTracker->isOpen())
153 mTracker->detachTools(mTools);
154 if (mTracker->isOpen())
161 if (on && !mTracker->isTracking())
162 mTracker->startTracking();
163 else if (!on && mTracker->isTracking())
164 mTracker->stopTracking();
167 void IgstkToolManager::checkTimeoutsAndRequestTransformSlot()
169 igstk::PulseGenerator::CheckTimeouts();
171 std::map<QString, IgstkToolPtr>::iterator it = mTools.begin();
172 for (; it != mTools.end(); ++it)
178 it->second->getPointer()->RequestComputeTransformTo(mReferenceTool->getPointer());
180 it->second->getPointer()->RequestComputeTransformTo(mTracker->getPointer());
184 void IgstkToolManager::deviceInitializedSlot(
bool deviceInit)
186 size_t numberOfDevices = mTools.size() + 1;
192 if (mInitAnsweres == numberOfDevices)
194 mInternalInitialized =
true;
202 if (mInitAnsweres < numberOfDevices)
204 if (mInternalInitialized)
207 mInternalInitialized =
false;
214 void IgstkToolManager::attachToolsWhenTrackerIsInitializedSlot(
bool open)
219 disconnect(mTracker.get(), SIGNAL(
initialized(
bool)),
this, SLOT(attachToolsWhenTrackerIsInitializedSlot(
bool)));
220 mTracker->attachTools(mTools);
223 void IgstkToolManager::printStatus()
225 std::cout <<
"mInternalInitialized " << mInternalInitialized << std::endl;
226 std::cout <<
"mInitAnsweres " << mInitAnsweres << std::endl;
227 std::cout <<
"mTracker->isValid() " << mTracker->isValid() << std::endl;
228 std::cout <<
"mTracker->isOpen() " << mTracker->isOpen() << std::endl;
229 std::cout <<
"mTracker->isInitialized() " << mTracker->isInitialized() << std::endl;
230 std::cout <<
"mTracker->isTracking() " << mTracker->isTracking() << std::endl;
231 std::cout <<
"mTools.size() " <<
string_cast(mTools.size()) << std::endl;