diff --git a/Modules/Core/files.cmake b/Modules/Core/files.cmake index 1aa29e2075..e9f3daabdf 100644 --- a/Modules/Core/files.cmake +++ b/Modules/Core/files.cmake @@ -1,328 +1,329 @@ file(GLOB_RECURSE H_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/include/*") set(CPP_FILES mitkCoreActivator.cpp mitkCoreObjectFactoryBase.cpp mitkCoreObjectFactory.cpp mitkCoreServices.cpp mitkException.cpp Algorithms/mitkBaseDataSource.cpp Algorithms/mitkClippedSurfaceBoundsCalculator.cpp Algorithms/mitkCompareImageDataFilter.cpp Algorithms/mitkCompositePixelValueToString.cpp Algorithms/mitkConvert2Dto3DImageFilter.cpp Algorithms/mitkDataNodeSource.cpp Algorithms/mitkExtractSliceFilter.cpp Algorithms/mitkExtractSliceFilter2.cpp Algorithms/mitkHistogramGenerator.cpp Algorithms/mitkImageChannelSelector.cpp Algorithms/mitkImageSliceSelector.cpp Algorithms/mitkImageSource.cpp Algorithms/mitkImageTimeSelector.cpp Algorithms/mitkImageToImageFilter.cpp Algorithms/mitkImageToSurfaceFilter.cpp Algorithms/mitkMultiComponentImageDataComparisonFilter.cpp Algorithms/mitkPlaneGeometryDataToSurfaceFilter.cpp Algorithms/mitkPointSetSource.cpp Algorithms/mitkPointSetToPointSetFilter.cpp Algorithms/mitkRGBToRGBACastImageFilter.cpp Algorithms/mitkSubImageSelector.cpp Algorithms/mitkSurfaceSource.cpp Algorithms/mitkSurfaceToImageFilter.cpp Algorithms/mitkSurfaceToSurfaceFilter.cpp Algorithms/mitkUIDGenerator.cpp Algorithms/mitkVolumeCalculator.cpp Algorithms/mitkTemporalJoinImagesFilter.cpp Controllers/mitkBaseController.cpp Controllers/mitkCallbackFromGUIThread.cpp Controllers/mitkCameraController.cpp Controllers/mitkCameraRotationController.cpp Controllers/mitkCrosshairManager.cpp Controllers/mitkLimitedLinearUndo.cpp Controllers/mitkOperationEvent.cpp Controllers/mitkPlanePositionManager.cpp Controllers/mitkProgressBar.cpp Controllers/mitkRenderingManager.cpp Controllers/mitkSliceNavigationController.cpp Controllers/mitkSliceNavigationHelper.cpp Controllers/mitkStatusBar.cpp Controllers/mitkStepper.cpp Controllers/mitkTestManager.cpp Controllers/mitkTimeNavigationController.cpp Controllers/mitkUndoController.cpp Controllers/mitkVerboseLimitedLinearUndo.cpp Controllers/mitkVtkLayerController.cpp DataManagement/mitkAnatomicalStructureColorPresets.cpp DataManagement/mitkArbitraryTimeGeometry.cpp DataManagement/mitkAbstractTransformGeometry.cpp DataManagement/mitkAnnotationProperty.cpp DataManagement/mitkApplicationCursor.cpp DataManagement/mitkApplyTransformMatrixOperation.cpp DataManagement/mitkBaseData.cpp DataManagement/mitkBaseGeometry.cpp DataManagement/mitkBaseProperty.cpp DataManagement/mitkChannelDescriptor.cpp DataManagement/mitkClippingProperty.cpp DataManagement/mitkColorProperty.cpp DataManagement/mitkCrosshairData.cpp DataManagement/mitkDataNode.cpp DataManagement/mitkDataStorage.cpp DataManagement/mitkEnumerationProperty.cpp DataManagement/mitkFloatPropertyExtension.cpp DataManagement/mitkGeometry3D.cpp DataManagement/mitkGeometryData.cpp DataManagement/mitkGeometryTransformHolder.cpp DataManagement/mitkGroupTagProperty.cpp DataManagement/mitkGenericIDRelationRule.cpp DataManagement/mitkIdentifiable.cpp DataManagement/mitkImageAccessorBase.cpp DataManagement/mitkImageCaster.cpp DataManagement/mitkImageCastPart1.cpp DataManagement/mitkImageCastPart2.cpp DataManagement/mitkImageCastPart3.cpp DataManagement/mitkImageCastPart4.cpp DataManagement/mitkImage.cpp DataManagement/mitkImageDataItem.cpp DataManagement/mitkImageDescriptor.cpp DataManagement/mitkImageReadAccessor.cpp DataManagement/mitkImageStatisticsHolder.cpp DataManagement/mitkImageVtkAccessor.cpp DataManagement/mitkImageVtkReadAccessor.cpp DataManagement/mitkImageVtkWriteAccessor.cpp DataManagement/mitkImageWriteAccessor.cpp DataManagement/mitkIntPropertyExtension.cpp DataManagement/mitkIPersistenceService.cpp DataManagement/mitkIPropertyAliases.cpp DataManagement/mitkIPropertyDescriptions.cpp DataManagement/mitkIPropertyDeserialization.cpp DataManagement/mitkIPropertyExtensions.cpp DataManagement/mitkIPropertyFilters.cpp DataManagement/mitkIPropertyOwner.cpp DataManagement/mitkIPropertyPersistence.cpp DataManagement/mitkIPropertyProvider.cpp + DataManagement/mitkITKEventObserverGuard.cpp DataManagement/mitkLandmarkProjectorBasedCurvedGeometry.cpp DataManagement/mitkLandmarkProjector.cpp DataManagement/mitkLevelWindow.cpp DataManagement/mitkLevelWindowManager.cpp DataManagement/mitkLevelWindowPreset.cpp DataManagement/mitkLevelWindowProperty.cpp DataManagement/mitkLookupTable.cpp DataManagement/mitkLookupTableProperty.cpp DataManagement/mitkLookupTables.cpp DataManagement/mitkMaterial.cpp DataManagement/mitkMemoryUtilities.cpp DataManagement/mitkModalityProperty.cpp DataManagement/mitkModifiedLock.cpp DataManagement/mitkNodePredicateAnd.cpp DataManagement/mitkNodePredicateBase.cpp DataManagement/mitkNodePredicateCompositeBase.cpp DataManagement/mitkNodePredicateData.cpp DataManagement/mitkNodePredicateDataType.cpp DataManagement/mitkNodePredicateDataUID.cpp DataManagement/mitkNodePredicateDimension.cpp DataManagement/mitkNodePredicateFunction.cpp DataManagement/mitkNodePredicateGeometry.cpp DataManagement/mitkNodePredicateNot.cpp DataManagement/mitkNodePredicateOr.cpp DataManagement/mitkNodePredicateProperty.cpp DataManagement/mitkNodePredicateDataProperty.cpp DataManagement/mitkNodePredicateSubGeometry.cpp DataManagement/mitkNumericConstants.cpp DataManagement/mitkPlaneGeometry.cpp DataManagement/mitkPlaneGeometryData.cpp DataManagement/mitkPlaneOperation.cpp DataManagement/mitkPlaneOrientationProperty.cpp DataManagement/mitkPointOperation.cpp DataManagement/mitkPointSet.cpp DataManagement/mitkPointSetShapeProperty.cpp DataManagement/mitkProperties.cpp DataManagement/mitkPropertyAliases.cpp DataManagement/mitkPropertyDescriptions.cpp DataManagement/mitkPropertyDeserialization.cpp DataManagement/mitkPropertyExtension.cpp DataManagement/mitkPropertyExtensions.cpp DataManagement/mitkPropertyFilter.cpp DataManagement/mitkPropertyFilters.cpp DataManagement/mitkPropertyKeyPath.cpp DataManagement/mitkPropertyList.cpp DataManagement/mitkPropertyListReplacedObserver.cpp DataManagement/mitkPropertyNameHelper.cpp DataManagement/mitkPropertyObserver.cpp DataManagement/mitkPropertyPersistence.cpp DataManagement/mitkPropertyPersistenceInfo.cpp DataManagement/mitkPropertyRelationRuleBase.cpp DataManagement/mitkProportionalTimeGeometry.cpp DataManagement/mitkRenderingModeProperty.cpp DataManagement/mitkResliceMethodProperty.cpp DataManagement/mitkRestorePlanePositionOperation.cpp DataManagement/mitkRotationOperation.cpp DataManagement/mitkScaleOperation.cpp DataManagement/mitkSlicedData.cpp DataManagement/mitkSlicedGeometry3D.cpp DataManagement/mitkSmartPointerProperty.cpp DataManagement/mitkStandaloneDataStorage.cpp DataManagement/mitkStringProperty.cpp DataManagement/mitkSurface.cpp DataManagement/mitkSurfaceOperation.cpp DataManagement/mitkSourceImageRelationRule.cpp DataManagement/mitkThinPlateSplineCurvedGeometry.cpp DataManagement/mitkTimeGeometry.cpp DataManagement/mitkTransferFunction.cpp DataManagement/mitkTransferFunctionInitializer.cpp DataManagement/mitkTransferFunctionProperty.cpp DataManagement/mitkTemporoSpatialStringProperty.cpp DataManagement/mitkUIDManipulator.cpp DataManagement/mitkVectorProperty.cpp DataManagement/mitkVtkInterpolationProperty.cpp DataManagement/mitkVtkRepresentationProperty.cpp DataManagement/mitkVtkResliceInterpolationProperty.cpp DataManagement/mitkVtkScalarModeProperty.cpp DataManagement/mitkWeakPointerProperty.cpp DataManagement/mitkIPropertyRelations.cpp DataManagement/mitkPropertyRelations.cpp Interactions/mitkAction.cpp Interactions/mitkBindDispatcherInteractor.cpp Interactions/mitkDataInteractor.cpp Interactions/mitkDispatcher.cpp Interactions/mitkDisplayActionEventBroadcast.cpp Interactions/mitkDisplayActionEventFunctions.cpp Interactions/mitkDisplayActionEventHandler.cpp Interactions/mitkDisplayActionEventHandlerDesynchronized.cpp Interactions/mitkDisplayActionEventHandlerStd.cpp Interactions/mitkDisplayActionEventHandlerSynchronized.cpp Interactions/mitkDisplayCoordinateOperation.cpp Interactions/mitkEventConfig.cpp Interactions/mitkEventFactory.cpp Interactions/mitkEventRecorder.cpp Interactions/mitkEventStateMachine.cpp Interactions/mitkInteractionEventConst.cpp Interactions/mitkInteractionEvent.cpp Interactions/mitkInteractionEventHandler.cpp Interactions/mitkInteractionEventObserver.cpp Interactions/mitkInteractionKeyEvent.cpp Interactions/mitkInteractionPositionEvent.cpp Interactions/mitkInteractionSchemeSwitcher.cpp Interactions/mitkInternalEvent.cpp Interactions/mitkMouseDoubleClickEvent.cpp Interactions/mitkMouseMoveEvent.cpp Interactions/mitkMousePressEvent.cpp Interactions/mitkMouseReleaseEvent.cpp Interactions/mitkMouseWheelEvent.cpp Interactions/mitkPointSetDataInteractor.cpp Interactions/mitkSinglePointDataInteractor.cpp Interactions/mitkStateMachineAction.cpp Interactions/mitkStateMachineCondition.cpp Interactions/mitkStateMachineContainer.cpp Interactions/mitkStateMachineState.cpp Interactions/mitkStateMachineTransition.cpp Interactions/mitkVtkEventAdapter.cpp Interactions/mitkVtkInteractorStyle.cxx Interactions/mitkXML2EventParser.cpp IO/mitkAbstractFileIO.cpp IO/mitkAbstractFileReader.cpp IO/mitkAbstractFileWriter.cpp IO/mitkCustomMimeType.cpp IO/mitkFileReader.cpp IO/mitkFileReaderRegistry.cpp IO/mitkFileReaderSelector.cpp IO/mitkFileReaderWriterBase.cpp IO/mitkFileWriter.cpp IO/mitkFileWriterRegistry.cpp IO/mitkFileWriterSelector.cpp IO/mitkGeometry3DToXML.cpp IO/mitkIFileIO.cpp IO/mitkIFileReader.cpp IO/mitkIFileWriter.cpp IO/mitkGeometryDataReaderService.cpp IO/mitkGeometryDataWriterService.cpp IO/mitkImageVtkLegacyIO.cpp IO/mitkImageVtkXmlIO.cpp IO/mitkIMimeTypeProvider.cpp IO/mitkIOConstants.cpp IO/mitkIOMimeTypes.cpp IO/mitkIOUtil.cpp IO/mitkItkImageIO.cpp IO/mitkItkLoggingAdapter.cpp IO/mitkLegacyFileReaderService.cpp IO/mitkLegacyFileWriterService.cpp IO/mitkLocaleSwitch.cpp IO/mitkLogBackend.cpp IO/mitkMimeType.cpp IO/mitkMimeTypeProvider.cpp IO/mitkOperation.cpp IO/mitkPixelType.cpp IO/mitkPointSetReaderService.cpp IO/mitkPointSetWriterService.cpp IO/mitkProportionalTimeGeometryToXML.cpp IO/mitkRawImageFileReader.cpp IO/mitkStandardFileLocations.cpp IO/mitkSurfaceStlIO.cpp IO/mitkSurfaceVtkIO.cpp IO/mitkSurfaceVtkLegacyIO.cpp IO/mitkSurfaceVtkXmlIO.cpp IO/mitkUtf8Util.cpp IO/mitkVtkLoggingAdapter.cpp IO/mitkPreferenceListReaderOptionsFunctor.cpp IO/mitkIOMetaInformationPropertyConstants.cpp IO/mitkIPreferences.cpp IO/mitkPreferences.cpp IO/mitkIPreferencesService.cpp IO/mitkPreferencesService.cpp IO/mitkIPreferencesStorage.cpp IO/mitkXMLPreferencesStorage.cpp Rendering/mitkAbstractAnnotationRenderer.cpp Rendering/mitkAnnotationUtils.cpp Rendering/mitkBaseRenderer.cpp Rendering/mitkBaseRendererHelper.cpp Rendering/mitkCrosshairVtkMapper2D.cpp Rendering/mitkGradientBackground.cpp Rendering/mitkImageVtkMapper2D.cpp Rendering/mitkMapper.cpp Rendering/mitkAnnotation.cpp Rendering/mitkPlaneGeometryDataMapper2D.cpp Rendering/mitkPlaneGeometryDataVtkMapper3D.cpp Rendering/mitkPointSetVtkMapper2D.cpp Rendering/mitkPointSetVtkMapper3D.cpp Rendering/mitkRenderWindowBase.cpp Rendering/mitkRenderWindow.cpp Rendering/mitkRenderWindowFrame.cpp Rendering/mitkSurfaceVtkMapper2D.cpp Rendering/mitkSurfaceVtkMapper3D.cpp Rendering/mitkVideoRecorder.cpp Rendering/mitkVtkEventProvider.cpp Rendering/mitkVtkMapper.cpp Rendering/mitkVtkPropRenderer.cpp Rendering/mitkVtkWidgetRendering.cpp Rendering/vtkMitkLevelWindowFilter.cpp Rendering/vtkMitkRectangleProp.cpp Rendering/vtkMitkRenderProp.cpp Rendering/vtkMitkThickSlicesFilter.cpp Rendering/vtkNeverTranslucentTexture.cpp ) set(RESOURCE_FILES Interactions/globalConfig.xml Interactions/DisplayInteraction.xml Interactions/DisplayConfigMITKBase.xml Interactions/DisplayConfigPACSBase.xml Interactions/DisplayConfigCrosshair.xml Interactions/DisplayConfigRotation.xml Interactions/DisplayConfigActivateCoupling.xml Interactions/DisplayConfigSwivel.xml Interactions/DisplayConfigPACSPan.xml Interactions/DisplayConfigPACSScroll.xml Interactions/DisplayConfigPACSZoom.xml Interactions/DisplayConfigPACSLevelWindow.xml Interactions/DisplayConfigBlockLMB.xml Interactions/PointSet.xml Interactions/PointSetConfig.xml mitkLevelWindowPresets.xml mitkAnatomicalStructureColorPresets.xml ) diff --git a/Modules/Core/include/mitkITKEventObserverGuard.h b/Modules/Core/include/mitkITKEventObserverGuard.h new file mode 100644 index 0000000000..df3c495c08 --- /dev/null +++ b/Modules/Core/include/mitkITKEventObserverGuard.h @@ -0,0 +1,93 @@ +/*============================================================================ + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center (DKFZ) +All rights reserved. + +Use of this source code is governed by a 3-clause BSD license that can be +found in the LICENSE file. + +============================================================================*/ + +#ifndef mitkITKEventObserverGuard_h +#define mitkITKEventObserverGuard_h + +#include <functional> + +#include "MitkCoreExports.h" + +namespace itk +{ + class Object; + class Command; + class EventObject; +} + +namespace mitk +{ + /** + \brief Convenience class that helps to manage the lifetime of itk event observers. + + This helper class can be used to ensure itk event observers are removed form + a sender object at the end of a certain scope. + This class behaves simelar to a std::unique_ptr but for event observers. + Therfore the observer will be removed from the sender when one of the following + conditions are met: + - the guard is destroyed + - the guard is resetted (by Reset() or operator = ) + + Sample usage: + \code + { + auto &objRef = *o.GetPointer(); + auto guard = ITKEventObserverGuard(o, itk::AnyEvent(), [&objRef](const itk::EventObject &event) + { std::cout << "Object: " << objRef.GetNameOfClass() << " Event: " << event << std::endl; }); + //some code + } + //now the guard is destroyed + \endcode + This will add an Observer to o executing the lambda for any event as long as the guard exists. + @remark If the sender is already destroyed at the moment, when the guard wants to + remove the observer, the removal will be skipped. + */ + + class MITKCORE_EXPORT ITKEventObserverGuard + { + public: + ITKEventObserverGuard(); + ITKEventObserverGuard(const itk::Object* sender, unsigned long observerTag); + ITKEventObserverGuard(const itk::Object* sender, const itk::EventObject& event, itk::Command* command); + ITKEventObserverGuard(const itk::Object* sender, const itk::EventObject& event, std::function<void(const itk::EventObject&)> function); + ITKEventObserverGuard(ITKEventObserverGuard&); + ITKEventObserverGuard& operator=(ITKEventObserverGuard&); + + ~ITKEventObserverGuard(); + + /** Resets the guard by removing the currently guarded observer. After the reset the guard is uninitialized. + *@remark resetting an uninitialized guard has no effect.*/ + void Reset(); + + /** Resets the guard by first removing the currently guarded observer. Then the passed observer tag for the + * passed sender will be guarded.*/ + void Reset(const itk::Object* sender, unsigned long observerTag); + + /** Resets the guard by first removing the currently guarded observer. Then a observer will be added for + * the passed sender with the passed event and command. The new observer is now guarded.*/ + void Reset(const itk::Object* sender, const itk::EventObject& event, itk::Command* command); + + /** Resets the guard by first removing the currently guarded observer. Then a observer will be added for + * the passed sender with the passed event and lamba function. The new observer is now guarded.*/ + void Reset(const itk::Object* sender, const itk::EventObject& event, std::function<void(const itk::EventObject&)> function); + + bool IsInitialized() const; + + private: + struct Impl; + Impl *m_ITKEventObserverGuardImpl; + }; + + +} + +#endif diff --git a/Modules/Core/src/DataManagement/mitkITKEventObserverGuard.cpp b/Modules/Core/src/DataManagement/mitkITKEventObserverGuard.cpp new file mode 100644 index 0000000000..d227f1ad59 --- /dev/null +++ b/Modules/Core/src/DataManagement/mitkITKEventObserverGuard.cpp @@ -0,0 +1,112 @@ +/*============================================================================ + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center (DKFZ) +All rights reserved. + +Use of this source code is governed by a 3-clause BSD license that can be +found in the LICENSE file. + +============================================================================*/ + +#include "mitkITKEventObserverGuard.h" + +#include <itkObject.h> +#include <itkEventObject.h> +#include <mitkWeakPointer.h> + +namespace mitk +{ + struct ITKEventObserverGuard::Impl + { + explicit Impl(const itk::Object* sender, unsigned long observerTag); + + ~Impl(); + + private: + mitk::WeakPointer<itk::Object> m_Sender; + unsigned long m_ObserverTag; + }; + + ITKEventObserverGuard::Impl::Impl(const itk::Object* sender, unsigned long observerTag) : m_Sender(const_cast<itk::Object*>(sender)), m_ObserverTag(observerTag) + { + //we cast const sender to non const in order to be able to remove observers but + //also support constness in code that uses the guard. + } + + ITKEventObserverGuard::Impl::~Impl() + { + auto sender = m_Sender.Lock(); + + if (sender.IsNotNull()) + { + sender->RemoveObserver(m_ObserverTag); + } + } + + ITKEventObserverGuard::ITKEventObserverGuard() : m_ITKEventObserverGuardImpl(nullptr) {} + + ITKEventObserverGuard::ITKEventObserverGuard(const itk::Object* sender, unsigned long observerTag) : m_ITKEventObserverGuardImpl(new Impl(sender, observerTag)) {} + + ITKEventObserverGuard::ITKEventObserverGuard(const itk::Object* sender, const itk::EventObject& event, itk::Command* command) + { + auto tag = sender->AddObserver(event, command); + m_ITKEventObserverGuardImpl = new Impl(sender, tag); + } + + ITKEventObserverGuard::ITKEventObserverGuard(const itk::Object* sender, const itk::EventObject& event, std::function<void(const itk::EventObject&)> function) + { + auto tag = sender->AddObserver(event, function); + m_ITKEventObserverGuardImpl = new Impl(sender, tag); + } + + ITKEventObserverGuard::ITKEventObserverGuard(ITKEventObserverGuard& g) + { + m_ITKEventObserverGuardImpl = nullptr; + + std::swap(m_ITKEventObserverGuardImpl, g.m_ITKEventObserverGuardImpl); + } + + ITKEventObserverGuard& ITKEventObserverGuard::operator=(ITKEventObserverGuard& g) + { + this->Reset(); + + std::swap(m_ITKEventObserverGuardImpl, g.m_ITKEventObserverGuardImpl); + return *this; + } + + ITKEventObserverGuard::~ITKEventObserverGuard() { delete m_ITKEventObserverGuardImpl; } + + void ITKEventObserverGuard::Reset() + { + delete m_ITKEventObserverGuardImpl; + m_ITKEventObserverGuardImpl = nullptr; + } + + void ITKEventObserverGuard::Reset(const itk::Object* sender, unsigned long observerTag) + { + delete m_ITKEventObserverGuardImpl; + m_ITKEventObserverGuardImpl = new Impl(sender, observerTag); + } + + void ITKEventObserverGuard::Reset(const itk::Object* sender, const itk::EventObject& event, itk::Command* command) + { + delete m_ITKEventObserverGuardImpl; + auto tag = sender->AddObserver(event, command); + m_ITKEventObserverGuardImpl = new Impl(sender, tag); + } + + void ITKEventObserverGuard::Reset(const itk::Object* sender, const itk::EventObject& event, std::function<void(const itk::EventObject&)> function) + { + delete m_ITKEventObserverGuardImpl; + auto tag = sender->AddObserver(event, function); + m_ITKEventObserverGuardImpl = new Impl(sender, tag); + } + + bool ITKEventObserverGuard::IsInitialized() const + { + return nullptr != this->m_ITKEventObserverGuardImpl; + } + +} diff --git a/Modules/Core/test/files.cmake b/Modules/Core/test/files.cmake index 5e7a4c8a5f..b4b926c612 100644 --- a/Modules/Core/test/files.cmake +++ b/Modules/Core/test/files.cmake @@ -1,198 +1,199 @@ # tests with no extra command line parameter set(MODULE_TESTS # IMPORTANT: If you plan to deactivate / comment out a test please write a bug number to the commented out line of code. # # Example: #mitkMyTest #this test is commented out because of bug 12345 # # It is important that the bug is open and that the test will be activated again before the bug is closed. This assures that # no test is forgotten after it was commented out. If there is no bug for your current problem, please add a new one and # mark it as critical. ################## DISABLED TESTS ################################################# #mitkAbstractTransformGeometryTest.cpp #seems as tested class mitkExternAbstractTransformGeometry doesn't exist any more #mitkStateMachineContainerTest.cpp #rewrite test, indirect since no longer exported Bug 14529 #mitkRegistrationBaseTest.cpp #tested class mitkRegistrationBase doesn't exist any more #mitkSegmentationInterpolationTest.cpp #file doesn't exist! #mitkPipelineSmartPointerCorrectnessTest.cpp #file doesn't exist! #mitkITKThreadingTest.cpp #test outdated because itk::Semaphore was removed from ITK #mitkAbstractTransformPlaneGeometryTest.cpp #mitkVtkAbstractTransformPlaneGeometry doesn't exist any more #mitkTestUtilSharedLibrary.cpp #Linker problem with this test... #mitkTextOverlay2DSymbolsRenderingTest.cpp #Implementation of the tested feature is not finished yet. Ask Christoph or see bug 15104 for details. ################# RUNNING TESTS ################################################### mitkAccessByItkTest.cpp mitkCoreObjectFactoryTest.cpp mitkDataNodeTest.cpp mitkMaterialTest.cpp mitkActionTest.cpp mitkDispatcherTest.cpp mitkEnumerationPropertyTest.cpp mitkFileReaderRegistryTest.cpp #mitkFileWriterRegistryTest.cpp mitkFloatToStringTest.cpp mitkGenericPropertyTest.cpp mitkGeometry3DTest.cpp mitkGeometry3DEqualTest.cpp mitkGeometryDataIOTest.cpp mitkGeometryDataToSurfaceFilterTest.cpp mitkImageCastTest.cpp mitkImageDataItemTest.cpp mitkImageGeneratorTest.cpp mitkIOUtilTest.cpp + mitkITKEventObserverGuardTest.cpp mitkBaseDataTest.cpp mitkImportItkImageTest.cpp mitkGrabItkImageMemoryTest.cpp mitkInstantiateAccessFunctionTest.cpp mitkLevelWindowTest.cpp mitkMessageTest.cpp mitkPixelTypeTest.cpp mitkPlaneGeometryTest.cpp mitkPointSetTest.cpp mitkPointSetEqualTest.cpp mitkPointSetFileIOTest.cpp mitkPointSetOnEmptyTest.cpp mitkPointSetLocaleTest.cpp mitkPointSetWriterTest.cpp mitkPointSetPointOperationsTest.cpp mitkProgressBarTest.cpp mitkPropertyTest.cpp mitkPropertyListTest.cpp mitkPropertyPersistenceTest.cpp mitkPropertyPersistenceInfoTest.cpp mitkPropertyRelationRuleBaseTest.cpp mitkPropertyRelationsTest.cpp mitkSlicedGeometry3DTest.cpp mitkSliceNavigationControllerTest.cpp mitkSurfaceTest.cpp mitkSurfaceEqualTest.cpp mitkSurfaceToSurfaceFilterTest.cpp mitkTimeGeometryTest.cpp mitkProportionalTimeGeometryTest.cpp mitkUndoControllerTest.cpp mitkVtkWidgetRenderingTest.cpp mitkVerboseLimitedLinearUndoTest.cpp mitkWeakPointerTest.cpp mitkTransferFunctionTest.cpp mitkStepperTest.cpp mitkRenderingManagerTest.cpp mitkCompositePixelValueToStringTest.cpp vtkMitkThickSlicesFilterTest.cpp mitkNodePredicateDataPropertyTest.cpp mitkNodePredicateFunctionTest.cpp mitkVectorTest.cpp mitkClippedSurfaceBoundsCalculatorTest.cpp mitkExceptionTest.cpp mitkExtractSliceFilterTest.cpp mitkLogTest.cpp mitkImageDimensionConverterTest.cpp mitkLoggingAdapterTest.cpp mitkUIDGeneratorTest.cpp mitkPlanePositionManagerTest.cpp mitkAffineTransformBaseTest.cpp mitkPropertyAliasesTest.cpp mitkPropertyDescriptionsTest.cpp mitkPropertyExtensionsTest.cpp mitkPropertyFiltersTest.cpp mitkPropertyKeyPathTest.cpp mitkTinyXMLTest.cpp mitkRawImageFileReaderTest.cpp mitkInteractionEventTest.cpp mitkLookupTableTest.cpp mitkSTLFileReaderTest.cpp mitkPointTypeConversionTest.cpp mitkVectorTypeConversionTest.cpp mitkMatrixTypeConversionTest.cpp mitkArrayTypeConversionTest.cpp mitkSurfaceToImageFilterTest.cpp mitkBaseGeometryTest.cpp mitkImageToSurfaceFilterTest.cpp mitkEqualTest.cpp mitkLineTest.cpp mitkArbitraryTimeGeometryTest.cpp mitkItkImageIOTest.cpp mitkLevelWindowManagerTest.cpp mitkVectorPropertyTest.cpp mitkTemporoSpatialStringPropertyTest.cpp mitkPropertyNameHelperTest.cpp mitkNodePredicateGeometryTest.cpp mitkNodePredicateSubGeometryTest.cpp mitkPreferenceListReaderOptionsFunctorTest.cpp mitkGenericIDRelationRuleTest.cpp mitkSourceImageRelationRuleTest.cpp mitkTemporalJoinImagesFilterTest.cpp mitkPreferencesTest.cpp ) set(MODULE_RENDERING_TESTS mitkPointSetDataInteractorTest.cpp mitkSurfaceVtkMapper2DTest.cpp mitkSurfaceVtkMapper2D3DTest.cpp ) # test with image filename as an extra command line parameter set(MODULE_IMAGE_TESTS mitkImageTimeSelectorTest.cpp #only runs on images mitkImageAccessorTest.cpp #only runs on images ) set(MODULE_SURFACE_TESTS mitkSurfaceVtkWriterTest.cpp #only runs on surfaces ) # list of images for which the tests are run set(MODULE_TESTIMAGE US4DCyl.nrrd Pic3D.nrrd Pic2DplusT.nrrd BallBinary30x30x30.nrrd Png2D-bw.png ) set(MODULE_TESTSURFACE binary.stl ball.stl ) set(MODULE_CUSTOM_TESTS mitkDataStorageTest.cpp mitkDataNodeTest.cpp mitkEventConfigTest.cpp mitkPointSetLocaleTest.cpp mitkImageTest.cpp mitkImageVtkMapper2DTest.cpp mitkImageVtkMapper2DLevelWindowTest.cpp mitkImageVtkMapper2DOpacityTest.cpp mitkImageVtkMapper2DResliceInterpolationPropertyTest.cpp mitkImageVtkMapper2DColorTest.cpp mitkImageVtkMapper2DSwivelTest.cpp mitkImageVtkMapper2DTransferFunctionTest.cpp mitkImageVtkMapper2DOpacityTransferFunctionTest.cpp mitkImageVtkMapper2DLookupTableTest.cpp mitkSurfaceVtkMapper3DTest.cpp mitkVolumeCalculatorTest.cpp mitkLevelWindowManagerTest.cpp mitkPointSetVtkMapper2DTest.cpp mitkPointSetVtkMapper2DImageTest.cpp mitkPointSetVtkMapper2DGlyphTypeTest.cpp mitkPointSetVtkMapper2DTransformedPointsTest.cpp mitkVTKRenderWindowSizeTest.cpp mitkMultiComponentImageDataComparisonFilterTest.cpp mitkImageToItkTest.cpp mitkImageSliceSelectorTest.cpp mitkPointSetReaderTest.cpp mitkImageEqualTest.cpp mitkRotatedSlice4DTest.cpp mitkPlaneGeometryDataMapper2DTest.cpp ) # Currently not working on windows because of a rendering timing issue # see bug 18083 for details if(NOT WIN32) set(MODULE_CUSTOM_TESTS ${MODULE_CUSTOM_TESTS} mitkSurfaceDepthSortingTest.cpp) endif() set(RESOURCE_FILES Interactions/AddAndRemovePoints.xml Interactions/globalConfig.xml Interactions/StatemachineTest.xml Interactions/StatemachineConfigTest.xml ) diff --git a/Modules/Core/test/mitkITKEventObserverGuardTest.cpp b/Modules/Core/test/mitkITKEventObserverGuardTest.cpp new file mode 100644 index 0000000000..22a77c1c7b --- /dev/null +++ b/Modules/Core/test/mitkITKEventObserverGuardTest.cpp @@ -0,0 +1,258 @@ +/*============================================================================ + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center (DKFZ) +All rights reserved. + +Use of this source code is governed by a 3-clause BSD license that can be +found in the LICENSE file. + +============================================================================*/ + +#include "mitkITKEventObserverGuard.h" + +#include <itkEventObject.h> +#include <itkCommand.h> + +#include <mitkTestFixture.h> +#include <mitkTestingMacros.h> + +// Create a command to observe events +class DummyCommand : public itk::Command +{ +public: + using Self = DummyCommand; + using Superclass = itk::Command; + using Pointer = itk::SmartPointer<Self>; + using ConstPointer = itk::SmartPointer<const Self>; + + itkNewMacro(DummyCommand); + + void Execute(itk::Object*, const itk::EventObject&) override + { + ++ExecutionCount; + } + + void Execute(const itk::Object*, const itk::EventObject&) override + { + ++ExecutionCount; + } + + int ExecutionCount; + +protected: + DummyCommand() : ExecutionCount(0) {} +}; + +class mitkITKEventObserverGuardTestSuite : public mitk::TestFixture +{ + CPPUNIT_TEST_SUITE(mitkITKEventObserverGuardTestSuite); + MITK_TEST(TestConstructor); + MITK_TEST(TestConstructor2); + MITK_TEST(TestConstructor3); + MITK_TEST(TestConstructor4); + MITK_TEST(TestReset); + MITK_TEST(TestReset2); + MITK_TEST(TestOperateAssign); + CPPUNIT_TEST_SUITE_END(); + + itk::Object::Pointer m_TestObject; + DummyCommand::Pointer m_DummyCommand; + DummyCommand::Pointer m_DummyCommand2; + +public: + void setUp() override + { + m_TestObject = itk::Object::New(); + m_DummyCommand = DummyCommand::New(); + m_DummyCommand2 = DummyCommand::New(); + } + + void tearDown() override + { + m_TestObject = nullptr; + m_DummyCommand = nullptr; + m_DummyCommand2 = nullptr; + } + // This test is supposed to verify inheritance behaviour, this test will fail if the behaviour changes in the future + + void TestConstructor() + { + mitk::ITKEventObserverGuard guard; + + CPPUNIT_ASSERT(!guard.IsInitialized()); + } + + void TestConstructor2() + { + m_TestObject->InvokeEvent(itk::ModifiedEvent()); + CPPUNIT_ASSERT_EQUAL(0, m_DummyCommand->ExecutionCount); + + { + auto tag = m_TestObject->AddObserver(itk::ModifiedEvent(), m_DummyCommand); + mitk::ITKEventObserverGuard guard(m_TestObject, tag); + + CPPUNIT_ASSERT(guard.IsInitialized()); + m_TestObject->InvokeEvent(itk::ModifiedEvent()); + CPPUNIT_ASSERT_EQUAL(1, m_DummyCommand->ExecutionCount); + + m_TestObject->InvokeEvent(itk::ProgressEvent()); + CPPUNIT_ASSERT_EQUAL(1, m_DummyCommand->ExecutionCount); + } + + m_TestObject->InvokeEvent(itk::ModifiedEvent()); + CPPUNIT_ASSERT_EQUAL(1, m_DummyCommand->ExecutionCount); + } + + void TestConstructor3() + { + m_TestObject->InvokeEvent(itk::ModifiedEvent()); + CPPUNIT_ASSERT_EQUAL(0, m_DummyCommand->ExecutionCount); + + { + mitk::ITKEventObserverGuard guard(m_TestObject, itk::ModifiedEvent(), m_DummyCommand); + + CPPUNIT_ASSERT(guard.IsInitialized()); + m_TestObject->InvokeEvent(itk::ModifiedEvent()); + CPPUNIT_ASSERT_EQUAL(1, m_DummyCommand->ExecutionCount); + + m_TestObject->InvokeEvent(itk::ProgressEvent()); + CPPUNIT_ASSERT_EQUAL(1, m_DummyCommand->ExecutionCount); + } + + m_TestObject->InvokeEvent(itk::ModifiedEvent()); + CPPUNIT_ASSERT_EQUAL(1, m_DummyCommand->ExecutionCount); + } + + void TestConstructor4() + { + m_TestObject->InvokeEvent(itk::ModifiedEvent()); + CPPUNIT_ASSERT_EQUAL(0, m_DummyCommand->ExecutionCount); + + { + mitk::ITKEventObserverGuard guard(m_TestObject, itk::ModifiedEvent(), [this](const itk::EventObject& e) {++(this->m_DummyCommand->ExecutionCount); }); + + CPPUNIT_ASSERT(guard.IsInitialized()); + m_TestObject->InvokeEvent(itk::ModifiedEvent()); + CPPUNIT_ASSERT_EQUAL(1, m_DummyCommand->ExecutionCount); + + m_TestObject->InvokeEvent(itk::ProgressEvent()); + CPPUNIT_ASSERT_EQUAL(1, m_DummyCommand->ExecutionCount); + } + + m_TestObject->InvokeEvent(itk::ModifiedEvent()); + CPPUNIT_ASSERT_EQUAL(1, m_DummyCommand->ExecutionCount); + } + + void TestReset() + { + m_TestObject->InvokeEvent(itk::ModifiedEvent()); + CPPUNIT_ASSERT_EQUAL(0, m_DummyCommand->ExecutionCount); + + mitk::ITKEventObserverGuard guard(m_TestObject, itk::ModifiedEvent(), m_DummyCommand); + + CPPUNIT_ASSERT(guard.IsInitialized()); + m_TestObject->InvokeEvent(itk::ModifiedEvent()); + CPPUNIT_ASSERT_EQUAL(1, m_DummyCommand->ExecutionCount); + + guard.Reset(); + CPPUNIT_ASSERT(!guard.IsInitialized()); + m_TestObject->InvokeEvent(itk::ModifiedEvent()); + CPPUNIT_ASSERT_EQUAL(1, m_DummyCommand->ExecutionCount); + + guard.Reset(); + CPPUNIT_ASSERT(!guard.IsInitialized()); + } + + void TestReset2() + { + m_TestObject->InvokeEvent(itk::ModifiedEvent()); + CPPUNIT_ASSERT_EQUAL(0, m_DummyCommand->ExecutionCount); + + mitk::ITKEventObserverGuard guard(m_TestObject, itk::ModifiedEvent(), m_DummyCommand); + + CPPUNIT_ASSERT(guard.IsInitialized()); + m_TestObject->InvokeEvent(itk::ModifiedEvent()); + CPPUNIT_ASSERT_EQUAL(1, m_DummyCommand->ExecutionCount); + + auto tag = m_TestObject->AddObserver(itk::ProgressEvent(), m_DummyCommand2); + guard.Reset(m_TestObject, tag); + CPPUNIT_ASSERT(guard.IsInitialized()); + m_TestObject->InvokeEvent(itk::ModifiedEvent()); + CPPUNIT_ASSERT_EQUAL(1, m_DummyCommand->ExecutionCount); + + m_TestObject->InvokeEvent(itk::ProgressEvent()); + CPPUNIT_ASSERT_EQUAL(1, m_DummyCommand2->ExecutionCount); + } + + void TestReset3() + { + m_TestObject->InvokeEvent(itk::ModifiedEvent()); + CPPUNIT_ASSERT_EQUAL(0, m_DummyCommand->ExecutionCount); + + mitk::ITKEventObserverGuard guard(m_TestObject, itk::ModifiedEvent(), m_DummyCommand); + + CPPUNIT_ASSERT(guard.IsInitialized()); + m_TestObject->InvokeEvent(itk::ModifiedEvent()); + CPPUNIT_ASSERT_EQUAL(1, m_DummyCommand->ExecutionCount); + + guard.Reset(m_TestObject, itk::ProgressEvent(), m_DummyCommand2); + CPPUNIT_ASSERT(guard.IsInitialized()); + m_TestObject->InvokeEvent(itk::ModifiedEvent()); + CPPUNIT_ASSERT_EQUAL(1, m_DummyCommand->ExecutionCount); + + m_TestObject->InvokeEvent(itk::ProgressEvent()); + CPPUNIT_ASSERT_EQUAL(1, m_DummyCommand2->ExecutionCount); + } + + void TestReset4() + { + m_TestObject->InvokeEvent(itk::ModifiedEvent()); + CPPUNIT_ASSERT_EQUAL(0, m_DummyCommand->ExecutionCount); + + mitk::ITKEventObserverGuard guard(m_TestObject, itk::ModifiedEvent(), m_DummyCommand); + + CPPUNIT_ASSERT(guard.IsInitialized()); + m_TestObject->InvokeEvent(itk::ModifiedEvent()); + CPPUNIT_ASSERT_EQUAL(1, m_DummyCommand->ExecutionCount); + + guard.Reset(m_TestObject, itk::ProgressEvent(), [this](const itk::EventObject& e) {++(this->m_DummyCommand2->ExecutionCount); }); + CPPUNIT_ASSERT(guard.IsInitialized()); + m_TestObject->InvokeEvent(itk::ModifiedEvent()); + CPPUNIT_ASSERT_EQUAL(1, m_DummyCommand->ExecutionCount); + + m_TestObject->InvokeEvent(itk::ProgressEvent()); + CPPUNIT_ASSERT_EQUAL(1, m_DummyCommand2->ExecutionCount); + } + + void TestOperateAssign() + { + m_TestObject->InvokeEvent(itk::ModifiedEvent()); + CPPUNIT_ASSERT_EQUAL(0, m_DummyCommand->ExecutionCount); + + mitk::ITKEventObserverGuard guard(m_TestObject, itk::ModifiedEvent(), m_DummyCommand); + + CPPUNIT_ASSERT(guard.IsInitialized()); + m_TestObject->InvokeEvent(itk::ModifiedEvent()); + CPPUNIT_ASSERT_EQUAL(1, m_DummyCommand->ExecutionCount); + + auto guard2 = mitk::ITKEventObserverGuard(m_TestObject, itk::ProgressEvent(), [this](const itk::EventObject& e) {++(this->m_DummyCommand2->ExecutionCount); }); + CPPUNIT_ASSERT(guard.IsInitialized()); + CPPUNIT_ASSERT(guard2.IsInitialized()); + m_TestObject->InvokeEvent(itk::ProgressEvent()); + CPPUNIT_ASSERT_EQUAL(1, m_DummyCommand2->ExecutionCount); + + guard = guard2; + + CPPUNIT_ASSERT(guard.IsInitialized()); + CPPUNIT_ASSERT(!guard2.IsInitialized()); + m_TestObject->InvokeEvent(itk::ModifiedEvent()); + CPPUNIT_ASSERT_EQUAL(1, m_DummyCommand->ExecutionCount); + + m_TestObject->InvokeEvent(itk::ProgressEvent()); + CPPUNIT_ASSERT_EQUAL(2, m_DummyCommand2->ExecutionCount); + } +}; + +MITK_TEST_SUITE_REGISTRATION(mitkITKEventObserverGuard)