#ifndef CLITKCOMMON_CXX
#define CLITKCOMMON_CXX
+// clitk include
#include "clitkCommon.h"
+
+// std include
#include <fstream>
#include <iomanip>
#include <sstream>
+#include <cerrno>
//------------------------------------------------------------------
// skip line which begin with a sharp '#'
{
is.open(filename.c_str(), std::ios::in);
if ( is.fail() ) {
- clitkExceptionMacro("Could not open file (for reading): " << filename);
+ clitkExceptionMacro("Could not open file for reading: "
+ << filename << ". Error is : <"
+ << strerror(errno) << ">");
}
}
//--------------------------------------------------------------------
{
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) << ">");
}
}
//--------------------------------------------------------------------
//--------------------------------------------------------------------
+//--------------------------------------------------------------------
+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 */
#include <itkImageRegionConstIterator.h>
#include <itkImageRegionIterator.h>
+// std include
#include <fstream>
+// Include for "rusage"
+#include <ctime>
+#if defined(unix) || defined(__APPLE__)
+# include <sys/time.h>
+# include <sys/resource.h>
+#elif defined(WIN32)
+# include <windows.h>
+#endif
+
//--------------------------------------------------------------------
namespace clitk {
template<class T> std::string toStringVector(const T * t, const int n);
template<class T> std::string toStringVector(const T & t, const int n);
template<class T> std::string toStringVector(const std::vector<T> & t);
+ template <class T> bool fromString(T& t,
+ const std::string& s,
+ std::ios_base& (*f)(std::ios_base&)=std::dec);
//--------------------------------------------------------------------
// Display a progress %
template<class ImageType>
void CloneImage(const typename ImageType::Pointer & input, typename ImageType::Pointer & output);
+ //--------------------------------------------------------------------
+ void PrintMemoryUsed();
+
#include "clitkCommon.txx"
} // end namespace
}
//--------------------------------------------------------------------
+
+//--------------------------------------------------------------------
+// http://www.codeguru.com/forum/showthread.php?t=231054
+template <class T>
+bool fromString(T& t, const std::string& s,
+ std::ios_base& (*f)(std::ios_base&))
+{
+ std::istringstream iss(s);
+ return !(iss >> f >> t).fail();
+}
+//--------------------------------------------------------------------
+
+
//--------------------------------------------------------------------
// Convert float*, double* ... to string
template<class T>