18 #include "igtlTrackingDataMessage.h"
19 #include "igtlQuaternionTrackingDataMessage.h"
20 #include "igtlTransformMessage.h"
22 #include <vnl/vnl_det.h>
28 this->SetNumberOfRequiredOutputs(1);
29 this->SetNthOutput(0, output.GetPointer());
38 this->SetInput(0, msg);
45 this->RemoveInput(idx);
50 this->ProcessObject::SetNthInput(idx, const_cast<IGTLMessage*>(msg));
52 this->CreateOutputsForAllInputs();
58 if (this->GetNumberOfInputs() < 1)
61 return static_cast<const IGTLMessage*
>(this->ProcessObject::GetInput(0));
67 if (this->GetNumberOfInputs() < 1)
70 return static_cast<const IGTLMessage*
>(this->ProcessObject::GetInput(idx));
76 const DataObjectPointerArray& inputs =
const_cast<Self*
>(
this)->GetInputs();
77 for (DataObjectPointerArray::const_iterator it = inputs.begin();
78 it != inputs.end(); ++it)
80 if (std::string(messageName) ==
81 (
static_cast<IGTLMessage*
>(it->GetPointer()))->GetName())
89 itk::ProcessObject::DataObjectPointerArraySizeType
92 DataObjectPointerArray outputs = this->GetInputs();
93 for (DataObjectPointerArray::size_type i = 0; i < outputs.size(); ++i)
96 (static_cast<IGTLMessage*>(outputs.at(i).GetPointer()))->GetName())
101 throw std::invalid_argument(
"output name does not exist");
107 for (DataObjectPointerArraySizeType i = 0;
108 i < UpstreamFilter->GetNumberOfOutputs(); i++)
110 this->SetInput(i, UpstreamFilter->
GetOutput(i));
115 unsigned int numOutputs)
117 this->SetNumberOfIndexedOutputs(numOutputs);
118 this->CreateOutputsForAllInputs();
125 bool isModified =
false;
126 for (
unsigned int idx = 0; idx < this->GetNumberOfIndexedOutputs(); ++idx)
128 if (this->GetOutput(idx) == NULL)
131 this->SetNthOutput(idx, newOutput);
146 igtl::TransformMessage* tMsg =
147 (igtl::TransformMessage*)(input->
GetMessage().GetPointer());
152 mitkThrow() <<
"Cast from igtl::MessageBase to igtl::TransformMessage "
153 <<
"failed! Please check the message.";
157 for (
unsigned int i = 0; i < this->GetNumberOfOutputs(); ++i)
169 igtl::Matrix4x4 transformation_;
170 tMsg->GetMatrix(transformation_);
175 for (
unsigned int r = 0; r < 3; r++)
177 for (
unsigned int c = 0; c < 3; c++)
179 transformation.GetVnlMatrix().set(r, c, transformation_[r][c]);
181 offset.SetElement(r, transformation_[r][3]);
184 affineTransformation->SetMatrix(transformation);
185 affineTransformation->SetOffset(offset);
194 nd->SetIGTTimeStamp(input->GetTimeStamp());
208 igtl::TrackingDataMessage* tdMsg =
209 (igtl::TrackingDataMessage*)(input->
GetMessage().GetPointer());
214 mitkThrow() <<
"Cast from igtl::MessageBase to igtl::TrackingDataMessage "
215 <<
"failed! Please check the message.";
219 unsigned int numTrackingDataElements =
220 tdMsg->GetNumberOfTrackingDataElements();
222 if (!numTrackingDataElements)
224 MITK_ERROR(
"IGTLMsgToNavDataFilter") <<
"There are no tracking data "
225 "elements in this message";
229 for (
unsigned int i = 0; i < this->GetNumberOfOutputs(); ++i)
240 if (input->
IsDataValid() ==
false || i >= numTrackingDataElements)
248 tdMsg->GetTrackingDataElement(i, td);
251 igtl::Matrix4x4 transformation_;
252 td->GetMatrix(transformation_);
257 for (
unsigned int r = 0; r < 3; r++)
259 for (
unsigned int c = 0; c < 3; c++)
261 transformation.GetVnlMatrix().set(r, c, transformation_[r][c]);
263 offset.SetElement(r, transformation_[r][3]);
266 affineTransformation->SetMatrix(transformation);
267 affineTransformation->SetOffset(offset);
272 vnl_matrix_fixed<ScalarType, 3, 3> rotationMatrix =
273 affineTransformation->GetMatrix().GetVnlMatrix();
274 vnl_matrix_fixed<ScalarType, 3, 3> rotationMatrixTransposed =
275 rotationMatrix.transpose();
278 if (!
Equal(1.0, vnl_det(rotationMatrix), 0.1)
279 || !((rotationMatrix*rotationMatrixTransposed).is_identity(0.1)))
281 MITK_ERROR(
"IGTLMsgToNavDataFilter") <<
"tried to initialize NavData "
282 <<
"with non-rotation matrix :" << rotationMatrix <<
" (Does your "
283 "AffineTransform3D object include spacing? This is not "
284 "supported by NavigationData objects!)";
298 nd->SetName(td->GetName());
310 igtl::QuaternionTrackingDataMessage* tdMsg =
311 (igtl::QuaternionTrackingDataMessage*)(input->
GetMessage().GetPointer());
316 mitkThrow() <<
"Cast from igtl::MessageBase to igtl::TrackingDataMessage "
317 <<
"failed! Please check the message.";
321 unsigned int numTrackingDataElements =
322 tdMsg->GetNumberOfQuaternionTrackingDataElements();
324 if (!numTrackingDataElements)
326 MITK_ERROR(
"IGTLMsgToNavDataFilter") <<
"There are no tracking data "
327 "elements in this message";
331 for (
unsigned int i = 0; i < this->GetNumberOfOutputs(); ++i)
342 if (input->
IsDataValid() ==
false || i >= numTrackingDataElements)
350 tdMsg->GetQuaternionTrackingDataElement(i, td);
353 float quaternion_[4];
354 td->GetQuaternion(quaternion_);
356 quaternion.put(0, quaternion_[0]);
357 quaternion.put(1, quaternion_[1]);
358 quaternion.put(2, quaternion_[2]);
359 quaternion.put(3, quaternion_[3]);
365 td->GetPosition(position_);
367 position.SetElement(0, position_[0]);
368 position.SetElement(1, position_[1]);
369 position.SetElement(2, position_[2]);
375 output->
SetName(td->GetName());
392 MITK_DEBUG(
"IGTLMessageToNavigationDataFilter") <<
"Input data is invalid.";
400 if (strcmp(msgType,
"TRANSFORM") == 0)
402 this->GenerateTransformData();
404 else if (strcmp(msgType,
"TDATA") == 0)
406 this->GenerateTrackingDataData();
408 else if (strcmp(msgType,
"QTDATA") == 0)
410 this->GenerateQuaternionTrackingDataData();
416 MITK_INFO(
"IGTLMessageToNavigationDataFilter") <<
"The input has a unknown "
431 itkDebugMacro(<<
"GenerateOutputInformation()");
virtual bool IsDataValid() const
returns true if the object contains valid data
virtual igtl::MessageBase::Pointer GetMessage() const
returns the OpenIGTLink message
DataObjectPointerArraySizeType GetInputIndex(std::string messageName)
return the index of the input with name messageName, throw std::invalid_argument exception if that na...
virtual void ConnectTo(mitk::IGTLMessageSource *UpstreamFilter)
Connects the input of this filter to the outputs of the given IGTLMessageSource.
itk::SmartPointer< Self > Pointer
itk::Matrix< mitk::ScalarType, 6, 6 > CovarianceMatrixType
type that holds the error characterization of the position and orientation measurements ...
void GenerateTransformData()
virtual void SetCovErrorMatrix(CovarianceMatrixType _arg)
sets the 6x6 Error Covariance Matrix of the NavigationData object
IGTLMessageToNavigationDataFilter()
virtual void SetName(const char *_arg)
set the name of the NavigationData object
DataCollection - Class to facilitate loading/accessing structured data.
virtual void SetInput(const IGTLMessage *msg)
Set the input of this filter.
virtual void SetDataValid(bool _arg)
sets the dataValid flag of the NavigationData object indicating if the object contains valid data ...
const char * GetIGTLMessageType() const
virtual void SetIGTTimeStamp(TimeStampType _arg)
sets the IGT timestamp of the NavigationData object
void GenerateQuaternionTrackingDataData()
virtual void GenerateOutputInformation() override
Defines how the input will be copied into the output.
void GenerateTrackingDataData()
virtual void SetHasPosition(bool _arg)
sets the HasPosition flag of the NavigationData object
void CreateOutputsForAllInputs()
Create an output for each input.
const IGTLMessage * GetInput(void) const
Get the input of this filter.
IGTLMessage * GetOutput(void)
return the output (output with id 0) of the filter
virtual void SetHasOrientation(bool _arg)
sets the HasOrientation flag of the NavigationData object
A wrapper for the OpenIGTLink message type.
virtual void SetOrientation(OrientationType _arg)
sets the orientation of the NavigationData object
void SetNumberOfExpectedOutputs(unsigned int numOutputs)
Sets the number of expected outputs.
virtual const char * GetName() const
returns the name of the IGTLMessage object
OpenIGTLink message source.
vnl_quaternion< ScalarType > Quaternion
virtual ~IGTLMessageToNavigationDataFilter()
virtual void SetPosition(PositionType _arg)
sets the position of the NavigationData object
virtual void Graft(const DataObject *data) override
Graft the data and information from one NavigationData to another.
MITKNEWMODULE_EXPORT bool Equal(mitk::ExampleDataStructure *leftHandSide, mitk::ExampleDataStructure *rightHandSide, mitk::ScalarType eps, bool verbose)
Returns true if the example data structures are considered equal.
virtual void GenerateData() override
virtual TimeStampType GetIGTTimeStamp() const
gets the IGT timestamp of the IGTLMessage object
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.