X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=common%2FclitkCommon.txx;h=c2e9a4ae3f92acca36287309d416971cc3a1e574;hb=03c0a567e50d4b3dcdee11112b0a404789468857;hp=f9eeb8c8bfd9280319f0ed0d38a47a393827b87b;hpb=0b7c9b1e1215634b02cbd38d4e4ba101d6111ba8;p=clitk.git diff --git a/common/clitkCommon.txx b/common/clitkCommon.txx index f9eeb8c..c2e9a4a 100644 --- a/common/clitkCommon.txx +++ b/common/clitkCommon.txx @@ -1,7 +1,7 @@ /*========================================================================= Program: vv http://www.creatis.insa-lyon.fr/rio/vv - Authors belong to: + 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 @@ -22,13 +22,14 @@ * @file clitkCommon.txx * @author David Sarrut * @date 18 May 2006 - * + * -------------------------------------------------*/ //-------------------------------------------------------------------- // Convert float, double ... to string template -std::string toString(const T & t) { +std::string toString(const T & t) +{ std::ostringstream myStream; myStream << t << std::flush; return(myStream.str()); @@ -38,7 +39,8 @@ std::string toString(const T & t) { //-------------------------------------------------------------------- // Convert float*, double* ... to string template -std::string toStringVector(const T * t, const int n) { +std::string toStringVector(const T * t, const int n) +{ std::ostringstream myStream; for(int i=0; i(t[i]) << " "; @@ -50,7 +52,8 @@ std::string toStringVector(const T * t, const int n) { //-------------------------------------------------------------------- // Convert float*, double* ... to string template -std::string toStringVector(const T & t, const int n) { +std::string toStringVector(const T & t, const int n) +{ std::ostringstream myStream; for(int i=0; i -std::string toStringVector(const std::vector & t) { +std::string toStringVector(const std::vector & t) +{ return toStringVector(&t[0], t.size()); } //-------------------------------------------------------------------- @@ -70,7 +74,8 @@ std::string toStringVector(const std::vector & t) { //-------------------------------------------------------------------- // Convert a pixel type to another (downcast) template -TPixelDown PixelTypeDownCast(const TPixelUp & x) { +TPixelDown PixelTypeDownCast(const TPixelUp & x) +{ return (TPixelDown)lrint(x); } //-------------------------------------------------------------------- @@ -79,7 +84,7 @@ TPixelDown PixelTypeDownCast(const TPixelUp & x) { template struct vectorComparisonLowerThan: public std::binary_function { vectorComparisonLowerThan(const std::vector & v):vect(v) {}; - bool operator()(int x, int y) { + bool operator()(int x, int y) { return (vect[x] < vect[y]); } const std::vector & vect; @@ -90,7 +95,7 @@ struct vectorComparisonLowerThan: public std::binary_function { template struct vectorComparisonGreaterThan: public std::binary_function { vectorComparisonGreaterThan(const std::vector & v):vect(v) {}; - bool operator()(int x, int y) { + bool operator()(int x, int y) { return (vect[x] > vect[y]); } const std::vector & vect; @@ -99,23 +104,25 @@ struct vectorComparisonGreaterThan: public std::binary_function //-------------------------------------------------------------------- template -void GetSortedIndex(const std::vector & toSort, std::vector & index, bool increasing) { - index.resize(toSort.size()); +void GetSortedIndex(const std::vector & toSort, std::vector & index, bool increasing) +{ + index.resize(toSort.size()); for(unsigned int i=0; i(toSort)); - else - std::sort(index.begin(), - index.end(), - vectorComparisonGreaterThan(toSort)); + if (increasing) + std::sort(index.begin(), + index.end(), + vectorComparisonLowerThan(toSort)); + else + std::sort(index.begin(), + index.end(), + vectorComparisonGreaterThan(toSort)); } //-------------------------------------------------------------------- //-------------------------------------------------------------------- template -std::string GetTypeAsString() { +std::string GetTypeAsString() +{ // http://www.vtk.org/doc/release/3/html/vtkSetGet_8h-source.html // and // itkImageIOBase.cxx @@ -137,17 +144,18 @@ std::string GetTypeAsString() { //-------------------------------------------------------------------- template -void CloneImage(const typename ImageType::Pointer & input, typename ImageType::Pointer & output) { +void CloneImage(const typename ImageType::Pointer & input, typename ImageType::Pointer & output) +{ output->SetRegions(input->GetLargestPossibleRegion()); output->SetOrigin(input->GetOrigin()); output->SetSpacing(input->GetSpacing()); output->Allocate(); - typedef itk::ImageRegionConstIterator ConstIteratorType; + typedef itk::ImageRegionConstIterator ConstIteratorType; ConstIteratorType pi(input,input->GetLargestPossibleRegion()); - pi.GoToBegin(); - typedef itk::ImageRegionIterator IteratorType; + pi.GoToBegin(); + typedef itk::ImageRegionIterator IteratorType; IteratorType po(output,input->GetLargestPossibleRegion()); - po.GoToBegin(); + po.GoToBegin(); while (!pi.IsAtEnd()) { po.Set(pi.Get()); ++pi;