Commit ec03fe30 authored by Cédric Traizet's avatar Cédric Traizet
Browse files

REFAC: remove otb::ChangeInformationImageFilter as it has no use anymore (note...

REFAC: remove otb::ChangeInformationImageFilter as it has no use anymore (note that the itk base class is still used in OTB)
parent 1be32986
Pipeline #8929 passed with stages
in 117 minutes and 37 seconds
/*
* Copyright (C) 2005-2020 Centre National d'Etudes Spatiales (CNES)
*
* This file is part of Orfeo Toolbox
*
* https://www.orfeo-toolbox.org/
*
* 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.
*/
#ifndef otbChangeInformationImageFilter_h
#define otbChangeInformationImageFilter_h
#include "itkChangeInformationImageFilter.h"
#include "otbMetaDataKey.h"
namespace otb
{
/**
* \class ChangeInformationImageFilter
* \brief Filter to modify image metadata
*
* The base class is itk::ChangeInformationImageFilter that allows
* modifying origin, spacing, direction and buffered region. This deriving
* filter adds the support of MetaDataDictionary.
*
* \ingroup OTBImageManipulation
*/
template <typename TInputImage>
class ChangeInformationImageFilter : public itk::ChangeInformationImageFilter<TInputImage>
{
public:
/** Standard class typedefs. */
typedef ChangeInformationImageFilter Self;
typedef itk::ChangeInformationImageFilter<TInputImage> Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Method for creation through the object factory. */
itkNewMacro(Self);
/** Creation through object factory macro */
itkTypeMacro(ChangeInformationImageFilter, itk::ChangeInformationImageFilter);
/** Set key names to change */
void SetChangeMetaData(const char* keyname, bool flag);
/** Ask if a metadata will be changed */
bool GetChangeMetaData(const char* keyname);
/** Set output values for metadata, passing a NULL value will remove the
* metadata from output. If not set for a key name in the change list,
* the metadata will also be set.
*/
template <typename T>
void SetOutputMetaData(const char* keyname, const T* value);
protected:
ChangeInformationImageFilter()
{
}
~ChangeInformationImageFilter() override
{
}
/** Apply changes to the output image metadata. */
void GenerateOutputInformation() override;
private:
ChangeInformationImageFilter(const Self&) = delete;
void operator=(const Self&) = delete;
/** List of metadata keys to change */
std::set<std::string> m_ChangedKeys;
};
} // End of namespace OTB
#ifndef OTB_MANUAL_INSTANTIATION
#include "otbChangeInformationImageFilter.hxx"
#endif
#endif
/*
* Copyright (C) 2005-2020 Centre National d'Etudes Spatiales (CNES)
*
* This file is part of Orfeo Toolbox
*
* https://www.orfeo-toolbox.org/
*
* 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.
*/
#ifndef otbChangeInformationImageFilter_hxx
#define otbChangeInformationImageFilter_hxx
#include "otbChangeInformationImageFilter.h"
#include "itkMetaDataObject.h"
namespace otb
{
template <typename TInputImage>
void ChangeInformationImageFilter<TInputImage>::SetChangeMetaData(const char* keyname, bool flag)
{
std::string key(keyname);
if (!key.empty())
{
if (flag)
{
m_ChangedKeys.insert(key);
}
else
{
std::set<std::string>::iterator pos = m_ChangedKeys.find(key);
if (pos != m_ChangedKeys.end())
{
m_ChangedKeys.erase(pos);
}
}
}
}
template <typename TInputImage>
bool ChangeInformationImageFilter<TInputImage>::GetChangeMetaData(const char* keyname)
{
std::string key(keyname);
if (!key.empty())
{
if (m_ChangedKeys.find(key) != m_ChangedKeys.end())
{
return true;
}
}
return false;
}
template <typename TInputImage>
template <typename T>
void ChangeInformationImageFilter<TInputImage>::SetOutputMetaData(const char* keyname, const T* value)
{
std::string key(keyname);
if (!key.empty())
{
// enable this key for metadata change
m_ChangedKeys.insert(key);
itk::MetaDataDictionary& dict = this->GetMetaDataDictionary();
if (value == nullptr)
{
// Remove meta-data from dictionary
dict.Erase(key);
}
else
{
// Set metadata in dictionary
const T& valueRef = (*value);
itk::EncapsulateMetaData<T>(dict, key, valueRef);
}
}
}
template <typename TInputImage>
void ChangeInformationImageFilter<TInputImage>::GenerateOutputInformation()
{
Superclass::GenerateOutputInformation();
// Process the metadatas to be changed
itk::MetaDataDictionary& dict = this->GetMetaDataDictionary();
itk::MetaDataDictionary& outputDict = this->GetOutput()->GetMetaDataDictionary();
std::set<std::string>::iterator it = m_ChangedKeys.begin();
for (; it != m_ChangedKeys.end(); ++it)
{
if (dict.HasKey(*it))
{
// Replace metadata in output dictionary
outputDict[*it] = dict[*it];
}
else
{
// Remove metadata from output dictionary
outputDict.Erase(*it);
}
}
}
} // End of namespace OTB
#endif
......@@ -67,7 +67,6 @@ otbOneRIBandImageToOneComplexBandImage.cxx
otbTwoNRIBandsImageToNComplexBandsImage.cxx
otbChangeNoDataValueFilter.cxx
otbImageToNoDataMaskFilter.cxx
otbChangeInformationImageFilter.cxx
otbGridResampleImageFilter.cxx
otbMaskedIteratorDecorator.cxx
)
......@@ -589,11 +588,6 @@ otb_add_test(NAME filteringImageManipulationChangeNoDataValueFilter COMMAND otbI
otb_add_test(NAME filteringImageManipulationImageToNoDataMaskFilter COMMAND otbImageManipulationTestDriver
otbImageToNoDataMaskFilter)
otb_add_test(NAME bfTvChangeInformationImageFilter COMMAND otbImageManipulationTestDriver
otbChangeInformationImageFilter
${INPUTDATA}/WV2_PAN_ROI_1000_100.tif
)
otb_add_test(NAME otbGridResampleImageFilter
COMMAND otbImageManipulationTestDriver otbGridResampleImageFilter)
......
/*
* Copyright (C) 2005-2020 Centre National d'Etudes Spatiales (CNES)
*
* This file is part of Orfeo Toolbox
*
* https://www.orfeo-toolbox.org/
*
* 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.
*/
#include "otbChangeInformationImageFilter.h"
#include "otbImageFileReader.h"
#include "otbImage.h"
int otbChangeInformationImageFilter(int itkNotUsed(argc), char* argv[])
{
const char* inputFilename(argv[1]);
typedef otb::Image<float, 2> ImageType;
typedef otb::ChangeInformationImageFilter<ImageType> FilterType;
typedef otb::ImageFileReader<ImageType> ReaderType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(inputFilename);
FilterType::Pointer filter = FilterType::New();
filter->SetInput(reader->GetOutput());
// try to set a different ProjRef
std::string newProj("Fake ProjRef");
filter->SetOutputMetaData<std::string>(otb::MetaDataKey::ProjectionRefKey, &newProj);
// erase that choice
filter->SetOutputMetaData<std::string>(otb::MetaDataKey::ProjectionRefKey, nullptr);
// add a no data to the image
std::vector<bool> flags;
flags.push_back(true);
std::vector<double> nodata;
nodata.push_back(0.0);
filter->SetOutputMetaData<std::vector<bool>>(otb::MetaDataKey::NoDataValueAvailable, &flags);
filter->SetOutputMetaData<std::vector<double>>(otb::MetaDataKey::NoDataValue, &nodata);
filter->UpdateOutputInformation();
ImageType::Pointer outImage = filter->GetOutput();
// TODO: RemoveOssim. ChangeInformationImageFilter should change the ImageMetadata object stored in
// the image instead of modifying the itk metadata dictionary. GetProjectionRef() look for the
// projection in ImageMetadata now, so we can't use this method in the test. The temporary solution
// is to look in the itk dictionary instead (this was the old behavior of GetProjectionRef). But
// when ChangeInformationImageFilter will be refactored, GetProjectionRef should be used again..
//if (!outImage->GetProjectionRef().empty())
if (outImage->GetMetaDataDictionary().HasKey(otb::MetaDataKey::ProjectionRefKey))
{
std::cout << "Projection is supposed to be removed but is still present !" << std::endl;
return EXIT_FAILURE;
}
itk::MetaDataDictionary& dict = outImage->GetMetaDataDictionary();
if (!dict.HasKey(otb::MetaDataKey::NoDataValueAvailable) || !dict.HasKey(otb::MetaDataKey::NoDataValue))
{
std::cout << "Missing no data metadata !" << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
......@@ -68,7 +68,6 @@ void RegisterTests()
REGISTER_TEST(otbTwoNRIBandsImageToNComplexBandsImage);
REGISTER_TEST(otbChangeNoDataValueFilter);
REGISTER_TEST(otbImageToNoDataMaskFilter);
REGISTER_TEST(otbChangeInformationImageFilter);
REGISTER_TEST(otbGridResampleImageFilter);
REGISTER_TEST(otbMaskedIteratorDecoratorNominal);
REGISTER_TEST(otbMaskedIteratorDecoratorDegenerate);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment