24 #include "itksys/SystemTools.hxx"
83 for (
unsigned int numChannel = 0; numChannel <
m_NbOfChannels; ++numChannel)
96 std::fstream header_file;
97 std::string lFileName(filename);
107 header_file.open(lFileName.c_str(), std::ios::in);
108 if (header_file.fail())
110 otbMsgDevMacro(<<
"RADImageIO::CanReadFile() failed header open ! ");
135 char * p =
static_cast<char *
>(buffer);
149 std::streamoff headerLength(0);
150 std::streamoff offset;
152 std::streamsize numberOfBytesToBeRead =
m_BytePerPixel * lNbColumns;
153 std::streamsize numberOfBytesRead;
154 unsigned long cpt = 0;
159 char * value =
new char[numberOfBytesToBeRead];
162 itkExceptionMacro(<<
"RADImageIO::Read(): Bad alloc");
166 otbMsgDevMacro(<<
" sizeof(streamsize) : " <<
sizeof(std::streamsize));
167 otbMsgDevMacro(<<
" sizeof(streampos) : " <<
sizeof(std::streampos));
168 otbMsgDevMacro(<<
" sizeof(streamoff) : " <<
sizeof(std::streamoff));
169 otbMsgDevMacro(<<
" sizeof(std::ios::beg) : " <<
sizeof(std::ios::beg));
171 otbMsgDevMacro(<<
" sizeof(unsigned long) : " <<
sizeof(
unsigned long));
173 for (
unsigned int numChannel = 0; numChannel <
m_NbOfChannels; ++numChannel)
175 cpt = (
unsigned long) (numChannel) * (
unsigned long) (
m_BytePerPixel);
177 for (
int LineNo = lFirstLine; LineNo < lFirstLine + lNbLines; LineNo++)
179 offset = headerLength + numberOfBytesPerLines *
static_cast<std::streamoff
>(LineNo);
180 offset +=
static_cast<std::streamoff
>(
m_BytePerPixel * lFirstColumn);
183 m_ChannelsFile[numChannel].read(static_cast<char *>(value), numberOfBytesToBeRead);
188 if (numberOfBytesRead != numberOfBytesToBeRead)
190 if ((numberOfBytesRead != numberOfBytesToBeRead) ||
m_ChannelsFile[numChannel].fail())
193 itkExceptionMacro(<<
"RADImageIO::Read() Can Read the specified Region");
195 for (std::streamsize i = 0; i < numberOfBytesToBeRead; i = i + static_cast<std::streamsize>(
m_BytePerPixel))
197 memcpy((
void*) (&(p[cpt])), (
const void*) (&(value[i])), (
size_t) (
m_BytePerPixel));
218 itkExceptionMacro(<<
"RADImageIO::Read() undefined component type! ");
235 itkExceptionMacro(<<
"RADImageIO::ReadImageInformation() failed header open ! ");
255 std::string lStrCodePix;
260 if ((lString !=
"NBCOLONNES") && (lString !=
"NBCOLUMNS"))
262 if (reportError ==
true)
264 itkExceptionMacro(<<
"RAD : 'NBCOLONNES' keyword is not find in the header file.");
276 if ((lString !=
"NBLIGNES") && (lString !=
"NBLINES"))
278 if (reportError ==
true)
280 itkExceptionMacro(<<
"RAD : 'NBLIGNES' keyword is not find in the header file.");
287 file >> m_Dimensions[1];
292 if ((lString !=
"NBPLANS") && (lString !=
"NBBANDS"))
294 if (reportError ==
true)
296 itkExceptionMacro(<<
"RAD : 'NBPLANS' keyword is not find in the header file.");
310 if ((lString !=
"TYPECODAGE") && (lString !=
"TYPE"))
312 if (reportError ==
true)
314 itkExceptionMacro(<<
"RAD : the first line of the header file must be contains 'TYPECODAGE' caracters.");
324 if (lStrCodePix ==
"OCT")
330 if (lStrCodePix ==
"PHA")
336 if (lStrCodePix ==
"I2")
342 if (lStrCodePix ==
"I4")
348 if (lStrCodePix ==
"R4")
354 else if (lStrCodePix ==
"CI2")
360 else if (lStrCodePix ==
"CR4")
366 else if (lStrCodePix ==
"COCT")
392 else if (lStrCodePix ==
"CI4")
398 else if (lStrCodePix ==
"CR8")
406 if (reportError ==
true)
409 <<
"RAD : the value type '" << lStrCodePix <<
410 "' (second line) set in the header file is not reconized as correct value.");
420 if (lString.empty() ==
false)
423 if ((lString ==
"SENSCODAGE") || (lString ==
"ORDER"))
427 if (lString ==
"INTEL")
431 else if (lString ==
"IEEE")
437 if (reportError ==
true)
440 <<
"RAD : the value SENSCODAGE '" << lString <<
441 "' set in the header file is not reconized as correct value. Possible values are INTEL or IEEE");
457 std::ostringstream lStream;
458 lStream << lPathName <<
"/" << lString;
473 if (reportError ==
true)
475 itkExceptionMacro(<<
"RAD : impossible to find the file <" <<
m_ChannelsFileName[channels] <<
">.");
491 std::string lFileName(filename);
533 std::streamoff headerLength(0);
535 std::streamsize numberOfBytesToBeWrite =
static_cast<std::streamsize
>(
m_BytePerPixel * lNbColumns);
537 std::streamoff offset = 0;
538 unsigned long cpt = 0;
543 const char * p =
static_cast<const char *
>(buffer);
545 char* value =
new char[numberOfBytesToBeWrite];
548 itkExceptionMacro(<<
"RADImageIO::Write : Bad Alloc");
552 for (
unsigned int numChannel = 0; numChannel <
m_NbOfChannels; ++numChannel)
554 cpt = (
unsigned long) (numChannel) * (
unsigned long) (
m_BytePerPixel);
556 for (
unsigned int LineNo = lFirstLine; LineNo < lFirstLine + lNbLines; LineNo++)
558 for (std::streamsize i = 0; i < numberOfBytesToBeWrite; i = i + static_cast<std::streamsize>(
m_BytePerPixel))
560 memcpy((
void*) (&(value[i])), (
const void*) (&(p[cpt])), (
size_t) (
m_BytePerPixel));
564 offset = headerLength + numberOfBytesPerLines *
static_cast<std::streamoff
>(LineNo);
565 offset +=
static_cast<std::streamoff
>(
m_BytePerPixel * lFirstColumn);
568 m_ChannelsFile[numChannel].write(static_cast<char *>(value), numberOfBytesToBeWrite);
579 itkExceptionMacro(<<
"A FileName must be specified.");
583 itkExceptionMacro(<<
"The file " <<
m_FileName.c_str() <<
" is not defined as a RAD file");
597 itkExceptionMacro(<<
"Cannot write requested file " <<
m_FileName.c_str() <<
".");
616 std::string lExtension;
620 if (lStringPixelType ==
"SCALAR")
622 if (lStringComponentType ==
"UCHAR")
628 else if (lStringComponentType ==
"CHAR")
634 else if (lStringComponentType ==
"SHORT")
640 else if (lStringComponentType ==
"INT")
646 else if (lStringComponentType ==
"FLOAT")
654 else if (lStringPixelType ==
"COMPLEX")
656 if (lStringComponentType ==
"SHORT")
663 else if (lStringComponentType ==
"FLOAT")
669 if (lStringComponentType ==
"CHAR")
673 lExtension =
".coct";
691 else if (lStringComponentType ==
"INT")
697 else if (lStringComponentType ==
"DOUBLE")
722 std::ostringstream lStream;
723 lStream << lRootName <<
"_" << i + 1 << lExtension;
740 m_ChannelsFileName[channels].c_str(), std::ios::out | std::ios::trunc | std::ios::binary);
743 itkExceptionMacro(<<
"RAD : impossible to find the file <" <<
m_ChannelsFileName[channels] <<
">.");
751 char* value =
new char[numberOfBytesPerLines];
757 for (
unsigned int numLigne = 0; numLigne < (m_Dimensions[1]); numLigne++)
767 otbMsgDebugMacro(<<
" Size : " << m_Dimensions[0] <<
"," << m_Dimensions[1]);