41 void sampleInfo2xml(
const igstk::NDITracker::TrackingSampleInfo& info, QDomElement& node)
43 node.setAttribute(
"timestamp", QString(
"%1").arg(info.m_TimeStamp, 0,
'f', 0));
44 node.setAttribute(
"error", QString(
"%1").arg(info.m_Error, 0,
'f', 3));
45 node.setAttribute(
"frame", QString(
"%1").arg(info.m_FrameNumber));
46 node.setAttribute(
"portstatus", QString(
"0b%1").arg(info.m_PortStatus, 16, 2, QChar(
'0')));
47 node.setAttribute(
"toolinformation", QString(
"0b%1").arg(info.m_ToolInformation, 8, 2, QChar(
'0')));
49 for (
unsigned i=0; i<info.m_MarkerInformation.size(); ++i)
50 markers += QString::number(info.m_MarkerInformation[i]);
51 node.setAttribute(
"markers", markers);
56 std::vector<ToolFileParser::ToolInternalStructure> toolStructures,
58 mInitAnsweres(0), mInternalInitialized(false)
62 this->createTracker(trackerStructure);
63 this->createTools(toolStructures, referenceToolStructure);
64 this->setReferenceAndTrackerOnTools();
66 connect(mTracker.get(), SIGNAL(
tracking(
bool)),
this, SIGNAL(
tracking(
bool)));
67 connect(mTracker.get(), SIGNAL(
error()),
this, SIGNAL(
error()));
69 connect(mTracker.get(), SIGNAL(
initialized(
bool)),
this, SLOT(deviceInitializedSlot(
bool)));
70 connect(mTracker.get(), SIGNAL(
tracking(
bool)),
this, SLOT(trackerTrackingSlot(
bool)));
72 mTimer =
new QTimer();
73 connect(mTimer, SIGNAL(timeout()),
this, SLOT(checkTimeoutsAndRequestTransformSlot()));
75 igstk::RealTimeClock::Initialize();
86 QMutexLocker sentry(&mToolMutex);
92 QMutexLocker sentry(&mReferenceMutex);
93 return mReferenceTool;
96 void IgstkToolManager::setReferenceAndTrackerOnTools()
100 reportWarning(
"Tracking is configured without a reference tool.");
103 std::map<QString, IgstkToolPtr>::iterator it;
104 for (it = mTools.begin(); it != mTools.end(); ++it)
107 it->second->setReference(mReferenceTool);
109 it->second->setTracker(mTracker);
113 void IgstkToolManager::createTracker(ToolFileParser::TrackerInternalStructure trackerStructure)
115 TrackerPtr tracker(
new IgstkTracker(trackerStructure));
116 if (tracker->isValid())
122 void IgstkToolManager::createTools(std::vector<ToolFileParser::ToolInternalStructure> toolStructures,
123 ToolFileParser::ToolInternalStructure referenceToolStructure)
125 for (
unsigned i = 0; i < toolStructures.size(); ++i)
127 this->addIgstkTools(toolStructures[i]);
129 if (!referenceToolStructure.mUid.isEmpty())
131 IgstkToolPtr refTool = this->addIgstkTools(referenceToolStructure);
132 if (refTool->isValid())
133 mReferenceTool = refTool;
137 IgstkToolPtr IgstkToolManager::addIgstkTools(ToolFileParser::ToolInternalStructure& toolStructure)
140 if (igstkTool->isValid())
142 QMutexLocker sentry(&mToolMutex);
143 mTools[igstkTool->getUid()] = igstkTool;
144 connect(igstkTool.get(), SIGNAL(attachedToTracker(
bool)),
this, SLOT(deviceInitializedSlot(
bool)));
153 void IgstkToolManager::trackerTrackingSlot(
bool isTracking)
155 int igstkPulsingDriveRate = 10;
157 mTimer->start(igstkPulsingDriveRate);
166 connect(mTracker.get(), SIGNAL(
initialized(
bool)),
this, SLOT(attachToolsWhenTrackerIsInitializedSlot(
bool)));
167 if (!mTracker->isOpen())
172 mTracker->detachTools(mTools);
173 if (mTracker->isOpen())
180 if (on && !mTracker->isTracking())
181 mTracker->startTracking();
182 else if (!on && mTracker->isTracking())
183 mTracker->stopTracking();
186 void IgstkToolManager::checkTimeoutsAndRequestTransformSlot()
188 igstk::PulseGenerator::CheckTimeouts();
190 std::map<QString, IgstkToolPtr>::iterator it = mTools.begin();
191 for (; it != mTools.end(); ++it)
197 it->second->getPointer()->RequestComputeTransformTo(mReferenceTool->getPointer());
199 it->second->getPointer()->RequestComputeTransformTo(mTracker->getPointer());
203 void IgstkToolManager::deviceInitializedSlot(
bool deviceInit)
205 int numberOfDevices = mTools.size() + 1;
211 if (mInitAnsweres == numberOfDevices)
213 mInternalInitialized =
true;
221 if (mInitAnsweres < numberOfDevices)
223 if (mInternalInitialized)
226 mInternalInitialized =
false;
233 void IgstkToolManager::attachToolsWhenTrackerIsInitializedSlot(
bool open)
238 disconnect(mTracker.get(), SIGNAL(
initialized(
bool)),
this, SLOT(attachToolsWhenTrackerIsInitializedSlot(
bool)));
239 mTracker->attachTools(mTools);
242 void IgstkToolManager::printStatus()
244 std::cout <<
"mInternalInitialized " << mInternalInitialized << std::endl;
245 std::cout <<
"mInitAnsweres " << mInitAnsweres << std::endl;
246 std::cout <<
"mTracker->isValid() " << mTracker->isValid() << std::endl;
247 std::cout <<
"mTracker->isOpen() " << mTracker->isOpen() << std::endl;
248 std::cout <<
"mTracker->isInitialized() " << mTracker->isInitialized() << std::endl;
249 std::cout <<
"mTracker->isTracking() " << mTracker->isTracking() << std::endl;
250 std::cout <<
"mTools.size() " <<
string_cast(mTools.size()) << std::endl;
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