void OpenIGTLinkProtocol::translate(const igtl::MessageHeader::Pointer &header, const igtl::MessageBase::Pointer &body) { //CX_LOG_DEBUG() << "Incoming message to OpenIGTLinkProtocol"; QString type = QString(header->GetDeviceType()).toUpper(); if (type=="TRANSFORM") { const igtl::TransformMessage::Pointer temp = dynamic_cast<igtl::TransformMessage*>(body.GetPointer()); this->translate(temp); } else if (type=="POLYDATA") { const igtl::PolyDataMessage::Pointer temp = dynamic_cast<igtl::PolyDataMessage*>(body.GetPointer()); this->translate(temp); } else if (type=="IMAGE") { // //----- CustusX openigtlink server ----- // //there is a special kind of image package coming from custusx // //server where crc is set to 0. // QString name(header->GetDeviceName()); // if(name.contains("Sonix", Qt::CaseInsensitive)) // { // const IGTLinkImageMessage::Pointer temp = dynamic_cast<IGTLinkImageMessage*>(body.GetPointer()); // this->translate(temp); // } // //---------- // else // { const igtl::ImageMessage::Pointer temp = dynamic_cast<igtl::ImageMessage*>(body.GetPointer()); this->translate(temp); // } } else if (type=="STATUS") { const igtl::StatusMessage::Pointer temp = dynamic_cast<igtl::StatusMessage*>(body.GetPointer()); this->translate(temp); } else if (type=="STRING") { const igtl::StringMessage::Pointer temp = dynamic_cast<igtl::StringMessage*>(body.GetPointer()); this->translate(temp); } else if (type=="CX_US_ST") { const IGTLinkUSStatusMessage::Pointer temp = dynamic_cast<IGTLinkUSStatusMessage*>(body.GetPointer()); this->translate(temp); } else { this->writeNotSupportedMessage(body); } }
void mitk::IGTLDevice::AddTrackingMeasurements(const int index, const igtl::MessageBase::Pointer msg, const long long timeStamp) { //Apparently this is the only "elegant" way to do a class check.. or is it??? if (dynamic_cast<igtl::TrackingDataMessage*>(msg.GetPointer()) != nullptr) { igtl::TrackingDataMessage* tdMsg = (igtl::TrackingDataMessage*)(msg.GetPointer()); igtl::TrackingDataElement::Pointer trackingData = igtl::TrackingDataElement::New(); tdMsg->GetTrackingDataElement(0, trackingData); float x_pos, y_pos, z_pos; trackingData->GetPosition(&x_pos, &y_pos, &z_pos); m_Measurement->AddMeasurement(index, x_pos, timeStamp); //x value is used as index } }
/** * @brief convert a igtl::RawMessage(which contain scalar) to a FwDataObjectType * * @return an fwData::Integer converted from an igtl::RawMessage */ ::fwData::Object::sptr fromIgtlMessage (const ::igtl::MessageBase::Pointer src) const { typename FwDataObjectType::sptr obj = FwDataObjectType::New(); RawMessage::Pointer msg = RawMessage::Pointer(dynamic_cast< RawMessage*>(src.GetPointer())); const ScalarType scalar = helper::ScalarToBytes<ScalarType>::fromBytes(msg->getMessage().data()); obj->setValue(scalar); return obj; }
::fwData::Object::sptr PointListConverter::fromIgtlMessage(const ::igtl::MessageBase::Pointer src) const { float igtlPos[3]; ::igtl::PointElement::Pointer elem; std::vector< ::fwData::Point::sptr> fwPoints; ::fwData::Point::sptr fwPoint; ::igtl::PointMessage* msg = dynamic_cast< ::igtl::PointMessage* >(src.GetPointer()); ::igtl::PointMessage::Pointer srcPoints = ::igtl::PointMessage::Pointer(msg); ::fwData::PointList::sptr dest = ::fwData::PointList::New(); for (int i = 0; i < srcPoints->GetNumberOfPointElement(); ++i) { fwPoint = ::fwData::Point::New(); srcPoints->GetPointElement(i, elem); elem->GetPosition(igtlPos); std::transform(&igtlPos[0], &igtlPos[3], fwPoint->getCoord().begin(), ::boost::numeric_cast<float, double>); fwPoints.push_back(fwPoint); } dest->setPoints(fwPoints); return dest; }
void testMessagesEqual(igtl::MessageBase::Pointer sentMessage, igtl::MessageBase::Pointer receivedMessage) { std::string lhs(sentMessage->GetDeviceName()); std::string rhs(receivedMessage->GetDeviceName()); CPPUNIT_ASSERT_MESSAGE("The device names were not the same", lhs == rhs); igtl::StatusMessage::Pointer receivedStatusMessage = dynamic_cast<igtl::StatusMessage*>(receivedMessage.GetPointer()); igtl::StatusMessage::Pointer sentStatusMessage = dynamic_cast<igtl::StatusMessage*>(sentMessage.GetPointer()); CPPUNIT_ASSERT_MESSAGE("The received message was not of the appropriate type.", receivedStatusMessage != nullptr); CPPUNIT_ASSERT_MESSAGE("The sent message was not of the appropriate type.", sentStatusMessage != nullptr); lhs = receivedStatusMessage->GetStatusString(); rhs = sentStatusMessage->GetStatusString(); CPPUNIT_ASSERT_MESSAGE("The sent and received message did not contain the same status message.", lhs == rhs); CPPUNIT_ASSERT_MESSAGE("The sent message did not contain the correct status message.", lhs == m_Message); CPPUNIT_ASSERT_MESSAGE("The received message did not contain the correct status message.", m_Message == rhs); };
::fwData::Object::sptr MatrixConverter::fromIgtlMessage(const ::igtl::MessageBase::Pointer src) const { ::igtl::Matrix4x4 matrix; ::igtl::TransformMessage* msg = dynamic_cast< ::igtl::TransformMessage* >(src.GetPointer()); ::igtl::TransformMessage::Pointer srcTransform = ::igtl::TransformMessage::Pointer(msg); ::fwData::TransformationMatrix3D::sptr dest = ::fwData::TransformationMatrix3D::New(); srcTransform->GetMatrix(matrix); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { dest->setCoefficient(i, j, matrix[i][j]); } } return dest; }
::fwData::Object::sptr CompositeConverter::fromIgtlMessage(const ::igtl::MessageBase::Pointer src) const { ::igtl::TrackingDataMessage::Pointer trackingMsg; trackingMsg = ::igtl::TrackingDataMessage::Pointer(dynamic_cast< ::igtl::TrackingDataMessage* >(src.GetPointer())); const int nbTrckingElement = trackingMsg->GetNumberOfTrackingDataElements(); FW_RAISE_EXCEPTION_IF(::igtlProtocol::exception::Conversion("TrackingDataElements"), nbTrckingElement < 0); ::fwData::Composite::sptr composite = ::fwData::Composite::New(); for(int i = 0; i < nbTrckingElement; ++i) { ::igtl::TrackingDataElement::Pointer trackElement = ::igtl::TrackingDataElement::New(); trackingMsg->GetTrackingDataElement(i, trackElement); const std::string name = trackElement->GetName(); ::fwData::TransformationMatrix3D::sptr transfoMatrix = ::fwData::TransformationMatrix3D::New(); (*composite)[name] = transfoMatrix; ::igtl::Matrix4x4 matrix; trackElement->GetMatrix(matrix); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { transfoMatrix->setCoefficient(i, j, matrix[i][j]); } } } return composite; }
void mitk::IGTLMessageQueue::PushMessage(igtl::MessageBase::Pointer msg) { this->m_Mutex->Lock(); std::stringstream infolog; infolog << "Received message of type "; if (dynamic_cast<igtl::TrackingDataMessage*>(msg.GetPointer()) != nullptr) { if (this->m_BufferingType == IGTLMessageQueue::NoBuffering) m_TrackingDataQueue.clear(); this->m_TrackingDataQueue.push_back(dynamic_cast<igtl::TrackingDataMessage*>(msg.GetPointer())); infolog << "TDATA"; } else if (dynamic_cast<igtl::TransformMessage*>(msg.GetPointer()) != nullptr) { if (this->m_BufferingType == IGTLMessageQueue::NoBuffering) m_TransformQueue.clear(); this->m_TransformQueue.push_back(dynamic_cast<igtl::TransformMessage*>(msg.GetPointer())); infolog << "TRANSFORM"; } else if (dynamic_cast<igtl::StringMessage*>(msg.GetPointer()) != nullptr) { if (this->m_BufferingType == IGTLMessageQueue::NoBuffering) m_StringQueue.clear(); this->m_StringQueue.push_back(dynamic_cast<igtl::StringMessage*>(msg.GetPointer())); infolog << "STRING"; } else if (dynamic_cast<igtl::ImageMessage*>(msg.GetPointer()) != nullptr) { igtl::ImageMessage::Pointer imageMsg = dynamic_cast<igtl::ImageMessage*>(msg.GetPointer()); int* dim = new int[3]; imageMsg->GetDimensions(dim); if (dim[2] > 1) { if (this->m_BufferingType == IGTLMessageQueue::NoBuffering) m_Image3dQueue.clear(); this->m_Image3dQueue.push_back(dynamic_cast<igtl::ImageMessage*>(msg.GetPointer())); infolog << "IMAGE3D"; } else { if (this->m_BufferingType == IGTLMessageQueue::NoBuffering) m_Image2dQueue.clear(); this->m_Image2dQueue.push_back(dynamic_cast<igtl::ImageMessage*>(msg.GetPointer())); infolog << "IMAGE2D"; } } else { if (this->m_BufferingType == IGTLMessageQueue::NoBuffering) m_MiscQueue.clear(); this->m_MiscQueue.push_back(msg); infolog << "OTHER"; } m_Latest_Message = msg; //MITK_INFO << infolog.str(); this->m_Mutex->Unlock(); }