16#include "igtlImageMessage.h"
17#include "igtlTransformMessage.h"
18#include "igtlPositionMessage.h"
19#include "igtlStatusMessage.h"
20#include "igtlImageMetaMessage.h"
21#include "igtlPointMessage.h"
22#include "igtlTrajectoryMessage.h"
23#include "igtlStringMessage.h"
24#include "igtlSensorMessage.h"
25#include "igtlBindMessage.h"
26#include "igtlPolyDataMessage.h"
27#include "igtlQuaternionTrackingDataMessage.h"
28#include "igtlCapabilityMessage.h"
29#include "igtlNDArrayMessage.h"
30#include "igtlTrackingDataMessage.h"
31#include "igtlColorTableMessage.h"
32#include "igtlLabelMetaMessage.h"
39#include "itksys/SystemTools.hxx"
59igtl::MessageBase::Pointer TransformMsgCloneHandler::Clone(igtl::MessageBase* original_)
61 bool copySuccess =
false;
62 igtl::TransformMessage::Pointer clone_ = igtl::TransformMessage::New();
67 igtl::TransformMessage* original = (igtl::TransformMessage*)original_;
70 copySuccess = clone_->Copy(original);
78 original->GetMatrix(mat);
79 clone_->SetMatrix(mat);
83 original->GetNormals(normals);
84 clone_->SetNormals(normals);
88 original->GetPosition(position);
89 clone_->SetPosition(position);
91 return igtl::MessageBase::Pointer(clone_.GetPointer());
165 mitk::IGTLMessageCloneHandler::Pointer cloneHandler)
167 this->AddMessageNewMethod(messageTypeName, messageTypeNewPointer);
168 this->AddMessageCloneHandler(messageTypeName, cloneHandler);
174 this->m_NewMethods[messageTypeName] = messageTypeNewPointer;
178 mitk::IGTLMessageCloneHandler::Pointer cloneHandler)
180 this->m_CloneHandlers[msgTypeName] = cloneHandler;
183mitk::IGTLMessageCloneHandler::Pointer
186 if (this->m_CloneHandlers.find(messageTypeName) !=
187 this->m_CloneHandlers.end())
189 return m_CloneHandlers[messageTypeName];
192 MITK_ERROR(
"IGTLMessageFactory") << messageTypeName <<
193 " message type is not registered to factory!";
195 mitkThrow() << messageTypeName <<
" message type is not registered to factory!";
200igtl::MessageBase::Pointer
203 return this->GetCloneHandler(msg->GetDeviceType())->Clone(msg);
209 if (this->m_NewMethods.find(messageTypeName) != this->m_NewMethods.end())
211 return m_NewMethods[messageTypeName];
214 MITK_ERROR(
"IGTLMessageFactory") << messageTypeName <<
215 " message type is not registered to factory!";
219igtl::MessageBase::Pointer
223 this->GetMessageTypeNewPointer(messageTypeName);
224 if (newPointer !=
nullptr)
234std::list<std::string>
237 std::list<std::string> allGetMessages;
238 for (std::map<std::string, PointerToMessageBaseNew>::const_iterator it =
239 this->m_NewMethods.begin();
240 it != this->m_NewMethods.end(); ++it)
242 if (it->first.find(
"GET_") != std::string::npos ||
243 it->first.find(
"STT_") != std::string::npos ||
244 it->first.find(
"STP_") != std::string::npos ||
245 it->first.find(
"RTS_") != std::string::npos)
247 allGetMessages.push_back(it->first);
251 return allGetMessages;
254igtl::MessageBase::Pointer
257 std::string messageType;
260 if (msgHeader.IsNull())
262 messageType =
"NONE";
266 messageType = msgHeader->GetDeviceType();
270 messageType = itksys::SystemTools::UpperCase(messageType);
273 if (this->m_NewMethods.find(messageType)
274 != this->m_NewMethods.end())
276 if (this->m_NewMethods[messageType] !=
nullptr)
279 return (*this->m_NewMethods[messageType])();
286 MITK_ERROR(
"IGTLMessageFactory") <<
"Unknown IGT message type: "
igtl::MessageBase::Pointer Clone(igtl::MessageBase::Pointer msg)
Clones the given message according to the available clone methods.
virtual IGTLMessageFactory::PointerToMessageBaseNew GetMessageTypeNewPointer(std::string messageTypeName)
Get pointer to message type new function, or nullptr if the message type not registered Usage: igtl::...
virtual void AddMessageNewMethod(std::string messageTypeName, IGTLMessageFactory::PointerToMessageBaseNew messageTypeNewPointer)
Add message type name and pointer to IGTL message new function Usage: AddMessageType("IMAGE",...
virtual mitk::IGTLMessageCloneHandler::Pointer GetCloneHandler(std::string messageTypeName)
Get pointer to message type clone function, or nullptr if the message type is not registered Usage: i...
igtl::MessageBase::Pointer CreateInstance(std::string messageTypeName)
Creates a new message instance fitting to the given type.
~IGTLMessageFactory() override
void AddMessageType(std::string messageTypeName, IGTLMessageFactory::PointerToMessageBaseNew messageTypeNewPointer, mitk::IGTLMessageCloneHandler::Pointer cloneHandler)
Add message type name and pointer to IGTL message new function and the clone handler.
igtl::MessageBase::Pointer(*) PointerToMessageBaseNew()
Function pointer for storing New() static methods of igtl::MessageBase classes.
virtual void AddMessageCloneHandler(std::string msgTypeName, mitk::IGTLMessageCloneHandler::Pointer msgCloneHandler)
Adds a clone function for the specified message type.
std::list< std::string > GetAvailableMessageRequestTypes()
Returns available get messages.
#define mitkIGTMessageCloneClassMacro(messagetype, classname)