]> Creatis software - clitk.git/blobdiff - common/clitkHisImageIO.cxx
- correct crop 2D bug
[clitk.git] / common / clitkHisImageIO.cxx
index 009d282428546ae2fdd18e29cbd4a41b8a7790f2..702a1ba1606895f3811825f6f491c0c76bc60d01 100755 (executable)
@@ -1,25 +1,23 @@
+/*=========================================================================
+  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://oncora1.lyon.fnclcc.fr
+  - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
 
-/*-------------------------------------------------------------------------
-                                                                                
-  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.
-                                                                             
-  -------------------------------------------------------------------------*/
+  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_CXX
 #define CLITKHISIMAGEIO_CXX
-
 #define HEADER_INFO_SIZE 68
-
 /**
    -------------------------------------------------
    * @file   clitkHisImageIO.cxx
@@ -31,6 +29,8 @@
    * 
    -------------------------------------------------*/
 
+// Based on a true story by the Nederlands Kanker Instituut (AVS_HEIMANN.CPP from the 20090608)
+
 // std include
 #include <fstream>
 
@@ -81,7 +81,6 @@ void clitk::HisImageIO::ReadImageInformation() {
   SetDimensions(1, brx-ulx+1);
   if (nrframes>1)\r
     SetDimensions(2, nrframes);\r
-  file.close();\r
 } ////
 
 //--------------------------------------------------------------------
@@ -97,7 +96,6 @@ bool clitk::HisImageIO::CanReadFile(const char* FileNameToRead)
 //--------------------------------------------------------------------
 // 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() )
@@ -117,10 +115,18 @@ void clitk::HisImageIO::Read(void * buffer) {
                       << file.gcount() << " bytes. The current state is: "
                       << file.rdstate());
 }
+  
+//--------------------------------------------------------------------
+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 Information
-void clitk::HisImageIO::WriteImageInformation(bool keepOfStream)
+// Write Image
+void clitk::HisImageIO::Write(const void* buffer)
 {
   std::ofstream file(m_FileName.c_str(), std::ios::out | std::ios::binary);
   if ( file.fail() )
@@ -168,28 +174,8 @@ void clitk::HisImageIO::WriteImageInformation(bool keepOfStream)
       itkExceptionMacro(<< "Unsupported field type");\r
       break;\r
   }\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();
 } ////