]> Creatis software - clitk.git/commitdiff
Copied His processing from rtk and use rtk file names to emphasize that they are...
authorSimon Rit <simon.rit@creatis.insa-lyon.fr>
Tue, 13 Nov 2012 16:30:43 +0000 (17:30 +0100)
committerSimon Rit <simon.rit@creatis.insa-lyon.fr>
Tue, 13 Nov 2012 16:30:43 +0000 (17:30 +0100)
common/CMakeLists.txt
common/clitkHisImageIO.h [deleted file]
common/clitkHisImageIOFactory.cxx [deleted file]
common/clitkHisImageIOFactory.h [deleted file]
common/clitkIO.cxx
common/rtkHisImageIO.cxx [moved from common/clitkHisImageIO.cxx with 50% similarity]
common/rtkHisImageIO.h [new file with mode: 0644]
common/rtkHisImageIOFactory.cxx [new file with mode: 0644]
common/rtkHisImageIOFactory.h [new file with mode: 0644]

index a85fda611b1054e0dcfe74ece18ce22c4fd13ebd..d23e0b325204e153a3bbb198fb33526b40845677 100644 (file)
@@ -15,11 +15,11 @@ SET(clitkCommon_SRC
   clitkVoxImageIOFactory.cxx
   clitkVfImageIO.cxx  
   clitkVfImageIOFactory.cxx
   clitkVoxImageIOFactory.cxx
   clitkVfImageIO.cxx  
   clitkVfImageIOFactory.cxx
-  clitkHisImageIO.cxx  
-  clitkHisImageIOFactory.cxx
   clitkXdrImageIOReader.cxx  
   clitkXdrImageIOWriter.cxx  
   clitkXdrImageIOFactory.cxx
   clitkXdrImageIOReader.cxx  
   clitkXdrImageIOWriter.cxx  
   clitkXdrImageIOFactory.cxx
+  rtkHisImageIO.cxx  
+  rtkHisImageIOFactory.cxx
   rtkHndImageIO.cxx
   rtkHndImageIOFactory.cxx
   clitkDicomRTDoseIO.cxx
   rtkHndImageIO.cxx
   rtkHndImageIOFactory.cxx
   clitkDicomRTDoseIO.cxx
diff --git a/common/clitkHisImageIO.h b/common/clitkHisImageIO.h
deleted file mode 100644 (file)
index 28633c8..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-/*=========================================================================
-  Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
-
-  Authors belong to: 
-  - University of LYON              http://www.universite-lyon.fr/
-  - Léon Bérard cancer center       http://www.centreleonberard.fr
-  - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
-
-  This software is distributed WITHOUT ANY WARRANTY; without even
-  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
-  PURPOSE.  See the copyright notices for more information.
-
-  It is distributed under dual licence
-
-  - BSD        See included LICENSE.txt file
-  - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
-===========================================================================**/
-#ifndef CLITKHISIMAGEIO_H
-#define CLITKHISIMAGEIO_H
-/**
- ===================================================================
- * @file   clitkHisImageIO.h
- * @author Simon Rit <simon.rit@gmail.com>
- * @date   16 Feb 2010
-
- * @brief  
-
- ===================================================================*/
-
-// itk include
-#include "itkImageIOBase.h"
-
-namespace clitk {
-  
-  //====================================================================
-  // Class for reading His Image file format
-  class HisImageIO: public itk::ImageIOBase
-  {
-  public: 
-       /** Standard class typedefs. */
-       typedef HisImageIO              Self;
-       typedef itk::ImageIOBase        Superclass;
-       typedef itk::SmartPointer<Self> Pointer;        
-       typedef signed short int        PixelType;
-       
-       HisImageIO():Superclass() {;}
-
-       /** Method for creation through the object factory. */
-       itkNewMacro(Self);
-       
-       /** Run-time type information (and related methods). */
-       itkTypeMacro(HisImageIO, ImageIOBase);
-       
-       /*-------- This part of the interface deals with reading data. ------ */
-       virtual void ReadImageInformation();
-       virtual bool CanReadFile( const char* FileNameToRead );
-       virtual void Read(void * buffer);
-
-       /*-------- This part of the interfaces deals with writing data. ----- */
-        virtual void WriteImageInformation(bool keepOfStream) { ; }
-       virtual void WriteImageInformation() { WriteImageInformation(false); }
-       virtual bool CanWriteFile(const char* filename);
-       virtual void Write(const void* buffer);
-       
-  protected:
-       int m_HeaderSize;
-
-  }; // end class HisImageIO  
-} // end namespace
-
-  // explicit template instantiation
-//template class itk::CreateObjectFunction<clitk::HisImageIO>;
-
-#endif /* end #define CLITKHISIMAGEIO_H */
-
diff --git a/common/clitkHisImageIOFactory.cxx b/common/clitkHisImageIOFactory.cxx
deleted file mode 100644 (file)
index cdcf894..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-/*=========================================================================
-  Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
-
-  Authors belong to:
-  - University of LYON              http://www.universite-lyon.fr/
-  - Léon Bérard cancer center       http://www.centreleonberard.fr
-  - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
-
-  This software is distributed WITHOUT ANY WARRANTY; without even
-  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
-  PURPOSE.  See the copyright notices for more information.
-
-  It is distributed under dual licence
-
-  - BSD        See included LICENSE.txt file
-  - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
-===========================================================================**/
-#ifndef CLITKHISIMAGEIOFACTORY_CXX
-#define CLITKHISIMAGEIOFACTORY_CXX
-/**
- =================================================
- * @file   clitkHisImageIOFactory.cxx
- * @author Simon Rit <simon.rit@gmail.com>
- * @date   16 Feb 2010
- *
- * @brief
- *
- *
- =================================================*/
-
-#include "clitkHisImageIOFactory.h"
-
-#include <fstream>
-
-//====================================================================
-clitk::HisImageIOFactory::HisImageIOFactory()
-{
-  this->RegisterOverride("itkImageIOBase",
-                         "HisImageIO",
-                         "His Image IO",
-                         1,
-                         itk::CreateObjectFunction<HisImageIO>::New());
-}
-
-
-#endif /* end #define CLITKHISIMAGEIOFACTORY_CXX */
-
diff --git a/common/clitkHisImageIOFactory.h b/common/clitkHisImageIOFactory.h
deleted file mode 100644 (file)
index c40f512..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-/*=========================================================================
-  Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
-
-  Authors belong to: 
-  - University of LYON              http://www.universite-lyon.fr/
-  - Léon Bérard cancer center       http://www.centreleonberard.fr
-  - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
-
-  This software is distributed WITHOUT ANY WARRANTY; without even
-  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
-  PURPOSE.  See the copyright notices for more information.
-
-  It is distributed under dual licence
-
-  - BSD        See included LICENSE.txt file
-  - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
-===========================================================================**/
-#ifndef CLITKHISIMAGEIOFACTORY_H
-#define CLITKHISIMAGEIOFACTORY_H
-/**
- ===================================================================
- * @file   clitkHisImageIOFactory.h
- * @author Simon Rit <simon.rit@gmail.com>
- * @date   16 Feb 2010
-
- * @brief  
-
- ===================================================================*/
-
-// clitk include
-#include "clitkHisImageIO.h"
-
-// itk include
-#include "itkImageIOBase.h"
-#include "itkObjectFactoryBase.h"
-#include "itkVersion.h"
-
-namespace clitk {
-  
-  //====================================================================
-  // Factory for reading His Image file format
-  class HisImageIOFactory: public itk::ObjectFactoryBase
-  {
-  public:
-       /** Standard class typedefs. */
-       typedef HisImageIOFactory              Self;
-       typedef itk::ObjectFactoryBase         Superclass;
-       typedef itk::SmartPointer<Self>        Pointer;
-       typedef itk::SmartPointer<const Self>  ConstPointer;
-       
-       /** Class methods used to interface with the registered factories. */
-       const char* GetITKSourceVersion(void) const {
-         return ITK_SOURCE_VERSION;
-       }
-       
-       const char* GetDescription(void) const {
-         return "His ImageIO Factory, allows the loading of His images into insight";
-       }
-       
-       /** Method for class instantiation. */
-       itkFactorylessNewMacro(Self);
-       
-       /** Run-time type information (and related methods). */
-       itkTypeMacro(HisImageIOFactory, ObjectFactoryBase);
-       
-       /** Register one factory of this type  */
-       static void RegisterOneFactory(void) {
-         ObjectFactoryBase::RegisterFactory( Self::New() );
-       }       
-
-  protected:
-       HisImageIOFactory();
-       ~HisImageIOFactory() {};
-       typedef HisImageIOFactory myProductType;
-       const myProductType* m_MyProduct;
-       
-  private:
-       HisImageIOFactory(const Self&); //purposely not implemented
-       void operator=(const Self&); //purposely not implemented
-  };
-
-} // end namespace
-
-#endif /* end #define CLITKHISIMAGEIOFACTORY_H */
-
index 806a81273eba79867caf5439dfc9dbfebf806aec..46e0580df572f7ac8cfabe4e809f921b85760d50 100644 (file)
@@ -28,9 +28,9 @@
 #include "clitkImageCommon.h"
 #include "clitkDicomRTDoseIOFactory.h"
 #include "clitkVoxImageIOFactory.h"
 #include "clitkImageCommon.h"
 #include "clitkDicomRTDoseIOFactory.h"
 #include "clitkVoxImageIOFactory.h"
-#include "clitkHisImageIOFactory.h"
 #include "clitkVfImageIOFactory.h"
 #include "clitkXdrImageIOFactory.h"
 #include "clitkVfImageIOFactory.h"
 #include "clitkXdrImageIOFactory.h"
+#include "rtkHisImageIOFactory.h"
 #include "rtkHndImageIOFactory.h"
 #include "clitkGateAsciiImageIOFactory.h"
 #include "clitkConfiguration.h"
 #include "rtkHndImageIOFactory.h"
 #include "clitkGateAsciiImageIOFactory.h"
 #include "clitkConfiguration.h"
@@ -56,8 +56,8 @@ void clitk::RegisterClitkFactories()
 #endif
   clitk::VoxImageIOFactory::RegisterOneFactory();
   clitk::VfImageIOFactory::RegisterOneFactory();
 #endif
   clitk::VoxImageIOFactory::RegisterOneFactory();
   clitk::VfImageIOFactory::RegisterOneFactory();
-  clitk::HisImageIOFactory::RegisterOneFactory();
   clitk::XdrImageIOFactory::RegisterOneFactory();
   clitk::XdrImageIOFactory::RegisterOneFactory();
+  rtk::HisImageIOFactory::RegisterOneFactory();
   rtk::HndImageIOFactory::RegisterOneFactory();
 } ////
 
   rtk::HndImageIOFactory::RegisterOneFactory();
 } ////
 
