]> Creatis software - clitk.git/commitdiff
Extended Gate Ascii output to any pixel type
authorSimon Rit <simon.rit@creatis.insa-lyon.fr>
Fri, 27 Apr 2012 11:09:34 +0000 (13:09 +0200)
committerSimon Rit <simon.rit@creatis.insa-lyon.fr>
Fri, 27 Apr 2012 11:12:58 +0000 (13:12 +0200)
common/clitkGateAsciiImageIO.cxx
common/clitkGateAsciiImageIO.h

index 589c30cfb783b0a9d0ae7d43a1a3609e1a7d8a8b..99520ee4241268c4a089712881fbfde4508e809e 100644 (file)
@@ -252,9 +252,49 @@ void clitk::GateAsciiImageIO::Write(const void* abstract_buffer)
   stream << "# nbVal      = " << nb_value << endl;
   stream << "######################" << endl;
 
-  const double* buffer = static_cast<const double*>(abstract_buffer);
-  for (unsigned long kk=0; kk<nb_value; kk++) {
-    stream << buffer[kk] << endl;
+  if(this->GetComponentType()==itk::ImageIOBase::UCHAR) {
+    const unsigned char* buffer = static_cast<const unsigned char*>(abstract_buffer);
+    for (unsigned long kk=0; kk<nb_value; kk++)
+      stream << buffer[kk] << endl;
+  } else if(this->GetComponentType()==itk::ImageIOBase::CHAR) {
+    const char* buffer = static_cast<const char*>(abstract_buffer);
+    for (unsigned long kk=0; kk<nb_value; kk++)
+      stream << buffer[kk] << endl;
+  } else if(this->GetComponentType()==itk::ImageIOBase::USHORT) {
+    const unsigned short* buffer = static_cast<const unsigned short*>(abstract_buffer);
+    for (unsigned long kk=0; kk<nb_value; kk++)
+      stream << buffer[kk] << endl;
+  } else if(this->GetComponentType()==itk::ImageIOBase::SHORT) {
+    const short* buffer = static_cast<const short*>(abstract_buffer);
+    for (unsigned long kk=0; kk<nb_value; kk++)
+      stream << buffer[kk] << endl;
+  } else if(this->GetComponentType()==itk::ImageIOBase::UINT) {
+    const unsigned int* buffer = static_cast<const unsigned int*>(abstract_buffer);
+    for (unsigned long kk=0; kk<nb_value; kk++)
+      stream << buffer[kk] << endl;
+  } else if(this->GetComponentType()==itk::ImageIOBase::INT) {
+    const int* buffer = static_cast<const int*>(abstract_buffer);
+    for (unsigned long kk=0; kk<nb_value; kk++)
+      stream << buffer[kk] << endl;
+  } else if(this->GetComponentType()==itk::ImageIOBase::ULONG) {
+    const unsigned long* buffer = static_cast<const unsigned long*>(abstract_buffer);
+    for (unsigned long kk=0; kk<nb_value; kk++)
+      stream << buffer[kk] << endl;
+  } else if(this->GetComponentType()==itk::ImageIOBase::LONG) {
+    const long* buffer = static_cast<const long*>(abstract_buffer);
+    for (unsigned long kk=0; kk<nb_value; kk++)
+      stream << buffer[kk] << endl;
+  } else if(this->GetComponentType()==itk::ImageIOBase::FLOAT) {
+    const float* buffer = static_cast<const float*>(abstract_buffer);
+    for (unsigned long kk=0; kk<nb_value; kk++)
+      stream << buffer[kk] << endl;
+  } else if(this->GetComponentType()==itk::ImageIOBase::DOUBLE) {
+    const double* buffer = static_cast<const double*>(abstract_buffer);
+    for (unsigned long kk=0; kk<nb_value; kk++)
+      stream << buffer[kk] << endl;
+  } else {
+    itkGenericExceptionMacro(<< "Unhandled pixel type: " << this->GetComponentTypeAsString(this->GetComponentType()));
+    return;
   }
 
   FILE* handle = fopen(m_FileName.c_str(),"w");
@@ -264,6 +304,5 @@ void clitk::GateAsciiImageIO::Write(const void* abstract_buffer)
   }
 
   fwrite(stream.str().c_str(),1,stream.str().size(),handle);
-
   fclose(handle);
 }
index 7d174f82ed01e164ef3d9d241af455b046f00428..7d134de7030ac61afdea880fde62abb2d74dd92a 100644 (file)
@@ -42,7 +42,6 @@ public:
   typedef GateAsciiImageIO        Self;
   typedef itk::ImageIOBase        Superclass;
   typedef itk::SmartPointer<Self> Pointer;
-  typedef signed short int        PixelType;
 
   struct GateAsciiHeader {
     double matrix_size[3];