RTK  1.4.0
Reconstruction Toolkit
rtkGeneralPurposeFunctions.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright RTK Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 
19 #ifndef rtkGeneralPurposeFunctions_h
20 #define rtkGeneralPurposeFunctions_h
21 
22 #include <vector>
23 #include <itkMacro.h>
24 #include <itkImageFileWriter.h>
25 #include <itkMath.h>
26 
27 namespace rtk
28 {
29 
37 inline
38 static std::vector<double>
39 ReadSignalFile(std::string filename)
40 {
41  std::vector<double> signalVector;
42  std::ifstream is( filename.c_str() );
43  if( !is.is_open() )
44  {
45  itkGenericExceptionMacro(<< "Could not open signal file " << filename);
46  }
47 
48  double value;
49  std::string s;
50  while (getline(is, s))
51  {
52  if (!s.empty())
53  {
54  std::istringstream tmp(s);
55  tmp >> value;
56  if (itk::Math::Round<double>(value * 100) / 100 == 1)
57  signalVector.push_back(0);
58  else
59  signalVector.push_back(itk::Math::Round<double>(value * 100) / 100);
60  }
61  }
62 
63  return signalVector;
64 }
65 
66 template< typename ImageType >
67 void
68 WriteImage(typename ImageType::ConstPointer input, std::string name)
69 {
70  //Create an itk::ImageFileWriter
71  typedef itk::ImageFileWriter<ImageType> WriterType;
72  typename WriterType::Pointer writer = WriterType::New();
73  writer->SetInput(input);
74  writer->SetFileName(name);
75  writer->Update();
76 }
77 
78 }
79 
80 #endif // rtkGeneralPurposeFunctions_h
void WriteImage(typename ImageType::ConstPointer input, std::string name)