]> Creatis software - clitk.git/blobdiff - common/clitkCommon.cxx
Add comment to precise the functionality of the inputs
[clitk.git] / common / clitkCommon.cxx
index df47f51ab943d3ed55177569165d9a8fd4c24306..c71bd5078fbf5598e7982eb81287204c1c26c694 100644 (file)
@@ -3,7 +3,7 @@
 
   Authors belong to:
   - University of LYON              http://www.universite-lyon.fr/
-  - Léon Bérard cancer center       http://oncora1.lyon.fnclcc.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
 
   - BSD        See included LICENSE.txt file
   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
-======================================================================-====*/
+===========================================================================**/
 
 #ifndef CLITKCOMMON_CXX
 #define CLITKCOMMON_CXX
 
+#include <itksys/SystemTools.hxx>
+
+#ifdef _WIN32
+  #define _USE_MATH_DEFINES
+  #include <cmath>
+  const double M_PI = std::acos(-1.0);
+#endif
+
 // clitk include 
 #include "clitkCommon.h"
 
@@ -41,7 +49,8 @@ void clitk::skipComment(std::istream & is)
     is >> c;
     if (is.eof()) return;
   }
-  is.unget();
+  if (!(is.fail()) && c != '\n')
+    is.unget();
 } ////
 //------------------------------------------------------------------
 
@@ -68,6 +77,24 @@ std::string clitk::GetExtension(const std::string& filename)
 } ////
 //------------------------------------------------------------------
 
+
+//------------------------------------------------------------------
+// Return filename splitting in 1 or 2 parts : directory name (if exists) & filename
+std::vector<std::string> clitk::SplitFilename(const std::string& filename)
+{
+  std::vector<std::string> dirname;
+  std::string path = itksys::SystemTools::GetFilenamePath(filename);
+  std::vector<std::string> pathComponents;
+  itksys::SystemTools::SplitPath(filename.c_str(), pathComponents);
+  std::string fileName = pathComponents.back();
+  if (path != "")
+    dirname.push_back(path);
+  dirname.push_back(fileName);
+  return( dirname );
+} ////
+//------------------------------------------------------------------
+
+
 //------------------------------------------------------------------
 // Display progression
 void clitk::VerboseInProgress(const int nb, const int current, const int percentage)
@@ -103,6 +130,15 @@ float clitk::PixelTypeDownCast(const double & x)
 }
 //------------------------------------------------------------------
 
+//------------------------------------------------------------------
+// Convert a pixel type without casting
+template<>
+double clitk::PixelTypeDownCast(const double & x)
+{
+  return x;
+}
+//------------------------------------------------------------------
+
 //------------------------------------------------------------------
 double clitk::rad2deg(const double anglerad)
 {
@@ -242,7 +278,7 @@ double clitk::ComputeEuclideanDistanceFromPointToPlane(const itk::ContinuousInde
 // Open a file for reading
 void clitk::openFileForReading(std::ifstream & is, const std::string & filename)
 {
-  is.open(filename.c_str(), std::ios::in);
+  is.open(filename.c_str(), std::ios::in | std::ios::binary);
   if ( is.fail() ) {
     clitkExceptionMacro("Could not open file for reading: " 
                         << filename << ". Error is : <"