diff --git a/Code/Algorithms/Plastimatch/test/mapDummyPlastimatch.cpp b/Code/Algorithms/Plastimatch/test/mapDummyPlastimatch.cpp index 92c4db3..50e3df8 100644 --- a/Code/Algorithms/Plastimatch/test/mapDummyPlastimatch.cpp +++ b/Code/Algorithms/Plastimatch/test/mapDummyPlastimatch.cpp @@ -1,106 +1,114 @@ // ----------------------------------------------------------------------- // MatchPoint - DKFZ translational registration framework // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See mapCopyright.txt or // http://www.dkfz.de/en/sidt/projects/MatchPoint/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision$ (last changed revision) // @date $Date$ (last change date) // @author $Author$ (last changed by) // Subversion HeadURL: $HeadURL$ */ #include #include #include "itkImageFileWriter.h" #include "litTestImageIO.h" #include "mapString.h" #include "mapFileDispatch.h" #include "mapPlmAlgorithmHelper.h" #include "mapFieldByModelFunctor.h" #include "mapITKTranslationTransform.h" int main(int argc, char* argv[]) { std::cout << "MatchPoint Plastimatch testing dummy." << std::endl << "This is a mock up exe, used by MatchPoint to test its Plastimatch integration." << std::endl << std::endl; std::cout << "Passed command line arguments:" << std::endl; std::ofstream file; std::ios_base::openmode iOpenFlag = std::ios_base::out | std::ios_base::trunc; file.open("plastimatchDummyCall.log", iOpenFlag); for (int i = 0; i < argc; ++i) { std::cout << argv[i] << std::endl; file << argv[i] << std::endl; } file.close(); if (argc > 3) { std::cerr << "Error. No valid call. Illegal commandline parameter count."; return EXIT_FAILURE; } map::core::String configPath = argv[2]; - map::algorithm::plastimatch::ConfigurationType config = - map::algorithm::plastimatch::loadConfigurationFromFile(configPath); + map::algorithm::plastimatch::ConfigurationType config; + try + { + config = map::algorithm::plastimatch::loadConfigurationFromFile(configPath); + } + catch (const std::exception &e) + { + std::cerr << "Error. Cannot load config file. Details: " << e.what(); + return EXIT_FAILURE; + } if (config.size() < 2) { std::cerr << "Error. Invalid config file. Config file:" << configPath; return EXIT_FAILURE; } map::core::String outputPath = config[0]["vf_out"][0]; map::core::String targetPath = config[0]["fixed"][0]; //////////////////////////////////////// //generate a result field typedef map::core::functors::FieldByModelFunctor<3, 3> FunctorType; typedef itk::TranslationTransform TransformType; TransformType::Pointer spModel = TransformType::New().GetPointer(); TransformType::ParametersType params(3); params[0] = 10.0; params[1] = -16.0; params[2] = -5.0; spModel->SetParameters(params); //load target image for field descriptor typedef map::core::discrete::Elements<3>::InternalImageType ImageType; ImageType::Pointer spTargetImage = lit::TestImageIO::readImage(targetPath); FunctorType::InFieldRepresentationType::Pointer spInRep = map::core::createFieldRepresentation(* (spTargetImage.GetPointer())); ::map::core::RegistrationTopology<3,3>::DirectFieldPointer spField = ::map::core::generateFieldFromTransform<3, 3>(spModel, spInRep); typedef ::itk::ImageFileWriter< ::map::core::RegistrationTopology<3, 3>::DirectFieldType > FieldWriterType; FieldWriterType::Pointer spFieldWriter = FieldWriterType::New(); spFieldWriter->SetFileName(outputPath.c_str()); spFieldWriter->SetInput(spField); spFieldWriter->Update(); return EXIT_SUCCESS; } diff --git a/Code/Core/include/mapDimensionlessRegistrationKernelBase.h b/Code/Core/include/mapDimensionlessRegistrationKernelBase.h index db3c174..d7a9f03 100644 --- a/Code/Core/include/mapDimensionlessRegistrationKernelBase.h +++ b/Code/Core/include/mapDimensionlessRegistrationKernelBase.h @@ -1,96 +1,96 @@ // ----------------------------------------------------------------------- // MatchPoint - DKFZ translational registration framework // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See mapCopyright.txt or // http://www.dkfz.de/en/sidt/projects/MatchPoint/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision$ (last changed revision) // @date $Date$ (last change date) // @author $Author$ (last changed by) // Subversion HeadURL: $HeadURL$ */ #ifndef __DIMENSIONLESS_REGISTRATION_KERNEL_INTERFACE_H #define __DIMENSIONLESS_REGISTRATION_KERNEL_INTERFACE_H #include "itkObject.h" #include "mapMAPCoreExports.h" #include "mapString.h" namespace map { namespace core { /*! @class DimensionlessRegistrationKernelBase This class is the dimensionless (thus abstract) base class for registration kernels. @ingroup RegKernel */ class MAPCore_EXPORT DimensionlessRegistrationKernelBase : public itk::Object { public: typedef DimensionlessRegistrationKernelBase Self; typedef itk::Object Superclass; typedef itk::SmartPointer Pointer; typedef itk::SmartPointer ConstPointer; itkTypeMacro(DimensionlessRegistrationKernelBase, itk::Object); /*! @brief determines if there is a limit in the data representation of the kernel @eguarantee strong @return if the registration kernel has limited representation @retval true if the data representation is limited @retval false if the data representation is not limited */ virtual bool hasLimitedRepresentation() const = 0; /*! @brief forces kernel to precompute, even if it is a LazyFieldKernel @eguarantee strong */ - virtual void precomputeKernel() = 0; + virtual void precomputeKernel() const = 0; /*! @brief Gets the number of input dimensions @eguarantee no fail */ virtual unsigned int getInputDimensions() const = 0; /*! @brief Gets the number of output dimensions @eguarantee no fail */ virtual unsigned int getOutputDimensions() const = 0; protected: /*! Methods invoked by itk::LightObject::Print(). */ virtual void PrintSelf(std::ostream& os, itk::Indent indent) const; DimensionlessRegistrationKernelBase(); virtual ~DimensionlessRegistrationKernelBase(); private: //No copy constructor allowed DimensionlessRegistrationKernelBase(const Self& source); void operator=(const Self&); //purposely not implemented }; std::ostream& operator<< (std::ostream& os, const DimensionlessRegistrationKernelBase& p); } } #endif diff --git a/Code/Core/include/mapNullRegistrationKernel.h b/Code/Core/include/mapNullRegistrationKernel.h index 83e0c4a..9822341 100644 --- a/Code/Core/include/mapNullRegistrationKernel.h +++ b/Code/Core/include/mapNullRegistrationKernel.h @@ -1,120 +1,120 @@ // ----------------------------------------------------------------------- // MatchPoint - DKFZ translational registration framework // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See mapCopyright.txt or // http://www.dkfz.de/en/sidt/projects/MatchPoint/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision$ (last changed revision) // @date $Date$ (last change date) // @author $Author$ (last changed by) // Subversion HeadURL: $HeadURL$ */ #ifndef __NULL_REGISTRATION_KERNEL_BASE_H #define __NULL_REGISTRATION_KERNEL_BASE_H #include "mapRegistrationKernelBase.h" namespace map { namespace core { /*! @class NullRegistrationKernel This class defines null kernels. This type of kernel should be used by registration algorithms, if there is no valid registration kernel (yet) for a mapping direction. Thus it is the "official" and explicit way to define, that a mapping direction (and its kernel) is undefined and not valid. (It is analog to the meaning of NULL pointer). Any attempt to use this kernel for mapping purposes will fail. The precompution of the kernel will raise an exception. Combination of a NullRegistrationKernel with a kernel of any other type will result in NullRegistrationKernel. The inversion of a NullRegistrationKernel is a NullRegistrationKernel @ingroup RegKernel */ template class NullRegistrationKernel : public RegistrationKernelBase { public: typedef NullRegistrationKernel Self; typedef RegistrationKernelBase Superclass; typedef itk::SmartPointer Pointer; typedef itk::SmartPointer ConstPointer; itkTypeMacro(NullRegistrationKernel, RegistrationKernelBase); itkNewMacro(Self); typedef typename Superclass::InputPointType InputPointType; typedef typename Superclass::OutputPointType OutputPointType; typedef typename Superclass::RepresentationDescriptorConstPointer RepresentationDescriptorConstPointer; /*! @brief gets the largest possible representation descriptor. The descriptor defines * the space the kernel guarantees to map. * @return Smart pointer to the descriptor (may be generated dynamicaly) * @retval NULL there is no descriptor. If hasLimitedRepresentation returns false, the kernel * has no mapping limitations and covers the total input space. @eguarantee strong */ virtual RepresentationDescriptorConstPointer getLargestPossibleRepresentation() const; /*! @brief forces kernel to precompute, even if it is a LazyFieldKernel @eguarantee strong */ - virtual void precomputeKernel() override; + virtual void precomputeKernel() const override; protected: /*! Methods invoked by itk::LightObject::Print(). */ virtual void PrintSelf(std::ostream& os, itk::Indent indent) const; /*! Maps the point from input to output space. Is used by mapPoint() * It will always return false because a NullRegistrationKernel cannot map * any points * @eguarantee strong */ virtual bool doMapPoint(const InputPointType& inPoint, OutputPointType& outPoint) const; NullRegistrationKernel(); virtual ~NullRegistrationKernel(); /** @reimplementation Reimplementation of the itk::LightObject::InternalClone*/ virtual ::itk::LightObject::Pointer InternalClone() const; private: //No copy constructor allowed NullRegistrationKernel(const Self& source); void operator=(const Self&); //purposely not implemented }; template std::ostream& operator<< (std::ostream& os, const NullRegistrationKernel& p) { p.Print(os); return os; } } } #ifndef MatchPoint_MANUAL_TPP #include "mapNullRegistrationKernel.tpp" #endif #endif diff --git a/Code/Core/include/mapNullRegistrationKernel.tpp b/Code/Core/include/mapNullRegistrationKernel.tpp index 13f6238..7e82fee 100644 --- a/Code/Core/include/mapNullRegistrationKernel.tpp +++ b/Code/Core/include/mapNullRegistrationKernel.tpp @@ -1,92 +1,92 @@ // ----------------------------------------------------------------------- // MatchPoint - DKFZ translational registration framework // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See mapCopyright.txt or // http://www.dkfz.de/en/sidt/projects/MatchPoint/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision$ (last changed revision) // @date $Date$ (last change date) // @author $Author$ (last changed by) // Subversion HeadURL: $HeadURL$ */ #ifndef __NULL_REGISTRATION_KERNEL_TPP #define __NULL_REGISTRATION_KERNEL_TPP #include "mapExceptionObjectMacros.h" namespace map { namespace core { template typename NullRegistrationKernel::RepresentationDescriptorConstPointer NullRegistrationKernel:: getLargestPossibleRepresentation() const { RepresentationDescriptorConstPointer spRep = NULL; return spRep; }; template void NullRegistrationKernel:: - precomputeKernel() + precomputeKernel() const { mapDefaultExceptionMacro( << "Error. Cannot precompute kernel/field. NullRegistrationKernel is not a valid Kernel and cannot be precomputed."); }; template NullRegistrationKernel:: NullRegistrationKernel() { }; template NullRegistrationKernel:: ~NullRegistrationKernel() { }; template bool NullRegistrationKernel:: doMapPoint(const InputPointType& inPoint, OutputPointType& outPoint) const { return false; }; template void NullRegistrationKernel:: PrintSelf(std::ostream& os, itk::Indent indent) const { Superclass::PrintSelf(os, indent); }; template ::itk::LightObject::Pointer NullRegistrationKernel:: InternalClone() const { Pointer clone = Self::New(); return clone.GetPointer(); } } // end namespace core } // end namespace map #endif diff --git a/Code/Core/include/mapRegistrationKernel.h b/Code/Core/include/mapRegistrationKernel.h index 0e05a01..c990bb9 100644 --- a/Code/Core/include/mapRegistrationKernel.h +++ b/Code/Core/include/mapRegistrationKernel.h @@ -1,134 +1,134 @@ // ----------------------------------------------------------------------- // MatchPoint - DKFZ translational registration framework // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See mapCopyright.txt or // http://www.dkfz.de/en/sidt/projects/MatchPoint/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision$ (last changed revision) // @date $Date$ (last change date) // @author $Author$ (last changed by) // Subversion HeadURL: $HeadURL$ */ #ifndef __REGISTRATION_KERNEL_H #define __REGISTRATION_KERNEL_H #include "mapRegistrationKernelBase.h" /*! @namespace map The namespace map::core is for the library of MatchPoint */ namespace map { namespace core { /*! RegistrationKernel implementation. * This class is the base class for concrete implemented registration kernels, * that define the mapping via a itk transformation model. * The concrete transform management behavior will be implemented by derived classes. * @ingroup RegKernel */ template class RegistrationKernel : public RegistrationKernelBase < VInputDimensions, VOutputDimensions > { public: typedef RegistrationKernel < VInputDimensions, VOutputDimensions > Self; typedef RegistrationKernelBase Superclass; typedef itk::SmartPointer Pointer; typedef itk::SmartPointer ConstPointer; itkTypeMacro(RegistrationKernel, RegistrationKernelBase); itkCloneMacro(Self); typedef typename Superclass::TransformType TransformType; typedef typename Superclass::RepresentationDescriptorType RepresentationDescriptorType; typedef typename Superclass::RepresentationDescriptorPointer RepresentationDescriptorPointer; typedef typename Superclass::RepresentationDescriptorConstPointer RepresentationDescriptorConstPointer; typedef typename Superclass::InputPointType InputPointType; typedef typename Superclass::OutputPointType OutputPointType; typedef typename Superclass::OutputVectorType OutputVectorType; /*! Returns pointer to the transform model used by the kernel @eguarantee strong @return const pointer to the internal tranform model */ virtual const TransformType* getTransformModel() const = 0; /*! @brief forces kernel to precompute, even if it is a LazyFieldKernel @eguarantee strong */ - virtual void precomputeKernel() override; + virtual void precomputeKernel() const override; /*! Returns if the transform was already created or if the generation still is pending / wasn't necessary. @eguarantee strong */ virtual bool transformExists() const = 0; /*! gets the name of the model @eguarantee strong @return an String containing the model name */ virtual String getModelName() const; typedef itk::Matrix MatrixType; /*! Tries to decompose the transform model into an affine matrix and an offset. It is indecated by the return value if * the actual modell can be decomposed.\n * Usage of the return values: Point_trans = Matrix*Point + Offset * * @eguarantee strong * @remark Implement the function for special transform model classes. * @param [out] matrix Reference to the matrix that define the affine non-translation part (e.g. rotation and scaling). * @param [out] offset Reference to a vector that defines the translation offset. * @return Indicates if the transform model can be decomposed in a affine transformation matrix plus offset. If it returns false, it cannot be decomposed * and the referenced output parameters are invalid.*/ virtual bool getAffineMatrixDecomposition(MatrixType& matrix, OutputVectorType& offset) const; virtual const OutputPointType getNullPoint() const = 0; virtual bool usesNullPoint() const = 0; protected: RegistrationKernel(); virtual ~RegistrationKernel(); virtual bool doMapPoint(const InputPointType& inPoint, OutputPointType& outPoint) const override; /*! checks the transform that has been set for correctness and prepares it to be used @eguarantee strong @return the success of the operation */ virtual bool checkAndPrepareTransform() const = 0; /*! Methods invoked by itk::LightObject::Print(). */ virtual void PrintSelf(std::ostream& os, itk::Indent indent) const override; private: //No copy constructor allowed RegistrationKernel(const Self& source); void operator=(const Self&); //purposely not implemented }; } } #ifndef MatchPoint_MANUAL_TPP #include "mapRegistrationKernel.tpp" #endif #endif diff --git a/Code/Core/include/mapRegistrationKernel.tpp b/Code/Core/include/mapRegistrationKernel.tpp index 6e66258..ac0df94 100644 --- a/Code/Core/include/mapRegistrationKernel.tpp +++ b/Code/Core/include/mapRegistrationKernel.tpp @@ -1,121 +1,121 @@ // ----------------------------------------------------------------------- // MatchPoint - DKFZ translational registration framework // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See mapCopyright.txt or // http://www.dkfz.de/en/sidt/projects/MatchPoint/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision$ (last changed revision) // @date $Date$ (last change date) // @author $Author$ (last changed by) // Subversion HeadURL: $HeadURL$ */ #ifndef __REGISTRATION_KERNEL_TPP #define __REGISTRATION_KERNEL_TPP #include "mapExceptionObjectMacros.h" #include "mapPointVectorCombinationPolicy.h" #include "mapNULLVectorAwareLinearInterpolateImageFunction.h" #include "mapAffineMatrixOffsetDecompositionPolicy.h" #include "itkVectorLinearInterpolateImageFunction.h" namespace map { namespace core { template void RegistrationKernel:: - precomputeKernel() + precomputeKernel() const { if (! this->checkAndPrepareTransform()) { mapDefaultExceptionMacro( << "Error. Cannot precompute kernel/field."); } }; template String RegistrationKernel:: getModelName() const { if (this->transformExists()) { return this->getTransformModel()->GetNameOfClass(); } else { return "Unkown"; } }; template RegistrationKernel:: RegistrationKernel() { }; template RegistrationKernel:: ~RegistrationKernel() { }; template bool RegistrationKernel:: doMapPoint(const InputPointType& inPoint, OutputPointType& outPoint) const { if (!this->checkAndPrepareTransform()) { mapDefaultExceptionMacro( << "Error. Transform is not ready and cannot be prepared. Unable to map point."); } outPoint = this->getTransformModel()->TransformPoint(inPoint); bool result = !this->usesNullPoint() || this->getNullPoint() != outPoint; return result; }; template bool RegistrationKernel::getAffineMatrixDecomposition(MatrixType& matrix, OutputVectorType& offset) const { if (this->transformExists()) { return AffineMatrixOffsetDecompositionPolicy::getAffineMatrixDecomposition(this->getTransformModel(), matrix, offset); } return false; }; template void RegistrationKernel:: PrintSelf(std::ostream& os, itk::Indent indent) const { Superclass::PrintSelf(os, indent); }; } // end namespace core } // end namespace map #endif diff --git a/Code/Core/include/mapRegistrationKernelBase.h b/Code/Core/include/mapRegistrationKernelBase.h index f73f3a9..96b28e0 100644 --- a/Code/Core/include/mapRegistrationKernelBase.h +++ b/Code/Core/include/mapRegistrationKernelBase.h @@ -1,155 +1,155 @@ // ----------------------------------------------------------------------- // MatchPoint - DKFZ translational registration framework // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See mapCopyright.txt or // http://www.dkfz.de/en/sidt/projects/MatchPoint/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision$ (last changed revision) // @date $Date$ (last change date) // @author $Author$ (last changed by) // Subversion HeadURL: $HeadURL$ */ #ifndef __REGISTRATION_KERNEL_BASE_H #define __REGISTRATION_KERNEL_BASE_H #include "mapFieldRepresentationDescriptor.h" #include "mapDimensionlessRegistrationKernelBase.h" #include "mapRegistrationTopology.h" #include "itkObject.h" namespace map { namespace core { /*! @class RegistrationKernelBase This class is the base class for the registration kernels. @ingroup RegKernel */ template class RegistrationKernelBase : public DimensionlessRegistrationKernelBase { public: typedef RegistrationKernelBase Self; typedef DimensionlessRegistrationKernelBase Superclass; typedef itk::SmartPointer Pointer; typedef itk::SmartPointer ConstPointer; itkTypeMacro(RegistrationKernelBase, DimensionlessRegistrationKernelBase); itkCloneMacro(Self); itkStaticConstMacro(InputDimensions, unsigned int, VInputDimensions); itkStaticConstMacro(OutputDimensions, unsigned int, VOutputDimensions); typedef typename continuous::Elements::PointType InputPointType; typedef typename continuous::Elements::PointType OutputPointType; typedef typename RegistrationTopology::DirectMappingVectorType MappingVectorType; typedef typename RegistrationTopology::DirectTransformType TransformType; typedef typename TransformType::OutputVectorType OutputVectorType; typedef FieldRepresentationDescriptor RepresentationDescriptorType; typedef typename RepresentationDescriptorType::Pointer RepresentationDescriptorPointer; typedef typename RepresentationDescriptorType::ConstPointer RepresentationDescriptorConstPointer; /*! maps a point as long as it is within the field representation of the kernel by calling doMapPoint() @param inPoint Point that should be mapped. @param outPoint Mapping result. If the input point cannot be mapped the return of the method will be false and outPoint will be zero. @eguarantee strong @return success of operation @retval true Point was mapped @retval false Point was not in the represented region of the kernel and thus not mapped. By default outPoint will then be zero. */ bool mapPoint(const InputPointType& inPoint, OutputPointType& outPoint) const; /*! @brief determines if there is a limit in the data representation of the kernel @eguarantee strong @return if the registration kernel has limited representation @retval true if the data representation is limited @retval false if the data representation is not limited */ bool hasLimitedRepresentation() const; /*! @brief gets the largest possible representation descriptor. The descriptor defines * the space the kernel guarantees to map. * @return Smart pointer to the descriptor (may be generated dynamically) * @retval NULL there is no descriptor. If hasLimitedRepresentation returns false, the kernel * has no mapping limitations and covers the total input space. @eguarantee strong */ virtual RepresentationDescriptorConstPointer getLargestPossibleRepresentation() const = 0; /*! @brief forces kernel to precompute, even if it is a LazyFieldKernel @eguarantee strong */ - virtual void precomputeKernel() = 0; + virtual void precomputeKernel() const = 0; /*! @brief Gets the number of input dimensions @eguarantee no fail */ virtual unsigned int getInputDimensions() const { return InputDimensions; }; /*! @brief Gets the number of output dimensions @eguarantee no fail */ virtual unsigned int getOutputDimensions() const { return OutputDimensions; }; protected: /*! Methods invoked by itk::LightObject::Print(). */ virtual void PrintSelf(std::ostream& os, itk::Indent indent) const; /*! Maps the point from input to output space. Is used by mapPoint() @eguarantee strong */ virtual bool doMapPoint(const InputPointType& inPoint, OutputPointType& outPoint) const = 0; RegistrationKernelBase(); virtual ~RegistrationKernelBase(); private: //No copy constructor allowed RegistrationKernelBase(const Self& source); void operator=(const Self&); //purposely not implemented }; template std::ostream& operator<< (std::ostream& os, const RegistrationKernelBase& p) { p.Print(os); return os; } } } #ifndef MatchPoint_MANUAL_TPP #include "mapRegistrationKernelBase.tpp" #endif #endif diff --git a/Code/Core/test/mapRegistrationTest.cpp b/Code/Core/test/mapRegistrationTest.cpp index f53f3b0..a9d3d6b 100644 --- a/Code/Core/test/mapRegistrationTest.cpp +++ b/Code/Core/test/mapRegistrationTest.cpp @@ -1,264 +1,264 @@ // ----------------------------------------------------------------------- // MatchPoint - DKFZ translational registration framework // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See mapCopyright.txt or // http://www.dkfz.de/en/sidt/projects/MatchPoint/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision$ (last changed revision) // @date $Date$ (last change date) // @author $Author$ (last changed by) // Subversion HeadURL: $HeadURL$ */ #if defined(_MSC_VER) #pragma warning ( disable : 4786 ) #endif #include "mapRegistration.h" #include "mapRegistrationManipulator.h" #include "litCheckMacros.h" #include "mapRegistrationKernelBase.h" #include namespace map { namespace testing { template class TestRegistrationKernel : public ::map::core::RegistrationKernelBase { public: typedef TestRegistrationKernel Self; typedef core::RegistrationKernelBase Superclass; typedef itk::SmartPointer Pointer; typedef itk::SmartPointer ConstPointer; typedef typename Superclass::InputPointType InputPointType; typedef typename Superclass::OutputPointType OutputPointType; typedef typename Superclass::RepresentationDescriptorConstPointer RepresentationDescriptorConstPointer; typedef typename Superclass::RepresentationDescriptorPointer RepresentationDescriptorPointer; itkTypeMacro(TestRegistrationKernel, RegistrationKernelBase); itkNewMacro(Self); virtual bool doMapPoint(const InputPointType& inPoint, OutputPointType& outPoint) const { //dummy mapping not important for this test level _hasMappedPoint = true; return true; }; virtual bool hasLimitedRepresentation() { return false; }; virtual RepresentationDescriptorConstPointer getLargestPossibleRepresentation() const { RepresentationDescriptorConstPointer _spDummy = _spFieldRepresentation.GetPointer(); return _spDummy; }; - virtual void precomputeKernel() + virtual void precomputeKernel() const override { _isPreComputed = true; }; - bool _isPreComputed; + mutable bool _isPreComputed; mutable bool _hasMappedPoint; RepresentationDescriptorPointer _spFieldRepresentation; protected: TestRegistrationKernel() { _isPreComputed = false; _hasMappedPoint = false; }; virtual ~TestRegistrationKernel() {}; private: //No copy constructor allowed TestRegistrationKernel(const Self& source); void operator=(const Self&); //purposely not implemented }; class TestRegistrationGenerator1 { public: typedef core::Registration<2, 2> Registration1Type; typedef core::RegistrationManipulator ManipulatorType; typedef Registration1Type::Pointer Registration1Pointer; typedef core::FieldRepresentationDescriptor<2> FRD2DType; typedef FRD2DType::Pointer FRD2DPointer; FRD2DPointer _spField2D; std::string _tag1; std::string _value1; TestRegistrationKernel<2, 2>::Pointer _spDirectKernel; TestRegistrationKernel<2, 2>::Pointer _spInverseKernel; Registration1Pointer generate() { Registration1Pointer spReg = Registration1Type::New(); ManipulatorType manip(spReg); manip.setDirectMapping(_spDirectKernel); manip.setInverseMapping(_spInverseKernel); ::map::core::RegistrationBase::TagMapType tags; std::pair taggedValue(_tag1, _value1); tags.insert(taggedValue); manip.setTagValues(tags); return spReg; }; TestRegistrationGenerator1() { _spField2D = FRD2DType::New(); _spDirectKernel = TestRegistrationKernel<2, 2>::New(); _spDirectKernel->_spFieldRepresentation = _spField2D; _spInverseKernel = TestRegistrationKernel<2, 2>::New(); _tag1 = "param1"; _value1 = "value1"; } }; class TestRegistrationGenerator2 { public: typedef core::Registration<2, 3> Registration2Type; typedef core::RegistrationManipulator ManipulatorType; typedef Registration2Type::Pointer Registration2Pointer; typedef core::FieldRepresentationDescriptor<3> FRD3DType; typedef FRD3DType::Pointer FRD3DPointer; FRD3DPointer _spField3D; TestRegistrationKernel<2, 3>::Pointer _spDirectKernel; TestRegistrationKernel<3, 2>::Pointer _spInverseKernel; std::string _tag2; std::string _value2; Registration2Pointer generate() { Registration2Pointer spReg = Registration2Type::New(); ManipulatorType manip(spReg); manip.setDirectMapping(_spDirectKernel); manip.setInverseMapping(_spInverseKernel); std::pair taggedValue(_tag2, _value2); manip.getTagValues().insert(taggedValue); return spReg; }; TestRegistrationGenerator2() { _spField3D = FRD3DType::New(); _spDirectKernel = TestRegistrationKernel<2, 3>::New(); _spInverseKernel = TestRegistrationKernel<3, 2>::New(); _spInverseKernel->_spFieldRepresentation = _spField3D; _tag2 = "param2"; _value2 = "value2"; } }; int mapRegistrationTest(int, char* []) { PREPARE_DEFAULT_TEST_REPORTING; TestRegistrationGenerator1 generator1; TestRegistrationGenerator2 generator2; TestRegistrationGenerator1::Registration1Pointer spReg1 = generator1.generate(); TestRegistrationGenerator2::Registration2Pointer spReg2 = generator2.generate(); CHECK_EQUAL(2, spReg1->getMovingDimensions()); CHECK_EQUAL(2, spReg1->getTargetDimensions()); CHECK_EQUAL(2, spReg2->getMovingDimensions()); CHECK_EQUAL(3, spReg2->getTargetDimensions()); CHECK_EQUAL(generator1._spField2D, spReg1->getDirectFieldRepresentation()); CHECK(spReg1->getInverseFieldRepresentation().IsNull()); CHECK(spReg2->getDirectFieldRepresentation().IsNull()); CHECK_EQUAL(generator2._spField3D, spReg2->getInverseFieldRepresentation()); CHECK_EQUAL(true, spReg1->hasLimitedMovingRepresentation()); CHECK_EQUAL(false, spReg1->hasLimitedTargetRepresentation()); CHECK_EQUAL(false, spReg2->hasLimitedMovingRepresentation()); CHECK_EQUAL(true, spReg2->hasLimitedTargetRepresentation()); std::string foundValue = ""; CHECK_NO_THROW(spReg1->getTagValue(generator1._tag1, foundValue)); CHECK_EQUAL(generator1._value1, foundValue); CHECK_NO_THROW(spReg2->getTagValue(generator2._tag2, foundValue)); CHECK_EQUAL(generator2._value2, foundValue); CHECK_EQUAL(false, spReg2->getTagValue(generator1._tag1, foundValue)); //Kernel function tests CHECK_EQUAL(generator1._spDirectKernel , &(spReg1->getDirectMapping())); CHECK_EQUAL(generator1._spInverseKernel , &(spReg1->getInverseMapping())); CHECK_EQUAL(generator2._spDirectKernel , &(spReg2->getDirectMapping())); CHECK_EQUAL(generator2._spInverseKernel , &(spReg2->getInverseMapping())); spReg1->precomputeInverseMapping(); spReg2->precomputeDirectMapping(); CHECK(!generator1._spDirectKernel->_isPreComputed); CHECK(generator1._spInverseKernel->_isPreComputed); CHECK(generator2._spDirectKernel->_isPreComputed); CHECK(!generator2._spInverseKernel->_isPreComputed); TestRegistrationGenerator1::Registration1Type::MovingPointType moving1; TestRegistrationGenerator1::Registration1Type::TargetPointType target1; moving1.Fill(1); TestRegistrationGenerator2::Registration2Type::MovingPointType moving2; TestRegistrationGenerator2::Registration2Type::TargetPointType target2; target2.Fill(3); spReg1->mapPoint(moving1, target1); spReg2->mapPointInverse(target2, moving2); CHECK(generator1._spDirectKernel->_hasMappedPoint); CHECK(!generator1._spInverseKernel->_hasMappedPoint); CHECK(!generator2._spDirectKernel->_hasMappedPoint); CHECK(generator2._spInverseKernel->_hasMappedPoint); RETURN_AND_REPORT_TEST_SUCCESS; } } //namespace testing } //namespace map diff --git a/Code/Core/test/mapTestKernelBase.h b/Code/Core/test/mapTestKernelBase.h index 144901f..ffa4d38 100644 --- a/Code/Core/test/mapTestKernelBase.h +++ b/Code/Core/test/mapTestKernelBase.h @@ -1,71 +1,71 @@ // ----------------------------------------------------------------------- // MatchPoint - DKFZ translational registration framework // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See mapCopyright.txt or // http://www.dkfz.de/en/sidt/projects/MatchPoint/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision$ (last changed revision) // @date $Date$ (last change date) // @author $Author$ (last changed by) // Subversion HeadURL: $HeadURL$ */ #ifndef __MAP_TEST_KERNEL_BASE_H #define __MAP_TEST_KERNEL_BASE_H #include "mapRegistrationKernelBase.h" namespace map { namespace testing { /*!@brief Dummy Kernel used if a simple testing kernel is needed that does nothing.*/ template class TestKernelBase: public core::RegistrationKernelBase { public: /*! Standard class typedefs. */ typedef TestKernelBase Self; typedef core::RegistrationKernelBase Superclass; typedef itk::SmartPointer Pointer; typedef itk::SmartPointer ConstPointer; itkTypeMacro(TestKernelBase, core::RegistrationKernelBase); itkNewMacro(Self); typename Superclass::RepresentationDescriptorConstPointer getLargestPossibleRepresentation() const { typename Superclass::RepresentationDescriptorConstPointer spTemp = NULL; return spTemp; } - void precomputeKernel() + void precomputeKernel() const override { // do nothing } bool doMapPoint(const typename Superclass::InputPointType& inPoint, typename Superclass::OutputPointType& outPoint) const { return false; } }; } // end namespace testing } // end namespace map #endif diff --git a/Code/IO/files.cmake b/Code/IO/files.cmake index 927f2a0..682d770 100644 --- a/Code/IO/files.cmake +++ b/Code/IO/files.cmake @@ -1,66 +1,69 @@ SET(CPP_FILES source/mapGenericImageReader.cpp source/mapRegistrationFileReader.cpp source/mapRegistrationKernelLoaderBase.cpp source/mapRegistrationKernelLoadRequest.cpp source/mapKernelLoaderLoadPolicy.cpp ) SET(H_FILES include/mapExpandingFieldKernelWriter.h include/mapFieldKernelLoader.h include/mapFieldKernelLoaderBase.h include/mapLazyFileFieldKernelLoader.h +include/mapLazyFieldFileKernelWriter.h include/mapMatrixModelBasedKernelWriter.h include/mapMatrixModelBasedKernelLoader.h include/mapNullRegistrationKernelLoader.h include/mapNullRegistrationKernelWriter.h include/mapRegistrationFileReader.h include/mapRegistrationFileTags.h include/mapRegistrationFileWriter.h include/mapRegistrationKernelLoaderBase.h include/mapRegistrationKernelWriterBase.h include/mapRegistrationKernelWriteRequest.h include/mapRegistrationKernelLoadRequest.h include/mapKernelWriterLoadPolicy.h include/mapKernelLoaderLoadPolicy.h include/mapImageReader.h include/mapImageWriter.h include/mapGenericImageReader.h include/mapGenericImageReadHelper.h include/mapInvertingKernelWriter.h include/mapInvertingKernelLoader.h ) SET(TPP_FILES include/mapExpandingFieldKernelWriter.tpp include/mapFieldKernelLoader.tpp include/mapFieldKernelLoaderBase.tpp include/mapLazyFileFieldKernelLoader.tpp +include/mapLazyFieldFileKernelWriter.tpp include/mapMatrixModelBasedKernelWriter.tpp include/mapMatrixModelBasedKernelLoader.tpp include/mapNullRegistrationKernelWriter.tpp include/mapNullRegistrationKernelLoader.tpp include/mapRegistrationFileWriter.tpp include/mapRegistrationKernelWriterBase.tpp include/mapRegistrationKernelWriteRequest.tpp include/mapKernelWriterLoadPolicy.tpp include/mapImageReader.tpp include/mapImageWriter.tpp include/mapInvertingKernelWriter.tpp include/mapInvertingKernelLoader.tpp ) SET(TEST_CPP_FILES test/mapIOTests.cpp test/mapMatrixModelBasedKernelWriterTest.cpp test/mapMatrixModelBasedKernelLoaderTest.cpp test/mapRegistrationFileWriterTest.cpp test/mapRegistrationFileReaderTest.cpp test/mapNullRegistrationKernelWriterTest.cpp test/mapExpandingFieldKernelWriterTest.cpp test/mapLazyFileFieldKernelLoaderTest.cpp test/mapFieldKernelLoaderTest.cpp test/mapInvertingKernelWriterTest.cpp test/mapInvertingKernelLoaderTest.cpp +test/mapLazyFieldFileKernelWriterTest.cpp ) \ No newline at end of file diff --git a/Code/IO/include/mapImageReader.tpp b/Code/IO/include/mapImageReader.tpp index d03d863..6bcc82e 100644 --- a/Code/IO/include/mapImageReader.tpp +++ b/Code/IO/include/mapImageReader.tpp @@ -1,541 +1,538 @@ // ----------------------------------------------------------------------- // MatchPoint - DKFZ translational registration framework // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See mapCopyright.txt or // http://www.dkfz.de/en/sidt/projects/MatchPoint/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision$ (last changed revision) // @date $Date$ (last change date) // @author $Author$ (last changed by) // Subversion HeadURL: $HeadURL$ */ #ifndef __MAP_IMAGE_READER_TPP #define __MAP_IMAGE_READER_TPP +#include +#include +#include +#include + #include "mapImageReader.h" #include "mapExceptionObjectMacros.h" #include "mapFileDispatch.h" #ifdef MAP_DISABLE_ITK_IO_FACTORY_AUTO_REGISTER #undef ITK_IO_FACTORY_REGISTER_MANAGER #endif //MAP_DISABLE_ITK_IO_FACTORY_AUTO_REGISTER #include "itkImageFileReader.h" #include "itkImageFileWriter.h" #include "itkImageSeriesReader.h" #include "itkImageSeriesWriter.h" #include "itkNumericSeriesFileNames.h" #include "itkGDCMSeriesFileNames.h" #include "itkRescaleIntensityImageFilter.h" #include "itkCastImageFilter.h" #include "itkFixedArray.h" #include "itksys/SystemTools.hxx" -#include -#include - - namespace map { namespace io { //////////////////////////////////////////////////////////////////////// /// Implementation of map::ImageReader //////////////////////////////// //////////////////////////////////////////////////////////////////////// template void ImageReader:: load2D() { typedef ::itk::ImageFileReader< InputImageType > ImageReaderType; typedef ::itk::RescaleIntensityImageFilter< InputImageType, InputImageType > RescaleFilterType; typedef ::itk::CastImageFilter< InputImageType, OutputImageType > CastFilterType; typename CastFilterType::Pointer imageCaster = CastFilterType::New(); typename ImageReaderType::Pointer imageReader = ImageReaderType::New(); typename RescaleFilterType::Pointer rescaleFilter = RescaleFilterType::New(); rescaleFilter->SetOutputMinimum(static_cast(_rescaleMin)); rescaleFilter->SetOutputMaximum(static_cast(_rescaleMax)); imageReader->SetFileName(_fileName.c_str()); rescaleFilter->SetInput(imageReader->GetOutput()); if (_rescaleImage) { imageCaster->SetInput(rescaleFilter->GetOutput()); } else { imageCaster->SetInput(imageReader->GetOutput()); } _spImage = imageCaster->GetOutput(); imageCaster->Update(); _dictionaryArray.clear(); _dictionaryArray.push_back(imageReader->GetImageIO()->GetMetaDataDictionary()); _upToDate = true; }; template const typename ImageReader::MetaDataDictionaryArrayType& ImageReader:: getMetaDictionaryArray() { return _dictionaryArray; }; template void ImageReader:: copyMetaDictionaryArray(const ITKMetaDataDictionaryArray* fromArray, MetaDataDictionaryArrayType& toArray) { toArray.clear(); ITKMetaDataDictionaryArray::const_iterator itr = fromArray->begin(); ITKMetaDataDictionaryArray::const_iterator end = fromArray->end(); while (itr != end) { toArray.push_back(*(*itr)); ++itr; } }; template typename itk::ImageSource::InputImageType>::Pointer ImageReader:: prepareNumericSource() const { //mumeric series image reader typedef ::itk::ImageSeriesReader< InputImageType > SeriesReaderType; typedef ::itk::NumericSeriesFileNames NamesType; typename SeriesReaderType::Pointer seriesReader = SeriesReaderType::New(); NamesType::Pointer names = NamesType::New(); names->SetStartIndex(1); names->SetEndIndex(_upperSeriesLimit); names->SetSeriesFormat(_fileName.c_str()); seriesReader->SetFileNames(names->GetFileNames()); if (seriesReader->GetFileNames().size() == 0) { mapDefaultExceptionMacro( << "Image reader is not correctly configured. Preparing a series reading of a numeric source no(!) files were found. Pattern: " << _fileName << "; upperSeriesLimit: " << _upperSeriesLimit); } typename itk::ImageSource::InputImageType>::Pointer genericReader = seriesReader.GetPointer(); return genericReader; }; template typename itk::ImageSource::InputImageType>::Pointer ImageReader:: prepareDICOMSource() const { //ITK > v4.3.x removed old DICOMSeriesFileNames. Thus currently only support GDCM as source by default return prepareGDCMSource(); /**@TODO Add support for DCMTKSeriesFileNames too*/ }; template typename itk::ImageSource::InputImageType>::Pointer ImageReader:: prepareGDCMSource() const { ::map::core::FileDispatch dispatch(_fileName); ::map::core::String dir = dispatch.getPath(); ::map::core::String strippedFileName = dispatch.getFullName(); typedef itk::GDCMSeriesFileNames NamesGeneratorType; NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New(); nameGenerator->SetInputDirectory(dir); nameGenerator->SetUseSeriesDetails(true); itk::FilenamesContainer fileNames; if (strippedFileName.empty()) { mapLogDebugStaticMacro( << "No file name specified. Use first DICOM series found in directory."); fileNames = nameGenerator->GetInputFileNames(); } else { itk::SerieUIDContainer seriesUIDs = nameGenerator->GetSeriesUIDs(); mapLogDebugStaticMacro( << "Checking found DICOM series"); //check the found series for the filename to pick the right series correlated to the passed filename while (seriesUIDs.size() > 0) { fileNames = nameGenerator->GetFileNames(seriesUIDs.back()); mapLogDebugStaticMacro( << "Checking series: " << seriesUIDs.back() << " (file count: " << fileNames.size() << ")"); seriesUIDs.pop_back(); for (itk::SerieUIDContainer::const_iterator pos = fileNames.begin(); pos != fileNames.end(); ++pos) { if (pos->find(strippedFileName) != core::String::npos) { //this series containes the passed filename -> //we have the right block of files -> we are done. mapLogDebugStaticMacro( << "Found right series!"); seriesUIDs.clear(); break; } } } } typedef ::itk::ImageSeriesReader< InputImageType > SeriesReaderType; typename SeriesReaderType::Pointer seriesReader = SeriesReaderType::New(); seriesReader->SetFileNames(fileNames); if (seriesReader->GetFileNames().size() == 0) { mapDefaultExceptionMacro( << "Image reader is not correctly configured. Preparing a series reading of a DICOM source no(!) dicom files were found. search location: " << _fileName); } typename itk::ImageSource::InputImageType>::Pointer genericReader = seriesReader.GetPointer(); return genericReader; }; template typename itk::ImageSource::InputImageType>::Pointer ImageReader:: prepareNormalSource() const { //Normal image reader (no series read style) typedef ::itk::ImageFileReader< InputImageType > ImageReaderType; typename ImageReaderType::Pointer imageReader = ImageReaderType::New(); imageReader->SetFileName(_fileName.c_str()); typename itk::ImageSource::InputImageType>::Pointer genericReader = imageReader.GetPointer(); return genericReader; }; template void ImageReader:: load3D() { ::map::core::FileDispatch dispatch(_fileName); ::map::core::String sTemp = dispatch.getExtension(); ::map::core::String sDir = dispatch.getPath(); - //Convert to lowercase - for (::map::core::String::iterator spos = sTemp.begin(); spos != sTemp.end(); spos++) - { - (*spos) = std::tolower((*spos), std::locale("")); - } + std::transform(sTemp.begin(), sTemp.end(), sTemp.begin(), ::tolower); typedef ::itk::RescaleIntensityImageFilter< InputImageType, InputImageType > RescaleFilterType; typedef ::itk::CastImageFilter< InputImageType, OutputImageType > CastFilterType; typename CastFilterType::Pointer imageCaster = CastFilterType::New(); typename RescaleFilterType::Pointer rescaleFilter = RescaleFilterType::New(); typename ::itk::ImageSource::Pointer spReader; rescaleFilter->SetOutputMinimum(static_cast(_rescaleMin)); rescaleFilter->SetOutputMaximum(static_cast(_rescaleMax)); if (_seriesReadStyle == ImageSeriesReadStyle::Numeric) { spReader = prepareNumericSource(); } else if (_seriesReadStyle == ImageSeriesReadStyle::Dicom) { spReader = prepareDICOMSource(); } else if (_seriesReadStyle == ImageSeriesReadStyle::GDCM) { spReader = prepareGDCMSource(); } else if (_seriesReadStyle == ImageSeriesReadStyle::Default) { bool isDir = itksys::SystemTools::FileIsDirectory(_fileName.c_str()); if (isDir || sTemp == ".dcm" || sTemp == ".ima") { spReader = prepareDICOMSource(); } else { spReader = prepareNormalSource(); } } else { //style is none spReader = prepareNormalSource(); } if (_rescaleImage) { rescaleFilter->SetInput(spReader->GetOutput()); imageCaster->SetInput(rescaleFilter->GetOutput()); } else { imageCaster->SetInput(spReader->GetOutput()); } imageCaster->Update(); _spImage = imageCaster->GetOutput(); typedef ::itk::ImageFileReader< InputImageType > ImageReaderType; typedef ::itk::ImageSeriesReader< InputImageType > ImageSeriesReaderType; ImageReaderType* pFileReader = dynamic_cast(spReader.GetPointer()); ImageSeriesReaderType* pSeriesReader = dynamic_cast(spReader.GetPointer()); if (pFileReader) { _dictionaryArray.clear(); _dictionaryArray.push_back(pFileReader->GetImageIO()->GetMetaDataDictionary()); } else if (pSeriesReader) { copyMetaDictionaryArray(pSeriesReader->GetMetaDataDictionaryArray(), _dictionaryArray); } else { mapDefaultExceptionMacro( << "Image reader is not valid. Internal reader seams not to be itk::ImageFileReader or itk::ImageSeriesReader."); } _upToDate = true; }; template const core::String& ImageReader:: getFileName() const { return _fileName; }; template void ImageReader:: setFileName(const core::String& fileName) { if (fileName != _fileName) { _upToDate = false; _fileName = fileName; } } template const typename ImageReader::RescaleValueType& ImageReader:: getRescaleMinimum() const { return _rescaleMin; }; template void ImageReader:: setRescaleMinimum(const RescaleValueType& dRescaleMin) { if (dRescaleMin != _rescaleMin) { _upToDate = false; _rescaleMin = dRescaleMin; }; }; template const typename ImageReader::RescaleValueType& ImageReader:: getRescaleMaximum() const { return _rescaleMax; }; template void ImageReader:: setRescaleMaximum(const RescaleValueType& dRescaleMax) { if (dRescaleMax != _rescaleMax) { _upToDate = false; _rescaleMax = dRescaleMax; }; }; template const bool ImageReader:: getRescaleImage() const { return _rescaleImage; }; template void ImageReader:: setRescaleImage(const bool rescaleImage) { if (rescaleImage != _rescaleImage) { _upToDate = false; _rescaleImage = rescaleImage; }; }; template const unsigned int ImageReader:: getUpperSeriesLimit() const { return _upperSeriesLimit; }; template void ImageReader:: setUpperSeriesLimit(const unsigned int upperLimit) { if (upperLimit != _upperSeriesLimit) { _upToDate = false; _upperSeriesLimit = upperLimit; }; }; template const ImageSeriesReadStyle::Type ImageReader:: getSeriesReadStyle() const { return _seriesReadStyle; }; template void ImageReader:: setSeriesReadStyle(ImageSeriesReadStyle::Type readStyle) { if (readStyle != _seriesReadStyle) { _upToDate = false; _seriesReadStyle = readStyle; }; }; template typename ImageReader::OutputImageType* ImageReader:: GetOutput(void) { if (!_upToDate) { switch (OutputImageType::GetImageDimension()) { case 2: load2D(); break; case 3: load3D(); break; default: mapDefaultExceptionMacro( << "Image reader only accepts 2 or 3 dimensional images.") }; }; return _spImage; }; template ImageReader:: ImageReader() { _fileName = ""; _upperSeriesLimit = 255; _upToDate = false; _rescaleImage = false; _rescaleMax = 255; _rescaleMin = 0; _seriesReadStyle = ImageSeriesReadStyle::Default; }; template ImageReader:: ~ImageReader() { }; template typename ImageReader::OutputImageType::Pointer readImage( const core::String& fileName, ImageSeriesReadStyle::Type readStyle, bool rescaleImage, typename ImageReader::RescaleValueType rescaleMin, typename ImageReader::RescaleValueType rescaleMax, unsigned int upperNumericSeriesLimit, typename ImageReader::MetaDataDictionaryArrayType* pLoadedDictArray) { ImageReader reader; reader.setFileName(fileName); reader.setSeriesReadStyle(readStyle); reader.setRescaleImage(rescaleImage); reader.setRescaleMaximum(rescaleMax); reader.setRescaleMinimum(rescaleMin); reader.setUpperSeriesLimit(upperNumericSeriesLimit); typename ImageReader::OutputImageType::Pointer spResult = reader.GetOutput(); if (pLoadedDictArray) { *pLoadedDictArray = reader.getMetaDictionaryArray(); }; return spResult; }; } } #endif diff --git a/Code/IO/include/mapKernelWriterLoadPolicy.h b/Code/IO/include/mapKernelWriterLoadPolicy.h index cc3d856..98287cc 100644 --- a/Code/IO/include/mapKernelWriterLoadPolicy.h +++ b/Code/IO/include/mapKernelWriterLoadPolicy.h @@ -1,78 +1,79 @@ // ----------------------------------------------------------------------- // MatchPoint - DKFZ translational registration framework // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See mapCopyright.txt or // http://www.dkfz.de/en/sidt/projects/MatchPoint/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision$ (last changed revision) // @date $Date$ (last change date) // @author $Author$ (last changed by) // Subversion HeadURL: $HeadURL$ */ #ifndef __MAP_KERNEL_WRITER_LOAD_POLICY_H #define __MAP_KERNEL_WRITER_LOAD_POLICY_H #include "mapGenericStaticLoadPolicyBase.h" #include "mapRegistrationKernelWriterBase.h" namespace map { namespace io { /*! @class KernelWriterLoadPolicy * @brief Load class used by RegistrationFileWriter to populate its service stacks. * * It loads the following providers: + * - NullRegistrationKernelWriter + * - InvertingKernelWriter * - MatrixModelBasedKernelWriter - * - FieldBasedKernelWriter - * - LazzyFieldBasedKernelWriter - * - ComposedKernelWriter + * - LazyFieldFileKernelWriter + * - ExpandingFieldKernelWriter * . * @TODO Add missing writers * @ingroup LoadPolicies * @ingroup RegOperation * @sa RegistrationFileWriter * @tparam VInputDimensions Input dimensions of the registration that should be stored to file. * @tparam VOutputDimensions Output dimensions of the registration that should be stored to file. */ template class KernelWriterLoadPolicy : public ::map::core::services::GenericStaticLoadPolicyBase > { protected: /*! Standard class typedefs. */ typedef core::services::GenericStaticLoadPolicyBase > Superclass; typedef typename Superclass::ProviderBaseType ProviderBaseType; typedef typename Superclass::ProviderBasePointer ProviderBasePointer; typedef typename Superclass::LoadInterfaceType LoadInterfaceType; virtual void doLoading(); KernelWriterLoadPolicy(); ~KernelWriterLoadPolicy(); private: KernelWriterLoadPolicy(const KernelWriterLoadPolicy&); //purposely not implemented void operator=(const KernelWriterLoadPolicy&); //purposely not implemented }; } // end namespace io } // end namespace map #ifndef MatchPoint_MANUAL_TPP # include "mapKernelWriterLoadPolicy.tpp" #endif #endif diff --git a/Code/IO/include/mapKernelWriterLoadPolicy.tpp b/Code/IO/include/mapKernelWriterLoadPolicy.tpp index 45b8abf..978f348 100644 --- a/Code/IO/include/mapKernelWriterLoadPolicy.tpp +++ b/Code/IO/include/mapKernelWriterLoadPolicy.tpp @@ -1,105 +1,115 @@ // ----------------------------------------------------------------------- // MatchPoint - DKFZ translational registration framework // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See mapCopyright.txt or // http://www.dkfz.de/en/sidt/projects/MatchPoint/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision$ (last changed revision) // @date $Date$ (last change date) // @author $Author$ (last changed by) // Subversion HeadURL: $HeadURL$ */ #ifndef __MAP_KERNEL_WRITER_LOAD_POLICY_TPP #define __MAP_KERNEL_WRITER_LOAD_POLICY_TPP #include "mapKernelWriterLoadPolicy.h" #include "mapServiceRepositoryPolicyLoadInterface.h" #include "mapMatrixModelBasedKernelWriter.h" #include "mapNullRegistrationKernelWriter.h" #include "mapExpandingFieldKernelWriter.h" #include "mapInvertingKernelWriter.h" +#include "mapLazyFieldFileKernelWriter.h" namespace map { namespace io { template void KernelWriterLoadPolicy:: doLoading() { ::map::core::services::ServiceRepositoryPolicyLoader loader( Superclass::_pLoadInterface); - typedef ExpandingFieldKernelWriter - ExpandingFieldKernelWriterType; + typedef ExpandingFieldKernelWriter + ExpandingFieldKernelWriterType; - typename ExpandingFieldKernelWriterType::Pointer spExpandingFieldWriter = - ExpandingFieldKernelWriterType::New(); + typename ExpandingFieldKernelWriterType::Pointer spExpandingFieldWriter = + ExpandingFieldKernelWriterType::New(); - if (!loader.addProviderByPolicy(spExpandingFieldWriter)) - { - mapLogWarningObjMacro("ExpandingFieldKernelWriter was not added because it was already on the service stack!"); - } - - typedef MatrixModelBasedKernelWriter ModelKernelWriterType; + if (!loader.addProviderByPolicy(spExpandingFieldWriter)) + { + mapLogWarningObjMacro("ExpandingFieldKernelWriter was not added because it was already on the service stack!"); + } + + typedef LazyFieldFileKernelWriter LazyFieldFileKernelWriterType; + + typename LazyFieldFileKernelWriterType::Pointer spLazyFileWriter = LazyFieldFileKernelWriterType::New(); + + if (!loader.addProviderByPolicy(spLazyFileWriter)) + { + mapLogWarningObjMacro("LazyFieldFileKernelWriter was not added because it was already on the service stack!"); + } + + typedef MatrixModelBasedKernelWriter ModelKernelWriterType; typename ModelKernelWriterType::Pointer spModelWriter = ModelKernelWriterType::New(); if (!loader.addProviderByPolicy(spModelWriter)) { mapLogWarningObjMacro("MatrixModelBasedKernelWriter was not added because it was already on the service stack!"); } typedef InvertingKernelWriter InvertingKernelWriterType; typename InvertingKernelWriterType::Pointer spInvertingFieldWriter = InvertingKernelWriterType::New(); if (!loader.addProviderByPolicy(spInvertingFieldWriter)) { mapLogWarningObjMacro("InvertingKernelWriter was not added because it was already on the service stack!"); } typedef NullRegistrationKernelWriter NullKernelWriterType; typename NullKernelWriterType::Pointer spNullWriter = NullKernelWriterType::New(); if (!loader.addProviderByPolicy(spNullWriter)) { mapLogWarningObjMacro("NullRegistrationKernelWriter was not added because it was already on the service stack!"); } } template KernelWriterLoadPolicy:: KernelWriterLoadPolicy() { } template KernelWriterLoadPolicy:: ~KernelWriterLoadPolicy() { } } // end namespace io } // end namespace map #endif diff --git a/Code/IO/include/mapLazyFieldFileKernelWriter.h b/Code/IO/include/mapLazyFieldFileKernelWriter.h new file mode 100644 index 0000000..0013ffd --- /dev/null +++ b/Code/IO/include/mapLazyFieldFileKernelWriter.h @@ -0,0 +1,109 @@ +// ----------------------------------------------------------------------- +// MatchPoint - DKFZ translational registration framework +// +// Copyright (c) German Cancer Research Center (DKFZ), +// Software development for Integrated Diagnostics and Therapy (SIDT). +// ALL RIGHTS RESERVED. +// See mapCopyright.txt or +// http://www.dkfz.de/en/sidt/projects/MatchPoint/copyright.html +// +// This software is distributed WITHOUT ANY WARRANTY; without even +// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +// PURPOSE. See the above copyright notices for more information. +// +//------------------------------------------------------------------------ +/*! +// @file +// @version $Revision$ (last changed revision) +// @date $Date$ (last change date) +// @author $Author$ (last changed by) +// Subversion HeadURL: $HeadURL$ +*/ + +#ifndef __MAP_LAZY_FIELD_FILE_KERNEL_WRITER_H +#define __MAP_LAZY_FIELD_FILE_KERNEL_WRITER_H + +#include "mapRegistrationKernelWriterBase.h" +#include "mapLazyRegistrationKernel.h" + +namespace map +{ + namespace io + { + /*! @class LazyFieldFileKernelWriter + * @brief Provider that is able to store lazy field based kernels that use a FieldByFileLoad functor. + * + * The writer always copies the file defined FieldByFileLoad functor to the new location defined by the current write operation. + * + * @sa FieldBasedRegistrationKernel + * @ingroup RegOperation + * @tparam VInputDimensions Dimensions of the input space of the kernel that should be inverted. + * @tparam VOutputDimensions Dimensions of the output space of the kernel that should be inverted. + */ + template + class LazyFieldFileKernelWriter : public + RegistrationKernelWriterBase + { + public: + /*! Standard class typedefs. */ + typedef LazyFieldFileKernelWriter Self; + typedef RegistrationKernelWriterBase Superclass; + typedef itk::SmartPointer Pointer; + typedef itk::SmartPointer ConstPointer; + + itkTypeMacro(LazyFieldFileKernelWriter, RegistrationKernelWriterBase); + itkNewMacro(Self); + + typedef typename Superclass::KernelBaseType KernelBaseType; + typedef typename Superclass::KernelBasePointer KernelBasePointer; + typedef typename Superclass::RequestType RequestType; + typedef core::LazyRegistrationKernel KernelType; + + /*! Uses the passed request data to check if the provider is able to provide the service for + * this request. Thus if the kernel is field based with a concrete vector field or expanding is + * wanted anyway. + * @return Indicates if the provider offers the right solution. + * @retval true Provider can handle the request. + * @retval false Provider is not able to handle the request.*/ + virtual bool canHandleRequest(const RequestType& request) const; + + /*! Returns an ID of the provider as string. Calls getStaticProviderName(). + * @return Service provider ID.*/ + virtual core::String getProviderName() const; + + /*! Returns an ID of the provider as string. + * @return Service provider ID.*/ + static core::String getStaticProviderName(); + + /*! Returns an ID of the provider as string. May be equal to GetClassName(), but it may differ. + * @return Service provider ID. + * @remark It is a return by value, becaus it might be possible that the description is generated on line + * when calling this method.*/ + virtual core::String getDescription() const; + + /*! Generates the inverse kernel. + * Returns a structured element containing the matrix. + * @eguarantee strong + * @param [in] request Referenz to the request that contains the kernel and all relevant information for the storing process. + * @return Smart pointer to structured date element containing the stored information. + */ + virtual structuredData::Element::Pointer storeKernel(const RequestType& request) const; + + protected: + + LazyFieldFileKernelWriter(); + virtual ~LazyFieldFileKernelWriter() {}; + + private: + LazyFieldFileKernelWriter(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented + }; + + } // end namespace io +} // end namespace map + +#ifndef MatchPoint_MANUAL_TPP +# include "mapLazyFieldFileKernelWriter.tpp" +#endif + +#endif diff --git a/Code/IO/include/mapLazyFieldFileKernelWriter.tpp b/Code/IO/include/mapLazyFieldFileKernelWriter.tpp new file mode 100644 index 0000000..6ccf416 --- /dev/null +++ b/Code/IO/include/mapLazyFieldFileKernelWriter.tpp @@ -0,0 +1,217 @@ +// ----------------------------------------------------------------------- +// MatchPoint - DKFZ translational registration framework +// +// Copyright (c) German Cancer Research Center (DKFZ), +// Software development for Integrated Diagnostics and Therapy (SIDT). +// ALL RIGHTS RESERVED. +// See mapCopyright.txt or +// http://www.dkfz.de/en/sidt/projects/MatchPoint/copyright.html +// +// This software is distributed WITHOUT ANY WARRANTY; without even +// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +// PURPOSE. See the above copyright notices for more information. +// +//------------------------------------------------------------------------ +/*! +// @file +// @version $Revision$ (last changed revision) +// @date $Date$ (last change date) +// @author $Author$ (last changed by) +// Subversion HeadURL: $HeadURL$ +*/ + +#ifndef __MAP_LAZY_FIELD_FILE_KERNEL_WRITER_TPP +#define __MAP_LAZY_FIELD_FILE_KERNEL_WRITER_TPP + +#include +#include + +#include "itksys/SystemTools.hxx" + +#include "mapLazyFieldFileKernelWriter.h" +#include "mapServiceException.h" +#include "mapRegistrationFileTags.h" +#include "mapFieldByFileLoadFunctor.h" +#include "mapConvert.h" +#include "mapLogbook.h" +#include "mapFileDispatch.h" +#include "mapExpandingFieldKernelWriter.h" + +namespace map +{ + namespace io + { + + template + bool + LazyFieldFileKernelWriter:: + canHandleRequest(const RequestType& request) const + { + const KernelType* pLazyKernel = dynamic_cast + (request._spKernel.GetPointer()); + + bool canHandle = false; + + if (pLazyKernel && !request._expandLazyKernels) + { + auto fileLoadFunctor = dynamic_cast *>(pLazyKernel->getTransformFunctor()); + + canHandle = fileLoadFunctor != nullptr; + }; + + return canHandle; + } + + + template + core::String + LazyFieldFileKernelWriter:: + getProviderName() const + { + return Self::getStaticProviderName(); + } + + template + core::String + LazyFieldFileKernelWriter:: + getStaticProviderName() + { + core::OStringStream os; + os << "LazyFieldFileKernelWriter<" << VInputDimensions << "," << VOutputDimensions << ">"; + return os.str(); + } + + + template + core::String + LazyFieldFileKernelWriter:: + getDescription() const + { + core::OStringStream os; + os << "LazyFieldFileKernelWriter, InputDimension: " << VInputDimensions << ", OutputDimension: " << + VOutputDimensions << "."; + return os.str(); + } + + + template + structuredData::Element::Pointer + LazyFieldFileKernelWriter:: + storeKernel(const RequestType& request) const + { + if (!canHandleRequest(request)) + { + mapExceptionMacro(::map::core::ServiceException, + << "Error: cannot store kernel. Reason: cannot handle request."); + } + + const KernelType* pKernel = dynamic_cast(request._spKernel.GetPointer()); + + if (pKernel == nullptr) + { + mapExceptionMacro(::map::core::ServiceException, + << "Error: cannot store kernel. Reason: cannot cast to LazyRegistrationKernel: " << + request._spKernel.GetPointer()); + } + + structuredData::Element::Pointer spKernelElement; + + if (pKernel->transformExists()) + { //pKernel is not lazy anymore. So we can just save the transform back to a file. + RequestType expandingRequest = request; + expandingRequest._expandLazyKernels = true; + typedef io::ExpandingFieldKernelWriter ExpandingWriterType; + typename ExpandingWriterType::Pointer writer = ExpandingWriterType::New(); + spKernelElement = writer->storeKernel(expandingRequest); + } + else + { + auto fileLoadFunctor = dynamic_cast *>(pKernel->getTransformFunctor()); + + if (fileLoadFunctor == nullptr) + { + mapExceptionMacro(::map::core::ServiceException, + << "Error: cannot store kernel. Reason: Lazy kernel seems to have no FieldByFileLoadFunctor. Kernel: " << pKernel); + } + + core::String sourcePath = fileLoadFunctor->getFieldFilePath(); + + spKernelElement = structuredData::Element::New(); + + spKernelElement->setTag(tags::Kernel); + + spKernelElement->setAttribute(tags::InputDimensions, core::convert::toStr(VInputDimensions)); + + spKernelElement->setAttribute(tags::OutputDimensions, core::convert::toStr(VOutputDimensions)); + + spKernelElement->addSubElement(structuredData::Element::createElement(tags::StreamProvider, + this->getProviderName())); + + spKernelElement->addSubElement(structuredData::Element::createElement(tags::KernelType, + "ExpandedFieldKernel")); + + //generate file name and save field to file + if (request._path.empty()) + { + core::Logbook::warning("No request path set for field storing. Will be stored to current directory."); + } + + if (request._name.empty()) + { + core::Logbook::warning("No request name specified. Field will be stored to unspecified file '_field.nrrd'."); + } + + core::String fieldPath = request._name + "_field.nrrd"; + core::String destinationPath = core::FileDispatch::createFullPath(request._path, fieldPath); + + //copy field file + auto extension = core::FileDispatch::getExtension(sourcePath); + std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower); + if (extension == ".nrrd" || extension == ".mda") + { //these format only consist of one file -> we can just copy it. + itksys::SystemTools::CopyAFile(sourcePath, destinationPath); + } + else + { + mapExceptionMacro(::map::core::ServiceException, + << "Error: cannot store kernel. Reason: Lazy kernel currently only support savely files in NRRD or MDA fromat. See https://phabricator.mitk.org/T24623 for more details. Kernel: " << pKernel); + } + + //add field file + structuredData::Element::Pointer spFieldPathElement = structuredData::Element::New(); + spFieldPathElement->setTag(tags::FieldPath); + spFieldPathElement->setValue(fieldPath); + + spKernelElement->addSubElement(spFieldPathElement); + + //add null point + structuredData::Element::Pointer spUseNullPointElement = structuredData::Element::New(); + spUseNullPointElement->setTag(tags::UseNullPoint); + spUseNullPointElement->setValue(::map::core::convert::toStr(fileLoadFunctor->getNullPointUsage())); + spKernelElement->addSubElement(spUseNullPointElement); + + if (fileLoadFunctor->getNullPointUsage()) + { + typename KernelType::OutputPointType nullPoint = fileLoadFunctor->getNullPoint(); + structuredData::Element::Pointer spNullPointElement = structuredData::streamITKFixedArrayToSD( + nullPoint); + spNullPointElement->setTag(tags::NullPoint); + + spKernelElement->addSubElement(spNullPointElement); + } + } + + return spKernelElement; + } + + + template + LazyFieldFileKernelWriter:: + LazyFieldFileKernelWriter() + {}; + + + } // end namespace io +} // end namespace map + +#endif diff --git a/Code/IO/test/mapExpandingFieldKernelWriterTest.cpp b/Code/IO/test/mapExpandingFieldKernelWriterTest.cpp index add45cc..667eeaa 100644 --- a/Code/IO/test/mapExpandingFieldKernelWriterTest.cpp +++ b/Code/IO/test/mapExpandingFieldKernelWriterTest.cpp @@ -1,174 +1,174 @@ // ----------------------------------------------------------------------- // MatchPoint - DKFZ translational registration framework // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See mapCopyright.txt or // http://www.dkfz.de/en/sidt/projects/MatchPoint/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision$ (last changed revision) // @date $Date$ (last change date) // @author $Author$ (last changed by) // Subversion HeadURL: $HeadURL$ */ #if defined(_MSC_VER) #pragma warning ( disable : 4786 ) #endif #include "mapNullRegistrationKernel.h" #include "mapPreCachedRegistrationKernel.h" #include "mapLazyRegistrationKernel.h" #include "mapExpandingFieldKernelWriter.h" #include "mapSDXMLStrWriter.h" #include "test/mapTestFieldGenerationFunctor.h" #include "mapFileDispatch.h" #include "mapFieldDecomposer.h" #include "litCheckMacros.h" #include "litFieldTester.h" #include "itkImageFileReader.h" namespace map { namespace testing { int mapExpandingFieldKernelWriterTest(int argc, char* argv[]) { //ARGUMENTS: 1: test storage path // 2: ref path PREPARE_DEFAULT_TEST_REPORTING; std::string testPath = ""; std::string refPath = ""; if (argc > 1) { testPath = argv[1]; } if (argc > 2) { refPath = argv[2]; } //functor for lazy field kernel typedef TestFieldGenerationFunctor<2, 2> FieldFunctorType; FieldFunctorType::InFieldRepresentationType::SpacingType spacing(0.5); FieldFunctorType::InFieldRepresentationType::PointType origin; origin.Fill(0); FieldFunctorType::InFieldRepresentationType::SizeType size; size.fill(10); FieldFunctorType::InFieldRepresentationType::Pointer spInRep = FieldFunctorType::InFieldRepresentationType::New(); spInRep->setSize(size); spInRep->setSpacing(spacing); spInRep->setOrigin(origin); FieldFunctorType::Pointer spFunctor = FieldFunctorType::New(spInRep); FieldFunctorType::TransformPointer spPreCachedTransform = spFunctor->generateTransform(); ////////////////////////////////////// //Kernel setup typedef core::LazyRegistrationKernel<2, 2> LazyKernelType; typedef core::PreCachedRegistrationKernel<2, 2> PreCachedKernelType; typedef core::NullRegistrationKernel<2, 2> IllegalKernelType; typedef io::ExpandingFieldKernelWriter<2, 2> WriterType; typedef io::ExpandingFieldKernelWriter<2, 3> Writer23Type; IllegalKernelType::Pointer spIllegalKernel = IllegalKernelType::New(); LazyKernelType::Pointer spLazyKernel = LazyKernelType::New(); PreCachedKernelType::Pointer spCachedKernel = PreCachedKernelType::New(); spLazyKernel->setTransformFunctor(spFunctor.GetPointer()); LazyKernelType::OutputPointType nullPoint; nullPoint[0] = -1; nullPoint[1] = -2; spFunctor->setNullPointUsage(true); spFunctor->setNullPoint(nullPoint); //////////////////////////////////////////// //Writer setup WriterType::Pointer spWriter = WriterType::New(); WriterType::RequestType illegalRequest1(spIllegalKernel, "", "", false); WriterType::RequestType illegalRequest2(spLazyKernel, "", "", false); WriterType::RequestType requestLazy(spLazyKernel, testPath, "ExpandingFieldKernelWriterTest_lazy", true); WriterType::RequestType requestCached(spCachedKernel, testPath, "ExpandingFieldKernelWriterTest_cached", true); ////////////////////////////////////// //Tests CHECK_EQUAL(false, spWriter->canHandleRequest(illegalRequest1)); CHECK_EQUAL(false, spWriter->canHandleRequest(illegalRequest2)); CHECK_EQUAL(true, spWriter->canHandleRequest(requestLazy)); CHECK_EQUAL(true, spWriter->canHandleRequest(requestCached)); CHECK_EQUAL("ExpandingFieldKernelWriter<2,2>", spWriter->getProviderName()); CHECK_EQUAL("ExpandingFieldKernelWriter<2,3>", Writer23Type::getStaticProviderName()); //test processing of illegal requests CHECK_THROW_EXPLICIT(spWriter->storeKernel(illegalRequest1), core::ServiceException); CHECK_THROW_EXPLICIT(spWriter->storeKernel(illegalRequest2), core::ServiceException); CHECK_THROW(spWriter->storeKernel(requestCached)); //illegal because field is not yet set //test valid request structuredData::Element::Pointer spDataLazy; CHECK_NO_THROW(spDataLazy = spWriter->storeKernel(requestLazy)); //make the cached kernel legal spCachedKernel->setTransformModel(spPreCachedTransform); structuredData::Element::Pointer spDataCached; CHECK_NO_THROW(spDataCached = spWriter->storeKernel(requestCached)); //test content structuredData::XMLStrWriter::Pointer spStrWriter = structuredData::XMLStrWriter::New(); core::String data = spStrWriter->write(spDataLazy); core::String ref = "ExpandingFieldKernelWriter<2,2>ExpandedFieldKernelExpandingFieldKernelWriterTest_lazy_field.nrrd1-1.000000000-2.000000000"; CHECK_EQUAL(ref, data); //test the fields map::core::FieldDecomposer<2, 2>::FieldConstPointer actualField; map::core::String refFieldPath = map::core::FileDispatch::createFullPath(refPath, - "expandingFieldKernelWriterTest_ref.mhd"); + "expandingFieldKernelWriterTest_ref.nrrd"); typedef ::itk::ImageFileReader::FieldType> ReaderType; ReaderType::Pointer spReader = ReaderType::New(); spReader->SetFileName(refFieldPath); map::core::FieldDecomposer<2, 2>::FieldPointer spRefField = spReader->GetOutput(); spReader->Update(); lit::FieldTester::FieldType> tester; double checkThreshold = 0.1; tester.setCheckThreshold(checkThreshold); tester.setExpectedField(spRefField); bool valid = map::core::FieldDecomposer<2, 2>::decomposeKernel(spLazyKernel, actualField); tester.setActualField(actualField); CHECK_TESTER(tester); map::core::FieldDecomposer<2, 2>::decomposeKernel(spCachedKernel, actualField); tester.setActualField(actualField); CHECK_TESTER(tester); RETURN_AND_REPORT_TEST_SUCCESS; } } //namespace testing } //namespace map diff --git a/Code/IO/test/mapFieldKernelLoaderTest.cpp b/Code/IO/test/mapFieldKernelLoaderTest.cpp index 1e0ede6..7235ed0 100644 --- a/Code/IO/test/mapFieldKernelLoaderTest.cpp +++ b/Code/IO/test/mapFieldKernelLoaderTest.cpp @@ -1,225 +1,225 @@ // ----------------------------------------------------------------------- // MatchPoint - DKFZ translational registration framework // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See mapCopyright.txt or // http://www.dkfz.de/en/sidt/projects/MatchPoint/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision: 797 $ (last changed revision) // @date $Date: 2014-10-10 11:42:05 +0200 (Fr, 10 Okt 2014) $ (last change date) // @author $Author: floca $ (last changed by) // Subversion HeadURL: $HeadURL: https://svn/sbr/Sources/SBR-Projects/MatchPoint/trunk/Code/IO/test/mapFieldKernelLoaderTest.cpp $ */ #if defined(_MSC_VER) #pragma warning ( disable : 4786 ) #endif #include "mapPreCachedRegistrationKernel.h" #include "mapFieldKernelLoader.h" #include "test/mapTestFieldGenerationFunctor.h" #include "mapFileDispatch.h" #include "mapSDXMLStrReader.h" #include "mapSDXMLStrWriter.h" #include "mapFieldDecomposer.h" #include "litCheckMacros.h" #include "litFieldTester.h" #include "itkImageFileReader.h" namespace map { namespace testing { int mapFieldKernelLoaderTest(int argc, char* argv[]) { //ARGUMENTS: 1: test storage path // 2: ref path PREPARE_DEFAULT_TEST_REPORTING; std::string testPath = ""; std::string refPath = ""; if (argc > 1) { testPath = argv[1]; } if (argc > 2) { refPath = argv[2]; } ////////////////////////////////////////////// //functor for reference field typedef TestFieldGenerationFunctor<2, 2> FieldFunctorType; FieldFunctorType::InFieldRepresentationType::SpacingType spacing(0.5); FieldFunctorType::InFieldRepresentationType::PointType origin; origin.Fill(0); FieldFunctorType::InFieldRepresentationType::SizeType size; size.fill(10); FieldFunctorType::InFieldRepresentationType::Pointer spInRep = FieldFunctorType::InFieldRepresentationType::New(); spInRep->setSize(size); spInRep->setSpacing(spacing); spInRep->setOrigin(origin); FieldFunctorType::Pointer spRefFunctor = FieldFunctorType::New(spInRep); typedef core::PreCachedRegistrationKernel<2, 2> PreCachedKernelType; typedef io::FieldKernelLoader<2, 2> LoaderType; typedef io::FieldKernelLoader<2, 3> Loader23Type; ////////////////////////////////////////////// //Loader and request setup LoaderType::Pointer spLoader = LoaderType::New(); map::core::String testFilePath = map::structuredData::encodeForXml( - map::core::FileDispatch::createFullPath(refPath, "expandingFieldKernelWriterTest_ref.mhd")); + map::core::FileDispatch::createFullPath(refPath, "expandingFieldKernelWriterTest_ref.nrrd")); ::map::core::String validData = "ExpandingFieldKernelWriter<2,2>ExpandedFieldKernel" + testFilePath + "1-1.000000000-2.000000000"; ::map::core::String validData_noNullPoint = "ExpandingFieldKernelWriter<2,2>ExpandedFieldKernel" + testFilePath + "1"; ::map::core::String invalidData_wrongDim = "ExpandingFieldKernelWriter<2,2>ExpandedFieldKernel"; ::map::core::String invalidData_wrongDim2 = "ExpandingFieldKernelWriter<2,2>ExpandedFieldKernel"; ::map::core::String invalidData_wrongType = "ExpandingFieldKernelWriter<2,2>WrongKernel"; ::map::core::String invalidData_noFile = "ExpandingFieldKernelWriter<2,2>ExpandedFieldKernel1-1.000000000-2.000000000"; ::map::core::String invalidData_noUseNullPoint = "ExpandingFieldKernelWriter<2,2>ExpandedFieldKernelexpandingFieldKernelWriterTest_ref.mhd-1.000000000-2.000000000"; ::map::core::String invalidData_wrongNullPoint = "ExpandingFieldKernelWriter<2,2>ExpandedFieldKernelexpandingFieldKernelWriterTest_ref.mhd1-1.000000000"; ::map::core::String invalidData_wrongFile = "ExpandingFieldKernelWriter<2,2>ExpandedFieldKernelinexistantDummyFile.error1-1.000000000-2.000000000"; ::map::core::String invalidData_wrongDimFile = "ExpandingFieldKernelWriter<2,2>ExpandedFieldKernel" + testFilePath + "1-1.000000000-2.000000000"; structuredData::XMLStrReader::Pointer spStrReader = structuredData::XMLStrReader::New(); LoaderType::RequestType validRequest(spStrReader->readXMLContent(validData), false); LoaderType::RequestType validRequest_lazy(spStrReader->readXMLContent(validData), true); LoaderType::RequestType validRequest_noNull(spStrReader->readXMLContent(validData_noNullPoint), false); LoaderType::RequestType validRequest_noNull_lazy(spStrReader->readXMLContent( validData_noNullPoint), true); LoaderType::RequestType invalidRequest_wrongDim(spStrReader->readXMLContent(invalidData_wrongDim), false); LoaderType::RequestType invalidRequest_wrongDim2(spStrReader->readXMLContent(invalidData_wrongDim2), false); LoaderType::RequestType invalidRequest_wrongType(spStrReader->readXMLContent(invalidData_wrongType), false); LoaderType::RequestType invalidRequest_noFile(spStrReader->readXMLContent(invalidData_noFile), false); LoaderType::RequestType invalidRequest_noUseNullPoint(spStrReader->readXMLContent( invalidData_noUseNullPoint), false); LoaderType::RequestType invalidRequest_wrongNullPoint(spStrReader->readXMLContent( invalidData_wrongNullPoint), false); LoaderType::RequestType invalidRequest_wrongFile(spStrReader->readXMLContent(invalidData_wrongFile), false); LoaderType::RequestType invalidRequest_wrongFile_lazy(spStrReader->readXMLContent( invalidData_wrongFile), true); //////////////////////////////////////////// // Start Tests CHECK_EQUAL(false, spLoader->canHandleRequest(invalidRequest_wrongDim)); CHECK_EQUAL(false, spLoader->canHandleRequest(invalidRequest_wrongDim2)); CHECK_EQUAL(false, spLoader->canHandleRequest(invalidRequest_wrongType)); CHECK_EQUAL(true, spLoader->canHandleRequest(validRequest)); CHECK_EQUAL(true, spLoader->canHandleRequest(validRequest_lazy)); CHECK_EQUAL(true, spLoader->canHandleRequest(validRequest_noNull)); CHECK_EQUAL(true, spLoader->canHandleRequest(validRequest_noNull_lazy)); CHECK_EQUAL("FieldKernelLoader<2,2>", spLoader->getProviderName()); CHECK_EQUAL("FieldKernelLoader<2,3>", Loader23Type::getStaticProviderName()); //test processing of illegal requests CHECK_THROW_EXPLICIT(spLoader->loadKernel(invalidRequest_wrongDim), core::ServiceException); CHECK_THROW_EXPLICIT(spLoader->loadKernel(invalidRequest_wrongDim2), core::ServiceException); CHECK_THROW_EXPLICIT(spLoader->loadKernel(invalidRequest_wrongType), core::ServiceException); CHECK_THROW_EXPLICIT(spLoader->loadKernel(invalidRequest_noFile), core::ServiceException); CHECK_THROW_EXPLICIT(spLoader->loadKernel(invalidRequest_noUseNullPoint), core::ServiceException); CHECK_THROW_EXPLICIT(spLoader->loadKernel(invalidRequest_wrongNullPoint), core::ServiceException); CHECK_THROW_EXPLICIT(spLoader->loadKernel(invalidRequest_wrongFile), ::itk::ImageFileReaderException); //test valid request LoaderType::GenericKernelPointer spKernel; CHECK_NO_THROW(spKernel = spLoader->loadKernel(validRequest)); LoaderType::GenericKernelPointer spKernel_lazy; CHECK_NO_THROW(spKernel_lazy = spLoader->loadKernel(validRequest_lazy)); LoaderType::GenericKernelPointer spKernel_noNull; CHECK_NO_THROW(spKernel_noNull = spLoader->loadKernel(validRequest_noNull)); LoaderType::GenericKernelPointer spKernel_noNull_lazy; CHECK_NO_THROW(spKernel_noNull_lazy = spLoader->loadKernel(validRequest_noNull_lazy)); //test the fields ::map::core::FieldDecomposer<2, 2>::FieldConstPointer actualField; ::map::core::FieldDecomposer<2, 2>::decomposeTransform(spRefFunctor->generateTransform(), actualField); lit::FieldTester< ::map::core::FieldDecomposer<2, 2>::FieldType> tester; double checkThreshold = 0.1; tester.setCheckThreshold(checkThreshold); tester.setExpectedField(actualField); PreCachedKernelType* pKernel = dynamic_cast(spKernel.GetPointer()); CHECK(pKernel != NULL); bool validField = ::map::core::FieldDecomposer<2, 2>::decomposeKernel(pKernel, actualField); CHECK(validField); tester.setActualField(actualField); CHECK_TESTER(tester); CHECK(*(pKernel->getLargestPossibleRepresentation()) == *spInRep); pKernel = dynamic_cast(spKernel.GetPointer()); CHECK(pKernel != NULL); validField = ::map::core::FieldDecomposer<2, 2>::decomposeKernel(pKernel, actualField); CHECK(validField); tester.setActualField(actualField); CHECK_TESTER(tester); CHECK(*(pKernel->getLargestPossibleRepresentation()) == *spInRep); pKernel = dynamic_cast(spKernel_noNull.GetPointer()); CHECK(pKernel != NULL); validField = ::map::core::FieldDecomposer<2, 2>::decomposeKernel(pKernel, actualField); CHECK(validField); tester.setActualField(actualField); CHECK_TESTER(tester); CHECK(*(pKernel->getLargestPossibleRepresentation()) == *spInRep); pKernel = dynamic_cast(spKernel_noNull_lazy.GetPointer()); CHECK(pKernel != NULL); validField = ::map::core::FieldDecomposer<2, 2>::decomposeKernel(pKernel, actualField); CHECK(validField); tester.setActualField(actualField); CHECK_TESTER(tester); CHECK(*(pKernel->getLargestPossibleRepresentation()) == *spInRep); //*@TODO Noch Test fuer: wenn man ein meta file unterschiebt, dass die falsche Dimension hat, also .mapr noch richtige dimension und dann das meta image falsch. RETURN_AND_REPORT_TEST_SUCCESS; } } //namespace testing } //namespace map diff --git a/Code/IO/test/mapIOTests.cpp b/Code/IO/test/mapIOTests.cpp index ca02022..11cdf83 100644 --- a/Code/IO/test/mapIOTests.cpp +++ b/Code/IO/test/mapIOTests.cpp @@ -1,90 +1,91 @@ // ----------------------------------------------------------------------- // MatchPoint - DKFZ translational registration framework // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See mapCopyright.txt or // http://www.dkfz.de/en/sidt/projects/MatchPoint/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision$ (last changed revision) // @date $Date$ (last change date) // @author $Author$ (last changed by) // Subversion HeadURL: $HeadURL$ */ // this file defines the mapCoreTests for the test driver // and all it expects is that you have a function called RegisterTests #if defined(_MSC_VER) #pragma warning ( disable : 4786 ) #endif #include "mapExceptionObject.h" #include "litMultiTestsMain.h" namespace map { namespace testing { void registerTests() { LIT_REGISTER_TEST(mapMatrixModelBasedKernelWriterTest); LIT_REGISTER_TEST(mapMatrixModelBasedKernelLoaderTest); LIT_REGISTER_TEST(mapNullRegistrationKernelWriterTest); LIT_REGISTER_TEST(mapExpandingFieldKernelWriterTest); LIT_REGISTER_TEST(mapLazyFileFieldKernelLoaderTest); - LIT_REGISTER_TEST(mapFieldKernelLoaderTest); + LIT_REGISTER_TEST(mapLazyFieldFileKernelWriterTest); + LIT_REGISTER_TEST(mapFieldKernelLoaderTest); LIT_REGISTER_TEST(mapInvertingKernelWriterTest); LIT_REGISTER_TEST(mapInvertingKernelLoaderTest); LIT_REGISTER_TEST(mapRegistrationFileWriterTest); LIT_REGISTER_TEST(mapRegistrationFileReaderTest); } } } int main(int argc, char* argv[]) { int result = 0; map::testing::registerTests(); try { result = lit::multiTestsMain(argc, argv); } catch (const map::core::ExceptionObject& e) { std::cerr << "MatchPoint test driver caught an MatchPoint exception:\n"; e.Print(std::cerr); std::cerr << "\n"; result = -1; } catch (const itk::ExceptionObject& e) { std::cerr << "MatchPoint test driver caught an ITK exception:\n"; std::cerr << e.GetFile() << ":" << e.GetLine() << ":\n" << e.GetDescription() << "\n"; result = -1; } catch (const std::exception& e) { std::cerr << "MatchPoint test driver caught an exception:\n"; std::cerr << e.what() << "\n"; result = -1; } catch (...) { std::cerr << "MatchPoint test driver caught an unknown exception!!!\n"; result = -1; } return result; } diff --git a/Code/IO/test/mapLazyFieldFileKernelWriterTest.cpp b/Code/IO/test/mapLazyFieldFileKernelWriterTest.cpp new file mode 100644 index 0000000..b8ad536 --- /dev/null +++ b/Code/IO/test/mapLazyFieldFileKernelWriterTest.cpp @@ -0,0 +1,166 @@ +// ----------------------------------------------------------------------- +// MatchPoint - DKFZ translational registration framework +// +// Copyright (c) German Cancer Research Center (DKFZ), +// Software development for Integrated Diagnostics and Therapy (SIDT). +// ALL RIGHTS RESERVED. +// See mapCopyright.txt or +// http://www.dkfz.de/en/sidt/projects/MatchPoint/copyright.html +// +// This software is distributed WITHOUT ANY WARRANTY; without even +// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +// PURPOSE. See the above copyright notices for more information. +// +//------------------------------------------------------------------------ +/*! +// @file +// @version $Revision$ (last changed revision) +// @date $Date$ (last change date) +// @author $Author$ (last changed by) +// Subversion HeadURL: $HeadURL$ +*/ + +#if defined(_MSC_VER) +#pragma warning ( disable : 4786 ) +#endif + +#include "itksys/SystemTools.hxx" + +#include "mapRegistrationFileReader.h" +#include "mapRegistration.h" +#include "mapNullRegistrationKernel.h" +#include "mapRegistrationKernel.h" +#include "mapLazyFieldFileKernelWriter.h" +#include "mapFileDispatch.h" +#include "mapSDXMLStrWriter.h" + +#include "litCheckMacros.h" +#include "litFieldTester.h" + + +namespace map +{ + namespace testing + { + + ::map::core::RegistrationKernel<2,2>::ConstPointer LoadLazyKernel(const std::string& refPath) + { + typedef ::map::io::RegistrationFileReader ReaderType; + ReaderType::Pointer spReader = ReaderType::New(); + spReader->setPreferLazyLoading(true); + + auto fullpath = ::map::core::FileDispatch::createFullPath(refPath, "registrationFileWriterReader_Ref7.mapr"); + ::map::core::Registration<2,2>::Pointer spRegistration = dynamic_cast<::map::core::Registration<2, 2> *>( spReader->read(fullpath).GetPointer()); + + return dynamic_cast *>(&(spRegistration->getInverseMapping())); + }; + + ::map::core::RegistrationKernel<2, 2>::ConstPointer LoadExpandedKernel(const std::string& refPath) + { + typedef ::map::io::RegistrationFileReader ReaderType; + ReaderType::Pointer spReader = ReaderType::New(); + spReader->setPreferLazyLoading(false); + + auto fullpath = ::map::core::FileDispatch::createFullPath(refPath, "registrationFileWriterReader_Ref7.mapr"); + ::map::core::Registration<2, 2>::Pointer spRegistration = dynamic_cast<::map::core::Registration<2, 2> *>(spReader->read(fullpath).GetPointer()); + + return dynamic_cast *>(&(spRegistration->getInverseMapping())); + }; + + int mapLazyFieldFileKernelWriterTest(int argc, char* argv[]) + { + //ARGUMENTS: 1: test storage path + // 2: ref path + + PREPARE_DEFAULT_TEST_REPORTING; + + std::string testPath = ""; + std::string refPath = ""; + + if (argc > 1) + { + testPath = argv[1]; + } + + if (argc > 2) + { + refPath = argv[2]; + } + + ////////////////////////////////////// + //Kernel setup + typedef core::RegistrationKernel<2, 2> KernelType; + + KernelType::ConstPointer lazyKernel = LoadLazyKernel(refPath); + KernelType::ConstPointer unLazyKernel = LoadLazyKernel(refPath); + unLazyKernel->precomputeKernel(); + KernelType::ConstPointer expandedKernel = LoadExpandedKernel(refPath); + + typedef core::NullRegistrationKernel<2, 2> IllegalKernelType; + + IllegalKernelType::Pointer spIllegalKernel = IllegalKernelType::New(); + + typedef io::LazyFieldFileKernelWriter<2, 2> WriterType; + typedef io::LazyFieldFileKernelWriter<2, 3> Writer23Type; + + + //////////////////////////////////////////// + //Writer setup + WriterType::Pointer spWriter = WriterType::New(); + + WriterType::RequestType illegalRequest1(spIllegalKernel, "", "", false); + WriterType::RequestType illegalRequest2(expandedKernel, "", "", false); + WriterType::RequestType illegalRequest3(lazyKernel, testPath, "LazyFieldFileKernelWriterTest", true); + WriterType::RequestType request(lazyKernel, testPath, "LazyFieldFileKernelWriterTest",false); + WriterType::RequestType unlazyRequest(unLazyKernel, testPath, "UnLazyFieldFileKernelWriterTest", false); + + ////////////////////////////////////// + //Tests + + CHECK_EQUAL(false, spWriter->canHandleRequest(illegalRequest1)); + CHECK_EQUAL(false, spWriter->canHandleRequest(illegalRequest2)); + CHECK_EQUAL(false, spWriter->canHandleRequest(illegalRequest3)); + CHECK_EQUAL(true, spWriter->canHandleRequest(request)); + + CHECK_EQUAL("LazyFieldFileKernelWriter<2,2>", spWriter->getProviderName()); + CHECK_EQUAL("LazyFieldFileKernelWriter<2,3>", Writer23Type::getStaticProviderName()); + + //test processing of illegal requests + CHECK_THROW_EXPLICIT(spWriter->storeKernel(illegalRequest1), core::ServiceException); + CHECK_THROW_EXPLICIT(spWriter->storeKernel(illegalRequest2), core::ServiceException); + CHECK_THROW_EXPLICIT(spWriter->storeKernel(illegalRequest3), core::ServiceException); + + //test valid request + structuredData::Element::Pointer spDataLazy; + CHECK_NO_THROW(spDataLazy = spWriter->storeKernel(request)); + + //test content + structuredData::XMLStrWriter::Pointer spStrWriter = structuredData::XMLStrWriter::New(); + + core::String data = spStrWriter->write(spDataLazy); + core::String ref = + "LazyFieldFileKernelWriter<2,2>ExpandedFieldKernelLazyFieldFileKernelWriterTest_field.nrrd1-1.000000000-2.000000000"; + CHECK_EQUAL(ref, data); + + auto refFieldPath = ::map::core::FileDispatch::createFullPath(refPath, "expandingFieldKernelWriterTest_ref.nrrd"); + auto testFieldPath = ::map::core::FileDispatch::createFullPath(testPath, "LazyFieldFileKernelWriterTest_field.nrrd"); + + CHECK(!itksys::SystemTools::FilesDiffer(refFieldPath, testFieldPath)); + + //write again. Now the data is not lazy any more and should be passed to the ExpandingFieldWriter + CHECK_NO_THROW(spDataLazy = spWriter->storeKernel(unlazyRequest)); + + data = spStrWriter->write(spDataLazy); + ref = + "ExpandingFieldKernelWriter<2,2>ExpandedFieldKernelUnLazyFieldFileKernelWriterTest_field.nrrd1-1.000000000-2.000000000"; + CHECK_EQUAL(ref, data); + + refFieldPath = ::map::core::FileDispatch::createFullPath(refPath, "expandingFieldKernelWriterTest_ref.nrrd"); + testFieldPath = ::map::core::FileDispatch::createFullPath(testPath, "UnLazyFieldFileKernelWriterTest_field.nrrd"); + + CHECK(!itksys::SystemTools::FilesDiffer(refFieldPath, testFieldPath)); + + RETURN_AND_REPORT_TEST_SUCCESS; + } + } //namespace testing +} //namespace map diff --git a/Code/IO/test/mapLazyFileFieldKernelLoaderTest.cpp b/Code/IO/test/mapLazyFileFieldKernelLoaderTest.cpp index 731d6da..f26bced 100644 --- a/Code/IO/test/mapLazyFileFieldKernelLoaderTest.cpp +++ b/Code/IO/test/mapLazyFileFieldKernelLoaderTest.cpp @@ -1,206 +1,206 @@ // ----------------------------------------------------------------------- // MatchPoint - DKFZ translational registration framework // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See mapCopyright.txt or // http://www.dkfz.de/en/sidt/projects/MatchPoint/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision: 797 $ (last changed revision) // @date $Date: 2014-10-10 11:42:05 +0200 (Fr, 10 Okt 2014) $ (last change date) // @author $Author: floca $ (last changed by) // Subversion HeadURL: $HeadURL: https://svn/sbr/Sources/SBR-Projects/MatchPoint/trunk/Code/IO/test/mapLazyFileFieldKernelLoaderTest.cpp $ */ #if defined(_MSC_VER) #pragma warning ( disable : 4786 ) #endif #include "mapLazyRegistrationKernel.h" #include "mapLazyFileFieldKernelLoader.h" #include "test/mapTestFieldGenerationFunctor.h" #include "mapFileDispatch.h" #include "mapSDXMLStrReader.h" #include "mapSDXMLStrWriter.h" #include "mapFieldDecomposer.h" #include "litCheckMacros.h" #include "litFieldTester.h" #include "itkImageFileReader.h" namespace map { namespace testing { int mapLazyFileFieldKernelLoaderTest(int argc, char* argv[]) { //ARGUMENTS: 1: test storage path // 2: ref path PREPARE_DEFAULT_TEST_REPORTING; std::string testPath = ""; std::string refPath = ""; if (argc > 1) { testPath = argv[1]; } if (argc > 2) { refPath = argv[2]; } ////////////////////////////////////////////// //functor for reference field typedef TestFieldGenerationFunctor<2, 2> FieldFunctorType; FieldFunctorType::InFieldRepresentationType::SpacingType spacing(0.5); FieldFunctorType::InFieldRepresentationType::PointType origin; origin.Fill(0); FieldFunctorType::InFieldRepresentationType::SizeType size; size.fill(10); FieldFunctorType::InFieldRepresentationType::Pointer spInRep = FieldFunctorType::InFieldRepresentationType::New(); spInRep->setSize(size); spInRep->setSpacing(spacing); spInRep->setOrigin(origin); FieldFunctorType::Pointer spRefFunctor = FieldFunctorType::New(spInRep); typedef core::LazyRegistrationKernel<2, 2> LazyKernelType; typedef io::LazyFileFieldKernelLoader<2, 2> LoaderType; typedef io::LazyFileFieldKernelLoader<2, 3> Loader23Type; ////////////////////////////////////////////// //Loader and request setup LoaderType::Pointer spLoader = LoaderType::New(); map::core::String testFilePath = map::structuredData::encodeForXml( - map::core::FileDispatch::createFullPath(refPath, "expandingFieldKernelWriterTest_ref.mhd")); + map::core::FileDispatch::createFullPath(refPath, "expandingFieldKernelWriterTest_ref.nrrd")); ::map::core::String validData = "ExpandingFieldKernelWriter<2,2>ExpandedFieldKernel" + testFilePath + "1-1.000000000-2.000000000"; ::map::core::String validData_noNullPoint = "ExpandingFieldKernelWriter<2,2>ExpandedFieldKernel" + testFilePath + "1"; ::map::core::String invalidData_wrongDim = "ExpandingFieldKernelWriter<2,2>ExpandedFieldKernel"; ::map::core::String invalidData_wrongDim2 = "ExpandingFieldKernelWriter<2,2>ExpandedFieldKernel"; ::map::core::String invalidData_wrongType = "ExpandingFieldKernelWriter<2,2>WrongKernel"; ::map::core::String invalidData_noFile = "ExpandingFieldKernelWriter<2,2>ExpandedFieldKernel1-1.000000000-2.000000000"; ::map::core::String invalidData_noUseNullPoint = "ExpandingFieldKernelWriter<2,2>ExpandedFieldKernelexpandingFieldKernelWriterTest_ref.mhd-1.000000000-2.000000000"; ::map::core::String invalidData_wrongNullPoint = "ExpandingFieldKernelWriter<2,2>ExpandedFieldKernelexpandingFieldKernelWriterTest_ref.mhd1-1.000000000"; ::map::core::String invalidData_wrongFile = "ExpandingFieldKernelWriter<2,2>ExpandedFieldKernelinexistantDummyFile.error1-1.000000000-2.000000000"; ::map::core::String invalidData_wrongDimFile = "ExpandingFieldKernelWriter<2,2>ExpandedFieldKernel" + testFilePath + "1-1.000000000-2.000000000"; structuredData::XMLStrReader::Pointer spStrReader = structuredData::XMLStrReader::New(); LoaderType::RequestType validRequest(spStrReader->readXMLContent(validData), false); LoaderType::RequestType validRequest_lazy(spStrReader->readXMLContent(validData), true); LoaderType::RequestType validRequest_noNull(spStrReader->readXMLContent(validData_noNullPoint), false); LoaderType::RequestType validRequest_noNull_lazy(spStrReader->readXMLContent( validData_noNullPoint), true); LoaderType::RequestType invalidRequest_wrongDim(spStrReader->readXMLContent(invalidData_wrongDim), false); LoaderType::RequestType invalidRequest_wrongDim2(spStrReader->readXMLContent(invalidData_wrongDim2), false); LoaderType::RequestType invalidRequest_wrongType(spStrReader->readXMLContent(invalidData_wrongType), false); LoaderType::RequestType invalidRequest_noFile(spStrReader->readXMLContent(invalidData_noFile), false); LoaderType::RequestType invalidRequest_noUseNullPoint(spStrReader->readXMLContent( invalidData_noUseNullPoint), false); LoaderType::RequestType invalidRequest_wrongNullPoint(spStrReader->readXMLContent( invalidData_wrongNullPoint), false); LoaderType::RequestType invalidRequest_wrongFile(spStrReader->readXMLContent(invalidData_wrongFile), false); LoaderType::RequestType invalidRequest_wrongFile_lazy(spStrReader->readXMLContent( invalidData_wrongFile), true); //////////////////////////////////////////// // Start Tests CHECK_EQUAL(false, spLoader->canHandleRequest(invalidRequest_wrongDim)); CHECK_EQUAL(false, spLoader->canHandleRequest(invalidRequest_wrongDim2)); CHECK_EQUAL(false, spLoader->canHandleRequest(invalidRequest_wrongType)); CHECK_EQUAL(false, spLoader->canHandleRequest(validRequest)); CHECK_EQUAL(true, spLoader->canHandleRequest(validRequest_lazy)); CHECK_EQUAL(false, spLoader->canHandleRequest(validRequest_noNull)); CHECK_EQUAL(true, spLoader->canHandleRequest(validRequest_noNull_lazy)); CHECK_EQUAL("LazyFileFieldKernelLoader<2,2>", spLoader->getProviderName()); CHECK_EQUAL("LazyFileFieldKernelLoader<2,3>", Loader23Type::getStaticProviderName()); //test processing of illegal requests CHECK_THROW_EXPLICIT(spLoader->loadKernel(invalidRequest_wrongDim), core::ServiceException); CHECK_THROW_EXPLICIT(spLoader->loadKernel(invalidRequest_wrongDim2), core::ServiceException); CHECK_THROW_EXPLICIT(spLoader->loadKernel(invalidRequest_wrongType), core::ServiceException); CHECK_THROW_EXPLICIT(spLoader->loadKernel(invalidRequest_noFile), core::ServiceException); CHECK_THROW_EXPLICIT(spLoader->loadKernel(invalidRequest_noUseNullPoint), core::ServiceException); CHECK_THROW_EXPLICIT(spLoader->loadKernel(invalidRequest_wrongNullPoint), core::ServiceException); CHECK_THROW_EXPLICIT(spLoader->loadKernel(invalidRequest_wrongFile), core::ServiceException); CHECK_THROW_EXPLICIT(spLoader->loadKernel(validRequest), core::ServiceException); CHECK_THROW_EXPLICIT(spLoader->loadKernel(validRequest_noNull), core::ServiceException); //test valid request LoaderType::GenericKernelPointer spKernel; CHECK_NO_THROW(spKernel = spLoader->loadKernel(validRequest_lazy)); LoaderType::GenericKernelPointer spKernel_noNull; CHECK_NO_THROW(spKernel_noNull = spLoader->loadKernel(validRequest_noNull_lazy)); //test the fields ::map::core::FieldDecomposer<2, 2>::FieldConstPointer actualField; ::map::core::FieldDecomposer<2, 2>::decomposeTransform(spRefFunctor->generateTransform(),actualField); lit::FieldTester< ::map::core::FieldDecomposer<2, 2>::FieldType> tester; double checkThreshold = 0.1; tester.setCheckThreshold(checkThreshold); tester.setExpectedField(actualField); LazyKernelType* pKernel = dynamic_cast(spKernel.GetPointer()); CHECK(pKernel != NULL); bool validField = ::map::core::FieldDecomposer<2, 2>::decomposeKernel(pKernel, actualField); CHECK(validField); tester.setActualField(actualField); CHECK_TESTER(tester); CHECK(*(pKernel->getLargestPossibleRepresentation()) == *spInRep); pKernel = dynamic_cast(spKernel_noNull.GetPointer()); CHECK(pKernel != NULL); validField = ::map::core::FieldDecomposer<2, 2>::decomposeKernel(pKernel, actualField); CHECK(validField); tester.setActualField(actualField); CHECK_TESTER(tester); CHECK(*(pKernel->getLargestPossibleRepresentation()) == *spInRep); //*@TODO Noch Test fuer: wenn man ein meta file unterschiebt, dass die falsche Dimension hat, also .mapr noch richtige dimension und dann das meta image falsch. RETURN_AND_REPORT_TEST_SUCCESS; } } //namespace testing } //namespace map diff --git a/Code/IO/test/mapMatrixModelBasedKernelWriterTest.cpp b/Code/IO/test/mapMatrixModelBasedKernelWriterTest.cpp index 593613a..d7a13c9 100644 --- a/Code/IO/test/mapMatrixModelBasedKernelWriterTest.cpp +++ b/Code/IO/test/mapMatrixModelBasedKernelWriterTest.cpp @@ -1,107 +1,107 @@ // ----------------------------------------------------------------------- // MatchPoint - DKFZ translational registration framework // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See mapCopyright.txt or // http://www.dkfz.de/en/sidt/projects/MatchPoint/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision$ (last changed revision) // @date $Date$ (last change date) // @author $Author$ (last changed by) // Subversion HeadURL: $HeadURL$ */ #if defined(_MSC_VER) #pragma warning ( disable : 4786 ) #endif #include "itkEuler2DTransform.h" #include "itkBSplineTransform.h" #include "mapPreCachedRegistrationKernel.h" #include "mapLazyRegistrationKernel.h" #include "mapMatrixModelBasedKernelWriter.h" #include "mapSDXMLStrWriter.h" #include "litCheckMacros.h" #include "litTransformFieldTester.h" namespace map { namespace testing { int mapMatrixModelBasedKernelWriterTest(int argc, char* argv[]) { PREPARE_DEFAULT_TEST_REPORTING; typedef core::PreCachedRegistrationKernel<2, 2> KernelType; typedef core::LazyRegistrationKernel<2, 2> IllegalKernelType; typedef itk::Euler2DTransform< ::map::core::continuous::ScalarType> TransformType; //define non matrix-offset-decomposable type typedef itk::BSplineTransform< ::map::core::continuous::ScalarType,2,2> IllegalTransformType; typedef io::MatrixModelBasedKernelWriter<2, 2> WriterType; typedef io::MatrixModelBasedKernelWriter<2, 3> Writer23Type; KernelType::Pointer spKernel = KernelType::New(); TransformType::Pointer spTransform = TransformType::New(); TransformType::ParametersType params(3); params[0] = 1.5708; params[1] = 5; params[2] = 2; spTransform->SetParameters(params); spKernel->setTransformModel(spTransform); KernelType::Pointer spNonMatrixKernel = KernelType::New(); IllegalTransformType::Pointer spNonMatrixTransform = IllegalTransformType::New(); spNonMatrixKernel->setTransformModel(spNonMatrixTransform); IllegalKernelType::Pointer spIllegalKernel = IllegalKernelType::New(); WriterType::Pointer spWriter = WriterType::New(); WriterType::RequestType illegalRequest1(spIllegalKernel, "", "", false); WriterType::RequestType illegalRequest2(spNonMatrixKernel, "", "", false); WriterType::RequestType request(spKernel, "", "MatrixModelBasedWriterTest", false); CHECK_EQUAL(false, spWriter->canHandleRequest(illegalRequest1)); CHECK_EQUAL(false, spWriter->canHandleRequest(illegalRequest2)); CHECK_EQUAL(true, spWriter->canHandleRequest(request)); CHECK_EQUAL("MatrixModelBasedKernelWriter<2,2>", spWriter->getProviderName()); CHECK_EQUAL("MatrixModelBasedKernelWriter<2,3>", Writer23Type::getStaticProviderName()); //test processing of illegal requests CHECK_THROW_EXPLICIT(spWriter->storeKernel(illegalRequest1), core::ServiceException); CHECK_THROW_EXPLICIT(spWriter->storeKernel(illegalRequest2), core::ServiceException); //test valid request structuredData::Element::Pointer spData; CHECK_NO_THROW(spData = spWriter->storeKernel(request)); //test content structuredData::XMLStrWriter::Pointer spStrWriter = structuredData::XMLStrWriter::New(); ::map::core::String data = spStrWriter->write(spData); ::map::core::String ref = - "MatrixModelBasedKernelWriter<2,2>MatrixModelKernel-3.673205103e-006-1.0000000001.000000000-3.673205103e-006-3.67321e-006 -1 1 -3.67321e-006 5.0000000002.0000000005 2 "; + "MatrixModelBasedKernelWriter<2,2>MatrixModelKernel-3.673205103e-06-1.0000000001.000000000-3.673205103e-06-3.67321e-06 -1 1 -3.67321e-06 5.0000000002.0000000005 2 "; CHECK_EQUAL(ref, data); RETURN_AND_REPORT_TEST_SUCCESS; } } //namespace testing } //namespace map diff --git a/Code/IO/test/mapRegistrationFileWriterTest.cpp b/Code/IO/test/mapRegistrationFileWriterTest.cpp index add60b4..ca86bc0 100644 --- a/Code/IO/test/mapRegistrationFileWriterTest.cpp +++ b/Code/IO/test/mapRegistrationFileWriterTest.cpp @@ -1,184 +1,189 @@ // ----------------------------------------------------------------------- // MatchPoint - DKFZ translational registration framework // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See mapCopyright.txt or // http://www.dkfz.de/en/sidt/projects/MatchPoint/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision$ (last changed revision) // @date $Date$ (last change date) // @author $Author$ (last changed by) // Subversion HeadURL: $HeadURL$ */ #if defined(_MSC_VER) #pragma warning ( disable : 4786 ) #endif #include #include "litCheckMacros.h" #include "litTextFileTester.h" #include "mapMatrixModelBasedKernelWriter.h" #include "mapPreCachedRegistrationKernel.h" #include "mapRegistrationFileWriter.h" #include "test/mapTestKernelBase.h" #include "mapNullRegistrationKernel.h" #include "mapExpandingFieldKernelWriter.h" +#include "mapLazyFieldFileKernelWriter.h" namespace map { namespace testing { int mapRegistrationFileWriterTest(int argc, char* argv[]) { //ARGUMENTS: 1: test storage path // 2: ref path PREPARE_DEFAULT_TEST_REPORTING; std::string testPath = ""; std::string refPath = ""; if (argc > 1) { testPath = argv[1]; } if (argc > 2) { refPath = argv[2]; } std::string testRegFile1 = testPath + "/savedReg1.mapr"; std::string testRegFile2 = testPath + "/savedReg2.mapr"; std::string testRegFile3 = testPath + "/savedReg3.mapr"; std::string refRegFile1 = refPath + "/registrationFileWriterReader_Ref1.mapr"; std::string refRegFile2 = refPath + "/registrationFileWriterReader_Ref2.mapr"; std::string refRegFile3 = refPath + "/registrationFileWriterReader_Ref3.mapr"; // create the generator typedef io::RegistrationFileWriter<2, 2> WriterType; WriterType::Pointer spWriter = WriterType::New(); typedef WriterType::RegistrationType RegistrationType; // check whether the LoadPolicy worked for the stacks typedef WriterType::DirectKernelWriterStackType DirectStackType; typedef WriterType::InverseKernelWriterStackType InverseStackType; CHECK(NULL != DirectStackType::getProvider( io::MatrixModelBasedKernelWriter<2, 2>::getStaticProviderName())); CHECK(NULL != DirectStackType::getProvider( io::NullRegistrationKernelWriter<2, 2>::getStaticProviderName())); CHECK(NULL != DirectStackType::getProvider( io::ExpandingFieldKernelWriter<2, 2>::getStaticProviderName())); CHECK(NULL != DirectStackType::getProvider( io::InvertingKernelWriter<2, 2>::getStaticProviderName())); - CHECK(NULL != InverseStackType::getProvider( + CHECK(NULL != DirectStackType::getProvider( + io::LazyFieldFileKernelWriter<2, 2>::getStaticProviderName())); + CHECK(NULL != InverseStackType::getProvider( io::MatrixModelBasedKernelWriter<2, 2>::getStaticProviderName())); CHECK(NULL != InverseStackType::getProvider( io::NullRegistrationKernelWriter<2, 2>::getStaticProviderName())); CHECK(NULL != InverseStackType::getProvider( io::ExpandingFieldKernelWriter<2, 2>::getStaticProviderName())); CHECK(NULL != InverseStackType::getProvider( io::InvertingKernelWriter<2, 2>::getStaticProviderName())); + CHECK(NULL != InverseStackType::getProvider( + io::LazyFieldFileKernelWriter<2, 2>::getStaticProviderName())); // create a ModelBasedKernels for testing typedef core::PreCachedRegistrationKernel<2, 2> KernelType; KernelType::Pointer spKernel = KernelType::New(); KernelType::Pointer spKernel2 = KernelType::New(); typedef TestKernelBase<2, 2> IllegalKernelType; typedef core::NullRegistrationKernel<2, 2> NullKernelType; typedef ::itk::Euler2DTransform< ::map::core::continuous::ScalarType> TransformType; TransformType::Pointer spTransform = TransformType::New(); TransformType::Pointer spTransform2 = TransformType::New(); TransformType::ParametersType params(3); params[0] = 1.5708; params[1] = 5; params[2] = 2; spTransform->SetParameters(params); spKernel->setTransformModel(spTransform); TransformType::ParametersType params2(3); params2[0] = -1.5708; params2[1] = -5; params2[2] = -2; spTransform2->SetParameters(params2); spKernel2->setTransformModel(spTransform2); // create registrations for testing purposes // let the writer store the registration RegistrationType::Pointer spValidRegistration = RegistrationType::New(); ::map::core::RegistrationManipulator manipulator(spValidRegistration.GetPointer()); manipulator.setDirectMapping(spKernel); manipulator.setInverseMapping(NullKernelType::New()); ::map::core::RegistrationManipulator::TagMapType tags; tags.insert(std::make_pair("RegistrationUID", "RegistrationFileWriterTest.reg1")); manipulator.setTagValues(tags); RegistrationType::Pointer spValidRegistration2 = RegistrationType::New(); ::map::core::RegistrationManipulator manipulator2(spValidRegistration2.GetPointer()); manipulator2.setDirectMapping(NullKernelType::New()); manipulator2.setInverseMapping(spKernel); ::map::core::RegistrationManipulator::TagMapType tags2; tags2.insert(std::make_pair("RegistrationUID", "RegistrationFileWriterTest.reg2")); manipulator2.setTagValues(tags2); RegistrationType::Pointer spValidRegistration3 = RegistrationType::New(); ::map::core::RegistrationManipulator manipulator3(spValidRegistration3.GetPointer()); manipulator3.setDirectMapping(spKernel); manipulator3.setInverseMapping(spKernel2); ::map::core::RegistrationManipulator::TagMapType tags3; tags3.insert(std::make_pair("RegistrationUID", "RegistrationFileWriterTest.reg3")); tags3.insert(std::make_pair("Purpose", "UnitTest")); manipulator3.setTagValues(tags3); RegistrationType::Pointer spInvalidDirectKernelRegistration = RegistrationType::New(); ::map::core::RegistrationManipulator manipulator4( spInvalidDirectKernelRegistration.GetPointer()); manipulator4.setDirectMapping(IllegalKernelType::New()); manipulator4.setInverseMapping(spKernel2); RegistrationType::Pointer spInvalidInverseKernelRegistration = RegistrationType::New(); ::map::core::RegistrationManipulator manipulator5( spInvalidInverseKernelRegistration.GetPointer()); manipulator5.setDirectMapping(spKernel); manipulator5.setInverseMapping(IllegalKernelType::New()); CHECK_NO_THROW(spWriter->write(spValidRegistration, testRegFile1)); CHECK_NO_THROW(spWriter->write(spValidRegistration2, testRegFile2)); CHECK_NO_THROW(spWriter->write(spValidRegistration3, testRegFile3)); CHECK_THROW_EXPLICIT(spWriter->write(spInvalidDirectKernelRegistration, ""), core::MissingProviderException); CHECK_THROW_EXPLICIT(spWriter->write(spInvalidInverseKernelRegistration, ""), core::MissingProviderException); lit::TextFileTester tester; tester.setExpectedFile(refRegFile1); tester.setActualFile(testRegFile1); CHECK_TESTER(tester); tester.setExpectedFile(refRegFile2); tester.setActualFile(testRegFile2); CHECK_TESTER(tester); tester.setExpectedFile(refRegFile3); tester.setActualFile(testRegFile3); CHECK_TESTER(tester); RETURN_AND_REPORT_TEST_SUCCESS; } } //namespace testing } //namespace map diff --git a/Code/IO/tests.cmake b/Code/IO/tests.cmake index a4c7d81..b813397 100644 --- a/Code/IO/tests.cmake +++ b/Code/IO/tests.cmake @@ -1,20 +1,21 @@ SET(TEST_DATA_ROOT ${MatchPointTesting_SOURCE_DIR}/Data) SET(TEMP ${MatchPointTesting_BINARY_DIR}/Temporary) SET(EXAMPLES_DATA_ROOT "${MatchPoint_SOURCE_DIR}/Examples/Data") #----------------------------------------------------------------------------- IF(NOT UNIX) ADD_TEST(mapMatrixModelBasedKernelWriterTest ${MODULE_TESTS} mapMatrixModelBasedKernelWriterTest) ENDIF(NOT UNIX) ADD_TEST(mapMatrixModelBasedKernelLoaderTest ${MODULE_TESTS} mapMatrixModelBasedKernelLoaderTest) IF(NOT UNIX) ADD_TEST(mapRegistrationFileWriterTest ${MODULE_TESTS} mapRegistrationFileWriterTest "${TEMP}" "${TEST_DATA_ROOT}/Core") ENDIF(NOT UNIX) ADD_TEST(mapRegistrationFileReaderTest ${MODULE_TESTS} mapRegistrationFileReaderTest "${TEST_DATA_ROOT}/Core") ADD_TEST(mapNullRegistrationKernelWriterTest ${MODULE_TESTS} mapNullRegistrationKernelWriterTest) ADD_TEST(mapExpandingFieldKernelWriterTest ${MODULE_TESTS} mapExpandingFieldKernelWriterTest "${TEMP}" "${TEST_DATA_ROOT}/Core") ADD_TEST(mapFieldKernelLoaderTest ${MODULE_TESTS} mapFieldKernelLoaderTest "${TEMP}" "${TEST_DATA_ROOT}/Core") ADD_TEST(mapLazyFileFieldKernelLoaderTest ${MODULE_TESTS} mapLazyFileFieldKernelLoaderTest "${TEMP}" "${TEST_DATA_ROOT}/Core") ADD_TEST(mapInvertingKernelWriterTest ${MODULE_TESTS} mapInvertingKernelWriterTest "${TEMP}" "${TEST_DATA_ROOT}/Core") -ADD_TEST(mapInvertingKernelLoaderTest ${MODULE_TESTS} mapInvertingKernelLoaderTest "${TEMP}" "${TEST_DATA_ROOT}/Core") \ No newline at end of file +ADD_TEST(mapInvertingKernelLoaderTest ${MODULE_TESTS} mapInvertingKernelLoaderTest "${TEMP}" "${TEST_DATA_ROOT}/Core") +ADD_TEST(mapLazyFieldFileKernelWriterTest ${MODULE_TESTS} mapLazyFieldFileKernelWriterTest "${TEMP}" "${TEST_DATA_ROOT}/Core") \ No newline at end of file diff --git a/Testing/Data/Core/expandingFieldKernelWriterTest_ref.mhd b/Testing/Data/Core/expandingFieldKernelWriterTest_ref.mhd deleted file mode 100644 index 8da8f5a..0000000 --- a/Testing/Data/Core/expandingFieldKernelWriterTest_ref.mhd +++ /dev/null @@ -1,14 +0,0 @@ -ObjectType = Image -NDims = 2 -BinaryData = True -BinaryDataByteOrderMSB = False -CompressedData = False -TransformMatrix = 1 0 0 1 -Offset = 0 0 -CenterOfRotation = 0 0 -ElementSpacing = 0.5 0.5 -DimSize = 20 20 -AnatomicalOrientation = ?? -ElementNumberOfChannels = 2 -ElementType = MET_DOUBLE -ElementDataFile = expandingFieldKernelWriterTest_ref.raw diff --git a/Testing/Data/Core/expandingFieldKernelWriterTest_ref.nrrd b/Testing/Data/Core/expandingFieldKernelWriterTest_ref.nrrd new file mode 100644 index 0000000..233239d Binary files /dev/null and b/Testing/Data/Core/expandingFieldKernelWriterTest_ref.nrrd differ diff --git a/Testing/Data/Core/expandingFieldKernelWriterTest_ref.raw b/Testing/Data/Core/expandingFieldKernelWriterTest_ref.raw deleted file mode 100644 index acedc54..0000000 Binary files a/Testing/Data/Core/expandingFieldKernelWriterTest_ref.raw and /dev/null differ diff --git a/Testing/Data/Core/registrationFileWriterReader_Ref1.mapr b/Testing/Data/Core/registrationFileWriterReader_Ref1.mapr index 2babd31..f6db735 100644 --- a/Testing/Data/Core/registrationFileWriterReader_Ref1.mapr +++ b/Testing/Data/Core/registrationFileWriterReader_Ref1.mapr @@ -1,26 +1,26 @@ RegistrationFileWriterTest.reg1 2 2 MatrixModelBasedKernelWriter<2,2> MatrixModelKernel - -3.673205103e-006 + -3.673205103e-06 -1.000000000 1.000000000 - -3.673205103e-006 + -3.673205103e-06 - -3.67321e-006 -1 1 -3.67321e-006 + -3.67321e-06 -1 1 -3.67321e-06 5.000000000 2.000000000 5 2 NullRegistrationKernelWriter<2,2> NullRegistrationKernel diff --git a/Testing/Data/Core/registrationFileWriterReader_Ref2.mapr b/Testing/Data/Core/registrationFileWriterReader_Ref2.mapr index 1cc23c9..f3b57b0 100644 --- a/Testing/Data/Core/registrationFileWriterReader_Ref2.mapr +++ b/Testing/Data/Core/registrationFileWriterReader_Ref2.mapr @@ -1,26 +1,26 @@ RegistrationFileWriterTest.reg2 2 2 NullRegistrationKernelWriter<2,2> NullRegistrationKernel MatrixModelBasedKernelWriter<2,2> MatrixModelKernel - -3.673205103e-006 + -3.673205103e-06 -1.000000000 1.000000000 - -3.673205103e-006 + -3.673205103e-06 - -3.67321e-006 -1 1 -3.67321e-006 + -3.67321e-06 -1 1 -3.67321e-06 5.000000000 2.000000000 5 2 diff --git a/Testing/Data/Core/registrationFileWriterReader_Ref3.mapr b/Testing/Data/Core/registrationFileWriterReader_Ref3.mapr index 4ffb027..e32dcf3 100644 --- a/Testing/Data/Core/registrationFileWriterReader_Ref3.mapr +++ b/Testing/Data/Core/registrationFileWriterReader_Ref3.mapr @@ -1,39 +1,39 @@ UnitTest RegistrationFileWriterTest.reg3 2 2 MatrixModelBasedKernelWriter<2,2> MatrixModelKernel - -3.673205103e-006 + -3.673205103e-06 -1.000000000 1.000000000 - -3.673205103e-006 + -3.673205103e-06 - -3.67321e-006 -1 1 -3.67321e-006 + -3.67321e-06 -1 1 -3.67321e-06 5.000000000 2.000000000 5 2 MatrixModelBasedKernelWriter<2,2> MatrixModelKernel - -3.673205103e-006 + -3.673205103e-06 1.000000000 -1.000000000 - -3.673205103e-006 + -3.673205103e-06 - -3.67321e-006 1 -1 -3.67321e-006 + -3.67321e-06 1 -1 -3.67321e-06 -5.000000000 -2.000000000 -5 -2 diff --git a/Testing/Data/Core/registrationFileWriterReader_Ref4.mapr b/Testing/Data/Core/registrationFileWriterReader_Ref4.mapr index 55327f9..c392125 100644 --- a/Testing/Data/Core/registrationFileWriterReader_Ref4.mapr +++ b/Testing/Data/Core/registrationFileWriterReader_Ref4.mapr @@ -1,20 +1,20 @@ RegistrationFileWriterTest.reg4 2 2 ExpandingFieldKernelWriter<2,2> ExpandedFieldKernel - expandingFieldKernelWriterTest_ref.mhd + expandingFieldKernelWriterTest_ref.nrrd 1 -1.000000000 -2.000000000 NullRegistrationKernelWriter<2,2> NullRegistrationKernel diff --git a/Testing/Data/Core/registrationFileWriterReader_Ref4_legacy.mapr b/Testing/Data/Core/registrationFileWriterReader_Ref4_legacy.mapr index cfe9bd0..0176365 100644 --- a/Testing/Data/Core/registrationFileWriterReader_Ref4_legacy.mapr +++ b/Testing/Data/Core/registrationFileWriterReader_Ref4_legacy.mapr @@ -1,20 +1,20 @@ RegistrationFileWriterTest.reg4 2 2 ExpandingFieldKernelWriter<2,2> ExpandedFieldKernel - expandingFieldKernelWriterTest_ref.mhd + expandingFieldKernelWriterTest_ref.nrrd 1 -1.000000000 -2.000000000 NullRegistrationKernelWriter<2,2> NullRegistrationKernel diff --git a/Testing/Data/Core/registrationFileWriterReader_Ref5.mapr b/Testing/Data/Core/registrationFileWriterReader_Ref5.mapr index 8be9bc4..eff9d81 100644 --- a/Testing/Data/Core/registrationFileWriterReader_Ref5.mapr +++ b/Testing/Data/Core/registrationFileWriterReader_Ref5.mapr @@ -1,44 +1,44 @@ RegistrationFileReaderTest.invertingKernel1 2 2 ExpandingFieldKernelWriter<2,2> ExpandedFieldKernel - expandingFieldKernelWriterTest_ref.mhd + expandingFieldKernelWriterTest_ref.nrrd 1 -1.000000000 -2.000000000 InvertingFieldKernelWriter<2,2> InvertingFieldKernel 10.00000000 10.00000000 0.0000000000 0.0000000000 0.5000000000 0.5000000000 1.000000000 0.0000000000 0.0000000000 1.000000000 1 -1.000000000 -2.000000000 \ No newline at end of file diff --git a/Testing/Data/Core/registrationFileWriterReader_Ref6.mapr b/Testing/Data/Core/registrationFileWriterReader_Ref6.mapr index 2b5eb24..b883e43 100644 --- a/Testing/Data/Core/registrationFileWriterReader_Ref6.mapr +++ b/Testing/Data/Core/registrationFileWriterReader_Ref6.mapr @@ -1,40 +1,40 @@ RegistrationFileReaderTest.invertingKernel2 2 2 InvertingFieldKernelWriter<2,2> InvertingFieldKernel 10.00000000 10.00000000 0.0000000000 0.0000000000 0.5000000000 0.5000000000 1.000000000 0.0000000000 0.0000000000 1.000000000 0 ExpandingFieldKernelWriter<2,2> ExpandedFieldKernel - expandingFieldKernelWriterTest_ref.mhd + expandingFieldKernelWriterTest_ref.nrrd 1 -1.000000000 -2.000000000 \ No newline at end of file diff --git a/Testing/Data/Core/registrationFileWriterReader_Ref4.mapr b/Testing/Data/Core/registrationFileWriterReader_Ref7.mapr similarity index 80% copy from Testing/Data/Core/registrationFileWriterReader_Ref4.mapr copy to Testing/Data/Core/registrationFileWriterReader_Ref7.mapr index 55327f9..83ccad1 100644 --- a/Testing/Data/Core/registrationFileWriterReader_Ref4.mapr +++ b/Testing/Data/Core/registrationFileWriterReader_Ref7.mapr @@ -1,20 +1,20 @@ - RegistrationFileWriterTest.reg4 + RegistrationFileReaderTest.onlyInverseKernelAsField 2 2 + NullRegistrationKernelWriter<2,2> + NullRegistrationKernel + + ExpandingFieldKernelWriter<2,2> ExpandedFieldKernel - expandingFieldKernelWriterTest_ref.mhd + expandingFieldKernelWriterTest_ref.nrrd 1 -1.000000000 -2.000000000 - - NullRegistrationKernelWriter<2,2> - NullRegistrationKernel - - + \ No newline at end of file diff --git a/Testing/Data/Core/savedReg1.mapr b/Testing/Data/Core/savedReg1.mapr deleted file mode 100644 index 1c30088..0000000 --- a/Testing/Data/Core/savedReg1.mapr +++ /dev/null @@ -1,25 +0,0 @@ - - - 2 - 2 - - MatrixModelBasedKernelWriter<2,2> - MatrixModelKernel - - -3.673205103e-006 - -1.000000000 - 1.000000000 - -3.673205103e-006 - - -3.67321e-006 -1 1 -3.67321e-006 - - 5.000000000 - 2.000000000 - - 5 2 - - - NullRegistrationKernelWriter<2,2> - NullRegistrationKernel - - diff --git a/Testing/Data/Core/savedReg2.mapr b/Testing/Data/Core/savedReg2.mapr deleted file mode 100644 index 5c91445..0000000 --- a/Testing/Data/Core/savedReg2.mapr +++ /dev/null @@ -1,25 +0,0 @@ - - - 2 - 2 - - NullRegistrationKernelWriter<2,2> - NullRegistrationKernel - - - MatrixModelBasedKernelWriter<2,2> - MatrixModelKernel - - -3.673205103e-006 - -1.000000000 - 1.000000000 - -3.673205103e-006 - - -3.67321e-006 -1 1 -3.67321e-006 - - 5.000000000 - 2.000000000 - - 5 2 - - diff --git a/Testing/Data/Core/savedReg3.mapr b/Testing/Data/Core/savedReg3.mapr deleted file mode 100644 index 06fd98c..0000000 --- a/Testing/Data/Core/savedReg3.mapr +++ /dev/null @@ -1,39 +0,0 @@ - - - RegistrationFileWriterTest - UnitTest - 2 - 2 - - MatrixModelBasedKernelWriter<2,2> - MatrixModelKernel - - -3.673205103e-006 - -1.000000000 - 1.000000000 - -3.673205103e-006 - - -3.67321e-006 -1 1 -3.67321e-006 - - 5.000000000 - 2.000000000 - - 5 2 - - - MatrixModelBasedKernelWriter<2,2> - MatrixModelKernel - - -3.673205103e-006 - 1.000000000 - -1.000000000 - -3.673205103e-006 - - -3.67321e-006 1 -1 -3.67321e-006 - - -5.000000000 - -2.000000000 - - -5 -2 - -