diff --git a/Modules/ModelFit/files.cmake b/Modules/ModelFit/files.cmake index 40d7ada4fc..89d64451c4 100644 --- a/Modules/ModelFit/files.cmake +++ b/Modules/ModelFit/files.cmake @@ -1,76 +1,77 @@ file(GLOB_RECURSE H_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/include/*") set(CPP_FILES Common/mitkExtractTimeGrid.cpp Common/mitkTimeGridHelper.cpp Common/mitkMaskedDynamicImageStatisticsGenerator.cpp Common/mitkModelFitConstants.cpp Common/mitkModelFitParameter.cpp Common/mitkModelFitCmdAppsHelper.cpp Common/mitkParameterFitImageGeneratorBase.cpp Common/mitkPixelBasedParameterFitImageGenerator.cpp Common/mitkROIBasedParameterFitImageGenerator.cpp Common/mitkModelFitInfo.cpp Common/mitkModelFitStaticParameterMap.cpp Common/mitkModelGenerator.cpp Common/mitkModelFitUIDHelper.cpp Common/mitkModelFitResultHelper.cpp Common/mitkScalarListLookupTable.cpp Common/mitkScalarListLookupTableProperty.cpp Common/mitkScalarListLookupTablePropertySerializer.cpp Common/mitkIModelFitProvider.cpp Common/mitkModelFitParameterValueExtraction.cpp Common/mitkBinaryImageToLabelSetImageFilter.cpp Common/mitkFormulaParser.cpp Common/mitkFresnel.cpp Common/mitkModelFitPlotDataHelper.cpp Common/mitkModelSignalImageGenerator.cpp + Common/mitkDynamicImageGenerator.cpp Functors/mitkSimpleFunctorBase.cpp Functors/mitkSimpleFunctorPolicy.cpp Functors/mitkChiSquareFitCostFunction.cpp Functors/mitkReducedChiSquareFitCostFunction.cpp Functors/mitkConstraintCheckerBase.cpp Functors/mitkSimpleBarrierConstraintChecker.cpp Functors/mitkSquaredDifferencesFitCostFunction.cpp Functors/mitkSumOfSquaredDifferencesFitCostFunction.cpp Functors/mitkMVConstrainedCostFunctionDecorator.cpp Functors/mitkMVModelFitCostFunction.cpp Functors/mitkNormalizedSumOfSquaredDifferencesFitCostFunction.cpp Functors/mitkSVModelFitCostFunction.cpp Functors/mitkModelFitFunctorBase.cpp Functors/mitkLevenbergMarquardtModelFitFunctor.cpp Functors/mitkDummyModelFitFunctor.cpp Functors/mitkModelFitInfoSignalGenerationFunctor.cpp Functors/mitkIndexedValueFunctorPolicy.cpp Functors/mitkModelDataGenerationFunctor.cpp Models/mitkModelBase.cpp Models/mitkModelFactoryBase.cpp Models/mitkModelParameterizerBase.cpp Models/mitkLinearModel.cpp Models/mitkLinearModelFactory.cpp Models/mitkInitialParameterizationDelegateBase.cpp Models/mitkImageBasedParameterizationDelegate.cpp Models/mitkGenericParamModel.cpp Models/mitkGenericParamModelFactory.cpp Models/mitkGenericParamModelParameterizer.cpp Models/mitkValueBasedParameterizationDelegate.cpp Models/mitkT2DecayModel.cpp Models/mitkT2DecayModelFactory.cpp Models/mitkT2DecayModelParameterizer.cpp TestingHelper/mitkTestModel.cpp TestingHelper/mitkTestModelFactory.cpp ) set(TPP_FILES include/itkMultiOutputNaryFunctorImageFilter.tpp include/itkMaskedStatisticsImageFilter.hxx include/itkMaskedNaryStatisticsImageFilter.hxx include/mitkModelFitProviderBase.tpp ) set(HXX_FILES ) set(MOC_H_FILES ) diff --git a/Modules/ModelFit/include/mitkDynamicImageGenerator.h b/Modules/ModelFit/include/mitkDynamicImageGenerator.h new file mode 100644 index 0000000000..77f49e254d --- /dev/null +++ b/Modules/ModelFit/include/mitkDynamicImageGenerator.h @@ -0,0 +1,52 @@ +/*============================================================================ + +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 DYNAMICIMAGEGENERATOR_H +#define DYNAMICIMAGEGENERATOR_H + + +#include "mitkImageToImageFilter.h" + +#include "MitkModelFitExports.h" + +namespace mitk +{ + /** Filter that takes n inputs and fuse it to a dynamic image (with n time points).*/ + class MITKMODELFIT_EXPORT DynamicImageGenerationFilter : public ImageToImageFilter + { + public: + mitkClassMacro(DynamicImageGenerationFilter, ImageToImageFilter); + itkFactorylessNewMacro(DynamicImageGenerationFilter); + itkCloneMacro(Self); + + typedef std::vector TimeBoundsVectorType; + + itkGetConstMacro(TimeBounds, TimeBoundsVectorType); + void SetTimeBounds(const TimeBoundsVectorType &bounds); + + protected: + DynamicImageGenerationFilter(){}; + ~DynamicImageGenerationFilter() override{}; + + void GenerateInputRequestedRegion() override; + + void GenerateOutputInformation() override; + + void GenerateData() override; + + private: + TimeBoundsVectorType m_TimeBounds; + }; +} + + +#endif // MODELSIGNALIMAGEGENERATOR_H diff --git a/Modules/ModelFit/src/Common/mitkDynamicImageGenerator.cpp b/Modules/ModelFit/src/Common/mitkDynamicImageGenerator.cpp new file mode 100644 index 0000000000..eb14f56b0c --- /dev/null +++ b/Modules/ModelFit/src/Common/mitkDynamicImageGenerator.cpp @@ -0,0 +1,87 @@ +/*============================================================================ + +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 "mitkDynamicImageGenerator.h" + +#include + +#include "mitkArbitraryTimeGeometry.h" +#include "mitkImageReadAccessor.h" + +void mitk::DynamicImageGenerationFilter::SetTimeBounds(const TimeBoundsVectorType& timeBounds) +{ + m_TimeBounds = timeBounds; + this->Modified(); +} + +void mitk::DynamicImageGenerationFilter::GenerateInputRequestedRegion() +{ + Superclass::GenerateInputRequestedRegion(); + + mitk::Image* input = this->GetInput(); + + input->SetRequestedRegionToLargestPossibleRegion(); +} + +void mitk::DynamicImageGenerationFilter::GenerateOutputInformation() +{ + mitk::Image::ConstPointer input = this->GetInput(); + mitk::Image::Pointer output = this->GetOutput(); + + auto timeBounds = m_TimeBounds; + + if (timeBounds.empty()) + { + timeBounds.resize(this->GetNumberOfInputs() + 1); + std::iota(timeBounds.begin(), timeBounds.end(), 0.0); + } + else if(timeBounds.size() != this->GetNumberOfInputs() + 1) + { + mitkThrow() << "User defined time bounds does not match the number if inputs (" << this->GetNumberOfInputs() << "). Size of timebounds is " << timeBounds.size() << ", but it should be " << this->GetNumberOfInputs() + 1 << "."; + } + + auto timeGeo = mitk::ArbitraryTimeGeometry::New(); + timeGeo->ReserveSpaceForGeometries(this->GetNumberOfInputs()); + + for (DataObjectPointerArraySizeType pos = 0; pos < this->GetNumberOfInputs(); pos++) + { + timeGeo->AppendNewTimeStepClone(this->GetInput(pos)->GetGeometry(), timeBounds[pos], timeBounds[pos + 1]); + } + + output->Initialize(input->GetPixelType(), *timeGeo); + output->SetPropertyList(input->GetPropertyList()->Clone()); +} + + +void mitk::DynamicImageGenerationFilter::GenerateData() +{ + mitk::Image::Pointer output = this->GetOutput(); + mitk::Image::ConstPointer refInput = this->GetInput(); + + for (DataObjectPointerArraySizeType pos = 0; pos < this->GetNumberOfInputs(); pos++) + { + if (!Equal(*(refInput->GetGeometry()), *(this->GetInput(pos)->GetGeometry()), mitk::eps, false)) + { + mitkThrow() << "Cannot fuse images. At least image #" << pos << " has another geometry than the first image."; + } + if (refInput->GetPixelType() != this->GetInput(pos)->GetPixelType()) + { + mitkThrow() << "Cannot fuse images. At least image #" << pos << " has another pixeltype than the first image."; + } + } + + for (DataObjectPointerArraySizeType pos = 0; pos < this->GetNumberOfInputs(); pos++) + { + mitk::ImageReadAccessor accessor(this->GetInput(pos)); + output->SetVolume(accessor.GetData(), pos); + } +}