RTK  2.6.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  * https://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 
24 
25 #include "math.h"
26 
27 #include <itkMacro.h>
28 #include <itkImageFileWriter.h>
29 #include <itkMath.h>
30 
31 namespace rtk
32 {
33 
41 inline static std::vector<double>
42 ReadSignalFile(std::string filename)
43 {
44  std::vector<double> signalVector;
45  std::ifstream is(filename.c_str());
46  if (!is.is_open())
47  {
48  itkGenericExceptionMacro(<< "Could not open signal file " << filename);
49  }
50 
51  double value = NAN;
52  std::string s;
53  while (getline(is, s))
54  {
55  if (!s.empty())
56  {
57  std::istringstream tmp(s);
58  tmp >> value;
59  if (itk::Math::Round<double>(value * 100) / 100 == 1)
60  signalVector.push_back(0);
61  else
62  signalVector.push_back(itk::Math::Round<double>(value * 100) / 100);
63  }
64  }
65 
66  return signalVector;
67 }
68 
69 template <typename ImageType>
70 void
71 WriteImage(typename ImageType::ConstPointer input, std::string name)
72 {
73  // Create an itk::ImageFileWriter
74  using WriterType = itk::ImageFileWriter<ImageType>;
75  typename WriterType::Pointer writer = WriterType::New();
76  writer->SetInput(input);
77  writer->SetFileName(name);
78  writer->Update();
79 }
80 
81 } // namespace rtk
82 
83 #endif // rtkGeneralPurposeFunctions_h
static std::vector< double > ReadSignalFile(std::string filename)
A few functions that are used either in the applications or for debugging purposes.
void WriteImage(typename ImageType::ConstPointer input, std::string name)