3 #include <QMutexLocker> 15 mHeader(igtl::MessageHeader::New()),
16 mBody(igtl::MessageBase::New())
18 this->getReadyToReceiveHeader();
30 return mReadyToReceive &&
mPack->isFinishedWith();
54 QString type = QString(header->GetDeviceType()).toUpper();
55 if (type==
"TRANSFORM")
57 const igtl::TransformMessage::Pointer temp =
dynamic_cast<igtl::TransformMessage*
>(body.GetPointer());
60 else if (type==
"POLYDATA")
62 const igtl::PolyDataMessage::Pointer temp =
dynamic_cast<igtl::PolyDataMessage*
>(body.GetPointer());
65 else if (type==
"IMAGE")
79 const igtl::ImageMessage::Pointer temp =
dynamic_cast<igtl::ImageMessage*
>(body.GetPointer());
83 else if (type==
"STATUS")
85 const igtl::StatusMessage::Pointer temp =
dynamic_cast<igtl::StatusMessage*
>(body.GetPointer());
88 else if (type==
"STRING")
90 const igtl::StringMessage::Pointer temp =
dynamic_cast<igtl::StringMessage*
>(body.GetPointer());
93 else if (type==
"CX_US_ST")
107 QString deviceName = body->GetDeviceName();
121 emit
transform(deviceName, prMs, timestamp.toMSecsSinceEpoch());
149 QString status = converter.
decode(body);
156 QString
string = converter.
decode(body);
168 QString dtype(base->GetDeviceType());
169 QString dname(base->GetDeviceName());
177 QString dtype(body->GetDeviceType());
178 QString dname(body->GetDeviceName());
184 void OpenIGTLinkProtocol::getReadyToReceiveBody()
187 this->prepareBody(mHeader, mBody);
189 this->prepareBodyPack(mBody);
190 this->setReadyToReceive(
true);
193 void OpenIGTLinkProtocol::getReadyToReceiveHeader()
196 this->prepareHeader(mHeader);
197 this->prepareHeaderPack(mHeader);
198 this->setReadyToReceive(
true);
201 bool OpenIGTLinkProtocol::isValid(
const igtl::MessageBase::Pointer &msg)
const 203 if(this->isSupportedBodyType(msg->GetDeviceType()))
209 bool OpenIGTLinkProtocol::isSupportedBodyType(QString type)
const 211 QStringList supportedTypes;
212 supportedTypes <<
"TRANSFORM";
213 supportedTypes <<
"POLYDATA";
214 supportedTypes <<
"IMAGE";
215 supportedTypes <<
"STATUS";
216 supportedTypes <<
"STRING";
217 supportedTypes <<
"CX_US_ST";
219 if(supportedTypes.contains(type, Qt::CaseInsensitive))
232 this->setReadyToReceive(
false);
234 if(
mPack->data()->size == mHeader->GetPackSize())
236 this->unpackHeader(mHeader);
237 CX_LOG_DEBUG() <<
"HEADER: " << mHeader->GetDeviceType();
238 if(this->isValid(mHeader))
239 this->getReadyToReceiveBody();
241 this->getReadyToReceiveHeader();
245 this->unpackBody(mBody);
247 if(this->isValid(mBody))
248 this->getReadyToReceiveHeader();
250 this->getReadyToReceiveBody();
255 void OpenIGTLinkProtocol::setReadyToReceive(
bool ready)
258 mReadyToReceive = ready;
262 void OpenIGTLinkProtocol::prepareHeaderPack(igtl::MessageHeader::Pointer &message)
270 void OpenIGTLinkProtocol::prepareBodyPack(igtl::MessageBase::Pointer &message)
278 void OpenIGTLinkProtocol::prepareHeader(
const igtl::MessageHeader::Pointer &header)
const 285 void OpenIGTLinkProtocol::prepareBody(
const igtl::MessageHeader::Pointer &header, igtl::MessageBase::Pointer &body)
287 QString type = QString(header->GetDeviceType()).toUpper();
288 if (type==
"TRANSFORM")
290 this->prepareBody<igtl::TransformMessage>(header, body);
292 else if (type==
"POLYDATA")
294 this->prepareBody<igtl::PolyDataMessage>(header, body);
296 else if (type==
"IMAGE")
298 this->prepareBody<igtl::ImageMessage>(header, body);
300 else if (type==
"STATUS")
302 this->prepareBody<igtl::StatusMessage>(header, body);
304 else if (type==
"STRING")
306 this->prepareBody<igtl::StringMessage>(header, body);
308 else if (type==
"CX_US_ST")
310 this->prepareBody<IGTLinkUSStatusMessage>(header, body);
318 bool OpenIGTLinkProtocol::unpackHeader(
const igtl::MessageHeader::Pointer &header)
const 320 int doCRCOnHeader = 1;
321 int c = header->Unpack(doCRCOnHeader);
322 if (c & igtl::MessageHeader::UNPACK_HEADER)
335 template <
typename T>
336 void OpenIGTLinkProtocol::prepareBody(
const igtl::MessageHeader::Pointer &header, igtl::MessageBase::Pointer &body)
339 body->SetMessageHeader(header);
340 body->AllocatePack();
345 bool OpenIGTLinkProtocol::unpackBody(
const igtl::MessageBase::Pointer &body)
347 int c = body->Unpack(this->
doCRC());
348 if (c & igtl::MessageHeader::UNPACK_BODY)
#define CX_LOG_CHANNEL_INFO(channel)
QDateTime decode_timestamp(igtl::MessageBase *msg)
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
static EncodedPackagePtr create(igtl::MessageBase::Pointer msg)
void transform(QString devicename, Transform3D transform, double timestamp)
boost::shared_ptr< class Image > ImagePtr
boost::shared_ptr< EncodedPackage > EncodedPackagePtr
void image(ImagePtr image)
#define CX_LOG_CHANNEL_VOLATILE(channel)
ImagePtr decode(igtl::ImageMessage *in)
QString decode(igtl::StringMessage::Pointer msg)
virtual EncodedPackagePtr encode(ImagePtr image)
virtual bool doCRC() const
#define CX_OPENIGTLINK_CHANNEL_NAME
StreamedTimestampSynchronizerPtr mStreamSynchronizer
#define CX_LOG_CHANNEL_DEBUG(channel)
virtual PATIENT_COORDINATE_SYSTEM coordinateSystem() const
void writeNotSupportedMessage(igtl::MessageBase *body) const
void writeAcceptingMessage(igtl::MessageBase *body) const
static EncodedPackagePtr create(typename TYPE::Pointer msg)
igtl::ImageMessage::Pointer encode(ImagePtr in, PATIENT_COORDINATE_SYSTEM externalSpace)
MeshPtr decode(igtl::PolyDataMessage *in, PATIENT_COORDINATE_SYSTEM externalSpace)
igtl::PolyDataMessage::Pointer encode(MeshPtr in, PATIENT_COORDINATE_SYSTEM externalSpace)
igtl::SmartPointer< Self > Pointer
virtual bool readyToReceiveData()
boost::shared_ptr< class Mesh > MeshPtr
#define CX_LOG_CHANNEL_ERROR(channel)
virtual void translate(const igtl::MessageHeader::Pointer &header, const igtl::MessageBase::Pointer &body)
Namespace for all CustusX production code.