]> Creatis software - clitk.git/commitdiff
Synergy projections file format
authorsrit <srit>
Wed, 17 Feb 2010 08:24:14 +0000 (08:24 +0000)
committersrit <srit>
Wed, 17 Feb 2010 08:24:14 +0000 (08:24 +0000)
common/CMakeLists.txt
common/clitkHisImageIO.cxx [new file with mode: 0755]
common/clitkHisImageIO.h [new file with mode: 0755]
common/clitkHisImageIOFactory.cxx [new file with mode: 0755]
common/clitkHisImageIOFactory.h [new file with mode: 0755]
common/clitkIO.h

index 92fd73b41bf9f8909b39e90d03216e6eab172be3..e5f0698e267e42974e4857a64eee645abac73208 100644 (file)
@@ -17,6 +17,8 @@ SET(clitkCommon_SRC
   clitkVoxImageIOFactory.cxx
   clitkVfImageIO.cxx  
   clitkVfImageIOFactory.cxx
+  clitkHisImageIO.cxx  
+  clitkHisImageIOFactory.cxx
   clitkOrientation.cxx
   vvImage.cxx
   clitkImageToImageGenericFilter.cxx
diff --git a/common/clitkHisImageIO.cxx b/common/clitkHisImageIO.cxx
new file mode 100755 (executable)
index 0000000..009d282
--- /dev/null
@@ -0,0 +1,198 @@
+
+/*-------------------------------------------------------------------------
+                                                                                
+  Program:   clitk
+  Language:  C++
+                                                                                
+  Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
+  l'Image). All rights reserved. See Doc/License.txt or
+  http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
+                                                                                
+  This software is distributed WITHOUT ANY WARRANTY; without even
+  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+  PURPOSE.  See the above copyright notices for more information.
+                                                                             
+  -------------------------------------------------------------------------*/
+
+
+#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  
+   * 
+   * 
+   -------------------------------------------------*/
+
+// std include
+#include <fstream>
+
+// clitk include
+#include "clitkHisImageIO.h"
+#include "clitkCommon.h"
+
+//--------------------------------------------------------------------
+// Read Image Information
+void clitk::HisImageIO::ReadImageInformation() {
+  // 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);
+
+  // read header
+  char header[HEADER_INFO_SIZE];\r
+  file.read(header, HEADER_INFO_SIZE);\r
+\r
+  if (header[0]!=0 || header[1]!=112 || header[2]!=68 || header[3]!=0)\r
+  { itkExceptionMacro(<< "clitk::HisImageIO::ReadImageInformation: file " << m_FileName << " not in Heimann HIS format version 100");\r
+    return;\r
+  }\r
+
+  int nrframes, type, ulx, uly, brx, bry;\r
+  m_HeaderSize  = header[10] + (header[11]<<8);\r
+  ulx      = header[12] + (header[13]<<8);\r
+  uly      = header[14] + (header[15]<<8);\r
+  brx      = header[16] + (header[17]<<8);\r
+  bry      = header[18] + (header[19]<<8);\r
+  nrframes = header[20] + (header[21]<<8);\r
+  type     = header[32] + (header[34]<<8);\r
+\r
+  switch(type)\r
+  { case  4: SetComponentType(itk::ImageIOBase::USHORT); break;\r
+//    case  8: SetComponentType(itk::ImageIOBase::INT);   break;\r
+//    case 16: SetComponentType(itk::ImageIOBase::FLOAT); break;\r
+//    case 32: SetComponentType(itk::ImageIOBase::INT);   break;\r
+    default: SetComponentType(itk::ImageIOBase::USHORT); break;\r
+  }\r
+
+  switch(nrframes)
+  { case 1:  SetNumberOfDimensions(2); break;
+    default: SetNumberOfDimensions(3); break;
+  }
+
+  SetDimensions(0, bry-uly+1);
+  SetDimensions(1, brx-ulx+1);
+  if (nrframes>1)\r
+    SetDimensions(2, nrframes);\r
+  file.close();\r
+} ////
+
+//--------------------------------------------------------------------
+// Read Image Information
+bool clitk::HisImageIO::CanReadFile(const char* FileNameToRead) 
+{
+  std::string filename(FileNameToRead);
+  std::string filenameext = GetExtension(filename);
+  if (filenameext != std::string("his")) return false;
+  return true;
+} ////
+
+//--------------------------------------------------------------------
+// Read Image Content
+void clitk::HisImageIO::Read(void * buffer) {
+
+  // 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);
+
+
+  file.seekg(m_HeaderSize+HEADER_INFO_SIZE, std::ios::beg);
+  if ( file.fail() )
+    itkExceptionMacro(<<"File seek failed (His Read)");
+
+\r
+  file.read((char*)buffer, GetImageSizeInBytes());\r
+  if ( file.fail() )
+    itkExceptionMacro(<<"Read failed: Wanted "
+                      << GetImageSizeInBytes()
+                      << " bytes, but read "
+                      << file.gcount() << " bytes. The current state is: "
+                      << file.rdstate());
+}
+
+//--------------------------------------------------------------------
+// Write Image Information
+void clitk::HisImageIO::WriteImageInformation(bool keepOfStream)
+{
+  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);
+
+  m_HeaderSize = HEADER_INFO_SIZE + 32;\r
+  char szHeader[HEADER_INFO_SIZE + 32] = {\r
+       0x00, 0x70, 0x44, 0x00, 0x64, 0x00, 0x64, 0x00, 0x20, 0x00, 0x20, 0x00, 0x01, 0x00, 0x01, 0x00,\r
+       0x00, 0x04, 0x00, 0x04, 0x01, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6A, 0x18, 0x41,\r
+       0x04, 0x00, 0x40, 0x5F, 0x48, 0x01, 0x40, 0x00, 0x86, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,\r
+       0x00, 0x00, 0x00, 0x00, 0x08, 0x63, 0x13, 0x00, 0xE8, 0x51, 0x13, 0x00, 0x5C, 0xE7, 0x12, 0x00,\r
+       0xFE, 0x2A, 0x49, 0x5F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r
+       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r
+       0x00, 0x00, 0x00, 0x00};\r
+\r
+  /* Fill into the header the essentials\r
+     The 'iheader' in previous module is fixed to 0x20, and is included in szHeader.\r
+     The 'ulx' and 'uly' are fixed to 0x01, so that 'brx' and 'bry' reflect the dimensions of\r
+     the image.\r
+  */\r
+  const unsigned int ndim = GetNumberOfDimensions();\r
+  if ((ndim < 2) || (ndim > 3))\r
+    itkExceptionMacro( <<"Only 2D or 3D support");\r
+\r
+  szHeader[16] = (char)(GetDimensions(0) % 256);       // X-size       lsb\r
+  szHeader[17] = (char)(GetDimensions(0) / 256);       // X-size       msb\r
+  szHeader[18] = (char)(GetDimensions(1) % 256);       // Y-size       lsb\r
+  szHeader[19] = (char)(GetDimensions(1) / 256);       // Y-size       msb\r
+  if (ndim == 3)\r
+  { szHeader[20] = (char)(GetDimensions(0) % 256);     // NbFrames     lsb\r
+    szHeader[21] = (char)(GetDimensions(0) / 256);     // NbFrames     msb\r
+  }\r
+\r
+  switch (GetComponentType())\r
+  { case itk::ImageIOBase::USHORT:\r
+      szHeader[32] = 4;\r
+      break;\r
+    //case AVS_TYPE_INTEGER:\r
+    //  szHeader[32] = 8;\r
+    //  break;\r
+    //case AVS_TYPE_REAL:\r
+    //  szHeader[32] = 16;\r
+    //  break;\r
+    default:\r
+      itkExceptionMacro(<< "Unsupported field type");\r
+      break;\r
+  }\r
+  file.write(szHeader, m_HeaderSize);\r
+  file.close();\r
+}
+  
+//--------------------------------------------------------------------
+// Write Image Information
+bool clitk::HisImageIO::CanWriteFile(const char* FileNameToWrite)
+{
+  std::string filename(FileNameToWrite);
+  std::string filenameext = GetExtension(filename);
+  if (filenameext != std::string("his")) return false;
+  return true;
+}
+
+//--------------------------------------------------------------------
+// Write Image
+void clitk::HisImageIO::Write(const void * buffer) 
+{
+  std::ofstream file(m_FileName.c_str(), std::ios::out | std::ios::binary | std::ios::ate);
+  if ( file.fail() )
+    itkGenericExceptionMacro(<< "Could not open file (for writing): " << m_FileName);
+
+  file.write((const char *)buffer, GetImageSizeInBytes());\r
+  file.close();
+} ////
+
+#endif /* end #define CLITKHISIMAGEIO_CXX */
+
diff --git a/common/clitkHisImageIO.h b/common/clitkHisImageIO.h
new file mode 100755 (executable)
index 0000000..dba5ae3
--- /dev/null
@@ -0,0 +1,59 @@
+#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
new file mode 100755 (executable)
index 0000000..6aee6f7
--- /dev/null
@@ -0,0 +1,47 @@
+/*=========================================================================
+                                                                                
+  Program:   clitk
+  Language:  C++
+                                                                                
+  Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
+  l'Image). All rights reserved. See Doc/License.txt or
+  http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
+                                                                                
+     This software is distributed WITHOUT ANY WARRANTY; without even
+     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+     PURPOSE.  See the above copyright notices for more information.
+                                                                             
+=========================================================================*/
+
+
+#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
new file mode 100755 (executable)
index 0000000..1b96375
--- /dev/null
@@ -0,0 +1,69 @@
+#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 cabf00ef98176cd716d856c5fe39840e38a107c0..268d064da2c44e38917efba514a55e36c4a378cc 100644 (file)
@@ -20,6 +20,8 @@
 #include "clitkImageCommon.h"
 #include "clitkVoxImageIO.h"
 #include "clitkVoxImageIOFactory.h"
+#include "clitkHisImageIO.h"
+#include "clitkHisImageIOFactory.h"
 #include "clitkVfImageIO.h"
 #include "clitkVfImageIOFactory.h"
 
@@ -28,7 +30,8 @@
 #define CLITK_INIT                                     \
   itk::ImageIOFactory::RegisterBuiltInFactories();     \
     clitk::VoxImageIOFactory::RegisterOneFactory();    \
-    clitk::VfImageIOFactory::RegisterOneFactory();
+    clitk::VfImageIOFactory::RegisterOneFactory();     \
+    clitk::HisImageIOFactory::RegisterOneFactory();
 
 #endif /* end #define CLITKIO_H */