#ifndef CLITKCOMMON_H #define CLITKCOMMON_H /** ------------------------------------------------------------------- * @file clitkCommon.h * @author David Sarrut * @date 17 May 2006 07:57:56 * @brief -------------------------------------------------------------------*/ // std include #include #include #include #include #include #include #include #include #include #include "itkMacro.h" #include //-------------------------------------------------------------------- namespace clitk { #if defined(WIN32) #define lrint(x) (floor(x+(x>0) ? 0.5 : -0.5)) #endif typedef unsigned char uchar; typedef unsigned short ushort; typedef unsigned int uint; //-------------------------------------------------------------------- // display #define DD(a) std::cout << #a " = [ " << a << " ]" << std::endl; #define DDV(a,n) { std::cout << #a " = [ "; for(unsigned int _i_=0; _i_ std::string toString(const T & t); template std::string toStringVector(const T * t, const int n); template std::string toStringVector(const T & t, const int n); template std::string toStringVector(const std::vector & t); //-------------------------------------------------------------------- // Display a progress % void VerboseInProgress(const int nb, const int current, const int percentage); void VerboseInProgressInPercentage(const int nb, const int current, const int percentage); //-------------------------------------------------------------------- // Convert a pixel type to another (downcast) template TPixelDown PixelTypeDownCast(const TPixelUp & x); template<> float PixelTypeDownCast(const double & x); //-------------------------------------------------------------------- // Return the indexes of sorted values in a vector template struct vectorComparisonLowerThan; template struct vectorComparisonGreaterThan; template void GetSortedIndex(const std::vector & toSort, std::vector & index, bool increasing=true); //-------------------------------------------------------------------- // Return the name of a type as a string template std::string GetTypeAsString(); //-------------------------------------------------------------------- // Convert radian / degree double rad2deg(double anglerad); double deg2rad(double anglerad); //-------------------------------------------------------------------- int GetTypeSizeFromString(const std::string & type); //-------------------------------------------------------------------- // Special case to handle "signed_char = schar" ... template bool IsSameType(std::string t) { return (t==GetTypeAsString()); } template<> bool IsSameType(std::string t); template<> bool IsSameType(std::string t); template<> bool IsSameType(std::string t); template<> bool IsSameType(std::string t); //-------------------------------------------------------------------- template std::string CreateListOfTypes(bool last=true) { return GetTypeAsString(); } template std::string CreateListOfTypes(bool last=true) { if (last) return CreateListOfTypes()+" and "+CreateListOfTypes(); else return CreateListOfTypes()+", "+CreateListOfTypes(); } template std::string CreateListOfTypes(bool last=true) { if (last) return CreateListOfTypes(false)+" and "+CreateListOfTypes(); else return CreateListOfTypes(false)+", "+CreateListOfTypes(); } template std::string CreateListOfTypes(bool last=true) { if (last) return CreateListOfTypes(false)+" and "+CreateListOfTypes(); else return CreateListOfTypes(false)+", "+CreateListOfTypes(); } template std::string CreateListOfTypes(bool last=true) { if (last) return CreateListOfTypes(false)+" and "+CreateListOfTypes(); else return CreateListOfTypes(false)+", "+CreateListOfTypes(); } template std::string CreateListOfTypes(bool last=true) { if (last) return CreateListOfTypes(false)+" and "+CreateListOfTypes(); else return CreateListOfTypes(false)+", "+CreateListOfTypes(); } template std::string CreateListOfTypes(bool last=true) { if (last) return CreateListOfTypes(false)+" and "+CreateListOfTypes(); else return CreateListOfTypes(false)+", "+CreateListOfTypes(); } template std::string CreateListOfTypes(bool last=true) { if (last) return CreateListOfTypes(false)+" and "+CreateListOfTypes(); else return CreateListOfTypes(false)+", "+CreateListOfTypes(); } //-------------------------------------------------------------------- //-------------------------------------------------------------------- void FindAndReplace(std::string & line, const std::string & tofind, const std::string & replacement); void FindAndReplace(std::string & line, const std::vector & tofind, const std::vector & toreplace); void FindAndReplace(std::ifstream & in, const std::vector & tofind, const std::vector & toreplace, std::ofstream & out); //-------------------------------------------------------------------- //-------------------------------------------------------------------- double ComputeEuclideanDistanceFromPointToPlane(const itk::ContinuousIndex point, const itk::ContinuousIndex pointInPlane, const itk::ContinuousIndex normalPlane); //-------------------------------------------------------------------- // Open a File for reading/writing void openFileForReading(std::ifstream & is, const std::string & filename); void openFileForWriting(std::ofstream & os, const std::string & filename); //-------------------------------------------------------------------- double cotan(double i); double invcotan(double i); //-------------------------------------------------------------------- void disableStdCerr(); void enableStdCerr(); #include "clitkCommon.txx" } // end namespace #endif /* end #define CLITKCOMMON_H */