similarity index 50%
rename from common/clitkHisImageIO.cxx
rename to common/rtkHisImageIO.cxx
index dd594a89a99986bfa4ccc406b79db1f07ad1c474..6f9aa227c96b4c406c1adad2f236ba91a7b1f22c 100644 (file)
 /*=========================================================================
 /*=========================================================================
-  Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
+ *
+ *  Copyright RTK Consortium
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0.txt
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ *=========================================================================*/
 
 
-  Authors belong to:
-  - University of LYON              http://www.universite-lyon.fr/
-  - Léon Bérard cancer center       http://www.centreleonberard.fr
-  - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
-
-  This software is distributed WITHOUT ANY WARRANTY; without even
-  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
-  PURPOSE.  See the copyright notices for more information.
+#define HEADER_INFO_SIZE 68
 
 
-  It is distributed under dual licence
+// Based on a true story by the Nederlands Kanker Instituut (AVS_HEIMANN.CPP
+// from the 20090608)
 
 
-  - BSD        See included LICENSE.txt file
-  - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
-===========================================================================**/
-#ifndef CLITKHISIMAGEIO_CXX
-#define CLITKHISIMAGEIO_CXX
-#define HEADER_INFO_SIZE 68
-/**
-   -------------------------------------------------
-   * @file   clitkHisImageIO.cxx
-   * @author Simon Rit <simon.rit@gmail.com>
-   * @date   16 Feb 2010
-   *
-   * @brief
-   *
-   *
-   -------------------------------------------------*/
-
-// Based on a true story by the Nederlands Kanker Instituut (AVS_HEIMANN.CPP from the 20090608)
-
-// std include
+// Includes
 #include <fstream>
 #include <fstream>
