diff --git a/Examples/Tutorial/Step6/CMakeLists.txt b/Examples/Tutorial/Step6/CMakeLists.txt index 8fb1bbb466..c486d97f84 100644 --- a/Examples/Tutorial/Step6/CMakeLists.txt +++ b/Examples/Tutorial/Step6/CMakeLists.txt @@ -1,3 +1,4 @@ mitk_create_executable( DEPENDS MitkQtWidgetsExt + PACKAGE_DEPENDS ITK|RegionGrowing ) diff --git a/Examples/Tutorial/Step7/CMakeLists.txt b/Examples/Tutorial/Step7/CMakeLists.txt index 13c7b070a6..f3a9489e05 100644 --- a/Examples/Tutorial/Step7/CMakeLists.txt +++ b/Examples/Tutorial/Step7/CMakeLists.txt @@ -1,5 +1,6 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../Step6) mitk_create_executable( DEPENDS MitkQtWidgetsExt + PACKAGE_DEPENDS ITK|RegionGrowing ) diff --git a/Examples/Tutorial/Step8/CMakeLists.txt b/Examples/Tutorial/Step8/CMakeLists.txt index a090d34d9e..aa07199000 100644 --- a/Examples/Tutorial/Step8/CMakeLists.txt +++ b/Examples/Tutorial/Step8/CMakeLists.txt @@ -1,8 +1,9 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/../Step6 ${CMAKE_CURRENT_SOURCE_DIR}/../Step7 ) mitk_create_executable( DEPENDS MitkQtWidgetsExt + PACKAGE_DEPENDS ITK|RegionGrowing ) diff --git a/Modules/Classification/CLMiniApps/CMakeLists.txt b/Modules/Classification/CLMiniApps/CMakeLists.txt index fb5bb3b6c8..7325e45a38 100644 --- a/Modules/Classification/CLMiniApps/CMakeLists.txt +++ b/Modules/Classification/CLMiniApps/CMakeLists.txt @@ -1,117 +1,117 @@ option(BUILD_ClassificationMiniApps "Build commandline tools for classification" OFF) if(BUILD_ClassificationMiniApps OR MITK_BUILD_ALL_APPS) include_directories( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ) # list of miniapps # if an app requires additional dependencies # they are added after a "^^" and separated by "_" set( classificationminiapps RandomForestTraining^^MitkCLVigraRandomForest NativeHeadCTSegmentation^^MitkCLVigraRandomForest ManualSegmentationEvaluation^^MitkCLVigraRandomForest CLScreenshot^^MitkCore_MitkQtWidgetsExt_MitkCLUtilities CLDicom2Nrrd^^MitkCore CLResampleImageToReference^^MitkCore CLGlobalImageFeatures^^MitkCLUtilities_MitkQtWidgetsExt CLMRNormalization^^MitkCLUtilities_MitkCLMRUtilities CLStaple^^MitkCLUtilities CLVoxelFeatures^^MitkCLUtilities CLPolyToNrrd^^ CLPlanarFigureToNrrd^^MitkCore_MitkSegmentation_MitkMultilabel CLSimpleVoxelClassification^^MitkDataCollection_MitkCLVigraRandomForest CLVoxelClassification^^MitkDataCollection_MitkCLImportanceWeighting_MitkCLVigraRandomForest CLBrainMask^^MitkCLUtilities XRaxSimulationFromCT^^MitkCLUtilities CLRandomSampling^^MitkCore_MitkCLUtilities CLRemoveEmptyVoxels^^MitkCore CLN4^^MitkCore CLSkullMask^^MitkCore CLPointSetToSegmentation^^ CLMultiForestPrediction^^MitkDataCollection_MitkCLVigraRandomForest CLNrrdToPoly^^MitkCore CL2Dto3DImage^^MitkCore CLWeighting^^MitkCore_MitkCLImportanceWeighting_MitkCLUtilities CLOverlayRoiCenterOfMass^^MitkCore_MitkCLUtilities_MitkQtWidgetsExt CLLungSegmentation^^MitkCore_MitkSegmentation_MitkMultilabel ) foreach(classificationminiapps ${classificationminiapps}) # extract mini app name and dependencies string(REPLACE "^^" "\\;" miniapp_info ${classificationminiapps}) set(miniapp_info_list ${miniapp_info}) list(GET miniapp_info_list 0 appname) list(GET miniapp_info_list 1 raw_dependencies) string(REPLACE "_" "\\;" dependencies "${raw_dependencies}") set(dependencies_list ${dependencies}) mitk_create_executable(${appname} DEPENDS MitkCore MitkCLCore MitkCommandLine ${dependencies_list} - PACKAGE_DEPENDS Qt5|Core Vigra VTK|IOImage + PACKAGE_DEPENDS Qt5|Core Vigra VTK|IOImage ITK|Smoothing CPP_FILES ${appname}.cpp ) if(EXECUTABLE_IS_ENABLED) # On Linux, create a shell script to start a relocatable application if(UNIX AND NOT APPLE) install(PROGRAMS "${MITK_SOURCE_DIR}/CMake/RunInstalledApp.sh" DESTINATION "." RENAME ${EXECUTABLE_TARGET}.sh) endif() get_target_property(_is_bundle ${EXECUTABLE_TARGET} MACOSX_BUNDLE) if(APPLE) if(_is_bundle) set(_target_locations ${EXECUTABLE_TARGET}.app) set(${_target_locations}_qt_plugins_install_dir ${EXECUTABLE_TARGET}.app/Contents/MacOS) set(_bundle_dest_dir ${EXECUTABLE_TARGET}.app/Contents/MacOS) set(_qt_plugins_for_current_bundle ${EXECUTABLE_TARGET}.app/Contents/MacOS) set(_qt_conf_install_dirs ${EXECUTABLE_TARGET}.app/Contents/Resources) install(TARGETS ${EXECUTABLE_TARGET} BUNDLE DESTINATION . ) else() if(NOT MACOSX_BUNDLE_NAMES) set(_qt_conf_install_dirs bin) set(_target_locations bin/${EXECUTABLE_TARGET}) set(${_target_locations}_qt_plugins_install_dir bin) install(TARGETS ${EXECUTABLE_TARGET} RUNTIME DESTINATION bin) else() foreach(bundle_name ${MACOSX_BUNDLE_NAMES}) list(APPEND _qt_conf_install_dirs ${bundle_name}.app/Contents/Resources) set(_current_target_location ${bundle_name}.app/Contents/MacOS/${EXECUTABLE_TARGET}) list(APPEND _target_locations ${_current_target_location}) set(${_current_target_location}_qt_plugins_install_dir ${bundle_name}.app/Contents/MacOS) message( " set(${_current_target_location}_qt_plugins_install_dir ${bundle_name}.app/Contents/MacOS) ") install(TARGETS ${EXECUTABLE_TARGET} RUNTIME DESTINATION ${bundle_name}.app/Contents/MacOS/) endforeach() endif() endif() else() set(_target_locations bin/${EXECUTABLE_TARGET}${CMAKE_EXECUTABLE_SUFFIX}) set(${_target_locations}_qt_plugins_install_dir bin) set(_qt_conf_install_dirs bin) install(TARGETS ${EXECUTABLE_TARGET} RUNTIME DESTINATION bin) endif() endif() endforeach() mitk_create_executable(CLMatchPointReg DEPENDS MitkCore MitkCLUtilities MitkMatchPointRegistration MitkCommandLine MitkMatchPointRegistrationUI PACKAGE_DEPENDS Qt5|Core Vigra MatchPoint CPP_FILES CLMatchPointReg.cpp ) # On Linux, create a shell script to start a relocatable application if(UNIX AND NOT APPLE) install(PROGRAMS "${MITK_SOURCE_DIR}/CMake/RunInstalledApp.sh" DESTINATION "." RENAME ${EXECUTABLE_TARGET}.sh) endif() if(EXECUTABLE_IS_ENABLED) MITK_INSTALL_TARGETS(EXECUTABLES ${EXECUTABLE_TARGET}) endif() endif() diff --git a/Modules/Classification/CLUtilities/include/itkEnhancedScalarImageToRunLengthMatrixFilter.hxx b/Modules/Classification/CLUtilities/include/itkEnhancedScalarImageToRunLengthMatrixFilter.hxx index 7057b02697..8775a8aef6 100644 --- a/Modules/Classification/CLUtilities/include/itkEnhancedScalarImageToRunLengthMatrixFilter.hxx +++ b/Modules/Classification/CLUtilities/include/itkEnhancedScalarImageToRunLengthMatrixFilter.hxx @@ -1,425 +1,411 @@ /*============================================================================ 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. ============================================================================*/ /*========================================================================= * * Copyright Insight Software Consortium * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0.txt * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * *=========================================================================*/ #ifndef __itkEnhancedScalarImageToRunLengthMatrixFilter_hxx #define __itkEnhancedScalarImageToRunLengthMatrixFilter_hxx #include "itkEnhancedScalarImageToRunLengthMatrixFilter.h" #include "itkConstNeighborhoodIterator.h" #include "itkNeighborhood.h" #include "vnl/vnl_math.h" #include "itkMacro.h" namespace itk { namespace Statistics { template EnhancedScalarImageToRunLengthMatrixFilter ::EnhancedScalarImageToRunLengthMatrixFilter() : m_NumberOfBinsPerAxis( itkGetStaticConstMacro( DefaultBinsPerAxis ) ), m_Min( NumericTraits::NonpositiveMin() ), m_Max( NumericTraits::max() ), m_MinDistance( NumericTraits::ZeroValue() ), m_MaxDistance( NumericTraits::max() ), m_InsidePixelValue( NumericTraits::OneValue() ) { this->SetNumberOfRequiredInputs( 1 ); this->SetNumberOfRequiredOutputs( 1 ); const unsigned int measurementVectorSize = 2; this->ProcessObject::SetNthOutput( 0, this->MakeOutput( 0 ) ); HistogramType *output = const_cast( this->GetOutput() ); output->SetMeasurementVectorSize( measurementVectorSize ); this->m_LowerBound.SetSize( measurementVectorSize ); this->m_UpperBound.SetSize( measurementVectorSize ); this->m_LowerBound[0] = this->m_Min; this->m_LowerBound[1] = this->m_MinDistance; this->m_UpperBound[0] = this->m_Max; this->m_UpperBound[1] = this->m_MaxDistance; } template void EnhancedScalarImageToRunLengthMatrixFilter ::SetOffset( const OffsetType offset ) { OffsetVectorPointer offsetVector = OffsetVector::New(); offsetVector->push_back( offset ); this->SetOffsets( offsetVector ); } template void EnhancedScalarImageToRunLengthMatrixFilter ::SetInput( const ImageType *image ) { // Process object is not const-correct so the const_cast is required here this->ProcessObject::SetNthInput( 0, const_cast( image ) ); } template void EnhancedScalarImageToRunLengthMatrixFilter ::SetMaskImage( const ImageType *image ) { // Process object is not const-correct so the const_cast is required here this->ProcessObject::SetNthInput( 1, const_cast( image ) ); } template const TImageType * EnhancedScalarImageToRunLengthMatrixFilter ::GetInput() const { if( this->GetNumberOfInputs() < 1 ) { return ITK_NULLPTR; } return static_cast( this->ProcessObject::GetInput( 0 ) ); } template const TImageType * EnhancedScalarImageToRunLengthMatrixFilter ::GetMaskImage() const { if( this->GetNumberOfInputs() < 2 ) { return ITK_NULLPTR; } return static_cast( this->ProcessObject::GetInput( 1 ) ); } template const typename EnhancedScalarImageToRunLengthMatrixFilter::HistogramType * EnhancedScalarImageToRunLengthMatrixFilter ::GetOutput() const { const HistogramType *output = static_cast( this->ProcessObject::GetOutput( 0 ) ); return output; } template typename EnhancedScalarImageToRunLengthMatrixFilter::DataObjectPointer EnhancedScalarImageToRunLengthMatrixFilter ::MakeOutput( DataObjectPointerArraySizeType itkNotUsed( idx ) ) { return HistogramType::New().GetPointer(); } template void EnhancedScalarImageToRunLengthMatrixFilter ::GenerateData() { HistogramType *output = static_cast( this->ProcessObject::GetOutput( 0 ) ); const ImageType * inputImage = this->GetInput(); // First, create an appropriate histogram with the right number of bins // and mins and maxes correct for the image type. typename HistogramType::SizeType size( output->GetMeasurementVectorSize() ); size.Fill( this->m_NumberOfBinsPerAxis ); this->m_LowerBound[0] = this->m_Min; this->m_LowerBound[1] = this->m_MinDistance; this->m_UpperBound[0] = this->m_Max; this->m_UpperBound[1] = this->m_MaxDistance; output->Initialize( size, this->m_LowerBound, this->m_UpperBound ); MeasurementVectorType run( output->GetMeasurementVectorSize() ); typename HistogramType::IndexType hIndex; // Iterate over all of those pixels and offsets, adding each // distance/intensity pair to the histogram typedef ConstNeighborhoodIterator NeighborhoodIteratorType; typename NeighborhoodIteratorType::RadiusType radius; radius.Fill( 1 ); NeighborhoodIteratorType neighborIt( radius, inputImage, inputImage->GetRequestedRegion() ); // this temp image has the same dimension for each offset // moving the allocation out of loop of offsets // while keeping FillBuffer with boolean false in each loop typedef Image BoolImageType; typename BoolImageType::Pointer alreadyVisitedImage = BoolImageType::New(); alreadyVisitedImage->CopyInformation( inputImage ); alreadyVisitedImage->SetRegions( inputImage->GetRequestedRegion() ); alreadyVisitedImage->Allocate(); typename OffsetVector::ConstIterator offsets; for( offsets = this->GetOffsets()->Begin(); offsets != this->GetOffsets()->End(); offsets++ ) { alreadyVisitedImage->FillBuffer( false ); neighborIt.GoToBegin(); OffsetType offset = offsets.Value(); this->NormalizeOffsetDirection(offset); for( neighborIt.GoToBegin(); !neighborIt.IsAtEnd(); ++neighborIt ) { const PixelType centerPixelIntensity = neighborIt.GetCenterPixel(); if (centerPixelIntensity != centerPixelIntensity) // Check for invalid values { continue; } IndexType centerIndex = neighborIt.GetIndex(); if( centerPixelIntensity < this->m_Min || centerPixelIntensity > this->m_Max || alreadyVisitedImage->GetPixel( centerIndex ) || ( this->GetMaskImage() && this->GetMaskImage()->GetPixel( centerIndex ) != this->m_InsidePixelValue ) ) { continue; // don't put a pixel in the histogram if the value // is out-of-bounds or is outside the mask. } itkDebugMacro("===> offset = " << offset << std::endl); MeasurementType centerBinMin = this->GetOutput()-> GetBinMinFromValue( 0, centerPixelIntensity ); MeasurementType centerBinMax = this->GetOutput()-> GetBinMaxFromValue( 0, centerPixelIntensity ); MeasurementType lastBinMax = this->GetOutput()-> GetDimensionMaxs( 0 )[ this->GetOutput()->GetSize( 0 ) - 1 ]; PixelType pixelIntensity( NumericTraits::ZeroValue() ); IndexType index; int steps = 0; index = centerIndex + offset; IndexType lastGoodIndex = centerIndex; bool runLengthSegmentAlreadyVisited = false; // Scan from the current pixel at index, following // the direction of offset. Run length is computed as the // length of continuous pixels whose pixel values are // in the same bin. while ( inputImage->GetRequestedRegion().IsInside(index) ) { pixelIntensity = inputImage->GetPixel(index); // For the same offset, each run length segment can // only be visited once if (alreadyVisitedImage->GetPixel( index ) ) { runLengthSegmentAlreadyVisited = true; break; } if (pixelIntensity != pixelIntensity) { break; } // Special attention paid to boundaries of bins. // For the last bin, // it is left close and right close (following the previous // gerrit patch). // For all // other bins, // the bin is left close and right open. if ( pixelIntensity >= centerBinMin && ( pixelIntensity < centerBinMax || ( pixelIntensity == centerBinMax && centerBinMax == lastBinMax ) ) && (!this->GetMaskImage() || this->GetMaskImage()->GetPixel(index) == this->m_InsidePixelValue)) { alreadyVisitedImage->SetPixel( index, true ); lastGoodIndex = index; index += offset; steps++; } else { break; } } if ( runLengthSegmentAlreadyVisited ) { MITK_INFO << "Already visited 1 " << index; continue; } IndexType lastGoodIndex2 = lastGoodIndex; index = centerIndex - offset; lastGoodIndex = centerIndex; while ( inputImage->GetRequestedRegion().IsInside(index) ) { pixelIntensity = inputImage->GetPixel(index); if (pixelIntensity != pixelIntensity) { break; } if (alreadyVisitedImage->GetPixel( index ) ) { if (pixelIntensity >= centerBinMin && (pixelIntensity < centerBinMax || (pixelIntensity == centerBinMax && centerBinMax == lastBinMax))) { runLengthSegmentAlreadyVisited = true; } break; } if ( pixelIntensity >= centerBinMin && ( pixelIntensity < centerBinMax || ( pixelIntensity == centerBinMax && centerBinMax == lastBinMax ) ) && (!this->GetMaskImage() || this->GetMaskImage()->GetPixel(index) == this->m_InsidePixelValue)) { alreadyVisitedImage->SetPixel( index, true ); lastGoodIndex = index; steps++; index -= offset; } else break; } if (runLengthSegmentAlreadyVisited) { MITK_INFO << "Already visited 2 " << index; continue; } PointType centerPoint; inputImage->TransformIndexToPhysicalPoint( centerIndex, centerPoint ); PointType point; inputImage->TransformIndexToPhysicalPoint( lastGoodIndex, point ); PointType point2; inputImage->TransformIndexToPhysicalPoint( lastGoodIndex2, point2 ); run[0] = centerPixelIntensity; run[1] = steps; //run[1] = point.EuclideanDistanceTo( point2 ); if( run[1] >= this->m_MinDistance && run[1] <= this->m_MaxDistance ) { output->GetIndex( run, hIndex ); output->IncreaseFrequencyOfIndex( hIndex, 1 ); - - itkDebugStatement(typename HistogramType::IndexType tempMeasurementIndex;) - itkDebugStatement(output->GetIndex(run,tempMeasurementIndex);) - itkDebugMacro( "centerIndex<->index: " - << static_cast( centerPixelIntensity ) - << "@"<< centerIndex - << "<->" << static_cast( pixelIntensity ) << "@" << index - <<", Bin# " << tempMeasurementIndex - << ", Measurement: (" << run[0] << ", " << run[1] << ")" - << ", Center bin [" << this->GetOutput()->GetBinMinFromValue( 0, run[0] ) - << "," << this->GetOutput()->GetBinMaxFromValue( 0, run[0] ) << "]" - << "~[" << this->GetOutput()->GetBinMinFromValue( 1, run[1] ) - << "," << this->GetOutput()->GetBinMaxFromValue( 1, run[1] ) << "]" - << std::endl ); } } } } template void EnhancedScalarImageToRunLengthMatrixFilter ::SetPixelValueMinMax( PixelType min, PixelType max ) { if( this->m_Min != min || this->m_Max != max ) { itkDebugMacro( "setting Min to " << min << "and Max to " << max ); this->m_Min = min; this->m_Max = max; this->Modified(); } } template void EnhancedScalarImageToRunLengthMatrixFilter ::SetDistanceValueMinMax( RealType min, RealType max ) { if( this->m_MinDistance != min || this->m_MaxDistance != max ) { itkDebugMacro( "setting MinDistance to " << min << "and MaxDistance to " << max ); this->m_MinDistance = min; this->m_MaxDistance = max; this->Modified(); } } template void EnhancedScalarImageToRunLengthMatrixFilter ::PrintSelf( std::ostream& os, Indent indent ) const { Superclass::PrintSelf( os,indent ); os << indent << "Offsets: " << this->GetOffsets() << std::endl; os << indent << "Min: " << this->m_Min << std::endl; os << indent << "Max: " << this->m_Max << std::endl; os << indent << "Min distance: " << this->m_MinDistance << std::endl; os << indent << "Max distance: " << this->m_MaxDistance << std::endl; os << indent << "NumberOfBinsPerAxis: " << this->m_NumberOfBinsPerAxis << std::endl; os << indent << "InsidePixelValue: " << this->m_InsidePixelValue << std::endl; } template void EnhancedScalarImageToRunLengthMatrixFilter ::NormalizeOffsetDirection(OffsetType &offset) { itkDebugMacro("old offset = " << offset << std::endl); int sign = 1; bool metLastNonZero = false; for (int i = offset.GetOffsetDimension()-1; i>=0; i--) { if (metLastNonZero) { offset[i] *= sign; } else if (offset[i] != 0) { sign = (offset[i] > 0 ) ? 1 : -1; metLastNonZero = true; offset[i] *= sign; } } itkDebugMacro("new offset = " << offset << std::endl); } } // end of namespace Statistics } // end of namespace itk #endif diff --git a/Modules/IGT/Testing/mitkTrackingDeviceTest.cpp b/Modules/IGT/Testing/mitkTrackingDeviceTest.cpp index 0a12699607..08ba485949 100644 --- a/Modules/IGT/Testing/mitkTrackingDeviceTest.cpp +++ b/Modules/IGT/Testing/mitkTrackingDeviceTest.cpp @@ -1,112 +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 "mitkTrackingDevice.h" #include "mitkTestingMacros.h" #include "mitkTrackingTool.h" #include "mitkTrackingTypes.h" #include "mitkCommon.h" #include #include #include #include #include #include #include #include "mitkTrackingDeviceTypeCollection.h" #include "mitkUnspecifiedTrackingTypeInformation.h" //All Tracking devices, which should be avaiable by default #include "mitkNDIAuroraTypeInformation.h" #include "mitkNDIPolarisTypeInformation.h" #include "mitkVirtualTrackerTypeInformation.h" #include "mitkMicronTrackerTypeInformation.h" #include "mitkNPOptitrackTrackingTypeInformation.h" #include "mitkOpenIGTLinkTypeInformation.h" /** * Create new class and derive it from TrackingDevice */ class TrackingDeviceTestClass : public mitk::TrackingDevice { public: mitkClassMacro(TrackingDeviceTestClass, mitk::TrackingDevice); itkFactorylessNewMacro(Self) itkCloneMacro(Self) bool OpenConnection() override{return true;}; bool CloseConnection() override{return true;}; - bool StartTracking() override{this->SetState(Tracking); this->m_TrackingFinishedMutex->Unlock(); return true;}; + bool StartTracking() override{this->SetState(Tracking); return true;}; mitk::TrackingTool* GetTool(unsigned int /*toolNumber*/) const override {return nullptr;}; unsigned int GetToolCount() const override {return 1;}; }; /** * This function is testing the Class TrackingDevice. For most tests we would need the MicronTracker hardware, so only a few * simple tests, which can run without the hardware are implemented yet (2009, January, 23rd). As soon as there is a working * concept to test the tracking classes which are very close to the hardware on all systems more tests are needed here. */ int mitkTrackingDeviceTest(int /* argc */, char* /*argv*/[]) { MITK_TEST_BEGIN("TrackingDevice"); mitk::TrackingDeviceTypeCollection deviceTypeCollection; deviceTypeCollection.RegisterTrackingDeviceType(new mitk::NDIAuroraTypeInformation()); deviceTypeCollection.RegisterAsMicroservice(); deviceTypeCollection.RegisterTrackingDeviceType(new mitk::VirtualTrackerTypeInformation()); deviceTypeCollection.RegisterTrackingDeviceType(new mitk::NDIPolarisTypeInformation()); deviceTypeCollection.RegisterTrackingDeviceType(new mitk::MicronTrackerTypeInformation()); // Test instantiation of TrackingDevice TrackingDeviceTestClass::Pointer trackingDeviceTestClass = TrackingDeviceTestClass::New(); MITK_TEST_CONDITION(trackingDeviceTestClass.IsNotNull(),"Test instatiation"); // Test method GetState() MITK_TEST_CONDITION(trackingDeviceTestClass->GetState()==mitk::TrackingDevice::Setup,"Mode should be initialized to SETUP"); // Test method SetType() MITK_TEST_CONDITION(trackingDeviceTestClass->GetType()==mitk::UnspecifiedTrackingTypeInformation::GetTrackingDeviceName(),"Type should be initialized to 'not specified'"); trackingDeviceTestClass->SetType(mitk::NDIAuroraTypeInformation::GetTrackingDeviceName()); MITK_TEST_CONDITION(trackingDeviceTestClass->GetType() == mitk::NDIAuroraTypeInformation::GetTrackingDeviceName(), "Type should be NDIAurora, as it has just been set"); trackingDeviceTestClass->SetType(mitk::NDIPolarisTypeInformation::GetTrackingDeviceName()); MITK_TEST_CONDITION(trackingDeviceTestClass->GetType() == mitk::NDIPolarisTypeInformation::GetTrackingDeviceName(), "Type should be NDIPolaris, as it has just been set"); trackingDeviceTestClass->SetType(mitk::MicronTrackerTypeInformation::GetTrackingDeviceName()); MITK_TEST_CONDITION(trackingDeviceTestClass->GetType() == mitk::MicronTrackerTypeInformation::GetTrackingDeviceName(), "Type should be ClaronMicron, as it has just been set"); trackingDeviceTestClass->SetType(mitk::VirtualTrackerTypeInformation::GetTrackingDeviceName()); MITK_TEST_CONDITION(trackingDeviceTestClass->GetType() == mitk::VirtualTrackerTypeInformation::GetTrackingDeviceName(), "Type should be VirtualTracker, as it has just been set"); // Test method StopTracking() trackingDeviceTestClass->StartTracking(); trackingDeviceTestClass->StopTracking(); MITK_TEST_CONDITION(trackingDeviceTestClass->GetState()== mitk::TrackingDevice::Ready,"Type should be NDIAurora, as it has just been set"); MITK_TEST_CONDITION(deviceTypeCollection.GetTrackingDeviceTypeInformation(mitk::VirtualTrackerTypeInformation::GetTrackingDeviceName())->GetTrackingDeviceName() == mitk::VirtualTrackerTypeInformation::GetTrackingDeviceName(), "Test GetTrackingDeviceTypeInformation"); MITK_TEST_CONDITION(deviceTypeCollection.GetTrackingDeviceTypeInformation(mitk::VirtualTrackerTypeInformation::GetTrackingDeviceName())->m_TrackingDeviceData[0].Model == "Virtual Tracker", "Test GetTrackingDeviceTypeInformation"); std::vector names = deviceTypeCollection.GetTrackingDeviceTypeNames(); MITK_TEST_CONDITION(names[0] == mitk::NDIAuroraTypeInformation::GetTrackingDeviceName(), "Test collection name list"); MITK_TEST_CONDITION(names[1] == mitk::VirtualTrackerTypeInformation::GetTrackingDeviceName(), "Test collection name list"); MITK_TEST_CONDITION(names[2] == mitk::NDIPolarisTypeInformation::GetTrackingDeviceName(), "Test collection name list"); MITK_TEST_CONDITION(names[3] == mitk::MicronTrackerTypeInformation::GetTrackingDeviceName(), "Test collection name list"); MITK_TEST_END(); } diff --git a/Modules/ImageStatistics/Testing/mitkImageStatisticsTextureAnalysisTest.cpp b/Modules/ImageStatistics/Testing/mitkImageStatisticsTextureAnalysisTest.cpp index 4b3ad225f1..f517de9074 100644 --- a/Modules/ImageStatistics/Testing/mitkImageStatisticsTextureAnalysisTest.cpp +++ b/Modules/ImageStatistics/Testing/mitkImageStatisticsTextureAnalysisTest.cpp @@ -1,230 +1,239 @@ /*============================================================================ 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 "mitkTestingMacros.h" #include "itkImage.h" -#include "mitkExtendedLabelStatisticsImageFilter.h" +#include "mitkLabelStatisticsImageFilter.h" #include "mitkStatisticsImageFilter.h" #include "mitkNumericConstants.h" /** \section Testing of Skewness and Kurtosis * This test class is for testing the added coefficients Skewness and Kurtosis * for the mitkExtendedLabelStatisticsImageFilter (Masked Images) and for the * mitkExtendedStatisticsImageFilter (Unmasked Images). Both filter will be tested * against two pictures. */ class mitkImageStatisticsTextureAnalysisTestClass { /** * \brief Explanation of the mitkImageStatisticsTextureAnalysisTestClass test class * * this test class produce test images and masking images with the method CreatingTestImageForDifferentLabelSize. * TestInstanceFortheMaskedStatisticsFilter and TestInstanceFortheUnmaskedStatisticsFilter are the two Instances * for the filters of masking and unmasking images. * TestofSkewnessAndKurtosisForMaskedImagesand TestofSkewnessAndKurtosisForUnmaskedImages are the correlated test * for the checking the values. */ public: - typedef itk::Image< int,3 >ImageType; + typedef itk::Image< mitk::Label::PixelType,3 >ImageType; typedef ImageType::Pointer PointerOfImage; - typedef itk::ExtendedLabelStatisticsImageFilter< ImageType, ImageType > LabelStatisticsFilterType; + typedef mitk::LabelStatisticsImageFilter< ImageType > LabelStatisticsFilterType; typedef LabelStatisticsFilterType::Pointer labelStatisticsFilterPointer; typedef mitk::StatisticsImageFilter< ImageType > StatisticsFilterType; typedef StatisticsFilterType::Pointer StatisticsFilterPointer; ImageType::Pointer CreatingTestImageForDifferentLabelSize( int factorOfDividingThePicture, int bufferValue, int labelValue) { ImageType::Pointer image = ImageType :: New(); ImageType::IndexType start; ImageType::SizeType size; start[0] = 0; start[1] = 0; start[2] = 0; size[0] = 100; size[1] = 100; size[2] = 100; ImageType:: RegionType region; region.SetSize( size ); region.SetIndex( start ); image->SetRegions(region); image->Allocate(); image->FillBuffer(bufferValue); for(unsigned int r = 0; r < 50; r++) { for(int c = 0; c < factorOfDividingThePicture; c++) { for(unsigned int l = 0; l < 100; l++) { ImageType::IndexType pixelIndex; pixelIndex[0] = r; pixelIndex[1] = c; pixelIndex[2] = l; image->SetPixel(pixelIndex, labelValue); } } } return image; } LabelStatisticsFilterType::Pointer TestInstanceFortheMaskedStatisticsFilter(ImageType::Pointer image, ImageType::Pointer maskImage) { LabelStatisticsFilterType::Pointer labelStatisticsFilter; labelStatisticsFilter = LabelStatisticsFilterType::New(); labelStatisticsFilter->SetInput( image ); - labelStatisticsFilter->UseHistogramsOn(); - labelStatisticsFilter->SetHistogramParameters( 20, -10, 10); + + std::unordered_map sizes; + sizes[1] = 20; + + std::unordered_map lowerBounds; + lowerBounds[1] = -10; + + std::unordered_map upperBounds; + upperBounds[1] = 10; + + labelStatisticsFilter->SetHistogramParameters(sizes, lowerBounds, upperBounds); labelStatisticsFilter->SetLabelInput( maskImage ); labelStatisticsFilter->Update(); return labelStatisticsFilter; } StatisticsFilterType::Pointer TestInstanceFortheUnmaskedStatisticsFilter(ImageType::Pointer image ) { StatisticsFilterType::Pointer StatisticsFilter; StatisticsFilter = StatisticsFilterType::New(); StatisticsFilter->SetInput( image ); StatisticsFilter->SetHistogramParameters( 20, -10, 10 ); StatisticsFilter->Update(); return StatisticsFilter; } //test for Skewness,Kurtosis and MPP for masked Images void TestofSkewnessKurtosisAndMPPForMaskedImages(LabelStatisticsFilterType::Pointer labelStatisticsFilter, double expectedSkewness, double expectedKurtosis, double expectedMPP) { // let's create an object of our class bool isSkewsnessLowerlimitCorrect = labelStatisticsFilter->GetSkewness( 1 )- expectedKurtosis+ std::pow(10,-3) <= expectedSkewness; bool isSkewsnessUpperlimitCorrect = labelStatisticsFilter->GetSkewness( 1 )+ expectedKurtosis+ std::pow(10,-3) >= expectedSkewness; MITK_TEST_CONDITION( isSkewsnessLowerlimitCorrect && isSkewsnessUpperlimitCorrect,"expectedSkewness: " << expectedSkewness << " actual Value: " << labelStatisticsFilter->GetSkewness( 1 ) ); bool isKurtosisUpperlimitCorrect = labelStatisticsFilter->GetKurtosis( 1 ) <= expectedKurtosis+ std::pow(10,-3); bool isKurtosisLowerlimitCorrect = expectedKurtosis- std::pow(10,-3) <= labelStatisticsFilter->GetKurtosis( 1 ); MITK_TEST_CONDITION( isKurtosisUpperlimitCorrect && isKurtosisLowerlimitCorrect,"expectedKurtosis: " << expectedKurtosis << " actual Value: " << labelStatisticsFilter->GetKurtosis( 1 ) ); MITK_TEST_CONDITION( ( expectedMPP - labelStatisticsFilter->GetMPP( 1 ) ) < 1, "expected MPP: " << expectedMPP << " actual Value: " << labelStatisticsFilter->GetMPP( 1 ) ); } //test for Entropy,Uniformity and UPP for masked Images void TestofEntropyUniformityAndUppForMaskedImages(LabelStatisticsFilterType::Pointer labelStatisticsFilter, double expectedEntropy, double expectedUniformity, double expectedUPP) { bool calculatedEntropyLowerLimit = labelStatisticsFilter->GetEntropy( 1 ) >= expectedEntropy - std::pow(10,-3); bool calculatedUniformityLowerLimit = labelStatisticsFilter->GetUniformity( 1 ) >= expectedUniformity - std::pow(10,-3); bool calculatedUppLowerLimit = labelStatisticsFilter->GetUPP( 1 ) >= expectedUPP - std::pow(10,-3); bool calculatedEntropyUpperLimit = labelStatisticsFilter->GetEntropy( 1 ) <= expectedEntropy + std::pow(10,-3); bool calculatedUniformityUpperLimit = labelStatisticsFilter->GetUniformity( 1 ) <= expectedUniformity + std::pow(10,-3); bool calculatedUppUpperLimit = labelStatisticsFilter->GetUPP( 1 ) <= expectedUPP + std::pow(10,-3); MITK_TEST_CONDITION( calculatedEntropyLowerLimit && calculatedEntropyUpperLimit, "expected Entropy: " << expectedEntropy << " actual Value: " << labelStatisticsFilter->GetEntropy( 1 ) ); MITK_TEST_CONDITION( calculatedUniformityLowerLimit && calculatedUniformityUpperLimit, "expected Uniformity: " << expectedUniformity << " actual Value: " << labelStatisticsFilter->GetUniformity( 1 ) ); MITK_TEST_CONDITION( calculatedUppLowerLimit && calculatedUppUpperLimit, "expected UPP: " << expectedUPP << " actual Value: " << labelStatisticsFilter->GetUPP( 1 ) ); } //test for Skewness,Kurtosis and MPP for unmasked Images void TestofSkewnessKurtosisAndMPPForUnmaskedImages(StatisticsFilterType::Pointer StatisticsFilter, double expectedSkewness, double expectedKurtosis, double expectedMPP) { // let's create an object of our class bool isSkewsnessLowerlimitCorrect = StatisticsFilter->GetSkewness()- expectedKurtosis+ std::pow(10,-3) <= expectedSkewness; bool isSkewsnessUpperlimitCorrect = StatisticsFilter->GetSkewness()+ expectedKurtosis+ std::pow(10,-3) >= expectedSkewness; MITK_TEST_CONDITION( isSkewsnessLowerlimitCorrect && isSkewsnessUpperlimitCorrect,"expectedSkewness: " << expectedSkewness << " actual Value: " << StatisticsFilter->GetSkewness() ); bool isKurtosisUpperlimitCorrect = StatisticsFilter->GetKurtosis() <= expectedKurtosis+ std::pow(10,-3); bool isKurtosisLowerlimitCorrect = expectedKurtosis- std::pow(10,-3) <= StatisticsFilter->GetKurtosis(); MITK_TEST_CONDITION( isKurtosisUpperlimitCorrect && isKurtosisLowerlimitCorrect,"expectedKurtosis: " << expectedKurtosis << " actual Value: " << StatisticsFilter->GetKurtosis() ); MITK_TEST_CONDITION( ( expectedMPP - StatisticsFilter->GetMPP() ) < mitk::eps, "expected MPP: " << expectedMPP << " actual Value: " << StatisticsFilter->GetMPP() ); } //test for Entropy,Uniformity and UPP for unmasked Images void TestofEntropyUniformityAndUppForUnmaskedImages(StatisticsFilterType::Pointer StatisticsFilter, double expectedEntropy, double expectedUniformity, double expectedUPP) { bool calculatedEntropyLowerLimit = StatisticsFilter->GetEntropy() >= expectedEntropy - std::pow(10,-3); bool calculatedUniformityLowerLimit = StatisticsFilter->GetUniformity() >= expectedUniformity - std::pow(10,-3); bool calculatedUppLowerLimit = StatisticsFilter->GetUPP() >= expectedUPP - std::pow(10,-3); bool calculatedEntropyUpperLimit = StatisticsFilter->GetEntropy() <= expectedEntropy + std::pow(10,-3); bool calculatedUniformityUpperLimit = StatisticsFilter->GetUniformity() <= expectedUniformity + std::pow(10,-3); bool calculatedUppUpperLimit = StatisticsFilter->GetUPP() <= expectedUPP + std::pow(10,-3); MITK_TEST_CONDITION( calculatedEntropyLowerLimit && calculatedEntropyUpperLimit, "expected Entropy: " << expectedEntropy << " actual Value: " << StatisticsFilter->GetEntropy() ); MITK_TEST_CONDITION( calculatedUniformityLowerLimit && calculatedUniformityUpperLimit, "expected Uniformity: " << expectedUniformity << " actual Value: " << StatisticsFilter->GetUniformity() ); MITK_TEST_CONDITION( calculatedUppLowerLimit && calculatedUppUpperLimit, "expected UPP: " << expectedUPP << " actual Value: " << StatisticsFilter->GetUPP() ); } }; int mitkImageStatisticsTextureAnalysisTest(int, char* []) { // always start with this! MITK_TEST_BEGIN("mitkImageStatisticsTextureAnalysisTest") mitkImageStatisticsTextureAnalysisTestClass testclassInstance; mitkImageStatisticsTextureAnalysisTestClass::PointerOfImage labelImage = testclassInstance.CreatingTestImageForDifferentLabelSize(100, 1, 1); mitkImageStatisticsTextureAnalysisTestClass::PointerOfImage image = testclassInstance.CreatingTestImageForDifferentLabelSize(100, 3, 2); mitkImageStatisticsTextureAnalysisTestClass::PointerOfImage image2 = testclassInstance.CreatingTestImageForDifferentLabelSize(50, 3, 2); //test for masked images mitkImageStatisticsTextureAnalysisTestClass::labelStatisticsFilterPointer mitkLabelFilter= testclassInstance.TestInstanceFortheMaskedStatisticsFilter( image,labelImage); testclassInstance.TestofSkewnessKurtosisAndMPPForMaskedImages(mitkLabelFilter, 0, 0.999998, 2.5); testclassInstance.TestofEntropyUniformityAndUppForMaskedImages(mitkLabelFilter, 1, 0.5, 0.5); mitkImageStatisticsTextureAnalysisTestClass::labelStatisticsFilterPointer mitkLabelFilter2= testclassInstance.TestInstanceFortheMaskedStatisticsFilter( image2,labelImage); testclassInstance.TestofSkewnessKurtosisAndMPPForMaskedImages(mitkLabelFilter2, -1.1547, 2.33333, 2.75); testclassInstance.TestofEntropyUniformityAndUppForMaskedImages(mitkLabelFilter2, 0.811278, 0.625, 0.625); //test for unmasked images mitkImageStatisticsTextureAnalysisTestClass::StatisticsFilterPointer mitkFilter= testclassInstance.TestInstanceFortheUnmaskedStatisticsFilter( image); testclassInstance.TestofSkewnessKurtosisAndMPPForUnmaskedImages(mitkFilter, 0, 0.999998, 2.5); testclassInstance.TestofEntropyUniformityAndUppForUnmaskedImages(mitkFilter, 1, 0.5, 0.5); mitkImageStatisticsTextureAnalysisTestClass::StatisticsFilterPointer mitkFilter2= testclassInstance.TestInstanceFortheUnmaskedStatisticsFilter( image2); testclassInstance.TestofSkewnessKurtosisAndMPPForUnmaskedImages(mitkFilter2, -1.1547, 2.33333, 2.75); testclassInstance.TestofEntropyUniformityAndUppForUnmaskedImages( mitkFilter2, 0.811278, 0.625, 0.625); MITK_TEST_END() } diff --git a/Modules/OpenCVVideoSupport/Testing/mitkOpenCVToMitkImageFilterTest.cpp b/Modules/OpenCVVideoSupport/Testing/mitkOpenCVToMitkImageFilterTest.cpp index 9ce7fa7591..7bab414242 100644 --- a/Modules/OpenCVVideoSupport/Testing/mitkOpenCVToMitkImageFilterTest.cpp +++ b/Modules/OpenCVVideoSupport/Testing/mitkOpenCVToMitkImageFilterTest.cpp @@ -1,231 +1,202 @@ /*============================================================================ 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. ============================================================================*/ // mitk includes #include "mitkOpenCVToMitkImageFilter.h" #include #include #include -#include #include #include #include #include +#include /** Documentation * * @brief Objects of this class can start an internal thread by calling the Start() method. * The thread is then updateing the tested object until the method Stop() is called. The class * can be used to test if a filter is thread-save by using multiple objects and let * them update simuntanously. */ class mitkTestOpenCVToMITKImageFilterThread : public itk::Object { public: mitkClassMacroItkParent(mitkTestOpenCVToMITKImageFilterThread, itk::Object); - mitkNewMacro1Param(mitkTestOpenCVToMITKImageFilterThread, itk::MultiThreader::Pointer); + itkNewMacro(mitkTestOpenCVToMITKImageFilterThread); int NumberOfMessages; protected: - mitkTestOpenCVToMITKImageFilterThread(itk::MultiThreader::Pointer MultiThreader) + mitkTestOpenCVToMITKImageFilterThread() { - ThreadID = -1; NumberOfMessages = 0; - m_MultiThreader = MultiThreader; - } bool ThreadRunning; - int ThreadID; + std::thread Thread; cv::Mat currentImage; mitk::OpenCVToMitkImageFilter::Pointer m_testedFilter; - itk::MultiThreader::Pointer m_MultiThreader; - void DoSomething() { while (ThreadRunning) { m_testedFilter->SetOpenCVMat(currentImage); m_testedFilter->Update(); mitk::Image::Pointer result; result = m_testedFilter->GetOutput(); - //std::cout << "Thread " << ThreadID << " Update Call" << std::endl; } } - static ITK_THREAD_RETURN_TYPE ThreadStartTracking(void* pInfoStruct) + void ThreadStartTracking() { - /* extract this pointer from Thread Info structure */ - struct itk::MultiThreader::ThreadInfoStruct * pInfo = (struct itk::MultiThreader::ThreadInfoStruct*)pInfoStruct; - if (pInfo == nullptr) - { - return ITK_THREAD_RETURN_VALUE; - } - if (pInfo->UserData == nullptr) - { - return ITK_THREAD_RETURN_VALUE; - } - mitkTestOpenCVToMITKImageFilterThread *thisthread = (mitkTestOpenCVToMITKImageFilterThread*)pInfo->UserData; - - if (thisthread != nullptr) - thisthread->DoSomething(); - - return ITK_THREAD_RETURN_VALUE; + this->DoSomething(); } public: - int Start() + void Start() { ThreadRunning = true; - this->ThreadID = m_MultiThreader->SpawnThread(this->ThreadStartTracking, this); - return ThreadID; + this->Thread = std::thread(&mitkTestOpenCVToMITKImageFilterThread::ThreadStartTracking, this); } void Stop() { ThreadRunning = false; + if (this->Thread.joinable()) + this->Thread.join(); } void setFilter(mitk::OpenCVToMitkImageFilter::Pointer testedFilter) { m_testedFilter = testedFilter; } void setImage(cv::Mat image) { currentImage = image; } }; class mitkOpenCVToMitkImageFilterTestSuite : public mitk::TestFixture { CPPUNIT_TEST_SUITE(mitkOpenCVToMitkImageFilterTestSuite); MITK_TEST(TestInitialization); MITK_TEST(TestThreadSafety); CPPUNIT_TEST_SUITE_END(); private: cv::Mat image1,image2,image3,image4,image5; mitk::OpenCVToMitkImageFilter::Pointer testFilter; public: void setUp() override { image1 = cv::imread(GetTestDataFilePath("NrrdWritingTestImage.jpg").c_str()); image2 = cv::imread(GetTestDataFilePath("Png2D-bw.png").c_str()); image3 = cv::imread(GetTestDataFilePath("OpenCV-Data/CroppedImage.png").c_str()); image4 = cv::imread(GetTestDataFilePath("OpenCV-Data/GrabCutMask.png").c_str()); image5 = cv::imread(GetTestDataFilePath("OpenCV-Data/GrabCutOutput.png").c_str()); testFilter = mitk::OpenCVToMitkImageFilter::New(); //change input testFilter->SetOpenCVMat(image1); } void tearDown() override { } void TestInitialization() { testFilter = mitk::OpenCVToMitkImageFilter::New(); MITK_TEST_OUTPUT(<<"Testing Initialization"); } void TestThreadSafety() { - std::vector threadIDs; - std::vector threads; - itk::MultiThreader::Pointer multiThreader = itk::MultiThreader::New(); MITK_TEST_OUTPUT(<< "Testing Thread Safety with 2 Threads"); //create two threads - mitkTestOpenCVToMITKImageFilterThread::Pointer newThread1 = mitkTestOpenCVToMITKImageFilterThread::New(multiThreader); + auto newThread1 = mitkTestOpenCVToMITKImageFilterThread::New(); newThread1->setFilter(testFilter); newThread1->setImage(image1); - threads.push_back(newThread1); - mitkTestOpenCVToMITKImageFilterThread::Pointer newThread2 = mitkTestOpenCVToMITKImageFilterThread::New(multiThreader); + auto newThread2 = mitkTestOpenCVToMITKImageFilterThread::New(); newThread2->setFilter(testFilter); newThread2->setImage(image1); - threads.push_back(newThread2); - //start both - unsigned int id1 = newThread1->Start(); - unsigned int id2 = newThread2->Start(); + newThread1->Start(); + newThread2->Start(); int delay = 1; - for (int i = 0; i < 10000; i++) + for (int i = 0; i < 100; i++) { //std::cout << "Run " << i << std::endl; //wait a bit itksys::SystemTools::Delay(delay); //change input newThread1->setImage(image2); newThread1->setImage(image3); //wait a bit itksys::SystemTools::Delay(delay); //change input newThread1->setImage(image4); newThread1->setImage(image5); //wait a bit itksys::SystemTools::Delay(delay); //change input newThread1->setImage(image2); newThread1->setImage(image2); //wait a bit itksys::SystemTools::Delay(delay); //change input newThread1->setImage(image3); newThread1->setImage(image3); //wait a bit itksys::SystemTools::Delay(delay); } //stop both threads newThread1->Stop(); newThread2->Stop(); - multiThreader->TerminateThread(id1); - multiThreader->TerminateThread(id2); - MITK_TEST_OUTPUT(<< "Testing Thread Safety with 2 Threads"); } private: }; MITK_TEST_SUITE_REGISTRATION(mitkOpenCVToMitkImageFilter)