From e53e2aa91cf28ad1531263b7d3fa3ccbfe9a9001 Mon Sep 17 00:00:00 2001 From: Esquis Benjamin <benjamin.esquis@csgroup.eu> Date: Thu, 22 Oct 2020 15:25:51 +0200 Subject: [PATCH] Added DirectionalLUT and done some cleanup --- CMakeLists.txt | 20 +- Code/Common/CMakeLists.txt | 33 + .../Common}/include/BaseImageTypes.h | 0 Code/Common/include/FileUtils.hpp | 81 ++ .../Common}/include/FluentXML.hpp | 0 {Common => Code/Common}/include/GlobalDefs.h | 0 .../Common}/include/ImageResampler.h | 4 +- Code/Common/include/Macros.h | 61 ++ .../Common}/include/ResamplingBandExtractor.h | 4 +- .../Common/include/StringUtils.hpp | 12 +- .../Common}/include/TestImageCreator.h | 0 .../Common/include/TinyXMLUtils.hpp | 0 Code/Common/include/Utils.h | 40 + .../Common}/include/VectorImageSplitter.h | 0 Code/Common/src/FileUtils.cpp | 71 ++ .../Common}/src/FluentXML.cpp | 0 {Common => Code/Common}/src/GlobalDefs.cpp | 0 .../Common/src/StringUtils.cpp | 49 +- .../Common/src/TinyXMLUtils.cpp | 2 +- Code/Common/test/CMakeLists.txt | 9 + .../Common}/test/test_ImageResampler.cpp | 0 .../CompositePreprocessing}/CMakeLists.txt | 15 +- .../include/ComputeNDVI.h | 0 .../include/CreateS2AnglesRaster.h | 3 +- .../include/DirectionalCorrection.h | 0 .../include/DirectionalCorrectionFunctor.h | 4 +- .../include}/DirectionalCorrectionFunctor.txx | 0 .../include/DirectionalCorrectionLUT.h | 138 ++++ .../include/DirectionalCorrectionLUTFilter.h | 156 ++++ .../DirectionalCorrectionLUTFilter.txx | 282 +++++++ .../include/DirectionalModel.h | 0 .../include/MaskExtractorFilter.h | 4 +- .../include}/MaskExtractorFilter.txx | 0 .../include/MaskExtractorFunctor.h | 0 .../include/PreprocessingAdapter.h | 0 .../include/PreprocessingSentinel.h | 0 .../include/PreprocessingVenus.h | 0 .../scattering_coeffs_10m.txt | 0 .../scattering_coeffs_20m.txt | 0 .../src/CompositePreprocessing.cpp | 1 - .../src/ComputeNDVI.cpp | 4 +- .../src/CreateS2AnglesRaster.cpp | 4 +- .../src/DirectionalCorrection.cpp | 5 + .../src/DirectionalCorrectionLUT.cpp | 168 ++++ .../src/DirectionalModel.cpp | 0 .../src/PreprocessingAdapter.cpp | 0 .../src/PreprocessingSentinel.cpp | 2 +- .../src/PreprocessingVenus.cpp | 0 .../test/CMakeLists.txt | 18 +- .../test/test_ComputeNDVI.cpp | 0 .../test/test_CreateS2AnglesRaster.cpp | 0 .../test/test_DirectionalCorrection.cpp | 0 .../test/test_DirectionalCorrectionLUT.cpp | 195 +++++ .../test/test_MaskExtractorFilter.cpp | 0 Code/LutReader/CMakeLists.txt | 33 + Code/LutReader/include/vnsLookUpTable.hpp | 195 +++++ Code/LutReader/include/vnsLookUpTable.txx | 271 ++++++ .../include/vnsLookUpTableExtractor.hpp | 104 +++ .../include/vnsLookUpTableExtractor.txx | 166 ++++ .../include/vnsLookUpTableFileReader.hpp | 769 ++++++++++++++++++ .../include/vnsLookUpTableFileReader.txx | 196 +++++ .../include/vnsSimpleLutXMLContainer.hpp | 134 +++ .../include/vnsSimpleLutXMLFileHandler.hpp | 64 ++ .../vnsVectorInterpolateImageFunction.hpp | 246 ++++++ ...nsVectorLinearInterpolateImageFunction.hpp | 153 ++++ ...nsVectorLinearInterpolateImageFunction.txx | 201 +++++ .../include/vnsVectorLookUpTable.hpp | 204 +++++ .../include/vnsVectorLookUpTable.txx | 462 +++++++++++ .../include/vnsVectorLookUpTableExtractor.hpp | 113 +++ .../include/vnsVectorLookUpTableExtractor.txx | 179 ++++ .../src/vnsSimpleLutXMLContainer.cxx | 92 +++ .../src/vnsSimpleLutXMLFileHandler.cxx | 146 ++++ Code/LutReader/test/CMakeLists.txt | 12 + .../test/test_SimpleLutXMLReader.cpp | 152 ++++ .../MetadataHelper}/CMakeLists.txt | 17 +- .../MetadataHelper}/include/MetadataAngles.h | 0 .../MetadataHelper}/include/MetadataBands.h | 0 .../MetadataHelper}/include/MetadataHelper.h | 0 .../include/MetadataHelperFactory.h | 0 .../include/MuscateMetadataHelper.h | 2 +- .../MetadataHelper}/src/MetadataBands.cpp | 0 .../MetadataHelper}/src/MetadataHelper.cpp | 0 .../src/MetadataHelperFactory.cpp | 3 +- .../src/MuscateMetadataHelper.cpp | 5 +- .../MetadataHelper}/test/CMakeLists.txt | 11 - .../test/test_MetadataBands.cpp | 0 .../test/test_MuscateMetadataHelper.cpp | 4 +- .../test/test_MuscateMetadataHelperVenus.cpp | 0 .../MuscateMetadata}/CMakeLists.txt | 22 +- .../include/MuscateMetadata.hpp | 0 .../include/MuscateMetadataReader.hpp | 0 .../include/MuscateMetadataUtil.hpp | 0 .../include/MuscateMetadataWriter.hpp | 0 .../include/MuscateViewingAngles.hpp | 0 .../src/MuscateMetadataReader.cpp | 6 +- .../src/MuscateMetadataUtil.cpp | 2 +- .../src/MuscateMetadataWriter.cpp | 4 +- .../src/MuscateViewingAngles.cpp | 4 +- .../MuscateMetadata}/test/CMakeLists.txt | 0 .../test/test_MuscateMetadataReadWrite.cpp | 2 +- .../test/test_MuscateMetadataReader.cpp | 0 .../test/test_MuscateMetadataWriteRead.cpp | 2 +- .../ProductFormatter}/CMakeLists.txt | 0 .../include/ProductCreatorAdapter.h | 0 .../include/ProductCreatorSentinelMuscate.h | 0 .../include/ProductCreatorVenusMuscate.h | 0 .../include/ProductDefinitions.h | 0 .../src/ProductCreatorAdapter.cpp | 0 .../src/ProductCreatorSentinelMuscate.cpp | 4 +- .../src/ProductCreatorVenusMuscate.cpp | 2 +- .../src/ProductFormatter.cpp | 3 +- .../ProductFormatter}/test/CMakeLists.txt | 0 .../UpdateSynthesis}/CMakeLists.txt | 0 .../UpdateSynthesis}/include/BandsDefs.h | 0 .../include/UpdateSynthesisFunctor.h | 0 .../UpdateSynthesis}/src/UpdateSynthesis.cpp | 21 +- .../src/UpdateSynthesisFunctor.txx | 2 +- .../UpdateSynthesis}/test/CMakeLists.txt | 0 .../WeightCalculation}/CMakeLists.txt | 0 .../TotalWeight/CMakeLists.txt | 0 .../include/TotalWeightComputation.h | 0 .../TotalWeight/src/TotalWeight.cpp | 1 - .../src/TotalWeightComputation.cpp | 18 +- .../TotalWeight/test/CMakeLists.txt | 0 .../WeightAOT/CMakeLists.txt | 0 .../WeightAOT/include/WeightAOTComputation.h | 0 .../WeightAOT/src/WeightAOT.cpp | 1 - .../WeightAOT/src/WeightAOTComputation.cpp | 2 +- .../WeightAOT/test/CMakeLists.txt | 0 .../WeightOnClouds/CMakeLists.txt | 0 .../include/CloudMaskBinarization.h | 6 +- .../include/CloudWeightComputation.h | 4 +- .../include/CloudsInterpolation.h | 8 +- .../include/CuttingImageFilter.h | 4 +- .../WeightOnClouds/include/GaussianFilter.h | 4 +- .../include/PaddingImageHandler.h | 8 +- .../WeightOnClouds/include/ROIImageFilter.h | 0 .../WeightOnClouds/src/WeightOnClouds.cpp | 1 - .../WeightOnClouds/test/CMakeLists.txt | 0 .../include/DirectionalCorrectionFilter.h | 240 ------ 140 files changed, 5303 insertions(+), 387 deletions(-) create mode 100644 Code/Common/CMakeLists.txt rename {Common => Code/Common}/include/BaseImageTypes.h (100%) create mode 100644 Code/Common/include/FileUtils.hpp rename {MuscateMetadata => Code/Common}/include/FluentXML.hpp (100%) rename {Common => Code/Common}/include/GlobalDefs.h (100%) rename {Common => Code/Common}/include/ImageResampler.h (98%) create mode 100644 Code/Common/include/Macros.h rename {Common => Code/Common}/include/ResamplingBandExtractor.h (98%) rename MuscateMetadata/include/string_utils.hpp => Code/Common/include/StringUtils.hpp (80%) rename {Common => Code/Common}/include/TestImageCreator.h (100%) rename MuscateMetadata/include/tinyxml_utils.hpp => Code/Common/include/TinyXMLUtils.hpp (100%) create mode 100644 Code/Common/include/Utils.h rename {Common => Code/Common}/include/VectorImageSplitter.h (100%) create mode 100644 Code/Common/src/FileUtils.cpp rename {MuscateMetadata => Code/Common}/src/FluentXML.cpp (100%) rename {Common => Code/Common}/src/GlobalDefs.cpp (100%) rename MuscateMetadata/src/string_utils.cpp => Code/Common/src/StringUtils.cpp (57%) rename MuscateMetadata/src/tinyxml_utils.cpp => Code/Common/src/TinyXMLUtils.cpp (98%) create mode 100644 Code/Common/test/CMakeLists.txt rename {Common => Code/Common}/test/test_ImageResampler.cpp (100%) rename {CompositePreprocessing => Code/CompositePreprocessing}/CMakeLists.txt (59%) rename {CompositePreprocessing => Code/CompositePreprocessing}/include/ComputeNDVI.h (100%) rename {CompositePreprocessing => Code/CompositePreprocessing}/include/CreateS2AnglesRaster.h (98%) rename {CompositePreprocessing => Code/CompositePreprocessing}/include/DirectionalCorrection.h (100%) rename {CompositePreprocessing => Code/CompositePreprocessing}/include/DirectionalCorrectionFunctor.h (96%) rename {CompositePreprocessing/src => Code/CompositePreprocessing/include}/DirectionalCorrectionFunctor.txx (100%) create mode 100644 Code/CompositePreprocessing/include/DirectionalCorrectionLUT.h create mode 100644 Code/CompositePreprocessing/include/DirectionalCorrectionLUTFilter.h create mode 100644 Code/CompositePreprocessing/include/DirectionalCorrectionLUTFilter.txx rename {CompositePreprocessing => Code/CompositePreprocessing}/include/DirectionalModel.h (100%) rename {CompositePreprocessing => Code/CompositePreprocessing}/include/MaskExtractorFilter.h (97%) rename {CompositePreprocessing/src => Code/CompositePreprocessing/include}/MaskExtractorFilter.txx (100%) rename {CompositePreprocessing => Code/CompositePreprocessing}/include/MaskExtractorFunctor.h (100%) rename {CompositePreprocessing => Code/CompositePreprocessing}/include/PreprocessingAdapter.h (100%) rename {CompositePreprocessing => Code/CompositePreprocessing}/include/PreprocessingSentinel.h (100%) rename {CompositePreprocessing => Code/CompositePreprocessing}/include/PreprocessingVenus.h (100%) rename {CompositePreprocessing => Code/CompositePreprocessing}/scattering_coeffs_10m.txt (100%) rename {CompositePreprocessing => Code/CompositePreprocessing}/scattering_coeffs_20m.txt (100%) rename {CompositePreprocessing => Code/CompositePreprocessing}/src/CompositePreprocessing.cpp (99%) rename {CompositePreprocessing => Code/CompositePreprocessing}/src/ComputeNDVI.cpp (96%) rename {CompositePreprocessing => Code/CompositePreprocessing}/src/CreateS2AnglesRaster.cpp (97%) rename {CompositePreprocessing => Code/CompositePreprocessing}/src/DirectionalCorrection.cpp (99%) create mode 100644 Code/CompositePreprocessing/src/DirectionalCorrectionLUT.cpp rename {CompositePreprocessing => Code/CompositePreprocessing}/src/DirectionalModel.cpp (100%) rename {CompositePreprocessing => Code/CompositePreprocessing}/src/PreprocessingAdapter.cpp (100%) rename {CompositePreprocessing => Code/CompositePreprocessing}/src/PreprocessingSentinel.cpp (96%) rename {CompositePreprocessing => Code/CompositePreprocessing}/src/PreprocessingVenus.cpp (100%) rename {CompositePreprocessing => Code/CompositePreprocessing}/test/CMakeLists.txt (77%) rename {CompositePreprocessing => Code/CompositePreprocessing}/test/test_ComputeNDVI.cpp (100%) rename {CompositePreprocessing => Code/CompositePreprocessing}/test/test_CreateS2AnglesRaster.cpp (100%) rename {CompositePreprocessing => Code/CompositePreprocessing}/test/test_DirectionalCorrection.cpp (100%) create mode 100644 Code/CompositePreprocessing/test/test_DirectionalCorrectionLUT.cpp rename {CompositePreprocessing => Code/CompositePreprocessing}/test/test_MaskExtractorFilter.cpp (100%) create mode 100644 Code/LutReader/CMakeLists.txt create mode 100644 Code/LutReader/include/vnsLookUpTable.hpp create mode 100644 Code/LutReader/include/vnsLookUpTable.txx create mode 100644 Code/LutReader/include/vnsLookUpTableExtractor.hpp create mode 100644 Code/LutReader/include/vnsLookUpTableExtractor.txx create mode 100644 Code/LutReader/include/vnsLookUpTableFileReader.hpp create mode 100644 Code/LutReader/include/vnsLookUpTableFileReader.txx create mode 100644 Code/LutReader/include/vnsSimpleLutXMLContainer.hpp create mode 100644 Code/LutReader/include/vnsSimpleLutXMLFileHandler.hpp create mode 100644 Code/LutReader/include/vnsVectorInterpolateImageFunction.hpp create mode 100644 Code/LutReader/include/vnsVectorLinearInterpolateImageFunction.hpp create mode 100644 Code/LutReader/include/vnsVectorLinearInterpolateImageFunction.txx create mode 100644 Code/LutReader/include/vnsVectorLookUpTable.hpp create mode 100644 Code/LutReader/include/vnsVectorLookUpTable.txx create mode 100644 Code/LutReader/include/vnsVectorLookUpTableExtractor.hpp create mode 100644 Code/LutReader/include/vnsVectorLookUpTableExtractor.txx create mode 100644 Code/LutReader/src/vnsSimpleLutXMLContainer.cxx create mode 100644 Code/LutReader/src/vnsSimpleLutXMLFileHandler.cxx create mode 100644 Code/LutReader/test/CMakeLists.txt create mode 100644 Code/LutReader/test/test_SimpleLutXMLReader.cpp rename {Common => Code/MetadataHelper}/CMakeLists.txt (57%) rename {Common => Code/MetadataHelper}/include/MetadataAngles.h (100%) rename {Common => Code/MetadataHelper}/include/MetadataBands.h (100%) rename {Common => Code/MetadataHelper}/include/MetadataHelper.h (100%) rename {Common => Code/MetadataHelper}/include/MetadataHelperFactory.h (100%) rename {Common => Code/MetadataHelper}/include/MuscateMetadataHelper.h (98%) rename {Common => Code/MetadataHelper}/src/MetadataBands.cpp (100%) rename {Common => Code/MetadataHelper}/src/MetadataHelper.cpp (100%) rename {Common => Code/MetadataHelper}/src/MetadataHelperFactory.cpp (96%) rename {Common => Code/MetadataHelper}/src/MuscateMetadataHelper.cpp (99%) rename {Common => Code/MetadataHelper}/test/CMakeLists.txt (77%) rename {Common => Code/MetadataHelper}/test/test_MetadataBands.cpp (100%) rename {Common => Code/MetadataHelper}/test/test_MuscateMetadataHelper.cpp (99%) rename {Common => Code/MetadataHelper}/test/test_MuscateMetadataHelperVenus.cpp (100%) rename {MuscateMetadata => Code/MuscateMetadata}/CMakeLists.txt (60%) rename {MuscateMetadata => Code/MuscateMetadata}/include/MuscateMetadata.hpp (100%) rename {MuscateMetadata => Code/MuscateMetadata}/include/MuscateMetadataReader.hpp (100%) rename MuscateMetadata/include/MetadataUtil.hpp => Code/MuscateMetadata/include/MuscateMetadataUtil.hpp (100%) rename {MuscateMetadata => Code/MuscateMetadata}/include/MuscateMetadataWriter.hpp (100%) rename MuscateMetadata/include/ViewingAngles.hpp => Code/MuscateMetadata/include/MuscateViewingAngles.hpp (100%) rename {MuscateMetadata => Code/MuscateMetadata}/src/MuscateMetadataReader.cpp (99%) rename MuscateMetadata/src/MetadataUtil.cpp => Code/MuscateMetadata/src/MuscateMetadataUtil.cpp (99%) rename {MuscateMetadata => Code/MuscateMetadata}/src/MuscateMetadataWriter.cpp (99%) rename MuscateMetadata/src/ViewingAngles.cpp => Code/MuscateMetadata/src/MuscateViewingAngles.cpp (98%) rename {MuscateMetadata => Code/MuscateMetadata}/test/CMakeLists.txt (100%) rename {MuscateMetadata => Code/MuscateMetadata}/test/test_MuscateMetadataReadWrite.cpp (99%) rename {MuscateMetadata => Code/MuscateMetadata}/test/test_MuscateMetadataReader.cpp (100%) rename {MuscateMetadata => Code/MuscateMetadata}/test/test_MuscateMetadataWriteRead.cpp (99%) rename {ProductFormatter => Code/ProductFormatter}/CMakeLists.txt (100%) rename {ProductFormatter => Code/ProductFormatter}/include/ProductCreatorAdapter.h (100%) rename {ProductFormatter => Code/ProductFormatter}/include/ProductCreatorSentinelMuscate.h (100%) rename {ProductFormatter => Code/ProductFormatter}/include/ProductCreatorVenusMuscate.h (100%) rename {ProductFormatter => Code/ProductFormatter}/include/ProductDefinitions.h (100%) rename {ProductFormatter => Code/ProductFormatter}/src/ProductCreatorAdapter.cpp (100%) rename {ProductFormatter => Code/ProductFormatter}/src/ProductCreatorSentinelMuscate.cpp (99%) rename {ProductFormatter => Code/ProductFormatter}/src/ProductCreatorVenusMuscate.cpp (99%) rename {ProductFormatter => Code/ProductFormatter}/src/ProductFormatter.cpp (99%) rename {ProductFormatter => Code/ProductFormatter}/test/CMakeLists.txt (100%) rename {UpdateSynthesis => Code/UpdateSynthesis}/CMakeLists.txt (100%) rename {UpdateSynthesis => Code/UpdateSynthesis}/include/BandsDefs.h (100%) rename {UpdateSynthesis => Code/UpdateSynthesis}/include/UpdateSynthesisFunctor.h (100%) rename {UpdateSynthesis => Code/UpdateSynthesis}/src/UpdateSynthesis.cpp (96%) rename {UpdateSynthesis => Code/UpdateSynthesis}/src/UpdateSynthesisFunctor.txx (99%) rename {UpdateSynthesis => Code/UpdateSynthesis}/test/CMakeLists.txt (100%) rename {WeightCalculation => Code/WeightCalculation}/CMakeLists.txt (100%) rename {WeightCalculation => Code/WeightCalculation}/TotalWeight/CMakeLists.txt (100%) rename {WeightCalculation => Code/WeightCalculation}/TotalWeight/include/TotalWeightComputation.h (100%) rename {WeightCalculation => Code/WeightCalculation}/TotalWeight/src/TotalWeight.cpp (99%) rename {WeightCalculation => Code/WeightCalculation}/TotalWeight/src/TotalWeightComputation.cpp (92%) rename {WeightCalculation => Code/WeightCalculation}/TotalWeight/test/CMakeLists.txt (100%) rename {WeightCalculation => Code/WeightCalculation}/WeightAOT/CMakeLists.txt (100%) rename {WeightCalculation => Code/WeightCalculation}/WeightAOT/include/WeightAOTComputation.h (100%) rename {WeightCalculation => Code/WeightCalculation}/WeightAOT/src/WeightAOT.cpp (99%) rename {WeightCalculation => Code/WeightCalculation}/WeightAOT/src/WeightAOTComputation.cpp (98%) rename {WeightCalculation => Code/WeightCalculation}/WeightAOT/test/CMakeLists.txt (100%) rename {WeightCalculation => Code/WeightCalculation}/WeightOnClouds/CMakeLists.txt (100%) rename {WeightCalculation => Code/WeightCalculation}/WeightOnClouds/include/CloudMaskBinarization.h (98%) rename {WeightCalculation => Code/WeightCalculation}/WeightOnClouds/include/CloudWeightComputation.h (98%) rename {WeightCalculation => Code/WeightCalculation}/WeightOnClouds/include/CloudsInterpolation.h (97%) rename {WeightCalculation => Code/WeightCalculation}/WeightOnClouds/include/CuttingImageFilter.h (98%) rename {WeightCalculation => Code/WeightCalculation}/WeightOnClouds/include/GaussianFilter.h (98%) rename {WeightCalculation => Code/WeightCalculation}/WeightOnClouds/include/PaddingImageHandler.h (98%) rename {WeightCalculation => Code/WeightCalculation}/WeightOnClouds/include/ROIImageFilter.h (100%) rename {WeightCalculation => Code/WeightCalculation}/WeightOnClouds/src/WeightOnClouds.cpp (99%) rename {WeightCalculation => Code/WeightCalculation}/WeightOnClouds/test/CMakeLists.txt (100%) delete mode 100644 CompositePreprocessing/include/DirectionalCorrectionFilter.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 3eac9b6..12f45a2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,12 @@ find_program(BASH_Program bash) include(${OTB_USE_FILE}) include(FindPythonInterp) +#Include source directory to includes +INCLUDE_DIRECTORIES( +${PROJECT_SOURCE_DIR}/Code/Common/include +${PROJECT_SOURCE_DIR}/Code/LutReader/include +) + # Set a default build type if none was specified set(default_build_type "Release") @@ -32,12 +38,14 @@ add_definitions(-DBOOST_TEST_DYN_LINK) message("Project binary folder:" ${PROJECT_BINARY_DIR}) add_definitions(-DVCL_CAN_STATIC_CONST_INIT_FLOAT=0) -add_subdirectory(Common) -add_subdirectory(MuscateMetadata) -add_subdirectory(CompositePreprocessing) -add_subdirectory(WeightCalculation) -add_subdirectory(UpdateSynthesis) -add_subdirectory(ProductFormatter) +add_subdirectory(Code/Common) +add_subdirectory(Code/MetadataHelper) +add_subdirectory(Code/MuscateMetadata) +add_subdirectory(Code/LutReader) +add_subdirectory(Code/CompositePreprocessing) +add_subdirectory(Code/WeightCalculation) +add_subdirectory(Code/UpdateSynthesis) +add_subdirectory(Code/ProductFormatter) add_subdirectory(PythonScripts) install(FILES ./Scripts/WASP PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE GROUP_EXECUTE WORLD_EXECUTE DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) diff --git a/Code/Common/CMakeLists.txt b/Code/Common/CMakeLists.txt new file mode 100644 index 0000000..e7219cd --- /dev/null +++ b/Code/Common/CMakeLists.txt @@ -0,0 +1,33 @@ +set(Common_HEADERS + include/FluentXML.hpp + include/GlobalDefs.h + include/ResamplingBandExtractor.h + include/ImageResampler.h + include/TestImageCreator.h + include/FileUtils.hpp + include/TinyXMLUtils.hpp + include/StringUtils.hpp +) + +set(Common_SOURCES + src/FluentXML.cpp + src/GlobalDefs.cpp + src/FileUtils.cpp + src/TinyXMLUtils.cpp + src/StringUtils.cpp +) + +add_library(Common SHARED ${Common_HEADERS} ${Common_SOURCES}) +target_link_libraries(Common + "${Boost_LIBRARIES}" + "${OTBCommon_LIBRARIES}" + "${OTBITK_LIBRARIES}" + "${OTBTinyXML_LIBRARIES}" + ) + +target_include_directories(Common PUBLIC include) +install(TARGETS Common DESTINATION lib/) + +if(BUILD_TESTING) + add_subdirectory(test) +endif() diff --git a/Common/include/BaseImageTypes.h b/Code/Common/include/BaseImageTypes.h similarity index 100% rename from Common/include/BaseImageTypes.h rename to Code/Common/include/BaseImageTypes.h diff --git a/Code/Common/include/FileUtils.hpp b/Code/Common/include/FileUtils.hpp new file mode 100644 index 0000000..79b93d2 --- /dev/null +++ b/Code/Common/include/FileUtils.hpp @@ -0,0 +1,81 @@ + +/* + * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) + * All rights reserved + * + * This file is part of Weighted Average Synthesis Processor (WASP) + * + * Authors: + * - Esquis Benjamin <benjamin.esquis@csgroup.eu> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * See the LICENSE.md file for more details. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +#ifndef COMMON_FILE_UTILS_HPP_ +#define COMMON_FILE_UTILS_HPP_ +#include <string> +#include <vector> + +/** + * @brief Split string by a char delimiter + * @param s The string to be splitted + * @param delim The delimiter, occuring [0...*] + * @param remove_empty bool to remove empty values + * @return A vector containing all the splitted substrings + */ +void RelativeToAbsoluteFilename(const std::string & path, std::vector<std::string> & listOfFilename); + +/** + * @brief Split string by a char delimiter + * @param s The string to be splitted + * @param delim The delimiter, occuring [0...*] + * @param remove_empty bool to remove empty values + * @return A vector containing all the splitted substrings + */ +void CheckingExistenceFilenames(const std::vector<std::string> & listOfFilename); + +/** + * @brief Split string by a char delimiter + * @param s The string to be splitted + * @param delim The delimiter, occuring [0...*] + * @param remove_empty bool to remove empty values + * @return A vector containing all the splitted substrings + */ +void CheckingExistenceFilename(const std::string & Filename); + +/** + * @brief Split string by a char delimiter + * @param s The string to be splitted + * @param delim The delimiter, occuring [0...*] + * @param remove_empty bool to remove empty values + * @return A vector containing all the splitted substrings + */ +void CheckingExistenceDirectory(const std::string & Filename); + +/** + * @brief Split string by a char delimiter + * @param s The string to be splitted + * @param delim The delimiter, occuring [0...*] + * @param remove_empty bool to remove empty values + * @return A vector containing all the splitted substrings + */ +std::string JoinFilenames(const std::string& filename1, const std::string& filename2); + + +#endif + + diff --git a/MuscateMetadata/include/FluentXML.hpp b/Code/Common/include/FluentXML.hpp similarity index 100% rename from MuscateMetadata/include/FluentXML.hpp rename to Code/Common/include/FluentXML.hpp diff --git a/Common/include/GlobalDefs.h b/Code/Common/include/GlobalDefs.h similarity index 100% rename from Common/include/GlobalDefs.h rename to Code/Common/include/GlobalDefs.h diff --git a/Common/include/ImageResampler.h b/Code/Common/include/ImageResampler.h similarity index 98% rename from Common/include/ImageResampler.h rename to Code/Common/include/ImageResampler.h index 51d3f03..68c5400 100644 --- a/Common/include/ImageResampler.h +++ b/Code/Common/include/ImageResampler.h @@ -158,7 +158,7 @@ public: */ ResamplerPtr getResampler(const ResamplerInputImgPtr& image, const OutputVectorType& scale, int forcedWidth, int forcedHeight, Interpolator_Type interpolatorType=Interpolator_Linear) { - ResamplerInputImgSpacingType spacing = image->GetSpacing(); + ResamplerInputImgSpacingType spacing = image->GetSignedSpacing(); typename TOutput::PointType origin = image->GetOrigin(); typename TOutput::PointType outputOrigin; outputOrigin[0] = std::round(origin[0] + 0.5 * spacing[0] * (scale[0] - 1.0)); @@ -212,7 +212,7 @@ public: resampler->SetOutputParametersFromImage( image ); // Evaluate spacing - ResamplerInputImgSpacingType spacing = image->GetSpacing(); + ResamplerInputImgSpacingType spacing = image->GetSignedSpacing(); ResamplerInputImgSpacingType OutputSpacing; OutputSpacing[0] = std::round(spacing[0] * scale[0]); OutputSpacing[1] = std::round(spacing[1] * scale[1]); diff --git a/Code/Common/include/Macros.h b/Code/Common/include/Macros.h new file mode 100644 index 0000000..cf15739 --- /dev/null +++ b/Code/Common/include/Macros.h @@ -0,0 +1,61 @@ + +/* + * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) + * All rights reserved + * + * This file is part of Weighted Average Synthesis Processor (WASP) + * + * Authors: + * - Esquis Benjamin <benjamin.esquis@csgroup.eu> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * See the LICENSE.md file for more details. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#include "itkMacro.h" + +/** Macro to define Set/GetInput method */ +#define SetGetInputMacro(name,type,index) \ + /* ---------------------------------------------------------------------------------------------*/ \ + /* Set the ##name## Input image */ \ + void Set##name##Input( const type *object) \ + {\ + /* set the pointer */ \ + this->itk::ProcessObject::SetNthInput(index,const_cast<type*>(object)); \ + } \ + /* ---------------------------------------------------------------------------------------------*/ \ + /* Get the ##name## Input image */ \ + type * Get##name##Input() \ + { \ + /* return the pointer */ \ + return itkDynamicCastInDebugMode< type * >( this->itk::ProcessObject::GetInput(index) ); \ + } \ + /* ---------------------------------------------------------------------------------------------*/ \ + /* Get the ##name## Input image */ \ + const type * Get##name##Input() const \ + { \ + /* return the pointer */ \ + return itkDynamicCastInDebugMode< const type * >( this->itk::ProcessObject::GetInput(index) ); \ + } + +/** Get a smart pointer to an object. Creates the member + * Get"name"() (e.g., GetPoints()). */ +# define itkGetObjectMacro(name, type) \ + virtual type * Get##name () \ + { \ + return this->m_##name.GetPointer(); \ + } diff --git a/Common/include/ResamplingBandExtractor.h b/Code/Common/include/ResamplingBandExtractor.h similarity index 98% rename from Common/include/ResamplingBandExtractor.h rename to Code/Common/include/ResamplingBandExtractor.h index b836008..7b9fceb 100644 --- a/Common/include/ResamplingBandExtractor.h +++ b/Code/Common/include/ResamplingBandExtractor.h @@ -85,7 +85,7 @@ public: reader->SetFileName(filePath); reader->UpdateOutputInformation(); if(nDesiredRes > 0 && nCurRes == -1) { - nCurRes = reader->GetOutput()->GetSpacing()[0]; + nCurRes = reader->GetOutput()->GetSignedSpacing()[0]; } return ExtractImgResampledBand(reader->GetOutput(), nChannel, interpolator, nCurRes,nDesiredRes, @@ -105,7 +105,7 @@ public: reader->SetFileName(filePath); reader->UpdateOutputInformation(); if(nDesiredRes > 0 && nCurRes == -1) { - nCurRes = reader->GetOutput()->GetSpacing()[0]; + nCurRes = reader->GetOutput()->GetSignedSpacing()[0]; } return ExtractAllResampledBands(reader->GetOutput(), outList, interpolator, nCurRes, nDesiredRes, nForcedOutWidth, nForcedOutHeight); diff --git a/MuscateMetadata/include/string_utils.hpp b/Code/Common/include/StringUtils.hpp similarity index 80% rename from MuscateMetadata/include/string_utils.hpp rename to Code/Common/include/StringUtils.hpp index 9614c61..a288a2c 100644 --- a/MuscateMetadata/include/string_utils.hpp +++ b/Code/Common/include/StringUtils.hpp @@ -30,9 +30,10 @@ * @brief Split string by a char delimiter * @param s The string to be splitted * @param delim The delimiter, occuring [0...*] + * @param remove_empty bool to remove empty values * @return A vector containing all the splitted substrings */ -std::vector<std::string> split(const std::string &s, char delim); +std::vector<std::string> split(const std::string &s, char delim, const bool remove_empty = false); /** * @brief Read a double value from a given string @@ -41,6 +42,15 @@ std::vector<std::string> split(const std::string &s, char delim); */ double ReadDouble(const std::string &s); +/** + * @brief Read a double list value from a given string + * @param string The string list containing double separated by a space + * @param separator The delimiter, occuring [0...*] + * @param remove_empty bool to remove empty values + * @return The double list value + */ +std::vector<double> ReadDoubleList(const std::string& string, char separator = ' ', bool remove_empty = false); + /** * @brief Check if a string contains only digits * @param s The string to be checked diff --git a/Common/include/TestImageCreator.h b/Code/Common/include/TestImageCreator.h similarity index 100% rename from Common/include/TestImageCreator.h rename to Code/Common/include/TestImageCreator.h diff --git a/MuscateMetadata/include/tinyxml_utils.hpp b/Code/Common/include/TinyXMLUtils.hpp similarity index 100% rename from MuscateMetadata/include/tinyxml_utils.hpp rename to Code/Common/include/TinyXMLUtils.hpp diff --git a/Code/Common/include/Utils.h b/Code/Common/include/Utils.h new file mode 100644 index 0000000..3e742cf --- /dev/null +++ b/Code/Common/include/Utils.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2015-2016, CS Romania <office@c-s.ro> + * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) + * All rights reversed + * + * This file is part of: + * - Sen2agri-Processors (initial work) + * - Weighted Average Synthesis Processor (WASP) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. +* + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#include <math.h> + + +/** + * @brief Split string by a char delimiter + * @param s The string to be splitted + * @param delim The delimiter, occuring [0...*] + * @param remove_empty bool to remove empty values + * @return A vector containing all the splitted substrings + */ +template <class T> +bool compareValueWithEpsilon(const T &first, const T &second, const double epsilon= 1e-5) +{ + return fabs(first - second) < epsilon; +} diff --git a/Common/include/VectorImageSplitter.h b/Code/Common/include/VectorImageSplitter.h similarity index 100% rename from Common/include/VectorImageSplitter.h rename to Code/Common/include/VectorImageSplitter.h diff --git a/Code/Common/src/FileUtils.cpp b/Code/Common/src/FileUtils.cpp new file mode 100644 index 0000000..c30b587 --- /dev/null +++ b/Code/Common/src/FileUtils.cpp @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) + * All rights reserved + * + * This file is part of Weighted Average Synthesis Processor (WASP) + * + * Authors: + * - Esquis Benjamin <benjamin.esquis@csgroup.eu> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * See the LICENSE.md file for more details. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#include <FileUtils.hpp> +#include "itksys/SystemTools.hxx" + +void RelativeToAbsoluteFilename(const std::string & path, std::vector<std::string> & listOfFilename) +{ + const unsigned int nbFilenames(listOfFilename.size()); + for (unsigned int i = 0; i < nbFilenames; i++) + { + listOfFilename[i] = JoinFilenames(path, listOfFilename[i]); + } +} + +void CheckingExistenceFilenames(const std::vector<std::string> & listOfFilename) +{ + const unsigned int nbFilenames(listOfFilename.size()); + for (unsigned int i = 0; i < nbFilenames; i++) + { + CheckingExistenceFilename(listOfFilename[i]); + } +} + +std::string JoinFilenames(const std::string& filename1, const std::string& filename2) +{ + std::string relativePath(filename1); + const std::string relativeName(filename2); + if ((relativePath.size() && relativePath[relativePath.size() - 1] != '/') && (relativeName.size() && relativeName[0] != '/')) + { + relativePath += "/"; + } + return relativePath + filename2; +} + +void CheckingExistenceFilename(const std::string & Filename) +{ + if (itksys::SystemTools::FileExists(Filename) == false) + { + throw std::runtime_error("Utilities::CheckingExtentFilenames: The filename " + Filename + " doesn't exist !"); + } + if (itksys::SystemTools::FileIsDirectory(Filename) == true) + { + throw std::runtime_error( + "Utilities::CheckingExtentFilenames: The filename " + Filename + " doesn't exist. It's a directory !"); + } +} diff --git a/MuscateMetadata/src/FluentXML.cpp b/Code/Common/src/FluentXML.cpp similarity index 100% rename from MuscateMetadata/src/FluentXML.cpp rename to Code/Common/src/FluentXML.cpp diff --git a/Common/src/GlobalDefs.cpp b/Code/Common/src/GlobalDefs.cpp similarity index 100% rename from Common/src/GlobalDefs.cpp rename to Code/Common/src/GlobalDefs.cpp diff --git a/MuscateMetadata/src/string_utils.cpp b/Code/Common/src/StringUtils.cpp similarity index 57% rename from MuscateMetadata/src/string_utils.cpp rename to Code/Common/src/StringUtils.cpp index 264cdd7..0d6fff0 100644 --- a/MuscateMetadata/src/string_utils.cpp +++ b/Code/Common/src/StringUtils.cpp @@ -27,21 +27,37 @@ #include <sstream> #include <otbMacro.h> +#include <StringUtils.hpp> #include <algorithm> +#include "itksys/SystemTools.hxx" -#include "string_utils.hpp" -std::vector<std::string> split(const std::string &s, char delim) +std::vector<std::string> split(const std::string &s, char delim, const bool remove_empty) { - std::vector<std::string> result; - - std::istringstream is(s); - std::string item; - while (std::getline(is, item, delim)) { - result.emplace_back(std::move(item)); + std::vector<std::string> filenamekey; + // --------------------------------------------------------------------------------------------- + // Splits filename with 'separator' value + itksys::SystemTools::Split(s, filenamekey, delim); + std::vector<std::string> filenamekeyFormated; + if (remove_empty == false) + { + return filenamekey; + } + else + { + // --------------------------------------------------------------------------------------------- + // Loops on the values + const unsigned int NbSplit = filenamekey.size(); + for (unsigned int i = 0; i < NbSplit; i++) + { + if (!filenamekey[i].empty()) + { + filenamekeyFormated.push_back(filenamekey[i]); + } + } + // --------------------------------------------------------------------------------------------- + return filenamekeyFormated; } - - return result; } double ReadDouble(const std::string &s) @@ -59,6 +75,19 @@ double ReadDouble(const std::string &s) } } +std::vector<double> +ReadDoubleList(const std::string& string, char separator, bool remove_empty) +{ + const std::vector<std::string> l_ListOfString = split(string, separator, remove_empty); + const unsigned int l_ListOfStringSize = l_ListOfString.size(); + std::vector<double> l_ListOfDouble; + for (unsigned int i = 0; i < l_ListOfStringSize; i++) + { + l_ListOfDouble.push_back(ReadDouble(l_ListOfString[i])); + } + return l_ListOfDouble; +} + bool is_number(const std::string& s) { return !s.empty() && std::find_if(s.begin(), diff --git a/MuscateMetadata/src/tinyxml_utils.cpp b/Code/Common/src/TinyXMLUtils.cpp similarity index 98% rename from MuscateMetadata/src/tinyxml_utils.cpp rename to Code/Common/src/TinyXMLUtils.cpp index e8e2468..9ef244a 100644 --- a/MuscateMetadata/src/tinyxml_utils.cpp +++ b/Code/Common/src/TinyXMLUtils.cpp @@ -23,7 +23,7 @@ * SPDX-License-Identifier: GPL-3.0-or-later */ -#include "tinyxml_utils.hpp" +#include <TinyXMLUtils.hpp> std::string GetAttribute(const TiXmlElement *element, const char *attributeName) { diff --git a/Code/Common/test/CMakeLists.txt b/Code/Common/test/CMakeLists.txt new file mode 100644 index 0000000..5e856a9 --- /dev/null +++ b/Code/Common/test/CMakeLists.txt @@ -0,0 +1,9 @@ +add_executable(test_ImageResampler test_ImageResampler.cpp ../include/ImageResampler.h) +target_link_libraries(test_ImageResampler + Common + ${Boost_LIBRARIES} + ${OTB_LIBRARIES} + ) + +target_include_directories(test_ImageResampler PUBLIC ../include) +add_test(test_ImageResampler test_ImageResampler) diff --git a/Common/test/test_ImageResampler.cpp b/Code/Common/test/test_ImageResampler.cpp similarity index 100% rename from Common/test/test_ImageResampler.cpp rename to Code/Common/test/test_ImageResampler.cpp diff --git a/CompositePreprocessing/CMakeLists.txt b/Code/CompositePreprocessing/CMakeLists.txt similarity index 59% rename from CompositePreprocessing/CMakeLists.txt rename to Code/CompositePreprocessing/CMakeLists.txt index 41888c2..91c9010 100644 --- a/CompositePreprocessing/CMakeLists.txt +++ b/Code/CompositePreprocessing/CMakeLists.txt @@ -1,24 +1,15 @@ otb_create_application( NAME CompositePreprocessing - SOURCES src/CompositePreprocessing.cpp - include/ComputeNDVI.h + SOURCES src/CompositePreprocessing.cpp src/ComputeNDVI.cpp - include/MaskExtractorFilter.h - include/MaskExtractorFunctor.h - src/MaskExtractorFilter.txx - include/DirectionalCorrectionFunctor.h - src/DirectionalCorrectionFunctor.txx src/DirectionalCorrection.cpp - include/DirectionalModel.h + src/DirectionalCorrectionLUT.cpp src/DirectionalModel.cpp - include/DirectionalCorrection.h - include/DirectionalCorrectionFilter.h - include/CreateS2AnglesRaster.h src/CreateS2AnglesRaster.cpp src/PreprocessingAdapter.cpp src/PreprocessingSentinel.cpp src/PreprocessingVenus.cpp - LINK_LIBRARIES ${OTB_LIBRARIES} MuscateMetadata MetadataHelper) + LINK_LIBRARIES ${OTB_LIBRARIES} MuscateMetadata MetadataHelper Common LutReader) target_include_directories(otbapp_CompositePreprocessing PUBLIC include) diff --git a/CompositePreprocessing/include/ComputeNDVI.h b/Code/CompositePreprocessing/include/ComputeNDVI.h similarity index 100% rename from CompositePreprocessing/include/ComputeNDVI.h rename to Code/CompositePreprocessing/include/ComputeNDVI.h diff --git a/CompositePreprocessing/include/CreateS2AnglesRaster.h b/Code/CompositePreprocessing/include/CreateS2AnglesRaster.h similarity index 98% rename from CompositePreprocessing/include/CreateS2AnglesRaster.h rename to Code/CompositePreprocessing/include/CreateS2AnglesRaster.h index 91a4d0f..bfef978 100644 --- a/CompositePreprocessing/include/CreateS2AnglesRaster.h +++ b/Code/CompositePreprocessing/include/CreateS2AnglesRaster.h @@ -26,9 +26,8 @@ #ifndef CREATE_S2_ANGLES_RASTER_H #define CREATE_S2_ANGLES_RASTER_H +#include <MuscateViewingAngles.hpp> #include "itkLightObject.h" -#include "ViewingAngles.hpp" - #include "ImageResampler.h" #include "BaseImageTypes.h" diff --git a/CompositePreprocessing/include/DirectionalCorrection.h b/Code/CompositePreprocessing/include/DirectionalCorrection.h similarity index 100% rename from CompositePreprocessing/include/DirectionalCorrection.h rename to Code/CompositePreprocessing/include/DirectionalCorrection.h diff --git a/CompositePreprocessing/include/DirectionalCorrectionFunctor.h b/Code/CompositePreprocessing/include/DirectionalCorrectionFunctor.h similarity index 96% rename from CompositePreprocessing/include/DirectionalCorrectionFunctor.h rename to Code/CompositePreprocessing/include/DirectionalCorrectionFunctor.h index 314d031..304e72e 100644 --- a/CompositePreprocessing/include/DirectionalCorrectionFunctor.h +++ b/Code/CompositePreprocessing/include/DirectionalCorrectionFunctor.h @@ -68,14 +68,12 @@ public: bool IsWaterPixel(const TInput & A); bool IsCloudPixel(const TInput & A); bool IsLandPixel(const TInput & A); - float GetCurrentL2AWeightValue(const TInput & A); bool IsNoDataValue(float fValue, float fNoDataValue); private: std::vector<ScatteringFunctionCoefficients> m_ScatteringCoeffs; int m_nReflBandsCount; - int m_nCloudMaskBandIndex; int m_nSnowMaskBandIndex; int m_nWaterMaskBandIndex; @@ -89,6 +87,6 @@ private: } //namespace Functor } //namespace ts -#include "../src/DirectionalCorrectionFunctor.txx" +#include "DirectionalCorrectionFunctor.txx" #endif // DIRECTIONALCORRECTIONFUNCTOR_H diff --git a/CompositePreprocessing/src/DirectionalCorrectionFunctor.txx b/Code/CompositePreprocessing/include/DirectionalCorrectionFunctor.txx similarity index 100% rename from CompositePreprocessing/src/DirectionalCorrectionFunctor.txx rename to Code/CompositePreprocessing/include/DirectionalCorrectionFunctor.txx diff --git a/Code/CompositePreprocessing/include/DirectionalCorrectionLUT.h b/Code/CompositePreprocessing/include/DirectionalCorrectionLUT.h new file mode 100644 index 0000000..774e396 --- /dev/null +++ b/Code/CompositePreprocessing/include/DirectionalCorrectionLUT.h @@ -0,0 +1,138 @@ +/* + * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) + * All rights reserved + * + * This file is part of Weighted Average Synthesis Processor (WASP) + * + * Authors: + * - Esquis Benjamin <benjamin.esquis@csgroup.eu> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * See the LICENSE.md file for more details. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#ifndef DIRECTIONAL_CORRECTION_H +#define DIRECTIONAL_CORRECTION_H + +#include <DirectionalCorrectionLUTFilter.h> +#include "otbImage.h" +#include "otbVectorImage.h" +#include "otbImageList.h" +#include "BaseImageTypes.h" +#include "otbImageListToVectorImageFilter.h" +#include "otbFunctorImageFilter.h" +#include "ResamplingBandExtractor.h" +#include "vnsVectorLookUpTable.hpp" +#include "vnsLookUpTableFileReader.hpp" +#include "vnsSimpleLutXMLFileHandler.hpp" + +/** + * @brief The TemporalSynthesis namespace, covering all needed functions to execute this processing chain + */ +namespace ts { + +/** + * @brief Perform the directional correction on a set of images of the same resolution + */ +class DirectionalCorrectionLUT : public BaseImageTypes { +public: + + typedef otb::ImageList<FloatImageType> ImageListType; + typedef otb::ImageListToVectorImageFilter<ImageListType, FloatVectorImageType> ListConcatenerFilterType; + + typedef DirectionalCorrectionLUTFilter<FloatVectorImageType,FloatVectorImageType,FloatImageType,FloatVectorImageType,ShortVectorImageType> DirectionalCorrectionFilterType; + typedef DirectionalCorrectionFilterType::Pointer DirectionalCorrectionFilterPointer; + + //Reduced output lut typedef + typedef VNSLUT3DType LutType; + typedef typename LutType::ConstPointer ReducedLutConstPointer; + typedef typename LutType::Pointer ReducedLutPointer; + //LookupTable Reader + typedef LookUpTableFileReader<LutType> LookUpTableReaderType; + typedef typename LookUpTableReaderType::Pointer LookUpTableReaderPointer; + typedef typename LutType::ParameterValuesType ParameterValuesType; + +public: + /** + * @brief Constructor + */ + DirectionalCorrectionLUT(); + + /** + * @brief Init the Directional Correction + * @param res Current resolution + * @param xml Metadata file + * @param scatcoef Scattering coefficient filename + * @param cldImg Cloud Image + * @param watImg Water Image + * @param snowImg Snow Image + * @param angles Angles Image + * @param ndvi NDVI Image + */ + void Init(const size_t &res, const std::string &xml, const std::string &lut_file, FloatImageType::Pointer &cldImg, + FloatImageType::Pointer &watImg, FloatImageType::Pointer &snowImg, + FloatVectorImageType::Pointer &angles); + + /** + * @brief Execute the application + */ + void DoExecute(); + + /** + * @brief Return the corrected image + * @return ShortVectorImage containing the corrected S2-rasters + */ + ShortVectorImageType::Pointer GetCorrectedImg(); + + /** + * @brief Return the corrected image + * @return ShortVectorImage containing the corrected S2-rasters + */ + FloatVectorImageType::Pointer GetCoeffImg(); + + /** + * @brief Return the name of the class + * @return + */ + const char * GetNameOfClass() { return "DirectionalCorrection"; } + +private: + /** + * @brief Extract each band from the angles image to the image list + * @param imageType FloatVectorImage of the angles image + * @return The number of bands extracted + */ + int extractBandsFromImage(FloatVectorImageType::Pointer & imageType, ImageListType::Pointer & listToFill); + +private: + size_t m_nRes; + std::string m_strXml; + std::string m_strLutFileName; + FloatVectorImageType::Pointer m_AnglesImg; + FloatImageType::Pointer m_CSM, m_WM, m_SM; + ImageListType::Pointer m_ImageList; + ImageListType::Pointer m_AngleImageList; + ListConcatenerFilterType::Pointer m_Concat; + ListConcatenerFilterType::Pointer m_ConcatAngle; + DirectionalCorrectionFilterPointer m_DirectionalCorrectionFilter; + + FloatVectorImageReaderType::Pointer m_inputImageReader; + FloatVectorImageReaderListType::Pointer m_ReaderList; + ts::ResamplingBandExtractor<float> m_ResampledBandsExtractor; +}; +} //namespace ts +#endif // DIRECTIONAL_CORRECTION_H diff --git a/Code/CompositePreprocessing/include/DirectionalCorrectionLUTFilter.h b/Code/CompositePreprocessing/include/DirectionalCorrectionLUTFilter.h new file mode 100644 index 0000000..c26aad6 --- /dev/null +++ b/Code/CompositePreprocessing/include/DirectionalCorrectionLUTFilter.h @@ -0,0 +1,156 @@ +/* + * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) + * All rights reserved + * + * This file is part of Weighted Average Synthesis Processor (WASP) + * + * Authors: + * - Esquis Benjamin <benjamin.esquis@csgroup.eu> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * See the LICENSE.md file for more details. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#ifndef DIRECTIONALCORRECTIONLUTFILTER_H +#define DIRECTIONALCORRECTIONLUTFILTER_H + +#include "GlobalDefs.h" +#include "Utils.h" +#include "Macros.h" +#include "itkImageToImageFilter.h" +#include "vnsVectorLookUpTable.hpp" + + +/** + * @brief The TemporalSynthesis namespace, covering all needed functions to execute this processing chain + */ +namespace ts { + +template<class TInputAngleImage, class TInputReflectanceImage,class TInputMask, class TOuputCoeffImage, class TOutput> +class DirectionalCorrectionLUTFilter : public itk::ImageToImageFilter<TInputReflectanceImage, TOutput> +{ +public: + /** Standard class typedefs. */ + typedef DirectionalCorrectionLUTFilter<TInputAngleImage, TInputReflectanceImage,TInputMask,TOuputCoeffImage, TOutput> Self; + typedef itk::ImageToImageFilter<TInputReflectanceImage, TOutput> Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Type macro */ + itkNewMacro(Self) + + /** Creation through object factory macro */ + itkTypeMacro(DirectionalCorrectionLUTFilter, ProcessObject) + + typedef TInputReflectanceImage InputReflImageType; + typedef typename InputReflImageType::Pointer InputReflImagePointer; + typedef typename InputReflImageType::ConstPointer InputReflImageConstPointer; + typedef typename InputReflImageType::PixelType InputReflImagePixelType; + typedef TInputAngleImage InputAngleImageType; + typedef typename InputAngleImageType::Pointer InputAngleImagePointer; + typedef typename InputAngleImageType::ConstPointer InputAngleImageConstPointer; + typedef typename InputAngleImageType::PixelType InputAngleImagePixelType; + typedef TInputMask InputMaskType; + typedef typename InputMaskType::Pointer InputMaskPointer; + typedef typename InputMaskType::ConstPointer InputMaskConstPointer; + typedef typename InputMaskType::PixelType InputMaskPixelType; + /** Output image typedefs. */ + typedef TOutput OutputImageType; + typedef typename OutputImageType::Pointer OutputImagePointer; + typedef typename OutputImageType::ConstPointer OutputImageConstPointer; + typedef typename OutputImageType::PixelType OutputImagePixelType; + typedef typename OutputImageType::InternalPixelType OutputImageInternalPixelType; + typedef typename OutputImageType::RegionType OutputImageRegionType; + /** Output coeff image typedefs. */ + typedef TOuputCoeffImage OutputCoeffImageType; + typedef typename OutputCoeffImageType::Pointer OutputCoeffImagePointer; + typedef typename OutputCoeffImageType::ConstPointer OutputCoeffImageConstPointer; + typedef typename OutputCoeffImageType::PixelType OutputCoeffImagePixelType; + typedef typename OutputCoeffImageType::InternalPixelType OutputCoeffImageInternalPixelType; + typedef typename OutputCoeffImageType::RegionType OutputCoeffImageRegionType; + /** LUT image typedef */ + typedef VNSLUT3DType LUTType; + typedef typename LUTType::Pointer LUTPointer; + typedef typename LUTType::ConstPointer LUTConstPointer; + typedef typename LUTType::PixelType LUTPixelType; + typedef typename LUTType::InternalPixelType LUTInternalPixelType; + typedef typename LUTType::PointType LUTPointType; + typedef typename LUTPointType::ValueType LUTPointValueType; + + /** Product julian date accessors */ + itkSetMacro(fReflNoDataValue, float) + itkGetConstReferenceMacro(fReflNoDataValue, float) + + + /** Set the TOAC reflectance image */ + SetGetInputMacro(SnowMask , InputMaskType, 0); + /** Set the AOT reflectance image */ + SetGetInputMacro(WaterMask, InputMaskType, 1); + /** Set the EDG image */ + SetGetInputMacro(CloudMask, InputMaskType, 2); + /** Set the DTM image */ + SetGetInputMacro(Refl , InputReflImageType, 3); + /** Set the DTM image */ + SetGetInputMacro(Angles , InputAngleImageType, 4); + /** Set the LUT image */ + itkSetObjectMacro(LUT, LUTType) + /** Get the DTM image */ + itkGetConstObjectMacro(LUT, LUTType) + + + /** Get the coefficients image */ + OutputCoeffImageType * GetCoeffImage(); + +protected: + /** Constructor */ + DirectionalCorrectionLUTFilter(); + /** Destructor */ + virtual + ~DirectionalCorrectionLUTFilter(); + + void + operator=(const Self&); //purposely not implemented + + /** Validate the presence of all inputs and their sizes. If at least one input + * is missing, throws an exception. */ + void + CheckInputs(); + + /** BeforeThreaded generate data. */ + virtual void + BeforeThreadedGenerateData(void); + + /** Generate output information. */ + virtual void + GenerateOutputInformation(void); + + /** Composite Filter method. */ + virtual void + ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId); + +private: + float m_fReflNoDataValue; + /** Surface reflectance LUT */ + LUTConstPointer m_LUT; + +}; + +} //namespace ts + +#include "DirectionalCorrectionLUTFilter.txx" + +#endif // DIRECTIONALCORRECTIONFUNCTOR_H diff --git a/Code/CompositePreprocessing/include/DirectionalCorrectionLUTFilter.txx b/Code/CompositePreprocessing/include/DirectionalCorrectionLUTFilter.txx new file mode 100644 index 0000000..f23702b --- /dev/null +++ b/Code/CompositePreprocessing/include/DirectionalCorrectionLUTFilter.txx @@ -0,0 +1,282 @@ +/* + * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) + * All rights reserved + * + * This file is part of Weighted Average Synthesis Processor (WASP) + * + * Authors: + * - Esquis Benjamin <benjamin.esquis@csgroup.eu> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * See the LICENSE.md file for more details. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#include "DirectionalCorrectionLUTFilter.h" +#include "itkImageRegionConstIterator.h" +#include "itkImageRegionIterator.h" +#include "GlobalDefs.h" + + +/** + * @brief The TemporalSynthesis namespace, covering all needed functions to execute this processing chain + */ +namespace ts { + + +// Constructor +template<class TInputAngleImage, class TInputReflectanceImage,class TInputMask, class TOuputCoeffImage, class TOutput> +DirectionalCorrectionLUTFilter<TInputAngleImage, TInputReflectanceImage,TInputMask, TOuputCoeffImage, TOutput>::DirectionalCorrectionLUTFilter() +{ + // Input/Output initialization + this->SetNumberOfIndexedInputs(5); + this->SetNumberOfRequiredInputs(5); + this->SetNumberOfIndexedOutputs(2); + + this->SetNthOutput(0, OutputImageType::New()); + this->SetNthOutput(1, OutputCoeffImageType::New()); + + m_fReflNoDataValue = NO_DATA_VALUE; +}; + +// Destructor +template<class TInputAngleImage, class TInputReflectanceImage,class TInputMask, class TOuputCoeffImage, class TOutput> +DirectionalCorrectionLUTFilter<TInputAngleImage, TInputReflectanceImage,TInputMask,TOuputCoeffImage, TOutput>::~DirectionalCorrectionLUTFilter() +{ +} + +template<class TInputAngleImage, class TInputReflectanceImage,class TInputMask, class TOuputCoeffImage, class TOutput> +typename DirectionalCorrectionLUTFilter<TInputAngleImage, TInputReflectanceImage,TInputMask,TOuputCoeffImage, TOutput>::OutputCoeffImageType * +DirectionalCorrectionLUTFilter<TInputAngleImage, TInputReflectanceImage,TInputMask,TOuputCoeffImage, TOutput>::GetCoeffImage(void) +{ + return itkDynamicCastInDebugMode<OutputCoeffImageType *>(itk::ProcessObject::GetOutput(1)); +} + +//=============== Generate output information method ===================/ +template<class TInputAngleImage, class TInputReflectanceImage,class TInputMask, class TOuputCoeffImage, class TOutput> +void DirectionalCorrectionLUTFilter<TInputAngleImage, TInputReflectanceImage,TInputMask,TOuputCoeffImage, TOutput>::GenerateOutputInformation() +{ + // Call superclass implementation + Superclass::GenerateOutputInformation(); + + // Set the number of output channels to the number of input one. + // Check Snow Mask + if (!this->GetSnowMaskInput()) + { + throw new std::runtime_error("Waiting for a SnowMask image, but no one specified. Please set one."); + } + // Check water mask availability + if (!this->GetWaterMaskInput()) + { + throw new std::runtime_error("Waiting for a water mask, but no one specified. Please set one."); + } + // Check cloud mask availability + if (!this->GetCloudMaskInput()) + { + throw new std::runtime_error("Waiting for a cloud mask, but no one specified. Please set one."); + } + // Check cloud mask availability + if (!this->GetReflInput()) + { + throw new std::runtime_error("Waiting for a reflectance image, but no one specified. Please set one."); + } + // Check cloud mask availability + if (!this->GetAnglesInput()) + { + throw new std::runtime_error("Waiting for an Angles image, but no one specified. Please set one."); + } + this->GetOutput()->SetNumberOfComponentsPerPixel(this->GetReflInput()->GetNumberOfComponentsPerPixel()); + this->GetCoeffImage()->SetNumberOfComponentsPerPixel(this->GetReflInput()->GetNumberOfComponentsPerPixel()); +} + +//=============== BeforeThreaded generate data method ================/ +template<class TInputAngleImage, class TInputReflectanceImage,class TInputMask, class TOuputCoeffImage, class TOutput> +void DirectionalCorrectionLUTFilter<TInputAngleImage, TInputReflectanceImage,TInputMask,TOuputCoeffImage, TOutput>::BeforeThreadedGenerateData() +{ + // Call superclass implementation + Superclass::BeforeThreadedGenerateData(); + + // Check LUT availability + if (m_LUT.IsNull() == true) + { + throw new std::runtime_error("Waiting for a LUT, but no one specified. Please set one."); + } + + // Check Snow Mask + if (!this->GetSnowMaskInput()) + { + throw new std::runtime_error("Waiting for a SnowMask image, but no one specified. Please set one."); + } + // Check water mask availability + if (!this->GetWaterMaskInput()) + { + throw new std::runtime_error("Waiting for a water mask, but no one specified. Please set one."); + } + // Check cloud mask availability + if (!this->GetCloudMaskInput()) + { + throw new std::runtime_error("Waiting for a cloud mask, but no one specified. Please set one."); + } + // Check cloud mask availability + if (!this->GetReflInput()) + { + throw new std::runtime_error("Waiting for a reflectance image, but no one specified. Please set one."); + } + // Check cloud mask availability + if (!this->GetAnglesInput()) + { + throw new std::runtime_error("Waiting for an Angles image, but no one specified. Please set one."); + } + +} + +//====================== Main computation method ======================/ +template<class TInputAngleImage, class TInputReflectanceImage,class TInputMask, class TOuputCoeffImage, class TOutput> +void DirectionalCorrectionLUTFilter<TInputAngleImage, TInputReflectanceImage,TInputMask,TOuputCoeffImage, TOutput>::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType /*threadId*/) +{ + // Load inputs + // Input availability are checked in the BeforeThreadedGenerateData. + InputReflImageConstPointer l_IPReflPtr = this->GetReflInput(); + InputAngleImageConstPointer l_IPAnglePtr = this->GetAnglesInput(); + InputMaskConstPointer l_IPCLDPtr = this->GetCloudMaskInput(); + InputMaskConstPointer l_IPSNWPtr = this->GetSnowMaskInput(); + InputMaskConstPointer l_IPWMPtr = this->GetWaterMaskInput(); + + + // Load outputs + OutputImagePointer l_OPReflPtr = this->GetOutput(); + // Coeff image + OutputCoeffImagePointer l_OCoeffPtr = this->GetCoeffImage(); + // Prepare the threaded region input local iterators + itk::ImageRegionConstIterator<InputReflImageType> l_IPReflIt(l_IPReflPtr, outputRegionForThread); + itk::ImageRegionConstIterator<InputAngleImageType> l_IPAngleIt(l_IPAnglePtr, outputRegionForThread); + itk::ImageRegionConstIterator<InputMaskType> l_IPCLDIt(l_IPCLDPtr, outputRegionForThread); + itk::ImageRegionConstIterator<InputMaskType> l_IPSNWIt(l_IPSNWPtr, outputRegionForThread); + itk::ImageRegionConstIterator<InputMaskType> l_IPWMIt(l_IPWMPtr, outputRegionForThread); + + // Init to the beginning + l_IPReflIt.GoToBegin(); + l_IPAngleIt.GoToBegin(); + l_IPCLDIt.GoToBegin(); + l_IPSNWIt.GoToBegin(); + l_IPWMIt.GoToBegin(); + + // Prepare the threaded region output local iterator + itk::ImageRegionIterator<OutputImageType> l_OPReflIt(l_OPReflPtr, outputRegionForThread); + itk::ImageRegionIterator<OutputCoeffImageType> l_OCoeffIt(l_OCoeffPtr, outputRegionForThread); + + // Init to the beginning + l_OPReflIt.GoToBegin(); + l_OCoeffIt.GoToBegin(); + + // Get the number of band of the input image + const unsigned int nbOfChannels(l_IPReflPtr->GetNumberOfComponentsPerPixel()); + + // Set the output default pixel value to NoData. + OutputImagePixelType l_OPReflPix; + l_OPReflPix.SetSize(nbOfChannels); + OutputCoeffImagePixelType l_OCoeffPix; + l_OCoeffPix.SetSize(nbOfChannels); + //Lut ExtractPoint + LUTPointType point; + LUTPointType pointRef; + pointRef.Fill(0); + + // Loop over input and output images + while ((l_OPReflIt.IsAtEnd() == false) && (l_IPReflIt.IsAtEnd() == false)) + { + const double thetaS = l_IPAngleIt.Get()[0]; + const double phiS = l_IPAngleIt.Get()[1]; + point[0] = thetaS; + pointRef[0] = thetaS; + LUTPixelType interpRefValue = m_LUT->InterpolateValue(pointRef); + //Fill coeff pixel with 1.0 factor + l_OCoeffPix.Fill(1.0); + + const InputReflImagePixelType& l_inRefl = l_IPReflIt.Get(); + // Loop over the channels + const bool inCloud = ( (int)l_IPCLDIt.Get() != 0); + const bool inWater = ( (int)l_IPWMIt.Get() != 0); + const bool inSnow = ( (int)l_IPSNWIt.Get() != 0); + // If the pixel is not a No_data pixel + if ( inCloud || inWater || inSnow ) + { + // Band loop + for (unsigned int i = 0; i < nbOfChannels; i++) + { + l_OPReflPix[i] = static_cast<OutputImageInternalPixelType>(l_inRefl[i]); + l_OCoeffPix[i] = -4; + } + } else + { + // Band loop + for (unsigned int i = 0; i < nbOfChannels; i++) + { + if(compareValueWithEpsilon<float>(l_inRefl[i], m_fReflNoDataValue)) { + l_OPReflPix[i] = static_cast<OutputImageInternalPixelType>(m_fReflNoDataValue); + l_OCoeffPix[i] = -1; + } else { + const double thetaV = l_IPAngleIt.Get()[2*i+1]; + point[1] = thetaV; + const double phiV = l_IPAngleIt.Get()[2*i+2]; + if(std::isnan(thetaV) || std::isnan(phiV)) { + l_OPReflPix[i] = static_cast<OutputImageInternalPixelType>(l_inRefl[i]); + l_OCoeffPix[i] = -2; + } else { + // Get the relative azimuth angle + double deltaPhi = phiS - phiV; + if (deltaPhi < 0.) + { + deltaPhi = -deltaPhi; + } + if (deltaPhi > 180.) + { + deltaPhi = 360 - deltaPhi; + } + point[2] = deltaPhi; + LUTPixelType interpValue = m_LUT->InterpolateValue(point); + const float l_dirNorm = interpRefValue[i] / interpValue[i]; + l_OCoeffPix[i] = static_cast<OutputCoeffImageInternalPixelType>(l_dirNorm); + const float fNewReflVal = l_inRefl[i] * l_dirNorm; + if(fNewReflVal < 0) { + l_OPReflPix[i] = static_cast<OutputImageInternalPixelType>(l_inRefl[i]); + l_OCoeffPix[i] = -3; + } else { + l_OPReflPix[i] = static_cast<OutputImageInternalPixelType>(fNewReflVal); + } + } + } + } + } + // Fill the output pixel iterator + l_OPReflIt.Set(l_OPReflPix); + l_OCoeffIt.Set(l_OCoeffPix); + + ++l_OPReflIt; + ++l_OCoeffIt; + ++l_IPReflIt; + ++l_IPAngleIt; + ++l_IPCLDIt; + ++l_IPSNWIt; + ++l_IPWMIt; + + } // end pixel loop + +} + +} //namespace ts + + diff --git a/CompositePreprocessing/include/DirectionalModel.h b/Code/CompositePreprocessing/include/DirectionalModel.h similarity index 100% rename from CompositePreprocessing/include/DirectionalModel.h rename to Code/CompositePreprocessing/include/DirectionalModel.h diff --git a/CompositePreprocessing/include/MaskExtractorFilter.h b/Code/CompositePreprocessing/include/MaskExtractorFilter.h similarity index 97% rename from CompositePreprocessing/include/MaskExtractorFilter.h rename to Code/CompositePreprocessing/include/MaskExtractorFilter.h index 95d7f74..548f6b6 100644 --- a/CompositePreprocessing/include/MaskExtractorFilter.h +++ b/Code/CompositePreprocessing/include/MaskExtractorFilter.h @@ -29,7 +29,7 @@ #include "otbWrapperTypes.h" #include "otbMultiToMonoChannelExtractROI.h" #include "otbImageFileReader.h" -#include "otbUnaryFunctorImageFilter.h" +#include "itkUnaryFunctorImageFilter.h" #include "MaskExtractorFunctor.h" #include "itkNumericTraits.h" @@ -84,7 +84,7 @@ private: } /* namespace ts */ -#include "../src/MaskExtractorFilter.txx" +#include "MaskExtractorFilter.txx" #endif diff --git a/CompositePreprocessing/src/MaskExtractorFilter.txx b/Code/CompositePreprocessing/include/MaskExtractorFilter.txx similarity index 100% rename from CompositePreprocessing/src/MaskExtractorFilter.txx rename to Code/CompositePreprocessing/include/MaskExtractorFilter.txx diff --git a/CompositePreprocessing/include/MaskExtractorFunctor.h b/Code/CompositePreprocessing/include/MaskExtractorFunctor.h similarity index 100% rename from CompositePreprocessing/include/MaskExtractorFunctor.h rename to Code/CompositePreprocessing/include/MaskExtractorFunctor.h diff --git a/CompositePreprocessing/include/PreprocessingAdapter.h b/Code/CompositePreprocessing/include/PreprocessingAdapter.h similarity index 100% rename from CompositePreprocessing/include/PreprocessingAdapter.h rename to Code/CompositePreprocessing/include/PreprocessingAdapter.h diff --git a/CompositePreprocessing/include/PreprocessingSentinel.h b/Code/CompositePreprocessing/include/PreprocessingSentinel.h similarity index 100% rename from CompositePreprocessing/include/PreprocessingSentinel.h rename to Code/CompositePreprocessing/include/PreprocessingSentinel.h diff --git a/CompositePreprocessing/include/PreprocessingVenus.h b/Code/CompositePreprocessing/include/PreprocessingVenus.h similarity index 100% rename from CompositePreprocessing/include/PreprocessingVenus.h rename to Code/CompositePreprocessing/include/PreprocessingVenus.h diff --git a/CompositePreprocessing/scattering_coeffs_10m.txt b/Code/CompositePreprocessing/scattering_coeffs_10m.txt similarity index 100% rename from CompositePreprocessing/scattering_coeffs_10m.txt rename to Code/CompositePreprocessing/scattering_coeffs_10m.txt diff --git a/CompositePreprocessing/scattering_coeffs_20m.txt b/Code/CompositePreprocessing/scattering_coeffs_20m.txt similarity index 100% rename from CompositePreprocessing/scattering_coeffs_20m.txt rename to Code/CompositePreprocessing/scattering_coeffs_20m.txt diff --git a/CompositePreprocessing/src/CompositePreprocessing.cpp b/Code/CompositePreprocessing/src/CompositePreprocessing.cpp similarity index 99% rename from CompositePreprocessing/src/CompositePreprocessing.cpp rename to Code/CompositePreprocessing/src/CompositePreprocessing.cpp index d1b3813..2cf61e0 100644 --- a/CompositePreprocessing/src/CompositePreprocessing.cpp +++ b/Code/CompositePreprocessing/src/CompositePreprocessing.cpp @@ -75,7 +75,6 @@ private: SetName("CompositePreprocessing"); SetDescription("Perform the directional correction of FRE Images"); - SetDocName("CompositePreprocessing"); SetDocLongDescription("Perform the directional correction of FRE Images"); SetDocLimitations("None"); SetDocAuthors("Peter KETTIG"); diff --git a/CompositePreprocessing/src/ComputeNDVI.cpp b/Code/CompositePreprocessing/src/ComputeNDVI.cpp similarity index 96% rename from CompositePreprocessing/src/ComputeNDVI.cpp rename to Code/CompositePreprocessing/src/ComputeNDVI.cpp index 75ce156..00e2517 100644 --- a/CompositePreprocessing/src/ComputeNDVI.cpp +++ b/Code/CompositePreprocessing/src/ComputeNDVI.cpp @@ -49,11 +49,11 @@ ComputeNDVI::FloatImageType::Pointer ComputeNDVI::DoExecute() { m_InputImageReaderRed->SetFileName(imgFileNameRed); m_InputImageReaderRed->UpdateOutputInformation(); ShortImageType::Pointer imgRed = m_InputImageReaderRed->GetOutput(); - int curResRed = imgRed->GetSpacing()[0]; + int curResRed = imgRed->GetSignedSpacing()[0]; m_InputImageReaderNIR->SetFileName(imgFileNameNIR); m_InputImageReaderNIR->UpdateOutputInformation(); ShortImageType::Pointer imgNIR = m_InputImageReaderNIR->GetOutput(); - int curResNIR = imgNIR->GetSpacing()[0]; + int curResNIR = imgNIR->GetSignedSpacing()[0]; m_NDVI = NDVIFilterType::New(); if(curResRed != curResNIR){ //Rescale image in this case diff --git a/CompositePreprocessing/src/CreateS2AnglesRaster.cpp b/Code/CompositePreprocessing/src/CreateS2AnglesRaster.cpp similarity index 97% rename from CompositePreprocessing/src/CreateS2AnglesRaster.cpp rename to Code/CompositePreprocessing/src/CreateS2AnglesRaster.cpp index fbe78dd..b69e786 100644 --- a/CompositePreprocessing/src/CreateS2AnglesRaster.cpp +++ b/Code/CompositePreprocessing/src/CreateS2AnglesRaster.cpp @@ -51,7 +51,7 @@ CreateS2AnglesRaster::FloatVectorImageType::Pointer CreateS2AnglesRaster::DoExec imageReader->SetFileName(fileName); imageReader->UpdateOutputInformation(); auto sz = imageReader->GetOutput()->GetLargestPossibleRegion().GetSize(); - auto spacing = imageReader->GetOutput()->GetSpacing(); + auto spacing = imageReader->GetOutput()->GetSignedSpacing(); int width = sz[0]; int height = sz[1]; @@ -113,7 +113,7 @@ CreateS2AnglesRaster::FloatVectorImageType::Pointer CreateS2AnglesRaster::DoExec FloatVectorImageType::SpacingType anglesRasterSpacing; anglesRasterSpacing[0] = (((float)width) * spacing[0]) / nGridSize; // spacing along X anglesRasterSpacing[1] = (((float)height) * spacing[1]) / nGridSize; // spacing along Y - m_AnglesRaster->SetSpacing(anglesRasterSpacing); + m_AnglesRaster->SetSignedSpacing(anglesRasterSpacing); m_AnglesRaster->Allocate(); for(unsigned int i = 0; i < (unsigned int)nGridSize; i++) { diff --git a/CompositePreprocessing/src/DirectionalCorrection.cpp b/Code/CompositePreprocessing/src/DirectionalCorrection.cpp similarity index 99% rename from CompositePreprocessing/src/DirectionalCorrection.cpp rename to Code/CompositePreprocessing/src/DirectionalCorrection.cpp index 0985842..c524c8c 100644 --- a/CompositePreprocessing/src/DirectionalCorrection.cpp +++ b/Code/CompositePreprocessing/src/DirectionalCorrection.cpp @@ -29,6 +29,11 @@ using namespace ts; DirectionalCorrection::DirectionalCorrection() { + + m_nRes = 0; + m_strXml = ""; + m_strScatCoeffs = ""; + } void DirectionalCorrection::Init(const size_t &res, const std::string &xml, const std::string &scatcoef, diff --git a/Code/CompositePreprocessing/src/DirectionalCorrectionLUT.cpp b/Code/CompositePreprocessing/src/DirectionalCorrectionLUT.cpp new file mode 100644 index 0000000..0852696 --- /dev/null +++ b/Code/CompositePreprocessing/src/DirectionalCorrectionLUT.cpp @@ -0,0 +1,168 @@ +/* + * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) + * All rights reserved + * + * This file is part of Weighted Average Synthesis Processor (WASP) + * + * Authors: + * - Esquis Benjamin <benjamin.esquis@csgroup.eu> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * See the LICENSE.md file for more details. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#include "DirectionalCorrectionLUT.h" +#include "MetadataHelperFactory.h" +#include <vector> + +using namespace ts; + +DirectionalCorrectionLUT::DirectionalCorrectionLUT() { + m_nRes = 0; + m_strXml = ""; + m_strLutFileName = ""; +} + +void DirectionalCorrectionLUT::Init(const size_t &res, const std::string &xml, + const std::string &lut_file,FloatImageType::Pointer &cldImg, FloatImageType::Pointer &watImg, + FloatImageType::Pointer &snowImg, FloatVectorImageType::Pointer &angles) { + m_nRes = res; + m_strXml = xml; + m_strLutFileName = lut_file; + m_AnglesImg = angles; + m_CSM = cldImg; + m_WM = watImg; + m_SM = snowImg; + + m_ImageList = ImageListType::New(); + m_AngleImageList = ImageListType::New(); + m_Concat = ListConcatenerFilterType::New(); + m_ConcatAngle = ListConcatenerFilterType::New(); + m_ReaderList = FloatVectorImageReaderListType::New(); +} + +void DirectionalCorrectionLUT::DoExecute() { + //Load the reflectances files + auto factory = ts::MetadataHelperFactory::New(); + auto pHelper = factory->GetMetadataHelper(m_strXml); + ts::productReturnType inputImageFiles = pHelper->getResolutions().getNthResolutionFilenames(m_nRes); + std::cout << "Directional Correction Filenames found: " << std::endl; + for(auto filename : inputImageFiles){ + FloatVectorImageReaderType::Pointer reader = FloatVectorImageReaderType::New(); + reader->SetFileName(filename); + std::cout << filename << std::endl; + reader->UpdateOutputInformation(); + m_ReaderList->PushBack(reader); + FloatVectorImageType::Pointer inputImg = reader->GetOutput(); + extractBandsFromImage(inputImg, m_ImageList); + } + + //Construct the band list + std::vector<Band> l_bandList = pHelper->getResolutions().getResolutionVector()[m_nRes].getBands(); + + //Read the xml lut description file + SimpleLutXMLFileHandler::Pointer l_LUTXMLHandler = ts::SimpleLutXMLFileHandler::New(); + // Load the XML file and check with the schema + l_LUTXMLHandler->LoadFile(m_strLutFileName); + const ts::SimpleLutXMLContainer& l_lutxml = l_LUTXMLHandler->GetLutContainer(); + + // Init LUT filters + LookUpTableReaderPointer l_lookUpTableReader = LookUpTableReaderType::New(); + // Get the number of file that matches with the number of band + const std::vector<std::string>& l_GIP_L2TOCR_ListOfFilenames = l_lutxml.GetListOfPackaged_DBL_Files(); + const unsigned int fileNumber = l_GIP_L2TOCR_ListOfFilenames.size(); + + for (auto it : l_bandList) + { + // For each spectral band, add the filename of the LUT to the reader + for (auto file : l_GIP_L2TOCR_ListOfFilenames) + { + if (file.find(it.getType()) != std::string::npos) + { + std::cout<<"LUT file found for band "<<it.getType()<<" : "<<file<<std::endl; + l_lookUpTableReader->AddBandFilename(file); + } + } + } + // Read informations from the GIPP file + const std::vector<double>& l_GIP_L2TOCR_SolarZenithalAngleIndexes = l_lutxml.GetSolar_Zenith_Angle_Indexes(); + const std::vector<double>& l_GIP_L2TOCR_ViewZenithalAngleIndexes = l_lutxml.GetView_Zenith_Angle_Indexes(); + const std::vector<double>& l_GIP_L2TOCR_RelativeAzimuthAngleIndexes = l_lutxml.GetRelative_Azimuth_Angle_Indexes(); + + /* parameters are added one by one to the LUT */ + ParameterValuesType l_TOCRParam1; + l_TOCRParam1.ParameterName = "Solar_Zenith_Angle_Indexes"; + l_TOCRParam1.ParameterValues = l_GIP_L2TOCR_SolarZenithalAngleIndexes; + l_lookUpTableReader->AddParameterValues(l_TOCRParam1); + + ParameterValuesType l_TOCRParam2; + l_TOCRParam2.ParameterName = "View_Zenith_Angle_Indexes"; + l_TOCRParam2.ParameterValues = l_GIP_L2TOCR_ViewZenithalAngleIndexes; + l_lookUpTableReader->AddParameterValues(l_TOCRParam2); + + ParameterValuesType l_TOCRParam3; + l_TOCRParam3.ParameterName = "Relative_Azimuth_Angle_Indexes"; + l_TOCRParam3.ParameterValues = l_GIP_L2TOCR_RelativeAzimuthAngleIndexes; + l_lookUpTableReader->AddParameterValues(l_TOCRParam3); + //Gen Lut + l_lookUpTableReader->GenerateLUT(); + + typedef LutType::PointType LUTPointType; + typedef LutType::Pointer LUTPointer; + typedef LUTPointType::ValueType LUTPointValueType; + typedef LutType::PixelType LUTPixelType; + LUTPointer l_LutInPtr = l_lookUpTableReader->GetLUT(); + + m_Concat->SetInput(m_ImageList); + m_AnglesImg->UpdateOutputInformation(); + extractBandsFromImage(m_AnglesImg,m_AngleImageList); + m_ConcatAngle->SetInput(m_AngleImageList); + m_ConcatAngle->UpdateOutputInformation(); + m_Concat->UpdateOutputInformation(); + m_CSM->UpdateOutputInformation(); + m_SM->UpdateOutputInformation(); + m_WM->UpdateOutputInformation(); + + m_DirectionalCorrectionFilter = DirectionalCorrectionFilterType::New(); + m_DirectionalCorrectionFilter->SetAnglesInput(m_ConcatAngle->GetOutput()); + m_DirectionalCorrectionFilter->SetReflInput(m_Concat->GetOutput()); + m_DirectionalCorrectionFilter->SetCloudMaskInput(m_CSM); + m_DirectionalCorrectionFilter->SetSnowMaskInput(m_SM); + m_DirectionalCorrectionFilter->SetWaterMaskInput(m_WM); + m_DirectionalCorrectionFilter->SetLUT(l_LutInPtr); + m_DirectionalCorrectionFilter->UpdateOutputInformation(); + +} + +int DirectionalCorrectionLUT::extractBandsFromImage(FloatVectorImageType::Pointer & imageType, ImageListType::Pointer & listToFill) { + imageType->UpdateOutputInformation(); + int nbBands = imageType->GetNumberOfComponentsPerPixel(); + for(int j=0; j < nbBands; j++) + { + // extract the band without resampling + listToFill->PushBack(m_ResampledBandsExtractor.ExtractImgResampledBand(imageType, j+1, ts::Interpolator_Linear)); + } + return nbBands; +} + +DirectionalCorrectionLUT::ShortVectorImageType::Pointer DirectionalCorrectionLUT::GetCorrectedImg() { + return m_DirectionalCorrectionFilter->GetOutput(); +} + +DirectionalCorrectionLUT::FloatVectorImageType::Pointer DirectionalCorrectionLUT::GetCoeffImg() { + return m_DirectionalCorrectionFilter->GetCoeffImage(); +} diff --git a/CompositePreprocessing/src/DirectionalModel.cpp b/Code/CompositePreprocessing/src/DirectionalModel.cpp similarity index 100% rename from CompositePreprocessing/src/DirectionalModel.cpp rename to Code/CompositePreprocessing/src/DirectionalModel.cpp diff --git a/CompositePreprocessing/src/PreprocessingAdapter.cpp b/Code/CompositePreprocessing/src/PreprocessingAdapter.cpp similarity index 100% rename from CompositePreprocessing/src/PreprocessingAdapter.cpp rename to Code/CompositePreprocessing/src/PreprocessingAdapter.cpp diff --git a/CompositePreprocessing/src/PreprocessingSentinel.cpp b/Code/CompositePreprocessing/src/PreprocessingSentinel.cpp similarity index 96% rename from CompositePreprocessing/src/PreprocessingSentinel.cpp rename to Code/CompositePreprocessing/src/PreprocessingSentinel.cpp index a6a1b6e..97a0331 100644 --- a/CompositePreprocessing/src/PreprocessingSentinel.cpp +++ b/Code/CompositePreprocessing/src/PreprocessingSentinel.cpp @@ -88,7 +88,7 @@ std::vector<PreprocessingAdapter::ShortVectorImageType::Pointer> PreprocessingSe ts::DirectionalCorrection dirCorr; //If Resolution is not principal Resolution, then resize the additional images std::cout << "Current resolution: " << pHelper->getResolutions().getResolutionVector()[resolution].getBands()[0].getResolution() << std::endl; - if(cloudImage.GetPointer()->GetSpacing()[0] != pHelper->getResolutions().getResolutionVector()[resolution].getBands()[0].getResolution()){ + if(cloudImage.GetPointer()->GetSignedSpacing()[0] != pHelper->getResolutions().getResolutionVector()[resolution].getBands()[0].getResolution()){ PreprocessingAdapter::FloatImageType::Pointer ndviImgResampled = m_Resampler.getResampler(ndviImg.GetPointer(), 0.5f)->GetOutput(); PreprocessingAdapter::FloatImageType::Pointer cldImgResampled = m_Resampler.getResampler(cloudImage.GetPointer(), 0.5f)->GetOutput(); PreprocessingAdapter::FloatImageType::Pointer watImgResampled = m_Resampler.getResampler(watImage.GetPointer(), 0.5f)->GetOutput(); diff --git a/CompositePreprocessing/src/PreprocessingVenus.cpp b/Code/CompositePreprocessing/src/PreprocessingVenus.cpp similarity index 100% rename from CompositePreprocessing/src/PreprocessingVenus.cpp rename to Code/CompositePreprocessing/src/PreprocessingVenus.cpp diff --git a/CompositePreprocessing/test/CMakeLists.txt b/Code/CompositePreprocessing/test/CMakeLists.txt similarity index 77% rename from CompositePreprocessing/test/CMakeLists.txt rename to Code/CompositePreprocessing/test/CMakeLists.txt index d3ee8bb..ae6925f 100644 --- a/CompositePreprocessing/test/CMakeLists.txt +++ b/Code/CompositePreprocessing/test/CMakeLists.txt @@ -39,7 +39,7 @@ add_executable(test_DirectionalCorrection test_DirectionalCorrection.cpp ../include/DirectionalCorrectionFunctor.h ../include/DirectionalModel.h ../src/DirectionalModel.cpp - ../src/DirectionalCorrectionFunctor.txx + ../include/DirectionalCorrectionFunctor.txx ../src/DirectionalCorrection.cpp) target_link_libraries(test_DirectionalCorrection MuscateMetadata @@ -51,3 +51,19 @@ target_link_libraries(test_DirectionalCorrection target_include_directories(test_DirectionalCorrection PUBLIC ../include) add_test(test_DirectionalCorrection test_DirectionalCorrection) + +add_executable(test_DirectionalCorrectionLUT test_DirectionalCorrectionLUT.cpp + ../src/DirectionalCorrectionLUT.cpp) +target_link_libraries(test_DirectionalCorrectionLUT + MuscateMetadata + MetadataHelper + LutReader + Common + "${Boost_LIBRARIES}" + "${OTB_LIBRARIES}" + "${OTBITK_LIBRARIES}" +) + +target_include_directories(test_DirectionalCorrectionLUT PUBLIC ../include) +add_test(test_DirectionalCorrectionLUT test_DirectionalCorrectionLUT) + diff --git a/CompositePreprocessing/test/test_ComputeNDVI.cpp b/Code/CompositePreprocessing/test/test_ComputeNDVI.cpp similarity index 100% rename from CompositePreprocessing/test/test_ComputeNDVI.cpp rename to Code/CompositePreprocessing/test/test_ComputeNDVI.cpp diff --git a/CompositePreprocessing/test/test_CreateS2AnglesRaster.cpp b/Code/CompositePreprocessing/test/test_CreateS2AnglesRaster.cpp similarity index 100% rename from CompositePreprocessing/test/test_CreateS2AnglesRaster.cpp rename to Code/CompositePreprocessing/test/test_CreateS2AnglesRaster.cpp diff --git a/CompositePreprocessing/test/test_DirectionalCorrection.cpp b/Code/CompositePreprocessing/test/test_DirectionalCorrection.cpp similarity index 100% rename from CompositePreprocessing/test/test_DirectionalCorrection.cpp rename to Code/CompositePreprocessing/test/test_DirectionalCorrection.cpp diff --git a/Code/CompositePreprocessing/test/test_DirectionalCorrectionLUT.cpp b/Code/CompositePreprocessing/test/test_DirectionalCorrectionLUT.cpp new file mode 100644 index 0000000..caab768 --- /dev/null +++ b/Code/CompositePreprocessing/test/test_DirectionalCorrectionLUT.cpp @@ -0,0 +1,195 @@ +/* + * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) + * All rights reserved + * + * This file is part of Weighted Average Synthesis Processor (WASP) + * + * Authors: + * - Peter KETTIG <peter.kettig@cnes.fr> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * See the LICENSE.md file for more details. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#define BOOST_TEST_MODULE DirectionalCorrection +#include <boost/test/unit_test.hpp> +#include "DirectionalCorrectionLUT.h" +#include "GlobalDefs.h" +#include "otbImageFileReader.h" +#include "otbImageFileWriter.h" +#include "itkImageRegionIterator.h" +#include "otbWrapperApplication.h" +#include "ImageResampler.h" + +using namespace ts; + +#define WASP_TEST "WASP_TEST" +#define TEST_NAME "test_Preprocessing" + +typedef float FloatPixelType; +typedef otb::Image<FloatPixelType, 2> InputImageType; +typedef otb::Wrapper::FloatVectorImageType FloatVectorImageType; +typedef ts::DirectionalCorrectionLUT DirectionalCorrectionType; +typedef otb::ImageFileReader<FloatVectorImageType> FloatVectorImageReaderType; +typedef otb::ImageFileReader<InputImageType> InputImageReaderType; +typedef short ShortPixelType; +typedef otb::Wrapper::Int16VectorImageType ShortVectorImageType; +typedef otb::ImageFileReader<ShortVectorImageType> ShortVectorImageReaderType; +typedef otb::ImageFileWriter<ShortVectorImageType> ShortVectorImageWriterType; +typedef otb::ImageFileWriter<FloatVectorImageType> FloatVectorImageWriterType; + +BOOST_AUTO_TEST_CASE(testDirectionalCorrectionR2){ + size_t resolution = 1; + std::string wasp_test = getEnvVar(WASP_TEST); + if(wasp_test.empty()){ + std::cout << "Cannot find WASP_TEST environment variable. Exiting..." << std::endl; + exit(1); + } + std::string xml = wasp_test + "/" + + TEST_NAME + "/" + "INPUTS/" + "SENTINEL2A_20180315-144453-175_L2A_T19LGH_D_V1-6/" + "SENTINEL2A_20180315-144453-175_L2A_T19LGH_D_V1-6_MTD_ALL.xml"; + std::cout << "XML : "<< xml << std::endl; + std::string lut_xml = wasp_test + "/" + + TEST_NAME + "/" + "INPUTS/giplut_dircor.xml"; + std::cout << "XML LUT : "<< lut_xml << std::endl; + ImageResampler<InputImageType, InputImageType> resampler; + + DirectionalCorrectionType dirCorr; + std::string scatteringcoeffs = std::string(wasp_test + "/" + TEST_NAME + "/INPUTS/" + "scattering_coeffs_20m.txt"); + InputImageReaderType::Pointer cldReader = InputImageReaderType::New(); + cldReader->SetFileName(wasp_test + "/" + TEST_NAME + "/" + "INPUTS/" + "0_cld10.tif"); + cldReader->UpdateOutputInformation(); + InputImageType::Pointer cldImg = resampler.getResampler(cldReader->GetOutput(), 0.5f)->GetOutput(); + InputImageReaderType::Pointer watReader = InputImageReaderType::New(); + watReader->SetFileName(wasp_test + "/" + TEST_NAME + "/" + "INPUTS/" + "0_wat10.tif"); + watReader->UpdateOutputInformation(); + InputImageType::Pointer watImg = resampler.getResampler(watReader->GetOutput(), 0.5f)->GetOutput(); + InputImageReaderType::Pointer snwReader = InputImageReaderType::New(); + snwReader->SetFileName(wasp_test + "/" + TEST_NAME + "/" + "INPUTS/" + "0_snw10.tif"); + snwReader->UpdateOutputInformation(); + InputImageType::Pointer snwImg = resampler.getResampler(snwReader->GetOutput(), 0.5f)->GetOutput(); + FloatVectorImageReaderType::Pointer anglesReader = FloatVectorImageReaderType::New(); + anglesReader->SetFileName(wasp_test + "/" + TEST_NAME + "/INPUTS/" + "s2angles_raster_r2_bis.tiff"); + anglesReader->UpdateOutputInformation(); + FloatVectorImageType::Pointer anglesImg = anglesReader->GetOutput(); + + dirCorr.Init(resolution, xml, lut_xml, cldImg, watImg, snwImg, anglesImg); + dirCorr.DoExecute(); + ShortVectorImageType::Pointer output = dirCorr.GetCorrectedImg(); + ShortVectorImageReaderType::Pointer gReader = ShortVectorImageReaderType::New(); + gReader->SetFileName(wasp_test + "/" + TEST_NAME + "/INPUTS/" + "/0_CP_R2.tif"); + ShortVectorImageType::Pointer reference = gReader->GetOutput(); + reference->Update(); + output->Update(); + + ShortVectorImageWriterType::Pointer l_writer = ShortVectorImageWriterType::New(); + l_writer->SetInput(output); + l_writer->SetFileName(wasp_test + "/" + TEST_NAME + "/OUTPUTS//0_CP_R2.tif"); + std::cout<<"Writing to "<<wasp_test << "/" << TEST_NAME << "/OUTPUTS//0_CP_R2.tif"<<std::endl; + l_writer->Update(); + + FloatVectorImageWriterType::Pointer l_coeffwriter = FloatVectorImageWriterType::New(); + l_coeffwriter->SetInput(dirCorr.GetCoeffImg()); + l_coeffwriter->SetFileName(wasp_test + "/" + TEST_NAME + "/OUTPUTS//0_COEFF_R2.tif"); + std::cout<<"Writing coeff image to "<<wasp_test << "/" << TEST_NAME << "/OUTPUTS//0_COEFF_R2.tif"<<std::endl; + l_coeffwriter->Update(); + /*itk::ImageRegionIterator<ShortVectorImageType> imageIteratorRef(reference,reference->GetLargestPossibleRegion()); + itk::ImageRegionIterator<ShortVectorImageType> imageIteratorNew(output,output->GetLargestPossibleRegion()); + + BOOST_CHECK_EQUAL(reference->GetLargestPossibleRegion(), output->GetLargestPossibleRegion()); + while(!imageIteratorRef.IsAtEnd()) + { + itk::VariableLengthVector<short> referenceBands = imageIteratorRef.Get(); + itk::VariableLengthVector<short> newBands = imageIteratorNew.Get(); + BOOST_CHECK_EQUAL(referenceBands.GetSize(), newBands.GetSize()); + for(size_t i = 0; i < referenceBands.GetSize(); i++){ + if(!std::isnan(referenceBands[i]) && !std::isnan(newBands[i])){ + BOOST_CHECK_EQUAL(referenceBands[i], newBands[i]); + } + } + ++imageIteratorRef; + ++imageIteratorNew; + }*/ +}; + +#ifdef R1 +BOOST_AUTO_TEST_CASE(testDirectionalCorrectionR1){ + size_t resolution = 0; + std::string wasp_test = getEnvVar(WASP_TEST); + if(wasp_test.empty()){ + std::cout << "Cannot find WASP_TEST environment variable. Exiting..." << std::endl; + exit(1); + } + std::string xml = wasp_test + "/" + + TEST_NAME + "/" + "INPUTS/" + "SENTINEL2A_20180315-144453-175_L2A_T19LGH_D_V1-6/" + "SENTINEL2A_20180315-144453-175_L2A_T19LGH_D_V1-6_MTD_ALL.xml"; + std::cout << "XML : "<< xml << std::endl; + + DirectionalCorrectionType dirCorr; + std::string scatteringcoeffs = std::string(wasp_test + TEST_NAME + "/INPUTS/" + "scattering_coeffs_10m.txt"); + InputImageReaderType::Pointer cldReader = InputImageReaderType::New(); + cldReader->SetFileName(wasp_test + "/" + TEST_NAME + "/" + "INPUTS/" + "0_cld10.tif"); + cldReader->UpdateOutputInformation(); + InputImageType::Pointer cldImg = cldReader->GetOutput(); + InputImageReaderType::Pointer watReader = InputImageReaderType::New(); + watReader->SetFileName(wasp_test + "/" + TEST_NAME + "/" + "INPUTS/" + "0_wat10.tif"); + watReader->UpdateOutputInformation(); + InputImageType::Pointer watImg = watReader->GetOutput(); + InputImageReaderType::Pointer snwReader = InputImageReaderType::New(); + snwReader->SetFileName(wasp_test + "/" + TEST_NAME + "/" + "INPUTS/" + "0_snw10.tif"); + snwReader->UpdateOutputInformation(); + InputImageType::Pointer snwImg = snwReader->GetOutput(); + FloatVectorImageReaderType::Pointer anglesReader = FloatVectorImageReaderType::New(); + anglesReader->SetFileName(wasp_test + "/" + TEST_NAME + "/" + "s2angles_raster_r1.tif"); + anglesReader->UpdateOutputInformation(); + FloatVectorImageType::Pointer anglesImg = anglesReader->GetOutput(); + InputImageReaderType::Pointer ndviReader = InputImageReaderType::New(); + ndviReader->SetFileName(wasp_test + "/" + TEST_NAME + "/" + "ndvi.tif"); + ndviReader->UpdateOutputInformation(); + InputImageType::Pointer ndviImg = ndviReader->GetOutput(); + dirCorr.Init(resolution, xml, scatteringcoeffs, cldImg, watImg, snwImg, anglesImg, ndviImg); + dirCorr.DoExecute(); + ShortVectorImageType::Pointer output = dirCorr.GetCorrectedImg(); + ShortVectorImageReaderType::Pointer gReader = ShortVectorImageReaderType::New(); + gReader->SetFileName(wasp_test + "/" + TEST_NAME + "/0_CP_R1.tif"); + ShortVectorImageType::Pointer reference = gReader->GetOutput(); + reference->Update(); + output->Update(); + itk::ImageRegionIterator<ShortVectorImageType> imageIteratorRef(reference,reference->GetLargestPossibleRegion()); + itk::ImageRegionIterator<ShortVectorImageType> imageIteratorNew(output,output->GetLargestPossibleRegion()); + + BOOST_CHECK_EQUAL(reference->GetLargestPossibleRegion(), output->GetLargestPossibleRegion()); + while(!imageIteratorRef.IsAtEnd()) + { + itk::VariableLengthVector<short> referenceBands = imageIteratorRef.Get(); + itk::VariableLengthVector<short> newBands = imageIteratorNew.Get(); + BOOST_CHECK_EQUAL(referenceBands.GetSize(), newBands.GetSize()); + for(size_t i = 0; i < referenceBands.GetSize(); i++){ + if(!std::isnan(referenceBands[i]) && !std::isnan(newBands[i])){ + BOOST_CHECK_EQUAL(referenceBands[i], newBands[i]); + } + } + ++imageIteratorRef; + ++imageIteratorNew; + } +}; +#endif diff --git a/CompositePreprocessing/test/test_MaskExtractorFilter.cpp b/Code/CompositePreprocessing/test/test_MaskExtractorFilter.cpp similarity index 100% rename from CompositePreprocessing/test/test_MaskExtractorFilter.cpp rename to Code/CompositePreprocessing/test/test_MaskExtractorFilter.cpp diff --git a/Code/LutReader/CMakeLists.txt b/Code/LutReader/CMakeLists.txt new file mode 100644 index 0000000..0547dd8 --- /dev/null +++ b/Code/LutReader/CMakeLists.txt @@ -0,0 +1,33 @@ +set(LutReader_HEADERS + include/vnsLookUpTableExtractor.hpp + include/vnsLookUpTableFileReader.hpp + include/vnsLookUpTable.hpp + include/vnsSimpleLutXMLContainer.hpp + include/vnsVectorLookUpTableExtractor.hpp + include/vnsVectorInterpolateImageFunction.hpp + include/vnsVectorLinearInterpolateImageFunction.hpp + include/vnsVectorLookUpTable.hpp + include/vnsSimpleLutXMLFileHandler.hpp + ) + +set(LutReader_SOURCES + src/vnsSimpleLutXMLContainer.cxx + src/vnsSimpleLutXMLFileHandler.cxx + ) + +add_library(LutReader SHARED ${LutReader_HEADERS} ${LutReader_SOURCES}) +target_link_libraries(LutReader + "${Boost_LIBRARIES}" + "${OTBCommon_LIBRARIES}" + "${OTBTinyXML_LIBRARIES}" + "${OTBITK_LIBRARIES}" + Common + ) + +target_include_directories(LutReader PUBLIC include) + +install(TARGETS LutReader DESTINATION lib/) + +if(BUILD_TESTING) + add_subdirectory(test) +endif() diff --git a/Code/LutReader/include/vnsLookUpTable.hpp b/Code/LutReader/include/vnsLookUpTable.hpp new file mode 100644 index 0000000..2487e93 --- /dev/null +++ b/Code/LutReader/include/vnsLookUpTable.hpp @@ -0,0 +1,195 @@ +/* +* Copyright (C) 2020 Centre National d'Etudes Spatiales (CNES) +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +*/ +/************************************************************************************************************ + * * + * ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo * + * o * + * o * + * o * + * o * + * o ooooooo ooooooo o o oo * + * o o o o o o o o o o * + * o o o o o o o o o o * + * o o o o o o o o o o * + * o o o oooo o o o o o o * + * o o o o o o o o o * + * o o o o o o o o o o * + * oo oooooooo o o o oooooo o oooo * + * o * + * o * + * o o * + * o o oooo o o oooo * + * o o o o o o * + * o o ooo o o ooo * + * o o o o o * + * ooooo oooo o ooooo oooo * + * o * + * * + ************************************************************************************************************ + * * + * Author: CS Systemes d'Information (France) * + * * + ************************************************************************************************************ + * HISTORIQUE * + * * + * VERSION : 1.0.0 : FA : LAIG-FA-MAC-148399-CS : 21 octobre 2016 : Audit code - Correction qualite * + * VERSION : 5-0-0 : FA : LAIG-FA-MAC-143764-CS : 12 avril 2016 : Mise en forme du code (indentation, etc.) * + * VERSION : 4-0-0 : FA : LAIG-FA-MAC-117040-CS : 31 mars 2014 : Modifications mineures * + * VERSION : 1-0-0 : <TypeFT> : <NumFT> : 19 mars 2010 : Creation + * * + * FIN-HISTORIQUE * + * * + * $Id$ + * * + ************************************************************************************************************/ + +#ifndef TSLOOKUPTABLE_H_ +#define TSLOOKUPTABLE_H_ + +#include "otbImage.h" +#include "itkInterpolateImageFunction.h" +#include "itkLinearInterpolateImageFunction.h" +#include <vector> +#include "itkPoint.h" +#include "itkImageRegionIterator.h" +#include "itkSimpleFastMutexLock.h" + +namespace ts +{ + /** \class LookUpTable + * \brief This class implements the Look-Up Tables operations. + * + * This class is used to deal with Look-Up tables. It allows interpolation either + * in floating index values, or in real (physical) values. + * + * \sa LookUpTableExtractor + * + * \ingroup L2 + * \ingroup L3 + * \ingroup Checktool + * + */ + template<class TValue, unsigned int VLUTDimension = 2> + class LookUpTable : public otb::Image<TValue, VLUTDimension> + { + + public: + + /** Types definition for ITK macros */ + typedef LookUpTable<TValue, VLUTDimension> Self; + typedef otb::Image<TValue, VLUTDimension> Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Run-time type information (and related methods). */ + itkTypeMacro( LookUpTable, otb::Image ); + itkNewMacro (Self); + + /** Types definition for values */ + typedef TValue ValueType;itkStaticConstMacro(LUTDimension, unsigned int, VLUTDimension); + + typedef typename Superclass::IndexType IndexType; + typedef typename Superclass::IndexValueType IndexValueType; + typedef typename Superclass::PointType PointType; + typedef typename Superclass::ValueType PointValueType; + + typedef itk::InterpolateImageFunction<Superclass, TValue> InterpolatorType; + + typedef itk::LinearInterpolateImageFunction<Superclass, TValue> DefaultInterpolatorType; + + typedef itk::ImageRegionIterator<Superclass> IteratorType; + + class ParameterValuesType + { + public: + std::string ParameterName; + std::vector<TValue> ParameterValues; + }; + + typedef std::vector<ParameterValuesType> ParametersValuesType; + + /** Getter and Setter for Parameters values */ + //itkGetVectorMacro(ParametersValues, ParametersValuesType,0) + //itkSetVectorMacro(ParametersValues, ParametersValuesType) + ParametersValuesType + GetParametersValues() const + { + return m_ParametersValues; + } + + void + AddParameterValues(const ParameterValuesType &NewParamValues); + + /** Get exact value */ + TValue + GetValue(const IndexType &lutIndex) const; + + /** Set value */ + void + SetValue(const IndexType &lutIndex, TValue value); + + /** Interpolate from physical point values */ + TValue + InterpolateValue(const PointType &PhysicalPoint) const; + + /** Interpolate from physical point values */ + TValue + InterpolateIndex(const PointType &IndexPoint) const; + + /** Find real index from Value */ + TValue + FindIndexInParameterValues(unsigned int ParameterIndex, TValue ParameterValue) const; + + protected: + /** Constructor */ + LookUpTable(); + + /** Destructor */ + virtual + ~LookUpTable(); + + /** Setter for Interpolator instance (Interpolator is itk::LinearInterpolateImageFunction by default) */ + itkSetObjectMacro(Interpolator, InterpolatorType) + + /** Convert physical point into image point (index) */ + PointType ConvertPhysicalPointIntoImagePoint(const PointType &realPoint) const; + + private: + /** Allocate image when all variables values are set */ + void + AllocateLUT(); + + /** Interpolator on image */ + typename InterpolatorType::Pointer m_Interpolator; + + /** Parameters names and values */ + ParametersValuesType m_ParametersValues; + + /** Mutex for interpolation synchronisation */ + itk::SimpleFastMutexLock m_Mutex; + }; + + typedef LookUpTable<double, 1> VNSLUTMonoBand1DType; + typedef LookUpTable<double, 3> VNSLUTMonoBand3DType; + +} // End namespace vns + +#ifndef VNS_MANUAL_INSTANTIATION +#include "vnsLookUpTable.txx" +#endif + +#endif /* VNSLOOKUPTABLE_H_ */ diff --git a/Code/LutReader/include/vnsLookUpTable.txx b/Code/LutReader/include/vnsLookUpTable.txx new file mode 100644 index 0000000..ae37e63 --- /dev/null +++ b/Code/LutReader/include/vnsLookUpTable.txx @@ -0,0 +1,271 @@ +/* +* Copyright (C) 2020 Centre National d'Etudes Spatiales (CNES) +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +*/ +/************************************************************************************************************ + * * + * ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo * + * o * + * o * + * o * + * o * + * o ooooooo ooooooo o o oo * + * o o o o o o o o o o * + * o o o o o o o o o o * + * o o o o o o o o o o * + * o o o oooo o o o o o o * + * o o o o o o o o o * + * o o o o o o o o o o * + * oo oooooooo o o o oooooo o oooo * + * o * + * o * + * o o * + * o o oooo o o oooo * + * o o o o o o * + * o o ooo o o ooo * + * o o o o o * + * ooooo oooo o ooooo oooo * + * o * + * * + ************************************************************************************************************ + * * + * Author: CS Systemes d'Information (France) * + * * + ************************************************************************************************************ + * HISTORIQUE * + * * + * VERSION : 1.0.0 : FA : LAIG-FA-MAC-1988-CNES : 20 octobre 2016 : Correction qualite (code mort) * + * VERSION : 1.0.0 : FA : LAIG-FA-MAC-1990-CNES : 13 octobre 2016 : Correction qualite (TO DO) * + * VERSION : 5-0-0 : FA : LAIG-FA-MAC-143764-CS : 12 avril 2016 : Mise en forme du code (indentation, etc.) * + * VERSION : 4-0-0 : FA : LAIG-FA-MAC-117040-CS : 31 mars 2014 : Modifications mineures * + * VERSION : 1-0-0 : <TypeFT> : <NumFT> : 19 mars 2010 : Creation + * * + * FIN-HISTORIQUE * + * * + * $Id$ + * * + ************************************************************************************************************/ + +#ifndef VNSLOOKUPTABLE_TXX_ +#define VNSLOOKUPTABLE_TXX_ + +#include "vnsLookUpTable.hpp" + +namespace ts +{ + + template<class TValue, unsigned int VLUTDimension> + LookUpTable<TValue, VLUTDimension>::LookUpTable() + { + // Interpolator creation + SetInterpolator(DefaultInterpolatorType::New()); + } + + template<class TValue, unsigned int VLUTDimension> + LookUpTable<TValue, VLUTDimension>::~LookUpTable() + { + } + + // Add parameter values + template<class TValue, unsigned int VLUTDimension> + void + LookUpTable<TValue, VLUTDimension>::AddParameterValues(const ParameterValuesType &NewParamValues) + { + unsigned int lSize = m_ParametersValues.size(); + + // If LUT already has the required number of params + if (lSize == VLUTDimension) + { + // Error and Exit + throw std::runtime_error("Parameters values are all already defined"); + } + + // Store new parameter's name and values + m_ParametersValues.push_back(NewParamValues); + + lSize = m_ParametersValues.size(); + // If LUT now has the required number of params + if (lSize == VLUTDimension) + { + // Allocate image + this->AllocateLUT(); + } + } + + // Get exact value + template<class TValue, unsigned int VLUTDimension> + TValue + LookUpTable<TValue, VLUTDimension>::GetValue(const IndexType &lutIndex) const + { + // Forward to Image + return this->GetPixel(lutIndex); + } + + // Set value + template<class TValue, unsigned int VLUTDimension> + void + LookUpTable<TValue, VLUTDimension>::SetValue(const IndexType &lutIndex, TValue value) + { + // Forward to Image + this->SetPixel(lutIndex, value); + } + + // Interpolate from physical point values + template<class TValue, unsigned int VLUTDimension> + TValue + LookUpTable<TValue, VLUTDimension>::InterpolateValue(const PointType &PhysicalPoint) const + { + // TODO: use a scoped mutex the contention is much too important, this is bad for + // performances + // BTW, why a lock on const variables? Is it because the + // interpolator has a state? + m_Mutex.Lock(); + PointType imagePoint = ConvertPhysicalPointIntoImagePoint(PhysicalPoint); + + TValue ret = InterpolateIndex(imagePoint); + m_Mutex.Unlock(); + return ret; + } + + // Interpolate from physical point values + template<class TValue, unsigned int VLUTDimension> + TValue + LookUpTable<TValue, VLUTDimension>::InterpolateIndex(const PointType &IndexPoint) const + { + // 4.2 TODO Check test LUT tempo + if (m_Interpolator->IsInsideBuffer(IndexPoint) == false) + { + std::cout<<"ATTENTION: the following index point is outside of LUT: " << IndexPoint<<std::endl; + } + try + { + return static_cast<TValue>(m_Interpolator->Evaluate(IndexPoint)); + } + catch (...) + { + // TODO: if the catch is really redundant with the test at the + // start of the function as the message implies, then, don't + // do a try-catch here, and simplify the code! + throw std::runtime_error("ERROR : catch exception during interpolate point outside of LUT : " << IndexPoint); + } + } + // Convert physical point into image point (index) + template<class TValue, unsigned int VLUTDimension> + typename LookUpTable<TValue, VLUTDimension>::PointType + LookUpTable<TValue, VLUTDimension>::ConvertPhysicalPointIntoImagePoint( + const LookUpTable<TValue, VLUTDimension>::PointType &realPoint) const + { + PointType imagePoint; + imagePoint.Fill((PointValueType) 0); + + for (unsigned int dim = 0; dim < VLUTDimension; dim++) + { + imagePoint[dim] = FindIndexInParameterValues(dim, realPoint[dim]); + } + return imagePoint; + } + + template<class TValue, unsigned int VLUTDimension> + TValue + LookUpTable<TValue, VLUTDimension>::FindIndexInParameterValues(unsigned int ParameterIndex, TValue ParameterValue) const + { + // Get the parameter values for the considered parameter index + std::vector<TValue> const& valuesfordim = m_ParametersValues[ParameterIndex].ParameterValues; + + unsigned int index = 0; + const unsigned int size = valuesfordim.size(); + + // Get the index associated to the value + for ( ; index < size - 1 ; ++index) + { + if (valuesfordim[index] >= ParameterValue) + { + break; + } + } + + // If value is outside of bounds, push a warning + if (index == 0) + { + return 0; + } + // The value is greater than the max index value => Interpolation is an extrapolation + if ((index == (size - 1)) && (ParameterValue > valuesfordim[index])) + { + return index; + } + + // Check that the indices that surround the value are different + TValue v2 = valuesfordim[index]; + --index ; + const TValue v1 = valuesfordim[index]; + + const TValue diff = static_cast<TValue>(v2 - v1); + + if ( diff == static_cast<TValue>(0) ) + { + std::cout<<"Warning : Two consecutive indexes of the LUT are identical => return index 0 !!"<<std::endl; + return 0; + } + + // Compute the final index + const TValue k = (ParameterValue - v1) / diff; + + return index + k; + } + + // Allocate Image + template<class TValue, unsigned int VLUTDimension> + void + LookUpTable<TValue, VLUTDimension>::AllocateLUT() + { + std::cout<<"Allocating LookUpTable image dimension = " << (int)(VLUTDimension)<<std::endl; + + // Set Image Region + typename Superclass::IndexType start; + typename Superclass::SizeType size; + + for (unsigned int i = 0; i < VLUTDimension; i++) + { + start[i] = 0; + size[i] = m_ParametersValues[i].ParameterValues.size(); + } + typename Superclass::RegionType region; + + region.SetSize(size); + region.SetIndex(start); + + this->SetRegions(region); + + // Set image spacing to 1.0 + typename Superclass::SpacingType spacing; + spacing.Fill(1.0); + this->SetSpacing(spacing); + + // Set image origin + typename Superclass::PointType origin; + origin.Fill(0.); + this->SetOrigin(origin); + + // Allocate Image + this->Allocate(); + + // Update interpolator + m_Interpolator->SetInputImage(this); + } + +} // End namespace vns + +#endif diff --git a/Code/LutReader/include/vnsLookUpTableExtractor.hpp b/Code/LutReader/include/vnsLookUpTableExtractor.hpp new file mode 100644 index 0000000..ef1b027 --- /dev/null +++ b/Code/LutReader/include/vnsLookUpTableExtractor.hpp @@ -0,0 +1,104 @@ +/* +* Copyright (C) 2020 Centre National d'Etudes Spatiales (CNES) +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +*/ +/************************************************************************************************************ + * * + * ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo * + * o * + * o * + * o * + * o * + * o ooooooo ooooooo o o oo * + * o o o o o o o o o o * + * o o o o o o o o o o * + * o o o o o o o o o o * + * o o o oooo o o o o o o * + * o o o o o o o o o * + * o o o o o o o o o o * + * oo oooooooo o o o oooooo o oooo * + * o * + * o * + * o o * + * o o oooo o o oooo * + * o o o o o o * + * o o ooo o o ooo * + * o o o o o * + * ooooo oooo o ooooo oooo * + * o * + * * + ************************************************************************************************************ + * * + * Author: CS Systemes d'Information (France) * + * * + ************************************************************************************************************ + * HISTORIQUE * + * * + * VERSION : 1-0-0 : <TypeFT> : <NumFT> : 24 mars 2010 : Creation + * * + * FIN-HISTORIQUE * + * * + * $Id$ + * * + ************************************************************************************************************/ +#ifndef __tsLookUpTableExtractor_h +#define __tsLookUpTableExtractor_h + +#include "itkObject.h" +#include "itkPoint.h" + +namespace ts +{ + /** \class LookUpTableExtractor + * \brief This class implements the extraction of sub-LUTs (also called reduced LUTs). + * + * This class is used to extract sub-LUTs from a full LUT, by semi-interpolating on + * the extract point values. This extract point is a "semi-point" for the full LUT, i.e. + * the values are not filled for all dimensions. + * For extracting the sub-LUT, the LookUpTableExtractor uses the full LUT interpolator + * (Linear by default). + * + * \sa LookUpTable + * + * \ingroup L2 + * \ingroup L3 + * \ingroup Checktool + * + */ + template<class TFullLUT, class TReducedLUT> + class LookUpTableExtractor + { + public: + /** Standard class typedefs. */ + typedef LookUpTableExtractor Self; + + typedef itk::Point<typename TFullLUT::InternalPixelType, + TFullLUT::LUTDimension - TReducedLUT::LUTDimension> + ExtractPointType; + + static typename TReducedLUT::Pointer + ExtractLUT(typename TFullLUT::Pointer FullLUT,const ExtractPointType & ReducedPoint); + + protected: + + private: + + }; + +} // End namespace vns + +#include "vnsLookUpTableExtractor.txx" + +#endif /* __vnsLookUpTableExtractor_h */ diff --git a/Code/LutReader/include/vnsLookUpTableExtractor.txx b/Code/LutReader/include/vnsLookUpTableExtractor.txx new file mode 100644 index 0000000..d1a6d94 --- /dev/null +++ b/Code/LutReader/include/vnsLookUpTableExtractor.txx @@ -0,0 +1,166 @@ +/* +* Copyright (C) 2020 Centre National d'Etudes Spatiales (CNES) +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +*/ +/************************************************************************************************************ + * * + * ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo * + * o * + * o * + * o * + * o * + * o ooooooo ooooooo o o oo * + * o o o o o o o o o o * + * o o o o o o o o o o * + * o o o o o o o o o o * + * o o o oooo o o o o o o * + * o o o o o o o o o * + * o o o o o o o o o o * + * oo oooooooo o o o oooooo o oooo * + * o * + * o * + * o o * + * o o oooo o o oooo * + * o o o o o o * + * o o ooo o o ooo * + * o o o o o * + * ooooo oooo o ooooo oooo * + * o * + * * + ************************************************************************************************************ + * * + * Author: CS Systemes d'Information (France) * + * * + ************************************************************************************************************ + * HISTORIQUE * + * * + * VERSION : 5-1-0 : FA : LAIG-FA-MAC-145739-CS : 5 aout 2016 : Audit code - Correction du code * + * VERSION : 4-0-0 : FA : LAIG-FA-MAC-120653-CS : 3 avril 2014 : Correction de règles de qualité * + * VERSION : 1-0-0 : <TypeFT> : <NumFT> : 24 mars 2010 : Creation + * * + * FIN-HISTORIQUE * + * * + * $Id$ + * * + ************************************************************************************************************/ +#ifndef __vnsLookUpTableExtractor_txx +#define __vnsLookUpTableExtractor_txx + +#include "vnsLookUpTableExtractor.hpp" + +namespace ts +{ + + template<class TFullLUT, class TReducedLUT> + typename TReducedLUT::Pointer + LookUpTableExtractor<TFullLUT, TReducedLUT>::ExtractLUT( + typename TFullLUT::Pointer FullLUT, + const ExtractPointType & ReducedPoint) + { + typename TReducedLUT::Pointer ret = TReducedLUT::New(); + + // Dimension of the init LUT + unsigned int FullDimension = TFullLUT::LUTDimension; + // Dimension of the "miniLUT" in which several dimensions were lost by setting + // fixed values for those parameters + unsigned int ReducedDimension = TReducedLUT::LUTDimension; + unsigned int DimensionLost = FullDimension - ReducedDimension; + + // Set kept parameters values */ + typename TFullLUT::ParametersValuesType ParametersValues = + FullLUT->GetParametersValues(); + + + typename TReducedLUT::SizeType size; + typename TReducedLUT::IndexType orig; + unsigned int count = 0; + + // ---------------------------------------------------------------- + // For each kept dimension + // ---------------------------------------------------------------- + for (unsigned int idim = DimensionLost; idim < FullDimension; idim++) + { + // Copy dimension size and origin + size[count] = FullLUT->GetLargestPossibleRegion().GetSize()[idim]; + orig[count] = FullLUT->GetLargestPossibleRegion().GetIndex()[idim]; + count++; + + // Load the name of the parameter + typename TFullLUT::ParameterValuesType values = + ParametersValues[idim]; + + typename TReducedLUT::ParameterValuesType convertedValues; + convertedValues.ParameterName = values.ParameterName; + + // Load the associated indices for each parameter (dimension) of the LUT + const unsigned int NbValues = values.ParameterValues.size(); + for (unsigned int j = 0; j < NbValues; j++) + { + convertedValues.ParameterValues.push_back( + values.ParameterValues[j]); + } + + ret->AddParameterValues(convertedValues); + } + + // ---------------------------------------------------------------- + // Allocate output image + // ---------------------------------------------------------------- + typename TReducedLUT::RegionType region; + region.SetSize(size); + region.SetIndex(orig); + + ret->SetRegions(region); + ret->Allocate(); + + // Copy kept part of the buffer */ + typename TFullLUT::PointType interpPoint; + + // Convert physical values into float index, + // as we do it only once... We save time after ! (instead of interpolating each point on physical values) */ + for (unsigned int i = 0; i < ExtractPointType::PointDimension; i++) + { + interpPoint[i] = FullLUT->FindIndexInParameterValues(i, + ReducedPoint[i]); + } + + // Run over all the sub-LUT + typename TReducedLUT::IteratorType iterator(ret, ret->GetLargestPossibleRegion()); + + iterator.GoToBegin(); + while (iterator.IsAtEnd()==false) + { + // Get coordinates + typename TReducedLUT::IndexType index = iterator.GetIndex(); + + // Complete interpolation point in Full LUT + for (unsigned int i = DimensionLost; i + < FullDimension; i++) + { + interpPoint[i] = index[i - DimensionLost]; + } + + // Interpolate in full LUT and set value in reduced one + iterator.Set(FullLUT->InterpolateIndex(interpPoint)); + + ++iterator; + } + + return ret; + } + +} // End namespace ts + +#endif // __vnsLookUpTableExtractor_txx diff --git a/Code/LutReader/include/vnsLookUpTableFileReader.hpp b/Code/LutReader/include/vnsLookUpTableFileReader.hpp new file mode 100644 index 0000000..6e6d76b --- /dev/null +++ b/Code/LutReader/include/vnsLookUpTableFileReader.hpp @@ -0,0 +1,769 @@ +/* +* Copyright (C) 2020 Centre National d'Etudes Spatiales (CNES) +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +*/ +/************************************************************************************************************ + * * + * ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo * + * o * + * o * + * o * + * o * + * o ooooooo ooooooo o o oo * + * o o o o o o o o o o * + * o o o o o o o o o o * + * o o o o o o o o o o * + * o o o oooo o o o o o o * + * o o o o o o o o o * + * o o o o o o o o o o * + * oo oooooooo o o o oooooo o oooo * + * o * + * o * + * o o * + * o o oooo o o oooo * + * o o o o o o * + * o o ooo o o ooo * + * o o o o o * + * ooooo oooo o ooooo oooo * + * o * + * * + ************************************************************************************************************ + * * + * Author: CS Systemes d'Information (France) * + * * + ************************************************************************************************************ + * HISTORIQUE * + * * + * VERSION : 5-1-0 : FA : LAIG-FA-MAC-145739-CS : 27 juin 2016 : Audit code - Supp de la macro ITK_EXPORT * + * VERSION : 5-1-0 : FA : LAIG-FA-MAC-144674-CS : 2 mai 2016 : Correction warning, qualite, etc * + * VERSION : 4-0-0 : FA : LAIG-FA-MAC-372-CNES : 18 avril 2014 : Decoupage des methodes trop complexes. * + * VERSION : 4-0-0 : FA : LAIG-FA-MAC-117040-CS : 31 mars 2014 : Modifications mineures * + * VERSION : 1-0-0 : <TypeFT> : <NumFT> : 12 mai 2010 : Creation + * * + * FIN-HISTORIQUE * + * * + * $Id$ + * * + ************************************************************************************************************/ + +#ifndef __tsLookUpTableFileReader_h +#define __tsLookUpTableFileReader_h + +#include "itkProcessObject.h" + +#include "vnsLookUpTable.hpp" +#include "vnsVectorLookUpTable.hpp" +#include <fstream> + +namespace ts +{ + + /** \class LookUpTableFileReader + * \brief + * + * LookUpTableFileReader is used to load a LookUpTable file. + * The output is an otbImage or a n otbVectorImage with precision and dimension + * is given as class template. + * + * \ingroup L2 + * + * \sa LookUpTable + * \sa VectorLookUpTable + */ + template<class TLookUpTableType = LookUpTable<double> > + class LookUpTableFileReader : public itk::ProcessObject + { + public: + /** Standard class typedefs. */ + typedef LookUpTableFileReader<TLookUpTableType> Self; + typedef itk::ProcessObject Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + typedef TLookUpTableType LookUpTableType; + typedef typename LookUpTableType::PixelType LookUpTablePixelType; + typedef typename LookUpTableType::InternalPixelType LookUpTableInternalPixelType; + + typedef typename LookUpTableType::ParameterValuesType ParameterValuesType; + typedef typename LookUpTableType::ParametersValuesType ParametersValuesType; + typedef typename LookUpTableType::IndexType IndexType; + typedef typename LookUpTableType::IndexValueType IndexValueType; + + typedef std::vector< std::vector<float> > ListOfListOfFloats; + + typedef itk::VariableLengthVector<LookUpTableInternalPixelType> VectorPixelType; + + /** Method for creation through the object factory. */ + itkNewMacro(Self) + + /** Run-time type information (and related methods). */ + itkTypeMacro(LookUpTableFileReader,itk::ProcessObject) + + /** + * Get the output LookUpTable + * \return The extracted LookUpTablea. + */ + virtual LookUpTableType * + GetLUT(void) + { + return static_cast<LookUpTableType *>(m_LUT); + } + + /** Check FileName : is the nth filename is available */ + bool + IsLookUpTableFile(int num); + + /** Add parameters values to the LUT */ + void + AddParameterValues(const ParameterValuesType &NewParamValues) + { + // Add parameters to the LUT (readind hdr) + m_LUT->AddParameterValues(NewParamValues); + } + + /** LUT bands filename Add/Get */ + void + AddBandFilename(std::string path) + { + m_BandFileName.push_back(path); + // Increase the number of bands + m_LUT->SetNumberOfComponentsPerPixel(m_BandFileName.size()); + } + std::string + GetBandFileName() + { + return m_BandFileName.at(0); + } + std::string + GetBandFileName(unsigned int num) + { + return m_BandFileName.at(num); + } + + /* Read and fill the LUT */ + void + GenerateLUT(void); + + protected: + LookUpTableFileReader(); + virtual + ~LookUpTableFileReader() + { + } + + void + PrintSelf(std::ostream& os, itk::Indent indent) const; + + /** Generate Requested Data */ + virtual void + GenerateData(void) + { + } + + void + SetPixelSize(VectorPixelType & pPix, unsigned int pSize) + { + pPix.SetSize(pSize); + } + void + SetPixelSize(LookUpTableInternalPixelType &, unsigned int) + { + } + + void + SetPixelValue(VectorPixelType & pPix, float var, unsigned int lNumBand) + { + pPix[lNumBand] = static_cast<LookUpTableInternalPixelType>( var); + } + void + SetPixelValue(LookUpTableInternalPixelType & pPix, float var, unsigned int) + { + pPix = static_cast<LookUpTableInternalPixelType>(var); + } + + template<class T> + static std::vector<T> + ReadBinaryFileIntoVector(const std::string & filename) + { + std::fstream lFlux; + lFlux.open(filename.c_str(), std::ios::in | std::ios::binary); + + if (lFlux.fail() == true) + { + throw std::runtime_error("Error while opening the binary filename <" + filename + "> !"); + } + lFlux.seekg(0, lFlux.end); + std::streampos file_length = lFlux.tellg(); + lFlux.seekg(0, lFlux.beg); + std::streampos l_NbValues = (file_length / sizeof(T)); + std::vector<T> l_v(l_NbValues); + + // --------------------------------------------------------------------------------------------- + //Lectures du fichier d'un seul coup + lFlux.read(reinterpret_cast<char *>(&l_v[0]), static_cast<std::size_t>(file_length)); + if (!lFlux) + { + throw std::runtime_error( + "Error while reading the binary file <" + filename + "> not enought data to fill buffer !"); + } + + // --------------------------------------------------------------------------------------------- + lFlux.close(); + return l_v; + } + + private: + LookUpTableFileReader(const LookUpTableFileReader&); //purposely not implemented + void + operator=(const LookUpTableFileReader&); //purposely not implemented + + // ---------------------------------------------------------- + // Generates LUT with 2D + template<class TValue> + void + GenerateXDLUT(VectorLookUpTable<TValue, 2> * pLUT, const ListOfListOfFloats & pBuffersBands, const unsigned int pNbBands) + { + typedef VectorLookUpTable<TValue, 2> LocalLookUpTableType; + + std::cout<<"Generate LUT "<<LocalLookUpTableType::ImageDimension <<"D ..."<<std::endl; + // ---------------------------------------------------------- + // Used only for VectorLUTs + // The pixel size is equal to the number of spectral band + typename LocalLookUpTableType::PixelType lPix = static_cast<typename LocalLookUpTableType::PixelType>(0); + this->SetPixelSize(lPix, pNbBands); + // ---------------------------------------------------------- + // Index of the pixel + typename LocalLookUpTableType::IndexType index; + // ---------------------------------------------------------- + // Fill to 0 + index.Fill((typename LocalLookUpTableType::IndexValueType) 0); + + // ---------------------------------------------------------- + // Initialization + std::streamoff cpt(0); + + const ParametersValuesType & LUT_Indexes(pLUT->GetParametersValues()); + const unsigned int LUT_Indexes0ParameterValuesSize(LUT_Indexes.at(0).ParameterValues.size()); + const unsigned int LUT_Indexes1ParameterValuesSize(LUT_Indexes.at(1).ParameterValues.size()); + + const std::size_t l_NbValues = pBuffersBands.front().size(); + const std::size_t l_IndexSize = LUT_Indexes0ParameterValuesSize * LUT_Indexes1ParameterValuesSize; + + if (l_NbValues != l_IndexSize) + { + throw std::runtime_error( + "The size of the buffered value is incoherent with the size of the indexes parameters values "); + } + // loop over the first parameter (for example TOA reflectance) + for (unsigned int a = 0; a < LUT_Indexes0ParameterValuesSize; a++) + { + index[0] = a; + // loop over the second parameter (for example altitude reflectance) + for (unsigned int b = 0; b < LUT_Indexes1ParameterValuesSize; b++) + { + index[1] = b; + // Number of components per pixel + for (unsigned int lNumBand = 0; lNumBand < pNbBands; lNumBand++) + { + this->SetPixelValue(lPix, pBuffersBands[lNumBand][cpt], lNumBand); + } + cpt++; + pLUT->SetValue(index, lPix); + } + } + } + // ---------------------------------------------------------- + // Generates LUT with 2D + template<class TValue> + void + GenerateXDLUT(LookUpTable<TValue, 2> * pLUT, const ListOfListOfFloats & pBuffersBands, const unsigned int pNbBands) + { + typedef LookUpTable<TValue, 2> LocalLookUpTableType; + + std::cout<<"Generate LUT "<<LocalLookUpTableType::ImageDimension <<"D ..."<<std::endl; + // ---------------------------------------------------------- + // Used only for VectorLUTs + // The pixel size is equal to the number of spectral band + typename LocalLookUpTableType::PixelType lPix = static_cast<typename LocalLookUpTableType::PixelType>(0); + this->SetPixelSize(lPix, pNbBands); + // ---------------------------------------------------------- + // Index of the pixel + typename LocalLookUpTableType::IndexType index; + // ---------------------------------------------------------- + // Fill to 0 + index.Fill((typename LocalLookUpTableType::IndexValueType) 0); + + // ---------------------------------------------------------- + // Initialization + std::streamoff cpt(0); + + const ParametersValuesType & LUT_Indexes(pLUT->GetParametersValues()); + const unsigned int LUT_Indexes0ParameterValuesSize(LUT_Indexes.at(0).ParameterValues.size()); + const unsigned int LUT_Indexes1ParameterValuesSize(LUT_Indexes.at(1).ParameterValues.size()); + + const std::size_t l_NbValues = pBuffersBands.front().size(); + const std::size_t l_IndexSize = LUT_Indexes0ParameterValuesSize * LUT_Indexes1ParameterValuesSize; + + if (l_NbValues != l_IndexSize) + { + throw std::runtime_error( + "The size of the buffered value is incoherent with the size of the indexes parameters values "); + } + + // loop over the first parameter (for example TOA reflectance) + for (unsigned int a = 0; a < LUT_Indexes0ParameterValuesSize; a++) + { + index[0] = a; + // loop over the second parameter (for example altitude reflectance) + for (unsigned int b = 0; b < LUT_Indexes1ParameterValuesSize; b++) + { + index[1] = b; + // Number of components per pixel + for (unsigned int lNumBand = 0; lNumBand < pNbBands; lNumBand++) + { + this->SetPixelValue(lPix, pBuffersBands[lNumBand][cpt], lNumBand); + } + cpt++; + pLUT->SetValue(index, lPix); + } + } + } + // ---------------------------------------------------------- + // Generates LUT with 3D + template<class TValue> + void + GenerateXDLUT(VectorLookUpTable<TValue, 3> * pLUT, const ListOfListOfFloats & pBuffersBands, const unsigned int pNbBands) + { + typedef VectorLookUpTable<TValue, 3> LocalLookUpTableType; + + std::cout<<"Generate LUT "<<LocalLookUpTableType::ImageDimension <<"D ..."<<std::endl; + + // ---------------------------------------------------------- + // Used only for VectorLUTs + // The pixel size is equal to the number of spectral band + typename LocalLookUpTableType::PixelType lPix = static_cast<typename LocalLookUpTableType::PixelType>(0); + this->SetPixelSize(lPix, pNbBands); + // ---------------------------------------------------------- + // Index of the pixel + typename LocalLookUpTableType::IndexType index; + // ---------------------------------------------------------- + // Fill to 0 + index.Fill((typename LocalLookUpTableType::IndexValueType) 0); + + // ---------------------------------------------------------- + // Initialization + std::streamoff cpt(0); + + const ParametersValuesType & LUT_Indexes(pLUT->GetParametersValues()); + const unsigned int LUT_Indexes0ParameterValuesSize(LUT_Indexes.at(0).ParameterValues.size()); + const unsigned int LUT_Indexes1ParameterValuesSize(LUT_Indexes.at(1).ParameterValues.size()); + const unsigned int LUT_Indexes2ParameterValuesSize(LUT_Indexes.at(2).ParameterValues.size()); + const std::size_t l_NbValues = pBuffersBands.front().size(); + const std::size_t l_IndexSize = LUT_Indexes0ParameterValuesSize * LUT_Indexes1ParameterValuesSize + * LUT_Indexes2ParameterValuesSize; + if (l_NbValues != l_IndexSize) + { + throw std::runtime_error( + "The size of the buffered value is incoherent with the size of the indexes parameters values"); + } + // loop over the first parameter (for example TOA reflectance) + for (unsigned int a = 0; a < LUT_Indexes0ParameterValuesSize; a++) + { + index[0] = a; + // loop over the second parameter (for example AOT) + for (unsigned int b = 0; b < LUT_Indexes1ParameterValuesSize; b++) + { + index[1] = b; + // loop over the third parameter (for example altitude) + for (unsigned int c = 0; c < LUT_Indexes2ParameterValuesSize; c++) + { + index[2] = c; + // Number of components per pixel + for (unsigned int lNumBand = 0; lNumBand < pNbBands; lNumBand++) + { + this->SetPixelValue(lPix, pBuffersBands[lNumBand][cpt], lNumBand); + + } + pLUT->SetValue(index, lPix); + cpt++; + } + } + } + } + // ---------------------------------------------------------- + // Generates LUT with 3D + template<class TValue> + void + GenerateXDLUT(LookUpTable<TValue, 3> * pLUT, const ListOfListOfFloats & pBuffersBands, const unsigned int pNbBands) + { + typedef LookUpTable<TValue, 3> LocalLookUpTableType; + + std::cout<<"Generate LUT "<<LocalLookUpTableType::ImageDimension <<"D ..."<<std::endl; + + // ---------------------------------------------------------- + // Used only for VectorLUTs + // The pixel size is equal to the number of spectral band + typename LocalLookUpTableType::PixelType lPix = static_cast<typename LocalLookUpTableType::PixelType>(0); + this->SetPixelSize(lPix, pNbBands); + // ---------------------------------------------------------- + // Index of the pixel + typename LocalLookUpTableType::IndexType index; + // ---------------------------------------------------------- + // Fill to 0 + index.Fill((typename LocalLookUpTableType::IndexValueType) 0); + + // ---------------------------------------------------------- + // Initialization + std::streamoff cpt(0); + + const ParametersValuesType & LUT_Indexes(pLUT->GetParametersValues()); + const unsigned int LUT_Indexes0ParameterValuesSize(LUT_Indexes.at(0).ParameterValues.size()); + const unsigned int LUT_Indexes1ParameterValuesSize(LUT_Indexes.at(1).ParameterValues.size()); + const unsigned int LUT_Indexes2ParameterValuesSize(LUT_Indexes.at(2).ParameterValues.size()); + const std::size_t l_NbValues = pBuffersBands.front().size(); + const std::size_t l_IndexSize = LUT_Indexes0ParameterValuesSize * LUT_Indexes1ParameterValuesSize + * LUT_Indexes2ParameterValuesSize; + if (l_NbValues != l_IndexSize) + { + throw std::runtime_error( + "The size of the buffered value is incoherent with the size of the indexes parameters values "); + } + + // loop over the first parameter (for example TOA reflectance) + for (unsigned int a = 0; a < LUT_Indexes0ParameterValuesSize; a++) + { + index[0] = a; + // loop over the second parameter (for example AOT) + for (unsigned int b = 0; b < LUT_Indexes1ParameterValuesSize; b++) + { + index[1] = b; + // loop over the third parameter (for example altitude) + for (unsigned int c = 0; c < LUT_Indexes2ParameterValuesSize; c++) + { + index[2] = c; + // Number of components per pixel + for (unsigned int lNumBand = 0; lNumBand < pNbBands; lNumBand++) + { + this->SetPixelValue(lPix, pBuffersBands[lNumBand][cpt], lNumBand); + + } + pLUT->SetValue(index, lPix); + cpt++; + } + } + } + } + // ---------------------------------------------------------- + // Generates LUT with 4D + template<class TValue> + void + GenerateXDLUT(VectorLookUpTable<TValue, 4> * pLUT, const ListOfListOfFloats & pBuffersBands, const unsigned int pNbBands) + { + typedef VectorLookUpTable<TValue, 4> LocalLookUpTableType; + + std::cout<<"Generate LUT "<<LocalLookUpTableType::ImageDimension <<"D ..."<<std::endl; + + // ---------------------------------------------------------- + // Used only for VectorLUTs + // The pixel size is equal to the number of spectral band + typename LocalLookUpTableType::PixelType lPix = static_cast<typename LocalLookUpTableType::PixelType>(0); + this->SetPixelSize(lPix, pNbBands); + // ---------------------------------------------------------- + // Index of the pixel + typename LocalLookUpTableType::IndexType index; + // ---------------------------------------------------------- + // Fill to 0 + index.Fill((typename LocalLookUpTableType::IndexValueType) 0); + + // ---------------------------------------------------------- + // Initialization + std::streamoff cpt(0); + + const ParametersValuesType & LUT_Indexes(pLUT->GetParametersValues()); + const unsigned int LUT_Indexes0ParameterValuesSize(LUT_Indexes.at(0).ParameterValues.size()); + const unsigned int LUT_Indexes1ParameterValuesSize(LUT_Indexes.at(1).ParameterValues.size()); + const unsigned int LUT_Indexes2ParameterValuesSize(LUT_Indexes.at(2).ParameterValues.size()); + const unsigned int LUT_Indexes3ParameterValuesSize(LUT_Indexes.at(3).ParameterValues.size()); + const std::size_t l_NbValues = pBuffersBands.front().size(); + const std::size_t l_IndexSize = LUT_Indexes0ParameterValuesSize * LUT_Indexes1ParameterValuesSize + * LUT_Indexes2ParameterValuesSize * LUT_Indexes3ParameterValuesSize; + if (l_NbValues != l_IndexSize) + { + throw std::runtime_error( + "The size of the buffered value is incoherent with the size of the indexes parameters values "); + } + + for (unsigned int a = 0; a < LUT_Indexes0ParameterValuesSize; a++) + { + index[0] = a; + for (unsigned int b = 0; b < LUT_Indexes1ParameterValuesSize; b++) + { + index[1] = b; + for (unsigned int c = 0; c < LUT_Indexes2ParameterValuesSize; c++) + { + index[2] = c; + for (unsigned int d = 0; d < LUT_Indexes3ParameterValuesSize; d++) + { + index[3] = d; + // Number of components per pixel + for (unsigned int lNumBand = 0; lNumBand < pNbBands; lNumBand++) + { + this->SetPixelValue(lPix, pBuffersBands[lNumBand][cpt], lNumBand); + + } + pLUT->SetValue(index, lPix); + cpt++; + } + } + } + } + } + // ---------------------------------------------------------- + // Generates LUT with 4D + template<class TValue> + void + GenerateXDLUT(LookUpTable<TValue, 4> * pLUT, const ListOfListOfFloats & pBuffersBands, const unsigned int pNbBands) + { + typedef LookUpTable<TValue, 4> LocalLookUpTableType; + + std::cout<<"Generate LUT "<<LocalLookUpTableType::ImageDimension <<"D ..."<<std::endl; + + // ---------------------------------------------------------- + // Used only for VectorLUTs + // The pixel size is equal to the number of spectral band + typename LocalLookUpTableType::PixelType lPix = static_cast<typename LocalLookUpTableType::PixelType>(0); + this->SetPixelSize(lPix, pNbBands); + // ---------------------------------------------------------- + // Index of the pixel + typename LocalLookUpTableType::IndexType index; + // ---------------------------------------------------------- + // Fill to 0 + index.Fill((typename LocalLookUpTableType::IndexValueType) 0); + + // ---------------------------------------------------------- + // Initialization + std::streamoff cpt(0); + + const ParametersValuesType & LUT_Indexes(pLUT->GetParametersValues()); + const unsigned int LUT_Indexes0ParameterValuesSize(LUT_Indexes.at(0).ParameterValues.size()); + const unsigned int LUT_Indexes1ParameterValuesSize(LUT_Indexes.at(1).ParameterValues.size()); + const unsigned int LUT_Indexes2ParameterValuesSize(LUT_Indexes.at(2).ParameterValues.size()); + const unsigned int LUT_Indexes3ParameterValuesSize(LUT_Indexes.at(3).ParameterValues.size()); + + const std::size_t l_NbValues = pBuffersBands.front().size(); + const std::size_t l_IndexSize = LUT_Indexes0ParameterValuesSize * LUT_Indexes1ParameterValuesSize + * LUT_Indexes2ParameterValuesSize * LUT_Indexes3ParameterValuesSize; + if (l_NbValues != l_IndexSize) + { + throw std::runtime_error( + "The size of the buffered value is incoherent with the size of the indexes parameters values"); + } + + for (unsigned int a = 0; a < LUT_Indexes0ParameterValuesSize; a++) + { + index[0] = a; + for (unsigned int b = 0; b < LUT_Indexes1ParameterValuesSize; b++) + { + index[1] = b; + for (unsigned int c = 0; c < LUT_Indexes2ParameterValuesSize; c++) + { + index[2] = c; + for (unsigned int d = 0; d < LUT_Indexes3ParameterValuesSize; d++) + { + index[3] = d; + // Number of components per pixel + for (unsigned int lNumBand = 0; lNumBand < pNbBands; lNumBand++) + { + this->SetPixelValue(lPix, pBuffersBands[lNumBand][cpt], lNumBand); + } + pLUT->SetValue(index, lPix); + cpt++; + } + } + } + } + } + + // ---------------------------------------------------------- + // Generates LUT with 6D + template<class TValue> + void + GenerateXDLUT(VectorLookUpTable<TValue, 6> * pLUT, const ListOfListOfFloats & pBuffersBands, const unsigned int pNbBands) + { + typedef VectorLookUpTable<TValue, 6> LocalLookUpTableType; + + std::cout<<"Generate LUT "<<LocalLookUpTableType::ImageDimension <<"D ..."<<std::endl; + + // ---------------------------------------------------------- + // Used only for VectorLUTs + // The pixel size is equal to the number of spectral band + typename LocalLookUpTableType::PixelType lPix = static_cast<typename LocalLookUpTableType::PixelType>(0); + this->SetPixelSize(lPix, pNbBands); + + // ---------------------------------------------------------- + // Index of the pixel + typename LocalLookUpTableType::IndexType index; + // ---------------------------------------------------------- + // Fill to 0 + index.Fill((typename LocalLookUpTableType::IndexValueType) 0); + + // ---------------------------------------------------------- + // Initialization + std::streamoff cpt(0); + + // ---------------------------------------------------------- + //Init parameters + const ParametersValuesType & LUT_Indexes(pLUT->GetParametersValues()); + const unsigned int LUT_Indexes0ParameterValuesSize(LUT_Indexes.at(0).ParameterValues.size()); + const unsigned int LUT_Indexes1ParameterValuesSize(LUT_Indexes.at(1).ParameterValues.size()); + const unsigned int LUT_Indexes2ParameterValuesSize(LUT_Indexes.at(2).ParameterValues.size()); + const unsigned int LUT_Indexes3ParameterValuesSize(LUT_Indexes.at(3).ParameterValues.size()); + const unsigned int LUT_Indexes4ParameterValuesSize(LUT_Indexes.at(4).ParameterValues.size()); + const unsigned int LUT_Indexes5ParameterValuesSize(LUT_Indexes.at(5).ParameterValues.size()); + + const std::size_t l_NbValues = pBuffersBands.front().size(); + const std::size_t l_IndexSize = LUT_Indexes0ParameterValuesSize * LUT_Indexes1ParameterValuesSize + * LUT_Indexes2ParameterValuesSize * LUT_Indexes3ParameterValuesSize * LUT_Indexes4ParameterValuesSize + * LUT_Indexes5ParameterValuesSize; + if (l_NbValues != l_IndexSize) + { + throw std::runtime_error( + "The size of the buffered value is incoherent with the size of the indexes parameters values"); + } + + for (unsigned int a = 0; a < LUT_Indexes0ParameterValuesSize; a++) + { + index[0] = a; + for (unsigned int b = 0; b < LUT_Indexes1ParameterValuesSize; b++) + { + index[1] = b; + for (unsigned int c = 0; c < LUT_Indexes2ParameterValuesSize; c++) + { + index[2] = c; + for (unsigned int d = 0; d < LUT_Indexes3ParameterValuesSize; d++) + { + index[3] = d; + for (unsigned int e = 0; e < LUT_Indexes4ParameterValuesSize; e++) + { + index[4] = e; + for (unsigned int f = 0; f < LUT_Indexes5ParameterValuesSize; f++) + { + index[5] = f; + // Number of components per pixel + for (unsigned int lNumBand = 0; lNumBand < pNbBands; lNumBand++) + { + this->SetPixelValue(lPix, pBuffersBands[lNumBand][cpt], lNumBand); + } + pLUT->SetValue(index, lPix); + cpt++; + } + } + } + } + } + } + } + // ---------------------------------------------------------- + // Generates LUT with 6D + template<class TValue> + void + GenerateXDLUT(LookUpTable<TValue, 6> * pLUT, const ListOfListOfFloats & pBuffersBands, const unsigned int pNbBands) + { + typedef LookUpTable<TValue, 6> LocalLookUpTableType; + + std::cout<<"Generate LUT "<<LocalLookUpTableType::ImageDimension <<"D ..."<<std::endl; + + // ---------------------------------------------------------- + // Used only for VectorLUTs + // The pixel size is equal to the number of spectral band + typename LocalLookUpTableType::PixelType lPix = static_cast<typename LocalLookUpTableType::PixelType>(0); + this->SetPixelSize(lPix, pNbBands); + + // ---------------------------------------------------------- + // Index of the pixel + typename LocalLookUpTableType::IndexType index; + // ---------------------------------------------------------- + // Fill to 0 + index.Fill((typename LocalLookUpTableType::IndexValueType) 0); + + // ---------------------------------------------------------- + // Initialization + std::streamoff cpt(0); + + // ---------------------------------------------------------- + //Init parameters + const ParametersValuesType & LUT_Indexes(pLUT->GetParametersValues()); + const unsigned int LUT_Indexes0ParameterValuesSize(LUT_Indexes.at(0).ParameterValues.size()); + const unsigned int LUT_Indexes1ParameterValuesSize(LUT_Indexes.at(1).ParameterValues.size()); + const unsigned int LUT_Indexes2ParameterValuesSize(LUT_Indexes.at(2).ParameterValues.size()); + const unsigned int LUT_Indexes3ParameterValuesSize(LUT_Indexes.at(3).ParameterValues.size()); + const unsigned int LUT_Indexes4ParameterValuesSize(LUT_Indexes.at(4).ParameterValues.size()); + const unsigned int LUT_Indexes5ParameterValuesSize(LUT_Indexes.at(5).ParameterValues.size()); + + const std::size_t l_NbValues = pBuffersBands.front().size(); + const std::size_t l_IndexSize = LUT_Indexes0ParameterValuesSize * LUT_Indexes1ParameterValuesSize + * LUT_Indexes2ParameterValuesSize * LUT_Indexes3ParameterValuesSize * LUT_Indexes4ParameterValuesSize + * LUT_Indexes5ParameterValuesSize; + if (l_NbValues != l_IndexSize) + { + throw std::runtime_error( + "The size of the buffered value is incoherent with the size of the indexes parameters values"); + } + + for (unsigned int a = 0; a < LUT_Indexes0ParameterValuesSize; a++) + { + index[0] = a; + for (unsigned int b = 0; b < LUT_Indexes1ParameterValuesSize; b++) + { + index[1] = b; + for (unsigned int c = 0; c < LUT_Indexes2ParameterValuesSize; c++) + { + index[2] = c; + for (unsigned int d = 0; d < LUT_Indexes3ParameterValuesSize; d++) + { + index[3] = d; + for (unsigned int e = 0; e < LUT_Indexes4ParameterValuesSize; e++) + { + index[4] = e; + for (unsigned int f = 0; f < LUT_Indexes5ParameterValuesSize; f++) + { + index[5] = f; + // Number of components per pixel + for (unsigned int lNumBand = 0; lNumBand < pNbBands; lNumBand++) + { + this->SetPixelValue(lPix, pBuffersBands[lNumBand][cpt], lNumBand); + } + pLUT->SetValue(index, lPix); + cpt++; + } + } + } + } + } + } + } + + /** LUT Bands filename */ + std::vector<std::string> m_BandFileName; + + /** LUT Object */ + typename LookUpTableType::Pointer m_LUT; + }; + +} // end namespace ts + +#include "vnsLookUpTableFileReader.txx" + +#endif diff --git a/Code/LutReader/include/vnsLookUpTableFileReader.txx b/Code/LutReader/include/vnsLookUpTableFileReader.txx new file mode 100644 index 0000000..093e0c4 --- /dev/null +++ b/Code/LutReader/include/vnsLookUpTableFileReader.txx @@ -0,0 +1,196 @@ +/* +* Copyright (C) 2020 Centre National d'Etudes Spatiales (CNES) +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +*/ +/************************************************************************************************************ + * * + * ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo * + * o * + * o * + * o * + * o * + * o ooooooo ooooooo o o oo * + * o o o o o o o o o o * + * o o o o o o o o o o * + * o o o o o o o o o o * + * o o o oooo o o o o o o * + * o o o o o o o o o * + * o o o o o o o o o o * + * oo oooooooo o o o oooooo o oooo * + * o * + * o * + * o o * + * o o oooo o o oooo * + * o o o o o o * + * o o ooo o o ooo * + * o o o o o * + * ooooo oooo o ooooo oooo * + * o * + * * + ************************************************************************************************************ + * * + * Author: CS Systemes d'Information (France) * + * * + ************************************************************************************************************ + * HISTORIQUE * + * * + * VERSION : 5-1-0 : FA : LAIG-FA-MAC-144674-CS : 2 mai 2016 : Correction warning, qualite, etc * + * VERSION : 4-4-0 : FA : LAIG-FA-MAC-127944-CS : 3 juin 2015 : Correction code pour la qualite * + * VERSION : 4-0-0 : FA : LAIG-FA-MAC-372-CNES : 18 avril 2014 : Decoupage des methodes trop complexes. * + * VERSION : 4-0-0 : FA : LAIG-FA-MAC-117040-CS : 31 mars 2014 : Modifications mineures * + * VERSION : 3-0-0 : FA : LAIG-FA-MAC-371-CNES : 05 octobre 2012 : Correction qualite : taux de commentaire * + * VERSION : 1-0-0 : <TypeFT> : <NumFT> : 31 mai 2010 : Creation + * * + * FIN-HISTORIQUE * + * * + * $Id$ + * * + ***********************************************************************************************************/ +#ifndef __vnsLookUpTableFileReader_txx +#define __vnsLookUpTableFileReader_txx + +#include "vnsLookUpTableFileReader.hpp" +#include "itksys/SystemTools.hxx" +#include "itkIndex.h" +#include "itkMacro.h" + + +namespace ts +{ + + // Constructor + template<class TLookUpTableType> + LookUpTableFileReader<TLookUpTableType>::LookUpTableFileReader() + { + // Setup the number of required inputs. + this->SetNumberOfRequiredInputs(0); + this->SetNumberOfIndexedInputs(0); + m_LUT = LookUpTableType::New(); + m_LUT->SetNumberOfComponentsPerPixel(1); + } + + template<class TLookUpTableType> + bool + LookUpTableFileReader<TLookUpTableType>::IsLookUpTableFile(int num) + { + // --------------------------------------------------------------------------------------------- + std::string lFilename = this->GetBandFileName(num); + // If empty filename, throws an exception + if (lFilename == "") + { + std::cout<<"No Look up Table file specified."<<std::endl; + return false; + } + + // --------------------------------------------------------------------------------------------- + // If file don't exist, throws an exception + if (itksys::SystemTools::FileExists(lFilename.c_str()) == false) + { + std::cout<<"Look up Table file "<< lFilename<<" doesn't exist."<<std::endl; + return false; + } + + // --------------------------------------------------------------------------------------------- + // If the filename is not a file (ex: directory, ...) + if (itksys::SystemTools::FileIsDirectory(lFilename.c_str()) == true) + { + std::cout<<"Look up Table file "<< lFilename<<" is not a file."<<std::endl; + return false; + } + + return true; + } + + // Parse the LUT file and generate the LookUpTable. + template<class TLookUpTableType> + void + LookUpTableFileReader<TLookUpTableType>::GenerateLUT(void) + { + + // Initialization + const unsigned int lNbBands(m_BandFileName.size()); + const unsigned int lSize(m_LUT->GetNumberOfComponentsPerPixel()); + //std::fstream lFile; + // ---------------------------------------------------------- + // Check the number of spectral band of the LUT + // ---------------------------------------------------------- + if (lNbBands != lSize) + { + throw std::runtime_error( + "LookUpTableFileReader::GenerateData() : the number of bands is not correct" ); + } + + // ---------------------------------------------------------- + // Open the binary files + // ---------------------------------------------------------- + std::vector< std::vector<float> > l_BuffersBands; + for (unsigned int lNumBand = 0; lNumBand < lNbBands; lNumBand++) + { + // std::fstream* plFile = new std::fstream(); + std::string lFilename = this->GetBandFileName(lNumBand); + std::cout<<"GenerateLUT: Reading file for GenerateData(): " << lFilename<<std::endl; + + // Check if one LUT file exists for each spectral band + bool isLutFile = this->IsLookUpTableFile(lNumBand); + if (isLutFile == false) + { + throw std::runtime_error("LookUpTableFileReader::GenerateData() : Invalid Look up Table file : "+lFilename+"."); + } + // ---------------------------------------------------------- + // Read the binary file + // ---------------------------------------------------------- + l_BuffersBands.push_back(ReadBinaryFileIntoVector<float>(lFilename)); + std::cout<<"GenerateLUT: Reading '"<<l_BuffersBands.back().size() <<"' values for filename " << lFilename << "."<<std::endl; + + } + // ---------------------------------------------------------- + // Check nb value for each bands + const std::size_t l_NbValues = l_BuffersBands[0].size(); + for (unsigned int lNumBand = 1; lNumBand < lNbBands; lNumBand++) + { + if (l_BuffersBands[lNumBand].size() != l_NbValues) + { + throw std::runtime_error( + "Error: incoherence between nb value read from the band " + "and the fnb value from the first band in the binaries file of the LookUpTable !"); + } + } + + // ---------------------------------------------------------- + // Fill the LUT + // ---------------------------------------------------------- + // The LUT that provides surface reflectance depends on several parameters + // (TOA reflectance, AOT, altitude, viewing and solar zenith angles, relative azimuth angle) + // For Venus, only the first three parameters varies and the other ones are set + // to a constant value In order to accelerate the interpolation, + // ---------------------------------------------------------- + // Reorganize the LUT : + // TOA reflectance value -> AOT value -> altitude value -> one value for each spectral band + // ---------------------------------------------------------- + this->GenerateXDLUT(this->GetLUT(), l_BuffersBands, lNbBands); + } + + // + template<class TLookUpTableType> + void + LookUpTableFileReader<TLookUpTableType>::PrintSelf(std::ostream& os, itk::Indent indent) const + { + // Print + Superclass::PrintSelf(os, indent); + } + +} // end namespace ts + +#endif diff --git a/Code/LutReader/include/vnsSimpleLutXMLContainer.hpp b/Code/LutReader/include/vnsSimpleLutXMLContainer.hpp new file mode 100644 index 0000000..3ebdbdb --- /dev/null +++ b/Code/LutReader/include/vnsSimpleLutXMLContainer.hpp @@ -0,0 +1,134 @@ +/* +* Copyright (C) 2020 Centre National d'Etudes Spatiales (CNES) +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +*/ +/* + * SimpleLUTXMLFileHandler.h + * + * Created on: 26 oct. 2017 + * Author: besquis + */ +#ifndef CODE_CORE_DATA_IO_VNSSIMPLELUTXMLCONTAINER_HPP_ +#define CODE_CORE_DATA_IO_VNSSIMPLELUTXMLCONTAINER_HPP_ + +#include <vector> +#include <string> + +namespace ts +{ +class SimpleLutXMLContainer +{ +public: + + typedef std::vector<double> ListOfDoubles; + typedef std::vector<std::string> ListOfStrings; + + SimpleLutXMLContainer(); + virtual ~SimpleLutXMLContainer(); + + SimpleLutXMLContainer& operator=(const SimpleLutXMLContainer&); + + //----------------------------------------------------------------------------- + //----------------------------------------------------------------------------- + //----------------------------------------------------------------------------- + //----------------------------------------------------------------------------- + // Look Up Table Header + //----------------------------------------------------------------------------- + // Read the EarthExplorer field LUT Index 'Altitude_Indexes' + const ListOfDoubles& + GetAltitude_Indexes() const + { + return m_AtlIndx; + } + void SetAltitude_Indexes(const ListOfDoubles& list); + + // Read the EarthExplorer field LUT Index 'AOT_Indexes' + const ListOfDoubles& + GetAOT_Indexes() const + { + return m_AOTIndx; + } + void SetAOT_Indexes(const ListOfDoubles& list); + + // Read the EarthExplorer field LUT Index 'TOA_Reflectance_Indexes' + const ListOfDoubles& + GetTOA_Reflectance_Indexes() const + { + return m_TOAIdx; + } + void SetTOA_Reflectance_Indexes(const ListOfDoubles& list); + + // Read the EarthExplorer field LUT Index 'Reflectance_Ratio_Indexes' for WATV + const ListOfDoubles& + GetReflectance_Ratio_Indexes() const + { + return m_ReflRatioIdx; + } + void SetReflectance_Ratio_Indexes(const ListOfDoubles& list); + + // Read the EarthExplorer field LUT Index 'View_Zenith_Angle_Indexes' + const ListOfDoubles& + GetView_Zenith_Angle_Indexes() const + { + return m_VieZenithAngleIndx; + } + void SetView_Zenith_Angle_Indexes(const ListOfDoubles& list); + // Read the EarthExplorer field LUT Index 'Solar_Zenith_Angle_Indexes' + const ListOfDoubles& + GetSolar_Zenith_Angle_Indexes() const + { + return m_SolZenithIndx; + } + void SetSolar_Zenith_Angle_Indexes(const ListOfDoubles& list); + + // Read the EarthExplorer field LUT Index 'Relative_Azimuth_Angle_Indexes' + const ListOfDoubles& + GetRelative_Azimuth_Angle_Indexes() const + { + return m_RelAziIndx; + } + void SetRelative_Azimuth_Angle_Indexes(const ListOfDoubles& list); + + // Read the EarthExplorer field LUT Index 'Zenithal_Angle_Indexes' + const ListOfDoubles& + GetZenithal_Angle_Indexes() const + { + return m_ZenithalIndx; + } + void SetZenithal_Angle_Indexes(const ListOfDoubles& list); + + const ListOfStrings& + GetListOfPackaged_DBL_Files() const + { + return m_ListOfFiles; + } + void SetListOfPackaged_DBL_Files(const ListOfStrings& list); + + +protected: + + ListOfDoubles m_ZenithalIndx; + ListOfDoubles m_RelAziIndx; + ListOfDoubles m_SolZenithIndx; + ListOfDoubles m_VieZenithAngleIndx; + ListOfDoubles m_ReflRatioIdx; + ListOfDoubles m_TOAIdx; + ListOfDoubles m_AOTIndx; + ListOfDoubles m_AtlIndx; + ListOfStrings m_ListOfFiles; +}; + +} +#endif /* CODE_CORE_DATA_IO_VNSSIMPLELUTXMLCONTAINER_HPP_ */ diff --git a/Code/LutReader/include/vnsSimpleLutXMLFileHandler.hpp b/Code/LutReader/include/vnsSimpleLutXMLFileHandler.hpp new file mode 100644 index 0000000..ea643c4 --- /dev/null +++ b/Code/LutReader/include/vnsSimpleLutXMLFileHandler.hpp @@ -0,0 +1,64 @@ +/* +* Copyright (C) 2020 Centre National d'Etudes Spatiales (CNES) +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +*/ +/* + * SimpleLUTXMLFileHandler.h + * + * Created on: 26 oct. 2017 + * Author: besquis + */ +#ifndef CODE_CORE_DATA_IO_VNSSIMPLELUTXMLFILEHANDLER_HPP_ +#define CODE_CORE_DATA_IO_VNSSIMPLELUTXMLFILEHANDLER_HPP_ + +#include "vnsSimpleLutXMLContainer.hpp" +#include "itkObject.h" +#include "itkObjectFactory.h" + +namespace ts +{ +class SimpleLutXMLFileHandler : public itk::Object +{ +public: + typedef SimpleLutXMLFileHandler Self; + typedef itk::Object Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Run-time type information (and related methods). */ + itkTypeMacro( SimpleLutXMLFileHandler, itk::Object ); + + /** New macro for creation of through a Smart Pointer */ + itkNewMacro( Self ); + + typedef std::vector<double> ListOfDoubles; + typedef std::vector< std::string > ListOfStrings; + + void LoadFile(const std::string& filename); + + const SimpleLutXMLContainer& GetLutContainer() const + { + return m_Container; + } + +protected: + SimpleLutXMLFileHandler(); + virtual ~SimpleLutXMLFileHandler(); + + SimpleLutXMLContainer m_Container; +}; + +} +#endif /* CODE_CORE_DATA_IO_VNSSIMPLESMACXMLFILEHANDLER_HPP_ */ diff --git a/Code/LutReader/include/vnsVectorInterpolateImageFunction.hpp b/Code/LutReader/include/vnsVectorInterpolateImageFunction.hpp new file mode 100644 index 0000000..76cbbbd --- /dev/null +++ b/Code/LutReader/include/vnsVectorInterpolateImageFunction.hpp @@ -0,0 +1,246 @@ +/* +* Copyright (C) 2020 Centre National d'Etudes Spatiales (CNES) +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +*/ +/************************************************************************************************************ + * * + * ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo * + * o * + * o * + * o * + * o * + * o ooooooo ooooooo o o oo * + * o o o o o o o o o o * + * o o o o o o o o o o * + * o o o o o o o o o o * + * o o o oooo o o o o o o * + * o o o o o o o o o * + * o o o o o o o o o o * + * oo oooooooo o o o oooooo o oooo * + * o * + * o * + * o o * + * o o oooo o o oooo * + * o o o o o o * + * o o ooo o o ooo * + * o o o o o * + * ooooo oooo o ooooo oooo * + * o * + * * + ************************************************************************************************************ + * * + * Author: CS Systemes d'Information (France) * + * * + ************************************************************************************************************ + * HISTORIQUE * + * * + * VERSION : 5-1-0 : FA : LAIG-FA-MAC-145739-CS : 27 juin 2016 : Audit code - Supp de la macro ITK_EXPORT * + * VERSION : 5-1-0 : FA : LAIG-FA-MAC-144674-CS : 26 mai 2016 : Modifications cosmetique et menage, etc... * + * VERSION : 4-0-0 : FA : LAIG-FA-MAC-120653-CS : 7 mai 2014 : Correction de règles qualité ou commentaires * + * VERSION : 1-0-0 : <TypeFT> : <NumFT> : 10 avril 2010 : Creation + * * + * FIN-HISTORIQUE * + * * + * $Id$ + * * + ************************************************************************************************************/ +#ifndef __vnsVectorInterpolateImageFunction_h +#define __vnsVectorInterpolateImageFunction_h + +#include "itkImageFunction.h" +#include "itkFixedArray.h" + +namespace ts +{ + + /** + * Due to a bug in MSVC, an enum value cannot be accessed out of a template + * parameter until the template class opens. In order for templated classes + * to access the dimension of a template parameter in defining their + * own dimension, this class is needed as a work-around. + */ + template<typename T> + struct GetDimension + { + itkStaticConstMacro(Dimension, int, T::Dimension); + }; + + /** \class VectorInterpolateImageFunction + * \brief Base class for all vector image interpolaters. + * + * VectorInterpolateImageFunction is the base for all ImageFunctions that + * interpolates image with vector pixel types. This function outputs + * a return value of type Vector<double,Dimension>. + * + * This class is templated input image type and the coordinate + * representation type. + * + * \warning This hierarchy of functions work only for images + * with Vector-based pixel types. For scalar images use + * InterpolateImageFunction. + * + * \sa InterpolateImageFunction + * \ingroup ImageFunctions ImageInterpolators + */ + template<class TInputImage, class TCoordRep = double> + class VectorInterpolateImageFunction : public itk::ImageFunction<TInputImage, typename /*ITK_TYPENAME*/ itk::NumericTraits< + typename TInputImage::PixelType>::RealType, TCoordRep> + { + public: + + /** Dimension underlying input image. */ + itkStaticConstMacro(ImageDimension, unsigned int, + TInputImage::ImageDimension); + + /** Standard class typedefs. */ + typedef VectorInterpolateImageFunction Self; + typedef itk::ImageFunction<TInputImage, typename /*ITK_TYPENAME*/ itk::NumericTraits<typename TInputImage::PixelType>::RealType, TCoordRep> + Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Run-time type information (and related methods). */ + itkTypeMacro(VectorInterpolateImageFunction, ImageFunction) + + /** InputImageType typedef support. */ + typedef typename Superclass::InputImageType InputImageType; + typedef typename InputImageType::PixelType PixelType; + typedef typename PixelType::ValueType ValueType; + typedef typename itk::NumericTraits<ValueType>::RealType RealType; + + /** Point typedef support. */ + typedef typename Superclass::PointType PointType; + + /** Index typedef support. */ + typedef typename Superclass::IndexType IndexType; + + /** Index value type support */ + typedef typename Superclass::IndexValueType IndexValueType; + + /** ContinuousIndex typedef support. */ + typedef typename Superclass::ContinuousIndexType ContinuousIndexType; + + /** Output type is RealType of TInputImage::PixelType. */ + typedef typename Superclass::OutputType OutputType; + + /** CoordRep typedef support. */ + typedef TCoordRep CoordRepType; + + /** Returns the interpolated image intensity at a + * specified point position. No bounds checking is done. + * The point is assume to lie within the image buffer. + * ImageFunction::IsInsideBuffer() can be used to check bounds before + * calling the method. */ + virtual OutputType + Evaluate(const PointType& point) const + { + // --------------------------------------------------------------------------------------------- + ContinuousIndexType index; + // --------------------------------------------------------------------------------------------- + this->GetInputImage()->TransformPhysicalPointToContinuousIndex(point, index); + return (this->EvaluateAtContinuousIndex(index)); + } + + /** Interpolate the image at a continuous index position + * + * Returns the interpolated image intensity at a + * specified index position. No bounds checking is done. + * The point is assume to lie within the image buffer. + * + * Subclasses must override this method. + * + * ImageFunction::IsInsideBuffer() can be used to check bounds before + * calling the method. */ + virtual OutputType + EvaluateAtContinuousIndex(const ContinuousIndexType & index) const = 0; + + /** Interpolate the image at an index position. + * Simply returns the image value at the + * specified index position. No bounds checking is done. + * The point is assume to lie within the image buffer. + * + * ImageFunction::IsInsideBuffer() can be used to check bounds before + * calling the method. */ + virtual OutputType + EvaluateAtIndex(const IndexType & index) const + { + // --------------------------------------------------------------------------------------------- + OutputType output; + // --------------------------------------------------------------------------------------------- + // Get the input pixel + const PixelType & input = this->GetInputImage()->GetPixel(index); + // --------------------------------------------------------------------------------------------- + // Get the size + const unsigned int size = input.GetSize(); + output.SetSize(size); + // --------------------------------------------------------------------------------------------- + for (unsigned int k = 0; k < size; k++) + { + output[k] = static_cast<double> (input[k]); + } + return (output); + } + + virtual void + SetInputImage(const InputImageType * ptr) + { + // --------------------------------------------------------------------------------------------- + // set the input image + this->m_Image = ptr; + + // --------------------------------------------------------------------------------------------- + // If the input pointer is valid + if (ptr) + { + typename InputImageType::SizeType size = ptr->GetBufferedRegion().GetSize(); + // --------------------------------------------------------------------------------------------- + // set the start index + this->m_StartIndex = ptr->GetBufferedRegion().GetIndex(); + + for (unsigned int j = 0; j < ImageDimension; j++) + { + // --------------------------------------------------------------------------------------------- + // set the end index + this->m_EndIndex[j] = this->m_StartIndex[j] + static_cast<IndexValueType> (size[j]) - 1; + this->m_StartContinuousIndex[j] = static_cast<CoordRepType>( this->m_StartIndex[j] - 0.5 ); + this->m_EndContinuousIndex[j] = static_cast<CoordRepType>( this->m_EndIndex[j] + 0.5 ); + } + } + } + + protected: + VectorInterpolateImageFunction() + { + } + virtual + ~VectorInterpolateImageFunction() + { + } + void + PrintSelf(std::ostream& os, itk::Indent indent) const + { + Superclass::PrintSelf(os, indent); + } + + private: + VectorInterpolateImageFunction(const Self&); //purposely not implemented + void + operator=(const Self&); //purposely not implemented + + }; + +} // end namespace vns + +#endif diff --git a/Code/LutReader/include/vnsVectorLinearInterpolateImageFunction.hpp b/Code/LutReader/include/vnsVectorLinearInterpolateImageFunction.hpp new file mode 100644 index 0000000..7e67965 --- /dev/null +++ b/Code/LutReader/include/vnsVectorLinearInterpolateImageFunction.hpp @@ -0,0 +1,153 @@ +/* +* Copyright (C) 2020 Centre National d'Etudes Spatiales (CNES) +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +*/ +/************************************************************************************************************ + * * + * ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo * + * o * + * o * + * o * + * o * + * o ooooooo ooooooo o o oo * + * o o o o o o o o o o * + * o o o o o o o o o o * + * o o o o o o o o o o * + * o o o oooo o o o o o o * + * o o o o o o o o o * + * o o o o o o o o o o * + * oo oooooooo o o o oooooo o oooo * + * o * + * o * + * o o * + * o o oooo o o oooo * + * o o o o o o * + * o o ooo o o ooo * + * o o o o o * + * ooooo oooo o ooooo oooo * + * o * + * * + ************************************************************************************************************ + * * + * Author: CS Systemes d'Information (France) * + * * + ************************************************************************************************************ + * HISTORIQUE * + * * + * VERSION : 5-1-0 : FA : LAIG-FA-MAC-145739-CS : 27 juin 2016 : Audit code - Supp de la macro ITK_EXPORT * + * VERSION : 1-0-0 : <TypeFT> : <NumFT> : 10 avril 2010 : Creation + * * + * FIN-HISTORIQUE * + * * + * $Id$ + * * + ************************************************************************************************************/ +#ifndef __vnsVectorLinearInterpolateImageFunction_h +#define __vnsVectorLinearInterpolateImageFunction_h + +#include "vnsVectorInterpolateImageFunction.hpp" + +namespace ts +{ + + /** + * \class VectorLinearInterpolateImageFunction + * \brief Linearly interpolate a vector image at specified positions. + * + * VectorLinearInterpolateImageFunction linearly interpolates a vector + * image intensity non-integer pixel position. This class is templated + * over the input image type and the coordinate representation type. + * + * This function works for N-dimensional images. + * + * \warning This function work only for Vector images. For + * scalar images use LinearInterpolateImageFunction. + * + * \ingroup ImageFunctions ImageInterpolators + * + */ + template<class TInputImage, class TCoordRep = double> + class VectorLinearInterpolateImageFunction : public VectorInterpolateImageFunction< + TInputImage, TCoordRep> + { + public: + /** Standard class typedefs. */ + typedef VectorLinearInterpolateImageFunction Self; + typedef VectorInterpolateImageFunction<TInputImage, TCoordRep> Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Method for creation through the object factory. */ + itkNewMacro(Self) + + /** Run-time type information (and related methods). */ + itkTypeMacro(VectorLinearInterpolateImageFunction, + VectorInterpolateImageFunction) + + /** InputImageType typedef support. */ + typedef typename Superclass::InputImageType InputImageType; + typedef typename Superclass::PixelType PixelType; + typedef typename Superclass::ValueType ValueType; + typedef typename Superclass::RealType RealType; + + /** Dimension underlying input image. */ + itkStaticConstMacro(ImageDimension, unsigned int,Superclass::ImageDimension); + + /** Index typedef support. */ + typedef typename Superclass::IndexType IndexType; + + /** ContinuousIndex typedef support. */ + typedef typename Superclass::ContinuousIndexType ContinuousIndexType; + + /** Output type is Vector<double,Dimension> */ + typedef typename Superclass::OutputType OutputType; + + /** Evaluate the function at a ContinuousIndex position + * + * Returns the linearly interpolated image intensity at a + * specified point position. No bounds checking is done. + * The point is assume to lie within the image buffer. + * + * ImageFunction::IsInsideBuffer() can be used to check bounds before + * calling the method. */ + virtual OutputType + EvaluateAtContinuousIndex(const ContinuousIndexType & index) const; + + protected: + VectorLinearInterpolateImageFunction(); + virtual + ~VectorLinearInterpolateImageFunction() + { + } + void + PrintSelf(std::ostream& os, itk::Indent indent) const; + + private: + VectorLinearInterpolateImageFunction(const Self&); //purposely not implemented + void + operator=(const Self&); //purposely not implemented + + /** Number of neighbors used in the interpolation */ + static const unsigned long m_Neighbors; + + }; + +} // end namespace vns + +#ifndef VNS_MANUAL_INSTANTIATION +#include "vnsVectorLinearInterpolateImageFunction.txx" +#endif + +#endif diff --git a/Code/LutReader/include/vnsVectorLinearInterpolateImageFunction.txx b/Code/LutReader/include/vnsVectorLinearInterpolateImageFunction.txx new file mode 100644 index 0000000..84ca12b --- /dev/null +++ b/Code/LutReader/include/vnsVectorLinearInterpolateImageFunction.txx @@ -0,0 +1,201 @@ +/* +* Copyright (C) 2020 Centre National d'Etudes Spatiales (CNES) +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +*/ +/*********************************************************************************************************** + * * + * ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo * + * o * + * o * + * o * + * o * + * o ooooooo ooooooo o o oo * + * o o o o o o o o o o * + * o o o o o o o o o o * + * o o o o o o o o o o * + * o o o oooo o o o o o o * + * o o o o o o o o o * + * o o o o o o o o o o * + * oo oooooooo o o o oooooo o oooo * + * o * + * o * + * o o * + * o o oooo o o oooo * + * o o o o o o * + * o o ooo o o ooo * + * o o o o o * + * ooooo oooo o ooooo oooo * + * o * + * * + ************************************************************************************************************ + * * + * Author: CS Systemes d'Information (France) * + * * + ************************************************************************************************************ + * HISTORIQUE * + * * + * VERSION : 5-1-0 : FA : LAIG-FA-MAC-144674-CS : 26 mai 2016 : Modifications cosmetique et menage, etc... * + * VERSION : 1-0-0 : <TypeFT> : <NumFT> : 10 avril 2010 : Creation + * * + * FIN-HISTORIQUE * + * * + * $Id$ + * * + ************************************************************************************************************/ +#ifndef __vnsVectorLinearInterpolateImageFunction_txx +#define __vnsVectorLinearInterpolateImageFunction_txx + +#include "vnsVectorLinearInterpolateImageFunction.hpp" + +#include "vnl/vnl_math.h" + +namespace ts +{ + + // Define the number of neighbors + template<class TInputImage, class TCoordRep> + const unsigned long VectorLinearInterpolateImageFunction<TInputImage, TCoordRep>::m_Neighbors = 1 + << TInputImage::ImageDimension; + + // Constructor + template<class TInputImage, class TCoordRep> + VectorLinearInterpolateImageFunction<TInputImage, TCoordRep>::VectorLinearInterpolateImageFunction() + { + + } + + // PrintSelf + template<class TInputImage, class TCoordRep> + void + VectorLinearInterpolateImageFunction<TInputImage, TCoordRep>::PrintSelf(std::ostream& os, + itk::Indent indent) const + { + this->Superclass::PrintSelf(os, indent); + } + + // Evaluate at image index position + template<class TInputImage, class TCoordRep> + typename VectorLinearInterpolateImageFunction<TInputImage, TCoordRep>::OutputType + VectorLinearInterpolateImageFunction<TInputImage, TCoordRep>::EvaluateAtContinuousIndex( + const ContinuousIndexType& index) const + { + unsigned int dim; // index over dimension + + + // Compute base index = closet index below point + // Compute distance from point to base index + signed long baseIndex[ImageDimension]; + double distance[ImageDimension]; + long tIndex; + + for (dim = 0; dim < ImageDimension; dim++) + { + // The following "if" block is equivalent to the following line without + // having to call floor. + if (index[dim] >= 0.0) + { + baseIndex[dim] = static_cast<long> (index[dim]); + } + else + { + tIndex = static_cast<long> (index[dim]); + if (static_cast<double> (tIndex) != index[dim]) + { + tIndex--; + } + baseIndex[dim] = tIndex; + } + distance[dim] = index[dim] - static_cast<double> (baseIndex[dim]); + } + + // Interpolated value is the weighted sum of each of the surrounding + // neighbors. The weight for each neighbor is the fraction overlap + // of the neighbor pixel with respect to a pixel centered on point. + + const unsigned int size = this->GetInputImage()->GetNumberOfComponentsPerPixel(); + OutputType output; + output.SetSize(size); + output.Fill(0.0); + + typedef typename itk::NumericTraits<PixelType>::ScalarRealType ScalarRealType; + ScalarRealType totalOverlap = itk::NumericTraits<ScalarRealType>::Zero; + + IndexType neighIndex; + for (unsigned int counter = 0; counter < m_Neighbors; counter++) + { + double overlap(1.); // fraction overlap + unsigned int upper = counter; // each bit indicates upper/lower neighbour + // get neighbor index and overlap fraction + for (dim = 0; dim < ImageDimension; dim++) + { + + if (upper & 1) + { + neighIndex[dim] = baseIndex[dim] + 1; + // Take care of the case where the pixel is just + // in the outer upper boundary of the image grid. + // MACCS 4.2 ITK_USE_CENTERED_PIXEL_COORDINATES_CONSISTENTLY + // Take care of the case where the pixel is just + // in the outer upper boundary of the image grid. + if (neighIndex[dim] > this->m_EndIndex[dim]) + { + neighIndex[dim] = this->m_EndIndex[dim]; + } + overlap = overlap * distance[dim]; + } + else + { + neighIndex[dim] = baseIndex[dim]; + // Take care of the case where the pixel is just + // in the outer lower boundary of the image grid. + // MACCS 4.2 ITK_USE_CENTERED_PIXEL_COORDINATES_CONSISTENTLY + // Take care of the case where the pixel is just + // in the outer lower boundary of the image grid. + if (neighIndex[dim] < this->m_StartIndex[dim]) + { + neighIndex[dim] = this->m_StartIndex[dim]; + } + overlap = overlap * (1.0 - distance[dim]); + } + + upper >>= 1; + + } + + // Get neighbor value only if overlap is not zero + if (overlap) + { + const PixelType & input = this->GetInputImage()->GetPixel(neighIndex); + for (unsigned int k = 0; k < size; k++) + { + output[k] = output[k] + (overlap * static_cast<RealType> (input[k])); + } + totalOverlap = totalOverlap + overlap; + } + + if (totalOverlap == 1.0) + { + // Finished + break; + } + + } + + return (output); + } + +} // End namespace vns + +#endif diff --git a/Code/LutReader/include/vnsVectorLookUpTable.hpp b/Code/LutReader/include/vnsVectorLookUpTable.hpp new file mode 100644 index 0000000..3f1ebcd --- /dev/null +++ b/Code/LutReader/include/vnsVectorLookUpTable.hpp @@ -0,0 +1,204 @@ +/* +* Copyright (C) 2020 Centre National d'Etudes Spatiales (CNES) +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +*/ +/************************************************************************************************************ + * * + * ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo * + * o * + * o * + * o * + * o * + * o ooooooo ooooooo o o oo * + * o o o o o o o o o o * + * o o o o o o o o o o * + * o o o o o o o o o o * + * o o o oooo o o o o o o * + * o o o o o o o o o * + * o o o o o o o o o o * + * oo oooooooo o o o oooooo o oooo * + * o * + * o * + * o o * + * o o oooo o o oooo * + * o o o o o o * + * o o ooo o o ooo * + * o o o o o * + * ooooo oooo o ooooo oooo * + * o * + * * + ************************************************************************************************************ + * * + * Author: CS Systemes d'Information (France) * + * * + ************************************************************************************************************ + * HISTORIQUE * + * * + * VERSION : 3.0.0 : DM : LAIG-DM-MAJA-2369-CNES : 28 aout 2017 : Introduction données des CAMS * + * VERSION : 1.0.0 : FA : LAIG-FA-MAC-148399-CS : 14 octobre 2016 : Audit code - Correction qualite * + * VERSION : 5-1-0 : FA : LAIG-FA-MAC-145739-CS : 27 juin 2016 : Audit code - Supp de la macro ITK_EXPORT * + * VERSION : 5-0-0 : FA : LAIG-FA-MAC-143764-CS : 12 avril 2016 : Mise en forme du code (indentation, etc.) * + * VERSION : 1-0-0-3 : DM : 357 : 20 juil. 2011 : Correction AOT estimation. * + * Ajout d'un type dans la classe ParameterValue. * + * VERSION : 1-0-0 : <TypeFT> : <NumFT> : 19 mars 2010 : Creation + * * + * FIN-HISTORIQUE * + * * + * $Id$ + * * + ************************************************************************************************************/ + +#ifndef VNSVECTORLOOKUPTABLE_H_ +#define VNSVECTORLOOKUPTABLE_H_ + +#include "otbVectorImage.h" +#include "vnsVectorLinearInterpolateImageFunction.hpp" +#include "itkPoint.h" +#include "itkImageRegionIterator.h" +#include "itkSimpleFastMutexLock.h" + +namespace ts +{ + /** \class VectorLookUpTable + * \brief This class implements the multi-bands Look-Up Tables operations. + * + * This class is used to deal with multi-bands Look-Up tables. It allows interpolation either + * in floating index values, or in real (physical) values. + * + * \sa LookUpTableExtractor + * + * \ingroup L2 + * \ingroup L3 + * \ingroup Checktool + * + */ + template<class TValue, unsigned int VLUTDimension = 2> + class VectorLookUpTable : public otb::VectorImage<TValue, VLUTDimension> + { + + public: + + /** Types definition for ITK macros */ + typedef VectorLookUpTable Self; + typedef otb::VectorImage<TValue, VLUTDimension> Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + itkNewMacro(Self); + + /** Run-time type information (and related methods). */ + itkTypeMacro( VectorImage, otb::VectorImage ); + + /** Types definition for values */ + typedef typename Superclass::ValueType ValueType; + + itkStaticConstMacro(LUTDimension, unsigned int, VLUTDimension); + + typedef typename Superclass::IndexType IndexType; + typedef typename Superclass::PointType PointType; + typedef typename Superclass::SizeType SizeType; + typedef typename Superclass::PixelType PixelType; + typedef typename Superclass::InternalPixelType InternalPixelType; + typedef typename Superclass::IOPixelType IOPixelType; + + typedef VectorInterpolateImageFunction<Superclass, TValue > VectorInterpolatorType; + typedef typename VectorInterpolatorType::OutputType OutputType; + typedef VectorLinearInterpolateImageFunction + <Superclass, TValue > DefaultInterpolatorType; + + typedef itk::ImageRegionIterator<Superclass> IteratorType; + + typedef class ParameterValues + { + public: + typedef std::vector<TValue> ParamValuesType; + std::string ParameterName; + ParamValuesType ParameterValues; + } ParameterValuesType; + + typedef std::vector<ParameterValuesType> ParametersValuesType; + + /** Getter and Setter for Parameters values */ + ParametersValuesType GetParametersValues () const + { + return m_ParametersValues; + } + + ParameterValuesType GetParameterValues (unsigned int ind) const + { + return m_ParametersValues.at(ind); + } + + void AddParameterValues(const ParameterValuesType &NewParamValues); + + /** Get exact value */ + PixelType GetValue(const IndexType &lutIndex) const; + InternalPixelType GetValue(const IndexType &lutIndex, unsigned int pBandNum) const; + + /** Set value */ + void SetValue(const IndexType &lutIndex, PixelType pixel); + void SetValue(const IndexType &lutIndex, unsigned int pBandNum, InternalPixelType pVal); + + /** Interpolate from physical point values */ + PixelType InterpolateValue(const PointType &PhysicalPoint) const; + + /** Interpolate from physical point values */ + PixelType InterpolateIndex(const PointType &IndexPoint) const; + + /** Find real index from Value */ + TValue FindIndexInParameterValues(unsigned int ParameterIndex, TValue ParameterValue) const; + + /** Invert LUT : Find parameter value from LUT value */ + bool InvertLUT(const PointType & pFixedLutIndex,unsigned int pNumBand, unsigned int pTargetedDim,TValue pVal, double & pResult) const; + + /** Copy the parameters of the input vectorLUT */ + void copyParametersValue(const VectorLookUpTable<TValue, VLUTDimension>::Pointer & p_other); + + protected: + /** Constructor */ + VectorLookUpTable(); + + /** Destructor */ + virtual ~VectorLookUpTable(); + + /** Setter for Interpolator instance (Interpolator is itk::VectorLinearInterpolateImageFunction by default) */ + itkSetObjectMacro(Interpolator, VectorInterpolatorType) + + /** Convert physical point into image point (index) */ + PointType ConvertPhysicalPointIntoImagePoint(const PointType &realPoint) const; + + private: + /** Allocate image when all variables values are set */ + void AllocateLUT(); + + /** Interpolator on image */ + typename VectorInterpolatorType::Pointer m_Interpolator; + + /** Parameters names and values */ + ParametersValuesType m_ParametersValues; + + }; + + typedef VectorLookUpTable<double, 6> VNSLUT6DType; + typedef VectorLookUpTable<double, 3> VNSLUT3DType; + typedef VectorLookUpTable<double, 2> VNSLUT2DType; + +} // End namespace vns + +#ifndef VNS_MANUAL_INSTANTIATION +#include "vnsVectorLookUpTable.txx" +#endif + +#endif /* VNSVECTORLOOKUPTABLE_H_ */ diff --git a/Code/LutReader/include/vnsVectorLookUpTable.txx b/Code/LutReader/include/vnsVectorLookUpTable.txx new file mode 100644 index 0000000..846c700 --- /dev/null +++ b/Code/LutReader/include/vnsVectorLookUpTable.txx @@ -0,0 +1,462 @@ +/* +* Copyright (C) 2020 Centre National d'Etudes Spatiales (CNES) +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +*/ +/************************************************************************************************************ + * * + * ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo * + * o * + * o * + * o * + * o * + * o ooooooo ooooooo o o oo * + * o o o o o o o o o o * + * o o o o o o o o o o * + * o o o o o o o o o o * + * o o o oooo o o o o o o * + * o o o o o o o o o * + * o o o o o o o o o o * + * oo oooooooo o o o oooooo o oooo * + * o * + * o * + * o o * + * o o oooo o o oooo * + * o o o o o o * + * o o ooo o o ooo * + * o o o o o * + * ooooo oooo o ooooo oooo * + * o * + * * + ************************************************************************************************************ + * * + * Author: CS Systemes d'Information (France) * + * * + ************************************************************************************************************ + * HISTORIQUE * + * * + * VERSION : 3.0.0 : DM : LAIG-DM-MAJA-2369-CNES : 28 aout 2017 : Introduction données des CAMS * + * VERSION : 1.0.0 : FA : LAIG-FA-MAC-1988-CNES : 20 octobre 2016 : Correction qualite (code mort) * + * VERSION : 5-1-0 : FA : LAIG-FA-MAC-144674-CS : 26 mai 2016 : Modifications cosmetique et menage, etc... * + * VERSION : 4-0-0 : FA : LAIG-FA-MAC-120653-CS : 3 avril 2014 : Correction de règles de qualité * + * VERSION : 1-0-0 : <TypeFT> : <NumFT> : 19 mars 2010 : Creation + * * + * FIN-HISTORIQUE * + * * + * $Id$ + * * + ************************************************************************************************************/ +#ifndef VNSVECTORLOOKUPTABLE_TXX_ +#define VNSVECTORLOOKUPTABLE_TXX_ + +#include "vnsVectorLookUpTable.hpp" + +namespace ts +{ + + template<class TValue, unsigned int VLUTDimension> + VectorLookUpTable<TValue, VLUTDimension>::VectorLookUpTable() + { + // Interpolator creation + SetInterpolator(DefaultInterpolatorType::New()); + this->SetNumberOfComponentsPerPixel(1); + } + + template<class TValue, unsigned int VLUTDimension> + VectorLookUpTable<TValue, VLUTDimension>::~VectorLookUpTable() + { + + } + + // Add parameter values + template<class TValue, unsigned int VLUTDimension> + void + VectorLookUpTable<TValue, VLUTDimension>::AddParameterValues(const ParameterValuesType &NewParamValues) + { + unsigned int lSize = m_ParametersValues.size(); + + // If LUT already has the required number of params + if (lSize == VLUTDimension) + { + // Error and Exit + throw std::runtime_error("Parameters values are all already defined"); + } + + // Store new parameter's name and values + m_ParametersValues.push_back(NewParamValues); + + lSize = m_ParametersValues.size(); + // If LUT now has the required number of params + if (lSize == VLUTDimension) + { + // Allocate image + this->AllocateLUT(); + } + + } + + // Get exact value + template<class TValue, unsigned int VLUTDimension> + typename VectorLookUpTable<TValue, VLUTDimension>::PixelType + VectorLookUpTable<TValue, VLUTDimension>::GetValue(const IndexType &lutIndex) const + { + // Forward to Image + return this->GetPixel(lutIndex); + } + + // Get exact value for only one band + template<class TValue, unsigned int VLUTDimension> + typename VectorLookUpTable<TValue, VLUTDimension>::InternalPixelType + VectorLookUpTable<TValue, VLUTDimension>::GetValue(const IndexType &lutIndex, unsigned int pBandNum) const + { + const PixelType lPix = this->GetPixel(lutIndex); + return lPix[pBandNum]; + } + + // Set value + template<class TValue, unsigned int VLUTDimension> + void + VectorLookUpTable<TValue, VLUTDimension>::SetValue(const IndexType &lutIndex, PixelType pixel) + { + // Forward to VectorImage + this->SetPixel(lutIndex, pixel); + } + + // Set value for only one band + template<class TValue, unsigned int VLUTDimension> + void + VectorLookUpTable<TValue, VLUTDimension>::SetValue(const IndexType &lutIndex, unsigned int pBandNum, InternalPixelType pVal) + { + PixelType lPix = this->GetPixel(lutIndex); + lPix[pBandNum] = pVal; + this->SetPixel(lutIndex, lPix); + } + + // Interpolate from physical point values + template<class TValue, unsigned int VLUTDimension> + typename VectorLookUpTable<TValue, VLUTDimension>::PixelType + VectorLookUpTable<TValue, VLUTDimension>::InterpolateValue(const PointType &PhysicalPoint) const + { + return InterpolateIndex(ConvertPhysicalPointIntoImagePoint(PhysicalPoint)); + } + + // Interpolate from physical point values + template<class TValue, unsigned int VLUTDimension> + typename VectorLookUpTable<TValue, VLUTDimension>::PixelType + VectorLookUpTable<TValue, VLUTDimension>::InterpolateIndex(const PointType &IndexPoint) const + { + // 4.2 TODO Check test LUT tempo + if (m_Interpolator->IsInsideBuffer(IndexPoint) == false) + { + std::cout<<"ATTENTION: the following index point is outside of LUT: " << IndexPoint<<std::endl; + } + try + { + // Store interpolate value + const OutputType interpVal = m_Interpolator->Evaluate(IndexPoint); + // TODO optimization: check if template OutputType::PixelType == InternalPixelType, so return interpVal; else do actual code + + // Cast the interpolate value that is in RealType + // into the LUT type + const unsigned int l_Size(interpVal.Size()); + unsigned int l(0); + PixelType outVal; + outVal.SetSize(l_Size); + outVal.Fill(0); + for (l = 0; l < l_Size; l++) + { + outVal[l] = static_cast<InternalPixelType>(interpVal[l]); + } + + return outVal; + } + catch (...) + { + std::stringstream ofs; + ofs<<"ERROR : point outside of LUT : " << IndexPoint << "\nRegion index: Start: " << + m_Interpolator->GetStartIndex() << "; End: " << m_Interpolator->GetEndIndex() << + "\nRegion Continuous index: Start: " << m_Interpolator->GetStartContinuousIndex() << + "; End: " << m_Interpolator->GetEndContinuousIndex() << "\n m_Origin: "<< + this->m_Origin << "\n m_Spacing: "<< this->m_Spacing << "\n m_LargestPossibleRegion: "<< + this->GetLargestPossibleRegion(); + throw std::runtime_error(ofs.str()); + } + + } + + // Convert physical point into image point (index) + template<class TValue, unsigned int VLUTDimension> + typename VectorLookUpTable<TValue, VLUTDimension>::PointType + VectorLookUpTable<TValue, VLUTDimension>::ConvertPhysicalPointIntoImagePoint( + const VectorLookUpTable<TValue, VLUTDimension>::PointType &realPoint) const + { + PointType imagePoint; + for (unsigned int dim = 0; dim < VLUTDimension; dim++) + { + imagePoint[dim] = FindIndexInParameterValues(dim, realPoint[dim]); + } + return imagePoint; + } + + template<class TValue, unsigned int VLUTDimension> + TValue + VectorLookUpTable<TValue, VLUTDimension>::FindIndexInParameterValues(unsigned int ParameterIndex, TValue ParameterValue) const + { + + // Get the parameter values for the considered parameter index + const std::vector<TValue> valuesfordim = m_ParametersValues[ParameterIndex].ParameterValues; + + const unsigned int lSize_moins_1 = valuesfordim.size() - 1; + unsigned int index = 0; + + bool lValueIsInside = true; + while (lValueIsInside && (index < lSize_moins_1)) + { + if (valuesfordim[index] >= ParameterValue) + { + lValueIsInside = false; + } + else + { + index = index + 1; + } + } + + // If value is outside of bounds, push a warning + if (index == 0) + { + return 0; + } + + if ((index == lSize_moins_1) && (ParameterValue > valuesfordim[index])) + { + return index; + } + + // Check that the indices that surround the value are different + const TValue v2 = valuesfordim[index]; + index = index - 1; + const TValue v1 = valuesfordim[index]; + + const TValue diff = static_cast<TValue>(v2 - v1); + + if ( diff == static_cast<TValue>(0) ) + { + std::cout<<"Warning : Two consecutive indexes of the LUT are identical => return index 0 !!"<<std::endl; + return 0; + } + + const TValue k = (ParameterValue - v1) / diff; + + return (index + k); + + } + + // Allocate Image + template<class TValue, unsigned int VLUTDimension> + void + VectorLookUpTable<TValue, VLUTDimension>::AllocateLUT() + { + std::cout<<"Allocating VectorLookUpTable image dimension = " << (int)(VLUTDimension)<<std::endl; + + // Set Image Region + typename Superclass::IndexType start; + typename Superclass::SizeType size; + + if (m_ParametersValues.size() != VLUTDimension) + { + throw std::runtime_error( + "AllocateLUT: Internal error: The size m_ParametersValues is different than the dimension of the LUT !"); + } + + for (unsigned int i = 0; i < VLUTDimension; i++) + { + start[i] = 0; + size[i] = m_ParametersValues.at(i).ParameterValues.size(); + } + typename Superclass::RegionType region; + + region.SetSize(size); + region.SetIndex(start); + + this->SetRegions(region); + + // Set image spacing to 1.0 + typename Superclass::SpacingType spacing; + spacing.Fill(1.0); + this->SetSpacing(spacing); + + // Set image origin + typename Superclass::PointType origin; + origin.Fill(0.); + this->SetOrigin(origin); + + // TODO: Mem: free LUT allocated! + // Allocate Image + this->Allocate(); + + // Update interpolator + m_Interpolator->SetInputImage(this); + + } + + // Invert LUT : return false if the result is not found + template<class TValue, unsigned int VLUTDimension> + bool + VectorLookUpTable<TValue, VLUTDimension>::InvertLUT(const PointType & pFixedLutIndex, unsigned int pNumBand, + unsigned int pTargetedDim, TValue pVal, double & pResult) const + { + + // Initialization + ParameterValues lParamVal; + PointType lVariableLutIndex; + PixelType lPix; + InternalPixelType lVal1(0); + InternalPixelType lVal2(0); + InternalPixelType lPoids(1); + unsigned int lIndex1(0); + unsigned int lIndex2(1); + unsigned int i(0); + bool lFound(false); + pResult = 0.; + + // Copy FixedLutIndex into VariableLutIndex, two dimensions are fixed, + // the third is variable + for (i = 0; i < VLUTDimension; i++) + { + lVariableLutIndex[i] = pFixedLutIndex[i]; + } + + // Get the parameter values and its size + lParamVal = this->GetParameterValues(pTargetedDim); + std::vector<TValue> lVectorOfVal = lParamVal.ParameterValues; + const unsigned int lSize = lVectorOfVal.size(); + + lVariableLutIndex[pTargetedDim] = lIndex1; + lPix = this->InterpolateIndex(lVariableLutIndex); + lVal2 = lPix[pNumBand]; + + // lVal2 = dark surface reflectance mimimum associated to the AOT index min + // Test if the dark surface reflectance associated to the value of AOT index min is lower than the + // dark surface reflectance threshold + if (lVal2 < pVal) + { + std::cout<< + "Warning : The dark surface reflectance associated to the value of AOT index min is" << + " lower than the dark surface reflectance threshold. AOT dark is set to the AOT index min : " <<pResult<<"."<<std::endl; + + this->FindIndexInParameterValues(pTargetedDim, pResult); + return true; + } + + // ------------------------------------------------------------------------------------------ + // Search the two indices in the parameters of the LUT that surround the fixed output value + // of the LUT (surface reflectance) + // ------------------------------------------------------------------------------------------ + + // Loop on the Targeted (variable) Dimension Value + while ((lFound == false) && (lIndex2 < lSize)) + { + lVal1 = lVal2; + + // Get the interpolated value + lVariableLutIndex[pTargetedDim] = lIndex2; + lPix = this->InterpolateIndex(lVariableLutIndex); + lVal2 = lPix[pNumBand]; + + // Check if the value is include in the interval + if (((lVal1 <= pVal) && (pVal <= lVal2)) || ((lVal1 >= pVal) && (pVal >= lVal2))) + { + lFound = true; + } + else + { + lIndex1++; + lIndex2++; + } + } + + // If value is outside of bounds, push a warning + if (lFound == false) + { + std::cout<<"Warning : Interpolation is an extrapolation, value out of bound : no result found"<<std::endl; + } + else + { + // Compute the weight for the interpolation + if ((lVal1 < lVal2) && (lVal1 != lVal2)) + { + lPoids = 1 - (pVal - lVal1) / (lVal2 - lVal1); + } + else + { + lPoids = 1 - (pVal - lVal2) / (lVal1 - lVal2); + } + + // Linear interpolation between the two found indices + pResult = lVectorOfVal.at(lIndex1) + lPoids * (lVectorOfVal.at(lIndex2) - lVectorOfVal.at(lIndex1)); + + // Shows the results in debug mode + std::cout<<"Indexes: [" << lIndex1 << ";" << lIndex2 << "]"<<std::endl; + std::cout<<"Val1 : " << lVal1<<std::endl; + std::cout<<"pVal : " << pVal<<std::endl; + std::cout<<"Val2 : " << lVal2<<std::endl; + std::cout<<"Poids : " << lPoids<<std::endl; + std::cout<<"Result : " << pResult<<std::endl; + + } + return lFound; + + } + template<class TValue, unsigned int VLUTDimension> + void VectorLookUpTable<TValue, VLUTDimension>::copyParametersValue(const VectorLookUpTable<TValue, VLUTDimension>::Pointer& p_other) + { + // Set kept parameters values */ + ParametersValuesType ParametersValues = p_other->GetParametersValues(); + if (ParametersValues.size() == 0) + { + throw std::runtime_error("Input Lut has no parameters value to copy"); + } + // ---------------------------------------------------------------- + // For each kept dimension + // ---------------------------------------------------------------- + SizeType size; + IndexType orig; + unsigned int count = 0; + for (unsigned int idim = 0; idim < LUTDimension; idim++) + { + // Copy dimension size and origin + size[count] = p_other->GetLargestPossibleRegion().GetSize()[idim]; + orig[count] = p_other->GetLargestPossibleRegion().GetIndex()[idim]; + count++; + + // Load the name of the parameter + ParameterValuesType values = ParametersValues[idim]; + + ParameterValuesType convertedValues; + convertedValues.ParameterName = values.ParameterName; + + // Load the associated indices for each parameter (dimension) of the LUT + unsigned int NbValues = values.ParameterValues.size(); + for (unsigned int j = 0; j < NbValues; j++) + { + convertedValues.ParameterValues.push_back(values.ParameterValues[j]); + } + this->AddParameterValues(convertedValues); + } + } + +} // End namespace ts + +#endif diff --git a/Code/LutReader/include/vnsVectorLookUpTableExtractor.hpp b/Code/LutReader/include/vnsVectorLookUpTableExtractor.hpp new file mode 100644 index 0000000..1bbb870 --- /dev/null +++ b/Code/LutReader/include/vnsVectorLookUpTableExtractor.hpp @@ -0,0 +1,113 @@ +/* +* Copyright (C) 2020 Centre National d'Etudes Spatiales (CNES) +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +*/ +/************************************************************************************************************ + * * + * ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo * + * o * + * o * + * o * + * o * + * o ooooooo ooooooo o o oo * + * o o o o o o o o o o * + * o o o o o o o o o o * + * o o o o o o o o o o * + * o o o oooo o o o o o o * + * o o o o o o o o o * + * o o o o o o o o o o * + * oo oooooooo o o o oooooo o oooo * + * o * + * o * + * o o * + * o o oooo o o oooo * + * o o o o o o * + * o o ooo o o ooo * + * o o o o o * + * ooooo oooo o ooooo oooo * + * o * + * * + ************************************************************************************************************ + * * + * Author: CS Systemes d'Information (France) * + * * + ************************************************************************************************************ + * HISTORIQUE * + * * + * VERSION : 1-0-0 : <TypeFT> : <NumFT> : 24 mars 2010 : Creation + * * + * FIN-HISTORIQUE * + * * + * $Id$ + * * + ************************************************************************************************************/ +#ifndef __vnsVectorLookUpTableExtractor_h +#define __vnsVectorLookUpTableExtractor_h + +#include "itkObject.h" +#include "itkPoint.h" + +namespace ts +{ + /** \class VectorLookUpTableExtractor + * \brief This class implements the extraction of sub-LUTs (also called reduced LUTs). + * + * This class is used to extract sub-LUTs from a full VectorLUT, by semi-interpolating on + * the extract point values. This extract point is a "semi-point" for the full VectorLUT, i.e. + * the values are not filled for all dimensions. + * For extracting the sub-LUT, the LookUpTableExtractor uses the full VectorLUT interpolator + * (Linear by default). + * + * \sa VectorLookUpTable + * \sa VLookUpTableExtractor + * + * \ingroup L2 + * \ingroup L3 + * \ingroup Checktool + * + */ + template<class TFullLUT, class TReducedLUT> + class VectorLookUpTableExtractor + { + public: + /** Standard class typedefs. */ + typedef VectorLookUpTableExtractor Self; + + typedef itk::Point<typename TFullLUT::InternalPixelType, + TFullLUT::LUTDimension - TReducedLUT::LUTDimension> + ExtractPointType; + + typedef std::vector<ExtractPointType> VectorExtractPointType; + + typedef typename TFullLUT::PointType PointType; + + typedef typename std::vector<PointType> VectorPointType; + + static typename TReducedLUT::Pointer + ExtractLUT(typename TFullLUT::Pointer FullLUT,const VectorExtractPointType & ReducedPointList); + + protected: + + private: + + }; + +} // End namespace vns + +#ifndef VNS_MANUAL_INSTANTIATION +#include "vnsVectorLookUpTableExtractor.txx" +#endif + +#endif /* __vnsVectorLookUpTableExtractor_h */ diff --git a/Code/LutReader/include/vnsVectorLookUpTableExtractor.txx b/Code/LutReader/include/vnsVectorLookUpTableExtractor.txx new file mode 100644 index 0000000..e740961 --- /dev/null +++ b/Code/LutReader/include/vnsVectorLookUpTableExtractor.txx @@ -0,0 +1,179 @@ +/* +* Copyright (C) 2020 Centre National d'Etudes Spatiales (CNES) +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +*/ +/************************************************************************************************************ + * * + * ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo * + * o * + * o * + * o * + * o * + * o ooooooo ooooooo o o oo * + * o o o o o o o o o o * + * o o o o o o o o o o * + * o o o o o o o o o o * + * o o o oooo o o o o o o * + * o o o o o o o o o * + * o o o o o o o o o o * + * oo oooooooo o o o oooooo o oooo * + * o * + * o * + * o o * + * o o oooo o o oooo * + * o o o o o o * + * o o ooo o o ooo * + * o o o o o * + * ooooo oooo o ooooo oooo * + * o * + * * + ************************************************************************************************************ + * * + * Author: CS Systemes d'Information (France) * + * * + ************************************************************************************************************ + * HISTORIQUE * + * * + * VERSION : 4-0-0 : FA : LAIG-FA-MAC-120653-CS : 3 avril 2014 : Correction de règles de qualité * + * VERSION : 1-0-0 : <TypeFT> : <NumFT> : 24 mars 2010 : Creation + * * + * FIN-HISTORIQUE * + * * + * $Id$ + * * + ************************************************************************************************************/ +#ifndef __vnsVectorLookUpTableExtractor_txx +#define __vnsVectorLookUpTableExtractor_txx + +#include "vnsVectorLookUpTableExtractor.h" + +namespace ts +{ + + template<class TFullLUT, class TReducedLUT> + typename TReducedLUT::Pointer + VectorLookUpTableExtractor<TFullLUT, TReducedLUT>::ExtractLUT(typename TFullLUT::Pointer FullLUT, + const VectorExtractPointType & ReducedPointList) + { + // Number of dimension of the input LUT + unsigned int NbBand = FullLUT->GetNumberOfComponentsPerPixel(); + if (ReducedPointList.size() != NbBand) + { + vnsStaticExceptionDataMacro("Invalid reducePointList, its size ("<<ReducedPointList.size()<<") has to be the number of band of the FullLUT ("<<NbBand<<" !"); + } + + typename TReducedLUT::Pointer ret = TReducedLUT::New(); + + // Dimension of the init LUT + const unsigned int FullDimension = TFullLUT::LUTDimension; + // Dimension of the "miniLUT" in which several dimensions were lost by setting + // fixed values for those parameters + const unsigned int ReducedDimension = TReducedLUT::LUTDimension; + const unsigned int DimensionLost = FullDimension - ReducedDimension; + + // Set kept parameters values */ + typename TFullLUT::ParametersValuesType ParametersValues = FullLUT->GetParametersValues(); + + typename TReducedLUT::SizeType size; + typename TReducedLUT::IndexType orig; + unsigned int count = 0; + + // ---------------------------------------------------------------- + // For each kept dimension + // ---------------------------------------------------------------- + for (unsigned int idim = DimensionLost; idim < FullDimension; idim++) + { + // Copy dimension size and origin + size[count] = FullLUT->GetLargestPossibleRegion().GetSize()[idim]; + orig[count] = FullLUT->GetLargestPossibleRegion().GetIndex()[idim]; + count++; + + // Load the name of the parameter + typename TFullLUT::ParameterValuesType values = ParametersValues[idim]; + + typename TReducedLUT::ParameterValuesType convertedValues; + convertedValues.ParameterName = values.ParameterName; + + // Load the associated indices for each parameter (dimension) of the LUT + unsigned int NbValues = values.ParameterValues.size(); + for (unsigned int j = 0; j < NbValues; j++) + { + + convertedValues.ParameterValues.push_back(values.ParameterValues[j]); + } + + ret->AddParameterValues(convertedValues); + } + + // ---------------------------------------------------------------- + // Allocate output image + // ---------------------------------------------------------------- + typename TReducedLUT::RegionType region; + region.SetSize(size); + region.SetIndex(orig); + + ret->SetNumberOfComponentsPerPixel(NbBand); + ret->SetRegions(region); + ret->Allocate(); + + // Copy kept part of the buffer */ + VectorPointType interpPointList; + + // For each band + for (unsigned int l = 0; l < NbBand; l++) + { + PointType interpPoint; + // Convert physical values into float index, + // as we do it only once... We save time after ! (instead of interpolating each point on physical values) */ + for (unsigned int i = 0; i < ExtractPointType::PointDimension; i++) + { + interpPoint[i] = FullLUT->FindIndexInParameterValues(i, ReducedPointList.at(l)[i]); + } + interpPointList.push_back(interpPoint); + } + + // Run over all the sub-LUT + typename TReducedLUT::IteratorType iterator(ret, ret->GetLargestPossibleRegion()); + + iterator.GoToBegin(); + while (iterator.IsAtEnd() == false) + { + // Get coordinates + typename TReducedLUT::IndexType index = iterator.GetIndex(); + typename TReducedLUT::PixelType retPix; + retPix.SetSize(NbBand); + + // For each band + for (unsigned int l = 0; l < NbBand; l++) + { + // Complete interpolation point in Full LUT + for (unsigned int i = DimensionLost; i < FullDimension; i++) + { + interpPointList.at(l)[i] = index[i - DimensionLost]; + } + + // Interpolate in full LUT and set value in reduced one + retPix[l] = FullLUT->InterpolateIndex(interpPointList.at(l))[l]; + } + iterator.Set(retPix); + ++iterator; + } + + return ret; + } + +} // End namespace vns + +#endif // __vnsVectorLookUpTableExtractor_txx diff --git a/Code/LutReader/src/vnsSimpleLutXMLContainer.cxx b/Code/LutReader/src/vnsSimpleLutXMLContainer.cxx new file mode 100644 index 0000000..e9b337a --- /dev/null +++ b/Code/LutReader/src/vnsSimpleLutXMLContainer.cxx @@ -0,0 +1,92 @@ +/* +* Copyright (C) 2020 Centre National d'Etudes Spatiales (CNES) +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +*/ +/* + * SimpleSMACXMLFileHandler.cpp + * + * Created on: 26 oct. 2017 + * Author: besquis + */ + +#include "../include/vnsSimpleLutXMLContainer.hpp" + +namespace ts +{ +SimpleLutXMLContainer::SimpleLutXMLContainer() +{ + +} + +SimpleLutXMLContainer::~SimpleLutXMLContainer() { + +} + +SimpleLutXMLContainer& SimpleLutXMLContainer::operator=(const SimpleLutXMLContainer& other) +{ + if (this != &other) + { + m_ZenithalIndx = other.m_ZenithalIndx; + m_RelAziIndx = other.m_RelAziIndx; + m_SolZenithIndx = other.m_SolZenithIndx; + m_VieZenithAngleIndx = other.m_VieZenithAngleIndx; + m_ReflRatioIdx = other.m_ReflRatioIdx; + m_TOAIdx = other.m_TOAIdx; + m_AOTIndx = other.m_AOTIndx; + m_AtlIndx = other.m_AtlIndx; + m_ListOfFiles = other.m_ListOfFiles; + } + return *this; + +} + +void SimpleLutXMLContainer::SetAltitude_Indexes(const ListOfDoubles& list) +{ + m_AtlIndx = list; +} +void SimpleLutXMLContainer::SetAOT_Indexes(const ListOfDoubles& list) +{ + m_AOTIndx = list; +} +void SimpleLutXMLContainer::SetTOA_Reflectance_Indexes(const ListOfDoubles& list) +{ + m_TOAIdx = list; +} +void SimpleLutXMLContainer::SetReflectance_Ratio_Indexes(const ListOfDoubles& list) +{ + m_ReflRatioIdx = list; +} +void SimpleLutXMLContainer::SetView_Zenith_Angle_Indexes(const ListOfDoubles& list) +{ + m_VieZenithAngleIndx = list; +} +void SimpleLutXMLContainer::SetSolar_Zenith_Angle_Indexes(const ListOfDoubles& list) +{ + m_SolZenithIndx = list; +} +void SimpleLutXMLContainer::SetRelative_Azimuth_Angle_Indexes(const ListOfDoubles& list) +{ + m_RelAziIndx = list; +} +void SimpleLutXMLContainer::SetZenithal_Angle_Indexes(const ListOfDoubles& list) +{ + m_ZenithalIndx = list; +} +void SimpleLutXMLContainer::SetListOfPackaged_DBL_Files(const ListOfStrings& list) +{ + m_ListOfFiles = list; +} + +} diff --git a/Code/LutReader/src/vnsSimpleLutXMLFileHandler.cxx b/Code/LutReader/src/vnsSimpleLutXMLFileHandler.cxx new file mode 100644 index 0000000..a20a705 --- /dev/null +++ b/Code/LutReader/src/vnsSimpleLutXMLFileHandler.cxx @@ -0,0 +1,146 @@ +/* +* Copyright (C) 2020 Centre National d'Etudes Spatiales (CNES) +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +*/ +/* + * SimpleSMACXMLFileHandler.cpp + * + * Created on: 26 oct. 2017 + * Author: besquis + */ + +#include "vnsSimpleLutXMLFileHandler.hpp" + +#include <FileUtils.hpp> +#include <StringUtils.hpp> +#include "otb_tinyxml.h" +#include "itksys/SystemTools.hxx" + +namespace ts +{ +SimpleLutXMLFileHandler::SimpleLutXMLFileHandler() +{ + +} + +SimpleLutXMLFileHandler::~SimpleLutXMLFileHandler() { + +} + +void SimpleLutXMLFileHandler::LoadFile(const std::string& filename) { + + if(filename.empty()) + { + std::cerr <<"Input XML Filename is empty" << std::endl; + throw std::runtime_error("Input XML Filename is empty"); + } + + if (itksys::SystemTools::FileExists(filename.c_str()) == false) + { + std::cerr<<"Look up Table file "<< filename<<" doesn't exist."<<std::endl; + throw std::runtime_error("Look up Table file doesn't exist."); + } + + // Open the xml file + TiXmlDocument doc; + + //Use itksys::SystemTools::FOpen() and close it below because + //TiXmlDocument::TiXmlFileOpen( ) is not exposed from tinyXML library. Even + //though its available in the TiXmlDocument::SaveFile(). + FILE* fp = itksys::SystemTools::Fopen(filename.c_str(), "rb"); + + if (!doc.LoadFile(fp , TIXML_ENCODING_UTF8)) + { + fclose(fp); + throw std::runtime_error("Impossible to open "+filename); + } + + TiXmlHandle handle(&doc); + + TiXmlElement *n_DOC; + n_DOC = handle.FirstChild("LUT").Element(); + + if(!n_DOC) + { + return; + } + + TiXmlElement *n_IdxNode = n_DOC->FirstChildElement("Indexes"); + if(!n_IdxNode) + { + throw std::runtime_error("No Indexes in the lut xml file"); + } + + TiXmlElement *n_Node = n_IdxNode->FirstChildElement("Altitude_Indexes"); + if(n_Node) + { + m_Container.SetAltitude_Indexes( ReadDoubleList(n_Node->GetText())); + } + n_Node = n_IdxNode->FirstChildElement("AOT_Indexes"); + if(n_Node) + { + m_Container.SetAOT_Indexes(ReadDoubleList(n_Node->GetText())); + } + n_Node = n_IdxNode->FirstChildElement("TOA_Reflectance_Indexes"); + if(n_Node) + { + m_Container.SetTOA_Reflectance_Indexes( ReadDoubleList(n_Node->GetText())); + } + n_Node = n_IdxNode->FirstChildElement("Reflectance_Ratio_Indexes"); + if(n_Node) + { + m_Container.SetReflectance_Ratio_Indexes(ReadDoubleList(n_Node->GetText())); + } + n_Node = n_IdxNode->FirstChildElement("View_Zenith_Angle_Indexes"); + if(n_Node) + { + m_Container.SetView_Zenith_Angle_Indexes( ReadDoubleList(n_Node->GetText())); + } + n_Node = n_IdxNode->FirstChildElement("Solar_Zenith_Angle_Indexes"); + if(n_Node) + { + m_Container.SetSolar_Zenith_Angle_Indexes( ReadDoubleList(n_Node->GetText())); + } + n_Node = n_IdxNode->FirstChildElement("Relative_Azimuth_Angle_Indexes"); + if(n_Node) + { + m_Container.SetRelative_Azimuth_Angle_Indexes( ReadDoubleList(n_Node->GetText()) ); + } + n_Node = n_IdxNode->FirstChildElement("Zenithal_Angle_Indexes"); + if(n_Node) + { + m_Container.SetZenithal_Angle_Indexes( ReadDoubleList(n_Node->GetText()) ); + } + + n_Node = n_DOC->FirstChildElement("List_Of_Files"); + if(n_Node) + { + ListOfStrings l_ListOfFiles; + for( TiXmlElement* n_Parameter = n_Node->FirstChildElement("Relative_File_Path"); n_Parameter != ITK_NULLPTR; + n_Parameter = n_Parameter->NextSiblingElement() ) + { + l_ListOfFiles.push_back(n_Parameter->GetText()); + } + const std::string l_RootBasePath = itksys::SystemTools::GetFilenamePath(filename); + const unsigned int nbFilenames(l_ListOfFiles.size()); + RelativeToAbsoluteFilename(l_RootBasePath, l_ListOfFiles); + CheckingExistenceFilenames(l_ListOfFiles); + m_Container.SetListOfPackaged_DBL_Files(l_ListOfFiles); + } + fclose(fp); + +} + +} diff --git a/Code/LutReader/test/CMakeLists.txt b/Code/LutReader/test/CMakeLists.txt new file mode 100644 index 0000000..bbef37a --- /dev/null +++ b/Code/LutReader/test/CMakeLists.txt @@ -0,0 +1,12 @@ +add_executable(test_SimpleLUTXMLreader test_SimpleLutXMLReader.cpp) +target_link_libraries(test_SimpleLUTXMLreader + Common + LutReader + "${Boost_LIBRARIES}" + "${OTBCommon_LIBRARIES}" + "${OTBITK_LIBRARIES}" + "${OTB_LIBRARIES}" + ) + +target_include_directories(test_SimpleLUTXMLreader PUBLIC ../include) +add_test(test_SimpleLUTXMLreader test_SimpleLUTXMLreader) diff --git a/Code/LutReader/test/test_SimpleLutXMLReader.cpp b/Code/LutReader/test/test_SimpleLutXMLReader.cpp new file mode 100644 index 0000000..5425c62 --- /dev/null +++ b/Code/LutReader/test/test_SimpleLutXMLReader.cpp @@ -0,0 +1,152 @@ +/* + * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) + * All rights reserved + * + * This file is part of Weighted Average Synthesis Processor (WASP) + * + * Authors: + * - Benjamin ESQUIS <benjamin.esquis@csgroup.eu> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * See the LICENSE.md file for more details. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#define BOOST_TEST_MODULE MuscateReader +#include <boost/test/unit_test.hpp> +#include "GlobalDefs.h" +#include "vnsSimpleLutXMLFileHandler.hpp" +#include "vnsVectorLookUpTable.hpp" +#include "vnsLookUpTableFileReader.hpp" +#include "stdlib.h" +#include <string> + + +#define TEST_NAME "test_SimpleLutXMLReader" +#define TEST_SRC ts::getEnvVar("WASP_TEST") +#define EXAMPLE_LUTXML1 "giplut_dircor.xml" + +const std::vector<double> SolarZenithAngles = {15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80}; +const std::vector<double> ViewZenithAngles = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; +const std::vector<double> RelativeAzimuthIndex = {0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 210, 220, 230, 240, 250, 260, 270, 280, 290, 300, 310, 320, 330, 340, 350}; +const std::vector<double> Value_Out = {0.0993027, 0.073317952454, 0.065475486, 0.0330186896, 0.05777016, 0.233487516, 0.3611008524, 0.380975335, 0.430103570222, 0.14473305642, 0.0648960843}; + +BOOST_AUTO_TEST_CASE(SimpleLUTXMLReaderExample1) +{ + if(TEST_SRC == ""){ + BOOST_FAIL("Did not set env-var WASP_TEST!"); + } + std::cout << std::string(TEST_SRC + "/" + TEST_NAME + "/" + EXAMPLE_LUTXML1) << std::endl; + ts::SimpleLutXMLFileHandler::Pointer l_LUTXMLHandler = ts::SimpleLutXMLFileHandler::New(); + // Load the XML file and check with the schema + l_LUTXMLHandler->LoadFile(std::string(TEST_SRC + "/" + TEST_NAME + "/" + EXAMPLE_LUTXML1)); + const ts::SimpleLutXMLContainer& l_lutxml = l_LUTXMLHandler->GetLutContainer(); + + BOOST_REQUIRE(l_LUTXMLHandler); + + BOOST_CHECK_EQUAL(l_lutxml.GetSolar_Zenith_Angle_Indexes().size(), SolarZenithAngles.size()); + for(size_t i = 0 ; i < l_lutxml.GetSolar_Zenith_Angle_Indexes().size();i++){ + BOOST_CHECK_EQUAL(l_lutxml.GetSolar_Zenith_Angle_Indexes()[i], SolarZenithAngles[i]); + } + BOOST_CHECK_EQUAL(l_lutxml.GetView_Zenith_Angle_Indexes().size(), ViewZenithAngles.size()); + for(size_t i = 0 ; i < l_lutxml.GetView_Zenith_Angle_Indexes().size();i++){ + BOOST_CHECK_EQUAL(l_lutxml.GetView_Zenith_Angle_Indexes()[i], ViewZenithAngles[i]); + } + BOOST_CHECK_EQUAL(l_lutxml.GetRelative_Azimuth_Angle_Indexes().size(), RelativeAzimuthIndex.size()); + for(size_t i = 0 ; i < l_lutxml.GetRelative_Azimuth_Angle_Indexes().size();i++){ + BOOST_CHECK_EQUAL(l_lutxml.GetRelative_Azimuth_Angle_Indexes()[i], RelativeAzimuthIndex[i]); + } + BOOST_CHECK_EQUAL(l_lutxml.GetListOfPackaged_DBL_Files().size(), 11); +} + +BOOST_AUTO_TEST_CASE(SimpleLUTXMLReaderExample2) +{ + if(TEST_SRC == ""){ + BOOST_FAIL("Did not set env-var WASP_TEST!"); + } + std::cout << std::string(TEST_SRC + "/" + TEST_NAME + "/" + EXAMPLE_LUTXML1) << std::endl; + ts::SimpleLutXMLFileHandler::Pointer l_LUTXMLHandler = ts::SimpleLutXMLFileHandler::New(); + // Load the XML file and check with the schema + l_LUTXMLHandler->LoadFile(std::string(TEST_SRC + "/" + TEST_NAME + "/" + EXAMPLE_LUTXML1)); + const ts::SimpleLutXMLContainer& l_lutxml = l_LUTXMLHandler->GetLutContainer(); + + BOOST_REQUIRE(l_LUTXMLHandler); + + //Reduced output lut typedef + typedef ts::VNSLUT3DType LutType; + typedef LutType::ConstPointer ReducedLutConstPointer; + typedef LutType::Pointer ReducedLutPointer; + //LookupTable Reader + typedef ts::LookUpTableFileReader<LutType> LookUpTableReaderType; + typedef LookUpTableReaderType::Pointer LookUpTableReaderPointer; + typedef LutType::ParameterValuesType ParameterValuesType; + // Init filters + LookUpTableReaderPointer l_lookUpTableReader = LookUpTableReaderType::New(); + // Get the number of file that matches with the number of band + const std::vector<std::string>& l_GIP_L2TOCR_ListOfFilenames = l_lutxml.GetListOfPackaged_DBL_Files(); + const unsigned int fileNumber = l_GIP_L2TOCR_ListOfFilenames.size(); + // For each spectral band, add the filename of the LUT to the reader + for (unsigned int file = 0; file < fileNumber; file++) + { + // Set the filename of each band + l_lookUpTableReader->AddBandFilename(l_GIP_L2TOCR_ListOfFilenames[file]); + std::cout<<"BandFilename : " <<l_GIP_L2TOCR_ListOfFilenames[file]<<std::endl; + } + // Read informations from the GIPP file + const std::vector<double>& l_GIP_L2TOCR_SolarZenithalAngleIndexes = l_lutxml.GetSolar_Zenith_Angle_Indexes(); + const std::vector<double>& l_GIP_L2TOCR_ViewZenithalAngleIndexes = l_lutxml.GetView_Zenith_Angle_Indexes(); + const std::vector<double>& l_GIP_L2TOCR_RelativeAzimuthAngleIndexes = l_lutxml.GetRelative_Azimuth_Angle_Indexes(); + + /* parameters are added one by one to the LUT */ + ParameterValuesType l_TOCRParam1; + l_TOCRParam1.ParameterName = "Solar_Zenith_Angle_Indexes"; + l_TOCRParam1.ParameterValues = l_GIP_L2TOCR_SolarZenithalAngleIndexes; + l_lookUpTableReader->AddParameterValues(l_TOCRParam1); + + ParameterValuesType l_TOCRParam2; + l_TOCRParam2.ParameterName = "View_Zenith_Angle_Indexes"; + l_TOCRParam2.ParameterValues = l_GIP_L2TOCR_ViewZenithalAngleIndexes; + l_lookUpTableReader->AddParameterValues(l_TOCRParam2); + + ParameterValuesType l_TOCRParam3; + l_TOCRParam3.ParameterName = "Relative_Azimuth_Angle_Indexes"; + l_TOCRParam3.ParameterValues = l_GIP_L2TOCR_RelativeAzimuthAngleIndexes; + l_lookUpTableReader->AddParameterValues(l_TOCRParam3); + + //Gen Lut + l_lookUpTableReader->GenerateLUT(); + + typedef LutType::PointType LUTPointType; + typedef LutType::Pointer LUTPointer; + typedef LUTPointType::ValueType LUTPointValueType; + typedef LutType::PixelType LUTPixelType; + LUTPointer l_LutInPtr = l_lookUpTableReader->GetLUT(); + LUTPointType point; + // Set the point[1] value + point[0] = static_cast<LUTPointValueType>(15); + point[1] = static_cast<LUTPointValueType>(8); + point[2] = static_cast<LUTPointValueType>(100); + + LUTPixelType interpValue = l_LutInPtr->InterpolateValue(point); + std::cout<<"Value : "<<interpValue<<std::endl; + for (unsigned int idx = 0; idx < interpValue.Size(); idx++) + { + BOOST_CHECK_CLOSE(interpValue[idx], Value_Out[idx],0.00001); + } + +} + + diff --git a/Common/CMakeLists.txt b/Code/MetadataHelper/CMakeLists.txt similarity index 57% rename from Common/CMakeLists.txt rename to Code/MetadataHelper/CMakeLists.txt index 1950434..65543e8 100644 --- a/Common/CMakeLists.txt +++ b/Code/MetadataHelper/CMakeLists.txt @@ -1,28 +1,21 @@ set(MetadataHelper_HEADERS - include/MuscateMetadataHelper.h include/MetadataHelperFactory.h include/MetadataHelper.h + include/MuscateMetadataHelper.h include/MetadataBands.h include/MetadataAngles.h - include/GlobalDefs.h - include/ResamplingBandExtractor.h - include/ImageResampler.h - include/TestImageCreator.h ) -set(MetadataHelper_SOURCES - src/MuscateMetadataHelper.cpp - src/GlobalDefs.cpp +set(MetadataHelper_SOURCES src/MetadataHelper.cpp + src/MuscateMetadataHelper.cpp src/MetadataBands.cpp src/MetadataHelperFactory.cpp ) add_library(MetadataHelper SHARED ${MetadataHelper_HEADERS} ${MetadataHelper_SOURCES}) -target_link_libraries(MetadataHelper MuscateMetadata - "${Boost_LIBRARIES}" - "${OTBCommon_LIBRARIES}" - "${OTBITK_LIBRARIES}") +target_link_libraries(MetadataHelper Common MuscateMetadata + ) target_include_directories(MetadataHelper PUBLIC include) install(TARGETS MetadataHelper DESTINATION lib/) diff --git a/Common/include/MetadataAngles.h b/Code/MetadataHelper/include/MetadataAngles.h similarity index 100% rename from Common/include/MetadataAngles.h rename to Code/MetadataHelper/include/MetadataAngles.h diff --git a/Common/include/MetadataBands.h b/Code/MetadataHelper/include/MetadataBands.h similarity index 100% rename from Common/include/MetadataBands.h rename to Code/MetadataHelper/include/MetadataBands.h diff --git a/Common/include/MetadataHelper.h b/Code/MetadataHelper/include/MetadataHelper.h similarity index 100% rename from Common/include/MetadataHelper.h rename to Code/MetadataHelper/include/MetadataHelper.h diff --git a/Common/include/MetadataHelperFactory.h b/Code/MetadataHelper/include/MetadataHelperFactory.h similarity index 100% rename from Common/include/MetadataHelperFactory.h rename to Code/MetadataHelper/include/MetadataHelperFactory.h diff --git a/Common/include/MuscateMetadataHelper.h b/Code/MetadataHelper/include/MuscateMetadataHelper.h similarity index 98% rename from Common/include/MuscateMetadataHelper.h rename to Code/MetadataHelper/include/MuscateMetadataHelper.h index 24a38a3..fea773d 100644 --- a/Common/include/MuscateMetadataHelper.h +++ b/Code/MetadataHelper/include/MuscateMetadataHelper.h @@ -29,7 +29,7 @@ #define MUSCATEMETADATAHELPER_H #include "MetadataHelper.h" -#include "../../MuscateMetadata/include/MuscateMetadataReader.hpp" +#include "MuscateMetadataReader.hpp" #include <vector> #include "GlobalDefs.h" diff --git a/Common/src/MetadataBands.cpp b/Code/MetadataHelper/src/MetadataBands.cpp similarity index 100% rename from Common/src/MetadataBands.cpp rename to Code/MetadataHelper/src/MetadataBands.cpp diff --git a/Common/src/MetadataHelper.cpp b/Code/MetadataHelper/src/MetadataHelper.cpp similarity index 100% rename from Common/src/MetadataHelper.cpp rename to Code/MetadataHelper/src/MetadataHelper.cpp diff --git a/Common/src/MetadataHelperFactory.cpp b/Code/MetadataHelper/src/MetadataHelperFactory.cpp similarity index 96% rename from Common/src/MetadataHelperFactory.cpp rename to Code/MetadataHelper/src/MetadataHelperFactory.cpp index ac7ae7b..b6c535c 100644 --- a/Common/src/MetadataHelperFactory.cpp +++ b/Code/MetadataHelper/src/MetadataHelperFactory.cpp @@ -24,7 +24,8 @@ */ #include "MetadataHelperFactory.h" -#include "MuscateMetadataHelper.h" + +#include "../include/MuscateMetadataHelper.h" using namespace ts; diff --git a/Common/src/MuscateMetadataHelper.cpp b/Code/MetadataHelper/src/MuscateMetadataHelper.cpp similarity index 99% rename from Common/src/MuscateMetadataHelper.cpp rename to Code/MetadataHelper/src/MuscateMetadataHelper.cpp index c439f67..2dbcf45 100644 --- a/Common/src/MuscateMetadataHelper.cpp +++ b/Code/MetadataHelper/src/MuscateMetadataHelper.cpp @@ -25,10 +25,11 @@ * SPDX-License-Identifier: GPL-3.0-or-later */ -#include "MuscateMetadataHelper.h" -#include <ViewingAngles.hpp> +#include "../include/MuscateMetadataHelper.h" + #include <boost/algorithm/string/predicate.hpp> #include <boost/filesystem.hpp> +#include <MuscateViewingAngles.hpp> #include <sys/stat.h> diff --git a/Common/test/CMakeLists.txt b/Code/MetadataHelper/test/CMakeLists.txt similarity index 77% rename from Common/test/CMakeLists.txt rename to Code/MetadataHelper/test/CMakeLists.txt index fd613c8..7451a88 100644 --- a/Common/test/CMakeLists.txt +++ b/Code/MetadataHelper/test/CMakeLists.txt @@ -26,14 +26,6 @@ target_link_libraries(test_MuscateMetadataHelperVenus "${OTBITK_LIBRARIES}" ) -add_executable(test_ImageResampler test_ImageResampler.cpp ../include/ImageResampler.h) -target_link_libraries(test_ImageResampler - MuscateMetadata - MetadataHelper - ${Boost_LIBRARIES} - ${OTB_LIBRARIES} - ) - target_include_directories(test_MuscateMetadataHelper PUBLIC ../include) add_test(test_MuscateMetadataHelper test_MuscateMetadataHelper) @@ -42,6 +34,3 @@ add_test(test_MetadataBands test_MetadataBands) target_include_directories(test_MuscateMetadataHelperVenus PUBLIC ../include) add_test(test_MuscateMetadataHelperVenus test_MuscateMetadataHelperVenus) - -target_include_directories(test_ImageResampler PUBLIC ../include) -add_test(test_ImageResampler test_ImageResampler) diff --git a/Common/test/test_MetadataBands.cpp b/Code/MetadataHelper/test/test_MetadataBands.cpp similarity index 100% rename from Common/test/test_MetadataBands.cpp rename to Code/MetadataHelper/test/test_MetadataBands.cpp diff --git a/Common/test/test_MuscateMetadataHelper.cpp b/Code/MetadataHelper/test/test_MuscateMetadataHelper.cpp similarity index 99% rename from Common/test/test_MuscateMetadataHelper.cpp rename to Code/MetadataHelper/test/test_MuscateMetadataHelper.cpp index 25586e4..b754c7a 100644 --- a/Common/test/test_MuscateMetadataHelper.cpp +++ b/Code/MetadataHelper/test/test_MuscateMetadataHelper.cpp @@ -27,8 +27,8 @@ #define BOOST_TEST_MODULE MuscateWriter #include <boost/test/unit_test.hpp> -#include "../include/MuscateMetadataHelper.h" -#include "../include/GlobalDefs.h" +#include "MuscateMetadataHelper.h" +#include "GlobalDefs.h" #include <string> using namespace ts; diff --git a/Common/test/test_MuscateMetadataHelperVenus.cpp b/Code/MetadataHelper/test/test_MuscateMetadataHelperVenus.cpp similarity index 100% rename from Common/test/test_MuscateMetadataHelperVenus.cpp rename to Code/MetadataHelper/test/test_MuscateMetadataHelperVenus.cpp diff --git a/MuscateMetadata/CMakeLists.txt b/Code/MuscateMetadata/CMakeLists.txt similarity index 60% rename from MuscateMetadata/CMakeLists.txt rename to Code/MuscateMetadata/CMakeLists.txt index a6e5b5a..7bb55bc 100644 --- a/MuscateMetadata/CMakeLists.txt +++ b/Code/MuscateMetadata/CMakeLists.txt @@ -1,28 +1,24 @@ -set(MuscateMetadata_HEADERS - include/FluentXML.hpp - include/tinyxml_utils.hpp - include/string_utils.hpp - include/MuscateMetadata.hpp +set(MuscateMetadata_HEADERS + include/MuscateMetadata.hpp include/MuscateMetadataReader.hpp include/MuscateMetadataWriter.hpp - include/MetadataUtil.hpp - include/ViewingAngles.hpp) + include/MuscateMetadataUtil.hpp + include/MuscateViewingAngles.hpp) set(MuscateMetadata_SOURCES - src/FluentXML.cpp - src/tinyxml_utils.cpp - src/string_utils.cpp src/MuscateMetadataReader.cpp src/MuscateMetadataWriter.cpp - src/ViewingAngles.cpp - src/MetadataUtil.cpp) + src/MuscateViewingAngles.cpp + src/MuscateMetadataUtil.cpp) add_library(MuscateMetadata SHARED ${MuscateMetadata_HEADERS} ${MuscateMetadata_SOURCES}) target_link_libraries(MuscateMetadata + Common "${Boost_LIBRARIES}" "${OTBCommon_LIBRARIES}" "${OTBTinyXML_LIBRARIES}" - "${OTBITK_LIBRARIES}") + "${OTBITK_LIBRARIES}" + ) target_include_directories(MuscateMetadata PUBLIC include) diff --git a/MuscateMetadata/include/MuscateMetadata.hpp b/Code/MuscateMetadata/include/MuscateMetadata.hpp similarity index 100% rename from MuscateMetadata/include/MuscateMetadata.hpp rename to Code/MuscateMetadata/include/MuscateMetadata.hpp diff --git a/MuscateMetadata/include/MuscateMetadataReader.hpp b/Code/MuscateMetadata/include/MuscateMetadataReader.hpp similarity index 100% rename from MuscateMetadata/include/MuscateMetadataReader.hpp rename to Code/MuscateMetadata/include/MuscateMetadataReader.hpp diff --git a/MuscateMetadata/include/MetadataUtil.hpp b/Code/MuscateMetadata/include/MuscateMetadataUtil.hpp similarity index 100% rename from MuscateMetadata/include/MetadataUtil.hpp rename to Code/MuscateMetadata/include/MuscateMetadataUtil.hpp diff --git a/MuscateMetadata/include/MuscateMetadataWriter.hpp b/Code/MuscateMetadata/include/MuscateMetadataWriter.hpp similarity index 100% rename from MuscateMetadata/include/MuscateMetadataWriter.hpp rename to Code/MuscateMetadata/include/MuscateMetadataWriter.hpp diff --git a/MuscateMetadata/include/ViewingAngles.hpp b/Code/MuscateMetadata/include/MuscateViewingAngles.hpp similarity index 100% rename from MuscateMetadata/include/ViewingAngles.hpp rename to Code/MuscateMetadata/include/MuscateViewingAngles.hpp diff --git a/MuscateMetadata/src/MuscateMetadataReader.cpp b/Code/MuscateMetadata/src/MuscateMetadataReader.cpp similarity index 99% rename from MuscateMetadata/src/MuscateMetadataReader.cpp rename to Code/MuscateMetadata/src/MuscateMetadataReader.cpp index db091ec..8512962 100644 --- a/MuscateMetadata/src/MuscateMetadataReader.cpp +++ b/Code/MuscateMetadata/src/MuscateMetadataReader.cpp @@ -30,13 +30,13 @@ #include <boost/algorithm/string/predicate.hpp> #include <boost/filesystem.hpp> +#include <MuscateMetadataUtil.hpp> +#include <StringUtils.hpp> +#include <TinyXMLUtils.hpp> #include "otbMacro.h" #include "MuscateMetadataReader.hpp" -#include "tinyxml_utils.hpp" -#include "string_utils.hpp" -#include "MetadataUtil.hpp" namespace ts { namespace muscate { diff --git a/MuscateMetadata/src/MetadataUtil.cpp b/Code/MuscateMetadata/src/MuscateMetadataUtil.cpp similarity index 99% rename from MuscateMetadata/src/MetadataUtil.cpp rename to Code/MuscateMetadata/src/MuscateMetadataUtil.cpp index 4eb8402..a3792ff 100644 --- a/MuscateMetadata/src/MetadataUtil.cpp +++ b/Code/MuscateMetadata/src/MuscateMetadataUtil.cpp @@ -23,7 +23,7 @@ * SPDX-License-Identifier: GPL-3.0-or-later */ -#include "MetadataUtil.hpp" +#include <MuscateMetadataUtil.hpp> #include "MuscateMetadataReader.hpp" std::string toUpperCase(const std::string & s) diff --git a/MuscateMetadata/src/MuscateMetadataWriter.cpp b/Code/MuscateMetadata/src/MuscateMetadataWriter.cpp similarity index 99% rename from MuscateMetadata/src/MuscateMetadataWriter.cpp rename to Code/MuscateMetadata/src/MuscateMetadataWriter.cpp index 2d8802f..4c2e713 100644 --- a/MuscateMetadata/src/MuscateMetadataWriter.cpp +++ b/Code/MuscateMetadata/src/MuscateMetadataWriter.cpp @@ -25,9 +25,9 @@ * SPDX-License-Identifier: GPL-3.0-or-later */ +#include <MuscateMetadataUtil.hpp> +#include <StringUtils.hpp> #include "MuscateMetadataWriter.hpp" -#include "MetadataUtil.hpp" -#include "string_utils.hpp" namespace ts { namespace muscate { diff --git a/MuscateMetadata/src/ViewingAngles.cpp b/Code/MuscateMetadata/src/MuscateViewingAngles.cpp similarity index 98% rename from MuscateMetadata/src/ViewingAngles.cpp rename to Code/MuscateMetadata/src/MuscateViewingAngles.cpp index a17811e..f173760 100644 --- a/MuscateMetadata/src/ViewingAngles.cpp +++ b/Code/MuscateMetadata/src/MuscateViewingAngles.cpp @@ -23,13 +23,13 @@ * SPDX-License-Identifier: GPL-3.0-or-later */ +#include <MuscateMetadataUtil.hpp> +#include <MuscateViewingAngles.hpp> #include <cmath> #include <limits> #include <map> #include <stdexcept> -#include "ViewingAngles.hpp" -#include "MetadataUtil.hpp" static void checkDimensions(std::string expectedColumnUnit, std::string expectedColumnStep, std::string expectedRowUnit, diff --git a/MuscateMetadata/test/CMakeLists.txt b/Code/MuscateMetadata/test/CMakeLists.txt similarity index 100% rename from MuscateMetadata/test/CMakeLists.txt rename to Code/MuscateMetadata/test/CMakeLists.txt diff --git a/MuscateMetadata/test/test_MuscateMetadataReadWrite.cpp b/Code/MuscateMetadata/test/test_MuscateMetadataReadWrite.cpp similarity index 99% rename from MuscateMetadata/test/test_MuscateMetadataReadWrite.cpp rename to Code/MuscateMetadata/test/test_MuscateMetadataReadWrite.cpp index e274903..5acb71f 100644 --- a/MuscateMetadata/test/test_MuscateMetadataReadWrite.cpp +++ b/Code/MuscateMetadata/test/test_MuscateMetadataReadWrite.cpp @@ -31,7 +31,7 @@ #include "GlobalDefs.h" #include "MuscateMetadataWriter.hpp" #include "MuscateMetadataReader.hpp" -#include "MetadataUtil.hpp" +#include <MuscateMetadataUtil.hpp> #include "stdlib.h" #define TEST_NAME "test_MuscateMetadata" diff --git a/MuscateMetadata/test/test_MuscateMetadataReader.cpp b/Code/MuscateMetadata/test/test_MuscateMetadataReader.cpp similarity index 100% rename from MuscateMetadata/test/test_MuscateMetadataReader.cpp rename to Code/MuscateMetadata/test/test_MuscateMetadataReader.cpp diff --git a/MuscateMetadata/test/test_MuscateMetadataWriteRead.cpp b/Code/MuscateMetadata/test/test_MuscateMetadataWriteRead.cpp similarity index 99% rename from MuscateMetadata/test/test_MuscateMetadataWriteRead.cpp rename to Code/MuscateMetadata/test/test_MuscateMetadataWriteRead.cpp index 6de4698..055d733 100644 --- a/MuscateMetadata/test/test_MuscateMetadataWriteRead.cpp +++ b/Code/MuscateMetadata/test/test_MuscateMetadataWriteRead.cpp @@ -30,7 +30,7 @@ #include "MuscateMetadataWriter.hpp" #include "MuscateMetadataReader.hpp" -#include "MetadataUtil.hpp" +#include <MuscateMetadataUtil.hpp> #include "stdlib.h" #define EMPTY_XML "Empty.xml" diff --git a/ProductFormatter/CMakeLists.txt b/Code/ProductFormatter/CMakeLists.txt similarity index 100% rename from ProductFormatter/CMakeLists.txt rename to Code/ProductFormatter/CMakeLists.txt diff --git a/ProductFormatter/include/ProductCreatorAdapter.h b/Code/ProductFormatter/include/ProductCreatorAdapter.h similarity index 100% rename from ProductFormatter/include/ProductCreatorAdapter.h rename to Code/ProductFormatter/include/ProductCreatorAdapter.h diff --git a/ProductFormatter/include/ProductCreatorSentinelMuscate.h b/Code/ProductFormatter/include/ProductCreatorSentinelMuscate.h similarity index 100% rename from ProductFormatter/include/ProductCreatorSentinelMuscate.h rename to Code/ProductFormatter/include/ProductCreatorSentinelMuscate.h diff --git a/ProductFormatter/include/ProductCreatorVenusMuscate.h b/Code/ProductFormatter/include/ProductCreatorVenusMuscate.h similarity index 100% rename from ProductFormatter/include/ProductCreatorVenusMuscate.h rename to Code/ProductFormatter/include/ProductCreatorVenusMuscate.h diff --git a/ProductFormatter/include/ProductDefinitions.h b/Code/ProductFormatter/include/ProductDefinitions.h similarity index 100% rename from ProductFormatter/include/ProductDefinitions.h rename to Code/ProductFormatter/include/ProductDefinitions.h diff --git a/ProductFormatter/src/ProductCreatorAdapter.cpp b/Code/ProductFormatter/src/ProductCreatorAdapter.cpp similarity index 100% rename from ProductFormatter/src/ProductCreatorAdapter.cpp rename to Code/ProductFormatter/src/ProductCreatorAdapter.cpp diff --git a/ProductFormatter/src/ProductCreatorSentinelMuscate.cpp b/Code/ProductFormatter/src/ProductCreatorSentinelMuscate.cpp similarity index 99% rename from ProductFormatter/src/ProductCreatorSentinelMuscate.cpp rename to Code/ProductFormatter/src/ProductCreatorSentinelMuscate.cpp index c579fdc..6ccd33a 100644 --- a/ProductFormatter/src/ProductCreatorSentinelMuscate.cpp +++ b/Code/ProductFormatter/src/ProductCreatorSentinelMuscate.cpp @@ -59,8 +59,8 @@ bool ProductCreatorSentinelMuscate::createProduct(const std::string &destination reader->SetFileName(productFilename); ShortVectorImageType::Pointer productRaster = reader->GetOutput(); reader->UpdateOutputInformation(); - std::cout << "Spacing is: " << productRaster->GetSpacing()[0] << std::endl; - int resolution = productRaster->GetSpacing()[0]; + std::cout << "Spacing is: " << productRaster->GetSignedSpacing()[0] << std::endl; + int resolution = productRaster->GetSignedSpacing()[0]; if(resolution == S2_RESOLUTION_R1){ productr1 = productFilename; }else if(resolution == S2_RESOLUTION_R2){ diff --git a/ProductFormatter/src/ProductCreatorVenusMuscate.cpp b/Code/ProductFormatter/src/ProductCreatorVenusMuscate.cpp similarity index 99% rename from ProductFormatter/src/ProductCreatorVenusMuscate.cpp rename to Code/ProductFormatter/src/ProductCreatorVenusMuscate.cpp index a2d02e8..a6f1579 100644 --- a/ProductFormatter/src/ProductCreatorVenusMuscate.cpp +++ b/Code/ProductFormatter/src/ProductCreatorVenusMuscate.cpp @@ -332,7 +332,7 @@ void ProductCreatorVenusMuscate::generateMetadataFile(const std::string &strProd m_productMetadata.MetadataIdentification.MetadataProfile = "GENERIC"; m_productMetadata.MetadataIdentification.MetadataInformation = "EXPERT"; //DatasetIdentification - m_productMetadata.DatasetIdentification.Identifier = m_strProductDirectoryName.substr(0, m_strProductDirectoryName.find("_V")); + m_productMetadata.DatasetIdentification.Identifier = m_strProductDirectoryName.substr(0, m_strProductDirectoryName.find_last_of("_V")); m_productMetadata.DatasetIdentification.Authority = "THEIA"; m_productMetadata.DatasetIdentification.Producer = "MUSCATE"; m_productMetadata.DatasetIdentification.Project = getPlatform(m_mission); diff --git a/ProductFormatter/src/ProductFormatter.cpp b/Code/ProductFormatter/src/ProductFormatter.cpp similarity index 99% rename from ProductFormatter/src/ProductFormatter.cpp rename to Code/ProductFormatter/src/ProductFormatter.cpp index b81fdbc..3d9fbf2 100644 --- a/ProductFormatter/src/ProductFormatter.cpp +++ b/Code/ProductFormatter/src/ProductFormatter.cpp @@ -23,9 +23,9 @@ * SPDX-License-Identifier: GPL-3.0-or-later */ +#include <StringUtils.hpp> #include "otbWrapperApplication.h" #include "otbWrapperApplicationFactory.h" -#include "string_utils.hpp" #include "ProductCreatorSentinelMuscate.h" #include "ProductCreatorVenusMuscate.h" @@ -64,7 +64,6 @@ private: SetName("ProductFormatter"); SetDescription("Creates the final output product using the previously generated files from UpdateSynthesis as well as all Metadata Information"); - SetDocName("ProductFormatter"); SetDocLongDescription("Creates the final output product using the previously generated files from UpdateSynthesis as well as all Metadata Information"); SetDocLimitations("None"); SetDocAuthors("Peter KETTIG, CNES"); diff --git a/ProductFormatter/test/CMakeLists.txt b/Code/ProductFormatter/test/CMakeLists.txt similarity index 100% rename from ProductFormatter/test/CMakeLists.txt rename to Code/ProductFormatter/test/CMakeLists.txt diff --git a/UpdateSynthesis/CMakeLists.txt b/Code/UpdateSynthesis/CMakeLists.txt similarity index 100% rename from UpdateSynthesis/CMakeLists.txt rename to Code/UpdateSynthesis/CMakeLists.txt diff --git a/UpdateSynthesis/include/BandsDefs.h b/Code/UpdateSynthesis/include/BandsDefs.h similarity index 100% rename from UpdateSynthesis/include/BandsDefs.h rename to Code/UpdateSynthesis/include/BandsDefs.h diff --git a/UpdateSynthesis/include/UpdateSynthesisFunctor.h b/Code/UpdateSynthesis/include/UpdateSynthesisFunctor.h similarity index 100% rename from UpdateSynthesis/include/UpdateSynthesisFunctor.h rename to Code/UpdateSynthesis/include/UpdateSynthesisFunctor.h diff --git a/UpdateSynthesis/src/UpdateSynthesis.cpp b/Code/UpdateSynthesis/src/UpdateSynthesis.cpp similarity index 96% rename from UpdateSynthesis/src/UpdateSynthesis.cpp rename to Code/UpdateSynthesis/src/UpdateSynthesis.cpp index 7e4841e..0922dfd 100644 --- a/UpdateSynthesis/src/UpdateSynthesis.cpp +++ b/Code/UpdateSynthesis/src/UpdateSynthesis.cpp @@ -23,6 +23,7 @@ * SPDX-License-Identifier: GPL-3.0-or-later */ +#include <StringUtils.hpp> #include "otbWrapperApplication.h" #include "otbWrapperApplicationFactory.h" @@ -36,7 +37,6 @@ #include "ResamplingBandExtractor.h" #include "UpdateSynthesisFunctor.h" #include "BandsDefs.h" -#include "string_utils.hpp" /** * @brief otb Namespace for all OTB-related Filters and Applications @@ -91,7 +91,6 @@ private: SetName("UpdateSynthesis"); SetDescription("Update synthesis using the recurrent expression of the weighted average."); - SetDocName("UpdateSynthesis"); SetDocLongDescription("Update synthesis using the recurrent expression of the weighted average."); SetDocLimitations("None"); SetDocAuthors("Peter KETTIG"); @@ -201,7 +200,7 @@ private: int nDesiredWidth = nL2AWidth; int nDesiredHeight = nL2AHeight; - auto spacingL2A = L2AImage->GetSpacing(); + auto spacingL2A = L2AImage->GetSignedSpacing(); int nExtractedBandsNo = 0; @@ -236,10 +235,10 @@ private: nRelBlueBandIdx = nExtractedBandsNo++; } - nBandsL2A += ResampledBandsExtractor.ExtractAllResampledBands(m_CloudMask, rasterList, Interpolator_NNeighbor, m_CloudMask->GetSpacing()[0], spacingL2A[0], nDesiredWidth, nDesiredHeight); - nBandsL2A += ResampledBandsExtractor.ExtractAllResampledBands(m_WaterMask, rasterList, Interpolator_NNeighbor, m_WaterMask->GetSpacing()[0], spacingL2A[0], nDesiredWidth, nDesiredHeight); - nBandsL2A += ResampledBandsExtractor.ExtractAllResampledBands(m_SnowMask, rasterList, Interpolator_NNeighbor, m_SnowMask->GetSpacing()[0], spacingL2A[0], nDesiredWidth, nDesiredHeight); - ResampledBandsExtractor.ExtractAllResampledBands(m_WeightsL2A, rasterList, Interpolator_Linear, m_WeightsL2A->GetSpacing()[0], spacingL2A[0], nDesiredWidth, nDesiredHeight); + nBandsL2A += ResampledBandsExtractor.ExtractAllResampledBands(m_CloudMask, rasterList, Interpolator_NNeighbor, m_CloudMask->GetSignedSpacing()[0], spacingL2A[0], nDesiredWidth, nDesiredHeight); + nBandsL2A += ResampledBandsExtractor.ExtractAllResampledBands(m_WaterMask, rasterList, Interpolator_NNeighbor, m_WaterMask->GetSignedSpacing()[0], spacingL2A[0], nDesiredWidth, nDesiredHeight); + nBandsL2A += ResampledBandsExtractor.ExtractAllResampledBands(m_SnowMask, rasterList, Interpolator_NNeighbor, m_SnowMask->GetSignedSpacing()[0], spacingL2A[0], nDesiredWidth, nDesiredHeight); + ResampledBandsExtractor.ExtractAllResampledBands(m_WeightsL2A, rasterList, Interpolator_Linear, m_WeightsL2A->GetSignedSpacing()[0], spacingL2A[0], nDesiredWidth, nDesiredHeight); m_VectorObjectList.push_back(imageListPerResolution); @@ -264,11 +263,11 @@ private: auto szL3A = prevL3A->GetLargestPossibleRegion().GetSize(); nL3AWidth = szL3A[0]; nL3AHeight = szL3A[1]; - auto spacingPrevL3A = L2AImage->GetSpacing(); + auto spacingPrevL3A = L2AImage->GetSignedSpacing(); if((nL3AWidth != nL2AWidth) || (nL3AHeight != nL2AHeight)) { otbMsgDevMacro("WARNING: L3A and L2A product sizes differ: " << "L2A: " << nL2AWidth << " " << nL2AHeight << ", " - << "L3A: " << nL3AWidth << " " << nL3AHeight << std::endl;) + << "L3A: " << nL3AWidth << " " << nL3AHeight ) } InternalBandImageType::Pointer weights = ResampledBandsExtractor.ExtractImgResampledBand(prevL3A, 1, Interpolator_Linear, spacingPrevL3A[0], spacingL2A[0], nDesiredWidth, nDesiredHeight); rasterList->PushBack(weights); @@ -297,11 +296,11 @@ private: auto szL3A = prevL3AFlags->GetLargestPossibleRegion().GetSize(); nL3AWidth = szL3A[0]; nL3AHeight = szL3A[1]; - auto spacingPrevL3A = L2AImage->GetSpacing(); + auto spacingPrevL3A = L2AImage->GetSignedSpacing(); if((nL3AWidth != nL2AWidth) || (nL3AHeight != nL2AHeight)) { otbMsgDevMacro("WARNING: L3A and L2A product sizes differ: " << "L2A: " << nL2AWidth << " " << nL2AHeight << ", " - << "L3A: " << nL3AWidth << " " << nL3AHeight << std::endl;) + << "L3A: " << nL3AWidth << " " << nL3AHeight ) } int nL3Weights = ResampledBandsExtractor.ExtractAllResampledBands(prevL3AWeight, rasterList, Interpolator_Linear, spacingPrevL3A[0], spacingL2A[0], nDesiredWidth, nDesiredHeight); int nL3Dates= ResampledBandsExtractor.ExtractAllResampledBands(prevL3AAvgDate, rasterList, Interpolator_Linear, spacingPrevL3A[0], spacingL2A[0], nDesiredWidth, nDesiredHeight); diff --git a/UpdateSynthesis/src/UpdateSynthesisFunctor.txx b/Code/UpdateSynthesis/src/UpdateSynthesisFunctor.txx similarity index 99% rename from UpdateSynthesis/src/UpdateSynthesisFunctor.txx rename to Code/UpdateSynthesis/src/UpdateSynthesisFunctor.txx index 17bf734..35dbb9d 100644 --- a/UpdateSynthesis/src/UpdateSynthesisFunctor.txx +++ b/Code/UpdateSynthesis/src/UpdateSynthesisFunctor.txx @@ -574,7 +574,7 @@ float UpdateSynthesisFunctor<TInput,TOutput>::GetPrevL3AReflectanceValue(const T if(fPixelVal < 0) { return NO_DATA_VALUE; } - return fPixelVal/DEFAULT_COMPOSITION_QUANTIF_VALUE; + return fPixelVal/m_fReflQuantifValue; } return NO_DATA_VALUE; } diff --git a/UpdateSynthesis/test/CMakeLists.txt b/Code/UpdateSynthesis/test/CMakeLists.txt similarity index 100% rename from UpdateSynthesis/test/CMakeLists.txt rename to Code/UpdateSynthesis/test/CMakeLists.txt diff --git a/WeightCalculation/CMakeLists.txt b/Code/WeightCalculation/CMakeLists.txt similarity index 100% rename from WeightCalculation/CMakeLists.txt rename to Code/WeightCalculation/CMakeLists.txt diff --git a/WeightCalculation/TotalWeight/CMakeLists.txt b/Code/WeightCalculation/TotalWeight/CMakeLists.txt similarity index 100% rename from WeightCalculation/TotalWeight/CMakeLists.txt rename to Code/WeightCalculation/TotalWeight/CMakeLists.txt diff --git a/WeightCalculation/TotalWeight/include/TotalWeightComputation.h b/Code/WeightCalculation/TotalWeight/include/TotalWeightComputation.h similarity index 100% rename from WeightCalculation/TotalWeight/include/TotalWeightComputation.h rename to Code/WeightCalculation/TotalWeight/include/TotalWeightComputation.h diff --git a/WeightCalculation/TotalWeight/src/TotalWeight.cpp b/Code/WeightCalculation/TotalWeight/src/TotalWeight.cpp similarity index 99% rename from WeightCalculation/TotalWeight/src/TotalWeight.cpp rename to Code/WeightCalculation/TotalWeight/src/TotalWeight.cpp index 1a29429..936972e 100644 --- a/WeightCalculation/TotalWeight/src/TotalWeight.cpp +++ b/Code/WeightCalculation/TotalWeight/src/TotalWeight.cpp @@ -65,7 +65,6 @@ private: SetName("TotalWeight"); SetDescription("Calculate the total weight using the AOT- and cloud-images"); - SetDocName("Total Weight Computation"); SetDocLongDescription("Calculate the total weight using the AOT- and cloud-images"); SetDocLimitations("None"); diff --git a/WeightCalculation/TotalWeight/src/TotalWeightComputation.cpp b/Code/WeightCalculation/TotalWeight/src/TotalWeightComputation.cpp similarity index 92% rename from WeightCalculation/TotalWeight/src/TotalWeightComputation.cpp rename to Code/WeightCalculation/TotalWeight/src/TotalWeightComputation.cpp index c2b9b25..6ffe711 100644 --- a/WeightCalculation/TotalWeight/src/TotalWeightComputation.cpp +++ b/Code/WeightCalculation/TotalWeight/src/TotalWeightComputation.cpp @@ -140,8 +140,8 @@ void TotalWeightComputation::ComputeTotalWeight() ImageType::Pointer imgCld = m_inputReaderCld->GetOutput(); imgAot->UpdateOutputInformation(); imgCld->UpdateOutputInformation(); - ImageType::SpacingType spacingAot = imgAot->GetSpacing(); - ImageType::SpacingType spacingCld = imgCld->GetSpacing(); + ImageType::SpacingType spacingAot = imgAot->GetSignedSpacing(); + ImageType::SpacingType spacingCld = imgCld->GetSignedSpacing(); ImageType::PointType originAot = imgAot->GetOrigin(); ImageType::PointType originCld = imgCld->GetOrigin(); @@ -180,7 +180,7 @@ void TotalWeightComputation::CheckTolerance() // tolerance for origin and spacing depends on the size of pixel // tolerance for directions a fraction of the unit cube. const SpacePrecisionType coordinateTol - = m_CoordinateTolerance * inputPtr1->GetSpacing()[0]; // use first dimension spacing + = m_CoordinateTolerance * inputPtr1->GetSignedSpacing()[0]; // use first dimension spacing /*vnl_vector<double> vect1 = inputPtr1->GetOrigin().GetVnlVector(); double val11 = vect1.get(0); @@ -192,11 +192,11 @@ void TotalWeightComputation::CheckTolerance() double diff1 = fabs(val11-val21); double diff2 = fabs(val12-val22); - vnl_vector<double> vect3 = inputPtr1->GetSpacing().GetVnlVector(); + vnl_vector<double> vect3 = inputPtr1->GetSignedSpacing().GetVnlVector(); double val31 = vect3.get(0); double val32 = vect3.get(1); - vnl_vector<double> vect4 = inputPtrN->GetSpacing().GetVnlVector(); + vnl_vector<double> vect4 = inputPtrN->GetSignedSpacing().GetVnlVector(); double val41 = vect4.get(0); double val42 = vect4.get(1); @@ -208,7 +208,7 @@ void TotalWeightComputation::CheckTolerance() //vnl_vector<SpacingValueType> vect2 = inputPtrN->GetOrigin().GetVnlVector(); if ( !inputPtr1->GetOrigin().GetVnlVector().is_equal(inputPtrN->GetOrigin().GetVnlVector(), coordinateTol) || - !inputPtr1->GetSpacing().GetVnlVector().is_equal(inputPtrN->GetSpacing().GetVnlVector(), coordinateTol) || + !inputPtr1->GetSignedSpacing().GetVnlVector().is_equal(inputPtrN->GetSignedSpacing().GetVnlVector(), coordinateTol) || !inputPtr1->GetDirection().GetVnlMatrix().as_ref().is_equal(inputPtrN->GetDirection().GetVnlMatrix(), m_DirectionTolerance) ) { std::ostringstream originString, spacingString, directionString; @@ -220,12 +220,12 @@ void TotalWeightComputation::CheckTolerance() << ", InputImage" << " Origin: " << inputPtrN->GetOrigin() << std::endl; originString << "\tTolerance: " << coordinateTol << std::endl; } - if ( !inputPtr1->GetSpacing().GetVnlVector().is_equal(inputPtrN->GetSpacing().GetVnlVector(), coordinateTol) ) + if ( !inputPtr1->GetSignedSpacing().GetVnlVector().is_equal(inputPtrN->GetSignedSpacing().GetVnlVector(), coordinateTol) ) { spacingString.setf( std::ios::scientific ); spacingString.precision( 7 ); - spacingString << "InputImage Spacing: " << inputPtr1->GetSpacing() - << ", InputImage" << " Spacing: " << inputPtrN->GetSpacing() << std::endl; + spacingString << "InputImage Spacing: " << inputPtr1->GetSignedSpacing() + << ", InputImage" << " Spacing: " << inputPtrN->GetSignedSpacing() << std::endl; spacingString << "\tTolerance: " << coordinateTol << std::endl; } if ( !inputPtr1->GetDirection().GetVnlMatrix().as_ref().is_equal(inputPtrN->GetDirection().GetVnlMatrix(), m_DirectionTolerance) ) diff --git a/WeightCalculation/TotalWeight/test/CMakeLists.txt b/Code/WeightCalculation/TotalWeight/test/CMakeLists.txt similarity index 100% rename from WeightCalculation/TotalWeight/test/CMakeLists.txt rename to Code/WeightCalculation/TotalWeight/test/CMakeLists.txt diff --git a/WeightCalculation/WeightAOT/CMakeLists.txt b/Code/WeightCalculation/WeightAOT/CMakeLists.txt similarity index 100% rename from WeightCalculation/WeightAOT/CMakeLists.txt rename to Code/WeightCalculation/WeightAOT/CMakeLists.txt diff --git a/WeightCalculation/WeightAOT/include/WeightAOTComputation.h b/Code/WeightCalculation/WeightAOT/include/WeightAOTComputation.h similarity index 100% rename from WeightCalculation/WeightAOT/include/WeightAOTComputation.h rename to Code/WeightCalculation/WeightAOT/include/WeightAOTComputation.h diff --git a/WeightCalculation/WeightAOT/src/WeightAOT.cpp b/Code/WeightCalculation/WeightAOT/src/WeightAOT.cpp similarity index 99% rename from WeightCalculation/WeightAOT/src/WeightAOT.cpp rename to Code/WeightCalculation/WeightAOT/src/WeightAOT.cpp index 08da4ae..33b575d 100644 --- a/WeightCalculation/WeightAOT/src/WeightAOT.cpp +++ b/Code/WeightCalculation/WeightAOT/src/WeightAOT.cpp @@ -64,7 +64,6 @@ private: SetName("WeightAOT"); SetDescription("Calculate the AOT-weight from a given AOT-mask"); - SetDocName("WeightAOT"); SetDocLongDescription("Calculate the AOT-weight from a given AOT-mask"); SetDocLimitations("None"); SetDocAuthors("Peter Kettig"); diff --git a/WeightCalculation/WeightAOT/src/WeightAOTComputation.cpp b/Code/WeightCalculation/WeightAOT/src/WeightAOTComputation.cpp similarity index 98% rename from WeightCalculation/WeightAOT/src/WeightAOTComputation.cpp rename to Code/WeightCalculation/WeightAOT/src/WeightAOTComputation.cpp index 71460c5..88421ff 100644 --- a/WeightCalculation/WeightAOT/src/WeightAOTComputation.cpp +++ b/Code/WeightCalculation/WeightAOT/src/WeightAOTComputation.cpp @@ -88,7 +88,7 @@ int WeightOnAOT::GetInputImageResolution() { m_inputReader->UpdateOutputInformation(); ImageType::Pointer inputImage = m_inputReader->GetOutput(); - return inputImage->GetSpacing()[0]; + return inputImage->GetSignedSpacing()[0]; } diff --git a/WeightCalculation/WeightAOT/test/CMakeLists.txt b/Code/WeightCalculation/WeightAOT/test/CMakeLists.txt similarity index 100% rename from WeightCalculation/WeightAOT/test/CMakeLists.txt rename to Code/WeightCalculation/WeightAOT/test/CMakeLists.txt diff --git a/WeightCalculation/WeightOnClouds/CMakeLists.txt b/Code/WeightCalculation/WeightOnClouds/CMakeLists.txt similarity index 100% rename from WeightCalculation/WeightOnClouds/CMakeLists.txt rename to Code/WeightCalculation/WeightOnClouds/CMakeLists.txt diff --git a/WeightCalculation/WeightOnClouds/include/CloudMaskBinarization.h b/Code/WeightCalculation/WeightOnClouds/include/CloudMaskBinarization.h similarity index 98% rename from WeightCalculation/WeightOnClouds/include/CloudMaskBinarization.h rename to Code/WeightCalculation/WeightOnClouds/include/CloudMaskBinarization.h index 40c89fd..a20c646 100644 --- a/WeightCalculation/WeightOnClouds/include/CloudMaskBinarization.h +++ b/Code/WeightCalculation/WeightOnClouds/include/CloudMaskBinarization.h @@ -139,7 +139,7 @@ public: int GetInputImageResolution() { m_inputReader->UpdateOutputInformation(); typename TInput::Pointer inputImage = m_inputReader->GetOutput(); - return inputImage->GetSpacing()[0]; + return inputImage->GetSignedSpacing()[0]; } void SetThreshold(float fThreshold) { @@ -157,7 +157,7 @@ public: { writer->Update(); typename TInput::Pointer image = m_inputReader->GetOutput(); - typename TInput::SpacingType spacing = image->GetSpacing(); + typename TInput::SpacingType spacing = image->GetSignedSpacing(); typename TInput::PointType origin = image->GetOrigin(); std::cout << "============= CLOUD BINARIZATION ====================" << std::endl; std::cout << "Input Origin : " << origin[0] << " " << origin[1] << std::endl; @@ -165,7 +165,7 @@ public: std::cout << "Size : " << image->GetLargestPossibleRegion().GetSize()[0] << " " << image->GetLargestPossibleRegion().GetSize()[1] << std::endl; - typename TInput::SpacingType outspacing = m_filter->GetOutput()->GetSpacing(); + typename TInput::SpacingType outspacing = m_filter->GetOutput()->GetSignedSpacing(); typename TInput::PointType outorigin = m_filter->GetOutput()->GetOrigin(); std::cout << "Output Origin : " << outorigin[0] << " " << outorigin[1] << std::endl; std::cout << "Output Spacing : " << outspacing[0] << " " << outspacing[1] << std::endl; diff --git a/WeightCalculation/WeightOnClouds/include/CloudWeightComputation.h b/Code/WeightCalculation/WeightOnClouds/include/CloudWeightComputation.h similarity index 98% rename from WeightCalculation/WeightOnClouds/include/CloudWeightComputation.h rename to Code/WeightCalculation/WeightOnClouds/include/CloudWeightComputation.h index ef08ddc..5147616 100644 --- a/WeightCalculation/WeightOnClouds/include/CloudWeightComputation.h +++ b/Code/WeightCalculation/WeightOnClouds/include/CloudWeightComputation.h @@ -154,12 +154,12 @@ public: { writer->Update(); typename TInput::Pointer image1 = m_inputReader1->GetOutput(); - typename TInput::SpacingType spacing = image1->GetSpacing(); + typename TInput::SpacingType spacing = image1->GetSignedSpacing(); typename TInput::PointType origin = image1->GetOrigin(); std::cout << "=============CLOUD WEIGHT COMPUTATION====================" << std::endl; std::cout << "Origin : " << origin[0] << " " << origin[1] << std::endl; std::cout << "Spacing : " << spacing[0] << " " << spacing[1] << std::endl; - typename TInput::SpacingType outspacing = m_filter->GetOutput()->GetSpacing(); + typename TInput::SpacingType outspacing = m_filter->GetOutput()->GetSignedSpacing(); std::cout << "Size : " << image1->GetLargestPossibleRegion().GetSize()[0] << " " << image1->GetLargestPossibleRegion().GetSize()[1] << std::endl; diff --git a/WeightCalculation/WeightOnClouds/include/CloudsInterpolation.h b/Code/WeightCalculation/WeightOnClouds/include/CloudsInterpolation.h similarity index 97% rename from WeightCalculation/WeightOnClouds/include/CloudsInterpolation.h rename to Code/WeightCalculation/WeightOnClouds/include/CloudsInterpolation.h index 4c1bf08..e0c6a67 100644 --- a/WeightCalculation/WeightOnClouds/include/CloudsInterpolation.h +++ b/Code/WeightCalculation/WeightOnClouds/include/CloudsInterpolation.h @@ -151,7 +151,7 @@ public: int GetInputImageResolution() { m_inputReader->UpdateOutputInformation(); - return m_inputReader->GetOutput()->GetSpacing()[0]; + return m_inputReader->GetOutput()->GetSignedSpacing()[0]; } void WriteToOutputFile() { @@ -164,7 +164,7 @@ public: try { writer->Update(); - typename TOutput::SpacingType spacing = m_inputReader->GetOutput()->GetSpacing(); + typename TOutput::SpacingType spacing = m_inputReader->GetOutput()->GetSignedSpacing(); typename TOutput::PointType origin = m_inputReader->GetOutput()->GetOrigin(); std::cout << "==============CLOUD INTERPOLATION===================" << std::endl; std::cout << "Origin : " << origin[0] << " " << origin[1] << std::endl; @@ -172,7 +172,7 @@ public: std::cout << "Size : " << m_inputReader->GetOutput()->GetLargestPossibleRegion().GetSize()[0] << " " << m_inputReader->GetOutput()->GetLargestPossibleRegion().GetSize()[1] << std::endl; - typename TOutput::SpacingType outspacing = m_Resampler->GetOutput()->GetSpacing(); + typename TOutput::SpacingType outspacing = m_Resampler->GetOutput()->GetSignedSpacing(); typename TOutput::PointType outorigin = m_Resampler->GetOutput()->GetOrigin(); std::cout << "Output Origin : " << outorigin[0] << " " << outorigin[1] << std::endl; std::cout << "Output Spacing : " << outspacing[0] << " " << outspacing[1] << std::endl; @@ -205,7 +205,7 @@ private: m_inputReader->UpdateOutputInformation(); typename TInput::Pointer inputImage = m_inputReader->GetOutput(); if(m_inputRes < 0) { - m_inputRes = abs(inputImage->GetSpacing()[0]); + m_inputRes = abs(inputImage->GetSignedSpacing()[0]); } diff --git a/WeightCalculation/WeightOnClouds/include/CuttingImageFilter.h b/Code/WeightCalculation/WeightOnClouds/include/CuttingImageFilter.h similarity index 98% rename from WeightCalculation/WeightOnClouds/include/CuttingImageFilter.h rename to Code/WeightCalculation/WeightOnClouds/include/CuttingImageFilter.h index e503bec..a17f808 100644 --- a/WeightCalculation/WeightOnClouds/include/CuttingImageFilter.h +++ b/Code/WeightCalculation/WeightOnClouds/include/CuttingImageFilter.h @@ -98,7 +98,7 @@ public: { writer->Update(); typename TInput2::Pointer image = m_inputImgReader->GetOutput(); - typename TInput2::SpacingType spacing = image->GetSpacing(); + typename TInput2::SpacingType spacing = image->GetSignedSpacing(); typename TInput2::PointType origin = image->GetOrigin(); std::cout << "==============CUT IMAGE===================" << std::endl; std::cout << "Origin : " << origin[0] << " " << origin[1] << std::endl; @@ -106,7 +106,7 @@ public: std::cout << "Size : " << image->GetLargestPossibleRegion().GetSize()[0] << " " << image->GetLargestPossibleRegion().GetSize()[1] << std::endl; - typename TInput2::SpacingType outspacing = m_extractor->GetOutput()->GetSpacing(); + typename TInput2::SpacingType outspacing = m_extractor->GetOutput()->GetSignedSpacing(); typename TInput2::PointType outorigin = m_extractor->GetOutput()->GetOrigin(); std::cout << "Output Origin : " << outorigin[0] << " " << outorigin[1] << std::endl; std::cout << "Output Spacing : " << outspacing[0] << " " << outspacing[1] << std::endl; diff --git a/WeightCalculation/WeightOnClouds/include/GaussianFilter.h b/Code/WeightCalculation/WeightOnClouds/include/GaussianFilter.h similarity index 98% rename from WeightCalculation/WeightOnClouds/include/GaussianFilter.h rename to Code/WeightCalculation/WeightOnClouds/include/GaussianFilter.h index c9ef7bb..cdff0b2 100644 --- a/WeightCalculation/WeightOnClouds/include/GaussianFilter.h +++ b/Code/WeightCalculation/WeightOnClouds/include/GaussianFilter.h @@ -101,7 +101,7 @@ public: { writer->Update(); ImageType::Pointer inputImage = m_inputReader->GetOutput(); - ImageType::SpacingType spacing = inputImage->GetSpacing(); + ImageType::SpacingType spacing = inputImage->GetSignedSpacing(); ImageType::PointType origin = inputImage->GetOrigin(); std::cout << "===============GAUSSIAN==================" << std::endl; std::cout << "Origin : " << origin[0] << " " << origin[1] << std::endl; @@ -109,7 +109,7 @@ public: std::cout << "Size : " << inputImage->GetLargestPossibleRegion().GetSize()[0] << " " << inputImage->GetLargestPossibleRegion().GetSize()[1] << std::endl; - ImageType::SpacingType outspacing = m_gaussianFilter->GetOutput()->GetSpacing(); + ImageType::SpacingType outspacing = m_gaussianFilter->GetOutput()->GetSignedSpacing(); ImageType::PointType outorigin = m_gaussianFilter->GetOutput()->GetOrigin(); std::cout << "Output Origin : " << outorigin[0] << " " << outorigin[1] << std::endl; std::cout << "Output Spacing : " << outspacing[0] << " " << outspacing[1] << std::endl; diff --git a/WeightCalculation/WeightOnClouds/include/PaddingImageHandler.h b/Code/WeightCalculation/WeightOnClouds/include/PaddingImageHandler.h similarity index 98% rename from WeightCalculation/WeightOnClouds/include/PaddingImageHandler.h rename to Code/WeightCalculation/WeightOnClouds/include/PaddingImageHandler.h index 9f40d93..029d078 100644 --- a/WeightCalculation/WeightOnClouds/include/PaddingImageHandler.h +++ b/Code/WeightCalculation/WeightOnClouds/include/PaddingImageHandler.h @@ -80,8 +80,8 @@ public: inputImgReader->UpdateOutputInformation(); m_resampledImgReader->UpdateOutputInformation(); - int inputRes = inputImgReader->GetOutput()->GetSpacing()[0]; - int resampledRes = m_resampledImgReader->GetOutput()->GetSpacing()[0]; + int inputRes = inputImgReader->GetOutput()->GetSignedSpacing()[0]; + int resampledRes = m_resampledImgReader->GetOutput()->GetSignedSpacing()[0]; float scaleXY = ((float)resampledRes)/((float)inputRes); float sizeX = inputImgReader->GetOutput()->GetLargestPossibleRegion().GetSize()[0] / scaleXY; float sizeY = inputImgReader->GetOutput()->GetLargestPossibleRegion().GetSize()[1] / scaleXY; @@ -145,7 +145,7 @@ public: { writer->Update(); typename TInput2::Pointer image = m_resampledImgReader->GetOutput(); - typename TInput2::SpacingType spacing = image->GetSpacing(); + typename TInput2::SpacingType spacing = image->GetSignedSpacing(); typename TInput2::PointType origin = image->GetOrigin(); std::cout << "===============PADDING==================" << std::endl; std::cout << "Origin : " << origin[0] << " " << origin[1] << std::endl; @@ -153,7 +153,7 @@ public: std::cout << "Size : " << image->GetLargestPossibleRegion().GetSize()[0] << " " << image->GetLargestPossibleRegion().GetSize()[1] << std::endl; - typename TInput2::SpacingType outspacing = m_resizer->GetOutput()->GetSpacing(); + typename TInput2::SpacingType outspacing = m_resizer->GetOutput()->GetSignedSpacing(); typename TInput2::PointType outorigin = m_resizer->GetOutput()->GetOrigin(); std::cout << "Output Origin : " << outorigin[0] << " " << outorigin[1] << std::endl; std::cout << "Output Spacing : " << outspacing[0] << " " << outspacing[1] << std::endl; diff --git a/WeightCalculation/WeightOnClouds/include/ROIImageFilter.h b/Code/WeightCalculation/WeightOnClouds/include/ROIImageFilter.h similarity index 100% rename from WeightCalculation/WeightOnClouds/include/ROIImageFilter.h rename to Code/WeightCalculation/WeightOnClouds/include/ROIImageFilter.h diff --git a/WeightCalculation/WeightOnClouds/src/WeightOnClouds.cpp b/Code/WeightCalculation/WeightOnClouds/src/WeightOnClouds.cpp similarity index 99% rename from WeightCalculation/WeightOnClouds/src/WeightOnClouds.cpp rename to Code/WeightCalculation/WeightOnClouds/src/WeightOnClouds.cpp index 7154223..79e2f0b 100644 --- a/WeightCalculation/WeightOnClouds/src/WeightOnClouds.cpp +++ b/Code/WeightCalculation/WeightOnClouds/src/WeightOnClouds.cpp @@ -71,7 +71,6 @@ private: SetName("WeightOnClouds"); SetDescription("Computes the cloud weight value for the given mask cloud and parameters"); - SetDocName("Weight on Clouds"); SetDocLongDescription("Computes the cloud weight value for the given mask cloud and parameters"); SetDocLimitations("None"); diff --git a/WeightCalculation/WeightOnClouds/test/CMakeLists.txt b/Code/WeightCalculation/WeightOnClouds/test/CMakeLists.txt similarity index 100% rename from WeightCalculation/WeightOnClouds/test/CMakeLists.txt rename to Code/WeightCalculation/WeightOnClouds/test/CMakeLists.txt diff --git a/CompositePreprocessing/include/DirectionalCorrectionFilter.h b/CompositePreprocessing/include/DirectionalCorrectionFilter.h deleted file mode 100644 index 69df44b..0000000 --- a/CompositePreprocessing/include/DirectionalCorrectionFilter.h +++ /dev/null @@ -1,240 +0,0 @@ -/* - * Copyright (C) 2015-2016, CS Romania <office@c-s.ro> - * Copyright (C) 2018-2019, Centre National d'Etudes Spatiales (CNES) - * All rights reversed - * - * This file is part of: - * - Sen2agri-Processors (initial work) - * - Weighted Average Synthesis Processor (WASP) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. -* - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ - -#ifndef DirectionalCorrectionFilter_H -#define DirectionalCorrectionFilter_H - -#include "itkBinaryFunctorImageFilter.h" -#include "itkGradientMagnitudeImageFilter.h" -#include "itkThresholdImageFilter.h" -#include "itkRescaleIntensityImageFilter.h" -#include "otbImageListToVectorImageFilter.h" -#include "otbWrapperTypes.h" -#include "DirectionalCorrectionFunctor.h" -#include "libgen.h" -#include "otbMultiToMonoChannelExtractROI.h" - -#include "itkNumericTraits.h" -#include "otbImage.h" -#include "BaseImageTypes.h" - -/** - * @brief The TemporalSynthesis namespace, covering all needed functions to execute this processing chain - */ -namespace ts { - -/** - * @brief Filter to perform the directional correction - */ -template <class TImageType, class TOutputImageType> -class ITK_EXPORT DirectionalCorrectionFilter : public itk::ImageToImageFilter<TImageType, TOutputImageType>, public BaseImageTypes{ -public: - typedef DirectionalCorrectionFilter Self; - typedef itk::ImageToImageFilter<TImageType, TOutputImageType> Superclass; - typedef itk::SmartPointer<Self> Pointer; - typedef itk::SmartPointer<const Self> ConstPointer; - - - typedef typename TImageType::PixelType PixelType; - typedef typename TOutputImageType::PixelType OutputPixelType; - - /*typedef otb::Wrapper::FloatImageType InternalBandImageType; - typedef otb::ImageList<InternalBandImageType> ImageListType;*/ - - typedef otb::ImageListToVectorImageFilter<ImageListType, TImageType> ListConcatenerFilterType; - - typedef otb::MultiToMonoChannelExtractROI<typename TImageType::InternalPixelType, - InternalBandImageType::PixelType> ExtractROIFilterType; - typedef otb::ObjectList<ExtractROIFilterType> ExtractROIFilterListType; - - - typedef DirectionalCorrectionFunctor<PixelType, OutputPixelType> DirectionalCorrectionFunctorType; - typedef itk::UnaryFunctorImageFilter<TImageType, TOutputImageType, - DirectionalCorrectionFunctorType> FunctorFilterType; - - /** Method for creation through object factory */ - itkNewMacro(Self); - - /** Run-time type information */ - itkTypeMacro(DirectionalCorrectionFilter, itk::ImageToImageFilter); - - /** - * @brief Set Input raster - * @param inputImg The original raster from S2 - */ - void SetInputImage(TImageType inputImg) - { - this->SetInput(0, inputImg); - } - - /** - * @brief Set Cloud image - * @param inputImg The cloud image - */ - void SetCloudImage(TImageType inputImg) - { - this->SetInput(1, inputImg); - } - - /** - * @brief Set Water image - * @param inputImg The water image - */ - void SetWaterImage(TImageType inputImg) - { - this->SetInput(2, inputImg); - } - - /** - * @brief Set Snow image - * @param inputImg The snow image - */ - void SetSnowImage(TImageType inputImg) - { - this->SetInput(3, inputImg); - } - - /** - * @brief Set NDVI image - * @param inputImg The ndvi image - */ - void SetNdviImage(TImageType inputImg) - { - this->SetInput(4, inputImg); - } - - /** - * @brief Set Angles image - * @param inputImg the angles image - */ - void SetAnglesImage(TImageType inputImg) - { - this->SetInput(5, inputImg); - } - - /** - * @brief Set scattering coefficients - * @param scatCoeffs The vector containing all scattering coeffs for the current resolution - */ - void SetScatteringCoefficients(std::vector<ScaterringFunctionCoefficients> &scatCoeffs) { - m_scatteringCoeffs = scatCoeffs; - } - - /** - * @brief Set Reflectance quantification value - * @param fQuantifVal - */ - void SetReflQuantifValue(float fQuantifVal) { - m_fQuantifVal = fQuantifVal; - } - - /** - * @brief Update the output info of the generated image, setting the number of bands - */ - virtual void UpdateOutputInformation() ITK_OVERRIDE - { - Superclass::UpdateOutputInformation(); - this->GetOutput()->SetNumberOfComponentsPerPixel(m_scatteringCoeffs.size()); - } - - /** - * @brief Constructor - */ - DirectionalCorrectionFilter() - { - m_fQuantifVal = 0; - m_ImageList = ImageListType::New(); - m_Concat = ListConcatenerFilterType::New(); - m_ExtractorList = ExtractROIFilterListType::New(); - - this->SetNumberOfRequiredInputs(6); - m_directionalCorrectionFunctor = FunctorFilterType::New(); - } - - /** - * @brief Creates connections for the output image - */ - void GenerateData() ITK_OVERRIDE - { - extractBandsFromImage(this->GetInput(0)); - extractBandsFromImage(this->GetInput(1)); - extractBandsFromImage(this->GetInput(2)); - extractBandsFromImage(this->GetInput(3)); - extractBandsFromImage(this->GetInput(4)); - extractBandsFromImage(this->GetInput(5)); - - m_Concat->SetInput(m_ImageList); - - - DirectionalCorrectionFunctorType functor; - functor.Initialize(m_scatteringCoeffs, m_fQuantifVal); - m_directionalCorrectionFunctor->SetFunctor(functor); - - m_directionalCorrectionFunctor->SetInput(m_Concat->GetOutput()); - m_directionalCorrectionFunctor->UpdateOutputInformation(); - m_directionalCorrectionFunctor->GetOutput()->SetNumberOfComponentsPerPixel(m_scatteringCoeffs.size()); - m_directionalCorrectionFunctor->GraftOutput(this->GetOutput()); - m_directionalCorrectionFunctor->Update(); - this->GraftOutput(m_directionalCorrectionFunctor->GetOutput()); - } - -private: - - /** - * @brief Extract each band from the input vector image - * @param imageType The input image containing all needed images - * @return The number of bands extracted - */ - int extractBandsFromImage(const TImageType *imageType) { - int nbBands = imageType->GetNumberOfComponentsPerPixel(); - for(int j=0; j < nbBands; j++) - { - typename ExtractROIFilterType::Pointer extractor = ExtractROIFilterType::New(); - extractor->SetInput( imageType ); - extractor->SetChannel( j+1 ); - extractor->UpdateOutputInformation(); - m_ExtractorList->PushBack( extractor ); - m_ImageList->PushBack( extractor->GetOutput() ); - } - return nbBands; - } - - - DirectionalCorrectionFilter(Self &); // intentionally not implemented - void operator =(const Self&); // intentionally not implemented - - typename FunctorFilterType::Pointer m_directionalCorrectionFunctor; - std::vector<ScaterringFunctionCoefficients> m_scatteringCoeffs; - float m_fQuantifVal; - - FloatImageListType::Pointer m_ImageList; - typename ListConcatenerFilterType::Pointer m_Concat; - typename ExtractROIFilterListType::Pointer m_ExtractorList; - -}; -} //namespace ts - -#endif - -- GitLab