-
-// clitk include
-#include "clitkHisImageIO.h"
-#include "clitkCommon.h"
+#include "rtkHisImageIO.h"
 
 //--------------------------------------------------------------------
 // Read Image Information
 
 //--------------------------------------------------------------------
 // Read Image Information
-void clitk::HisImageIO::ReadImageInformation()
+void rtk::HisImageIO::ReadImageInformation()
 {
   // open file
   std::ifstream file(m_FileName.c_str(), std::ios::in | std::ios::binary);
 {
   // open file
   std::ifstream file(m_FileName.c_str(), std::ios::in | std::ios::binary);
+
   if ( file.fail() )
   if ( file.fail() )
-    itkGenericExceptionMacro(<< "Could not open file (for reading): " << m_FileName);
+    itkGenericExceptionMacro(<< "Could not open file (for reading): "
+                             << m_FileName);
 
   // read header
   char header[HEADER_INFO_SIZE];
   file.read(header, HEADER_INFO_SIZE);
 
   if (header[0]!=0 || header[1]!=112 || header[2]!=68 || header[3]!=0) {
 
   // read header
   char header[HEADER_INFO_SIZE];
   file.read(header, HEADER_INFO_SIZE);
 
   if (header[0]!=0 || header[1]!=112 || header[2]!=68 || header[3]!=0) {
-    itkExceptionMacro(<< "clitk::HisImageIO::ReadImageInformation: file " << m_FileName << " not in Heimann HIS format version 100");
+    itkExceptionMacro(<< "rtk::HisImageIO::ReadImageInformation: file "
+                      << m_FileName
+                      << " not in Heimann HIS format version 100");
     return;
     return;
-  }
+    }
 
   int nrframes, type, ulx, uly, brx, bry;
   m_HeaderSize  = header[10] + (header[11]<<8);
 
   int nrframes, type, ulx, uly, brx, bry;
   m_HeaderSize  = header[10] + (header[11]<<8);
-  ulx      = header[12] + (header[13]<<8);
-  uly      = header[14] + (header[15]<<8);
-  brx      = header[16] + (header[17]<<8);
-  bry      = header[18] + (header[19]<<8);
-  nrframes = header[20] + (header[21]<<8);
-  type     = header[32] + (header[34]<<8);
-
-  switch(type) {
-  case  4:
-    SetComponentType(itk::ImageIOBase::USHORT);
-    break;
+  ulx           = header[12] + (header[13]<<8);
+  uly           = header[14] + (header[15]<<8);
+  brx           = header[16] + (header[17]<<8);
+  bry           = header[18] + (header[19]<<8);
+  nrframes      = header[20] + (header[21]<<8);
+  type          = header[32] + (header[34]<<8);
+
+  switch(type)
+    {
+    case  4:
+      SetComponentType(itk::ImageIOBase::USHORT);
+      break;
 //    case  8: SetComponentType(itk::ImageIOBase::INT);   break;
 //    case 16: SetComponentType(itk::ImageIOBase::FLOAT); break;
 //    case 32: SetComponentType(itk::ImageIOBase::INT);   break;
 //    case  8: SetComponentType(itk::ImageIOBase::INT);   break;
 //    case 16: SetComponentType(itk::ImageIOBase::FLOAT); break;
 //    case 32: SetComponentType(itk::ImageIOBase::INT);   break;
-  default:
-    SetComponentType(itk::ImageIOBase::USHORT);
-    break;
-  }
-
-  switch(nrframes) {
-  case 1:
-    SetNumberOfDimensions(2);
-    break;
-  default:
-    SetNumberOfDimensions(3);
-    break;
-  }
+    default:
+      SetComponentType(itk::ImageIOBase::USHORT);
+      break;
+    }
+
+  switch(nrframes)
+    {
+    case 1:
+      SetNumberOfDimensions(2);
+      break;
+    default:
+      SetNumberOfDimensions(3);
+      break;
+    }
 
   SetDimensions(0, bry-uly+1);
   SetDimensions(1, brx-ulx+1);
   if (nrframes>1)
     SetDimensions(2, nrframes);
 
 
   SetDimensions(0, bry-uly+1);
   SetDimensions(1, brx-ulx+1);
   if (nrframes>1)
     SetDimensions(2, nrframes);
 
-  SetSpacing(0, 409.6/GetDimensions(0));
-  SetSpacing(1, 409.6/GetDimensions(1));
+  SetSpacing(0, 409.6/GetDimensions(0) );
+  SetSpacing(1, 409.6/GetDimensions(1) );
 
 
-  SetOrigin(0, -0.5*(GetDimensions(0)-1)*GetSpacing(0));
-  SetOrigin(1, -0.5*(GetDimensions(1)-1)*GetSpacing(1));
+  SetOrigin(0, -0.5*(GetDimensions(0)-1)*GetSpacing(0) );
+  SetOrigin(1, -0.5*(GetDimensions(1)-1)*GetSpacing(1) );
 } ////
 
 //--------------------------------------------------------------------
 // Read Image Information
 } ////
 
 //--------------------------------------------------------------------
 // Read Image Information
