diff --git a/CMakeLists.txt b/CMakeLists.txt index 49d8f29..e010b6e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,6 +45,13 @@ include(GenerateExportHeader) # Find dependencies find_package(OpenIGTLink REQUIRED NO_MODULE) find_package(VTK REQUIRED NO_MODULE) +if(VTK_VERSION VERSION_LESS 8.9.0) + set(IGTLIO_VTK_PREFIX vtk) + set(IGTLIO_MODULE_PREFIX vtk) +else() + set(IGTLIO_VTK_PREFIX VTK::) + set(IGTLIO_MODULE_PREFIX "") +endif() include(${OpenIGTLink_USE_FILE}) ########################################################### @@ -172,7 +179,7 @@ install(EXPORT OpenIGTLinkIO FILE "OpenIGTLinkIOTargets.cmake" ) -install(FILES ${CMAKE_BINARY_DIR}/CMakeFiles/install/OpenIGTLinkIOConfig.cmake +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/install/OpenIGTLinkIOConfig.cmake DESTINATION "${OpenIGTLinkIO_PACKAGE_INSTALL}" COMPONENT CMakeFiles ) diff --git a/Converter/CMakeLists.txt b/Converter/CMakeLists.txt index 8c45b3b..a3054ec 100644 --- a/Converter/CMakeLists.txt +++ b/Converter/CMakeLists.txt @@ -3,15 +3,18 @@ project(igtlioConverter) set(${PROJECT_NAME}_EXPORT_DIRECTIVE "OPENIGTLINKIO_CONVERTER_EXPORT") set(VTK_MODULES - vtkIOImage - vtkImagingMath + ${IGTLIO_MODULE_PREFIX}IOImage + ${IGTLIO_MODULE_PREFIX}ImagingMath ) find_package(VTK REQUIRED NO_MODULE COMPONENTS ${VTK_MODULES} ) -include(${VTK_USE_FILE}) + +if(VTK_VERSION VERSION_LESS 8.9.0) + include(${VTK_USE_FILE}) +endif() set(${PROJECT_NAME}_INCLUDE_DIRECTORIES PUBLIC $ @@ -31,6 +34,7 @@ set(${PROJECT_NAME}_SRCS igtlioStringConverter.cxx igtlioTransformConverter.cxx igtlioTrackingDataConverter.cxx + igtlioNDArrayConverter.cxx ) set(${PROJECT_NAME}_HDRS @@ -47,6 +51,7 @@ set(${PROJECT_NAME}_HDRS igtlioTransformConverter.h igtlioUsSectorDefinitions.h igtlioTrackingDataConverter.h + igtlioNDArrayConverter.h ) IF(OpenIGTLink_ENABLE_VIDEOSTREAMING) diff --git a/Converter/igtlioImageConverter.cxx b/Converter/igtlioImageConverter.cxx index 522b7d9..fd5aebd 100644 --- a/Converter/igtlioImageConverter.cxx +++ b/Converter/igtlioImageConverter.cxx @@ -19,8 +19,10 @@ #include #include +#include #include #include +#include #include namespace // unnamed namespace @@ -115,6 +117,7 @@ int igtlioImageConverter::IGTLToVTKImageData(igtl::ImageMessage::Pointer imgMsg, // Retrieve the image data int size[3]; // image dimension float spacing[3]; // spacing (mm/pixel) + float origin[3]; // origin (mm) int svsize[3]; // sub-volume size int svoffset[3]; // sub-volume offset int scalarType; // VTK scalar type @@ -125,10 +128,11 @@ int igtlioImageConverter::IGTLToVTKImageData(igtl::ImageMessage::Pointer imgMsg, endian = imgMsg->GetEndian(); imgMsg->GetDimensions(size); imgMsg->GetSpacing(spacing); + imgMsg->GetOrigin(origin); numComponents = imgMsg->GetNumComponents(); imgMsg->GetSubVolume(svsize, svoffset); - // check if the IGTL data fits to the current MRML node + // check if the IGTL data fits to the current MRML node int sizeInNode[3]={0,0,0}; int scalarTypeInNode=VTK_VOID; int numComponentsInNode=0; @@ -139,7 +143,7 @@ int igtlioImageConverter::IGTLToVTKImageData(igtl::ImageMessage::Pointer imgMsg, scalarTypeInNode = imageData->GetScalarType(); numComponentsInNode = imageData->GetNumberOfScalarComponents(); } - + if (imageData.GetPointer()==NULL || sizeInNode[0] != size[0] || sizeInNode[1] != size[1] || sizeInNode[2] != size[2] || scalarType != scalarTypeInNode @@ -149,8 +153,8 @@ int igtlioImageConverter::IGTLToVTKImageData(igtl::ImageMessage::Pointer imgMsg, dest->image = imageData; imageData->SetDimensions(size[0], size[1], size[2]); imageData->SetExtent(0, size[0]-1, 0, size[1]-1, 0, size[2]-1); - imageData->SetOrigin(0.0, 0.0, 0.0); - imageData->SetSpacing(1.0, 1.0, 1.0); + imageData->SetOrigin(origin[0], origin[1], origin[2]); + imageData->SetSpacing(spacing[0], spacing[1], spacing[2]); #if (VTK_MAJOR_VERSION <= 5) imageData->SetNumberOfScalarComponents(numComponents); imageData->SetScalarType(scalarType); @@ -284,7 +288,13 @@ int igtlioImageConverter::IGTLToVTKImageData(igtl::ImageMessage::Pointer imgMsg, } } - + + // Mark scalars as modified + // This is required for getting up-to-date scalar range. + if (imageData->GetPointData() && imageData->GetPointData()->GetScalars()) + { + imageData->GetPointData()->GetScalars()->Modified(); + } imageData->Modified(); return 1; diff --git a/Converter/igtlioImageMetaConverter.cxx b/Converter/igtlioImageMetaConverter.cxx index 6d674d6..0ced0f5 100644 --- a/Converter/igtlioImageMetaConverter.cxx +++ b/Converter/igtlioImageMetaConverter.cxx @@ -97,5 +97,6 @@ int igtlioImageMetaConverter::toIGTL(const HeaderData& header, const ContentData msg->AddImageMetaElement(imageMetaElement); } + msg->Pack(); return 1; } diff --git a/Converter/igtlioLabelMetaConverter.cxx b/Converter/igtlioLabelMetaConverter.cxx index 7df74ac..8595145 100644 --- a/Converter/igtlioLabelMetaConverter.cxx +++ b/Converter/igtlioLabelMetaConverter.cxx @@ -92,5 +92,6 @@ int igtlioLabelMetaConverter::toIGTL(const HeaderData& header, const ContentData msg->AddLabelMetaElement(labelMetaElement); } + msg->Pack(); return 1; } diff --git a/Converter/igtlioNDArrayConverter.cxx b/Converter/igtlioNDArrayConverter.cxx new file mode 100644 index 0000000..d9508a4 --- /dev/null +++ b/Converter/igtlioNDArrayConverter.cxx @@ -0,0 +1,56 @@ +#include "igtlioNDArrayConverter.h" +#include "igtlNDArrayMessage.h" +#include +#include +#include +#include +#include + +int igtlioNDArrayConverter::fromIGTL(igtl::MessageBase::Pointer source, + HeaderData* header, + ContentData* dest, + bool checkCRC, + igtl::MessageBase::MetaDataMap& outMetaInfo) +{ + igtl::NDArrayMessage::Pointer msg; + msg = igtl::NDArrayMessage::New(); + msg->Copy(source); + + int c = msg->Unpack(checkCRC); + if ((c & igtl::MessageHeader::UNPACK_BODY == 0)) + { + return 0; + } + + if (!IGTLtoHeader(dynamic_pointer_cast(msg), header, outMetaInfo)) + return 0; + + vtkSmartPointer collection = vtkSmartPointer::New(); + + for (int i = 0; i < msg->GetArray()->GetSize()[0]; ++i) { + vtkSmartPointer NDArray_msg = vtkSmartPointer::New(); + NDArray_msg->SetNumberOfTuples(msg->GetArray()->GetSize()[0]); + memcpy(NDArray_msg->GetPointer(0), static_cast(msg->GetArray()->GetRawArray()) + (NDArray_msg->GetDataSize() * NDArray_msg->GetDataTypeSize() * i), NDArray_msg->GetDataSize() * NDArray_msg->GetDataTypeSize()); + collection->AddItem(NDArray_msg); + } + dest->collection = collection; + return 1; +} + +int igtlioNDArrayConverter::toIGTL(const HeaderData& header, const ContentData& source, igtl::NDArrayMessage::Pointer* dest, igtl::MessageBase::MetaDataMap metaInfo) +{ + if (dest->IsNull()) + *dest = igtl::NDArrayMessage::New(); + (*dest)->InitPack(); + igtl::NDArrayMessage::Pointer msg = *dest; + + if (!metaInfo.empty()) + { + msg->SetHeaderVersion(IGTL_HEADER_VERSION_2); + } + igtl::MessageBase::Pointer basemsg = dynamic_pointer_cast(msg); + HeadertoIGTL(header, &basemsg, metaInfo); + + msg->Pack(); + return 1; +} \ No newline at end of file diff --git a/Converter/igtlioNDArrayConverter.h b/Converter/igtlioNDArrayConverter.h new file mode 100644 index 0000000..42e7578 --- /dev/null +++ b/Converter/igtlioNDArrayConverter.h @@ -0,0 +1,27 @@ +#ifndef NDARRAYCONVERTER_H +#define NDARRAYCONVERTER_H + +#include "igtlioConverterExport.h" +#include +#include "igtlioBaseConverter.h" +class vtkDataArray; +typedef vtkSmartPointer igtlioNDArrayDevicePointer; +class OPENIGTLINKIO_CONVERTER_EXPORT igtlioNDArrayConverter : public igtlioBaseConverter +{ +public: + + + struct ContentData + { + vtkSmartPointer NDArray_msg; + }; + + static const char* GetIGTLName() { return GetIGTLTypeName(); } + static const char* GetIGTLTypeName() {return "ARRAY"; } + + static int fromIGTL(igtl::MessageBase::Pointer source, HeaderData* header, ContentData* content, bool checkCRC, igtl::MessageBase::MetaDataMap& outMetaInfo); + static int toIGTL(const HeaderData& header, const ContentData& source, igtl::NDArrayMessage::Pointer* dest, igtl::MessageBase::MetaDataMap metaInfo = igtl::MessageBase::MetaDataMap()); + +}; + +#endif //NDARRAYCONVERTER_H \ No newline at end of file diff --git a/Converter/igtlioPointConverter.cxx b/Converter/igtlioPointConverter.cxx index 811d1d4..d946537 100644 --- a/Converter/igtlioPointConverter.cxx +++ b/Converter/igtlioPointConverter.cxx @@ -80,17 +80,33 @@ int igtlioPointConverter::toIGTL(const HeaderData& header, const ContentData& so igtl::MessageBase::Pointer basemsg = dynamic_pointer_cast(msg); HeadertoIGTL(header, &basemsg, metaInfo); + if (msg->GetNumberOfPointElement() > source.PointElements.size()) + { + // there is no API to delete a single element, so if we need to delete then we delete all + msg->ClearPointElement(); + } + int pointIndex = 0; for (PointList::const_iterator pointIt = source.PointElements.begin(); pointIt != source.PointElements.end(); ++pointIt) { - igtl::PointElement::Pointer pointElement = igtl::PointElement::New(); + igtl::PointElement::Pointer pointElement; + if (pointIndex < msg->GetNumberOfPointElement()) + { + msg->GetPointElement(pointIndex, pointElement); + } + else + { + pointElement = igtl::PointElement::New(); + msg->AddPointElement(pointElement); + } pointElement->SetName(pointIt->Name.c_str()); pointElement->SetGroupName(pointIt->GroupName.c_str()); pointElement->SetRGBA(pointIt->RGBA[0], pointIt->RGBA[1], pointIt->RGBA[2], pointIt->RGBA[3]); pointElement->SetPosition(pointIt->Position[0], pointIt->Position[1], pointIt->Position[2]); pointElement->SetRadius(pointIt->Radius); pointElement->SetOwner(pointIt->Owner.c_str()); - msg->AddPointElement(pointElement); + pointIndex++; } + msg->Pack(); return 1; } diff --git a/Converter/igtlioTransformConverter.cxx b/Converter/igtlioTransformConverter.cxx index 0f65f10..977d083 100644 --- a/Converter/igtlioTransformConverter.cxx +++ b/Converter/igtlioTransformConverter.cxx @@ -34,7 +34,6 @@ int igtlioTransformConverter::fromIGTL(igtl::MessageBase::Pointer source, // Deserialize the transform data // If CheckCRC==0, CRC check is skipped. int c = transMsg->Unpack(checkCRC); - if (!(c & igtl::MessageHeader::UNPACK_BODY)) // if CRC check fails { // TODO: error handling @@ -43,12 +42,15 @@ int igtlioTransformConverter::fromIGTL(igtl::MessageBase::Pointer source, // get header if (!IGTLtoHeader(dynamic_pointer_cast(transMsg), header, outMetaInfo)) + { return 0; + } // get additional transform header info if (!IGTLHeaderToTransformInfo(dynamic_pointer_cast(transMsg), dest)) + { return 0; - + } igtl::Matrix4x4 matrix; transMsg->GetMatrix(matrix); @@ -122,20 +124,24 @@ int igtlioTransformConverter::IGTLHeaderToTransformInfo(igtl::MessageBase::Point int igtlioTransformConverter::toIGTL(const HeaderData& header, const ContentData& source, igtl::TransformMessage::Pointer* dest, igtl::MessageBase::MetaDataMap metaInfo) { if (dest->IsNull()) + { *dest = igtl::TransformMessage::New(); + } (*dest)->InitPack(); igtl::TransformMessage::Pointer msg = *dest; if (!metaInfo.empty()) - { + { msg->SetHeaderVersion(IGTL_HEADER_VERSION_2); - } + } igtl::MessageBase::Pointer basemsg = dynamic_pointer_cast(msg); HeadertoIGTL(header, &basemsg, metaInfo); TransformMetaDataToIGTL(source, &basemsg); - if (source.transform.Get()==NULL) + if (source.transform.Get() == NULL) + { std::cerr << "Got NULL input transform" << std::endl; + } vtkSmartPointer matrix = source.transform; igtl::Matrix4x4 igtlmatrix; diff --git a/Devices/CMakeLists.txt b/Devices/CMakeLists.txt index 07558b9..a8d1742 100644 --- a/Devices/CMakeLists.txt +++ b/Devices/CMakeLists.txt @@ -3,15 +3,19 @@ project(igtlioDevices) set(${PROJECT_NAME}_EXPORT_DIRECTIVE "OPENIGTLINKIO_DEVICES_EXPORT") set(VTK_MODULES - vtkIOImage - vtkImagingMath + ${IGTLIO_MODULE_PREFIX}CommonSystem + ${IGTLIO_MODULE_PREFIX}IOImage + ${IGTLIO_MODULE_PREFIX}ImagingMath ) find_package(VTK REQUIRED NO_MODULE COMPONENTS ${VTK_MODULES} ) -include(${VTK_USE_FILE}) + +if(VTK_VERSION VERSION_LESS 8.9.0) + include(${VTK_USE_FILE}) +endif() set(${PROJECT_NAME}_INCLUDE_DIRECTORIES PUBLIC $ @@ -28,8 +32,10 @@ set(${PROJECT_NAME}_SRCS igtlioPolyDataDevice.cxx igtlioStatusDevice.cxx igtlioStringDevice.cxx + igtlioNDArrayDevice.cxx igtlioTransformDevice.cxx igtlioTrackingDataDevice.cxx + ) set(${PROJECT_NAME}_HDRS @@ -41,6 +47,7 @@ set(${PROJECT_NAME}_HDRS igtlioPolyDataDevice.h igtlioStatusDevice.h igtlioStringDevice.h + igtlioNDArrayDevice.h igtlioTransformDevice.h igtlioTrackingDataDevice.h ) diff --git a/Devices/igtlioDevice.h b/Devices/igtlioDevice.h index 97d589e..58992f5 100644 --- a/Devices/igtlioDevice.h +++ b/Devices/igtlioDevice.h @@ -15,15 +15,23 @@ #ifndef IGTLIODEVICE_H #define IGTLIODEVICE_H +// VTK includes #include #include + +// STL includes #include +// local includes #include "igtlioDevicesExport.h" #include "igtlioBaseConverter.h" typedef vtkSmartPointer igtlioDevicePointer; +#ifndef VTK_OVERRIDE +#define VTK_OVERRIDE override +#endif + /// A vtkIGTLIODevice represents one device connected over OpenIGTLink. /// /// The Device has a specific type, e.g. Image, Transform..., and diff --git a/Devices/igtlioImageDevice.cxx b/Devices/igtlioImageDevice.cxx index fda6003..566f9cc 100644 --- a/Devices/igtlioImageDevice.cxx +++ b/Devices/igtlioImageDevice.cxx @@ -91,7 +91,7 @@ igtl::MessageBase::Pointer igtlioImageDevice::GetIGTLMessage() { if (!Content.image) { - vtkWarningMacro("Image is NULL, message not generated.") + vtkWarningMacro("Image is NULL, message not generated."); return 0; } diff --git a/Devices/igtlioNDArrayDevice.cxx b/Devices/igtlioNDArrayDevice.cxx new file mode 100644 index 0000000..b922bea --- /dev/null +++ b/Devices/igtlioNDArrayDevice.cxx @@ -0,0 +1,119 @@ +#include "igtlioNDArrayDevice.h" +#include + +//--------------------------------------------------------------------------- +igtlioDevicePointer igtlioNDArrayDeviceCreator::Create(std::string device_name) +{ + igtlioNDArrayDevicePointer retval = igtlioNDArrayDevicePointer::New(); + retval->SetDeviceName(device_name); + return retval; +} + +//--------------------------------------------------------------------------- +std::string igtlioNDArrayDeviceCreator::GetDeviceType() const +{ + return igtlioNDArrayConverter::GetIGTLTypeName(); +} + +//--------------------------------------------------------------------------- +vtkStandardNewMacro(igtlioNDArrayDeviceCreator); + + + + +//--------------------------------------------------------------------------- +vtkStandardNewMacro(igtlioNDArrayDevice); +//--------------------------------------------------------------------------- +igtlioNDArrayDevice::igtlioNDArrayDevice() +{ +} + +//--------------------------------------------------------------------------- +igtlioNDArrayDevice::~igtlioNDArrayDevice() +{ +} + +//--------------------------------------------------------------------------- +std::string igtlioNDArrayDevice::GetDeviceType() const +{ + return igtlioNDArrayConverter::GetIGTLTypeName(); +} + +int igtlioNDArrayDevice::ReceiveIGTLMessage(igtl::NDArrayMessage::Pointer buffer, bool checkCRC) +{ + int success = igtlioNDArrayConverter::fromIGTL(buffer, &HeaderData, &Content, checkCRC, this->metaInfo); + if (success) + { + this->Modified(); + this->InvokeEvent(ArrayModifiedEvent, this); + } + return success; +} +//--------------------------------------------------------------------------- +unsigned int igtlioNDArrayDevice::GetDeviceContentModifiedEvent() const +{ + return ArrayModifiedEvent; +} + +//--------------------------------------------------------------------------- +int igtlioNDArrayDevice::ReceiveIGTLMessage(igtl::NDArrayMessage::Pointer buffer, bool checkCRC) +{ + int success = igtlioNDArrayConverter::fromIGTL(buffer, &HeaderData, &Content, checkCRC, this->metaInfo); + if (success) + { + this->Modified(); + this->InvokeEvent(ArrayModifiedEvent, this); + } + return success; +} + +//--------------------------------------------------------------------------- +igtl::NDArrayMessage::Pointer igtlioNDArrayDevice::GetIGTLMessage() +{ + + if (!igtlioNDArrayConverter::toIGTL(HeaderData, Content, &this->OutMessage, this->metaInfo)) + { + return 0; + } + + return dynamic_pointer_cast(this->OutMessage); +} + +//--------------------------------------------------------------------------- +igtl::NDArrayMessage::Pointer igtlioNDArrayDevice::GetIGTLMessage(MESSAGE_PREFIX prefix) +{ + if (prefix==MESSAGE_PREFIX_NOT_DEFINED) + { + return this->GetIGTLMessage(); + } + + return igtl::NDArrayMessage::Pointer(); +} + +//--------------------------------------------------------------------------- +std::set igtlioNDArrayDevice::GetSupportedMessagePrefixes() const +{ + std::set retval; + retval.insert(MESSAGE_PREFIX_NOT_DEFINED); + return retval; +} + +void igtlioNDArrayDevice::SetContent(igtlioNDArrayConverter::ContentData content) +{ + Content = content; + this->Modified(); + this->InvokeEvent(ArrayModifiedEvent, this); +} + +igtlioNDArrayConverter::ContentData igtlioNDArrayDevice::GetContent() +{ + return Content; +} + +//--------------------------------------------------------------------------- +void igtlioNDArrayDevice::PrintSelf(ostream& os, vtkIndent indent) +{ + igtlioDevice::PrintSelf(os, indent); + + os << indent << "Array:\t" << Content.NDArray_msg << "\n"; +} diff --git a/Devices/igtlioNDArrayDevice.h b/Devices/igtlioNDArrayDevice.h new file mode 100644 index 0000000..c489cdd --- /dev/null +++ b/Devices/igtlioNDArrayDevice.h @@ -0,0 +1,59 @@ +#ifndef NDARRAYDEVICE_H +#define NDARRAYDEVICE_H + +#include "igtlioDevicesExport.h" + +#include "igtlioNDArrayConverter.h" +#include "igtlioDevice.h" + +class vtkDataArray; + +typedef vtkSmartPointer igtlioNDArrayDevicePointer; + +class OPENIGTLINKIO_DEVICES_EXPORT igtlioNDArrayDevice : public igtlioDevice +{ +public: + enum { + ArrayModifiedEvent = 118960, + }; + + virtual unsigned int GetDeviceContentModifiedEvent() const; + virtual std::string GetDeviceType() const; + //virtual int ReceiveIGTLMessage(igtl::NDArrayMessage::Pointer buffer, bool checkCRC); + virtual igtl::NDArrayMessage::Pointer GetIGTLMessage() const; + virtual igtl::NDArrayMessage::Pointer GetIGTLMessage(MESSAGE_PREFIX prefix) const; + virtual std::set GetSupportedMessagePrefixes(); + + void SetContent(igtlioNDArrayConverter::ContentData content); + igtlioNDArrayConverter::ContentData GetContent(); + + public: + static igtlioNDArrayDevice *New(); + vtkTypeMacro(igtlioNDArrayDevice,igtlioDevice); + + void PrintSelf(ostream& os, vtkIndent indent); + + protected: + igtlioNDArrayDevice(); + ~igtlioNDArrayDevice(); + + protected: + igtl::NDArrayMessage::Pointer OutMessage; + //igtl::GetStatusMessage::Pointer GetMessage; + + igtlioNDArrayConverter::ContentData Content; +}; + + +//--------------------------------------------------------------------------- +class OPENIGTLINKIO_DEVICES_EXPORT igtlioNDArrayDeviceCreator : public igtlioDeviceCreator +{ +public: + virtual igtlioDevicePointer Create(std::string device_name); + virtual std::string GetDeviceType(); + + static igtlioNDArrayDeviceCreator *New(); + vtkTypeMacro(igtlioNDArrayDeviceCreator,vtkObject); +}; + +#endif // NDARRAYDEVICE_H diff --git a/Devices/igtlioVideoDevice.cxx b/Devices/igtlioVideoDevice.cxx index 0ee9653..55b2bb3 100644 --- a/Devices/igtlioVideoDevice.cxx +++ b/Devices/igtlioVideoDevice.cxx @@ -16,6 +16,7 @@ #include #include +#include #include "vtkMatrix4x4.h" //--------------------------------------------------------------------------- @@ -166,7 +167,7 @@ igtl::MessageBase::Pointer igtlioVideoDevice::GetIGTLMessage() { if (!Content.image) { - vtkWarningMacro("Video is NULL, message not generated.") + vtkWarningMacro("Video is NULL, message not generated."); return 0; } int imageSizePixels[3] = { 0 }; diff --git a/Examples/qIgtlClient/CMakeLists.txt b/Examples/qIgtlClient/CMakeLists.txt index d3a3bd2..a04d54d 100644 --- a/Examples/qIgtlClient/CMakeLists.txt +++ b/Examples/qIgtlClient/CMakeLists.txt @@ -5,11 +5,13 @@ project(igtlioQtClient) # ========================================================= find_package(VTK REQUIRED NO_MODULE COMPONENTS - vtkIOImage - vtkImagingMath - vtkGUISupportQt + ${IGTLIO_MODULE_PREFIX}IOImage + ${IGTLIO_MODULE_PREFIX}ImagingMath + ${IGTLIO_MODULE_PREFIX}GUISupportQt ) -include(${VTK_USE_FILE}) +if(VTK_VERSION VERSION_LESS 8.9.0) + include(${VTK_USE_FILE}) +endif() set(${PROJECT_NAME}_SRCS main.cpp diff --git a/GUI/CMakeLists.txt b/GUI/CMakeLists.txt index 72c4497..5c0babf 100644 --- a/GUI/CMakeLists.txt +++ b/GUI/CMakeLists.txt @@ -2,13 +2,20 @@ project(igtlioGUI) set(${PROJECT_NAME}_EXPORT_DIRECTIVE "OPENIGTLINKIO_GUI_EXPORT") +set(VTK_MODULES + ${IGTLIO_MODULE_PREFIX}IOImage + ${IGTLIO_MODULE_PREFIX}ImagingMath + ${IGTLIO_MODULE_PREFIX}GUISupportQt +) + find_package(VTK REQUIRED NO_MODULE COMPONENTS - vtkIOImage - vtkImagingMath - vtkGUISupportQt + ${VTK_MODULES} ) -include(${VTK_USE_FILE}) + +if(VTK_VERSION VERSION_LESS 8.9.0) + include(${VTK_USE_FILE}) +endif() set(OpenIGTLinkIO_Qt_Modules Widgets diff --git a/GUI/qIGTLIOClientWidget.cxx b/GUI/qIGTLIOClientWidget.cxx index 0a48931..df968c0 100644 --- a/GUI/qIGTLIOClientWidget.cxx +++ b/GUI/qIGTLIOClientWidget.cxx @@ -5,6 +5,7 @@ #include "qIGTLIOConnectorListWidget.h" #include "qIGTLIODevicesWidget.h" #include "qIGTLIOCommandWidget.h" +#include "igtlioLogic.h" qIGTLIOClientWidget::qIGTLIOClientWidget() { diff --git a/GUI/qIGTLIOConnectorPropertyWidget.h b/GUI/qIGTLIOConnectorPropertyWidget.h index dcfbe71..38a5a3f 100644 --- a/GUI/qIGTLIOConnectorPropertyWidget.h +++ b/GUI/qIGTLIOConnectorPropertyWidget.h @@ -28,7 +28,7 @@ // igtlio includes #include "igtlioGUIExport.h" - +#include "igtlioConnector.h" #include typedef vtkSmartPointer igtlioConnectorPointer; diff --git a/Logic/CMakeLists.txt b/Logic/CMakeLists.txt index c7c6e78..cf2cfda 100644 --- a/Logic/CMakeLists.txt +++ b/Logic/CMakeLists.txt @@ -3,15 +3,18 @@ project(igtlioLogic) set(${PROJECT_NAME}_EXPORT_DIRECTIVE "OPENIGTLINKIO_LOGIC_EXPORT") set(VTK_MODULES - vtkIOImage - vtkImagingMath + ${IGTLIO_MODULE_PREFIX}IOImage + ${IGTLIO_MODULE_PREFIX}ImagingMath ) find_package(VTK REQUIRED NO_MODULE COMPONENTS ${VTK_MODULES} ) -include(${VTK_USE_FILE}) + +if(VTK_VERSION VERSION_LESS 8.9.0) + include(${VTK_USE_FILE}) +endif() set(${PROJECT_NAME}_INCLUDE_DIRECTORIES PUBLIC $ @@ -45,6 +48,7 @@ set(${PROJECT_NAME}_HDRS set(${PROJECT_NAME}_TARGET_LIBRARIES igtlioDevices ${OpenIGTLink_LIBRARIES} + ${IGTLIO_VTK_PREFIX}CommonSystem ${VTK_LIBRARIES} ) diff --git a/Logic/igtlioCircularBuffer.h b/Logic/igtlioCircularBuffer.h index 68a380b..a0651e8 100644 --- a/Logic/igtlioCircularBuffer.h +++ b/Logic/igtlioCircularBuffer.h @@ -10,19 +10,29 @@ #ifndef IGTLIOCIRCULARBUFFER_H #define IGTLIOCIRCULARBUFFER_H +// STL includes #include + +// VTK includes #include + +// OpenIGTLink includes #include + +// Local includes #include "igtlioLogicExport.h" #define IGTLCB_CIRC_BUFFER_SIZE 3 +#ifndef VTK_OVERRIDE + #define VTK_OVERRIDE override +#endif + class vtkMutexLock; class OPENIGTLINKIO_LOGIC_EXPORT igtlioCircularBuffer : public vtkObject { public: - static igtlioCircularBuffer *New(); vtkTypeMacro(igtlioCircularBuffer, vtkObject); diff --git a/Logic/igtlioCircularSectionBuffer.cxx b/Logic/igtlioCircularSectionBuffer.cxx index a204efe..ec3b487 100644 --- a/Logic/igtlioCircularSectionBuffer.cxx +++ b/Logic/igtlioCircularSectionBuffer.cxx @@ -188,6 +188,7 @@ void igtlioCircularSectionBuffer::EndPull() } +//--------------------------------------------------------------------------- bool igtlioCircularSectionBuffer::IsSectionBufferInProcess() { if (InUseBegin>=0) diff --git a/Logic/igtlioCircularSectionBuffer.h b/Logic/igtlioCircularSectionBuffer.h index 7ccc7dd..1e3ad34 100644 --- a/Logic/igtlioCircularSectionBuffer.h +++ b/Logic/igtlioCircularSectionBuffer.h @@ -10,9 +10,16 @@ #ifndef IGTLIOCIRCULARSECTIONBUFFER_H #define IGTLIOCIRCULARSECTIONBUFFER_H +// STL includes #include + +// VTK includes #include + +// OpenIGTLink includes #include + +// Local includes #include "igtlioLogicExport.h" #define IGTLCB_CIRC_BUFFER_SIZE 3 @@ -20,6 +27,10 @@ class vtkMutexLock; +#ifndef VTK_OVERRIDE +#define VTK_OVERRIDE override +#endif + class OPENIGTLINKIO_LOGIC_EXPORT igtlioCircularSectionBuffer : public vtkObject { public: diff --git a/Logic/igtlioCommand.h b/Logic/igtlioCommand.h index 94a30be..a6b1c1f 100644 --- a/Logic/igtlioCommand.h +++ b/Logic/igtlioCommand.h @@ -32,6 +32,10 @@ Ontario with funds provided by the Ontario Ministry of Health and Long-Term Care typedef vtkSmartPointer igtlioCommandPointer; +#ifndef VTK_OVERRIDE + #define VTK_OVERRIDE override +#endif + enum igtlioCommandStatus { CommandUnknown, diff --git a/Logic/igtlioConnector.cxx b/Logic/igtlioConnector.cxx index 2db5fdb..4520559 100644 --- a/Logic/igtlioConnector.cxx +++ b/Logic/igtlioConnector.cxx @@ -28,14 +28,15 @@ Version: $Revision: 1.4 $ #include // VTK includes -#include #include +#include #include #include #include #include #include #include +#include // vtksys includes #include @@ -278,9 +279,17 @@ void* igtlioConnector::ReceiverThreadFunction(void* ptr) connector->RemoveClient(clientID); // Signal to the threader that this thread has become free +#if VTK_MAJOR_VERSION < 9 // change to std::mutex with v9.0.0 vinfo->ActiveFlagLock->Lock(); +#else + vinfo->ActiveFlagLock->lock(); +#endif (*vinfo->ActiveFlag) = 0; +#if VTK_MAJOR_VERSION < 9 // change to std::mutex with v9.0.0 vinfo->ActiveFlagLock->Unlock(); +#else + vinfo->ActiveFlagLock->unlock(); +#endif return NULL; //why??? } @@ -409,9 +418,17 @@ void* igtlioConnector::ConnectionAcceptThreadFunction(void* ptr) connector->RequestInvokeEvent(igtlioConnector::DeactivatedEvent); // need to Request the InvokeEvent, because we are not on the main thread now // Signal to the threader that this thread has become free +#if VTK_MAJOR_VERSION < 9 // change to std::mutex with v9.0.0 vinfo->ActiveFlagLock->Lock(); +#else + vinfo->ActiveFlagLock->lock(); +#endif (*vinfo->ActiveFlag) = 0; +#if VTK_MAJOR_VERSION < 9 // change to std::mutex with v9.0.0 vinfo->ActiveFlagLock->Unlock(); +#else + vinfo->ActiveFlagLock->unlock(); +#endif return 0; } @@ -440,7 +457,8 @@ bool igtlioConnector::ReceiveController(int clientID) vtkDebugMacro("Waiting for header of size: " << headerMsg->GetPackSize()); // This may need to be parallelized so that other socket aren't waiting on timeouts - int r = client.Socket->Receive(headerMsg->GetPackPointer(), headerMsg->GetPackSize()); + bool timeout(false); + int r = client.Socket->Receive(headerMsg->GetPackPointer(), headerMsg->GetPackSize(), timeout); vtkDebugMacro("Received header of size: " << headerMsg->GetPackSize()); @@ -523,7 +541,8 @@ bool igtlioConnector::ReceiveController(int clientID) vtkDebugMacro("Waiting to receive body: size=" << buffer->GetPackBodySize() << ", GetBodySizeToRead=" << buffer->GetBodySizeToRead() << ", GetPackSize=" << buffer->GetPackSize()); - int read = client.Socket->Receive(buffer->GetPackBodyPointer(), buffer->GetPackBodySize()); + bool timeout(false); + int read = client.Socket->Receive(buffer->GetPackBodyPointer(), buffer->GetPackBodySize(), timeout); vtkDebugMacro("Received body: " << read); if (read != buffer->GetPackBodySize()) { @@ -557,7 +576,8 @@ bool igtlioConnector::ReceiveCommandMessage(igtl::MessageHeader::Pointer headerM vtkDebugMacro("Waiting to receive body: size=" << buffer->GetBufferBodySize() << ", GetBodySizeToRead=" << buffer->GetBodySizeToRead() << ", GetPackSize=" << buffer->GetPackSize()); - int read = client.Socket->Receive(buffer->GetBufferBodyPointer(), buffer->GetBufferBodySize()); + bool timeout(false); + int read = client.Socket->Receive(buffer->GetBufferBodyPointer(), buffer->GetBufferBodySize(), timeout); vtkDebugMacro("Received body: " << read); if (read != buffer->GetBufferBodySize()) { @@ -575,7 +595,7 @@ bool igtlioConnector::ReceiveCommandMessage(igtl::MessageHeader::Pointer headerM } //---------------------------------------------------------------------------- -int igtlioConnector::SendData(int size, unsigned char* data, Client& client) +int igtlioConnector::SendData(igtlUint64 size, unsigned char* data, Client& client) { if (client.Socket.IsNull()) { @@ -592,12 +612,12 @@ int igtlioConnector::SendData(int size, unsigned char* data, Client& client) } //---------------------------------------------------------------------------- -int igtlioConnector::Skip(int length, Client& client, int skipFully /* = 1 */) +int igtlioConnector::Skip(igtlUint64 length, Client& client, int skipFully /* = 1 */) { unsigned char dummy[256]; - int block = 256; - int n = 0; - int remain = length; + igtlUint64 block = 256; + igtlUint64 n = 0; + igtlUint64 remain = length; do { @@ -606,7 +626,8 @@ int igtlioConnector::Skip(int length, Client& client, int skipFully /* = 1 */) block = remain; } - n = client.Socket->Receive(dummy, block, skipFully); + bool timeout(false); + n = client.Socket->Receive(dummy, block, timeout, skipFully); remain -= n; } while (remain > 0 || (skipFully && n < block)); @@ -836,7 +857,7 @@ int igtlioConnector::SendCommand(igtlioCommandPointer command) { if (command->IsInProgress()) { - vtkWarningMacro("SendCommand: Command " << command->GetCommandId() << "-" << command->GetName() << " is already in progress! Attempting to cancel and resend.") + vtkWarningMacro("SendCommand: Command " << command->GetCommandId() << "-" << command->GetName() << " is already in progress! Attempting to cancel and resend."); this->CancelCommand(command); } diff --git a/Logic/igtlioConnector.h b/Logic/igtlioConnector.h index 7db8190..46a6814 100644 --- a/Logic/igtlioConnector.h +++ b/Logic/igtlioConnector.h @@ -265,8 +265,8 @@ class OPENIGTLINKIO_LOGIC_EXPORT igtlioConnector : public vtkIGTLIOObject // OpenIGTLink Message handlers //---------------------------------------------------------------- bool ReceiveController(int clientID); // called from Thread - int SendData(int size, unsigned char* data, Client& client); - int Skip(int length, Client& client, int skipFully=1); + int SendData(igtlUint64 size, unsigned char* data, Client& client); + int Skip(igtlUint64 length, Client& client, int skipFully=1); //---------------------------------------------------------------- // Clients diff --git a/README.md b/README.md index a5cbd19..e4ff21a 100644 --- a/README.md +++ b/README.md @@ -25,11 +25,10 @@ cmake -G"generator_name" \ -DOpenIGTLink_DIR:PATH=path/to/igtl/build \ -DVTK_DIR:PATH=path/to/vtk/build \ -DCTK_DIR:PATH=path/to/ctk/build \ + -DQt5_DIR:PATH=path/to/Qt/lib/cmake/Qt5 path/to/source ``` -Make sure Qt 4 or 5 is in your path. - 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`. List of available generator are listed [here](https://cmake.org/cmake/help/v3.8/manual/cmake-generators.7.html). @@ -45,7 +44,6 @@ The following is an example of how to build the library with all prerequisites: ```bash # prerequisites: # -# cmake is in path # qmake is in path mkdir ~/dev @@ -54,14 +52,14 @@ cd ~/dev git clone git@github.com:Kitware/VTK.git mkdir -p VTK_build cd VTK_build -cmake ../VTK -DVTK_QT_VERSION:STRING=5 -DModule_vtkGUISupportQt:BOOL=ON +cmake ../VTK -DVTK_QT_VERSION:STRING=5 -DModule_vtkGUISupportQt:BOOL=ON -DQt5_DIR:PATH=/path/to/Qt5/lib/cmake/Qt5 make -j6 cd .. git clone git@github.com:commontk/CTK.git mkdir -p CTK_build cd CTK_build -cmake ../CTK -DCTK_QT_VERSION:STRING=5 -DCTK_LIB_Visualization/VTK/Core:BOOL=ON -DVTK_DIR:PATH=~/dev/VTK_build -DBUILD_TESTING:BOOL=OFF +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 make -j6 cd .. diff --git a/Tools/CMakeLists.txt b/Tools/CMakeLists.txt index f7490a9..3f9bb69 100644 --- a/Tools/CMakeLists.txt +++ b/Tools/CMakeLists.txt @@ -4,9 +4,16 @@ set(${PROJECT_NAME}_EXPORT_DIRECTIVE "OPENIGTLINKIO_TOOLS_EXPORT") find_package(OpenIGTLink REQUIRED) include(${OpenIGTLink_USE_FILE}) - -find_package(VTK REQUIRED NO_MODULE COMPONENTS vtkIOXMLParser) -include(${VTK_USE_FILE}) + +set(VTK_MODULES + ${IGTLIO_MODULE_PREFIX}IOXMLParser +) + +find_package(VTK REQUIRED NO_MODULE COMPONENTS ${VTK_MODULES}) + +if(VTK_VERSION VERSION_LESS 8.9.0) + include(${VTK_USE_FILE}) +endif() set(${PROJECT_NAME}_INCLUDE_DIRECTORIES PUBLIC $