Skip to content
Snippets Groups Projects
Commit ba318921 authored by Thomas Feuvrier's avatar Thomas Feuvrier
Browse files

Correction pour lecture gros fichiers.

Code modifié : la méthode itk::ImageIOBase::GetImageSizeInBytes() permettant de calculer la taille
de l'image en bytes se fonctionne plus lorque les images sont trop grosses.
En effet, la valeur retournée est définie en unsigned int, unsiffisant pour les gros fichiers.
Cette méthode contient les appels successifs aux méthodes :
GetImageSizeInPixels() * NUmberOfComponents * GetComponentSize()
Solution : appeler nous même ces 3 méthodes en stockant le résultats dans un std::streamoff.
ATTENTION : Comme la méthode GetComponentSize() est protected, elle a été dupliquée dans la classe ImageFileReader (caca).
TODO : revoir celà.
parent af5cfead
No related branches found
No related tags found
No related merge requests found
......@@ -82,7 +82,6 @@ protected:
ImageFileReader();
~ImageFileReader();
void PrintSelf(std::ostream& os, itk::Indent indent) const;
private:
/** Test whether the given filename exist and it is readable,
......@@ -91,6 +90,10 @@ private:
doesn't exist or it is not readable, and exception with an
approriate message will be thrown. */
void TestFileExistanceAndReadability();
/** Copy of the GetComponentSize() method of the itk::ImageIOBase.
We need this value to calculate buffer size. */
virtual unsigned int GetComponentSize() const;
ImageFileReader(const Self&); //purposely not implemented
void operator=(const Self&); //purposely not implemented
......
......@@ -164,17 +164,24 @@ ImageFileReader<TOutputImage>
// regardles of the actual type of the pixels.
ImageRegionType region = output->GetBufferedRegion();
//THOMAS : PB : le GetImageSizeInBytes s'appuie sur m_Dimension lue, donc dimensions physique,de
// l'image (pas celle bufferisd ans la cas du streaming )
// l'image (pas celle bufferisd ans la cas du streaming )
// JULIEN: fix for the problem mentionned : the componentsize is computed here since ad hoc methods in
// itkImageIOBase are protected.
unsigned int componentSize = this->m_ImageIO->GetImageSizeInBytes();
for(unsigned int i=0;i<this->m_ImageIO->GetNumberOfDimensions();++i)
//THOMAS : PB with big file : "unsigned int" is not adapted. We use streamoff type.
// unsigned int componentSize = this->m_ImageIO->GetImageSizeInBytes();
std::streamoff componentSize;
componentSize = static_cast<std::streamoff>(this->m_ImageIO->GetImageSizeInPixels());
componentSize = componentSize * static_cast<std::streamoff>(this->m_ImageIO->GetNumberOfComponents());
// PB : the GetComponentSize() method of the itkImageIOBase class is protected.
// duplicated this method in this class (very BAD)
componentSize = componentSize * static_cast<std::streamoff>(this->GetComponentSize());
for(std::streamoff i=0;i<static_cast<std::streamoff>(this->m_ImageIO->GetNumberOfDimensions());++i)
{
componentSize = componentSize/this->m_ImageIO->GetDimensions(i);
componentSize = componentSize/static_cast<std::streamoff>(this->m_ImageIO->GetDimensions(i));
}
unsigned int nbBytes = componentSize*region.GetNumberOfPixels();
std::streamoff nbBytes = componentSize*static_cast<std::streamoff>(region.GetNumberOfPixels());
otbMsgDevMacro(<<"NbBytes "<<nbBytes);
otbMsgDevMacro(<< "Buffer conversion required from: "
......@@ -193,6 +200,40 @@ ImageFileReader<TOutputImage>
}
}
template <class TOutputImage>
unsigned int
ImageFileReader<TOutputImage>
::GetComponentSize() const
{
switch(this->m_ImageIO->GetComponentType())
{
case itk::ImageIOBase::UCHAR:
return sizeof(unsigned char);
case itk::ImageIOBase::CHAR:
return sizeof(char);
case itk::ImageIOBase::USHORT:
return sizeof(unsigned short);
case itk::ImageIOBase::SHORT:
return sizeof(short);
case itk::ImageIOBase::UINT:
return sizeof(unsigned int);
case itk::ImageIOBase::INT:
return sizeof(int);
case itk::ImageIOBase::ULONG:
return sizeof(unsigned long);
case itk::ImageIOBase::LONG:
return sizeof(long);
case itk::ImageIOBase::FLOAT:
return sizeof(float);
case itk::ImageIOBase::DOUBLE:
return sizeof(double);
case itk::ImageIOBase::UNKNOWNCOMPONENTTYPE:
default:
itkExceptionMacro ("Unknown component type: " << this->m_ImageIO->GetComponentType());
}
return 0;
}
template <class TOutputImage>
void
......
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