-bool clitk::HisImageIO::CanReadFile(const char* FileNameToRead)
+bool rtk::HisImageIO::CanReadFile(const char* FileNameToRead)
 {
 {
-  std::string filename(FileNameToRead);
-  std::string filenameext = GetExtension(filename);
-  if (filenameext != std::string("his")) return false;
+  std::string                  filename(FileNameToRead);
+  const std::string::size_type it = filename.find_last_of( "." );
+  std::string                  fileExt( filename, it+1, filename.length() );
+
+  if (fileExt != std::string("his") )
+    return false;
   return true;
 } ////
 
 //--------------------------------------------------------------------
 // Read Image Content
   return true;
 } ////
 
 //--------------------------------------------------------------------
 // Read Image Content
-void clitk::HisImageIO::Read(void * buffer)
+void rtk::HisImageIO::Read(void * buffer)
 {
   // open file
   std::ifstream file(m_FileName.c_str(), std::ios::in | std::ios::binary);
 {
   // open file
   std::ifstream file(m_FileName.c_str(), std::ios::in | std::ios::binary);
+
   if ( file.fail() )
     itkGenericExceptionMacro(<< "Could not open file (for reading): " << m_FileName);
 
   if ( file.fail() )
     itkGenericExceptionMacro(<< "Could not open file (for reading): " << m_FileName);
 
-
   file.seekg(m_HeaderSize+HEADER_INFO_SIZE, std::ios::beg);
   if ( file.fail() )
     itkExceptionMacro(<<"File seek failed (His Read)");
 
   file.seekg(m_HeaderSize+HEADER_INFO_SIZE, std::ios::beg);
   if ( file.fail() )
     itkExceptionMacro(<<"File seek failed (His Read)");
 
-
-  file.read((char*)buffer, GetImageSizeInBytes());
+  file.read( (char*)buffer, GetImageSizeInBytes() );
   if ( file.fail() )
     itkExceptionMacro(<<"Read failed: Wanted "
                       << GetImageSizeInBytes()
                       << " bytes, but read "
                       << file.gcount() << " bytes. The current state is: "
   if ( file.fail() )
     itkExceptionMacro(<<"Read failed: Wanted "
                       << GetImageSizeInBytes()
                       << " bytes, but read "
                       << file.gcount() << " bytes. The current state is: "
-                      << file.rdstate());
+                      << file.rdstate() );
 }
 
 //--------------------------------------------------------------------
 }
 
 //--------------------------------------------------------------------
