19 #include "igtlQuaternionTrackingDataMessage.h"
20 #include "igtlTrackingDataMessage.h"
21 #include "igtlTransformMessage.h"
22 #include "igtlPositionMessage.h"
25 #include <itksys/SystemTools.hxx>
30 this->SetNumberOfRequiredOutputs(1);
31 this->SetNthOutput(0, output.GetPointer());
33 this->SetNumberOfRequiredInputs(1);
47 switch (m_OperationMode)
49 case ModeSendQTDataMsg:
50 this->GenerateDataModeSendQTDataMsg();
52 case ModeSendTDataMsg:
53 this->GenerateDataModeSendTDataMsg();
55 case ModeSendQTransMsg:
56 this->GenerateDataModeSendQTransMsg();
58 case ModeSendTransMsg:
59 this->GenerateDataModeSendTransMsg();
65 if (dynamic_cast<igtl::TrackingDataMessage*>(curMessage.GetPointer()) !=
nullptr)
67 igtl::TrackingDataMessage* tdMsg =
68 (igtl::TrackingDataMessage*)(curMessage.GetPointer());
76 this->ProcessObject::SetNthInput(0, const_cast<NavigationData*>(nd));
77 this->CreateOutputsForAllInputs();
83 this->ProcessObject::SetNthInput(idx, const_cast<NavigationData*>(nd));
84 this->CreateOutputsForAllInputs();
89 if (this->GetNumberOfInputs() < 1)
91 return static_cast<const NavigationData*
>(this->ProcessObject::GetInput(0));
96 if (this->GetNumberOfInputs() < 1)
98 return static_cast<const NavigationData*
>(this->ProcessObject::GetInput(idx));
103 switch (m_OperationMode)
105 case ModeSendQTDataMsg:
107 this->SetNumberOfIndexedOutputs(this->GetNumberOfIndexedInputs());
109 this->SetType(
"QTDATA");
111 case ModeSendTDataMsg:
113 this->SetNumberOfIndexedOutputs(this->GetNumberOfIndexedInputs());
115 this->SetType(
"TDATA");
117 case ModeSendQTransMsg:
119 this->SetNumberOfIndexedOutputs(this->GetNumberOfIndexedInputs());
121 this->SetType(
"POSITION");
123 case ModeSendTransMsg:
125 this->SetNumberOfIndexedOutputs(this->GetNumberOfIndexedInputs());
127 this->SetType(
"TRANS");
133 for (
unsigned int idx = 0; idx < this->GetNumberOfIndexedOutputs(); ++idx)
135 if (this->GetOutput(idx) == NULL)
137 DataObjectPointer newOutput = this->MakeOutput(idx);
138 this->SetNthOutput(idx, newOutput);
145 igtl::Matrix4x4 igtlTransform)
147 const mitk::AffineTransform3D::MatrixType& matrix = trans->GetMatrix();
150 for (
unsigned int r = 0; r < 3; r++)
152 for (
unsigned int c = 0; c < 3; c++)
154 igtlTransform[r][c] = matrix(r, c);
156 igtlTransform[r][3] = position[r];
158 for (
unsigned int c = 0; c < 3; c++)
160 igtlTransform[3][c] = 0.0;
162 igtlTransform[3][3] = 1.0;
168 for (
unsigned int i = 0; i < this->GetNumberOfIndexedOutputs(); ++i)
184 posMsg->SetPosition(pos[0], pos[1], pos[2]);
185 posMsg->SetQuaternion(ori[0], ori[1], ori[2], ori[3]);
187 timestamp->SetTime(input->GetTimeStamp().GetMTime() / 1000, input->GetTimeStamp().GetMTime() % 1000);
188 posMsg->SetTimeStamp(timestamp);
189 posMsg->SetDeviceName(input->
GetName());
200 for (
unsigned int i = 0; i < this->GetNumberOfIndexedOutputs(); ++i)
215 igtl::Matrix4x4 igtlTransform;
220 transMsg->SetMatrix(igtlTransform);
221 transMsg->SetPosition(position[0], position[1], position[2]);
223 timestamp->SetTime(input->GetTimeStamp().GetMTime() / 1000, input->GetTimeStamp().GetMTime() % 1000);
224 transMsg->SetTimeStamp(timestamp);
225 transMsg->SetDeviceName(input->
GetName());
245 for (
unsigned int index = 0; index < this->GetNumberOfIndexedInputs(); index++)
257 tde->SetPosition(pos[0], pos[1], pos[2]);
258 tde->SetQuaternion(ori[0], ori[1], ori[2], ori[3]);
262 qtdMsg->AddQuaternionTrackingDataElement(tde);
267 timestamp->SetTime(nd->GetTimeStamp().GetMTime() / 1000, nd->GetTimeStamp().GetMTime() % 1000);
278 bool isValidData =
true;
287 igtl::Matrix4x4 igtlTransform;
288 vnl_matrix_fixed<ScalarType, 3, 3> rotationMatrix;
289 vnl_matrix_fixed<ScalarType, 3, 3> rotationMatrixTransposed;
291 for (
unsigned int index = 0; index < this->GetNumberOfIndexedInputs(); index++)
301 position = transform->GetOffset();
304 rotationMatrix = transform->GetMatrix().GetVnlMatrix();
305 rotationMatrixTransposed = rotationMatrix.transpose();
308 if (!
Equal(1.0, vnl_det(rotationMatrix), 0.1)
309 || !((rotationMatrix*rotationMatrixTransposed).is_identity(0.1)))
319 tde->SetMatrix(igtlTransform);
320 tde->SetPosition(position[0], position[1], position[2]);
321 std::stringstream name;
323 if (name.rdbuf()->in_avail() == 0)
325 name <<
"TrackingTool" << index;
327 tde->SetName(name.str().c_str());
330 tdMsg->AddTrackingDataElement(tde);
335 timestamp->SetTime(nd->GetTimeStamp().GetMTime() / 1000, nd->GetTimeStamp().GetMTime() % 1000);
336 tdMsg->SetTimeStamp(timestamp);
347 m_OperationMode = mode;
349 this->CreateOutputsForAllInputs();
355 for (DataObjectPointerArraySizeType i = 0;
356 i < UpstreamFilter->GetNumberOfOutputs(); i++)
358 this->SetInput(i, UpstreamFilter->
GetOutput(i));
itk::SmartPointer< Self > Pointer
NavigationData * GetOutput(void)
return the output (output with id 0) of the filter
void SetMessage(igtl::MessageBase::Pointer msg)
Sets the OpenIGTLink message.
virtual const char * GetName() const
returns the name of the NavigationData object
unsigned int m_CurrentTimeStep
Indicates the current timestamp.
mitk::AffineTransform3D::Pointer GetAffineTransform3D() const
Calculate AffineTransform3D from the transformation held by this NavigationData. TODO: should throw a...
virtual OrientationType GetOrientation() const
returns the orientation of the NavigationData object
virtual void GenerateDataModeSendQTDataMsg()
Generates the output.
Constants for most interaction classes, due to the generic StateMachines.
mitk::Quaternion OrientationType
Type that holds the orientation part of the tracking data.
void ConvertAffineTransformationIntoIGTLMatrix(mitk::AffineTransform3D *trans, igtl::Matrix4x4 igtlTransform)
virtual void GenerateDataModeSendQTransMsg()
Generates the output for ModeSendQTransMsg.
virtual void GenerateData() override
filter execute method
virtual void ConnectTo(mitk::NavigationDataSource *UpstreamFilter)
Connects the input of this filter to the outputs of the given NavigationDataSource.
virtual void CreateOutputsForAllInputs()
create output objects according to OperationMode for all inputs
virtual ~NavigationDataToIGTLMessageFilter()
A wrapper for the OpenIGTLink message type.
virtual void SetInput(const mitk::NavigationData *NavigationData)
Sets one input NavigationData.
virtual void GenerateDataModeSendTransMsg()
Generates the output for ModeSendTransMsg.
itk::AffineGeometryFrame< ScalarType, 3 >::TransformType AffineTransform3D
virtual bool IsDataValid() const
returns true if the object contains valid data
virtual PositionType GetPosition() const
returns position of the NavigationData object
virtual void SetDataValid(bool _arg)
sets the dataValid flag of the IGTLMessage object indicating if the object contains valid data ...
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.
const mitk::NavigationData * GetInput()
Returns the input of this filter.
virtual void GenerateDataModeSendTDataMsg()
Generates the output for ModeSendTDataMsg.
NavigationDataToIGTLMessageFilter()
virtual void SetOperationMode(OperationMode mode)
Sets the mode of this filter.
OperationMode
There are four different operation modes.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.