+
+//--------------------------------------------------------------------
+template<class ImageType>
+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<ImageType> ConstIteratorType;
+ ConstIteratorType pi(input,input->GetLargestPossibleRegion());
+ pi.GoToBegin();
+ typedef itk::ImageRegionIterator<ImageType> IteratorType;
+ IteratorType po(output,input->GetLargestPossibleRegion());
+ po.GoToBegin();
+ while (!pi.IsAtEnd()) {
+ po.Set(pi.Get());
+ ++pi;
+ ++po;
+ }
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+// http://stackoverflow.com/questions/771453/copy-map-values-to-vector-in-stl
+template <typename M, typename V>
+void MapToVecFirst(const M & m, V & v) {
+ for( typename M::const_iterator it = m.begin(); it != m.end(); ++it ) {
+ v.push_back( it->first );
+ }
+}
+template <typename M, typename V>
+void MapToVecSecond(const M & m, V & v) {
+ for( typename M::const_iterator it = m.begin(); it != m.end(); ++it ) {
+ v.push_back( it->second );
+ }
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+//http://stackoverflow.com/questions/1494399/how-do-i-search-find-and-replace-in-a-standard-string
+template<class T>
+int inline findAndReplace(T& source, const T& find, const T& replace)
+{
+ int num=0;
+ int fLen = find.size();
+ int rLen = replace.size();
+ for (int pos=0; (pos=source.find(find, pos))!=T::npos; pos+=rLen) {
+ num++;
+ source.replace(pos, fLen, replace);
+ }
+ return num;
+}
+//--------------------------------------------------------------------
+