-bool clitk::HisImageIO::CanWriteFile(const char* FileNameToWrite)
+bool rtk::HisImageIO::CanWriteFile(const char* FileNameToWrite)
 {
 {
-  std::string filename(FileNameToWrite);
-  std::string filenameext = GetExtension(filename);
-  if (filenameext != std::string("his")) return false;
-  return true;
+  return CanReadFile(FileNameToWrite);
 }
 
 //--------------------------------------------------------------------
 // Write Image
 }
 
 //--------------------------------------------------------------------
 // Write Image
-void clitk::HisImageIO::Write(const void* buffer)
+void rtk::HisImageIO::Write(const void* buffer)
 {
   std::ofstream file(m_FileName.c_str(), std::ios::out | std::ios::binary);
 {
   std::ofstream file(m_FileName.c_str(), std::ios::out | std::ios::binary);
+
   if ( file.fail() )
     itkGenericExceptionMacro(<< "Could not open file (for writing): " << m_FileName);
 
   if ( file.fail() )
     itkGenericExceptionMacro(<< "Could not open file (for writing): " << m_FileName);
 
@@ -158,7 +151,7 @@ void clitk::HisImageIO::Write(const void* buffer)
     0xFE, 0x2A, 0x49, 0x5F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     0x00, 0x00, 0x00, 0x00
     0xFE, 0x2A, 0x49, 0x5F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     0x00, 0x00, 0x00, 0x00
-  };
+    };
 
   /* Fill into the header the essentials
      The 'iheader' in previous module is fixed to 0x20, and is included in szHeader.
 
   /* Fill into the header the essentials
      The 'iheader' in previous module is fixed to 0x20, and is included in szHeader.
@@ -166,37 +159,35 @@ void clitk::HisImageIO::Write(const void* buffer)
      the image.
   */
   const unsigned int ndim = GetNumberOfDimensions();
      the image.
   */
   const unsigned int ndim = GetNumberOfDimensions();
