Skip to content
Snippets Groups Projects
Commit 49714b82 authored by Guillaume Borrut's avatar Guillaume Borrut
Browse files

MRG

parent a5fed8da
No related branches found
No related tags found
No related merge requests found
...@@ -131,6 +131,9 @@ bool GDALImageIO::CanReadFile(const char* file) ...@@ -131,6 +131,9 @@ bool GDALImageIO::CanReadFile(const char* file)
} }
else else
{ {
std::cout<<"CanReadFile !!!!!!!!!!"<<std::endl;
GDALClose(m_poDataset); GDALClose(m_poDataset);
m_poDataset = NULL; m_poDataset = NULL;
GDALDestroyDriverManager(); GDALDestroyDriverManager();
...@@ -158,22 +161,38 @@ void GDALImageIO::ReadVolume(void*) ...@@ -158,22 +161,38 @@ void GDALImageIO::ReadVolume(void*)
void GDALImageIO::Read(void* buffer) void GDALImageIO::Read(void* buffer)
{ {
std::streamoff step = static_cast<std::streamoff>(this->GetNumberOfComponents()); std::streamoff step = static_cast<std::streamoff>(this->GetNumberOfComponents());
std::cout<< " PASSE DANS READ !!"<<std::endl;
std::cout<< "step : "<<step<<std::endl;
unsigned char * p = static_cast<unsigned char *>(buffer); unsigned char * p = static_cast<unsigned char *>(buffer);
if (p==NULL) if (p==NULL)
{ {
itkExceptionMacro(<<"Memory allocation error"); itkExceptionMacro(<<"Memory allocation error");
return; return;
} }
std::cout<< "buffer : "<< p <<std::endl;
int lNbLines = this->GetIORegion().GetSize()[1]; int lNbLines = this->GetIORegion().GetSize()[1];
int lNbColumns = this->GetIORegion().GetSize()[0]; int lNbColumns = this->GetIORegion().GetSize()[0];
int lFirstLine = this->GetIORegion().GetIndex()[1]; // [1... ] int lFirstLine = this->GetIORegion().GetIndex()[1]; // [1... ]
int lFirstColumn = this->GetIORegion().GetIndex()[0]; // [1... ] int lFirstColumn = this->GetIORegion().GetIndex()[0]; // [1... ]
// int lNbLines = 1354;
// int lNbColumns = 2030;
// int lFirstLine = 0; // [1... ]
// int lFirstColumn = 0; // [1... ]
// m_NumberOfComponents = 1;
std::cout<< "Lig "<<lNbLines <<std::endl;
std::cout<< "Col "<<lNbColumns<<std::endl;
std::cout<< "FirstL " <<lFirstLine <<std::endl;
std::cout<< "FirstC " <<lFirstColumn <<std::endl;
std::cout<< "NbOctetPxl "<<m_NbOctetPixel<<std::endl;
std::streamoff lNbPixels = (static_cast<std::streamoff>(lNbColumns))*(static_cast<std::streamoff>(lNbLines)); std::streamoff lNbPixels = (static_cast<std::streamoff>(lNbColumns))*(static_cast<std::streamoff>(lNbLines));
std::streamoff lBufferSize = static_cast<std::streamoff>(m_NbOctetPixel)*lNbPixels; std::streamoff lBufferSize = static_cast<std::streamoff>(m_NbOctetPixel)*lNbPixels;
std::cout<< "lNbPixels "<<lNbPixels<<std::endl;
std::cout<< "lBufferSize "<<lBufferSize<<std::endl;
unsigned char* value = new unsigned char[lBufferSize]; unsigned char* value = new unsigned char[lBufferSize];
if (value==NULL) if (value==NULL)
{ {
...@@ -187,6 +206,7 @@ void GDALImageIO::Read(void* buffer) ...@@ -187,6 +206,7 @@ void GDALImageIO::Read(void* buffer)
if ( GDALDataTypeIsComplex(m_PxType) ) if ( GDALDataTypeIsComplex(m_PxType) )
{ {
std::cout<<"COMPLEX !!"<<std::endl;
lCrGdal = m_poBands[0]->RasterIO( GF_Read,lFirstColumn,lFirstLine,lNbColumns, lNbLines, value , lNbColumns, lNbLines, m_PxType,0, 0 ); lCrGdal = m_poBands[0]->RasterIO( GF_Read,lFirstColumn,lFirstLine,lNbColumns, lNbLines, value , lNbColumns, lNbLines, m_PxType,0, 0 );
if (lCrGdal == CE_Failure) if (lCrGdal == CE_Failure)
...@@ -202,12 +222,18 @@ void GDALImageIO::Read(void* buffer) ...@@ -202,12 +222,18 @@ void GDALImageIO::Read(void* buffer)
} }
else else
{ {
std::cout<<"NOT COMPLEX !!"<<std::endl;
// Mise a jour du step // Mise a jour du step
step = step * static_cast<std::streamoff>(m_NbOctetPixel); step = step * static_cast<std::streamoff>(m_NbOctetPixel);
m_NumberOfComponents = 1;
std::cout<<"GetNumberOfComponents : "<<this->GetNumberOfComponents()<<std::endl;
std::cout<<"Step : "<<step<<std::endl;
for (unsigned int nbComponents = 0; nbComponents < this->GetNumberOfComponents(); ++nbComponents) for (unsigned int nbComponents = 0; nbComponents < this->GetNumberOfComponents(); ++nbComponents)
{ {
std::cout<<"INFO POUR RasterIO : FC:"<<lFirstColumn<<" FL:"<<lFirstLine<<" nbC:"<<lNbColumns<<" nbL:"<<lNbLines<<" pxltype:"<<m_PxType<<std::endl;
lCrGdal = m_poBands[nbComponents]->RasterIO( GF_Read,lFirstColumn,lFirstLine,lNbColumns, lNbLines, value , lNbColumns, lNbLines, m_PxType,0, 0 ); lCrGdal = m_poBands[nbComponents]->RasterIO( GF_Read,lFirstColumn,lFirstLine,lNbColumns, lNbLines, value , lNbColumns, lNbLines, m_PxType,0, 0 );
std::cout<<"lCrGdal : "<<lCrGdal<<std::endl;
if (lCrGdal == CE_Failure) if (lCrGdal == CE_Failure)
{ {
itkExceptionMacro(<< "Error while reading image (GDAL format) " << m_FileName.c_str()<<"."); itkExceptionMacro(<< "Error while reading image (GDAL format) " << m_FileName.c_str()<<".");
...@@ -216,6 +242,7 @@ void GDALImageIO::Read(void* buffer) ...@@ -216,6 +242,7 @@ void GDALImageIO::Read(void* buffer)
cpt = static_cast<std::streamoff>(nbComponents)*static_cast<std::streamoff>(m_NbOctetPixel); cpt = static_cast<std::streamoff>(nbComponents)*static_cast<std::streamoff>(m_NbOctetPixel);
for ( std::streamoff i=0; i < lBufferSize; i = i+static_cast<std::streamoff>(m_NbOctetPixel) ) for ( std::streamoff i=0; i < lBufferSize; i = i+static_cast<std::streamoff>(m_NbOctetPixel) )
{ {
//std::cout<<"val:"<<value[i] <<std::endl;
memcpy((void*)(&(p[cpt])),(const void*)(&(value[i])),(size_t)(m_NbOctetPixel)); memcpy((void*)(&(p[cpt])),(const void*)(&(value[i])),(size_t)(m_NbOctetPixel));
cpt += step; cpt += step;
} }
...@@ -236,6 +263,13 @@ void GDALImageIO::InternalReadImageInformation() ...@@ -236,6 +263,13 @@ void GDALImageIO::InternalReadImageInformation()
{ {
int i; int i;
//GDALDatasetH hDataset;
int bSubCall = TRUE;
const char *pszSource=NULL;
int argc;
char ** argv;
if ( m_FileName.empty() == true ) if ( m_FileName.empty() == true )
{ {
itkExceptionMacro(<<"GDAl read : empty image file name file."); itkExceptionMacro(<<"GDAl read : empty image file name file.");
...@@ -254,6 +288,16 @@ void GDALImageIO::InternalReadImageInformation() ...@@ -254,6 +288,16 @@ void GDALImageIO::InternalReadImageInformation()
m_poDataset = NULL; m_poDataset = NULL;
} }
m_poDataset = static_cast<GDALDataset *>( GDALOpen(lFileNameGdal.c_str(), GA_ReadOnly )); m_poDataset = static_cast<GDALDataset *>( GDALOpen(lFileNameGdal.c_str(), GA_ReadOnly ));
/* -------------------------------------------------------------------- */
/* Attempt to open source file. */
/* -------------------------------------------------------------------- */
/// ATTENTION MODIFIE
//hDataset = GDALOpenShared( lFileNameGdal.c_str(), GA_ReadOnly );
m_poDataset = static_cast<GDALDataset *>( GDALOpenShared(lFileNameGdal.c_str(), GA_ReadOnly ));
otbMsgDevMacro( <<" GCPCount (original): " << m_poDataset->GetGCPCount()); otbMsgDevMacro( <<" GCPCount (original): " << m_poDataset->GetGCPCount());
if (m_poDataset==NULL) if (m_poDataset==NULL)
{ {
...@@ -267,6 +311,8 @@ void GDALImageIO::InternalReadImageInformation() ...@@ -267,6 +311,8 @@ void GDALImageIO::InternalReadImageInformation()
m_width = m_poDataset->GetRasterXSize(); m_width = m_poDataset->GetRasterXSize();
m_height = m_poDataset->GetRasterYSize(); m_height = m_poDataset->GetRasterYSize();
printf("W / H : %d %d \n",m_width,m_height);
if ( (m_width==0) || (m_height==0)) if ( (m_width==0) || (m_height==0))
{ {
itkExceptionMacro(<<"Dimension is undefined."); itkExceptionMacro(<<"Dimension is undefined.");
...@@ -282,33 +328,76 @@ void GDALImageIO::InternalReadImageInformation() ...@@ -282,33 +328,76 @@ void GDALImageIO::InternalReadImageInformation()
m_NbBands = m_poDataset->GetRasterCount(); m_NbBands = m_poDataset->GetRasterCount();
if (m_NbBands==0) if (m_NbBands==0)
{ {
//FIXME this happen in the case of a hdf file with SUBDATASETS
// in this situation, at least the first dataset should be open (ideally all in an imagelist)
// char** papszMetadata;
// papszMetadata = m_poDataset->GetMetadata("SUBDATASETS");
// if( CSLCount(papszMetadata) > 0 )
// {
// std::string key;
// itk::MetaDataDictionary & dict = this->GetMetaDataDictionary();
// for( int cpt = 0; papszMetadata[cpt] != NULL; cpt++ )
// {
// std::cout << papszMetadata[cpt] << std::endl;
// ::itk::OStringStream lStream;
// lStream << MetaDataKey::SubMetadataKey << cpt;
// key = lStream.str();
//
// itk::EncapsulateMetaData<std::string>(dict, key,
// static_cast<std::string>( papszMetadata[cpt] ) );
// }
// std::cout << dict[dict.GetKeys()[0]] << std::endl;
// std::cout << key << std::endl;
// }
itkExceptionMacro(<<"Zero band found in the dataset");
return;
}
this->SetNumberOfComponents(m_NbBands); // PART OF THE METADATAS
/** papszMetadata avec m_poDataset->GetMetadata */
char** papszMetadata;
papszMetadata = m_poDataset->GetMetadata("SUBDATASETS");
if( CSLCount(papszMetadata) > 0 )
{
std::string key;
itk::MetaDataDictionary & dict = this->GetMetaDataDictionary();
for( int cpt = 0; papszMetadata[cpt] != NULL; cpt++ )
{
std::cout << papszMetadata[cpt] << std::endl;
::itk::OStringStream lStream;
lStream << MetaDataKey::SubMetadataKey << cpt;
key = lStream.str();
itk::EncapsulateMetaData<std::string>(dict, key,
static_cast<std::string>( papszMetadata[cpt] ) );
}
std::cout << dict[dict.GetKeys()[0]] << std::endl;
std::cout << key << std::endl;
// PART OF THE SDS
/** papszSubdatasets avec GDALGetMetadata */
char **papszSubdatasets = GDALGetMetadata(m_poDataset,"SUBDATASETS");
int cpt2;
for( cpt2 = 0; papszSubdatasets[cpt2] != NULL; cpt2 += 2 )
{
/* argv[iSrcFileArg] = strstr(papszSubdatasets[i],"=")+1; */
lFileNameGdal = strstr(papszSubdatasets[cpt2],"=")+1;
std::cout<< "*--- SDS A LIRE : " << lFileNameGdal <<std::endl;
lFileNameGdal = "HDF4_SDS:EOS_SWATH:/home2/guillaume/ORFEO/OTB-Data/Input/Modis.hdf:MODIS_SWATH_Type_L1B:EV_1KM_RefSB";
//lFileNameGdal = "HDF4_SDS:MODIS_L1B:/home2/guillaume/ORFEO/OTB-Data/Input/Modis.hdf:1";
std::cout<< "*--- devient : " <<lFileNameGdal << std::endl;
m_FileName = lFileNameGdal;
// Read a SDS with GDAL
if (m_poDataset != NULL)
{
GDALClose(m_poDataset);
m_poDataset = NULL;
}
m_poDataset = static_cast<GDALDataset *>( GDALOpenShared(lFileNameGdal.c_str(), GA_ReadOnly ));
// Get image dimensions
m_width = m_poDataset->GetRasterXSize();
m_height = m_poDataset->GetRasterYSize();
std::cout<<"-----------W : " << m_width << " H :"<<m_height<<" nbBand : "<< m_NbBands<<std::endl;
/// TRICHE
m_width = 2030;
m_height = 1354;
// Get Number of Bands
m_NbBands = m_poDataset->GetRasterCount();
std::cout<<"-----------W : " << m_width << " H :"<<m_height<<" nbBand : "<< m_NbBands<<std::endl;
break;
}
} // fin if CSLCount
else
{
itkExceptionMacro(<<"Zero band found in the dataset");
return;
}
//GDALClose( hDataset );
this->SetNumberOfComponents(m_NbBands);
}
else
{
this->SetNumberOfComponents(m_NbBands);
}
// Set the number of dimensions (verify for the dim ) // Set the number of dimensions (verify for the dim )
this->SetNumberOfDimensions(2); this->SetNumberOfDimensions(2);
...@@ -325,13 +414,22 @@ void GDALImageIO::InternalReadImageInformation() ...@@ -325,13 +414,22 @@ void GDALImageIO::InternalReadImageInformation()
itkExceptionMacro(<<"Memory allocation error for the 'rasterBands'"); itkExceptionMacro(<<"Memory allocation error for the 'rasterBands'");
return; return;
} }
for (i=0; i<m_NbBands; ++i) for (i=0; i<m_NbBands; ++i)
m_poBands[i] = m_poDataset->GetRasterBand(i+1); m_poBands[i] = m_poDataset->GetRasterBand(i+1);
// Get Data Type // Get Data Type
// Consider only the data type given by the first band!!!!! // Consider only the data type given by the first band!!!!!
// Maybe be could changed (to check) // Maybe be could changed (to check)
m_PxType = m_poBands[0]->GetRasterDataType();
/// MARCHE PAS
//m_poBands[0]->SetRasterDataType(GDT_UInt16);
/// A DECOMMENTER
// m_PxType = m_poBands[0]->GetRasterDataType();
std::cout<< " JE TRICHE" <<std::endl;
std::cout<< m_PxType <<std::endl;
m_PxType = GDT_UInt16;
// Following the data type given by GDAL we set it for ImageIO // Following the data type given by GDAL we set it for ImageIO
// BE CAREFUL !!!! At this time the complex data type are regarded // BE CAREFUL !!!! At this time the complex data type are regarded
...@@ -426,10 +524,12 @@ void GDALImageIO::InternalReadImageInformation() ...@@ -426,10 +524,12 @@ void GDALImageIO::InternalReadImageInformation()
this-> SetNumberOfComponents(m_NbBands); this-> SetNumberOfComponents(m_NbBands);
if ( this->GetNumberOfComponents() == 1 ) if ( this->GetNumberOfComponents() == 1 )
{ {
std::cout<<"SCALAAAAAAAAAR" <<std::endl;
this->SetPixelType(SCALAR); this->SetPixelType(SCALAR);
} }
else else
{ {
std::cout<<"VECTOOOOOOOOOOOOOOR" <<std::endl;
this->SetPixelType(VECTOR); this->SetPixelType(VECTOR);
} }
} }
...@@ -444,7 +544,7 @@ void GDALImageIO::InternalReadImageInformation() ...@@ -444,7 +544,7 @@ void GDALImageIO::InternalReadImageInformation()
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
/* Get Spacing */ /* Get Spacing */
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
// Default Spacing // Default Spacing
...@@ -470,7 +570,7 @@ void GDALImageIO::InternalReadImageInformation() ...@@ -470,7 +570,7 @@ void GDALImageIO::InternalReadImageInformation()
static_cast<std::string>( GDALGetDriverLongName( hDriver ) ) ); static_cast<std::string>( GDALGetDriverLongName( hDriver ) ) );
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
/* Get the projection coordinate system of the image : ProjectionRef */ /* Get the projection coordinate system of the image : ProjectionRef */
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
if ( m_poDataset->GetProjectionRef() != NULL ) if ( m_poDataset->GetProjectionRef() != NULL )
......
...@@ -92,10 +92,14 @@ ImageFileReader<TOutputImage> ...@@ -92,10 +92,14 @@ ImageFileReader<TOutputImage>
//otbMsgDebugMacro( <<"ImageFileReader<TOutputImage>::GenerateData : "); //otbMsgDebugMacro( <<"ImageFileReader<TOutputImage>::GenerateData : ");
//otbMsgDebugMacro( <<" output->GetRequestedRegion() : "<<output->GetRequestedRegion()); //otbMsgDebugMacro( <<" output->GetRequestedRegion() : "<<output->GetRequestedRegion());
std::cout<< "ImageFileReader<TOutputImage>::GenerateData : " <<std::endl;
std::cout<<" output->GetRequestedRegion() : "<<output->GetRequestedRegion() <<std::endl;
// Test if the file exist and if it can be open. // Test if the file exist and if it can be open.
// and exception will be thrown otherwise. // and exception will be thrown otherwise.
this->TestFileExistanceAndReadability(); this->TestFileExistanceAndReadability();
std::cout<<" FILENAME ?? " << this->m_FileName.c_str()<<std::endl;
// Tell the ImageIO to read the file // Tell the ImageIO to read the file
// //
OutputImagePixelType *buffer = OutputImagePixelType *buffer =
...@@ -149,7 +153,7 @@ ImageFileReader<TOutputImage> ...@@ -149,7 +153,7 @@ ImageFileReader<TOutputImage>
//otbMsgDebugMacro( <<" Apres ioRegion : "<<ioRegion); //otbMsgDebugMacro( <<" Apres ioRegion : "<<ioRegion);
std::cout<< "ioRegion : "<<ioRegion<<std::endl;
this->m_ImageIO->SetIORegion(ioRegion); this->m_ImageIO->SetIORegion(ioRegion);
typedef itk::DefaultConvertPixelTraits< ITK_TYPENAME TOutputImage::IOPixelType > ConvertPixelTraits; typedef itk::DefaultConvertPixelTraits< ITK_TYPENAME TOutputImage::IOPixelType > ConvertPixelTraits;
...@@ -228,6 +232,7 @@ ImageFileReader<TOutputImage> ...@@ -228,6 +232,7 @@ ImageFileReader<TOutputImage>
// !!!! Update FileName // !!!! Update FileName
std::string lFileName; std::string lFileName;
bool found = GetGdalReadImageFileName(this->m_FileName,lFileName); bool found = GetGdalReadImageFileName(this->m_FileName,lFileName);
std::cout<<" GenerateOutputInformation : filename " << lFileName << std::endl;
if ( found == false ) if ( found == false )
{ {
otbMsgDebugMacro( <<"Filename was NOT unknowed. May be reconize by a Image factory ! "); otbMsgDebugMacro( <<"Filename was NOT unknowed. May be reconize by a Image factory ! ");
......
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