Skip to content
Snippets Groups Projects
Commit 0db0ead7 authored by Julien Michel's avatar Julien Michel
Browse files

Ajout du filtre import geo information.

parent abc1174d
No related branches found
No related tags found
No related merge requests found
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef _otbImportGeoInformationImageFilter_h
#define _otbImportGeoInformationImageFilter_h
#include "itkInPlaceImageFilter.h"
namespace otb
{
/** \class ImportGeoInformationImageFilter
* \brief This filter is a helper class to import metadata
* from an existing image into a non-georeferenced image.
*
* It derives from itk::InPlaceImageFilter since it overwrites
* its ouput if possible. This class has been written as a workaround
* for the bug http://public.kitware.com/Bug/bug.php?op=show&bugid=4625&pos=0.
* There should be no needs for this filter in a standard pipeline.
*
* \sa InPlaceImageFilter
* \sa ImageBase
*/
template <class TImage, class TSourceImage>
class ITK_EXPORT ImportGeoInformationImageFilter
: public itk::InPlaceImageFilter<TImage,TImage>
{
public:
/** Standard typedefs */
typedef ImportGeoInformationImageFilter Self;
typedef itk::InPlaceImageFilter<TImage,TImage> Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Type macro */
itkNewMacro(Self);
/** Creation through object factory macro */
itkTypeMacro(ImportGeoInformationImageFilter, InPlaceImageFilter);
/** Template parameters typedefs */
typedef TImage ImageType;
typedef typename ImageType::Pointer ImagePointerType;
typedef typename ImageType::ConstPointer ImageConstPointerType;
typedef TSourceImage SourceImageType;
typedef SourceImageType SourceImagePointerType;
/**
* Set the source for geo information.
* \param source The source image.
*/
void SetSource(const TSourceImage * source);
/**
* Get the source for geo information.
* \return The source image.
*/
const TSourceImage * GetSource(void);
protected:
/** Constructor */
ImportGeoInformationImageFilter();
/** Destructor */
virtual ~ImportGeoInformationImageFilter() {};
/**PrintSelf method */
virtual void PrintSelf(std::ostream& os, itk::Indent indent) const;
/** GenerateData */
virtual void GenerateData(void);
private:
ImportGeoInformationImageFilter(const Self&); //purposely not implemented
void operator=(const Self&); //purposely not implemented
};
}// End namespace otb
#ifndef OTB_MANUAL_INSTANTIATION
#include "otbImportGeoInformationImageFilter.txx"
#endif
#endif
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef _otbImportGeoInformationImageFilter_txx
#define _otbImportGeoInformationImageFilter_txx
#include "itkDataObject.h"
#include "otbImportGeoInformationImageFilter.h"
namespace otb
{
/**
* Constructor
*/
template <class TImage, class TSourceImage>
ImportGeoInformationImageFilter<TImage,TSourceImage>
::ImportGeoInformationImageFilter()
{
this->SetNumberOfRequiredInputs(2);
this->SetNthInput(1,SourceImageType::New().GetPointer());
}
template <class TImage, class TSourceImage>
void
ImportGeoInformationImageFilter<TImage,TSourceImage>
::SetSource(const TSourceImage * source)
{
this->SetNthInput(1,const_cast<TSourceImage *>(source));
}
template <class TImage, class TSourceImage>
const TSourceImage *
ImportGeoInformationImageFilter<TImage,TSourceImage>
::GetSource()
{
return static_cast<const TSourceImage *>(this->GetInput(1));
}
/**
* Main computation method.
*/
template <class TImage, class TSourceImage>
void
ImportGeoInformationImageFilter<TImage,TSourceImage>
::GenerateData(void)
{
// Since this filter is not multi-threaded, we have to call this method by ourselves
this->AllocateOutputs();
// Get output and source pointer
ImagePointerType outputPtr = this->GetOutput();
const SourceImageType * sourcePtr = this->GetSource();
// Import metdata
outputPtr->CopyInformation(sourcePtr);
}
/**
* PrintSelf Method
*/
template <class TImage, class TSourceImage>
void
ImportGeoInformationImageFilter<TImage,TSourceImage>
::PrintSelf(std::ostream& os, itk::Indent indent) const
{
Superclass::PrintSelf(os, indent);
}
} // End namespace otb
#endif
......@@ -183,6 +183,21 @@ ADD_TEST(bfTvStreamingShrinkImageFilterQBMUL ${BASICFILTERS_TESTS}
50
)
# ------- otb::ImportGeoInformationImageFilter ----------------------------
ADD_TEST(bfTuImportGeoInformationImageFilterNew ${BASICFILTERS_TESTS}
otbImportGeoInformationImageFilterNew)
ADD_TEST(bfTvImportGeoInformationImageFilter ${BASICFILTERS_TESTS}
--compare-metadata ${TOL}
${INPUTDATA}/HFAGeoreferenced.img
${TEMP}/bfTvImportGeoInformationOutput.img
otbImportGeoInformationImageFilter
${INPUTDATA}/HFAGeoreferenced.img
${TEMP}/bfTvImportGeoInformationOutput.img
)
# A enrichir
SET(BasicFilters_SRCS
otbLeeFilter.cxx
......@@ -206,6 +221,8 @@ otbStreamingShrinkImageFilterNew.cxx
otbStreamingShrinkImageFilter.cxx
otbSpatialObjectToImageDrawingFilterNew.cxx
otbSpatialObjectToImageDrawingFilter.cxx
otbImportGeoInformationImageFilterNew.cxx
otbImportGeoInformationImageFilter.cxx
)
......
......@@ -48,4 +48,6 @@ REGISTER_TEST(otbStreamingShrinkImageFilterNew);
REGISTER_TEST(otbStreamingShrinkImageFilter);
REGISTER_TEST(otbSpatialObjectToImageDrawingFilterNew);
REGISTER_TEST(otbSpatialObjectToImageDrawingFilter);
REGISTER_TEST(otbImportGeoInformationImageFilterNew);
REGISTER_TEST(otbImportGeoInformationImageFilter);
}
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include "itkExceptionObject.h"
#include "otbImportGeoInformationImageFilter.h"
#include "otbImage.h"
#include "otbImageFileReader.h"
#include "otbImageFileWriter.h"
int otbImportGeoInformationImageFilter(int argc, char * argv[])
{
try
{
const char * infname = argv[1];
const char * outfname = argv[2];
const unsigned int Dimension = 2;
typedef unsigned int PixelType;
typedef otb::Image<PixelType,Dimension> ImageType;
typedef otb::ImageFileReader<ImageType> ReaderType;
typedef otb::ImageFileWriter<ImageType> WriterType;
typedef otb::ImportGeoInformationImageFilter<ImageType,ImageType> ImportGeoInformationImageFilterType;
// Instantiating objects
ReaderType::Pointer reader = ReaderType::New();
WriterType::Pointer writer = WriterType::New();
ImportGeoInformationImageFilterType::Pointer import = ImportGeoInformationImageFilterType::New();
ImageType::IndexType index;
index.Fill(25);
reader->SetFileName(infname);
reader->GenerateOutputInformation();
reader->Update();
std::cout<<"import input: "<<reader->GetOutput()<<std::endl;
std::cout<<"import input: "<<reader->GetOutput()->GetPixel(index)<<std::endl;
ImageType::Pointer black = ImageType::New();
black->SetRegions(reader->GetOutput()->GetLargestPossibleRegion());
black->Allocate();
black->FillBuffer(0);
std::cout<<"black: " <<black->GetLargestPossibleRegion()<<std::endl;
import->SetInput(reader->GetOutput());
import->SetSource(reader->GetOutput());
import->Update();
std::cout<<"import output: "<<import->GetOutput()<<std::endl;
writer->SetFileName(outfname);
writer->SetInput(import->GetOutput());
writer->Update();
}
catch( itk::ExceptionObject & err )
{
std::cout << "Exception itk::ExceptionObject thrown !" << std::endl;
std::cout << err << std::endl;
return EXIT_FAILURE;
}
catch( ... )
{
std::cout << "Unknown exception thrown !" << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include "itkExceptionObject.h"
#include "otbImportGeoInformationImageFilter.h"
#include "otbImage.h"
int otbImportGeoInformationImageFilterNew(int argc, char * argv[])
{
try
{
const unsigned int Dimension = 2;
typedef unsigned char PixelType;
typedef otb::Image<PixelType,Dimension> ImageType;
typedef otb::ImportGeoInformationImageFilter<ImageType,ImageType> ImportGeoInformationImageFilterType;
// Instantiating object
ImportGeoInformationImageFilterType::Pointer object = ImportGeoInformationImageFilterType::New();
}
catch( itk::ExceptionObject & err )
{
std::cout << "Exception itk::ExceptionObject thrown !" << std::endl;
std::cout << err << std::endl;
return EXIT_FAILURE;
}
catch( ... )
{
std::cout << "Unknown exception thrown !" << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment