/*========================================================================= Program: vv http://www.creatis.insa-lyon.fr/rio/vv Authors belong to: - University of LYON http://www.universite-lyon.fr/ - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the copyright notices for more information. It is distributed under dual licence - BSD See included LICENSE.txt file - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html ======================================================================-====*/ #ifndef CLITKCOMMON_H #define CLITKCOMMON_H // clitk include #include "clitkConfiguration.h" #include "clitkPortability.h" // itk include (include std) #include #include #include #include //-------------------------------------------------------------------- namespace clitk { 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); //-------------------------------------------------------------------- void readDoubleFromFile(const std::string & filename, std::vector & list); //-------------------------------------------------------------------- double cotan(double i); double invcotan(double i); //-------------------------------------------------------------------- void disableStdCerr(); void enableStdCerr(); //-------------------------------------------------------------------- template void CloneImage(const typename ImageType::Pointer & input, typename ImageType::Pointer & output); #include "clitkCommon.txx" } // end namespace #endif /* end #define CLITKCOMMON_H */