Commit b380dabc authored by Julien Michel's avatar Julien Michel

MRG

parents 42b33f78 35c38c63
......@@ -46,9 +46,9 @@ public:
typedef std::map< std::string, std::string > OptionMapType;
void SetExtendedFileName(const char * extFname);
OptionMapType GetOptionMap(void) const;
virtual void SetExtendedFileName(const char * extFname);
const OptionMapType & GetOptionMap(void) const;
itkGetStringMacro(ExtendedFileName);
itkGetStringMacro(SimpleFileName);
......
......@@ -38,19 +38,19 @@ namespace otb
* \ingroup OTBExtendedFilename
*/
class ITK_EXPORT ExtendedFilenameToReaderOptions : public itk::Object
class ITK_EXPORT ExtendedFilenameToReaderOptions : public ExtendedFilenameHelper
{
public:
/** Standard class typedefs. */
typedef ExtendedFilenameToReaderOptions Self;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
typedef itk::Object Superclass;
typedef ExtendedFilenameHelper Superclass;
itkTypeMacro(ExtendedFilenameToReaderOptions, itk::Object);
itkTypeMacro(ExtendedFilenameToReaderOptions, otb::ExtendedFilenameHelper);
itkNewMacro(Self);
typedef ExtendedFilenameHelper FNameHelperType;
typedef Superclass FNameHelperType;
typedef FNameHelperType::OptionMapType MapType;
typedef MapType::iterator MapIteratorType;
......@@ -68,10 +68,9 @@ public:
};
/* Set Methods */
void SetExtendedFileName(const char * extFname);
virtual void SetExtendedFileName(const char * extFname);
/* Get Methods */
bool SimpleFileNameIsSet () const;
const char* GetSimpleFileName () const;
bool ExtGEOMFileNameIsSet () const;
const char* GetExtGEOMFileName () const;
bool SubDatasetIndexIsSet () const;
......@@ -93,7 +92,6 @@ private:
ExtendedFilenameToReaderOptions(const Self &); //purposely not implemented
void operator =(const Self&); //purposely not implemented
FNameHelperType::Pointer m_FilenameHelper;
OptionType m_Options;
};
......
......@@ -39,19 +39,19 @@ namespace otb
* \ingroup OTBExtendedFilename
*/
class ITK_EXPORT ExtendedFilenameToWriterOptions : public itk::Object
class ITK_EXPORT ExtendedFilenameToWriterOptions : public ExtendedFilenameHelper
{
public:
/** Standard class typedefs. */
typedef ExtendedFilenameToWriterOptions Self;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
typedef itk::Object Superclass;
typedef ExtendedFilenameHelper Superclass;
itkTypeMacro(ExtendedFilenameToWriterOptions, itk::Object);
itkTypeMacro(ExtendedFilenameToWriterOptions, otb::ExtendedFilenameHelper);
itkNewMacro(Self);
typedef ExtendedFilenameHelper FNameHelperType;
typedef Superclass FNameHelperType;
typedef FNameHelperType::OptionMapType MapType;
typedef MapType::iterator MapIteratorType;
......@@ -73,10 +73,9 @@ public:
};
/* Set Methods */
void SetExtendedFileName(const char * extFname);
virtual void SetExtendedFileName(const char * extFname);
/* Get Methods */
bool SimpleFileNameIsSet () const;
const char* GetSimpleFileName () const;
bool WriteGEOMFileIsSet () const;
bool WriteRPCTagsIsSet() const;
bool GetWriteGEOMFile () const;
......@@ -102,7 +101,6 @@ private:
ExtendedFilenameToWriterOptions(const Self &); //purposely not implemented
void operator =(const Self&); //purposely not implemented
FNameHelperType::Pointer m_FilenameHelper;
OptionType m_Options;
};
......
......@@ -66,7 +66,7 @@ ExtendedFilenameHelper
}
ExtendedFilenameHelper::OptionMapType
const ExtendedFilenameHelper::OptionMapType &
ExtendedFilenameHelper
::GetOptionMap(void) const
{
......
......@@ -22,10 +22,8 @@ namespace otb
{
ExtendedFilenameToReaderOptions
::ExtendedFilenameToReaderOptions() : itk::Object()
::ExtendedFilenameToReaderOptions() : ExtendedFilenameHelper()
{
m_FilenameHelper = FNameHelperType::New();
m_Options.simpleFileName.first = false;
m_Options.simpleFileName.second = "";
......@@ -59,11 +57,11 @@ void
ExtendedFilenameToReaderOptions
::SetExtendedFileName(const char *extFname)
{
this->m_FilenameHelper->SetExtendedFileName(extFname);
MapType map = this->m_FilenameHelper->GetOptionMap();
Superclass::SetExtendedFileName(extFname);
MapType map = GetOptionMap();
m_Options.simpleFileName.first = true;
m_Options.simpleFileName.second = this->m_FilenameHelper->GetSimpleFileName();
m_Options.simpleFileName.second = this->GetSimpleFileName();
if (!map["geom"].empty())
{
......@@ -144,12 +142,6 @@ ExtendedFilenameToReaderOptions
{
return m_Options.simpleFileName.first;
}
const char*
ExtendedFilenameToReaderOptions
::GetSimpleFileName () const
{
return m_Options.simpleFileName.second.c_str();
}
bool
ExtendedFilenameToReaderOptions
......
......@@ -24,10 +24,8 @@ namespace otb
{
ExtendedFilenameToWriterOptions
::ExtendedFilenameToWriterOptions() : itk::Object()
::ExtendedFilenameToWriterOptions() : ExtendedFilenameHelper()
{
m_FilenameHelper = FNameHelperType::New();
m_Options.simpleFileName.first = false;
m_Options.simpleFileName.second = "";
......@@ -54,12 +52,12 @@ void
ExtendedFilenameToWriterOptions
::SetExtendedFileName(const char *extFname)
{
this->m_FilenameHelper->SetExtendedFileName(extFname);
this->Superclass::SetExtendedFileName(extFname);
// TODO: Rename map to a less confusing (with std::map) name
MapType map = this->m_FilenameHelper->GetOptionMap();
MapType map = this->GetOptionMap();
m_Options.simpleFileName.first = true;
m_Options.simpleFileName.second = this->m_FilenameHelper->GetSimpleFileName();
m_Options.simpleFileName.second = this->GetSimpleFileName();
MapIteratorType it;
for ( it=map.begin(); it != map.end(); it++ )
......@@ -189,12 +187,6 @@ ExtendedFilenameToWriterOptions
{
return m_Options.simpleFileName.first;
}
const char*
ExtendedFilenameToWriterOptions
::GetSimpleFileName () const
{
return m_Options.simpleFileName.second.c_str();
}
bool
ExtendedFilenameToWriterOptions
......
......@@ -202,6 +202,8 @@ private:
FNameHelperType::Pointer m_FilenameHelper;
unsigned int m_AdditionalNumber;
bool m_KeywordListUpToDate;
};
} //namespace otb
......
......@@ -65,7 +65,8 @@ ImageFileReader<TOutputImage, ConvertPixelTraits>
m_ExceptionMessage(""),
m_ActualIORegion(),
m_FilenameHelper(FNameHelperType::New()),
m_AdditionalNumber(0)
m_AdditionalNumber(0),
m_KeywordListUpToDate(false)
{
}
......@@ -262,14 +263,12 @@ ImageFileReader<TOutputImage, ConvertPixelTraits>
}
// Update FileName
this->m_FileName = lFileName;
std::string lFileNameOssimKeywordlist = GetDerivedDatasetSourceFileName(m_FileName);
// Test if the file exists and if it can be opened.
// An exception will be thrown otherwise.
// We catch the exception because some ImageIO's may not actually
// open a file. Still reports file error if no ImageIO is loaded.
try
{
m_ExceptionMessage = "";
......@@ -279,12 +278,12 @@ ImageFileReader<TOutputImage, ConvertPixelTraits>
{
m_ExceptionMessage = err.GetDescription();
}
if (this->m_UserSpecifiedImageIO == false) //try creating via factory
{
this->m_ImageIO = ImageIOFactory::CreateImageIO(this->m_FileName.c_str(), otb::ImageIOFactory::ReadMode);
}
if (this->m_ImageIO.IsNull())
{
//this->Print(std::cerr);
......@@ -425,25 +424,30 @@ ImageFileReader<TOutputImage, ConvertPixelTraits>
output->SetOrigin(origin); // Set the image origin
output->SetDirection(direction); // Set the image direction cosines
// Update otb Keywordlist
ImageKeywordlist otb_kwl;
if (!m_FilenameHelper->ExtGEOMFileNameIsSet())
{
otb_kwl = ReadGeometryFromImage(lFileNameOssimKeywordlist,!m_FilenameHelper->GetSkipRpcTag());
otbMsgDevMacro(<< "Loading internal kwl");
}
else
{
otb_kwl = ReadGeometryFromGEOMFile(m_FilenameHelper->GetExtGEOMFileName());
otbMsgDevMacro(<< "Loading external kwl");
}
// Don't add an empty ossim keyword list
if(!otb_kwl.Empty())
if(!m_KeywordListUpToDate && !m_FilenameHelper->GetSkipGeom())
{
std::string lFileNameOssimKeywordlist = GetDerivedDatasetSourceFileName(m_FileName);
// Update otb Keywordlist
ImageKeywordlist otb_kwl;
if (!m_FilenameHelper->ExtGEOMFileNameIsSet())
{
otb_kwl = ReadGeometryFromImage(lFileNameOssimKeywordlist,!m_FilenameHelper->GetSkipRpcTag());
otbMsgDevMacro(<< "Loading internal kwl");
}
else
{
otb_kwl = ReadGeometryFromGEOMFile(m_FilenameHelper->GetExtGEOMFileName());
otbMsgDevMacro(<< "Loading external kwl");
}
// Don't add an empty ossim keyword list
if(!otb_kwl.Empty())
{
itk::EncapsulateMetaData<ImageKeywordlist>(dict,
MetaDataKey::OSSIMKeywordlistKey, otb_kwl);
}
}
/*else
{
//
......@@ -484,6 +488,21 @@ ImageFileReader<TOutputImage, ConvertPixelTraits>
}
}*/
m_KeywordListUpToDate = true;
}
else
{
// Read back from existing dictionnary
ImageKeywordlist otb_kwl;
itk::ExposeMetaData<ImageKeywordlist>(this->GetOutput()->GetMetaDataDictionary(),
MetaDataKey::OSSIMKeywordlistKey,otb_kwl);
// And add to new one
itk::EncapsulateMetaData<ImageKeywordlist>(dict,
MetaDataKey::OSSIMKeywordlistKey, otb_kwl);
}
// If Skip ProjectionRef is activated, remove ProjRef from dict
if (m_FilenameHelper->GetSkipCarto())
{
......@@ -670,13 +689,55 @@ ImageFileReader<TOutputImage, ConvertPixelTraits>
template <class TOutputImage, class ConvertPixelTraits>
void
ImageFileReader<TOutputImage, ConvertPixelTraits>
::SetFileName(const char* extendedFileName)
::SetFileName(const char* in)
{
if (extendedFileName)
const std::string skip_geom_key = "skipgeom";
const std::string geom_key = "geom";
if (in)
{
this->m_FilenameHelper->SetExtendedFileName(extendedFileName);
this->m_FileName = this->m_FilenameHelper->GetSimpleFileName();
this->Modified();
// First, see if the simple filename has changed
typename FNameHelperType::Pointer helper = FNameHelperType::New();
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();
// Both maps are not completely the same
if(oldMap.size() != newMap.size() || !std::equal(oldMap.begin(),oldMap.end(),newMap.begin()))
{
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;
}
}
}
else
{
this->m_FileName = simpleFileName;
m_KeywordListUpToDate = false;
this->Modified();
}
m_FilenameHelper = helper;
}
}
......
......@@ -141,8 +141,6 @@ void GlImageActor::Initialize(const std::string & filename)
m_FileReader->SetFileName(m_FileName);
m_FileReader->GetOutput()->UpdateOutputInformation();
//std::cout<<"GlImageActor::Initialize"<<std::endl;
m_LargestRegion = m_FileReader->GetOutput()->GetLargestPossibleRegion();
if(m_FileReader->GetOutput()->GetNumberOfComponentsPerPixel() < 3)
......@@ -1041,10 +1039,6 @@ void GlImageActor::UpdateResolution()
std::ostringstream extFilename;
extFilename<<m_FileName<<"?&resol="<<m_CurrentResolution;
// ReaderType::New() is forced because of warning message
// 'Duplicated option detected: <option>. Using value <value>.'
// output by otb::ExtendedFilenameHelper.
m_FileReader = ReaderType::New();
m_FileReader->SetFileName(extFilename.str());
m_FileReader->GetOutput()->UpdateOutputInformation();
// std::cout << "Switched to resolution: " << m_CurrentResolution <<
......
......@@ -108,8 +108,8 @@ VectorImageModel
// << std::endl;
m_ImageFileReader->SetFileName( QFile::encodeName( GetFilename() ) );
m_ImageFileReader->UpdateOutputInformation();
m_ImageFileReader->GetOutput()->UpdateOutputInformation();
// Retrieve the list of Lod from file
m_LodCount = m_ImageFileReader->GetOverviewsCount();
......@@ -172,8 +172,10 @@ VectorImageModel
DefaultImageFileReaderType::New()
);
imageFileReader->SetFileName( QFile::encodeName( filename ).constData() );
imageFileReader->UpdateOutputInformation();
QString fname = filename;
imageFileReader->SetFileName( QFile::encodeName( fname.append(QString("?&skipgeom=true"))).constData());
imageFileReader->GetOutput()->UpdateOutputInformation();
}
catch( std::exception& exc )
......@@ -539,15 +541,9 @@ VectorImageModel
lodFilename.append( QString( "?&resol=%1" ).arg( lod ) );
// Update m_ImageFileReader
DefaultImageFileReaderType::Pointer fileReader(
DefaultImageFileReaderType::New()
);
fileReader->SetFileName( QFile::encodeName( lodFilename ).constData() );
fileReader->UpdateOutputInformation();
m_ImageFileReader = fileReader;
m_ImageFileReader->SetFileName( QFile::encodeName( lodFilename ).constData() );
m_ImageFileReader->GetOutput()->UpdateOutputInformation();
// (Always) Update m_Image reference.
m_Image = m_ImageFileReader->GetOutput();
}
......
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