Orfeo Toolbox  4.0
otbRADImageIO.cxx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ORFEO Toolbox
4  Language: C++
5  Date: $Date$
6  Version: $Revision$
7 
8 
9  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10  See OTBCopyright.txt for details.
11 
12 
13  This software is distributed WITHOUT ANY WARRANTY; without even
14  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  PURPOSE. See the above copyright notices for more information.
16 
17 =========================================================================*/
18 #include "otbRADImageIO.h"
19 
20 #include <fstream>
21 #include <iostream>
22 
23 #include "itkByteSwapper.h"
24 #include "otbSystem.h"
25 #include "itksys/SystemTools.hxx"
26 
27 #include "otbMacro.h"
28 
29 
30 namespace otb
31 {
32 
34 {
35  // By default set number of dimensions to two.
36  this->SetNumberOfDimensions(2);
37 
38  // By default the type to CI2
39  m_TypeRAD = "CR4";
40  m_BytePerPixel = 8;
41  m_NbOfChannels = 1;
42  this->SetNumberOfComponents(2);
45 
47  {
49  }
50  else
51  {
53  }
54 
56 
57  // Set default spacing to one
58  m_Spacing[0] = 1.0;
59  m_Spacing[1] = 1.0;
60  // Set default origin to zero
61  m_Origin[0] = 0.0;
62  m_Origin[1] = 0.0;
65 
66  this->AddSupportedWriteExtension(".rad");
67  this->AddSupportedWriteExtension(".RAD");
68 
69  this->AddSupportedReadExtension(".rad");
70  this->AddSupportedReadExtension(".RAD");
71 
72 }
73 
75 {
76 
77  if (m_HeaderFile.is_open())
78  {
79  m_HeaderFile.close();
80  }
81  if (m_ChannelsFile != NULL)
82  {
83  for (unsigned int numChannel = 0; numChannel < m_NbOfChannels; ++numChannel)
84  {
85  if (m_ChannelsFile[numChannel].is_open())
86  {
87  m_ChannelsFile[numChannel].close();
88  }
89  }
90  delete[] m_ChannelsFile;
91  }
92 }
93 
94 bool RADImageIO::CanReadFile(const char* filename)
95 {
96  std::fstream header_file;
97  std::string lFileName(filename);
98  if (itksys::SystemTools::FileIsDirectory(lFileName.c_str()) == true)
99  {
100  return false;
101  }
102  if (itksys::SystemTools::LowerCase(itksys::SystemTools::GetFilenameLastExtension(lFileName)) != ".rad")
103  {
104  return false;
105  }
106 
107  header_file.open(lFileName.c_str(), std::ios::in);
108  if (header_file.fail())
109  {
110  otbMsgDevMacro(<< "RADImageIO::CanReadFile() failed header open ! ");
111  return false;
112  }
113 
114  //Read header informations
115  bool lResult = InternalReadHeaderInformation(lFileName, header_file, false);
116  header_file.close();
117  return (lResult);
118 }
119 
120 // Used to print information about this object
121 void RADImageIO::PrintSelf(std::ostream& os, itk::Indent indent) const
122 {
123  Superclass::PrintSelf(os, indent);
124 }
125 
126 // Read a 3D image (or event more bands)... not implemented yet
128 {
129 }
130 
131 // Read image
132 void RADImageIO::Read(void* buffer)
133 {
134  unsigned long step = this->GetNumberOfComponents();
135  char * p = static_cast<char *>(buffer);
136 
137  int lNbLines = this->GetIORegion().GetSize()[1];
138  int lNbColumns = this->GetIORegion().GetSize()[0];
139  int lFirstLine = this->GetIORegion().GetIndex()[1]; // [1... ]
140  int lFirstColumn = this->GetIORegion().GetIndex()[0]; // [1... ]
141 
142  otbMsgDevMacro(<< " RADImageIO::Read() ");
143  otbMsgDevMacro(<< " Image size : " << m_Dimensions[0] << "," << m_Dimensions[1]);
144  otbMsgDevMacro(<< " Region read (IORegion) : " << this->GetIORegion());
145  otbMsgDevMacro(<< " Nb Of Components : " << this->GetNumberOfComponents());
146  otbMsgDevMacro(<< " Size Of Components : " << this->GetComponentSize());
147  otbMsgDevMacro(<< " Nb Of Channels : " << m_NbOfChannels);
148 
149  std::streamoff headerLength(0);
150  std::streamoff offset;
151  std::streamoff numberOfBytesPerLines = static_cast<std::streamoff>(m_BytePerPixel * m_Dimensions[0]);
152  std::streamsize numberOfBytesToBeRead = m_BytePerPixel * lNbColumns;
153  std::streamsize numberOfBytesRead;
154  unsigned long cpt = 0;
155 
156  // Update the step variable
157  step = step * (unsigned long) (this->GetComponentSize());
158 
159  char * value = new char[numberOfBytesToBeRead];
160  if (value == NULL)
161  {
162  itkExceptionMacro(<< "RADImageIO::Read(): Bad alloc");
163  return;
164  }
165 
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));
170  otbMsgDevMacro(<< " sizeof(size_t) : " << sizeof(size_t));
171  otbMsgDevMacro(<< " sizeof(unsigned long) : " << sizeof(unsigned long));
172 
173  for (unsigned int numChannel = 0; numChannel < m_NbOfChannels; ++numChannel)
174  {
175  cpt = (unsigned long) (numChannel) * (unsigned long) (m_BytePerPixel);
176  //Read region of the channel
177  for (int LineNo = lFirstLine; LineNo < lFirstLine + lNbLines; LineNo++)
178  {
179  offset = headerLength + numberOfBytesPerLines * static_cast<std::streamoff>(LineNo);
180  offset += static_cast<std::streamoff>(m_BytePerPixel * lFirstColumn);
181  m_ChannelsFile[numChannel].seekg(offset, std::ios::beg);
182  //Read a line
183  m_ChannelsFile[numChannel].read(static_cast<char *>(value), numberOfBytesToBeRead);
184 
185  numberOfBytesRead = m_ChannelsFile[numChannel].gcount();
186 #ifdef __APPLE_CC__
187  // fail() is broken in the Mac. It returns true when reaches eof().
188  if (numberOfBytesRead != numberOfBytesToBeRead)
189 #else
190  if ((numberOfBytesRead != numberOfBytesToBeRead) || m_ChannelsFile[numChannel].fail())
191 #endif
192  {
193  itkExceptionMacro(<< "RADImageIO::Read() Can Read the specified Region"); // read failed
194  }
195  for (std::streamsize i = 0; i < numberOfBytesToBeRead; i = i + static_cast<std::streamsize>(m_BytePerPixel))
196  {
197  memcpy((void*) (&(p[cpt])), (const void*) (&(value[i])), (size_t) (m_BytePerPixel));
198  cpt += step;
199  }
200  }
201  }
202  unsigned long numberOfPixelsOfRegion = lNbLines * lNbColumns * this->GetNumberOfComponents();
203 
204  // Swap bytes if necessary
205  if (0) {}
206  otbSwappFileToSystemMacro(unsigned short, USHORT, buffer, numberOfPixelsOfRegion)
207  otbSwappFileToSystemMacro(short, SHORT, buffer, numberOfPixelsOfRegion)
208  otbSwappFileToSystemMacro(char, CHAR, buffer, numberOfPixelsOfRegion)
209  otbSwappFileToSystemMacro(unsigned char, UCHAR, buffer, numberOfPixelsOfRegion)
210  otbSwappFileToSystemMacro(unsigned int, UINT, buffer, numberOfPixelsOfRegion)
211  otbSwappFileToSystemMacro(int, INT, buffer, numberOfPixelsOfRegion)
212  otbSwappFileToSystemMacro(long, LONG, buffer, numberOfPixelsOfRegion)
213  otbSwappFileToSystemMacro(unsigned long, ULONG, buffer, numberOfPixelsOfRegion)
214  otbSwappFileToSystemMacro(float, FLOAT, buffer, numberOfPixelsOfRegion)
215  otbSwappFileToSystemMacro(double, DOUBLE, buffer, numberOfPixelsOfRegion)
216  else
217  {
218  itkExceptionMacro(<< "RADImageIO::Read() undefined component type! ");
219  }
220 
221  delete[] value;
222  value = NULL;
223 
224 }
225 
227 {
228  if (m_HeaderFile.is_open())
229  {
230  m_HeaderFile.close();
231  }
232  m_HeaderFile.open(m_FileName.c_str(), std::ios::in);
233  if (m_HeaderFile.fail())
234  {
235  itkExceptionMacro(<< "RADImageIO::ReadImageInformation() failed header open ! ");
236  }
237 
238  //Read header informations
240 
241  otbMsgDebugMacro(<< "Driver to read: RAD");
242  otbMsgDebugMacro(<< " Read file : " << m_FileName);
243  otbMsgDebugMacro(<< " Size : " << m_Dimensions[0] << "," << m_Dimensions[1]);
244  otbMsgDebugMacro(<< " ComponentType : " << this->GetComponentType());
245  otbMsgDebugMacro(<< " NumberOfComponents : " << this->GetNumberOfComponents());
246  otbMsgDebugMacro(<< " ComponentSize : " << this->GetComponentSize());
247  otbMsgDebugMacro(<< " GetPixelSize : " << this->GetPixelSize());
248 
249 }
250 
251 bool RADImageIO::InternalReadHeaderInformation(const std::string& file_name, std::fstream& file, const bool reportError)
252 {
253 
254  std::string lString;
255  std::string lStrCodePix;
256 
257  // Read NBCOLONNES information
258  file >> lString;
259  lString = itksys::SystemTools::UpperCase(lString);
260  if ((lString != "NBCOLONNES") && (lString != "NBCOLUMNS"))
261  {
262  if (reportError == true)
263  {
264  itkExceptionMacro(<< "RAD : 'NBCOLONNES' keyword is not find in the header file.");
265  }
266  else
267  {
268  return false;
269  }
270  }
271  file >> m_Dimensions[0];
272 
273  // Read NBLIGNES information
274  file >> lString;
275  lString = itksys::SystemTools::UpperCase(lString);
276  if ((lString != "NBLIGNES") && (lString != "NBLINES"))
277  {
278  if (reportError == true)
279  {
280  itkExceptionMacro(<< "RAD : 'NBLIGNES' keyword is not find in the header file.");
281  }
282  else
283  {
284  return false;
285  }
286  }
287  file >> m_Dimensions[1];
288 
289  // Read NBPLANS information
290  file >> lString;
291  lString = itksys::SystemTools::UpperCase(lString);
292  if ((lString != "NBPLANS") && (lString != "NBBANDS"))
293  {
294  if (reportError == true)
295  {
296  itkExceptionMacro(<< "RAD : 'NBPLANS' keyword is not find in the header file.");
297  }
298  else
299  {
300  return false;
301  }
302  }
303  file >> m_NbOfChannels;
304  // Because we read complex : *2
305  this->SetNumberOfComponents(2 * m_NbOfChannels);
306 
307  // Read TYPECODAGE information
308  file >> lString;
309  lString = itksys::SystemTools::UpperCase(lString);
310  if ((lString != "TYPECODAGE") && (lString != "TYPE"))
311  {
312  if (reportError == true)
313  {
314  itkExceptionMacro(<< "RAD : the first line of the header file must be contains 'TYPECODAGE' caracters.");
315  }
316  else
317  {
318  return false;
319  }
320  }
321  file >> lStrCodePix;
322 
323  lStrCodePix = itksys::SystemTools::UpperCase(lStrCodePix);
324  if (lStrCodePix == "OCT")
325  {
328  m_BytePerPixel = 1;
329  }
330  if (lStrCodePix == "PHA")
331  {
334  m_BytePerPixel = 1;
335  }
336  if (lStrCodePix == "I2")
337  {
340  m_BytePerPixel = 2;
341  }
342  if (lStrCodePix == "I4")
343  {
346  m_BytePerPixel = 4;
347  }
348  if (lStrCodePix == "R4")
349  {
352  m_BytePerPixel = 4;
353  }
354  else if (lStrCodePix == "CI2")
355  {
358  m_BytePerPixel = 4;
359  }
360  else if (lStrCodePix == "CR4")
361  {
364  m_BytePerPixel = 8;
365  }
366  else if (lStrCodePix == "COCT")
367  {
370  m_BytePerPixel = 2;
371  }
372  /* else if(lStrCodePix == "C3B")
373  {
374  m_PixelType = COMPLEX;
375  SetComponentType(FLOAT);
376  m_BytePerPixel=2;
377  }
378  else if(lStrCodePix == "C5B")
379  {
380  m_PixelType = COMPLEX;
381  SetComponentType(FLOAT);
382  m_BytePerPixel=2;
383  }
384  else if(lStrCodePix == "C7B")
385  {
386  m_PixelType = COMPLEX;
387  SetComponentType(FLOAT);
388  m_BytePerPixel=2;
389  }
390  */
391 
392  else if (lStrCodePix == "CI4")
393  {
396  m_BytePerPixel = 8;
397  }
398  else if (lStrCodePix == "CR8")
399  {
402  m_BytePerPixel = 16;
403  }
404  else
405  {
406  if (reportError == true)
407  {
408  itkExceptionMacro(
409  << "RAD : the value type '" << lStrCodePix <<
410  "' (second line) set in the header file is not reconized as correct value.");
411  }
412  else
413  {
414  return false;
415  }
416  }
417 
418  // Read "SENSCODAGE" informations (optionnal)
419  file >> lString;
420  if (lString.empty() == false)
421  {
422  lString = itksys::SystemTools::UpperCase(lString);
423  if ((lString == "SENSCODAGE") || (lString == "ORDER"))
424  {
425  file >> lString;
426  lString = itksys::SystemTools::UpperCase(lString);
427  if (lString == "INTEL")
428  {
430  }
431  else if (lString == "IEEE")
432  {
434  }
435  else
436  {
437  if (reportError == true)
438  {
439  itkExceptionMacro(
440  << "RAD : the value SENSCODAGE '" << lString <<
441  "' set in the header file is not reconized as correct value. Possible values are INTEL or IEEE");
442  }
443  else
444  {
445  return false;
446  }
447  }
448  }
449  }
450 
451  // Read FileName information
452  std::string lPathName = itksys::SystemTools::GetFilenamePath(file_name);
453  m_ChannelsFileName.clear();
454  for (unsigned int i = 0; i < m_NbOfChannels; ++i)
455  {
456  file >> lString;
457  std::ostringstream lStream;
458  lStream << lPathName << "/" << lString;
459  m_ChannelsFileName.push_back(lStream.str());
460 
461  }
462  file.close();
463 
464  m_ChannelsFile = new std::fstream[m_NbOfChannels];
465 
466  // Try to open channels file
467  for (unsigned int channels = 0; channels < m_ChannelsFileName.size(); ++channels)
468  {
469 
470  m_ChannelsFile[channels].open(m_ChannelsFileName[channels].c_str(), std::ios::in | std::ios::binary);
471  if (m_ChannelsFile[channels].fail())
472  {
473  if (reportError == true)
474  {
475  itkExceptionMacro(<< "RAD : impossible to find the file <" << m_ChannelsFileName[channels] << ">.");
476  }
477  else
478  {
479  return false;
480  }
481  }
482  }
483  this->SetFileTypeToBinary();
484  this->SetNumberOfDimensions(2);
485 
486  return (true);
487 }
488 
489 bool RADImageIO::CanWriteFile(const char* filename)
490 {
491  std::string lFileName(filename);
492  if (itksys::SystemTools::LowerCase(itksys::SystemTools::GetFilenameLastExtension(lFileName)) != ".rad")
493  {
494  return false;
495  }
496  if (itksys::SystemTools::FileIsDirectory(lFileName.c_str()) == true)
497  {
498  return false;
499  }
500  return true;
501 }
502 
503 void RADImageIO::Write(const void* buffer)
504 {
505 
506  if (m_FlagWriteImageInformation == true)
507  {
508  this->WriteImageInformation();
510  }
511 
512  unsigned long step = this->GetNumberOfComponents();
513  unsigned int lNbLines = this->GetIORegion().GetSize()[1];
514  unsigned int lNbColumns = this->GetIORegion().GetSize()[0];
515  int lFirstLine = this->GetIORegion().GetIndex()[1]; // [1... ]
516  int lFirstColumn = this->GetIORegion().GetIndex()[0]; // [1... ]
517 
518  // Special case : we control that if the region to write has the same dimension that the entire picture,
519  // we start to the offset to 0 ( when ze4re not in "Streaming")
520  if ((lNbLines == m_Dimensions[1]) && (lNbColumns == m_Dimensions[0]))
521  {
522  otbMsgDevMacro(<< "Force the IORegion offset to 0");
523  lFirstLine = 0;
524  lFirstColumn = 0;
525  }
526 
527  otbMsgDevMacro(<< " RADImageIO::Write() ");
528  otbMsgDevMacro(<< " Image size : " << m_Dimensions[0] << "," << m_Dimensions[1]);
529  otbMsgDevMacro(<< " Region read (IORegion) : " << this->GetIORegion());
530  otbMsgDevMacro(<< " Nb Of Components : " << this->GetNumberOfComponents());
531  otbMsgDevMacro(<< " GetComponentSize : " << this->GetComponentSize());
532 
533  std::streamoff headerLength(0);
534  std::streamoff numberOfBytesPerLines = static_cast<std::streamoff>(m_BytePerPixel * m_Dimensions[0]);
535  std::streamsize numberOfBytesToBeWrite = static_cast<std::streamsize>(m_BytePerPixel * lNbColumns);
536 
537  std::streamoff offset = 0;
538  unsigned long cpt = 0;
539 
540  // Update the step variable
541  step = m_BytePerPixel;
542 
543  const char * p = static_cast<const char *>(buffer);
544 
545  char* value = new char[numberOfBytesToBeWrite];
546  if (value == NULL)
547  {
548  itkExceptionMacro(<< "RADImageIO::Write : Bad Alloc");
549  return;
550  }
551 
552  for (unsigned int numChannel = 0; numChannel < m_NbOfChannels; ++numChannel)
553  {
554  cpt = (unsigned long) (numChannel) * (unsigned long) (m_BytePerPixel);
555  //Read region of the channel
556  for (unsigned int LineNo = lFirstLine; LineNo < lFirstLine + lNbLines; LineNo++)
557  {
558  for (std::streamsize i = 0; i < numberOfBytesToBeWrite; i = i + static_cast<std::streamsize>(m_BytePerPixel))
559  {
560  memcpy((void*) (&(value[i])), (const void*) (&(p[cpt])), (size_t) (m_BytePerPixel));
561  cpt += step;
562  }
563 
564  offset = headerLength + numberOfBytesPerLines * static_cast<std::streamoff>(LineNo);
565  offset += static_cast<std::streamoff>(m_BytePerPixel * lFirstColumn);
566  m_ChannelsFile[numChannel].seekp(offset, std::ios::beg);
567  //Write a line
568  m_ChannelsFile[numChannel].write(static_cast<char *>(value), numberOfBytesToBeWrite);
569  }
570  }
571 
572  delete[] value;
573 }
574 
576 {
577  if (m_FileName == "")
578  {
579  itkExceptionMacro(<< "A FileName must be specified.");
580  }
581  if (CanWriteFile(m_FileName.c_str()) == false)
582  {
583  itkExceptionMacro(<< "The file " << m_FileName.c_str() << " is not defined as a RAD file");
584  }
585 
586  // Close file from any previous image
587  if (m_HeaderFile.is_open())
588  {
589  m_HeaderFile.close();
590  }
591 
592  // Open the new file for writing
593  // Actually open the file
594  m_HeaderFile.open(m_FileName.c_str(), std::ios::out | std::ios::trunc);
595  if (m_HeaderFile.fail())
596  {
597  itkExceptionMacro(<< "Cannot write requested file " << m_FileName.c_str() << ".");
598  }
599 
600  //Write COLUMNS information
601  m_HeaderFile << "NBCOLUMNS ";
602  m_HeaderFile << m_Dimensions[0] << std::endl;
603 
604  //Write LINES information
605  m_HeaderFile << "NBLINES ";
606  m_HeaderFile << m_Dimensions[1] << std::endl;
607 
608  //Write CHANNELS information
609  m_HeaderFile << "NBBANDS ";
610  m_HeaderFile << m_NbOfChannels << std::endl;
611 
612  std::string lString;
613  //Write TYPE information
614  m_HeaderFile << "TYPECODAGE ";
615 
616  std::string lExtension;
617  std::string lStringPixelType = itksys::SystemTools::UpperCase(this->GetPixelTypeAsString(m_PixelType));
618  std::string lStringComponentType = itksys::SystemTools::UpperCase(this->GetComponentTypeAsString(this->GetComponentType()));
619 
620  if (lStringPixelType == "SCALAR")
621  {
622  if (lStringComponentType == "UCHAR")
623  {
624  m_BytePerPixel = 1;
625  m_TypeRAD = "OCT";
626  lExtension = ".oct";
627  }
628  else if (lStringComponentType == "CHAR")
629  {
630  m_BytePerPixel = 1;
631  m_TypeRAD = "PHA";
632  lExtension = ".pha";
633  }
634  else if (lStringComponentType == "SHORT")
635  {
636  m_BytePerPixel = 2;
637  m_TypeRAD = "I2";
638  lExtension = ".i2";
639  }
640  else if (lStringComponentType == "INT")
641  {
642  m_BytePerPixel = 4;
643  m_TypeRAD = "I4";
644  lExtension = ".i4";
645  }
646  else if (lStringComponentType == "FLOAT")
647  {
648  m_BytePerPixel = 4;
649  m_TypeRAD = "R4";
650  lExtension = ".r4";
651 
652  }
653  }
654  else if (lStringPixelType == "COMPLEX")
655  {
656  if (lStringComponentType == "SHORT")
657  {
658 
659  m_BytePerPixel = 4;
660  m_TypeRAD = "CI2";
661  lExtension = ".ci2";
662  }
663  else if (lStringComponentType == "FLOAT")
664  {
665  m_BytePerPixel = 8;
666  m_TypeRAD = "CR4";
667  lExtension = ".cr4";
668  }
669  if (lStringComponentType == "CHAR")
670  {
671  m_BytePerPixel = 2;
672  m_TypeRAD = "COCT";
673  lExtension = ".coct";
674  }
675  /* if( this->GetComponentType()=="FLOAT")
676  {
677  m_BytePerPixel=2;
678  m_TypeRAD = "C3B"
679  }
680  if( this->GetComponentType()==FLOAT)
681  {
682  m_BytePerPixel=2;
683  m_TypeRAD = "C5B"
684  }
685  if( this->GetComponentType()==FLOAT)
686  {
687  m_BytePerPixel=2;
688  m_TypeRAD = "C7B"
689  }
690  */
691  else if (lStringComponentType == "INT")
692  {
693  m_BytePerPixel = 8;
694  m_TypeRAD = "CI4";
695  lExtension = ".ci4";
696  }
697  else if (lStringComponentType == "DOUBLE")
698  {
699  m_BytePerPixel = 16;
700  m_TypeRAD = "CR8";
701  lExtension = ".cr8";
702  }
703  }
704  m_HeaderFile << m_TypeRAD << std::endl;
705 
706  //Write "SENSCODAGE" informations
707  m_HeaderFile << "SENSCODAGE "; // << std::endl;
708  if (m_ByteOrder == LittleEndian)
709  {
710  m_HeaderFile << "INTEL" << std::endl;
711  }
712  else
713  {
714  m_HeaderFile << "IEEE" << std::endl;
715  }
716 
717  //Define channels file name
718  std::string lRootName = System::GetRootName(m_FileName);
719  m_ChannelsFileName.clear();
720  for (unsigned int i = 0; i < m_NbOfChannels; ++i)
721  {
722  std::ostringstream lStream;
723  lStream << lRootName << "_" << i + 1 << lExtension;
724  m_ChannelsFileName.push_back(lStream.str());
725  }
726 
727  for (unsigned int i = 0; i < m_NbOfChannels; ++i)
728  {
729  m_HeaderFile << itksys::SystemTools::GetFilenameName(this->m_ChannelsFileName[i].c_str()) << std::endl;
730  }
731  m_HeaderFile.close();
732 
733  //Allocate buffer of stream file
734  m_ChannelsFile = new std::fstream[m_NbOfChannels];
735 
736  //Try to open channels file
737  for (unsigned int channels = 0; channels < m_ChannelsFileName.size(); ++channels)
738  {
739  m_ChannelsFile[channels].open(
740  m_ChannelsFileName[channels].c_str(), std::ios::out | std::ios::trunc | std::ios::binary);
741  if (m_ChannelsFile[channels].fail())
742  {
743  itkExceptionMacro(<< "RAD : impossible to find the file <" << m_ChannelsFileName[channels] << ">.");
744  }
745  }
746  this->SetFileTypeToBinary();
747  this->SetNumberOfDimensions(2);
748  this->SetNumberOfComponents(2 * m_NbOfChannels);
749 
750  unsigned long numberOfBytesPerLines = m_BytePerPixel * m_Dimensions[0];
751  char* value = new char[numberOfBytesPerLines];
752 
753  for (unsigned int channels = 0; channels < m_ChannelsFileName.size(); ++channels)
754  {
755  m_ChannelsFile[channels].seekp(0, std::ios::beg);
756  //Write Header line and all file (whitout information)
757  for (unsigned int numLigne = 0; numLigne < (m_Dimensions[1]); numLigne++)
758  {
759  m_ChannelsFile[channels].write(value, numberOfBytesPerLines);
760  }
761  }
762 
763  delete[] value;
764 
765  otbMsgDebugMacro(<< "Driver to write: RAD");
766  otbMsgDebugMacro(<< " Write file : " << m_FileName);
767  otbMsgDebugMacro(<< " Size : " << m_Dimensions[0] << "," << m_Dimensions[1]);
768  otbMsgDebugMacro(<< " Type Rad : " << m_TypeRAD);
769  otbMsgDebugMacro(<< " ComponentType : " << this->GetComponentType());
770  otbMsgDebugMacro(<< " NumberOfComponents : " << this->GetNumberOfComponents());
771  otbMsgDebugMacro(<< " ComponentSize : " << this->GetComponentSize());
772  otbMsgDebugMacro(<< " GetPixelSize : " << this->GetPixelSize());
773 
774 }
775 
776 } // end namespace otb

Generated at Sat Mar 8 2014 16:14:28 for Orfeo Toolbox with doxygen 1.8.3.1