-  if ((ndim < 2) || (ndim > 3))
+  if ( (ndim < 2) || (ndim > 3) )
     itkExceptionMacro( <<"Only 2D or 3D support");
 
     itkExceptionMacro( <<"Only 2D or 3D support");
 
-  szHeader[16] = (char)(GetDimensions(0) % 256);       // X-size       lsb
-  szHeader[17] = (char)(GetDimensions(0) / 256);       // X-size       msb
-  szHeader[18] = (char)(GetDimensions(1) % 256);       // Y-size       lsb
-  szHeader[19] = (char)(GetDimensions(1) / 256);       // Y-size       msb
+  szHeader[16] = (char)(GetDimensions(0) % 256);  // X-size    lsb
+  szHeader[17] = (char)(GetDimensions(0) / 256);  // X-size    msb
+  szHeader[18] = (char)(GetDimensions(1) % 256);  // Y-size    lsb
+  szHeader[19] = (char)(GetDimensions(1) / 256);  // Y-size    msb
   if (ndim == 3) {
   if (ndim == 3) {
-    szHeader[20] = (char)(GetDimensions(0) % 256);     // NbFrames     lsb
-    szHeader[21] = (char)(GetDimensions(0) / 256);     // NbFrames     msb
-  }
-
-  switch (GetComponentType()) {
-  case itk::ImageIOBase::USHORT:
-    szHeader[32] = 4;
-    break;
+    szHeader[20] = (char)(GetDimensions(0) % 256);  // NbFrames    lsb
+    szHeader[21] = (char)(GetDimensions(0) / 256);  // NbFrames    msb
+    }
+
+  switch (GetComponentType())
+    {
+    case itk::ImageIOBase::USHORT:
+      szHeader[32] = 4;
+      break;
     //case AVS_TYPE_INTEGER:
     //  szHeader[32] = 8;
     //  break;
     //case AVS_TYPE_REAL:
     //  szHeader[32] = 16;
     //  break;
     //case AVS_TYPE_INTEGER:
     //  szHeader[32] = 8;
     //  break;
     //case AVS_TYPE_REAL:
     //  szHeader[32] = 16;
     //  break;
-  default:
-    itkExceptionMacro(<< "Unsupported field type");
-    break;
-  }
+    default:
+      itkExceptionMacro(<< "Unsupported field type");
+      break;
+    }
 
   file.write(szHeader, m_HeaderSize);
 
   file.write(szHeader, m_HeaderSize);
-  file.write((const char *)buffer, GetImageSizeInBytes());
+  file.write( (const char *)buffer, GetImageSizeInBytes() );
   file.close();
 } ////
   file.close();
 } ////
