diff --git a/Modules/Core/include/mitkNodePredicateSubGeometry.h b/Modules/Core/include/mitkNodePredicateSubGeometry.h index 898c434378..53cddf1959 100644 --- a/Modules/Core/include/mitkNodePredicateSubGeometry.h +++ b/Modules/Core/include/mitkNodePredicateSubGeometry.h @@ -1,68 +1,68 @@ /*============================================================================ 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 MITKNODEPREDICATESUBGEOMETRY_H_HEADER_INCLUDED_ -#define MITKNODEPREDICATEGSUBEOMETRY_H_HEADER_INCLUDED_ +#define MITKNODEPREDICATESUBGEOMETRY_H_HEADER_INCLUDED_ #include "mitkNodePredicateBase.h" #include "mitkBaseGeometry.h" #include "mitkTimeGeometry.h" namespace mitk { class BaseData; /**Documentation @brief Predicate that evaluates if the given DataNode's data object has a geimetry that is a sub geomety of the reference geometry. Sub geometry means that both geometries have the same voxel grid (same spacing, same axes, orgin is on voxel grid), but the boundingbox of the checked geometry is contained or equal to the bounding box of the reference geometry.\n One can either check the whole time geometry of - the date node by defining a referenc time geometry or check against one given + the date node by defining a referenc time geometry or check against one given2 reference base geometry. If the predicate should check against a base geometry, you can specify the timepoint of the data's time geometry that should be checked. If no timepoint is defined the predicate will evaluate the data geometry in the first timestep. Evaluates to "false" for unsupported or undefined data objects/geometries. @ingroup DataStorage */ class MITKCORE_EXPORT NodePredicateSubGeometry : public NodePredicateBase { public: mitkClassMacro(NodePredicateSubGeometry, NodePredicateBase); mitkNewMacro1Param(NodePredicateSubGeometry, const BaseGeometry*); mitkNewMacro2Param(NodePredicateSubGeometry, const BaseGeometry*, TimePointType); itkSetMacro(CheckPrecision, mitk::ScalarType); itkGetMacro(CheckPrecision, mitk::ScalarType); ~NodePredicateSubGeometry() override; bool CheckNode(const mitk::DataNode *node) const override; protected: /**Constructor that is used configures the predicate to check the reference geometry against the first data timepoint.*/ NodePredicateSubGeometry(const BaseGeometry* refGeometry); /**Constructor allows to define the timepoint that should be evaluated against the reference.*/ NodePredicateSubGeometry(const BaseGeometry* refGeometry, TimePointType relevantTimePoint); BaseGeometry::ConstPointer m_RefGeometry; TimePointType m_TimePoint; /**Indicates if m_TimePoint should be regarded or always the first timestep should be used.*/ bool m_UseTimePoint; /**Precision that should be used for the equal checks.*/ mitk::ScalarType m_CheckPrecision; }; } // namespace mitk #endif diff --git a/Modules/Core/test/files.cmake b/Modules/Core/test/files.cmake index 5efc282bfa..63b574f8ed 100644 --- a/Modules/Core/test/files.cmake +++ b/Modules/Core/test/files.cmake @@ -1,194 +1,195 @@ # 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 doesnt 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 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 mitkNodePredicateSourceTest.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 mitkLevelWindowManagerCppUnitTest.cpp mitkVectorPropertyTest.cpp mitkTemporoSpatialStringPropertyTest.cpp mitkPropertyNameHelperTest.cpp mitkNodePredicateGeometryTest.cpp + mitkNodePredicateSubGeometryTest.cpp mitkPreferenceListReaderOptionsFunctorTest.cpp mitkGenericIDRelationRuleTest.cpp mitkSourceImageRelationRuleTest.cpp mitkPointSetDataInteractorTest.cpp #since mitkInteractionTestHelper is currently creating a vtkRenderWindow mitkSurfaceVtkMapper2DTest.cpp #new rendering test in CppUnit style mitkSurfaceVtkMapper2D3DTest.cpp # comparisons/consistency 2D/3D mitkTemporalJoinImagesFilterTest.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/mitkNodePredicateSubGeometryTest.cpp b/Modules/Core/test/mitkNodePredicateSubGeometryTest.cpp new file mode 100644 index 0000000000..e4f271fc73 --- /dev/null +++ b/Modules/Core/test/mitkNodePredicateSubGeometryTest.cpp @@ -0,0 +1,244 @@ +/*============================================================================ + +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 "mitkGeometry3D.h" +#include "mitkBaseDataTestImplementation.h" +#include "mitkNodePredicateSubGeometry.h" +#include "mitkDataNode.h" +#include "mitkTestFixture.h" +#include "mitkTestingMacros.h" + +class mitkNodePredicateSubGeometryTestSuite : public mitk::TestFixture +{ + CPPUNIT_TEST_SUITE(mitkNodePredicateSubGeometryTestSuite); + MITK_TEST(Check_InvalidConstructor); + MITK_TEST(Check_Spacing); + MITK_TEST(Check_TransformMatrix); + MITK_TEST(Check_Bounds); + MITK_TEST(Check_Grid); + CPPUNIT_TEST_SUITE_END(); + +private: + mitk::BaseDataTestImplementation::Pointer m_Data; + mitk::DataNode::Pointer m_Node; + + mitk::Geometry3D::Pointer m_RefGeometry; + + mitk::Geometry3D::Pointer m_AnotherGeometry3D; + +public: + /** +* @brief Setup Always call this method before each Test-case to ensure correct and new intialization of the used members +* for a new test case. (If the members are not used in a test, the method does not need to be called). +*/ + void setUp() override + { + m_RefGeometry = mitk::Geometry3D::New(); + m_RefGeometry->Initialize(); + + m_Data = mitk::BaseDataTestImplementation::New(); + m_Data->SetClonedGeometry(m_RefGeometry); + + m_Node = mitk::DataNode::New(); + m_Node->SetData(m_Data); + + m_AnotherGeometry3D = m_RefGeometry->Clone(); + } + + void tearDown() override + { + m_RefGeometry = nullptr; + m_AnotherGeometry3D = nullptr; + m_Data = nullptr; + } + + void Check_InvalidConstructor() + { + m_RefGeometry = nullptr; + CPPUNIT_ASSERT_THROW(mitk::NodePredicateSubGeometry::New(m_RefGeometry, 3), mitk::Exception); + CPPUNIT_ASSERT_THROW(mitk::NodePredicateSubGeometry::New(m_RefGeometry), mitk::Exception); + } + + void Check_CloneAndOriginal() + { + mitk::NodePredicateSubGeometry::Pointer predicate = mitk::NodePredicateSubGeometry::New(m_RefGeometry); + + CPPUNIT_ASSERT(predicate->CheckNode(m_Node)); + } + + void Check_Spacing() + { + mitk::NodePredicateSubGeometry::Pointer predicate = mitk::NodePredicateSubGeometry::New(m_RefGeometry); + + mitk::Vector3D spacing = m_RefGeometry->GetSpacing(); + for (unsigned int i = 0; i < 3; ++i) + { + mitk::Vector3D wrongSpacing = m_RefGeometry->GetSpacing(); + wrongSpacing[i] += mitk::eps * 2; + auto wrongGeometry = m_RefGeometry->Clone(); + wrongGeometry->SetSpacing(wrongSpacing); + m_Node->GetData()->SetGeometry(wrongGeometry); + + CPPUNIT_ASSERT(!predicate->CheckNode(m_Node)); + } + for (unsigned int i = 0; i < 3; ++i) + { + mitk::Vector3D wrongSpacing = m_RefGeometry->GetSpacing(); + wrongSpacing[i] -= mitk::eps * 2; + auto wrongGeometry = m_RefGeometry->Clone(); + wrongGeometry->SetSpacing(wrongSpacing); + m_Node->GetData()->SetGeometry(wrongGeometry); + + CPPUNIT_ASSERT(!predicate->CheckNode(m_Node)); + } + } + + void Check_TransformMatrix() + { + mitk::NodePredicateSubGeometry::Pointer predicate = mitk::NodePredicateSubGeometry::New(m_RefGeometry); + + for (unsigned int i = 0; i < 3; ++i) + { + for (unsigned int j = 0; j < 3; ++j) + { + itk::Matrix wrongMatrix = m_RefGeometry->GetIndexToWorldTransform()->GetMatrix(); + wrongMatrix[i][j] += mitk::eps * 2; + auto wrongGeometry = m_RefGeometry->Clone(); + wrongGeometry->GetIndexToWorldTransform()->SetMatrix(wrongMatrix); + m_Node->GetData()->SetGeometry(wrongGeometry); + + CPPUNIT_ASSERT(!predicate->CheckNode(m_Node)); + } + } + } + + void Check_Bounds() + { + auto newBounds = m_RefGeometry->GetBounds(); + newBounds[0] = 10; + newBounds[1] = 20; + newBounds[2] = 10; + newBounds[3] = 20; + newBounds[4] = 10; + newBounds[5] = 20; + m_RefGeometry->SetBounds(newBounds); + mitk::NodePredicateSubGeometry::Pointer predicate = mitk::NodePredicateSubGeometry::New(m_RefGeometry); + + for (unsigned int i = 0; i < 6; ++i) + { + auto legalBounds = newBounds; + if (i % 2 == 0) + { + legalBounds[i] += 1; + } + else + { + legalBounds[i] -= 1; + } + auto legalGeometry = m_RefGeometry->Clone(); + legalGeometry->SetBounds(legalBounds); + m_Node->GetData()->SetGeometry(legalGeometry); + + CPPUNIT_ASSERT(predicate->CheckNode(m_Node)); + } + + for (unsigned int i = 0; i < 6; ++i) + { + auto wrongBounds = m_RefGeometry->GetBounds(); + if (i % 2 == 0) + { + wrongBounds[i] -= 1; + } + else + { + wrongBounds[i] += 1; + } + auto wrongGeometry = m_RefGeometry->Clone(); + wrongGeometry->SetBounds(wrongBounds); + m_Node->GetData()->SetGeometry(wrongGeometry); + + CPPUNIT_ASSERT(!predicate->CheckNode(m_Node)); + } + } + + void Check_Grid() + { + auto newBounds = m_RefGeometry->GetBounds(); + newBounds[0] = 0; + newBounds[1] = 20; + newBounds[2] = 0; + newBounds[3] = 20; + newBounds[4] = 0; + newBounds[5] = 20; + m_RefGeometry->SetBounds(newBounds); + mitk::NodePredicateSubGeometry::Pointer predicate = mitk::NodePredicateSubGeometry::New(m_RefGeometry); + + auto smallerGeometry = m_RefGeometry->Clone(); + newBounds[0] = 5; + newBounds[1] = 10; + newBounds[2] = 5; + newBounds[3] = 10; + newBounds[4] = 5; + newBounds[5] = 10; + smallerGeometry->SetBounds(newBounds); + + //legal negative shift + for (unsigned int i = 0; i < 3; ++i) + { + auto legalOrigin = smallerGeometry->GetOrigin(); + legalOrigin[i] -= smallerGeometry->GetSpacing()[i]; + auto legalGeometry = smallerGeometry->Clone(); + legalGeometry->SetOrigin(legalOrigin); + m_Node->GetData()->SetGeometry(legalGeometry); + + CPPUNIT_ASSERT(predicate->CheckNode(m_Node)); + } + + //legal positive shift + for (unsigned int i = 0; i < 3; ++i) + { + auto legalOrigin = smallerGeometry->GetOrigin(); + legalOrigin[i] += smallerGeometry->GetSpacing()[i]; + auto legalGeometry = smallerGeometry->Clone(); + legalGeometry->SetOrigin(legalOrigin); + m_Node->GetData()->SetGeometry(legalGeometry); + + CPPUNIT_ASSERT(predicate->CheckNode(m_Node)); + } + + //wrong negative shift + for (unsigned int i = 0; i < 3; ++i) + { + auto wrongOrigin = smallerGeometry->GetOrigin(); + wrongOrigin[i] -= 2 * mitk::eps; + auto wrongGeometry = smallerGeometry->Clone(); + wrongGeometry->SetOrigin(wrongOrigin); + m_Node->GetData()->SetGeometry(wrongGeometry); + + CPPUNIT_ASSERT(!predicate->CheckNode(m_Node)); + } + + //wrong positive shift + for (unsigned int i = 0; i < 3; ++i) + { + auto wrongOrigin = smallerGeometry->GetOrigin(); + wrongOrigin[i] += 2 * mitk::eps; + auto wrongGeometry = smallerGeometry->Clone(); + wrongGeometry->SetOrigin(wrongOrigin); + m_Node->GetData()->SetGeometry(wrongGeometry); + + CPPUNIT_ASSERT(!predicate->CheckNode(m_Node)); + } + } +}; + +MITK_TEST_SUITE_REGISTRATION(mitkNodePredicateSubGeometry)