X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=common%2FclitkCommon.cxx;h=96980bbbb6b47f3c7c20106f0ef9dd0e2cabd09d;hb=65e4f8505d33e3079d386731845cbd6c413966fd;hp=b12f6f5d4b64eb17add326e8ae6dfd69e26d2c2d;hpb=573d80d0f7a17607d2ee883c21c940c0ba020282;p=clitk.git diff --git a/common/clitkCommon.cxx b/common/clitkCommon.cxx index b12f6f5..96980bb 100644 --- a/common/clitkCommon.cxx +++ b/common/clitkCommon.cxx @@ -19,6 +19,8 @@ #ifndef CLITKCOMMON_CXX #define CLITKCOMMON_CXX +#include + // clitk include #include "clitkCommon.h" @@ -41,7 +43,8 @@ void clitk::skipComment(std::istream & is) is >> c; if (is.eof()) return; } - is.unget(); + if (!(is.fail()) && c != '\n') + is.unget(); } //// //------------------------------------------------------------------ @@ -68,6 +71,24 @@ std::string clitk::GetExtension(const std::string& filename) } //// //------------------------------------------------------------------ + +//------------------------------------------------------------------ +// Return filename splitting in 1 or 2 parts : directory name (if exists) & filename +std::vector clitk::SplitFilename(const std::string& filename) +{ + std::vector dirname; + std::string path = itksys::SystemTools::GetFilenamePath(filename); + std::vector 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 +124,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 +272,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 : <"