14 #include "igtlTrackingDataMessage.h" 15 #include "igtlQuaternionTrackingDataMessage.h" 16 #include "igtlTransformMessage.h" 18 #include <vnl/vnl_det.h> 24 this->SetNumberOfRequiredOutputs(1);
25 this->SetNthOutput(0, output.GetPointer());
41 this->RemoveInput(idx);
46 this->ProcessObject::SetNthInput(idx, const_cast<IGTLMessage*>(msg));
54 if (this->GetNumberOfInputs() < 1)
57 return static_cast<const IGTLMessage*
>(this->ProcessObject::GetInput(0));
63 if (this->GetNumberOfInputs() < 1)
66 return static_cast<const IGTLMessage*
>(this->ProcessObject::GetInput(idx));
72 const DataObjectPointerArray& inputs =
const_cast<Self*
>(
this)->GetInputs();
73 for (DataObjectPointerArray::const_iterator it = inputs.begin();
74 it != inputs.end(); ++it)
76 if (std::string(messageName) ==
77 (
static_cast<IGTLMessage*
>(it->GetPointer()))->GetName())
85 itk::ProcessObject::DataObjectPointerArraySizeType
88 DataObjectPointerArray outputs = this->GetInputs();
89 for (DataObjectPointerArray::size_type i = 0; i < outputs.size(); ++i)
92 (static_cast<IGTLMessage*>(outputs.at(i).GetPointer()))->GetName())
97 throw std::invalid_argument(
"output name does not exist");
103 for (DataObjectPointerArraySizeType i = 0;
104 i < UpstreamFilter->GetNumberOfOutputs(); i++)
111 unsigned int numOutputs)
113 this->SetNumberOfIndexedOutputs(numOutputs);
121 bool isModified =
false;
122 for (
unsigned int idx = 0; idx < this->GetNumberOfIndexedOutputs(); ++idx)
127 this->SetNthOutput(idx, newOutput);
142 igtl::TransformMessage* tMsg =
143 (igtl::TransformMessage*)(input->
GetMessage().GetPointer());
148 mitkThrow() <<
"Cast from igtl::MessageBase to igtl::TransformMessage " 149 <<
"failed! Please check the message.";
153 for (
unsigned int i = 0; i < this->GetNumberOfOutputs(); ++i)
165 igtl::Matrix4x4 transformation_;
166 tMsg->GetMatrix(transformation_);
167 mitk::AffineTransform3D::Pointer affineTransformation =
168 mitk::AffineTransform3D::New();
171 for (
unsigned int r = 0; r < 3; r++)
173 for (
unsigned int c = 0; c < 3; c++)
175 transformation.GetVnlMatrix().set(r, c, transformation_[r][c]);
177 offset.SetElement(r, transformation_[r][3]);
180 affineTransformation->SetMatrix(transformation);
181 affineTransformation->SetOffset(offset);
187 mitk::NavigationData::Pointer nd =
190 nd->SetIGTTimeStamp(input->GetTimeStamp());
204 igtl::TrackingDataMessage* tdMsg =
205 (igtl::TrackingDataMessage*)(input->
GetMessage().GetPointer());
210 mitkThrow() <<
"Cast from igtl::MessageBase to igtl::TrackingDataMessage " 211 <<
"failed! Please check the message.";
215 unsigned int numTrackingDataElements =
216 tdMsg->GetNumberOfTrackingDataElements();
218 if (!numTrackingDataElements)
220 MITK_ERROR(
"IGTLMsgToNavDataFilter") <<
"There are no tracking data " 221 "elements in this message";
225 for (
unsigned int i = 0; i < this->GetNumberOfOutputs(); ++i)
240 igtl::TrackingDataElement::Pointer td;
241 tdMsg->GetTrackingDataElement(i, td);
244 igtl::Matrix4x4 transformation_;
245 td->GetMatrix(transformation_);
246 mitk::AffineTransform3D::Pointer affineTransformation =
247 mitk::AffineTransform3D::New();
250 for (
unsigned int r = 0; r < 3; r++)
252 for (
unsigned int c = 0; c < 3; c++)
254 transformation.GetVnlMatrix().set(r, c, transformation_[r][c]);
256 offset.SetElement(r, transformation_[r][3]);
259 affineTransformation->SetMatrix(transformation);
260 affineTransformation->SetOffset(offset);
262 mitk::NavigationData::Pointer nd;
265 vnl_matrix_fixed<ScalarType, 3, 3> rotationMatrix =
266 affineTransformation->GetMatrix().GetVnlMatrix();
267 vnl_matrix_fixed<ScalarType, 3, 3> rotationMatrixTransposed =
268 rotationMatrix.transpose();
271 if (!
Equal(1.0, vnl_det(rotationMatrix), 0.1)
272 || !((rotationMatrix*rotationMatrixTransposed).is_identity(0.1)))
274 MITK_ERROR(
"IGTLMsgToNavDataFilter") <<
"tried to initialize NavData " 275 <<
"with non-rotation matrix :" << rotationMatrix <<
" (Does your " 276 "AffineTransform3D object include spacing? This is not " 277 "supported by NavigationData objects!)";
291 nd->SetName(td->GetName());
303 igtl::QuaternionTrackingDataMessage* tdMsg =
304 (igtl::QuaternionTrackingDataMessage*)(input->
GetMessage().GetPointer());
309 mitkThrow() <<
"Cast from igtl::MessageBase to igtl::TrackingDataMessage " 310 <<
"failed! Please check the message.";
314 unsigned int numTrackingDataElements =
315 tdMsg->GetNumberOfQuaternionTrackingDataElements();
317 if (!numTrackingDataElements)
319 MITK_ERROR(
"IGTLMsgToNavDataFilter") <<
"There are no tracking data " 320 "elements in this message";
324 for (
unsigned int i = 0; i < this->GetNumberOfOutputs(); ++i)
335 if (input->
IsDataValid() ==
false || i >= numTrackingDataElements)
342 igtl::QuaternionTrackingDataElement::Pointer td;
343 tdMsg->GetQuaternionTrackingDataElement(i, td);
346 float quaternion_[4];
347 td->GetQuaternion(quaternion_);
349 quaternion.put(0, quaternion_[0]);
350 quaternion.put(1, quaternion_[1]);
351 quaternion.put(2, quaternion_[2]);
352 quaternion.put(3, quaternion_[3]);
358 td->GetPosition(position_);
360 position.SetElement(0, position_[0]);
361 position.SetElement(1, position_[1]);
362 position.SetElement(2, position_[2]);
368 output->
SetName(td->GetName());
385 MITK_DEBUG(
"IGTLMessageToNavigationDataFilter") <<
"Input data is invalid.";
393 if (strcmp(msgType,
"TRANSFORM") == 0)
397 else if (strcmp(msgType,
"TDATA") == 0)
401 else if (strcmp(msgType,
"QTDATA") == 0)
409 MITK_INFO(
"IGTLMessageToNavigationDataFilter") <<
"The input has a unknown " 424 itkDebugMacro(<<
"GenerateOutputInformation()");
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.
NavigationData * GetOutput(void)
return the output (output with id 0) of the filter
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 ...
virtual void SetIGTTimeStamp(TimeStampType _arg)
sets the IGT timestamp of the NavigationData object in milliseconds
void GenerateQuaternionTrackingDataData()
~IGTLMessageToNavigationDataFilter() override
void GenerateOutputInformation() override
Defines how the input will be copied into the output.
void GenerateTrackingDataData()
virtual bool IsDataValid() const
returns true if the object contains valid data
virtual void SetHasPosition(bool _arg)
sets the HasPosition flag of the NavigationData object
void CreateOutputsForAllInputs()
Create an output for each input.
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
const IGTLMessage * GetInput(void) const
Get the input of this filter.
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.
const char * GetIGTLMessageType() const
OpenIGTLink message source.
vnl_quaternion< ScalarType > Quaternion
virtual igtl::MessageBase::Pointer GetMessage() const
returns the OpenIGTLink message
virtual void SetPosition(PositionType _arg)
sets the position of the NavigationData object
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.
void GenerateData() override
virtual const char * GetName() const
returns the name of the IGTLMessage object
virtual TimeStampType GetIGTTimeStamp() const
gets the IGT timestamp of the IGTLMessage object