Commit cb168a3c authored by Victor Poughon's avatar Victor Poughon

Merge branch '513-SetFileName' into 'develop'

Remove more c_str with SetFileName string overload

See merge request !189
parents 1c6b1407 c594dfcb
......@@ -122,7 +122,7 @@ int main(int argc, char * argv[])
writer->SetInput(Izz);
outputFileName = outputPrefix + "-Izz.hdr";
writer->SetFileName(outputFileName.c_str());
writer->SetFileName(outputFileName);
writer->Update();
gc->SetDirection(1); // gc now works along Y
......@@ -135,7 +135,7 @@ int main(int argc, char * argv[])
writer->SetInput(Iyy);
outputFileName = outputPrefix + "-Iyy.hdr";
writer->SetFileName(outputFileName.c_str());
writer->SetFileName(outputFileName);
writer->Update();
gc->SetDirection(0); // gc now works along X
......@@ -148,7 +148,7 @@ int main(int argc, char * argv[])
writer->SetInput(Ixx);
outputFileName = outputPrefix + "-Ixx.hdr";
writer->SetFileName(outputFileName.c_str());
writer->SetFileName(outputFileName);
writer->Update();
ga->SetDirection(0);
......@@ -166,7 +166,7 @@ int main(int argc, char * argv[])
writer->SetInput(Iyz);
outputFileName = outputPrefix + "-Iyz.hdr";
writer->SetFileName(outputFileName.c_str());
writer->SetFileName(outputFileName);
writer->Update();
ga->SetDirection(1);
......@@ -184,7 +184,7 @@ int main(int argc, char * argv[])
writer->SetInput(Ixz);
outputFileName = outputPrefix + "-Ixz.hdr";
writer->SetFileName(outputFileName.c_str());
writer->SetFileName(outputFileName);
writer->Update();
ga->SetDirection(2);
......@@ -202,7 +202,7 @@ int main(int argc, char * argv[])
writer->SetInput(Ixy);
outputFileName = outputPrefix + "-Ixy.hdr";
writer->SetFileName(outputFileName.c_str());
writer->SetFileName(outputFileName);
writer->Update();
// Software Guide : EndCodeSnippet
......
......@@ -101,7 +101,7 @@ int main(int itkNotUsed(argc), char * argv[])
// Software Guide : BeginCodeSnippet
otb::GDALImageIO::Pointer readerGDAL = otb::GDALImageIO::New();
readerGDAL->SetFileName(inputFilename.c_str());
readerGDAL->SetFileName(inputFilename);
std::vector<std::string> vectSubdatasetNames;
std::vector<std::string> vectorSubdatasetDescriptions;
......@@ -146,7 +146,7 @@ int main(int itkNotUsed(argc), char * argv[])
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
writer->SetFileName(outputFilename.c_str());
writer->SetFileName(outputFilename);
writer->SetInput(reader->GetOutput());
writer->Update();
......
......@@ -209,7 +209,7 @@ int main(int itkNotUsed(argc), char * argv[])
oss << outputFilenamePrefix << index << "." << outputFilenameSuffix;
writer = WriterType::New();
writer->SetInput(it.Get());
writer->SetFileName(oss.str().c_str());
writer->SetFileName(oss.str());
writer->Update();
std::cout << oss.str() << " file written." << std::endl;
oss.str("");
......
......@@ -215,8 +215,8 @@ int main(int argc, char * argv[])
// Software Guide : BeginLatex
// Software Guide : BeginCodeSnippet
reader->SetFileName(parseResult->GetInputImage().c_str());
writer->SetFileName(parseResult->GetOutputImage().c_str());
reader->SetFileName(parseResult->GetInputImage());
writer->SetFileName(parseResult->GetOutputImage());
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
......
......@@ -71,8 +71,10 @@ public:
std::unordered_map< std::string , std::string > gdalOptions;
};
/** Set extended filename */
void SetExtendedFileName(const char * extFname) override;
/** \deprecated const char* overload of SetExtendedFileName is deprecated, use std::string instead */
void SetExtendedFileName(const char* extFname) override;
void SetExtendedFileName(const std::string& extFname) override;
/** Get the GDAL option for type operation */
GDALOptionType GetGDALOptions( const std::string & type ) const ;
......
......@@ -48,10 +48,21 @@ GetGDALLayerOptionsHelper( const GDALOptionType & options )
return res;
}
void
OGRExtendedFilenameToOptions::
SetExtendedFileName(const char* extFname)
{
if (extFname == nullptr)
{
itkGenericExceptionMacro( << "Filename is NULL" );
}
this->SetExtendedFileName(std::string(extFname));
}
void
OGRExtendedFilenameToOptions::
SetExtendedFileName(const char *extFname)
SetExtendedFileName(const std::string& extFname)
{
Superclass::SetExtendedFileName(extFname);
m_HasFileName = true;
......
......@@ -215,7 +215,7 @@ TrainVectorBase::GetStatistics(unsigned int nbFeatures)
{
StatisticsReader::Pointer statisticsReader = StatisticsReader::New();
std::string XMLfile = GetParameterString( "io.stats" );
statisticsReader->SetFileName( XMLfile.c_str() );
statisticsReader->SetFileName( XMLfile );
measurement.meanMeasurementVector = statisticsReader->GetStatisticVectorByName( "mean" );
measurement.stddevMeasurementVector = statisticsReader->GetStatisticVectorByName( "stddev" );
}
......
......@@ -55,7 +55,11 @@ public:
typedef std::map< std::string, std::string > OptionMapType;
/** \deprecated const char* overload of SetExtendedFileName is deprecated, use std::string instead */
virtual void SetExtendedFileName(const char * extFname);
virtual void SetExtendedFileName(const std::string& extFname);
const OptionMapType & GetOptionMap(void) const;
itkGetStringMacro(ExtendedFileName);
......
......@@ -42,6 +42,14 @@ ExtendedFilenameHelper
{
itkGenericExceptionMacro( << "Filename is NULL" );
}
this->SetExtendedFileName(std::string(extFname));
}
void
ExtendedFilenameHelper
::SetExtendedFileName(const std::string& extFname)
{
this->m_ExtendedFileName = extFname;
this->m_OptionMap.clear();
std::vector<std::string> tmp1;
......
......@@ -117,7 +117,7 @@ int otbVectorImageToImageListFilterIterator(int itkNotUsed(argc), char * argv[])
writer->SetInput(itOutput.Get());
writer->SetFileName(oss.str().c_str());
writer->SetFileName(oss.str());
writer->SetNumberOfDivisionsTiledStreaming(8);
writer->Update();
......@@ -135,7 +135,7 @@ int otbVectorImageToImageListFilterIterator(int itkNotUsed(argc), char * argv[])
writer->SetInput(itOutput.Get());
writer->SetFileName(oss.str().c_str());
writer->SetFileName(oss.str());
writer->Update();
......
......@@ -110,7 +110,7 @@ int main(int argc, char * argv[])
//-----------------------------------------------------------------
//read image
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(parseResult->GetInputImage().c_str());
reader->SetFileName(parseResult->GetInputImage());
reader->UpdateOutputInformation();
///////////////////////////////////////////////////////////////////
......@@ -258,7 +258,7 @@ int main(int argc, char * argv[])
//-----------------------------------------------------------------
//write image
WriterType::Pointer writer = WriterType::New();
writer->SetFileName(parseResult->GetOutputImage().c_str());
writer->SetFileName(parseResult->GetOutputImage());
writer->SetInput(rescaler->GetOutput());
try
......
......@@ -116,7 +116,7 @@ int otbAngularProjectionBinaryImageFilterTest ( int argc, char * argv[] )
title << outputImageName << "_" << i << ".hdr";
writers[i] = WriterType::New();
writers[i]->SetFileName( title.str().c_str() );
writers[i]->SetFileName( title.str() );
writers[i]->SetInput( filter->GetOutput(i) );
writers[i]->Update();
}
......
......@@ -81,7 +81,7 @@ int otbAngularProjectionSetImageFilterTest ( int argc, char * argv[] )
for ( unsigned int i = 0; i < nbInputImages; i++ )
{
reader->SetNthElement(i, ReaderType::New());
reader->GetNthElement(i)->SetFileName( inputImageName[i].c_str() );
reader->GetNthElement(i)->SetFileName( inputImageName[i] );
reader->GetNthElement(i)->Update();
}
......@@ -118,7 +118,7 @@ int otbAngularProjectionSetImageFilterTest ( int argc, char * argv[] )
writers->SetNthElement(i, WriterType::New());
WriterType::Pointer writer = writers->GetNthElement(i);
writer->SetFileName( title.str().c_str() );
writer->SetFileName( title.str() );
writer->SetInput( filter->GetOutput()->GetNthElement(i) );
writer->Update();
}
......
......@@ -95,7 +95,7 @@ int otbSparseWvltToAngleMapperListFilterNewTest ( int argc, char * argv[] )
for ( unsigned int i = 0; i < nbInputImages; i++ )
{
reader->SetNthElement(i, ReaderType::New());
reader->GetNthElement(i)->SetFileName( inputImageName[i].c_str() );
reader->GetNthElement(i)->SetFileName( inputImageName[i] );
reader->GetNthElement(i)->Update();
// Here, we will have 'nbInputImages' image lists of one image each only
......
......@@ -85,28 +85,28 @@ int otbMorphologicalPyramidAnalysisFilter(int itkNotUsed(argc), char * argv[])
{
oss << outputFilenamePrefix << "_an_" << i << "." << outputFilenameSuffix;
writer->SetInput(itAnalyse.Get());
writer->SetFileName(oss.str().c_str());
writer->SetFileName(oss.str());
writer->Update();
oss.str("");
oss << outputFilenamePrefix << "_sf_" << i << "." << outputFilenameSuffix;
writer->SetInput(itSupFilter.Get());
writer->SetFileName(oss.str().c_str());
writer->SetFileName(oss.str());
writer->Update();
oss.str("");
oss << outputFilenamePrefix << "_if_" << i << "." << outputFilenameSuffix;
writer->SetInput(itInfFilter.Get());
writer->SetFileName(oss.str().c_str());
writer->SetFileName(oss.str());
writer->Update();
oss.str("");
oss << outputFilenamePrefix << "_id_" << i << "." << outputFilenameSuffix;
writer->SetInput(itInfDeci.Get());
writer->SetFileName(oss.str().c_str());
writer->SetFileName(oss.str());
writer->Update();
std::cout << "File " << oss.str() << " written" << std::endl;
oss.str("");
oss << outputFilenamePrefix << "_sd_" << i << "." << outputFilenameSuffix;
writer->SetInput(itSupDeci.Get());
writer->SetFileName(oss.str().c_str());
writer->SetFileName(oss.str());
writer->Update();
oss.str("");
++itAnalyse;
......
......@@ -87,7 +87,7 @@ int otbMorphologicalPyramidSegmentationFilter(int itkNotUsed(argc), char * argv[
oss << outputFilenamePrefix << index << "." << outputFilenameSuffix;
writer = WriterType::New();
writer->SetInput(it.Get());
writer->SetFileName(oss.str().c_str());
writer->SetFileName(oss.str());
writer->Update();
std::cout << oss.str() << " file written." << std::endl;
oss.str("");
......
......@@ -132,7 +132,7 @@ int otbRationalTransformToDisplacementFieldSourceTest(int argc, char* argv[])
/** Write deformation field to disk. */
WriterType::Pointer writer = WriterType::New();
writer->SetInput( defGenerator->GetOutput() );
writer->SetFileName( fileName.c_str() );
writer->SetFileName( fileName );
try
{
......
......@@ -79,7 +79,7 @@ int otbSparseUnmixingImageFilterTest ( int argc, char * argv[] )
for ( unsigned int i = 0; i < nbInputImages; i++ )
{
reader->SetNthElement(i, ReaderType::New());
reader->GetNthElement(i)->SetFileName( inputImageName[i].c_str() );
reader->GetNthElement(i)->SetFileName( inputImageName[i] );
reader->GetNthElement(i)->Update();
}
......@@ -110,7 +110,7 @@ int otbSparseUnmixingImageFilterTest ( int argc, char * argv[] )
WriterType::Pointer writer = writers->GetNthElement(i);
std::string stitle = title.str();
writer->SetFileName( stitle.c_str() );
writer->SetFileName( stitle );
writer->SetInput( filter->GetOutput()->GetNthElement(i) );
writer->Update();
}
......
......@@ -354,7 +354,7 @@ MapFileProductWriter<TInputImage>
// Configure writer
m_VectorWriter = VectorWriterType::New();
m_VectorWriter->SetFileName(ossFileName.str().c_str());
m_VectorWriter->SetFileName(ossFileName.str());
m_VectorWriter->SetInput(m_VectorImageExtractROIFilter->GetOutput());
m_VectorWriter->Update();
......
......@@ -79,8 +79,11 @@ public:
std::vector<std::string> optionList;
};
/* Set Methods */
void SetExtendedFileName(const char * extFname) override;
/** \deprecated const char* overload of SetExtendedFileName is deprecated, use std::string instead */
void SetExtendedFileName(const char* extFname) override;
void SetExtendedFileName(const std::string& extFname) override;
/* Get Methods */
bool SimpleFileNameIsSet () const;
bool ExtGEOMFileNameIsSet () const;
......
......@@ -83,8 +83,11 @@ public:
NoDataListType m_NoDataList;
bool has_noDataValue;
/* Set Methods */
void SetExtendedFileName(const char * extFname) override;
/** \deprecated const char* overload of SetExtendedFileName is deprecated, use std::string instead */
void SetExtendedFileName(const char* extFname) override;
void SetExtendedFileName(const std::string& extFname) override;
/* Get Methods */
bool SimpleFileNameIsSet () const;
bool NoDataValueIsSet () const;
......
......@@ -63,7 +63,17 @@ ExtendedFilenameToReaderOptions
void
ExtendedFilenameToReaderOptions
::SetExtendedFileName(const char *extFname)
::SetExtendedFileName(const char* extFname)
{
if (extFname)
{
this->SetExtendedFileName(std::string(extFname));
}
}
void
ExtendedFilenameToReaderOptions
::SetExtendedFileName(const std::string& extFname)
{
Superclass::SetExtendedFileName(extFname);
MapType map = GetOptionMap();
......
......@@ -61,7 +61,19 @@ ExtendedFilenameToWriterOptions
void
ExtendedFilenameToWriterOptions
::SetExtendedFileName(const char *extFname)
::SetExtendedFileName(const char* extFname)
{
if (extFname == nullptr)
{
itkGenericExceptionMacro( << "Filename is NULL" );
}
this->SetExtendedFileName(std::string(extFname));
}
void
ExtendedFilenameToWriterOptions
::SetExtendedFileName(const std::string& extFname)
{
this->Superclass::SetExtendedFileName(extFname);
// TODO: Rename map to a less confusing (with std::map) name
......
......@@ -364,7 +364,7 @@ void TileMapImageIO::ReadTile(const std::string& filename, void * buffer)
if (lCanRead == true)
{
imageIO->SetFileName(filename.c_str());
imageIO->SetFileName(filename);
imageIO->ReadImageInformation();
itk::ImageIORegion ioRegion(2);
ioRegion.SetIndex(0, 0);
......@@ -695,7 +695,7 @@ void TileMapImageIO::InternalWrite(double x, double y, const void* buffer)
imageIO->SetUseCompression(1);
imageIO->SetFileName(filename.str().c_str());
imageIO->SetFileName(filename.str());
imageIO->WriteImageInformation();
itk::ImageIORegion ioRegion(2);
......
......@@ -140,8 +140,11 @@ public:
void SetImageIO( otb::ImageIOBase * imageIO );
itkGetObjectMacro(ImageIO,otb::ImageIOBase);
/** \deprecated const char* overload of SetFileName is deprecated, use std::string instead */
virtual void SetFileName(const char* extendedFileName);
virtual void SetFileName(std::string extendedFileName);
virtual void SetFileName(const std::string& extendedFileName);
virtual const char* GetFileName () const;
/** Get the resolution information from the file */
......
......@@ -134,7 +134,7 @@ ImageFileReader<TOutputImage, ConvertPixelTraits>
// Tell the ImageIO to read the file
OutputImagePixelType *buffer =
output->GetPixelContainer()->GetBufferPointer();
this->m_ImageIO->SetFileName(this->m_FileName.c_str());
this->m_ImageIO->SetFileName(this->m_FileName);
itk::ImageIORegion ioRegion(TOutputImage::ImageDimension);
......@@ -305,7 +305,7 @@ ImageFileReader<TOutputImage, ConvertPixelTraits>
// Got to allocate space for the image. Determine the characteristics of
// the image.
//
this->m_ImageIO->SetFileName(this->m_FileName.c_str());
this->m_ImageIO->SetFileName(this->m_FileName);
this->m_ImageIO->ReadImageInformation();
// Initialize the number of component per pixel
// THOMAS: This is not in ITK!
......@@ -658,64 +658,64 @@ ImageFileReader<TOutputImage, ConvertPixelTraits>
template <class TOutputImage, class ConvertPixelTraits>
void
ImageFileReader<TOutputImage, ConvertPixelTraits>
::SetFileName(std::string extendedFileName)
::SetFileName(const char* in)
{
this->SetFileName(extendedFileName.c_str());
if (in)
{
this->SetFileName(std::string(in));
}
}
template <class TOutputImage, class ConvertPixelTraits>
void
ImageFileReader<TOutputImage, ConvertPixelTraits>
::SetFileName(const char* in)
::SetFileName(const std::string& extendedFileName)
{
const std::string skip_geom_key = "skipgeom";
const std::string geom_key = "geom";
if (in)
{
// First, see if the simple filename has changed
typename FNameHelperType::Pointer helper = FNameHelperType::New();
// First, see if the simple filename has changed
typename FNameHelperType::Pointer helper = FNameHelperType::New();
helper->SetExtendedFileName(extendedFileName);
std::string simpleFileName = helper->GetSimpleFileName();
helper->SetExtendedFileName(in);
std::string simpleFileName = helper->GetSimpleFileName();
if(simpleFileName == this->m_FileName)
{
// Then, see if the option map changed
const typename ExtendedFilenameHelper::OptionMapType & newMap = helper->GetOptionMap();
const typename ExtendedFilenameHelper::OptionMapType & oldMap = m_FilenameHelper->GetOptionMap();
if(simpleFileName == this->m_FileName)
// Both maps are not completely the same
if(oldMap.size() != newMap.size() || !std::equal(oldMap.begin(),oldMap.end(),newMap.begin()))
{
// Then, see if the option map changed
const typename ExtendedFilenameHelper::OptionMapType & newMap = helper->GetOptionMap();
const typename ExtendedFilenameHelper::OptionMapType & oldMap = m_FilenameHelper->GetOptionMap();
this->Modified();
// Both maps are not completely the same
if(oldMap.size() != newMap.size() || !std::equal(oldMap.begin(),oldMap.end(),newMap.begin()))
// Now check if keywordlist needs to be generated again
// Condition is: one of the old or new map has the skip_geom
// key and the other does not
// OR
// one of the old or new map has the geom key and the other
// does not
// OR
// both have the geom key but the geom value is different
if((oldMap.count(skip_geom_key) != newMap.count(skip_geom_key))
|| (oldMap.count(geom_key) != newMap.count(geom_key))
|| ((oldMap.count(geom_key) && newMap.count(geom_key))
&& oldMap.find(geom_key)->second != newMap.find(geom_key)->second))
{
this->Modified();
// Now check if keywordlist needs to be generated again
// Condition is: one of the old or new map has the skip_geom
// key and the other does not
// OR
// one of the old or new map has the geom key and the other
// does not
// OR
// both have the geom key but the geom value is different
if((oldMap.count(skip_geom_key) != newMap.count(skip_geom_key))
|| (oldMap.count(geom_key) != newMap.count(geom_key))
|| ((oldMap.count(geom_key) && newMap.count(geom_key))
&& oldMap.find(geom_key)->second != newMap.find(geom_key)->second))
{
m_KeywordListUpToDate = false;
}
m_KeywordListUpToDate = false;
}
}
else
{
this->m_FileName = simpleFileName;
m_KeywordListUpToDate = false;
this->Modified();
}
m_FilenameHelper = helper;
}
else
{
this->m_FileName = simpleFileName;
m_KeywordListUpToDate = false;
this->Modified();
}
m_FilenameHelper = helper;
}
template <class TOutputImage, class ConvertPixelTraits>
......
......@@ -172,9 +172,11 @@ public:
* has no output. */
void Update() override;
/** ImageFileWriter Methods */
/** \deprecated const char* overload of SetFileName is deprecated, use std::string instead */
virtual void SetFileName(const char* extendedFileName);
virtual void SetFileName(std::string extendedFileName);
virtual void SetFileName(const std::string& extendedFileName);
virtual const char* GetFileName () const;
/** Specify the region to write. If left NULL, then the whole image
......
......@@ -571,7 +571,7 @@ ImageFileWriter<TInputImage>
/** Create Image file */
// Setup the image IO for writing.
//
m_ImageIO->SetFileName(m_FileName.c_str());
m_ImageIO->SetFileName(m_FileName);
m_ImageIO->WriteImageInformation();
}
......@@ -832,9 +832,12 @@ ImageFileWriter<TInputImage>
template <class TInputImage>
void
ImageFileWriter<TInputImage>
::SetFileName(std::string extendedFileName)
::SetFileName(const std::string& extendedFileName)
{
this->SetFileName(extendedFileName.c_str());
this->m_FilenameHelper->SetExtendedFileName(extendedFileName);
m_FileName = this->m_FilenameHelper->GetSimpleFileName();
m_ImageIO = nullptr;
this->Modified();
}
template <class TInputImage>
......@@ -842,10 +845,12 @@ void
ImageFileWriter<TInputImage>
::SetFileName(const char* extendedFileName)
{
this->m_FilenameHelper->SetExtendedFileName(extendedFileName);
m_FileName = this->m_FilenameHelper->GetSimpleFileName();
m_ImageIO = nullptr;
this->Modified();
if (extendedFileName == nullptr)
{
itkGenericExceptionMacro( << "Filename is NULL" );
}
this->SetFileName(std::string(extendedFileName));
}
template <class TInputImage>
......
......@@ -111,6 +111,13 @@ public:
* selection
*/
virtual void SetFileName(const std::string& file);
/**
* Set the file to be read. Once the Filename is set, ReadMeatFile is called in order to get
* the number of image files to be read, the images file names, the band and region
* selection
* \deprecated const char* overload of SetFileName is deprecated, use std::string instead
*/
virtual void SetFileName(const char * file);
/** get the Filenames */
......
......@@ -43,7 +43,13 @@ void
ImageSeriesFileReaderBase<TImage, TInternalImage>
::SetFileName(const std::string& file)
{
return SetFileName(file.c_str());
if (file == m_FileName) return;
this->m_FileName = file;
ReadMetaFile();
AllocateListOfComponents();
this->Modified();
}
template <class TImage, class TInternalImage>
......@@ -51,17 +57,10 @@ void
ImageSeriesFileReaderBase<TImage, TInternalImage>
::SetFileName(const char * file)
{
if (file && (file == m_FileName)) return;
if (file)
{
this->m_FileName = file;
ReadMetaFile();
AllocateListOfComponents();
}
else this->m_FileName = "";
this->Modified();
{
this->SetFileName(std::string(file));
}
}
template <class TImage, class TInternalImage>
......
......@@ -235,7 +235,7 @@ KmzProductWriter<TInputImage>
castFiler->SetInput(legend);
m_VectorWriter = VectorWriterType::New();
m_VectorWriter->SetFileName(legendName.str().c_str());
m_VectorWriter->SetFileName(legendName.str());