Orfeo Toolbox  3.16
itkVoxBoCUBImageIO.cxx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkVoxBoCUBImageIO.cxx,v $
5  Language: C++
6  Date: $Date: 2009-11-29 02:06:56 $
7  Version: $Revision: 1.12 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 #include "itkVoxBoCUBImageIO.h"
18 #include "itkIOCommon.h"
19 #include "itkExceptionObject.h"
20 #include "itkMetaDataObject.h"
21 #include "itkByteSwapper.h"
22 #include <itksys/SystemTools.hxx>
23 #include <iostream>
24 #include <list>
25 #include <string>
26 #include <math.h>
27 #include <time.h>
28 
29 
30 #include "itk_zlib.h"
31 
32 namespace itk {
33 
34 
51 {
52 public:
55 
57 
58  virtual unsigned char ReadByte() = 0;
59  virtual void ReadData(void *data, SizeType bytes) = 0;
60  virtual void WriteData(const void *data, SizeType bytes) = 0;
61 
62  std::string ReadHeader()
63  {
64  // Read everything up to the \f symbol
65  itksys_ios::ostringstream oss;
66  unsigned char byte = ReadByte();
67  while(byte != '\f')
68  {
69  oss << byte;
70  byte = ReadByte();
71  }
72 
73  // Read the next byte
74  unsigned char term = ReadByte();
75  if(term == '\r')
76  {
77  term = ReadByte();
78  }
79  // Throw exception if term is not there
80  if(term != '\n')
81  {
82  ExceptionObject exception;
83  exception.SetDescription("Header is not terminated by newline.");
84  throw exception;
85  }
86 
87  // Return the header string
88  return oss.str();
89  }
90 };
91 
97 {
98 public:
99  CompressedCUBFileAdaptor(const char *file, const char *mode)
100  {
101  m_GzFile = ::gzopen(file, mode);
102  if(m_GzFile == NULL)
103  {
104  ExceptionObject exception;
105  exception.SetDescription("File cannot be accessed");
106  throw exception;
107  }
108  }
109 
111  {
112  if(m_GzFile)
113  {
114  ::gzflush(m_GzFile,Z_FINISH);
115  ::gzclose(m_GzFile);
116  }
117  }
118 
119  unsigned char ReadByte()
120  {
121  int byte = ::gzgetc(m_GzFile);
122  if(byte < 0)
123  {
124  itksys_ios::ostringstream oss;
125  oss << "Error reading byte from file at position: " << ::gztell(m_GzFile);
126  ExceptionObject exception;
127  exception.SetDescription(oss.str().c_str());
128  throw exception;
129  }
130  return static_cast<unsigned char>(byte);
131  }
132 
133  void ReadData(void *data, SizeType bytes)
134  {
135  if(m_GzFile == NULL)
136  {
137  ExceptionObject exception;
138  exception.SetDescription("File cannot be read");
139  throw exception;
140  }
141 
142  unsigned int numberOfBytesToRead = Math::CastWithRangeCheck< unsigned int, SizeType >( bytes );
143  SizeType bread = ::gzread(m_GzFile, data, numberOfBytesToRead );
144  if( bread != bytes )
145  {
146  itksys_ios::ostringstream oss;
147  oss << "File size does not match header: "
148  << bytes << " bytes requested but only "
149  << bread << " bytes available!" << std::endl
150  << "At file position " << ::gztell(m_GzFile);
151  ExceptionObject exception;
152  exception.SetDescription(oss.str().c_str());
153  throw exception;
154  }
155  }
156 
157  void WriteData(const void *data, SizeType bytes)
158  {
159  if(m_GzFile == NULL)
160  {
161  ExceptionObject exception;
162  exception.SetDescription("File cannot be written");
163  throw exception;
164  }
165 
166  unsigned int numberOfBytesToWrite = Math::CastWithRangeCheck< unsigned int, SizeType >( bytes );
167  SizeType bwritten = ::gzwrite(m_GzFile, const_cast<void *>(data), numberOfBytesToWrite);
168  if( bwritten != bytes )
169  {
170  ExceptionObject exception;
171  exception.SetDescription("Could not write all bytes to file");
172  std::cout << "Could not write all bytes to file" << std::endl;
173  throw exception;
174  }
175  ::gzflush(m_GzFile,Z_SYNC_FLUSH);
176  }
177 
178 private:
179  gzFile m_GzFile;
180 };
181 
182 
187 {
188 public:
189  DirectCUBFileAdaptor(const char *file, const char *mode)
190  {
191  m_File = fopen(file, mode);
192  if(!m_File)
193  {
194  ExceptionObject exception;
195  exception.SetDescription("File cannot be read");
196  throw exception;
197  }
198  }
199 
201  {
202  if(m_File)
203  {
204  fclose(m_File);
205  }
206  }
207 
208  unsigned char ReadByte()
209  {
210  int byte = fgetc(m_File);
211  if(byte == EOF)
212  {
213  itksys_ios::ostringstream oss;
214  oss << "Error reading byte from file at position: " << ::ftell(m_File);
215  ExceptionObject exception;
216  exception.SetDescription(oss.str().c_str());
217  throw exception;
218  }
219  return static_cast<unsigned char>(byte);
220  }
221 
222  void ReadData(void *data, SizeType bytes)
223  {
224  if(m_File == NULL)
225  {
226  ExceptionObject exception;
227  exception.SetDescription("File cannot be read");
228  throw exception;
229  }
230 
231  const size_t numberOfBytesToRead = Math::CastWithRangeCheck< size_t, SizeType >( bytes );
232  SizeType bread = fread(data, NumericTraits<size_t>::One, numberOfBytesToRead, m_File);
233  if( bread != bytes )
234  {
235  itksys_ios::ostringstream oss;
236  oss << "File size does not match header: "
237  << bytes << " bytes requested but only "
238  << bread << " bytes available!" << std::endl
239  << "At file position " << ftell(m_File);
240  ExceptionObject exception;
241  exception.SetDescription(oss.str().c_str());
242  throw exception;
243  }
244  }
245 
246  void WriteData(const void *data, SizeType bytes)
247  {
248  if(m_File == NULL)
249  {
250  ExceptionObject exception;
251  exception.SetDescription("File cannot be written");
252  throw exception;
253  }
254 
255  const size_t numberOfBytesToWrite = Math::CastWithRangeCheck< size_t, SizeType >( bytes );
256  SizeType bwritten = fwrite(data, NumericTraits<size_t>::One, numberOfBytesToWrite, m_File);
257  if( bwritten != bytes )
258  {
259  ExceptionObject exception;
260  exception.SetDescription("Could not write all bytes to file");
261  throw exception;
262  }
263  }
264 
265 private:
266  FILE *m_File;
267 };
268 
269 
277 template<typename TPixel>
279 {
280 public:
283 
284  static void SwapIfNecessary(
285  void *buffer, BufferSizeType numberOfBytes, ByteOrder dataByteOrder)
286  {
287  if ( dataByteOrder == ImageIOBase::LittleEndian )
288  {
290  (TPixel*)buffer, numberOfBytes / sizeof(TPixel) );
291  }
292  else if ( dataByteOrder == ImageIOBase::BigEndian )
293  {
295  (TPixel *)buffer, numberOfBytes / sizeof(TPixel) );
296  }
297  }
298 };
299 
300 
301 // Strings
302 const char *VoxBoCUBImageIO::m_VB_IDENTIFIER_SYSTEM = "VB98";
303 const char *VoxBoCUBImageIO::m_VB_IDENTIFIER_FILETYPE = "CUB1";
304 const char *VoxBoCUBImageIO::m_VB_DIMENSIONS = "VoxDims(XYZ)";
305 const char *VoxBoCUBImageIO::m_VB_SPACING = "VoxSizes(XYZ)";
306 const char *VoxBoCUBImageIO::m_VB_ORIGIN = "Origin(XYZ)";
307 const char *VoxBoCUBImageIO::m_VB_DATATYPE = "DataType";
308 const char *VoxBoCUBImageIO::m_VB_BYTEORDER = "Byteorder";
309 const char *VoxBoCUBImageIO::m_VB_ORIENTATION = "Orientation";
310 const char *VoxBoCUBImageIO::m_VB_BYTEORDER_MSB = "msbfirst";
311 const char *VoxBoCUBImageIO::m_VB_BYTEORDER_LSB = "lsbfirst";
312 const char *VoxBoCUBImageIO::m_VB_DATATYPE_BYTE = "Byte";
313 const char *VoxBoCUBImageIO::m_VB_DATATYPE_INT = "Integer";
314 const char *VoxBoCUBImageIO::m_VB_DATATYPE_FLOAT = "Float";
315 const char *VoxBoCUBImageIO::m_VB_DATATYPE_DOUBLE = "Double";
316 
319 {
322  m_Reader = NULL;
323  m_Writer = NULL;
324 }
325 
326 
329 {
330  if(m_Reader)
331  {
332  delete m_Reader;
333  }
334 
335  if(m_Writer)
336  {
337  delete m_Writer;
338  }
339 }
340 
342 VoxBoCUBImageIO::CreateReader(const char *filename)
343 {
344  try
345  {
346  bool compressed;
347  if(CheckExtension(filename, compressed))
348  {
349  if(compressed)
350  {
351  return new CompressedCUBFileAdaptor(filename, "rb");
352  }
353  else
354  {
355  return new DirectCUBFileAdaptor(filename, "rb");
356  }
357  }
358  else
359  {
360  return NULL;
361  }
362  }
363  catch(...)
364  {
365  return NULL;
366  }
367 }
368 
370 VoxBoCUBImageIO::CreateWriter(const char *filename)
371 {
372  try
373  {
374  bool compressed;
375  if(CheckExtension(filename, compressed))
376  {
377  if(compressed)
378  {
379  return new CompressedCUBFileAdaptor(filename, "wb");
380  }
381  else
382  {
383  return new DirectCUBFileAdaptor(filename, "wb");
384  }
385  }
386  else
387  {
388  return NULL;
389  }
390  }
391  catch(...)
392  {
393  return NULL;
394  }
395 }
396 
397 bool VoxBoCUBImageIO::CanReadFile( const char* filename )
398 {
399  // First check if the file can be read
400  GenericCUBFileAdaptor *reader = CreateReader(filename);
401  if(reader == NULL)
402  {
403  itkDebugMacro(<<"The file is not a valid CUB file");
404  return false;
405  }
406 
407  // Now check the content
408  bool iscub = true;
409  try
410  {
411  // Get the header
412  std::istringstream iss(reader->ReadHeader());
413 
414  // Read the first two words
415  std::string word;
416 
417  // Read the first line from the file
418  iss >> word;
419  if(word != m_VB_IDENTIFIER_SYSTEM)
420  {
421  iscub = false;
422  }
423 
424  // Read the second line
425  iss >> word;
426  if(word != m_VB_IDENTIFIER_FILETYPE)
427  {
428  iscub = false;
429  }
430  }
431  catch(...)
432  {
433  iscub = false;
434  }
435 
436  delete reader;
437  return iscub;
438 }
439 
440 bool VoxBoCUBImageIO::CanWriteFile( const char * name )
441 {
442  bool compressed;
443  return CheckExtension(name, compressed);
444 }
445 
446 void VoxBoCUBImageIO::Read(void* buffer)
447 {
448  if(m_Reader == NULL)
449  {
450  ExceptionObject exception(__FILE__, __LINE__);
451  exception.SetDescription("File cannot be read");
452  throw exception;
453  }
454 
455  BufferSizeType numberOfBytesToRead =
456  Math::CastWithRangeCheck< BufferSizeType, SizeType >( this->GetImageSizeInBytes() );
457  m_Reader->ReadData( buffer, numberOfBytesToRead );
458  this->SwapBytesIfNecessary(buffer, numberOfBytesToRead );
459 }
460 
466 {
467  // Make sure there is no other reader
468  if(m_Reader)
469  {
470  delete m_Reader;
471  }
472 
473  // Create a reader
474  m_Reader = CreateReader(m_FileName.c_str());
475  if(m_Reader == NULL)
476  {
477  ExceptionObject exception(__FILE__, __LINE__);
478  exception.SetDescription("File cannot be read");
479  throw exception;
480  }
481 
482  // Set the number of dimensions to three
484 
485  // Read the file header
486  std::istringstream issHeader(m_Reader->ReadHeader());
487 
488  // Read every string in the header. Parse the strings that are special
489  while(issHeader.good())
490  {
491  // Read a line from the stream
492  char linebuffer[512];
493  issHeader.getline(linebuffer, 512);
494 
495  // Get the key string
496  std::istringstream iss(linebuffer);
497  std::string key;
498 
499  // Read the key and strip the colon from it
500  iss >> key;
501 
502  const std::string::size_type keysize = key.size();
503 
504  if( ( keysize > 0 ) && (key[key.size() - 1] == ':' ))
505  {
506  // Strip the colon off the key
507  key = key.substr(0, key.size() - 1);
508 
509  // Check if this is a relevant key
510  if(key == m_VB_DIMENSIONS)
511  {
512  iss >> m_Dimensions[0];
513  iss >> m_Dimensions[1];
514  iss >> m_Dimensions[2];
515  }
516 
517  else if(key == m_VB_SPACING)
518  {
519  iss >> m_Spacing[0];
520  iss >> m_Spacing[1];
521  iss >> m_Spacing[2];
522  }
523 
524  else if(key == m_VB_ORIGIN)
525  {
526  double ox, oy, oz;
527  iss >> ox; iss >> oy; iss >> oz;
528  m_Origin[0] = -ox * m_Spacing[0];
529  m_Origin[1] = -oy * m_Spacing[1];
530  m_Origin[2] = -oz * m_Spacing[2];
531  }
532 
533  else if(key == m_VB_DATATYPE)
534  {
535  std::string type;
536  iss >> type;
538  if(type == m_VB_DATATYPE_BYTE)
539  {
541  }
542  else if(type == m_VB_DATATYPE_INT)
543  {
545  }
546  else if(type == m_VB_DATATYPE_FLOAT)
547  {
549  }
550  else if(type == m_VB_DATATYPE_DOUBLE)
551  {
553  }
554  }
555 
556  else if(key == m_VB_BYTEORDER)
557  {
558  std::string type;
559  iss >> type;
560  if(type == m_VB_BYTEORDER_MSB)
561  {
563  }
564  else if(type == m_VB_BYTEORDER_LSB)
565  {
567  }
568  else
569  {
570  ExceptionObject exception(__FILE__, __LINE__);
571  exception.SetDescription("Unknown byte order constant");
572  throw exception;
573  }
574  }
575 
576  else if(key == m_VB_ORIENTATION)
577  {
578  std::string code;
579  iss >> code;
580 
581  // Set the orientation code in the data dictionary
582  OrientationMap::const_iterator it = m_OrientationMap.find(code);
583  if(it != m_OrientationMap.end())
584  {
586  EncapsulateMetaData<OrientationFlags>(
587  dic, ITK_CoordinateOrientation, it->second);
588  }
589  }
590 
591  else
592  {
593  // Encode the right hand side of the string in the meta-data dic
594  std::string word;
595  itksys_ios::ostringstream oss;
596  while(iss >> word)
597  {
598  if(oss.str().size())
599  {
600  oss << " ";
601  }
602  oss << word;
603  }
605  EncapsulateMetaData<std::string>(dic, key, oss.str());
606  }
607  }
608  }
609 }
610 
611 void
614 {
615  if(m_Writer == NULL)
616  {
617  ExceptionObject exception(__FILE__, __LINE__);
618  exception.SetDescription("File cannot be read");
619  throw exception;
620  }
621 
622  // Check that the number of dimensions is correct
623  if(GetNumberOfDimensions() != 3)
624  {
625  ExceptionObject exception(__FILE__, __LINE__);
626  exception.SetDescription("Unsupported number of dimensions");
627  throw exception;
628  }
629 
630  // Put together a header
631  itksys_ios::ostringstream header;
632 
633  // Write the identifiers
634  header << m_VB_IDENTIFIER_SYSTEM << std::endl;
635  header << m_VB_IDENTIFIER_FILETYPE << std::endl;
636 
637  // Write the data type
638  switch(m_ComponentType)
639  {
640  case CHAR:
641  case UCHAR:
642  header << m_VB_DATATYPE << ":\t" << m_VB_DATATYPE_BYTE << std::endl;
643  break;
644  case SHORT:
645  case USHORT:
646  header << m_VB_DATATYPE << ":\t" << m_VB_DATATYPE_INT << std::endl;
647  break;
648  case FLOAT:
649  header << m_VB_DATATYPE << ":\t" << m_VB_DATATYPE_FLOAT << std::endl;
650  break;
651  case DOUBLE:
652  header << m_VB_DATATYPE << ":\t" << m_VB_DATATYPE_DOUBLE << std::endl;
653  break;
654  default:
655  ExceptionObject exception(__FILE__, __LINE__);
656  exception.SetDescription("Unsupported pixel component type");
657  throw exception;
658  }
659 
660  // Write the image dimensions
661  header << m_VB_DIMENSIONS << ":\t"
662  << m_Dimensions[0] << "\t"
663  << m_Dimensions[1] << "\t"
664  << m_Dimensions[2] << std::endl;
665 
666  // Write the spacing
667  header << m_VB_SPACING << ":\t"
668  << m_Spacing[0] << "\t"
669  << m_Spacing[1] << "\t"
670  << m_Spacing[2] << std::endl;
671 
672  // Write the origin (have to convert to bytes)
673 
674  double x= -m_Origin[0] / m_Spacing[0];
675  double y= -m_Origin[1] / m_Spacing[1];
676  double z= -m_Origin[2] / m_Spacing[2];
677  header << m_VB_ORIGIN << ":\t"
678  << ((x>=0)?(int) (x+.5):(int) (x-.5)) << "\t"
679  << ((y>=0)?(int) (y+.5):(int) (y-.5)) << "\t"
680  << ((z>=0)?(int) (z+.5):(int) (z-.5)) << std::endl;
681 
682 
683  // Write the byte order
684  header << m_VB_BYTEORDER << ":\t" << ((ByteSwapper<short>::SystemIsBigEndian()) ? m_VB_BYTEORDER_MSB : m_VB_BYTEORDER_LSB) << std::endl;
685 
686  // Write the orientation code
687  MetaDataDictionary &dic = GetMetaDataDictionary();
689  if(ExposeMetaData<OrientationFlags>(dic, ITK_CoordinateOrientation, oflag))
690  {
691  InverseOrientationMap::const_iterator it =
692  m_InverseOrientationMap.find(oflag);
693  if(it != m_InverseOrientationMap.end())
694  {
695  header << m_VB_ORIENTATION << ":\t" << it->second << std::endl;
696  }
697  }
698 
699  //Add CUB specific parameters to header from MetaDictionary
700 
701  std::vector<std::string> keys= dic.GetKeys();
702  std::string word;
703  for(size_t i=0; i<keys.size(); i++)
704  {
705  if (strcmp(keys[i].c_str(),ITK_CoordinateOrientation))
706  {
707  // The following local, key, was required to avoid Borland compiler errors
708  // Using const reference should avoid extra copy while still please bcc32
709  const std::string &key = keys[i];
710  ExposeMetaData<std::string>(dic, key, word);
711  if (!strcmp(key.c_str(),"resample_date"))
712  {
713  time_t rawtime;
714  time(&rawtime);
715  word=ctime(&rawtime);
716  header<<key<<":\t"<<word;
717  }
718  else
719  {
720  header<<key<<":\t"<<word<<std::endl;
721  }
722  }
723  }
724  // Write the terminating characters
725  header << "\f\n";
726 
727  // Write the header to the file as data
728  m_Writer->WriteData(header.str().c_str(), header.str().size());
729 }
730 
732 void
734 ::Write( const void* buffer)
735 {
736  m_Writer = CreateWriter(m_FileName.c_str());
737  WriteImageInformation();
738  m_Writer->WriteData(buffer, this->GetImageSizeInBytes());
739  delete m_Writer;
740  m_Writer=NULL;
741 }
742 
744 void VoxBoCUBImageIO::PrintSelf(std::ostream& os, Indent indent) const
745 {
746  Superclass::PrintSelf(os, indent);
747  os << indent << "PixelType " << m_PixelType << "\n";
748 }
749 
750 
751 bool VoxBoCUBImageIO::CheckExtension(const char* filename, bool &isCompressed)
752 {
753  std::string fname = filename;
754  if ( fname == "" )
755  {
756  itkDebugMacro(<< "No filename specified.");
757  return false;
758  }
759 
760  bool extensionFound = false;
761  isCompressed = false;
762 
763  std::string::size_type giplPos = fname.rfind(".cub");
764  if ((giplPos != std::string::npos)
765  && (giplPos == fname.length() - 4))
766  {
767  extensionFound = true;
768  }
769 
770  giplPos = fname.rfind(".cub.gz");
771  if ((giplPos != std::string::npos)
772  && (giplPos == fname.length() - 7))
773  {
774  extensionFound = true;
775  isCompressed = true;
776  }
777 
778  return extensionFound;
779 }
780 
781 void
784 {
785  m_OrientationMap["RIP"] = SpatialOrientation::ITK_COORDINATE_ORIENTATION_RIP;
786  m_OrientationMap["LIP"] = SpatialOrientation::ITK_COORDINATE_ORIENTATION_LIP;
787  m_OrientationMap["RSP"] = SpatialOrientation::ITK_COORDINATE_ORIENTATION_RSP;
788  m_OrientationMap["LSP"] = SpatialOrientation::ITK_COORDINATE_ORIENTATION_LSP;
789  m_OrientationMap["RIA"] = SpatialOrientation::ITK_COORDINATE_ORIENTATION_RIA;
790  m_OrientationMap["LIA"] = SpatialOrientation::ITK_COORDINATE_ORIENTATION_LIA;
791  m_OrientationMap["RSA"] = SpatialOrientation::ITK_COORDINATE_ORIENTATION_RSA;
792  m_OrientationMap["LSA"] = SpatialOrientation::ITK_COORDINATE_ORIENTATION_LSA;
793  m_OrientationMap["IRP"] = SpatialOrientation::ITK_COORDINATE_ORIENTATION_IRP;
794  m_OrientationMap["ILP"] = SpatialOrientation::ITK_COORDINATE_ORIENTATION_ILP;
795  m_OrientationMap["SRP"] = SpatialOrientation::ITK_COORDINATE_ORIENTATION_SRP;
796  m_OrientationMap["SLP"] = SpatialOrientation::ITK_COORDINATE_ORIENTATION_SLP;
797  m_OrientationMap["IRA"] = SpatialOrientation::ITK_COORDINATE_ORIENTATION_IRA;
798  m_OrientationMap["ILA"] = SpatialOrientation::ITK_COORDINATE_ORIENTATION_ILA;
799  m_OrientationMap["SRA"] = SpatialOrientation::ITK_COORDINATE_ORIENTATION_SRA;
800  m_OrientationMap["SLA"] = SpatialOrientation::ITK_COORDINATE_ORIENTATION_SLA;
801  m_OrientationMap["RPI"] = SpatialOrientation::ITK_COORDINATE_ORIENTATION_RPI;
802  m_OrientationMap["LPI"] = SpatialOrientation::ITK_COORDINATE_ORIENTATION_LPI;
803  m_OrientationMap["RAI"] = SpatialOrientation::ITK_COORDINATE_ORIENTATION_RAI;
804  m_OrientationMap["LAI"] = SpatialOrientation::ITK_COORDINATE_ORIENTATION_LAI;
805  m_OrientationMap["RPS"] = SpatialOrientation::ITK_COORDINATE_ORIENTATION_RPS;
806  m_OrientationMap["LPS"] = SpatialOrientation::ITK_COORDINATE_ORIENTATION_LPS;
807  m_OrientationMap["RAS"] = SpatialOrientation::ITK_COORDINATE_ORIENTATION_RAS;
808  m_OrientationMap["LAS"] = SpatialOrientation::ITK_COORDINATE_ORIENTATION_LAS;
809  m_OrientationMap["PRI"] = SpatialOrientation::ITK_COORDINATE_ORIENTATION_PRI;
810  m_OrientationMap["PLI"] = SpatialOrientation::ITK_COORDINATE_ORIENTATION_PLI;
811  m_OrientationMap["ARI"] = SpatialOrientation::ITK_COORDINATE_ORIENTATION_ARI;
812  m_OrientationMap["ALI"] = SpatialOrientation::ITK_COORDINATE_ORIENTATION_ALI;
813  m_OrientationMap["PRS"] = SpatialOrientation::ITK_COORDINATE_ORIENTATION_PRS;
814  m_OrientationMap["PLS"] = SpatialOrientation::ITK_COORDINATE_ORIENTATION_PLS;
815  m_OrientationMap["ARS"] = SpatialOrientation::ITK_COORDINATE_ORIENTATION_ARS;
816  m_OrientationMap["ALS"] = SpatialOrientation::ITK_COORDINATE_ORIENTATION_ALS;
817  m_OrientationMap["IPR"] = SpatialOrientation::ITK_COORDINATE_ORIENTATION_IPR;
818  m_OrientationMap["SPR"] = SpatialOrientation::ITK_COORDINATE_ORIENTATION_SPR;
819  m_OrientationMap["IAR"] = SpatialOrientation::ITK_COORDINATE_ORIENTATION_IAR;
820  m_OrientationMap["SAR"] = SpatialOrientation::ITK_COORDINATE_ORIENTATION_SAR;
821  m_OrientationMap["IPL"] = SpatialOrientation::ITK_COORDINATE_ORIENTATION_IPL;
822  m_OrientationMap["SPL"] = SpatialOrientation::ITK_COORDINATE_ORIENTATION_SPL;
823  m_OrientationMap["IAL"] = SpatialOrientation::ITK_COORDINATE_ORIENTATION_IAL;
824  m_OrientationMap["SAL"] = SpatialOrientation::ITK_COORDINATE_ORIENTATION_SAL;
825  m_OrientationMap["PIR"] = SpatialOrientation::ITK_COORDINATE_ORIENTATION_PIR;
826  m_OrientationMap["PSR"] = SpatialOrientation::ITK_COORDINATE_ORIENTATION_PSR;
827  m_OrientationMap["AIR"] = SpatialOrientation::ITK_COORDINATE_ORIENTATION_AIR;
828  m_OrientationMap["ASR"] = SpatialOrientation::ITK_COORDINATE_ORIENTATION_ASR;
829  m_OrientationMap["PIL"] = SpatialOrientation::ITK_COORDINATE_ORIENTATION_PIL;
830  m_OrientationMap["PSL"] = SpatialOrientation::ITK_COORDINATE_ORIENTATION_PSL;
831  m_OrientationMap["AIL"] = SpatialOrientation::ITK_COORDINATE_ORIENTATION_AIL;
832  m_OrientationMap["ASL"] = SpatialOrientation::ITK_COORDINATE_ORIENTATION_ASL;
833 
834  OrientationMap::const_iterator it;
835  for(it = m_OrientationMap.begin(); it != m_OrientationMap.end(); ++it)
836  m_InverseOrientationMap[it->second] = it->first;
837 
838 }
839 
840 void
842 ::SwapBytesIfNecessary(void *buffer, BufferSizeType numberOfBytes)
843 {
844  if(m_ComponentType == CHAR)
845  {
847  buffer, numberOfBytes, m_ByteOrder);
848  }
849  else if(m_ComponentType == UCHAR)
850  {
852  buffer, numberOfBytes, m_ByteOrder);
853  }
854  else if(m_ComponentType == SHORT)
855  {
857  buffer, numberOfBytes, m_ByteOrder);
858  }
859  else if(m_ComponentType == USHORT)
860  {
862  buffer, numberOfBytes, m_ByteOrder);
863  }
864  else if(m_ComponentType == INT)
865  {
867  buffer, numberOfBytes, m_ByteOrder);
868  }
869  else if(m_ComponentType == UINT)
870  {
872  buffer, numberOfBytes, m_ByteOrder);
873  }
874  else if(m_ComponentType == LONG)
875  {
877  buffer, numberOfBytes, m_ByteOrder);
878  }
879  else if(m_ComponentType == ULONG)
880  {
882  buffer, numberOfBytes, m_ByteOrder);
883  }
884  else if(m_ComponentType == FLOAT)
885  {
887  buffer, numberOfBytes, m_ByteOrder);
888  }
889  else if(m_ComponentType == DOUBLE)
890  {
892  buffer, numberOfBytes, m_ByteOrder);
893  }
894  else
895  {
896  ExceptionObject exception(__FILE__, __LINE__);
897  exception.SetDescription("Pixel Type Unknown");
898  throw exception;
899  }
900 }
901 
902 } // end namespace itk

Generated at Sun Jun 16 2013 00:15:01 for Orfeo Toolbox with doxygen 1.8.3.1