Commit 338e4778 authored by Antoine Regimbeau's avatar Antoine Regimbeau

MRG: Merge branch 'metadata_pixeltype' into develop

parents 35219b52 3c0e2a2c
......@@ -74,6 +74,8 @@ namespace MetaDataKey
extern OTBOSSIMAdapters_EXPORT char const * NoDataValueAvailable;
extern OTBOSSIMAdapters_EXPORT char const * NoDataValue;
extern OTBOSSIMAdapters_EXPORT char const * DataType;
enum KeyType
{
......
......@@ -21,8 +21,6 @@
#include "otbMetaDataKey.h"
#define NBKEYS 24
namespace otb
{
namespace MetaDataKey
......@@ -65,6 +63,8 @@ char const* TileHintY = "TileHintY";
char const * NoDataValueAvailable = "NoDataValueAvailable";
char const * NoDataValue = "NoDataValue";
char const * DataType = "DataType";
}
const MetaDataKey::KeyTypeDef Types[] =
......@@ -77,6 +77,7 @@ const MetaDataKey::KeyTypeDef Types[] =
MetaDataKey::KeyTypeDef(MetaDataKey::GCPCountKey, MetaDataKey::TENTIER),
MetaDataKey::KeyTypeDef(MetaDataKey::GeoTransformKey, MetaDataKey::TVECTOR),
MetaDataKey::KeyTypeDef(MetaDataKey::MetadataKey, MetaDataKey::TSTRING),
MetaDataKey::KeyTypeDef(MetaDataKey::SubMetadataKey, MetaDataKey::TSTRING),
MetaDataKey::KeyTypeDef(MetaDataKey::UpperLeftCornerKey, MetaDataKey::TVECTOR),
MetaDataKey::KeyTypeDef(MetaDataKey::UpperRightCornerKey, MetaDataKey::TVECTOR),
MetaDataKey::KeyTypeDef(MetaDataKey::LowerLeftCornerKey, MetaDataKey::TVECTOR),
......@@ -94,22 +95,24 @@ const MetaDataKey::KeyTypeDef Types[] =
MetaDataKey::KeyTypeDef(MetaDataKey::TileHintX, MetaDataKey::TENTIER),
MetaDataKey::KeyTypeDef(MetaDataKey::TileHintY, MetaDataKey::TENTIER),
MetaDataKey::KeyTypeDef(MetaDataKey::NoDataValueAvailable, MetaDataKey::TVECTOR),
MetaDataKey::KeyTypeDef(MetaDataKey::NoDataValue, MetaDataKey::TVECTOR)
MetaDataKey::KeyTypeDef(MetaDataKey::NoDataValue, MetaDataKey::TVECTOR),
MetaDataKey::KeyTypeDef(MetaDataKey::DataType, MetaDataKey::TENTIER),
};
MetaDataKey::KeyType MetaDataKey::GetKeyType(const std::string& name)
{
MetaDataKey::KeyType ktype(MetaDataKey::TSTRING);
// MetaDataKey::KeyType ktype(MetaDataKey::TSTRING);
for (unsigned int i = 0; i < NBKEYS; ++i)
for ( const auto & key : Types )
{
if ( name.find(Types[i].keyname) != std::string::npos )
if ( name.find(key.keyname) != std::string::npos )
{
ktype = Types[i].type;
break;
return MetaDataKey::KeyType(key.type);
// ktype = key.type;
// return ktype;
}
}
return (ktype);
return MetaDataKey::KeyType(MetaDataKey::TSTRING);
}
OTB_GCP::OTB_GCP()
......
......@@ -52,7 +52,9 @@ private:
SetDocName("DEM Conversion");
SetDocLongDescription("In order to be understood by the Orfeo ToolBox and the underlying OSSIM library, a geo-referenced Digital Elevation Model image can be converted into a general raster image, which consists in 3 files with the following extensions: .ras, .geom and .omd. Once converted, you have to place these files in a separate directory, and you can then use this directory to set the \"DEM Directory\" parameter of a DEM based OTB application or filter.");
SetDocLimitations("None");
SetDocLimitations("For this application to work one need the input "
"pixel type to be retrieved. It can only be done through GDAL IO driver "
"for now.");
SetDocAuthors("OTB-Team");
SetDocSeeAlso(" ");
......@@ -109,42 +111,60 @@ void DoExecute() override
paramOut->SetValue(inImage);
// Set the output pixel type
ImageIOBase::Pointer imageIO = ImageIOFactory::CreateImageIO( GetParameterString("in").c_str(),
ImageIOFactory::ReadMode);
std::string componentTypeInfo(imageIO->GetComponentTypeInfo().name());
if( componentTypeInfo == typeid(unsigned char).name())
ImageIOBase::IOComponentType typeInfo;
bool hasType( itk::ExposeMetaData< ImageIOBase::IOComponentType >( inImage->GetMetaDataDictionary(),
MetaDataKey::DataType , typeInfo) );
if ( ! hasType )
itkExceptionMacro("The pixel type could not be retrieved.");
switch(typeInfo)
{
paramOut->SetPixelType(ImagePixelType_uint8);
case ImageIOBase::UCHAR:
paramOut->SetPixelType(ImagePixelType_uint8);
break;
case ImageIOBase::CHAR:
itkExceptionMacro("This application doesn't support image pixel type char.");
break;
case ImageIOBase::USHORT:
paramOut->SetPixelType(ImagePixelType_uint16);
break;
case ImageIOBase::SHORT:
paramOut->SetPixelType(ImagePixelType_int16);
break;
case ImageIOBase::UINT:
paramOut->SetPixelType(ImagePixelType_uint32);
break;
case ImageIOBase::INT:
paramOut->SetPixelType(ImagePixelType_int32);
break;
case ImageIOBase::ULONG:
itkExceptionMacro("This application doesn't support image pixel type unsigned long.");
break;
case ImageIOBase::LONG:
itkExceptionMacro("This application doesn't support image pixel type long.");
break;
case ImageIOBase::FLOAT:
paramOut->SetPixelType(ImagePixelType_float);
break;
case ImageIOBase::DOUBLE:
paramOut->SetPixelType(ImagePixelType_double);
break;
case ImageIOBase::CSHORT:
paramOut->SetPixelType(ImagePixelType_cint16);
break;
case ImageIOBase::CINT:
paramOut->SetPixelType(ImagePixelType_cint32);
break;
case ImageIOBase::CFLOAT:
paramOut->SetPixelType(ImagePixelType_cfloat);
break;
case ImageIOBase::CDOUBLE:
paramOut->SetPixelType(ImagePixelType_cdouble);
break;
case ImageIOBase::UNKNOWNCOMPONENTTYPE:
itkExceptionMacro("The pixel type is unknown.");
break;
}
else if( componentTypeInfo == typeid(unsigned short).name())
{
paramOut->SetPixelType(ImagePixelType_uint16);
}
else if( componentTypeInfo == typeid(short).name())
{
paramOut->SetPixelType(ImagePixelType_int16);
}
else if( componentTypeInfo == typeid(unsigned int).name())
{
paramOut->SetPixelType(ImagePixelType_uint32);
}
else if( componentTypeInfo == typeid(int).name())
{
paramOut->SetPixelType(ImagePixelType_int32);
}
else if( componentTypeInfo == typeid(float).name())
{
paramOut->SetPixelType(ImagePixelType_float);
}
else if( componentTypeInfo == typeid(double).name())
{
paramOut->SetPixelType(ImagePixelType_double);
}
else
{
itkExceptionMacro("This application doesn't support image pixel type " << componentTypeInfo);
}
// Add the tempfilename to be written
paramOut->InitializeWriters();
AddProcess(paramOut->GetWriter(), osswriter.str());
......
......@@ -711,9 +711,16 @@ void GDALImageIO::InternalReadImageInformation()
}
}
/* -------------------------------------------------------------------- */
/* Get Pixel type */
/* -------------------------------------------------------------------- */
itk::EncapsulateMetaData< IOComponentType >( dict,
MetaDataKey::DataType ,
this->GetComponentType() );
/* -------------------------------------------------------------------- */
/* Get Spacing */
/* Get Spacing */
/* -------------------------------------------------------------------- */
// Default Spacing
......
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