├── .gitignore ├── PlantUML ├── logic.png ├── devices.png ├── logicEventHandle.png └── logicEventHandle.puml ├── doc └── IGSIO_doc.pptx ├── Examples ├── CMakeLists.txt └── qIgtlClient │ ├── main.cpp │ └── CMakeLists.txt ├── Resources └── Icons │ ├── LoadVolume.png │ └── OpenIGTLinkIF.png ├── GUI ├── qIGTLIOGuiUtilities.h ├── qIGTLIOGuiUtilities.cxx ├── DeviceWidgets │ ├── qIGTLIODeviceWidget.cxx │ ├── qIGTLIOGenericDeviceWidget.h │ ├── qIGTLIOStatusDeviceWidget.h │ ├── qIGTLIOStringDeviceWidget.h │ ├── qIGTLIOGenericDeviceWidget.cxx │ ├── qIGTLIODeviceWidget.h │ ├── qIGTLIODeviceWidgetFactory.h │ ├── qIGTLIODeviceWidgetFactory.cxx │ ├── qIGTLIOStatusDeviceWidget.cxx │ └── qIGTLIOStringDeviceWidget.cxx ├── qIGTLIOClientWidget.h ├── qIGTLIODevicePropertiesWidget.h ├── qIGTLIOLogicController.h ├── qIGTLIODeviceButtonsWidget.h ├── qIGTLIOClientWidget.cxx ├── qIGTLIODeviceAddWidget.h ├── qIGTLIOLogicController.cxx ├── qIGTLIOVtkConnectionMacro.h ├── qIGTLIODevicesWidget.h ├── qIGTLIOConnectorListWidget.h ├── qIGTLIOCommandWidget.h ├── qIGTLIODevicePropertiesWidget.cxx ├── qMRMLIGTLIOModel_p.h ├── qMRMLIGTLConnectorTreeView.h ├── vtkIGTLIONode.h ├── qIGTLIOConnectorPropertyWidget.h ├── qSlicerIGTLIONodeSelectorWidget.h ├── qIGTLIOConnectorModel.h ├── qIGTLIODevicesModel.h ├── qIGTLIODevicesWidget.cxx ├── qMRMLIGTLIOModel.h ├── qIGTLIODeviceButtonsWidget.cxx ├── qMRMLIGTLIOTreeView.h └── qIGTLIODeviceAddWidget.cxx ├── Testing ├── testClientServer.cxx ├── igtlioTestUtilities.h ├── igtlioFixture.h ├── testCommandMessageCodec.cxx ├── CMakeLists.txt ├── testReceiveImage.cxx ├── igtlioTestUtilities.cxx ├── testDeduceToolBasedOnName.cxx ├── testReceiveVideo.cxx └── testSendReceiveCommand.cxx ├── Tools ├── igtlioTranslator.h ├── igtlioTranslator.cxx ├── igtlioCommandMessageCodec.h ├── CMakeLists.txt └── igtlioCommandMessageCodec.cxx ├── Converter ├── igtlioUsSectorDefinitions.h ├── igtlioStringConverter.h ├── igtlioStatusConverter.h ├── igtlioConverterUtilities.h ├── igtlioPointConverter.h ├── igtlioBaseConverter.h ├── igtlioImageMetaConverter.h ├── igtlioLabelMetaConverter.h ├── igtlioCommandConverter.h ├── igtlioBaseConverter.cxx ├── igtlioStringConverter.cxx ├── igtlioStatusConverter.cxx ├── igtlioImageConverter.h ├── igtlioTransformConverter.h ├── igtlioTrackingDataConverter.h ├── igtlioPolyDataConverter.h ├── CMakeLists.txt ├── igtlioVideoConverter.h ├── igtlioLabelMetaConverter.cxx ├── igtlioPointConverter.cxx └── igtlioImageMetaConverter.cxx ├── Logic ├── igtlioObject.h ├── igtlioUtilities.cxx ├── igtlioObject.cxx ├── igtlioUtilities.h ├── igtlioDeviceFactory.h ├── igtlioCircularBuffer.h ├── CMakeLists.txt ├── igtlioDeviceFactory.cxx ├── igtlioCircularSectionBuffer.h └── igtlioLogic.h ├── OpenIGTLinkIOConfig.cmake.in ├── Devices ├── igtlioPointDevice.h ├── igtlioStatusDevice.h ├── igtlioImageMetaDevice.h ├── igtlioLabelMetaDevice.h ├── igtlioStringDevice.h ├── igtlioTrackingDataDevice.h ├── CMakeLists.txt ├── igtlioImageDevice.h ├── igtlioPolyDataDevice.h ├── igtlioTransformDevice.h ├── igtlioStringDevice.cxx ├── igtlioVideoDevice.h ├── igtlioStatusDevice.cxx └── igtlioPolyDataDevice.cxx └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | CMakeLists.txt.user 2 | -------------------------------------------------------------------------------- /PlantUML/logic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IGSIO/OpenIGTLinkIO/HEAD/PlantUML/logic.png -------------------------------------------------------------------------------- /doc/IGSIO_doc.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IGSIO/OpenIGTLinkIO/HEAD/doc/IGSIO_doc.pptx -------------------------------------------------------------------------------- /Examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if(${IGTLIO_USE_GUI}) 2 | add_subdirectory(qIgtlClient) 3 | endif() 4 | -------------------------------------------------------------------------------- /PlantUML/devices.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IGSIO/OpenIGTLinkIO/HEAD/PlantUML/devices.png -------------------------------------------------------------------------------- /PlantUML/logicEventHandle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IGSIO/OpenIGTLinkIO/HEAD/PlantUML/logicEventHandle.png -------------------------------------------------------------------------------- /Resources/Icons/LoadVolume.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IGSIO/OpenIGTLinkIO/HEAD/Resources/Icons/LoadVolume.png -------------------------------------------------------------------------------- /Resources/Icons/OpenIGTLinkIF.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IGSIO/OpenIGTLinkIO/HEAD/Resources/Icons/OpenIGTLinkIF.png -------------------------------------------------------------------------------- /GUI/qIGTLIOGuiUtilities.h: -------------------------------------------------------------------------------- 1 | #ifndef QIGTLIOGUIUTILITIES_H 2 | #define QIGTLIOGUIUTILITIES_H 3 | 4 | #include 5 | 6 | std::string convertDeviceNameToDisplay(std::string internal_name); 7 | std::string convertDisplayToDeviceName(std::string display_name); 8 | 9 | #endif // QIGTLIOGUIUTILITIES_H 10 | -------------------------------------------------------------------------------- /GUI/qIGTLIOGuiUtilities.cxx: -------------------------------------------------------------------------------- 1 | #include "qIGTLIOGuiUtilities.h" 2 | 3 | 4 | std::string convertDisplayToDeviceName(std::string display_name) 5 | { 6 | if (display_name=="") 7 | return ""; 8 | return display_name; 9 | } 10 | 11 | std::string convertDeviceNameToDisplay(std::string internal_name) 12 | { 13 | if (internal_name=="") 14 | return ""; 15 | return internal_name; 16 | } 17 | -------------------------------------------------------------------------------- /Testing/testClientServer.cxx: -------------------------------------------------------------------------------- 1 | #include 2 | #include "igtlioLogic.h" 3 | #include "igtlioConnector.h" 4 | #include "vtkTimerLog.h" 5 | #include 6 | #include "igtlioFixture.h" 7 | #include "igtlioTestUtilities.h" 8 | 9 | int main(int argc, char **argv) 10 | { 11 | igtlioClientServerFixture fixture; 12 | 13 | if (!fixture.ConnectClientToServer()) 14 | return TEST_FAILED; 15 | 16 | return TEST_SUCCESS; 17 | } 18 | -------------------------------------------------------------------------------- /Tools/igtlioTranslator.h: -------------------------------------------------------------------------------- 1 | #ifndef IGTLIOTRANSLATOR_H 2 | #define IGTLIOTRANSLATOR_H 3 | 4 | #include "vtkObject.h" 5 | 6 | #include "igtlioToolsExport.h" 7 | 8 | class OPENIGTLINKIO_TOOLS_EXPORT igtlioTranslator 9 | { 10 | public: 11 | igtlioTranslator(); 12 | 13 | std::string GetToolNameFromDeviceName(std::string device_name); 14 | std::string DetermineTypeBasedOnToolName(std::string tool_name); 15 | 16 | }; 17 | 18 | #endif // IGTLIOTRANSLATOR_H 19 | -------------------------------------------------------------------------------- /GUI/DeviceWidgets/qIGTLIODeviceWidget.cxx: -------------------------------------------------------------------------------- 1 | #include "qIGTLIODeviceWidget.h" 2 | 3 | #include "igtlioDevice.h" 4 | 5 | qIGTLIODeviceWidget::qIGTLIODeviceWidget(QWidget *parent) : QWidget(parent) 6 | { 7 | 8 | } 9 | 10 | void qIGTLIODeviceWidget::SetDevice(igtlioDevicePointer device) 11 | { 12 | qvtkReconnect(Device, device, vtkCommand::ModifiedEvent, 13 | this, SLOT(onDeviceModified())); 14 | 15 | Device = device; 16 | 17 | this->setupUi(); 18 | this->onDeviceModified(); 19 | } 20 | -------------------------------------------------------------------------------- /GUI/DeviceWidgets/qIGTLIOGenericDeviceWidget.h: -------------------------------------------------------------------------------- 1 | #ifndef QIGTLIOGENERICDEVICEWIDGET_H 2 | #define QIGTLIOGENERICDEVICEWIDGET_H 3 | 4 | #include "qIGTLIODeviceWidget.h" 5 | 6 | class QLineEdit; 7 | 8 | 9 | class OPENIGTLINKIO_GUI_EXPORT qIGTLIOGenericDeviceWidget : public qIGTLIODeviceWidget 10 | { 11 | public: 12 | qIGTLIOGenericDeviceWidget(QWidget* parent=NULL); 13 | 14 | protected: 15 | virtual void setupUi(); 16 | QLineEdit* DeviceNameEdit; 17 | QLineEdit* TimestampEdit; 18 | virtual void onDeviceModified(); 19 | }; 20 | 21 | 22 | #endif // QIGTLIOGENERICDEVICEWIDGET_H 23 | -------------------------------------------------------------------------------- /Examples/qIgtlClient/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "qIGTLIOClientWidget.h" 5 | #include "igtlioLogic.h" 6 | #include "qIGTLIOLogicController.h" 7 | 8 | int main(int argc, char** argv) 9 | { 10 | QApplication app(argc, argv); 11 | 12 | 13 | igtlioLogicPointer logic = igtlioLogicPointer::New(); 14 | qIGTLIOLogicController logicController; 15 | logicController.setLogic(logic); 16 | 17 | qIGTLIOClientWidget widget; 18 | widget.setLogic(logic); 19 | 20 | widget.setGeometry(0, 0, 859, 811); 21 | widget.show(); 22 | widget.activateWindow(); 23 | widget.raise(); 24 | 25 | int val = app.exec(); 26 | return val; 27 | } 28 | -------------------------------------------------------------------------------- /GUI/qIGTLIOClientWidget.h: -------------------------------------------------------------------------------- 1 | #ifndef QIGTLIOCLIENTWIDGET_H 2 | #define QIGTLIOCLIENTWIDGET_H 3 | 4 | #include 5 | 6 | // igtlio includes 7 | #include "igtlioGUIExport.h" 8 | 9 | #include 10 | 11 | typedef vtkSmartPointer igtlioLogicPointer; 12 | 13 | class OPENIGTLINKIO_GUI_EXPORT qIGTLIOClientWidget : public QWidget 14 | { 15 | Q_OBJECT 16 | public: 17 | qIGTLIOClientWidget(); 18 | void setLogic(igtlioLogicPointer logic); 19 | 20 | signals: 21 | 22 | public slots: 23 | private: 24 | igtlioLogicPointer Logic; 25 | 26 | class qIGTLIOConnectorListWidget* ConnectorListWidget; 27 | class qIGTLIODevicesWidget* DevicesWidget; 28 | class qIGTLIOCommandWidget* CommandWidget; 29 | }; 30 | 31 | #endif // QIGTLIOCLIENTWIDGET_H 32 | -------------------------------------------------------------------------------- /Converter/igtlioUsSectorDefinitions.h: -------------------------------------------------------------------------------- 1 | #ifndef IGTLIOUSSECTORDEFINITIONS_H 2 | #define IGTLIOUSSECTORDEFINITIONS_H 3 | 4 | 5 | // This defines the meta information tag names for OpenIGTLinkIO ultrasound messages 6 | #define IGTLIO_KEY_PROBE_TYPE "ProbeType" 7 | #define IGTLIO_KEY_ORIGIN "Origin" 8 | #define IGTLIO_KEY_ANGLES "Angles" 9 | #define IGTLIO_KEY_BOUNDING_BOX "BoundingBox" 10 | #define IGTLIO_KEY_DEPTHS "Depths" 11 | #define IGTLIO_KEY_LINEAR_WIDTH "LinearWidth" 12 | #define IGTLIO_KEY_SPACING_X "SpacingX" 13 | #define IGTLIO_KEY_SPACING_Y "SpacingY" 14 | #define IGTLIO_KEY_SPACING_Z "SpacingZ" 15 | #define IGTLIO_KEY_TIMESTAMP "ScannerTimestamp" 16 | 17 | enum IGTLIO_PROBE_TYPE 18 | { 19 | UNKNOWN, 20 | SECTOR, 21 | LINEAR, 22 | MECHANICAL 23 | }; 24 | 25 | #endif // IGTLIOUSSECTORDEFINITIONS_H 26 | -------------------------------------------------------------------------------- /GUI/qIGTLIODevicePropertiesWidget.h: -------------------------------------------------------------------------------- 1 | #ifndef QIGTLIODEVICEPROPERTIESWIDGET_H 2 | #define QIGTLIODEVICEPROPERTIESWIDGET_H 3 | 4 | #include 5 | #include 6 | 7 | // igtlio includes 8 | #include "igtlioGUIExport.h" 9 | 10 | class QVBoxLayout; 11 | class qIGTLIODevicesModelNode; 12 | class WidgetInGroupBoxClass; 13 | typedef vtkSmartPointer vtkIGTLIODeviceWidgetFactoryPointer; 14 | 15 | class OPENIGTLINKIO_GUI_EXPORT qIGTLIODevicePropertiesWidget : public QWidget 16 | { 17 | Q_OBJECT 18 | public: 19 | qIGTLIODevicePropertiesWidget(QWidget* parent=NULL); 20 | void SetNode(qIGTLIODevicesModelNode* node); 21 | 22 | private: 23 | // QVBoxLayout* mLayout; 24 | qIGTLIODevicesModelNode* Node; 25 | WidgetInGroupBoxClass* WidgetInGroupBox; 26 | vtkIGTLIODeviceWidgetFactoryPointer DeviceWidgetFactory; 27 | }; 28 | 29 | #endif // QIGTLIODEVICEPROPERTIESWIDGET_H 30 | -------------------------------------------------------------------------------- /Tools/igtlioTranslator.cxx: -------------------------------------------------------------------------------- 1 | #include "igtlioTranslator.h" 2 | 3 | std::string extractStringBeforeCharacter(std::string const& s, char character) 4 | { 5 | std::string::size_type pos = s.find(character); 6 | if (pos != std::string::npos) 7 | { 8 | return s.substr(0, pos); 9 | } 10 | else 11 | { 12 | return s; 13 | } 14 | } 15 | 16 | igtlioTranslator::igtlioTranslator() 17 | { 18 | } 19 | 20 | std::string igtlioTranslator::GetToolNameFromDeviceName(std::string device_name) 21 | { 22 | std::string retval = extractStringBeforeCharacter(device_name, '_'); 23 | return retval; 24 | } 25 | 26 | std::string igtlioTranslator::DetermineTypeBasedOnToolName(std::string tool_name) 27 | { 28 | if (tool_name.find("probe") != std::string::npos) { 29 | return "probe"; 30 | } 31 | if (tool_name.find("pointer") != std::string::npos) { 32 | return "tool"; 33 | } 34 | return "unknown"; 35 | } 36 | -------------------------------------------------------------------------------- /GUI/qIGTLIOLogicController.h: -------------------------------------------------------------------------------- 1 | #ifndef QIGTLIOLOGICCONTROLLER_H 2 | #define QIGTLIOLOGICCONTROLLER_H 3 | 4 | #include 5 | class QTimer; 6 | 7 | #include "qIGTLIOVtkConnectionMacro.h" 8 | 9 | #include 10 | 11 | typedef vtkSmartPointer igtlioLogicPointer; 12 | 13 | // igtlio includes 14 | #include "igtlioGUIExport.h" 15 | 16 | /// Adds a timer calling vtkIGTLIOLogic regularly. 17 | /// 18 | class OPENIGTLINKIO_GUI_EXPORT qIGTLIOLogicController : public QObject 19 | { 20 | Q_OBJECT 21 | IGTLIO_QVTK_OBJECT 22 | 23 | public: 24 | qIGTLIOLogicController(); 25 | void setLogic(igtlioLogicPointer logic); 26 | 27 | signals: 28 | 29 | public slots: 30 | private slots: 31 | void onConnectionsChanged(); 32 | private slots: 33 | void importDataAndEvents(); 34 | private: 35 | QTimer* ImportDataAndEventsTimer; 36 | igtlioLogicPointer Logic; 37 | 38 | }; 39 | 40 | #endif // QIGTLIOLOGICCONTROLLER_H 41 | -------------------------------------------------------------------------------- /Testing/igtlioTestUtilities.h: -------------------------------------------------------------------------------- 1 | #ifndef TESTUTILITIES_H 2 | #define TESTUTILITIES_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "igtlioImageDevice.h" 9 | 10 | 11 | #define GenerateErrorIf( condition, errorMessage ) if( condition ) { std::cerr << errorMessage << std::endl; return 1; } 12 | #define TEST_FAILED 1; 13 | #define TEST_SUCCESS 0; 14 | 15 | vtkSmartPointer igtlioCreateTestTransform(); 16 | vtkSmartPointer igtlioCreateTestImage(); 17 | 18 | bool igtlioContains(std::vector input, int value, int count); 19 | bool igtlioCompare(vtkSmartPointer a, vtkSmartPointer b); 20 | bool igtlioCompare(vtkSmartPointer a, vtkSmartPointer b); 21 | bool igtlioCompare(igtlioImageDevicePointer a, igtlioImageDevicePointer b); 22 | 23 | std::string igtlioBoolToString(bool b); 24 | 25 | #endif // TESTUTILITIES_H 26 | -------------------------------------------------------------------------------- /GUI/qIGTLIODeviceButtonsWidget.h: -------------------------------------------------------------------------------- 1 | #ifndef QIGTLIODEVICEBUTTONSWIDGET_H 2 | #define QIGTLIODEVICEBUTTONSWIDGET_H 3 | 4 | #include 5 | 6 | // igtlio includes 7 | #include "igtlioGUIExport.h" 8 | 9 | class qIGTLIODevicesModelNode; 10 | class qIGTLIODevicesModel; 11 | class QItemSelectionModel; 12 | #include 13 | #include 14 | 15 | typedef vtkSmartPointer igtlioLogicPointer; 16 | 17 | class OPENIGTLINKIO_GUI_EXPORT qIGTLIODeviceButtonsWidget : public QWidget 18 | { 19 | Q_OBJECT 20 | public: 21 | qIGTLIODeviceButtonsWidget(); 22 | void setLogic(igtlioLogicPointer logic); 23 | void setModel(qIGTLIODevicesModel* model); 24 | 25 | private slots: 26 | void onCurrentConnectorChanged(); 27 | void onActionClicked(); 28 | 29 | private: 30 | igtlioLogicPointer Logic; 31 | QPointer DevicesModel; 32 | QList Actions; 33 | 34 | qIGTLIODevicesModelNode* getSelectedNode(); 35 | }; 36 | 37 | #endif // QIGTLIODEVICEBUTTONSWIDGET_H 38 | -------------------------------------------------------------------------------- /Converter/igtlioStringConverter.h: -------------------------------------------------------------------------------- 1 | #ifndef STRINGCONVERTER_H 2 | #define STRINGCONVERTER_H 3 | 4 | #include "igtlioConverterExport.h" 5 | 6 | #include 7 | #include "igtlioBaseConverter.h" 8 | 9 | class OPENIGTLINKIO_CONVERTER_EXPORT igtlioStringConverter : public igtlioBaseConverter 10 | { 11 | public: 12 | /** 13 | * Content of STRING message. 14 | */ 15 | struct ContentData 16 | { 17 | unsigned int encoding; 18 | std::string string_msg; 19 | }; 20 | 21 | static const char* GetIGTLName() { return GetIGTLTypeName(); } 22 | static const char* GetIGTLTypeName() { return "STRING"; } 23 | 24 | static int fromIGTL(igtl::MessageBase::Pointer source, HeaderData* header, ContentData* content, bool checkCRC, igtl::MessageBase::MetaDataMap& outMetaInfo); 25 | static int toIGTL(const HeaderData& header, const ContentData& source, igtl::StringMessage::Pointer* dest, igtl::MessageBase::MetaDataMap metaInfo = igtl::MessageBase::MetaDataMap()); 26 | 27 | }; 28 | 29 | #endif // STRINGCONVERTER_H 30 | -------------------------------------------------------------------------------- /GUI/qIGTLIOClientWidget.cxx: -------------------------------------------------------------------------------- 1 | #include "qIGTLIOClientWidget.h" 2 | 3 | #include 4 | #include 5 | #include "qIGTLIOConnectorListWidget.h" 6 | #include "qIGTLIODevicesWidget.h" 7 | #include "qIGTLIOCommandWidget.h" 8 | #include "igtlioLogic.h" 9 | 10 | qIGTLIOClientWidget::qIGTLIOClientWidget() 11 | { 12 | QVBoxLayout* layout = new QVBoxLayout(this); 13 | 14 | QSplitter* splitter = new QSplitter(this); 15 | // splitter->setOrientation(Qt::Vertical); 16 | layout->addWidget(splitter); 17 | 18 | ConnectorListWidget = new qIGTLIOConnectorListWidget; 19 | splitter->addWidget(ConnectorListWidget); 20 | 21 | DevicesWidget = new qIGTLIODevicesWidget; 22 | splitter->addWidget(DevicesWidget); 23 | 24 | CommandWidget = new qIGTLIOCommandWidget; 25 | splitter->addWidget(CommandWidget); 26 | } 27 | 28 | void qIGTLIOClientWidget::setLogic(igtlioLogicPointer logic) 29 | { 30 | this->Logic = logic; 31 | ConnectorListWidget->setLogic(Logic); 32 | DevicesWidget->setLogic(Logic); 33 | CommandWidget->setLogic(Logic); 34 | } 35 | 36 | 37 | -------------------------------------------------------------------------------- /Converter/igtlioStatusConverter.h: -------------------------------------------------------------------------------- 1 | #ifndef IGTLIOSTATUSCONVERTER_H 2 | #define IGTLIOSTATUSCONVERTER_H 3 | 4 | #include "igtlioConverterExport.h" 5 | 6 | #include 7 | #include "igtlioBaseConverter.h" 8 | 9 | class OPENIGTLINKIO_CONVERTER_EXPORT igtlioStatusConverter : public igtlioBaseConverter 10 | { 11 | public: 12 | /** 13 | * Content of STATUS message. 14 | */ 15 | struct ContentData 16 | { 17 | int code; 18 | int subcode; 19 | std::string errorname; 20 | std::string statusstring; 21 | }; 22 | 23 | static const char* GetIGTLName() { return GetIGTLTypeName(); } 24 | static const char* GetIGTLTypeName() { return "STATUS"; } 25 | 26 | static int fromIGTL(igtl::MessageBase::Pointer source, HeaderData* header, ContentData* content, bool checkCRC, igtl::MessageBase::MetaDataMap& outMetaInfo); 27 | static int toIGTL(const HeaderData& header, const ContentData& source, igtl::StatusMessage::Pointer* dest, igtl::MessageBase::MetaDataMap metaInfo = igtl::MessageBase::MetaDataMap()); 28 | 29 | }; 30 | 31 | #endif // IGTLIOSTATUSCONVERTER_H 32 | -------------------------------------------------------------------------------- /Logic/igtlioObject.h: -------------------------------------------------------------------------------- 1 | /*=auto========================================================================= 2 | 3 | Portions (c) Copyright 2009 Brigham and Women's Hospital (BWH) All Rights Reserved. 4 | 5 | See Doc/copyright/copyright.txt 6 | or http://www.slicer.org/copyright/copyright.txt for details. 7 | 8 | =========================================================================auto=*/ 9 | #ifndef IGTLIOOBJECT_H 10 | #define IGTLIOOBJECT_H 11 | 12 | #include "vtkObject.h" 13 | 14 | // IGTLIO includes 15 | #include "igtlioLogicExport.h" 16 | 17 | /// 18 | /// Extracted from the Slicer/MRML class vtkMRMLAbstractLogic 19 | /// 20 | class OPENIGTLINKIO_LOGIC_EXPORT vtkIGTLIOObject : public vtkObject 21 | { 22 | typedef vtkObject Superclass; 23 | public: 24 | int InvokePendingModifiedEvent(); 25 | void Modified(); 26 | void SetDisableModifiedEvent(bool onOff); 27 | bool GetDisableModifiedEvent() const; 28 | protected: 29 | vtkIGTLIOObject(); 30 | 31 | private: 32 | bool DisableModifiedEvent; 33 | int ModifiedEventPending; 34 | }; 35 | 36 | #endif 37 | 38 | -------------------------------------------------------------------------------- /OpenIGTLinkIOConfig.cmake.in: -------------------------------------------------------------------------------- 1 | if(NOT OpenIGTLink_FOUND) 2 | set(OpenIGTLink_DIR "@OpenIGTLink_DIR@") 3 | find_package(OpenIGTLink REQUIRED NO_MODULE) 4 | else() 5 | if(NOT "@OpenIGTLink_VERSION_MAJOR@.@OpenIGTLink_VERSION_MINOR@.@OpenIGTLink_VERSION_PATCH@" VERSION_EQUAL "${OpenIGTLink_VERSION_MAJOR}.${OpenIGTLink_VERSION_MINOR}.${OpenIGTLink_VERSION_PATCH}") 6 | message(SEND_ERROR "Different versions in OpenIGTLinkIO (@OpenIGTLink_VERSION_MAJOR@.@OpenIGTLink_VERSION_MINOR@.@OpenIGTLink_VERSION_PATCH@) and referencing project (${OpenIGTLink_VERSION_MAJOR}.${OpenIGTLink_VERSION_MINOR}.${OpenIGTLink_VERSION_PATCH}). Issues may arise.") 7 | endif() 8 | endif() 9 | 10 | if(EXISTS ${OpenIGTLink_USE_FILE}) 11 | include(${OpenIGTLink_USE_FILE}) 12 | endif() 13 | 14 | @OpenIGTLinkIO_CONFIG_CODE@ 15 | 16 | include("@OpenIGTLinkIO_LIBRARY_TARGETS_FILE@") 17 | 18 | # Enable support for old style include/linking 19 | # It is highly recommended to link to target names, thus 20 | # includes/linking are handled automatically 21 | SET(OpenIGTLinkIO_FOUND 1) 22 | SET(OpenIGTLinkIO_LIBRARIES "@OpenIGTLinkIO_LIBRARIES@") 23 | 24 | @OpenIGTLinkIO_Qt_CONFIG_CODE@ -------------------------------------------------------------------------------- /Testing/igtlioFixture.h: -------------------------------------------------------------------------------- 1 | #ifndef IGTLIOFIXTURE_H 2 | #define IGTLIOFIXTURE_H 3 | 4 | 5 | #include 6 | #include "igtlioLogic.h" 7 | #include "igtlioConnector.h" 8 | #include "vtkTimerLog.h" 9 | #include "igtlioImageDevice.h" 10 | #include "igtlioTranslator.h" 11 | 12 | class vtkImageData; 13 | 14 | struct igtlioLogicFixture 15 | { 16 | igtlioLogicFixture(); 17 | 18 | void startClient(); 19 | void startServer(); 20 | 21 | igtlioLogicPointer Logic; 22 | igtlioConnectorPointer Connector; 23 | igtlioSessionPointer Session; 24 | 25 | vtkSmartPointer LogicEventCallback; 26 | std::vector ReceivedEvents; 27 | }; 28 | 29 | struct igtlioClientServerFixture 30 | { 31 | igtlioLogicFixture Server; 32 | igtlioLogicFixture Client; 33 | igtlioTranslator Translator; 34 | 35 | bool ConnectClientToServer(); 36 | bool LoopUntilEventDetected(igtlioLogicFixture *logic, int eventId, int count=1); 37 | 38 | public: 39 | vtkSmartPointer CreateTestTransform(); 40 | vtkSmartPointer CreateTestImage(); 41 | int CreateTestFrame(vtkImageData* image ); 42 | }; 43 | 44 | 45 | #endif // IGTLIOFIXTURE_H 46 | -------------------------------------------------------------------------------- /GUI/qIGTLIODeviceAddWidget.h: -------------------------------------------------------------------------------- 1 | #ifndef QIGTLIODEVICEADDWIDGET_H 2 | #define QIGTLIODEVICEADDWIDGET_H 3 | 4 | #include 5 | 6 | // igtlio includes 7 | #include "igtlioGUIExport.h" 8 | 9 | class qIGTLIODevicesModelNode; 10 | class qIGTLIODevicesModel; 11 | class QItemSelectionModel; 12 | class QComboBox; 13 | class QLineEdit; 14 | 15 | #include 16 | #include 17 | 18 | typedef vtkSmartPointer igtlioLogicPointer; 19 | 20 | /// 21 | /// Widget for adding Devices manually. 22 | /// 23 | class OPENIGTLINKIO_GUI_EXPORT qIGTLIODeviceAddWidget : public QWidget 24 | { 25 | Q_OBJECT 26 | public: 27 | qIGTLIODeviceAddWidget(); 28 | void setLogic(igtlioLogicPointer logic); 29 | void setModel(qIGTLIODevicesModel* model); 30 | 31 | private slots: 32 | void onCurrentConnectorChanged(); 33 | void onAddDevice(); 34 | 35 | private: 36 | igtlioLogicPointer Logic; 37 | QPointer DevicesModel; 38 | // QList Actions; 39 | 40 | QComboBox* mSelectDeviceType; 41 | QLineEdit* mDeviceName; 42 | QAction* mAddDeviceAction; 43 | 44 | qIGTLIODevicesModelNode* getSelectedNode(); 45 | }; 46 | 47 | #endif // QIGTLIODEVICEADDWIDGET_H 48 | -------------------------------------------------------------------------------- /Logic/igtlioUtilities.cxx: -------------------------------------------------------------------------------- 1 | #include "igtlioUtilities.h" 2 | #include "igtlioDevice.h" 3 | 4 | std::string igtlioDeviceKeyType::GetBaseTypeName() const 5 | { 6 | int pos = (int)type.find("_"); 7 | if (pos>=0) 8 | return type.substr(pos+1); 9 | return type; 10 | } 11 | 12 | igtlioDeviceKeyType igtlioDeviceKeyType::CreateDeviceKey(igtl::MessageBase::Pointer message) 13 | { 14 | if (!message) 15 | return igtlioDeviceKeyType(); 16 | return igtlioDeviceKeyType(message->GetDeviceType(), message->GetDeviceName()); 17 | } 18 | 19 | igtlioDeviceKeyType igtlioDeviceKeyType::CreateDeviceKey(igtlioDevicePointer device) 20 | { 21 | if (!device) 22 | return igtlioDeviceKeyType(); 23 | return igtlioDeviceKeyType(device->GetDeviceType(), device->GetDeviceName()); 24 | } 25 | 26 | 27 | bool operator<(const igtlioDeviceKeyType &lhs, const igtlioDeviceKeyType &rhs) 28 | { 29 | if (lhs.GetBaseTypeName() > rhs.GetBaseTypeName()) 30 | return false; 31 | if (lhs.GetBaseTypeName() < rhs.GetBaseTypeName()) 32 | return true; 33 | return (lhs.name < rhs.name); 34 | } 35 | 36 | bool operator==(const igtlioDeviceKeyType &lhs, const igtlioDeviceKeyType &rhs) 37 | { 38 | return (lhs.GetBaseTypeName()==rhs.GetBaseTypeName()) && 39 | (lhs.name==rhs.name); 40 | } 41 | -------------------------------------------------------------------------------- /Logic/igtlioObject.cxx: -------------------------------------------------------------------------------- 1 | #include "igtlioObject.h" 2 | 3 | vtkIGTLIOObject::vtkIGTLIOObject() 4 | { 5 | this->DisableModifiedEvent = false; 6 | this->ModifiedEventPending = 0; 7 | } 8 | 9 | //--------------------------------------------------------------------------- 10 | bool vtkIGTLIOObject::GetDisableModifiedEvent()const 11 | { 12 | return DisableModifiedEvent; 13 | } 14 | 15 | //--------------------------------------------------------------------------- 16 | void vtkIGTLIOObject::SetDisableModifiedEvent(bool onOff) 17 | { 18 | DisableModifiedEvent = onOff; 19 | } 20 | 21 | //--------------------------------------------------------------------------- 22 | void vtkIGTLIOObject::Modified() 23 | { 24 | if (this->GetDisableModifiedEvent()) 25 | { 26 | ++ModifiedEventPending; 27 | return; 28 | } 29 | this->Superclass::Modified(); 30 | } 31 | 32 | //--------------------------------------------------------------------------- 33 | int vtkIGTLIOObject::InvokePendingModifiedEvent () 34 | { 35 | if ( ModifiedEventPending ) 36 | { 37 | int oldModifiedEventPending = ModifiedEventPending; 38 | ModifiedEventPending = 0; 39 | this->Superclass::Modified(); 40 | return oldModifiedEventPending; 41 | } 42 | return ModifiedEventPending; 43 | } 44 | 45 | -------------------------------------------------------------------------------- /Converter/igtlioConverterUtilities.h: -------------------------------------------------------------------------------- 1 | /*========================================================================== 2 | 3 | Portions (c) Copyright 2018 IGSIO 4 | 5 | See Doc/copyright/copyright.txt 6 | or http://www.slicer.org/copyright/copyright.txt for details. 7 | 8 | Program: igtlio 9 | Module: $RCSfile: igtlioConverterUtilities.h,v $ 10 | Date: $Date: 2018/07/20 4:08:00 $ 11 | Version: $Revision: 1.0 $ 12 | 13 | =========================================================================auto=*/ 14 | 15 | #ifndef IGTLIOCONVERTERUTILITIES_H 16 | #define IGTLIOCONVERTERUTILITIES_H 17 | 18 | #include "igtlioConverterExport.h" 19 | 20 | // OpenIGTLink includes 21 | #include 22 | 23 | // VTK includes 24 | #include 25 | #include 26 | #include 27 | 28 | 29 | class OPENIGTLINKIO_CONVERTER_EXPORT igtlioConverterUtilities 30 | { 31 | public: 32 | 33 | static void VTKTransformToIGTLTransform(vtkSmartPointer ijk2ras, const int imageSize[3], const double spacing[3], igtl::Matrix4x4 &matrix); 34 | static void IGTLTransformToVTKTransform(const int imageSize[3], const float spacing[3], const igtl::Matrix4x4 matrix, vtkSmartPointer ijk2ras); 35 | 36 | }; 37 | 38 | #endif // IGTLIOCONVERTERUTILITIES_H 39 | -------------------------------------------------------------------------------- /GUI/DeviceWidgets/qIGTLIOStatusDeviceWidget.h: -------------------------------------------------------------------------------- 1 | #ifndef QIGTLIOSTATUSDEVICEWIDGET_H 2 | #define QIGTLIOSTATUSDEVICEWIDGET_H 3 | 4 | 5 | #include "qIGTLIODeviceWidget.h" 6 | 7 | class QLineEdit; 8 | class QGridLayout; 9 | 10 | class OPENIGTLINKIO_GUI_EXPORT vtkIGTLIOStatusDeviceWidgetCreator : public vtkIGTLIODeviceWidgetCreator 11 | { 12 | public: 13 | virtual qIGTLIODeviceWidget* Create(); 14 | virtual std::string GetDeviceType() const; 15 | 16 | static vtkIGTLIOStatusDeviceWidgetCreator *New(); 17 | vtkTypeMacro(vtkIGTLIOStatusDeviceWidgetCreator,vtkIGTLIODeviceWidgetCreator); 18 | 19 | }; 20 | //--------------------------------------------------------------------------- 21 | 22 | class OPENIGTLINKIO_GUI_EXPORT qIGTLIOStatusDeviceWidget : public qIGTLIODeviceWidget 23 | { 24 | Q_OBJECT 25 | 26 | public: 27 | qIGTLIOStatusDeviceWidget(QWidget* parent=NULL); 28 | 29 | protected: 30 | QLineEdit* DeviceNameEdit; 31 | QLineEdit* TimestampEdit; 32 | 33 | QLineEdit* CodeEdit; 34 | QLineEdit* SubCodeEdit; 35 | QLineEdit* ErrorNameEdit; 36 | QLineEdit* StatusStringEdit; 37 | 38 | virtual void setupUi(); 39 | virtual void onDeviceModified(); 40 | 41 | private slots: 42 | void AddCaptionedLineEdit(QGridLayout *layout, QLineEdit *edit, QString caption, int line); 43 | }; 44 | 45 | 46 | #endif // QIGTLIOSTATUSDEVICEWIDGET_H 47 | -------------------------------------------------------------------------------- /Tools/igtlioCommandMessageCodec.h: -------------------------------------------------------------------------------- 1 | #ifndef IGTLIOCOMMANDMESSAGECODEC_H 2 | #define IGTLIOCOMMANDMESSAGECODEC_H 3 | 4 | #include "igtlioToolsExport.h" 5 | #include 6 | #include 7 | #include 8 | 9 | class OPENIGTLINKIO_TOOLS_EXPORT igtlioCommandMessageCodec 10 | { 11 | 12 | public: 13 | 14 | igtlioCommandMessageCodec(); 15 | igtlioCommandMessageCodec(bool isReply); 16 | 17 | // Build the content of the command to send 18 | void SetResult( bool res ); 19 | void AddParameter( std::string paramName, std::string value ); 20 | void AddParameter( std::string paramName, double value ); 21 | std::string GetContent(); 22 | 23 | // Parse the content of a command received 24 | void SetContent( std::string content ); 25 | int GetNumberOfParameters() { return m_parameters.size(); } 26 | std::string GetParameterName( int index ) { return m_parameters[index].first; } 27 | std::string GetParameterValue( int index ) { return m_parameters[index].second; } 28 | bool IsReply() { return m_isReply; } 29 | bool GetResult(); 30 | std::string GetParameter( std::string paramName ); 31 | 32 | protected: 33 | 34 | typedef std::vector > ParamContainer; 35 | bool m_isReply; 36 | bool m_result; 37 | ParamContainer m_parameters; 38 | }; 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /GUI/DeviceWidgets/qIGTLIOStringDeviceWidget.h: -------------------------------------------------------------------------------- 1 | #ifndef QIGTLIOSTRINGDEVICEWIDGET_H 2 | #define QIGTLIOSTRINGDEVICEWIDGET_H 3 | 4 | 5 | #include "qIGTLIODeviceWidget.h" 6 | 7 | class QLineEdit; 8 | class QGridLayout; 9 | 10 | class OPENIGTLINKIO_GUI_EXPORT vtkIGTLIOStringDeviceWidgetCreator : public vtkIGTLIODeviceWidgetCreator 11 | { 12 | public: 13 | virtual qIGTLIODeviceWidget* Create(); 14 | virtual std::string GetDeviceType() const; 15 | 16 | static vtkIGTLIOStringDeviceWidgetCreator *New(); 17 | vtkTypeMacro(vtkIGTLIOStringDeviceWidgetCreator,vtkIGTLIODeviceWidgetCreator); 18 | 19 | }; 20 | //--------------------------------------------------------------------------- 21 | 22 | class OPENIGTLINKIO_GUI_EXPORT qIGTLIOStringDeviceWidget : public qIGTLIODeviceWidget 23 | { 24 | Q_OBJECT 25 | 26 | public: 27 | qIGTLIOStringDeviceWidget(QWidget* parent=NULL); 28 | 29 | protected: 30 | QLineEdit* DeviceNameEdit; 31 | QLineEdit* TimestampEdit; 32 | 33 | QLineEdit* EncodingEdit; 34 | QLineEdit* StringEdit; 35 | 36 | virtual void setupUi(); 37 | virtual void onDeviceModified(); 38 | 39 | private slots: 40 | void AddCaptionedLineEdit(QGridLayout *layout, QLineEdit *edit, QString caption, int line, bool read_only=true); 41 | void onGUIModified(); 42 | void blockGUI(bool on); 43 | }; 44 | 45 | 46 | #endif // QIGTLIOSTRINGDEVICEWIDGET_H 47 | -------------------------------------------------------------------------------- /GUI/qIGTLIOLogicController.cxx: -------------------------------------------------------------------------------- 1 | #include "qIGTLIOLogicController.h" 2 | #include 3 | #include "igtlioLogic.h" 4 | 5 | qIGTLIOLogicController::qIGTLIOLogicController() 6 | { 7 | ImportDataAndEventsTimer = new QTimer(this); 8 | ImportDataAndEventsTimer->setInterval(5); 9 | connect(ImportDataAndEventsTimer, SIGNAL(timeout()), 10 | this, SLOT(importDataAndEvents())); 11 | } 12 | 13 | void qIGTLIOLogicController::setLogic(igtlioLogicPointer logic) 14 | { 15 | foreach(int evendId, QList() 16 | << igtlioLogic::ConnectionAddedEvent 17 | << igtlioLogic::ConnectionAboutToBeRemovedEvent) 18 | { 19 | qvtkReconnect(this->Logic, logic, evendId, 20 | this, SLOT(onConnectionsChanged())); 21 | } 22 | 23 | this->Logic = logic; 24 | 25 | this->onConnectionsChanged(); 26 | } 27 | 28 | void qIGTLIOLogicController::onConnectionsChanged() 29 | { 30 | if (Logic->GetNumberOfConnectors() > 0) 31 | { 32 | if (!ImportDataAndEventsTimer->isActive()) 33 | ImportDataAndEventsTimer->start(); 34 | } 35 | else 36 | { 37 | ImportDataAndEventsTimer->stop(); 38 | } 39 | } 40 | 41 | //----------------------------------------------------------------------------- 42 | void qIGTLIOLogicController::importDataAndEvents() 43 | { 44 | if (Logic) 45 | { 46 | Logic->PeriodicProcess(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /GUI/DeviceWidgets/qIGTLIOGenericDeviceWidget.cxx: -------------------------------------------------------------------------------- 1 | #include "qIGTLIOGenericDeviceWidget.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "vtkCommand.h" 10 | 11 | #include "igtlioDevice.h" 12 | #include "qIGTLIOGuiUtilities.h" 13 | 14 | qIGTLIOGenericDeviceWidget::qIGTLIOGenericDeviceWidget(QWidget* parent) : qIGTLIODeviceWidget(parent) 15 | { 16 | 17 | } 18 | 19 | void qIGTLIOGenericDeviceWidget::setupUi() 20 | { 21 | QGridLayout* layout = new QGridLayout(this); 22 | 23 | layout->addWidget(new QLabel("device: "), 0, 0); 24 | DeviceNameEdit = new QLineEdit; 25 | DeviceNameEdit->setReadOnly(true); 26 | layout->addWidget(DeviceNameEdit, 0, 1); 27 | 28 | layout->addWidget(new QLabel("timestamp: "), 1, 0); 29 | TimestampEdit = new QLineEdit; 30 | TimestampEdit->setReadOnly(true); 31 | layout->addWidget(TimestampEdit, 1, 1); 32 | } 33 | 34 | void qIGTLIOGenericDeviceWidget::onDeviceModified() 35 | { 36 | QString text = (Device ? QString(convertDeviceNameToDisplay(Device->GetDeviceName()).c_str()) : "none"); 37 | DeviceNameEdit->setText(text); 38 | 39 | QDateTime timestamp = QDateTime::fromMSecsSinceEpoch(Device->GetTimestamp()*1000); 40 | //mTimestampEdit->setText(timestamp.toString(Qt::ISODate)); 41 | TimestampEdit->setText(timestamp.toString("hh:mm:ss.zzz")); 42 | } 43 | -------------------------------------------------------------------------------- /GUI/qIGTLIOVtkConnectionMacro.h: -------------------------------------------------------------------------------- 1 | #ifndef QIGTLIOVTKCONNECTIONMACRO_H 2 | #define QIGTLIOVTKCONNECTIONMACRO_H 3 | 4 | #include "vtkEventQtSlotConnect.h" 5 | 6 | #define IGTLIO_QVTK_OBJECT_RECONNECT_METHOD \ 7 | void qvtkReconnect( vtkObject* old_vtk_obj, vtkObject* vtk_obj, \ 8 | unsigned long vtk_event, const QObject* qt_obj, \ 9 | const char* qt_slot, float priority = 0.0, \ 10 | Qt::ConnectionType connectionType = Qt::AutoConnection) \ 11 | { \ 12 | Q_ASSERT( qt_obj ); \ 13 | if( old_vtk_obj ) \ 14 | MyQVTK.connectPtr->Disconnect( old_vtk_obj, vtk_event, qt_obj, qt_slot ); \ 15 | if( vtk_obj ) \ 16 | MyQVTK.connectPtr->Connect( vtk_obj, vtk_event, qt_obj, qt_slot, NULL, priority, connectionType ); \ 17 | } 18 | 19 | 20 | #define IGTLIO_QVTK_OBJECT \ 21 | protected: \ 22 | IGTLIO_QVTK_OBJECT_RECONNECT_METHOD \ 23 | private: \ 24 | class QVTKConnect \ 25 | { \ 26 | public: \ 27 | QVTKConnect() { connectPtr = vtkEventQtSlotConnect::New(); } \ 28 | ~QVTKConnect() { connectPtr->Delete(); } \ 29 | vtkEventQtSlotConnect * connectPtr; \ 30 | }; \ 31 | QVTKConnect MyQVTK; \ 32 | 33 | #endif // QIGTLIOVTKCONNECTIONMACRO_H 34 | -------------------------------------------------------------------------------- /GUI/DeviceWidgets/qIGTLIODeviceWidget.h: -------------------------------------------------------------------------------- 1 | #ifndef QIGTLIODEVICEWIDGET_H 2 | #define QIGTLIODEVICEWIDGET_H 3 | 4 | #include 5 | 6 | // igtlio includes 7 | #include "igtlioGUIExport.h" 8 | 9 | #include 10 | #include 11 | 12 | #include "qIGTLIOVtkConnectionMacro.h" 13 | 14 | typedef vtkSmartPointer igtlioDevicePointer; 15 | 16 | class qIGTLIODeviceWidget; 17 | 18 | class OPENIGTLINKIO_GUI_EXPORT vtkIGTLIODeviceWidgetCreator : public vtkObject 19 | { 20 | public: 21 | // Create an instance of the specific device widget, with the given device_id 22 | virtual qIGTLIODeviceWidget* Create() = 0; 23 | // Return the device_type this factory creates device widgets for. 24 | virtual std::string GetDeviceType() const = 0; 25 | 26 | vtkAbstractTypeMacro(vtkIGTLIODeviceWidgetCreator,vtkObject); 27 | }; 28 | //--------------------------------------------------------------------------- 29 | 30 | class OPENIGTLINKIO_GUI_EXPORT qIGTLIODeviceWidget : public QWidget 31 | { 32 | Q_OBJECT 33 | IGTLIO_QVTK_OBJECT 34 | public: 35 | qIGTLIODeviceWidget(QWidget* parent=NULL); 36 | virtual void SetDevice(igtlioDevicePointer device); 37 | 38 | protected: 39 | igtlioDevicePointer Device; 40 | 41 | virtual void setupUi() = 0; 42 | 43 | protected slots: 44 | virtual void onDeviceModified() = 0; 45 | }; 46 | 47 | 48 | #endif // QIGTLIODEVICEWIDGET_H 49 | -------------------------------------------------------------------------------- /Examples/qIgtlClient/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(igtlioQtClient) 2 | 3 | # ========================================================= 4 | # Reference Qt client implementation 5 | # ========================================================= 6 | find_package(VTK REQUIRED NO_MODULE 7 | COMPONENTS 8 | ${IGTLIO_MODULE_PREFIX}IOImage 9 | ${IGTLIO_MODULE_PREFIX}ImagingMath 10 | ${IGTLIO_MODULE_PREFIX}GUISupportQt 11 | ) 12 | if(VTK_VERSION VERSION_LESS 8.9.0) 13 | include(${VTK_USE_FILE}) 14 | endif() 15 | 16 | set(${PROJECT_NAME}_SRCS 17 | main.cpp 18 | ) 19 | 20 | set(${PROJECT_NAME}_TARGET_LIBRARIES 21 | igtlioGUI 22 | ) 23 | 24 | if(IGTLIO_QT_VERSION VERSION_EQUAL "5") 25 | find_package(Qt5 COMPONENTS Widgets REQUIRED) 26 | list(APPEND ${PROJECT_NAME}_TARGET_LIBRARIES Qt5::Widgets) 27 | else() 28 | find_package(Qt6 COMPONENTS Widgets REQUIRED) 29 | list(APPEND ${PROJECT_NAME}_TARGET_LIBRARIES Qt6::Widgets) 30 | endif() 31 | 32 | add_executable(${PROJECT_NAME} ${${PROJECT_NAME}_SRCS}) 33 | target_link_libraries(${PROJECT_NAME} PRIVATE ${${PROJECT_NAME}_TARGET_LIBRARIES}) 34 | 35 | INSTALL(TARGETS ${PROJECT_NAME} EXPORT OpenIGTLinkIO 36 | RUNTIME DESTINATION "${OpenIGTLinkIO_BINARY_INSTALL}" COMPONENT RuntimeLibraries 37 | LIBRARY DESTINATION "${OpenIGTLinkIO_LIBRARY_INSTALL}" COMPONENT RuntimeLibraries 38 | ARCHIVE DESTINATION "${OpenIGTLinkIO_ARCHIVE_INSTALL}" COMPONENT Development 39 | ) -------------------------------------------------------------------------------- /GUI/DeviceWidgets/qIGTLIODeviceWidgetFactory.h: -------------------------------------------------------------------------------- 1 | #ifndef QIGTLIODEVICEWIDGETFACTORY_H 2 | #define QIGTLIODEVICEWIDGETFACTORY_H 3 | 4 | #include 5 | 6 | // VTK includes 7 | #include 8 | #include 9 | 10 | // IGTLIO includes 11 | #include "igtlioGUIExport.h" 12 | #include "igtlioDevice.h" 13 | 14 | class qIGTLIODeviceWidget; 15 | typedef vtkSmartPointer vtkIGTLIODeviceWidgetCreatorPointer; 16 | typedef vtkSmartPointer vtkIGTLIODeviceWidgetFactoryPointer; 17 | 18 | class OPENIGTLINKIO_GUI_EXPORT vtkIGTLIODeviceWidgetFactory : public vtkObject 19 | { 20 | public: 21 | static vtkIGTLIODeviceWidgetFactory *New(); 22 | vtkTypeMacro(vtkIGTLIODeviceWidgetFactory,vtkObject); 23 | 24 | void PrintSelf(ostream& os, vtkIndent indent); 25 | 26 | vtkIGTLIODeviceWidgetCreatorPointer GetCreator(std::string device_type) const; 27 | 28 | // Create a Device object based on an input device_type 29 | qIGTLIODeviceWidget *create(std::string device_type) const; 30 | 31 | protected: 32 | vtkIGTLIODeviceWidgetFactory(); 33 | virtual ~vtkIGTLIODeviceWidgetFactory(); 34 | 35 | // Register a factory for a specific Device Type. 36 | template 37 | void registerCreator(); 38 | 39 | std::map Creators; 40 | }; 41 | 42 | 43 | #endif // QIGTLIODEVICEWIDGETFACTORY_H 44 | -------------------------------------------------------------------------------- /GUI/qIGTLIODevicesWidget.h: -------------------------------------------------------------------------------- 1 | #ifndef QIGTLIODEVICESWIDGET_H 2 | #define QIGTLIODEVICESWIDGET_H 3 | 4 | #include 5 | 6 | #include "qIGTLIOVtkConnectionMacro.h" 7 | 8 | // igtlio includes 9 | #include "igtlioGUIExport.h" 10 | class qIGTLIODevicesModel; 11 | class QVBoxLayout; 12 | class QModelIndex; 13 | //class qIGTLIOConnectorPropertyWidget; 14 | class QItemSelectionModel; 15 | class qIGTLIODeviceButtonsWidget; 16 | class qIGTLIODevicePropertiesWidget; 17 | class qIGTLIODeviceAddWidget; 18 | 19 | class QTreeView; 20 | #include 21 | 22 | typedef vtkSmartPointer igtlioLogicPointer; 23 | 24 | class OPENIGTLINKIO_GUI_EXPORT qIGTLIODevicesWidget : public QWidget 25 | { 26 | Q_OBJECT 27 | IGTLIO_QVTK_OBJECT 28 | public: 29 | qIGTLIODevicesWidget(); 30 | void setLogic(igtlioLogicPointer logic); 31 | 32 | signals: 33 | 34 | private slots: 35 | void onConnectionsChanged(vtkObject *caller, unsigned long event, void *b, void *connector ); 36 | void onCurrentDeviceChanged(const QModelIndex ¤t, const QModelIndex &previous); 37 | private: 38 | igtlioLogicPointer Logic; 39 | qIGTLIODevicesModel* DevicesModel; 40 | QItemSelectionModel* SelectionModel; 41 | qIGTLIODeviceButtonsWidget* ButtonsWidget; 42 | qIGTLIODevicePropertiesWidget* DevicePropertiesWidget; 43 | QTreeView* DevicesListView; 44 | qIGTLIODeviceAddWidget* AddDeviceWidget; 45 | 46 | }; 47 | 48 | #endif // QIGTLIODEVICESWIDGET_H 49 | -------------------------------------------------------------------------------- /GUI/qIGTLIOConnectorListWidget.h: -------------------------------------------------------------------------------- 1 | #ifndef QIGTLIOCONNECTORLISTWIDGET_H 2 | #define QIGTLIOCONNECTORLISTWIDGET_H 3 | 4 | #include 5 | 6 | #include "qIGTLIOVtkConnectionMacro.h" 7 | 8 | // igtlio includes 9 | #include "igtlioGUIExport.h" 10 | class qIGTLIOConnectorModel; 11 | class QVBoxLayout; 12 | class qIGTLIOConnectorPropertyWidget; 13 | class QItemSelectionModel; 14 | 15 | class QTreeView; 16 | #include 17 | 18 | typedef vtkSmartPointer igtlioLogicPointer; 19 | 20 | /// 21 | /// A Widget showing all connections, and a GUI to add/remove/modify them. 22 | /// 23 | class OPENIGTLINKIO_GUI_EXPORT qIGTLIOConnectorListWidget : public QWidget 24 | { 25 | Q_OBJECT 26 | IGTLIO_QVTK_OBJECT 27 | 28 | public: 29 | qIGTLIOConnectorListWidget(); 30 | void setLogic(igtlioLogicPointer logic); 31 | 32 | signals: 33 | 34 | private slots: 35 | void onConnectionsChanged(vtkObject* caller, unsigned long event, void * clientData, void* connector); 36 | void onCurrentConnectorChanged(); 37 | private slots: 38 | void onAddConnectorButtonClicked(); 39 | void onRemoveConnectorButtonClicked(); 40 | private: 41 | igtlioLogicPointer Logic; 42 | qIGTLIOConnectorModel* ConnectorModel; 43 | QItemSelectionModel* SelectionModel; 44 | QTreeView* ConnectorListView; 45 | qIGTLIOConnectorPropertyWidget* ConnectorPropertyWidget; 46 | void selectRow(int row); 47 | void addButtonFrame(QVBoxLayout *topLayout); 48 | }; 49 | 50 | #endif // QIGTLIOCONNECTORLISTWIDGET_H 51 | -------------------------------------------------------------------------------- /Logic/igtlioUtilities.h: -------------------------------------------------------------------------------- 1 | #ifndef IGTLIOUTILITIES_H 2 | #define IGTLIOUTILITIES_H 3 | 4 | #include "igtlioLogicExport.h" 5 | 6 | // std includes 7 | #include 8 | #include 9 | 10 | // OpenIGTLink includes 11 | #include "igtlMessageBase.h" 12 | 13 | // VTK includes 14 | #include "vtkImageData.h" 15 | #include "vtkMatrix4x4.h" 16 | #include "vtkSmartPointer.h" 17 | 18 | typedef vtkSmartPointer igtlioDevicePointer; 19 | 20 | enum OPENIGTLINKIO_LOGIC_EXPORT IGTLIO_SYNCHRONIZATION_TYPE 21 | { 22 | IGTLIO_BLOCKING, 23 | IGTLIO_ASYNCHRONOUS 24 | }; 25 | 26 | /// 27 | /// Uniquely identify a Device by both its name and type. 28 | /// This enables broadcast Devices (with empty name) of different types 29 | /// to be stored in the same structures. 30 | /// 31 | struct OPENIGTLINKIO_LOGIC_EXPORT igtlioDeviceKeyType 32 | { 33 | explicit igtlioDeviceKeyType() {} 34 | explicit igtlioDeviceKeyType(const std::string& type_, const std::string& name_) : 35 | type(type_), name(name_) {} 36 | std::string type; 37 | std::string name; 38 | 39 | public: 40 | std::string GetBaseTypeName() const; 41 | 42 | static igtlioDeviceKeyType CreateDeviceKey(igtl::MessageBase::Pointer message); 43 | static igtlioDeviceKeyType CreateDeviceKey(igtlioDevicePointer device); 44 | }; 45 | 46 | bool operator==(const igtlioDeviceKeyType& lhs, const igtlioDeviceKeyType& rhs); 47 | bool operator<(const igtlioDeviceKeyType& lhs, const igtlioDeviceKeyType& rhs); 48 | 49 | #endif // IGTLIOUTILITIES_H 50 | -------------------------------------------------------------------------------- /Converter/igtlioPointConverter.h: -------------------------------------------------------------------------------- 1 | #ifndef POINTCONVERTER_H 2 | #define POINTCONVERTER_H 3 | 4 | // OpenIGTLInkIO includes 5 | #include "igtlioBaseConverter.h" 6 | #include "igtlioConverterExport.h" 7 | 8 | // OpenIGTLink includes 9 | #include 10 | 11 | class OPENIGTLINKIO_CONVERTER_EXPORT igtlioPointConverter : public igtlioBaseConverter 12 | { 13 | public: 14 | /** 15 | * Content of STRING message. 16 | */ 17 | struct PointElement 18 | { 19 | std::string Name; /* name / description (< 64 bytes) */ 20 | std::string GroupName; /* Can be "Labeled Point", "Landmark", Fiducial", ... */ 21 | igtlUint8 RGBA[4]; /* Color in R/G/B/A */ 22 | igtlFloat32 Position[3]; /* Position */ 23 | igtlFloat32 Radius; /* Radius of the point. Can be 0.*/ 24 | std::string Owner; /* Device name of the ower image */ 25 | }; 26 | typedef std::vector PointList; 27 | 28 | struct ContentData 29 | { 30 | PointList PointElements; 31 | }; 32 | 33 | static const char* GetIGTLName() { return GetIGTLTypeName(); } 34 | static const char* GetIGTLTypeName() { return "POINT"; } 35 | 36 | static int fromIGTL(igtl::MessageBase::Pointer source, HeaderData* header, ContentData* content, bool checkCRC, igtl::MessageBase::MetaDataMap& outMetaInfo); 37 | static int toIGTL(const HeaderData& header, const ContentData& source, igtl::PointMessage::Pointer* dest, igtl::MessageBase::MetaDataMap metaInfo = igtl::MessageBase::MetaDataMap()); 38 | 39 | }; 40 | 41 | #endif // IMAGEMETACONVERTER_H 42 | -------------------------------------------------------------------------------- /Logic/igtlioDeviceFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * vtkIGTLIODeviceFactory.h 3 | * 4 | * Created on: 21. jan. 2016 5 | * Author: cas 6 | */ 7 | 8 | #ifndef IGTLIODEVICEFACTORY_H_ 9 | #define IGTLIODEVICEFACTORY_H_ 10 | 11 | #include 12 | #include 13 | 14 | // VTK includes 15 | #include 16 | #include 17 | 18 | // IGTLIO includes 19 | #include "igtlioLogicExport.h" 20 | #include "igtlioDevice.h" 21 | 22 | typedef vtkSmartPointer igtlioDeviceCreatorPointer; 23 | typedef vtkSmartPointer igtlioDeviceFactoryPointer; 24 | 25 | class OPENIGTLINKIO_LOGIC_EXPORT igtlioDeviceFactory : public vtkObject 26 | { 27 | public: 28 | static igtlioDeviceFactory *New(); 29 | vtkTypeMacro(igtlioDeviceFactory,vtkObject); 30 | 31 | void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE; 32 | 33 | igtlioDeviceCreatorPointer GetCreator(std::string device_type) const; 34 | std::vector GetAvailableDeviceTypes() const; 35 | 36 | // Create a Device object based on an input device_type 37 | // TODO: Should we accept prefixed message types as well? 38 | igtlioDevicePointer create(std::string device_type, std::string device_name) const; 39 | 40 | protected: 41 | igtlioDeviceFactory(); 42 | virtual ~igtlioDeviceFactory(); 43 | 44 | // Register a factory for a specific Device Type. 45 | template 46 | void registerCreator(); 47 | 48 | std::map Creators; 49 | }; 50 | 51 | #endif /* IGTLIODEVICEFACTORY_H_ */ 52 | -------------------------------------------------------------------------------- /Testing/testCommandMessageCodec.cxx: -------------------------------------------------------------------------------- 1 | #include "igtlioCommandMessageCodec.h" 2 | #include 3 | #include 4 | #include "igtlioTestUtilities.h" 5 | 6 | int main(int argc, char **argv) 7 | { 8 | // Generate initial string with command xml 9 | igtlioCommandMessageCodec initialCodec(true); 10 | initialCodec.SetResult( true ); 11 | initialCodec.AddParameter( "Depth", "45" ); 12 | initialCodec.AddParameter( "Gain", "35" ); 13 | std::string commandContent = initialCodec.GetContent(); 14 | 15 | std::cerr << "Command content: " << std::endl << commandContent << std::endl; 16 | 17 | // Try decoding string 18 | igtlioCommandMessageCodec codec; 19 | codec.SetContent( commandContent ); 20 | 21 | if( !codec.IsReply() ) 22 | { 23 | std::cerr << "Command is a reply" << std::endl; 24 | return TEST_FAILED; 25 | } 26 | 27 | if( !codec.GetResult() ) 28 | { 29 | std::cerr << "Result should be true" << std::endl; 30 | return TEST_FAILED; 31 | } 32 | 33 | if( codec.GetNumberOfParameters() != 2 ) 34 | { 35 | std::cerr << "There should be 2 parameters" << std::endl; 36 | return TEST_FAILED; 37 | } 38 | 39 | if( codec.GetParameter("Depth") != "45" ) 40 | { 41 | std::cerr << "Depth should be 45" << std::endl; 42 | return TEST_FAILED; 43 | } 44 | 45 | if( codec.GetParameter("Gain") != "35" ) 46 | { 47 | std::cerr << "Gain should be 35" << std::endl; 48 | return TEST_FAILED; 49 | } 50 | 51 | return TEST_SUCCESS; 52 | } 53 | -------------------------------------------------------------------------------- /Converter/igtlioBaseConverter.h: -------------------------------------------------------------------------------- 1 | #ifndef IGTLIOBASECONVERTER_H 2 | #define IGTLIOBASECONVERTER_H 3 | 4 | #include "igtlioConverterExport.h" 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | 11 | //--------------------------------------------------------------------------- 12 | 13 | // TODO: Move this into igtlSmartPointer.h 14 | /// implements smart pointer conversion for igtl::SmartPointer, 15 | /// similar to std::dynamic_pointer_cast 16 | template 17 | igtl::SmartPointer dynamic_pointer_cast(const igtl::SmartPointer& sp) //noexcept 18 | { 19 | T* ptr = dynamic_cast(sp.GetPointer()); 20 | return igtl::SmartPointer(ptr); 21 | } 22 | //--------------------------------------------------------------------------- 23 | 24 | /** Conversion between igtl::ImageMessage and vtk classes. 25 | * 26 | */ 27 | class OPENIGTLINKIO_CONVERTER_EXPORT igtlioBaseConverter 28 | { 29 | public: 30 | /** 31 | * This structure contains data common to all igtl messages, 32 | * TODO: add header xml-data here. 33 | */ 34 | struct HeaderData 35 | { 36 | std::string deviceName; 37 | double timestamp; 38 | }; 39 | 40 | static int IGTLtoHeader(igtl::MessageBase::Pointer source, HeaderData* header, igtl::MessageBase::MetaDataMap& outMetaInfo); 41 | static int HeadertoIGTL(const HeaderData& header, igtl::MessageBase::Pointer* dest, igtl::MessageBase::MetaDataMap metaInfo = igtl::MessageBase::MetaDataMap()); 42 | 43 | static int IGTLToTimestamp(igtl::MessageBase::Pointer msg, HeaderData *dest); 44 | }; 45 | 46 | #endif // IGTLIOBASECONVERTER_H 47 | -------------------------------------------------------------------------------- /GUI/qIGTLIOCommandWidget.h: -------------------------------------------------------------------------------- 1 | #ifndef qIGTLIOCommandWidget_H 2 | #define qIGTLIOCommandWidget_H 3 | 4 | #include "igtlioGUIExport.h" 5 | 6 | // Qt includes 7 | #include 8 | 9 | // igtlio includes 10 | #include "igtlioCommand.h" 11 | #include "qIGTLIOVtkConnectionMacro.h" 12 | 13 | class QLineEdit; 14 | class QGridLayout; 15 | class QComboBox; 16 | class QTextEdit; 17 | class QPushButton; 18 | 19 | typedef vtkSmartPointer igtlioLogicPointer; 20 | typedef vtkSmartPointer igtlioConnectorPointer; 21 | 22 | //--------------------------------------------------------------------------- 23 | 24 | class OPENIGTLINKIO_GUI_EXPORT qIGTLIOCommandWidget : public QWidget 25 | { 26 | Q_OBJECT 27 | IGTLIO_QVTK_OBJECT 28 | 29 | public: 30 | qIGTLIOCommandWidget(QWidget* parent=NULL); 31 | 32 | void setLogic(igtlioLogicPointer logic); 33 | 34 | protected: 35 | 36 | igtlioLogicPointer Logic; 37 | 38 | QComboBox* ConnectorSelector; 39 | QLineEdit* TimestampEdit; 40 | QLineEdit* IdEdit; 41 | QLineEdit* NameEdit; 42 | QTextEdit* ContentEdit; 43 | QLineEdit* StatusEdit; 44 | QTextEdit* ResponseEdit; 45 | QPushButton* SendCommandButton; 46 | 47 | virtual void setupUi(); 48 | 49 | private slots: 50 | void addCaptionedLineEdit(QGridLayout *layout, QLineEdit *edit, QString caption, int line); 51 | void blockGUI(bool on); 52 | void onCommandModified(); 53 | void onSendCommand(); 54 | void onConnectionsChanged(vtkObject *caller, unsigned long event, void *b, void *connector); 55 | 56 | public: 57 | void setCommand(igtlioCommandPointer command); 58 | 59 | private: 60 | igtlioCommandPointer Command; 61 | }; 62 | 63 | 64 | #endif // qIGTLIOCommandWidget_H 65 | -------------------------------------------------------------------------------- /Converter/igtlioImageMetaConverter.h: -------------------------------------------------------------------------------- 1 | #ifndef IMAGEMETACONVERTER_H 2 | #define IMAGEMETACONVERTER_H 3 | 4 | // OpenIGTLinkIO includes 5 | #include "igtlioBaseConverter.h" 6 | #include "igtlioConverterExport.h" 7 | 8 | // OpenIGTLink includes 9 | #include 10 | 11 | class OPENIGTLINKIO_CONVERTER_EXPORT igtlioImageMetaConverter : public igtlioBaseConverter 12 | { 13 | public: 14 | /** 15 | * Content of STRING message. 16 | */ 17 | struct ImageMetaElement 18 | { 19 | std::string Name; /* name / description (< 64 bytes)*/ 20 | std::string DeviceName; /* device name to query the IMAGE and COLORT */ 21 | std::string Modality; /* modality name (< 32 bytes) */ 22 | std::string PatientName; /* patient name (< 64 bytes) */ 23 | std::string PatientID; /* patient ID (MRN etc.) (< 64 bytes) */ 24 | double Timestamp; /* scan time */ 25 | int Size[3]; /* entire image volume size */ 26 | unsigned char ScalarType; /* scalar type. see scalar_type in IMAGE message */ 27 | }; 28 | typedef std::vector ImageMetaDataList; 29 | 30 | struct ContentData 31 | { 32 | ImageMetaDataList ImageMetaDataElements; 33 | }; 34 | 35 | static const char* GetIGTLName() { return GetIGTLTypeName(); } 36 | static const char* GetIGTLTypeName() { return "IMGMETA"; } 37 | 38 | static int fromIGTL(igtl::MessageBase::Pointer source, HeaderData* header, ContentData* content, bool checkCRC, igtl::MessageBase::MetaDataMap& outMetaInfo); 39 | static int toIGTL(const HeaderData& header, const ContentData& source, igtl::ImageMetaMessage::Pointer* dest, igtl::MessageBase::MetaDataMap metaInfo = igtl::MessageBase::MetaDataMap()); 40 | 41 | }; 42 | 43 | #endif // IMAGEMETACONVERTER_H 44 | -------------------------------------------------------------------------------- /Converter/igtlioLabelMetaConverter.h: -------------------------------------------------------------------------------- 1 | #ifndef LABELMETACONVERTER_H 2 | #define LABELMETACONVERTER_H 3 | 4 | // OpenIGTLinkIO includes 5 | #include "igtlioBaseConverter.h" 6 | #include "igtlioConverterExport.h" 7 | 8 | // OpenIGTLink includes 9 | #include 10 | 11 | class OPENIGTLINKIO_CONVERTER_EXPORT igtlioLabelMetaConverter : public igtlioBaseConverter 12 | { 13 | public: 14 | /** 15 | * Content of STRING message. 16 | */ 17 | struct LabelMetaElement 18 | { 19 | std::string Name; /* Name or description of the image */ 20 | std::string DeviceName; /* ID to query the IMAGE */ 21 | unsigned char Label; /* Label of the structure (0 if unused) */ 22 | unsigned char RGBA[4]; /* Color in RGBA (0 0 0 0 if no color is defined) */ 23 | int Size[3]; /* Number of pixels in each direction (same as in IMAGE), bounding box of the structure(s) */ 24 | std::string Owner; /* ID of the owner image/sliceset. Voxel objects from different slicesets can be sent if 25 | slicesets are fused. Can be empty if n/a */ 26 | }; 27 | typedef std::vector LabelMetaDataList; 28 | 29 | struct ContentData 30 | { 31 | LabelMetaDataList LabelMetaDataElements; 32 | }; 33 | 34 | static const char* GetIGTLName() { return GetIGTLTypeName(); } 35 | static const char* GetIGTLTypeName() { return "LBMETA"; } 36 | 37 | static int fromIGTL(igtl::MessageBase::Pointer source, HeaderData* header, ContentData* content, bool checkCRC, igtl::MessageBase::MetaDataMap& outMetaInfo); 38 | static int toIGTL(const HeaderData& header, const ContentData& source, igtl::LabelMetaMessage::Pointer* dest, igtl::MessageBase::MetaDataMap metaInfo = igtl::MessageBase::MetaDataMap()); 39 | 40 | }; 41 | 42 | #endif // IMAGEMETACONVERTER_H 43 | -------------------------------------------------------------------------------- /GUI/qIGTLIODevicePropertiesWidget.cxx: -------------------------------------------------------------------------------- 1 | #include "qIGTLIODevicePropertiesWidget.h" 2 | 3 | #include 4 | #include 5 | #include "vtkIGTLIONode.h" 6 | #include 7 | #include "qIGTLIODeviceWidgetFactory.h" 8 | #include "qIGTLIODeviceWidget.h" 9 | 10 | class WidgetInGroupBoxClass 11 | { 12 | public: 13 | WidgetInGroupBoxClass(QVBoxLayout* parentLayout, QString header) 14 | { 15 | groupBox = new QGroupBox(header); 16 | parentLayout->addWidget(groupBox); 17 | layout = new QVBoxLayout(groupBox); 18 | layout->setContentsMargins(0, 0, 0, 0); 19 | } 20 | 21 | void replaceWidget(QWidget* newWidget) 22 | { 23 | this->clearLayout(); 24 | if (newWidget) 25 | layout->addWidget(newWidget); 26 | } 27 | void clearLayout() 28 | { 29 | QLayoutItem *child; 30 | while ((child = layout->takeAt(0)) != 0) 31 | { 32 | QWidget* widget = child->widget(); 33 | delete child; 34 | delete widget; 35 | } 36 | } 37 | 38 | protected: 39 | QGroupBox* groupBox; 40 | QVBoxLayout* layout; 41 | }; 42 | 43 | 44 | qIGTLIODevicePropertiesWidget::qIGTLIODevicePropertiesWidget(QWidget* parent) : QWidget(parent) 45 | { 46 | DeviceWidgetFactory = vtkIGTLIODeviceWidgetFactoryPointer::New(); 47 | 48 | QVBoxLayout* layout = new QVBoxLayout(this); 49 | layout->setContentsMargins(0, 0, 0, 0); 50 | 51 | WidgetInGroupBox = new WidgetInGroupBoxClass(layout, "Device"); 52 | } 53 | 54 | void qIGTLIODevicePropertiesWidget::SetNode(qIGTLIODevicesModelNode *node) 55 | { 56 | Node = node; 57 | 58 | igtlioDevice* device = Node->device; 59 | 60 | qIGTLIODeviceWidget* widget = NULL; 61 | 62 | if (device) 63 | { 64 | widget = DeviceWidgetFactory->create(device->GetDeviceType()); 65 | widget->SetDevice(device); 66 | } 67 | 68 | WidgetInGroupBox->replaceWidget(widget); 69 | } 70 | 71 | -------------------------------------------------------------------------------- /Tools/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(igtlioTools) 2 | 3 | set(${PROJECT_NAME}_EXPORT_DIRECTIVE "OPENIGTLINKIO_TOOLS_EXPORT") 4 | 5 | find_package(OpenIGTLink REQUIRED) 6 | include(${OpenIGTLink_USE_FILE}) 7 | 8 | set(VTK_MODULES 9 | ${IGTLIO_MODULE_PREFIX}IOXMLParser 10 | ) 11 | 12 | find_package(VTK REQUIRED NO_MODULE COMPONENTS ${VTK_MODULES}) 13 | 14 | if(VTK_VERSION VERSION_LESS 8.9.0) 15 | include(${VTK_USE_FILE}) 16 | endif() 17 | 18 | set(${PROJECT_NAME}_INCLUDE_DIRECTORIES PUBLIC 19 | $ 20 | $ 21 | $ 22 | ) 23 | 24 | set(${PROJECT_NAME}_SRCS 25 | igtlioTranslator.cxx 26 | igtlioCommandMessageCodec.cxx 27 | ) 28 | 29 | set(${PROJECT_NAME}_HDRS 30 | igtlioTranslator.h 31 | igtlioCommandMessageCodec.h 32 | ) 33 | 34 | set(${PROJECT_NAME}_TARGET_LIBRARIES 35 | ${OpenIGTLink_LIBRARIES} 36 | ${VTK_LIBRARIES} 37 | ) 38 | 39 | add_library(${PROJECT_NAME} ${${PROJECT_NAME}_SRCS} ${${PROJECT_NAME}_HDRS}) 40 | target_link_libraries(${PROJECT_NAME} ${${PROJECT_NAME}_TARGET_LIBRARIES}) 41 | target_include_directories(${PROJECT_NAME} ${${PROJECT_NAME}_INCLUDE_DIRECTORIES}) 42 | 43 | generate_export_header( ${PROJECT_NAME} EXPORT_FILE_NAME ${PROJECT_NAME}Export.h EXPORT_MACRO_NAME ${${PROJECT_NAME}_EXPORT_DIRECTIVE}) 44 | 45 | INSTALL(TARGETS ${PROJECT_NAME} EXPORT OpenIGTLinkIO 46 | RUNTIME DESTINATION "${OpenIGTLinkIO_BINARY_INSTALL}" COMPONENT RuntimeLibraries 47 | LIBRARY DESTINATION "${OpenIGTLinkIO_LIBRARY_INSTALL}" COMPONENT RuntimeLibraries 48 | ARCHIVE DESTINATION "${OpenIGTLinkIO_ARCHIVE_INSTALL}" COMPONENT Development 49 | ) 50 | 51 | INSTALL(FILES ${${PROJECT_NAME}_HDRS} "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Export.h" DESTINATION "${OpenIGTLinkIO_INCLUDE_INSTALL}" COMPONENT Includes) -------------------------------------------------------------------------------- /Converter/igtlioCommandConverter.h: -------------------------------------------------------------------------------- 1 | #ifndef IGTLIOCOMMANDCONVERTER_H 2 | #define IGTLIOCOMMANDCONVERTER_H 3 | 4 | #include 5 | #include 6 | 7 | #include "igtlioConverterExport.h" 8 | #include "igtlioBaseConverter.h" 9 | 10 | /** Conversion between igtl::StatusMessage and vtk classes. 11 | * 12 | */ 13 | class OPENIGTLINKIO_CONVERTER_EXPORT igtlioCommandConverter : public igtlioBaseConverter 14 | { 15 | public: 16 | 17 | /** 18 | * Content of COMMAND message. 19 | */ 20 | struct ContentData 21 | { 22 | ContentData() : id(0) {} 23 | int id; 24 | std::string name; 25 | std::string content; 26 | bool status; 27 | }; 28 | 29 | static const char* GetIGTLName() { return GetIGTLTypeName(); } 30 | static const char* GetIGTLTypeName() { return "COMMAND"; } 31 | static const char* GetIGTLResponseName() { return "RTS_COMMAND"; } 32 | 33 | static const char* GetComandStatusAttributeName() { return "Status"; } 34 | static const char* GetComandErrorMessageAttributeName() { return "ErrorMessage"; } 35 | 36 | static int fromIGTL(igtl::MessageBase::Pointer source, HeaderData* header, ContentData* content, bool checkCRC, igtl::MessageBase::MetaDataMap& outMetaInfo); 37 | static int fromIGTLResponse(igtl::MessageBase::Pointer source, HeaderData *header, ContentData *dest, bool checkCRC, igtl::MessageBase::MetaDataMap& outMetaInfo); 38 | static int toIGTL(const HeaderData& header, const ContentData& source, igtl::CommandMessage::Pointer* dest, igtl::MessageBase::MetaDataMap metaInfo = igtl::MessageBase::MetaDataMap()); 39 | static int toIGTLResponse(const HeaderData& header, const ContentData& source, igtl::RTSCommandMessage::Pointer* dest, igtl::MessageBase::MetaDataMap metaInfo = igtl::MessageBase::MetaDataMap()); 40 | 41 | static std::vector GetAvailableCommandNames(); 42 | }; 43 | 44 | #endif // IGTLIOCOMMANDCONVERTER_H 45 | -------------------------------------------------------------------------------- /GUI/qMRMLIGTLIOModel_p.h: -------------------------------------------------------------------------------- 1 | /*============================================================================== 2 | 3 | Program: 3D Slicer 4 | 5 | Copyright (c) Kitware Inc. 6 | 7 | See COPYRIGHT.txt 8 | or http://www.slicer.org/copyright/copyright.txt for details. 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | This file was originally developed by Julien Finet, Kitware Inc. 17 | and was partially funded by NIH grant 3P41RR013218-12S1 18 | 19 | ==============================================================================*/ 20 | 21 | #ifndef __qMRMLIGTLIOModel_p_h 22 | #define __qMRMLIGTLIOModel_p_h 23 | 24 | // Qt includes 25 | 26 | // qMRML includes 27 | #include "qMRMLIGTLIOModel.h" 28 | #include "qMRMLSceneModel_p.h" 29 | 30 | // MRML includes 31 | class qMRMLIGTLIOModel; 32 | 33 | //------------------------------------------------------------------------------ 34 | // qMRMLIGTLIOModelPrivate 35 | //------------------------------------------------------------------------------ 36 | 37 | //------------------------------------------------------------------------------ 38 | class qMRMLIGTLIOModelPrivate: public qMRMLSceneModelPrivate 39 | { 40 | protected: 41 | Q_DECLARE_PUBLIC(qMRMLIGTLIOModel); 42 | public: 43 | typedef qMRMLSceneModelPrivate Superclass; 44 | qMRMLIGTLIOModelPrivate(qMRMLIGTLIOModel& object); 45 | 46 | QStandardItem* insertExtraItem2(int row, QStandardItem* parent, 47 | const QString& text, 48 | const QString& extraType, 49 | const Qt::ItemFlags& flags); 50 | }; 51 | 52 | #endif 53 | 54 | 55 | -------------------------------------------------------------------------------- /Devices/igtlioPointDevice.h: -------------------------------------------------------------------------------- 1 | #ifndef POINTDEVICE_H 2 | #define POINTDEVICE_H 3 | 4 | // OpenIGTLinkIO includes 5 | #include "igtlioDevice.h" 6 | #include "igtlioDevicesExport.h" 7 | #include "igtlioPointConverter.h" 8 | 9 | typedef vtkSmartPointer igtlioPointDevicePointer; 10 | 11 | class OPENIGTLINKIO_DEVICES_EXPORT igtlioPointDevice : public igtlioDevice 12 | { 13 | public: 14 | enum { 15 | PointModifiedEvent = 118964, 16 | }; 17 | 18 | virtual unsigned int GetDeviceContentModifiedEvent() const VTK_OVERRIDE; 19 | virtual std::string GetDeviceType() const VTK_OVERRIDE; 20 | virtual int ReceiveIGTLMessage(igtl::MessageBase::Pointer buffer, bool checkCRC) VTK_OVERRIDE; 21 | virtual igtl::MessageBase::Pointer GetIGTLMessage() VTK_OVERRIDE; 22 | virtual igtl::MessageBase::Pointer GetIGTLMessage(MESSAGE_PREFIX prefix) VTK_OVERRIDE; 23 | virtual std::set GetSupportedMessagePrefixes() const VTK_OVERRIDE; 24 | 25 | void SetContent(igtlioPointConverter::ContentData content); 26 | igtlioPointConverter::ContentData GetContent(); 27 | 28 | public: 29 | static igtlioPointDevice *New(); 30 | vtkTypeMacro(igtlioPointDevice, igtlioDevice); 31 | 32 | void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE; 33 | 34 | protected: 35 | igtlioPointDevice(); 36 | ~igtlioPointDevice(); 37 | 38 | protected: 39 | igtl::PointMessage::Pointer OutMessage; 40 | 41 | igtlioPointConverter::ContentData Content; 42 | }; 43 | 44 | //--------------------------------------------------------------------------- 45 | class OPENIGTLINKIO_DEVICES_EXPORT igtlioPointDeviceCreator : public igtlioDeviceCreator 46 | { 47 | public: 48 | virtual igtlioDevicePointer Create(std::string device_name) VTK_OVERRIDE; 49 | virtual std::string GetDeviceType() const VTK_OVERRIDE; 50 | 51 | static igtlioPointDeviceCreator *New(); 52 | vtkTypeMacro(igtlioPointDeviceCreator, vtkObject); 53 | }; 54 | 55 | #endif // POINTDEVICE_H 56 | -------------------------------------------------------------------------------- /Converter/igtlioBaseConverter.cxx: -------------------------------------------------------------------------------- 1 | #include "igtlioBaseConverter.h" 2 | 3 | //--------------------------------------------------------------------------- 4 | int igtlioBaseConverter::IGTLtoHeader(igtl::MessageBase::Pointer source, HeaderData *header, igtl::MessageBase::MetaDataMap& outMetaInfo) 5 | { 6 | header->deviceName = source->GetDeviceName(); 7 | // get timestamp 8 | if (IGTLToTimestamp(source, header) == 0) 9 | return 0; 10 | 11 | igtl::MessageBase::MetaDataMap sourceMetaInfo = source->GetMetaData(); 12 | outMetaInfo.clear(); 13 | for (igtl::MessageBase::MetaDataMap::const_iterator it = sourceMetaInfo.begin(); it != sourceMetaInfo.end(); ++it) 14 | { 15 | std::string key = it->first; 16 | IANA_ENCODING_TYPE encodingScheme = it->second.first; 17 | std::string value = it->second.second; 18 | outMetaInfo[key] = std::pair(encodingScheme, value); 19 | } 20 | return 1; 21 | } 22 | 23 | //--------------------------------------------------------------------------- 24 | int igtlioBaseConverter::HeadertoIGTL(const HeaderData &header, igtl::MessageBase::Pointer *dest, igtl::MessageBase::MetaDataMap metaInfo) 25 | { 26 | (*dest)->SetDeviceName(header.deviceName.c_str()); 27 | for (igtl::MessageBase::MetaDataMap::const_iterator it = metaInfo.begin(); it != metaInfo.end(); ++it) 28 | { 29 | std::string key = it->first; 30 | IANA_ENCODING_TYPE encodingScheme = it->second.first; 31 | std::string value = it->second.second; 32 | (*dest)->SetMetaDataElement(key, encodingScheme, value); 33 | } 34 | return 1; 35 | } 36 | 37 | //--------------------------------------------------------------------------- 38 | int igtlioBaseConverter::IGTLToTimestamp(igtl::MessageBase::Pointer msg, HeaderData *dest) 39 | { 40 | // Save OpenIGTLink time stamp 41 | igtl::TimeStamp::Pointer ts = igtl::TimeStamp::New(); 42 | msg->GetTimeStamp(ts); 43 | dest->timestamp = ts->GetTimeStamp(); 44 | return 1; 45 | } 46 | -------------------------------------------------------------------------------- /Devices/igtlioStatusDevice.h: -------------------------------------------------------------------------------- 1 | #ifndef IGTLIOSTATUSDEVICE_H 2 | #define IGTLIOSTATUSDEVICE_H 3 | 4 | #include "igtlioDevicesExport.h" 5 | 6 | #include "igtlioStatusConverter.h" 7 | #include "igtlioDevice.h" 8 | 9 | typedef vtkSmartPointer igtlioStatusDevicePointer; 10 | 11 | class OPENIGTLINKIO_DEVICES_EXPORT igtlioStatusDevice : public igtlioDevice 12 | { 13 | public: 14 | enum { 15 | StatusModifiedEvent = 118956, 16 | }; 17 | 18 | virtual unsigned int GetDeviceContentModifiedEvent() const VTK_OVERRIDE; 19 | virtual std::string GetDeviceType() const VTK_OVERRIDE; 20 | virtual int ReceiveIGTLMessage(igtl::MessageBase::Pointer buffer, bool checkCRC) VTK_OVERRIDE; 21 | virtual igtl::MessageBase::Pointer GetIGTLMessage() VTK_OVERRIDE; 22 | virtual igtl::MessageBase::Pointer GetIGTLMessage(MESSAGE_PREFIX prefix) VTK_OVERRIDE; 23 | virtual std::set GetSupportedMessagePrefixes() const VTK_OVERRIDE; 24 | 25 | void SetContent(igtlioStatusConverter::ContentData content); 26 | igtlioStatusConverter::ContentData GetContent(); 27 | 28 | public: 29 | static igtlioStatusDevice *New(); 30 | vtkTypeMacro(igtlioStatusDevice,igtlioDevice); 31 | 32 | void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE; 33 | 34 | protected: 35 | igtlioStatusDevice(); 36 | ~igtlioStatusDevice(); 37 | 38 | protected: 39 | igtl::StatusMessage::Pointer OutMessage; 40 | igtl::GetStatusMessage::Pointer GetMessage; 41 | 42 | igtlioStatusConverter::ContentData Content; 43 | }; 44 | 45 | 46 | //--------------------------------------------------------------------------- 47 | class OPENIGTLINKIO_DEVICES_EXPORT igtlioStatusDeviceCreator : public igtlioDeviceCreator 48 | { 49 | public: 50 | virtual igtlioDevicePointer Create(std::string device_name) VTK_OVERRIDE; 51 | virtual std::string GetDeviceType() const VTK_OVERRIDE; 52 | 53 | static igtlioStatusDeviceCreator *New(); 54 | vtkTypeMacro(igtlioStatusDeviceCreator,vtkObject); 55 | }; 56 | 57 | #endif // IGTLIOSTATUSDEVICE_H 58 | -------------------------------------------------------------------------------- /Devices/igtlioImageMetaDevice.h: -------------------------------------------------------------------------------- 1 | #ifndef IMAGEMETADEVICE_H 2 | #define IMAGEMETADEVICE_H 3 | 4 | // OpenIGTLinkIO includes 5 | #include "igtlioDevice.h" 6 | #include "igtlioDevicesExport.h" 7 | #include "igtlioImageMetaConverter.h" 8 | 9 | typedef vtkSmartPointer igtlioImageMetaDevicePointer; 10 | 11 | class OPENIGTLINKIO_DEVICES_EXPORT igtlioImageMetaDevice : public igtlioDevice 12 | { 13 | public: 14 | enum { 15 | ImageMetaModifiedEvent = 118962, 16 | }; 17 | 18 | virtual unsigned int GetDeviceContentModifiedEvent() const VTK_OVERRIDE; 19 | virtual std::string GetDeviceType() const VTK_OVERRIDE; 20 | virtual int ReceiveIGTLMessage(igtl::MessageBase::Pointer buffer, bool checkCRC) VTK_OVERRIDE; 21 | virtual igtl::MessageBase::Pointer GetIGTLMessage() VTK_OVERRIDE; 22 | virtual igtl::MessageBase::Pointer GetIGTLMessage(MESSAGE_PREFIX prefix) VTK_OVERRIDE; 23 | virtual std::set GetSupportedMessagePrefixes() const VTK_OVERRIDE; 24 | 25 | void SetContent(igtlioImageMetaConverter::ContentData content); 26 | igtlioImageMetaConverter::ContentData GetContent(); 27 | 28 | public: 29 | static igtlioImageMetaDevice *New(); 30 | vtkTypeMacro(igtlioImageMetaDevice, igtlioDevice); 31 | 32 | void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE; 33 | 34 | protected: 35 | igtlioImageMetaDevice(); 36 | ~igtlioImageMetaDevice(); 37 | 38 | protected: 39 | igtl::ImageMetaMessage::Pointer OutMessage; 40 | 41 | igtlioImageMetaConverter::ContentData Content; 42 | }; 43 | 44 | //--------------------------------------------------------------------------- 45 | class OPENIGTLINKIO_DEVICES_EXPORT igtlioImageMetaDeviceCreator : public igtlioDeviceCreator 46 | { 47 | public: 48 | virtual igtlioDevicePointer Create(std::string device_name) VTK_OVERRIDE; 49 | virtual std::string GetDeviceType() const VTK_OVERRIDE; 50 | 51 | static igtlioImageMetaDeviceCreator *New(); 52 | vtkTypeMacro(igtlioImageMetaDeviceCreator, vtkObject); 53 | }; 54 | 55 | #endif // IMAGEMETADEVICE_H 56 | -------------------------------------------------------------------------------- /Devices/igtlioLabelMetaDevice.h: -------------------------------------------------------------------------------- 1 | #ifndef LABELMETADEVICE_H 2 | #define LABELMETADEVICE_H 3 | 4 | // OpenIGTLinkIO includes 5 | #include "igtlioDevice.h" 6 | #include "igtlioDevicesExport.h" 7 | #include "igtlioLabelMetaConverter.h" 8 | 9 | typedef vtkSmartPointer igtlioLabelMetaDevicePointer; 10 | 11 | class OPENIGTLINKIO_DEVICES_EXPORT igtlioLabelMetaDevice : public igtlioDevice 12 | { 13 | public: 14 | enum { 15 | LabelMetaModifiedEvent = 118963, 16 | }; 17 | 18 | virtual unsigned int GetDeviceContentModifiedEvent() const VTK_OVERRIDE; 19 | virtual std::string GetDeviceType() const VTK_OVERRIDE; 20 | virtual int ReceiveIGTLMessage(igtl::MessageBase::Pointer buffer, bool checkCRC) VTK_OVERRIDE; 21 | virtual igtl::MessageBase::Pointer GetIGTLMessage() VTK_OVERRIDE; 22 | virtual igtl::MessageBase::Pointer GetIGTLMessage(MESSAGE_PREFIX prefix) VTK_OVERRIDE; 23 | virtual std::set GetSupportedMessagePrefixes() const VTK_OVERRIDE; 24 | 25 | void SetContent(igtlioLabelMetaConverter::ContentData content); 26 | igtlioLabelMetaConverter::ContentData GetContent(); 27 | 28 | public: 29 | static igtlioLabelMetaDevice *New(); 30 | vtkTypeMacro(igtlioLabelMetaDevice, igtlioDevice); 31 | 32 | void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE; 33 | 34 | protected: 35 | igtlioLabelMetaDevice(); 36 | ~igtlioLabelMetaDevice(); 37 | 38 | protected: 39 | igtl::LabelMetaMessage::Pointer OutMessage; 40 | 41 | igtlioLabelMetaConverter::ContentData Content; 42 | }; 43 | 44 | //--------------------------------------------------------------------------- 45 | class OPENIGTLINKIO_DEVICES_EXPORT igtlioLabelMetaDeviceCreator : public igtlioDeviceCreator 46 | { 47 | public: 48 | virtual igtlioDevicePointer Create(std::string device_name) VTK_OVERRIDE; 49 | virtual std::string GetDeviceType() const VTK_OVERRIDE; 50 | 51 | static igtlioLabelMetaDeviceCreator *New(); 52 | vtkTypeMacro(igtlioLabelMetaDeviceCreator, vtkObject); 53 | }; 54 | 55 | #endif // LABELMETADEVICE_H 56 | -------------------------------------------------------------------------------- /Testing/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(igtlioTesting) 2 | 3 | find_package(VTK REQUIRED NO_MODULE 4 | COMPONENTS 5 | vtkIOImage 6 | vtkImagingMath 7 | vtkImagingCore 8 | vtkIOXMLParser 9 | ) 10 | include(${VTK_USE_FILE}) 11 | 12 | set(${PROJECT_NAME}_SRCS 13 | igtlioFixture.cxx 14 | igtlioFixture.h 15 | igtlioTestUtilities.h 16 | igtlioTestUtilities.cxx 17 | ) 18 | 19 | set(${PROJECT_NAME}_MOC_SRCS 20 | ) 21 | 22 | set(${PROJECT_NAME}_UI_SRCS 23 | ) 24 | 25 | 26 | set(${PROJECT_NAME}_INCLUDE_DIRECTORIES PUBLIC 27 | ${CMAKE_CURRENT_SOURCE_DIR} 28 | ${CMAKE_CURRENT_BINARY_DIR} 29 | ) 30 | 31 | set(${PROJECT_NAME}_TARGET_LIBRARIES 32 | ${OpenIGTLink_LIBRARIES} 33 | ${VTK_LIBRARIES} 34 | igtlioLogic 35 | igtlioTools 36 | ) 37 | 38 | macro(add_io_test test_name test_target source_files) 39 | add_executable(${test_target} ${source_files} ${${PROJECT_NAME}_SRCS} ${${PROJECT_NAME}_MOC_SRCS}) 40 | target_link_libraries(${test_target} PUBLIC ${${PROJECT_NAME}_TARGET_LIBRARIES}) 41 | target_include_directories(${test_target} ${${PROJECT_NAME}_INCLUDE_DIRECTORIES}) 42 | add_test(${test_name} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${test_target}) 43 | endmacro() 44 | 45 | add_io_test("testClientServer" testClientServer testClientServer.cxx) 46 | add_io_test("testReceiveImage" testReceiveImage testReceiveImage.cxx) 47 | add_io_test("testSendReceiveCommand" testSendReceiveCommand testSendReceiveCommand.cxx) 48 | add_io_test("testDeduceToolBasedOnName" testDeduceToolBasedOnName testDeduceToolBasedOnName.cxx) 49 | add_io_test("testCommandMessageCodec" testCommandMessageCodec testCommandMessageCodec.cxx) 50 | add_io_test("testSendReceiveCommandWithCodec" testSendReceiveCommandWithCodec testSendReceiveCommandWithCodec.cxx) 51 | IF(OpenIGTLink_USE_H264 OR OpenIGTLink_USE_VP9 OR (OpenIGTLink_USE_X265 AND OpenIGTLink_USE_OpenHEVC)) 52 | add_io_test("testReceiveVideo" testReceiveVideo testReceiveVideo.cxx) 53 | add_io_test("testBufferForVideoStream" testBufferForVideoStream testBufferForVideoStream.cxx) 54 | ENDIF() -------------------------------------------------------------------------------- /Converter/igtlioStringConverter.cxx: -------------------------------------------------------------------------------- 1 | #include "igtlioStringConverter.h" 2 | 3 | #include 4 | #include 5 | 6 | //--------------------------------------------------------------------------- 7 | int igtlioStringConverter::fromIGTL(igtl::MessageBase::Pointer source, 8 | HeaderData* header, 9 | ContentData* dest, 10 | bool checkCRC, 11 | igtl::MessageBase::MetaDataMap& outMetaInfo) 12 | { 13 | // Create a message buffer to receive data 14 | igtl::StringMessage::Pointer msg; 15 | msg = igtl::StringMessage::New(); 16 | msg->Copy(source); // !! TODO: copy makes performance issue. 17 | 18 | // Deserialize the data 19 | // If CheckCRC==0, CRC check is skipped. 20 | int c = msg->Unpack(checkCRC); 21 | 22 | if ((c & igtl::MessageHeader::UNPACK_BODY) == 0) // if CRC check fails 23 | { 24 | // TODO: error handling 25 | return 0; 26 | } 27 | 28 | // get header 29 | if (!IGTLtoHeader(dynamic_pointer_cast(msg), header, outMetaInfo)) 30 | return 0; 31 | 32 | dest->string_msg = msg->GetString(); 33 | dest->encoding = msg->GetEncoding(); 34 | 35 | return 1; 36 | } 37 | 38 | //--------------------------------------------------------------------------- 39 | int igtlioStringConverter::toIGTL(const HeaderData& header, const ContentData& source, igtl::StringMessage::Pointer* dest, igtl::MessageBase::MetaDataMap metaInfo) 40 | { 41 | if (dest->IsNull()) 42 | *dest = igtl::StringMessage::New(); 43 | (*dest)->InitPack(); 44 | igtl::StringMessage::Pointer msg = *dest; 45 | 46 | if (!metaInfo.empty()) 47 | { 48 | msg->SetHeaderVersion(IGTL_HEADER_VERSION_2); 49 | } 50 | igtl::MessageBase::Pointer basemsg = dynamic_pointer_cast(msg); 51 | HeadertoIGTL(header, &basemsg, metaInfo); 52 | 53 | msg->SetString(source.string_msg); 54 | msg->SetEncoding(source.encoding); 55 | msg->Pack(); 56 | 57 | return 1; 58 | } 59 | -------------------------------------------------------------------------------- /Devices/igtlioStringDevice.h: -------------------------------------------------------------------------------- 1 | #ifndef STRINGDEVICE_H 2 | #define STRINGDEVICE_H 3 | 4 | #include "igtlioDevicesExport.h" 5 | 6 | #include "igtlioStringConverter.h" 7 | #include "igtlioDevice.h" 8 | 9 | class vtkImageData; 10 | 11 | typedef vtkSmartPointer igtlioStringDevicePointer; 12 | 13 | class OPENIGTLINKIO_DEVICES_EXPORT igtlioStringDevice : public igtlioDevice 14 | { 15 | public: 16 | enum { 17 | StringModifiedEvent = 118960, 18 | }; 19 | 20 | virtual unsigned int GetDeviceContentModifiedEvent() const VTK_OVERRIDE; 21 | virtual std::string GetDeviceType() const VTK_OVERRIDE; 22 | virtual int ReceiveIGTLMessage(igtl::MessageBase::Pointer buffer, bool checkCRC) VTK_OVERRIDE; 23 | virtual igtl::MessageBase::Pointer GetIGTLMessage() VTK_OVERRIDE; 24 | virtual igtl::MessageBase::Pointer GetIGTLMessage(MESSAGE_PREFIX prefix) VTK_OVERRIDE; 25 | virtual std::set GetSupportedMessagePrefixes() const VTK_OVERRIDE; 26 | 27 | void SetContent(igtlioStringConverter::ContentData content); 28 | igtlioStringConverter::ContentData GetContent(); 29 | 30 | public: 31 | static igtlioStringDevice *New(); 32 | vtkTypeMacro(igtlioStringDevice,igtlioDevice); 33 | 34 | void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE; 35 | 36 | protected: 37 | igtlioStringDevice(); 38 | ~igtlioStringDevice(); 39 | 40 | protected: 41 | igtl::StringMessage::Pointer OutMessage; 42 | //igtl::GetStatusMessage::Pointer GetMessage; 43 | 44 | igtlioStringConverter::ContentData Content; 45 | }; 46 | 47 | 48 | //--------------------------------------------------------------------------- 49 | class OPENIGTLINKIO_DEVICES_EXPORT igtlioStringDeviceCreator : public igtlioDeviceCreator 50 | { 51 | public: 52 | virtual igtlioDevicePointer Create(std::string device_name) VTK_OVERRIDE; 53 | virtual std::string GetDeviceType() const VTK_OVERRIDE; 54 | 55 | static igtlioStringDeviceCreator *New(); 56 | vtkTypeMacro(igtlioStringDeviceCreator,vtkObject); 57 | }; 58 | 59 | #endif // STRINGDEVICE_H 60 | -------------------------------------------------------------------------------- /Converter/igtlioStatusConverter.cxx: -------------------------------------------------------------------------------- 1 | #include "igtlioStatusConverter.h" 2 | 3 | #include 4 | #include 5 | 6 | //--------------------------------------------------------------------------- 7 | int igtlioStatusConverter::fromIGTL(igtl::MessageBase::Pointer source, 8 | HeaderData* header, 9 | ContentData* dest, 10 | bool checkCRC, 11 | igtl::MessageBase::MetaDataMap& outMetaInfo) 12 | { 13 | // Create a message buffer to receive data 14 | igtl::StatusMessage::Pointer msg; 15 | msg = igtl::StatusMessage::New(); 16 | msg->Copy(source); // !! TODO: copy makes performance issue. 17 | 18 | // Deserialize the data 19 | // If CheckCRC==0, CRC check is skipped. 20 | int c = msg->Unpack(checkCRC); 21 | 22 | if ((c & igtl::MessageHeader::UNPACK_BODY) == 0) // if CRC check fails 23 | { 24 | // TODO: error handling 25 | return 0; 26 | } 27 | 28 | // get header 29 | if (!IGTLtoHeader(dynamic_pointer_cast(msg), header, outMetaInfo)) 30 | return 0; 31 | 32 | dest->code = msg->GetCode(); 33 | dest->subcode = msg->GetSubCode(); 34 | dest->errorname = msg->GetErrorName(); 35 | dest->statusstring = msg->GetStatusString(); 36 | 37 | return 1; 38 | } 39 | 40 | //--------------------------------------------------------------------------- 41 | int igtlioStatusConverter::toIGTL(const HeaderData& header, const ContentData& source, igtl::StatusMessage::Pointer* dest, igtl::MessageBase::MetaDataMap metaInfo) 42 | { 43 | if (dest->IsNull()) 44 | *dest = igtl::StatusMessage::New(); 45 | (*dest)->InitPack(); 46 | igtl::StatusMessage::Pointer msg = *dest; 47 | if (!metaInfo.empty()) 48 | { 49 | msg->SetHeaderVersion(IGTL_HEADER_VERSION_2); 50 | } 51 | igtl::MessageBase::Pointer basemsg = dynamic_pointer_cast(msg); 52 | HeadertoIGTL(header, &basemsg, metaInfo); 53 | 54 | msg->SetCode(source.code); 55 | msg->SetSubCode(source.code); 56 | msg->SetErrorName(source.errorname.c_str()); 57 | msg->SetStatusString(source.statusstring.c_str()); 58 | msg->Pack(); 59 | 60 | return 1; 61 | } 62 | -------------------------------------------------------------------------------- /GUI/qMRMLIGTLConnectorTreeView.h: -------------------------------------------------------------------------------- 1 | /*============================================================================== 2 | 3 | Program: 3D Slicer 4 | 5 | Copyright (c) 2010 Kitware Inc. 6 | 7 | See COPYRIGHT.txt 8 | or http://www.slicer.org/copyright/copyright.txt for details. 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | This file was originally developed by Julien Finet, Kitware Inc. 17 | and was partially funded by NIH grant 3P41RR013218-12S1 18 | 19 | ==============================================================================*/ 20 | 21 | #ifndef __qMRMLIGTLConnectorTreeView_h 22 | #define __qMRMLIGTLConnectorTreeView_h 23 | 24 | // qMRML includes 25 | #include "qMRMLTreeView.h" 26 | 27 | // OpenIGTLinkIF GUI includes 28 | #include "qSlicerOpenIGTLinkIFModuleExport.h" 29 | 30 | class qMRMLIGTLConnectorTreeViewPrivate; 31 | class vtkMRMLNode; 32 | class vtkMRMLScene; 33 | class vtkSlicerOpenIGTLinkIFLogic; 34 | 35 | /// \ingroup Slicer_QtModules_OpenIGTLinkIF 36 | class Q_SLICER_QTMODULES_OPENIGTLINKIF_EXPORT qMRMLIGTLConnectorTreeView : public qMRMLTreeView 37 | { 38 | Q_OBJECT 39 | 40 | public: 41 | typedef qMRMLTreeView Superclass; 42 | qMRMLIGTLConnectorTreeView(QWidget *parent=0); 43 | virtual ~qMRMLIGTLConnectorTreeView(); 44 | 45 | void setLogic(vtkSlicerOpenIGTLinkIFLogic* logic); 46 | 47 | void setSelectedNode(const char* id); 48 | 49 | public slots: 50 | void setMRMLScene(vtkMRMLScene* scene); 51 | // void onSelectionChanged(const QItemSelection& index,const QItemSelection& beforeIndex); 52 | 53 | protected: 54 | QScopedPointer d_ptr; 55 | #ifndef QT_NO_CURSOR 56 | void mouseMoveEvent(QMouseEvent* e); 57 | bool viewportEvent(QEvent* e); 58 | #endif 59 | virtual void mousePressEvent(QMouseEvent* event); 60 | 61 | private: 62 | Q_DECLARE_PRIVATE(qMRMLIGTLConnectorTreeView); 63 | Q_DISABLE_COPY(qMRMLIGTLConnectorTreeView); 64 | 65 | }; 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /GUI/DeviceWidgets/qIGTLIODeviceWidgetFactory.cxx: -------------------------------------------------------------------------------- 1 | #include "qIGTLIODeviceWidgetFactory.h" 2 | #include 3 | #include "qIGTLIODeviceWidget.h" 4 | #include "qIGTLIOGenericDeviceWidget.h" 5 | 6 | #include "igtlioImageDevice.h" 7 | #include "qIGTLIOStatusDeviceWidget.h" 8 | #include "qIGTLIOStringDeviceWidget.h" 9 | 10 | //--------------------------------------------------------------------------- 11 | vtkStandardNewMacro(vtkIGTLIODeviceWidgetFactory); 12 | //--------------------------------------------------------------------------- 13 | vtkIGTLIODeviceWidgetFactory::vtkIGTLIODeviceWidgetFactory() 14 | { 15 | this->registerCreator(); 16 | this->registerCreator(); 17 | } 18 | 19 | //--------------------------------------------------------------------------- 20 | vtkIGTLIODeviceWidgetFactory::~vtkIGTLIODeviceWidgetFactory() 21 | { 22 | } 23 | 24 | //--------------------------------------------------------------------------- 25 | void vtkIGTLIODeviceWidgetFactory::PrintSelf(ostream &os, vtkIndent indent) 26 | { 27 | } 28 | 29 | //--------------------------------------------------------------------------- 30 | vtkIGTLIODeviceWidgetCreatorPointer vtkIGTLIODeviceWidgetFactory::GetCreator(std::string device_type) const 31 | { 32 | std::map::const_iterator iter = Creators.find(device_type); 33 | if (iter==Creators.end()) 34 | { 35 | return vtkIGTLIODeviceWidgetCreatorPointer(); 36 | } 37 | return iter->second; 38 | } 39 | 40 | //--------------------------------------------------------------------------- 41 | qIGTLIODeviceWidget* vtkIGTLIODeviceWidgetFactory::create(std::string device_type) const 42 | { 43 | vtkIGTLIODeviceWidgetCreatorPointer creator = this->GetCreator(device_type); 44 | if (!creator) 45 | return new qIGTLIOGenericDeviceWidget(); 46 | return creator->Create(); 47 | } 48 | 49 | //--------------------------------------------------------------------------- 50 | template 51 | void vtkIGTLIODeviceWidgetFactory::registerCreator() 52 | { 53 | vtkIGTLIODeviceWidgetCreatorPointer creator = vtkSmartPointer::New(); 54 | Creators[creator->GetDeviceType()] = creator; 55 | } 56 | 57 | -------------------------------------------------------------------------------- /Logic/igtlioCircularBuffer.h: -------------------------------------------------------------------------------- 1 | /*========================================================================== 2 | 3 | Portions (c) Copyright 2008-2009 Brigham and Women's Hospital (BWH) All Rights Reserved. 4 | 5 | See Doc/copyright/copyright.txt 6 | or http://www.slicer.org/copyright/copyright.txt for details. 7 | 8 | ==========================================================================*/ 9 | 10 | #ifndef IGTLIOCIRCULARBUFFER_H 11 | #define IGTLIOCIRCULARBUFFER_H 12 | 13 | // STL includes 14 | #include 15 | #include 16 | 17 | // VTK includes 18 | #include 19 | 20 | // OpenIGTLink includes 21 | #include 22 | 23 | // Local includes 24 | #include "igtlioLogicExport.h" 25 | 26 | #define IGTLCB_CIRC_BUFFER_SIZE 3 27 | 28 | #ifndef VTK_OVERRIDE 29 | #define VTK_OVERRIDE override 30 | #endif 31 | 32 | class vtkCriticalSection; 33 | 34 | class OPENIGTLINKIO_LOGIC_EXPORT igtlioCircularBuffer : public vtkObject 35 | { 36 | public: 37 | static igtlioCircularBuffer *New(); 38 | vtkTypeMacro(igtlioCircularBuffer, vtkObject); 39 | 40 | void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE; 41 | 42 | int GetNumberOfBuffer() { return IGTLCB_CIRC_BUFFER_SIZE; } 43 | 44 | int StartPush(); 45 | void EndPush(); 46 | igtl::MessageBase::Pointer GetPushBuffer(); 47 | 48 | int StartPull(); 49 | void EndPull(); 50 | igtl::MessageBase::Pointer GetPullBuffer(); 51 | 52 | int IsUpdated() { return this->UpdateFlag; }; 53 | 54 | protected: 55 | igtlioCircularBuffer(); 56 | virtual ~igtlioCircularBuffer(); 57 | 58 | protected: 59 | 60 | std::recursive_mutex Mutex; 61 | int Last; // updated by connector thread 62 | int InPush; // updated by connector thread 63 | int InUse; // updated by main thread 64 | 65 | int UpdateFlag; // non-zero if updated since StartPull() has called 66 | 67 | std::string DeviceType[IGTLCB_CIRC_BUFFER_SIZE]; 68 | long long Size[IGTLCB_CIRC_BUFFER_SIZE]; 69 | unsigned char* Data[IGTLCB_CIRC_BUFFER_SIZE]; 70 | 71 | igtl::MessageBase::Pointer Messages[IGTLCB_CIRC_BUFFER_SIZE]; 72 | 73 | }; 74 | 75 | #endif //IGTLIOCIRCULARBUFFER_H 76 | -------------------------------------------------------------------------------- /Logic/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(igtlioLogic) 2 | 3 | set(${PROJECT_NAME}_EXPORT_DIRECTIVE "OPENIGTLINKIO_LOGIC_EXPORT") 4 | 5 | set(VTK_MODULES 6 | ${IGTLIO_MODULE_PREFIX}IOImage 7 | ${IGTLIO_MODULE_PREFIX}ImagingMath 8 | ) 9 | 10 | find_package(VTK REQUIRED NO_MODULE 11 | COMPONENTS 12 | ${VTK_MODULES} 13 | ) 14 | 15 | if(VTK_VERSION VERSION_LESS 8.9.0) 16 | include(${VTK_USE_FILE}) 17 | endif() 18 | 19 | set(${PROJECT_NAME}_INCLUDE_DIRECTORIES PUBLIC 20 | $ 21 | $ 22 | $ 23 | ) 24 | 25 | set(${PROJECT_NAME}_SRCS 26 | igtlioUtilities.cxx 27 | igtlioObject.cxx 28 | igtlioDeviceFactory.cxx 29 | igtlioCircularBuffer.cxx 30 | igtlioCircularSectionBuffer.cxx 31 | igtlioConnector.cxx 32 | igtlioSession.cxx 33 | igtlioLogic.cxx 34 | igtlioCommand.cxx 35 | ) 36 | 37 | set(${PROJECT_NAME}_HDRS 38 | igtlioUtilities.h 39 | igtlioObject.h 40 | igtlioDeviceFactory.h 41 | igtlioCircularBuffer.h 42 | igtlioCircularSectionBuffer.h 43 | igtlioConnector.h 44 | igtlioSession.h 45 | igtlioCommand.h 46 | ) 47 | 48 | set(${PROJECT_NAME}_TARGET_LIBRARIES 49 | igtlioDevices 50 | ${OpenIGTLink_LIBRARIES} 51 | ${IGTLIO_VTK_PREFIX}CommonSystem 52 | ${VTK_LIBRARIES} 53 | ) 54 | 55 | add_library(${PROJECT_NAME} ${${PROJECT_NAME}_SRCS}) 56 | target_link_libraries(${PROJECT_NAME} ${${PROJECT_NAME}_TARGET_LIBRARIES}) 57 | target_include_directories(${PROJECT_NAME} ${${PROJECT_NAME}_INCLUDE_DIRECTORIES}) 58 | 59 | generate_export_header(${PROJECT_NAME} EXPORT_FILE_NAME ${PROJECT_NAME}Export.h EXPORT_MACRO_NAME ${${PROJECT_NAME}_EXPORT_DIRECTIVE} ) 60 | 61 | # -------------------------------------------------------------------------- 62 | 63 | INSTALL(TARGETS ${PROJECT_NAME} EXPORT OpenIGTLinkIO 64 | RUNTIME DESTINATION "${OpenIGTLinkIO_BINARY_INSTALL}" COMPONENT RuntimeLibraries 65 | LIBRARY DESTINATION "${OpenIGTLinkIO_LIBRARY_INSTALL}" COMPONENT RuntimeLibraries 66 | ARCHIVE DESTINATION "${OpenIGTLinkIO_ARCHIVE_INSTALL}" COMPONENT Development 67 | ) 68 | 69 | INSTALL(FILES 70 | ${${PROJECT_NAME}_HDRS} "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Export.h" DESTINATION "${OpenIGTLinkIO_INCLUDE_INSTALL}" COMPONENT Includes 71 | ) -------------------------------------------------------------------------------- /Converter/igtlioImageConverter.h: -------------------------------------------------------------------------------- 1 | /*========================================================================== 2 | 3 | Portions (c) Copyright 2008-2009 Brigham and Women's Hospital (BWH) All Rights Reserved. 4 | 5 | See Doc/copyright/copyright.txt 6 | or http://www.slicer.org/copyright/copyright.txt for details. 7 | 8 | Program: 3D Slicer 9 | Module: $HeadURL: http://svn.slicer.org/Slicer3/trunk/Modules/OpenIGTLinkIF/vtkIGTLToMRMLImage.h $ 10 | Date: $Date: 2010-11-23 00:58:13 -0500 (Tue, 23 Nov 2010) $ 11 | Version: $Revision: 15552 $ 12 | 13 | ==========================================================================*/ 14 | 15 | #ifndef IGTLIOIMAGECONVERTER_H 16 | #define IGTLIOIMAGECONVERTER_H 17 | 18 | #include "igtlioConverterExport.h" 19 | 20 | #include 21 | 22 | #include "igtlioBaseConverter.h" 23 | 24 | class vtkImageData; 25 | class vtkMatrix4x4; 26 | 27 | /** Conversion between igtl::ImageMessage and vtk classes. 28 | * 29 | */ 30 | class OPENIGTLINKIO_CONVERTER_EXPORT igtlioImageConverter : public igtlioBaseConverter 31 | { 32 | public: 33 | /** 34 | * This structure contains everything that igtl::ImageMessage is able to contain, 35 | * in a vtk-friendly format. 36 | */ 37 | struct ContentData 38 | { 39 | vtkSmartPointer image; 40 | vtkSmartPointer transform; // ijk2ras, From image pixel space to RAS 41 | }; 42 | 43 | static const char* GetIGTLName() { return GetIGTLTypeName(); } 44 | static const char* GetIGTLTypeName() { return "IMAGE"; } 45 | 46 | static int fromIGTL(igtl::MessageBase::Pointer source, HeaderData* header, ContentData* content, bool checkCRC, igtl::MessageBase::MetaDataMap& outMetaInfo); 47 | static int toIGTL(const HeaderData& header, const ContentData& source, igtl::ImageMessage::Pointer* dest, igtl::MessageBase::MetaDataMap metaInfo = igtl::MessageBase::MetaDataMap()); 48 | 49 | static int IGTLToVTKScalarType(int igtlType); 50 | static int IGTLToVTKImageData(igtl::ImageMessage::Pointer imgMsg, ContentData* dest); 51 | 52 | static int IGTLImageToVTKTransform(igtl::ImageMessage::Pointer imgMsg, vtkSmartPointer ijk2ras); 53 | static int VTKTransformToIGTLImage(const vtkMatrix4x4& ijk2ras, int imageSize[3], double spacing[3], double origin[3], igtl::ImageMessage::Pointer imgMsg); 54 | 55 | }; 56 | 57 | #endif //IGTLIOIMAGECONVERTER_H 58 | -------------------------------------------------------------------------------- /Converter/igtlioTransformConverter.h: -------------------------------------------------------------------------------- 1 | /*========================================================================== 2 | 3 | Portions (c) Copyright 2008-2009 Brigham and Women's Hospital (BWH) All Rights Reserved. 4 | 5 | See Doc/copyright/copyright.txt 6 | or http://www.slicer.org/copyright/copyright.txt for details. 7 | 8 | Program: 3D Slicer 9 | Module: $HeadURL: http://svn.slicer.org/Slicer3/trunk/Modules/OpenIGTLinkIF/vtkIGTLToMRMLImage.h $ 10 | Date: $Date: 2010-11-23 00:58:13 -0500 (Tue, 23 Nov 2010) $ 11 | Version: $Revision: 15552 $ 12 | 13 | ==========================================================================*/ 14 | 15 | #ifndef IGTLIOTRANSFORMCONVERTER_H 16 | #define IGTLIOTRANSFORMCONVERTER_H 17 | 18 | #include "igtlioConverterExport.h" 19 | 20 | #include 21 | 22 | #include "igtlioBaseConverter.h" 23 | 24 | class vtkMatrix4x4; 25 | 26 | /** Conversion between igtl::TransformMessage and vtk classes. 27 | * 28 | */ 29 | class OPENIGTLINKIO_CONVERTER_EXPORT igtlioTransformConverter : public igtlioBaseConverter 30 | { 31 | public: 32 | /** 33 | * This structure contains everything that igtl::TransformMessage is able to contain, 34 | * in a vtk-friendly format. 35 | */ 36 | struct ContentData 37 | { 38 | vtkSmartPointer transform; 39 | std::string deviceName; 40 | std::string streamIdTo; 41 | std::string streamIdFrom; 42 | }; 43 | 44 | static const char* GetIGTLName() { return GetIGTLTypeName(); }; 45 | static const char* GetIGTLTypeName() { return "TRANSFORM"; }; 46 | 47 | static int fromIGTL(igtl::MessageBase::Pointer source, HeaderData* header, ContentData* content, bool checkCRC, igtl::MessageBase::MetaDataMap& outMetaInfo); 48 | static int toIGTL(const HeaderData& header, const ContentData& source, igtl::TransformMessage::Pointer* dest, igtl::MessageBase::MetaDataMap metaInfo = igtl::MessageBase::MetaDataMap()); 49 | 50 | static int IGTLToVTKTransform(const igtl::Matrix4x4& igtlTransform, vtkSmartPointer vtkTransform); 51 | static int VTKToIGTLTransform(const vtkMatrix4x4& vtkTransform, igtl::Matrix4x4& igtlTransform); 52 | 53 | private: 54 | static int IGTLHeaderToTransformInfo(igtl::MessageBase::Pointer source, ContentData* dest); 55 | static int TransformMetaDataToIGTL(const ContentData& source, igtl::MessageBase::Pointer *dest); 56 | 57 | }; 58 | 59 | #endif //IGTLIOTRANSFORMCONVERTER_H 60 | -------------------------------------------------------------------------------- /GUI/vtkIGTLIONode.h: -------------------------------------------------------------------------------- 1 | #ifndef VTKIGTLIONODE_H 2 | #define VTKIGTLIONODE_H 3 | 4 | // igtlio includes 5 | #include "igtlioGUIExport.h" 6 | 7 | #include "igtlioLogic.h" 8 | #include "igtlioConnector.h" 9 | 10 | #include 11 | 12 | typedef QSharedPointer qIGTLIODevicesModelNodePointer; 13 | 14 | //class vtkIGTLIONode 15 | //{ 16 | //}; 17 | 18 | /// Convenience class for holding each tree item. 19 | /// 20 | /// There are three levels/types of nodes: connector, group and device. 21 | /// - connector: only connector field defined 22 | /// - group: connector and group fields defined 23 | /// - device: connect, group, device fields defined 24 | class OPENIGTLINKIO_GUI_EXPORT qIGTLIODevicesModelNode 25 | { 26 | public: 27 | enum NODE_TYPE { 28 | NODE_TYPE_ROOT, 29 | NODE_TYPE_CONNECTOR, 30 | NODE_TYPE_GROUP, 31 | NODE_TYPE_DEVICE, 32 | }; 33 | bool isRoot() const { return type==NODE_TYPE_ROOT; } 34 | bool isConnector() const { return type==NODE_TYPE_CONNECTOR; } 35 | bool isGroup() const { return type==NODE_TYPE_GROUP; } 36 | bool isDevice() const { return type==NODE_TYPE_DEVICE; } 37 | 38 | static qIGTLIODevicesModelNodePointer createRoot(igtlioLogic* logic_); 39 | bool operator==(const qIGTLIODevicesModelNode& rhs) const; 40 | std::string GetName(); 41 | qIGTLIODevicesModelNode* GetChild(int row); 42 | qIGTLIODevicesModelNode* GetParent(); 43 | 44 | int GetNumberOfChildren() const; 45 | /// get the index of this node among its siblings 46 | int GetSiblingIndex() const; 47 | void PrintSelf(ostream& os, vtkIndent indent); 48 | 49 | qIGTLIODevicesModelNode* FindDeviceNode(igtlioDevice* device_); 50 | 51 | igtlioDevice* device; 52 | igtlioConnector* connector; 53 | 54 | private: 55 | qIGTLIODevicesModelNode* GetNode(igtlioConnector* connector=NULL, igtlioDevice::MESSAGE_DIRECTION group=igtlioDevice::NUM_MESSAGE_DIRECTION, igtlioDevice* device=NULL); 56 | qIGTLIODevicesModelNode(qIGTLIODevicesModelNode* parent_, igtlioLogic* logic_, igtlioConnector* connector_=NULL, igtlioDevice::MESSAGE_DIRECTION group_=igtlioDevice::NUM_MESSAGE_DIRECTION, igtlioDevice* device_=NULL); 57 | std::vector GetDevicesInGroup() const; 58 | NODE_TYPE type; 59 | igtlioLogic* logic; 60 | igtlioDevice::MESSAGE_DIRECTION group; 61 | mutable std::set Children; 62 | qIGTLIODevicesModelNode* Parent; 63 | }; 64 | 65 | 66 | 67 | #endif // VTKIGTLIONODE_H 68 | -------------------------------------------------------------------------------- /Devices/igtlioTrackingDataDevice.h: -------------------------------------------------------------------------------- 1 | /*========================================================================== 2 | 3 | Portions (c) Copyright 2019 Robarts Research Institute All Rights Reserved. 4 | 5 | ==========================================================================*/ 6 | 7 | #ifndef IGTLIOTDATADEVICE_H 8 | #define IGTLIOTDATADEVICE_H 9 | 10 | #include "igtlioDevicesExport.h" 11 | 12 | #include "igtlioTrackingDataConverter.h" 13 | #include "igtlioDevice.h" 14 | 15 | class vtkImageData; 16 | 17 | typedef vtkSmartPointer igtlioTrackingDataDevicePointer; 18 | 19 | /// A Device supporting the IMAGE igtl Message. 20 | class OPENIGTLINKIO_DEVICES_EXPORT igtlioTrackingDataDevice : public igtlioDevice 21 | { 22 | public: 23 | enum 24 | { 25 | TDATAModifiedEvent = 118957, 26 | StartTDATAEvent = 118970, 27 | StopTDATAEvent = 118971 28 | }; 29 | 30 | virtual unsigned int GetDeviceContentModifiedEvent() const VTK_OVERRIDE; 31 | virtual std::string GetDeviceType() const VTK_OVERRIDE; 32 | virtual int ReceiveIGTLMessage(igtl::MessageBase::Pointer buffer, bool checkCRC) VTK_OVERRIDE; 33 | virtual igtl::MessageBase::Pointer GetIGTLMessage() VTK_OVERRIDE; 34 | virtual igtl::MessageBase::Pointer GetIGTLMessage(MESSAGE_PREFIX prefix) VTK_OVERRIDE; 35 | virtual std::set GetSupportedMessagePrefixes() const VTK_OVERRIDE; 36 | 37 | void SetContent(igtlioTrackingDataConverter::ContentData content); 38 | igtlioTrackingDataConverter::ContentData GetContent(); 39 | 40 | public: 41 | static igtlioTrackingDataDevice* New(); 42 | vtkTypeMacro(igtlioTrackingDataDevice, igtlioDevice); 43 | void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE; 44 | 45 | protected: 46 | igtlioTrackingDataDevice(); 47 | ~igtlioTrackingDataDevice(); 48 | 49 | protected: 50 | igtl::TrackingDataMessage::Pointer OutTDATAMessage; 51 | igtl::StartTrackingDataMessage::Pointer StartTDATAMessage; 52 | igtl::StopTrackingDataMessage::Pointer StopTDATAMessage; 53 | 54 | igtlioTrackingDataConverter::ContentData Content; 55 | }; 56 | 57 | //--------------------------------------------------------------------------- 58 | class OPENIGTLINKIO_DEVICES_EXPORT igtlioTrackingDataDeviceCreator : public igtlioDeviceCreator 59 | { 60 | public: 61 | virtual igtlioDevicePointer Create(std::string device_name) VTK_OVERRIDE; 62 | virtual std::string GetDeviceType() const VTK_OVERRIDE; 63 | 64 | static igtlioTrackingDataDeviceCreator* New(); 65 | vtkTypeMacro(igtlioTrackingDataDeviceCreator, vtkObject); 66 | }; 67 | 68 | #endif //IGTLIOTDATADEVICE_H 69 | -------------------------------------------------------------------------------- /Converter/igtlioTrackingDataConverter.h: -------------------------------------------------------------------------------- 1 | /*========================================================================== 2 | 3 | Portions (c) Copyright 2019 Robarts Research Institute All Rights Reserved. 4 | 5 | ==========================================================================*/ 6 | 7 | #ifndef IGTLIOTDATACONVERTER_H 8 | #define IGTLIOTDATACONVERTER_H 9 | 10 | // Local includes 11 | #include "igtlioConverterExport.h" 12 | #include "igtlioBaseConverter.h" 13 | 14 | // OpenIGTLink includes 15 | #include 16 | 17 | // STL includes 18 | #include 19 | 20 | class vtkMatrix4x4; 21 | 22 | /** Conversion between igtl::TDATAMessage and vtk classes. 23 | * 24 | */ 25 | class OPENIGTLINKIO_CONVERTER_EXPORT igtlioTrackingDataConverter : public igtlioBaseConverter 26 | { 27 | public: 28 | /** 29 | * This structure contains everything that igtl::TDATAMessage is able to contain, 30 | * in a vtk-friendly format. 31 | */ 32 | struct ContentEntry 33 | { 34 | ContentEntry() {} 35 | ContentEntry(vtkSmartPointer _transform, std::string _deviceName, std::string _transformName) 36 | : transform(_transform) 37 | , deviceName(_deviceName) 38 | , transformName(_transformName) {} 39 | vtkSmartPointer transform; 40 | std::string deviceName; 41 | std::string transformName; 42 | igtlUint8 type; 43 | }; 44 | struct ContentData 45 | { 46 | std::map trackingDataElements; 47 | }; 48 | 49 | static const char* GetIGTLName() { return GetIGTLTypeName(); }; 50 | static const char* GetIGTLTypeName() { return "TDATA"; }; 51 | 52 | static int fromIGTL(igtl::MessageBase::Pointer source, HeaderData* header, ContentData* content, bool checkCRC, igtl::MessageBase::MetaDataMap& outMetaInfo); 53 | static int toIGTL(const HeaderData& header, const ContentData& source, igtl::TrackingDataMessage::Pointer* dest, igtl::MessageBase::MetaDataMap metaInfo = igtl::MessageBase::MetaDataMap()); 54 | 55 | static int fromIGTLResponse(igtl::MessageBase::Pointer source, HeaderData *header, ContentData *dest, bool checkCRC, igtl::MessageBase::MetaDataMap& outMetaInfo); 56 | 57 | static int IGTLToVTKTDATA(const igtl::Matrix4x4& igtlTDATA, vtkSmartPointer vtkTDATA); 58 | static int VTKToIGTLTDATA(const vtkMatrix4x4& vtkTDATA, igtl::Matrix4x4& igtlTDATA); 59 | 60 | private: 61 | static int IGTLHeaderToTDATAInfo(igtl::MessageBase::Pointer source, ContentData* dest); 62 | static int TDATAMetaDataToIGTL(const ContentData& source, igtl::MessageBase::Pointer* dest); 63 | 64 | }; 65 | 66 | #endif //IGTLIOTDATACONVERTER_H 67 | -------------------------------------------------------------------------------- /Devices/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(igtlioDevices) 2 | 3 | set(${PROJECT_NAME}_EXPORT_DIRECTIVE "OPENIGTLINKIO_DEVICES_EXPORT") 4 | 5 | set(VTK_MODULES 6 | ${IGTLIO_MODULE_PREFIX}CommonSystem 7 | ${IGTLIO_MODULE_PREFIX}IOImage 8 | ${IGTLIO_MODULE_PREFIX}ImagingMath 9 | ) 10 | 11 | find_package(VTK REQUIRED NO_MODULE 12 | COMPONENTS 13 | ${VTK_MODULES} 14 | ) 15 | 16 | if(VTK_VERSION VERSION_LESS 8.9.0) 17 | include(${VTK_USE_FILE}) 18 | endif() 19 | 20 | set(${PROJECT_NAME}_INCLUDE_DIRECTORIES PUBLIC 21 | $ 22 | $ 23 | $ 24 | ) 25 | 26 | set(${PROJECT_NAME}_SRCS 27 | igtlioDevice.cxx 28 | igtlioImageDevice.cxx 29 | igtlioImageMetaDevice.cxx 30 | igtlioLabelMetaDevice.cxx 31 | igtlioPointDevice.cxx 32 | igtlioPolyDataDevice.cxx 33 | igtlioStatusDevice.cxx 34 | igtlioStringDevice.cxx 35 | igtlioTransformDevice.cxx 36 | igtlioTrackingDataDevice.cxx 37 | ) 38 | 39 | set(${PROJECT_NAME}_HDRS 40 | igtlioDevice.h 41 | igtlioImageDevice.h 42 | igtlioImageMetaDevice.h 43 | igtlioLabelMetaDevice.h 44 | igtlioPointDevice.h 45 | igtlioPolyDataDevice.h 46 | igtlioStatusDevice.h 47 | igtlioStringDevice.h 48 | igtlioTransformDevice.h 49 | igtlioTrackingDataDevice.h 50 | ) 51 | 52 | IF(OpenIGTLink_ENABLE_VIDEOSTREAMING) 53 | LIST(APPEND ${PROJECT_NAME}_SRCS 54 | igtlioVideoDevice.cxx 55 | ) 56 | LIST(APPEND ${PROJECT_NAME}_HDRS 57 | igtlioVideoDevice.h 58 | ) 59 | ENDIF() 60 | 61 | set(${PROJECT_NAME}_TARGET_LIBRARIES 62 | igtlioConverter 63 | ${OpenIGTLink_LIBRARIES} 64 | ${VTK_LIBRARIES} 65 | ) 66 | 67 | add_library(${PROJECT_NAME} ${${PROJECT_NAME}_SRCS} ${${PROJECT_NAME}_HDRS}) 68 | target_link_libraries(${PROJECT_NAME} ${${PROJECT_NAME}_TARGET_LIBRARIES}) 69 | target_include_directories(${PROJECT_NAME} ${${PROJECT_NAME}_INCLUDE_DIRECTORIES}) 70 | 71 | generate_export_header(${PROJECT_NAME} EXPORT_FILE_NAME ${PROJECT_NAME}Export.h EXPORT_MACRO_NAME ${${PROJECT_NAME}_EXPORT_DIRECTIVE}) 72 | 73 | # -------------------------------------------------------------------------- 74 | 75 | INSTALL(TARGETS ${PROJECT_NAME} EXPORT OpenIGTLinkIO 76 | RUNTIME DESTINATION "${OpenIGTLinkIO_BINARY_INSTALL}" COMPONENT RuntimeLibraries 77 | LIBRARY DESTINATION "${OpenIGTLinkIO_LIBRARY_INSTALL}" COMPONENT RuntimeLibraries 78 | ARCHIVE DESTINATION "${OpenIGTLinkIO_ARCHIVE_INSTALL}" COMPONENT Development 79 | ) 80 | 81 | INSTALL(FILES ${${PROJECT_NAME}_HDRS} "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Export.h" DESTINATION "${OpenIGTLinkIO_INCLUDE_INSTALL}" COMPONENT Includes) 82 | -------------------------------------------------------------------------------- /Devices/igtlioImageDevice.h: -------------------------------------------------------------------------------- 1 | /*========================================================================== 2 | 3 | Portions (c) Copyright 2008-2009 Brigham and Women's Hospital (BWH) All Rights Reserved. 4 | 5 | See Doc/copyright/copyright.txt 6 | or http://www.slicer.org/copyright/copyright.txt for details. 7 | 8 | Program: 3D Slicer 9 | Module: $HeadURL: http://svn.slicer.org/Slicer3/trunk/Modules/OpenIGTLinkIF/vtkIGTLToMRMLImage.h $ 10 | Date: $Date: 2010-11-23 00:58:13 -0500 (Tue, 23 Nov 2010) $ 11 | Version: $Revision: 15552 $ 12 | 13 | ==========================================================================*/ 14 | 15 | #ifndef IGTLIOIMAGEDEVICE_H 16 | #define IGTLIOIMAGEDEVICE_H 17 | 18 | #include "igtlioDevicesExport.h" 19 | 20 | #include "igtlioImageConverter.h" 21 | #include "igtlioDevice.h" 22 | 23 | 24 | class vtkImageData; 25 | 26 | typedef vtkSmartPointer igtlioImageDevicePointer; 27 | 28 | /// A Device supporting the IMAGE igtl Message. 29 | class OPENIGTLINKIO_DEVICES_EXPORT igtlioImageDevice : public igtlioDevice 30 | { 31 | public: 32 | 33 | enum { 34 | ImageModifiedEvent = 118955, 35 | }; 36 | 37 | virtual unsigned int GetDeviceContentModifiedEvent() const VTK_OVERRIDE ; 38 | virtual std::string GetDeviceType() const VTK_OVERRIDE; 39 | virtual int ReceiveIGTLMessage(igtl::MessageBase::Pointer buffer, bool checkCRC) VTK_OVERRIDE; 40 | virtual igtl::MessageBase::Pointer GetIGTLMessage() VTK_OVERRIDE; 41 | virtual igtl::MessageBase::Pointer GetIGTLMessage(MESSAGE_PREFIX prefix) VTK_OVERRIDE; 42 | virtual std::set GetSupportedMessagePrefixes() const VTK_OVERRIDE; 43 | 44 | void SetContent(igtlioImageConverter::ContentData content); 45 | igtlioImageConverter::ContentData GetContent(); 46 | 47 | public: 48 | static igtlioImageDevice *New(); 49 | vtkTypeMacro(igtlioImageDevice, igtlioDevice); 50 | void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE; 51 | 52 | protected: 53 | igtlioImageDevice(); 54 | ~igtlioImageDevice(); 55 | 56 | protected: 57 | igtl::ImageMessage::Pointer OutImageMessage; 58 | igtl::GetImageMessage::Pointer GetImageMessage; 59 | 60 | igtlioImageConverter::ContentData Content; 61 | }; 62 | 63 | //--------------------------------------------------------------------------- 64 | class OPENIGTLINKIO_DEVICES_EXPORT igtlioImageDeviceCreator : public igtlioDeviceCreator 65 | { 66 | public: 67 | virtual igtlioDevicePointer Create(std::string device_name) VTK_OVERRIDE; 68 | virtual std::string GetDeviceType() const VTK_OVERRIDE; 69 | 70 | static igtlioImageDeviceCreator *New(); 71 | vtkTypeMacro(igtlioImageDeviceCreator,vtkObject); 72 | }; 73 | 74 | #endif //IGTLIOIMAGEDEVICE_H 75 | -------------------------------------------------------------------------------- /GUI/qIGTLIOConnectorPropertyWidget.h: -------------------------------------------------------------------------------- 1 | /*============================================================================== 2 | 3 | Program: 3D Slicer 4 | 5 | Copyright (c) 2011 Kitware Inc. 6 | 7 | See COPYRIGHT.txt 8 | or http://www.slicer.org/copyright/copyright.txt for details. 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | This file was originally developed by Jean-Christophe Fillion-Robin, Kitware Inc. 17 | and was partially funded by NIH grant 3P41RR013218-12S1 18 | 19 | ==============================================================================*/ 20 | 21 | #ifndef __qIGTLIOConnectorPropertyWidget_h 22 | #define __qIGTLIOConnectorPropertyWidget_h 23 | 24 | // Qt includes 25 | #include 26 | 27 | #include "qIGTLIOVtkConnectionMacro.h" 28 | 29 | // igtlio includes 30 | #include "igtlioGUIExport.h" 31 | #include "igtlioConnector.h" 32 | #include 33 | 34 | typedef vtkSmartPointer igtlioConnectorPointer; 35 | 36 | class qIGTLIOConnectorPropertyWidgetPrivate; 37 | 38 | class vtkObject; 39 | 40 | /// \ingroup Slicer_QtModules_OpenIGTLinkIF 41 | class OPENIGTLINKIO_GUI_EXPORT qIGTLIOConnectorPropertyWidget : public QWidget 42 | { 43 | Q_OBJECT 44 | IGTLIO_QVTK_OBJECT 45 | 46 | public: 47 | typedef QWidget Superclass; 48 | qIGTLIOConnectorPropertyWidget(QWidget *parent = 0); 49 | virtual ~qIGTLIOConnectorPropertyWidget(); 50 | 51 | public slots: 52 | /// Set the MRML node of interest 53 | void setMRMLIGTLConnectorNode(igtlioConnectorPointer connectorNode); 54 | igtlioConnectorPointer getMRMLIGTLConnectorNode(); 55 | 56 | // /// Utility function that calls setMRMLIGTLConnectorNode(vtkMRMLIGTLConnectorNode*) 57 | // /// It's useful to connect to vtkMRMLNode* signals when you are sure of 58 | // /// the type 59 | // void setMRMLIGTLConnectorNode(vtkMRMLNode* node); 60 | 61 | protected slots: 62 | /// Internal function to update the widgets based on the IGTLConnector node 63 | void onMRMLNodeModified(); 64 | 65 | void startCurrentIGTLConnector(bool enabled); 66 | 67 | /// Internal function to update the IGTLConnector node based on the property widget 68 | void updateIGTLConnectorNode(); 69 | 70 | protected: 71 | QScopedPointer d_ptr; 72 | 73 | private: 74 | Q_DECLARE_PRIVATE(qIGTLIOConnectorPropertyWidget); 75 | Q_DISABLE_COPY(qIGTLIOConnectorPropertyWidget); 76 | }; 77 | 78 | #endif 79 | 80 | -------------------------------------------------------------------------------- /GUI/qSlicerIGTLIONodeSelectorWidget.h: -------------------------------------------------------------------------------- 1 | /*============================================================================== 2 | 3 | Program: 3D Slicer 4 | 5 | Copyright (c) 2011 Kitware Inc. 6 | 7 | See COPYRIGHT.txt 8 | or http://www.slicer.org/copyright/copyright.txt for details. 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | This file was originally developed by Jean-Christophe Fillion-Robin, Kitware Inc. 17 | and was partially funded by NIH grant 3P41RR013218-12S1 18 | 19 | ==============================================================================*/ 20 | 21 | #ifndef __qSlicerIGTLIONodeSelectorWidget_h 22 | #define __qSlicerIGTLIONodeSelectorWidget_h 23 | 24 | // Qt includes 25 | #include 26 | 27 | // CTK includes 28 | #include 29 | 30 | 31 | // OpenIGTLinkIF GUI includes 32 | #include "qSlicerOpenIGTLinkIFModuleExport.h" 33 | 34 | class qSlicerIGTLIONodeSelectorWidgetPrivate; 35 | class vtkMRMLIGTLConnectorNode; 36 | class vtkMRMLNode; 37 | class vtkMRMLScene; 38 | class vtkObject; 39 | 40 | /// \ingroup Slicer_QtModules_OpenIGTLinkIF 41 | class Q_SLICER_QTMODULES_OPENIGTLINKIF_EXPORT qSlicerIGTLIONodeSelectorWidget : public QWidget 42 | { 43 | Q_OBJECT 44 | QVTK_OBJECT 45 | public: 46 | typedef QWidget Superclass; 47 | qSlicerIGTLIONodeSelectorWidget(QWidget *parent = 0); 48 | virtual ~qSlicerIGTLIONodeSelectorWidget(); 49 | 50 | enum { 51 | UNDEFINED, 52 | INCOMING, 53 | OUTGOING 54 | }; 55 | 56 | public slots: 57 | 58 | /// Set the MRML scene 59 | void setMRMLScene(vtkMRMLScene* scene); 60 | 61 | /// Set the MRML node of interest 62 | //void setCurrentNode(vtkMRMLNode* node); 63 | 64 | /// Set the MRML node of interest 65 | void updateEnabledStatus(int type, vtkMRMLIGTLConnectorNode* cnode, int dir, vtkMRMLNode* dnode); 66 | 67 | 68 | 69 | protected slots: 70 | /// Add node to the I/O tree 71 | void onAddNodeButtonClicked(); 72 | 73 | /// Remove node from the I/O tree 74 | void onRemoveNodeButtonClicked(); 75 | 76 | /// Send node from the I/O tree 77 | void onSendButtonClicked(); 78 | 79 | signals: 80 | //void addNode(vtkMRMLNode*); 81 | //void removeNode(vtkMRMLNode*); 82 | 83 | protected: 84 | QScopedPointer d_ptr; 85 | 86 | private: 87 | Q_DECLARE_PRIVATE(qSlicerIGTLIONodeSelectorWidget); 88 | Q_DISABLE_COPY(qSlicerIGTLIONodeSelectorWidget); 89 | }; 90 | 91 | #endif 92 | 93 | -------------------------------------------------------------------------------- /Devices/igtlioPolyDataDevice.h: -------------------------------------------------------------------------------- 1 | /*========================================================================== 2 | 3 | Portions (c) Copyright 2008-2009 Brigham and Women's Hospital (BWH) All Rights Reserved. 4 | 5 | See Doc/copyright/copyright.txt 6 | or http://www.slicer.org/copyright/copyright.txt for details. 7 | 8 | Program: 3D Slicer 9 | Module: $HeadURL: https://github.com/openigtlink/OpenIGTLinkIF/blob/master/MRML/vtkIGTLToMRMLPolyData.h $ 10 | Date: $Date: 2010-11-23 00:58:13 -0500 (Tue, 23 Nov 2010) $ 11 | Version: $Revision: 15552 $ 12 | 13 | ==========================================================================*/ 14 | 15 | 16 | #ifndef IGTLIOPOLYDATADEVICE_H 17 | #define IGTLIOPOLYDATADEVICE_H 18 | 19 | #include "igtlioDevicesExport.h" 20 | 21 | #include "igtlioPolyDataConverter.h" 22 | #include "igtlioDevice.h" 23 | 24 | class vtkPolyDataData; 25 | typedef vtkSmartPointer igtlioPolyDataDevicePointer; 26 | 27 | class OPENIGTLINKIO_DEVICES_EXPORT igtlioPolyDataDevice : public igtlioDevice 28 | { 29 | public: 30 | 31 | enum { 32 | PolyDataModifiedEvent = 118959, 33 | }; 34 | 35 | virtual unsigned int GetDeviceContentModifiedEvent() const VTK_OVERRIDE; 36 | virtual std::string GetDeviceType() const VTK_OVERRIDE; 37 | virtual int ReceiveIGTLMessage(igtl::MessageBase::Pointer buffer, bool checkCRC) VTK_OVERRIDE; 38 | virtual igtl::MessageBase::Pointer GetIGTLMessage() VTK_OVERRIDE; 39 | virtual igtl::MessageBase::Pointer GetIGTLMessage(MESSAGE_PREFIX prefix) VTK_OVERRIDE; 40 | virtual std::set GetSupportedMessagePrefixes() const VTK_OVERRIDE; 41 | 42 | void SetContent(igtlioPolyDataConverter::ContentData content); 43 | igtlioPolyDataConverter::ContentData GetContent(); 44 | 45 | public: 46 | static igtlioPolyDataDevice *New(); 47 | vtkTypeMacro(igtlioPolyDataDevice,igtlioDevice); 48 | 49 | void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE; 50 | 51 | protected: 52 | igtlioPolyDataDevice(); 53 | ~igtlioPolyDataDevice(); 54 | 55 | protected: 56 | igtl::PolyDataMessage::Pointer OutMessage; 57 | igtl::GetPolyDataMessage::Pointer GetMessage; 58 | 59 | igtlioPolyDataConverter::ContentData Content; 60 | }; 61 | 62 | 63 | //--------------------------------------------------------------------------- 64 | class OPENIGTLINKIO_DEVICES_EXPORT igtlioPolyDataDeviceCreator : public igtlioDeviceCreator 65 | { 66 | public: 67 | virtual igtlioDevicePointer Create(std::string device_name) VTK_OVERRIDE; 68 | virtual std::string GetDeviceType() const VTK_OVERRIDE; 69 | 70 | static igtlioPolyDataDeviceCreator *New(); 71 | vtkTypeMacro(igtlioPolyDataDeviceCreator,vtkObject); 72 | 73 | }; 74 | 75 | #endif // IGTLIOPOLYDATADEVICE_H 76 | -------------------------------------------------------------------------------- /PlantUML/logicEventHandle.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | class Connector{ 3 | ..events.. 4 | ConnectedEvent = 118944 5 | DisconnectedEvent = 118945 6 | ActivatedEvent = 118946 7 | DeactivatedEvent = 118947 8 | NewDeviceEvent = 118949 9 | DeviceContentModifedEvent = 118950 10 | RemovedDeviceEvent = 118951 11 | .. 12 | +DeviceContentModified() : void 13 | InvokeEvent(DeviceContentModifedEvent) 14 | +AddDevice(): int 15 | InvokeEvent(NewDeviceEvent) 16 | +RemoveDevice(): int 17 | InvokeEvent(RemovedDeviceEvent) 18 | } 19 | 20 | class Device{ 21 | ..events.. 22 | ReceiveEvent = 118948 23 | ResponseEvent = 118952 24 | ModifiedEvent = vtkCommand::ModifiedEvent 25 | CommandReceivedEvent = 119001 26 | CommandResponseReceivedEvent = 119002 27 | .. 28 | } 29 | 30 | class CommandDevice{ 31 | ..events.. 32 | CommandModifiedEvent = 118958 33 | .. 34 | +ReceiveIGTLMessage() : int 35 | InvokeEvent(CommandReceivedEvent) 36 | InvokeEvent(CommandResponseReceivedEvent) 37 | +SetContent() 38 | InvokeEvent(ContentModifiedEvent) 39 | +CheckQueryExpiration() : int 40 | InvokeEvent(ResponseEvent) 41 | } 42 | 43 | class NonCommandDevices{ 44 | ..events.. 45 | ContentModifiedEvent = 118955-118967, 118959-118960 46 | .. 47 | +ReceiveIGTLMessage(): int 48 | InvokeEvent(ContentModifiedEvent) 49 | InvokeEvent(ReceiveEvent) 50 | +SetContent() 51 | InvokeEvent(ContentModifiedEvent) 52 | } 53 | 54 | class Logic { 55 | ..events.. 56 | ConnectionAddedEvent = 118970 57 | ConnectionAboutToBeRemovedEvent = 118971 58 | NewDeviceEvent = 118949 59 | DeviceModifiedEvent = 118950 60 | RemovedDeviceEvent = 118951 61 | CommandReceivedEvent = 119001 62 | CommandResponseReceivedEvent = 119002 63 | .... 64 | +CreateConnector(): ConnectorPointer 65 | InvokeEvent(ConnectionAddedEvent) 66 | #onDeviceEventFunc() : void 67 | #onNewDeviceEventFunc() : void 68 | #onRemovedDeviceEventFunc() : void 69 | } 70 | together { 71 | class Device 72 | class CommandDevice 73 | class NonCommandDevices 74 | } 75 | Device<|--CommandDevice 76 | Device<|--NonCommandDevices 77 | Logic"1"-->"0..*"Connector : observes 78 | Connector"1"-->"0..*"NonCommandDevices : observes 79 | Logic"1"-->"0..*"NonCommandDevices : observes 80 | Connector"1"-->"0..*"CommandDevice : observes 81 | Logic"1"-->"0..*"CommandDevice : observes 82 | 'Connector::AddDevice-->Logic::onNewDeviceEventFunc : callback 83 | 'Connector::RemovedDevice-->Logic::onRemovedDeviceEventFunc : callback 84 | 'NonCommandDevices::ReceiveIGTLMessage-->Connector::DeviceContentModified : callback 85 | 'CommandDevice::ReceiveIGTLMessage->Logic::onDeviceEventFunc: callback 86 | @enduml -------------------------------------------------------------------------------- /Converter/igtlioPolyDataConverter.h: -------------------------------------------------------------------------------- 1 | /*========================================================================== 2 | 3 | Portions (c) Copyright 2008-2009 Brigham and Women's Hospital (BWH) All Rights Reserved. 4 | 5 | See Doc/copyright/copyright.txt 6 | or http://www.slicer.org/copyright/copyright.txt for details. 7 | 8 | Program: 3D Slicer 9 | Module: $HeadURL: http://svn.slicer.org/Slicer3/trunk/Modules/OpenIGTLinkIF/vtkIGTLToMRMLImage.h $ 10 | Date: $Date: 2010-11-23 00:58:13 -0500 (Tue, 23 Nov 2010) $ 11 | Version: $Revision: 15552 $ 12 | 13 | ==========================================================================*/ 14 | 15 | #ifndef IGTLIOPOLYDATACONVERTER_H 16 | #define IGTLIOPOLYDATACONVERTER_H 17 | 18 | #include "igtlioConverterExport.h" 19 | 20 | #include 21 | #include "igtlioBaseConverter.h" 22 | 23 | class vtkPolyData; 24 | class vtkCellArray; 25 | class vtkDataSetAttributes; 26 | 27 | /** Conversion between igtl::PolyDataMessage and vtk classes. 28 | * 29 | */ 30 | class OPENIGTLINKIO_CONVERTER_EXPORT igtlioPolyDataConverter : public igtlioBaseConverter 31 | { 32 | public: 33 | /** 34 | * This structure contains everything that igtl::PolyMessage is able to contain, 35 | * in a vtk-friendly format. 36 | */ 37 | struct ContentData 38 | { 39 | vtkSmartPointer polydata; 40 | std::string deviceName; 41 | }; 42 | 43 | static const char* GetIGTLName() { return GetIGTLTypeName(); } 44 | static const char* GetIGTLTypeName() { return "POLYDATA"; } 45 | 46 | static int fromIGTL(igtl::MessageBase::Pointer source, HeaderData* header, ContentData* content, bool checkCRC, igtl::MessageBase::MetaDataMap& outMetaInfo); 47 | static int toIGTL(const HeaderData& header, const ContentData& source, igtl::PolyDataMessage::Pointer* dest, igtl::MessageBase::MetaDataMap metaInfo = igtl::MessageBase::MetaDataMap()); 48 | 49 | // Extract vtkPolyData from existing polyDataMsg, insert into existing poly. 50 | static int IGTLToVTKPolyData(igtl::PolyDataMessage::Pointer polyDataMsg, vtkSmartPointer poly); 51 | 52 | // Insert an existing vtkPolyData into a cleared PolyDataMessage. 53 | static int VTKPolyDataToIGTL(vtkSmartPointer poly, igtl::PolyDataMessage::Pointer outMessage); 54 | 55 | // Utility function for MRMLToIGTL(): Convert vtkCellArray to igtl::PolyDataCellArray 56 | static int VTKToIGTLCellArray(vtkCellArray* src, igtl::PolyDataCellArray* dest); 57 | 58 | // Utility function for MRMLToIGTL(): Convert i-th vtkDataSetAttributes (vtkCellData and vtkPointData) 59 | // to igtl::PolyDataAttribute 60 | static int VTKToIGTLAttribute(vtkDataSetAttributes* src, int i, igtl::PolyDataAttribute* dest); 61 | }; 62 | 63 | #endif //IGTLIOPOLYDATACONVERTER_H 64 | -------------------------------------------------------------------------------- /Devices/igtlioTransformDevice.h: -------------------------------------------------------------------------------- 1 | /*========================================================================== 2 | 3 | Portions (c) Copyright 2008-2009 Brigham and Women's Hospital (BWH) All Rights Reserved. 4 | 5 | See Doc/copyright/copyright.txt 6 | or http://www.slicer.org/copyright/copyright.txt for details. 7 | 8 | Program: 3D Slicer 9 | Module: $HeadURL: http://svn.slicer.org/Slicer3/trunk/Modules/OpenIGTLinkIF/vtkIGTLToMRMLImage.h $ 10 | Date: $Date: 2010-11-23 00:58:13 -0500 (Tue, 23 Nov 2010) $ 11 | Version: $Revision: 15552 $ 12 | 13 | ==========================================================================*/ 14 | 15 | #ifndef IGTLIOTRANSFORMDEVICE_H 16 | #define IGTLIOTRANSFORMDEVICE_H 17 | 18 | #include "igtlioDevicesExport.h" 19 | 20 | #include "igtlioTransformConverter.h" 21 | #include "igtlioDevice.h" 22 | 23 | class vtkImageData; 24 | 25 | typedef vtkSmartPointer igtlioTransformDevicePointer; 26 | 27 | /// A Device supporting the IMAGE igtl Message. 28 | class OPENIGTLINKIO_DEVICES_EXPORT igtlioTransformDevice : public igtlioDevice 29 | { 30 | public: 31 | enum { 32 | TransformModifiedEvent = 118957, 33 | }; 34 | 35 | virtual unsigned int GetDeviceContentModifiedEvent() const VTK_OVERRIDE; 36 | virtual std::string GetDeviceType() const VTK_OVERRIDE; 37 | virtual int ReceiveIGTLMessage(igtl::MessageBase::Pointer buffer, bool checkCRC) VTK_OVERRIDE; 38 | virtual igtl::MessageBase::Pointer GetIGTLMessage() VTK_OVERRIDE; 39 | virtual igtl::MessageBase::Pointer GetIGTLMessage(MESSAGE_PREFIX prefix) VTK_OVERRIDE; 40 | virtual std::set GetSupportedMessagePrefixes() const VTK_OVERRIDE; 41 | 42 | void SetContent(igtlioTransformConverter::ContentData content); 43 | igtlioTransformConverter::ContentData GetContent(); 44 | 45 | public: 46 | static igtlioTransformDevice *New(); 47 | vtkTypeMacro(igtlioTransformDevice,igtlioDevice); 48 | void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE; 49 | 50 | protected: 51 | igtlioTransformDevice(); 52 | ~igtlioTransformDevice(); 53 | 54 | protected: 55 | igtl::TransformMessage::Pointer OutTransformMessage; 56 | igtl::GetTransformMessage::Pointer GetTransformMessage; 57 | 58 | igtlioTransformConverter::ContentData Content; 59 | }; 60 | 61 | //--------------------------------------------------------------------------- 62 | class OPENIGTLINKIO_DEVICES_EXPORT igtlioTransformDeviceCreator : public igtlioDeviceCreator 63 | { 64 | public: 65 | virtual igtlioDevicePointer Create(std::string device_name) VTK_OVERRIDE; 66 | virtual std::string GetDeviceType() const VTK_OVERRIDE; 67 | 68 | static igtlioTransformDeviceCreator *New(); 69 | vtkTypeMacro(igtlioTransformDeviceCreator,vtkObject); 70 | }; 71 | 72 | #endif //IGTLIOTRANSFORMDEVICE_H 73 | -------------------------------------------------------------------------------- /Testing/testReceiveImage.cxx: -------------------------------------------------------------------------------- 1 | #include 2 | #include "igtlioLogic.h" 3 | #include "igtlioConnector.h" 4 | #include "vtkTimerLog.h" 5 | #include "igtlioImageDevice.h" 6 | #include "vtkImageData.h" 7 | #include "igtlioImageConverter.h" 8 | #include "vtkMatrix4x4.h" 9 | #include 10 | #include "igtlioImageConverter.h" 11 | #include 12 | #include "igtlioFixture.h" 13 | #include "igtlioImageDevice.h" 14 | #include "igtlioSession.h" 15 | #include "igtlioTestUtilities.h" 16 | 17 | int main(int argc, char **argv) 18 | { 19 | igtlioClientServerFixture fixture; 20 | 21 | if (!fixture.ConnectClientToServer()) 22 | return TEST_FAILED; 23 | 24 | 25 | if (fixture.Client.Logic->GetNumberOfDevices() != 0) 26 | { 27 | std::cout << "ERROR: Client has devices before they have been added or fundamental error!" << std::endl; 28 | return TEST_FAILED; 29 | } 30 | 31 | std::cout << "*** Connection done" << std::endl; 32 | //--------------------------------------------------------------------------- 33 | 34 | igtlioImageDevicePointer imageDevice; 35 | imageDevice = fixture.Server.Session->SendImage("TestDevice_Image", 36 | fixture.CreateTestImage(), 37 | fixture.CreateTestTransform()); 38 | std::cout << "*** Sent message from Server to Client" << std::endl; 39 | 40 | //--------------------------------------------------------------------------- 41 | 42 | if (!fixture.LoopUntilEventDetected(&fixture.Client, igtlioLogic::NewDeviceEvent)) 43 | { 44 | return TEST_FAILED; 45 | } 46 | 47 | //--------------------------------------------------------------------------- 48 | // The device modified event should be invoke when the setContent was called in the device 49 | if (!fixture.LoopUntilEventDetected(&fixture.Client, igtlioLogic::DeviceModifiedEvent)) 50 | { 51 | return TEST_FAILED; 52 | } 53 | 54 | if (fixture.Client.Logic->GetNumberOfDevices() == 0) 55 | { 56 | std::cout << "FAILURE: No devices received." << std::endl; 57 | return TEST_FAILED; 58 | } 59 | 60 | igtlioImageDevicePointer receivedDevice; 61 | receivedDevice = igtlioImageDevice::SafeDownCast(fixture.Client.Logic->GetDevice(0)); 62 | if (!receivedDevice) 63 | { 64 | std::cout << "FAILURE: Non-image device received." << std::endl; 65 | return TEST_FAILED; 66 | } 67 | 68 | std::cout << "*** Client received IMAGE device." << std::endl; 69 | //--------------------------------------------------------------------------- 70 | 71 | if (!igtlioCompare(imageDevice, receivedDevice)) 72 | { 73 | std::cout << "FAILURE: Image differs from the one sent from server." << std::endl; 74 | return TEST_FAILED; 75 | } 76 | return TEST_SUCCESS; 77 | } 78 | -------------------------------------------------------------------------------- /Tools/igtlioCommandMessageCodec.cxx: -------------------------------------------------------------------------------- 1 | #include "igtlioCommandMessageCodec.h" 2 | #include "vtkXMLUtilities.h" 3 | #include "vtkXMLDataElement.h" 4 | #include 5 | 6 | 7 | igtlioCommandMessageCodec::igtlioCommandMessageCodec() : m_isReply(false), m_result(false) 8 | { 9 | } 10 | 11 | igtlioCommandMessageCodec::igtlioCommandMessageCodec( bool isReply ) : m_isReply( isReply ), m_result( false ) 12 | { 13 | } 14 | 15 | void igtlioCommandMessageCodec::SetResult( bool res ) 16 | { 17 | m_result = res; 18 | } 19 | 20 | void igtlioCommandMessageCodec::AddParameter( std::string paramName, std::string value ) 21 | { 22 | m_parameters.push_back( std::pair(paramName, value ) ); 23 | } 24 | 25 | void igtlioCommandMessageCodec::AddParameter( std::string paramName, double value ) 26 | { 27 | std::stringstream ss; 28 | ss << value; 29 | AddParameter( paramName, ss.str() ); 30 | } 31 | 32 | std::string igtlioCommandMessageCodec::GetContent() 33 | { 34 | std::stringstream os; 35 | os << "" << std::endl; 36 | if( m_isReply ) 37 | { 38 | std::string resString = m_result ? "true" : "false"; 39 | os << " " << resString << "" << std::endl; 40 | } 41 | for(unsigned int i = 0; i < m_parameters.size(); ++i ) 42 | { 43 | os << " " << std::endl; 44 | } 45 | os << "" << std::endl; 46 | return os.str(); 47 | } 48 | 49 | void igtlioCommandMessageCodec::SetContent( std::string content ) 50 | { 51 | vtkXMLDataElement * root = vtkXMLUtilities::ReadElementFromString( content.c_str() ); 52 | for( int i = 0; i < root->GetNumberOfNestedElements(); ++i ) 53 | { 54 | vtkXMLDataElement * elem = root->GetNestedElement( i ); 55 | if( std::string(elem->GetName()) == "Result" ) 56 | { 57 | m_isReply = true; 58 | std::string result = elem->GetCharacterData(); 59 | m_result = result == "true" ? true : false; 60 | } 61 | else if( std::string(elem->GetName()) == "Parameter" ) 62 | { 63 | std::string name = elem->GetAttribute( "Name" ); 64 | std::string value = elem->GetAttribute( "Value" ); 65 | m_parameters.push_back( std::pair( name, value) ); 66 | } 67 | } 68 | root->Delete(); 69 | } 70 | 71 | bool igtlioCommandMessageCodec::GetResult() 72 | { 73 | return m_result; 74 | } 75 | 76 | std::string igtlioCommandMessageCodec::GetParameter( std::string paramName ) 77 | { 78 | for(unsigned int i = 0; i < m_parameters.size(); ++i ) 79 | if( m_parameters[i].first == paramName ) 80 | return m_parameters[i].second; 81 | return std::string(); 82 | } 83 | -------------------------------------------------------------------------------- /Converter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(igtlioConverter) 2 | 3 | set(${PROJECT_NAME}_EXPORT_DIRECTIVE "OPENIGTLINKIO_CONVERTER_EXPORT") 4 | 5 | set(VTK_MODULES 6 | ${IGTLIO_MODULE_PREFIX}IOImage 7 | ${IGTLIO_MODULE_PREFIX}ImagingMath 8 | ) 9 | 10 | find_package(VTK REQUIRED NO_MODULE 11 | COMPONENTS 12 | ${VTK_MODULES} 13 | ) 14 | 15 | if(VTK_VERSION VERSION_LESS 8.9.0) 16 | include(${VTK_USE_FILE}) 17 | endif() 18 | 19 | set(${PROJECT_NAME}_INCLUDE_DIRECTORIES PUBLIC 20 | $ 21 | $ 22 | $ 23 | ) 24 | set(${PROJECT_NAME}_SRCS 25 | igtlioBaseConverter.cxx 26 | igtlioCommandConverter.cxx 27 | igtlioConverterUtilities.cxx 28 | igtlioImageConverter.cxx 29 | igtlioImageMetaConverter.cxx 30 | igtlioLabelMetaConverter.cxx 31 | igtlioPolyDataConverter.cxx 32 | igtlioPointConverter.cxx 33 | igtlioStatusConverter.cxx 34 | igtlioStringConverter.cxx 35 | igtlioTransformConverter.cxx 36 | igtlioTrackingDataConverter.cxx 37 | ) 38 | 39 | set(${PROJECT_NAME}_HDRS 40 | igtlioBaseConverter.h 41 | igtlioCommandConverter.h 42 | igtlioConverterUtilities.h 43 | igtlioImageConverter.h 44 | igtlioImageMetaConverter.h 45 | igtlioLabelMetaConverter.h 46 | igtlioPolyDataConverter.h 47 | igtlioPointConverter.h 48 | igtlioStatusConverter.h 49 | igtlioStringConverter.h 50 | igtlioTransformConverter.h 51 | igtlioUsSectorDefinitions.h 52 | igtlioTrackingDataConverter.h 53 | ) 54 | 55 | IF(OpenIGTLink_ENABLE_VIDEOSTREAMING) 56 | LIST(APPEND ${PROJECT_NAME}_SRCS 57 | igtlioVideoConverter.cxx 58 | ) 59 | LIST(APPEND ${PROJECT_NAME}_HDRS 60 | igtlioVideoConverter.h 61 | ) 62 | ENDIF() 63 | 64 | set(${PROJECT_NAME}_TARGET_LIBRARIES 65 | ${OpenIGTLink_LIBRARIES} 66 | ${VTK_LIBRARIES} 67 | ) 68 | 69 | add_library(${PROJECT_NAME} ${${PROJECT_NAME}_SRCS} ${${PROJECT_NAME}_HDRS}) 70 | target_link_libraries(${PROJECT_NAME} PUBLIC ${${PROJECT_NAME}_TARGET_LIBRARIES}) 71 | target_include_directories(${PROJECT_NAME} ${${PROJECT_NAME}_INCLUDE_DIRECTORIES}) 72 | 73 | generate_export_header(${PROJECT_NAME} EXPORT_FILE_NAME ${PROJECT_NAME}Export.h EXPORT_MACRO_NAME ${${PROJECT_NAME}_EXPORT_DIRECTIVE}) 74 | 75 | # -------------------------------------------------------------------------- 76 | 77 | INSTALL(TARGETS ${PROJECT_NAME} EXPORT OpenIGTLinkIO 78 | RUNTIME DESTINATION "${OpenIGTLinkIO_BINARY_INSTALL}" COMPONENT RuntimeLibraries 79 | LIBRARY DESTINATION "${OpenIGTLinkIO_LIBRARY_INSTALL}" COMPONENT RuntimeLibraries 80 | ARCHIVE DESTINATION "${OpenIGTLinkIO_ARCHIVE_INSTALL}" COMPONENT Development 81 | ) 82 | 83 | INSTALL(FILES ${${PROJECT_NAME}_HDRS} "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Export.h" DESTINATION "${OpenIGTLinkIO_INCLUDE_INSTALL}" COMPONENT Includes) 84 | -------------------------------------------------------------------------------- /Testing/igtlioTestUtilities.cxx: -------------------------------------------------------------------------------- 1 | #include "igtlioTestUtilities.h" 2 | 3 | #include 4 | 5 | vtkSmartPointer igtlioCreateTestImage() 6 | { 7 | vtkSmartPointer image = vtkSmartPointer::New(); 8 | image->SetSpacing(1.5, 1.2, 1); 9 | image->SetExtent(0, 19, 0, 49, 0, 1); 10 | image->AllocateScalars(VTK_UNSIGNED_CHAR, 3); 11 | 12 | int scalarSize = image->GetScalarSize(); 13 | unsigned char* ptr = reinterpret_cast(image->GetScalarPointer()); 14 | unsigned char color = 0; 15 | std::fill(ptr, ptr + scalarSize, color++); 16 | 17 | return image; 18 | } 19 | 20 | vtkSmartPointer igtlioCreateTestTransform() 21 | { 22 | vtkSmartPointer transform = vtkSmartPointer::New(); 23 | transform->Identity(); 24 | return transform; 25 | } 26 | 27 | bool igtlioCompare(vtkSmartPointer a, vtkSmartPointer b) 28 | { 29 | for (int x = 0; x < 4; ++x) 30 | { 31 | for (int y = 0; y < 4; ++y) 32 | { 33 | if (fabs(b->Element[x][y] - a->Element[x][y]) > 1E-3) 34 | { 35 | return false; 36 | } 37 | } 38 | } 39 | return true; 40 | } 41 | 42 | bool igtlioCompare(vtkSmartPointer a, vtkSmartPointer b) 43 | { 44 | vtkSmartPointer differenceFilter = vtkSmartPointer::New(); 45 | differenceFilter->SetInputData(a); 46 | differenceFilter->SetImageData(b); 47 | differenceFilter->Update(); 48 | double imageError = differenceFilter->GetError(); 49 | if (fabs(imageError) > 1E-3) 50 | { 51 | return false; 52 | } 53 | return true; 54 | } 55 | 56 | bool igtlioCompare(igtlioImageDevicePointer a, igtlioImageDevicePointer b) 57 | { 58 | if (a->GetDeviceName() != b->GetDeviceName()) 59 | { 60 | return false; 61 | } 62 | if (fabs(a->GetTimestamp() - b->GetTimestamp()) < 1E-3) 63 | { 64 | return false; 65 | } 66 | if (a->GetDeviceType() != b->GetDeviceType()) 67 | { 68 | return false; 69 | } 70 | if (!igtlioCompare(a->GetContent().image, b->GetContent().image)) 71 | { 72 | return false; 73 | } 74 | if (!igtlioCompare(a->GetContent().transform, b->GetContent().transform)) 75 | { 76 | return false; 77 | } 78 | 79 | return true; 80 | } 81 | 82 | std::string igtlioBoolToString(bool b) 83 | { 84 | std::string ret = b ? "true" : "false"; 85 | return ret; 86 | } 87 | 88 | bool igtlioContains(std::vector input, int value, int count) 89 | { 90 | int found_times = 0; 91 | for (int i = 0; i < input.size(); ++i) 92 | { 93 | if (input[i] == value) 94 | { 95 | found_times += 1; 96 | } 97 | } 98 | return (found_times >= count) ? true : false; 99 | } 100 | -------------------------------------------------------------------------------- /GUI/qIGTLIOConnectorModel.h: -------------------------------------------------------------------------------- 1 | /*============================================================================== 2 | 3 | Program: 3D Slicer 4 | 5 | Copyright (c) 2010 Kitware Inc. 6 | 7 | See COPYRIGHT.txt 8 | or http://www.slicer.org/copyright/copyright.txt for details. 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | This file was originally developed by Julien Finet, Kitware Inc. 17 | and was partially funded by NIH grant 3P41RR013218-12S1 18 | 19 | ==============================================================================*/ 20 | 21 | #ifndef __qIGTLIOConnectorModel_h 22 | #define __qIGTLIOConnectorModel_h 23 | 24 | #include 25 | #include 26 | 27 | #include "qIGTLIOVtkConnectionMacro.h" 28 | 29 | // igtlio includes 30 | #include "igtlioGUIExport.h" 31 | #include "igtlioConnector.h" 32 | #include 33 | 34 | typedef vtkSmartPointer igtlioLogicPointer; 35 | 36 | /// 37 | /// A model describing all connectors and their properties. 38 | /// 39 | class OPENIGTLINKIO_GUI_EXPORT qIGTLIOConnectorModel : public QAbstractItemModel 40 | { 41 | Q_OBJECT 42 | IGTLIO_QVTK_OBJECT 43 | 44 | public: 45 | qIGTLIOConnectorModel(QObject *parent=0); 46 | virtual ~qIGTLIOConnectorModel(); 47 | 48 | virtual int columnCount (const QModelIndex& parent = QModelIndex() ) const; 49 | virtual int rowCount(const QModelIndex& parent = QModelIndex() ) const; 50 | virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole ) const; 51 | virtual Qt::ItemFlags flags(const QModelIndex& index ) const; 52 | virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const; 53 | virtual QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex() ) const; 54 | virtual QModelIndex parent(const QModelIndex& index ) const; 55 | 56 | void resetModel(); 57 | void setLogic(igtlioLogicPointer logic); 58 | 59 | enum Columns{ 60 | NameColumn = 0, 61 | TypeColumn, 62 | StatusColumn, 63 | HostnameColumn, 64 | PortColumn 65 | }; 66 | 67 | private slots: 68 | void onConnectorEvent(vtkObject *caller, unsigned long event, void *, void *connector ); 69 | void onConnectionEvent(vtkObject *caller, unsigned long, void *, void * ); 70 | 71 | private: 72 | Q_DISABLE_COPY(qIGTLIOConnectorModel); 73 | igtlioConnector* getNodeFromIndex(const QModelIndex& index) const; 74 | void ReconnectConnector(igtlioConnector *oldConnector, igtlioConnector *newConnector); 75 | 76 | igtlioLogicPointer Logic; 77 | QStringList HeaderLabels; 78 | }; 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /GUI/qIGTLIODevicesModel.h: -------------------------------------------------------------------------------- 1 | #ifndef QIGTLIODEVICESMODEL_H 2 | #define QIGTLIODEVICESMODEL_H 3 | 4 | #include 5 | #include 6 | 7 | #include "qIGTLIOVtkConnectionMacro.h" 8 | 9 | // igtlio includes 10 | #include "igtlioGUIExport.h" 11 | 12 | #include "igtlioConnector.h" 13 | #include 14 | #include 15 | #include 16 | 17 | typedef vtkSmartPointer igtlioLogicPointer; 18 | 19 | typedef QSharedPointer qIGTLIODevicesModelNodePointer; 20 | class QItemSelectionModel; 21 | 22 | /// 23 | /// A model describing all IGTL devices, 24 | /// organized by connector and direction (IN/OUT). 25 | /// 26 | class OPENIGTLINKIO_GUI_EXPORT qIGTLIODevicesModel : public QAbstractItemModel 27 | { 28 | Q_OBJECT 29 | IGTLIO_QVTK_OBJECT 30 | 31 | public: 32 | qIGTLIODevicesModel(QObject *parent=0); 33 | virtual ~qIGTLIODevicesModel(); 34 | 35 | virtual int columnCount (const QModelIndex& parent = QModelIndex() ) const; 36 | virtual int rowCount(const QModelIndex& parent = QModelIndex() ) const; 37 | virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole ) const; 38 | virtual bool setData(const QModelIndex& index, const QVariant& value, int role); 39 | virtual Qt::ItemFlags flags(const QModelIndex& index ) const; 40 | virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const; 41 | virtual QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex() ) const; 42 | virtual QModelIndex parent(const QModelIndex& index ) const; 43 | 44 | 45 | void resetModel(); 46 | void setLogic(igtlioLogicPointer logic); 47 | 48 | void setSelectionModel(QItemSelectionModel* selectionModel); 49 | QItemSelectionModel* selectionModel(); 50 | // qIGTLIODevicesModelNode* selectedNode(); 51 | 52 | enum Columns{ 53 | NameColumn = 0, 54 | TypeColumn, 55 | StatusColumn, 56 | VisualizationColumn, 57 | PushOnConnectColumn, 58 | NumColumns 59 | }; 60 | enum Direction{ 61 | UNDEFINED = 0, 62 | INCOMING, 63 | OUTGOING, 64 | }; 65 | 66 | qIGTLIODevicesModelNode* getNodeFromIndex(const QModelIndex& index) const; 67 | 68 | private slots: 69 | void onConnectorEvent(vtkObject *caller, unsigned long event, void *, void *connector); 70 | void onConnectionEvent(vtkObject *caller, unsigned long, void *, void *connector); 71 | private: 72 | Q_DISABLE_COPY(qIGTLIODevicesModel); 73 | 74 | 75 | igtlioLogicPointer Logic; 76 | QStringList HeaderLabels; 77 | QPointer SelectionModel; 78 | 79 | mutable qIGTLIODevicesModelNodePointer RootNode; 80 | void ReconnectConnector(igtlioConnector *oldConnector, igtlioConnector *newConnector); 81 | qIGTLIODevicesModelNode *FindDeviceNode(igtlioDevice *device, qIGTLIODevicesModelNode *parent); 82 | }; 83 | 84 | 85 | 86 | #endif // QIGTLIODEVICESMODEL_H 87 | -------------------------------------------------------------------------------- /GUI/qIGTLIODevicesWidget.cxx: -------------------------------------------------------------------------------- 1 | #include "qIGTLIODevicesWidget.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "igtlioLogic.h" 9 | #include "qIGTLIOConnectorPropertyWidget.h" 10 | #include "qIGTLIODevicesModel.h" 11 | #include "qIGTLIODeviceButtonsWidget.h" 12 | #include "qIGTLIODevicePropertiesWidget.h" 13 | #include "vtkIGTLIONode.h" 14 | #include "qIGTLIODeviceAddWidget.h" 15 | 16 | //----------------------------------------------------------------------------- 17 | qIGTLIODevicesWidget::qIGTLIODevicesWidget() 18 | { 19 | DevicesModel = new qIGTLIODevicesModel(this); 20 | 21 | QVBoxLayout* topLayout = new QVBoxLayout(this); 22 | topLayout->setContentsMargins(0, 0, 0, 0); 23 | 24 | DevicesListView = new QTreeView; 25 | DevicesListView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); 26 | DevicesListView->setModel(DevicesModel); 27 | topLayout->addWidget(DevicesListView, 1); 28 | 29 | SelectionModel = DevicesListView->selectionModel(); 30 | DevicesModel->setSelectionModel(SelectionModel); 31 | DevicesListView->setColumnWidth(0, 200); 32 | 33 | 34 | ButtonsWidget = new qIGTLIODeviceButtonsWidget(); 35 | topLayout->addWidget(ButtonsWidget); 36 | ButtonsWidget->setModel(DevicesModel); 37 | 38 | DevicePropertiesWidget = new qIGTLIODevicePropertiesWidget(); 39 | topLayout->addWidget(DevicePropertiesWidget); 40 | 41 | AddDeviceWidget = new qIGTLIODeviceAddWidget(); 42 | topLayout->addWidget(AddDeviceWidget); 43 | AddDeviceWidget->setModel(DevicesModel); 44 | 45 | connect(SelectionModel, SIGNAL(currentRowChanged(const QModelIndex&, const QModelIndex&)), 46 | this, SLOT(onCurrentDeviceChanged(const QModelIndex&, const QModelIndex&))); 47 | } 48 | 49 | //----------------------------------------------------------------------------- 50 | void qIGTLIODevicesWidget::onCurrentDeviceChanged(const QModelIndex& current, const QModelIndex& previous) 51 | { 52 | qIGTLIODevicesModelNode* node = DevicesModel->getNodeFromIndex(current); 53 | DevicePropertiesWidget->SetNode(node); 54 | } 55 | 56 | //----------------------------------------------------------------------------- 57 | void qIGTLIODevicesWidget::setLogic(igtlioLogicPointer logic) 58 | { 59 | foreach(int evendId, QList() 60 | << igtlioLogic::ConnectionAddedEvent 61 | << igtlioLogic::ConnectionAboutToBeRemovedEvent) 62 | { 63 | qvtkReconnect(this->Logic, logic, evendId, 64 | this, SLOT(onConnectionsChanged(vtkObject*, unsigned long, void*, void*))); 65 | } 66 | 67 | this->Logic = logic; 68 | DevicesModel->setLogic(logic); 69 | ButtonsWidget->setLogic(Logic); 70 | } 71 | 72 | //----------------------------------------------------------------------------- 73 | void qIGTLIODevicesWidget::onConnectionsChanged(vtkObject* caller, unsigned long event , void* b, void* connector) 74 | { 75 | } 76 | 77 | 78 | -------------------------------------------------------------------------------- /GUI/qMRMLIGTLIOModel.h: -------------------------------------------------------------------------------- 1 | /*============================================================================== 2 | 3 | Program: 3D Slicer 4 | 5 | Copyright (c) 2010 Kitware Inc. 6 | 7 | See COPYRIGHT.txt 8 | or http://www.slicer.org/copyright/copyright.txt for details. 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | This file was originally developed by Julien Finet, Kitware Inc. 17 | and was partially funded by NIH grant 3P41RR013218-12S1 18 | 19 | ==============================================================================*/ 20 | 21 | #ifndef __qMRMLIGTLIOModel_h 22 | #define __qMRMLIGTLIOModel_h 23 | 24 | #include "../Logic/vtkIGTLIOLogic.h" 25 | #include "qMRMLSceneModel.h" 26 | 27 | // OpenIGTLinkIF GUI includes 28 | #include "qSlicerOpenIGTLinkIFModuleExport.h" 29 | 30 | // Logic includes 31 | 32 | class vtkMRMLNode; 33 | class qMRMLIGTLIOModelPrivate; 34 | 35 | /// \ingroup Slicer_QtModules_OpenIGTLink 36 | class Q_SLICER_QTMODULES_OPENIGTLINKIF_EXPORT qMRMLIGTLIOModel : public qMRMLSceneModel 37 | { 38 | Q_OBJECT 39 | 40 | public: 41 | 42 | enum Columns{ 43 | NameColumn = 0, 44 | TypeColumn, 45 | StatusColumn, 46 | VisualizationColumn, 47 | PushOnConnectColumn, 48 | NumColumns 49 | }; 50 | enum Direction{ 51 | UNDEFINED = 0, 52 | INCOMING, 53 | OUTGOING, 54 | }; 55 | 56 | public: 57 | typedef qMRMLSceneModel Superclass; 58 | qMRMLIGTLIOModel(QObject *parent=0); 59 | virtual ~qMRMLIGTLIOModel(); 60 | 61 | void setLogic(vtkSlicerOpenIGTLinkIFLogic* logic); 62 | 63 | virtual QStandardItem* insertNode(vtkMRMLNode* node, QStandardItem* parent, int row); 64 | virtual void updateItemDataFromNode(QStandardItem* item, vtkMRMLNode* node, int column); 65 | virtual void updateNodeFromItem(vtkMRMLNode* node, QStandardItem* item); 66 | 67 | protected: 68 | qMRMLIGTLIOModel(qMRMLIGTLIOModelPrivate* pimpl, QObject *parent=0); 69 | 70 | virtual void updateIOTreeBranch(vtkMRMLIGTLConnectorNode* node, QStandardItem* item, qMRMLIGTLIOModel::Direction dir); 71 | virtual QStandardItem* insertIOTree(vtkMRMLNode* node); 72 | virtual QStandardItem* insertNode(vtkMRMLNode* node); 73 | 74 | protected slots: 75 | virtual void onDeviceVisibilityModified(vtkObject*); 76 | virtual void onMRMLSceneNodeAdded(vtkMRMLScene* scene, vtkMRMLNode* node); 77 | virtual void onMRMLSceneNodeAboutToBeRemoved(vtkMRMLScene* scene, vtkMRMLNode* node); 78 | virtual void onMRMLSceneNodeRemoved(vtkMRMLScene* scene, vtkMRMLNode* node); 79 | 80 | 81 | private: 82 | Q_DECLARE_PRIVATE(qMRMLIGTLIOModel); 83 | Q_DISABLE_COPY(qMRMLIGTLIOModel); 84 | 85 | vtkSlicerOpenIGTLinkIFLogic* Logic; 86 | 87 | 88 | 89 | }; 90 | 91 | 92 | 93 | #endif //__qMRMLIGTLIOModel_h 94 | 95 | 96 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OpenIGTLinkIO 2 | 3 | OpenIGTLink utility library. 4 | 5 | Originally forked from OpenIGTLinkIF. 6 | 7 | OpenIGTLinkIO contains several wrapper layers on top of OpenIGTLink. The code originates from OpenIGTLink/OpenIGTLinkIF. The main intent of the library is to share igtl code between Slicer, CustusX, IBIS, MITK and other systems. 8 | 9 | **Warning: This is a work in progress. The code is highly unstable!** 10 | 11 | The library contains the following modules, ordered from few to lots of dependencies: 12 | * **Converter Module** VTK<->OpenIGTLink: Standalone utility classes for converting between VTK and igtl formats. 13 | * **Devices Module**: A library of device classes, one for each igtl message, VTK-dependent. 14 | * **Logic Module**: An igtl client that used Devices to send/receive igtl messages over one or more Connections, VTK-dependent. 15 | * **GUI Module**: User interface classes and widgets for the Logic Module. Qt and CTK-dependent. 16 | 17 | An example application for running a standalone client is also available. 18 | 19 | ## Build instructions 20 | 21 | Build with cmake: 22 | 23 | ``` 24 | cmake -G"generator_name" \ 25 | -DOpenIGTLink_DIR:PATH=path/to/igtl/build \ 26 | -DVTK_DIR:PATH=path/to/vtk/build \ 27 | -DCTK_DIR:PATH=path/to/ctk/build \ 28 | -DQt5_DIR:PATH=path/to/Qt/lib/cmake/Qt5 29 | path/to/source 30 | ``` 31 | 32 | If you use a single configuration generator, you can explicitly select the configuration passing `-DCMAKE_BUILD_TYPE:STRING=Release` or `-DCMAKE_BUILD_TYPE:STRING=Debug`. 33 | 34 | List of available generator are listed [here](https://cmake.org/cmake/help/v3.8/manual/cmake-generators.7.html). 35 | 36 | CTK must be build with VTK support `-DCTK_LIB_Visualization/VTK/Core:BOOL=ON`. Set `-DVTK_DIR:PATH=path/to/vtk/build` as well. 37 | 38 | The library can be included into other systems through the usual cmake framework. *Install not tested.* 39 | 40 | ## Example 41 | 42 | The following is an example of how to build the library with all prerequisites: 43 | 44 | ```bash 45 | # prerequisites: 46 | # 47 | # qmake is in path 48 | 49 | mkdir ~/dev 50 | cd ~/dev 51 | 52 | git clone git@github.com:Kitware/VTK.git 53 | mkdir -p VTK_build 54 | cd VTK_build 55 | cmake ../VTK -DVTK_QT_VERSION:STRING=5 -DModule_vtkGUISupportQt:BOOL=ON -DQt5_DIR:PATH=/path/to/Qt5/lib/cmake/Qt5 56 | make -j6 57 | cd .. 58 | 59 | git clone git@github.com:commontk/CTK.git 60 | mkdir -p CTK_build 61 | cd CTK_build 62 | cmake ../CTK -DCTK_QT_VERSION:STRING=5 -DCTK_LIB_Visualization/VTK/Core:BOOL=ON -DVTK_DIR:PATH=~/dev/VTK_build -DBUILD_TESTING:BOOL=OFF -DQt5_DIR:PATH=/path/to/Qt5/lib/cmake/Qt5 63 | make -j6 64 | cd .. 65 | 66 | git clone git@github.com:IGSIO/OpenIGTLink.git 67 | mkdir -p OpenIGTLink_build 68 | cd OpenIGTLink_build 69 | cmake ../OpenIGTLink -DBUILD_TESTING:BOOL=OFF 70 | make -j6 71 | 72 | 73 | git clone git@github.com:IGSIO/OpenIGTLinkIO.git 74 | mkdir -p OpenIGTLinkIO_build 75 | cd OpenIGTLinkIO_build 76 | cmake ../OpenIGTLinkIO -DOpenIGTLink_DIR:PATH=~/dev/OpenIGTLink_build -DVTK_DIR:PATH=~/dev/VTK_build -DCTK_DIR:PATH=~/dev/CTK_build 77 | make -j6 78 | ``` 79 | 80 | # License 81 | This project is released under the [Apache 2 license](LICENSE.md). 82 | -------------------------------------------------------------------------------- /Logic/igtlioDeviceFactory.cxx: -------------------------------------------------------------------------------- 1 | /* 2 | * vtkIGTLIODeviceFactory.cpp 3 | * 4 | * Created on: 21. jan. 2016 5 | * Author: cas 6 | */ 7 | 8 | #include "igtlioDeviceFactory.h" 9 | #include 10 | 11 | #include "igtlioImageDevice.h" 12 | #include "igtlioImageMetaDevice.h" 13 | #include "igtlioLabelMetaDevice.h" 14 | #include "igtlioPointDevice.h" 15 | #include "igtlioPolyDataDevice.h" 16 | #include "igtlioStatusDevice.h" 17 | #include "igtlioStringDevice.h" 18 | #include "igtlioTrackingDataDevice.h" 19 | #include "igtlioTransformDevice.h" 20 | #if defined(OpenIGTLink_ENABLE_VIDEOSTREAMING) 21 | #include "igtlioVideoDevice.h" 22 | #endif 23 | 24 | //--------------------------------------------------------------------------- 25 | vtkStandardNewMacro(igtlioDeviceFactory); 26 | //--------------------------------------------------------------------------- 27 | igtlioDeviceFactory::igtlioDeviceFactory() 28 | { 29 | this->registerCreator(); 30 | this->registerCreator(); 31 | this->registerCreator(); 32 | this->registerCreator(); 33 | this->registerCreator(); 34 | this->registerCreator(); 35 | this->registerCreator(); 36 | this->registerCreator(); 37 | this->registerCreator(); 38 | #if defined(OpenIGTLink_ENABLE_VIDEOSTREAMING) 39 | this->registerCreator(); 40 | #endif 41 | } 42 | 43 | //--------------------------------------------------------------------------- 44 | igtlioDeviceFactory::~igtlioDeviceFactory() 45 | { 46 | } 47 | 48 | //--------------------------------------------------------------------------- 49 | void igtlioDeviceFactory::PrintSelf(ostream& os, vtkIndent indent) 50 | { 51 | } 52 | 53 | //--------------------------------------------------------------------------- 54 | igtlioDeviceCreatorPointer igtlioDeviceFactory::GetCreator(std::string device_type) const 55 | { 56 | std::map::const_iterator iter = Creators.find(device_type); 57 | if (iter == Creators.end()) 58 | { 59 | return igtlioDeviceCreatorPointer(); 60 | } 61 | return iter->second; 62 | } 63 | 64 | std::vector igtlioDeviceFactory::GetAvailableDeviceTypes() const 65 | { 66 | std::vector retval; 67 | for (std::map::const_iterator iter = Creators.begin(); 68 | iter != Creators.end(); 69 | ++iter) 70 | { 71 | retval.push_back(iter->first); 72 | } 73 | return retval; 74 | } 75 | 76 | //--------------------------------------------------------------------------- 77 | igtlioDevicePointer igtlioDeviceFactory::create(std::string device_type, std::string device_name) const 78 | { 79 | igtlioDeviceCreatorPointer creator = this->GetCreator(device_type); 80 | if (!creator) 81 | { 82 | return igtlioDevicePointer(); 83 | } 84 | return creator->Create(device_name); 85 | } 86 | 87 | //--------------------------------------------------------------------------- 88 | template 89 | void igtlioDeviceFactory::registerCreator() 90 | { 91 | igtlioDeviceCreatorPointer creator = vtkSmartPointer::New(); 92 | Creators[creator->GetDeviceType()] = creator; 93 | } 94 | -------------------------------------------------------------------------------- /GUI/qIGTLIODeviceButtonsWidget.cxx: -------------------------------------------------------------------------------- 1 | #include "qIGTLIODeviceButtonsWidget.h" 2 | 3 | #include "igtlioLogic.h" 4 | #include "qIGTLIODevicesModel.h" 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include "vtkIGTLIONode.h" 13 | 14 | #pragma push_macro("SendMessage") 15 | #undef SendMessage 16 | 17 | qIGTLIODeviceButtonsWidget::qIGTLIODeviceButtonsWidget() 18 | { 19 | QVBoxLayout* topLayout = new QVBoxLayout(this); 20 | topLayout->setContentsMargins(0, 0, 0, 0); 21 | 22 | QFrame* buttonFrame = new QFrame; 23 | buttonFrame->setFrameShape(QFrame::NoFrame); 24 | buttonFrame->setFrameShadow(QFrame::Plain); 25 | topLayout->addWidget(buttonFrame); 26 | QHBoxLayout* buttonLayout = new QHBoxLayout(buttonFrame); 27 | buttonLayout->setContentsMargins(0, 0, 0, 0); 28 | 29 | QStringList actionNames = QStringList() << "SEND"; 30 | 31 | for (int i=0; isetData(i); 35 | Actions.push_back(action); 36 | connect(action, SIGNAL(triggered()), this, SLOT(onActionClicked())); 37 | } 38 | 39 | for (int i=0; isetDefaultAction(Actions[i]); 43 | buttonLayout->addWidget(button); 44 | } 45 | buttonLayout->addStretch(1); 46 | 47 | this->onCurrentConnectorChanged(); 48 | } 49 | 50 | void qIGTLIODeviceButtonsWidget::setLogic(igtlioLogicPointer logic) 51 | { 52 | Logic = logic; 53 | } 54 | 55 | void qIGTLIODeviceButtonsWidget::setModel(qIGTLIODevicesModel *model) 56 | { 57 | DevicesModel = model; 58 | connect(DevicesModel->selectionModel(), SIGNAL(currentRowChanged(const QModelIndex&, const QModelIndex&)), 59 | this, SLOT(onCurrentConnectorChanged())); 60 | this->onCurrentConnectorChanged(); 61 | } 62 | 63 | qIGTLIODevicesModelNode* qIGTLIODeviceButtonsWidget::getSelectedNode() 64 | { 65 | if (DevicesModel.isNull()) 66 | return NULL; 67 | 68 | QModelIndex index = DevicesModel->selectionModel()->currentIndex(); 69 | qIGTLIODevicesModelNode* node = DevicesModel->getNodeFromIndex(index); 70 | return node; 71 | } 72 | 73 | void qIGTLIODeviceButtonsWidget::onCurrentConnectorChanged() 74 | { 75 | qIGTLIODevicesModelNode* node = this->getSelectedNode(); 76 | 77 | for (int i=0; i(Actions[i]->data().toInt()); 80 | bool e = node && node->isDevice() && 81 | (node->device->GetSupportedMessagePrefixes().count(prefix) || 82 | (prefix==igtlioDevice::MESSAGE_PREFIX_NOT_DEFINED)); 83 | Actions[i]->setEnabled(e); 84 | } 85 | } 86 | 87 | void qIGTLIODeviceButtonsWidget::onActionClicked() 88 | { 89 | QAction* action = dynamic_cast(sender()); 90 | if (!action) 91 | return; 92 | 93 | igtlioDevice::MESSAGE_PREFIX prefix = static_cast(action->data().toInt()); 94 | 95 | qIGTLIODevicesModelNode* node = this->getSelectedNode(); 96 | if (!node || !node->isDevice()) 97 | return; 98 | 99 | node->connector->SendMessage(igtlioDeviceKeyType::CreateDeviceKey(node->device), prefix); 100 | 101 | } 102 | 103 | #pragma pop_macro("SendMessage") 104 | -------------------------------------------------------------------------------- /Converter/igtlioVideoConverter.h: -------------------------------------------------------------------------------- 1 | /*========================================================================== 2 | 3 | Portions (c) Copyright 2008-2009 Brigham and Women's Hospital (BWH) All Rights Reserved. 4 | 5 | See Doc/copyright/copyright.txt 6 | or http://www.slicer.org/copyright/copyright.txt for details. 7 | 8 | Date: $Date: 2010-11-23 00:58:13 -0500 (Tue, 23 Nov 2010) $ 9 | Version: $Revision: 15552 $ 10 | 11 | ==========================================================================*/ 12 | 13 | #ifndef IGTLIOVIDEOCONVERTER_H 14 | #define IGTLIOVIDEOCONVERTER_H 15 | 16 | #include "igtlioConverterExport.h" 17 | 18 | 19 | // OpenIGTLink includes 20 | #include "igtlVideoMessage.h" 21 | #include "igtlCodecCommonClasses.h" 22 | #include "igtlConfigure.h" 23 | #include "igtl_util.h" 24 | #include "igtlI420Encoder.h" 25 | #include "igtlI420Decoder.h" 26 | #if defined(OpenIGTLink_USE_H264) 27 | #include "igtlH264Encoder.h" 28 | #include "igtlH264Decoder.h" 29 | #endif 30 | #if defined(OpenIGTLink_USE_AV1) 31 | #include "igtlAV1Encoder.h" 32 | #include "igtlAV1Decoder.h" 33 | #endif 34 | #if defined(OpenIGTLink_USE_VP9) 35 | #include "igtlVP9Encoder.h" 36 | #include "igtlVP9Decoder.h" 37 | #endif 38 | #if defined(OpenIGTLink_USE_OpenHEVC) 39 | #include "igtlH265Decoder.h" 40 | #endif 41 | #if defined(OpenIGTLink_USE_X265) 42 | #include "igtlH265Encoder.h" 43 | #endif 44 | #include "igtlioBaseConverter.h" 45 | 46 | class vtkImageData; 47 | class vtkMatrix4x4; 48 | class vtkUnsignedCharArray; 49 | 50 | using namespace igtl; 51 | 52 | /** Conversion between igtl::VideoMessage and vtk classes. 53 | * 54 | */ 55 | class OPENIGTLINKIO_CONVERTER_EXPORT igtlioVideoConverter : public igtlioBaseConverter 56 | { 57 | public: 58 | igtlioVideoConverter(); 59 | /** 60 | * This structure contains everything that igtl::VideoMessage is able to contain, 61 | * in a vtk-friendly format. 62 | */ 63 | struct ContentData 64 | { 65 | vtkSmartPointer image; 66 | VideoFrameType frameType; 67 | char codecName[IGTL_VIDEO_CODEC_NAME_SIZE]; 68 | VideoMessage::Pointer videoMessage; // for saving the compressed data. 69 | VideoMessage::Pointer keyFrameMessage; // for saving the compressed data. 70 | bool keyFrameUpdated; 71 | vtkSmartPointer transform; // ijk2ras, From image pixel space to RAS 72 | vtkSmartPointer frameData; 73 | bool grayscale; 74 | }; 75 | 76 | static const char* GetIGTLName() { return GetIGTLTypeName(); } 77 | static const char* GetIGTLTypeName() { return "VIDEO"; } 78 | 79 | static int fromIGTL(MessageBase::Pointer source, HeaderData* header, ContentData* content, std::map decoders, bool checkCRC, igtl::MessageBase::MetaDataMap& outMetaInfo); 80 | static int toIGTL(const HeaderData& header, const ContentData& source, GenericEncoder* encoder, igtl::MessageBase::MetaDataMap metaInfo = igtl::MessageBase::MetaDataMap()); 81 | 82 | static int IGTLFrameToVTKTransform(igtl::VideoMessage::Pointer videoMsg, vtkSmartPointer ijk2ras); 83 | static int VTKTransformToIGTLFrame(const vtkMatrix4x4& ijk2ras, int imageSize[3], double spacing[3], double origin[3], igtl::VideoMessage::Pointer videoMsg); 84 | 85 | protected: 86 | 87 | static int IGTLToVTKScalarType(int igtlType); 88 | static int IGTLToVTKImageData(ContentData *dest, VideoMessage::Pointer videoMessage, GenericDecoder * videoStreamDecoder); 89 | 90 | }; 91 | 92 | #endif //IGTLIOVIDEOCONVERTER_H 93 | -------------------------------------------------------------------------------- /Logic/igtlioCircularSectionBuffer.h: -------------------------------------------------------------------------------- 1 | /*========================================================================== 2 | 3 | Portions (c) Copyright 2008-2009 Brigham and Women's Hospital (BWH) All Rights Reserved. 4 | 5 | See Doc/copyright/copyright.txt 6 | or http://www.slicer.org/copyright/copyright.txt for details. 7 | 8 | ==========================================================================*/ 9 | 10 | #ifndef IGTLIOCIRCULARSECTIONBUFFER_H 11 | #define IGTLIOCIRCULARSECTIONBUFFER_H 12 | 13 | // STL includes 14 | #include 15 | #include 16 | 17 | // VTK includes 18 | #include 19 | 20 | // OpenIGTLink includes 21 | #include 22 | 23 | // Local includes 24 | #include "igtlioLogicExport.h" 25 | 26 | #define IGTLCB_CIRC_BUFFER_SIZE 3 27 | #define IGTLCB_CIRC_BUFFER_SIZE_VIDEOSTREAM 50 28 | 29 | class vtkCriticalSection; 30 | 31 | #ifndef VTK_OVERRIDE 32 | #define VTK_OVERRIDE override 33 | #endif 34 | 35 | class OPENIGTLINKIO_LOGIC_EXPORT igtlioCircularSectionBuffer : public vtkObject 36 | { 37 | public: 38 | 39 | static igtlioCircularSectionBuffer *New(); 40 | vtkTypeMacro(igtlioCircularSectionBuffer, vtkObject); 41 | 42 | void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE; 43 | 44 | int GetNumberOfBuffer() { return this->BufferSize; } 45 | 46 | int StartPush(); 47 | void EndPush(); 48 | igtl::MessageBase::Pointer GetPushBuffer(); 49 | 50 | int StartPull(); 51 | void EndPull(); 52 | igtl::MessageBase::Pointer GetPullBuffer(); 53 | 54 | igtl::MessageBase::Pointer GetPullSectionBuffer(); 55 | 56 | int IsUpdated() { return this->UpdateFlag; }; 57 | 58 | int Initialization(); 59 | 60 | enum 61 | { 62 | SinglePacketMode = 0, 63 | MultiplePacketsMode = 1 64 | }; 65 | 66 | enum 67 | { 68 | DataFilled = 2, 69 | DataEmpty = 3, 70 | DataProcessed =4 71 | }; 72 | 73 | vtkSetMacro( PacketMode, int); 74 | vtkGetMacro( PacketMode, int); 75 | 76 | vtkSetMacro( BufferSize, int); 77 | vtkGetMacro( BufferSize, int); 78 | 79 | bool IsSectionBufferInProcess(); 80 | 81 | 82 | protected: 83 | igtlioCircularSectionBuffer(); 84 | virtual ~igtlioCircularSectionBuffer(); 85 | 86 | protected: 87 | 88 | std::recursive_mutex Mutex; 89 | int Last; // updated by connector thread 90 | int First; // updated by connector thread 91 | int InPush; // updated by connector thread 92 | int InUseBegin; // updated by main thread 93 | int InUseEnd; // updated by main thread 94 | 95 | int UpdateFlag; // non-zero if updated since StartPull() has called 96 | 97 | int PacketMode; 98 | 99 | int BufferSize; 100 | 101 | #if defined(OpenIGTLink_ENABLE_VIDEOSTREAMING) 102 | std::string DeviceType[IGTLCB_CIRC_BUFFER_SIZE_VIDEOSTREAM]; 103 | unsigned short DataStatus[IGTLCB_CIRC_BUFFER_SIZE_VIDEOSTREAM]; 104 | igtl::MessageBase::Pointer Messages[IGTLCB_CIRC_BUFFER_SIZE_VIDEOSTREAM]; 105 | #else 106 | std::string DeviceType[IGTLCB_CIRC_BUFFER_SIZE]; 107 | unsigned short DataStatus[IGTLCB_CIRC_BUFFER_SIZE_VIDEOSTREAM]; 108 | igtl::MessageBase::Pointer Messages[IGTLCB_CIRC_BUFFER_SIZE]; 109 | #endif 110 | 111 | }; 112 | 113 | #endif //IGTLIOCIRCULARSECTIONBUFFER_H 114 | -------------------------------------------------------------------------------- /GUI/DeviceWidgets/qIGTLIOStatusDeviceWidget.cxx: -------------------------------------------------------------------------------- 1 | #include "qIGTLIOStatusDeviceWidget.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "vtkCommand.h" 10 | #include 11 | 12 | #include "igtlioDevice.h" 13 | #include "igtlioStatusConverter.h" 14 | #include "igtlioStatusDevice.h" 15 | #include "qIGTLIOGuiUtilities.h" 16 | 17 | //--------------------------------------------------------------------------- 18 | qIGTLIODeviceWidget* vtkIGTLIOStatusDeviceWidgetCreator::Create() 19 | { 20 | return new qIGTLIOStatusDeviceWidget(); 21 | } 22 | 23 | //--------------------------------------------------------------------------- 24 | std::string vtkIGTLIOStatusDeviceWidgetCreator::GetDeviceType() const 25 | { 26 | return igtlioStatusConverter::GetIGTLTypeName(); 27 | } 28 | 29 | //--------------------------------------------------------------------------- 30 | vtkStandardNewMacro(vtkIGTLIOStatusDeviceWidgetCreator); 31 | 32 | 33 | 34 | //--------------------------------------------------------------------------- 35 | //--------------------------------------------------------------------------- 36 | 37 | 38 | qIGTLIOStatusDeviceWidget::qIGTLIOStatusDeviceWidget(QWidget* parent) : qIGTLIODeviceWidget(parent) 39 | { 40 | 41 | } 42 | 43 | void qIGTLIOStatusDeviceWidget::setupUi() 44 | { 45 | QGridLayout* layout = new QGridLayout(this); 46 | 47 | DeviceNameEdit = new QLineEdit; 48 | TimestampEdit = new QLineEdit; 49 | CodeEdit = new QLineEdit; 50 | SubCodeEdit = new QLineEdit; 51 | ErrorNameEdit = new QLineEdit; 52 | StatusStringEdit = new QLineEdit; 53 | 54 | int line=0; 55 | this->AddCaptionedLineEdit(layout, DeviceNameEdit, "device: ", line++); 56 | this->AddCaptionedLineEdit(layout, TimestampEdit, "timestamp: ", line++); 57 | this->AddCaptionedLineEdit(layout, CodeEdit, "code: ", line++); 58 | this->AddCaptionedLineEdit(layout, SubCodeEdit, "subcode: ", line++); 59 | this->AddCaptionedLineEdit(layout, ErrorNameEdit, "error: ", line++); 60 | this->AddCaptionedLineEdit(layout, StatusStringEdit, "status: ", line++); 61 | } 62 | 63 | void qIGTLIOStatusDeviceWidget::AddCaptionedLineEdit(QGridLayout *layout, QLineEdit* edit, QString caption, int line) 64 | { 65 | layout->addWidget(new QLabel(caption), line, 0); 66 | edit->setReadOnly(true); 67 | layout->addWidget(edit, line, 1); 68 | } 69 | 70 | void qIGTLIOStatusDeviceWidget::onDeviceModified() 71 | { 72 | DeviceNameEdit->setText(""); 73 | TimestampEdit->setText(""); 74 | CodeEdit->setText(""); 75 | SubCodeEdit->setText(""); 76 | ErrorNameEdit->setText(""); 77 | StatusStringEdit->setText(""); 78 | 79 | QString text = (Device ? QString(convertDeviceNameToDisplay(Device->GetDeviceName()).c_str()) : "none"); 80 | DeviceNameEdit->setText(text); 81 | 82 | if (!Device) 83 | return; 84 | 85 | QDateTime timestamp = QDateTime::fromMSecsSinceEpoch(Device->GetTimestamp()*1000); 86 | //mTimestampEdit->setText(timestamp.toString(Qt::ISODate)); 87 | TimestampEdit->setText(timestamp.toString("hh:mm:ss.zzz")); 88 | 89 | igtlioStatusDevice* device = dynamic_cast(Device.GetPointer()); 90 | 91 | if (!device) 92 | return; 93 | 94 | CodeEdit->setText("0x"+QString::number(device->GetContent().code, 16)); 95 | SubCodeEdit->setText("0x"+QString::number(device->GetContent().subcode, 16)); 96 | ErrorNameEdit->setText(device->GetContent().errorname.c_str()); 97 | StatusStringEdit->setText(device->GetContent().statusstring.c_str()); 98 | } 99 | -------------------------------------------------------------------------------- /Converter/igtlioLabelMetaConverter.cxx: -------------------------------------------------------------------------------- 1 | 2 | // OpenIGTLInkIO includes 3 | #include "igtlioLabelMetaConverter.h" 4 | 5 | // OpenIGTLink includes 6 | #include 7 | #include 8 | 9 | //--------------------------------------------------------------------------- 10 | int igtlioLabelMetaConverter::fromIGTL(igtl::MessageBase::Pointer source, 11 | HeaderData* header, 12 | ContentData* dest, 13 | bool checkCRC, 14 | igtl::MessageBase::MetaDataMap& outMetaInfo) 15 | { 16 | // Create a message buffer to receive data 17 | igtl::LabelMetaMessage::Pointer msg; 18 | msg = igtl::LabelMetaMessage::New(); 19 | msg->Copy(source); // !! TODO: copy makes performance issue. 20 | 21 | // Deserialize the data 22 | // If CheckCRC==0, CRC check is skipped. 23 | int c = msg->Unpack(checkCRC); 24 | if ((c & igtl::MessageHeader::UNPACK_BODY) == 0) // if CRC check fails 25 | { 26 | // TODO: error handling 27 | return 0; 28 | } 29 | 30 | // get header 31 | if (!IGTLtoHeader(dynamic_pointer_cast(msg), header, outMetaInfo)) 32 | { 33 | return 0; 34 | } 35 | 36 | dest->LabelMetaDataElements.clear(); 37 | int nElements = msg->GetNumberOfLabelMetaElement(); 38 | for (int i = 0; i < nElements; i++) 39 | { 40 | igtl::LabelMetaElement::Pointer lbMetaElement; 41 | msg->GetLabelMetaElement(i, lbMetaElement); 42 | 43 | igtlUint16 size[3]; 44 | lbMetaElement->GetSize(size); 45 | 46 | LabelMetaElement element; 47 | element.Name = lbMetaElement->GetName(); 48 | element.DeviceName = lbMetaElement->GetDeviceName(); 49 | element.Label = lbMetaElement->GetLabel(); 50 | unsigned char r,b,g,a = 0; 51 | lbMetaElement->GetRGBA(r,g,b,a); 52 | element.RGBA[0] = r; 53 | element.RGBA[1] = g; 54 | element.RGBA[2] = b; 55 | element.RGBA[3] = a; 56 | element.Size[0] = size[0]; 57 | element.Size[1] = size[1]; 58 | element.Size[2] = size[2]; 59 | element.Owner = lbMetaElement->GetOwner(); 60 | dest->LabelMetaDataElements.push_back(element); 61 | } 62 | 63 | return 1; 64 | } 65 | 66 | //--------------------------------------------------------------------------- 67 | int igtlioLabelMetaConverter::toIGTL(const HeaderData& header, const ContentData& source, igtl::LabelMetaMessage::Pointer* dest, igtl::MessageBase::MetaDataMap metaInfo) 68 | { 69 | if (dest->IsNull()) 70 | { 71 | *dest = igtl::LabelMetaMessage::New(); 72 | } 73 | (*dest)->InitPack(); 74 | igtl::LabelMetaMessage::Pointer msg = *dest; 75 | 76 | if (!metaInfo.empty()) 77 | { 78 | msg->SetHeaderVersion(IGTL_HEADER_VERSION_2); 79 | } 80 | igtl::MessageBase::Pointer basemsg = dynamic_pointer_cast(msg); 81 | HeadertoIGTL(header, &basemsg, metaInfo); 82 | 83 | for (LabelMetaDataList::const_iterator labelMetaDataIt = source.LabelMetaDataElements.begin(); labelMetaDataIt != source.LabelMetaDataElements.end(); ++labelMetaDataIt) 84 | { 85 | igtl::LabelMetaElement::Pointer labelMetaElement = igtl::LabelMetaElement::New(); 86 | labelMetaElement->SetName(labelMetaDataIt->Name.c_str()); 87 | labelMetaElement->SetDeviceName(labelMetaDataIt->DeviceName.c_str()); 88 | labelMetaElement->SetLabel(labelMetaDataIt->Label); 89 | labelMetaElement->SetRGBA(labelMetaDataIt->RGBA[0], labelMetaDataIt->RGBA[1], labelMetaDataIt->RGBA[2], labelMetaDataIt->RGBA[3]); 90 | labelMetaElement->SetSize(labelMetaDataIt->Size[0], labelMetaDataIt->Size[1], labelMetaDataIt->Size[2]); 91 | labelMetaElement->SetOwner(labelMetaDataIt->Owner.c_str()); 92 | msg->AddLabelMetaElement(labelMetaElement); 93 | } 94 | 95 | msg->Pack(); 96 | return 1; 97 | } 98 | -------------------------------------------------------------------------------- /Testing/testDeduceToolBasedOnName.cxx: -------------------------------------------------------------------------------- 1 | #include "igtlioFixture.h" 2 | #include "igtlioSession.h" 3 | #include "igtlioTransformDevice.h" 4 | #include "igtlioTestUtilities.h" 5 | 6 | /// 7 | /// Setup a client and server. 8 | /// Simulate a server sending: 9 | /// IMAGE and TRANSFROM from a usprobe 10 | /// TRANSFORM from a pointer 11 | /// Receive messages on the client. 12 | /// Deduce tools (usprobe and pointer) base on incoming messages. 13 | /// 14 | 15 | int main(int argc, char **argv) 16 | { 17 | igtlioClientServerFixture fixture; 18 | 19 | if (!fixture.ConnectClientToServer()) 20 | return TEST_FAILED; 21 | 22 | if (fixture.Client.Logic->GetNumberOfDevices() != 0) 23 | { 24 | std::cout << "ERROR: Client has devices before they have been added or fundamental error!" << std::endl; 25 | return TEST_FAILED; 26 | } 27 | 28 | std::cout << "*** Connection done" << std::endl; 29 | 30 | //--------------------------------------------------------------------------- 31 | 32 | std::string usprobe_name = "usprobe"; 33 | std::string usprobe_image_stream_name = usprobe_name+"_image"; 34 | std::string usprobe_transform_stream_name = usprobe_name+"_transform"; 35 | 36 | igtlioImageDevicePointer imageDevice; 37 | imageDevice = fixture.Server.Session->SendImage(usprobe_image_stream_name, 38 | fixture.CreateTestImage(), 39 | fixture.CreateTestTransform()); 40 | 41 | igtlioTransformDevicePointer usprobe_transformDevice; 42 | usprobe_transformDevice = fixture.Server.Session->SendTransform(usprobe_transform_stream_name, 43 | fixture.CreateTestTransform()); 44 | 45 | std::string pointer_name = "pointer"; 46 | std::string pointer_transform_stream_name = pointer_name+"_transform"; 47 | 48 | igtlioTransformDevicePointer transformDevice; 49 | transformDevice = fixture.Server.Session->SendTransform(pointer_transform_stream_name, 50 | fixture.CreateTestTransform()); 51 | 52 | //-------------------------------------------------------------------------- 53 | 54 | int number_of_devices = 3; 55 | if (!fixture.LoopUntilEventDetected(&fixture.Client, igtlioLogic::NewDeviceEvent, number_of_devices)) 56 | { 57 | std::cout << "ERROR: Did not get " << number_of_devices << " events" << std::endl; 58 | return TEST_FAILED; 59 | } 60 | 61 | //--------------------------------------------------------------------------- 62 | 63 | std::map tools; 64 | for(int i=0; i< fixture.Client.Logic->GetNumberOfDevices(); ++i) 65 | { 66 | igtlioDevicePointer device = fixture.Client.Logic->GetDevice(i); 67 | std::string tool_name = fixture.Translator.GetToolNameFromDeviceName(device->GetDeviceName()); 68 | if(tool_name != usprobe_name && tool_name != pointer_name) 69 | { 70 | std::cout << "ERROR: tool is not what is expected: " << tool_name << std::endl; 71 | return TEST_FAILED; 72 | } 73 | else 74 | tools[tool_name] = 1; 75 | } 76 | 77 | if(tools.size() != 2) 78 | { 79 | std::cout << "ERROR: Expected 2 tools to be present, found " << tools.size() << std::endl; 80 | return TEST_FAILED; 81 | } 82 | 83 | std::map::iterator it; 84 | for(it=tools.begin() ; it!=tools.end(); ++it) 85 | { 86 | std::string type = fixture.Translator.DetermineTypeBasedOnToolName(it->first); 87 | if(type == "unknown") 88 | { 89 | std::cout << "ERROR: Tool with name " << it->first << " is of unknown type." << std::endl; 90 | return TEST_FAILED; 91 | } 92 | } 93 | 94 | 95 | return TEST_SUCCESS; 96 | } 97 | -------------------------------------------------------------------------------- /GUI/DeviceWidgets/qIGTLIOStringDeviceWidget.cxx: -------------------------------------------------------------------------------- 1 | #include "qIGTLIOStringDeviceWidget.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "vtkCommand.h" 10 | #include 11 | 12 | #include "igtlioDevice.h" 13 | #include "igtlioStringDevice.h" 14 | #include "qIGTLIOGuiUtilities.h" 15 | 16 | //--------------------------------------------------------------------------- 17 | qIGTLIODeviceWidget* vtkIGTLIOStringDeviceWidgetCreator::Create() 18 | { 19 | return new qIGTLIOStringDeviceWidget(); 20 | } 21 | 22 | //--------------------------------------------------------------------------- 23 | std::string vtkIGTLIOStringDeviceWidgetCreator::GetDeviceType() const 24 | { 25 | return igtlioStringConverter::GetIGTLTypeName(); 26 | } 27 | 28 | //--------------------------------------------------------------------------- 29 | vtkStandardNewMacro(vtkIGTLIOStringDeviceWidgetCreator); 30 | 31 | 32 | 33 | //--------------------------------------------------------------------------- 34 | //--------------------------------------------------------------------------- 35 | 36 | 37 | qIGTLIOStringDeviceWidget::qIGTLIOStringDeviceWidget(QWidget* parent) : qIGTLIODeviceWidget(parent) 38 | { 39 | 40 | } 41 | 42 | void qIGTLIOStringDeviceWidget::setupUi() 43 | { 44 | QGridLayout* layout = new QGridLayout(this); 45 | 46 | DeviceNameEdit = new QLineEdit; 47 | TimestampEdit = new QLineEdit; 48 | EncodingEdit = new QLineEdit; 49 | StringEdit = new QLineEdit; 50 | connect(StringEdit, SIGNAL(textEdited(const QString &)), this, SLOT(onGUIModified())); 51 | 52 | int line=0; 53 | this->AddCaptionedLineEdit(layout, DeviceNameEdit, "device: ", line++); 54 | this->AddCaptionedLineEdit(layout, TimestampEdit, "timestamp: ", line++); 55 | this->AddCaptionedLineEdit(layout, EncodingEdit, "encoding: ", line++); 56 | this->AddCaptionedLineEdit(layout, StringEdit, "string: ", line++, false); 57 | } 58 | 59 | void qIGTLIOStringDeviceWidget::AddCaptionedLineEdit(QGridLayout *layout, QLineEdit* edit, QString caption, int line, bool read_only) 60 | { 61 | layout->addWidget(new QLabel(caption), line, 0); 62 | edit->setReadOnly(read_only); 63 | layout->addWidget(edit, line, 1); 64 | } 65 | 66 | void qIGTLIOStringDeviceWidget::onGUIModified() 67 | { 68 | igtlioStringDevice* device = dynamic_cast(Device.GetPointer()); 69 | if (!device) 70 | return; 71 | 72 | igtlioStringConverter::ContentData content = device->GetContent(); 73 | content.encoding = EncodingEdit->text().toInt(); 74 | content.string_msg = StringEdit->text().toStdString(); 75 | device->SetContent(content); 76 | } 77 | 78 | void qIGTLIOStringDeviceWidget::blockGUI(bool on) 79 | { 80 | StringEdit->blockSignals(on); 81 | } 82 | 83 | void qIGTLIOStringDeviceWidget::onDeviceModified() 84 | { 85 | this->blockGUI(true); 86 | DeviceNameEdit->setText(""); 87 | TimestampEdit->setText(""); 88 | EncodingEdit->setText(""); 89 | StringEdit->setText(""); 90 | 91 | QString text = (Device ? QString(convertDeviceNameToDisplay(Device->GetDeviceName()).c_str()) : "none"); 92 | DeviceNameEdit->setText(text); 93 | 94 | if (!Device) 95 | return; 96 | 97 | QDateTime timestamp = QDateTime::fromMSecsSinceEpoch(Device->GetTimestamp()*1000); 98 | TimestampEdit->setText(timestamp.toString("hh:mm:ss.zzz")); 99 | 100 | igtlioStringDevice* device = dynamic_cast(Device.GetPointer()); 101 | 102 | if (!device) 103 | return; 104 | 105 | EncodingEdit->setText(QString::number(device->GetContent().encoding)); 106 | StringEdit->setText(device->GetContent().string_msg.c_str()); 107 | this->blockGUI(false); 108 | } 109 | -------------------------------------------------------------------------------- /Devices/igtlioStringDevice.cxx: -------------------------------------------------------------------------------- 1 | #include "igtlioStringDevice.h" 2 | #include 3 | #include "igtlStringMessage.h" 4 | 5 | //--------------------------------------------------------------------------- 6 | igtlioDevicePointer igtlioStringDeviceCreator::Create(std::string device_name) 7 | { 8 | igtlioStringDevicePointer retval = igtlioStringDevicePointer::New(); 9 | retval->SetDeviceName(device_name); 10 | return retval; 11 | } 12 | 13 | //--------------------------------------------------------------------------- 14 | std::string igtlioStringDeviceCreator::GetDeviceType() const 15 | { 16 | return igtlioStringConverter::GetIGTLTypeName(); 17 | } 18 | 19 | //--------------------------------------------------------------------------- 20 | vtkStandardNewMacro(igtlioStringDeviceCreator); 21 | 22 | 23 | 24 | 25 | //--------------------------------------------------------------------------- 26 | vtkStandardNewMacro(igtlioStringDevice); 27 | //--------------------------------------------------------------------------- 28 | igtlioStringDevice::igtlioStringDevice() 29 | { 30 | } 31 | 32 | //--------------------------------------------------------------------------- 33 | igtlioStringDevice::~igtlioStringDevice() 34 | { 35 | } 36 | 37 | //--------------------------------------------------------------------------- 38 | std::string igtlioStringDevice::GetDeviceType() const 39 | { 40 | return igtlioStringConverter::GetIGTLTypeName(); 41 | } 42 | 43 | //--------------------------------------------------------------------------- 44 | unsigned int igtlioStringDevice::GetDeviceContentModifiedEvent() const 45 | { 46 | return StringModifiedEvent; 47 | } 48 | 49 | //--------------------------------------------------------------------------- 50 | int igtlioStringDevice::ReceiveIGTLMessage(igtl::MessageBase::Pointer buffer, bool checkCRC) 51 | { 52 | int success = igtlioStringConverter::fromIGTL(buffer, &HeaderData, &Content, checkCRC, this->metaInfo); 53 | if (success) 54 | { 55 | this->Modified(); 56 | this->InvokeEvent(StringModifiedEvent, this); 57 | } 58 | return success; 59 | } 60 | 61 | //--------------------------------------------------------------------------- 62 | igtl::MessageBase::Pointer igtlioStringDevice::GetIGTLMessage() 63 | { 64 | 65 | if (!igtlioStringConverter::toIGTL(HeaderData, Content, &this->OutMessage, this->metaInfo)) 66 | { 67 | return 0; 68 | } 69 | 70 | return dynamic_pointer_cast(this->OutMessage); 71 | } 72 | 73 | //--------------------------------------------------------------------------- 74 | igtl::MessageBase::Pointer igtlioStringDevice::GetIGTLMessage(MESSAGE_PREFIX prefix) 75 | { 76 | if (prefix==MESSAGE_PREFIX_NOT_DEFINED) 77 | { 78 | return this->GetIGTLMessage(); 79 | } 80 | 81 | return igtl::MessageBase::Pointer(); 82 | } 83 | 84 | //--------------------------------------------------------------------------- 85 | std::set igtlioStringDevice::GetSupportedMessagePrefixes() const 86 | { 87 | std::set retval; 88 | retval.insert(MESSAGE_PREFIX_NOT_DEFINED); 89 | return retval; 90 | } 91 | 92 | void igtlioStringDevice::SetContent(igtlioStringConverter::ContentData content) 93 | { 94 | Content = content; 95 | this->Modified(); 96 | this->InvokeEvent(StringModifiedEvent, this); 97 | } 98 | 99 | igtlioStringConverter::ContentData igtlioStringDevice::GetContent() 100 | { 101 | return Content; 102 | } 103 | 104 | //--------------------------------------------------------------------------- 105 | void igtlioStringDevice::PrintSelf(ostream& os, vtkIndent indent) 106 | { 107 | igtlioDevice::PrintSelf(os, indent); 108 | 109 | os << indent << "Encoding:\t" << Content.encoding << "\n"; 110 | os << indent << "String:\t" << Content.string_msg << "\n"; 111 | } 112 | -------------------------------------------------------------------------------- /GUI/qMRMLIGTLIOTreeView.h: -------------------------------------------------------------------------------- 1 | /*============================================================================== 2 | 3 | Program: 3D Slicer 4 | 5 | Copyright (c) 2010 Kitware Inc. 6 | 7 | See COPYRIGHT.txt 8 | or http://www.slicer.org/copyright/copyright.txt for details. 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | This file was originally developed by Julien Finet, Kitware Inc. 17 | and was partially funded by NIH grant 3P41RR013218-12S1 18 | 19 | ==============================================================================*/ 20 | 21 | #ifndef __qMRMLIGTLIOTreeView_h 22 | #define __qMRMLIGTLIOTreeView_h 23 | 24 | // qMRML includes 25 | #include "qMRMLTreeView.h" 26 | 27 | // OpenIGTLinkIF GUI includes 28 | #include "qSlicerOpenIGTLinkIFModuleExport.h" 29 | 30 | class qMRMLIGTLIOTreeViewPrivate; 31 | class vtkMRMLNode; 32 | class vtkMRMLScene; 33 | class vtkSlicerOpenIGTLinkIFLogic; 34 | class vtkMRMLIGTLConnectorNode; 35 | 36 | /// \ingroup Slicer_QtModules_OpenIGTLinkIF 37 | class Q_SLICER_QTMODULES_OPENIGTLINKIF_EXPORT qMRMLIGTLIOTreeView : public qMRMLTreeView 38 | { 39 | Q_OBJECT 40 | 41 | public: 42 | enum { 43 | TYPE_UNKNOWN = 0, 44 | TYPE_ROOT, 45 | TYPE_CONNECTOR, 46 | TYPE_STREAM, 47 | TYPE_DATANODE 48 | }; 49 | 50 | public: 51 | typedef qMRMLTreeView Superclass; 52 | qMRMLIGTLIOTreeView(QWidget *parent=0); 53 | virtual ~qMRMLIGTLIOTreeView(); 54 | 55 | // Register the logic 56 | void setLogic(vtkSlicerOpenIGTLinkIFLogic* logic); 57 | 58 | // void toggleLockForSelected(); 59 | // void toggleVisibilityForSelected(); 60 | // void deleteSelected(); 61 | // void selectedAsCollection(vtkCollection* collection); 62 | void setSelectedNode(const char* id); 63 | 64 | public slots: 65 | void setMRMLScene(vtkMRMLScene* scene); 66 | 67 | signals: 68 | //void connectorNodeUpdated(vtkMRMLIGTLConnectorNode*, int); 69 | void ioTreeViewUpdated(int, vtkMRMLIGTLConnectorNode*, int, vtkMRMLNode*); 70 | 71 | protected slots: 72 | void onClicked(const QModelIndex& index); 73 | virtual void onCurrentRowChanged(const QModelIndex& index); 74 | 75 | protected: 76 | QScopedPointer d_ptr; 77 | #ifndef QT_NO_CURSOR 78 | void mouseMoveEvent(QMouseEvent* e); 79 | bool viewportEvent(QEvent* e); 80 | #endif 81 | virtual void mousePressEvent(QMouseEvent* event); 82 | 83 | // Description: 84 | // rowProperty() returns row type and properties (connector node and direction). 85 | // The type can be either TYPE_UNKNOWN (error - cannot determined), 86 | // TYPE_ROOT (root), TYPE_CONNECTOR (connector node), TYPE_STREAM (stream -- IN or OUT) 87 | // or TYPE_DATANODE (data node). 88 | // If the type is TYPE_CONNECTOR, the pointer to the highlighted connector node is set 89 | // to 'cnode'. If the type is TYPE_STREAM or TYPE_DATANODE, the pointer to the parent 90 | // connector node, the direction of stream (either vtkMRMLIGTLConnectorNode::IO_INCOMING 91 | // or vtkMRMLIGTLConnectorNode::IO_OUTGOING), and the pointer to the data node 92 | // are set to 'cnode', 'dir', and 'dnode' respectively. 93 | int rowProperty(const QModelIndex& index, vtkMRMLIGTLConnectorNode* &cnode, int & dir, vtkMRMLNode* &dnode); 94 | 95 | private: 96 | Q_DECLARE_PRIVATE(qMRMLIGTLIOTreeView); 97 | Q_DISABLE_COPY(qMRMLIGTLIOTreeView); 98 | 99 | QModelIndex CurrentIndex; 100 | 101 | // toggle the visibility of an OpenIGTLinkIF 102 | // void onVisibilityColumnClicked(vtkMRMLNode* node); 103 | 104 | // toggle un-/lock of an annotation 105 | // void onLockColumnClicked(vtkMRMLNode* node); 106 | 107 | }; 108 | 109 | #endif 110 | -------------------------------------------------------------------------------- /Converter/igtlioPointConverter.cxx: -------------------------------------------------------------------------------- 1 | 2 | // OpenIGTLinkIO incldues 3 | #include "igtlioPointConverter.h" 4 | 5 | // OpenIGTLink includes 6 | #include 7 | #include 8 | 9 | //--------------------------------------------------------------------------- 10 | int igtlioPointConverter::fromIGTL(igtl::MessageBase::Pointer source, 11 | HeaderData* header, 12 | ContentData* dest, 13 | bool checkCRC, 14 | igtl::MessageBase::MetaDataMap& outMetaInfo) 15 | { 16 | // Create a message buffer to receive data 17 | igtl::PointMessage::Pointer msg; 18 | msg = igtl::PointMessage::New(); 19 | msg->Copy(source); // !! TODO: copy makes performance issue. 20 | 21 | // Deserialize the data 22 | // If CheckCRC==0, CRC check is skipped. 23 | int c = msg->Unpack(checkCRC); 24 | if ((c & igtl::MessageHeader::UNPACK_BODY) == 0) // if CRC check fails 25 | { 26 | // TODO: error handling 27 | return 0; 28 | } 29 | 30 | // get header 31 | if (!IGTLtoHeader(dynamic_pointer_cast(msg), header, outMetaInfo)) 32 | { 33 | return 0; 34 | } 35 | 36 | dest->PointElements.clear(); 37 | int nElements = msg->GetNumberOfPointElement(); 38 | for (int i = 0; i < nElements; i++) 39 | { 40 | igtl::PointElement::Pointer pointElement; 41 | msg->GetPointElement(i, pointElement); 42 | 43 | PointElement element; 44 | element.Name = pointElement->GetName(); 45 | element.GroupName = pointElement->GetGroupName(); 46 | unsigned char r,b,g,a = 0; 47 | pointElement->GetRGBA(r,g,b,a); 48 | element.RGBA[0] = r; 49 | element.RGBA[1] = g; 50 | element.RGBA[2] = b; 51 | element.RGBA[3] = a; 52 | float position[3] = { 0,0,0 }; 53 | pointElement->GetPosition(position); 54 | for (int i = 0; i < 3; ++i) 55 | { 56 | element.Position[i] = position[i]; 57 | } 58 | element.Radius = pointElement->GetRadius(); 59 | element.Owner = pointElement->GetOwner(); 60 | dest->PointElements.push_back(element); 61 | } 62 | 63 | return 1; 64 | } 65 | 66 | //--------------------------------------------------------------------------- 67 | int igtlioPointConverter::toIGTL(const HeaderData& header, const ContentData& source, igtl::PointMessage::Pointer* dest, igtl::MessageBase::MetaDataMap metaInfo) 68 | { 69 | if (dest->IsNull()) 70 | { 71 | *dest = igtl::PointMessage::New(); 72 | } 73 | (*dest)->InitPack(); 74 | igtl::PointMessage::Pointer msg = *dest; 75 | 76 | if (!metaInfo.empty()) 77 | { 78 | msg->SetHeaderVersion(IGTL_HEADER_VERSION_2); 79 | } 80 | igtl::MessageBase::Pointer basemsg = dynamic_pointer_cast(msg); 81 | HeadertoIGTL(header, &basemsg, metaInfo); 82 | 83 | if (msg->GetNumberOfPointElement() > source.PointElements.size()) 84 | { 85 | // there is no API to delete a single element, so if we need to delete then we delete all 86 | msg->ClearPointElement(); 87 | } 88 | int pointIndex = 0; 89 | for (PointList::const_iterator pointIt = source.PointElements.begin(); pointIt != source.PointElements.end(); ++pointIt) 90 | { 91 | igtl::PointElement::Pointer pointElement; 92 | if (pointIndex < msg->GetNumberOfPointElement()) 93 | { 94 | msg->GetPointElement(pointIndex, pointElement); 95 | } 96 | else 97 | { 98 | pointElement = igtl::PointElement::New(); 99 | msg->AddPointElement(pointElement); 100 | } 101 | pointElement->SetName(pointIt->Name.c_str()); 102 | pointElement->SetGroupName(pointIt->GroupName.c_str()); 103 | pointElement->SetRGBA(pointIt->RGBA[0], pointIt->RGBA[1], pointIt->RGBA[2], pointIt->RGBA[3]); 104 | pointElement->SetPosition(pointIt->Position[0], pointIt->Position[1], pointIt->Position[2]); 105 | pointElement->SetRadius(pointIt->Radius); 106 | pointElement->SetOwner(pointIt->Owner.c_str()); 107 | pointIndex++; 108 | } 109 | 110 | msg->Pack(); 111 | return 1; 112 | } 113 | -------------------------------------------------------------------------------- /Testing/testReceiveVideo.cxx: -------------------------------------------------------------------------------- 1 | #include 2 | #include "igtlioLogic.h" 3 | #include "igtlioConnector.h" 4 | #include "vtkTimerLog.h" 5 | #include "vtkImageData.h" 6 | #include "igtlioVideoConverter.h" 7 | #include "vtkMatrix4x4.h" 8 | #include 9 | #include "igtlioVideoConverter.h" 10 | #include 11 | #include "igtlioFixture.h" 12 | #include "igtlioVideoDevice.h" 13 | #include "igtlioSession.h" 14 | #include "igtlMessageDebugFunction.h" 15 | 16 | bool a_compare(vtkSmartPointer a, vtkSmartPointer b) 17 | { 18 | #if defined(OpenIGTLink_ENABLE_VIDEOSTREAMING) 19 | igtlUint8* yuv_a = new igtlUint8[a->GetDimensions()[0]*a->GetDimensions()[1]*3/2]; 20 | igtlUint8* rgb_a = new igtlUint8[a->GetDimensions()[0]*a->GetDimensions()[1]*3]; 21 | GenericEncoder::ConvertRGBToYUV((igtlUint8*)a->GetScalarPointer(), yuv_a, a->GetDimensions()[0], a->GetDimensions()[1]); 22 | GenericDecoder::ConvertYUVToRGB(yuv_a, rgb_a, b->GetDimensions()[0], b->GetDimensions()[1]); 23 | memcmp(rgb_a, a->GetScalarPointer(),a->GetDimensions()[0]*a->GetDimensions()[1]*3);// The conversion is not valid. Image is not the same after conversion. 24 | //TestDebugCharArrayCmp(b->GetScalarPointer(),rgb_a,a->GetDimensions()[0]*a->GetDimensions()[1]*3); 25 | int sumError = 0; 26 | for (int i = 0 ; i< a->GetDimensions()[0]*a->GetDimensions()[1];i++) 27 | { 28 | sumError += abs(*((igtlUint8*)rgb_a+i)-*((igtlUint8*)b->GetScalarPointer()+i)); 29 | } 30 | if (sumErrorGetDimensions()[0]*a->GetDimensions()[1]) // To do, check the lossless encoding problem. most likely from the RGB and YUV conversion 31 | return true; 32 | #endif 33 | return false; 34 | } 35 | 36 | bool compare(igtlioVideoDevicePointer a, igtlioVideoDevicePointer b) 37 | { 38 | if (a->GetDeviceName() != b->GetDeviceName()) 39 | return false; 40 | if (a->GetDeviceType() != b->GetDeviceType()) 41 | return false; 42 | if (!a_compare(a->GetContent().image, b->GetContent().image)) 43 | return false; 44 | 45 | return true; 46 | } 47 | 48 | 49 | int main(int argc, char **argv) 50 | { 51 | igtlioClientServerFixture fixture; 52 | 53 | if (!fixture.ConnectClientToServer()) 54 | return 1; 55 | 56 | 57 | if (fixture.Client.Logic->GetNumberOfDevices() != 0) 58 | { 59 | std::cout << "ERROR: Client has devices before they have been added or fundamental error!" << std::endl; 60 | return 1; 61 | } 62 | 63 | std::cout << "*** Connection done" << std::endl; 64 | //--------------------------------------------------------------------------- 65 | 66 | igtlioVideoDevicePointer videoDevice; 67 | vtkSmartPointer image = vtkImageData::New(); 68 | fixture.CreateTestFrame(image); 69 | videoDevice = fixture.Server.Session->SendFrame("TestDevice_Image",image); 70 | std::cout << "*** Sent message from Server to Client" << std::endl; 71 | //--------------------------------------------------------------------------- 72 | 73 | if (!fixture.LoopUntilEventDetected(&fixture.Client, igtlioLogic::NewDeviceEvent)) 74 | { 75 | return 1; 76 | } 77 | 78 | if (fixture.Client.Logic->GetNumberOfDevices() == 0) 79 | { 80 | std::cout << "FAILURE: No devices received." << std::endl; 81 | return 1; 82 | } 83 | 84 | igtlioVideoDevicePointer receivedDevice; 85 | receivedDevice = igtlioVideoDevice::SafeDownCast(fixture.Client.Logic->GetDevice(0)); 86 | if (!receivedDevice) 87 | { 88 | std::cout << "FAILURE: Non-video device received." << std::endl; 89 | return 1; 90 | } 91 | 92 | std::cout << "*** Client received video device." << std::endl; 93 | //--------------------------------------------------------------------------- 94 | if (!compare(videoDevice, receivedDevice)) 95 | { 96 | std::cout << "FAILURE: frame differs from the one sent from server." << std::endl; 97 | return 1; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /Converter/igtlioImageMetaConverter.cxx: -------------------------------------------------------------------------------- 1 | 2 | // OpenIGTLinkIO includes 3 | #include "igtlioImageMetaConverter.h" 4 | 5 | // OpenIGTLink includes 6 | #include 7 | #include 8 | 9 | //--------------------------------------------------------------------------- 10 | int igtlioImageMetaConverter::fromIGTL(igtl::MessageBase::Pointer source, 11 | HeaderData* header, 12 | ContentData* dest, 13 | bool checkCRC, 14 | igtl::MessageBase::MetaDataMap& outMetaInfo) 15 | { 16 | // Create a message buffer to receive data 17 | igtl::ImageMetaMessage::Pointer msg; 18 | msg = igtl::ImageMetaMessage::New(); 19 | msg->Copy(source); // !! TODO: copy makes performance issue. 20 | 21 | // Deserialize the data 22 | // If CheckCRC==0, CRC check is skipped. 23 | int c = msg->Unpack(checkCRC); 24 | if ((c & igtl::MessageHeader::UNPACK_BODY) == 0) // if CRC check fails 25 | { 26 | // TODO: error handling 27 | return 0; 28 | } 29 | 30 | // get header 31 | if (!IGTLtoHeader(dynamic_pointer_cast(msg), header, outMetaInfo)) 32 | { 33 | return 0; 34 | } 35 | 36 | dest->ImageMetaDataElements.clear(); 37 | int nElements = msg->GetNumberOfImageMetaElement(); 38 | for (int i = 0; i < nElements; i++) 39 | { 40 | igtl::ImageMetaElement::Pointer imgMetaElement; 41 | msg->GetImageMetaElement(i, imgMetaElement); 42 | 43 | igtlUint16 size[3]; 44 | imgMetaElement->GetSize(size); 45 | 46 | igtl::TimeStamp::Pointer ts; 47 | imgMetaElement->GetTimeStamp(ts); 48 | double time = ts->GetTimeStamp(); 49 | 50 | ImageMetaElement element; 51 | element.Name = imgMetaElement->GetName(); 52 | element.DeviceName = imgMetaElement->GetDeviceName(); 53 | element.Modality = imgMetaElement->GetModality(); 54 | element.PatientName = imgMetaElement->GetPatientName(); 55 | element.PatientID = imgMetaElement->GetPatientID(); 56 | element.Timestamp = time; 57 | element.Size[0] = size[0]; 58 | element.Size[1] = size[1]; 59 | element.Size[2] = size[2]; 60 | element.ScalarType = imgMetaElement->GetScalarType(); 61 | dest->ImageMetaDataElements.push_back(element); 62 | } 63 | 64 | return 1; 65 | } 66 | 67 | //--------------------------------------------------------------------------- 68 | int igtlioImageMetaConverter::toIGTL(const HeaderData& header, const ContentData& source, igtl::ImageMetaMessage::Pointer* dest, igtl::MessageBase::MetaDataMap metaInfo) 69 | { 70 | if (dest->IsNull()) 71 | { 72 | *dest = igtl::ImageMetaMessage::New(); 73 | } 74 | (*dest)->InitPack(); 75 | igtl::ImageMetaMessage::Pointer msg = *dest; 76 | 77 | if (!metaInfo.empty()) 78 | { 79 | msg->SetHeaderVersion(IGTL_HEADER_VERSION_2); 80 | } 81 | igtl::MessageBase::Pointer basemsg = dynamic_pointer_cast(msg); 82 | HeadertoIGTL(header, &basemsg, metaInfo); 83 | 84 | for (ImageMetaDataList::const_iterator imageMetaDataIt = source.ImageMetaDataElements.begin(); imageMetaDataIt != source.ImageMetaDataElements.end(); ++imageMetaDataIt) 85 | { 86 | igtl::ImageMetaElement::Pointer imageMetaElement = igtl::ImageMetaElement::New(); 87 | imageMetaElement->SetName(imageMetaDataIt->Name.c_str()); 88 | imageMetaElement->SetDeviceName(imageMetaDataIt->DeviceName.c_str()); 89 | imageMetaElement->SetModality(imageMetaDataIt->Modality.c_str()); 90 | imageMetaElement->SetPatientName(imageMetaDataIt->PatientName.c_str()); 91 | imageMetaElement->SetPatientID(imageMetaDataIt->PatientID.c_str()); 92 | igtl::TimeStamp::Pointer timestamp = igtl::TimeStamp::New(); 93 | timestamp->SetTime(imageMetaDataIt->Timestamp); 94 | imageMetaElement->SetTimeStamp(timestamp); 95 | imageMetaElement->SetSize(imageMetaDataIt->Size[0], imageMetaDataIt->Size[1], imageMetaDataIt->Size[2]); 96 | imageMetaElement->SetScalarType(imageMetaDataIt->ScalarType); 97 | msg->AddImageMetaElement(imageMetaElement); 98 | } 99 | 100 | msg->Pack(); 101 | return 1; 102 | } 103 | -------------------------------------------------------------------------------- /GUI/qIGTLIODeviceAddWidget.cxx: -------------------------------------------------------------------------------- 1 | #include "qIGTLIODeviceAddWidget.h" 2 | 3 | #include "igtlioLogic.h" 4 | #include "qIGTLIODevicesModel.h" 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include "vtkIGTLIONode.h" 15 | #include "qIGTLIOGuiUtilities.h" 16 | 17 | qIGTLIODeviceAddWidget::qIGTLIODeviceAddWidget() 18 | { 19 | QVBoxLayout* topLayout = new QVBoxLayout(this); 20 | topLayout->setContentsMargins(0, 0, 0, 0); 21 | 22 | QFrame* buttonFrame = new QFrame; 23 | buttonFrame->setFrameShape(QFrame::NoFrame); 24 | buttonFrame->setFrameShadow(QFrame::Plain); 25 | topLayout->addWidget(buttonFrame); 26 | QHBoxLayout* buttonLayout = new QHBoxLayout(buttonFrame); 27 | buttonLayout->setContentsMargins(0, 0, 0, 0); 28 | 29 | mAddDeviceAction = new QAction("Add Device", this); 30 | connect(mAddDeviceAction, SIGNAL(triggered()), this, SLOT(onAddDevice())); 31 | QToolButton* button = new QToolButton(this); 32 | button->setDefaultAction(mAddDeviceAction); 33 | buttonLayout->addWidget(button); 34 | 35 | mSelectDeviceType = new QComboBox; 36 | buttonLayout->addWidget(mSelectDeviceType); 37 | 38 | mDeviceName = new QLineEdit; 39 | mDeviceName->setText(convertDeviceNameToDisplay("").c_str()); 40 | mDeviceName->setToolTip("Enter device name for new device, or empty for a broadcast"); 41 | buttonLayout->addWidget(mDeviceName); 42 | 43 | buttonLayout->addStretch(1); 44 | 45 | this->onCurrentConnectorChanged(); 46 | } 47 | 48 | void qIGTLIODeviceAddWidget::setLogic(igtlioLogicPointer logic) 49 | { 50 | Logic = logic; 51 | } 52 | 53 | void qIGTLIODeviceAddWidget::setModel(qIGTLIODevicesModel *model) 54 | { 55 | DevicesModel = model; 56 | connect(DevicesModel->selectionModel(), SIGNAL(currentRowChanged(const QModelIndex&, const QModelIndex&)), 57 | this, SLOT(onCurrentConnectorChanged())); 58 | this->onCurrentConnectorChanged(); 59 | } 60 | 61 | qIGTLIODevicesModelNode* qIGTLIODeviceAddWidget::getSelectedNode() 62 | { 63 | if (DevicesModel.isNull()) 64 | return NULL; 65 | 66 | QModelIndex index = DevicesModel->selectionModel()->currentIndex(); 67 | qIGTLIODevicesModelNode* node = DevicesModel->getNodeFromIndex(index); 68 | return node; 69 | } 70 | 71 | void qIGTLIODeviceAddWidget::onCurrentConnectorChanged() 72 | { 73 | qIGTLIODevicesModelNode* node = this->getSelectedNode(); 74 | 75 | this->setEnabled(node); 76 | 77 | if (!node) 78 | return; 79 | 80 | int index = mSelectDeviceType->currentIndex(); 81 | mSelectDeviceType->clear(); 82 | std::vector availableDeviceTypes = node->connector->GetDeviceFactory()->GetAvailableDeviceTypes(); 83 | for (unsigned i=0; iaddItem(availableDeviceTypes[i].c_str()); 86 | } 87 | 88 | 89 | if (index<0) 90 | index = 0; 91 | if (index >= mSelectDeviceType->count()) 92 | { 93 | index = mSelectDeviceType->count() -1; 94 | } 95 | mSelectDeviceType->setCurrentIndex(index); 96 | } 97 | 98 | void qIGTLIODeviceAddWidget::onAddDevice() 99 | { 100 | qIGTLIODevicesModelNode* node = this->getSelectedNode(); 101 | 102 | if (!node) 103 | return; 104 | 105 | std::string deviceType = mSelectDeviceType->currentText().toStdString(); 106 | std::string deviceName = mDeviceName->text().toStdString(); 107 | deviceName = convertDisplayToDeviceName(deviceName); 108 | 109 | if (!node->connector->GetDevice(igtlioDeviceKeyType(deviceType, deviceName))) 110 | { 111 | qIGTLIODevicesModelNode* node = this->getSelectedNode(); 112 | igtlioDevicePointer device = node->connector->GetDeviceFactory()->create(deviceType, deviceName); 113 | device->SetMessageDirection(igtlioDevice::MESSAGE_DIRECTION_OUT); 114 | node->connector->AddDevice(device); 115 | } 116 | 117 | // TODO select the device, even if it was not created. Expand view to see it. 118 | } 119 | 120 | -------------------------------------------------------------------------------- /Devices/igtlioVideoDevice.h: -------------------------------------------------------------------------------- 1 | /*========================================================================== 2 | 3 | Portions (c) Copyright 2008-2009 Brigham and Women's Hospital (BWH) All Rights Reserved. 4 | 5 | See Doc/copyright/copyright.txt 6 | or http://www.slicer.org/copyright/copyright.txt for details. 7 | 8 | Date: $Date: 2010-11-23 00:58:13 -0500 (Tue, 23 Nov 2010) $ 9 | Version: $Revision: 15552 $ 10 | 11 | ==========================================================================*/ 12 | 13 | #ifndef IGTLIOVIDEODEVICE_H 14 | #define IGTLIOVIDEODEVICE_H 15 | 16 | #include "igtlioDevicesExport.h" 17 | 18 | #include "igtlioVideoConverter.h" 19 | #include "igtlioDevice.h" 20 | 21 | 22 | class vtkImageData; 23 | 24 | typedef vtkSmartPointer igtlioVideoDevicePointer; 25 | 26 | /// A Device supporting the Video igtl Message. 27 | class OPENIGTLINKIO_DEVICES_EXPORT igtlioVideoDevice : public igtlioDevice 28 | { 29 | public: 30 | 31 | enum { 32 | VideoModifiedEvent = 118961, 33 | }; 34 | 35 | virtual unsigned int GetDeviceContentModifiedEvent() const VTK_OVERRIDE; 36 | virtual std::string GetDeviceType() const VTK_OVERRIDE; 37 | virtual int ReceiveIGTLMessage(igtl::MessageBase::Pointer buffer, bool checkCRC) VTK_OVERRIDE; 38 | virtual igtl::MessageBase::Pointer GetIGTLMessage() VTK_OVERRIDE; 39 | virtual igtl::MessageBase::Pointer GetIGTLMessage(MESSAGE_PREFIX prefix) VTK_OVERRIDE ; 40 | virtual std::set GetSupportedMessagePrefixes() const VTK_OVERRIDE; 41 | 42 | igtl::VideoMessage::Pointer GetCompressedIGTLMessage(); 43 | 44 | igtl::VideoMessage::Pointer GetKeyFrameMessage(); 45 | 46 | void SetContent(igtlioVideoConverter::ContentData content); 47 | 48 | igtlioVideoConverter::ContentData GetContent(); 49 | 50 | std::string GetCurrentCodecType() 51 | { 52 | return CurrentCodecType; 53 | }; 54 | 55 | int SetCurrentCodecType(std::string codecType) 56 | { 57 | if (strncmp(codecType.c_str(), IGTL_VIDEO_CODEC_NAME_X265, IGTL_VIDEO_CODEC_NAME_SIZE)==0 || 58 | strncmp(codecType.c_str(), IGTL_VIDEO_CODEC_NAME_VP9, IGTL_VIDEO_CODEC_NAME_SIZE)==0 || 59 | strncmp(codecType.c_str(), IGTL_VIDEO_CODEC_NAME_H264, IGTL_VIDEO_CODEC_NAME_SIZE)==0 || 60 | strncmp(codecType.c_str(), IGTL_VIDEO_CODEC_NAME_OPENHEVC, IGTL_VIDEO_CODEC_NAME_SIZE)==0) 61 | { 62 | this->CurrentCodecType = std::string(codecType); 63 | return 0; 64 | } 65 | else 66 | { 67 | return -1; 68 | } 69 | }; 70 | 71 | 72 | public: 73 | static igtlioVideoDevice *New(); 74 | vtkTypeMacro(igtlioVideoDevice,igtlioDevice); 75 | void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE; 76 | 77 | protected: 78 | igtlioVideoDevice(); 79 | ~igtlioVideoDevice(); 80 | 81 | protected: 82 | igtl::StartVideoMessage::Pointer StartVideoMessage; 83 | 84 | igtl::StopVideoMessage::Pointer StopVideoMessage; 85 | 86 | igtlioVideoConverter::ContentData Content; 87 | 88 | igtl::GenericDecoder* VideoStreamDecoderI420; 89 | 90 | igtl::GenericDecoder* VideoStreamDecoderVPX; 91 | 92 | igtl::GenericDecoder* VideoStreamDecoderX265; 93 | 94 | igtl::GenericDecoder* VideoStreamDecoderH264; 95 | 96 | igtl::GenericDecoder* VideoStreamDecoderAV1; 97 | 98 | std::map DecodersMap; 99 | 100 | igtl::SourcePicture* DecodedPic; 101 | 102 | std::string CurrentCodecType; 103 | 104 | igtl::GenericEncoder* VideoStreamEncoderI420; 105 | 106 | igtl::GenericEncoder* VideoStreamEncoderVPX; 107 | 108 | igtl::GenericEncoder* VideoStreamEncoderX265; 109 | 110 | igtl::GenericEncoder* VideoStreamEncoderH264; 111 | 112 | igtl::GenericEncoder* VideoStreamEncoderAV1; 113 | 114 | }; 115 | 116 | //--------------------------------------------------------------------------- 117 | class OPENIGTLINKIO_DEVICES_EXPORT igtlioVideoDeviceCreator : public igtlioDeviceCreator 118 | { 119 | public: 120 | virtual igtlioDevicePointer Create(std::string device_name) VTK_OVERRIDE; 121 | virtual std::string GetDeviceType() const VTK_OVERRIDE; 122 | 123 | static igtlioVideoDeviceCreator *New(); 124 | vtkTypeMacro(igtlioVideoDeviceCreator,vtkObject); 125 | }; 126 | 127 | #endif //IGTLIOVIDEODEVICE_H 128 | -------------------------------------------------------------------------------- /Devices/igtlioStatusDevice.cxx: -------------------------------------------------------------------------------- 1 | 2 | #include "igtlioStatusDevice.h" 3 | #include 4 | 5 | //--------------------------------------------------------------------------- 6 | igtlioDevicePointer igtlioStatusDeviceCreator::Create(std::string device_name) 7 | { 8 | igtlioStatusDevicePointer retval = igtlioStatusDevicePointer::New(); 9 | retval->SetDeviceName(device_name); 10 | return retval; 11 | } 12 | 13 | //--------------------------------------------------------------------------- 14 | std::string igtlioStatusDeviceCreator::GetDeviceType() const 15 | { 16 | return igtlioStatusConverter::GetIGTLTypeName(); 17 | } 18 | 19 | //--------------------------------------------------------------------------- 20 | vtkStandardNewMacro(igtlioStatusDeviceCreator); 21 | 22 | 23 | 24 | 25 | //--------------------------------------------------------------------------- 26 | vtkStandardNewMacro(igtlioStatusDevice); 27 | //--------------------------------------------------------------------------- 28 | igtlioStatusDevice::igtlioStatusDevice() 29 | { 30 | } 31 | 32 | //--------------------------------------------------------------------------- 33 | igtlioStatusDevice::~igtlioStatusDevice() 34 | { 35 | } 36 | 37 | //--------------------------------------------------------------------------- 38 | unsigned int igtlioStatusDevice::GetDeviceContentModifiedEvent() const 39 | { 40 | return StatusModifiedEvent; 41 | } 42 | 43 | //--------------------------------------------------------------------------- 44 | std::string igtlioStatusDevice::GetDeviceType() const 45 | { 46 | return igtlioStatusConverter::GetIGTLTypeName(); 47 | } 48 | 49 | //--------------------------------------------------------------------------- 50 | int igtlioStatusDevice::ReceiveIGTLMessage(igtl::MessageBase::Pointer buffer, bool checkCRC) 51 | { 52 | int success = igtlioStatusConverter::fromIGTL(buffer, &HeaderData, &Content, checkCRC, this->metaInfo); 53 | if (success) 54 | { 55 | this->Modified(); 56 | this->InvokeEvent(StatusModifiedEvent, this); 57 | } 58 | return success; 59 | } 60 | 61 | //--------------------------------------------------------------------------- 62 | igtl::MessageBase::Pointer igtlioStatusDevice::GetIGTLMessage() 63 | { 64 | /* 65 | // cannot send a non-existent status (?) 66 | if (Content.errorname.empty()) 67 | { 68 | return 0; 69 | } 70 | */ 71 | 72 | if (!igtlioStatusConverter::toIGTL(HeaderData, Content, &this->OutMessage, this->metaInfo)) 73 | { 74 | return 0; 75 | } 76 | 77 | return dynamic_pointer_cast(this->OutMessage); 78 | } 79 | 80 | //--------------------------------------------------------------------------- 81 | igtl::MessageBase::Pointer igtlioStatusDevice::GetIGTLMessage(MESSAGE_PREFIX prefix) 82 | { 83 | /* 84 | if (prefix==MESSAGE_PREFIX_GET) 85 | { 86 | if (this->GetMessage.IsNull()) 87 | { 88 | this->GetMessage = igtl::GetStatusMessage::New(); 89 | } 90 | this->GetMessage->SetDeviceName(HeaderData.deviceName.c_str()); 91 | this->GetMessage->Pack(); 92 | return dynamic_pointer_cast(this->GetMessage); 93 | } 94 | */ 95 | if (prefix==MESSAGE_PREFIX_NOT_DEFINED) 96 | { 97 | return this->GetIGTLMessage(); 98 | } 99 | 100 | return igtl::MessageBase::Pointer(); 101 | } 102 | 103 | //--------------------------------------------------------------------------- 104 | std::set igtlioStatusDevice::GetSupportedMessagePrefixes() const 105 | { 106 | std::set retval; 107 | retval.insert(MESSAGE_PREFIX_NOT_DEFINED); 108 | return retval; 109 | } 110 | 111 | void igtlioStatusDevice::SetContent(igtlioStatusConverter::ContentData content) 112 | { 113 | Content = content; 114 | this->Modified(); 115 | this->InvokeEvent(StatusModifiedEvent, this); 116 | } 117 | 118 | igtlioStatusConverter::ContentData igtlioStatusDevice::GetContent() 119 | { 120 | return Content; 121 | } 122 | 123 | //--------------------------------------------------------------------------- 124 | void igtlioStatusDevice::PrintSelf(ostream& os, vtkIndent indent) 125 | { 126 | igtlioDevice::PrintSelf(os, indent); 127 | 128 | os << indent << "ErrorCode:\t" << Content.code << "\n"; 129 | os << indent << "ErrorSubCode:\t" << Content.subcode << "\n"; 130 | os << indent << "ErrorName:\t" << Content.errorname << "\n"; 131 | os << indent << "StatusString:\t" << Content.statusstring << "\n"; 132 | } 133 | -------------------------------------------------------------------------------- /Devices/igtlioPolyDataDevice.cxx: -------------------------------------------------------------------------------- 1 | /*========================================================================== 2 | 3 | Portions (c) Copyright 2008-2009 Brigham and Women's Hospital (BWH) All Rights Reserved. 4 | 5 | See Doc/copyright/copyright.txt 6 | or http://www.slicer.org/copyright/copyright.txt for details. 7 | 8 | Program: 3D Slicer 9 | Module: $HeadURL: https://github.com/openigtlink/OpenIGTLinkIF/blob/master/MRML/vtkIGTLToMRMLPolyData.cxx $ 10 | Date: $Date: 2010-12-07 21:39:19 -0500 (Tue, 07 Dec 2010) $ 11 | Version: $Revision: 15621 $ 12 | 13 | ==========================================================================*/ 14 | 15 | #include "igtlioPolyDataDevice.h" 16 | #include 17 | #include 18 | 19 | //--------------------------------------------------------------------------- 20 | igtlioDevicePointer igtlioPolyDataDeviceCreator::Create(std::string device_name) 21 | { 22 | igtlioPolyDataDevicePointer retval = igtlioPolyDataDevicePointer::New(); 23 | retval->SetDeviceName(device_name); 24 | return retval; 25 | } 26 | 27 | //--------------------------------------------------------------------------- 28 | std::string igtlioPolyDataDeviceCreator::GetDeviceType() const 29 | { 30 | return igtlioPolyDataConverter::GetIGTLTypeName(); 31 | } 32 | 33 | //--------------------------------------------------------------------------- 34 | vtkStandardNewMacro(igtlioPolyDataDeviceCreator); 35 | 36 | 37 | 38 | 39 | //--------------------------------------------------------------------------- 40 | vtkStandardNewMacro(igtlioPolyDataDevice); 41 | //--------------------------------------------------------------------------- 42 | igtlioPolyDataDevice::igtlioPolyDataDevice() 43 | { 44 | } 45 | 46 | //--------------------------------------------------------------------------- 47 | igtlioPolyDataDevice::~igtlioPolyDataDevice() 48 | { 49 | } 50 | 51 | //--------------------------------------------------------------------------- 52 | unsigned int igtlioPolyDataDevice::GetDeviceContentModifiedEvent() const 53 | { 54 | return PolyDataModifiedEvent; 55 | } 56 | 57 | //--------------------------------------------------------------------------- 58 | std::string igtlioPolyDataDevice::GetDeviceType() const 59 | { 60 | return igtlioPolyDataConverter::GetIGTLTypeName(); 61 | } 62 | 63 | //--------------------------------------------------------------------------- 64 | int igtlioPolyDataDevice::ReceiveIGTLMessage(igtl::MessageBase::Pointer buffer, bool checkCRC) 65 | { 66 | int success = igtlioPolyDataConverter::fromIGTL(buffer, &HeaderData, &Content, checkCRC, this->metaInfo); 67 | if (success) 68 | { 69 | this->Modified(); 70 | this->InvokeEvent(igtlioPolyDataDevice::PolyDataModifiedEvent, this); 71 | } 72 | return success; 73 | } 74 | 75 | //--------------------------------------------------------------------------- 76 | igtl::MessageBase::Pointer igtlioPolyDataDevice::GetIGTLMessage() 77 | { 78 | /* 79 | // cannot send a non-existent status (?) 80 | if (Content.errorname.empty()) 81 | { 82 | return 0; 83 | } 84 | */ 85 | 86 | if (!igtlioPolyDataConverter::toIGTL(HeaderData, Content, &this->OutMessage, this->metaInfo)) 87 | { 88 | return 0; 89 | } 90 | 91 | return dynamic_pointer_cast(this->OutMessage); 92 | } 93 | 94 | //--------------------------------------------------------------------------- 95 | igtl::MessageBase::Pointer igtlioPolyDataDevice::GetIGTLMessage(MESSAGE_PREFIX prefix) 96 | { 97 | 98 | if (prefix==MESSAGE_PREFIX_NOT_DEFINED) 99 | { 100 | return this->GetIGTLMessage(); 101 | } 102 | 103 | return igtl::MessageBase::Pointer(); 104 | } 105 | 106 | //--------------------------------------------------------------------------- 107 | std::set igtlioPolyDataDevice::GetSupportedMessagePrefixes() const 108 | { 109 | std::set retval; 110 | retval.insert(MESSAGE_PREFIX_NOT_DEFINED); 111 | return retval; 112 | } 113 | 114 | void igtlioPolyDataDevice::SetContent(igtlioPolyDataConverter::ContentData content) 115 | { 116 | Content = content; 117 | this->Modified(); 118 | this->InvokeEvent(PolyDataModifiedEvent, this); 119 | } 120 | 121 | igtlioPolyDataConverter::ContentData igtlioPolyDataDevice::GetContent() 122 | { 123 | return Content; 124 | } 125 | 126 | //--------------------------------------------------------------------------- 127 | void igtlioPolyDataDevice::PrintSelf(ostream& os, vtkIndent indent) 128 | { 129 | igtlioDevice::PrintSelf(os, indent); 130 | 131 | os << indent << "deviceName:\t" << Content.deviceName << "\n"; 132 | } 133 | -------------------------------------------------------------------------------- /Logic/igtlioLogic.h: -------------------------------------------------------------------------------- 1 | /*========================================================================== 2 | 3 | Portions (c) Copyright 2008-2009 Brigham and Women's Hospital (BWH) All Rights Reserved. 4 | 5 | See Doc/copyright/copyright.txt 6 | or http://www.slicer.org/copyright/copyright.txt for details. 7 | 8 | Program: 3D Slicer 9 | Module: $HeadURL: http://svn.slicer.org/Slicer4/trunk/Modules/OpenIGTLinkIF/vtkSlicerOpenIGTLinkIFLogic.h $ 10 | Date: $Date: 2010-06-10 11:05:22 -0400 (Thu, 10 Jun 2010) $ 11 | Version: $Revision: 13728 $ 12 | 13 | ==========================================================================*/ 14 | #ifndef IGTLIOLOGIC_H 15 | #define IGTLIOLOGIC_H 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include "igtlioLogicExport.h" 23 | #include "igtlioDevice.h" 24 | #include "igtlioConnector.h" 25 | #include "igtlioUtilities.h" 26 | 27 | typedef vtkSmartPointer igtlioLogicPointer; 28 | typedef vtkSmartPointer igtlioConnectorPointer; 29 | typedef vtkSmartPointer igtlioSessionPointer; 30 | 31 | 32 | /// Logic is the manager for the IGTLIO module. 33 | /// 34 | /// The module contains a number of Connectors, each with a specific 35 | /// TCP/IP channel and a set of Devices that communicates through 36 | /// their Connector. 37 | /// 38 | /// 39 | /// Contents: 40 | /// - list of connectors 41 | /// - device factory usable by connectors 42 | /// - timer that trigger main thread actions in the connectors. 43 | /// 44 | /// Notifications: 45 | /// - new/create/modified connectors and devices 46 | /// 47 | /// Requirements: 48 | /// - Call the PeriodicProcess() method every N ms in order to do the 49 | /// main thread processing. This should be handled externally by a timer 50 | /// or similar. 51 | /// 52 | class OPENIGTLINKIO_LOGIC_EXPORT igtlioLogic : public vtkObject 53 | { 54 | public: 55 | enum { 56 | //TODO: harmonize event handling for Logic, Connector, Device. 57 | ConnectionAddedEvent = 118970, 58 | ConnectionAboutToBeRemovedEvent = 118971, 59 | 60 | NewDeviceEvent = 118949, 61 | DeviceModifiedEvent = igtlioConnector::DeviceContentModifiedEvent, // listen to the custom event invoked from connector. 62 | RemovedDeviceEvent = 118951, 63 | }; 64 | 65 | static igtlioLogic *New(); 66 | vtkTypeMacro(igtlioLogic, vtkObject); 67 | void PrintSelf(ostream&, vtkIndent) VTK_OVERRIDE; 68 | 69 | igtlioConnectorPointer CreateConnector(); 70 | int RemoveConnector(unsigned int index); 71 | int RemoveConnector(igtlioConnectorPointer connector); 72 | int GetNumberOfConnectors() const; 73 | igtlioConnectorPointer GetConnector(unsigned int index); 74 | 75 | /// Start a server and return a Session representing the connection. 76 | /// If sync is BLOCKING, the call blocks until at client has connected to the server. 77 | igtlioSessionPointer StartServer(int serverPort=-1, IGTLIO_SYNCHRONIZATION_TYPE sync=IGTLIO_BLOCKING, double timeout_s=5); 78 | 79 | /// Connect to the given server and return Session representing the connection. 80 | /// if sync is BLOCKING, the call blocks until the server responds or until timeout. 81 | igtlioSessionPointer ConnectToServer(std::string serverHost, int serverPort=-1, IGTLIO_SYNCHRONIZATION_TYPE sync=IGTLIO_BLOCKING, double timeout_s=5); 82 | 83 | /// Call timer-driven routines for each connector 84 | void PeriodicProcess(); 85 | 86 | //TODO: interface for accessing Devices 87 | unsigned int GetNumberOfDevices() const; 88 | void RemoveDevice(unsigned int index); 89 | igtlioDevicePointer GetDevice(unsigned int index); 90 | int ConnectorIndexFromDevice( igtlioDevicePointer d ); 91 | 92 | 93 | protected: 94 | igtlioLogic(); 95 | virtual ~igtlioLogic(); 96 | 97 | private: 98 | std::vector Connectors; 99 | 100 | private: 101 | igtlioLogic(const igtlioLogic&); // Not implemented 102 | void operator=(const igtlioLogic&); // Not implemented 103 | 104 | int CreateUniqueConnectorID() const; 105 | std::vector CreateDeviceList() const; 106 | int RemoveConnector(std::vector::iterator toRemove); 107 | 108 | vtkSmartPointer NewDeviceCallback; 109 | vtkSmartPointer RemovedDeviceCallback; 110 | vtkSmartPointer CommandEventCallback; 111 | 112 | public: 113 | vtkSmartPointer DeviceEventCallback; 114 | 115 | }; 116 | 117 | #endif // IGTLIOLOGIC_H 118 | -------------------------------------------------------------------------------- /Testing/testSendReceiveCommand.cxx: -------------------------------------------------------------------------------- 1 | #include 2 | #include "igtlioLogic.h" 3 | #include "igtlioConnector.h" 4 | #include "vtkTimerLog.h" 5 | #include "igtlioImageDevice.h" 6 | #include "vtkImageData.h" 7 | #include "igtlioImageConverter.h" 8 | #include "vtkMatrix4x4.h" 9 | #include 10 | #include "igtlioImageConverter.h" 11 | #include 12 | #include "igtlioFixture.h" 13 | #include "igtlioSession.h" 14 | #include "igtlioTestUtilities.h" 15 | 16 | /// 17 | /// Setup a client and server. 18 | /// Send a COMMAND from client to server. 19 | /// Server replies to the client with a RTS_COMMAND 20 | /// 21 | igtlioCommandPointer command = NULL; 22 | void testCommandReceived(vtkObject* vtkNotUsed(object), unsigned long event, void *vtkNotUsed(clientdata), void* (calldata)) 23 | { 24 | command = reinterpret_cast(calldata); 25 | } 26 | 27 | int main(int argc, char **argv) 28 | { 29 | igtlioClientServerFixture fixture; 30 | 31 | if (!fixture.ConnectClientToServer()) 32 | return TEST_FAILED; 33 | 34 | if (fixture.Client.Logic->GetNumberOfDevices() != 0) 35 | { 36 | std::cout << "ERROR: Client has devices before they have been added or fundamental error!" << std::endl; 37 | return TEST_FAILED; 38 | } 39 | 40 | std::cout << "*** Connection done" << std::endl; 41 | //--------------------------------------------------------------------------- 42 | 43 | vtkSmartPointer commandReceivedCallback = vtkSmartPointer::New(); 44 | commandReceivedCallback->SetCallback(testCommandReceived); 45 | fixture.Server.Connector->AddObserver(igtlioCommand::CommandReceivedEvent, commandReceivedCallback); 46 | 47 | std::string device_name = "TestDevice"; 48 | igtlioCommandPointer sentCommand; 49 | sentCommand = fixture.Client.Session->SendCommand("Get", 50 | "\n" 51 | " \n" 52 | "", 53 | IGTLIO_ASYNCHRONOUS); 54 | 55 | fixture.LoopUntilEventDetected(&fixture.Server, igtlioCommand::CommandReceivedEvent); 56 | 57 | if (!sentCommand || sentCommand->GetStatus() != igtlioCommandStatus::CommandWaiting) 58 | { 59 | std::cout << "FAILURE: Command not sent." << std::endl; 60 | return TEST_FAILED; 61 | } 62 | 63 | std::cout << "*** COMMAND sent from Client" << std::endl; 64 | //--------------------------------------------------------------------------- 65 | 66 | igtlioCommandPointer receivedCommand = command; 67 | if (!receivedCommand || sentCommand->GetName() != receivedCommand->GetName()) 68 | { 69 | std::cout << "FAILURE: Command names in server and client do not match." << std::endl; 70 | return TEST_FAILED; 71 | } 72 | 73 | std::cout << "*** COMMAND query received by Server" << std::endl; 74 | //--------------------------------------------------------------------------- 75 | 76 | receivedCommand->SetResponseContent("\n" 77 | " \n" 78 | ""); 79 | receivedCommand->SetSuccessful(true); 80 | 81 | int success = fixture.Server.Session->SendCommandResponse(receivedCommand); 82 | if (!success) 83 | { 84 | std::cout << "FAILURE: Server did not send response." << std::endl; 85 | return false; 86 | } 87 | 88 | std::cout << "*** RTS_COMMAND response sent from Server" << std::endl; 89 | //--------------------------------------------------------------------------- 90 | 91 | fixture.LoopUntilEventDetected(&fixture.Client, igtlioCommand::CommandResponseEvent); 92 | 93 | if (sentCommand->GetStatus() != igtlioCommandStatus::CommandResponseReceived) 94 | { 95 | std::cout << "FAILURE: Response sent but not received." << std::endl; 96 | return TEST_FAILED; 97 | } 98 | 99 | std::cout << "*** RTS_COMMAND response received by Client" << std::endl; 100 | //--------------------------------------------------------------------------- 101 | 102 | if (sentCommand->GetResponseContent() != receivedCommand->GetResponseContent()) 103 | { 104 | std::cout << "FAILURE: Received response not equal to what the Server sent." << std::endl; 105 | return TEST_FAILED; 106 | } 107 | 108 | std::cout << "*** Client command/response match found." << std::endl; 109 | //--------------------------------------------------------------------------- 110 | 111 | return TEST_SUCCESS; 112 | } 113 | --------------------------------------------------------------------------------