X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=common%2FclitkCommon.cxx;h=57be29e5297f833d53769818b0aa097cb3d93a6c;hb=c99295881254fc9245d4ee2a4cf940cf87ca2d7f;hp=7afeb074e4da048bdc4af1a9b6ae0e429c09dcd8;hpb=c7f6f682ddc01d2a41740bbdb806f9ef967b57d5;p=clitk.git diff --git a/common/clitkCommon.cxx b/common/clitkCommon.cxx index 7afeb07..57be29e 100644 --- a/common/clitkCommon.cxx +++ b/common/clitkCommon.cxx @@ -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 @@ -14,15 +14,19 @@ - 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 +// clitk include #include "clitkCommon.h" + +// std include #include #include #include +#include //------------------------------------------------------------------ // skip line which begin with a sharp '#' @@ -37,7 +41,8 @@ void clitk::skipComment(std::istream & is) is >> c; if (is.eof()) return; } - is.unget(); + if (!(is.fail()) && c != '\n') + is.unget(); } //// //------------------------------------------------------------------ @@ -99,6 +104,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) { @@ -238,9 +252,11 @@ 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); + clitkExceptionMacro("Could not open file for reading: " + << filename << ". Error is : <" + << strerror(errno) << ">"); } } //-------------------------------------------------------------------- @@ -251,7 +267,9 @@ void clitk::openFileForWriting(std::ofstream & os, const std::string & filename) { os.open(filename.c_str(), std::ios::out); if ( os.fail() ) { - clitkExceptionMacro("Could not open file (for writing): " << filename); + clitkExceptionMacro("Could not open file for writing: " + << filename << ". Error is : <" + << strerror(errno) << ">"); } } //-------------------------------------------------------------------- @@ -308,5 +326,20 @@ void clitk::readDoubleFromFile(const std::string & filename, std::vector //-------------------------------------------------------------------- +//-------------------------------------------------------------------- +void clitk::PrintMemoryUsed() +{ +#if defined(unix) || defined(__APPLE__) + rusage usage; + getrusage(RUSAGE_SELF, &usage); + DD(usage.ru_maxrss); /* maximum resident set size */ + // DD(usage.ru_ixrss); /* integral shared memory size */ + // DD(usage.ru_idrss); /* integral unshared data size */ + // DD(usage.ru_isrss); /* integral unshared stack size */ +#endif +} +//-------------------------------------------------------------------- + + #endif /* end #define CLITKCOMMON_CXX */