<commit_before>/*=========================================================================

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 "otbMorphologicalPyramidAnalyseFilter.h"
#include "otbOpeningClosingMorphologicalFilter.h"
#include "itkBinaryBallStructuringElement.h"
#include "otbImageFileReader.h"
#include "otbImageFileWriter.h"
#include "otbImage.h"

int otbMorphologicalPyramidAnalyseFilter(int argc, char * argv[])
{
  try
    {
      const char * inputFilename = argv[1];
      const char * outputFilenamePrefix = argv[2];
      const char * outputFilenameSuffix = argv[3];
      const unsigned int numberOfIterations = atoi(argv[4]);
      const float subSampleScale = atof(argv[5]);

      const unsigned int Dimension = 2;
      typedef unsigned char InputPixelType;
      typedef unsigned char OutputPixelType;

      typedef otb::Image<InputPixelType,Dimension> InputImageType;
      typedef otb::Image<OutputPixelType,Dimension> OutputImageType;

      typedef otb::ImageFileReader<InputImageType> ReaderType;
      typedef otb::ImageFileWriter<OutputImageType> WriterType;

      typedef itk::BinaryBallStructuringElement<InputPixelType,Dimension> StructuringElementType;
      typedef otb::OpeningClosingMorphologicalFilter<InputImageType,InputImageType,StructuringElementType>
	OpeningClosingFilterType;
      typedef otb::MorphologicalPyramidAnalyseFilter<InputImageType,OutputImageType,OpeningClosingFilterType>
	PyramidFilterType;
      typedef PyramidFilterType::OutputImageListType::Iterator ImageListIterator;
      
      // Reading input image
      ReaderType::Pointer reader = ReaderType::New();
      reader->SetFileName(inputFilename);

      // Instantiation
      PyramidFilterType::Pointer pyramid = PyramidFilterType::New();
      pyramid->SetNumberOfIterations(numberOfIterations);
      pyramid->SetSubSampleScale(subSampleScale);
      pyramid->SetInput(reader->GetOutput());
      pyramid->Update();


      // Retrieving iterators on the results images
      ImageListIterator itAnalyse = pyramid->GetOutput()->Begin();
      ImageListIterator itSupFiltre = pyramid->GetSupFiltre()->Begin();
      ImageListIterator itInfFiltre = pyramid->GetInfFiltre()->Begin();
      ImageListIterator itInfDeci = pyramid->GetSupDeci()->Begin();
      ImageListIterator itSupDeci =  pyramid->GetInfDeci()->Begin();

      WriterType::Pointer writer =  WriterType::New();

      int i=1;
      std::stringstream oss;
      // Writing the results images
      std::cout<<(itAnalyse!=(pyramid->GetOutput()->End()))<<std::endl;
      while((itAnalyse!=pyramid->GetOutput()->End())
	    &&(itSupFiltre!=pyramid->GetSupFiltre()->End())
	    &&(itInfFiltre!=pyramid->GetInfFiltre()->End())
	    &&(itInfDeci!=pyramid->GetInfDeci()->End())
	    &&(itSupDeci!=pyramid->GetSupDeci()->End())
	    )
	{
	  oss<<outputFilenamePrefix<<"_an_"<<i<<"."<<outputFilenameSuffix;
	  writer->SetInput(itAnalyse.Get());
	  writer->SetFileName(oss.str().c_str());	  
	  writer->Update();
	  oss.str("");
	  oss<<outputFilenamePrefix<<"_sf_"<<i<<"."<<outputFilenameSuffix;
	  writer->SetInput(itSupFiltre.Get());
	  writer->SetFileName(oss.str().c_str());
	  writer->Update();
	  oss.str("");
	  oss<<outputFilenamePrefix<<"_if_"<<i<<"."<<outputFilenameSuffix;
	  writer->SetInput(itInfFiltre.Get());
	  writer->SetFileName(oss.str().c_str());
	  writer->Update();
	  oss.str("");
	  oss<<outputFilenamePrefix<<"_id_"<<i<<"."<<outputFilenameSuffix;
	  writer->SetInput(itInfDeci.Get());<commit_msg>Remplacement de std::stringstream par un itkOStringStream<commit_after>/*=========================================================================

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 "otbMorphologicalPyramidAnalyseFilter.h"
#include "otbOpeningClosingMorphologicalFilter.h"
#include "itkBinaryBallStructuringElement.h"
#include "otbImageFileReader.h"
#include "otbImageFileWriter.h"
#include "otbImage.h"

#include "itkMacro.h"

int otbMorphologicalPyramidAnalyseFilter(int argc, char * argv[])
{
  try
    {
      const char * inputFilename = argv[1];
      const char * outputFilenamePrefix = argv[2];
      const char * outputFilenameSuffix = argv[3];
      const unsigned int numberOfIterations = atoi(argv[4]);
      const float subSampleScale = atof(argv[5]);

      const unsigned int Dimension = 2;
      typedef unsigned char InputPixelType;
      typedef unsigned char OutputPixelType;

      typedef otb::Image<InputPixelType,Dimension> InputImageType;
      typedef otb::Image<OutputPixelType,Dimension> OutputImageType;

      typedef otb::ImageFileReader<InputImageType> ReaderType;
      typedef otb::ImageFileWriter<OutputImageType> WriterType;

      typedef itk::BinaryBallStructuringElement<InputPixelType,Dimension> StructuringElementType;
      typedef otb::OpeningClosingMorphologicalFilter<InputImageType,InputImageType,StructuringElementType>
	OpeningClosingFilterType;
      typedef otb::MorphologicalPyramidAnalyseFilter<InputImageType,OutputImageType,OpeningClosingFilterType>
	PyramidFilterType;
      typedef PyramidFilterType::OutputImageListType::Iterator ImageListIterator;
      
      // Reading input image
      ReaderType::Pointer reader = ReaderType::New();
      reader->SetFileName(inputFilename);

      // Instantiation
      PyramidFilterType::Pointer pyramid = PyramidFilterType::New();
      pyramid->SetNumberOfIterations(numberOfIterations);
      pyramid->SetSubSampleScale(subSampleScale);
      pyramid->SetInput(reader->GetOutput());
      pyramid->Update();


      // Retrieving iterators on the results images
      ImageListIterator itAnalyse = pyramid->GetOutput()->Begin();
      ImageListIterator itSupFiltre = pyramid->GetSupFiltre()->Begin();
      ImageListIterator itInfFiltre = pyramid->GetInfFiltre()->Begin();
      ImageListIterator itInfDeci = pyramid->GetSupDeci()->Begin();
      ImageListIterator itSupDeci =  pyramid->GetInfDeci()->Begin();

      WriterType::Pointer writer =  WriterType::New();

      int i=1;
//      std::stringstream oss;
      itk::OStringStream oss;
      // Writing the results images
      std::cout<<(itAnalyse!=(pyramid->GetOutput()->End()))<<std::endl;
      while((itAnalyse!=pyramid->GetOutput()->End())
	    &&(itSupFiltre!=pyramid->GetSupFiltre()->End())
	    &&(itInfFiltre!=pyramid->GetInfFiltre()->End())
	    &&(itInfDeci!=pyramid->GetInfDeci()->End())
	    &&(itSupDeci!=pyramid->GetSupDeci()->End())
	    )
	{
	  oss<<outputFilenamePrefix<<"_an_"<<i<<"."<<outputFilenameSuffix;
	  writer->SetInput(itAnalyse.Get());
	  writer->SetFileName(oss.str().c_str());	  
	  writer->Update();
	  oss.str("");
	  oss<<outputFilenamePrefix<<"_sf_"<<i<<"."<<outputFilenameSuffix;
	  writer->SetInput(itSupFiltre.Get());
	  writer->SetFileName(oss.str().c_str());
	  writer->Update();
	  oss.str("");
	  oss<<outputFilenamePrefix<<"_if_"<<i<<"."<<outputFilenameSuffix;
	  writer->SetInput(itInfFiltre.Get());
	  writer->SetFileName(oss.str().c_str());
	  writer->Update();
	  oss.str("");
	  oss<<outputFilenamePrefix<<"_id_"<<i<<"."<<outputFilenameSuffix;
	  writer->SetInput(itInfDeci.Get());
{'fraction_non_alphanumeric': 0.16564875981553034, 'fraction_numerical': 0.0017449831733765424, 'mean_word_length': 5.0604229607250755, 'pattern_counts': {'":': 0, '<': 105, '<?xml version=': 0, '>': 93, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6201931', 'n_tokens_mistral': 2485, 'n_tokens_neox': 2330, 'n_words': 406}