diff --git a/Code/IO/test/mapLazyFieldFileKernelWriterTest.cpp b/Code/IO/test/mapLazyFieldFileKernelWriterTest.cpp index c0e56e9..b8ad536 100644 --- a/Code/IO/test/mapLazyFieldFileKernelWriterTest.cpp +++ b/Code/IO/test/mapLazyFieldFileKernelWriterTest.cpp @@ -1,150 +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_Ref6.mapr"); + 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_Ref6.mapr"); + 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/Testing/Data/Core/expandingFieldKernelWriterTest_ref.nrrd b/Testing/Data/Core/expandingFieldKernelWriterTest_ref.nrrd index da305e8..233239d 100644 Binary files a/Testing/Data/Core/expandingFieldKernelWriterTest_ref.nrrd and b/Testing/Data/Core/expandingFieldKernelWriterTest_ref.nrrd differ diff --git a/Testing/Data/Core/registrationFileWriterReader_Ref7.mapr b/Testing/Data/Core/registrationFileWriterReader_Ref7.mapr new file mode 100644 index 0000000..83ccad1 --- /dev/null +++ b/Testing/Data/Core/registrationFileWriterReader_Ref7.mapr @@ -0,0 +1,20 @@ + + + RegistrationFileReaderTest.onlyInverseKernelAsField + 2 + 2 + + NullRegistrationKernelWriter<2,2> + NullRegistrationKernel + + + ExpandingFieldKernelWriter<2,2> + ExpandedFieldKernel + expandingFieldKernelWriterTest_ref.nrrd + 1 + + -1.000000000 + -2.000000000 + + + \ No newline at end of file