42 std::vector<IgstkTool::InternalStructure> toolStructures,
44 mInitAnsweres(0), mInternalInitialized(false)
48 this->createTracker(trackerStructure);
49 this->createTools(toolStructures, referenceToolStructure);
50 this->setReferenceAndTrackerOnTools();
52 connect(mTracker.get(), SIGNAL(
tracking(
bool)),
this, SIGNAL(
tracking(
bool)));
53 connect(mTracker.get(), SIGNAL(
error()),
this, SIGNAL(
error()));
55 connect(mTracker.get(), SIGNAL(
initialized(
bool)),
this, SLOT(deviceInitializedSlot(
bool)));
56 connect(mTracker.get(), SIGNAL(
tracking(
bool)),
this, SLOT(trackerTrackingSlot(
bool)));
58 mTimer =
new QTimer();
59 connect(mTimer, SIGNAL(timeout()),
this, SLOT(checkTimeoutsAndRequestTransformSlot()));
61 igstk::RealTimeClock::Initialize();
64 mPulseGenerator = igstk::PulseGenerator::New();
65 mPulseGenerator->RequestSetFrequency(30.0);
66 mPulseGenerator->RequestStart();
74 mPulseGenerator->RequestStop();
79 QMutexLocker sentry(&mToolMutex);
85 QMutexLocker sentry(&mReferenceMutex);
86 return mReferenceTool;
89 void IgstkToolManager::setReferenceAndTrackerOnTools()
93 reportWarning(
"Tracking is configured without a reference tool.");
96 std::map<QString, IgstkToolPtr>::iterator it;
97 for (it = mTools.begin(); it != mTools.end(); ++it)
100 it->second->setReference(mReferenceTool);
102 it->second->setTracker(mTracker);
106 void IgstkToolManager::createTracker(IgstkTracker::InternalStructure trackerStructure)
108 TrackerPtr tracker(
new IgstkTracker(trackerStructure));
109 if (tracker->isValid())
115 void IgstkToolManager::createTools(std::vector<IgstkTool::InternalStructure> toolStructures,
116 IgstkTool::InternalStructure referenceToolStructure)
118 for (
unsigned i = 0; i < toolStructures.size(); ++i)
120 this->addIgstkTools(toolStructures[i]);
122 if (!referenceToolStructure.mUid.isEmpty())
124 IgstkToolPtr refTool = this->addIgstkTools(referenceToolStructure);
125 if (refTool->isValid())
126 mReferenceTool = refTool;
130 IgstkToolPtr IgstkToolManager::addIgstkTools(IgstkTool::InternalStructure& toolStructure)
133 if (igstkTool->isValid())
135 QMutexLocker sentry(&mToolMutex);
136 mTools[igstkTool->getUid()] = igstkTool;
137 connect(igstkTool.get(), SIGNAL(attachedToTracker(
bool)),
this, SLOT(deviceInitializedSlot(
bool)));
146 void IgstkToolManager::trackerTrackingSlot(
bool isTracking)
158 connect(mTracker.get(), SIGNAL(
initialized(
bool)),
this, SLOT(attachToolsWhenTrackerIsInitializedSlot(
bool)));
159 if (!mTracker->isOpen())
164 mTracker->detachTools(mTools);
165 if (mTracker->isOpen())
172 if (on && !mTracker->isTracking())
173 mTracker->startTracking();
174 else if (!on && mTracker->isTracking())
175 mTracker->stopTracking();
178 void IgstkToolManager::checkTimeoutsAndRequestTransformSlot()
180 mPulseGenerator->CheckTimeouts();
182 std::map<QString, IgstkToolPtr>::iterator it = mTools.begin();
183 for (; it != mTools.end(); ++it)
188 it->second->getPointer()->RequestComputeTransformTo(mReferenceTool->getPointer());
190 it->second->getPointer()->RequestComputeTransformTo(mTracker->getPointer());
194 void IgstkToolManager::deviceInitializedSlot(
bool deviceInit)
196 int numberOfDevices = mTools.size() + 1;
202 if (mInitAnsweres == numberOfDevices)
204 mInternalInitialized =
true;
212 if (mInitAnsweres < numberOfDevices)
214 if (mInternalInitialized)
217 mInternalInitialized =
false;
224 void IgstkToolManager::attachToolsWhenTrackerIsInitializedSlot(
bool open)
229 disconnect(mTracker.get(), SIGNAL(
initialized(
bool)),
this, SLOT(attachToolsWhenTrackerIsInitializedSlot(
bool)));
230 mTracker->attachTools(mTools);
233 void IgstkToolManager::printStatus()
235 std::cout <<
"mInternalInitialized " << mInternalInitialized << std::endl;
236 std::cout <<
"mInitAnsweres " << mInitAnsweres << std::endl;
237 std::cout <<
"mTracker->isValid() " << mTracker->isValid() << std::endl;
238 std::cout <<
"mTracker->isOpen() " << mTracker->isOpen() << std::endl;
239 std::cout <<
"mTracker->isInitialized() " << mTracker->isInitialized() << std::endl;
240 std::cout <<
"mTracker->isTracking() " << mTracker->isTracking() << std::endl;
241 std::cout <<
"mTools.size() " <<
string_cast(mTools.size()) << std::endl;
boost::shared_ptr< IgstkTracker > TrackerPtr
boost::shared_ptr< IgstkTool > IgstkToolPtr
std::string string_cast(const T &val)
void reportWarning(QString msg)