diff --git a/Modules/IGT/Testing/mitkInternalTrackingToolTest.cpp b/Modules/IGT/Testing/mitkInternalTrackingToolTest.cpp index 5581e99f34..89b4a105af 100644 --- a/Modules/IGT/Testing/mitkInternalTrackingToolTest.cpp +++ b/Modules/IGT/Testing/mitkInternalTrackingToolTest.cpp @@ -1,183 +1,180 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ -#include "mitkInternalTrackingTool.h" +#include "mitkTrackingTool.h" #include "mitkTestingMacros.h" #include #include /**Documentation * NDIPassiveTool has a protected constructor and a protected itkFactorylessNewMacro * so that only it's friend class NDITrackingDevice is able to instantiate * tool objects. Therefore, we derive from NDIPassiveTool and add a * public itkFactorylessNewMacro, so that we can instantiate and test the class */ -class InternalTrackingToolTestClass : public mitk::InternalTrackingTool +class InternalTrackingToolTestClass : public mitk::TrackingTool { public: - mitkClassMacro(InternalTrackingToolTestClass, InternalTrackingTool); + mitkClassMacro(InternalTrackingToolTestClass, TrackingTool); /** make a public constructor, so that the test is able * to instantiate NDIPassiveTool */ itkFactorylessNewMacro(Self) itkCloneMacro(Self) protected: - InternalTrackingToolTestClass() : mitk::InternalTrackingTool() + InternalTrackingToolTestClass() : mitk::TrackingTool() { } public: //these static methods are only to structure the test //please see them seperated from the upper part of the class static void TestBasicFunctionality() - { +{ // let's create an object of our class - mitk::InternalTrackingTool::Pointer internalTrackingTool = InternalTrackingToolTestClass::New().GetPointer(); + mitk::TrackingTool::Pointer trackingTool = InternalTrackingToolTestClass::New().GetPointer(); // first test: did this work? // using MITK_TEST_CONDITION_REQUIRED makes the test stop after failure, since // it makes no sense to continue without an object. - MITK_TEST_CONDITION_REQUIRED(internalTrackingTool.IsNotNull(),"Testing instantiation"); + MITK_TEST_CONDITION_REQUIRED(trackingTool.IsNotNull(),"Testing instantiation"); // test for Enable() - internalTrackingTool->Enable(); - MITK_TEST_CONDITION((internalTrackingTool->IsEnabled()==true),"Testing of Enable()"); + trackingTool->Enable(); + MITK_TEST_CONDITION((trackingTool->IsEnabled()==true),"Testing of Enable()"); srand(time(nullptr)); // generate a random position to test Set/GetPosition() mitk::Point3D position; position[0] = rand()%1000; position[1] = rand()%1000; position[2] = rand()%1000; - internalTrackingTool->SetPosition(position); + trackingTool->SetPosition(position); mitk::Point3D returnedPosition; returnedPosition.Fill(0); - internalTrackingTool->GetPosition(returnedPosition); + trackingTool->GetPosition(returnedPosition); MITK_TEST_CONDITION((position==returnedPosition),"Testing of Set/GetPosition()"); // generate a random orientation to test Set/GetOrientation() mitk::Quaternion orientation; orientation[0] = (rand()%1000)/1000.0; orientation[1] = (rand()%1000)/1000.0; orientation[2] = (rand()%1000)/1000.0; orientation[3] = (rand()%1000)/1000.0; - internalTrackingTool->SetOrientation(orientation); + trackingTool->SetOrientation(orientation); mitk::Quaternion returnedOrientation(0,0,0,0); - internalTrackingTool->GetOrientation(returnedOrientation); + trackingTool->GetOrientation(returnedOrientation); MITK_TEST_CONDITION((orientation==returnedOrientation),"Testing of Set/GetQuaternion()"); // test Set/GetTrackingError() float trackingError = rand()%2; - internalTrackingTool->SetTrackingError(trackingError); - MITK_TEST_CONDITION((internalTrackingTool->GetTrackingError()==trackingError),"Testing of Set/GetTrackingError()"); + trackingTool->SetTrackingError(trackingError); + MITK_TEST_CONDITION((trackingTool->GetTrackingError()==trackingError),"Testing of Set/GetTrackingError()"); // test Set/GetDataValid() - internalTrackingTool->SetDataValid(true); - MITK_TEST_CONDITION((internalTrackingTool->IsDataValid()==true),"Testing of SetDataValid and IsDataValid() for parameter 'true'"); - internalTrackingTool->SetDataValid(false); - MITK_TEST_CONDITION((internalTrackingTool->IsDataValid()==false),"Testing of SetDataValid and IsDataValid() for parameter 'false'"); + trackingTool->SetDataValid(true); + MITK_TEST_CONDITION((trackingTool->IsDataValid()==true),"Testing of SetDataValid and IsDataValid() for parameter 'true'"); + trackingTool->SetDataValid(false); + MITK_TEST_CONDITION((trackingTool->IsDataValid()==false),"Testing of SetDataValid and IsDataValid() for parameter 'false'"); - internalTrackingTool->Disable(); - MITK_TEST_CONDITION((internalTrackingTool->IsEnabled()==false),"Testing of Disable()"); - } + trackingTool->Disable(); + MITK_TEST_CONDITION((trackingTool->IsEnabled()==false),"Testing of Disable()"); +} static void TestTooltipFunctionality() - { - mitk::InternalTrackingTool::Pointer internalTrackingTool = InternalTrackingToolTestClass::New().GetPointer(); +{ + mitk::TrackingTool::Pointer trackingTool = InternalTrackingToolTestClass::New().GetPointer(); mitk::Point3D toolTipPos; mitk::FillVector3D(toolTipPos,1,1,1); mitk::Quaternion toolTipQuat = mitk::Quaternion(0,0,0,1); - internalTrackingTool->SetToolTip(toolTipPos,toolTipQuat); + trackingTool->SetToolTip(toolTipPos,toolTipQuat); mitk::Point3D positionInput; mitk::FillVector3D(positionInput,5,6,7); - internalTrackingTool->SetPosition(positionInput); + trackingTool->SetPosition(positionInput); mitk::Point3D positionOutput; - internalTrackingTool->GetPosition(positionOutput); + trackingTool->GetPosition(positionOutput); MITK_TEST_CONDITION(((positionOutput[0] == 6)&& (positionOutput[0] == 6)&& (positionOutput[0] == 6)&& (positionOutput[0] == 6)), "Testing tooltip definition." ); - - - } +} static void TestModiciationTimeCorrectness() { - mitk::InternalTrackingTool::Pointer tool = InternalTrackingToolTestClass::New().GetPointer(); + mitk::TrackingTool::Pointer tool = InternalTrackingToolTestClass::New().GetPointer(); unsigned long mTime1 = tool->GetMTime(); mitk::Point3D position1; mitk::FillVector3D(position1, 1.1, 2.2, 3.3); tool->SetPosition(position1); MITK_TEST_CONDITION( mTime1 < tool->GetMTime(), "Testing MTime updated after initial position set" ); mitk::Quaternion quat1 = mitk::Quaternion(0,0,0.70710678118654757,0.70710678118654757); tool->SetOrientation(quat1); MITK_TEST_CONDITION( mTime1 < tool->GetMTime(), "Testing MTime updated after initial orientation set" ); unsigned long mTime2 = tool->GetMTime(); mitk::Point3D position2; mitk::FillVector3D(position2, 1.10001, 2.2, 3.3); tool->SetPosition(position2); MITK_TEST_CONDITION( mTime2 < tool->GetMTime(), "Testing MTime updated after new position set" ); unsigned long mTime3 = tool->GetMTime(); mitk::Quaternion quat2 = mitk::Quaternion(0.0, 0.0, 0.70710678118654757, 0.70710678118654757 + 0.00001); tool->SetOrientation(quat2); MITK_TEST_CONDITION( mTime3 < tool->GetMTime(), "Testing MTime updated after new orientation set" ); mitk::Point3D position3; mitk::FillVector3D(position3, 1.10002, 2.2, 3.3); } }; /** - * Simple example for a test for the class "InternalTrackingTool". + * Simple example for a test for the class "TrackingTool". * * argc and argv are the command line parameters which were passed to * the ADD_TEST command in the CMakeLists.txt file. For the automatic * tests, argv is either empty for the simple tests or contains the filename * of a test image for the image tests (see CMakeLists.txt). */ int mitkInternalTrackingToolTest(int /* argc */, char* /*argv*/[]) { // always start with this! - MITK_TEST_BEGIN("InternalTrackingTool") + MITK_TEST_BEGIN("TrackingTool") InternalTrackingToolTestClass::TestBasicFunctionality(); InternalTrackingToolTestClass::TestTooltipFunctionality(); InternalTrackingToolTestClass::TestModiciationTimeCorrectness(); - // always end with this! MITK_TEST_END(); } diff --git a/Modules/IGT/TrackingDevices/mitkClaronTool.cpp b/Modules/IGT/TrackingDevices/mitkClaronTool.cpp index 575d872f34..9853620688 100644 --- a/Modules/IGT/TrackingDevices/mitkClaronTool.cpp +++ b/Modules/IGT/TrackingDevices/mitkClaronTool.cpp @@ -1,104 +1,104 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkClaronTool.h" #include #include #include -mitk::ClaronTool::ClaronTool() :InternalTrackingTool() +mitk::ClaronTool::ClaronTool() : TrackingTool() { } mitk::ClaronTool::~ClaronTool(void) { } std::string mitk::ClaronTool::GetCalibrationName() { return &m_CalibrationName[0]; } void mitk::ClaronTool::SetCalibrationName(std::string name) { this->m_CalibrationName=name; } bool mitk::ClaronTool::LoadFile(const char* filename) { if (filename==nullptr) { return false; } else { return this->LoadFile(std::string(filename)); } } bool mitk::ClaronTool::LoadFile(std::string filename) { //This method is not really "loading" a file. It is saving the filename and //parsing the calibration name out of the filename. The calibration name is //later used by the tracking device to really load the file. if (filename.empty()) { return false; } else { m_Filename = filename; int end = m_Filename.length(); int start = end; //check whether the path is given in Windows format while( (start!=0) && (filename[start-1]!='\\') ) start--; //if not (start==0) perhaps it is given in Linux format if (start==0) { start = end; while( (start!=0) && (filename[start-1]!='/') ) { start--; } } //if there are no \ and no / in the string something must be wrong... if (start==0) return false; this->m_CalibrationName = m_Filename.substr(start,end); return true; } } std::string mitk::ClaronTool::GetFile() { return m_Filename; } void mitk::ClaronTool::SetToolHandle (mitk::claronToolHandle handle) { this->m_ToolHandle = handle; } mitk::claronToolHandle mitk::ClaronTool::GetToolHandle() { return this->m_ToolHandle; } diff --git a/Modules/IGT/TrackingDevices/mitkClaronTool.h b/Modules/IGT/TrackingDevices/mitkClaronTool.h index 6d94e5de60..1b436fc6a6 100644 --- a/Modules/IGT/TrackingDevices/mitkClaronTool.h +++ b/Modules/IGT/TrackingDevices/mitkClaronTool.h @@ -1,86 +1,86 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef MITKCLARONTOOL_H_HEADER_INCLUDED_ #define MITKCLARONTOOL_H_HEADER_INCLUDED_ #include -#include +#include #include namespace mitk { class ClaronTrackingDevice; /** Documentation: * \brief An object of this class represents a MicronTracker 2 tool. * A tool has to be added to a tracking device which will then * continuously update the tool coordinates. * \ingroup IGT */ - class MITKIGT_EXPORT ClaronTool : public InternalTrackingTool + class MITKIGT_EXPORT ClaronTool : public TrackingTool { public: friend class ClaronTrackingDevice; - mitkClassMacro(ClaronTool, InternalTrackingTool); + mitkClassMacro(ClaronTool, TrackingTool); /** * \brief Loads a tool calibration file. Without this file the tool can not be tracked! */ bool LoadFile(const char* filename); /** * \brief Loads a tool calibration file. Without this file the tool can not be tracked! */ bool LoadFile(std::string filename); std::string GetFile(); /** * \brief Sets the handle of the tool. * \param handle The new handle of the tool. */ void SetToolHandle (claronToolHandle handle); /** * \return Returns the calibration name which is used to identify the tool. */ std::string GetCalibrationName(); /** * \brief Sets the calibration name of the tool. Be careful, only use this method if you know what you are doing. * If you want to change the tool name use the method setToolName instead! */ void SetCalibrationName(std::string name); /** * @return Returns the tool handle of the tool. */ claronToolHandle GetToolHandle(); protected: itkFactorylessNewMacro(Self) itkCloneMacro(Self) ClaronTool(); virtual ~ClaronTool(); /** \brief Tool handle variable from tracking device */ claronToolHandle m_ToolHandle; /** \brief Variable which holds the Tool's calibration name */ std::string m_CalibrationName; /** \brief Variable to check filename's format and to get back complete filename */ std::string m_Filename; }; }//mitk #endif // MITKCLARONTOOL_H_HEADER_INCLUDED_ diff --git a/Modules/IGT/TrackingDevices/mitkMicroBirdTool.cpp b/Modules/IGT/TrackingDevices/mitkMicroBirdTool.cpp index 80621d2254..a2323c72f6 100644 --- a/Modules/IGT/TrackingDevices/mitkMicroBirdTool.cpp +++ b/Modules/IGT/TrackingDevices/mitkMicroBirdTool.cpp @@ -1,26 +1,26 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkMicroBirdTool.h" mitk::MicroBirdTool::MicroBirdTool() -: InternalTrackingTool() +: TrackingTool() { } mitk::MicroBirdTool::~MicroBirdTool() { } diff --git a/Modules/IGT/TrackingDevices/mitkMicroBirdTool.h b/Modules/IGT/TrackingDevices/mitkMicroBirdTool.h index fa4601e651..fd2184b88f 100644 --- a/Modules/IGT/TrackingDevices/mitkMicroBirdTool.h +++ b/Modules/IGT/TrackingDevices/mitkMicroBirdTool.h @@ -1,43 +1,42 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef MITKMICROBIRDTOOL_H_HEADER_INCLUDED_ #define MITKMICROBIRDTOOL_H_HEADER_INCLUDED_ -#include -//#include "mitkTrackingTypes.h" +#include namespace mitk { //##Documentation //## \brief Implementation of a MicroBird tool //## //## //## \ingroup IGT - class MITKIGT_EXPORT MicroBirdTool : public InternalTrackingTool + class MITKIGT_EXPORT MicroBirdTool : public TrackingTool { public: - mitkClassMacro(MicroBirdTool, InternalTrackingTool); + mitkClassMacro(MicroBirdTool, TrackingTool); itkFactorylessNewMacro(Self) itkCloneMacro(Self) protected: MicroBirdTool(); virtual ~MicroBirdTool(); }; } // namespace mitk #endif /* MITKMICROBIRDTOOL_H_HEADER_INCLUDED_ */ diff --git a/Modules/IGT/TrackingDevices/mitkMicroBirdTrackingDevice.h b/Modules/IGT/TrackingDevices/mitkMicroBirdTrackingDevice.h index a4720b6435..6b08322256 100644 --- a/Modules/IGT/TrackingDevices/mitkMicroBirdTrackingDevice.h +++ b/Modules/IGT/TrackingDevices/mitkMicroBirdTrackingDevice.h @@ -1,141 +1,141 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef MITKMIRCOBIRDTRACKINGDEVICE_H_HEADER_INCLUDED #define MITKMIRCOBIRDTRACKINGDEVICE_H_HEADER_INCLUDED #include "mitkTrackingDevice.h" #include #include #include #include "mitkTrackingTypes.h" #include "mitkMicroBirdTool.h" #include "PCIBird3.h" namespace mitk { /**Documentation * \brief superclass for specific MIRCOBIRD tracking Devices * * This class connects to a Ascension Microbird tracking device. * You can not add tools manually. All connected tools are discovered * during OpenConnection() and added automatically. Retrieve them with * GetTool(unsigned int toolNumber) and GetToolCount() after a call to * OpenConnection(). * * \ingroup IGT */ class MITKIGT_EXPORT MicroBirdTrackingDevice : public TrackingDevice { public: mitkClassMacro(MicroBirdTrackingDevice, TrackingDevice); itkFactorylessNewMacro(Self) itkCloneMacro(Self) /**Documentation * \brief Set the type of the microBird Tracking Device because it can not yet handle this itself */ itkSetMacro(Type,TrackingDeviceType); /**Documentation * \brief Builds up the connection (loads tools, initializes and enables them) */ virtual bool OpenConnection(); /**Documentation * \brief Closes the connection **/ virtual bool CloseConnection(); /**Documentation * \brief Start the tracking. * * A new thread is created, which reads the position and orientation information of each tool and stores them inside the tools. **/ virtual bool StartTracking(); /**Documentation * \brief here we use the superclass method. **/ virtual bool StopTracking(); /**Documentation * \brief returns a tracking tool that contains positional information about one of the sensors **/ virtual TrackingTool* GetTool(unsigned int toolNumber); /**Documentation * \brief returns a the number of attached sensors **/ virtual unsigned int GetToolCount() const; /**Documentation * \brief returns description of most recent error. **/ itkGetStringMacro(ErrorMessage); protected: void HandleError(int errorCode); bool CompareError(int errorCode, int errorConstant); - typedef InternalTrackingTool ToolType; + typedef TrackingTool ToolType; typedef std::vector ToolContainerType; MicroBirdTrackingDevice(); virtual ~MicroBirdTrackingDevice(); /**Documentation * \brief returns a tracking tool that contains positional information about one of the sensors **/ ToolType* GetMicroBirdTool(unsigned int toolNumber); virtual void InvalidateAll(); ///< invalidates all tools (on stoptracking, closeconnection) bool SwitchTransmitter(bool switchOn);///< Switches the transmitter on resp. off /**Documentation * \brief tracks the position and orientation of all tools until StopTracking() is called. * * This function should only be executed by a new thread (through StartTracking() and ThreadStartTracking()) */ virtual void TrackTools(); static ITK_THREAD_RETURN_TYPE ThreadStartTracking(void* data); ///< Helper function, because the itk::MultiThreader can only start a new thread with a static member function itkSetStringMacro(ErrorMessage); itk::FastMutexLock::Pointer m_ToolsMutex; ToolContainerType m_Tools; std::string m_ErrorMessage; itk::MultiThreader::Pointer m_MultiThreader; int m_ThreadID; //DOUBLE_POSITION_MATRIX_TIME_Q_RECORD record, *pRecord; ///< One tracking data record (matrix orientation format) DOUBLE_POSITION_QUATERNION_TIME_Q_RECORD record, *pRecord; ///< One tracking data record (quaternion orientation format) SYSTEM_CONFIGURATION m_SystemConfig; ///< The system configuration - used to specify its use SENSOR_CONFIGURATION *m_SensorConfig; ///< The sensor configuration - used to get and set the sensor properties TRANSMITTER_CONFIGURATION *m_TransmitterConfig; ///< The transmitter configuration - used to get and set the transmitter properties BOOL m_metric; ///< Specifies whether metric measurement is used double m_measurementRate; ///< Specifies the measurement rate - default set to maximum double m_pl; ///< Specifies the power line frequency (Europe 50Hz, USA 60Hz) bool m_agcModeBoth; ///< AGC (automatic gain control) mode flag AGC_MODE_TYPE m_agc; }; } // namespace mitk #endif /* MITKMIRCOBIRDTRACKINGDEVICE_H_HEADER_INCLUDED*/ diff --git a/Modules/IGT/TrackingDevices/mitkNDIPassiveTool.cpp b/Modules/IGT/TrackingDevices/mitkNDIPassiveTool.cpp index de0d5e4e93..ae50e71837 100644 --- a/Modules/IGT/TrackingDevices/mitkNDIPassiveTool.cpp +++ b/Modules/IGT/TrackingDevices/mitkNDIPassiveTool.cpp @@ -1,84 +1,84 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkNDIPassiveTool.h" #include #include mitk::NDIPassiveTool::NDIPassiveTool() -: InternalTrackingTool(), +: TrackingTool(), m_SROMData(nullptr), m_SROMDataLength(0), m_TrackingPriority(Dynamic), m_PortHandle() { } mitk::NDIPassiveTool::~NDIPassiveTool() { if (m_SROMData != nullptr) { delete[] m_SROMData; m_SROMData = nullptr; } } bool mitk::NDIPassiveTool::LoadSROMFile(const char* filename) { if (filename == nullptr) return false; if (filename[0] == '\0') return false; m_File = filename; std::basic_ifstream file; file.open(filename, std::ios::in | std::ios::binary); // open the file if (file.is_open() == false) return false; file.seekg (0, std::ios::end); // get the length of the file unsigned int newLength = file.tellg(); file.seekg (0, std::ios::beg); auto newData = new char [newLength]; // create a buffer to store the srom file file.read(newData, newLength); // read the file into the buffer file.close(); if (file.fail() == true) // reading of data unsuccessful? { delete[] newData; return false; } if (m_SROMData != nullptr) // reading was successful, delete old data delete[] m_SROMData; m_SROMDataLength = newLength; // set member variables to new values m_SROMData = (unsigned char*) newData; this->Modified(); return true; } const unsigned char* mitk::NDIPassiveTool::GetSROMData() const { return m_SROMData; } unsigned int mitk::NDIPassiveTool::GetSROMDataLength() const { return m_SROMDataLength; } diff --git a/Modules/IGT/TrackingDevices/mitkNDIPassiveTool.h b/Modules/IGT/TrackingDevices/mitkNDIPassiveTool.h index 25d4a4a0bc..fe9ad8f963 100644 --- a/Modules/IGT/TrackingDevices/mitkNDIPassiveTool.h +++ b/Modules/IGT/TrackingDevices/mitkNDIPassiveTool.h @@ -1,78 +1,78 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef MITKNDIPASSIVETOOL_H_HEADER_INCLUDED_ #define MITKNDIPASSIVETOOL_H_HEADER_INCLUDED_ -#include +#include #include "mitkTrackingTypes.h" namespace mitk { class NDITrackingDevice; /**Documentation * \brief Implementation of a passive NDI optical tool * * implements the TrackingTool interface and has the ability to * load an srom file that contains the marker configuration for that tool * * \ingroup IGT */ - class MITKIGT_EXPORT NDIPassiveTool : public InternalTrackingTool + class MITKIGT_EXPORT NDIPassiveTool : public TrackingTool { public: friend class NDITrackingDevice; /** * \brief tracking priority for NDI tracking devices */ enum TrackingPriority { Static = 'S', Dynamic = 'D', ButtonBox = 'B' }; - mitkClassMacro(NDIPassiveTool, InternalTrackingTool); + mitkClassMacro(NDIPassiveTool, TrackingTool); virtual bool LoadSROMFile(const char* filename); ///< load a srom tool description file virtual const unsigned char* GetSROMData() const; ///< get loaded srom file as unsigned char array virtual unsigned int GetSROMDataLength() const; ///< get length of SROMData char array itkSetStringMacro(PortHandle); ///< get port handle under which the tool is registered in the tracking device itkGetStringMacro(PortHandle); ///< set port handle under which the tool is registered in the tracking device itkSetMacro(TrackingPriority, TrackingPriority); ///< set tracking priority that the ndi tracking device should use itkGetConstMacro(TrackingPriority, TrackingPriority); ///< get tracking priority that the ndi tracking device should use itkSetStringMacro(SerialNumber); ///< set serial number of the tool itkGetStringMacro(SerialNumber); ///< get serial number of the tool itkGetStringMacro(File); ///< get file from which this tool was loaded protected: itkFactorylessNewMacro(Self) itkCloneMacro(Self) NDIPassiveTool(); virtual ~NDIPassiveTool(); unsigned char* m_SROMData; ///< content of the srom tool description file unsigned int m_SROMDataLength; ///< length of the srom tool description file TrackingPriority m_TrackingPriority; ///< priority for this tool std::string m_PortHandle; ///< port handle for this tool std::string m_SerialNumber; ///< serial number for this tool std::string m_File; ///< the original file from which this tool was loaded }; } // namespace mitk #endif /* MITKNDIPASSIVETOOL_H_HEADER_INCLUDED_ */ diff --git a/Modules/IGT/TrackingDevices/mitkOpenIGTLinkTrackingTool.cpp b/Modules/IGT/TrackingDevices/mitkOpenIGTLinkTrackingTool.cpp index 13f9ae4d24..189353a195 100644 --- a/Modules/IGT/TrackingDevices/mitkOpenIGTLinkTrackingTool.cpp +++ b/Modules/IGT/TrackingDevices/mitkOpenIGTLinkTrackingTool.cpp @@ -1,28 +1,28 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkOpenIGTLinkTrackingTool.h" #include #include #include -mitk::OpenIGTLinkTrackingTool::OpenIGTLinkTrackingTool() :InternalTrackingTool() +mitk::OpenIGTLinkTrackingTool::OpenIGTLinkTrackingTool() : TrackingTool() { } mitk::OpenIGTLinkTrackingTool::~OpenIGTLinkTrackingTool(void) { } diff --git a/Modules/IGT/TrackingDevices/mitkOpenIGTLinkTrackingTool.h b/Modules/IGT/TrackingDevices/mitkOpenIGTLinkTrackingTool.h index 67f761eadb..80dadcfe1f 100644 --- a/Modules/IGT/TrackingDevices/mitkOpenIGTLinkTrackingTool.h +++ b/Modules/IGT/TrackingDevices/mitkOpenIGTLinkTrackingTool.h @@ -1,46 +1,46 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef MITKOpenIGTLinkTrackingTOOL_H_HEADER_INCLUDED_ #define MITKOpenIGTLinkTrackingTOOL_H_HEADER_INCLUDED_ -#include +#include #include namespace mitk { class OpenIGTLinkTrackingDevice; /** Documentation: * \brief An object of this class represents a OpenIGTLink tracking tool. * A tool has to be added to a tracking device which will then * continuously update the tool coordinates. * \ingroup IGT */ - class MITKIGT_EXPORT OpenIGTLinkTrackingTool : public InternalTrackingTool + class MITKIGT_EXPORT OpenIGTLinkTrackingTool : public TrackingTool { public: friend class OpenIGTLinkTrackingTrackingDevice; - mitkClassMacro(OpenIGTLinkTrackingTool, InternalTrackingTool); + mitkClassMacro(OpenIGTLinkTrackingTool, TrackingTool); itkFactorylessNewMacro(Self) protected: itkCloneMacro(Self) OpenIGTLinkTrackingTool(); virtual ~OpenIGTLinkTrackingTool(); }; }//mitk #endif // MITKOpenIGTLinkTrackingTOOL_H_HEADER_INCLUDED_ diff --git a/Modules/IGT/TrackingDevices/mitkOptitrackTrackingTool.cpp b/Modules/IGT/TrackingDevices/mitkOptitrackTrackingTool.cpp index 3fb6348a22..6204cfa3ed 100644 --- a/Modules/IGT/TrackingDevices/mitkOptitrackTrackingTool.cpp +++ b/Modules/IGT/TrackingDevices/mitkOptitrackTrackingTool.cpp @@ -1,642 +1,642 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkOptitrackTrackingTool.h" #ifdef MITK_USE_OPTITRACK_TRACKER /** * \brief API library header for Optitrack Systems */ #include //======================================================= // Constructor //======================================================= mitk::OptitrackTrackingTool::OptitrackTrackingTool() - : mitk::InternalTrackingTool(), + : mitk::TrackingTool(), m_ID(-1) { MITK_DEBUG << "Creating OptitrackTrackingTool Object"; this->m_FLE = 0.0; } //======================================================= // Destructor //======================================================= mitk::OptitrackTrackingTool::~OptitrackTrackingTool() { delete this->m_calibrationPoints; delete m_pivotPoint; MITK_DEBUG << "Deleting OptitrackTrackingTool Object"; } //======================================================= // SetToolByFileName //======================================================= bool mitk::OptitrackTrackingTool::SetToolByFileName(std::string nameFile) { MITK_DEBUG << "SetToolByFileName"; MITK_INFO<<"Name of the file for configuration: "<m_fileConfiguration = nameFile; int resultFscan, resultUpdate, resultCreateTrackable, resultTrackableTranslatePivot; // Check the file path if(this->m_fileConfiguration.empty()) { MITK_INFO << "Calibration File for Tool is empty"; mitkThrowException(mitk::IGTException) << "Calibration File for Tool is empty"; return false; } // Open the file FILE* calib_file = fopen(this->m_fileConfiguration.c_str(),"r"); if (calib_file == nullptr) { MITK_INFO << "Error using opening file"; mitkThrowException(mitk::IGTException) << "Cannot open configuration file"; return false; } MITK_DEBUG<<"Reading configuration file..."; // Get the name this->m_ToolName = ""; char* aux = new char[200]; resultFscan = fscanf(calib_file,"%s\n",aux); this->m_ToolName.append(aux); delete aux; if ((resultFscan < 1) || this->m_ToolName.empty()) { MITK_INFO << "No name found in the tool configuration file"; mitkThrowException(mitk::IGTException) << "No name found in the tool configuration file"; return false; } MITK_INFO<<"ToolName: " << this->m_ToolName; // Get the number of of points resultFscan = fscanf(calib_file,"%i\n",&(this->m_numMarkers)); if (this->m_numMarkers < 3) { MITK_INFO << "The minimum number for define a tool is 3 markers"; mitkThrowException(mitk::IGTException) << "Tool has less than 3 markers"; return false; } MITK_INFO<<"\tNumer of Markers: " << this->m_numMarkers; // Read the Calibration Point locations and save them this->m_calibrationPoints = new float[3*this->m_numMarkers]; for(int i=0; im_numMarkers; i++) { resultFscan = fscanf(calib_file,"%fe ", &this->m_calibrationPoints[i*3+0]); if (resultFscan < 1) { MITK_INFO << "Cannot read X location for marker " << i; mitkThrowException(mitk::IGTException) << "Cannot read X location for marker " << i; return false; } resultFscan = fscanf(calib_file,"%fe ", &this->m_calibrationPoints[i*3+1]); if (resultFscan < 1) { MITK_INFO << "Cannot read Y location for marker " << i; mitkThrowException(mitk::IGTException) << "Cannot read Y location for marker " << i; return false; } resultFscan = fscanf(calib_file,"%fe\n", &this->m_calibrationPoints[i*3+2]); if (resultFscan < 1) { MITK_INFO << "Cannot read Z location for marker " << i; mitkThrowException(mitk::IGTException) << "Cannot read Z location for marker " << i; return false; } MITK_DEBUG << "\t\tMarker " << i; MITK_DEBUG << "\t\t X: " << this->m_calibrationPoints[i*3+0] << " Y: " << this->m_calibrationPoints[i*3+1] << " Z: " << this->m_calibrationPoints[i*3+2]; this->m_calibrationPoints[i*3+0] = this->m_calibrationPoints[i*3+0]/1000; this->m_calibrationPoints[i*3+1] = this->m_calibrationPoints[i*3+1]/1000; this->m_calibrationPoints[i*3+2] = -this->m_calibrationPoints[i*3+2]/1000;// Optitrack works with Left Handed System } // Read the Pivot Point location this->m_pivotPoint = new float[3]; resultFscan = fscanf(calib_file,"%fe ", &this->m_pivotPoint[0]); if (resultFscan < 1) { MITK_INFO << "Cannot read X location for Pivot Point "; mitkThrowException(mitk::IGTException) << "Cannot read X location for Pivot Point "; return false; } resultFscan = fscanf(calib_file,"%fe ", &this->m_pivotPoint[1]); if (resultFscan < 1) { MITK_INFO << "Cannot read Y location for Pivot Point " ; mitkThrowException(mitk::IGTException) << "Cannot read Y location for Pivot Point "; return false; } resultFscan = fscanf(calib_file,"%fe\n", &this->m_pivotPoint[2]); if (resultFscan < 1) { MITK_INFO << "Cannot read Z location for Pivot Point " ; mitkThrowException(mitk::IGTException) << "Cannot read Z location for Pivot Point "; return false; } MITK_INFO << "\tPivotPoint " ; MITK_INFO << "\t\t X: " << this->m_pivotPoint[0] << " Y: " << this->m_pivotPoint[1] << " Z: " << this->m_pivotPoint[2]; // mm -> m this->m_pivotPoint[0] = this->m_pivotPoint[0]/1000; this->m_pivotPoint[1] = this->m_pivotPoint[1]/1000; this->m_pivotPoint[2] = -this->m_pivotPoint[2]/1000; // get the ID for next tool in Optitrack System this->m_ID = this->get_IDnext(); // Create the Tool for( int i=OPTITRACK_ATTEMPTS; i>0; i--) { resultCreateTrackable = TT_CreateTrackable(m_ToolName.c_str(), this->m_ID,this->m_numMarkers,this->m_calibrationPoints); if(NPRESULT_SUCCESS == resultCreateTrackable) { MITK_INFO << "Trackable Created Successfully"; i = -1; } else { MITK_DEBUG << mitk::OptitrackErrorMessages::GetOptitrackErrorMessage(resultCreateTrackable); MITK_DEBUG << "Trying again..."; } } for( int i=OPTITRACK_ATTEMPTS; i>0; i--) { resultUpdate = TT_Update(); if(NPRESULT_SUCCESS == resultUpdate) { resultTrackableTranslatePivot = TT_TrackableTranslatePivot(this->m_ID,this->m_pivotPoint[0],this->m_pivotPoint[1],this->m_pivotPoint[2]); if(NPRESULT_SUCCESS == resultCreateTrackable) { MITK_INFO << "Pivot Translation Successfull"; fclose(calib_file); i=-1; return true; } else { MITK_INFO << mitk::OptitrackErrorMessages::GetOptitrackErrorMessage(resultUpdate); MITK_DEBUG << "Trying again..."; } } else { MITK_INFO << mitk::OptitrackErrorMessages::GetOptitrackErrorMessage(resultUpdate); MITK_DEBUG << "Trying again..."; } } MITK_INFO << "Cannot create tool "; mitkThrowException(mitk::IGTException) << "Cannot create tool "; return false; } //======================================================= // get_IDnext //======================================================= int mitk::OptitrackTrackingTool::get_IDnext() { MITK_DEBUG << "get_ID"; int num_trackables = -1; int resultUpdate; for( int i=OPTITRACK_ATTEMPTS; i>0; i--) { resultUpdate = TT_Update(); if(NPRESULT_SUCCESS == resultUpdate) { num_trackables = TT_TrackableCount(); MITK_DEBUG << " Next ID: " << num_trackables; if(num_trackables > -1) { return num_trackables; } else { MITK_DEBUG << "get_IDnext failed"; mitkThrowException(mitk::IGTException) << "get_IDnext failed"; } } else { MITK_DEBUG << mitk::OptitrackErrorMessages::GetOptitrackErrorMessage(resultUpdate); MITK_DEBUG << "Trying again..."; } } mitkThrowException(mitk::IGTException) << "get_IDnext failed"; return num_trackables; } //======================================================= // DeleteTrackable //======================================================= bool mitk::OptitrackTrackingTool::DeleteTrackable() { MITK_DEBUG << "DeleteTrackable"; int resultRemoveTrackable; resultRemoveTrackable = TT_RemoveTrackable(this->m_ID); if(resultRemoveTrackable != NPRESULT_SUCCESS) { MITK_INFO << "Cannot Remove Trackable"; MITK_INFO << mitk::OptitrackErrorMessages::GetOptitrackErrorMessage(resultRemoveTrackable); mitkThrowException(mitk::IGTException) << "Cannot Remove Trackable" << mitk::OptitrackErrorMessages::GetOptitrackErrorMessage(resultRemoveTrackable); return false; } else { MITK_INFO<<"Trackable " << this->m_ToolName << " removed"; } return true; } //======================================================= // SetPosition //======================================================= void mitk::OptitrackTrackingTool::SetPosition(mitk::Point3D position, ScalarType eps) { MITK_DEBUG << "SetPosition"; // sets the position this->m_Position[0] = position[0]; this->m_Position[1] = position[1]; this->m_Position[2] = position[2]; } //======================================================= // SetOrientation //======================================================= void mitk::OptitrackTrackingTool::SetOrientation(mitk::Quaternion orientation, ScalarType eps) { MITK_DEBUG << "SetOrientation"; // sets the orientation as a quaternion this->m_Orientation.x() = orientation.x(); this->m_Orientation.y() = orientation.y(); this->m_Orientation.z() = orientation.z(); this->m_Orientation.r() = orientation.r(); } //======================================================= // GetPosition //======================================================= void mitk::OptitrackTrackingTool::GetPosition(mitk::Point3D& positionOutput) const { MITK_DEBUG << "GetPosition"; // returns the current position of the tool as an array of three floats (in the tracking device coordinate system) positionOutput[0] = this->m_Position[0]; positionOutput[1] = this->m_Position[1]; positionOutput[2] = this->m_Position[2]; } //======================================================= // GetOrientation //======================================================= void mitk::OptitrackTrackingTool::GetOrientation(mitk::Quaternion& orientation) const { MITK_DEBUG << "GetOrientation"; // returns the current orientation of the tool as a quaternion (in the tracking device coordinate system) orientation.x() = this->m_Orientation.x(); orientation.y() = this->m_Orientation.y(); orientation.z() = this->m_Orientation.z(); orientation.r() = this->m_Orientation.r(); } //======================================================= // Enable //======================================================= bool mitk::OptitrackTrackingTool::Enable() { MITK_DEBUG << "Enable"; // enable the tool, so that it will be tracked. Returns true if enabling was successfull TT_SetTrackableEnabled(this->m_ID, true); if(TT_TrackableEnabled(this->m_ID) == true) { this->m_Enabled = true; return true; } else { this->m_Enabled = false; MITK_INFO << "Enable failed"; mitkThrowException(mitk::IGTException) << "Enable failed"; return false; } } //======================================================= // Disable //======================================================= bool mitk::OptitrackTrackingTool::Disable() { MITK_DEBUG << "Disable"; // disables the tool, so that it will not be tracked anymore. Returns true if disabling was successfull TT_SetTrackableEnabled(this->m_ID, false); if(TT_TrackableEnabled(this->m_ID) == true) { this->m_Enabled = false; return true; } else { this->m_Enabled = true; MITK_INFO << "Disable failed"; mitkThrowException(mitk::IGTException) << "Disable failed"; return false; } } //======================================================= // IsEnabled //======================================================= bool mitk::OptitrackTrackingTool::IsEnabled() const { MITK_DEBUG << "IsEnabled"; // returns whether the tool is enabled or disabled return TT_TrackableEnabled(this->m_ID); } //======================================================= // IsDataValid //======================================================= bool mitk::OptitrackTrackingTool::IsDataValid() const { MITK_DEBUG << "IsDataValid"; // returns true if the current position data is valid (no error during tracking, tracking error below threshold, ...) return this->m_DataValid; } //======================================================= // GetTrackingError //======================================================= float mitk::OptitrackTrackingTool::GetTrackingError() const { MITK_DEBUG << "GetTrackingError"; // return one value that corresponds to the overall tracking error. The dimension of this value is specific to each tracking device return this->m_TrackingError; } //======================================================= // SetTrackingError //======================================================= void mitk::OptitrackTrackingTool::SetTrackingError(float error) { MITK_DEBUG << "GetTrackingError"; //< sets the tracking error //this->m_FLE = error; //this->UpdateError; this->m_TrackingError = error; } //======================================================= // SetDataValid //======================================================= void mitk::OptitrackTrackingTool::SetDataValid(bool validate) { MITK_DEBUG << "SetDataValid"; // sets if the tracking data (position & Orientation) is valid this->m_DataValid = validate; } //======================================================= // updateTool //======================================================= void mitk::OptitrackTrackingTool::updateTool() { MITK_DEBUG << "updateTool"; float yaw,pitch,roll; float data[7]; if(TT_Update() == NPRESULT_SUCCESS) { if(this->IsEnabled()) { TT_TrackableLocation(this->m_ID, &data[0], &data[1], &data[2], // Position &data[3], &data[4], &data[5], &data[6], // Orientation &yaw, &pitch, &roll); // Orientation //for( int i=0; i<7; i++) //{ // if(boost::math::isinf(data[i])) // Possible Tracking check for INF numbers // { // this->SetDataValid(false); // MITK_DEBUG << "Data set to INF by the system"; // return; // } //} // m -> mm this->m_Position[0] = data[0]*1000; this->m_Position[1] = data[1]*1000; this->m_Position[2] = -data[2]*1000; // Correction from LeftHanded to RightHanded system this->m_Orientation.x() = data[3]; this->m_Orientation.y() = data[4]; this->m_Orientation.z() = -data[5]; this->m_Orientation.r() = data[6]; this->SetDataValid(true); MITK_DEBUG << this->m_Position[0] << " " << this->m_Position[1] << " " << this->m_Position[2]; MITK_DEBUG << data[3] << " " << data[4] << " " << data[5] << " " << data[6]; } else { this->SetDataValid(false); MITK_DEBUG << "Trackable: "<< this->m_ToolName << "is not Tracked"; } } else { this->SetDataValid(false); MITK_DEBUG << "Update Failed"; } } //======================================================= // IF Optitrack is not installed set functions to warnings //======================================================= #else //======================================================= // Constructor //======================================================= mitk::OptitrackTrackingTool::OptitrackTrackingTool() - : mitk::InternalTrackingTool(), + : mitk::TrackingTool(), m_ID(-1) { MITK_WARN("IGT") << "Error: " << mitk::OptitrackErrorMessages::GetOptitrackErrorMessage(100); } //======================================================= // Destructor //======================================================= mitk::OptitrackTrackingTool::~OptitrackTrackingTool() { MITK_WARN("IGT") << "Error: " << mitk::OptitrackErrorMessages::GetOptitrackErrorMessage(100); } //======================================================= // SetToolByFileName //======================================================= bool mitk::OptitrackTrackingTool::SetToolByFileName(std::string) { MITK_WARN("IGT") << "Error: " << mitk::OptitrackErrorMessages::GetOptitrackErrorMessage(100); return false; } //======================================================= // get_IDnext //======================================================= int mitk::OptitrackTrackingTool::get_IDnext() { MITK_WARN("IGT") << "Error: " << mitk::OptitrackErrorMessages::GetOptitrackErrorMessage(100); return -1; } //======================================================= // DeleteTrackable //======================================================= bool mitk::OptitrackTrackingTool::DeleteTrackable() { MITK_WARN("IGT") << "Error: " << mitk::OptitrackErrorMessages::GetOptitrackErrorMessage(100); return false; } //======================================================= // SetPosition //======================================================= void mitk::OptitrackTrackingTool::SetPosition(mitk::Point3D, ScalarType) { MITK_WARN("IGT") << "Error: " << mitk::OptitrackErrorMessages::GetOptitrackErrorMessage(100); } //======================================================= // SetOrientation //======================================================= void mitk::OptitrackTrackingTool::SetOrientation(mitk::Quaternion, ScalarType) { MITK_WARN("IGT") << "Error: " << mitk::OptitrackErrorMessages::GetOptitrackErrorMessage(100); } //======================================================= // GetPosition //======================================================= void mitk::OptitrackTrackingTool::GetPosition(mitk::Point3D&) const { MITK_WARN("IGT") << "Error: " << mitk::OptitrackErrorMessages::GetOptitrackErrorMessage(100); } //======================================================= // GetOrientation //======================================================= void mitk::OptitrackTrackingTool::GetOrientation(mitk::Quaternion&) const { MITK_WARN("IGT") << "Error: " << mitk::OptitrackErrorMessages::GetOptitrackErrorMessage(100); } //======================================================= // Enable //======================================================= bool mitk::OptitrackTrackingTool::Enable() { MITK_WARN("IGT") << "Error: " << mitk::OptitrackErrorMessages::GetOptitrackErrorMessage(100); return false; } //======================================================= // Disable //======================================================= bool mitk::OptitrackTrackingTool::Disable() { MITK_WARN("IGT") << "Error: " << mitk::OptitrackErrorMessages::GetOptitrackErrorMessage(100); return false; } //======================================================= // IsEnabled //======================================================= bool mitk::OptitrackTrackingTool::IsEnabled() const { MITK_WARN("IGT") << "Error: " << mitk::OptitrackErrorMessages::GetOptitrackErrorMessage(100); return false; } //======================================================= // IsDataValid //======================================================= bool mitk::OptitrackTrackingTool::IsDataValid() const { MITK_WARN("IGT") << "Error: " << mitk::OptitrackErrorMessages::GetOptitrackErrorMessage(100); return false; } //======================================================= // GetTrackingError //======================================================= float mitk::OptitrackTrackingTool::GetTrackingError() const { MITK_WARN("IGT") << "Error: " << mitk::OptitrackErrorMessages::GetOptitrackErrorMessage(100); return 0.0; } //======================================================= // SetTrackingError //======================================================= void mitk::OptitrackTrackingTool::SetTrackingError(float) { MITK_WARN("IGT") << "Error: " << mitk::OptitrackErrorMessages::GetOptitrackErrorMessage(100); } //======================================================= // SetDataValid //======================================================= void mitk::OptitrackTrackingTool::SetDataValid(bool) { MITK_WARN("IGT") << "Error: " << mitk::OptitrackErrorMessages::GetOptitrackErrorMessage(100); } //======================================================= // updateTool //======================================================= void mitk::OptitrackTrackingTool::updateTool() { MITK_WARN("IGT") << "Error: " << mitk::OptitrackErrorMessages::GetOptitrackErrorMessage(100); } #endif diff --git a/Modules/IGT/TrackingDevices/mitkOptitrackTrackingTool.h b/Modules/IGT/TrackingDevices/mitkOptitrackTrackingTool.h index f119c11934..f47895ba43 100644 --- a/Modules/IGT/TrackingDevices/mitkOptitrackTrackingTool.h +++ b/Modules/IGT/TrackingDevices/mitkOptitrackTrackingTool.h @@ -1,221 +1,221 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef OptiTrackTrackingTool_H_HEADER_INCLUDED_ #define OptiTrackTrackingTool_H_HEADER_INCLUDED_ #include #include #include "itkFastMutexLock.h" #include "mitkTrackingDevice.h" #include "mitkTrackingTool.h" #include "mitkIGTTimeStamp.h" #include #include #include #include #include #include "mitkCommon.h" -#include +#include #include #include #include "mitkIGTException.h" /** * \brief Function to get the Error messages from API */ #include namespace mitk { - //class OptitrackTragkingDevice; + //class OptitrackTrackingDevice; /** Documentation: * \brief An object of this class represents the a Tool tracked by Optitrack System. You can define * the tool by the a definition file like in the example in ****. Remember that it will be necessary to * to have a license for using the Optitrack System. * See http://www.naturalpoint.com/ for details. * \author E. Marinetto (emarinetto@hggm.es) Instituto de Investigación Sanitaria Gregorio Marañón, Madrid, Spain. & M. Noll (matthias.noll@igd.fraunhofer.de) Cognitive Computing & Medical Imaging | Fraunhofer IGD * \ingroup IGT */ - class MITKIGT_EXPORT OptitrackTrackingTool : public InternalTrackingTool + class MITKIGT_EXPORT OptitrackTrackingTool : public TrackingTool { public: friend class OptitrackTrackingDevice; - mitkClassMacro(mitk::OptitrackTrackingTool, mitk::InternalTrackingTool); + mitkClassMacro(mitk::OptitrackTrackingTool, mitk::TrackingTool); itkNewMacro(Self); /** * \brief Define the tool by a calibration File. * The file must to have the next structure. Makers locations must to have "%fe %fe %fe\n" format and in (mm). See http://www.cplusplus.com/reference/cstdio/fscanf/ * ToolName * #NumberOfMarkers * X Y Z - for the first marker * X Y Z - for the second marker * ... * X Y Z - for the last marker, the number #NumberOfMarkers * X Y Z - for the PIVOT point * \return Returns true if the tool was set correctly * @throw mitk::IGTException Throws an exception if there exist any problem during the configuration file reading. */ bool SetToolByFileName(std::string nameFile); /** * \brief Ask API the next number of defined tool * \return Returns the next ID (int) for a new tool in the device list for API * @throw mitk::IGTException Throws an exception if get_IDnext failed */ int get_IDnext(); /** * \brief Delete the tool from the list of tools inside API Optitrack * \return Returns true if the deletion was correct * @throw mitk::IGTException Throws an exception if */ bool DeleteTrackable(); /** * \brief Set the position to a given one * @throw mitk::IGTException Throws an exception if */ using Superclass::SetPosition; void SetPosition(mitk::Point3D position, ScalarType eps=0.0); /** * \brief Set the orientation to a given one using a quaternion nomenclature * @throw mitk::IGTException Throws an exception if */ using Superclass::SetOrientation; void SetOrientation(mitk::Quaternion orientation, ScalarType eps=0.0); /** * \brief Get the position of the tool * @throw mitk::IGTException Throws an exception if */ void GetPosition(mitk::Point3D& position) const override; /** * \brief Get the orientation of the tool using quaternion nomenclature * @throw mitk::IGTException Throws an exception if */ void GetOrientation(mitk::Quaternion& orientation) const override; /** * \brief Set the tool enabled for tracking. * \return Return true if the enabling was successfull * @throw mitk::IGTException Throws an exception if */ bool Enable() override; /** * \brief Set the tool disabled for tracking. * \return Return true if the disabling was successfull * @throw mitk::IGTException Throws an exception if */ bool Disable() override; /** * \brief Check if the tool is enabled (true) or not. * \return Return true if the tool is enabled for tracking * @throw mitk::IGTException Throws an exception if */ bool IsEnabled() const override; /** * \brief Check if the data of the tool is valid. * \return Return true if location data is valid * @throw mitk::IGTException Throws an exception if */ bool IsDataValid() const override; /** * \brief Get the expectated error in the tracked tool * \return Return the error location * @throw mitk::IGTException Throws an exception if */ float GetTrackingError() const override; /** * \brief Set the FLE (Fiducial Localization Error) for the tool * @throw mitk::IGTException Throws an exception if */ void SetTrackingError(float FLEerror) override; /** * \brief Set the valid flag for tracking data to true * @throw mitk::IGTException Throws an exception if */ void SetDataValid(bool _arg) override; /** * \brief Update location and orientation of the tool * @throw mitk::IGTException Throws an exception if */ void updateTool(); /** * \brief Constructor of the class */ OptitrackTrackingTool(); /** * \brief Destructor of the class */ ~OptitrackTrackingTool(); /** * \brief File of the configuration for the tool */ std::string m_fileConfiguration; /** * \brief ID number from Optitrack API */ int m_ID; /** * \brief List of Markers locations in calibration position and orientation */ float* m_calibrationPoints; /** * \brief location of the pivot point during calibration */ float* m_pivotPoint; /** * \brief Number of Markers that blong to the tool */ int m_numMarkers; /** * \brief Expected value of the fiducial localization error (rms) */ float m_FLE; private: OptitrackTrackingTool(const OptitrackTrackingTool&); const OptitrackTrackingTool& operator=(const OptitrackTrackingTool&); }; } #endif /* OptiTrackTrackingTool_H_HEADER_INCLUDED_ */ diff --git a/Modules/IGT/TrackingDevices/mitkPolhemusTool.cpp b/Modules/IGT/TrackingDevices/mitkPolhemusTool.cpp index 5131f608ae..cf25994d27 100644 --- a/Modules/IGT/TrackingDevices/mitkPolhemusTool.cpp +++ b/Modules/IGT/TrackingDevices/mitkPolhemusTool.cpp @@ -1,35 +1,35 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkPolhemusTool.h" -mitk::PolhemusTool::PolhemusTool() :InternalTrackingTool() +mitk::PolhemusTool::PolhemusTool() : TrackingTool() { } mitk::PolhemusTool::~PolhemusTool(void) { } void mitk::PolhemusTool::SetToolPort(int _ToolPort) { this->m_ToolPort = _ToolPort; } int mitk::PolhemusTool::GetToolPort() { return this->m_ToolPort; } diff --git a/Modules/IGT/TrackingDevices/mitkPolhemusTool.h b/Modules/IGT/TrackingDevices/mitkPolhemusTool.h index 1f23d2ece5..09495b6f98 100644 --- a/Modules/IGT/TrackingDevices/mitkPolhemusTool.h +++ b/Modules/IGT/TrackingDevices/mitkPolhemusTool.h @@ -1,60 +1,60 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef MITKPolhemusTOOL_H_HEADER_INCLUDED_ #define MITKPolhemusTOOL_H_HEADER_INCLUDED_ #include -#include +#include #include namespace mitk { class PolhemusTrackingDevice; /** Documentation: * \brief An object of this class represents a tool of a Polhemus tracking device. * A tool has to be added to a tracking device which will then * continuously update the tool coordinates. * \ingroup IGT */ - class MITKIGT_EXPORT PolhemusTool : public InternalTrackingTool + class MITKIGT_EXPORT PolhemusTool : public TrackingTool { public: friend class PolhemusTrackingDevice; - mitkClassMacro(PolhemusTool, InternalTrackingTool); + mitkClassMacro(PolhemusTool, TrackingTool); /** * \brief Sets the port of the tool. (e.g. 1 for port "SENS 1" etc.) */ virtual void SetToolPort(int _ToolPort); /** * \brief Sets the port of the tool. (e.g. 1 for port "SENS 1" etc.) */ virtual int GetToolPort(); protected: itkFactorylessNewMacro(Self) itkCloneMacro(Self) PolhemusTool(); virtual ~PolhemusTool(); //This is the port, on which the tool is connected. It is identical with the "ToolIdentifier" set on NavigationDataTools. //If tool is connected on port "SENS 2", the m_ToolPort is 2 etc. int m_ToolPort; }; }//mitk #endif // MITKPolhemusTOOL_H_HEADER_INCLUDED_ diff --git a/Modules/IGT/TrackingDevices/mitkTrackingTool.cpp b/Modules/IGT/TrackingDevices/mitkTrackingTool.cpp index 9386e027a6..28d800163e 100644 --- a/Modules/IGT/TrackingDevices/mitkTrackingTool.cpp +++ b/Modules/IGT/TrackingDevices/mitkTrackingTool.cpp @@ -1,54 +1,288 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkTrackingTool.h" #include typedef itk::MutexLockHolder MutexLockHolder; - mitk::TrackingTool::TrackingTool() -: itk::Object(), m_ToolName(""), m_ErrorMessage(""), m_IGTTimeStamp(0) +: itk::Object(), + m_ToolName(""), + m_ErrorMessage(""), + m_IGTTimeStamp(0), + m_MyMutex(itk::FastMutexLock::New()), + m_TrackingError(0.0f), + m_Enabled(true), + m_DataValid(false), + m_ToolTipSet(false) { - m_MyMutex = itk::FastMutexLock::New(); + m_Position[0] = 0.0f; + m_Position[1] = 0.0f; + m_Position[2] = 0.0f; + m_Orientation[0] = 0.0f; + m_Orientation[1] = 0.0f; + m_Orientation[2] = 0.0f; + m_Orientation[3] = 0.0f; + // this should not be necessary as the tools bring their own tooltip transformation + m_ToolTip[0] = 0.0f; + m_ToolTip[1] = 0.0f; + m_ToolTip[2] = 0.0f; + m_ToolTipRotation[0] = 0.0f; + m_ToolTipRotation[1] = 0.0f; + m_ToolTipRotation[2] = 0.0f; + m_ToolTipRotation[3] = 1.0f; } - mitk::TrackingTool::~TrackingTool() { m_MyMutex->Unlock(); m_MyMutex = nullptr; } void mitk::TrackingTool::PrintSelf(std::ostream& os, itk::Indent indent) const { Superclass::PrintSelf(os, indent); os << indent << "ToolName: " << m_ToolName << std::endl; os << indent << "ErrorMesage: " << m_ErrorMessage << std::endl; + os << indent << "Position: " << m_Position << std::endl; + os << indent << "Orientation: " << m_Orientation << std::endl; + os << indent << "TrackingError: " << m_TrackingError << std::endl; + os << indent << "Enabled: " << m_Enabled << std::endl; + os << indent << "DataValid: " << m_DataValid << std::endl; + os << indent << "ToolTip: " << m_ToolTip << std::endl; + os << indent << "ToolTipRotation: " << m_ToolTipRotation << std::endl; + os << indent << "ToolTipSet: " << m_ToolTipSet << std::endl; } const char* mitk::TrackingTool::GetToolName() const { MutexLockHolder lock(*m_MyMutex); // lock and unlock the mutex return this->m_ToolName.c_str(); } +void mitk::TrackingTool::SetToolName(const char* _arg) +{ + itkDebugMacro("setting m_ToolName to " << _arg); + MutexLockHolder lock(*m_MyMutex); // lock and unlock the mutex + if ( _arg && (_arg == this->m_ToolName) ) + { + return; + } + if (_arg) + { + this->m_ToolName= _arg; + } + else + { + this->m_ToolName= ""; + } + this->Modified(); +} + + +void mitk::TrackingTool::SetToolName( const std::string _arg ) +{ + this->SetToolName(_arg.c_str()); +} + +mitk::Point3D mitk::TrackingTool::GetToolTip() const +{ + return m_ToolTip; +} + +void mitk::TrackingTool::SetToolTip(mitk::Point3D toolTipPosition, + mitk::Quaternion orientation, + mitk::ScalarType eps) +{ + if ( !Equal(m_ToolTip, toolTipPosition, eps) || + !Equal(m_ToolTipRotation, orientation, eps) ) + { + if( (toolTipPosition[0] == 0) && + (toolTipPosition[1] == 0) && + (toolTipPosition[2] == 0) && + (orientation.x() == 0) && + (orientation.y() == 0) && + (orientation.z() == 0) && + (orientation.r() == 1)) + { + m_ToolTipSet = false; + } + else + { + m_ToolTipSet = true; + } + m_ToolTip = toolTipPosition; + m_ToolTipRotation = orientation; + this->Modified(); + } +} + +bool mitk::TrackingTool::IsTooltipSet() const +{ + MutexLockHolder lock(*m_MyMutex); // lock and unlock the mutex + return m_ToolTipSet; +} + +mitk::Quaternion mitk::TrackingTool::GetToolTipOrientation() const +{ + MutexLockHolder lock(*m_MyMutex); + return m_ToolTipRotation; +} + +void mitk::TrackingTool::GetPosition(mitk::Point3D& position) const +{ + MutexLockHolder lock(*m_MyMutex); // lock and unlock the mutex + if (m_ToolTipSet) + { + // Compute the position of tool tip in the coordinate frame of the + // tracking device: Rotate the position of the tip into the tracking + // device coordinate frame then add to the position of the tracking + // sensor + vnl_vector pos_vnl = m_Position.GetVnlVector() + m_Orientation.rotate( m_ToolTip.GetVnlVector() ) ; + + position[0] = pos_vnl[0]; + position[1] = pos_vnl[1]; + position[2] = pos_vnl[2]; + } + else + { + position[0] = m_Position[0]; + position[1] = m_Position[1]; + position[2] = m_Position[2]; + } + this->Modified(); +} + +void mitk::TrackingTool::SetPosition(mitk::Point3D position) +{ + itkDebugMacro("setting m_Position to " << position); + + MutexLockHolder lock(*m_MyMutex); // lock and unlock the mutex + m_Position = position; + this->Modified(); +} + +void mitk::TrackingTool::GetOrientation(mitk::Quaternion& orientation) const +{ + MutexLockHolder lock(*m_MyMutex); // lock and unlock the mutex + if (m_ToolTipSet) + { + // Compute the orientation of the tool tip in the coordinate frame of + // the tracking device. + // + // * m_Orientation is the orientation of the sensor relative to the transmitter + // * m_ToolTipRotation is the orientation of the tool tip relative to the sensor + orientation = m_Orientation * m_ToolTipRotation; + } + else + { + orientation = m_Orientation; + } +} + +void mitk::TrackingTool::SetOrientation(mitk::Quaternion orientation) +{ + itkDebugMacro("setting m_Orientation to " << orientation); + + MutexLockHolder lock(*m_MyMutex); // lock and unlock the mutex + m_Orientation = orientation; + this->Modified(); +} + +bool mitk::TrackingTool::Enable() +{ + MutexLockHolder lock(*m_MyMutex); // lock and unlock the mutex + if (m_Enabled == false) + { + this->m_Enabled = true; + this->Modified(); + } + return true; +} + +bool mitk::TrackingTool::Disable() +{ + MutexLockHolder lock(*m_MyMutex); // lock and unlock the mutex + if (m_Enabled == true) + { + this->m_Enabled = false; + this->Modified(); + } + return true; +} + +bool mitk::TrackingTool::IsEnabled() const +{ + MutexLockHolder lock(*m_MyMutex); // lock and unlock the mutex + return m_Enabled; +} + +void mitk::TrackingTool::SetDataValid(bool _arg) +{ + itkDebugMacro("setting m_DataValid to " << _arg); + if (this->m_DataValid != _arg) + { + MutexLockHolder lock(*m_MyMutex); // lock and unlock the mutex + this->m_DataValid = _arg; + this->Modified(); + } +} + +bool mitk::TrackingTool::IsDataValid() const +{ + MutexLockHolder lock(*m_MyMutex); // lock and unlock the mutex + return m_DataValid; +} + +float mitk::TrackingTool::GetTrackingError() const +{ + MutexLockHolder lock(*m_MyMutex); // lock and unlock the mutex + float r = m_TrackingError; + return r; +} + +void mitk::TrackingTool::SetTrackingError(float error) +{ + itkDebugMacro("setting m_TrackingError to " << error); + MutexLockHolder lock(*m_MyMutex); // lock and unlock the mutex + if (error == m_TrackingError) + { + return; + } + m_TrackingError = error; + this->Modified(); +} const char* mitk::TrackingTool::GetErrorMessage() const { MutexLockHolder lock(*m_MyMutex); // lock and unlock the mutex return this->m_ErrorMessage.c_str(); } + +void mitk::TrackingTool::SetErrorMessage(const char* _arg) +{ + itkDebugMacro("setting m_ErrorMessage to " << _arg); + MutexLockHolder lock(*m_MyMutex); // lock and unlock the mutex + if ((_arg == nullptr) || (_arg == this->m_ErrorMessage)) + return; + + if (_arg != nullptr) + this->m_ErrorMessage = _arg; + else + this->m_ErrorMessage = ""; + this->Modified(); +} diff --git a/Modules/IGT/TrackingDevices/mitkTrackingTool.h b/Modules/IGT/TrackingDevices/mitkTrackingTool.h index 9bf467ef97..b8278a954d 100644 --- a/Modules/IGT/TrackingDevices/mitkTrackingTool.h +++ b/Modules/IGT/TrackingDevices/mitkTrackingTool.h @@ -1,65 +1,98 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef MITKTRACKINGTOOL_H_HEADER_INCLUDED_ #define MITKTRACKINGTOOL_H_HEADER_INCLUDED_ #include #include #include #include #include namespace mitk { /**Documentation * \brief Interface for all Tracking Tools * - * Abstract class that defines the methods that are common for all tracking tools. + * This class is a complete TrackingTool implementation. It can either be used directly by + * TrackingDevices, or be subclassed for more specific implementations. + * mitk::MicroBirdTrackingDevice uses this class to manage its tools. Other tracking devices + * uses specialized versions of this class (e.g. mitk::NDITrackingTool) * * \ingroup IGT */ class MITKIGT_EXPORT TrackingTool : public itk::Object { public: mitkClassMacroItkParent(TrackingTool, itk::Object); virtual void PrintSelf(std::ostream& os, itk::Indent indent) const override; - virtual void SetToolTip(Point3D toolTipPosition, Quaternion orientation, ScalarType eps=0.0) = 0; ///< defines a tool tip for this tool in tool coordinates. GetPosition() and GetOrientation() return the data of the tool tip if it is defined. By default no tooltip is defined. - virtual void GetPosition(Point3D& position) const = 0; ///< returns the current position of the tool as an array of three floats (in the tracking device coordinate system) - virtual void GetOrientation(Quaternion& orientation) const = 0; ///< returns the current orientation of the tool as a quaternion in a mitk::Point4D (in the tracking device coordinate system) - virtual bool Enable() = 0; ///< enables the tool, so that it will be tracked - virtual bool Disable() = 0; ///< disables the tool, so that it will not be tracked anymore - virtual bool IsEnabled() const = 0; ///< returns whether the tool is enabled or disabled - virtual bool IsDataValid() const = 0; ///< returns true if the current position data is valid (no error during tracking, tracking error below threshold, ...) - virtual float GetTrackingError() const = 0; ///< returns one value that corresponds to the overall tracking error. - virtual const char* GetToolName() const; ///< every tool has a name that can be used to identify it. - virtual const char* GetErrorMessage() const; ///< if the data is not valid, ErrorMessage should contain a string explaining why it is invalid (the Set-method should be implemented in subclasses, it should not be accessible by the user) - itkSetMacro(IGTTimeStamp, double); ///< Sets the IGT timestamp of the tracking tool object (time in milliseconds) - itkGetConstMacro(IGTTimeStamp, double); ///< Gets the IGT timestamp of the tracking tool object (time in milliseconds). Returns 0 if the timestamp was not set. + virtual const char* GetToolName() const; ///< every tool has a name that can be used to identify it. + virtual void SetToolName(const std::string _arg); ///< Sets the name of the tool + virtual void SetToolName(const char* _arg); ///< Sets the name of the tool + + Point3D GetToolTip() const; ///< returns the tool tip in tool coordinates, which where set by SetToolTip + virtual void SetToolTip(Point3D toolTipPosition, Quaternion orientation, ScalarType eps=0.0); ///< defines a tool tip for this tool in tool coordinates. GetPosition() and GetOrientation() return the data of the tool tip if it is defined. By default no tooltip is defined. + virtual bool IsTooltipSet() const; ///< returns true if a tooltip is set, false if not + Quaternion GetToolTipOrientation() const; ///< returns the tool tip orientation in tool coordinates, which where set by SetToolTip + + virtual void GetPosition(Point3D& position) const; ///< returns the current position of the tool as an array of three floats (in the tracking device coordinate system) + virtual void SetPosition(Point3D position); ///< sets the position + + virtual void GetOrientation(Quaternion& orientation) const; ///< returns the current orientation of the tool as a quaternion in a mitk::Point4D (in the tracking device coordinate system) + virtual void SetOrientation(Quaternion orientation); ///< sets the orientation as a quaternion + + virtual bool Enable(); ///< enables the tool, so that it will be tracked + virtual bool Disable(); ///< disables the tool, so that it will not be tracked anymore + virtual bool IsEnabled() const; ///< returns whether the tool is enabled or disabled + + virtual void SetDataValid(bool _arg); ///< sets if the tracking data (position & Orientation) is valid + virtual bool IsDataValid() const; ///< returns true if the current position data is valid (no error during tracking, tracking error below threshold, ...) + + virtual float GetTrackingError() const; ///< returns one value that corresponds to the overall tracking error. + virtual void SetTrackingError(float error); ///< sets the tracking error + + virtual const char* GetErrorMessage() const; ///< if the data is not valid, ErrorMessage should contain a string explaining why it is invalid (the Set-method should be implemented in subclasses, it should not be accessible by the user) + virtual void SetErrorMessage(const char* _arg); ///< sets the error message + + itkSetMacro(IGTTimeStamp, double) ///< Sets the IGT timestamp of the tracking tool object (time in milliseconds) + itkGetConstMacro(IGTTimeStamp, double) ///< Gets the IGT timestamp of the tracking tool object (time in milliseconds). Returns 0 if the timestamp was not set. protected: + itkFactorylessNewMacro(Self) + itkCloneMacro(Self) TrackingTool(); virtual ~TrackingTool(); + std::string m_ToolName; ///< every tool has a name that can be used to identify it. std::string m_ErrorMessage; ///< if a tool is invalid, this member should contain a human readable explanation of why it is invalid double m_IGTTimeStamp; ///< contains the time at which the tracking data was recorded itk::FastMutexLock::Pointer m_MyMutex; ///< mutex to control concurrent access to the tool + + Point3D m_Position; ///< holds the position of the tool + Quaternion m_Orientation; ///< holds the orientation of the tool + float m_TrackingError; ///< holds the tracking error of the tool + bool m_Enabled; ///< if true, tool is enabled and should receive tracking updates from the tracking device + bool m_DataValid; ///< if true, data in m_Position and m_Orientation is valid, e.g. true tracking data + Point3D m_ToolTip; + Quaternion m_ToolTipRotation; + bool m_ToolTipSet; }; } // namespace mitk #endif /* MITKTRACKINGTOOL_H_HEADER_INCLUDED_ */ diff --git a/Modules/IGT/TrackingDevices/mitkVirtualTrackingTool.cpp b/Modules/IGT/TrackingDevices/mitkVirtualTrackingTool.cpp index 3eb34d1e4a..6f4ba7928d 100644 --- a/Modules/IGT/TrackingDevices/mitkVirtualTrackingTool.cpp +++ b/Modules/IGT/TrackingDevices/mitkVirtualTrackingTool.cpp @@ -1,30 +1,29 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkVirtualTrackingTool.h" #include typedef itk::MutexLockHolder MutexLockHolder; mitk::VirtualTrackingTool::VirtualTrackingTool() -: InternalTrackingTool(), m_Spline(nullptr), m_SplineLength(0.0), m_Velocity(0.1) +: TrackingTool(), m_Spline(SplineType::New()), m_SplineLength(0.0), m_Velocity(0.1) { - m_Spline = SplineType::New(); } mitk::VirtualTrackingTool::~VirtualTrackingTool() { } diff --git a/Modules/IGT/TrackingDevices/mitkVirtualTrackingTool.h b/Modules/IGT/TrackingDevices/mitkVirtualTrackingTool.h index 526a4b859e..6b7fcc8cb0 100644 --- a/Modules/IGT/TrackingDevices/mitkVirtualTrackingTool.h +++ b/Modules/IGT/TrackingDevices/mitkVirtualTrackingTool.h @@ -1,67 +1,67 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef MITKVirtualTrackingTool_H_HEADER_INCLUDED_ #define MITKVirtualTrackingTool_H_HEADER_INCLUDED_ -#include +#include #include #include #include #include namespace mitk { /**Documentation * \brief implements TrackingTool interface * * This class is a complete TrackingTool implementation. It can either be used directly by * TrackingDevices, or be subclassed for more specific implementations. * mitk::MicroBirdTrackingDevice uses this class to manage its tools. Other tracking devices * uses specialized versions of this class (e.g. mitk::NDITrackingTool) * * \ingroup IGT */ - class MITKIGT_EXPORT VirtualTrackingTool : public InternalTrackingTool + class MITKIGT_EXPORT VirtualTrackingTool : public TrackingTool { public: - mitkClassMacro(VirtualTrackingTool, InternalTrackingTool); + mitkClassMacro(VirtualTrackingTool, TrackingTool); friend class VirtualTrackingDevice; itkFactorylessNewMacro(Self) typedef itk::NonUniformBSpline<3> SplineType; ///< spline type used for tool path interpolation itkGetMacro(SplineLength, mitk::ScalarType); itkSetMacro(SplineLength, mitk::ScalarType); itkGetMacro(Velocity, mitk::ScalarType); itkSetMacro(Velocity, mitk::ScalarType); itkGetObjectMacro(Spline, SplineType); protected: itkCloneMacro(Self) VirtualTrackingTool(); virtual ~VirtualTrackingTool(); SplineType::Pointer m_Spline; mitk::ScalarType m_SplineLength; mitk::ScalarType m_Velocity; }; } // namespace mitk #endif /* MITKVirtualTrackingTool_H_HEADER_INCLUDED_ */ diff --git a/Modules/IGT/Tutorial/mitkIGTTutorialStep1.cpp b/Modules/IGT/Tutorial/mitkIGTTutorialStep1.cpp index bb644e6d43..c8cad1f310 100644 --- a/Modules/IGT/Tutorial/mitkIGTTutorialStep1.cpp +++ b/Modules/IGT/Tutorial/mitkIGTTutorialStep1.cpp @@ -1,204 +1,204 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include -#include +#include #include #include #include #include "mitkNavigationDataDisplacementFilter.h" #include #include #include //##Documentation //## \brief A small console tutorial about MITK-IGT int main(int /*argc*/, char* /*argv*/[]) { //The next line starts a snippet to display this code in the documentation. If you don't revise the documentation, don't remove it! //! [What we will do] //************************************************************************* // What we will do... //************************************************************************* //In this tutorial we build up a small navigation pipeline with a virtual tracking device //which produce random positions and orientation so no additional hardware is required. // //The source of the pipeline is a TrackingDeviceSource object. This we connect to a simple //filter which just displaces the positions with an offset. After that we use a recorder //to store this new positions and other information to disc in a XML file. After that, we use //another source (NavigationDataPlayer) to replay the recorded data. //! [What we will do] //! [Part I Basic 1] //************************************************************************* // Part I: Basic initialization of the source and tracking device //************************************************************************* //First of all create a tracking device object and two tools for this "device". //Here we take the VirtualTrackingDevice. This is not a real tracking device it just delivers random //positions and orientations. You can use other/real tracking devices if you replace the following //code with different tracking devices, e.g. mitk::NDITrackingDevice. The tools represent the //sensors of the tracking device. The TrackingDevice fills the tools with data. std::cout << "Generating TrackingDevice ..." << std::endl; mitk::VirtualTrackingDevice::Pointer tracker = mitk::VirtualTrackingDevice::New(); tracker->AddTool("tool1"); tracker->AddTool("tool2"); //! [Part I Basic 1] //! [Part I Basic 2] //The tracking device object is used for the physical connection to the device. To use the //data inside of our tracking pipeline we need a source. This source encapsulate the tracking device //and provides objects of the type mitk::NavigationData as output. The NavigationData objects stores //position, orientation, if the data is valid or not and special error informations in a covariance //matrix. // //Typically the start of our pipeline is a TrackingDeviceSource. To work correct we have to set a //TrackingDevice object. Attention you have to set the tools before you set the whole TrackingDevice //object to the TrackingDeviceSource because the source need to know how many outputs should be //generated. std::cout << "Generating Source ..." << std::endl; mitk::TrackingDeviceSource::Pointer source = mitk::TrackingDeviceSource::New(); source->SetTrackingDevice(tracker); //here we set the device for the pipeline source source->Connect(); //here we connect to the tracking system //Note we do not call this on the TrackingDevice object source->StartTracking(); //start the tracking //Now the source generates outputs. //! [Part I Basic 2] //! [Part II] //************************************************************************* // Part II: Create a NavigationDataToNavigationDataFilter //************************************************************************* //The next thing we do is using a NavigationDataToNavigationDataFilter. One of these filter is the //very simple NavigationDataDisplacementFilter. This filter just changes the positions of the input //NavigationData objects with an offset for each direction (X,Y,Z). The input of this filter is the //source and the output of this filter is the "displaced" input. std::cout << "Generating DisplacementFilter ..." << std::endl; mitk::NavigationDataDisplacementFilter::Pointer displacer = mitk::NavigationDataDisplacementFilter::New(); mitk::Vector3D offset; mitk::FillVector3D(offset, 10.0, 100.0, 1.0); //initialize the offset displacer->SetOffset(offset); //now set the offset in the NavigationDataDisplacementFilter object //Connect the two filters. You can use the ConnectTo method to automatically connect all outputs from one filter // to inputs from another filter. displacer->ConnectTo(source.GetPointer()); // Alternatively, you can manually connect inputs and outputs. // The code below shows what the ConnectTo Methods does internally: // //for (unsigned int i = 0; i < source->GetNumberOfOutputs(); i++) //{ // displacer->SetInput(i, source->GetOutput(i)); //here we connect to the displacement filter //} //! [Part II] //! [Part III: Record the data with the NavigationDataRecorder] //************************************************************************* // Part III: Record the data with the NavigationDataRecorder //************************************************************************* //The next part of our pipeline is the recorder. The input of the recorder is the output of the displacement filter //and the output is a XML file with the name "Test Output-0.xml", which is written with a NavigationDataSetWriter. std::cout << "Start Recording ..." << std::endl; //we need the stringstream for building up our filename std::stringstream filename; //the .xml extension and an counter is NOT added automatically anymore -- that was the case in an earlier version filename << itksys::SystemTools::GetCurrentWorkingDirectory() << "/Test Output-0.xml"; std::cout << "Record to file: " << filename.str() << " ..." << std::endl; mitk::NavigationDataRecorder::Pointer recorder = mitk::NavigationDataRecorder::New(); //now the output of the displacer object is connected to the recorder object recorder->ConnectTo(displacer); recorder->StartRecording(); //after finishing the settings you can start the recording mechanism //now every update of the recorder stores one line into the file for //each added NavigationData for (unsigned int x = 0; x < 100; x++) //write 100 datasets { recorder->Update(); //the update causes one line in the XML file for every tool //in this case two lines itksys::SystemTools::Delay(100); //sleep a little } recorder->StopRecording(); //to get proper XML files you should stop recording //if your application crashes during recording no data //will be lost it is all stored to disc //The IO-System needs a filename. Otherwise the output //is redirected to the console. See MITK-Concepts page for more details on IO in MITK mitk::IOUtil::Save(recorder->GetNavigationDataSet(), filename.str()); //! [Part III: Record the data with the NavigationDataRecorder] //! [Part IV: Play the data with the NavigationDataPlayer] //************************************************************************* // Part IV: Play the data with the NavigationDataSequentialPlayer //************************************************************************* //The recording is finished now so now we can play the data. The NavigationDataPlayer is similar //to the TrackingDevice source. It also derives from NavigationDataSource. So you can use a player //instead of a TrackingDeviceSource. The input of this player is a NavigationDataSet, which we //read with a NavigationDataReader. std::cout << "Start playing from file: " << filename.str() << " ..." << std::endl; mitk::NavigationDataSequentialPlayer::Pointer player = mitk::NavigationDataSequentialPlayer::New(); mitk::NavigationDataSet::Pointer naviDataSet = dynamic_cast (mitk::IOUtil::Load(filename.str())[0].GetPointer()); player->SetNavigationDataSet(naviDataSet); //From now on, the player provides NavigationDatas in a sequential order. The next position is given, as soon as "update" is called, so this player is not in real time. //If you need the correct time of your tracking Data, use the NavigationDataPlayer instead and call "StartPlaying" and "StopPlaying". //this connects the outputs of the player to the NavigationData objects mitk::NavigationData::Pointer nd = player->GetOutput(); mitk::NavigationData::Pointer nd2 = player->GetOutput(1); for (unsigned int x = 0; x < 100; x++) { if (nd.IsNotNull()) //check if the output is not null { //With this call, we go to the next recorded data set. player->GoToNextSnapshot(); MITK_INFO << "Time Step " << x; MITK_INFO << "Tool 1:" << nd->GetPosition(); MITK_INFO << "Tool 2:" << nd2->GetPosition(); itksys::SystemTools::Delay(100); //sleep a little like in the recorder part, just for nice reading... } } itksys::SystemTools::Delay(2000); std::cout << "finished" << std::endl; //! [Part IV: Play the data with the NavigationDataPlayer] } diff --git a/Modules/IGT/files.cmake b/Modules/IGT/files.cmake index f9b80c1194..1f3256abb0 100644 --- a/Modules/IGT/files.cmake +++ b/Modules/IGT/files.cmake @@ -1,115 +1,114 @@ set(CPP_FILES TestingHelper/mitkNavigationToolStorageTestHelper.cpp Algorithms/mitkNavigationDataDelayFilter.cpp Algorithms/mitkNavigationDataDisplacementFilter.cpp Algorithms/mitkNavigationDataEvaluationFilter.cpp Algorithms/mitkNavigationDataLandmarkTransformFilter.cpp Algorithms/mitkNavigationDataPassThroughFilter.cpp Algorithms/mitkNavigationDataReferenceTransformFilter.cpp Algorithms/mitkNavigationDataSmoothingFilter.cpp Algorithms/mitkNavigationDataToMessageFilter.cpp Algorithms/mitkNavigationDataToNavigationDataFilter.cpp Algorithms/mitkNavigationDataToPointSetFilter.cpp Algorithms/mitkNavigationDataTransformFilter.cpp Algorithms/mitkNavigationDataToIGTLMessageFilter.cpp Algorithms/mitkIGTLMessageToNavigationDataFilter.cpp Algorithms/mitkNeedleProjectionFilter.cpp Algorithms/mitkPivotCalibration.cpp Common/mitkIGTTimeStamp.cpp Common/mitkSerialCommunication.cpp DataManagement/mitkNavigationDataSource.cpp DataManagement/mitkNavigationTool.cpp DataManagement/mitkNavigationToolStorage.cpp DataManagement/mitkTrackingDeviceSourceConfigurator.cpp DataManagement/mitkTrackingDeviceSource.cpp DataManagement/mitkTrackingDeviceTypeCollection.cpp ExceptionHandling/mitkIGTException.cpp ExceptionHandling/mitkIGTHardwareException.cpp ExceptionHandling/mitkIGTIOException.cpp IO/mitkNavigationDataPlayer.cpp IO/mitkNavigationDataPlayerBase.cpp IO/mitkNavigationDataRecorder.cpp IO/mitkNavigationDataRecorderDeprecated.cpp IO/mitkNavigationDataSequentialPlayer.cpp IO/mitkNavigationToolReader.cpp IO/mitkNavigationToolStorageSerializer.cpp IO/mitkNavigationToolStorageDeserializer.cpp IO/mitkNavigationToolWriter.cpp IO/mitkNavigationDataReaderInterface.cpp Rendering/mitkCameraVisualization.cpp Rendering/mitkNavigationDataObjectVisualizationFilter.cpp Rendering/mitkNavigationDataSliceVisualization.cpp TrackingDevices/mitkClaronTool.cpp TrackingDevices/mitkClaronTrackingDevice.cpp - TrackingDevices/mitkInternalTrackingTool.cpp TrackingDevices/mitkNDIPassiveTool.cpp TrackingDevices/mitkNDIProtocol.cpp TrackingDevices/mitkNDITrackingDevice.cpp TrackingDevices/mitkTrackingDevice.cpp TrackingDevices/mitkTrackingTool.cpp TrackingDevices/mitkTrackingVolumeGenerator.cpp TrackingDevices/mitkVirtualTrackingDevice.cpp TrackingDevices/mitkVirtualTrackingTool.cpp TrackingDevices/mitkOptitrackErrorMessages.cpp TrackingDevices/mitkOptitrackTrackingDevice.cpp TrackingDevices/mitkOptitrackTrackingTool.cpp TrackingDevices/mitkOpenIGTLinkTrackingDevice.cpp TrackingDevices/mitkOpenIGTLinkTrackingTool.cpp TrackingDevices/mitkNDIAuroraTypeInformation.cpp TrackingDevices/mitkNDIPolarisTypeInformation.cpp TrackingDevices/mitkNPOptitrackTrackingTypeInformation.cpp TrackingDevices/mitkVirtualTrackerTypeInformation.cpp TrackingDevices/mitkMicronTrackerTypeInformation.cpp TrackingDevices/mitkOpenIGTLinkTypeInformation.cpp TrackingDevices/mitkUnspecifiedTrackingTypeInformation.cpp # TrackingDevices/mitkPolhemusTrackingDevice.cpp # TrackingDevices/mitkPolhemusTool.cpp # TrackingDevices/mitkPolhemusTrackerTypeInformation.cpp ) set(H_FILES DataManagement/mitkTrackingDeviceTypeInformation.h Common/mitkTrackingTypes.h ) set(RESOURCE_FILES ClaronMicron.stl IntuitiveDaVinci.stl NDIAurora.stl NDIAurora_Dome.stl NDIAuroraCompactFG_Dome.stl NDIAuroraPlanarFG_Dome.stl NDIAuroraTabletopFG_Dome.stl NDIAuroraTabletopFG_Prototype_Dome.stl NDIPolarisOldModel.stl NDIPolarisSpectra.stl NDIPolarisSpectraExtendedPyramid.stl NDIPolarisVicra.stl ) if(MITK_USE_MICRON_TRACKER) set(CPP_FILES ${CPP_FILES} TrackingDevices/mitkClaronInterface.cpp) else() set(CPP_FILES ${CPP_FILES} TrackingDevices/mitkClaronInterfaceStub.cpp) endif(MITK_USE_MICRON_TRACKER) if(MITK_USE_MICROBIRD_TRACKER) set(CPP_FILES ${CPP_FILES} TrackingDevices/mitkMicroBirdTrackingDevice.cpp) endif(MITK_USE_MICROBIRD_TRACKER) if(MITK_USE_POLHEMUS_TRACKER) set(CPP_FILES ${CPP_FILES} TrackingDevices/mitkPolhemusInterface.cpp TrackingDevices/mitkPolhemusTrackingDevice.cpp TrackingDevices/mitkPolhemusTool.cpp TrackingDevices/mitkPolhemusTrackerTypeInformation.cpp ) endif(MITK_USE_POLHEMUS_TRACKER)