28 #include <itkCommand.h> 36 this->
SetName(
"IGTLDeviceSource (no defined type)");
64 igtl::MessageBase::Pointer msgIn =
dynamic_cast<igtl::MessageBase*
>(
m_IGTLDevice->GetNextImage2dMessage().GetPointer());
65 if (msgIn.IsNotNull())
70 msgOut->
SetName(msgIn->GetDeviceName());
90 MITK_DEBUG <<
"Setting IGTLDevice to " << igtlDevice;
102 std::stringstream name;
103 name <<
"OIGTL Device Source ( " << igtlDevice->GetName() <<
" )";
107 typedef itk::SimpleMemberCommand<IGTLDeviceSource> DeviceSrcCommand;
109 DeviceSrcCommand::Pointer msgReceivedCommand = DeviceSrcCommand::New();
112 this->
m_IGTLDevice->AddObserver(mitk::MessageReceivedEvent(), msgReceivedCommand);
114 DeviceSrcCommand::Pointer cmdReceivedCommand = DeviceSrcCommand::New();
117 this->
m_IGTLDevice->AddObserver(mitk::CommandReceivedEvent(), cmdReceivedCommand);
119 DeviceSrcCommand::Pointer connectionLostCommand = DeviceSrcCommand::New();
122 this->
m_IGTLDevice->AddObserver(mitk::LostConnectionEvent(), connectionLostCommand);
129 if (this->GetNumberOfOutputs() > 0)
131 for (
int numOP = this->GetNumberOfOutputs() - 1; numOP >= 0; numOP--)
132 this->RemoveOutput(numOP);
140 this->SetNumberOfIndexedOutputs(1);
143 DataObjectPointer newOutput = this->
MakeOutput(0);
144 this->SetNthOutput(0, newOutput);
153 throw std::invalid_argument(
"mitk::IGTLDeviceSource: " 154 "No OpenIGTLink device set");
166 throw std::runtime_error(std::string(
"mitk::IGTLDeviceSource: Could not open" 167 "connection to OpenIGTLink device. Error: ") + e.GetDescription());
174 throw std::invalid_argument(
"mitk::IGTLDeviceSource: " 175 "No OpenIGTLink device set");
179 throw std::runtime_error(
"mitk::IGTLDeviceSource: " 180 "Could not start communication");
186 throw std::invalid_argument(
"mitk::IGTLDeviceSource: " 187 "No OpenIGTLink device set");
189 throw std::runtime_error(
"mitk::IGTLDeviceSource: Could not close connection" 190 " to OpenIGTLink device");
196 throw std::invalid_argument(
"mitk::IGTLDeviceSource: " 197 "No OpenIGTLink device set");
199 throw std::runtime_error(
"mitk::IGTLDeviceSource: " 200 "Could not stop communicating");
206 Superclass::UpdateOutputInformation();
213 this->RemoveInput(idx);
218 this->ProcessObject::SetNthInput(idx, const_cast<IGTLMessage*>(msg));
255 MITK_INFO <<
"Registered new DeviceSource as microservice: " << uidGen.
GetUID();
272 if (this->GetNumberOfInputs() < 1)
275 return static_cast<const IGTLMessage*
>(this->ProcessObject::GetInput(0));
281 if (this->GetNumberOfInputs() < 1)
284 return static_cast<const IGTLMessage*
>(this->ProcessObject::GetInput(idx));
290 const DataObjectPointerArray& inputs =
const_cast<Self*
>(
this)->GetInputs();
291 for (DataObjectPointerArray::const_iterator it = inputs.begin();
292 it != inputs.end(); ++it)
293 if (std::string(msgName) ==
294 (
static_cast<IGTLMessage*
>(it->GetPointer()))->GetName())
295 return static_cast<IGTLMessage*>(it->GetPointer());
299 itk::ProcessObject::DataObjectPointerArraySizeType
302 DataObjectPointerArray outputs = this->GetInputs();
303 for (DataObjectPointerArray::size_type i = 0; i < outputs.size(); ++i)
305 (static_cast<IGTLMessage*>(outputs.at(i).GetPointer()))->GetName())
307 throw std::invalid_argument(
"output name does not exist");
virtual bool IsCommunicating()
returns true if communication is in progress
virtual void OnIncomingCommand()
This method is called when the IGTL device hold by this class receives a new command.
static const std::string US_PROPKEY_IGTLDEVICENAME
These Constants are used in conjunction with Microservices.
unsigned int m_IncomingCommandObserverTag
void SetMessage(igtl::MessageBase::Pointer msg)
Sets the OpenIGTLink message.
void StopCommunication()
stops the communication of the device.
~IGTLDeviceSource() override
us::ServiceRegistration< Self > m_ServiceRegistration
virtual void OnLostConnection()
This method is called when the IGTL device lost the connection to the other side. ...
itk::DataObject::Pointer MakeOutput(DataObjectPointerArraySizeType idx) override
void Disconnect()
Closes the connection to the OpenIGTLink device.
const IGTLMessage * GetInput(void) const
Get the input of this filter.
DataCollection - Class to facilitate loading/accessing structured data.
void UpdateOutputInformation() override
Used for pipeline update.
mitk::IGTLDevice::Pointer m_IGTLDevice
void GenerateData() override
filter execute method
virtual void SetIGTLDevice(mitk::IGTLDevice *td)
sets the OpenIGTLink device that will be used as a data source
virtual void SetName(const char *_arg)
set the name of the IGTLMessage object
void CreateOutputs()
Create the necessary outputs for the m_IGTLDevice.
virtual std::string GetName()
IGTLMessage * GetOutput(void)
return the output (output with id 0) of the filter
A wrapper for the OpenIGTLink message type.
An object of this class represents an exception of MITK. Please don't instantiate exceptions manually...
void RegisterAsMicroservice() override
Registers this object as a Microservice, making it available to every module and/or plugin...
static const std::string US_PROPKEY_DEVICETYPE
unsigned int m_LostConnectionObserverTag
OpenIGTLink message source.
void StartCommunication()
starts the communication of the device. This needs to be called before Update() or GetOutput()->Updat...
static const std::string US_PROPKEY_ID
virtual void OnIncomingMessage()
This method is called when the IGTL device hold by this class receives a new message.
virtual void RemoveObservers()
Removes all observers that listen to the igtl device.
US_UNORDERED_MAP_TYPE< std::string, Any > ServiceProperties
virtual void SetInput(unsigned int idx, const IGTLMessage *msg)
Set input with id idx of this filter.
Interface for all OpenIGTLink Devices.
static const std::string US_PROPKEY_DEVICENAME
void Connect()
Establishes a connection to the OpenIGTLink device. If there is already a connection the method does ...
virtual void SetName(std::string _arg)
Sets the human readable name of this source. There is also a default name, but you can use this metho...
virtual bool IsConnected()
returns true if a connection to the OpenIGTLink device is established
static const std::string US_INTERFACE_NAME
These Constants are used in conjunction with Microservices.
unsigned int m_IncomingMessageObserverTag
DataObjectPointerArraySizeType GetInputIndex(std::string msgName)
return the index of the input with name msgName, throw std::invalid_argument exception if that name w...
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.