-
-#endif /* end #define CLITKHISIMAGEIO_CXX */
-
diff --git a/common/rtkHisImageIO.h b/common/rtkHisImageIO.h
new file mode 100644 (file)
index 0000000..030711c
--- /dev/null
@@ -0,0 +1,82 @@
+/*=========================================================================
+ *
+ *  Copyright RTK Consortium
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0.txt
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ *=========================================================================*/
+
+#ifndef __rtkHisImageIO_h
+#define __rtkHisImageIO_h
+
+// itk include
+#include <itkImageIOBase.h>
+
+namespace rtk
+{
+
+/** \class HisImageIO
+ * \brief Class for reading His Image file format
+ *
+ * The his image file format is used by Perkin Elmer flat panels.
+ *
+ * \author Simon Rit
+ *
+ * \ingroup IOFilters
+ */
+class HisImageIO : public itk::ImageIOBase
+{
+public:
+  /** Standard class typedefs. */
+  typedef HisImageIO              Self;
+  typedef itk::ImageIOBase        Superclass;
+  typedef itk::SmartPointer<Self> Pointer;
+  typedef signed short int        PixelType;
+
+  HisImageIO() : Superclass() {
+    ;
+  }
+
+  /** Method for creation through the object factory. */
+  itkNewMacro(Self);
+
+  /** Run-time type information (and related methods). */
+  itkTypeMacro(HisImageIO, itk::ImageIOBase);
+
+  /*-------- This part of the interface deals with reading data. ------ */
+  virtual void ReadImageInformation();
+
+  virtual bool CanReadFile( const char* FileNameToRead );
+
+  virtual void Read(void * buffer);
+
+  /*-------- This part of the interfaces deals with writing data. ----- */
+  virtual void WriteImageInformation(bool /*keepOfStream*/) {
+    ;
+  }
+
+  virtual void WriteImageInformation() {
+    WriteImageInformation(false);
+  }
+
+  virtual bool CanWriteFile(const char* filename);
+
+  virtual void Write(const void* buffer);
+
+protected:
+  int m_HeaderSize;
+
+}; // end class HisImageIO
+} // end namespace
+
+#endif /* end #define __rtkHisImageIO_h */
diff --git a/common/rtkHisImageIOFactory.cxx b/common/rtkHisImageIOFactory.cxx
new file mode 100644 (file)
index 0000000..2fb6c0b
--- /dev/null
@@ -0,0 +1,31 @@
+/*=========================================================================
+ *
+ *  Copyright RTK Consortium
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0.txt
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ *=========================================================================*/
+
+#include "rtkHisImageIOFactory.h"
+
+#include <fstream>
+
+//====================================================================
+rtk::HisImageIOFactory::HisImageIOFactory()
+{
+  this->RegisterOverride("itkImageIOBase",
+                         "HisImageIO",
+                         "His Image IO",
+                         1,
+                         itk::CreateObjectFunction<HisImageIO>::New() );
+}
diff --git a/common/rtkHisImageIOFactory.h b/common/rtkHisImageIOFactory.h
new file mode 100644 (file)
index 0000000..fbaccda
--- /dev/null
@@ -0,0 +1,80 @@
+/*=========================================================================
+ *
+ *  Copyright RTK Consortium
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0.txt
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ *=========================================================================*/
+
+#ifndef __rtkHisImageIOFactory_h
+#define __rtkHisImageIOFactory_h
+
+#include "rtkHisImageIO.h"
+
+// itk include
+#include <itkImageIOBase.h>
+#include <itkObjectFactoryBase.h>
+#include <itkVersion.h>
+
+namespace rtk
+{
+
+/** \class HisImageIOFactory
+ * \brief ITK factory for His file I/O.
+ *
+ * \author Simon Rit
+ */
+class HisImageIOFactory : public itk::ObjectFactoryBase
+{
+public:
+  /** Standard class typedefs. */
+  typedef HisImageIOFactory             Self;
+  typedef itk::ObjectFactoryBase        Superclass;
+  typedef itk::SmartPointer<Self>       Pointer;
+  typedef itk::SmartPointer<const Self> ConstPointer;
+
+  /** Class methods used to interface with the registered factories. */
+  const char* GetITKSourceVersion(void) const {
+    return ITK_SOURCE_VERSION;
+  }
+
+  const char* GetDescription(void) const {
+    return "His ImageIO Factory, allows the loading of His images into insight";
+  }
+
+  /** Method for class instantiation. */
+  itkFactorylessNewMacro(Self);
+
+  /** Run-time type information (and related methods). */
+  itkTypeMacro(HisImageIOFactory, itk::ObjectFactoryBase);
+
+  /** Register one factory of this type  */
+  static void RegisterOneFactory(void) {
+    ObjectFactoryBase::RegisterFactory( Self::New() );
+  }
+
+protected:
+  HisImageIOFactory();
+  ~HisImageIOFactory() {};
+  typedef HisImageIOFactory myProductType;
+  const myProductType* m_MyProduct;
+
+private:
+  HisImageIOFactory(const Self&); //purposely not implemented
+  void operator=(const Self&);    //purposely not implemented
+
+};
+
+} // end namespace
+
+#endif /* end #define __rtkHisImageIOFactory_h */