diff --git a/Modules/IGT/TrackingDevices/mitkPolhemusInterface.cpp b/Modules/IGT/TrackingDevices/mitkPolhemusInterface.cpp index 2da5ecf835..62bcb6d31c 100644 --- a/Modules/IGT/TrackingDevices/mitkPolhemusInterface.cpp +++ b/Modules/IGT/TrackingDevices/mitkPolhemusInterface.cpp @@ -1,168 +1,195 @@ /*=================================================================== 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 #define _USE_MATH_DEFINES #include BYTE MotionBuf[0x1FA400]; mitk::PolhemusInterface::PolhemusInterface() { + +} + +mitk::PolhemusInterface::~PolhemusInterface() +{ + +} +bool mitk::PolhemusInterface::InitializeDevice() +{ + m_pdiDev.Trace(TRUE, 7); + return true; +} + +bool mitk::PolhemusInterface::SetupDevice() +{ m_pdiDev.SetPnoBuffer(MotionBuf, 0x1FA400); m_pdiDev.SetMetric(true); //use cm instead of inches - /* some settings, not sure if we need them - m_pdiDev.Trace(TRUE, 7); + + m_pdiDev.StartPipeExport(); + CPDImdat pdiMDat; pdiMDat.Empty(); pdiMDat.Append(PDI_MODATA_FRAMECOUNT); pdiMDat.Append(PDI_MODATA_POS); pdiMDat.Append(PDI_MODATA_ORI); m_pdiDev.SetSDataList(-1, pdiMDat); - */ -} -mitk::PolhemusInterface::~PolhemusInterface() -{ + CPDIbiterr cBE; + m_pdiDev.GetBITErrs(cBE); + + TCHAR sz[100]; + cBE.Parse(sz, 100); + if (!(cBE.IsClear())) {m_pdiDev.ClearBITErrs();} + + return true; } bool mitk::PolhemusInterface::StartTracking() { - /* some setting / not sure if we need them LPCTSTR szWindowClass = _T("PDIconsoleWinClass"); HINSTANCE hInst = GetModuleHandle(0); HWND hwnd = CreateWindowEx( WS_EX_NOACTIVATE,//WS_EX_STATICEDGE, // szWindowClass, _T("MyWindowName"), WS_POPUP, 0, 0, 1, 1, HWND_MESSAGE, 0, hInst, 0); - */ + m_continousTracking = true; - return m_pdiDev.StartContPno(0); + return m_pdiDev.StartContPno(hwnd); } bool mitk::PolhemusInterface::StopTracking() { m_continousTracking = false; return true; } bool mitk::PolhemusInterface::Connect() { + if (!InitializeDevice()) { return false; } + if (m_pdiDev.CnxReady()) { return true; } + CPDIser pdiSer; + m_pdiDev.SetSerialIF(&pdiSer); ePiCommType eType = m_pdiDev.DiscoverCnx(); switch (eType) { case PI_CNX_USB: MITK_INFO << "USB Connection: " << m_pdiDev.GetLastResultStr(); break; case PI_CNX_SERIAL: MITK_INFO << "Serial Connection: " << m_pdiDev.GetLastResultStr(); break; default: MITK_INFO << "DiscoverCnx result: " << m_pdiDev.GetLastResultStr(); break; } + if (!SetupDevice()) { return false; } + return m_pdiDev.CnxReady(); } bool mitk::PolhemusInterface::Disconnect() { if (m_continousTracking) { m_continousTracking = false; if (!m_pdiDev.Disconnect()) return false; } return true; } std::vector mitk::PolhemusInterface::GetLastFrame() { PBYTE pBuf; DWORD dwSize; //read one frame if (!m_pdiDev.LastPnoPtr(pBuf, dwSize)) {MITK_WARN << m_pdiDev.GetLastResultStr();} std::vector returnValue = ParsePolhemusRawData(pBuf, dwSize); if (returnValue.empty()) { MITK_WARN << "Cannot parse data / no tools present"; } return returnValue; } unsigned int mitk::PolhemusInterface::GetNumberOfTools() { if (m_continousTracking) return GetLastFrame().size(); else return GetSingleFrame().size(); } std::vector mitk::PolhemusInterface::GetSingleFrame() { if (m_continousTracking) return std::vector(); PBYTE pBuf; DWORD dwSize; //read one frame if (!m_pdiDev.ReadSinglePnoBuf(pBuf, dwSize)) { MITK_WARN << m_pdiDev.GetLastResultStr(); } return ParsePolhemusRawData(pBuf, dwSize); } std::vector mitk::PolhemusInterface::ParsePolhemusRawData(PBYTE pBuf, DWORD dwSize) { std::vector returnValue; DWORD i = 0; while (i eulerQuat(rollAngle, elevationAngle, azimuthAngle); currentTrackingData.rot = eulerQuat; returnValue.push_back(currentTrackingData); i += shSize; } return returnValue; } diff --git a/Modules/IGT/TrackingDevices/mitkPolhemusInterface.h b/Modules/IGT/TrackingDevices/mitkPolhemusInterface.h index 86607dde45..c62698b746 100644 --- a/Modules/IGT/TrackingDevices/mitkPolhemusInterface.h +++ b/Modules/IGT/TrackingDevices/mitkPolhemusInterface.h @@ -1,108 +1,113 @@ /*=================================================================== 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 MITKPolhemusINTERFACE_H_HEADER_INCLUDED_ #define MITKPolhemusINTERFACE_H_HEADER_INCLUDED_ #include #include #include #include "mitkCommon.h" #include #include #include #include #include #include #include namespace mitk { /** Documentation: * \brief An object of this class represents the interface to Polhemus trackers. * \ingroup IGT */ class MITKIGT_EXPORT PolhemusInterface : public itk::Object { public: mitkClassMacroItkParent(PolhemusInterface,itk::Object); itkFactorylessNewMacro(Self); itkCloneMacro(Self); struct trackingData { mitk::Point3D pos; mitk::Quaternion rot; + BYTE id; }; /** * \brief Opens the connection to the device and makes it ready to track tools. * \return Returns true if there is a connection to the device and the device is ready to track tools, false if not. */ bool StartTracking(); /** * \brief Clears all resources. After this method have been called the system isn't ready to track any longer. * \return Returns true if the operation was succesful, false if not. */ bool StopTracking(); bool Connect(); bool Disconnect(); /** @return Returns a single frame. Only works if the tracking device is not in continous tracking mode. Returns an empty vector in case of an error.*/ std::vector GetSingleFrame(); /** @return Returns the last frame when the tracking device is in continous tracking mode. Returns an empty vector in case of an error.*/ std::vector GetLastFrame(); /** @return Returns the number of tools. Returns 0 if no information is avialable.*/ unsigned int GetNumberOfTools(); protected: /** * \brief standard constructor */ PolhemusInterface(); /** * \brief standard destructor */ ~PolhemusInterface(); /** Polhemus liberty/patriot tracker object*/ CPDIdev m_pdiDev; /** Parses polhemus raw data to a collection of tracking data of single tools. */ std::vector ParsePolhemusRawData(PBYTE pBuf, DWORD dwSize); unsigned int m_numberOfTools; bool m_continousTracking; + bool InitializeDevice(); + + bool SetupDevice(); + }; }//mitk #endif